2 * Copyright (c) 2017 SUSE LLC.
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.
15 #include <vnet/geneve/geneve.h>
16 #include <vnet/ip/format.h>
17 #include <vnet/fib/fib_entry.h>
18 #include <vnet/fib/fib_table.h>
19 #include <vnet/mfib/mfib_table.h>
20 #include <vnet/adj/adj_mcast.h>
21 #include <vnet/interface.h>
22 #include <vlib/vlib.h>
28 * GENEVE provides the features needed to allow L2 bridge domains (BDs)
29 * to span multiple servers. This is done by building an L2 overlay on
30 * top of an L3 network underlay using GENEVE tunnels.
32 * This makes it possible for servers to be co-located in the same data
33 * center or be separated geographically as long as they are reachable
34 * through the underlay L3 network.
38 geneve_main_t geneve_main;
41 format_decap_next (u8 * s, va_list * args)
43 u32 next_index = va_arg (*args, u32);
47 case GENEVE_INPUT_NEXT_DROP:
48 return format (s, "drop");
49 case GENEVE_INPUT_NEXT_L2_INPUT:
50 return format (s, "l2");
52 return format (s, "index %d", next_index);
58 format_geneve_tunnel (u8 * s, va_list * args)
60 geneve_tunnel_t *t = va_arg (*args, geneve_tunnel_t *);
61 geneve_main_t *ngm = &geneve_main;
63 s = format (s, "[%d] local %U remote %U vni %d sw_if_index %d ",
65 format_ip46_address, &t->local, IP46_TYPE_ANY,
66 format_ip46_address, &t->remote, IP46_TYPE_ANY,
67 t->vni, t->sw_if_index);
69 if (ip46_address_is_multicast (&t->remote))
70 s = format (s, "mcast_sw_if_index %d ", t->mcast_sw_if_index);
72 s = format (s, "encap_fib_index %d fib_entry_index %d decap_next %U\n",
73 t->encap_fib_index, t->fib_entry_index,
74 format_decap_next, t->decap_next_index);
79 format_geneve_name (u8 * s, va_list * args)
81 u32 dev_instance = va_arg (*args, u32);
82 return format (s, "geneve_tunnel%d", dev_instance);
86 dummy_interface_tx (vlib_main_t * vm,
87 vlib_node_runtime_t * node, vlib_frame_t * frame)
89 clib_warning ("you shouldn't be here, leaking buffers...");
90 return frame->n_vectors;
94 geneve_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
96 u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
97 VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
98 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
100 return /* no error */ 0;
104 VNET_DEVICE_CLASS (geneve_device_class, static) = {
106 .format_device_name = format_geneve_name,
107 .format_tx_trace = format_geneve_encap_trace,
108 .tx_function = dummy_interface_tx,
109 .admin_up_down_function = geneve_interface_admin_up_down,
114 format_geneve_header_with_length (u8 * s, va_list * args)
116 u32 dev_instance = va_arg (*args, u32);
117 s = format (s, "unimplemented dev %u", dev_instance);
122 VNET_HW_INTERFACE_CLASS (geneve_hw_class) = {
124 .format_header = format_geneve_header_with_length,
125 .build_rewrite = default_build_rewrite,
130 geneve_tunnel_restack_dpo (geneve_tunnel_t * t)
132 dpo_id_t dpo = DPO_INVALID;
133 u32 encap_index = ip46_address_is_ip4 (&t->remote) ?
134 geneve4_encap_node.index : geneve6_encap_node.index;
135 fib_forward_chain_type_t forw_type = ip46_address_is_ip4 (&t->remote) ?
136 FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
138 fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
139 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
143 static geneve_tunnel_t *
144 geneve_tunnel_from_fib_node (fib_node_t * node)
146 ASSERT (FIB_NODE_TYPE_GENEVE_TUNNEL == node->fn_type);
147 return ((geneve_tunnel_t *) (((char *) node) -
148 STRUCT_OFFSET_OF (geneve_tunnel_t, node)));
152 * Function definition to backwalk a FIB node -
153 * Here we will restack the new dpo of GENEVE DIP to encap node.
155 static fib_node_back_walk_rc_t
156 geneve_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
158 geneve_tunnel_restack_dpo (geneve_tunnel_from_fib_node (node));
159 return (FIB_NODE_BACK_WALK_CONTINUE);
163 * Function definition to get a FIB node from its index
166 geneve_tunnel_fib_node_get (fib_node_index_t index)
169 geneve_main_t *vxm = &geneve_main;
171 t = pool_elt_at_index (vxm->tunnels, index);
177 * Function definition to inform the FIB node that its last lock has gone.
180 geneve_tunnel_last_lock_gone (fib_node_t * node)
183 * The GENEVE tunnel is a root of the graph. As such
184 * it never has children and thus is never locked.
190 * Virtual function table registered by GENEVE tunnels
191 * for participation in the FIB object graph.
193 const static fib_node_vft_t geneve_vft = {
194 .fnv_get = geneve_tunnel_fib_node_get,
195 .fnv_last_lock = geneve_tunnel_last_lock_gone,
196 .fnv_back_walk = geneve_tunnel_back_walk,
200 #define foreach_copy_field \
202 _(mcast_sw_if_index) \
204 _(decap_next_index) \
209 geneve_rewrite (geneve_tunnel_t * t, bool is_ip6)
213 ip4_geneve_header_t *h4;
214 ip6_geneve_header_t *h6;
219 int len = is_ip6 ? sizeof *r.h6 : sizeof *r.h4;
220 #if SUPPORT_OPTIONS_HEADER==1
221 len += t->options_len;
224 vec_validate_aligned (r.rw, len - 1, CLIB_CACHE_LINE_BYTES);
227 geneve_header_t *geneve;
228 /* Fixed portion of the (outer) ip header */
231 ip4_header_t *ip = &r.h4->ip4;
232 udp = &r.h4->udp, geneve = &r.h4->geneve;
233 ip->ip_version_and_header_length = 0x45;
235 ip->protocol = IP_PROTOCOL_UDP;
237 ip->src_address = t->local.ip4;
238 ip->dst_address = t->remote.ip4;
240 /* we fix up the ip4 header length and checksum after-the-fact */
241 ip->checksum = ip4_header_checksum (ip);
245 ip6_header_t *ip = &r.h6->ip6;
246 udp = &r.h6->udp, geneve = &r.h6->geneve;
247 ip->ip_version_traffic_class_and_flow_label =
248 clib_host_to_net_u32 (6 << 28);
250 ip->protocol = IP_PROTOCOL_UDP;
252 ip->src_address = t->local.ip6;
253 ip->dst_address = t->remote.ip6;
256 /* UDP header, randomize local port on something, maybe? */
257 udp->src_port = clib_host_to_net_u16 (5251);
258 udp->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_geneve);
261 vnet_set_geneve_version (geneve, GENEVE_VERSION);
262 #if SUPPORT_OPTIONS_HEADER==1
263 vnet_set_geneve_options_len (geneve, t->options_len);
265 vnet_set_geneve_options_len (geneve, 0);
267 vnet_set_geneve_oamframe_bit (geneve, 0);
268 vnet_set_geneve_critical_bit (geneve, 0);
269 vnet_set_geneve_protocol (geneve, GENEVE_ETH_PROTOCOL);
271 vnet_geneve_hdr_1word_hton (geneve);
273 vnet_set_geneve_vni (geneve, t->vni);
280 geneve_decap_next_is_valid (geneve_main_t * vxm, u32 is_ip6,
281 u32 decap_next_index)
283 vlib_main_t *vm = vxm->vlib_main;
285 (!is_ip6) ? geneve4_input_node.index : geneve6_input_node.index;
286 vlib_node_runtime_t *r = vlib_node_get_runtime (vm, input_idx);
288 return decap_next_index < r->n_next_nodes;
292 hash_set_key_copy (uword ** h, void *key, uword v)
294 size_t ksz = hash_header (*h)->user;
295 void *copy = clib_mem_alloc (ksz);
296 clib_memcpy (copy, key, ksz);
297 hash_set_mem (*h, copy, v);
301 hash_unset_key_free (uword ** h, void *key)
303 hash_pair_t *hp = hash_get_pair_mem (*h, key);
305 key = uword_to_pointer (hp->key, void *);
306 hash_unset_mem (*h, key);
311 vtep_addr_ref (ip46_address_t * ip)
313 uword *vtep = ip46_address_is_ip4 (ip) ?
314 hash_get (geneve_main.vtep4, ip->ip4.as_u32) :
315 hash_get_mem (geneve_main.vtep6, &ip->ip6);
318 ip46_address_is_ip4 (ip) ?
319 hash_set (geneve_main.vtep4, ip->ip4.as_u32, 1) :
320 hash_set_key_copy (&geneve_main.vtep6, &ip->ip6, 1);
325 vtep_addr_unref (ip46_address_t * ip)
327 uword *vtep = ip46_address_is_ip4 (ip) ?
328 hash_get (geneve_main.vtep4, ip->ip4.as_u32) :
329 hash_get_mem (geneve_main.vtep6, &ip->ip6);
333 ip46_address_is_ip4 (ip) ?
334 hash_unset (geneve_main.vtep4, ip->ip4.as_u32) :
335 hash_unset_key_free (&geneve_main.vtep6, &ip->ip6);
339 typedef CLIB_PACKED (union
343 fib_node_index_t mfib_entry_index;
344 adj_index_t mcast_adj_index;
348 static inline mcast_shared_t
349 mcast_shared_get (ip46_address_t * ip)
351 ASSERT (ip46_address_is_multicast (ip));
352 uword *p = hash_get_mem (geneve_main.mcast_shared, ip);
354 return (mcast_shared_t)
360 mcast_shared_add (ip46_address_t * remote,
361 fib_node_index_t mfei, adj_index_t ai)
363 mcast_shared_t new_ep = {
364 .mcast_adj_index = ai,
365 .mfib_entry_index = mfei,
368 hash_set_key_copy (&geneve_main.mcast_shared, remote, new_ep.as_u64);
372 mcast_shared_remove (ip46_address_t * remote)
374 mcast_shared_t ep = mcast_shared_get (remote);
376 adj_unlock (ep.mcast_adj_index);
377 mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_GENEVE);
379 hash_unset_key_free (&geneve_main.mcast_shared, remote);
382 static inline fib_protocol_t
383 fib_ip_proto (bool is_ip6)
385 return (is_ip6) ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4;
388 int vnet_geneve_add_del_tunnel
389 (vnet_geneve_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
391 geneve_main_t *vxm = &geneve_main;
392 geneve_tunnel_t *t = 0;
393 vnet_main_t *vnm = vxm->vnet_main;
395 u32 hw_if_index = ~0;
396 u32 sw_if_index = ~0;
398 geneve4_tunnel_key_t key4;
399 geneve6_tunnel_key_t key6;
400 u32 is_ip6 = a->is_ip6;
404 key4.remote = a->remote.ip4.as_u32;
406 clib_host_to_net_u32 ((a->vni << GENEVE_VNI_SHIFT) & GENEVE_VNI_MASK);
407 p = hash_get (vxm->geneve4_tunnel_by_key, key4.as_u64);
411 key6.remote = a->remote.ip6;
413 clib_host_to_net_u32 ((a->vni << GENEVE_VNI_SHIFT) & GENEVE_VNI_MASK);
414 p = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6);
419 l2input_main_t *l2im = &l2input_main;
421 /* adding a tunnel: tunnel must not already exist */
423 return VNET_API_ERROR_TUNNEL_EXIST;
425 /*if not set explicitly, default to l2 */
426 if (a->decap_next_index == ~0)
427 a->decap_next_index = GENEVE_INPUT_NEXT_L2_INPUT;
428 if (!geneve_decap_next_is_valid (vxm, is_ip6, a->decap_next_index))
429 return VNET_API_ERROR_INVALID_DECAP_NEXT;
431 pool_get_aligned (vxm->tunnels, t, CLIB_CACHE_LINE_BYTES);
432 memset (t, 0, sizeof (*t));
434 /* copy from arg structure */
435 #define _(x) t->x = a->x;
439 rv = geneve_rewrite (t, is_ip6);
442 pool_put (vxm->tunnels, t);
448 hash_set_key_copy (&vxm->geneve6_tunnel_by_key, &key6,
451 hash_set (vxm->geneve4_tunnel_by_key, key4.as_u64, t - vxm->tunnels);
453 vnet_hw_interface_t *hi;
454 if (vec_len (vxm->free_geneve_tunnel_hw_if_indices) > 0)
456 vnet_interface_main_t *im = &vnm->interface_main;
457 hw_if_index = vxm->free_geneve_tunnel_hw_if_indices
458 [vec_len (vxm->free_geneve_tunnel_hw_if_indices) - 1];
459 _vec_len (vxm->free_geneve_tunnel_hw_if_indices) -= 1;
461 hi = vnet_get_hw_interface (vnm, hw_if_index);
462 hi->dev_instance = t - vxm->tunnels;
463 hi->hw_instance = hi->dev_instance;
465 /* clear old stats of freed tunnel before reuse */
466 sw_if_index = hi->sw_if_index;
467 vnet_interface_counter_lock (im);
468 vlib_zero_combined_counter
469 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
471 vlib_zero_combined_counter (&im->combined_sw_if_counters
472 [VNET_INTERFACE_COUNTER_RX],
474 vlib_zero_simple_counter (&im->sw_if_counters
475 [VNET_INTERFACE_COUNTER_DROP],
477 vnet_interface_counter_unlock (im);
481 hw_if_index = vnet_register_interface
482 (vnm, geneve_device_class.index, t - vxm->tunnels,
483 geneve_hw_class.index, t - vxm->tunnels);
484 hi = vnet_get_hw_interface (vnm, hw_if_index);
487 t->hw_if_index = hw_if_index;
488 t->sw_if_index = sw_if_index = hi->sw_if_index;
490 vec_validate_init_empty (vxm->tunnel_index_by_sw_if_index, sw_if_index,
492 vxm->tunnel_index_by_sw_if_index[sw_if_index] = t - vxm->tunnels;
494 /* setup l2 input config with l2 feature and bd 0 to drop packet */
495 vec_validate (l2im->configs, sw_if_index);
496 l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
497 l2im->configs[sw_if_index].bd_index = 0;
499 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
500 si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
501 vnet_sw_interface_set_flags (vnm, sw_if_index,
502 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
504 fib_node_init (&t->node, FIB_NODE_TYPE_GENEVE_TUNNEL);
505 fib_prefix_t tun_remote_pfx;
506 u32 encap_index = !is_ip6 ?
507 geneve4_encap_node.index : geneve6_encap_node.index;
508 vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
510 fib_prefix_from_ip46_addr (&t->remote, &tun_remote_pfx);
511 if (!ip46_address_is_multicast (&t->remote))
514 * source the FIB entry for the tunnel's destination
515 * and become a child thereof. The tunnel will then get poked
516 * when the forwarding for the entry updates, and the tunnel can
517 * re-stack accordingly
519 vtep_addr_ref (&t->local);
520 t->fib_entry_index = fib_table_entry_special_add
521 (t->encap_fib_index, &tun_remote_pfx, FIB_SOURCE_RR,
522 FIB_ENTRY_FLAG_NONE);
523 t->sibling_index = fib_entry_child_add
524 (t->fib_entry_index, FIB_NODE_TYPE_GENEVE_TUNNEL,
526 geneve_tunnel_restack_dpo (t);
530 /* Multicast tunnel -
531 * as the same mcast group can be used for mutiple mcast tunnels
532 * with different VNIs, create the output fib adjecency only if
533 * it does not already exist
535 fib_protocol_t fp = fib_ip_proto (is_ip6);
537 if (vtep_addr_ref (&t->remote) == 1)
539 fib_node_index_t mfei;
541 fib_route_path_t path = {
542 .frp_proto = fib_proto_to_dpo (fp),
543 .frp_addr = zero_addr,
544 .frp_sw_if_index = 0xffffffff,
547 .frp_flags = FIB_ROUTE_PATH_LOCAL,
549 const mfib_prefix_t mpfx = {
551 .fp_len = (is_ip6 ? 128 : 32),
552 .fp_grp_addr = tun_remote_pfx.fp_addr,
556 * Setup the (*,G) to receive traffic on the mcast group
557 * - the forwarding interface is for-us
558 * - the accepting interface is that from the API
560 mfib_table_entry_path_update (t->encap_fib_index,
563 &path, MFIB_ITF_FLAG_FORWARD);
565 path.frp_sw_if_index = a->mcast_sw_if_index;
566 path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
567 mfei = mfib_table_entry_path_update (t->encap_fib_index,
571 MFIB_ITF_FLAG_ACCEPT);
574 * Create the mcast adjacency to send traffic to the group
576 ai = adj_mcast_add_or_lock (fp,
577 fib_proto_to_link (fp),
578 a->mcast_sw_if_index);
581 * create a new end-point
583 mcast_shared_add (&t->remote, mfei, ai);
586 dpo_id_t dpo = DPO_INVALID;
587 mcast_shared_t ep = mcast_shared_get (&t->remote);
589 /* Stack shared mcast remote mac addr rewrite on encap */
590 dpo_set (&dpo, DPO_ADJACENCY_MCAST,
591 fib_proto_to_dpo (fp), ep.mcast_adj_index);
593 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
595 flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
598 /* Set geneve tunnel output node */
599 hi->output_node_index = encap_index;
601 vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
606 /* deleting a tunnel: tunnel must exist */
608 return VNET_API_ERROR_NO_SUCH_ENTRY;
610 t = pool_elt_at_index (vxm->tunnels, p[0]);
612 sw_if_index = t->sw_if_index;
613 vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
614 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, t->sw_if_index);
615 si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
617 /* make sure tunnel is removed from l2 bd or xconnect */
618 set_int_l2_mode (vxm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0,
620 vec_add1 (vxm->free_geneve_tunnel_hw_if_indices, t->hw_if_index);
622 vxm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
625 hash_unset (vxm->geneve4_tunnel_by_key, key4.as_u64);
627 hash_unset_key_free (&vxm->geneve6_tunnel_by_key, &key6);
629 if (!ip46_address_is_multicast (&t->remote))
631 vtep_addr_unref (&t->local);
632 fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
633 fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
635 else if (vtep_addr_unref (&t->remote) == 0)
637 mcast_shared_remove (&t->remote);
640 fib_node_deinit (&t->node);
641 vec_free (t->rewrite);
642 pool_put (vxm->tunnels, t);
646 *sw_if_indexp = sw_if_index;
652 get_decap_next_for_node (u32 node_index, u32 ipv4_set)
654 geneve_main_t *vxm = &geneve_main;
655 vlib_main_t *vm = vxm->vlib_main;
656 uword input_node = (ipv4_set) ? geneve4_input_node.index :
657 geneve6_input_node.index;
659 return vlib_node_add_next (vm, input_node, node_index);
663 unformat_decap_next (unformat_input_t * input, va_list * args)
665 u32 *result = va_arg (*args, u32 *);
666 u32 ipv4_set = va_arg (*args, int);
667 geneve_main_t *vxm = &geneve_main;
668 vlib_main_t *vm = vxm->vlib_main;
672 if (unformat (input, "l2"))
673 *result = GENEVE_INPUT_NEXT_L2_INPUT;
674 else if (unformat (input, "node %U", unformat_vlib_node, vm, &node_index))
675 *result = get_decap_next_for_node (node_index, ipv4_set);
676 else if (unformat (input, "%d", &tmp))
683 static clib_error_t *
684 geneve_add_del_tunnel_command_fn (vlib_main_t * vm,
685 unformat_input_t * input,
686 vlib_cli_command_t * cmd)
688 unformat_input_t _line_input, *line_input = &_line_input;
689 ip46_address_t local, remote;
696 u32 encap_fib_index = 0;
697 u32 mcast_sw_if_index = ~0;
698 u32 decap_next_index = GENEVE_INPUT_NEXT_L2_INPUT;
702 vnet_geneve_add_del_tunnel_args_t _a, *a = &_a;
703 u32 tunnel_sw_if_index;
704 clib_error_t *error = NULL;
706 /* Cant "universally zero init" (={0}) due to GCC bug 53119 */
707 memset (&local, 0, sizeof local);
708 memset (&remote, 0, sizeof remote);
710 /* Get a line of input. */
711 if (!unformat_user (input, unformat_line_input, line_input))
714 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
716 if (unformat (line_input, "del"))
720 else if (unformat (line_input, "local %U",
721 unformat_ip4_address, &local.ip4))
726 else if (unformat (line_input, "remote %U",
727 unformat_ip4_address, &remote.ip4))
732 else if (unformat (line_input, "local %U",
733 unformat_ip6_address, &local.ip6))
738 else if (unformat (line_input, "remote %U",
739 unformat_ip6_address, &remote.ip6))
744 else if (unformat (line_input, "group %U %U",
745 unformat_ip4_address, &remote.ip4,
746 unformat_vnet_sw_interface,
747 vnet_get_main (), &mcast_sw_if_index))
749 grp_set = remote_set = 1;
752 else if (unformat (line_input, "group %U %U",
753 unformat_ip6_address, &remote.ip6,
754 unformat_vnet_sw_interface,
755 vnet_get_main (), &mcast_sw_if_index))
757 grp_set = remote_set = 1;
760 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
762 encap_fib_index = fib_table_find (fib_ip_proto (ipv6_set), tmp);
763 if (encap_fib_index == ~0)
766 clib_error_return (0, "nonexistent encap-vrf-id %d", tmp);
770 else if (unformat (line_input, "decap-next %U", unformat_decap_next,
771 &decap_next_index, ipv4_set))
773 else if (unformat (line_input, "vni %d", &vni))
777 error = clib_error_return (0, "vni %d out of range", vni);
783 error = clib_error_return (0, "parse error: '%U'",
784 format_unformat_error, line_input);
791 error = clib_error_return (0, "tunnel local address not specified");
797 error = clib_error_return (0, "tunnel remote address not specified");
801 if (grp_set && !ip46_address_is_multicast (&remote))
803 error = clib_error_return (0, "tunnel group address not multicast");
807 if (grp_set == 0 && ip46_address_is_multicast (&remote))
809 error = clib_error_return (0, "remote address must be unicast");
813 if (grp_set && mcast_sw_if_index == ~0)
815 error = clib_error_return (0, "tunnel nonexistent multicast device");
819 if (ipv4_set && ipv6_set)
821 error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
825 if (ip46_address_cmp (&local, &remote) == 0)
828 clib_error_return (0, "local and remote addresses are identical");
832 if (decap_next_index == ~0)
834 error = clib_error_return (0, "next node not found");
840 error = clib_error_return (0, "vni not specified");
844 memset (a, 0, sizeof (*a));
847 a->is_ip6 = ipv6_set;
849 #define _(x) a->x = x;
853 rv = vnet_geneve_add_del_tunnel (a, &tunnel_sw_if_index);
859 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
860 vnet_get_main (), tunnel_sw_if_index);
863 case VNET_API_ERROR_TUNNEL_EXIST:
864 error = clib_error_return (0, "tunnel already exists...");
867 case VNET_API_ERROR_NO_SUCH_ENTRY:
868 error = clib_error_return (0, "tunnel does not exist...");
872 error = clib_error_return
873 (0, "vnet_geneve_add_del_tunnel returned %d", rv);
878 unformat_free (line_input);
884 * Add or delete a GENEVE Tunnel.
886 * GENEVE provides the features needed to allow L2 bridge domains (BDs)
887 * to span multiple servers. This is done by building an L2 overlay on
888 * top of an L3 network underlay using GENEVE tunnels.
890 * This makes it possible for servers to be co-located in the same data
891 * center or be separated geographically as long as they are reachable
892 * through the underlay L3 network.
894 * You can refer to this kind of L2 overlay bridge domain as a GENEVE
898 * Example of how to create a GENEVE Tunnel:
899 * @cliexcmd{create geneve tunnel local 10.0.3.1 remote 10.0.3.3 vni 13 encap-vrf-id 7}
900 * Example of how to delete a GENEVE Tunnel:
901 * @cliexcmd{create geneve tunnel local 10.0.3.1 remote 10.0.3.3 vni 13 del}
904 VLIB_CLI_COMMAND (create_geneve_tunnel_command, static) = {
905 .path = "create geneve tunnel",
907 "create geneve tunnel local <local-vtep-addr>"
908 " {remote <remote-vtep-addr>|group <mcast-vtep-addr> <intf-name>} vni <nn>"
909 " [encap-vrf-id <nn>] [decap-next [l2|node <name>]] [del]",
910 .function = geneve_add_del_tunnel_command_fn,
914 static clib_error_t *
915 show_geneve_tunnel_command_fn (vlib_main_t * vm,
916 unformat_input_t * input,
917 vlib_cli_command_t * cmd)
919 geneve_main_t *vxm = &geneve_main;
922 if (pool_elts (vxm->tunnels) == 0)
923 vlib_cli_output (vm, "No geneve tunnels configured...");
925 pool_foreach (t, vxm->tunnels, (
927 vlib_cli_output (vm, "%U",
928 format_geneve_tunnel, t);
936 * Display all the GENEVE Tunnel entries.
939 * Example of how to display the GENEVE Tunnel entries:
940 * @cliexstart{show geneve tunnel}
941 * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
945 VLIB_CLI_COMMAND (show_geneve_tunnel_command, static) = {
946 .path = "show geneve tunnel",
947 .short_help = "show geneve tunnel",
948 .function = show_geneve_tunnel_command_fn,
954 vnet_int_geneve_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
957 vnet_feature_enable_disable ("ip6-unicast", "ip6-geneve-bypass",
958 sw_if_index, is_enable, 0, 0);
960 vnet_feature_enable_disable ("ip4-unicast", "ip4-geneve-bypass",
961 sw_if_index, is_enable, 0, 0);
965 static clib_error_t *
966 set_ip_geneve_bypass (u32 is_ip6,
967 unformat_input_t * input, vlib_cli_command_t * cmd)
969 unformat_input_t _line_input, *line_input = &_line_input;
970 vnet_main_t *vnm = vnet_get_main ();
971 clib_error_t *error = 0;
972 u32 sw_if_index, is_enable;
977 if (!unformat_user (input, unformat_line_input, line_input))
980 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
983 (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
985 else if (unformat (line_input, "del"))
989 error = unformat_parse_error (line_input);
994 if (~0 == sw_if_index)
996 error = clib_error_return (0, "unknown interface `%U'",
997 format_unformat_error, line_input);
1001 vnet_int_geneve_bypass_mode (sw_if_index, is_ip6, is_enable);
1004 unformat_free (line_input);
1009 static clib_error_t *
1010 set_ip4_geneve_bypass (vlib_main_t * vm,
1011 unformat_input_t * input, vlib_cli_command_t * cmd)
1013 return set_ip_geneve_bypass (0, input, cmd);
1017 * This command adds the 'ip4-geneve-bypass' graph node for a given interface.
1018 * By adding the IPv4 geneve-bypass graph node to an interface, the node checks
1019 * for and validate input geneve packet and bypass ip4-lookup, ip4-local,
1020 * ip4-udp-lookup nodes to speedup geneve packet forwarding. This node will
1021 * cause extra overhead to for non-geneve packets which is kept at a minimum.
1025 * Example of graph node before ip4-geneve-bypass is enabled:
1026 * @cliexstart{show vlib graph ip4-geneve-bypass}
1027 * Name Next Previous
1028 * ip4-geneve-bypass error-drop [0]
1033 * Example of how to enable ip4-geneve-bypass on an interface:
1034 * @cliexcmd{set interface ip geneve-bypass GigabitEthernet2/0/0}
1036 * Example of graph node after ip4-geneve-bypass is enabled:
1037 * @cliexstart{show vlib graph ip4-geneve-bypass}
1038 * Name Next Previous
1039 * ip4-geneve-bypass error-drop [0] ip4-input
1040 * geneve4-input [1] ip4-input-no-checksum
1044 * Example of how to display the feature enabed on an interface:
1045 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1046 * IP feature paths configured on GigabitEthernet2/0/0...
1054 * Example of how to disable ip4-geneve-bypass on an interface:
1055 * @cliexcmd{set interface ip geneve-bypass GigabitEthernet2/0/0 del}
1059 VLIB_CLI_COMMAND (set_interface_ip_geneve_bypass_command, static) = {
1060 .path = "set interface ip geneve-bypass",
1061 .function = set_ip4_geneve_bypass,
1062 .short_help = "set interface ip geneve-bypass <interface> [del]",
1066 static clib_error_t *
1067 set_ip6_geneve_bypass (vlib_main_t * vm,
1068 unformat_input_t * input, vlib_cli_command_t * cmd)
1070 return set_ip_geneve_bypass (1, input, cmd);
1074 * This command adds the 'ip6-geneve-bypass' graph node for a given interface.
1075 * By adding the IPv6 geneve-bypass graph node to an interface, the node checks
1076 * for and validate input geneve packet and bypass ip6-lookup, ip6-local,
1077 * ip6-udp-lookup nodes to speedup geneve packet forwarding. This node will
1078 * cause extra overhead to for non-geneve packets which is kept at a minimum.
1082 * Example of graph node before ip6-geneve-bypass is enabled:
1083 * @cliexstart{show vlib graph ip6-geneve-bypass}
1084 * Name Next Previous
1085 * ip6-geneve-bypass error-drop [0]
1090 * Example of how to enable ip6-geneve-bypass on an interface:
1091 * @cliexcmd{set interface ip6 geneve-bypass GigabitEthernet2/0/0}
1093 * Example of graph node after ip6-geneve-bypass is enabled:
1094 * @cliexstart{show vlib graph ip6-geneve-bypass}
1095 * Name Next Previous
1096 * ip6-geneve-bypass error-drop [0] ip6-input
1097 * geneve6-input [1] ip4-input-no-checksum
1101 * Example of how to display the feature enabed on an interface:
1102 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1103 * IP feature paths configured on GigabitEthernet2/0/0...
1111 * Example of how to disable ip6-geneve-bypass on an interface:
1112 * @cliexcmd{set interface ip6 geneve-bypass GigabitEthernet2/0/0 del}
1116 VLIB_CLI_COMMAND (set_interface_ip6_geneve_bypass_command, static) = {
1117 .path = "set interface ip6 geneve-bypass",
1118 .function = set_ip6_geneve_bypass,
1119 .short_help = "set interface ip geneve-bypass <interface> [del]",
1124 geneve_init (vlib_main_t * vm)
1126 geneve_main_t *vxm = &geneve_main;
1128 vxm->vnet_main = vnet_get_main ();
1129 vxm->vlib_main = vm;
1131 /* initialize the ip6 hash */
1132 vxm->geneve6_tunnel_by_key = hash_create_mem (0,
1133 sizeof (geneve6_tunnel_key_t),
1135 vxm->vtep6 = hash_create_mem (0, sizeof (ip6_address_t), sizeof (uword));
1136 vxm->mcast_shared = hash_create_mem (0,
1137 sizeof (ip46_address_t),
1138 sizeof (mcast_shared_t));
1140 udp_register_dst_port (vm, UDP_DST_PORT_geneve,
1141 geneve4_input_node.index, /* is_ip4 */ 1);
1142 udp_register_dst_port (vm, UDP_DST_PORT_geneve6,
1143 geneve6_input_node.index, /* is_ip4 */ 0);
1145 fib_node_register_type (FIB_NODE_TYPE_GENEVE_TUNNEL, &geneve_vft);
1150 VLIB_INIT_FUNCTION (geneve_init);
1153 * fd.io coding-style-patch-verification: ON
1156 * eval: (c-set-style "gnu")