blob: 3ce8ad619faa60cf6a1bf45f5e23939a2ccbc17d [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>
29#include <vlib/vlib.h>
30
31/**
32 * @file
33 * @brief VXLAN-GPE.
34 *
35 * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
36 * to span multiple servers. This is done by building an L2 overlay on
37 * top of an L3 network underlay using VXLAN-GPE tunnels.
38 *
39 * This makes it possible for servers to be co-located in the same data
40 * center or be separated geographically as long as they are reachable
41 * through the underlay L3 network.
42 *
43 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
44 */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070045
46vxlan_gpe_main_t vxlan_gpe_main;
47
John Lo4478d8e2018-01-12 17:15:25 -050048static u8 *
49format_decap_next (u8 * s, va_list * args)
50{
51 vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
52
53 switch (t->protocol)
54 {
55 case VXLAN_GPE_PROTOCOL_IP4:
56 s = format (s, "protocol ip4 fib-idx %d", t->decap_fib_index);
57 break;
58 case VXLAN_GPE_PROTOCOL_IP6:
59 s = format (s, "protocol ip6 fib-idx %d", t->decap_fib_index);
60 break;
61 case VXLAN_GPE_PROTOCOL_ETHERNET:
62 s = format (s, "protocol ethernet");
63 break;
64 case VXLAN_GPE_PROTOCOL_NSH:
65 s = format (s, "protocol nsh");
66 break;
67 default:
68 s = format (s, "protocol unknown %d", t->protocol);
69 }
70
71 return s;
72}
73
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070074/**
John Lo4478d8e2018-01-12 17:15:25 -050075 * @brief Format function for VXLAN GPE tunnel
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070076 *
77 * @param *s formatting string
78 * @param *args
79 *
80 * @return *s formatted string
81 *
82 */
sharath reddy6f8273a2017-12-11 11:31:31 +053083u8 *
84format_vxlan_gpe_tunnel (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070085{
sharath reddy6f8273a2017-12-11 11:31:31 +053086 vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
87 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070088
John Lo4478d8e2018-01-12 17:15:25 -050089 s = format (s, "[%d] lcl %U rmt %U vni %d fib-idx %d sw-if-idx %d ",
sharath reddy6f8273a2017-12-11 11:31:31 +053090 t - ngm->tunnels,
91 format_ip46_address, &t->local, IP46_TYPE_ANY,
John Lo4478d8e2018-01-12 17:15:25 -050092 format_ip46_address, &t->remote, IP46_TYPE_ANY,
93 t->vni, t->encap_fib_index, t->sw_if_index);
Hongjun Nidf921cc2016-05-25 01:16:19 +080094
John Lo4478d8e2018-01-12 17:15:25 -050095#if 0
96 /* next_dpo not yet used by vxlan-gpe-encap node */
97 s = format (s, "encap-dpo-idx %d ", t->next_dpo.dpoi_index);
98 */
99#endif
100 s = format (s, "decap-next-%U ", format_decap_next, t);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700101
John Lo4478d8e2018-01-12 17:15:25 -0500102 if (PREDICT_FALSE (ip46_address_is_multicast (&t->remote)))
103 s = format (s, "mcast-sw-if-idx %d ", t->mcast_sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700104
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700105 return s;
106}
107
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700108/**
109 * @brief Naming for VXLAN GPE tunnel
110 *
111 * @param *s formatting string
112 * @param *args
113 *
114 * @return *s formatted string
115 *
116 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530117static u8 *
118format_vxlan_gpe_name (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700119{
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800120 u32 dev_instance = va_arg (*args, u32);
121 return format (s, "vxlan_gpe_tunnel%d", dev_instance);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700122}
123
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700124/**
125 * @brief CLI function for VXLAN GPE admin up/down
126 *
127 * @param *vnm
128 * @param hw_if_index
129 * @param flag
130 *
131 * @return *rc
132 *
133 */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800134static clib_error_t *
sharath reddy6f8273a2017-12-11 11:31:31 +0530135vxlan_gpe_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
136 u32 flags)
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800137{
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800138 u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
139 VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
140 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800141
142 return 0;
143}
144
sharath reddy6f8273a2017-12-11 11:31:31 +0530145/* *INDENT-OFF* */
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800146VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
147 .name = "VXLAN_GPE",
148 .format_device_name = format_vxlan_gpe_name,
149 .format_tx_trace = format_vxlan_gpe_encap_trace,
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800150 .admin_up_down_function = vxlan_gpe_interface_admin_up_down,
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800151};
sharath reddy6f8273a2017-12-11 11:31:31 +0530152/* *INDENT-ON* */
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
sharath reddy6f8273a2017-12-11 11:31:31 +0530172/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700173VNET_HW_INTERFACE_CLASS (vxlan_gpe_hw_class) = {
174 .name = "VXLAN_GPE",
175 .format_header = format_vxlan_gpe_header_with_length,
Neale Rannsb80c5362016-10-08 13:03:40 +0100176 .build_rewrite = default_build_rewrite,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700177};
sharath reddy6f8273a2017-12-11 11:31:31 +0530178/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700179
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800180static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530181vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_t * t)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800182{
sharath reddy6f8273a2017-12-11 11:31:31 +0530183 dpo_id_t dpo = DPO_INVALID;
184 u32 encap_index = vxlan_gpe_encap_node.index;
185 fib_forward_chain_type_t forw_type = ip46_address_is_ip4 (&t->remote) ?
186 FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800187
sharath reddy6f8273a2017-12-11 11:31:31 +0530188 fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
189 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
190 dpo_reset (&dpo);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800191}
192
193static vxlan_gpe_tunnel_t *
sharath reddy6f8273a2017-12-11 11:31:31 +0530194vxlan_gpe_tunnel_from_fib_node (fib_node_t * node)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800195{
sharath reddy6f8273a2017-12-11 11:31:31 +0530196 ASSERT (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL == node->fn_type);
197 return ((vxlan_gpe_tunnel_t *) (((char *) node) -
198 STRUCT_OFFSET_OF (vxlan_gpe_tunnel_t,
199 node)));
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800200}
201
202/**
203 * Function definition to backwalk a FIB node -
204 * Here we will restack the new dpo of VXLAN_GPE DIP to encap node.
205 */
206static fib_node_back_walk_rc_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530207vxlan_gpe_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800208{
sharath reddy6f8273a2017-12-11 11:31:31 +0530209 vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_from_fib_node (node));
210 return (FIB_NODE_BACK_WALK_CONTINUE);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800211}
212
213/**
214 * Function definition to get a FIB node from its index
215 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530216static fib_node_t *
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800217vxlan_gpe_tunnel_fib_node_get (fib_node_index_t index)
218{
sharath reddy6f8273a2017-12-11 11:31:31 +0530219 vxlan_gpe_tunnel_t *t;
220 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800221
sharath reddy6f8273a2017-12-11 11:31:31 +0530222 t = pool_elt_at_index (ngm->tunnels, index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800223
sharath reddy6f8273a2017-12-11 11:31:31 +0530224 return (&t->node);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800225}
226
227/**
228 * Function definition to inform the FIB node that its last lock has gone.
229 */
230static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530231vxlan_gpe_tunnel_last_lock_gone (fib_node_t * node)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800232{
sharath reddy6f8273a2017-12-11 11:31:31 +0530233 /*
234 * The VXLAN_GPE tunnel is a root of the graph. As such
235 * it never has children and thus is never locked.
236 */
237 ASSERT (0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800238}
239
240/*
241 * Virtual function table registered by VXLAN_GPE tunnels
242 * for participation in the FIB object graph.
243 */
244const static fib_node_vft_t vxlan_gpe_vft = {
sharath reddy6f8273a2017-12-11 11:31:31 +0530245 .fnv_get = vxlan_gpe_tunnel_fib_node_get,
246 .fnv_last_lock = vxlan_gpe_tunnel_last_lock_gone,
247 .fnv_back_walk = vxlan_gpe_tunnel_back_walk,
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800248};
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700249
250#define foreach_gpe_copy_field \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700251_(vni) \
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800252_(protocol) \
253_(mcast_sw_if_index) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700254_(encap_fib_index) \
Hongjun Ni7deb1392016-06-15 22:49:23 +0800255_(decap_fib_index)
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? */
306 h0->udp.src_port = clib_host_to_net_u16 (4790);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800307 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
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? */
365 h0->udp.src_port = clib_host_to_net_u16 (4790);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800366 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
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
sharath reddy6f8273a2017-12-11 11:31:31 +0530387/* *INDENT-OFF* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800388typedef CLIB_PACKED(union {
389 struct {
390 fib_node_index_t mfib_entry_index;
391 adj_index_t mcast_adj_index;
392 };
393 u64 as_u64;
394}) mcast_shared_t;
sharath reddy6f8273a2017-12-11 11:31:31 +0530395/* *INDENT-ON* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800396
397static inline mcast_shared_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530398mcast_shared_get (ip46_address_t * ip)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800399{
sharath reddy6f8273a2017-12-11 11:31:31 +0530400 ASSERT (ip46_address_is_multicast (ip));
401 uword *p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip);
Dave Barachffd15462020-02-18 10:12:23 -0500402 ALWAYS_ASSERT (p);
sharath reddy6f8273a2017-12-11 11:31:31 +0530403 return (mcast_shared_t)
404 {
405 .as_u64 = *p};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800406}
407
408static inline void
sharath reddy6f8273a2017-12-11 11:31:31 +0530409mcast_shared_add (ip46_address_t * remote,
410 fib_node_index_t mfei, adj_index_t ai)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800411{
sharath reddy6f8273a2017-12-11 11:31:31 +0530412 mcast_shared_t new_ep = {
413 .mcast_adj_index = ai,
414 .mfib_entry_index = mfei,
415 };
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800416
John Loe6bfeab2018-01-04 16:39:42 -0500417 hash_set_mem_alloc (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800418}
419
420static inline void
sharath reddy6f8273a2017-12-11 11:31:31 +0530421mcast_shared_remove (ip46_address_t * remote)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800422{
sharath reddy6f8273a2017-12-11 11:31:31 +0530423 mcast_shared_t ep = mcast_shared_get (remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800424
sharath reddy6f8273a2017-12-11 11:31:31 +0530425 adj_unlock (ep.mcast_adj_index);
426 mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_VXLAN_GPE);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800427
John Loe6bfeab2018-01-04 16:39:42 -0500428 hash_unset_mem_free (&vxlan_gpe_main.mcast_shared, remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800429}
430
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700431/**
432 * @brief Add or Del a VXLAN GPE tunnel
433 *
434 * @param *a
435 * @param *sw_if_index
436 *
437 * @return rc
438 *
439 */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800440int vnet_vxlan_gpe_add_del_tunnel
sharath reddy6f8273a2017-12-11 11:31:31 +0530441 (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700442{
sharath reddy6f8273a2017-12-11 11:31:31 +0530443 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700444 vxlan_gpe_tunnel_t *t = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530445 vnet_main_t *vnm = ngm->vnet_main;
446 vnet_hw_interface_t *hi;
447 uword *p;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700448 u32 hw_if_index = ~0;
449 u32 sw_if_index = ~0;
450 int rv;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800451 vxlan4_gpe_tunnel_key_t key4, *key4_copy;
452 vxlan6_gpe_tunnel_key_t key6, *key6_copy;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800453 u32 is_ip6 = a->is_ip6;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800454
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800455 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530456 {
457 key4.local = a->local.ip4.as_u32;
458 key4.remote = a->remote.ip4.as_u32;
459 key4.vni = clib_host_to_net_u32 (a->vni << 8);
460 key4.pad = 0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700461
sharath reddy6f8273a2017-12-11 11:31:31 +0530462 p = hash_get_mem (ngm->vxlan4_gpe_tunnel_by_key, &key4);
463 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800464 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530465 {
466 key6.local.as_u64[0] = a->local.ip6.as_u64[0];
467 key6.local.as_u64[1] = a->local.ip6.as_u64[1];
468 key6.remote.as_u64[0] = a->remote.ip6.as_u64[0];
469 key6.remote.as_u64[1] = a->remote.ip6.as_u64[1];
470 key6.vni = clib_host_to_net_u32 (a->vni << 8);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800471
sharath reddy6f8273a2017-12-11 11:31:31 +0530472 p = hash_get_mem (ngm->vxlan6_gpe_tunnel_by_key, &key6);
473 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800474
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700475 if (a->is_add)
476 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530477 l2input_main_t *l2im = &l2input_main;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800478
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700479 /* adding a tunnel: tunnel must not already exist */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800480 if (p)
sharath reddy6f8273a2017-12-11 11:31:31 +0530481 return VNET_API_ERROR_TUNNEL_EXIST;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800482
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800483 pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
Dave Barachb7b92992018-10-17 10:38:51 -0400484 clib_memset (t, 0, sizeof (*t));
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800485
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700486 /* copy from arg structure */
John Loe6bfeab2018-01-04 16:39:42 -0500487/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700488#define _(x) t->x = a->x;
489 foreach_gpe_copy_field;
sharath reddy6f8273a2017-12-11 11:31:31 +0530490 if (!a->is_ip6)
491 foreach_copy_ipv4
John Loe6bfeab2018-01-04 16:39:42 -0500492 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530493 foreach_copy_ipv6
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700494#undef _
John Loe6bfeab2018-01-04 16:39:42 -0500495/* *INDENT-ON* */
496
497 if (!a->is_ip6)
498 t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700499
sharath reddy6f8273a2017-12-11 11:31:31 +0530500 if (!a->is_ip6)
501 {
502 rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
503 }
504 else
505 {
506 rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
507 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700508
509 if (rv)
sharath reddy6f8273a2017-12-11 11:31:31 +0530510 {
511 pool_put (ngm->tunnels, t);
512 return rv;
513 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700514
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800515 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530516 {
517 key4_copy = clib_mem_alloc (sizeof (*key4_copy));
Dave Barach178cf492018-11-13 16:34:13 -0500518 clib_memcpy_fast (key4_copy, &key4, sizeof (*key4_copy));
sharath reddy6f8273a2017-12-11 11:31:31 +0530519 hash_set_mem (ngm->vxlan4_gpe_tunnel_by_key, key4_copy,
520 t - ngm->tunnels);
521 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800522 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530523 {
524 key6_copy = clib_mem_alloc (sizeof (*key6_copy));
Dave Barach178cf492018-11-13 16:34:13 -0500525 clib_memcpy_fast (key6_copy, &key6, sizeof (*key6_copy));
sharath reddy6f8273a2017-12-11 11:31:31 +0530526 hash_set_mem (ngm->vxlan6_gpe_tunnel_by_key, key6_copy,
527 t - ngm->tunnels);
528 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800529
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800530 if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0)
sharath reddy6f8273a2017-12-11 11:31:31 +0530531 {
532 vnet_interface_main_t *im = &vnm->interface_main;
533 hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
534 [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) - 1];
535 _vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) -= 1;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800536
sharath reddy6f8273a2017-12-11 11:31:31 +0530537 hi = vnet_get_hw_interface (vnm, hw_if_index);
538 hi->dev_instance = t - ngm->tunnels;
539 hi->hw_instance = hi->dev_instance;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800540 /* clear old stats of freed tunnel before reuse */
541 sw_if_index = hi->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530542 vnet_interface_counter_lock (im);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800543 vlib_zero_combined_counter
sharath reddy6f8273a2017-12-11 11:31:31 +0530544 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
545 sw_if_index);
546 vlib_zero_combined_counter (&im->combined_sw_if_counters
547 [VNET_INTERFACE_COUNTER_RX],
548 sw_if_index);
549 vlib_zero_simple_counter (&im->sw_if_counters
550 [VNET_INTERFACE_COUNTER_DROP],
551 sw_if_index);
552 vnet_interface_counter_unlock (im);
553 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800554 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530555 {
556 hw_if_index = vnet_register_interface
557 (vnm, vxlan_gpe_device_class.index, t - ngm->tunnels,
558 vxlan_gpe_hw_class.index, t - ngm->tunnels);
559 hi = vnet_get_hw_interface (vnm, hw_if_index);
sharath reddy6f8273a2017-12-11 11:31:31 +0530560 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800561
John Loe5453d02018-01-23 19:21:34 -0500562 /* Set vxlan-gpe tunnel output node */
563 u32 encap_index = vxlan_gpe_encap_node.index;
564 vnet_set_interface_output_node (vnm, hw_if_index, encap_index);
565
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700566 t->hw_if_index = hw_if_index;
567 t->sw_if_index = sw_if_index = hi->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530568 vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index,
569 ~0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800570 ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800571
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800572 /* setup l2 input config with l2 feature and bd 0 to drop packet */
573 vec_validate (l2im->configs, sw_if_index);
574 l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
575 l2im->configs[sw_if_index].bd_index = 0;
576
sharath reddy6f8273a2017-12-11 11:31:31 +0530577 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800578 si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800579 vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
sharath reddy6f8273a2017-12-11 11:31:31 +0530580 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
581 fib_node_init (&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800582 fib_prefix_t tun_remote_pfx;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800583 vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
584
sharath reddy6f8273a2017-12-11 11:31:31 +0530585 fib_prefix_from_ip46_addr (&t->remote, &tun_remote_pfx);
586 if (!ip46_address_is_multicast (&t->remote))
587 {
588 /* Unicast tunnel -
589 * source the FIB entry for the tunnel's destination
590 * and become a child thereof. The tunnel will then get poked
591 * when the forwarding for the entry updates, and the tunnel can
592 * re-stack accordingly
593 */
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000594 vtep_addr_ref (&ngm->vtep_table, t->encap_fib_index, &t->local);
Neale Ranns1f50bf82019-07-16 15:28:52 +0000595 t->fib_entry_index = fib_entry_track (t->encap_fib_index,
596 &tun_remote_pfx,
597 FIB_NODE_TYPE_VXLAN_GPE_TUNNEL,
598 t - ngm->tunnels,
599 &t->sibling_index);
sharath reddy6f8273a2017-12-11 11:31:31 +0530600 vxlan_gpe_tunnel_restack_dpo (t);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800601 }
602 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530603 {
604 /* Multicast tunnel -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700605 * as the same mcast group can be used for multiple mcast tunnels
606 * with different VNIs, create the output fib adjacency only if
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800607 * it does not already exist
608 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530609 fib_protocol_t fp = fib_ip_proto (is_ip6);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800610
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000611 if (vtep_addr_ref (&ngm->vtep_table,
612 t->encap_fib_index, &t->remote) == 1)
sharath reddy6f8273a2017-12-11 11:31:31 +0530613 {
614 fib_node_index_t mfei;
615 adj_index_t ai;
616 fib_route_path_t path = {
617 .frp_proto = fib_proto_to_dpo (fp),
618 .frp_addr = zero_addr,
619 .frp_sw_if_index = 0xffffffff,
620 .frp_fib_index = ~0,
Neale Ranns097fa662018-05-01 05:17:55 -0700621 .frp_weight = 1,
sharath reddy6f8273a2017-12-11 11:31:31 +0530622 .frp_flags = FIB_ROUTE_PATH_LOCAL,
Neale Ranns097fa662018-05-01 05:17:55 -0700623 .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
sharath reddy6f8273a2017-12-11 11:31:31 +0530624 };
625 const mfib_prefix_t mpfx = {
626 .fp_proto = fp,
627 .fp_len = (is_ip6 ? 128 : 32),
628 .fp_grp_addr = tun_remote_pfx.fp_addr,
629 };
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800630
sharath reddy6f8273a2017-12-11 11:31:31 +0530631 /*
632 * Setup the (*,G) to receive traffic on the mcast group
633 * - the forwarding interface is for-us
634 * - the accepting interface is that from the API
635 */
636 mfib_table_entry_path_update (t->encap_fib_index,
637 &mpfx,
Neale Ranns097fa662018-05-01 05:17:55 -0700638 MFIB_SOURCE_VXLAN_GPE, &path);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800639
sharath reddy6f8273a2017-12-11 11:31:31 +0530640 path.frp_sw_if_index = a->mcast_sw_if_index;
641 path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
Neale Ranns097fa662018-05-01 05:17:55 -0700642 path.frp_mitf_flags = MFIB_ITF_FLAG_ACCEPT;
sharath reddy6f8273a2017-12-11 11:31:31 +0530643 mfei = mfib_table_entry_path_update (t->encap_fib_index,
644 &mpfx,
645 MFIB_SOURCE_VXLAN_GPE,
Neale Ranns097fa662018-05-01 05:17:55 -0700646 &path);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800647
sharath reddy6f8273a2017-12-11 11:31:31 +0530648 /*
649 * Create the mcast adjacency to send traffic to the group
650 */
651 ai = adj_mcast_add_or_lock (fp,
652 fib_proto_to_link (fp),
653 a->mcast_sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800654
sharath reddy6f8273a2017-12-11 11:31:31 +0530655 /*
656 * create a new end-point
657 */
658 mcast_shared_add (&t->remote, mfei, ai);
659 }
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800660
sharath reddy6f8273a2017-12-11 11:31:31 +0530661 dpo_id_t dpo = DPO_INVALID;
662 mcast_shared_t ep = mcast_shared_get (&t->remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800663
sharath reddy6f8273a2017-12-11 11:31:31 +0530664 /* Stack shared mcast remote mac addr rewrite on encap */
665 dpo_set (&dpo, DPO_ADJACENCY_MCAST,
666 fib_proto_to_dpo (fp), ep.mcast_adj_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800667
sharath reddy6f8273a2017-12-11 11:31:31 +0530668 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
669 dpo_reset (&dpo);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800670 flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
671 }
672
sharath reddy6f8273a2017-12-11 11:31:31 +0530673 vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
674 flood_class;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700675 }
676 else
677 {
678 /* deleting a tunnel: tunnel must exist */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800679 if (!p)
sharath reddy6f8273a2017-12-11 11:31:31 +0530680 return VNET_API_ERROR_NO_SUCH_ENTRY;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700681
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800682 t = pool_elt_at_index (ngm->tunnels, p[0]);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700683
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800684 sw_if_index = t->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530685 vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
686 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, t->sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800687 si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
Neale Rannsb4743802018-09-05 09:13:57 -0700688 set_int_l2_mode (ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0,
689 L2_BD_PORT_TYPE_NORMAL, 0, 0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800690 vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700691
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800692 ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
Hongjun Nic0959c92016-06-16 20:18:15 +0800693
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800694 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530695 hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800696 else
John Loe6bfeab2018-01-04 16:39:42 -0500697 hash_unset_mem_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700698
sharath reddy6f8273a2017-12-11 11:31:31 +0530699 if (!ip46_address_is_multicast (&t->remote))
700 {
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000701 vtep_addr_unref (&ngm->vtep_table, t->encap_fib_index, &t->local);
Neale Ranns1f50bf82019-07-16 15:28:52 +0000702 fib_entry_untrack (t->fib_entry_index, t->sibling_index);
sharath reddy6f8273a2017-12-11 11:31:31 +0530703 }
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000704 else if (vtep_addr_unref (&ngm->vtep_table,
705 t->encap_fib_index, &t->remote) == 0)
sharath reddy6f8273a2017-12-11 11:31:31 +0530706 {
707 mcast_shared_remove (&t->remote);
708 }
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800709
sharath reddy6f8273a2017-12-11 11:31:31 +0530710 fib_node_deinit (&t->node);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700711 vec_free (t->rewrite);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800712 pool_put (ngm->tunnels, t);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700713 }
714
715 if (sw_if_indexp)
sharath reddy6f8273a2017-12-11 11:31:31 +0530716 *sw_if_indexp = sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700717
Jakub Grajciardf3ca232019-06-04 13:16:42 +0200718 if (a->is_add)
719 {
720 /* register udp ports */
721 if (!is_ip6 && !udp_is_valid_dst_port (UDP_DST_PORT_VXLAN_GPE, 1))
722 udp_register_dst_port (ngm->vlib_main, UDP_DST_PORT_VXLAN_GPE,
723 vxlan4_gpe_input_node.index, 1 /* is_ip4 */ );
724 if (is_ip6 && !udp_is_valid_dst_port (UDP_DST_PORT_VXLAN6_GPE, 0))
725 udp_register_dst_port (ngm->vlib_main, UDP_DST_PORT_VXLAN6_GPE,
726 vxlan6_gpe_input_node.index, 0 /* is_ip4 */ );
727 }
728
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700729 return 0;
730}
731
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700732static clib_error_t *
733vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +0530734 unformat_input_t * input,
735 vlib_cli_command_t * cmd)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700736{
sharath reddy6f8273a2017-12-11 11:31:31 +0530737 unformat_input_t _line_input, *line_input = &_line_input;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700738 u8 is_add = 1;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800739 ip46_address_t local, remote;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700740 u8 local_set = 0;
741 u8 remote_set = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800742 u8 grp_set = 0;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800743 u8 ipv4_set = 0;
744 u8 ipv6_set = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800745 u32 mcast_sw_if_index = ~0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700746 u32 encap_fib_index = 0;
747 u32 decap_fib_index = 0;
748 u8 protocol = VXLAN_GPE_PROTOCOL_IP4;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700749 u32 vni;
750 u8 vni_set = 0;
751 int rv;
752 u32 tmp;
sharath reddy6f8273a2017-12-11 11:31:31 +0530753 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
Pierre Pfister78ea9c22016-05-23 12:51:54 +0100754 u32 sw_if_index;
Billy McFalla9a20e72017-02-15 11:39:12 -0500755 clib_error_t *error = NULL;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800756
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700757 /* Get a line of input. */
sharath reddy6f8273a2017-12-11 11:31:31 +0530758 if (!unformat_user (input, unformat_line_input, line_input))
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700759 return 0;
760
sharath reddy6f8273a2017-12-11 11:31:31 +0530761 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Hongjun Nidf921cc2016-05-25 01:16:19 +0800762 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530763 if (unformat (line_input, "del"))
764 is_add = 0;
765 else if (unformat (line_input, "local %U",
766 unformat_ip4_address, &local.ip4))
767 {
768 local_set = 1;
769 ipv4_set = 1;
770 }
771 else if (unformat (line_input, "remote %U",
772 unformat_ip4_address, &remote.ip4))
773 {
774 remote_set = 1;
775 ipv4_set = 1;
776 }
777 else if (unformat (line_input, "local %U",
778 unformat_ip6_address, &local.ip6))
779 {
780 local_set = 1;
781 ipv6_set = 1;
782 }
783 else if (unformat (line_input, "remote %U",
784 unformat_ip6_address, &remote.ip6))
785 {
786 remote_set = 1;
787 ipv6_set = 1;
788 }
789 else if (unformat (line_input, "group %U %U",
790 unformat_ip4_address, &remote.ip4,
791 unformat_vnet_sw_interface,
792 vnet_get_main (), &mcast_sw_if_index))
793 {
794 grp_set = remote_set = 1;
795 ipv4_set = 1;
796 }
797 else if (unformat (line_input, "group %U %U",
798 unformat_ip6_address, &remote.ip6,
799 unformat_vnet_sw_interface,
800 vnet_get_main (), &mcast_sw_if_index))
801 {
802 grp_set = remote_set = 1;
803 ipv6_set = 1;
804 }
805 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
806 {
807 if (ipv6_set)
808 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
809 else
810 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800811
sharath reddy6f8273a2017-12-11 11:31:31 +0530812 if (encap_fib_index == ~0)
813 {
814 error =
815 clib_error_return (0, "nonexistent encap fib id %d", tmp);
816 goto done;
817 }
818 }
819 else if (unformat (line_input, "decap-vrf-id %d", &tmp))
820 {
821 if (ipv6_set)
822 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
823 else
824 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800825
sharath reddy6f8273a2017-12-11 11:31:31 +0530826 if (decap_fib_index == ~0)
827 {
828 error =
829 clib_error_return (0, "nonexistent decap fib id %d", tmp);
830 goto done;
831 }
832 }
833 else if (unformat (line_input, "vni %d", &vni))
834 vni_set = 1;
835 else if (unformat (line_input, "next-ip4"))
836 protocol = VXLAN_GPE_PROTOCOL_IP4;
837 else if (unformat (line_input, "next-ip6"))
838 protocol = VXLAN_GPE_PROTOCOL_IP6;
839 else if (unformat (line_input, "next-ethernet"))
840 protocol = VXLAN_GPE_PROTOCOL_ETHERNET;
841 else if (unformat (line_input, "next-nsh"))
842 protocol = VXLAN_GPE_PROTOCOL_NSH;
843 else
844 {
845 error = clib_error_return (0, "parse error: '%U'",
846 format_unformat_error, line_input);
847 goto done;
848 }
849 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700850
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700851 if (local_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500852 {
853 error = clib_error_return (0, "tunnel local address not specified");
854 goto done;
855 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700856
857 if (remote_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500858 {
859 error = clib_error_return (0, "tunnel remote address not specified");
860 goto done;
861 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700862
sharath reddy6f8273a2017-12-11 11:31:31 +0530863 if (grp_set && !ip46_address_is_multicast (&remote))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800864 {
865 error = clib_error_return (0, "tunnel group address not multicast");
866 goto done;
867 }
868
sharath reddy6f8273a2017-12-11 11:31:31 +0530869 if (grp_set == 0 && ip46_address_is_multicast (&remote))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800870 {
871 error = clib_error_return (0, "remote address must be unicast");
872 goto done;
873 }
874
875 if (grp_set && mcast_sw_if_index == ~0)
876 {
877 error = clib_error_return (0, "tunnel nonexistent multicast device");
878 goto done;
879 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800880 if (ipv4_set && ipv6_set)
Billy McFalla9a20e72017-02-15 11:39:12 -0500881 {
882 error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
883 goto done;
884 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800885
sharath reddy6f8273a2017-12-11 11:31:31 +0530886 if ((ipv4_set && memcmp (&local.ip4, &remote.ip4, sizeof (local.ip4)) == 0)
887 || (ipv6_set
888 && memcmp (&local.ip6, &remote.ip6, sizeof (local.ip6)) == 0))
Billy McFalla9a20e72017-02-15 11:39:12 -0500889 {
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800890 error = clib_error_return (0, "src and remote addresses are identical");
Billy McFalla9a20e72017-02-15 11:39:12 -0500891 goto done;
892 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800893
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700894 if (vni_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500895 {
896 error = clib_error_return (0, "vni not specified");
897 goto done;
898 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700899
Dave Barachb7b92992018-10-17 10:38:51 -0400900 clib_memset (a, 0, sizeof (*a));
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700901
902 a->is_add = is_add;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800903 a->is_ip6 = ipv6_set;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700904
John Loe6bfeab2018-01-04 16:39:42 -0500905/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700906#define _(x) a->x = x;
907 foreach_gpe_copy_field;
sharath reddy6f8273a2017-12-11 11:31:31 +0530908 if (ipv4_set)
909 foreach_copy_ipv4
John Loe6bfeab2018-01-04 16:39:42 -0500910 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530911 foreach_copy_ipv6
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700912#undef _
John Loe6bfeab2018-01-04 16:39:42 -0500913/* *INDENT-ON* */
914
915 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700916
sharath reddy6f8273a2017-12-11 11:31:31 +0530917 switch (rv)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700918 {
919 case 0:
sharath reddy6f8273a2017-12-11 11:31:31 +0530920 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
921 vnet_get_main (), sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700922 break;
923 case VNET_API_ERROR_INVALID_DECAP_NEXT:
Billy McFalla9a20e72017-02-15 11:39:12 -0500924 error = clib_error_return (0, "invalid decap-next...");
925 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700926
927 case VNET_API_ERROR_TUNNEL_EXIST:
Billy McFalla9a20e72017-02-15 11:39:12 -0500928 error = clib_error_return (0, "tunnel already exists...");
929 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700930
931 case VNET_API_ERROR_NO_SUCH_ENTRY:
Billy McFalla9a20e72017-02-15 11:39:12 -0500932 error = clib_error_return (0, "tunnel does not exist...");
933 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700934
935 default:
Billy McFalla9a20e72017-02-15 11:39:12 -0500936 error = clib_error_return
sharath reddy6f8273a2017-12-11 11:31:31 +0530937 (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500938 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700939 }
940
Billy McFalla9a20e72017-02-15 11:39:12 -0500941done:
942 unformat_free (line_input);
943
944 return error;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700945}
946
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800947/*?
948 * Add or delete a VXLAN-GPE Tunnel.
949 *
950 * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
951 * to span multiple servers. This is done by building an L2 overlay on
952 * top of an L3 network underlay using VXLAN-GPE tunnels.
953 *
954 * This makes it possible for servers to be co-located in the same data
955 * center or be separated geographically as long as they are reachable
956 * through the underlay L3 network.
957 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700958 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800959 *
960 * @cliexpar
961 * Example of how to create a VXLAN-GPE Tunnel:
Zhiyong Yang42e64e92019-05-22 03:49:43 -0400962 * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 remote 10.0.3.3 vni 13 encap-vrf-id 7}
963 * Example of how to delete a VXLAN-GPE Tunnel:
964 * @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 +0800965 ?*/
966/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700967VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = {
968 .path = "create vxlan-gpe tunnel",
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800969 .short_help =
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800970 "create vxlan-gpe tunnel local <local-addr> "
971 " {remote <remote-addr>|group <mcast-addr> <intf-name>}"
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700972 " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]"
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800973 " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n",
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700974 .function = vxlan_gpe_add_del_tunnel_command_fn,
975};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800976/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700977
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700978/**
979 * @brief CLI function for showing VXLAN GPE tunnels
980 *
981 * @param *vm
982 * @param *input
983 * @param *cmd
984 *
985 * @return error
986 *
987 */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700988static clib_error_t *
989show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +0530990 unformat_input_t * input,
991 vlib_cli_command_t * cmd)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700992{
sharath reddy6f8273a2017-12-11 11:31:31 +0530993 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
994 vxlan_gpe_tunnel_t *t;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800995
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800996 if (pool_elts (ngm->tunnels) == 0)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700997 vlib_cli_output (vm, "No vxlan-gpe tunnels configured.");
998
sharath reddy6f8273a2017-12-11 11:31:31 +0530999 /* *INDENT-OFF* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001000 pool_foreach (t, ngm->tunnels,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001001 ({
1002 vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t);
1003 }));
sharath reddy6f8273a2017-12-11 11:31:31 +05301004 /* *INDENT-ON* */
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001005
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001006 return 0;
1007}
1008
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001009/*?
1010 * Display all the VXLAN-GPE Tunnel entries.
1011 *
1012 * @cliexpar
1013 * Example of how to display the VXLAN-GPE Tunnel entries:
1014 * @cliexstart{show vxlan-gpe tunnel}
1015 * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
1016 * @cliexend
1017 ?*/
1018/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001019VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = {
1020 .path = "show vxlan-gpe",
1021 .function = show_vxlan_gpe_tunnel_command_fn,
1022};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001023/* *INDENT-ON* */
1024
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/*?
1089 * This command adds the 'ip4-vxlan-gpe-bypass' graph node for a given interface.
1090 * By adding the IPv4 vxlan-gpe-bypass graph node to an interface, the node checks
1091 * for and validate input vxlan_gpe packet and bypass ip4-lookup, ip4-local,
1092 * ip4-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1093 * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1094 *
1095 * @cliexpar
1096 * @parblock
1097 * Example of graph node before ip4-vxlan-gpe-bypass is enabled:
1098 * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1099 * Name Next Previous
1100 * ip4-vxlan-gpe-bypass error-drop [0]
1101 * vxlan4-gpe-input [1]
1102 * ip4-lookup [2]
1103 * @cliexend
1104 *
1105 * Example of how to enable ip4-vxlan-gpe-bypass on an interface:
1106 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0}
1107 *
1108 * Example of graph node after ip4-vxlan-gpe-bypass is enabled:
1109 * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1110 * Name Next Previous
1111 * ip4-vxlan-gpe-bypass error-drop [0] ip4-input
1112 * vxlan4-gpe-input [1] ip4-input-no-checksum
1113 * ip4-lookup [2]
1114 * @cliexend
1115 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001116 * Example of how to display the feature enabled on an interface:
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001117 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1118 * IP feature paths configured on GigabitEthernet2/0/0...
1119 * ...
1120 * ipv4 unicast:
1121 * ip4-vxlan-gpe-bypass
1122 * ip4-lookup
1123 * ...
1124 * @cliexend
1125 *
1126 * Example of how to disable ip4-vxlan-gpe-bypass on an interface:
1127 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1128 * @endparblock
1129?*/
1130/* *INDENT-OFF* */
1131VLIB_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};
1136/* *INDENT-ON* */
1137
1138static clib_error_t *
1139set_ip6_vxlan_gpe_bypass (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301140 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001141{
1142 return set_ip_vxlan_gpe_bypass (1, input, cmd);
1143}
1144
1145/*?
1146 * This command adds the 'ip6-vxlan-gpe-bypass' graph node for a given interface.
1147 * By adding the IPv6 vxlan-gpe-bypass graph node to an interface, the node checks
1148 * for and validate input vxlan_gpe packet and bypass ip6-lookup, ip6-local,
1149 * ip6-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1150 * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1151 *
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}
1167 * 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]
1171 * @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?*/
1187/* *INDENT-OFF* */
1188VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gpe_bypass_command, static) = {
1189 .path = "set interface ip6 vxlan-gpe-bypass",
1190 .function = set_ip6_vxlan_gpe_bypass,
Paul Vinciguerra5fb22782019-11-07 17:20:48 -05001191 .short_help = "set interface ip6 vxlan-gpe-bypass <interface> [del]",
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001192};
1193/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001194
Hongjun Nie1bf5722017-08-03 20:34:45 +08001195/* *INDENT-OFF* */
1196VNET_FEATURE_INIT (ip4_vxlan_gpe_bypass, static) =
1197{
1198 .arc_name = "ip4-unicast",
1199 .node_name = "ip4-vxlan-gpe-bypass",
1200 .runs_before = VNET_FEATURES ("ip4-lookup"),
1201};
1202
1203VNET_FEATURE_INIT (ip6_vxlan_gpe_bypass, static) =
1204{
1205 .arc_name = "ip6-unicast",
1206 .node_name = "ip6-vxlan-gpe-bypass",
1207 .runs_before = VNET_FEATURES ("ip6-lookup"),
1208};
1209/* *INDENT-ON* */
1210
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -07001211/**
1212 * @brief Feature init function for VXLAN GPE
1213 *
1214 * @param *vm
1215 *
1216 * @return error
1217 *
1218 */
sharath reddy6f8273a2017-12-11 11:31:31 +05301219clib_error_t *
1220vxlan_gpe_init (vlib_main_t * vm)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001221{
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001222 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001223
sharath reddy6f8273a2017-12-11 11:31:31 +05301224 ngm->vnet_main = vnet_get_main ();
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001225 ngm->vlib_main = vm;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001226
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001227 ngm->vxlan4_gpe_tunnel_by_key
sharath reddy6f8273a2017-12-11 11:31:31 +05301228 = hash_create_mem (0, sizeof (vxlan4_gpe_tunnel_key_t), sizeof (uword));
Hongjun Nidf921cc2016-05-25 01:16:19 +08001229
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001230 ngm->vxlan6_gpe_tunnel_by_key
sharath reddy6f8273a2017-12-11 11:31:31 +05301231 = hash_create_mem (0, sizeof (vxlan6_gpe_tunnel_key_t), sizeof (uword));
Hongjun Nidf921cc2016-05-25 01:16:19 +08001232
1233
sharath reddy6f8273a2017-12-11 11:31:31 +05301234 ngm->mcast_shared = hash_create_mem (0,
1235 sizeof (ip46_address_t),
1236 sizeof (mcast_shared_t));
Nick Zavaritsky27518c22020-02-27 15:54:58 +00001237 ngm->vtep_table = vtep_table_create ();
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001238
Vengada Govindan6d403a02016-10-12 05:54:09 -07001239 /* Register the list of standard decap protocols supported */
1240 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4,
sharath reddy6f8273a2017-12-11 11:31:31 +05301241 VXLAN_GPE_INPUT_NEXT_IP4_INPUT);
Vengada Govindan6d403a02016-10-12 05:54:09 -07001242 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6,
sharath reddy6f8273a2017-12-11 11:31:31 +05301243 VXLAN_GPE_INPUT_NEXT_IP6_INPUT);
Vengada Govindan6d403a02016-10-12 05:54:09 -07001244 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET,
Gabriel Ganne7e665d62017-11-17 09:18:53 +01001245 VXLAN_GPE_INPUT_NEXT_L2_INPUT);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001246
sharath reddy6f8273a2017-12-11 11:31:31 +05301247 fib_node_register_type (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001248
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001249 return 0;
1250}
1251
sharath reddy6f8273a2017-12-11 11:31:31 +05301252VLIB_INIT_FUNCTION (vxlan_gpe_init);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001253
sharath reddy6f8273a2017-12-11 11:31:31 +05301254
1255/*
1256 * fd.io coding-style-patch-verification: ON
1257 *
1258 * Local Variables:
1259 * eval: (c-set-style "gnu")
1260 * End:
1261 */