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_t srv6_end_main_v6;
27 clb_dpo_lock_srv6_end_m_gtp6_e (dpo_id_t * dpo)
32 clb_dpo_unlock_srv6_end_m_gtp6_e (dpo_id_t * dpo)
37 clb_dpo_format_srv6_end_m_gtp6_e (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_e,
47 .dv_unlock = clb_dpo_unlock_srv6_end_m_gtp6_e,
48 .dv_format = clb_dpo_format_srv6_end_m_gtp6_e,
51 const static char *const srv6_end_m_gtp6_e_nodes[] = {
56 const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
57 [DPO_PROTO_IP6] = srv6_end_m_gtp6_e_nodes,
60 static u8 fn_name[] = "SRv6-End.M.GTP6.E-plugin";
61 static u8 keyword_str[] = "end.m.gtp6.e";
63 "Endpoint function with encapsulation for IPv6/GTP tunnel";
64 static u8 param_str[] = "";
67 clb_format_srv6_end_m_gtp6_e (u8 * s, va_list * args)
69 srv6_end_gtp6_e_param_t *ls_mem = va_arg (*args, void *);
72 s = format (s, "SRv6 End.M.GTP6.E function.");
74 s = format (s, "\tFib Table %d\n", ls_mem->fib_table);
80 alloc_param_srv6_end_m_gtp6_e (void **plugin_mem_p, const u32 fib_table)
82 srv6_end_gtp6_e_param_t *ls_mem;
83 ls_mem = clib_mem_alloc (sizeof *ls_mem);
84 clib_memset (ls_mem, 0, sizeof *ls_mem);
85 *plugin_mem_p = ls_mem;
87 ls_mem->fib_table = fib_table;
88 ls_mem->fib4_index = ip4_fib_index_from_table_id (fib_table);
89 ls_mem->fib6_index = ip6_fib_index_from_table_id (fib_table);
93 clb_unformat_srv6_end_m_gtp6_e (unformat_input_t *input, va_list *args)
95 void **plugin_mem_p = va_arg (*args, void **);
98 if (!unformat (input, "end.m.gtp6.e fib-table %d", &fib_table))
101 alloc_param_srv6_end_m_gtp6_e (plugin_mem_p, fib_table);
107 clb_creation_srv6_end_m_gtp6_e (ip6_sr_localsid_t * localsid)
113 clb_removal_srv6_end_m_gtp6_e (ip6_sr_localsid_t * localsid)
115 srv6_end_gtp6_e_param_t *ls_mem;
117 ls_mem = localsid->plugin_mem;
119 clib_mem_free (ls_mem);
124 static clib_error_t *
125 srv6_end_m_gtp6_e_init (vlib_main_t * vm)
127 srv6_end_main_v6_t *sm = &srv6_end_main_v6;
128 ip6_header_t *ip6 = &sm->cache_hdr.ip6;
129 udp_header_t *udp = &sm->cache_hdr.udp;
130 gtpu_header_t *gtpu = &sm->cache_hdr.gtpu;
136 sm->vnet_main = vnet_get_main ();
138 node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-e");
139 sm->end_m_gtp6_e_node_index = node->index;
141 node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
142 sm->error_node_index = node->index;
144 // clear the pre cached packet
145 clib_memset_u8 (ip6, 0, sizeof (ip6_gtpu_header_t));
148 ip6->ip_version_traffic_class_and_flow_label = 0x60;
149 ip6->protocol = IP_PROTOCOL_UDP;
152 udp->dst_port = clib_host_to_net_u16 (SRV6_GTP_UDP_DST_PORT);
154 gtpu->ver_flags = GTPU_V1_VER | GTPU_PT_GTP;
155 gtpu->type = GTPU_TYPE_GTPU;
157 dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
159 rc = sr_localsid_register_function (vm, fn_name, keyword_str, def_str, param_str, 128, //prefix len
161 clb_format_srv6_end_m_gtp6_e,
162 clb_unformat_srv6_end_m_gtp6_e,
163 clb_creation_srv6_end_m_gtp6_e,
164 clb_removal_srv6_end_m_gtp6_e);
166 clib_error_return (0, "SRv6 Endpoint GTP6.E LocalSID function"
167 "couldn't be registered");
172 VNET_FEATURE_INIT (srv6_end_m_gtp6_e, static) =
174 .arc_name = "ip6-unicast",
175 .node_name = "srv6-end-m-gtp6-e",
179 VLIB_INIT_FUNCTION (srv6_end_m_gtp6_e_init);
183 * fd.io coding-style-patch-verification: ON
186 * eval: (c-set-style "gnu")