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_t_main_v4_decap_t srv6_t_main_v4_decap;
27 clb_dpo_lock_srv6_t_m_gtp4_d (dpo_id_t * dpo)
32 clb_dpo_unlock_srv6_t_m_gtp4_d (dpo_id_t * dpo)
37 clb_dpo_format_srv6_t_m_gtp4_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_t_m_gtp4_d,
47 .dv_unlock = clb_dpo_unlock_srv6_t_m_gtp4_d,
48 .dv_format = clb_dpo_format_srv6_t_m_gtp4_d,
51 const static char *const srv6_t_m_gtp4_d_nodes[] = {
56 const static char *const srv6_t_m_gtp4_d_v6_nodes[] = {
61 const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
62 [DPO_PROTO_IP6] = srv6_t_m_gtp4_d_v6_nodes,
63 [DPO_PROTO_IP4] = srv6_t_m_gtp4_d_nodes,
66 static u8 fn_name[] = "SRv6-T.M.GTP4.D-plugin";
67 static u8 keyword_str[] = "t.m.gtp4.d";
69 "Transit function with decapsulation for IPv4/GTP tunnel";
70 static u8 param_str[] =
71 "<sr-prefix>/<sr-prefixlen> v6src_prefix <v6src_prefix>/<prefixlen> [nhtype "
72 "<nhtype>] fib-table <id>";
75 clb_format_srv6_t_m_gtp4_d (u8 * s, va_list * args)
77 srv6_end_gtp4_d_param_t *ls_mem = va_arg (*args, void *);
79 s = format (s, "SRv6 T.M.GTP4.D\n\t");
82 format (s, "SR Prefix: %U/%d, ", format_ip6_address, &ls_mem->sr_prefix,
83 ls_mem->sr_prefixlen);
86 format (s, "v6src Prefix: %U/%d", format_ip6_address,
87 &ls_mem->v6src_prefix, ls_mem->v6src_prefixlen);
89 if (ls_mem->nhtype != SRV6_NHTYPE_NONE)
91 if (ls_mem->nhtype == SRV6_NHTYPE_IPV4)
92 s = format (s, ", NHType IPv4");
93 else if (ls_mem->nhtype == SRV6_NHTYPE_IPV6)
94 s = format (s, ", NHType IPv6");
95 else if (ls_mem->nhtype == SRV6_NHTYPE_NON_IP)
96 s = format (s, ", NHType Non-IP");
98 s = format (s, ", NHType Unknow(%d)", ls_mem->nhtype);
101 s = format (s, ", FIB table %d", ls_mem->fib_table);
103 s = format (s, ", Drop In %d\n", ls_mem->drop_in);
109 clb_unformat_srv6_t_m_gtp4_d (unformat_input_t * input, va_list * args)
111 void **plugin_mem_p = va_arg (*args, void **);
112 srv6_end_gtp4_d_param_t *ls_mem;
113 ip6_address_t sr_prefix;
115 ip6_address_t v6src_prefix;
118 bool drop_in = false;
119 u8 nhtype = SRV6_NHTYPE_NONE;
122 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
126 "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype ipv4 fib-table %d",
127 unformat_ip6_address, &sr_prefix, &sr_prefixlen,
128 unformat_ip6_address, &v6src_prefix, &v6src_prefixlen, &fib_table))
131 nhtype = SRV6_NHTYPE_IPV4;
133 else if (unformat (input,
134 "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype ipv6 "
136 unformat_ip6_address, &sr_prefix, &sr_prefixlen,
137 unformat_ip6_address, &v6src_prefix, &v6src_prefixlen,
141 nhtype = SRV6_NHTYPE_IPV6;
144 input, "t.m.gtp4.d %U/%d v6src_prefix %U/%d nhtype non-ip",
145 unformat_ip6_address, &sr_prefix, &sr_prefixlen,
146 unformat_ip6_address, &v6src_prefix, &v6src_prefixlen))
149 nhtype = SRV6_NHTYPE_NON_IP;
151 else if (unformat (input,
152 "t.m.gtp4.d %U/%d v6src_prefix %U/%d fib-table %d",
153 unformat_ip6_address, &sr_prefix, &sr_prefixlen,
154 unformat_ip6_address, &v6src_prefix, &v6src_prefixlen,
158 nhtype = SRV6_NHTYPE_NONE;
160 else if (unformat (input, "drop-in"))
175 ls_mem = clib_mem_alloc (sizeof *ls_mem);
176 clib_memset (ls_mem, 0, sizeof *ls_mem);
177 *plugin_mem_p = ls_mem;
179 ls_mem->sr_prefix = sr_prefix;
180 ls_mem->sr_prefixlen = sr_prefixlen;
182 ls_mem->v6src_prefix = v6src_prefix;
183 ls_mem->v6src_prefixlen = v6src_prefixlen;
185 ls_mem->nhtype = nhtype;
187 ls_mem->drop_in = drop_in;
189 ls_mem->fib_table = fib_table;
190 ls_mem->fib4_index = ip4_fib_index_from_table_id (fib_table);
191 ls_mem->fib6_index = ip6_fib_index_from_table_id (fib_table);
197 clb_creation_srv6_t_m_gtp4_d (ip6_sr_policy_t * sr_policy)
203 clb_removal_srv6_t_m_gtp4_d (ip6_sr_policy_t * sr_policy)
205 srv6_end_gtp4_d_param_t *ls_mem;
207 ls_mem = (srv6_end_gtp4_d_param_t *) sr_policy->plugin_mem;
209 clib_mem_free (ls_mem);
214 static clib_error_t *
215 srv6_t_m_gtp4_d_init (vlib_main_t * vm)
217 srv6_t_main_v4_decap_t *sm = &srv6_t_main_v4_decap;
224 sm->vnet_main = vnet_get_main ();
226 node = vlib_get_node_by_name (vm, (u8 *) "srv6-t-m-gtp4-d");
227 sm->t_m_gtp4_d_node_index = node->index;
229 node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
230 sm->error_node_index = node->index;
232 ip6 = &sm->cache_hdr;
234 clib_memset_u8 (ip6, 0, sizeof (ip6_header_t));
236 // IPv6 header (default)
237 ip6->ip_version_traffic_class_and_flow_label = 0x60;
239 ip6->protocol = IP_PROTOCOL_IPV6;
241 dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
243 rc = sr_policy_register_function (vm, fn_name, keyword_str, def_str, param_str, 128, //prefix len
245 clb_format_srv6_t_m_gtp4_d,
246 clb_unformat_srv6_t_m_gtp4_d,
247 clb_creation_srv6_t_m_gtp4_d,
248 clb_removal_srv6_t_m_gtp4_d);
250 clib_error_return (0, "SRv6 Transit GTP4.D Policy function"
251 "couldn't be registered");
256 VNET_FEATURE_INIT (srv6_t_m_gtp4_d, static) =
258 .arc_name = "ip4-unicast",
259 .node_name = "srv6-t-m-gtp4-d",
263 VLIB_INIT_FUNCTION (srv6_t_m_gtp4_d_init);
267 * fd.io coding-style-patch-verification: ON
270 * eval: (c-set-style "gnu")