blob: 5a5262ea9dba07334ba337bec755711bfe5430f1 [file] [log] [blame]
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070015/**
16 * @file
17 * @brief Common utility functions for IPv4 and IPv6 VXLAN GPE tunnels
18 *
19*/
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070020#include <vnet/vxlan-gpe/vxlan_gpe.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010021#include <vnet/fib/fib.h>
Hongjun Nidf921cc2016-05-25 01:16:19 +080022#include <vnet/ip/format.h>
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +080023#include <vnet/fib/fib_entry.h>
24#include <vnet/fib/fib_table.h>
Neale Ranns1f50bf82019-07-16 15:28:52 +000025#include <vnet/fib/fib_entry_track.h>
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +080026#include <vnet/mfib/mfib_table.h>
27#include <vnet/adj/adj_mcast.h>
28#include <vnet/interface.h>
Florin Corasb040f982020-10-20 14:59:43 -070029#include <vnet/udp/udp_local.h>
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +080030#include <vlib/vlib.h>
31
32/**
33 * @file
34 * @brief VXLAN-GPE.
35 *
36 * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
37 * to span multiple servers. This is done by building an L2 overlay on
38 * top of an L3 network underlay using VXLAN-GPE tunnels.
39 *
40 * This makes it possible for servers to be co-located in the same data
41 * center or be separated geographically as long as they are reachable
42 * through the underlay L3 network.
43 *
44 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
45 */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070046
47vxlan_gpe_main_t vxlan_gpe_main;
48
John Lo4478d8e2018-01-12 17:15:25 -050049static u8 *
50format_decap_next (u8 * s, va_list * args)
51{
52 vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
53
54 switch (t->protocol)
55 {
56 case VXLAN_GPE_PROTOCOL_IP4:
57 s = format (s, "protocol ip4 fib-idx %d", t->decap_fib_index);
58 break;
59 case VXLAN_GPE_PROTOCOL_IP6:
60 s = format (s, "protocol ip6 fib-idx %d", t->decap_fib_index);
61 break;
62 case VXLAN_GPE_PROTOCOL_ETHERNET:
63 s = format (s, "protocol ethernet");
64 break;
65 case VXLAN_GPE_PROTOCOL_NSH:
66 s = format (s, "protocol nsh");
67 break;
68 default:
69 s = format (s, "protocol unknown %d", t->protocol);
70 }
71
72 return s;
73}
74
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070075/**
John Lo4478d8e2018-01-12 17:15:25 -050076 * @brief Format function for VXLAN GPE tunnel
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070077 *
78 * @param *s formatting string
79 * @param *args
80 *
81 * @return *s formatted string
82 *
83 */
sharath reddy6f8273a2017-12-11 11:31:31 +053084u8 *
85format_vxlan_gpe_tunnel (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070086{
sharath reddy6f8273a2017-12-11 11:31:31 +053087 vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
88 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070089
Artem Glazychevea962922021-05-28 19:09:14 +070090 s = format (s,
91 "[%d] lcl %U rmt %U lcl_port %d rmt_port %d vni %d "
92 "fib-idx %d sw-if-idx %d ",
93 t - ngm->tunnels, format_ip46_address, &t->local, IP46_TYPE_ANY,
94 format_ip46_address, &t->remote, IP46_TYPE_ANY, t->local_port,
95 t->remote_port, t->vni, t->encap_fib_index, t->sw_if_index);
Hongjun Nidf921cc2016-05-25 01:16:19 +080096
John Lo4478d8e2018-01-12 17:15:25 -050097#if 0
98 /* next_dpo not yet used by vxlan-gpe-encap node */
99 s = format (s, "encap-dpo-idx %d ", t->next_dpo.dpoi_index);
100 */
101#endif
102 s = format (s, "decap-next-%U ", format_decap_next, t);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700103
John Lo4478d8e2018-01-12 17:15:25 -0500104 if (PREDICT_FALSE (ip46_address_is_multicast (&t->remote)))
105 s = format (s, "mcast-sw-if-idx %d ", t->mcast_sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700106
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700107 return s;
108}
109
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700110/**
111 * @brief Naming for VXLAN GPE tunnel
112 *
113 * @param *s formatting string
114 * @param *args
115 *
116 * @return *s formatted string
117 *
118 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530119static u8 *
120format_vxlan_gpe_name (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700121{
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800122 u32 dev_instance = va_arg (*args, u32);
123 return format (s, "vxlan_gpe_tunnel%d", dev_instance);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700124}
125
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700126/**
127 * @brief CLI function for VXLAN GPE admin up/down
128 *
129 * @param *vnm
130 * @param hw_if_index
131 * @param flag
132 *
133 * @return *rc
134 *
135 */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800136static clib_error_t *
sharath reddy6f8273a2017-12-11 11:31:31 +0530137vxlan_gpe_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
138 u32 flags)
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800139{
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800140 u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
141 VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
142 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800143
144 return 0;
145}
146
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800147VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
148 .name = "VXLAN_GPE",
149 .format_device_name = format_vxlan_gpe_name,
150 .format_tx_trace = format_vxlan_gpe_encap_trace,
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800151 .admin_up_down_function = vxlan_gpe_interface_admin_up_down,
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800152};
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700153
Vengada Govindan6d403a02016-10-12 05:54:09 -0700154
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700155/**
156 * @brief Formatting function for tracing VXLAN GPE with length
157 *
158 * @param *s
159 * @param *args
160 *
161 * @return *s
162 *
163 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530164static u8 *
165format_vxlan_gpe_header_with_length (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700166{
167 u32 dev_instance = va_arg (*args, u32);
168 s = format (s, "unimplemented dev %u", dev_instance);
169 return s;
170}
171
172VNET_HW_INTERFACE_CLASS (vxlan_gpe_hw_class) = {
173 .name = "VXLAN_GPE",
174 .format_header = format_vxlan_gpe_header_with_length,
Neale Rannsb80c5362016-10-08 13:03:40 +0100175 .build_rewrite = default_build_rewrite,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700176};
177
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800178static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530179vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_t * t)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800180{
sharath reddy6f8273a2017-12-11 11:31:31 +0530181 dpo_id_t dpo = DPO_INVALID;
182 u32 encap_index = vxlan_gpe_encap_node.index;
183 fib_forward_chain_type_t forw_type = ip46_address_is_ip4 (&t->remote) ?
184 FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800185
sharath reddy6f8273a2017-12-11 11:31:31 +0530186 fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
187 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
188 dpo_reset (&dpo);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800189}
190
191static vxlan_gpe_tunnel_t *
sharath reddy6f8273a2017-12-11 11:31:31 +0530192vxlan_gpe_tunnel_from_fib_node (fib_node_t * node)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800193{
sharath reddy6f8273a2017-12-11 11:31:31 +0530194 ASSERT (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL == node->fn_type);
195 return ((vxlan_gpe_tunnel_t *) (((char *) node) -
196 STRUCT_OFFSET_OF (vxlan_gpe_tunnel_t,
197 node)));
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800198}
199
200/**
201 * Function definition to backwalk a FIB node -
202 * Here we will restack the new dpo of VXLAN_GPE DIP to encap node.
203 */
204static fib_node_back_walk_rc_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530205vxlan_gpe_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800206{
sharath reddy6f8273a2017-12-11 11:31:31 +0530207 vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_from_fib_node (node));
208 return (FIB_NODE_BACK_WALK_CONTINUE);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800209}
210
211/**
212 * Function definition to get a FIB node from its index
213 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530214static fib_node_t *
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800215vxlan_gpe_tunnel_fib_node_get (fib_node_index_t index)
216{
sharath reddy6f8273a2017-12-11 11:31:31 +0530217 vxlan_gpe_tunnel_t *t;
218 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800219
sharath reddy6f8273a2017-12-11 11:31:31 +0530220 t = pool_elt_at_index (ngm->tunnels, index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800221
sharath reddy6f8273a2017-12-11 11:31:31 +0530222 return (&t->node);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800223}
224
225/**
226 * Function definition to inform the FIB node that its last lock has gone.
227 */
228static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530229vxlan_gpe_tunnel_last_lock_gone (fib_node_t * node)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800230{
sharath reddy6f8273a2017-12-11 11:31:31 +0530231 /*
232 * The VXLAN_GPE tunnel is a root of the graph. As such
233 * it never has children and thus is never locked.
234 */
235 ASSERT (0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800236}
237
238/*
239 * Virtual function table registered by VXLAN_GPE tunnels
240 * for participation in the FIB object graph.
241 */
242const static fib_node_vft_t vxlan_gpe_vft = {
sharath reddy6f8273a2017-12-11 11:31:31 +0530243 .fnv_get = vxlan_gpe_tunnel_fib_node_get,
244 .fnv_last_lock = vxlan_gpe_tunnel_last_lock_gone,
245 .fnv_back_walk = vxlan_gpe_tunnel_back_walk,
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800246};
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700247
Artem Glazychevea962922021-05-28 19:09:14 +0700248#define foreach_gpe_copy_field \
249 _ (vni) \
250 _ (protocol) \
251 _ (mcast_sw_if_index) \
252 _ (encap_fib_index) \
253 _ (decap_fib_index) \
254 _ (local_port) \
255 _ (remote_port)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700256
Hongjun Nidf921cc2016-05-25 01:16:19 +0800257#define foreach_copy_ipv4 { \
258 _(local.ip4.as_u32) \
259 _(remote.ip4.as_u32) \
260}
261
262#define foreach_copy_ipv6 { \
263 _(local.ip6.as_u64[0]) \
264 _(local.ip6.as_u64[1]) \
265 _(remote.ip6.as_u64[0]) \
266 _(remote.ip6.as_u64[1]) \
267}
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700268
269
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700270/**
271 * @brief Calculate IPv4 VXLAN GPE rewrite header
272 *
273 * @param *t
274 *
275 * @return rc
276 *
277 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530278int
279vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
280 u8 protocol_override, uword encap_next_node)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700281{
282 u8 *rw = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530283 ip4_header_t *ip0;
284 ip4_vxlan_gpe_header_t *h0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700285 int len;
286
Vengada Govindan6d403a02016-10-12 05:54:09 -0700287 len = sizeof (*h0) + extension_size;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700288
sharath reddy6f8273a2017-12-11 11:31:31 +0530289 vec_free (t->rewrite);
290 vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700291
292 h0 = (ip4_vxlan_gpe_header_t *) rw;
293
294 /* Fixed portion of the (outer) ip4 header */
295 ip0 = &h0->ip4;
296 ip0->ip_version_and_header_length = 0x45;
297 ip0->ttl = 254;
298 ip0->protocol = IP_PROTOCOL_UDP;
299
300 /* we fix up the ip4 header length and checksum after-the-fact */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800301 ip0->src_address.as_u32 = t->local.ip4.as_u32;
302 ip0->dst_address.as_u32 = t->remote.ip4.as_u32;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700303 ip0->checksum = ip4_header_checksum (ip0);
304
305 /* UDP header, randomize src port on something, maybe? */
Artem Glazychevea962922021-05-28 19:09:14 +0700306 h0->udp.src_port = clib_host_to_net_u16 (t->local_port);
307 h0->udp.dst_port = clib_host_to_net_u16 (t->remote_port);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700308
309 /* VXLAN header. Are we having fun yet? */
310 h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
311 h0->vxlan.ver_res = VXLAN_GPE_VERSION;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700312 if (protocol_override)
sharath reddy6f8273a2017-12-11 11:31:31 +0530313 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700314 h0->vxlan.protocol = protocol_override;
sharath reddy6f8273a2017-12-11 11:31:31 +0530315 }
Vengada Govindan6d403a02016-10-12 05:54:09 -0700316 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530317 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700318 h0->vxlan.protocol = t->protocol;
sharath reddy6f8273a2017-12-11 11:31:31 +0530319 }
320 t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
321 h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700322
323 t->rewrite = rw;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700324 t->encap_next_node = encap_next_node;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700325 return (0);
326}
327
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700328/**
329 * @brief Calculate IPv6 VXLAN GPE rewrite header
330 *
331 * @param *t
332 *
333 * @return rc
334 *
335 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530336int
337vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
338 u8 protocol_override, uword encap_next_node)
Hongjun Nidf921cc2016-05-25 01:16:19 +0800339{
340 u8 *rw = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530341 ip6_header_t *ip0;
342 ip6_vxlan_gpe_header_t *h0;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800343 int len;
344
Vengada Govindan6d403a02016-10-12 05:54:09 -0700345 len = sizeof (*h0) + extension_size;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800346
sharath reddy6f8273a2017-12-11 11:31:31 +0530347 vec_free (t->rewrite);
348 vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800349
350 h0 = (ip6_vxlan_gpe_header_t *) rw;
351
352 /* Fixed portion of the (outer) ip4 header */
353 ip0 = &h0->ip6;
sharath reddy6f8273a2017-12-11 11:31:31 +0530354 ip0->ip_version_traffic_class_and_flow_label =
355 clib_host_to_net_u32 (6 << 28);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800356 ip0->hop_limit = 255;
357 ip0->protocol = IP_PROTOCOL_UDP;
358
359 ip0->src_address.as_u64[0] = t->local.ip6.as_u64[0];
360 ip0->src_address.as_u64[1] = t->local.ip6.as_u64[1];
361 ip0->dst_address.as_u64[0] = t->remote.ip6.as_u64[0];
362 ip0->dst_address.as_u64[1] = t->remote.ip6.as_u64[1];
363
364 /* UDP header, randomize src port on something, maybe? */
Artem Glazychevea962922021-05-28 19:09:14 +0700365 h0->udp.src_port = clib_host_to_net_u16 (t->local_port);
366 h0->udp.dst_port = clib_host_to_net_u16 (t->remote_port);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800367
368 /* VXLAN header. Are we having fun yet? */
369 h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
370 h0->vxlan.ver_res = VXLAN_GPE_VERSION;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700371 if (protocol_override)
sharath reddy6f8273a2017-12-11 11:31:31 +0530372 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700373 h0->vxlan.protocol = t->protocol;
sharath reddy6f8273a2017-12-11 11:31:31 +0530374 }
Vengada Govindan6d403a02016-10-12 05:54:09 -0700375 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530376 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700377 h0->vxlan.protocol = protocol_override;
sharath reddy6f8273a2017-12-11 11:31:31 +0530378 }
379 t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
380 h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800381
382 t->rewrite = rw;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700383 t->encap_next_node = encap_next_node;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800384 return (0);
385}
386
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800387typedef CLIB_PACKED(union {
388 struct {
389 fib_node_index_t mfib_entry_index;
390 adj_index_t mcast_adj_index;
391 };
392 u64 as_u64;
393}) mcast_shared_t;
394
395static inline mcast_shared_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530396mcast_shared_get (ip46_address_t * ip)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800397{
sharath reddy6f8273a2017-12-11 11:31:31 +0530398 ASSERT (ip46_address_is_multicast (ip));
399 uword *p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip);
Dave Barachffd15462020-02-18 10:12:23 -0500400 ALWAYS_ASSERT (p);
sharath reddy6f8273a2017-12-11 11:31:31 +0530401 return (mcast_shared_t)
402 {
403 .as_u64 = *p};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800404}
405
406static inline void
sharath reddy6f8273a2017-12-11 11:31:31 +0530407mcast_shared_add (ip46_address_t * remote,
408 fib_node_index_t mfei, adj_index_t ai)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800409{
sharath reddy6f8273a2017-12-11 11:31:31 +0530410 mcast_shared_t new_ep = {
411 .mcast_adj_index = ai,
412 .mfib_entry_index = mfei,
413 };
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800414
John Loe6bfeab2018-01-04 16:39:42 -0500415 hash_set_mem_alloc (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800416}
417
418static inline void
sharath reddy6f8273a2017-12-11 11:31:31 +0530419mcast_shared_remove (ip46_address_t * remote)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800420{
sharath reddy6f8273a2017-12-11 11:31:31 +0530421 mcast_shared_t ep = mcast_shared_get (remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800422
sharath reddy6f8273a2017-12-11 11:31:31 +0530423 adj_unlock (ep.mcast_adj_index);
424 mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_VXLAN_GPE);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800425
John Loe6bfeab2018-01-04 16:39:42 -0500426 hash_unset_mem_free (&vxlan_gpe_main.mcast_shared, remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800427}
428
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700429/**
430 * @brief Add or Del a VXLAN GPE tunnel
431 *
432 * @param *a
433 * @param *sw_if_index
434 *
435 * @return rc
436 *
437 */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800438int vnet_vxlan_gpe_add_del_tunnel
sharath reddy6f8273a2017-12-11 11:31:31 +0530439 (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700440{
sharath reddy6f8273a2017-12-11 11:31:31 +0530441 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700442 vxlan_gpe_tunnel_t *t = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530443 vnet_main_t *vnm = ngm->vnet_main;
444 vnet_hw_interface_t *hi;
445 uword *p;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700446 u32 hw_if_index = ~0;
447 u32 sw_if_index = ~0;
448 int rv;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800449 vxlan4_gpe_tunnel_key_t key4, *key4_copy;
450 vxlan6_gpe_tunnel_key_t key6, *key6_copy;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800451 u32 is_ip6 = a->is_ip6;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800452
Artem Glazychevea962922021-05-28 19:09:14 +0700453 /* Set udp-ports */
454 if (a->local_port == 0)
455 a->local_port = is_ip6 ? UDP_DST_PORT_VXLAN6_GPE : UDP_DST_PORT_VXLAN_GPE;
456
457 if (a->remote_port == 0)
458 a->remote_port = is_ip6 ? UDP_DST_PORT_VXLAN6_GPE : UDP_DST_PORT_VXLAN_GPE;
459
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800460 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530461 {
462 key4.local = a->local.ip4.as_u32;
463 key4.remote = a->remote.ip4.as_u32;
464 key4.vni = clib_host_to_net_u32 (a->vni << 8);
Artem Glazychevea962922021-05-28 19:09:14 +0700465 key4.port = (u32) clib_host_to_net_u16 (a->local_port);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700466
sharath reddy6f8273a2017-12-11 11:31:31 +0530467 p = hash_get_mem (ngm->vxlan4_gpe_tunnel_by_key, &key4);
468 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800469 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530470 {
471 key6.local.as_u64[0] = a->local.ip6.as_u64[0];
472 key6.local.as_u64[1] = a->local.ip6.as_u64[1];
473 key6.remote.as_u64[0] = a->remote.ip6.as_u64[0];
474 key6.remote.as_u64[1] = a->remote.ip6.as_u64[1];
475 key6.vni = clib_host_to_net_u32 (a->vni << 8);
Artem Glazychevea962922021-05-28 19:09:14 +0700476 key6.port = (u32) clib_host_to_net_u16 (a->local_port);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800477
sharath reddy6f8273a2017-12-11 11:31:31 +0530478 p = hash_get_mem (ngm->vxlan6_gpe_tunnel_by_key, &key6);
479 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800480
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700481 if (a->is_add)
482 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530483 l2input_main_t *l2im = &l2input_main;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800484
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700485 /* adding a tunnel: tunnel must not already exist */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800486 if (p)
sharath reddy6f8273a2017-12-11 11:31:31 +0530487 return VNET_API_ERROR_TUNNEL_EXIST;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800488
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800489 pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
Dave Barachb7b92992018-10-17 10:38:51 -0400490 clib_memset (t, 0, sizeof (*t));
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800491
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700492 /* copy from arg structure */
493#define _(x) t->x = a->x;
494 foreach_gpe_copy_field;
sharath reddy6f8273a2017-12-11 11:31:31 +0530495 if (!a->is_ip6)
496 foreach_copy_ipv4
John Loe6bfeab2018-01-04 16:39:42 -0500497 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530498 foreach_copy_ipv6
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700499#undef _
John Loe6bfeab2018-01-04 16:39:42 -0500500
501 if (!a->is_ip6)
502 t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700503
sharath reddy6f8273a2017-12-11 11:31:31 +0530504 if (!a->is_ip6)
505 {
506 rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
507 }
508 else
509 {
510 rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
511 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700512
513 if (rv)
sharath reddy6f8273a2017-12-11 11:31:31 +0530514 {
515 pool_put (ngm->tunnels, t);
516 return rv;
517 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700518
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800519 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530520 {
521 key4_copy = clib_mem_alloc (sizeof (*key4_copy));
Dave Barach178cf492018-11-13 16:34:13 -0500522 clib_memcpy_fast (key4_copy, &key4, sizeof (*key4_copy));
sharath reddy6f8273a2017-12-11 11:31:31 +0530523 hash_set_mem (ngm->vxlan4_gpe_tunnel_by_key, key4_copy,
524 t - ngm->tunnels);
525 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800526 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530527 {
528 key6_copy = clib_mem_alloc (sizeof (*key6_copy));
Dave Barach178cf492018-11-13 16:34:13 -0500529 clib_memcpy_fast (key6_copy, &key6, sizeof (*key6_copy));
sharath reddy6f8273a2017-12-11 11:31:31 +0530530 hash_set_mem (ngm->vxlan6_gpe_tunnel_by_key, key6_copy,
531 t - ngm->tunnels);
532 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800533
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800534 if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0)
sharath reddy6f8273a2017-12-11 11:31:31 +0530535 {
536 vnet_interface_main_t *im = &vnm->interface_main;
537 hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
538 [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) - 1];
Damjan Marion8bea5892022-04-04 22:40:45 +0200539 vec_dec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices, 1);
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800540
sharath reddy6f8273a2017-12-11 11:31:31 +0530541 hi = vnet_get_hw_interface (vnm, hw_if_index);
542 hi->dev_instance = t - ngm->tunnels;
543 hi->hw_instance = hi->dev_instance;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800544 /* clear old stats of freed tunnel before reuse */
545 sw_if_index = hi->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530546 vnet_interface_counter_lock (im);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800547 vlib_zero_combined_counter
sharath reddy6f8273a2017-12-11 11:31:31 +0530548 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
549 sw_if_index);
550 vlib_zero_combined_counter (&im->combined_sw_if_counters
551 [VNET_INTERFACE_COUNTER_RX],
552 sw_if_index);
553 vlib_zero_simple_counter (&im->sw_if_counters
554 [VNET_INTERFACE_COUNTER_DROP],
555 sw_if_index);
556 vnet_interface_counter_unlock (im);
557 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800558 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530559 {
560 hw_if_index = vnet_register_interface
561 (vnm, vxlan_gpe_device_class.index, t - ngm->tunnels,
562 vxlan_gpe_hw_class.index, t - ngm->tunnels);
563 hi = vnet_get_hw_interface (vnm, hw_if_index);
sharath reddy6f8273a2017-12-11 11:31:31 +0530564 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800565
John Loe5453d02018-01-23 19:21:34 -0500566 /* Set vxlan-gpe tunnel output node */
567 u32 encap_index = vxlan_gpe_encap_node.index;
568 vnet_set_interface_output_node (vnm, hw_if_index, encap_index);
569
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700570 t->hw_if_index = hw_if_index;
571 t->sw_if_index = sw_if_index = hi->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530572 vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index,
573 ~0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800574 ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800575
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800576 /* setup l2 input config with l2 feature and bd 0 to drop packet */
577 vec_validate (l2im->configs, sw_if_index);
578 l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
579 l2im->configs[sw_if_index].bd_index = 0;
580
sharath reddy6f8273a2017-12-11 11:31:31 +0530581 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800582 si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800583 vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
sharath reddy6f8273a2017-12-11 11:31:31 +0530584 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
585 fib_node_init (&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800586 fib_prefix_t tun_remote_pfx;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800587 vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
588
Huawei LI06923b32022-09-29 11:28:12 +0800589 fib_protocol_t fp = fib_ip_proto (is_ip6);
590 fib_prefix_from_ip46_addr (fp, &t->remote, &tun_remote_pfx);
sharath reddy6f8273a2017-12-11 11:31:31 +0530591 if (!ip46_address_is_multicast (&t->remote))
592 {
593 /* Unicast tunnel -
594 * source the FIB entry for the tunnel's destination
595 * and become a child thereof. The tunnel will then get poked
596 * when the forwarding for the entry updates, and the tunnel can
597 * re-stack accordingly
598 */
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000599 vtep_addr_ref (&ngm->vtep_table, t->encap_fib_index, &t->local);
Neale Ranns1f50bf82019-07-16 15:28:52 +0000600 t->fib_entry_index = fib_entry_track (t->encap_fib_index,
601 &tun_remote_pfx,
602 FIB_NODE_TYPE_VXLAN_GPE_TUNNEL,
603 t - ngm->tunnels,
604 &t->sibling_index);
sharath reddy6f8273a2017-12-11 11:31:31 +0530605 vxlan_gpe_tunnel_restack_dpo (t);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800606 }
607 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530608 {
609 /* Multicast tunnel -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700610 * as the same mcast group can be used for multiple mcast tunnels
611 * with different VNIs, create the output fib adjacency only if
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800612 * it does not already exist
613 */
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000614 if (vtep_addr_ref (&ngm->vtep_table,
615 t->encap_fib_index, &t->remote) == 1)
sharath reddy6f8273a2017-12-11 11:31:31 +0530616 {
617 fib_node_index_t mfei;
618 adj_index_t ai;
619 fib_route_path_t path = {
620 .frp_proto = fib_proto_to_dpo (fp),
621 .frp_addr = zero_addr,
622 .frp_sw_if_index = 0xffffffff,
623 .frp_fib_index = ~0,
Neale Ranns097fa662018-05-01 05:17:55 -0700624 .frp_weight = 1,
sharath reddy6f8273a2017-12-11 11:31:31 +0530625 .frp_flags = FIB_ROUTE_PATH_LOCAL,
Neale Ranns097fa662018-05-01 05:17:55 -0700626 .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
sharath reddy6f8273a2017-12-11 11:31:31 +0530627 };
628 const mfib_prefix_t mpfx = {
629 .fp_proto = fp,
630 .fp_len = (is_ip6 ? 128 : 32),
631 .fp_grp_addr = tun_remote_pfx.fp_addr,
632 };
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800633
sharath reddy6f8273a2017-12-11 11:31:31 +0530634 /*
635 * Setup the (*,G) to receive traffic on the mcast group
636 * - the forwarding interface is for-us
637 * - the accepting interface is that from the API
638 */
Paul Atkins8e2b1b12021-10-12 14:32:11 +0100639 mfib_table_entry_path_update (t->encap_fib_index, &mpfx,
640 MFIB_SOURCE_VXLAN_GPE,
641 MFIB_ENTRY_FLAG_NONE, &path);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800642
sharath reddy6f8273a2017-12-11 11:31:31 +0530643 path.frp_sw_if_index = a->mcast_sw_if_index;
644 path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
Neale Ranns097fa662018-05-01 05:17:55 -0700645 path.frp_mitf_flags = MFIB_ITF_FLAG_ACCEPT;
Paul Atkins8e2b1b12021-10-12 14:32:11 +0100646 mfei = mfib_table_entry_path_update (
647 t->encap_fib_index, &mpfx, MFIB_SOURCE_VXLAN_GPE,
648 MFIB_ENTRY_FLAG_NONE, &path);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800649
sharath reddy6f8273a2017-12-11 11:31:31 +0530650 /*
651 * Create the mcast adjacency to send traffic to the group
652 */
653 ai = adj_mcast_add_or_lock (fp,
654 fib_proto_to_link (fp),
655 a->mcast_sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800656
sharath reddy6f8273a2017-12-11 11:31:31 +0530657 /*
658 * create a new end-point
659 */
660 mcast_shared_add (&t->remote, mfei, ai);
661 }
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800662
sharath reddy6f8273a2017-12-11 11:31:31 +0530663 dpo_id_t dpo = DPO_INVALID;
664 mcast_shared_t ep = mcast_shared_get (&t->remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800665
sharath reddy6f8273a2017-12-11 11:31:31 +0530666 /* Stack shared mcast remote mac addr rewrite on encap */
667 dpo_set (&dpo, DPO_ADJACENCY_MCAST,
668 fib_proto_to_dpo (fp), ep.mcast_adj_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800669
sharath reddy6f8273a2017-12-11 11:31:31 +0530670 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
671 dpo_reset (&dpo);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800672 flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
673 }
674
sharath reddy6f8273a2017-12-11 11:31:31 +0530675 vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
676 flood_class;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700677 }
678 else
679 {
680 /* deleting a tunnel: tunnel must exist */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800681 if (!p)
sharath reddy6f8273a2017-12-11 11:31:31 +0530682 return VNET_API_ERROR_NO_SUCH_ENTRY;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700683
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800684 t = pool_elt_at_index (ngm->tunnels, p[0]);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700685
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800686 sw_if_index = t->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530687 vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
688 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, t->sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800689 si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
Neale Rannsb4743802018-09-05 09:13:57 -0700690 set_int_l2_mode (ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0,
691 L2_BD_PORT_TYPE_NORMAL, 0, 0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800692 vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700693
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800694 ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
Hongjun Nic0959c92016-06-16 20:18:15 +0800695
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800696 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530697 hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800698 else
John Loe6bfeab2018-01-04 16:39:42 -0500699 hash_unset_mem_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700700
sharath reddy6f8273a2017-12-11 11:31:31 +0530701 if (!ip46_address_is_multicast (&t->remote))
702 {
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000703 vtep_addr_unref (&ngm->vtep_table, t->encap_fib_index, &t->local);
Neale Ranns1f50bf82019-07-16 15:28:52 +0000704 fib_entry_untrack (t->fib_entry_index, t->sibling_index);
sharath reddy6f8273a2017-12-11 11:31:31 +0530705 }
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000706 else if (vtep_addr_unref (&ngm->vtep_table,
707 t->encap_fib_index, &t->remote) == 0)
sharath reddy6f8273a2017-12-11 11:31:31 +0530708 {
709 mcast_shared_remove (&t->remote);
710 }
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800711
sharath reddy6f8273a2017-12-11 11:31:31 +0530712 fib_node_deinit (&t->node);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700713 vec_free (t->rewrite);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800714 pool_put (ngm->tunnels, t);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700715 }
716
717 if (sw_if_indexp)
sharath reddy6f8273a2017-12-11 11:31:31 +0530718 *sw_if_indexp = sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700719
Jakub Grajciardf3ca232019-06-04 13:16:42 +0200720 if (a->is_add)
721 {
722 /* register udp ports */
Artem Glazychevea962922021-05-28 19:09:14 +0700723 if (!is_ip6 && !udp_is_valid_dst_port (a->local_port, 1))
724 udp_register_dst_port (ngm->vlib_main, a->local_port,
725 vxlan4_gpe_input_node.index, 1 /* is_ip4 */);
726 if (is_ip6 && !udp_is_valid_dst_port (a->remote_port, 0))
727 udp_register_dst_port (ngm->vlib_main, a->remote_port,
728 vxlan6_gpe_input_node.index, 0 /* is_ip4 */);
Jakub Grajciardf3ca232019-06-04 13:16:42 +0200729 }
730
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700731 return 0;
732}
733
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700734static clib_error_t *
735vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +0530736 unformat_input_t * input,
737 vlib_cli_command_t * cmd)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700738{
sharath reddy6f8273a2017-12-11 11:31:31 +0530739 unformat_input_t _line_input, *line_input = &_line_input;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700740 u8 is_add = 1;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800741 ip46_address_t local, remote;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700742 u8 local_set = 0;
743 u8 remote_set = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800744 u8 grp_set = 0;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800745 u8 ipv4_set = 0;
746 u8 ipv6_set = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800747 u32 mcast_sw_if_index = ~0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700748 u32 encap_fib_index = 0;
749 u32 decap_fib_index = 0;
750 u8 protocol = VXLAN_GPE_PROTOCOL_IP4;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700751 u32 vni;
752 u8 vni_set = 0;
Artem Glazychevea962922021-05-28 19:09:14 +0700753 u32 local_port = 0;
754 u32 remote_port = 0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700755 int rv;
756 u32 tmp;
sharath reddy6f8273a2017-12-11 11:31:31 +0530757 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
Pierre Pfister78ea9c22016-05-23 12:51:54 +0100758 u32 sw_if_index;
Billy McFalla9a20e72017-02-15 11:39:12 -0500759 clib_error_t *error = NULL;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800760
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700761 /* Get a line of input. */
sharath reddy6f8273a2017-12-11 11:31:31 +0530762 if (!unformat_user (input, unformat_line_input, line_input))
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700763 return 0;
764
sharath reddy6f8273a2017-12-11 11:31:31 +0530765 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Hongjun Nidf921cc2016-05-25 01:16:19 +0800766 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530767 if (unformat (line_input, "del"))
768 is_add = 0;
769 else if (unformat (line_input, "local %U",
770 unformat_ip4_address, &local.ip4))
771 {
772 local_set = 1;
773 ipv4_set = 1;
774 }
775 else if (unformat (line_input, "remote %U",
776 unformat_ip4_address, &remote.ip4))
777 {
778 remote_set = 1;
779 ipv4_set = 1;
780 }
781 else if (unformat (line_input, "local %U",
782 unformat_ip6_address, &local.ip6))
783 {
784 local_set = 1;
785 ipv6_set = 1;
786 }
787 else if (unformat (line_input, "remote %U",
788 unformat_ip6_address, &remote.ip6))
789 {
790 remote_set = 1;
791 ipv6_set = 1;
792 }
793 else if (unformat (line_input, "group %U %U",
794 unformat_ip4_address, &remote.ip4,
795 unformat_vnet_sw_interface,
796 vnet_get_main (), &mcast_sw_if_index))
797 {
798 grp_set = remote_set = 1;
799 ipv4_set = 1;
800 }
801 else if (unformat (line_input, "group %U %U",
802 unformat_ip6_address, &remote.ip6,
803 unformat_vnet_sw_interface,
804 vnet_get_main (), &mcast_sw_if_index))
805 {
806 grp_set = remote_set = 1;
807 ipv6_set = 1;
808 }
809 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
810 {
811 if (ipv6_set)
812 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
813 else
814 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800815
sharath reddy6f8273a2017-12-11 11:31:31 +0530816 if (encap_fib_index == ~0)
817 {
818 error =
819 clib_error_return (0, "nonexistent encap fib id %d", tmp);
820 goto done;
821 }
822 }
823 else if (unformat (line_input, "decap-vrf-id %d", &tmp))
824 {
825 if (ipv6_set)
826 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
827 else
828 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800829
sharath reddy6f8273a2017-12-11 11:31:31 +0530830 if (decap_fib_index == ~0)
831 {
832 error =
833 clib_error_return (0, "nonexistent decap fib id %d", tmp);
834 goto done;
835 }
836 }
837 else if (unformat (line_input, "vni %d", &vni))
838 vni_set = 1;
Artem Glazychevea962922021-05-28 19:09:14 +0700839 else if (unformat (line_input, "local_port %d", &local_port))
840 ;
841 else if (unformat (line_input, "remote_port %d", &remote_port))
842 ;
sharath reddy6f8273a2017-12-11 11:31:31 +0530843 else if (unformat (line_input, "next-ip4"))
844 protocol = VXLAN_GPE_PROTOCOL_IP4;
845 else if (unformat (line_input, "next-ip6"))
846 protocol = VXLAN_GPE_PROTOCOL_IP6;
847 else if (unformat (line_input, "next-ethernet"))
848 protocol = VXLAN_GPE_PROTOCOL_ETHERNET;
849 else if (unformat (line_input, "next-nsh"))
850 protocol = VXLAN_GPE_PROTOCOL_NSH;
851 else
852 {
853 error = clib_error_return (0, "parse error: '%U'",
854 format_unformat_error, line_input);
855 goto done;
856 }
857 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700858
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700859 if (local_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500860 {
861 error = clib_error_return (0, "tunnel local address not specified");
862 goto done;
863 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700864
865 if (remote_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500866 {
867 error = clib_error_return (0, "tunnel remote address not specified");
868 goto done;
869 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700870
sharath reddy6f8273a2017-12-11 11:31:31 +0530871 if (grp_set && !ip46_address_is_multicast (&remote))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800872 {
873 error = clib_error_return (0, "tunnel group address not multicast");
874 goto done;
875 }
876
sharath reddy6f8273a2017-12-11 11:31:31 +0530877 if (grp_set == 0 && ip46_address_is_multicast (&remote))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800878 {
879 error = clib_error_return (0, "remote address must be unicast");
880 goto done;
881 }
882
883 if (grp_set && mcast_sw_if_index == ~0)
884 {
885 error = clib_error_return (0, "tunnel nonexistent multicast device");
886 goto done;
887 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800888 if (ipv4_set && ipv6_set)
Billy McFalla9a20e72017-02-15 11:39:12 -0500889 {
890 error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
891 goto done;
892 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800893
sharath reddy6f8273a2017-12-11 11:31:31 +0530894 if ((ipv4_set && memcmp (&local.ip4, &remote.ip4, sizeof (local.ip4)) == 0)
895 || (ipv6_set
896 && memcmp (&local.ip6, &remote.ip6, sizeof (local.ip6)) == 0))
Billy McFalla9a20e72017-02-15 11:39:12 -0500897 {
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800898 error = clib_error_return (0, "src and remote addresses are identical");
Billy McFalla9a20e72017-02-15 11:39:12 -0500899 goto done;
900 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800901
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700902 if (vni_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500903 {
904 error = clib_error_return (0, "vni not specified");
905 goto done;
906 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700907
Dave Barachb7b92992018-10-17 10:38:51 -0400908 clib_memset (a, 0, sizeof (*a));
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700909
910 a->is_add = is_add;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800911 a->is_ip6 = ipv6_set;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700912
913#define _(x) a->x = x;
914 foreach_gpe_copy_field;
sharath reddy6f8273a2017-12-11 11:31:31 +0530915 if (ipv4_set)
916 foreach_copy_ipv4
John Loe6bfeab2018-01-04 16:39:42 -0500917 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530918 foreach_copy_ipv6
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700919#undef _
John Loe6bfeab2018-01-04 16:39:42 -0500920
921 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700922
sharath reddy6f8273a2017-12-11 11:31:31 +0530923 switch (rv)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700924 {
925 case 0:
sharath reddy6f8273a2017-12-11 11:31:31 +0530926 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
927 vnet_get_main (), sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700928 break;
929 case VNET_API_ERROR_INVALID_DECAP_NEXT:
Billy McFalla9a20e72017-02-15 11:39:12 -0500930 error = clib_error_return (0, "invalid decap-next...");
931 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700932
933 case VNET_API_ERROR_TUNNEL_EXIST:
Billy McFalla9a20e72017-02-15 11:39:12 -0500934 error = clib_error_return (0, "tunnel already exists...");
935 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700936
937 case VNET_API_ERROR_NO_SUCH_ENTRY:
Billy McFalla9a20e72017-02-15 11:39:12 -0500938 error = clib_error_return (0, "tunnel does not exist...");
939 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700940
941 default:
Billy McFalla9a20e72017-02-15 11:39:12 -0500942 error = clib_error_return
sharath reddy6f8273a2017-12-11 11:31:31 +0530943 (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500944 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700945 }
946
Billy McFalla9a20e72017-02-15 11:39:12 -0500947done:
948 unformat_free (line_input);
949
950 return error;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700951}
952
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800953/*?
954 * Add or delete a VXLAN-GPE Tunnel.
955 *
956 * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
957 * to span multiple servers. This is done by building an L2 overlay on
958 * top of an L3 network underlay using VXLAN-GPE tunnels.
959 *
960 * This makes it possible for servers to be co-located in the same data
961 * center or be separated geographically as long as they are reachable
962 * through the underlay L3 network.
963 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700964 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800965 *
966 * @cliexpar
967 * Example of how to create a VXLAN-GPE Tunnel:
Zhiyong Yang42e64e92019-05-22 03:49:43 -0400968 * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 remote 10.0.3.3 vni 13 encap-vrf-id 7}
969 * Example of how to delete a VXLAN-GPE Tunnel:
970 * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 remote 10.0.3.3 vni 13 del}
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800971 ?*/
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700972VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = {
973 .path = "create vxlan-gpe tunnel",
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800974 .short_help =
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800975 "create vxlan-gpe tunnel local <local-addr> "
976 " {remote <remote-addr>|group <mcast-addr> <intf-name>}"
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700977 " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]"
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800978 " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n",
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700979 .function = vxlan_gpe_add_del_tunnel_command_fn,
980};
981
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700982/**
983 * @brief CLI function for showing VXLAN GPE tunnels
984 *
985 * @param *vm
986 * @param *input
987 * @param *cmd
988 *
989 * @return error
990 *
991 */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700992static clib_error_t *
993show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +0530994 unformat_input_t * input,
995 vlib_cli_command_t * cmd)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700996{
sharath reddy6f8273a2017-12-11 11:31:31 +0530997 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
998 vxlan_gpe_tunnel_t *t;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800999
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001000 if (pool_elts (ngm->tunnels) == 0)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001001 vlib_cli_output (vm, "No vxlan-gpe tunnels configured.");
1002
Damjan Marionb2c31b62020-12-13 21:47:40 +01001003 pool_foreach (t, ngm->tunnels)
1004 {
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001005 vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t);
Damjan Marionb2c31b62020-12-13 21:47:40 +01001006 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001007
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001008 return 0;
1009}
1010
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001011/*?
1012 * Display all the VXLAN-GPE Tunnel entries.
1013 *
1014 * @cliexpar
1015 * Example of how to display the VXLAN-GPE Tunnel entries:
1016 * @cliexstart{show vxlan-gpe tunnel}
1017 * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
1018 * @cliexend
1019 ?*/
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001020VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = {
1021 .path = "show vxlan-gpe",
1022 .function = show_vxlan_gpe_tunnel_command_fn,
1023};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001024
sharath reddy6f8273a2017-12-11 11:31:31 +05301025void
1026vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001027{
1028 if (is_ip6)
1029 vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-gpe-bypass",
1030 sw_if_index, is_enable, 0, 0);
1031 else
1032 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-gpe-bypass",
1033 sw_if_index, is_enable, 0, 0);
1034}
1035
1036
1037static clib_error_t *
1038set_ip_vxlan_gpe_bypass (u32 is_ip6,
sharath reddy6f8273a2017-12-11 11:31:31 +05301039 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001040{
sharath reddy6f8273a2017-12-11 11:31:31 +05301041 unformat_input_t _line_input, *line_input = &_line_input;
1042 vnet_main_t *vnm = vnet_get_main ();
1043 clib_error_t *error = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001044 u32 sw_if_index, is_enable;
1045
1046 sw_if_index = ~0;
1047 is_enable = 1;
1048
sharath reddy6f8273a2017-12-11 11:31:31 +05301049 if (!unformat_user (input, unformat_line_input, line_input))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001050 return 0;
1051
1052 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1053 {
sharath reddy6f8273a2017-12-11 11:31:31 +05301054 if (unformat_user
1055 (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1056 ;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001057 else if (unformat (line_input, "del"))
sharath reddy6f8273a2017-12-11 11:31:31 +05301058 is_enable = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001059 else
sharath reddy6f8273a2017-12-11 11:31:31 +05301060 {
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001061 error = unformat_parse_error (line_input);
1062 goto done;
1063 }
1064 }
1065
1066 if (~0 == sw_if_index)
1067 {
1068 error = clib_error_return (0, "unknown interface `%U'",
1069 format_unformat_error, line_input);
1070 goto done;
1071 }
1072
1073 vnet_int_vxlan_gpe_bypass_mode (sw_if_index, is_ip6, is_enable);
1074
sharath reddy6f8273a2017-12-11 11:31:31 +05301075done:
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001076 unformat_free (line_input);
1077
1078 return error;
1079}
1080
1081static clib_error_t *
1082set_ip4_vxlan_gpe_bypass (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301083 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001084{
1085 return set_ip_vxlan_gpe_bypass (0, input, cmd);
1086}
1087
1088/*?
Nathan Skrzypczak5e6a1652021-10-06 15:03:35 +02001089 * This command adds the 'ip4-vxlan-gpe-bypass' graph node for a given
1090 * interface. By adding the IPv4 vxlan-gpe-bypass graph node to an interface,
1091 * the node checks for and validate input vxlan_gpe packet and bypass
1092 * ip4-lookup, ip4-local, ip4-udp-lookup nodes to speedup vxlan_gpe packet
1093 * forwarding. This node will cause extra overhead to for non-vxlan_gpe
1094 * packets which is kept at a minimum.
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001095 *
1096 * @cliexpar
1097 * @parblock
1098 * Example of graph node before ip4-vxlan-gpe-bypass is enabled:
1099 * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1100 * Name Next Previous
1101 * ip4-vxlan-gpe-bypass error-drop [0]
1102 * vxlan4-gpe-input [1]
1103 * ip4-lookup [2]
1104 * @cliexend
1105 *
1106 * Example of how to enable ip4-vxlan-gpe-bypass on an interface:
1107 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0}
1108 *
1109 * Example of graph node after ip4-vxlan-gpe-bypass is enabled:
1110 * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
Nathan Skrzypczak5e6a1652021-10-06 15:03:35 +02001111 * Name Next Previous
1112 * ip4-vxlan-gpe-bypass error-drop [0] ip4-input
1113 * vxlan4-gpe-input [1] ip4-input-no-checksum
1114 * ip4-lookup [2]
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001115 * @cliexend
1116 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001117 * Example of how to display the feature enabled on an interface:
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001118 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1119 * IP feature paths configured on GigabitEthernet2/0/0...
1120 * ...
1121 * ipv4 unicast:
1122 * ip4-vxlan-gpe-bypass
1123 * ip4-lookup
1124 * ...
1125 * @cliexend
1126 *
1127 * Example of how to disable ip4-vxlan-gpe-bypass on an interface:
1128 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1129 * @endparblock
1130?*/
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001131VLIB_CLI_COMMAND (set_interface_ip_vxlan_gpe_bypass_command, static) = {
1132 .path = "set interface ip vxlan-gpe-bypass",
1133 .function = set_ip4_vxlan_gpe_bypass,
1134 .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1135};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001136
1137static clib_error_t *
1138set_ip6_vxlan_gpe_bypass (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301139 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001140{
1141 return set_ip_vxlan_gpe_bypass (1, input, cmd);
1142}
1143
1144/*?
Nathan Skrzypczak5e6a1652021-10-06 15:03:35 +02001145 * This command adds the 'ip6-vxlan-gpe-bypass' graph node for a given
1146 * interface. By adding the IPv6 vxlan-gpe-bypass graph node to an interface,
1147 * the node checks for and validate input vxlan_gpe packet and bypass
1148 * ip6-lookup, ip6-local, ip6-udp-lookup nodes to speedup vxlan_gpe packet
1149 * forwarding. This node will cause extra overhead to for non-vxlan_gpe packets
1150 * which is kept at a minimum.
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001151 *
1152 * @cliexpar
1153 * @parblock
1154 * Example of graph node before ip6-vxlan-gpe-bypass is enabled:
1155 * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1156 * Name Next Previous
1157 * ip6-vxlan-gpe-bypass error-drop [0]
1158 * vxlan6-gpe-input [1]
1159 * ip6-lookup [2]
1160 * @cliexend
1161 *
1162 * Example of how to enable ip6-vxlan-gpe-bypass on an interface:
1163 * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0}
1164 *
1165 * Example of graph node after ip6-vxlan-gpe-bypass is enabled:
1166 * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
Nathan Skrzypczak5e6a1652021-10-06 15:03:35 +02001167 * Name Next Previous
1168 * ip6-vxlan-gpe-bypass error-drop [0] ip6-input
1169 * vxlan6-gpe-input [1] ip4-input-no-checksum
1170 * ip6-lookup [2]
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001171 * @cliexend
1172 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001173 * Example of how to display the feature enabled on an interface:
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001174 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1175 * IP feature paths configured on GigabitEthernet2/0/0...
1176 * ...
1177 * ipv6 unicast:
1178 * ip6-vxlan-gpe-bypass
1179 * ip6-lookup
1180 * ...
1181 * @cliexend
1182 *
1183 * Example of how to disable ip6-vxlan-gpe-bypass on an interface:
1184 * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1185 * @endparblock
1186?*/
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001187VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gpe_bypass_command, static) = {
1188 .path = "set interface ip6 vxlan-gpe-bypass",
1189 .function = set_ip6_vxlan_gpe_bypass,
Paul Vinciguerra5fb22782019-11-07 17:20:48 -05001190 .short_help = "set interface ip6 vxlan-gpe-bypass <interface> [del]",
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001191};
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001192
Hongjun Nie1bf5722017-08-03 20:34:45 +08001193VNET_FEATURE_INIT (ip4_vxlan_gpe_bypass, static) =
1194{
1195 .arc_name = "ip4-unicast",
1196 .node_name = "ip4-vxlan-gpe-bypass",
1197 .runs_before = VNET_FEATURES ("ip4-lookup"),
1198};
1199
1200VNET_FEATURE_INIT (ip6_vxlan_gpe_bypass, static) =
1201{
1202 .arc_name = "ip6-unicast",
1203 .node_name = "ip6-vxlan-gpe-bypass",
1204 .runs_before = VNET_FEATURES ("ip6-lookup"),
1205};
Hongjun Nie1bf5722017-08-03 20:34:45 +08001206
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -07001207/**
1208 * @brief Feature init function for VXLAN GPE
1209 *
1210 * @param *vm
1211 *
1212 * @return error
1213 *
1214 */
sharath reddy6f8273a2017-12-11 11:31:31 +05301215clib_error_t *
1216vxlan_gpe_init (vlib_main_t * vm)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001217{
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001218 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001219
sharath reddy6f8273a2017-12-11 11:31:31 +05301220 ngm->vnet_main = vnet_get_main ();
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001221 ngm->vlib_main = vm;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001222
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001223 ngm->vxlan4_gpe_tunnel_by_key
sharath reddy6f8273a2017-12-11 11:31:31 +05301224 = hash_create_mem (0, sizeof (vxlan4_gpe_tunnel_key_t), sizeof (uword));
Hongjun Nidf921cc2016-05-25 01:16:19 +08001225
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001226 ngm->vxlan6_gpe_tunnel_by_key
sharath reddy6f8273a2017-12-11 11:31:31 +05301227 = hash_create_mem (0, sizeof (vxlan6_gpe_tunnel_key_t), sizeof (uword));
Hongjun Nidf921cc2016-05-25 01:16:19 +08001228
1229
sharath reddy6f8273a2017-12-11 11:31:31 +05301230 ngm->mcast_shared = hash_create_mem (0,
1231 sizeof (ip46_address_t),
1232 sizeof (mcast_shared_t));
Nick Zavaritsky27518c22020-02-27 15:54:58 +00001233 ngm->vtep_table = vtep_table_create ();
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001234
Vengada Govindan6d403a02016-10-12 05:54:09 -07001235 /* Register the list of standard decap protocols supported */
1236 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4,
sharath reddy6f8273a2017-12-11 11:31:31 +05301237 VXLAN_GPE_INPUT_NEXT_IP4_INPUT);
Vengada Govindan6d403a02016-10-12 05:54:09 -07001238 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6,
sharath reddy6f8273a2017-12-11 11:31:31 +05301239 VXLAN_GPE_INPUT_NEXT_IP6_INPUT);
Vengada Govindan6d403a02016-10-12 05:54:09 -07001240 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET,
Gabriel Ganne7e665d62017-11-17 09:18:53 +01001241 VXLAN_GPE_INPUT_NEXT_L2_INPUT);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001242
sharath reddy6f8273a2017-12-11 11:31:31 +05301243 fib_node_register_type (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001244
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001245 return 0;
1246}
1247
sharath reddy6f8273a2017-12-11 11:31:31 +05301248VLIB_INIT_FUNCTION (vxlan_gpe_init);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001249
sharath reddy6f8273a2017-12-11 11:31:31 +05301250
1251/*
1252 * fd.io coding-style-patch-verification: ON
1253 *
1254 * Local Variables:
1255 * eval: (c-set-style "gnu")
1256 * End:
1257 */