FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gtp6_dt.c
Go to the documentation of this file.
1 /*
2  * srv6_end_m_gtp6_dt.c
3  *
4  * Copyright (c) 2019 Arrcus Inc and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/adj/adj.h>
20 #include <vnet/fib/fib_table.h>
21 #include <vnet/plugin/plugin.h>
22 #include <vpp/app/version.h>
23 #include <srv6-mobile/mobile.h>
24 
26 
27 static void
29 {
30 }
31 
32 static void
34 {
35 }
36 
37 static u8 *
39 {
40  index_t index = va_arg (*args, index_t);
41  CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
42 
43  return (format (s, "SR: dynamic_proxy_index:[%u]", index));
44 }
45 
46 const static dpo_vft_t dpo_vft = {
50 };
51 
52 const static char *const srv6_end_m_gtp6_dt_nodes[] = {
53  "srv6-end-m-gtp6-dt",
54  NULL,
55 };
56 
57 const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
59 };
60 
61 static u8 fn_name[] = "SRv6-End.M.GTP6.DT-plugin";
62 static u8 keyword_str[] = "end.m.gtp6.dt";
63 static u8 def_str[] = "Endpoint function with DT for IPv6/GTP tunnel";
64 static u8 param_str[] = "fib-index <index> [local-fib-table <index>]";
65 
66 static u8 *
67 clb_format_srv6_end_m_gtp6_dt (u8 * s, va_list * args)
68 {
69  srv6_end_gtp6_dt_param_t *ls_mem = va_arg (*args, void *);
70 
71  s = format (s, "SRv6 End gtp6.dt\n\t");
72 
73  if (ls_mem->type == SRV6_GTP6_DT4)
74  s = format (s, " Type GTP6.DT4 fib-table %u\n", ls_mem->fib4_index);
75  else if (ls_mem->type == SRV6_GTP6_DT6)
76  s = format (s, " Type GTP6.DT6, fib-table %u, local-fib-table %u\n",
77  ls_mem->fib6_index, ls_mem->local_fib_index);
78  else if (ls_mem->type == SRV6_GTP6_DT46)
79  s = format (s, " Type GTP6.DT46, fib-table %u, local-fib-table %u\n",
80  ls_mem->fib6_index, ls_mem->local_fib_index);
81  else
82  s = format (s, "\n");
83 
84  return s;
85 }
86 
87 static uword
89 {
90  void **plugin_mem_p = va_arg (*args, void **);
92  u32 fib_index = 0;
93  u32 local_fib_index = 0;
94  u32 type;
95 
96  if (unformat (input, "end.m.gtp6.dt4 fib-table %u", &fib_index))
97  {
99  }
100  else if (unformat (input, "end.m.gtp6.dt6 fib-table %u local-fib-table %u",
101  &fib_index, &local_fib_index))
102  {
104  }
105  else if (unformat (input, "end.m.gtp6.dt46 fib-table %u local-fib-table %u",
106  &fib_index, &local_fib_index))
107  {
109  }
110  else
111  {
112  return 0;
113  }
114 
115  ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
116  clib_memset (ls_mem, 0, sizeof *ls_mem);
117  *plugin_mem_p = ls_mem;
118 
119  ls_mem->fib4_index = fib_table_find (FIB_PROTOCOL_IP4, fib_index);
120  ls_mem->fib6_index = fib_table_find (FIB_PROTOCOL_IP6, fib_index);
121 
122  if (type == SRV6_GTP6_DT6 || type == SRV6_GTP6_DT46)
123  {
124  ls_mem->local_fib_index =
125  fib_table_find (FIB_PROTOCOL_IP6, local_fib_index);
126  }
127 
128  ls_mem->type = type;
129 
130  return 1;
131 }
132 
133 static int
135 {
136  return 0;
137 }
138 
139 static int
141 {
142  srv6_end_gtp6_dt_param_t *ls_mem;
143 
144  ls_mem = localsid->plugin_mem;
145 
146  clib_mem_free (ls_mem);
147 
148  return 0;
149 }
150 
151 static clib_error_t *
153 {
155  dpo_type_t dpo_type;
156  vlib_node_t *node;
157  int rc;
158 
159  sm->vlib_main = vm;
160  sm->vnet_main = vnet_get_main ();
161 
162  node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-dt");
163  sm->end_m_gtp6_dt_node_index = node->index;
164 
165  node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
166  sm->error_node_index = node->index;
167 
168  dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
169 
171  &dpo_type,
176  if (rc < 0)
177  clib_error_return (0, "SRv6 Endpoint GTP6.DT LocalSID function"
178  "couldn't be registered");
179  return 0;
180 }
181 
182 /* *INDENT-OFF* */
184 {
185  .arc_name = "ip6-unicast",
186  .node_name = "srv6-end-m-gtp6-dt",
187  .runs_before = 0,
188 };
189 
191 /* *INDENT-ON* */
192 
193 /*
194  * fd.io coding-style-patch-verification: ON
195  *
196  * Local Variables:
197  * eval: (c-set-style "gnu")
198  * End:
199  */
adj.h
param_str
static u8 param_str[]
Definition: gtp6_dt.c:64
dpo_register_new_type
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
Definition: dpo.c:349
srv6_end_gtp6_dt_param_s::type
u8 type
Definition: mobile.h:187
srv6_end_main_v6_dt_s::end_m_gtp6_dt_node_index
u32 end_m_gtp6_dt_node_index
Definition: mobile.h:293
clb_unformat_srv6_end_m_gtp6_dt
static uword clb_unformat_srv6_end_m_gtp6_dt(unformat_input_t *input, va_list *args)
Definition: gtp6_dt.c:88
srv6_end_gtp6_dt_param_s::fib4_index
u32 fib4_index
Definition: mobile.h:189
ip6_sr_localsid_t
SR LocalSID.
Definition: sr.h:123
sr_localsid_register_function
int sr_localsid_register_function(vlib_main_t *vm, u8 *fn_name, u8 *keyword_str, u8 *def_str, u8 *params_str, u8 prefix_length, dpo_type_t *dpo, format_function_t *ls_format, unformat_function_t *ls_unformat, sr_plugin_callback_t *creation_fn, sr_plugin_callback_t *removal_fn)
SR LocalSID plugin registry.
Definition: sr_localsid.c:2347
srv6_end_main_v6_dt_s::vnet_main
vnet_main_t * vnet_main
Definition: mobile.h:291
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:314
ip6_sr_localsid_t::plugin_mem
void * plugin_mem
Memory to be used by the plugin callback functions.
Definition: sr.h:156
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
fn_name
static u8 fn_name[]
Definition: gtp6_dt.c:61
dpo_nodes
const static char *const *const dpo_nodes[DPO_PROTO_NUM]
Definition: gtp6_dt.c:57
fib_table.h
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_input_t
struct _unformat_input_t unformat_input_t
srv6_end_m_gtp6_dt_init
static clib_error_t * srv6_end_m_gtp6_dt_init(vlib_main_t *vm)
Definition: gtp6_dt.c:152
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
VNET_FEATURE_INIT
VNET_FEATURE_INIT(srv6_end_m_gtp6_dt, static)
clb_dpo_lock_srv6_end_m_gtp6_dt
static void clb_dpo_lock_srv6_end_m_gtp6_dt(dpo_id_t *dpo)
Definition: gtp6_dt.c:28
SRV6_GTP6_DT6
#define SRV6_GTP6_DT6
Definition: mobile.h:42
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
clb_dpo_format_srv6_end_m_gtp6_dt
static u8 * clb_dpo_format_srv6_end_m_gtp6_dt(u8 *s, va_list *args)
Definition: gtp6_dt.c:38
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
srv6_end_gtp6_dt_param_s::local_fib_index
u32 local_fib_index
Definition: mobile.h:191
clb_dpo_unlock_srv6_end_m_gtp6_dt
static void clb_dpo_unlock_srv6_end_m_gtp6_dt(dpo_id_t *dpo)
Definition: gtp6_dt.c:33
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
def_str
static u8 def_str[]
Definition: gtp6_dt.c:63
mobile.h
uword
u64 uword
Definition: types.h:112
dpo_vft
const static dpo_vft_t dpo_vft
Definition: gtp6_dt.c:46
dpo_type_t
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type()
dpo_vft_t_::dv_lock
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:428
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
srv6_end_gtp6_dt_param_s::fib6_index
u32 fib6_index
Definition: mobile.h:190
clb_creation_srv6_end_m_gtp6_dt
static int clb_creation_srv6_end_m_gtp6_dt(ip6_sr_localsid_t *localsid)
Definition: gtp6_dt.c:134
plugin.h
clb_format_srv6_end_m_gtp6_dt
static u8 * clb_format_srv6_end_m_gtp6_dt(u8 *s, va_list *args)
Definition: gtp6_dt.c:67
index
u32 index
Definition: flow_types.api:221
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
format
description fragment has unexpected format
Definition: map.api:433
clb_removal_srv6_end_m_gtp6_dt
static int clb_removal_srv6_end_m_gtp6_dt(ip6_sr_localsid_t *localsid)
Definition: gtp6_dt.c:140
DPO_PROTO_IP6
@ DPO_PROTO_IP6
Definition: dpo.h:65
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
srv6_end_m_gtp6_dt
vlib_node_registration_t srv6_end_m_gtp6_dt
(constructor) VLIB_REGISTER_NODE (srv6_end_m_gtp6_dt)
Definition: node.c:2999
srv6_end_main_v6_dt_s
Definition: mobile.h:288
SRV6_GTP6_DT46
#define SRV6_GTP6_DT46
Definition: mobile.h:43
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
srv6_end_m_gtp6_dt_nodes
const static char *const srv6_end_m_gtp6_dt_nodes[]
Definition: gtp6_dt.c:52
vlib_node_t
Definition: node.h:247
dpo_vft_t_
A virtual function table regisitered for a DPO type.
Definition: dpo.h:423
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
clib_mem_alloc_aligned_at_offset
static void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset, int os_out_of_memory_on_failure)
Definition: mem.h:225
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
srv6_end_main_v6_dt
srv6_end_main_v6_dt_t srv6_end_main_v6_dt
Definition: gtp6_dt.c:25
vnet.h
srv6_end_main_v6_dt_s::error_node_index
u32 error_node_index
Definition: mobile.h:294
fib_table_find
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1111
srv6_end_gtp6_dt_param_s
Definition: mobile.h:185
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
SRV6_GTP6_DT4
#define SRV6_GTP6_DT4
Definition: mobile.h:41
srv6_end_main_v6_dt_s::vlib_main
vlib_main_t * vlib_main
Definition: mobile.h:290
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
keyword_str
static u8 keyword_str[]
Definition: gtp6_dt.c:62