blob: a95062b53f0178235d0fdca98068152936458043 [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
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070047/**
48 * @brief Tracing function for VXLAN GPE tunnel packets
49 *
50 * @param *s formatting string
51 * @param *args
52 *
53 * @return *s formatted string
54 *
55 */
sharath reddy6f8273a2017-12-11 11:31:31 +053056u8 *
57format_vxlan_gpe_tunnel (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070058{
sharath reddy6f8273a2017-12-11 11:31:31 +053059 vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
60 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070061
62 s = format (s, "[%d] local: %U remote: %U ",
sharath reddy6f8273a2017-12-11 11:31:31 +053063 t - ngm->tunnels,
64 format_ip46_address, &t->local, IP46_TYPE_ANY,
65 format_ip46_address, &t->remote, IP46_TYPE_ANY);
Hongjun Nidf921cc2016-05-25 01:16:19 +080066
67 s = format (s, " vxlan VNI %d ", t->vni);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070068
69 switch (t->protocol)
70 {
71 case VXLAN_GPE_PROTOCOL_IP4:
72 s = format (s, "next-protocol ip4");
Hongjun Ni4a713142016-05-24 02:54:10 +080073 break;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070074 case VXLAN_GPE_PROTOCOL_IP6:
75 s = format (s, "next-protocol ip6");
Hongjun Ni4a713142016-05-24 02:54:10 +080076 break;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070077 case VXLAN_GPE_PROTOCOL_ETHERNET:
78 s = format (s, "next-protocol ethernet");
Hongjun Ni4a713142016-05-24 02:54:10 +080079 break;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070080 case VXLAN_GPE_PROTOCOL_NSH:
81 s = format (s, "next-protocol nsh");
Hongjun Ni4a713142016-05-24 02:54:10 +080082 break;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070083 default:
84 s = format (s, "next-protocol unknown %d", t->protocol);
85 }
86
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080087 if (ip46_address_is_multicast (&t->remote))
88 s = format (s, "mcast_sw_if_index %d ", t->mcast_sw_if_index);
sharath reddy6f8273a2017-12-11 11:31:31 +053089
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070090 s = format (s, " fibs: (encap %d, decap %d)",
sharath reddy6f8273a2017-12-11 11:31:31 +053091 t->encap_fib_index, t->decap_fib_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070092
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -070093 return s;
94}
95
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -070096/**
97 * @brief Naming for VXLAN GPE tunnel
98 *
99 * @param *s formatting string
100 * @param *args
101 *
102 * @return *s formatted string
103 *
104 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530105static u8 *
106format_vxlan_gpe_name (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700107{
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800108 u32 dev_instance = va_arg (*args, u32);
109 return format (s, "vxlan_gpe_tunnel%d", dev_instance);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700110}
111
sharath reddy6f8273a2017-12-11 11:31:31 +0530112static uword
113dummy_interface_tx (vlib_main_t * vm,
114 vlib_node_runtime_t * node, vlib_frame_t * frame)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700115{
116 clib_warning ("you shouldn't be here, leaking buffers...");
117 return frame->n_vectors;
118}
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700119
120/**
121 * @brief CLI function for VXLAN GPE admin up/down
122 *
123 * @param *vnm
124 * @param hw_if_index
125 * @param flag
126 *
127 * @return *rc
128 *
129 */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800130static clib_error_t *
sharath reddy6f8273a2017-12-11 11:31:31 +0530131vxlan_gpe_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
132 u32 flags)
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800133{
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800134 u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
135 VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
136 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800137
138 return 0;
139}
140
sharath reddy6f8273a2017-12-11 11:31:31 +0530141/* *INDENT-OFF* */
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800142VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
143 .name = "VXLAN_GPE",
144 .format_device_name = format_vxlan_gpe_name,
145 .format_tx_trace = format_vxlan_gpe_encap_trace,
146 .tx_function = dummy_interface_tx,
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800147 .admin_up_down_function = vxlan_gpe_interface_admin_up_down,
Hongjun Ni0e06e2b2016-05-30 19:45:51 +0800148};
sharath reddy6f8273a2017-12-11 11:31:31 +0530149/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700150
Vengada Govindan6d403a02016-10-12 05:54:09 -0700151
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700152/**
153 * @brief Formatting function for tracing VXLAN GPE with length
154 *
155 * @param *s
156 * @param *args
157 *
158 * @return *s
159 *
160 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530161static u8 *
162format_vxlan_gpe_header_with_length (u8 * s, va_list * args)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700163{
164 u32 dev_instance = va_arg (*args, u32);
165 s = format (s, "unimplemented dev %u", dev_instance);
166 return s;
167}
168
sharath reddy6f8273a2017-12-11 11:31:31 +0530169/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700170VNET_HW_INTERFACE_CLASS (vxlan_gpe_hw_class) = {
171 .name = "VXLAN_GPE",
172 .format_header = format_vxlan_gpe_header_with_length,
Neale Rannsb80c5362016-10-08 13:03:40 +0100173 .build_rewrite = default_build_rewrite,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700174};
sharath reddy6f8273a2017-12-11 11:31:31 +0530175/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700176
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800177static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530178vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_t * t)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800179{
sharath reddy6f8273a2017-12-11 11:31:31 +0530180 dpo_id_t dpo = DPO_INVALID;
181 u32 encap_index = vxlan_gpe_encap_node.index;
182 fib_forward_chain_type_t forw_type = ip46_address_is_ip4 (&t->remote) ?
183 FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800184
sharath reddy6f8273a2017-12-11 11:31:31 +0530185 fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
186 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
187 dpo_reset (&dpo);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800188}
189
190static vxlan_gpe_tunnel_t *
sharath reddy6f8273a2017-12-11 11:31:31 +0530191vxlan_gpe_tunnel_from_fib_node (fib_node_t * node)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800192{
sharath reddy6f8273a2017-12-11 11:31:31 +0530193 ASSERT (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL == node->fn_type);
194 return ((vxlan_gpe_tunnel_t *) (((char *) node) -
195 STRUCT_OFFSET_OF (vxlan_gpe_tunnel_t,
196 node)));
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800197}
198
199/**
200 * Function definition to backwalk a FIB node -
201 * Here we will restack the new dpo of VXLAN_GPE DIP to encap node.
202 */
203static fib_node_back_walk_rc_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530204vxlan_gpe_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800205{
sharath reddy6f8273a2017-12-11 11:31:31 +0530206 vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_from_fib_node (node));
207 return (FIB_NODE_BACK_WALK_CONTINUE);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800208}
209
210/**
211 * Function definition to get a FIB node from its index
212 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530213static fib_node_t *
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800214vxlan_gpe_tunnel_fib_node_get (fib_node_index_t index)
215{
sharath reddy6f8273a2017-12-11 11:31:31 +0530216 vxlan_gpe_tunnel_t *t;
217 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800218
sharath reddy6f8273a2017-12-11 11:31:31 +0530219 t = pool_elt_at_index (ngm->tunnels, index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800220
sharath reddy6f8273a2017-12-11 11:31:31 +0530221 return (&t->node);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800222}
223
224/**
225 * Function definition to inform the FIB node that its last lock has gone.
226 */
227static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530228vxlan_gpe_tunnel_last_lock_gone (fib_node_t * node)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800229{
sharath reddy6f8273a2017-12-11 11:31:31 +0530230 /*
231 * The VXLAN_GPE tunnel is a root of the graph. As such
232 * it never has children and thus is never locked.
233 */
234 ASSERT (0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800235}
236
237/*
238 * Virtual function table registered by VXLAN_GPE tunnels
239 * for participation in the FIB object graph.
240 */
241const static fib_node_vft_t vxlan_gpe_vft = {
sharath reddy6f8273a2017-12-11 11:31:31 +0530242 .fnv_get = vxlan_gpe_tunnel_fib_node_get,
243 .fnv_last_lock = vxlan_gpe_tunnel_last_lock_gone,
244 .fnv_back_walk = vxlan_gpe_tunnel_back_walk,
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800245};
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700246
247#define foreach_gpe_copy_field \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700248_(vni) \
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800249_(protocol) \
250_(mcast_sw_if_index) \
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700251_(encap_fib_index) \
Hongjun Ni7deb1392016-06-15 22:49:23 +0800252_(decap_fib_index)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700253
Hongjun Nidf921cc2016-05-25 01:16:19 +0800254#define foreach_copy_ipv4 { \
255 _(local.ip4.as_u32) \
256 _(remote.ip4.as_u32) \
257}
258
259#define foreach_copy_ipv6 { \
260 _(local.ip6.as_u64[0]) \
261 _(local.ip6.as_u64[1]) \
262 _(remote.ip6.as_u64[0]) \
263 _(remote.ip6.as_u64[1]) \
264}
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700265
266
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700267/**
268 * @brief Calculate IPv4 VXLAN GPE rewrite header
269 *
270 * @param *t
271 *
272 * @return rc
273 *
274 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530275int
276vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
277 u8 protocol_override, uword encap_next_node)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700278{
279 u8 *rw = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530280 ip4_header_t *ip0;
281 ip4_vxlan_gpe_header_t *h0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700282 int len;
283
Vengada Govindan6d403a02016-10-12 05:54:09 -0700284 len = sizeof (*h0) + extension_size;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700285
sharath reddy6f8273a2017-12-11 11:31:31 +0530286 vec_free (t->rewrite);
287 vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700288
289 h0 = (ip4_vxlan_gpe_header_t *) rw;
290
291 /* Fixed portion of the (outer) ip4 header */
292 ip0 = &h0->ip4;
293 ip0->ip_version_and_header_length = 0x45;
294 ip0->ttl = 254;
295 ip0->protocol = IP_PROTOCOL_UDP;
296
297 /* we fix up the ip4 header length and checksum after-the-fact */
Hongjun Nidf921cc2016-05-25 01:16:19 +0800298 ip0->src_address.as_u32 = t->local.ip4.as_u32;
299 ip0->dst_address.as_u32 = t->remote.ip4.as_u32;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700300 ip0->checksum = ip4_header_checksum (ip0);
301
302 /* UDP header, randomize src port on something, maybe? */
303 h0->udp.src_port = clib_host_to_net_u16 (4790);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800304 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700305
306 /* VXLAN header. Are we having fun yet? */
307 h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
308 h0->vxlan.ver_res = VXLAN_GPE_VERSION;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700309 if (protocol_override)
sharath reddy6f8273a2017-12-11 11:31:31 +0530310 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700311 h0->vxlan.protocol = protocol_override;
sharath reddy6f8273a2017-12-11 11:31:31 +0530312 }
Vengada Govindan6d403a02016-10-12 05:54:09 -0700313 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530314 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700315 h0->vxlan.protocol = t->protocol;
sharath reddy6f8273a2017-12-11 11:31:31 +0530316 }
317 t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
318 h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700319
320 t->rewrite = rw;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700321 t->encap_next_node = encap_next_node;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700322 return (0);
323}
324
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700325/**
326 * @brief Calculate IPv6 VXLAN GPE rewrite header
327 *
328 * @param *t
329 *
330 * @return rc
331 *
332 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530333int
334vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
335 u8 protocol_override, uword encap_next_node)
Hongjun Nidf921cc2016-05-25 01:16:19 +0800336{
337 u8 *rw = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530338 ip6_header_t *ip0;
339 ip6_vxlan_gpe_header_t *h0;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800340 int len;
341
Vengada Govindan6d403a02016-10-12 05:54:09 -0700342 len = sizeof (*h0) + extension_size;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800343
sharath reddy6f8273a2017-12-11 11:31:31 +0530344 vec_free (t->rewrite);
345 vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800346
347 h0 = (ip6_vxlan_gpe_header_t *) rw;
348
349 /* Fixed portion of the (outer) ip4 header */
350 ip0 = &h0->ip6;
sharath reddy6f8273a2017-12-11 11:31:31 +0530351 ip0->ip_version_traffic_class_and_flow_label =
352 clib_host_to_net_u32 (6 << 28);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800353 ip0->hop_limit = 255;
354 ip0->protocol = IP_PROTOCOL_UDP;
355
356 ip0->src_address.as_u64[0] = t->local.ip6.as_u64[0];
357 ip0->src_address.as_u64[1] = t->local.ip6.as_u64[1];
358 ip0->dst_address.as_u64[0] = t->remote.ip6.as_u64[0];
359 ip0->dst_address.as_u64[1] = t->remote.ip6.as_u64[1];
360
361 /* UDP header, randomize src port on something, maybe? */
362 h0->udp.src_port = clib_host_to_net_u16 (4790);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800363 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800364
365 /* VXLAN header. Are we having fun yet? */
366 h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
367 h0->vxlan.ver_res = VXLAN_GPE_VERSION;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700368 if (protocol_override)
sharath reddy6f8273a2017-12-11 11:31:31 +0530369 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700370 h0->vxlan.protocol = t->protocol;
sharath reddy6f8273a2017-12-11 11:31:31 +0530371 }
Vengada Govindan6d403a02016-10-12 05:54:09 -0700372 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530373 {
Vengada Govindan6d403a02016-10-12 05:54:09 -0700374 h0->vxlan.protocol = protocol_override;
sharath reddy6f8273a2017-12-11 11:31:31 +0530375 }
376 t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
377 h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800378
379 t->rewrite = rw;
Vengada Govindan6d403a02016-10-12 05:54:09 -0700380 t->encap_next_node = encap_next_node;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800381 return (0);
382}
383
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800384static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530385hash_set_key_copy (uword ** h, void *key, uword v)
386{
387 size_t ksz = hash_header (*h)->user;
388 void *copy = clib_mem_alloc (ksz);
389 clib_memcpy (copy, key, ksz);
390 hash_set_mem (*h, copy, v);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800391}
392
393static void
sharath reddy6f8273a2017-12-11 11:31:31 +0530394hash_unset_key_free (uword ** h, void *key)
395{
396 hash_pair_t *hp = hash_get_pair_mem (*h, key);
397 ASSERT (hp);
398 key = uword_to_pointer (hp->key, void *);
399 hash_unset_mem (*h, key);
400 clib_mem_free (key);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800401}
402
403static uword
sharath reddy6f8273a2017-12-11 11:31:31 +0530404vtep_addr_ref (ip46_address_t * ip)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800405{
sharath reddy6f8273a2017-12-11 11:31:31 +0530406 uword *vtep = ip46_address_is_ip4 (ip) ?
407 hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
408 hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
409 if (vtep)
410 return ++(*vtep);
411 ip46_address_is_ip4 (ip) ?
412 hash_set (vxlan_gpe_main.vtep4, ip->ip4.as_u32, 1) :
413 hash_set_key_copy (&vxlan_gpe_main.vtep6, &ip->ip6, 1);
414 return 1;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800415}
416
417static uword
sharath reddy6f8273a2017-12-11 11:31:31 +0530418vtep_addr_unref (ip46_address_t * ip)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800419{
sharath reddy6f8273a2017-12-11 11:31:31 +0530420 uword *vtep = ip46_address_is_ip4 (ip) ?
421 hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
422 hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
423 ASSERT (vtep);
424 if (--(*vtep) != 0)
425 return *vtep;
426 ip46_address_is_ip4 (ip) ?
427 hash_unset (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
428 hash_unset_key_free (&vxlan_gpe_main.vtep6, &ip->ip6);
429 return 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800430}
431
sharath reddy6f8273a2017-12-11 11:31:31 +0530432/* *INDENT-OFF* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800433typedef CLIB_PACKED(union {
434 struct {
435 fib_node_index_t mfib_entry_index;
436 adj_index_t mcast_adj_index;
437 };
438 u64 as_u64;
439}) mcast_shared_t;
sharath reddy6f8273a2017-12-11 11:31:31 +0530440/* *INDENT-ON* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800441
442static inline mcast_shared_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530443mcast_shared_get (ip46_address_t * ip)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800444{
sharath reddy6f8273a2017-12-11 11:31:31 +0530445 ASSERT (ip46_address_is_multicast (ip));
446 uword *p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip);
447 ASSERT (p);
448 return (mcast_shared_t)
449 {
450 .as_u64 = *p};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800451}
452
453static inline void
sharath reddy6f8273a2017-12-11 11:31:31 +0530454mcast_shared_add (ip46_address_t * remote,
455 fib_node_index_t mfei, adj_index_t ai)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800456{
sharath reddy6f8273a2017-12-11 11:31:31 +0530457 mcast_shared_t new_ep = {
458 .mcast_adj_index = ai,
459 .mfib_entry_index = mfei,
460 };
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800461
sharath reddy6f8273a2017-12-11 11:31:31 +0530462 hash_set_key_copy (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800463}
464
465static inline void
sharath reddy6f8273a2017-12-11 11:31:31 +0530466mcast_shared_remove (ip46_address_t * remote)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800467{
sharath reddy6f8273a2017-12-11 11:31:31 +0530468 mcast_shared_t ep = mcast_shared_get (remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800469
sharath reddy6f8273a2017-12-11 11:31:31 +0530470 adj_unlock (ep.mcast_adj_index);
471 mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_VXLAN_GPE);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800472
sharath reddy6f8273a2017-12-11 11:31:31 +0530473 hash_unset_key_free (&vxlan_gpe_main.mcast_shared, remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800474}
475
476static inline fib_protocol_t
sharath reddy6f8273a2017-12-11 11:31:31 +0530477fib_ip_proto (bool is_ip6)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800478{
479 return (is_ip6) ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4;
480}
481
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -0700482/**
483 * @brief Add or Del a VXLAN GPE tunnel
484 *
485 * @param *a
486 * @param *sw_if_index
487 *
488 * @return rc
489 *
490 */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800491int vnet_vxlan_gpe_add_del_tunnel
sharath reddy6f8273a2017-12-11 11:31:31 +0530492 (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700493{
sharath reddy6f8273a2017-12-11 11:31:31 +0530494 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700495 vxlan_gpe_tunnel_t *t = 0;
sharath reddy6f8273a2017-12-11 11:31:31 +0530496 vnet_main_t *vnm = ngm->vnet_main;
497 vnet_hw_interface_t *hi;
498 uword *p;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700499 u32 hw_if_index = ~0;
500 u32 sw_if_index = ~0;
501 int rv;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800502 vxlan4_gpe_tunnel_key_t key4, *key4_copy;
503 vxlan6_gpe_tunnel_key_t key6, *key6_copy;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800504 u32 is_ip6 = a->is_ip6;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800505
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800506 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530507 {
508 key4.local = a->local.ip4.as_u32;
509 key4.remote = a->remote.ip4.as_u32;
510 key4.vni = clib_host_to_net_u32 (a->vni << 8);
511 key4.pad = 0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700512
sharath reddy6f8273a2017-12-11 11:31:31 +0530513 p = hash_get_mem (ngm->vxlan4_gpe_tunnel_by_key, &key4);
514 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800515 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530516 {
517 key6.local.as_u64[0] = a->local.ip6.as_u64[0];
518 key6.local.as_u64[1] = a->local.ip6.as_u64[1];
519 key6.remote.as_u64[0] = a->remote.ip6.as_u64[0];
520 key6.remote.as_u64[1] = a->remote.ip6.as_u64[1];
521 key6.vni = clib_host_to_net_u32 (a->vni << 8);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800522
sharath reddy6f8273a2017-12-11 11:31:31 +0530523 p = hash_get_mem (ngm->vxlan6_gpe_tunnel_by_key, &key6);
524 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800525
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700526 if (a->is_add)
527 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530528 l2input_main_t *l2im = &l2input_main;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800529
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700530 /* adding a tunnel: tunnel must not already exist */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800531 if (p)
sharath reddy6f8273a2017-12-11 11:31:31 +0530532 return VNET_API_ERROR_TUNNEL_EXIST;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800533
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800534 pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700535 memset (t, 0, sizeof (*t));
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800536
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700537 /* copy from arg structure */
538#define _(x) t->x = a->x;
539 foreach_gpe_copy_field;
sharath reddy6f8273a2017-12-11 11:31:31 +0530540 if (!a->is_ip6)
541 foreach_copy_ipv4
542 else
543 foreach_copy_ipv6
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700544#undef _
sharath reddy6f8273a2017-12-11 11:31:31 +0530545 if (!a->is_ip6)
546 t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700547
sharath reddy6f8273a2017-12-11 11:31:31 +0530548 if (!a->is_ip6)
549 {
550 rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
551 }
552 else
553 {
554 rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
555 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700556
557 if (rv)
sharath reddy6f8273a2017-12-11 11:31:31 +0530558 {
559 pool_put (ngm->tunnels, t);
560 return rv;
561 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700562
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800563 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530564 {
565 key4_copy = clib_mem_alloc (sizeof (*key4_copy));
566 clib_memcpy (key4_copy, &key4, sizeof (*key4_copy));
567 hash_set_mem (ngm->vxlan4_gpe_tunnel_by_key, key4_copy,
568 t - ngm->tunnels);
569 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800570 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530571 {
572 key6_copy = clib_mem_alloc (sizeof (*key6_copy));
573 clib_memcpy (key6_copy, &key6, sizeof (*key6_copy));
574 hash_set_mem (ngm->vxlan6_gpe_tunnel_by_key, key6_copy,
575 t - ngm->tunnels);
576 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800577
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800578 if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0)
sharath reddy6f8273a2017-12-11 11:31:31 +0530579 {
580 vnet_interface_main_t *im = &vnm->interface_main;
581 hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
582 [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) - 1];
583 _vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) -= 1;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800584
sharath reddy6f8273a2017-12-11 11:31:31 +0530585 hi = vnet_get_hw_interface (vnm, hw_if_index);
586 hi->dev_instance = t - ngm->tunnels;
587 hi->hw_instance = hi->dev_instance;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800588 /* clear old stats of freed tunnel before reuse */
589 sw_if_index = hi->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530590 vnet_interface_counter_lock (im);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800591 vlib_zero_combined_counter
sharath reddy6f8273a2017-12-11 11:31:31 +0530592 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
593 sw_if_index);
594 vlib_zero_combined_counter (&im->combined_sw_if_counters
595 [VNET_INTERFACE_COUNTER_RX],
596 sw_if_index);
597 vlib_zero_simple_counter (&im->sw_if_counters
598 [VNET_INTERFACE_COUNTER_DROP],
599 sw_if_index);
600 vnet_interface_counter_unlock (im);
601 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800602 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530603 {
604 hw_if_index = vnet_register_interface
605 (vnm, vxlan_gpe_device_class.index, t - ngm->tunnels,
606 vxlan_gpe_hw_class.index, t - ngm->tunnels);
607 hi = vnet_get_hw_interface (vnm, hw_if_index);
608 hi->output_node_index = vxlan_gpe_encap_node.index;
609 }
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800610
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700611 t->hw_if_index = hw_if_index;
612 t->sw_if_index = sw_if_index = hi->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530613 vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index,
614 ~0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800615 ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800616
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800617 /* setup l2 input config with l2 feature and bd 0 to drop packet */
618 vec_validate (l2im->configs, sw_if_index);
619 l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
620 l2im->configs[sw_if_index].bd_index = 0;
621
sharath reddy6f8273a2017-12-11 11:31:31 +0530622 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800623 si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800624 vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
sharath reddy6f8273a2017-12-11 11:31:31 +0530625 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
626 fib_node_init (&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800627 fib_prefix_t tun_remote_pfx;
628 u32 encap_index = vxlan_gpe_encap_node.index;
629 vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
630
sharath reddy6f8273a2017-12-11 11:31:31 +0530631 fib_prefix_from_ip46_addr (&t->remote, &tun_remote_pfx);
632 if (!ip46_address_is_multicast (&t->remote))
633 {
634 /* Unicast tunnel -
635 * source the FIB entry for the tunnel's destination
636 * and become a child thereof. The tunnel will then get poked
637 * when the forwarding for the entry updates, and the tunnel can
638 * re-stack accordingly
639 */
640 vtep_addr_ref (&t->local);
641 t->fib_entry_index = fib_table_entry_special_add
642 (t->encap_fib_index, &tun_remote_pfx, FIB_SOURCE_RR,
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800643 FIB_ENTRY_FLAG_NONE);
sharath reddy6f8273a2017-12-11 11:31:31 +0530644 t->sibling_index = fib_entry_child_add
645 (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL,
646 t - ngm->tunnels);
647 vxlan_gpe_tunnel_restack_dpo (t);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800648 }
649 else
sharath reddy6f8273a2017-12-11 11:31:31 +0530650 {
651 /* Multicast tunnel -
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800652 * as the same mcast group can be used for mutiple mcast tunnels
653 * with different VNIs, create the output fib adjecency only if
654 * it does not already exist
655 */
sharath reddy6f8273a2017-12-11 11:31:31 +0530656 fib_protocol_t fp = fib_ip_proto (is_ip6);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800657
sharath reddy6f8273a2017-12-11 11:31:31 +0530658 if (vtep_addr_ref (&t->remote) == 1)
659 {
660 fib_node_index_t mfei;
661 adj_index_t ai;
662 fib_route_path_t path = {
663 .frp_proto = fib_proto_to_dpo (fp),
664 .frp_addr = zero_addr,
665 .frp_sw_if_index = 0xffffffff,
666 .frp_fib_index = ~0,
667 .frp_weight = 0,
668 .frp_flags = FIB_ROUTE_PATH_LOCAL,
669 };
670 const mfib_prefix_t mpfx = {
671 .fp_proto = fp,
672 .fp_len = (is_ip6 ? 128 : 32),
673 .fp_grp_addr = tun_remote_pfx.fp_addr,
674 };
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800675
sharath reddy6f8273a2017-12-11 11:31:31 +0530676 /*
677 * Setup the (*,G) to receive traffic on the mcast group
678 * - the forwarding interface is for-us
679 * - the accepting interface is that from the API
680 */
681 mfib_table_entry_path_update (t->encap_fib_index,
682 &mpfx,
683 MFIB_SOURCE_VXLAN_GPE,
684 &path, MFIB_ITF_FLAG_FORWARD);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800685
sharath reddy6f8273a2017-12-11 11:31:31 +0530686 path.frp_sw_if_index = a->mcast_sw_if_index;
687 path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
688 mfei = mfib_table_entry_path_update (t->encap_fib_index,
689 &mpfx,
690 MFIB_SOURCE_VXLAN_GPE,
691 &path,
692 MFIB_ITF_FLAG_ACCEPT);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800693
sharath reddy6f8273a2017-12-11 11:31:31 +0530694 /*
695 * Create the mcast adjacency to send traffic to the group
696 */
697 ai = adj_mcast_add_or_lock (fp,
698 fib_proto_to_link (fp),
699 a->mcast_sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800700
sharath reddy6f8273a2017-12-11 11:31:31 +0530701 /*
702 * create a new end-point
703 */
704 mcast_shared_add (&t->remote, mfei, ai);
705 }
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800706
sharath reddy6f8273a2017-12-11 11:31:31 +0530707 dpo_id_t dpo = DPO_INVALID;
708 mcast_shared_t ep = mcast_shared_get (&t->remote);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800709
sharath reddy6f8273a2017-12-11 11:31:31 +0530710 /* Stack shared mcast remote mac addr rewrite on encap */
711 dpo_set (&dpo, DPO_ADJACENCY_MCAST,
712 fib_proto_to_dpo (fp), ep.mcast_adj_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800713
sharath reddy6f8273a2017-12-11 11:31:31 +0530714 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
715 dpo_reset (&dpo);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800716 flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
717 }
718
719 /* Set vxlan tunnel output node */
720 hi->output_node_index = encap_index;
721
sharath reddy6f8273a2017-12-11 11:31:31 +0530722 vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
723 flood_class;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700724 }
725 else
726 {
727 /* deleting a tunnel: tunnel must exist */
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800728 if (!p)
sharath reddy6f8273a2017-12-11 11:31:31 +0530729 return VNET_API_ERROR_NO_SUCH_ENTRY;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700730
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800731 t = pool_elt_at_index (ngm->tunnels, p[0]);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700732
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800733 sw_if_index = t->sw_if_index;
sharath reddy6f8273a2017-12-11 11:31:31 +0530734 vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
735 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, t->sw_if_index);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800736 si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
sharath reddy6f8273a2017-12-11 11:31:31 +0530737 set_int_l2_mode (ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0,
738 0);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800739 vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700740
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800741 ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
Hongjun Nic0959c92016-06-16 20:18:15 +0800742
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800743 if (!is_ip6)
sharath reddy6f8273a2017-12-11 11:31:31 +0530744 hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800745 else
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800746 hash_unset_key_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700747
sharath reddy6f8273a2017-12-11 11:31:31 +0530748 if (!ip46_address_is_multicast (&t->remote))
749 {
750 vtep_addr_unref (&t->local);
751 fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
752 fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
753 }
754 else if (vtep_addr_unref (&t->remote) == 0)
755 {
756 mcast_shared_remove (&t->remote);
757 }
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800758
sharath reddy6f8273a2017-12-11 11:31:31 +0530759 fib_node_deinit (&t->node);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700760 vec_free (t->rewrite);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800761 pool_put (ngm->tunnels, t);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700762 }
763
764 if (sw_if_indexp)
sharath reddy6f8273a2017-12-11 11:31:31 +0530765 *sw_if_indexp = sw_if_index;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700766
767 return 0;
768}
769
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700770static clib_error_t *
771vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +0530772 unformat_input_t * input,
773 vlib_cli_command_t * cmd)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700774{
sharath reddy6f8273a2017-12-11 11:31:31 +0530775 unformat_input_t _line_input, *line_input = &_line_input;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700776 u8 is_add = 1;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800777 ip46_address_t local, remote;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700778 u8 local_set = 0;
779 u8 remote_set = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800780 u8 grp_set = 0;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800781 u8 ipv4_set = 0;
782 u8 ipv6_set = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800783 u32 mcast_sw_if_index = ~0;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700784 u32 encap_fib_index = 0;
785 u32 decap_fib_index = 0;
786 u8 protocol = VXLAN_GPE_PROTOCOL_IP4;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700787 u32 vni;
788 u8 vni_set = 0;
789 int rv;
790 u32 tmp;
sharath reddy6f8273a2017-12-11 11:31:31 +0530791 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
Pierre Pfister78ea9c22016-05-23 12:51:54 +0100792 u32 sw_if_index;
Billy McFalla9a20e72017-02-15 11:39:12 -0500793 clib_error_t *error = NULL;
Hongjun Nicccd1bf2016-06-07 18:43:05 +0800794
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700795 /* Get a line of input. */
sharath reddy6f8273a2017-12-11 11:31:31 +0530796 if (!unformat_user (input, unformat_line_input, line_input))
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700797 return 0;
798
sharath reddy6f8273a2017-12-11 11:31:31 +0530799 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Hongjun Nidf921cc2016-05-25 01:16:19 +0800800 {
sharath reddy6f8273a2017-12-11 11:31:31 +0530801 if (unformat (line_input, "del"))
802 is_add = 0;
803 else if (unformat (line_input, "local %U",
804 unformat_ip4_address, &local.ip4))
805 {
806 local_set = 1;
807 ipv4_set = 1;
808 }
809 else if (unformat (line_input, "remote %U",
810 unformat_ip4_address, &remote.ip4))
811 {
812 remote_set = 1;
813 ipv4_set = 1;
814 }
815 else if (unformat (line_input, "local %U",
816 unformat_ip6_address, &local.ip6))
817 {
818 local_set = 1;
819 ipv6_set = 1;
820 }
821 else if (unformat (line_input, "remote %U",
822 unformat_ip6_address, &remote.ip6))
823 {
824 remote_set = 1;
825 ipv6_set = 1;
826 }
827 else if (unformat (line_input, "group %U %U",
828 unformat_ip4_address, &remote.ip4,
829 unformat_vnet_sw_interface,
830 vnet_get_main (), &mcast_sw_if_index))
831 {
832 grp_set = remote_set = 1;
833 ipv4_set = 1;
834 }
835 else if (unformat (line_input, "group %U %U",
836 unformat_ip6_address, &remote.ip6,
837 unformat_vnet_sw_interface,
838 vnet_get_main (), &mcast_sw_if_index))
839 {
840 grp_set = remote_set = 1;
841 ipv6_set = 1;
842 }
843 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
844 {
845 if (ipv6_set)
846 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
847 else
848 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800849
sharath reddy6f8273a2017-12-11 11:31:31 +0530850 if (encap_fib_index == ~0)
851 {
852 error =
853 clib_error_return (0, "nonexistent encap fib id %d", tmp);
854 goto done;
855 }
856 }
857 else if (unformat (line_input, "decap-vrf-id %d", &tmp))
858 {
859 if (ipv6_set)
860 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
861 else
862 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
Hongjun Nidf921cc2016-05-25 01:16:19 +0800863
sharath reddy6f8273a2017-12-11 11:31:31 +0530864 if (decap_fib_index == ~0)
865 {
866 error =
867 clib_error_return (0, "nonexistent decap fib id %d", tmp);
868 goto done;
869 }
870 }
871 else if (unformat (line_input, "vni %d", &vni))
872 vni_set = 1;
873 else if (unformat (line_input, "next-ip4"))
874 protocol = VXLAN_GPE_PROTOCOL_IP4;
875 else if (unformat (line_input, "next-ip6"))
876 protocol = VXLAN_GPE_PROTOCOL_IP6;
877 else if (unformat (line_input, "next-ethernet"))
878 protocol = VXLAN_GPE_PROTOCOL_ETHERNET;
879 else if (unformat (line_input, "next-nsh"))
880 protocol = VXLAN_GPE_PROTOCOL_NSH;
881 else
882 {
883 error = clib_error_return (0, "parse error: '%U'",
884 format_unformat_error, line_input);
885 goto done;
886 }
887 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700888
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700889 if (local_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500890 {
891 error = clib_error_return (0, "tunnel local address not specified");
892 goto done;
893 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700894
895 if (remote_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500896 {
897 error = clib_error_return (0, "tunnel remote address not specified");
898 goto done;
899 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700900
sharath reddy6f8273a2017-12-11 11:31:31 +0530901 if (grp_set && !ip46_address_is_multicast (&remote))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800902 {
903 error = clib_error_return (0, "tunnel group address not multicast");
904 goto done;
905 }
906
sharath reddy6f8273a2017-12-11 11:31:31 +0530907 if (grp_set == 0 && ip46_address_is_multicast (&remote))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800908 {
909 error = clib_error_return (0, "remote address must be unicast");
910 goto done;
911 }
912
913 if (grp_set && mcast_sw_if_index == ~0)
914 {
915 error = clib_error_return (0, "tunnel nonexistent multicast device");
916 goto done;
917 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800918 if (ipv4_set && ipv6_set)
Billy McFalla9a20e72017-02-15 11:39:12 -0500919 {
920 error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
921 goto done;
922 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800923
sharath reddy6f8273a2017-12-11 11:31:31 +0530924 if ((ipv4_set && memcmp (&local.ip4, &remote.ip4, sizeof (local.ip4)) == 0)
925 || (ipv6_set
926 && memcmp (&local.ip6, &remote.ip6, sizeof (local.ip6)) == 0))
Billy McFalla9a20e72017-02-15 11:39:12 -0500927 {
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800928 error = clib_error_return (0, "src and remote addresses are identical");
Billy McFalla9a20e72017-02-15 11:39:12 -0500929 goto done;
930 }
Hongjun Nidf921cc2016-05-25 01:16:19 +0800931
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700932 if (vni_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500933 {
934 error = clib_error_return (0, "vni not specified");
935 goto done;
936 }
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700937
938 memset (a, 0, sizeof (*a));
939
940 a->is_add = is_add;
Hongjun Nidf921cc2016-05-25 01:16:19 +0800941 a->is_ip6 = ipv6_set;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700942
943#define _(x) a->x = x;
944 foreach_gpe_copy_field;
sharath reddy6f8273a2017-12-11 11:31:31 +0530945 if (ipv4_set)
946 foreach_copy_ipv4
947 else
948 foreach_copy_ipv6
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700949#undef _
sharath reddy6f8273a2017-12-11 11:31:31 +0530950 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700951
sharath reddy6f8273a2017-12-11 11:31:31 +0530952 switch (rv)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700953 {
954 case 0:
sharath reddy6f8273a2017-12-11 11:31:31 +0530955 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
956 vnet_get_main (), sw_if_index);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700957 break;
958 case VNET_API_ERROR_INVALID_DECAP_NEXT:
Billy McFalla9a20e72017-02-15 11:39:12 -0500959 error = clib_error_return (0, "invalid decap-next...");
960 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700961
962 case VNET_API_ERROR_TUNNEL_EXIST:
Billy McFalla9a20e72017-02-15 11:39:12 -0500963 error = clib_error_return (0, "tunnel already exists...");
964 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700965
966 case VNET_API_ERROR_NO_SUCH_ENTRY:
Billy McFalla9a20e72017-02-15 11:39:12 -0500967 error = clib_error_return (0, "tunnel does not exist...");
968 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700969
970 default:
Billy McFalla9a20e72017-02-15 11:39:12 -0500971 error = clib_error_return
sharath reddy6f8273a2017-12-11 11:31:31 +0530972 (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500973 goto done;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700974 }
975
Billy McFalla9a20e72017-02-15 11:39:12 -0500976done:
977 unformat_free (line_input);
978
979 return error;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -0700980}
981
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800982/*?
983 * Add or delete a VXLAN-GPE Tunnel.
984 *
985 * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
986 * to span multiple servers. This is done by building an L2 overlay on
987 * top of an L3 network underlay using VXLAN-GPE tunnels.
988 *
989 * This makes it possible for servers to be co-located in the same data
990 * center or be separated geographically as long as they are reachable
991 * through the underlay L3 network.
992 *
993 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE sengment.
994 *
995 * @cliexpar
996 * Example of how to create a VXLAN-GPE Tunnel:
997 * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 local 10.0.3.3 vni 13 encap-vrf-id 7}
998 * Example of how to delete a VXLAN Tunnel:
999 * @cliexcmd{create vxlan tunnel src 10.0.3.1 remote 10.0.3.3 vni 13 del}
1000 ?*/
1001/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001002VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = {
1003 .path = "create vxlan-gpe tunnel",
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001004 .short_help =
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001005 "create vxlan-gpe tunnel local <local-addr> "
1006 " {remote <remote-addr>|group <mcast-addr> <intf-name>}"
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001007 " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]"
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001008 " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n",
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001009 .function = vxlan_gpe_add_del_tunnel_command_fn,
1010};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001011/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001012
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -07001013/**
1014 * @brief CLI function for showing VXLAN GPE tunnels
1015 *
1016 * @param *vm
1017 * @param *input
1018 * @param *cmd
1019 *
1020 * @return error
1021 *
1022 */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001023static clib_error_t *
1024show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301025 unformat_input_t * input,
1026 vlib_cli_command_t * cmd)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001027{
sharath reddy6f8273a2017-12-11 11:31:31 +05301028 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1029 vxlan_gpe_tunnel_t *t;
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001030
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001031 if (pool_elts (ngm->tunnels) == 0)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001032 vlib_cli_output (vm, "No vxlan-gpe tunnels configured.");
1033
sharath reddy6f8273a2017-12-11 11:31:31 +05301034 /* *INDENT-OFF* */
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001035 pool_foreach (t, ngm->tunnels,
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001036 ({
1037 vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t);
1038 }));
sharath reddy6f8273a2017-12-11 11:31:31 +05301039 /* *INDENT-ON* */
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001040
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001041 return 0;
1042}
1043
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001044/*?
1045 * Display all the VXLAN-GPE Tunnel entries.
1046 *
1047 * @cliexpar
1048 * Example of how to display the VXLAN-GPE Tunnel entries:
1049 * @cliexstart{show vxlan-gpe tunnel}
1050 * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
1051 * @cliexend
1052 ?*/
1053/* *INDENT-OFF* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001054VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = {
1055 .path = "show vxlan-gpe",
1056 .function = show_vxlan_gpe_tunnel_command_fn,
1057};
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001058/* *INDENT-ON* */
1059
sharath reddy6f8273a2017-12-11 11:31:31 +05301060void
1061vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001062{
1063 if (is_ip6)
1064 vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-gpe-bypass",
1065 sw_if_index, is_enable, 0, 0);
1066 else
1067 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-gpe-bypass",
1068 sw_if_index, is_enable, 0, 0);
1069}
1070
1071
1072static clib_error_t *
1073set_ip_vxlan_gpe_bypass (u32 is_ip6,
sharath reddy6f8273a2017-12-11 11:31:31 +05301074 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001075{
sharath reddy6f8273a2017-12-11 11:31:31 +05301076 unformat_input_t _line_input, *line_input = &_line_input;
1077 vnet_main_t *vnm = vnet_get_main ();
1078 clib_error_t *error = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001079 u32 sw_if_index, is_enable;
1080
1081 sw_if_index = ~0;
1082 is_enable = 1;
1083
sharath reddy6f8273a2017-12-11 11:31:31 +05301084 if (!unformat_user (input, unformat_line_input, line_input))
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001085 return 0;
1086
1087 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1088 {
sharath reddy6f8273a2017-12-11 11:31:31 +05301089 if (unformat_user
1090 (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1091 ;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001092 else if (unformat (line_input, "del"))
sharath reddy6f8273a2017-12-11 11:31:31 +05301093 is_enable = 0;
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001094 else
sharath reddy6f8273a2017-12-11 11:31:31 +05301095 {
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001096 error = unformat_parse_error (line_input);
1097 goto done;
1098 }
1099 }
1100
1101 if (~0 == sw_if_index)
1102 {
1103 error = clib_error_return (0, "unknown interface `%U'",
1104 format_unformat_error, line_input);
1105 goto done;
1106 }
1107
1108 vnet_int_vxlan_gpe_bypass_mode (sw_if_index, is_ip6, is_enable);
1109
sharath reddy6f8273a2017-12-11 11:31:31 +05301110done:
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001111 unformat_free (line_input);
1112
1113 return error;
1114}
1115
1116static clib_error_t *
1117set_ip4_vxlan_gpe_bypass (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301118 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001119{
1120 return set_ip_vxlan_gpe_bypass (0, input, cmd);
1121}
1122
1123/*?
1124 * This command adds the 'ip4-vxlan-gpe-bypass' graph node for a given interface.
1125 * By adding the IPv4 vxlan-gpe-bypass graph node to an interface, the node checks
1126 * for and validate input vxlan_gpe packet and bypass ip4-lookup, ip4-local,
1127 * ip4-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1128 * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1129 *
1130 * @cliexpar
1131 * @parblock
1132 * Example of graph node before ip4-vxlan-gpe-bypass is enabled:
1133 * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1134 * Name Next Previous
1135 * ip4-vxlan-gpe-bypass error-drop [0]
1136 * vxlan4-gpe-input [1]
1137 * ip4-lookup [2]
1138 * @cliexend
1139 *
1140 * Example of how to enable ip4-vxlan-gpe-bypass on an interface:
1141 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0}
1142 *
1143 * Example of graph node after ip4-vxlan-gpe-bypass is enabled:
1144 * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1145 * Name Next Previous
1146 * ip4-vxlan-gpe-bypass error-drop [0] ip4-input
1147 * vxlan4-gpe-input [1] ip4-input-no-checksum
1148 * ip4-lookup [2]
1149 * @cliexend
1150 *
1151 * Example of how to display the feature enabed on an interface:
1152 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1153 * IP feature paths configured on GigabitEthernet2/0/0...
1154 * ...
1155 * ipv4 unicast:
1156 * ip4-vxlan-gpe-bypass
1157 * ip4-lookup
1158 * ...
1159 * @cliexend
1160 *
1161 * Example of how to disable ip4-vxlan-gpe-bypass on an interface:
1162 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1163 * @endparblock
1164?*/
1165/* *INDENT-OFF* */
1166VLIB_CLI_COMMAND (set_interface_ip_vxlan_gpe_bypass_command, static) = {
1167 .path = "set interface ip vxlan-gpe-bypass",
1168 .function = set_ip4_vxlan_gpe_bypass,
1169 .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1170};
1171/* *INDENT-ON* */
1172
1173static clib_error_t *
1174set_ip6_vxlan_gpe_bypass (vlib_main_t * vm,
sharath reddy6f8273a2017-12-11 11:31:31 +05301175 unformat_input_t * input, vlib_cli_command_t * cmd)
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001176{
1177 return set_ip_vxlan_gpe_bypass (1, input, cmd);
1178}
1179
1180/*?
1181 * This command adds the 'ip6-vxlan-gpe-bypass' graph node for a given interface.
1182 * By adding the IPv6 vxlan-gpe-bypass graph node to an interface, the node checks
1183 * for and validate input vxlan_gpe packet and bypass ip6-lookup, ip6-local,
1184 * ip6-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1185 * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1186 *
1187 * @cliexpar
1188 * @parblock
1189 * Example of graph node before ip6-vxlan-gpe-bypass is enabled:
1190 * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1191 * Name Next Previous
1192 * ip6-vxlan-gpe-bypass error-drop [0]
1193 * vxlan6-gpe-input [1]
1194 * ip6-lookup [2]
1195 * @cliexend
1196 *
1197 * Example of how to enable ip6-vxlan-gpe-bypass on an interface:
1198 * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0}
1199 *
1200 * Example of graph node after ip6-vxlan-gpe-bypass is enabled:
1201 * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1202 * Name Next Previous
1203 * ip6-vxlan-gpe-bypass error-drop [0] ip6-input
1204 * vxlan6-gpe-input [1] ip4-input-no-checksum
1205 * ip6-lookup [2]
1206 * @cliexend
1207 *
1208 * Example of how to display the feature enabed on an interface:
1209 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1210 * IP feature paths configured on GigabitEthernet2/0/0...
1211 * ...
1212 * ipv6 unicast:
1213 * ip6-vxlan-gpe-bypass
1214 * ip6-lookup
1215 * ...
1216 * @cliexend
1217 *
1218 * Example of how to disable ip6-vxlan-gpe-bypass on an interface:
1219 * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1220 * @endparblock
1221?*/
1222/* *INDENT-OFF* */
1223VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gpe_bypass_command, static) = {
1224 .path = "set interface ip6 vxlan-gpe-bypass",
1225 .function = set_ip6_vxlan_gpe_bypass,
1226 .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1227};
1228/* *INDENT-ON* */
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001229
Hongjun Nie1bf5722017-08-03 20:34:45 +08001230/* *INDENT-OFF* */
1231VNET_FEATURE_INIT (ip4_vxlan_gpe_bypass, static) =
1232{
1233 .arc_name = "ip4-unicast",
1234 .node_name = "ip4-vxlan-gpe-bypass",
1235 .runs_before = VNET_FEATURES ("ip4-lookup"),
1236};
1237
1238VNET_FEATURE_INIT (ip6_vxlan_gpe_bypass, static) =
1239{
1240 .arc_name = "ip6-unicast",
1241 .node_name = "ip6-vxlan-gpe-bypass",
1242 .runs_before = VNET_FEATURES ("ip6-lookup"),
1243};
1244/* *INDENT-ON* */
1245
Keith Burns (alagalah)d46cca12016-08-25 11:21:39 -07001246/**
1247 * @brief Feature init function for VXLAN GPE
1248 *
1249 * @param *vm
1250 *
1251 * @return error
1252 *
1253 */
sharath reddy6f8273a2017-12-11 11:31:31 +05301254clib_error_t *
1255vxlan_gpe_init (vlib_main_t * vm)
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001256{
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001257 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
Hongjun Nicccd1bf2016-06-07 18:43:05 +08001258
sharath reddy6f8273a2017-12-11 11:31:31 +05301259 ngm->vnet_main = vnet_get_main ();
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001260 ngm->vlib_main = vm;
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001261
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001262 ngm->vxlan4_gpe_tunnel_by_key
sharath reddy6f8273a2017-12-11 11:31:31 +05301263 = hash_create_mem (0, sizeof (vxlan4_gpe_tunnel_key_t), sizeof (uword));
Hongjun Nidf921cc2016-05-25 01:16:19 +08001264
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001265 ngm->vxlan6_gpe_tunnel_by_key
sharath reddy6f8273a2017-12-11 11:31:31 +05301266 = hash_create_mem (0, sizeof (vxlan6_gpe_tunnel_key_t), sizeof (uword));
Hongjun Nidf921cc2016-05-25 01:16:19 +08001267
1268
sharath reddy6f8273a2017-12-11 11:31:31 +05301269 ngm->mcast_shared = hash_create_mem (0,
1270 sizeof (ip46_address_t),
1271 sizeof (mcast_shared_t));
Swarup Nayak284f7052017-12-13 13:02:22 +05301272 ngm->vtep6 = hash_create_mem (0, sizeof (ip6_address_t), sizeof (uword));
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001273
1274 udp_register_dst_port (vm, UDP_DST_PORT_VXLAN_GPE,
sharath reddy6f8273a2017-12-11 11:31:31 +05301275 vxlan4_gpe_input_node.index, 1 /* is_ip4 */ );
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001276 udp_register_dst_port (vm, UDP_DST_PORT_VXLAN6_GPE,
sharath reddy6f8273a2017-12-11 11:31:31 +05301277 vxlan6_gpe_input_node.index, 0 /* is_ip4 */ );
Vengada Govindan6d403a02016-10-12 05:54:09 -07001278
1279 /* Register the list of standard decap protocols supported */
1280 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4,
sharath reddy6f8273a2017-12-11 11:31:31 +05301281 VXLAN_GPE_INPUT_NEXT_IP4_INPUT);
Vengada Govindan6d403a02016-10-12 05:54:09 -07001282 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6,
sharath reddy6f8273a2017-12-11 11:31:31 +05301283 VXLAN_GPE_INPUT_NEXT_IP6_INPUT);
Vengada Govindan6d403a02016-10-12 05:54:09 -07001284 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET,
sharath reddy6f8273a2017-12-11 11:31:31 +05301285 VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001286
sharath reddy6f8273a2017-12-11 11:31:31 +05301287 fib_node_register_type (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft);
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001288
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001289 return 0;
1290}
1291
sharath reddy6f8273a2017-12-11 11:31:31 +05301292VLIB_INIT_FUNCTION (vxlan_gpe_init);
Keith Burns (alagalah)94b14422016-05-05 18:16:50 -07001293
sharath reddy6f8273a2017-12-11 11:31:31 +05301294
1295/*
1296 * fd.io coding-style-patch-verification: ON
1297 *
1298 * Local Variables:
1299 * eval: (c-set-style "gnu")
1300 * End:
1301 */