FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gtp6_d_di.c
Go to the documentation of this file.
1 /*
2  * srv6_end_m_gtp6_d_di_di.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 *
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_gtp6_d_di_nodes[] = {
52  "srv6-end-m-gtp6-d-di",
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.GTP6.D.DI-plugin";
61 static u8 keyword_str[] = "end.m.gtp6.d.di";
62 static u8 def_str[] =
63  "Endpoint function with drop-in dencapsulation for IPv6/GTP tunnel";
64 static u8 param_str[] = "<sr-prefix>/<sr-prefixlen> [nhtype <nhtype>]";
65 
66 static u8 *
67 clb_format_srv6_end_m_gtp6_d_di (u8 * s, va_list * args)
68 {
69  srv6_end_gtp6_param_t *ls_mem = va_arg (*args, void *);
70 
71  s = format (s, "SRv6 End gtp6.d Drop-in\n\t");
72 
73  s =
74  format (s, "SR Prefix: %U/%d", format_ip6_address, &ls_mem->sr_prefix,
75  ls_mem->sr_prefixlen);
76 
77  if (ls_mem->nhtype != SRV6_NHTYPE_NONE)
78  {
79  if (ls_mem->nhtype == SRV6_NHTYPE_IPV4)
80  s = format (s, ", NHType IPv4\n");
81  else if (ls_mem->nhtype == SRV6_NHTYPE_IPV6)
82  s = format (s, ", NHType IPv6\n");
83  else if (ls_mem->nhtype == SRV6_NHTYPE_NON_IP)
84  s = format (s, ", NHType Non-IP\n");
85  else
86  s = format (s, ", NHType Unknow(%d)\n", ls_mem->nhtype);
87  }
88  else
89  s = format (s, "\n");
90 
91  return s;
92 }
93 
94 static uword
96 {
97  void **plugin_mem_p = va_arg (*args, void **);
98  srv6_end_gtp6_param_t *ls_mem;
99  ip6_address_t sr_prefix;
100  u32 sr_prefixlen = 0;
101  u8 nhtype;
102 
103  if (unformat (input, "end.m.gtp6.d.di %U/%d nhtype ipv4",
104  unformat_ip6_address, &sr_prefix, &sr_prefixlen))
105  {
106  nhtype = SRV6_NHTYPE_IPV4;
107  }
108  else if (unformat (input, "end.m.gtp6.d.di %U/%d nhtype ipv6",
109  unformat_ip6_address, &sr_prefix, &sr_prefixlen))
110  {
111  nhtype = SRV6_NHTYPE_IPV6;
112  }
113  else if (unformat (input, "end.m.gtp6.d.di %U/%d nhtype non-ip",
114  unformat_ip6_address, &sr_prefix, &sr_prefixlen))
115  {
116  nhtype = SRV6_NHTYPE_NON_IP;
117  }
118  else if (unformat (input, "end.m.gtp6.d.di %U/%d",
119  unformat_ip6_address, &sr_prefix, &sr_prefixlen))
120  {
121  nhtype = SRV6_NHTYPE_NONE;
122  }
123  else
124  {
125  return 0;
126  }
127 
128  ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
129  clib_memset (ls_mem, 0, sizeof *ls_mem);
130  *plugin_mem_p = ls_mem;
131 
132  ls_mem->sr_prefix = sr_prefix;
133  ls_mem->sr_prefixlen = sr_prefixlen;
134  ls_mem->nhtype = nhtype;
135 
136  return 1;
137 }
138 
139 static int
141 {
142  return 0;
143 }
144 
145 static int
147 {
148  srv6_end_gtp6_param_t *ls_mem;
149 
150  ls_mem = localsid->plugin_mem;
151 
152  clib_mem_free (ls_mem);
153 
154  return 0;
155 }
156 
157 static clib_error_t *
159 {
162  dpo_type_t dpo_type;
163  vlib_node_t *node;
164  int rc;
165 
166  sm->vlib_main = vm;
167  sm->vnet_main = vnet_get_main ();
168 
169  node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-d-di");
170  sm->end_m_gtp6_d_di_node_index = node->index;
171 
172  node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
173  sm->error_node_index = node->index;
174 
175  ip6 = &sm->cache_hdr;
176 
178 
179  // IPv6 header (default)
180  ip6->ip.ip_version_traffic_class_and_flow_label = 0x60;
181  ip6->ip.hop_limit = 64;
182  ip6->ip.protocol = IPPROTO_IPV6_ROUTE;
183 
184  // SR header (default)
185  ip6->sr.type = 4;
186 
187  dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
188 
190  &dpo_type,
195  if (rc < 0)
196  clib_error_return (0, "SRv6 Endpoint GTP6.D.DI LocalSID function"
197  "couldn't be registered");
198  return 0;
199 }
200 
201 /* *INDENT-OFF* */
203 {
204  .arc_name = "ip6-unicast",
205  .node_name = "srv6-end-m-gtp6-d-di",
206  .runs_before = 0,
207 };
208 
210 /* *INDENT-ON* */
211 
212 /*
213  * fd.io coding-style-patch-verification: ON
214  *
215  * Local Variables:
216  * eval: (c-set-style "gnu")
217  * End:
218  */
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
srv6_end_m_gtp6_d_di_init
static clib_error_t * srv6_end_m_gtp6_d_di_init(vlib_main_t *vm)
Definition: gtp6_d_di.c:158
srv6_end_m_gtp6_d_di_nodes
const static char *const srv6_end_m_gtp6_d_di_nodes[]
Definition: gtp6_d_di.c:51
srv6_end_main_v6_decap_di_s::end_m_gtp6_d_di_node_index
u32 end_m_gtp6_d_di_node_index
Definition: mobile.h:279
clb_removal_srv6_end_m_gtp6_d_di
static int clb_removal_srv6_end_m_gtp6_d_di(ip6_sr_localsid_t *localsid)
Definition: gtp6_d_di.c:146
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
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
IPPROTO_IPV6_ROUTE
#define IPPROTO_IPV6_ROUTE
Definition: sr_packet.h:114
SRV6_NHTYPE_NON_IP
#define SRV6_NHTYPE_NON_IP
Definition: mobile.h:34
VNET_FEATURE_INIT
VNET_FEATURE_INIT(srv6_end_m_gtp6_d_di, static)
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
clb_dpo_format_srv6_end_m_gtp6_d_di
static u8 * clb_dpo_format_srv6_end_m_gtp6_d_di(u8 *s, va_list *args)
Definition: gtp6_d_di.c:37
srv6_end_main_v6_decap_di_s
Definition: mobile.h:274
unformat_input_t
struct _unformat_input_t unformat_input_t
srv6_end_main_v6_decap_di
srv6_end_main_v6_decap_di_t srv6_end_main_v6_decap_di
Definition: gtp6_d_di.c:24
def_str
static u8 def_str[]
Definition: gtp6_d_di.c:62
SRV6_NHTYPE_IPV6
#define SRV6_NHTYPE_IPV6
Definition: mobile.h:33
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
clb_dpo_lock_srv6_end_m_gtp6_d_di
static void clb_dpo_lock_srv6_end_m_gtp6_d_di(dpo_id_t *dpo)
Definition: gtp6_d_di.c:27
srv6_end_m_gtp6_d_di
vlib_node_registration_t srv6_end_m_gtp6_d_di
(constructor) VLIB_REGISTER_NODE (srv6_end_m_gtp6_d_di)
Definition: node.c:2987
keyword_str
static u8 keyword_str[]
Definition: gtp6_d_di.c:61
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
SRV6_NHTYPE_NONE
#define SRV6_NHTYPE_NONE
Definition: mobile.h:31
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_end_main_v6_decap_di_s::vnet_main
vnet_main_t * vnet_main
Definition: mobile.h:277
clb_unformat_srv6_end_m_gtp6_d_di
static uword clb_unformat_srv6_end_m_gtp6_d_di(unformat_input_t *input, va_list *args)
Definition: gtp6_d_di.c:95
srv6_end_main_v6_decap_di_s::cache_hdr
ip6srv_combo_header_t cache_hdr
Definition: mobile.h:282
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
clib_memset_u8
static_always_inline void clib_memset_u8(void *p, u8 val, uword count)
Definition: string.h:441
SRV6_NHTYPE_IPV4
#define SRV6_NHTYPE_IPV4
Definition: mobile.h:32
plugin.h
srv6_end_gtp6_param_s::nhtype
u8 nhtype
Definition: mobile.h:179
srv6_end_main_v6_decap_di_s::error_node_index
u32 error_node_index
Definition: mobile.h:280
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
srv6_end_gtp6_param_s::sr_prefixlen
u32 sr_prefixlen
Definition: mobile.h:182
format
description fragment has unexpected format
Definition: map.api:433
dpo_nodes
const static char *const *const dpo_nodes[DPO_PROTO_NUM]
Definition: gtp6_d_di.c:56
param_str
static u8 param_str[]
Definition: gtp6_d_di.c:64
DPO_PROTO_IP6
@ DPO_PROTO_IP6
Definition: dpo.h:65
ip6srv_combo_header_t
Definition: sr.h:60
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
ip6
vl_api_ip6_address_t ip6
Definition: one.api:424
srv6_end_gtp6_param_s::sr_prefix
ip6_address_t sr_prefix
Definition: mobile.h:181
clb_format_srv6_end_m_gtp6_d_di
static u8 * clb_format_srv6_end_m_gtp6_d_di(u8 *s, va_list *args)
Definition: gtp6_d_di.c:67
clb_dpo_unlock_srv6_end_m_gtp6_d_di
static void clb_dpo_unlock_srv6_end_m_gtp6_d_di(dpo_id_t *dpo)
Definition: gtp6_d_di.c:32
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
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
format_ip6_address
format_function_t format_ip6_address
Definition: format.h:91
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
unformat_ip6_address
unformat_function_t unformat_ip6_address
Definition: format.h:89
clb_creation_srv6_end_m_gtp6_d_di
static int clb_creation_srv6_end_m_gtp6_d_di(ip6_sr_localsid_t *localsid)
Definition: gtp6_d_di.c:140
vnet.h
dpo_vft
const static dpo_vft_t dpo_vft
Definition: gtp6_d_di.c:45
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
srv6_end_main_v6_decap_di_s::vlib_main
vlib_main_t * vlib_main
Definition: mobile.h:276
fn_name
static u8 fn_name[]
Definition: gtp6_d_di.c:60
srv6_end_gtp6_param_s
Definition: mobile.h:177