2 * Copyright (c) 2018 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.
16 #include <plugins/gbp/gbp_vxlan.h>
17 #include <plugins/gbp/gbp_itf.h>
18 #include <plugins/gbp/gbp_learn.h>
19 #include <plugins/gbp/gbp_bridge_domain.h>
20 #include <plugins/gbp/gbp_route_domain.h>
21 #include <plugins/gbp/gbp_sclass.h>
23 #include <vnet/vxlan-gbp/vxlan_gbp.h>
24 #include <vlibmemory/api.h>
25 #include <vnet/fib/fib_table.h>
28 * A reference to a VXLAN-GBP tunnel created as a child/dependent tunnel
29 * of the tempplate GBP-VXLAN tunnel
31 typedef struct vxlan_tunnel_ref_t_
37 gbp_vxlan_tunnel_layer_t vxr_layer;
48 vlib_log_class_t gt_logger;
51 * Pool of template tunnels
53 gbp_vxlan_tunnel_t *gbp_vxlan_tunnel_pool;
56 * Pool of child tunnels
58 vxlan_tunnel_ref_t *vxlan_tunnel_ref_pool;
61 * DB of template interfaces by SW interface index
63 index_t *gbp_vxlan_tunnel_db;
66 * DB of child interfaces by SW interface index
68 index_t *vxlan_tunnel_ref_db;
71 static char *gbp_vxlan_tunnel_layer_strings[] = {
72 #define _(n,s) [GBP_VXLAN_TUN_##n] = s,
73 forecah_gbp_vxlan_tunnel_layer
77 #define GBP_VXLAN_TUN_DBG(...) \
78 vlib_log_debug (gt_logger, __VA_ARGS__);
82 always_inline gbp_vxlan_tunnel_t *
83 gbp_vxlan_tunnel_get (index_t gti)
85 return (pool_elt_at_index (gbp_vxlan_tunnel_pool, gti));
88 static vxlan_tunnel_ref_t *
89 vxlan_tunnel_ref_get (index_t vxri)
91 return (pool_elt_at_index (vxlan_tunnel_ref_pool, vxri));
95 format_vxlan_tunnel_ref (u8 * s, va_list * args)
97 index_t vxri = va_arg (*args, u32);
98 vxlan_tunnel_ref_t *vxr;
100 vxr = vxlan_tunnel_ref_get (vxri);
102 s = format (s, "[%U locks:%d]", format_vnet_sw_if_index_name,
103 vnet_get_main (), vxr->vxr_sw_if_index, vxr->vxr_locks);
109 gdb_vxlan_dep_add (gbp_vxlan_tunnel_t * gt,
110 const ip46_address_t * src, const ip46_address_t * dst)
112 vnet_vxlan_gbp_tunnel_add_del_args_t args = {
114 .is_ip6 = !ip46_address_is_ip4 (src),
119 .mode = (GBP_VXLAN_TUN_L2 == gt->gt_layer ?
120 VXLAN_GBP_TUNNEL_MODE_L2 : VXLAN_GBP_TUNNEL_MODE_L3),
122 vxlan_tunnel_ref_t *vxr;
128 rv = vnet_vxlan_gbp_tunnel_add_del (&args, &sw_if_index);
130 if (VNET_API_ERROR_TUNNEL_EXIST == rv)
132 vxri = vxlan_tunnel_ref_db[sw_if_index];
134 vxr = vxlan_tunnel_ref_get (vxri);
139 ASSERT (~0 != sw_if_index);
140 GBP_VXLAN_TUN_DBG ("add-dep:%U %U %U %d", format_vnet_sw_if_index_name,
141 vnet_get_main (), sw_if_index,
142 format_ip46_address, src, IP46_TYPE_ANY,
143 format_ip46_address, dst, IP46_TYPE_ANY, gt->gt_vni);
145 pool_get_zero (vxlan_tunnel_ref_pool, vxr);
147 vxri = (vxr - vxlan_tunnel_ref_pool);
148 vxr->vxr_parent = gt - gbp_vxlan_tunnel_pool;
149 vxr->vxr_sw_if_index = sw_if_index;
151 vxr->vxr_layer = gt->gt_layer;
154 * store the child both on the parent's list and the global DB
156 vec_add1 (gt->gt_tuns, vxri);
158 vec_validate_init_empty (vxlan_tunnel_ref_db,
159 vxr->vxr_sw_if_index, INDEX_INVALID);
160 vxlan_tunnel_ref_db[vxr->vxr_sw_if_index] = vxri;
162 if (GBP_VXLAN_TUN_L2 == vxr->vxr_layer)
164 l2output_feat_masks_t ofeat;
165 l2input_feat_masks_t ifeat;
166 gbp_bridge_domain_t *gbd;
168 gbd = gbp_bridge_domain_get (gt->gt_gbd);
169 vxr->vxr_itf = gbp_itf_add_and_lock (vxr->vxr_sw_if_index,
172 ofeat = (L2OUTPUT_FEAT_GBP_POLICY_MAC |
173 L2OUTPUT_FEAT_GBP_ID_2_SCLASS);
174 ifeat = L2INPUT_FEAT_GBP_SCLASS_2_ID;
176 if (!(gbd->gb_flags & GBP_BD_FLAG_DO_NOT_LEARN))
177 ifeat |= L2INPUT_FEAT_GBP_LEARN;
179 gbp_itf_set_l2_output_feature (vxr->vxr_itf,
180 vxr->vxr_sw_if_index, ofeat);
181 gbp_itf_set_l2_input_feature (vxr->vxr_itf,
182 vxr->vxr_sw_if_index, ifeat);
186 const gbp_route_domain_t *grd;
187 fib_protocol_t fproto;
189 grd = gbp_route_domain_get (gt->gt_grd);
191 FOR_EACH_FIB_IP_PROTOCOL (fproto)
192 ip_table_bind (fproto, vxr->vxr_sw_if_index,
193 grd->grd_table_id[fproto], 1);
195 gbp_learn_enable (vxr->vxr_sw_if_index, GBP_LEARN_MODE_L3);
196 gbp_sclass_enable_ip (vxr->vxr_sw_if_index);
200 return (sw_if_index);
204 vxlan_gbp_tunnel_get_parent (u32 sw_if_index)
206 ASSERT ((sw_if_index < vec_len (vxlan_tunnel_ref_db)) &&
207 (INDEX_INVALID != vxlan_tunnel_ref_db[sw_if_index]));
209 gbp_vxlan_tunnel_t *gt;
210 vxlan_tunnel_ref_t *vxr;
212 vxr = vxlan_tunnel_ref_get (vxlan_tunnel_ref_db[sw_if_index]);
213 gt = gbp_vxlan_tunnel_get (vxr->vxr_parent);
215 return (gt->gt_sw_if_index);
218 gbp_vxlan_tunnel_type_t
219 gbp_vxlan_tunnel_get_type (u32 sw_if_index)
221 if (sw_if_index < vec_len (vxlan_tunnel_ref_db) &&
222 INDEX_INVALID != vxlan_tunnel_ref_db[sw_if_index])
224 return (VXLAN_GBP_TUNNEL);
226 else if (sw_if_index < vec_len (gbp_vxlan_tunnel_db) &&
227 INDEX_INVALID != gbp_vxlan_tunnel_db[sw_if_index])
229 return (GBP_VXLAN_TEMPLATE_TUNNEL);
233 return (GBP_VXLAN_TEMPLATE_TUNNEL);
237 gbp_vxlan_tunnel_clone_and_lock (u32 sw_if_index,
238 const ip46_address_t * src,
239 const ip46_address_t * dst)
241 gbp_vxlan_tunnel_t *gt;
244 gti = gbp_vxlan_tunnel_db[sw_if_index];
246 if (INDEX_INVALID == gti)
249 gt = pool_elt_at_index (gbp_vxlan_tunnel_pool, gti);
251 return (gdb_vxlan_dep_add (gt, src, dst));
255 gdb_vxlan_dep_del (index_t vxri)
257 vxlan_tunnel_ref_t *vxr;
258 gbp_vxlan_tunnel_t *gt;
261 vxr = vxlan_tunnel_ref_get (vxri);
262 gt = gbp_vxlan_tunnel_get (vxr->vxr_parent);
264 GBP_VXLAN_TUN_DBG ("del-dep:%U", format_vxlan_tunnel_ref, vxri);
266 vxlan_tunnel_ref_db[vxr->vxr_sw_if_index] = INDEX_INVALID;
267 pos = vec_search (gt->gt_tuns, vxri);
270 vec_del1 (gt->gt_tuns, pos);
272 if (GBP_VXLAN_TUN_L2 == vxr->vxr_layer)
274 gbp_itf_set_l2_output_feature (vxr->vxr_itf, vxr->vxr_sw_if_index,
276 gbp_itf_set_l2_input_feature (vxr->vxr_itf, vxr->vxr_sw_if_index,
278 gbp_itf_unlock (vxr->vxr_itf);
282 fib_protocol_t fproto;
284 FOR_EACH_FIB_IP_PROTOCOL (fproto)
285 ip_table_bind (fproto, vxr->vxr_sw_if_index, 0, 0);
286 gbp_sclass_disable_ip (vxr->vxr_sw_if_index);
287 gbp_learn_disable (vxr->vxr_sw_if_index, GBP_LEARN_MODE_L3);
290 vnet_vxlan_gbp_tunnel_del (vxr->vxr_sw_if_index);
292 pool_put (vxlan_tunnel_ref_pool, vxr);
296 vxlan_gbp_tunnel_unlock (u32 sw_if_index)
298 vxlan_tunnel_ref_t *vxr;
301 vxri = vxlan_tunnel_ref_db[sw_if_index];
303 ASSERT (vxri != INDEX_INVALID);
305 vxr = vxlan_tunnel_ref_get (vxri);
308 if (0 == vxr->vxr_locks)
310 gdb_vxlan_dep_del (vxri);
315 vxlan_gbp_tunnel_lock (u32 sw_if_index)
317 vxlan_tunnel_ref_t *vxr;
320 vxri = vxlan_tunnel_ref_db[sw_if_index];
322 ASSERT (vxri != INDEX_INVALID);
324 vxr = vxlan_tunnel_ref_get (vxri);
328 #define foreach_gbp_vxlan_input_next \
329 _(DROP, "error-drop") \
330 _(L2_INPUT, "l2-input") \
331 _(IP4_INPUT, "ip4-input") \
332 _(IP6_INPUT, "ip6-input")
336 #define _(s,n) GBP_VXLAN_INPUT_NEXT_##s,
337 foreach_gbp_vxlan_input_next
339 GBP_VXLAN_INPUT_N_NEXT,
340 } gbp_vxlan_input_next_t;
342 #define foreach_gbp_vxlan_error \
343 _(DECAPPED, "decapped") \
344 _(LEARNED, "learned")
348 #define _(s,n) GBP_VXLAN_ERROR_##s,
349 foreach_gbp_vxlan_error
352 } gbp_vxlan_input_error_t;
354 static char *gbp_vxlan_error_strings[] = {
356 foreach_gbp_vxlan_error
360 typedef struct gbp_vxlan_trace_t_
371 gbp_vxlan_decap (vlib_main_t * vm,
372 vlib_node_runtime_t * node,
373 vlib_frame_t * from_frame, u8 is_ip4)
375 u32 n_left_to_next, n_left_from, next_index, *to_next, *from;
378 from = vlib_frame_vector_args (from_frame);
379 n_left_from = from_frame->n_vectors;
381 while (n_left_from > 0)
384 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
386 while (n_left_from > 0 && n_left_to_next > 0)
388 vxlan_gbp_header_t *vxlan_gbp0;
389 gbp_vxlan_input_next_t next0;
390 gbp_vxlan_tunnel_t *gt0;
395 bi0 = to_next[0] = from[0];
400 next0 = GBP_VXLAN_INPUT_NEXT_DROP;
402 b0 = vlib_get_buffer (vm, bi0);
404 vlib_buffer_get_current (b0) - sizeof (vxlan_gbp_header_t);
406 vni0 = vxlan_gbp_get_vni (vxlan_gbp0);
407 p = hash_get (gv_db, vni0);
409 if (PREDICT_FALSE (NULL == p))
412 next0 = GBP_VXLAN_INPUT_NEXT_DROP;
416 gt0 = gbp_vxlan_tunnel_get (p[0]);
418 vnet_buffer (b0)->sw_if_index[VLIB_RX] = gt0->gt_sw_if_index;
420 if (GBP_VXLAN_TUN_L2 == gt0->gt_layer)
422 * An L2 layer tunnel goes into the BD
424 next0 = GBP_VXLAN_INPUT_NEXT_L2_INPUT;
428 * An L3 layer tunnel needs to strip the L2 header
429 * an inject into the RD
431 ethernet_header_t *e0;
434 e0 = vlib_buffer_get_current (b0);
435 type0 = clib_net_to_host_u16 (e0->type);
438 case ETHERNET_TYPE_IP4:
439 next0 = GBP_VXLAN_INPUT_NEXT_IP4_INPUT;
441 case ETHERNET_TYPE_IP6:
442 next0 = GBP_VXLAN_INPUT_NEXT_IP6_INPUT;
447 vlib_buffer_advance (b0, sizeof (*e0));
452 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
454 gbp_vxlan_trace_t *tr;
456 tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
457 tr->dropped = (next0 == GBP_VXLAN_INPUT_NEXT_DROP);
459 tr->sw_if_index = (gt0 ? gt0->gt_sw_if_index : ~0);
460 tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
461 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
464 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
465 to_next, n_left_to_next,
469 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
472 return from_frame->n_vectors;
476 format_gbp_vxlan_rx_trace (u8 * s, va_list * args)
478 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
479 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
480 gbp_vxlan_trace_t *t = va_arg (*args, gbp_vxlan_trace_t *);
482 s = format (s, "vni:%d dropped:%d rx:%d sclass:%d flags:%U",
483 t->vni, t->dropped, t->sw_if_index,
484 t->sclass, format_vxlan_gbp_header_gpflags, t->flags);
490 gbp_vxlan4_decap (vlib_main_t * vm,
491 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
493 return gbp_vxlan_decap (vm, node, from_frame, 1);
497 VLIB_REGISTER_NODE (gbp_vxlan4_input_node) =
499 .function = gbp_vxlan4_decap,
500 .name = "gbp-vxlan4",
501 .vector_size = sizeof (u32),
502 .n_errors = GBP_VXLAN_N_ERROR,
503 .error_strings = gbp_vxlan_error_strings,
504 .n_next_nodes = GBP_VXLAN_INPUT_N_NEXT,
505 .format_trace = format_gbp_vxlan_rx_trace,
507 #define _(s,n) [GBP_VXLAN_INPUT_NEXT_##s] = n,
508 foreach_gbp_vxlan_input_next
512 VLIB_NODE_FUNCTION_MULTIARCH (gbp_vxlan4_input_node, gbp_vxlan4_decap)
517 gbp_vxlan_walk (gbp_vxlan_cb_t cb, void *ctx)
519 gbp_vxlan_tunnel_t *gt;
522 pool_foreach (gt, gbp_vxlan_tunnel_pool,
524 if (WALK_CONTINUE != cb(gt, ctx))
531 gbp_vxlan_tunnel_show_one (gbp_vxlan_tunnel_t * gt, void *ctx)
533 vlib_cli_output (ctx, "%U", format_gbp_vxlan_tunnel,
534 gt - gbp_vxlan_tunnel_pool);
536 return (WALK_CONTINUE);
540 format_gbp_vxlan_tunnel_name (u8 * s, va_list * args)
542 u32 dev_instance = va_arg (*args, u32);
544 return format (s, "gbp-vxlan-%d", dev_instance);
548 format_gbp_vxlan_tunnel_layer (u8 * s, va_list * args)
550 gbp_vxlan_tunnel_layer_t gl = va_arg (*args, gbp_vxlan_tunnel_layer_t);
551 s = format (s, "%s", gbp_vxlan_tunnel_layer_strings[gl]);
557 format_gbp_vxlan_tunnel (u8 * s, va_list * args)
559 u32 dev_instance = va_arg (*args, u32);
560 CLIB_UNUSED (int verbose) = va_arg (*args, int);
561 gbp_vxlan_tunnel_t *gt = gbp_vxlan_tunnel_get (dev_instance);
564 s = format (s, "GBP VXLAN tunnel: hw:%d sw:%d vni:%d %U",
565 gt->gt_hw_if_index, gt->gt_sw_if_index, gt->gt_vni,
566 format_gbp_vxlan_tunnel_layer, gt->gt_layer);
567 if (GBP_VXLAN_TUN_L2 == gt->gt_layer)
568 s = format (s, " BD:%d bd-index:%d", gt->gt_bd_rd_id, gt->gt_bd_index);
570 s = format (s, " RD:%d fib-index:[%d,%d]",
572 gt->gt_fib_index[FIB_PROTOCOL_IP4],
573 gt->gt_fib_index[FIB_PROTOCOL_IP6]);
575 s = format (s, " children:[");
576 vec_foreach (vxri, gt->gt_tuns)
578 s = format (s, "%U, ", format_vxlan_tunnel_ref, *vxri);
585 typedef struct gbp_vxlan_tx_trace_t_
588 } gbp_vxlan_tx_trace_t;
591 format_gbp_vxlan_tx_trace (u8 * s, va_list * args)
593 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
594 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
595 gbp_vxlan_tx_trace_t *t = va_arg (*args, gbp_vxlan_tx_trace_t *);
597 s = format (s, "GBP-VXLAN: vni:%d", t->vni);
603 gbp_vxlan_interface_admin_up_down (vnet_main_t * vnm,
604 u32 hw_if_index, u32 flags)
606 vnet_hw_interface_t *hi;
609 hi = vnet_get_hw_interface (vnm, hw_if_index);
611 if (NULL == gbp_vxlan_tunnel_db ||
612 hi->sw_if_index >= vec_len (gbp_vxlan_tunnel_db))
615 ti = gbp_vxlan_tunnel_db[hi->sw_if_index];
618 /* not one of ours */
621 if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
622 vnet_hw_interface_set_flags (vnm, hw_if_index,
623 VNET_HW_INTERFACE_FLAG_LINK_UP);
625 vnet_hw_interface_set_flags (vnm, hw_if_index, 0);
631 gbp_vxlan_interface_tx (vlib_main_t * vm,
632 vlib_node_runtime_t * node, vlib_frame_t * frame)
634 clib_warning ("you shouldn't be here, leaking buffers...");
635 return frame->n_vectors;
639 VNET_DEVICE_CLASS (gbp_vxlan_device_class) = {
640 .name = "GBP VXLAN tunnel-template",
641 .format_device_name = format_gbp_vxlan_tunnel_name,
642 .format_device = format_gbp_vxlan_tunnel,
643 .format_tx_trace = format_gbp_vxlan_tx_trace,
644 .admin_up_down_function = gbp_vxlan_interface_admin_up_down,
645 .tx_function = gbp_vxlan_interface_tx,
648 VNET_HW_INTERFACE_CLASS (gbp_vxlan_hw_interface_class) = {
650 .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
655 gbp_vxlan_tunnel_add (u32 vni, gbp_vxlan_tunnel_layer_t layer,
656 u32 bd_rd_id, u32 * sw_if_indexp)
658 gbp_vxlan_tunnel_t *gt;
664 p = hash_get (gv_db, vni);
666 GBP_VXLAN_TUN_DBG ("add: %d %d %d", vni, layer, bd_rd_id);
670 vnet_sw_interface_t *si;
671 vnet_hw_interface_t *hi;
675 gbi = grdi = INDEX_INVALID;
677 if (layer == GBP_VXLAN_TUN_L2)
679 gbi = gbp_bridge_domain_find_and_lock (bd_rd_id);
681 if (INDEX_INVALID == gbi)
683 return (VNET_API_ERROR_BD_NOT_MODIFIABLE);
688 grdi = gbp_route_domain_find_and_lock (bd_rd_id);
690 if (INDEX_INVALID == grdi)
692 return (VNET_API_ERROR_NO_SUCH_FIB);
696 vnm = vnet_get_main ();
697 pool_get (gbp_vxlan_tunnel_pool, gt);
698 gti = gt - gbp_vxlan_tunnel_pool;
701 gt->gt_layer = layer;
702 gt->gt_bd_rd_id = bd_rd_id;
703 gt->gt_hw_if_index = vnet_register_interface (vnm,
704 gbp_vxlan_device_class.index,
706 gbp_vxlan_hw_interface_class.index,
709 hi = vnet_get_hw_interface (vnm, gt->gt_hw_if_index);
711 gt->gt_sw_if_index = hi->sw_if_index;
713 /* don't flood packets in a BD to these interfaces */
714 si = vnet_get_sw_interface (vnm, gt->gt_sw_if_index);
715 si->flood_class = VNET_FLOOD_CLASS_NO_FLOOD;
717 if (layer == GBP_VXLAN_TUN_L2)
719 gbp_bridge_domain_t *gb;
721 gb = gbp_bridge_domain_get (gbi);
724 gt->gt_bd_index = gb->gb_bd_index;
725 gb->gb_vni_sw_if_index = gt->gt_sw_if_index;
726 /* set it up as a GBP interface */
727 gt->gt_itf = gbp_itf_add_and_lock (gt->gt_sw_if_index,
729 gbp_learn_enable (gt->gt_sw_if_index, GBP_LEARN_MODE_L2);
730 gbp_sclass_enable_l2 (gt->gt_sw_if_index);
734 gbp_route_domain_t *grd;
735 fib_protocol_t fproto;
737 grd = gbp_route_domain_get (grdi);
740 grd->grd_vni_sw_if_index = gt->gt_sw_if_index;
742 gbp_learn_enable (gt->gt_sw_if_index, GBP_LEARN_MODE_L3);
743 gbp_sclass_enable_ip (gt->gt_sw_if_index);
745 ip4_sw_interface_enable_disable (gt->gt_sw_if_index, 1);
746 ip6_sw_interface_enable_disable (gt->gt_sw_if_index, 1);
748 FOR_EACH_FIB_IP_PROTOCOL (fproto)
750 gt->gt_fib_index[fproto] = grd->grd_fib_index[fproto];
752 ip_table_bind (fproto, gt->gt_sw_if_index,
753 grd->grd_table_id[fproto], 1);
758 * save the tunnel by VNI and by sw_if_index
760 hash_set (gv_db, vni, gti);
762 vec_validate (gbp_vxlan_tunnel_db, gt->gt_sw_if_index);
763 gbp_vxlan_tunnel_db[gt->gt_sw_if_index] = gti;
766 *sw_if_indexp = gt->gt_sw_if_index;
768 vxlan_gbp_register_udp_ports ();
773 rv = VNET_API_ERROR_IF_ALREADY_EXISTS;
776 GBP_VXLAN_TUN_DBG ("add: %U", format_gbp_vxlan_tunnel, gti);
782 gbp_vxlan_tunnel_del (u32 vni)
784 gbp_vxlan_tunnel_t *gt;
787 p = hash_get (gv_db, vni);
793 vnm = vnet_get_main ();
794 gt = gbp_vxlan_tunnel_get (p[0]);
796 vxlan_gbp_unregister_udp_ports ();
798 GBP_VXLAN_TUN_DBG ("del: %U", format_gbp_vxlan_tunnel,
799 gt - gbp_vxlan_tunnel_pool);
801 gbp_endpoint_flush (GBP_ENDPOINT_SRC_DP, gt->gt_sw_if_index);
802 ASSERT (0 == vec_len (gt->gt_tuns));
803 vec_free (gt->gt_tuns);
805 if (GBP_VXLAN_TUN_L2 == gt->gt_layer)
807 gbp_learn_disable (gt->gt_sw_if_index, GBP_LEARN_MODE_L2);
808 gbp_sclass_disable_l2 (gt->gt_sw_if_index);
809 gbp_itf_unlock (gt->gt_itf);
810 gbp_bridge_domain_unlock (gt->gt_gbd);
814 fib_protocol_t fproto;
816 FOR_EACH_FIB_IP_PROTOCOL (fproto)
817 ip_table_bind (fproto, gt->gt_sw_if_index, 0, 0);
819 ip4_sw_interface_enable_disable (gt->gt_sw_if_index, 0);
820 ip6_sw_interface_enable_disable (gt->gt_sw_if_index, 0);
822 gbp_learn_disable (gt->gt_sw_if_index, GBP_LEARN_MODE_L3);
823 gbp_sclass_disable_ip (gt->gt_sw_if_index);
824 gbp_route_domain_unlock (gt->gt_grd);
827 vnet_sw_interface_set_flags (vnm, gt->gt_sw_if_index, 0);
828 vnet_delete_hw_interface (vnm, gt->gt_hw_if_index);
830 hash_unset (gv_db, vni);
831 gbp_vxlan_tunnel_db[gt->gt_sw_if_index] = INDEX_INVALID;
833 pool_put (gbp_vxlan_tunnel_pool, gt);
836 return VNET_API_ERROR_NO_SUCH_ENTRY;
841 static clib_error_t *
842 gbp_vxlan_show (vlib_main_t * vm,
843 unformat_input_t * input, vlib_cli_command_t * cmd)
845 gbp_vxlan_walk (gbp_vxlan_tunnel_show_one, vm);
851 * Show Group Based Policy VXLAN tunnels
854 * @cliexstart{show gbp vxlan}
858 VLIB_CLI_COMMAND (gbp_vxlan_show_node, static) = {
859 .path = "show gbp vxlan",
860 .short_help = "show gbp vxlan\n",
861 .function = gbp_vxlan_show,
865 static clib_error_t *
866 gbp_vxlan_init (vlib_main_t * vm)
871 * insert ourselves into the VXLAN-GBP arc to collect the no-tunnel
874 slot4 = vlib_node_add_next_with_slot (vm,
875 vxlan4_gbp_input_node.index,
876 gbp_vxlan4_input_node.index,
877 VXLAN_GBP_INPUT_NEXT_NO_TUNNEL);
878 ASSERT (slot4 == VXLAN_GBP_INPUT_NEXT_NO_TUNNEL);
880 /* slot6 = vlib_node_add_next_with_slot (vm, */
881 /* vxlan6_gbp_input_node.index, */
882 /* gbp_vxlan6_input_node.index, */
883 /* VXLAN_GBP_INPUT_NEXT_NO_TUNNEL); */
884 /* ASSERT (slot6 == VXLAN_GBP_INPUT_NEXT_NO_TUNNEL); */
886 gt_logger = vlib_log_register_class ("gbp", "tun");
891 VLIB_INIT_FUNCTION (gbp_vxlan_init);
894 * fd.io coding-style-patch-verification: ON
897 * eval: (c-set-style "gnu")