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[] = "<sr-prefix>/<sr-prefixlen> [nhtype <nhtype>]";
67 clb_format_srv6_end_m_gtp6_d (u8 * s, va_list * args)
69 srv6_end_gtp6_param_t *ls_mem = va_arg (*args, void *);
71 s = format (s, "SRv6 End gtp6.d\n\t");
74 format (s, "SR Prefix: %U/%d", format_ip6_address, &ls_mem->sr_prefix,
75 ls_mem->sr_prefixlen);
77 if (ls_mem->nhtype != SRV6_NHTYPE_NONE)
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");
86 s = format (s, ", NHType Unknow(%d)\n", ls_mem->nhtype);
95 clb_unformat_srv6_end_m_gtp6_d (unformat_input_t * input, va_list * args)
97 void **plugin_mem_p = va_arg (*args, void **);
98 srv6_end_gtp6_param_t *ls_mem;
99 ip6_address_t sr_prefix;
103 if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv4",
104 unformat_ip6_address, &sr_prefix, &sr_prefixlen))
106 nhtype = SRV6_NHTYPE_IPV4;
108 else if (unformat (input, "end.m.gtp6.d %U/%d nh-type ipv6",
109 unformat_ip6_address, &sr_prefix, &sr_prefixlen))
111 nhtype = SRV6_NHTYPE_IPV6;
113 else if (unformat (input, "end.m.gtp6.d %U/%d nh-type none",
114 unformat_ip6_address, &sr_prefix, &sr_prefixlen))
116 nhtype = SRV6_NHTYPE_NON_IP;
118 else if (unformat (input, "end.m.gtp6.d %U/%d",
119 unformat_ip6_address, &sr_prefix, &sr_prefixlen))
121 nhtype = SRV6_NHTYPE_NONE;
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;
132 ls_mem->sr_prefix = sr_prefix;
133 ls_mem->sr_prefixlen = sr_prefixlen;
135 ls_mem->nhtype = nhtype;
141 clb_creation_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid)
147 clb_removal_srv6_end_m_gtp6_d (ip6_sr_localsid_t * localsid)
149 srv6_end_gtp6_param_t *ls_mem;
151 ls_mem = localsid->plugin_mem;
153 clib_mem_free (ls_mem);
158 static clib_error_t *
159 srv6_end_m_gtp6_d_init (vlib_main_t * vm)
161 srv6_end_main_v6_decap_t *sm = &srv6_end_main_v6_decap;
168 sm->vnet_main = vnet_get_main ();
170 node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-d");
171 sm->end_m_gtp6_d_node_index = node->index;
173 node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
174 sm->error_node_index = node->index;
176 ip6 = &sm->cache_hdr;
178 clib_memset_u8 (ip6, 0, sizeof (ip6_header_t));
180 // IPv6 header (default)
181 ip6->ip_version_traffic_class_and_flow_label = 0x60;
183 ip6->protocol = IP_PROTOCOL_IPV6;
185 dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
187 rc = sr_localsid_register_function (vm, fn_name, keyword_str, def_str, param_str, 128, //prefix len
189 clb_format_srv6_end_m_gtp6_d,
190 clb_unformat_srv6_end_m_gtp6_d,
191 clb_creation_srv6_end_m_gtp6_d,
192 clb_removal_srv6_end_m_gtp6_d);
194 clib_error_return (0, "SRv6 Endpoint GTP6.D LocalSID function"
195 "couldn't be registered");
200 VNET_FEATURE_INIT (srv6_end_m_gtp6_d, static) =
202 .arc_name = "ip6-unicast",
203 .node_name = "srv6-end-m-gtp6-d",
207 VLIB_INIT_FUNCTION (srv6_end_m_gtp6_d_init);
211 * fd.io coding-style-patch-verification: ON
214 * eval: (c-set-style "gnu")