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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
24 srv6_end_main_v6_decap_t srv6_end_main_v6_decap;
27 clb_dpo_lock_srv6_end_m_gtp6_d (dpo_id_t * dpo)
32 clb_dpo_unlock_srv6_end_m_gtp6_d (dpo_id_t * dpo)
37 clb_dpo_format_srv6_end_m_gtp6_d (u8 * s, va_list * args)
39 index_t index = va_arg (*args, index_t);
40 CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
42 return (format (s, "SR: dynamic_proxy_index:[%u]", index));
45 const static dpo_vft_t dpo_vft = {
46 .dv_lock = clb_dpo_lock_srv6_end_m_gtp6_d,
47 .dv_unlock = clb_dpo_unlock_srv6_end_m_gtp6_d,
48 .dv_format = clb_dpo_format_srv6_end_m_gtp6_d,
51 const static char *const srv6_end_m_gtp6_d_nodes[] = {
56 const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
57 [DPO_PROTO_IP6] = srv6_end_m_gtp6_d_nodes,
60 static u8 fn_name[] = "SRv6-End.M.GTP6.D-plugin";
61 static u8 keyword_str[] = "end.m.gtp6.d";
63 "Endpoint function with dencapsulation for IPv6/GTP tunnel";
64 static u8 param_str[] =
65 "<sr-prefix>/<sr-prefixlen> [nhtype <nhtype>] fib-table <id>";
68 clb_format_srv6_end_m_gtp6_d (u8 * s, va_list * args)
70 srv6_end_gtp6_d_param_t *ls_mem = va_arg (*args, void *);
72 s = format (s, "SRv6 End gtp6.d\n\t");
75 format (s, "SR Prefix: %U/%d", format_ip6_address, &ls_mem->sr_prefix,
76 ls_mem->sr_prefixlen);
78 if (ls_mem->nhtype != SRV6_NHTYPE_NONE)
80 if (ls_mem->nhtype == SRV6_NHTYPE_IPV4)
81 s = format (s, ", NHType IPv4");
82 else if (ls_mem->nhtype == SRV6_NHTYPE_IPV6)
83 s = format (s, ", NHType IPv6");
84 else if (ls_mem->nhtype == SRV6_NHTYPE_NON_IP)
85 s = format (s, ", NHType Non-IP");
87 s = format (s, ", NHType Unknow(%d)", ls_mem->nhtype);
90 s = format (s, " FIB table %d", ls_mem->fib_table);
92 s = format (s, " Drop In %d", ls_mem->drop_in);
98 alloc_param_srv6_end_m_gtp6_d (void **plugin_mem_p, const void *sr_prefix,
99 const u32 sr_prefixlen, const u8 nhtype,
100 const bool drop_in, const u32 fib_table)
102 srv6_end_gtp6_d_param_t *ls_mem;
103 ls_mem = clib_mem_alloc (sizeof *ls_mem);
104 clib_memset (ls_mem, 0, sizeof *ls_mem);
105 *plugin_mem_p = ls_mem;
107 ls_mem->sr_prefixlen = sr_prefixlen;
108 memcpy (&ls_mem->sr_prefix, sr_prefix, sizeof (ip6_address_t));
109 ls_mem->nhtype = nhtype;
110 ls_mem->drop_in = drop_in;
111 ls_mem->fib_table = fib_table;
112 ls_mem->fib4_index = ip4_fib_index_from_table_id (fib_table);
113 ls_mem->fib6_index = ip6_fib_index_from_table_id (fib_table);
117 clb_unformat_srv6_end_m_gtp6_d (unformat_input_t * input, va_list * args)
119 void **plugin_mem_p = va_arg (*args, void **);
120 ip6_address_t sr_prefix;
122 u8 nhtype = SRV6_NHTYPE_NONE;
123 bool drop_in = false;
127 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
129 if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv4 fib-table %d",
130 unformat_ip6_address, &sr_prefix, &sr_prefixlen,
134 nhtype = SRV6_NHTYPE_IPV4;
136 else if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv6 fib-table %d",
137 unformat_ip6_address, &sr_prefix, &sr_prefixlen,
141 nhtype = SRV6_NHTYPE_IPV6;
143 else if (unformat (input, "end.m.gtp6.d %U/%d nh-type none",
144 unformat_ip6_address, &sr_prefix, &sr_prefixlen))
147 nhtype = SRV6_NHTYPE_NON_IP;
149 else if (unformat (input, "end.m.gtp6.d %U/%d fib-table %d",
150 unformat_ip6_address, &sr_prefix, &sr_prefixlen,
154 nhtype = SRV6_NHTYPE_NONE;
156 else if (unformat (input, "drop-in"))
171 alloc_param_srv6_end_m_gtp6_d (plugin_mem_p, &sr_prefix, sr_prefixlen,
172 nhtype, drop_in, fib_table);
178 clb_creation_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid)
184 clb_creation_srv6_end_m_gtp6_d_2 (ip6_sr_policy_t *sr_policy)
190 clb_removal_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid)
192 srv6_end_gtp6_d_param_t *ls_mem;
194 ls_mem = localsid->plugin_mem;
196 clib_mem_free (ls_mem);
202 clb_removal_srv6_end_m_gtp6_d_2 (ip6_sr_policy_t *sr_policy)
204 srv6_end_gtp6_d_param_t *ls_mem;
206 ls_mem = sr_policy->plugin_mem;
208 clib_mem_free (ls_mem);
213 static clib_error_t *
214 srv6_end_m_gtp6_d_init (vlib_main_t * vm)
216 srv6_end_main_v6_decap_t *sm = &srv6_end_main_v6_decap;
223 sm->vnet_main = vnet_get_main ();
225 node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-d");
226 sm->end_m_gtp6_d_node_index = node->index;
228 node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
229 sm->error_node_index = node->index;
231 ip6 = &sm->cache_hdr;
233 clib_memset_u8 (ip6, 0, sizeof (ip6_header_t));
235 // IPv6 header (default)
236 ip6->ip_version_traffic_class_and_flow_label = 0x60;
238 ip6->protocol = IP_PROTOCOL_IPV6;
240 dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
242 rc = sr_localsid_register_function (vm, fn_name, keyword_str, def_str, param_str, 128, //prefix len
244 clb_format_srv6_end_m_gtp6_d,
245 clb_unformat_srv6_end_m_gtp6_d,
246 clb_creation_srv6_end_m_gtp6_d,
247 clb_removal_srv6_end_m_gtp6_d);
249 clib_error_return (0, "SRv6 Endpoint GTP6.D LocalSID function"
250 "couldn't be registered");
252 rc = sr_policy_register_function (
253 vm, fn_name, keyword_str, def_str, param_str, 128, // prefix len
254 &dpo_type, clb_format_srv6_end_m_gtp6_d, clb_unformat_srv6_end_m_gtp6_d,
255 clb_creation_srv6_end_m_gtp6_d_2, clb_removal_srv6_end_m_gtp6_d_2);
257 clib_error_return (0, "SRv6 GTP6.D Steering function"
258 "couldn't be registered");
263 VNET_FEATURE_INIT (srv6_end_m_gtp6_d, static) =
265 .arc_name = "ip6-unicast",
266 .node_name = "srv6-end-m-gtp6-d",
270 VLIB_INIT_FUNCTION (srv6_end_m_gtp6_d_init);
273 * fd.io coding-style-patch-verification: ON
276 * eval: (c-set-style "gnu")