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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @brief Common utility functions for IPv4 and IPv6 VXLAN GPE tunnels
20 #include <vnet/vxlan-gpe/vxlan_gpe.h>
21 #include <vnet/fib/fib.h>
22 #include <vnet/ip/format.h>
23 #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>
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.
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.
42 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
45 vxlan_gpe_main_t vxlan_gpe_main;
48 * @brief Tracing function for VXLAN GPE tunnel packets
50 * @param *s formatting string
53 * @return *s formatted string
57 format_vxlan_gpe_tunnel (u8 * s, va_list * args)
59 vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
60 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
62 s = format (s, "[%d] local: %U remote: %U ",
64 format_ip46_address, &t->local, IP46_TYPE_ANY,
65 format_ip46_address, &t->remote, IP46_TYPE_ANY);
67 s = format (s, " vxlan VNI %d ", t->vni);
71 case VXLAN_GPE_PROTOCOL_IP4:
72 s = format (s, "next-protocol ip4");
74 case VXLAN_GPE_PROTOCOL_IP6:
75 s = format (s, "next-protocol ip6");
77 case VXLAN_GPE_PROTOCOL_ETHERNET:
78 s = format (s, "next-protocol ethernet");
80 case VXLAN_GPE_PROTOCOL_NSH:
81 s = format (s, "next-protocol nsh");
84 s = format (s, "next-protocol unknown %d", t->protocol);
87 if (ip46_address_is_multicast (&t->remote))
88 s = format (s, "mcast_sw_if_index %d ", t->mcast_sw_if_index);
90 s = format (s, " fibs: (encap %d, decap %d)",
91 t->encap_fib_index, t->decap_fib_index);
97 * @brief Naming for VXLAN GPE tunnel
99 * @param *s formatting string
102 * @return *s formatted string
106 format_vxlan_gpe_name (u8 * s, va_list * args)
108 u32 dev_instance = va_arg (*args, u32);
109 return format (s, "vxlan_gpe_tunnel%d", dev_instance);
113 dummy_interface_tx (vlib_main_t * vm,
114 vlib_node_runtime_t * node, vlib_frame_t * frame)
116 clib_warning ("you shouldn't be here, leaking buffers...");
117 return frame->n_vectors;
121 * @brief CLI function for VXLAN GPE admin up/down
130 static clib_error_t *
131 vxlan_gpe_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
134 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);
142 VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
144 .format_device_name = format_vxlan_gpe_name,
145 .format_tx_trace = format_vxlan_gpe_encap_trace,
146 .tx_function = dummy_interface_tx,
147 .admin_up_down_function = vxlan_gpe_interface_admin_up_down,
153 * @brief Formatting function for tracing VXLAN GPE with length
162 format_vxlan_gpe_header_with_length (u8 * s, va_list * args)
164 u32 dev_instance = va_arg (*args, u32);
165 s = format (s, "unimplemented dev %u", dev_instance);
170 VNET_HW_INTERFACE_CLASS (vxlan_gpe_hw_class) = {
172 .format_header = format_vxlan_gpe_header_with_length,
173 .build_rewrite = default_build_rewrite,
178 vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_t * t)
180 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;
185 fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
186 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
190 static vxlan_gpe_tunnel_t *
191 vxlan_gpe_tunnel_from_fib_node (fib_node_t * node)
193 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,
200 * Function definition to backwalk a FIB node -
201 * Here we will restack the new dpo of VXLAN_GPE DIP to encap node.
203 static fib_node_back_walk_rc_t
204 vxlan_gpe_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
206 vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_from_fib_node (node));
207 return (FIB_NODE_BACK_WALK_CONTINUE);
211 * Function definition to get a FIB node from its index
214 vxlan_gpe_tunnel_fib_node_get (fib_node_index_t index)
216 vxlan_gpe_tunnel_t *t;
217 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
219 t = pool_elt_at_index (ngm->tunnels, index);
225 * Function definition to inform the FIB node that its last lock has gone.
228 vxlan_gpe_tunnel_last_lock_gone (fib_node_t * node)
231 * The VXLAN_GPE tunnel is a root of the graph. As such
232 * it never has children and thus is never locked.
238 * Virtual function table registered by VXLAN_GPE tunnels
239 * for participation in the FIB object graph.
241 const static fib_node_vft_t vxlan_gpe_vft = {
242 .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,
247 #define foreach_gpe_copy_field \
250 _(mcast_sw_if_index) \
254 #define foreach_copy_ipv4 { \
255 _(local.ip4.as_u32) \
256 _(remote.ip4.as_u32) \
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]) \
268 * @brief Calculate IPv4 VXLAN GPE rewrite header
276 vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
277 u8 protocol_override, uword encap_next_node)
281 ip4_vxlan_gpe_header_t *h0;
284 len = sizeof (*h0) + extension_size;
286 vec_free (t->rewrite);
287 vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
289 h0 = (ip4_vxlan_gpe_header_t *) rw;
291 /* Fixed portion of the (outer) ip4 header */
293 ip0->ip_version_and_header_length = 0x45;
295 ip0->protocol = IP_PROTOCOL_UDP;
297 /* we fix up the ip4 header length and checksum after-the-fact */
298 ip0->src_address.as_u32 = t->local.ip4.as_u32;
299 ip0->dst_address.as_u32 = t->remote.ip4.as_u32;
300 ip0->checksum = ip4_header_checksum (ip0);
302 /* UDP header, randomize src port on something, maybe? */
303 h0->udp.src_port = clib_host_to_net_u16 (4790);
304 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
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;
309 if (protocol_override)
311 h0->vxlan.protocol = protocol_override;
315 h0->vxlan.protocol = t->protocol;
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);
321 t->encap_next_node = encap_next_node;
326 * @brief Calculate IPv6 VXLAN GPE rewrite header
334 vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
335 u8 protocol_override, uword encap_next_node)
339 ip6_vxlan_gpe_header_t *h0;
342 len = sizeof (*h0) + extension_size;
344 vec_free (t->rewrite);
345 vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
347 h0 = (ip6_vxlan_gpe_header_t *) rw;
349 /* Fixed portion of the (outer) ip4 header */
351 ip0->ip_version_traffic_class_and_flow_label =
352 clib_host_to_net_u32 (6 << 28);
353 ip0->hop_limit = 255;
354 ip0->protocol = IP_PROTOCOL_UDP;
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];
361 /* UDP header, randomize src port on something, maybe? */
362 h0->udp.src_port = clib_host_to_net_u16 (4790);
363 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
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;
368 if (protocol_override)
370 h0->vxlan.protocol = t->protocol;
374 h0->vxlan.protocol = protocol_override;
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);
380 t->encap_next_node = encap_next_node;
385 hash_set_key_copy (uword ** h, void *key, uword v)
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);
394 hash_unset_key_free (uword ** h, void *key)
396 hash_pair_t *hp = hash_get_pair_mem (*h, key);
398 key = uword_to_pointer (hp->key, void *);
399 hash_unset_mem (*h, key);
404 vtep_addr_ref (ip46_address_t * ip)
406 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);
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);
418 vtep_addr_unref (ip46_address_t * ip)
420 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);
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);
433 typedef CLIB_PACKED(union {
435 fib_node_index_t mfib_entry_index;
436 adj_index_t mcast_adj_index;
442 static inline mcast_shared_t
443 mcast_shared_get (ip46_address_t * ip)
445 ASSERT (ip46_address_is_multicast (ip));
446 uword *p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip);
448 return (mcast_shared_t)
454 mcast_shared_add (ip46_address_t * remote,
455 fib_node_index_t mfei, adj_index_t ai)
457 mcast_shared_t new_ep = {
458 .mcast_adj_index = ai,
459 .mfib_entry_index = mfei,
462 hash_set_key_copy (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
466 mcast_shared_remove (ip46_address_t * remote)
468 mcast_shared_t ep = mcast_shared_get (remote);
470 adj_unlock (ep.mcast_adj_index);
471 mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_VXLAN_GPE);
473 hash_unset_key_free (&vxlan_gpe_main.mcast_shared, remote);
476 static inline fib_protocol_t
477 fib_ip_proto (bool is_ip6)
479 return (is_ip6) ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4;
483 * @brief Add or Del a VXLAN GPE tunnel
486 * @param *sw_if_index
491 int vnet_vxlan_gpe_add_del_tunnel
492 (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
494 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
495 vxlan_gpe_tunnel_t *t = 0;
496 vnet_main_t *vnm = ngm->vnet_main;
497 vnet_hw_interface_t *hi;
499 u32 hw_if_index = ~0;
500 u32 sw_if_index = ~0;
502 vxlan4_gpe_tunnel_key_t key4, *key4_copy;
503 vxlan6_gpe_tunnel_key_t key6, *key6_copy;
504 u32 is_ip6 = a->is_ip6;
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);
513 p = hash_get_mem (ngm->vxlan4_gpe_tunnel_by_key, &key4);
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);
523 p = hash_get_mem (ngm->vxlan6_gpe_tunnel_by_key, &key6);
528 l2input_main_t *l2im = &l2input_main;
530 /* adding a tunnel: tunnel must not already exist */
532 return VNET_API_ERROR_TUNNEL_EXIST;
534 pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
535 memset (t, 0, sizeof (*t));
537 /* copy from arg structure */
538 #define _(x) t->x = a->x;
539 foreach_gpe_copy_field;
546 t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
550 rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
554 rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
559 pool_put (ngm->tunnels, t);
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,
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,
578 if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0)
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;
585 hi = vnet_get_hw_interface (vnm, hw_if_index);
586 hi->dev_instance = t - ngm->tunnels;
587 hi->hw_instance = hi->dev_instance;
588 /* clear old stats of freed tunnel before reuse */
589 sw_if_index = hi->sw_if_index;
590 vnet_interface_counter_lock (im);
591 vlib_zero_combined_counter
592 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
594 vlib_zero_combined_counter (&im->combined_sw_if_counters
595 [VNET_INTERFACE_COUNTER_RX],
597 vlib_zero_simple_counter (&im->sw_if_counters
598 [VNET_INTERFACE_COUNTER_DROP],
600 vnet_interface_counter_unlock (im);
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;
611 t->hw_if_index = hw_if_index;
612 t->sw_if_index = sw_if_index = hi->sw_if_index;
613 vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index,
615 ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels;
617 /* 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;
622 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
623 si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
624 vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
625 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
626 fib_node_init (&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL);
627 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;
631 fib_prefix_from_ip46_addr (&t->remote, &tun_remote_pfx);
632 if (!ip46_address_is_multicast (&t->remote))
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
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,
643 FIB_ENTRY_FLAG_NONE);
644 t->sibling_index = fib_entry_child_add
645 (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL,
647 vxlan_gpe_tunnel_restack_dpo (t);
651 /* Multicast tunnel -
652 * 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
656 fib_protocol_t fp = fib_ip_proto (is_ip6);
658 if (vtep_addr_ref (&t->remote) == 1)
660 fib_node_index_t mfei;
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,
668 .frp_flags = FIB_ROUTE_PATH_LOCAL,
670 const mfib_prefix_t mpfx = {
672 .fp_len = (is_ip6 ? 128 : 32),
673 .fp_grp_addr = tun_remote_pfx.fp_addr,
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
681 mfib_table_entry_path_update (t->encap_fib_index,
683 MFIB_SOURCE_VXLAN_GPE,
684 &path, MFIB_ITF_FLAG_FORWARD);
686 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,
690 MFIB_SOURCE_VXLAN_GPE,
692 MFIB_ITF_FLAG_ACCEPT);
695 * Create the mcast adjacency to send traffic to the group
697 ai = adj_mcast_add_or_lock (fp,
698 fib_proto_to_link (fp),
699 a->mcast_sw_if_index);
702 * create a new end-point
704 mcast_shared_add (&t->remote, mfei, ai);
707 dpo_id_t dpo = DPO_INVALID;
708 mcast_shared_t ep = mcast_shared_get (&t->remote);
710 /* 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);
714 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
716 flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
719 /* Set vxlan tunnel output node */
720 hi->output_node_index = encap_index;
722 vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
727 /* deleting a tunnel: tunnel must exist */
729 return VNET_API_ERROR_NO_SUCH_ENTRY;
731 t = pool_elt_at_index (ngm->tunnels, p[0]);
733 sw_if_index = t->sw_if_index;
734 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);
736 si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
737 set_int_l2_mode (ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0,
739 vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index);
741 ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
744 hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
746 hash_unset_key_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
748 if (!ip46_address_is_multicast (&t->remote))
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);
754 else if (vtep_addr_unref (&t->remote) == 0)
756 mcast_shared_remove (&t->remote);
759 fib_node_deinit (&t->node);
760 vec_free (t->rewrite);
761 pool_put (ngm->tunnels, t);
765 *sw_if_indexp = sw_if_index;
770 static clib_error_t *
771 vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
772 unformat_input_t * input,
773 vlib_cli_command_t * cmd)
775 unformat_input_t _line_input, *line_input = &_line_input;
777 ip46_address_t local, remote;
783 u32 mcast_sw_if_index = ~0;
784 u32 encap_fib_index = 0;
785 u32 decap_fib_index = 0;
786 u8 protocol = VXLAN_GPE_PROTOCOL_IP4;
791 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
793 clib_error_t *error = NULL;
795 /* Get a line of input. */
796 if (!unformat_user (input, unformat_line_input, line_input))
799 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
801 if (unformat (line_input, "del"))
803 else if (unformat (line_input, "local %U",
804 unformat_ip4_address, &local.ip4))
809 else if (unformat (line_input, "remote %U",
810 unformat_ip4_address, &remote.ip4))
815 else if (unformat (line_input, "local %U",
816 unformat_ip6_address, &local.ip6))
821 else if (unformat (line_input, "remote %U",
822 unformat_ip6_address, &remote.ip6))
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))
832 grp_set = remote_set = 1;
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))
840 grp_set = remote_set = 1;
843 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
846 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
848 encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
850 if (encap_fib_index == ~0)
853 clib_error_return (0, "nonexistent encap fib id %d", tmp);
857 else if (unformat (line_input, "decap-vrf-id %d", &tmp))
860 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
862 decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
864 if (decap_fib_index == ~0)
867 clib_error_return (0, "nonexistent decap fib id %d", tmp);
871 else if (unformat (line_input, "vni %d", &vni))
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;
883 error = clib_error_return (0, "parse error: '%U'",
884 format_unformat_error, line_input);
891 error = clib_error_return (0, "tunnel local address not specified");
897 error = clib_error_return (0, "tunnel remote address not specified");
901 if (grp_set && !ip46_address_is_multicast (&remote))
903 error = clib_error_return (0, "tunnel group address not multicast");
907 if (grp_set == 0 && ip46_address_is_multicast (&remote))
909 error = clib_error_return (0, "remote address must be unicast");
913 if (grp_set && mcast_sw_if_index == ~0)
915 error = clib_error_return (0, "tunnel nonexistent multicast device");
918 if (ipv4_set && ipv6_set)
920 error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
924 if ((ipv4_set && memcmp (&local.ip4, &remote.ip4, sizeof (local.ip4)) == 0)
926 && memcmp (&local.ip6, &remote.ip6, sizeof (local.ip6)) == 0))
928 error = clib_error_return (0, "src and remote addresses are identical");
934 error = clib_error_return (0, "vni not specified");
938 memset (a, 0, sizeof (*a));
941 a->is_ip6 = ipv6_set;
943 #define _(x) a->x = x;
944 foreach_gpe_copy_field;
950 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
955 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
956 vnet_get_main (), sw_if_index);
958 case VNET_API_ERROR_INVALID_DECAP_NEXT:
959 error = clib_error_return (0, "invalid decap-next...");
962 case VNET_API_ERROR_TUNNEL_EXIST:
963 error = clib_error_return (0, "tunnel already exists...");
966 case VNET_API_ERROR_NO_SUCH_ENTRY:
967 error = clib_error_return (0, "tunnel does not exist...");
971 error = clib_error_return
972 (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv);
977 unformat_free (line_input);
983 * Add or delete a VXLAN-GPE Tunnel.
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.
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.
993 * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE sengment.
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}
1002 VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = {
1003 .path = "create vxlan-gpe tunnel",
1005 "create vxlan-gpe tunnel local <local-addr> "
1006 " {remote <remote-addr>|group <mcast-addr> <intf-name>}"
1007 " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]"
1008 " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n",
1009 .function = vxlan_gpe_add_del_tunnel_command_fn,
1014 * @brief CLI function for showing VXLAN GPE tunnels
1023 static clib_error_t *
1024 show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm,
1025 unformat_input_t * input,
1026 vlib_cli_command_t * cmd)
1028 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1029 vxlan_gpe_tunnel_t *t;
1031 if (pool_elts (ngm->tunnels) == 0)
1032 vlib_cli_output (vm, "No vxlan-gpe tunnels configured.");
1035 pool_foreach (t, ngm->tunnels,
1037 vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t);
1045 * Display all the VXLAN-GPE Tunnel entries.
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
1054 VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = {
1055 .path = "show vxlan-gpe",
1056 .function = show_vxlan_gpe_tunnel_command_fn,
1061 vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
1064 vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-gpe-bypass",
1065 sw_if_index, is_enable, 0, 0);
1067 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-gpe-bypass",
1068 sw_if_index, is_enable, 0, 0);
1072 static clib_error_t *
1073 set_ip_vxlan_gpe_bypass (u32 is_ip6,
1074 unformat_input_t * input, vlib_cli_command_t * cmd)
1076 unformat_input_t _line_input, *line_input = &_line_input;
1077 vnet_main_t *vnm = vnet_get_main ();
1078 clib_error_t *error = 0;
1079 u32 sw_if_index, is_enable;
1084 if (!unformat_user (input, unformat_line_input, line_input))
1087 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1090 (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1092 else if (unformat (line_input, "del"))
1096 error = unformat_parse_error (line_input);
1101 if (~0 == sw_if_index)
1103 error = clib_error_return (0, "unknown interface `%U'",
1104 format_unformat_error, line_input);
1108 vnet_int_vxlan_gpe_bypass_mode (sw_if_index, is_ip6, is_enable);
1111 unformat_free (line_input);
1116 static clib_error_t *
1117 set_ip4_vxlan_gpe_bypass (vlib_main_t * vm,
1118 unformat_input_t * input, vlib_cli_command_t * cmd)
1120 return set_ip_vxlan_gpe_bypass (0, input, cmd);
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.
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]
1140 * Example of how to enable ip4-vxlan-gpe-bypass on an interface:
1141 * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0}
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
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...
1156 * ip4-vxlan-gpe-bypass
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}
1166 VLIB_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]",
1173 static clib_error_t *
1174 set_ip6_vxlan_gpe_bypass (vlib_main_t * vm,
1175 unformat_input_t * input, vlib_cli_command_t * cmd)
1177 return set_ip_vxlan_gpe_bypass (1, input, cmd);
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.
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]
1197 * Example of how to enable ip6-vxlan-gpe-bypass on an interface:
1198 * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0}
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
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...
1213 * ip6-vxlan-gpe-bypass
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}
1223 VLIB_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]",
1231 VNET_FEATURE_INIT (ip4_vxlan_gpe_bypass, static) =
1233 .arc_name = "ip4-unicast",
1234 .node_name = "ip4-vxlan-gpe-bypass",
1235 .runs_before = VNET_FEATURES ("ip4-lookup"),
1238 VNET_FEATURE_INIT (ip6_vxlan_gpe_bypass, static) =
1240 .arc_name = "ip6-unicast",
1241 .node_name = "ip6-vxlan-gpe-bypass",
1242 .runs_before = VNET_FEATURES ("ip6-lookup"),
1247 * @brief Feature init function for VXLAN GPE
1255 vxlan_gpe_init (vlib_main_t * vm)
1257 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1259 ngm->vnet_main = vnet_get_main ();
1260 ngm->vlib_main = vm;
1262 ngm->vxlan4_gpe_tunnel_by_key
1263 = hash_create_mem (0, sizeof (vxlan4_gpe_tunnel_key_t), sizeof (uword));
1265 ngm->vxlan6_gpe_tunnel_by_key
1266 = hash_create_mem (0, sizeof (vxlan6_gpe_tunnel_key_t), sizeof (uword));
1269 ngm->mcast_shared = hash_create_mem (0,
1270 sizeof (ip46_address_t),
1271 sizeof (mcast_shared_t));
1273 udp_register_dst_port (vm, UDP_DST_PORT_VXLAN_GPE,
1274 vxlan4_gpe_input_node.index, 1 /* is_ip4 */ );
1275 udp_register_dst_port (vm, UDP_DST_PORT_VXLAN6_GPE,
1276 vxlan6_gpe_input_node.index, 0 /* is_ip4 */ );
1278 /* Register the list of standard decap protocols supported */
1279 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4,
1280 VXLAN_GPE_INPUT_NEXT_IP4_INPUT);
1281 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6,
1282 VXLAN_GPE_INPUT_NEXT_IP6_INPUT);
1283 vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET,
1284 VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT);
1286 fib_node_register_type (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft);
1291 VLIB_INIT_FUNCTION (vxlan_gpe_init);
1295 * fd.io coding-style-patch-verification: ON
1298 * eval: (c-set-style "gnu")