FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gtp4_e.c
Go to the documentation of this file.
1 /*
2  * srv6_end_m_gtp4_e.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/plugin/plugin.h>
21 #include <vpp/app/version.h>
22 #include <srv6-mobile/mobile.h>
23 
25 
26 static void
28 {
29 }
30 
31 static void
33 {
34 }
35 
36 static u8 *
37 clb_dpo_format_srv6_end_m_gtp4_e (u8 * s, va_list * args)
38 {
39  index_t index = va_arg (*args, index_t);
40  CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
41 
42  return (format (s, "SR: dynamic_proxy_index:[%u]", index));
43 }
44 
45 const static dpo_vft_t dpo_vft = {
49 };
50 
51 const static char *const srv6_end_m_gtp4_e_nodes[] = {
52  "srv6-end-m-gtp4-e",
53  NULL,
54 };
55 
56 const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
58 };
59 
60 static u8 fn_name[] = "SRv6-End.M.GTP4.E-plugin";
61 static u8 keyword_str[] = "end.m.gtp4.e";
62 static u8 def_str[] =
63  "Endpoint function with encapsulation for IPv4/GTP tunnel";
64 static u8 param_str[] = "";
65 
66 static u8 *
67 clb_format_srv6_end_m_gtp4_e (u8 * s, va_list * args)
68 {
69  srv6_end_gtp4_param_t *ls_mem = va_arg (*args, void *);
70 
71  s = format (s, "SRv6 End gtp4.e\n\t");
72 
73  s = format (s, "IPv4 address position: %d\n", ls_mem->v4src_position);
74 
75  return s;
76 }
77 
78 static uword
80 {
81  void **plugin_mem_p = va_arg (*args, void **);
82  srv6_end_gtp4_param_t *ls_mem;
83  u32 v4src_position;
84 
85  if (!unformat (input, "end.m.gtp4.e v4src_position %d", &v4src_position))
86  return 0;
87 
88  ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
89  clib_memset (ls_mem, 0, sizeof *ls_mem);
90  *plugin_mem_p = ls_mem;
91 
92  ls_mem->v4src_position = v4src_position;
93 
94  return 1;
95 }
96 
97 static int
99 {
100  return 0;
101 }
102 
103 static int
105 {
106  srv6_end_gtp4_param_t *ls_mem;
107 
108  ls_mem = localsid->plugin_mem;
109 
110  clib_mem_free (ls_mem);
111 
112  return 0;
113 }
114 
115 static clib_error_t *
117 {
119  ip4_header_t *ip4 = &sm->cache_hdr.ip4;
120  udp_header_t *udp = &sm->cache_hdr.udp;
121  gtpu_header_t *gtpu = &sm->cache_hdr.gtpu;
122  dpo_type_t dpo_type;
123  vlib_node_t *node;
124  int rc;
125 
126  sm->vlib_main = vm;
127  sm->vnet_main = vnet_get_main ();
128 
129  node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp4-e");
130  sm->end_m_gtp4_e_node_index = node->index;
131 
132  node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
133  sm->error_node_index = node->index;
134 
135  sm->dst_p_len = 32;
136  sm->src_p_len = 64;
137 
138  // clear the pre cached packet
139  clib_memset_u8 (ip4, 0, sizeof (ip4_gtpu_header_t));
140 
141  // set defaults
142  ip4->ip_version_and_header_length = 0x45;
143  ip4->protocol = IP_PROTOCOL_UDP;
144  ip4->ttl = 64;
145 
146  udp->dst_port = clib_host_to_net_u16 (SRV6_GTP_UDP_DST_PORT);
147 
149  gtpu->type = GTPU_TYPE_GTPU;
150  //
151 
152  dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
153 
155  &dpo_type,
160  if (rc < 0)
161  clib_error_return (0, "SRv6 Endpoint GTP4.E LocalSID function"
162  "couldn't be registered");
163  return 0;
164 }
165 
166 /* *INDENT-OFF* */
168 {
169  .arc_name = "ip6-unicast",
170  .node_name = "srv6-end-m-gtp4-e",
171  .runs_before = 0,
172 };
173 
175 
177  .version = VPP_BUILD_VER,
178  .description = "SRv6 GTP Endpoint Functions",
179 };
180 /* *INDENT-ON* */
181 
182 /*
183  * fd.io coding-style-patch-verification: ON
184  *
185  * Local Variables:
186  * eval: (c-set-style "gnu")
187  * End:
188  */
srv6_end_main_v4_s::vnet_main
vnet_main_t * vnet_main
Definition: mobile.h:219
adj.h
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
clb_unformat_srv6_end_m_gtp4_e
static uword clb_unformat_srv6_end_m_gtp4_e(unformat_input_t *input, va_list *args)
Definition: gtp4_e.c:79
GTPU_PT_GTP
#define GTPU_PT_GTP
Definition: mobile.h:164
gtpu_header_t::ver_flags
u8 ver_flags
Definition: mobile.h:92
keyword_str
static u8 keyword_str[]
Definition: gtp4_e.c:61
ip4_gtpu_header_t
Definition: mobile.h:145
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
SRV6_GTP_UDP_DST_PORT
#define SRV6_GTP_UDP_DST_PORT
Definition: mobile.h:29
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
ip4_gtpu_header_t::gtpu
gtpu_header_t gtpu
Definition: mobile.h:149
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
srv6_end_main_v4_s
Definition: mobile.h:216
srv6_end_main_v4_s::vlib_main
vlib_main_t * vlib_main
Definition: mobile.h:218
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
param_str
static u8 param_str[]
Definition: gtp4_e.c:64
clb_dpo_unlock_srv6_end_m_gtp4_e
static void clb_dpo_unlock_srv6_end_m_gtp4_e(dpo_id_t *dpo)
Definition: gtp4_e.c:32
srv6_end_m_gtp4_e_nodes
const static char *const srv6_end_m_gtp4_e_nodes[]
Definition: gtp4_e.c:51
unformat_input_t
struct _unformat_input_t unformat_input_t
clb_dpo_lock_srv6_end_m_gtp4_e
static void clb_dpo_lock_srv6_end_m_gtp4_e(dpo_id_t *dpo)
Definition: gtp4_e.c:27
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
VNET_FEATURE_INIT
VNET_FEATURE_INIT(srv6_end_m_gtp4_e, static)
GTPU_V1_VER
#define GTPU_V1_VER
Definition: mobile.h:162
srv6_end_m_gtp4_e
vlib_node_registration_t srv6_end_m_gtp4_e
(constructor) VLIB_REGISTER_NODE (srv6_end_m_gtp4_e)
Definition: node.c:1213
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
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
mobile.h
gtpu_header_t
Definition: mobile.h:90
uword
u64 uword
Definition: types.h:112
clb_creation_srv6_end_m_gtp4_e
static int clb_creation_srv6_end_m_gtp4_e(ip6_sr_localsid_t *localsid)
Definition: gtp4_e.c:98
srv6_end_main_v4_s::cache_hdr
ip4_gtpu_header_t cache_hdr
Definition: mobile.h:227
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()
ip4_gtpu_header_t::udp
udp_header_t udp
Definition: mobile.h:148
srv6_end_main_v4
srv6_end_main_v4_t srv6_end_main_v4
Definition: gtp4_e.c:24
dpo_vft_t_::dv_lock
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:428
srv6_end_main_v4_s::dst_p_len
u32 dst_p_len
Definition: mobile.h:224
clib_memset_u8
static_always_inline void clib_memset_u8(void *p, u8 val, uword count)
Definition: string.h:441
srv6_end_main_v4_s::end_m_gtp4_e_node_index
u32 end_m_gtp4_e_node_index
Definition: mobile.h:221
plugin.h
clb_removal_srv6_end_m_gtp4_e
static int clb_removal_srv6_end_m_gtp4_e(ip6_sr_localsid_t *localsid)
Definition: gtp4_e.c:104
index
u32 index
Definition: flow_types.api:221
srv6_end_main_v4_s::src_p_len
u32 src_p_len
Definition: mobile.h:225
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
dpo_vft
const static dpo_vft_t dpo_vft
Definition: gtp4_e.c:45
dpo_nodes
const static char *const *const dpo_nodes[DPO_PROTO_NUM]
Definition: gtp4_e.c:56
format
description fragment has unexpected format
Definition: map.api:433
srv6_end_m_gtp4_e_init
static clib_error_t * srv6_end_m_gtp4_e_init(vlib_main_t *vm)
Definition: gtp4_e.c:116
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
udp_header_t::dst_port
u16 dst_port
Definition: udp_packet.h:48
gtpu_header_t::type
u8 type
Definition: mobile.h:93
clb_dpo_format_srv6_end_m_gtp4_e
static u8 * clb_dpo_format_srv6_end_m_gtp4_e(u8 *s, va_list *args)
Definition: gtp4_e.c:37
fn_name
static u8 fn_name[]
Definition: gtp4_e.c:60
def_str
static u8 def_str[]
Definition: gtp4_e.c:62
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_end_main_v4_s::error_node_index
u32 error_node_index
Definition: mobile.h:222
srv6_end_gtp4_param_s
Definition: mobile.h:203
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
clb_format_srv6_end_m_gtp4_e
static u8 * clb_format_srv6_end_m_gtp4_e(u8 *s, va_list *args)
Definition: gtp4_e.c:67
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
vnet.h
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
GTPU_TYPE_GTPU
#define GTPU_TYPE_GTPU
Definition: mobile.h:104
ip4_gtpu_header_t::ip4
ip4_header_t ip4
Definition: mobile.h:147
srv6_end_gtp4_param_s::v4src_position
u32 v4src_position
Definition: mobile.h:213