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_v4_t srv6_end_main_v4;
27 clb_dpo_lock_srv6_end_m_gtp4_e (dpo_id_t * dpo)
32 clb_dpo_unlock_srv6_end_m_gtp4_e (dpo_id_t * dpo)
37 clb_dpo_format_srv6_end_m_gtp4_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_gtp4_e,
47 .dv_unlock = clb_dpo_unlock_srv6_end_m_gtp4_e,
48 .dv_format = clb_dpo_format_srv6_end_m_gtp4_e,
51 const static char *const srv6_end_m_gtp4_e_nodes[] = {
56 const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
57 [DPO_PROTO_IP6] = srv6_end_m_gtp4_e_nodes,
60 static u8 fn_name[] = "SRv6-End.M.GTP4.E-plugin";
61 static u8 keyword_str[] = "end.m.gtp4.e";
63 "Endpoint function with encapsulation for IPv4/GTP tunnel";
64 static u8 param_str[] = "";
67 clb_format_srv6_end_m_gtp4_e (u8 * s, va_list * args)
69 srv6_end_gtp4_param_t *ls_mem = va_arg (*args, void *);
71 s = format (s, "SRv6 End gtp4.e\n\t");
73 s = format (s, "IPv4 address position: %d\n", ls_mem->v4src_position);
79 clb_unformat_srv6_end_m_gtp4_e (unformat_input_t * input, va_list * args)
81 void **plugin_mem_p = va_arg (*args, void **);
82 srv6_end_gtp4_param_t *ls_mem;
85 if (!unformat (input, "end.m.gtp4.e v4src_position %d", &v4src_position))
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;
92 ls_mem->v4src_position = v4src_position;
98 clb_creation_srv6_end_m_gtp4_e (ip6_sr_localsid_t * localsid)
104 clb_removal_srv6_end_m_gtp4_e (ip6_sr_localsid_t * localsid)
106 srv6_end_gtp4_param_t *ls_mem;
108 ls_mem = localsid->plugin_mem;
110 clib_mem_free (ls_mem);
115 static clib_error_t *
116 srv6_end_m_gtp4_e_init (vlib_main_t * vm)
118 srv6_end_main_v4_t *sm = &srv6_end_main_v4;
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;
127 sm->vnet_main = vnet_get_main ();
129 node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp4-e");
130 sm->end_m_gtp4_e_node_index = node->index;
132 node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
133 sm->error_node_index = node->index;
138 // clear the pre cached packet
139 clib_memset_u8 (ip4, 0, sizeof (ip4_gtpu_header_t));
142 ip4->ip_version_and_header_length = 0x45;
143 ip4->protocol = IP_PROTOCOL_UDP;
146 udp->dst_port = clib_host_to_net_u16 (SRV6_GTP_UDP_DST_PORT);
148 gtpu->ver_flags = GTPU_V1_VER | GTPU_PT_GTP;
149 gtpu->type = GTPU_TYPE_GTPU;
152 dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
154 rc = sr_localsid_register_function (vm, fn_name, keyword_str, def_str, param_str, 32, //prefix len
156 clb_format_srv6_end_m_gtp4_e,
157 clb_unformat_srv6_end_m_gtp4_e,
158 clb_creation_srv6_end_m_gtp4_e,
159 clb_removal_srv6_end_m_gtp4_e);
161 clib_error_return (0, "SRv6 Endpoint GTP4.E LocalSID function"
162 "couldn't be registered");
167 VNET_FEATURE_INIT (srv6_end_m_gtp4_e, static) =
169 .arc_name = "ip6-unicast",
170 .node_name = "srv6-end-m-gtp4-e",
174 VLIB_INIT_FUNCTION (srv6_end_m_gtp4_e_init);
176 VLIB_PLUGIN_REGISTER () = {
177 .version = VPP_BUILD_VER,
178 .description = "SRv6 GTP Endpoint Functions",
183 * fd.io coding-style-patch-verification: ON
186 * eval: (c-set-style "gnu")