FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gtp4_dt.c
Go to the documentation of this file.
1 /*
2  * srv6_t_m_gtp4_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 *
38 clb_dpo_format_srv6_t_m_gtp4_dt (u8 * s, va_list * args)
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_t_m_gtp4_dt_nodes[] = {
53  "srv6-t-m-gtp4-dt",
54  NULL,
55 };
56 
57 const static char *const srv6_t_m_gtp4_dt_v6_nodes[] = {
58  "error-drop",
59  NULL,
60 };
61 
62 const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
65 };
66 
67 static u8 fn_name[] = "SRv6-T.M.GTP4.DT-plugin";
68 static u8 keyword_str[] = "t.m.gtp4.dt";
69 static u8 def_str[] = "Transit function with DT for IPv4/GTP tunnel";
70 static u8 param_str[] = "fib-index <index> [local-fib-table <index>]";
71 
72 static u8 *
73 clb_format_srv6_t_m_gtp4_dt (u8 * s, va_list * args)
74 {
75  srv6_t_gtp4_dt_param_t *ls_mem = va_arg (*args, void *);
76 
77  s = format (s, "SRv6 Transit gtp4.dt\n\t");
78 
79  if (ls_mem->type == SRV6_GTP4_DT4)
80  s = format (s, " Type GTP4.DT4 fib-table %u\n", ls_mem->fib4_index);
81  else if (ls_mem->type == SRV6_GTP4_DT6)
82  s = format (s, " Type GTP4.DT6, fib-table %u, local-fib-table %u\n",
83  ls_mem->fib6_index, ls_mem->local_fib_index);
84  else if (ls_mem->type == SRV6_GTP4_DT46)
85  s = format (s, " Type GTP4.DT46, fib-table %u, local-fib-table %u\n",
86  ls_mem->fib6_index, ls_mem->local_fib_index);
87  else
88  s = format (s, "\n");
89 
90  return s;
91 }
92 
93 static uword
95 {
96  void **plugin_mem_p = va_arg (*args, void **);
97  srv6_t_gtp4_dt_param_t *ls_mem;
98  u32 fib_index = 0;
99  u32 local_fib_index = 0;
100  u32 type;
101 
102  if (unformat (input, "t.m.gtp4.dt4 fib-table %u", &fib_index))
103  {
105  }
106  else if (unformat (input, "t.m.gtp4.dt6 fib-table %u local-fib-table %u",
107  &fib_index, &local_fib_index))
108  {
110  }
111  else if (unformat (input, "t.m.gtp4.dt46 fib-table %u local-fib-table %u",
112  &fib_index, &local_fib_index))
113  {
115  }
116  else
117  {
118  return 0;
119  }
120 
121  ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
122  clib_memset (ls_mem, 0, sizeof *ls_mem);
123  *plugin_mem_p = ls_mem;
124 
125  ls_mem->fib4_index = fib_table_find (FIB_PROTOCOL_IP4, fib_index);
126  ls_mem->fib6_index = fib_table_find (FIB_PROTOCOL_IP6, fib_index);
127 
128  if (type == SRV6_GTP4_DT6 || type == SRV6_GTP4_DT46)
129  {
130  ls_mem->local_fib_index =
131  fib_table_find (FIB_PROTOCOL_IP6, local_fib_index);
132  }
133 
134  ls_mem->type = type;
135 
136  return 1;
137 }
138 
139 static int
141 {
142  return 0;
143 }
144 
145 static int
147 {
148  srv6_t_gtp4_dt_param_t *ls_mem;
149 
150  ls_mem = (srv6_t_gtp4_dt_param_t *) sr_policy->plugin_mem;
151 
152  clib_mem_free (ls_mem);
153 
154  return 0;
155 }
156 
157 static clib_error_t *
159 {
161  dpo_type_t dpo_type;
162  vlib_node_t *node;
163  int rc;
164 
165  sm->vlib_main = vm;
166  sm->vnet_main = vnet_get_main ();
167 
168  node = vlib_get_node_by_name (vm, (u8 *) "srv6-t-m-gtp4-dt");
169  sm->t_m_gtp4_dt_node_index = node->index;
170 
171  node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
172  sm->error_node_index = node->index;
173 
174  dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
175 
177  &dpo_type,
182  if (rc < 0)
183  clib_error_return (0, "SRv6 Transit GTP4.DT Policy function"
184  "couldn't be registered");
185  return 0;
186 }
187 
188 /* *INDENT-OFF* */
190 {
191  .arc_name = "ip4-unicast",
192  .node_name = "srv6-t-m-gtp4-dt",
193  .runs_before = 0,
194 };
195 
197 /* *INDENT-ON* */
198 
199 /*
200  * fd.io coding-style-patch-verification: ON
201  *
202  * Local Variables:
203  * eval: (c-set-style "gnu")
204  * End:
205  */
adj.h
srv6_t_gtp4_dt_param_s::local_fib_index
u32 local_fib_index
Definition: mobile.h:200
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_t_gtp4_dt_param_s::fib4_index
u32 fib4_index
Definition: mobile.h:198
param_str
static u8 param_str[]
Definition: gtp4_dt.c:70
srv6_t_gtp4_dt_param_s::type
u8 type
Definition: mobile.h:196
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:314
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
fib_table.h
clb_creation_srv6_t_m_gtp4_dt
static int clb_creation_srv6_t_m_gtp4_dt(ip6_sr_policy_t *sr_policy)
Definition: gtp4_dt.c:140
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
clb_format_srv6_t_m_gtp4_dt
static u8 * clb_format_srv6_t_m_gtp4_dt(u8 *s, va_list *args)
Definition: gtp4_dt.c:73
clb_dpo_lock_srv6_t_m_gtp4_dt
static void clb_dpo_lock_srv6_t_m_gtp4_dt(dpo_id_t *dpo)
Definition: gtp4_dt.c:28
srv6_t_main_v4_dt_s::error_node_index
u32 error_node_index
Definition: mobile.h:306
unformat_input_t
struct _unformat_input_t unformat_input_t
fn_name
static u8 fn_name[]
Definition: gtp4_dt.c:67
dpo_nodes
const static char *const *const dpo_nodes[DPO_PROTO_NUM]
Definition: gtp4_dt.c:62
srv6_t_main_v4_dt
srv6_t_main_v4_dt_t srv6_t_main_v4_dt
Definition: gtp4_dt.c:25
srv6_t_m_gtp4_dt_nodes
const static char *const srv6_t_m_gtp4_dt_nodes[]
Definition: gtp4_dt.c:52
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
ip6_sr_policy_t::plugin_mem
void * plugin_mem
Definition: sr.h:115
ip6_sr_policy_t
SR Policy.
Definition: sr.h:96
srv6_t_m_gtp4_dt
vlib_node_registration_t srv6_t_m_gtp4_dt
(constructor) VLIB_REGISTER_NODE (srv6_t_m_gtp4_dt)
Definition: node.c:3013
def_str
static u8 def_str[]
Definition: gtp4_dt.c:69
srv6_t_m_gtp4_dt_init
static clib_error_t * srv6_t_m_gtp4_dt_init(vlib_main_t *vm)
Definition: gtp4_dt.c:158
clb_removal_srv6_t_m_gtp4_dt
static int clb_removal_srv6_t_m_gtp4_dt(ip6_sr_policy_t *sr_policy)
Definition: gtp4_dt.c:146
srv6_t_gtp4_dt_param_s
Definition: mobile.h:194
clb_dpo_unlock_srv6_t_m_gtp4_dt
static void clb_dpo_unlock_srv6_t_m_gtp4_dt(dpo_id_t *dpo)
Definition: gtp4_dt.c:33
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
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
mobile.h
uword
u64 uword
Definition: types.h:112
SRV6_GTP4_DT6
#define SRV6_GTP4_DT6
Definition: mobile.h:47
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()
sr_policy_register_function
int sr_policy_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_p_plugin_callback_t *creation_fn, sr_p_plugin_callback_t *removal_fn)
SR Policy plugin registry.
Definition: sr_policy_rewrite.c:3405
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
dpo_vft
const static dpo_vft_t dpo_vft
Definition: gtp4_dt.c:46
plugin.h
SRV6_GTP4_DT4
#define SRV6_GTP4_DT4
Definition: mobile.h:46
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
clb_dpo_format_srv6_t_m_gtp4_dt
static u8 * clb_dpo_format_srv6_t_m_gtp4_dt(u8 *s, va_list *args)
Definition: gtp4_dt.c:38
format
description fragment has unexpected format
Definition: map.api:433
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_t_main_v4_dt_s::t_m_gtp4_dt_node_index
u32 t_m_gtp4_dt_node_index
Definition: mobile.h:305
clb_unformat_srv6_t_m_gtp4_dt
static uword clb_unformat_srv6_t_m_gtp4_dt(unformat_input_t *input, va_list *args)
Definition: gtp4_dt.c:94
srv6_t_main_v4_dt_s::vlib_main
vlib_main_t * vlib_main
Definition: mobile.h:302
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
dpo_vft_t_
A virtual function table regisitered for a DPO type.
Definition: dpo.h:423
srv6_t_main_v4_dt_s::vnet_main
vnet_main_t * vnet_main
Definition: mobile.h:303
srv6_t_gtp4_dt_param_s::fib6_index
u32 fib6_index
Definition: mobile.h:199
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
srv6_t_main_v4_dt_s
Definition: mobile.h:300
DPO_PROTO_IP4
@ DPO_PROTO_IP4
Definition: dpo.h:64
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
keyword_str
static u8 keyword_str[]
Definition: gtp4_dt.c:68
SRV6_GTP4_DT46
#define SRV6_GTP4_DT46
Definition: mobile.h:48
srv6_t_m_gtp4_dt_v6_nodes
const static char *const srv6_t_m_gtp4_dt_v6_nodes[]
Definition: gtp4_dt.c:57
vnet.h
VNET_FEATURE_INIT
VNET_FEATURE_INIT(srv6_t_m_gtp4_dt, static)
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
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123