blob: dd0e544352f48f060c15a00ce1c07ce26aa1a86a [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>
25#include <vnet/mfib/mfib_table.h>
26#include <vnet/adj/adj_mcast.h>
27#include <vnet/interface.h>
28#include <vlib/vlib.h>
29
30/**
31 * @file
32 * @brief VXLAN-GPE.
33 *
34 * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
35 * to span multiple servers. This is done by building an L2 overlay on
36 * top of an L3 network underlay using VXLAN-GPE tunnels.
37 *
38 * This makes it possible for servers to be co-located in the same data
39 * center or be separated geographically as long as they are reachable
40 * through the underlay L3 network.
41 *
42 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
43 */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070044
45vxlan_gpe_main_t vxlan_gpe_main;
46
John Lo4478d8e2018-01-12 17:15:25 -050047static u8 *
48format_decap_next (u8 * s, va_list * args)
49{
50 vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
51
52 switch (t->protocol)
53 {
54 case VXLAN_GPE_PROTOCOL_IP4:
55 s = format (s, "protocol ip4 fib-idx %d", t->decap_fib_index);
56 break;
57 case VXLAN_GPE_PROTOCOL_IP6:
58 s = format (s, "protocol ip6 fib-idx %d", t->decap_fib_index);
59 break;
60 case VXLAN_GPE_PROTOCOL_ETHERNET:
61 s = format (s, "protocol ethernet");
62 break;
63 case VXLAN_GPE_PROTOCOL_NSH:
64 s = format (s, "protocol nsh");
65 break;
66 default:
67 s = format (s, "protocol unknown %d", t->protocol);
68 }
69
70 return s;
71}
72
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070073/**
John Lo4478d8e2018-01-12 17:15:25 -050074 * @brief Format function for VXLAN GPE tunnel
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070075 *
76 * @param *s formatting string
77 * @param *args
78 *
79 * @return *s formatted string
80 *
81 */
sharath reddy6f8273a2017-12-11 11:31:31 +053082u8 *
83format_vxlan_gpe_tunnel (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070084{
sharath reddy6f8273a2017-12-11 11:31:31 +053085 vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
86 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070087
John Lo4478d8e2018-01-12 17:15:25 -050088 s = format (s, "[%d] lcl %U rmt %U vni %d fib-idx %d sw-if-idx %d ",
sharath reddy6f8273a2017-12-11 11:31:31 +053089 t - ngm->tunnels,
90 format_ip46_address, &t->local, IP46_TYPE_ANY,
John Lo4478d8e2018-01-12 17:15:25 -050091 format_ip46_address, &t->remote, IP46_TYPE_ANY,
92 t->vni, t->encap_fib_index, t->sw_if_index);
Hongjun Nidf921cc2016-05-25 01:16:19 +080093
John Lo4478d8e2018-01-12 17:15:25 -050094#if 0
95 /* next_dpo not yet used by vxlan-gpe-encap node */
96 s = format (s, "encap-dpo-idx %d ", t->next_dpo.dpoi_index);
97 */
98#endif
99 s = format (s, "decap-next-%U ", format_decap_next, t);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700100
John Lo4478d8e2018-01-12 17:15:25 -0500101 if (PREDICT_FALSE (ip46_address_is_multicast (&t->remote)))
102 s = format (s, "mcast-sw-if-idx %d ", t->mcast_sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700103
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700104 return s;
105}
106
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700107/**
108 * @brief Naming for VXLAN GPE tunnel
109 *
110 * @param *s formatting string
111 * @param *args
112 *
113 * @return *s formatted string
114 *
115 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530116static u8 *
117format_vxlan_gpe_name (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700118{
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800119 u32 dev_instance = va_arg (*args, u32);
120 return format (s, "vxlan_gpe_tunnel%d", dev_instance);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700121}
122
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700123/**
124 * @brief CLI function for VXLAN GPE admin up/down
125 *
126 * @param *vnm
127 * @param hw_if_index
128 * @param flag
129 *
130 * @return *rc
131 *
132 */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800133static clib_error_t *
sharath reddy6f8273a2017-12-11 11:31:31 +0530134vxlan_gpe_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
135 u32 flags)
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800136{
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800137 u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
138 VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
139 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800140
141 return 0;
142}
143
sharath reddy6f8273a2017-12-11 11:31:31 +0530144/* *INDENT-OFF* */
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800145VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
146 .name = "VXLAN_GPE",
147 .format_device_name = format_vxlan_gpe_name,
148 .format_tx_trace = format_vxlan_gpe_encap_trace,
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800149 .admin_up_down_function = vxlan_gpe_interface_admin_up_down,
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800150};
sharath reddy6f8273a2017-12-11 11:31:31 +0530151/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700152
Vengada Govindan6d403a02016-10-12 05:54:09 -0700153
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700154/**
155 * @brief Formatting function for tracing VXLAN GPE with length
156 *
157 * @param *s
158 * @param *args
159 *
160 * @return *s
161 *
162 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530163static u8 *
164format_vxlan_gpe_header_with_length (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700165{
166 u32 dev_instance = va_arg (*args, u32);
167 s = format (s, "unimplemented dev %u", dev_instance);
168 return s;
169}
170
sharath reddy6f8273a2017-12-11 11:31:31 +0530171/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700172VNET_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};
sharath reddy6f8273a2017-12-11 11:31:31 +0530177/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700178
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800179static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530180vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_t * t)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800181{
sharath reddy6f8273a2017-12-11 11:31:31 +0530182 dpo_id_t dpo = DPO_INVALID;
183 u32 encap_index = vxlan_gpe_encap_node.index;
184 fib_forward_chain_type_t forw_type = ip46_address_is_ip4 (&t->remote) ?
185 FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800186
sharath reddy6f8273a2017-12-11 11:31:31 +0530187 fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
188 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
189 dpo_reset (&dpo);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800190}
191
192static vxlan_gpe_tunnel_t *
sharath reddy6f8273a2017-12-11 11:31:31 +0530193vxlan_gpe_tunnel_from_fib_node (fib_node_t * node)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800194{
sharath reddy6f8273a2017-12-11 11:31:31 +0530195 ASSERT (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL == node->fn_type);
196 return ((vxlan_gpe_tunnel_t *) (((char *) node) -
197 STRUCT_OFFSET_OF (vxlan_gpe_tunnel_t,
198 node)));
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800199}
200
201/**
202 * Function definition to backwalk a FIB node -
203 * Here we will restack the new dpo of VXLAN_GPE DIP to encap node.
204 */
205static fib_node_back_walk_rc_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530206vxlan_gpe_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800207{
sharath reddy6f8273a2017-12-11 11:31:31 +0530208 vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_from_fib_node (node));
209 return (FIB_NODE_BACK_WALK_CONTINUE);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800210}
211
212/**
213 * Function definition to get a FIB node from its index
214 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530215static fib_node_t *
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800216vxlan_gpe_tunnel_fib_node_get (fib_node_index_t index)
217{
sharath reddy6f8273a2017-12-11 11:31:31 +0530218 vxlan_gpe_tunnel_t *t;
219 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800220
sharath reddy6f8273a2017-12-11 11:31:31 +0530221 t = pool_elt_at_index (ngm->tunnels, index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800222
sharath reddy6f8273a2017-12-11 11:31:31 +0530223 return (&t->node);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800224}
225
226/**
227 * Function definition to inform the FIB node that its last lock has gone.
228 */
229static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530230vxlan_gpe_tunnel_last_lock_gone (fib_node_t * node)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800231{
sharath reddy6f8273a2017-12-11 11:31:31 +0530232 /*
233 * The VXLAN_GPE tunnel is a root of the graph. As such
234 * it never has children and thus is never locked.
235 */
236 ASSERT (0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800237}
238
239/*
240 * Virtual function table registered by VXLAN_GPE tunnels
241 * for participation in the FIB object graph.
242 */
243const static fib_node_vft_t vxlan_gpe_vft = {
sharath reddy6f8273a2017-12-11 11:31:31 +0530244 .fnv_get = vxlan_gpe_tunnel_fib_node_get,
245 .fnv_last_lock = vxlan_gpe_tunnel_last_lock_gone,
246 .fnv_back_walk = vxlan_gpe_tunnel_back_walk,
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800247};
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700248
249#define foreach_gpe_copy_field \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700250_(vni) \
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800251_(protocol) \
252_(mcast_sw_if_index) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700253_(encap_fib_index) \
Hongjun Ni7deb1392016-06-15 22:49:23 +0800254_(decap_fib_index)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700255
Hongjun Nidf921cc2016-05-25 01:16:19 +0800256#define foreach_copy_ipv4 { \
257 _(local.ip4.as_u32) \
258 _(remote.ip4.as_u32) \
259}
260
261#define foreach_copy_ipv6 { \
262 _(local.ip6.as_u64[0]) \
263 _(local.ip6.as_u64[1]) \
264 _(remote.ip6.as_u64[0]) \
265 _(remote.ip6.as_u64[1]) \
266}
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700267
268
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700269/**
270 * @brief Calculate IPv4 VXLAN GPE rewrite header
271 *
272 * @param *t
273 *
274 * @return rc
275 *
276 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530277int
278vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
279 u8 protocol_override, uword encap_next_node)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700280{
281 u8 *rw = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530282 ip4_header_t *ip0;
283 ip4_vxlan_gpe_header_t *h0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700284 int len;
285
Vengada Govindan6d403a02016-10-12 05:54:09 -0700286 len = sizeof (*h0) + extension_size;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700287
sharath reddy6f8273a2017-12-11 11:31:31 +0530288 vec_free (t->rewrite);
289 vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700290
291 h0 = (ip4_vxlan_gpe_header_t *) rw;
292
293 /* Fixed portion of the (outer) ip4 header */
294 ip0 = &h0->ip4;
295 ip0->ip_version_and_header_length = 0x45;
296 ip0->ttl = 254;
297 ip0->protocol = IP_PROTOCOL_UDP;
298
299 /* we fix up the ip4 header length and checksum after-the-fact */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800300 ip0->src_address.as_u32 = t->local.ip4.as_u32;
301 ip0->dst_address.as_u32 = t->remote.ip4.as_u32;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700302 ip0->checksum = ip4_header_checksum (ip0);
303
304 /* UDP header, randomize src port on something, maybe? */
305 h0->udp.src_port = clib_host_to_net_u16 (4790);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800306 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700307
308 /* VXLAN header. Are we having fun yet? */
309 h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
310 h0->vxlan.ver_res = VXLAN_GPE_VERSION;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700311 if (protocol_override)
sharath reddy6f8273a2017-12-11 11:31:31 +0530312 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700313 h0->vxlan.protocol = protocol_override;
sharath reddy6f8273a2017-12-11 11:31:31 +0530314 }
Vengada Govindan6d403a02016-10-12 05:54:09 -0700315 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530316 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700317 h0->vxlan.protocol = t->protocol;
sharath reddy6f8273a2017-12-11 11:31:31 +0530318 }
319 t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
320 h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700321
322 t->rewrite = rw;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700323 t->encap_next_node = encap_next_node;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700324 return (0);
325}
326
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700327/**
328 * @brief Calculate IPv6 VXLAN GPE rewrite header
329 *
330 * @param *t
331 *
332 * @return rc
333 *
334 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530335int
336vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
337 u8 protocol_override, uword encap_next_node)
Hongjun Nidf921cc2016-05-25 01:16:19 +0800338{
339 u8 *rw = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530340 ip6_header_t *ip0;
341 ip6_vxlan_gpe_header_t *h0;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800342 int len;
343
Vengada Govindan6d403a02016-10-12 05:54:09 -0700344 len = sizeof (*h0) + extension_size;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800345
sharath reddy6f8273a2017-12-11 11:31:31 +0530346 vec_free (t->rewrite);
347 vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800348
349 h0 = (ip6_vxlan_gpe_header_t *) rw;
350
351 /* Fixed portion of the (outer) ip4 header */
352 ip0 = &h0->ip6;
sharath reddy6f8273a2017-12-11 11:31:31 +0530353 ip0->ip_version_traffic_class_and_flow_label =
354 clib_host_to_net_u32 (6 << 28);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800355 ip0->hop_limit = 255;
356 ip0->protocol = IP_PROTOCOL_UDP;
357
358 ip0->src_address.as_u64[0] = t->local.ip6.as_u64[0];
359 ip0->src_address.as_u64[1] = t->local.ip6.as_u64[1];
360 ip0->dst_address.as_u64[0] = t->remote.ip6.as_u64[0];
361 ip0->dst_address.as_u64[1] = t->remote.ip6.as_u64[1];
362
363 /* UDP header, randomize src port on something, maybe? */
364 h0->udp.src_port = clib_host_to_net_u16 (4790);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800365 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800366
367 /* VXLAN header. Are we having fun yet? */
368 h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
369 h0->vxlan.ver_res = VXLAN_GPE_VERSION;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700370 if (protocol_override)
sharath reddy6f8273a2017-12-11 11:31:31 +0530371 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700372 h0->vxlan.protocol = t->protocol;
sharath reddy6f8273a2017-12-11 11:31:31 +0530373 }
Vengada Govindan6d403a02016-10-12 05:54:09 -0700374 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530375 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700376 h0->vxlan.protocol = protocol_override;
sharath reddy6f8273a2017-12-11 11:31:31 +0530377 }
378 t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
379 h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800380
381 t->rewrite = rw;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700382 t->encap_next_node = encap_next_node;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800383 return (0);
384}
385
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800386static uword
sharath reddy6f8273a2017-12-11 11:31:31 +0530387vtep_addr_ref (ip46_address_t * ip)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800388{
sharath reddy6f8273a2017-12-11 11:31:31 +0530389 uword *vtep = ip46_address_is_ip4 (ip) ?
390 hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
391 hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
392 if (vtep)
393 return ++(*vtep);
394 ip46_address_is_ip4 (ip) ?
395 hash_set (vxlan_gpe_main.vtep4, ip->ip4.as_u32, 1) :
John Loe6bfeab2018-01-04 16:39:42 -0500396 hash_set_mem_alloc (&vxlan_gpe_main.vtep6, &ip->ip6, 1);
sharath reddy6f8273a2017-12-11 11:31:31 +0530397 return 1;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800398}
399
400static uword
sharath reddy6f8273a2017-12-11 11:31:31 +0530401vtep_addr_unref (ip46_address_t * ip)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800402{
sharath reddy6f8273a2017-12-11 11:31:31 +0530403 uword *vtep = ip46_address_is_ip4 (ip) ?
404 hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
405 hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
406 ASSERT (vtep);
407 if (--(*vtep) != 0)
408 return *vtep;
409 ip46_address_is_ip4 (ip) ?
410 hash_unset (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
John Loe6bfeab2018-01-04 16:39:42 -0500411 hash_unset_mem_free (&vxlan_gpe_main.vtep6, &ip->ip6);
sharath reddy6f8273a2017-12-11 11:31:31 +0530412 return 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800413}
414
sharath reddy6f8273a2017-12-11 11:31:31 +0530415/* *INDENT-OFF* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800416typedef CLIB_PACKED(union {
417 struct {
418 fib_node_index_t mfib_entry_index;
419 adj_index_t mcast_adj_index;
420 };
421 u64 as_u64;
422}) mcast_shared_t;
sharath reddy6f8273a2017-12-11 11:31:31 +0530423/* *INDENT-ON* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800424
425static inline mcast_shared_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530426mcast_shared_get (ip46_address_t * ip)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800427{
sharath reddy6f8273a2017-12-11 11:31:31 +0530428 ASSERT (ip46_address_is_multicast (ip));
429 uword *p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip);
430 ASSERT (p);
431 return (mcast_shared_t)
432 {
433 .as_u64 = *p};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800434}
435
436static inline void
sharath reddy6f8273a2017-12-11 11:31:31 +0530437mcast_shared_add (ip46_address_t * remote,
438 fib_node_index_t mfei, adj_index_t ai)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800439{
sharath reddy6f8273a2017-12-11 11:31:31 +0530440 mcast_shared_t new_ep = {
441 .mcast_adj_index = ai,
442 .mfib_entry_index = mfei,
443 };
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800444
John Loe6bfeab2018-01-04 16:39:42 -0500445 hash_set_mem_alloc (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800446}
447
448static inline void
sharath reddy6f8273a2017-12-11 11:31:31 +0530449mcast_shared_remove (ip46_address_t * remote)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800450{
sharath reddy6f8273a2017-12-11 11:31:31 +0530451 mcast_shared_t ep = mcast_shared_get (remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800452
sharath reddy6f8273a2017-12-11 11:31:31 +0530453 adj_unlock (ep.mcast_adj_index);
454 mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_VXLAN_GPE);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800455
John Loe6bfeab2018-01-04 16:39:42 -0500456 hash_unset_mem_free (&vxlan_gpe_main.mcast_shared, remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800457}
458
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700459/**
460 * @brief Add or Del a VXLAN GPE tunnel
461 *
462 * @param *a
463 * @param *sw_if_index
464 *
465 * @return rc
466 *
467 */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800468int vnet_vxlan_gpe_add_del_tunnel
sharath reddy6f8273a2017-12-11 11:31:31 +0530469 (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700470{
sharath reddy6f8273a2017-12-11 11:31:31 +0530471 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700472 vxlan_gpe_tunnel_t *t = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530473 vnet_main_t *vnm = ngm->vnet_main;
474 vnet_hw_interface_t *hi;
475 uword *p;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700476 u32 hw_if_index = ~0;
477 u32 sw_if_index = ~0;
478 int rv;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800479 vxlan4_gpe_tunnel_key_t key4, *key4_copy;
480 vxlan6_gpe_tunnel_key_t key6, *key6_copy;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800481 u32 is_ip6 = a->is_ip6;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800482
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800483 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530484 {
485 key4.local = a->local.ip4.as_u32;
486 key4.remote = a->remote.ip4.as_u32;
487 key4.vni = clib_host_to_net_u32 (a->vni << 8);
488 key4.pad = 0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700489
sharath reddy6f8273a2017-12-11 11:31:31 +0530490 p = hash_get_mem (ngm->vxlan4_gpe_tunnel_by_key, &key4);
491 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800492 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530493 {
494 key6.local.as_u64[0] = a->local.ip6.as_u64[0];
495 key6.local.as_u64[1] = a->local.ip6.as_u64[1];
496 key6.remote.as_u64[0] = a->remote.ip6.as_u64[0];
497 key6.remote.as_u64[1] = a->remote.ip6.as_u64[1];
498 key6.vni = clib_host_to_net_u32 (a->vni << 8);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800499
sharath reddy6f8273a2017-12-11 11:31:31 +0530500 p = hash_get_mem (ngm->vxlan6_gpe_tunnel_by_key, &key6);
501 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800502
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700503 if (a->is_add)
504 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530505 l2input_main_t *l2im = &l2input_main;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800506
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700507 /* adding a tunnel: tunnel must not already exist */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800508 if (p)
sharath reddy6f8273a2017-12-11 11:31:31 +0530509 return VNET_API_ERROR_TUNNEL_EXIST;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800510
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800511 pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
Dave Barachb7b92992018-10-17 10:38:51 -0400512 clib_memset (t, 0, sizeof (*t));
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800513
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700514 /* copy from arg structure */
John Loe6bfeab2018-01-04 16:39:42 -0500515/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700516#define _(x) t->x = a->x;
517 foreach_gpe_copy_field;
sharath reddy6f8273a2017-12-11 11:31:31 +0530518 if (!a->is_ip6)
519 foreach_copy_ipv4
John Loe6bfeab2018-01-04 16:39:42 -0500520 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530521 foreach_copy_ipv6
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700522#undef _
John Loe6bfeab2018-01-04 16:39:42 -0500523/* *INDENT-ON* */
524
525 if (!a->is_ip6)
526 t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700527
sharath reddy6f8273a2017-12-11 11:31:31 +0530528 if (!a->is_ip6)
529 {
530 rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
531 }
532 else
533 {
534 rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
535 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700536
537 if (rv)
sharath reddy6f8273a2017-12-11 11:31:31 +0530538 {
539 pool_put (ngm->tunnels, t);
540 return rv;
541 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700542
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800543 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530544 {
545 key4_copy = clib_mem_alloc (sizeof (*key4_copy));
Dave Barach178cf492018-11-13 16:34:13 -0500546 clib_memcpy_fast (key4_copy, &key4, sizeof (*key4_copy));
sharath reddy6f8273a2017-12-11 11:31:31 +0530547 hash_set_mem (ngm->vxlan4_gpe_tunnel_by_key, key4_copy,
548 t - ngm->tunnels);
549 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800550 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530551 {
552 key6_copy = clib_mem_alloc (sizeof (*key6_copy));
Dave Barach178cf492018-11-13 16:34:13 -0500553 clib_memcpy_fast (key6_copy, &key6, sizeof (*key6_copy));
sharath reddy6f8273a2017-12-11 11:31:31 +0530554 hash_set_mem (ngm->vxlan6_gpe_tunnel_by_key, key6_copy,
555 t - ngm->tunnels);
556 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800557
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800558 if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0)
sharath reddy6f8273a2017-12-11 11:31:31 +0530559 {
560 vnet_interface_main_t *im = &vnm->interface_main;
561 hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
562 [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) - 1];
563 _vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) -= 1;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800564
sharath reddy6f8273a2017-12-11 11:31:31 +0530565 hi = vnet_get_hw_interface (vnm, hw_if_index);
566 hi->dev_instance = t - ngm->tunnels;
567 hi->hw_instance = hi->dev_instance;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800568 /* clear old stats of freed tunnel before reuse */
569 sw_if_index = hi->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530570 vnet_interface_counter_lock (im);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800571 vlib_zero_combined_counter
sharath reddy6f8273a2017-12-11 11:31:31 +0530572 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
573 sw_if_index);
574 vlib_zero_combined_counter (&im->combined_sw_if_counters
575 [VNET_INTERFACE_COUNTER_RX],
576 sw_if_index);
577 vlib_zero_simple_counter (&im->sw_if_counters
578 [VNET_INTERFACE_COUNTER_DROP],
579 sw_if_index);
580 vnet_interface_counter_unlock (im);
581 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800582 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530583 {
584 hw_if_index = vnet_register_interface
585 (vnm, vxlan_gpe_device_class.index, t - ngm->tunnels,
586 vxlan_gpe_hw_class.index, t - ngm->tunnels);
587 hi = vnet_get_hw_interface (vnm, hw_if_index);
sharath reddy6f8273a2017-12-11 11:31:31 +0530588 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800589
John Loe5453d02018-01-23 19:21:34 -0500590 /* Set vxlan-gpe tunnel output node */
591 u32 encap_index = vxlan_gpe_encap_node.index;
592 vnet_set_interface_output_node (vnm, hw_if_index, encap_index);
593
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700594 t->hw_if_index = hw_if_index;
595 t->sw_if_index = sw_if_index = hi->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530596 vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index,
597 ~0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800598 ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800599
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800600 /* setup l2 input config with l2 feature and bd 0 to drop packet */
601 vec_validate (l2im->configs, sw_if_index);
602 l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
603 l2im->configs[sw_if_index].bd_index = 0;
604
sharath reddy6f8273a2017-12-11 11:31:31 +0530605 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800606 si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800607 vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
sharath reddy6f8273a2017-12-11 11:31:31 +0530608 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
609 fib_node_init (&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800610 fib_prefix_t tun_remote_pfx;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800611 vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
612
sharath reddy6f8273a2017-12-11 11:31:31 +0530613 fib_prefix_from_ip46_addr (&t->remote, &tun_remote_pfx);
614 if (!ip46_address_is_multicast (&t->remote))
615 {
616 /* Unicast tunnel -
617 * source the FIB entry for the tunnel's destination
618 * and become a child thereof. The tunnel will then get poked
619 * when the forwarding for the entry updates, and the tunnel can
620 * re-stack accordingly
621 */
622 vtep_addr_ref (&t->local);
623 t->fib_entry_index = fib_table_entry_special_add
624 (t->encap_fib_index, &tun_remote_pfx, FIB_SOURCE_RR,
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800625 FIB_ENTRY_FLAG_NONE);
sharath reddy6f8273a2017-12-11 11:31:31 +0530626 t->sibling_index = fib_entry_child_add
627 (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL,
628 t - ngm->tunnels);
629 vxlan_gpe_tunnel_restack_dpo (t);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800630 }
631 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530632 {
633 /* Multicast tunnel -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700634 * as the same mcast group can be used for multiple mcast tunnels
635 * with different VNIs, create the output fib adjacency only if
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800636 * it does not already exist
637 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530638 fib_protocol_t fp = fib_ip_proto (is_ip6);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800639
sharath reddy6f8273a2017-12-11 11:31:31 +0530640 if (vtep_addr_ref (&t->remote) == 1)
641 {
642 fib_node_index_t mfei;
643 adj_index_t ai;
644 fib_route_path_t path = {
645 .frp_proto = fib_proto_to_dpo (fp),
646 .frp_addr = zero_addr,
647 .frp_sw_if_index = 0xffffffff,
648 .frp_fib_index = ~0,
Neale Ranns097fa662018-05-01 05:17:55 -0700649 .frp_weight = 1,
sharath reddy6f8273a2017-12-11 11:31:31 +0530650 .frp_flags = FIB_ROUTE_PATH_LOCAL,
Neale Ranns097fa662018-05-01 05:17:55 -0700651 .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
sharath reddy6f8273a2017-12-11 11:31:31 +0530652 };
653 const mfib_prefix_t mpfx = {
654 .fp_proto = fp,
655 .fp_len = (is_ip6 ? 128 : 32),
656 .fp_grp_addr = tun_remote_pfx.fp_addr,
657 };
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800658
sharath reddy6f8273a2017-12-11 11:31:31 +0530659 /*
660 * Setup the (*,G) to receive traffic on the mcast group
661 * - the forwarding interface is for-us
662 * - the accepting interface is that from the API
663 */
664 mfib_table_entry_path_update (t->encap_fib_index,
665 &mpfx,
Neale Ranns097fa662018-05-01 05:17:55 -0700666 MFIB_SOURCE_VXLAN_GPE, &path);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800667
sharath reddy6f8273a2017-12-11 11:31:31 +0530668 path.frp_sw_if_index = a->mcast_sw_if_index;
669 path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
Neale Ranns097fa662018-05-01 05:17:55 -0700670 path.frp_mitf_flags = MFIB_ITF_FLAG_ACCEPT;
sharath reddy6f8273a2017-12-11 11:31:31 +0530671 mfei = mfib_table_entry_path_update (t->encap_fib_index,
672 &mpfx,
673 MFIB_SOURCE_VXLAN_GPE,
Neale Ranns097fa662018-05-01 05:17:55 -0700674 &path);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800675
sharath reddy6f8273a2017-12-11 11:31:31 +0530676 /*
677 * Create the mcast adjacency to send traffic to the group
678 */
679 ai = adj_mcast_add_or_lock (fp,
680 fib_proto_to_link (fp),
681 a->mcast_sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800682
sharath reddy6f8273a2017-12-11 11:31:31 +0530683 /*
684 * create a new end-point
685 */
686 mcast_shared_add (&t->remote, mfei, ai);
687 }
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800688
sharath reddy6f8273a2017-12-11 11:31:31 +0530689 dpo_id_t dpo = DPO_INVALID;
690 mcast_shared_t ep = mcast_shared_get (&t->remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800691
sharath reddy6f8273a2017-12-11 11:31:31 +0530692 /* Stack shared mcast remote mac addr rewrite on encap */
693 dpo_set (&dpo, DPO_ADJACENCY_MCAST,
694 fib_proto_to_dpo (fp), ep.mcast_adj_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800695
sharath reddy6f8273a2017-12-11 11:31:31 +0530696 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
697 dpo_reset (&dpo);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800698 flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
699 }
700
sharath reddy6f8273a2017-12-11 11:31:31 +0530701 vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
702 flood_class;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700703 }
704 else
705 {
706 /* deleting a tunnel: tunnel must exist */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800707 if (!p)
sharath reddy6f8273a2017-12-11 11:31:31 +0530708 return VNET_API_ERROR_NO_SUCH_ENTRY;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700709
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800710 t = pool_elt_at_index (ngm->tunnels, p[0]);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700711
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800712 sw_if_index = t->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530713 vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
714 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, t->sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800715 si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
Neale Rannsb4743802018-09-05 09:13:57 -0700716 set_int_l2_mode (ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0,
717 L2_BD_PORT_TYPE_NORMAL, 0, 0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800718 vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700719
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800720 ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
Hongjun Nic0959c92016-06-16 20:18:15 +0800721
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800722 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530723 hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800724 else
John Loe6bfeab2018-01-04 16:39:42 -0500725 hash_unset_mem_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700726
sharath reddy6f8273a2017-12-11 11:31:31 +0530727 if (!ip46_address_is_multicast (&t->remote))
728 {
729 vtep_addr_unref (&t->local);
730 fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
731 fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
732 }
733 else if (vtep_addr_unref (&t->remote) == 0)
734 {
735 mcast_shared_remove (&t->remote);
736 }
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800737
sharath reddy6f8273a2017-12-11 11:31:31 +0530738 fib_node_deinit (&t->node);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700739 vec_free (t->rewrite);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800740 pool_put (ngm->tunnels, t);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700741 }
742
743 if (sw_if_indexp)
sharath reddy6f8273a2017-12-11 11:31:31 +0530744 *sw_if_indexp = sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700745
Jakub Grajciardf3ca232019-06-04 13:16:42 +0200746 if (a->is_add)
747 {
748 /* register udp ports */
749 if (!is_ip6 && !udp_is_valid_dst_port (UDP_DST_PORT_VXLAN_GPE, 1))
750 udp_register_dst_port (ngm->vlib_main, UDP_DST_PORT_VXLAN_GPE,
751 vxlan4_gpe_input_node.index, 1 /* is_ip4 */ );
752 if (is_ip6 && !udp_is_valid_dst_port (UDP_DST_PORT_VXLAN6_GPE, 0))
753 udp_register_dst_port (ngm->vlib_main, UDP_DST_PORT_VXLAN6_GPE,
754 vxlan6_gpe_input_node.index, 0 /* is_ip4 */ );
755 }
756
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700757 return 0;
758}
759
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700760static clib_error_t *
761vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +0530762 unformat_input_t * input,
763 vlib_cli_command_t * cmd)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700764{
sharath reddy6f8273a2017-12-11 11:31:31 +0530765 unformat_input_t _line_input, *line_input = &_line_input;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700766 u8 is_add = 1;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800767 ip46_address_t local, remote;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700768 u8 local_set = 0;
769 u8 remote_set = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800770 u8 grp_set = 0;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800771 u8 ipv4_set = 0;
772 u8 ipv6_set = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800773 u32 mcast_sw_if_index = ~0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700774 u32 encap_fib_index = 0;
775 u32 decap_fib_index = 0;
776 u8 protocol = VXLAN_GPE_PROTOCOL_IP4;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700777 u32 vni;
778 u8 vni_set = 0;
779 int rv;
780 u32 tmp;
sharath reddy6f8273a2017-12-11 11:31:31 +0530781 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
Pierre Pfister78ea9c22016-05-23 12:51:54 +0100782 u32 sw_if_index;
Billy McFalla9a20e72017-02-15 11:39:12 -0500783 clib_error_t *error = NULL;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800784
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700785 /* Get a line of input. */
sharath reddy6f8273a2017-12-11 11:31:31 +0530786 if (!unformat_user (input, unformat_line_input, line_input))
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700787 return 0;
788
sharath reddy6f8273a2017-12-11 11:31:31 +0530789 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Hongjun Nidf921cc2016-05-25 01:16:19 +0800790 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530791 if (unformat (line_input, "del"))
792 is_add = 0;
793 else if (unformat (line_input, "local %U",
794 unformat_ip4_address, &local.ip4))
795 {
796 local_set = 1;
797 ipv4_set = 1;
798 }
799 else if (unformat (line_input, "remote %U",
800 unformat_ip4_address, &remote.ip4))
801 {
802 remote_set = 1;
803 ipv4_set = 1;
804 }
805 else if (unformat (line_input, "local %U",
806 unformat_ip6_address, &local.ip6))
807 {
808 local_set = 1;
809 ipv6_set = 1;
810 }
811 else if (unformat (line_input, "remote %U",
812 unformat_ip6_address, &remote.ip6))
813 {
814 remote_set = 1;
815 ipv6_set = 1;
816 }
817 else if (unformat (line_input, "group %U %U",
818 unformat_ip4_address, &remote.ip4,
819 unformat_vnet_sw_interface,
820 vnet_get_main (), &mcast_sw_if_index))
821 {
822 grp_set = remote_set = 1;
823 ipv4_set = 1;
824 }
825 else if (unformat (line_input, "group %U %U",
826 unformat_ip6_address, &remote.ip6,
827 unformat_vnet_sw_interface,
828 vnet_get_main (), &mcast_sw_if_index))
829 {
830 grp_set = remote_set = 1;
831 ipv6_set = 1;
832 }
833 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
834 {
835 if (ipv6_set)
836 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
837 else
838 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800839
sharath reddy6f8273a2017-12-11 11:31:31 +0530840 if (encap_fib_index == ~0)
841 {
842 error =
843 clib_error_return (0, "nonexistent encap fib id %d", tmp);
844 goto done;
845 }
846 }
847 else if (unformat (line_input, "decap-vrf-id %d", &tmp))
848 {
849 if (ipv6_set)
850 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
851 else
852 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800853
sharath reddy6f8273a2017-12-11 11:31:31 +0530854 if (decap_fib_index == ~0)
855 {
856 error =
857 clib_error_return (0, "nonexistent decap fib id %d", tmp);
858 goto done;
859 }
860 }
861 else if (unformat (line_input, "vni %d", &vni))
862 vni_set = 1;
863 else if (unformat (line_input, "next-ip4"))
864 protocol = VXLAN_GPE_PROTOCOL_IP4;
865 else if (unformat (line_input, "next-ip6"))
866 protocol = VXLAN_GPE_PROTOCOL_IP6;
867 else if (unformat (line_input, "next-ethernet"))
868 protocol = VXLAN_GPE_PROTOCOL_ETHERNET;
869 else if (unformat (line_input, "next-nsh"))
870 protocol = VXLAN_GPE_PROTOCOL_NSH;
871 else
872 {
873 error = clib_error_return (0, "parse error: '%U'",
874 format_unformat_error, line_input);
875 goto done;
876 }
877 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700878
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700879 if (local_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500880 {
881 error = clib_error_return (0, "tunnel local address not specified");
882 goto done;
883 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700884
885 if (remote_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500886 {
887 error = clib_error_return (0, "tunnel remote address not specified");
888 goto done;
889 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700890
sharath reddy6f8273a2017-12-11 11:31:31 +0530891 if (grp_set && !ip46_address_is_multicast (&remote))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800892 {
893 error = clib_error_return (0, "tunnel group address not multicast");
894 goto done;
895 }
896
sharath reddy6f8273a2017-12-11 11:31:31 +0530897 if (grp_set == 0 && ip46_address_is_multicast (&remote))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800898 {
899 error = clib_error_return (0, "remote address must be unicast");
900 goto done;
901 }
902
903 if (grp_set && mcast_sw_if_index == ~0)
904 {
905 error = clib_error_return (0, "tunnel nonexistent multicast device");
906 goto done;
907 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800908 if (ipv4_set && ipv6_set)
Billy McFalla9a20e72017-02-15 11:39:12 -0500909 {
910 error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
911 goto done;
912 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800913
sharath reddy6f8273a2017-12-11 11:31:31 +0530914 if ((ipv4_set && memcmp (&local.ip4, &remote.ip4, sizeof (local.ip4)) == 0)
915 || (ipv6_set
916 && memcmp (&local.ip6, &remote.ip6, sizeof (local.ip6)) == 0))
Billy McFalla9a20e72017-02-15 11:39:12 -0500917 {
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800918 error = clib_error_return (0, "src and remote addresses are identical");
Billy McFalla9a20e72017-02-15 11:39:12 -0500919 goto done;
920 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800921
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700922 if (vni_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500923 {
924 error = clib_error_return (0, "vni not specified");
925 goto done;
926 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700927
Dave Barachb7b92992018-10-17 10:38:51 -0400928 clib_memset (a, 0, sizeof (*a));
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700929
930 a->is_add = is_add;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800931 a->is_ip6 = ipv6_set;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700932
John Loe6bfeab2018-01-04 16:39:42 -0500933/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700934#define _(x) a->x = x;
935 foreach_gpe_copy_field;
sharath reddy6f8273a2017-12-11 11:31:31 +0530936 if (ipv4_set)
937 foreach_copy_ipv4
John Loe6bfeab2018-01-04 16:39:42 -0500938 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530939 foreach_copy_ipv6
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700940#undef _
John Loe6bfeab2018-01-04 16:39:42 -0500941/* *INDENT-ON* */
942
943 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700944
sharath reddy6f8273a2017-12-11 11:31:31 +0530945 switch (rv)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700946 {
947 case 0:
sharath reddy6f8273a2017-12-11 11:31:31 +0530948 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
949 vnet_get_main (), sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700950 break;
951 case VNET_API_ERROR_INVALID_DECAP_NEXT:
Billy McFalla9a20e72017-02-15 11:39:12 -0500952 error = clib_error_return (0, "invalid decap-next...");
953 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700954
955 case VNET_API_ERROR_TUNNEL_EXIST:
Billy McFalla9a20e72017-02-15 11:39:12 -0500956 error = clib_error_return (0, "tunnel already exists...");
957 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700958
959 case VNET_API_ERROR_NO_SUCH_ENTRY:
Billy McFalla9a20e72017-02-15 11:39:12 -0500960 error = clib_error_return (0, "tunnel does not exist...");
961 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700962
963 default:
Billy McFalla9a20e72017-02-15 11:39:12 -0500964 error = clib_error_return
sharath reddy6f8273a2017-12-11 11:31:31 +0530965 (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500966 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700967 }
968
Billy McFalla9a20e72017-02-15 11:39:12 -0500969done:
970 unformat_free (line_input);
971
972 return error;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700973}
974
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800975/*?
976 * Add or delete a VXLAN-GPE Tunnel.
977 *
978 * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
979 * to span multiple servers. This is done by building an L2 overlay on
980 * top of an L3 network underlay using VXLAN-GPE tunnels.
981 *
982 * This makes it possible for servers to be co-located in the same data
983 * center or be separated geographically as long as they are reachable
984 * through the underlay L3 network.
985 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700986 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800987 *
988 * @cliexpar
989 * Example of how to create a VXLAN-GPE Tunnel:
Zhiyong Yang42e64e92019-05-22 03:49:43 -0400990 * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 remote 10.0.3.3 vni 13 encap-vrf-id 7}
991 * Example of how to delete a VXLAN-GPE Tunnel:
992 * @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 +0800993 ?*/
994/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700995VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = {
996 .path = "create vxlan-gpe tunnel",
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800997 .short_help =
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800998 "create vxlan-gpe tunnel local <local-addr> "
999 " {remote <remote-addr>|group <mcast-addr> <intf-name>}"
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001000 " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]"
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001001 " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n",
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001002 .function = vxlan_gpe_add_del_tunnel_command_fn,
1003};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001004/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001005
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -07001006/**
1007 * @brief CLI function for showing VXLAN GPE tunnels
1008 *
1009 * @param *vm
1010 * @param *input
1011 * @param *cmd
1012 *
1013 * @return error
1014 *
1015 */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001016static clib_error_t *
1017show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301018 unformat_input_t * input,
1019 vlib_cli_command_t * cmd)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001020{
sharath reddy6f8273a2017-12-11 11:31:31 +05301021 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1022 vxlan_gpe_tunnel_t *t;
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001023
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001024 if (pool_elts (ngm->tunnels) == 0)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001025 vlib_cli_output (vm, "No vxlan-gpe tunnels configured.");
1026
sharath reddy6f8273a2017-12-11 11:31:31 +05301027 /* *INDENT-OFF* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001028 pool_foreach (t, ngm->tunnels,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001029 ({
1030 vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t);
1031 }));
sharath reddy6f8273a2017-12-11 11:31:31 +05301032 /* *INDENT-ON* */
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001033
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001034 return 0;
1035}
1036
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001037/*?
1038 * Display all the VXLAN-GPE Tunnel entries.
1039 *
1040 * @cliexpar
1041 * Example of how to display the VXLAN-GPE Tunnel entries:
1042 * @cliexstart{show vxlan-gpe tunnel}
1043 * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
1044 * @cliexend
1045 ?*/
1046/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001047VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = {
1048 .path = "show vxlan-gpe",
1049 .function = show_vxlan_gpe_tunnel_command_fn,
1050};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001051/* *INDENT-ON* */
1052
sharath reddy6f8273a2017-12-11 11:31:31 +05301053void
1054vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001055{
1056 if (is_ip6)
1057 vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-gpe-bypass",
1058 sw_if_index, is_enable, 0, 0);
1059 else
1060 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-gpe-bypass",
1061 sw_if_index, is_enable, 0, 0);
1062}
1063
1064
1065static clib_error_t *
1066set_ip_vxlan_gpe_bypass (u32 is_ip6,
sharath reddy6f8273a2017-12-11 11:31:31 +05301067 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001068{
sharath reddy6f8273a2017-12-11 11:31:31 +05301069 unformat_input_t _line_input, *line_input = &_line_input;
1070 vnet_main_t *vnm = vnet_get_main ();
1071 clib_error_t *error = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001072 u32 sw_if_index, is_enable;
1073
1074 sw_if_index = ~0;
1075 is_enable = 1;
1076
sharath reddy6f8273a2017-12-11 11:31:31 +05301077 if (!unformat_user (input, unformat_line_input, line_input))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001078 return 0;
1079
1080 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1081 {
sharath reddy6f8273a2017-12-11 11:31:31 +05301082 if (unformat_user
1083 (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1084 ;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001085 else if (unformat (line_input, "del"))
sharath reddy6f8273a2017-12-11 11:31:31 +05301086 is_enable = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001087 else
sharath reddy6f8273a2017-12-11 11:31:31 +05301088 {
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001089 error = unformat_parse_error (line_input);
1090 goto done;
1091 }
1092 }
1093
1094 if (~0 == sw_if_index)
1095 {
1096 error = clib_error_return (0, "unknown interface `%U'",
1097 format_unformat_error, line_input);
1098 goto done;
1099 }
1100
1101 vnet_int_vxlan_gpe_bypass_mode (sw_if_index, is_ip6, is_enable);
1102
sharath reddy6f8273a2017-12-11 11:31:31 +05301103done:
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001104 unformat_free (line_input);
1105
1106 return error;
1107}
1108
1109static clib_error_t *
1110set_ip4_vxlan_gpe_bypass (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301111 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001112{
1113 return set_ip_vxlan_gpe_bypass (0, input, cmd);
1114}
1115
1116/*?
1117 * This command adds the 'ip4-vxlan-gpe-bypass' graph node for a given interface.
1118 * By adding the IPv4 vxlan-gpe-bypass graph node to an interface, the node checks
1119 * for and validate input vxlan_gpe packet and bypass ip4-lookup, ip4-local,
1120 * ip4-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1121 * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1122 *
1123 * @cliexpar
1124 * @parblock
1125 * Example of graph node before ip4-vxlan-gpe-bypass is enabled:
1126 * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1127 * Name Next Previous
1128 * ip4-vxlan-gpe-bypass error-drop [0]
1129 * vxlan4-gpe-input [1]
1130 * ip4-lookup [2]
1131 * @cliexend
1132 *
1133 * Example of how to enable ip4-vxlan-gpe-bypass on an interface:
1134 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0}
1135 *
1136 * Example of graph node after ip4-vxlan-gpe-bypass is enabled:
1137 * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1138 * Name Next Previous
1139 * ip4-vxlan-gpe-bypass error-drop [0] ip4-input
1140 * vxlan4-gpe-input [1] ip4-input-no-checksum
1141 * ip4-lookup [2]
1142 * @cliexend
1143 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001144 * Example of how to display the feature enabled on an interface:
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001145 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1146 * IP feature paths configured on GigabitEthernet2/0/0...
1147 * ...
1148 * ipv4 unicast:
1149 * ip4-vxlan-gpe-bypass
1150 * ip4-lookup
1151 * ...
1152 * @cliexend
1153 *
1154 * Example of how to disable ip4-vxlan-gpe-bypass on an interface:
1155 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1156 * @endparblock
1157?*/
1158/* *INDENT-OFF* */
1159VLIB_CLI_COMMAND (set_interface_ip_vxlan_gpe_bypass_command, static) = {
1160 .path = "set interface ip vxlan-gpe-bypass",
1161 .function = set_ip4_vxlan_gpe_bypass,
1162 .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1163};
1164/* *INDENT-ON* */
1165
1166static clib_error_t *
1167set_ip6_vxlan_gpe_bypass (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301168 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001169{
1170 return set_ip_vxlan_gpe_bypass (1, input, cmd);
1171}
1172
1173/*?
1174 * This command adds the 'ip6-vxlan-gpe-bypass' graph node for a given interface.
1175 * By adding the IPv6 vxlan-gpe-bypass graph node to an interface, the node checks
1176 * for and validate input vxlan_gpe packet and bypass ip6-lookup, ip6-local,
1177 * ip6-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1178 * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1179 *
1180 * @cliexpar
1181 * @parblock
1182 * Example of graph node before ip6-vxlan-gpe-bypass is enabled:
1183 * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1184 * Name Next Previous
1185 * ip6-vxlan-gpe-bypass error-drop [0]
1186 * vxlan6-gpe-input [1]
1187 * ip6-lookup [2]
1188 * @cliexend
1189 *
1190 * Example of how to enable ip6-vxlan-gpe-bypass on an interface:
1191 * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0}
1192 *
1193 * Example of graph node after ip6-vxlan-gpe-bypass is enabled:
1194 * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1195 * Name Next Previous
1196 * ip6-vxlan-gpe-bypass error-drop [0] ip6-input
1197 * vxlan6-gpe-input [1] ip4-input-no-checksum
1198 * ip6-lookup [2]
1199 * @cliexend
1200 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001201 * Example of how to display the feature enabled on an interface:
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001202 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1203 * IP feature paths configured on GigabitEthernet2/0/0...
1204 * ...
1205 * ipv6 unicast:
1206 * ip6-vxlan-gpe-bypass
1207 * ip6-lookup
1208 * ...
1209 * @cliexend
1210 *
1211 * Example of how to disable ip6-vxlan-gpe-bypass on an interface:
1212 * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1213 * @endparblock
1214?*/
1215/* *INDENT-OFF* */
1216VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gpe_bypass_command, static) = {
1217 .path = "set interface ip6 vxlan-gpe-bypass",
1218 .function = set_ip6_vxlan_gpe_bypass,
1219 .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1220};
1221/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001222
Hongjun Nie1bf5722017-08-03 20:34:45 +08001223/* *INDENT-OFF* */
1224VNET_FEATURE_INIT (ip4_vxlan_gpe_bypass, static) =
1225{
1226 .arc_name = "ip4-unicast",
1227 .node_name = "ip4-vxlan-gpe-bypass",
1228 .runs_before = VNET_FEATURES ("ip4-lookup"),
1229};
1230
1231VNET_FEATURE_INIT (ip6_vxlan_gpe_bypass, static) =
1232{
1233 .arc_name = "ip6-unicast",
1234 .node_name = "ip6-vxlan-gpe-bypass",
1235 .runs_before = VNET_FEATURES ("ip6-lookup"),
1236};
1237/* *INDENT-ON* */
1238
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -07001239/**
1240 * @brief Feature init function for VXLAN GPE
1241 *
1242 * @param *vm
1243 *
1244 * @return error
1245 *
1246 */
sharath reddy6f8273a2017-12-11 11:31:31 +05301247clib_error_t *
1248vxlan_gpe_init (vlib_main_t * vm)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001249{
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001250 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001251
sharath reddy6f8273a2017-12-11 11:31:31 +05301252 ngm->vnet_main = vnet_get_main ();
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001253 ngm->vlib_main = vm;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001254
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001255 ngm->vxlan4_gpe_tunnel_by_key
sharath reddy6f8273a2017-12-11 11:31:31 +05301256 = hash_create_mem (0, sizeof (vxlan4_gpe_tunnel_key_t), sizeof (uword));
Hongjun Nidf921cc2016-05-25 01:16:19 +08001257
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001258 ngm->vxlan6_gpe_tunnel_by_key
sharath reddy6f8273a2017-12-11 11:31:31 +05301259 = hash_create_mem (0, sizeof (vxlan6_gpe_tunnel_key_t), sizeof (uword));
Hongjun Nidf921cc2016-05-25 01:16:19 +08001260
1261
sharath reddy6f8273a2017-12-11 11:31:31 +05301262 ngm->mcast_shared = hash_create_mem (0,
1263 sizeof (ip46_address_t),
1264 sizeof (mcast_shared_t));
Swarup Nayak284f7052017-12-13 13:02:22 +05301265 ngm->vtep6 = hash_create_mem (0, sizeof (ip6_address_t), sizeof (uword));
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001266
Vengada Govindan6d403a02016-10-12 05:54:09 -07001267 /* Register the list of standard decap protocols supported */
1268 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4,
sharath reddy6f8273a2017-12-11 11:31:31 +05301269 VXLAN_GPE_INPUT_NEXT_IP4_INPUT);
Vengada Govindan6d403a02016-10-12 05:54:09 -07001270 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6,
sharath reddy6f8273a2017-12-11 11:31:31 +05301271 VXLAN_GPE_INPUT_NEXT_IP6_INPUT);
Vengada Govindan6d403a02016-10-12 05:54:09 -07001272 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET,
Gabriel Ganne7e665d62017-11-17 09:18:53 +01001273 VXLAN_GPE_INPUT_NEXT_L2_INPUT);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001274
sharath reddy6f8273a2017-12-11 11:31:31 +05301275 fib_node_register_type (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001276
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001277 return 0;
1278}
1279
sharath reddy6f8273a2017-12-11 11:31:31 +05301280VLIB_INIT_FUNCTION (vxlan_gpe_init);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001281
sharath reddy6f8273a2017-12-11 11:31:31 +05301282
1283/*
1284 * fd.io coding-style-patch-verification: ON
1285 *
1286 * Local Variables:
1287 * eval: (c-set-style "gnu")
1288 * End:
1289 */