#include <vnet/ip/format.h>
#include <vnet/fib/fib_entry.h>
#include <vnet/fib/fib_table.h>
+#include <vnet/fib/fib_entry_track.h>
#include <vnet/mfib/mfib_table.h>
#include <vnet/adj/adj_mcast.h>
#include <vnet/adj/rewrite.h>
*
* VXLAN GBP provides the features of vxlan and carry group policy id.
*/
-
+static vlib_punt_hdl_t punt_hdl;
vxlan_gbp_main_t vxlan_gbp_main;
-static u8 *
-format_decap_next (u8 * s, va_list * args)
+u8 *
+format_vxlan_gbp_tunnel_mode (u8 * s, va_list * args)
{
- u32 next_index = va_arg (*args, u32);
+ vxlan_gbp_tunnel_mode_t mode = va_arg (*args, vxlan_gbp_tunnel_mode_t);
- if (next_index == VXLAN_GBP_INPUT_NEXT_DROP)
- return format (s, "drop");
- else
- return format (s, "index %d", next_index);
- return s;
+ switch (mode)
+ {
+ case VXLAN_GBP_TUNNEL_MODE_L2:
+ s = format (s, "L2");
+ break;
+ case VXLAN_GBP_TUNNEL_MODE_L3:
+ s = format (s, "L3");
+ break;
+ }
+ return (s);
}
u8 *
s = format (s,
"[%d] instance %d src %U dst %U vni %d fib-idx %d"
- " sw-if-idx %d ",
+ " sw-if-idx %d mode %U ",
t->dev_instance, t->user_instance,
format_ip46_address, &t->src, IP46_TYPE_ANY,
format_ip46_address, &t->dst, IP46_TYPE_ANY,
- t->vni, t->encap_fib_index, t->sw_if_index);
+ t->vni, t->encap_fib_index, t->sw_if_index,
+ format_vxlan_gbp_tunnel_mode, t->mode);
s = format (s, "encap-dpo-idx %d ", t->next_dpo.dpoi_index);
- if (PREDICT_FALSE (t->decap_next_index != VXLAN_GBP_INPUT_NEXT_L2_INPUT))
- s = format (s, "decap-next-%U ", format_decap_next, t->decap_next_index);
-
if (PREDICT_FALSE (ip46_address_is_multicast (&t->dst)))
s = format (s, "mcast-sw-if-idx %d ", t->mcast_sw_if_index);
#define foreach_copy_field \
_(vni) \
+_(mode) \
_(mcast_sw_if_index) \
_(encap_fib_index) \
-_(decap_next_index) \
_(src) \
_(dst)
vxlan_gbp_header_t *vxlan_gbp;
/* Fixed portion of the (outer) ip header */
- memset (&h, 0, sizeof (h));
+ clib_memset (&h, 0, sizeof (h));
if (!is_ip6)
{
ip4_header_t *ip = &h.h4.ip4;
vnet_rewrite_set_data (*t, &h, len);
}
-static bool
-vxlan_gbp_decap_next_is_valid (vxlan_gbp_main_t * vxm, u32 is_ip6,
- u32 decap_next_index)
-{
- vlib_main_t *vm = vxm->vlib_main;
- u32 input_idx = (!is_ip6) ?
- vxlan4_gbp_input_node.index : vxlan6_gbp_input_node.index;
- vlib_node_runtime_t *r = vlib_node_get_runtime (vm, input_idx);
-
- return decap_next_index < r->n_next_nodes;
-}
-
static uword
vtep_addr_ref (ip46_address_t * ip)
{
uword *vtep = ip46_address_is_ip4 (ip) ?
hash_get (vxlan_gbp_main.vtep4, ip->ip4.as_u32) :
hash_get_mem (vxlan_gbp_main.vtep6, &ip->ip6);
- ASSERT (vtep);
+ ALWAYS_ASSERT (vtep);
if (--(*vtep) != 0)
return *vtep;
ip46_address_is_ip4 (ip) ?
hash_unset_mem_free (&vxlan_gbp_main.mcast_shared, dst);
}
+inline void
+vxlan_gbp_register_udp_ports (void)
+{
+ vxlan_gbp_main_t *vxm = &vxlan_gbp_main;
+
+ if (vxm->udp_ports_registered == 0)
+ {
+ udp_register_dst_port (vxm->vlib_main, UDP_DST_PORT_vxlan_gbp,
+ vxlan4_gbp_input_node.index, /* is_ip4 */ 1);
+ udp_register_dst_port (vxm->vlib_main, UDP_DST_PORT_vxlan6_gbp,
+ vxlan6_gbp_input_node.index, /* is_ip4 */ 0);
+ }
+ /*
+ * Counts the number of vxlan_gbp tunnels
+ */
+ vxm->udp_ports_registered += 1;
+}
+
+inline void
+vxlan_gbp_unregister_udp_ports (void)
+{
+ vxlan_gbp_main_t *vxm = &vxlan_gbp_main;
+
+ ASSERT (vxm->udp_ports_registered != 0);
+
+ if (vxm->udp_ports_registered == 1)
+ {
+ udp_unregister_dst_port (vxm->vlib_main, UDP_DST_PORT_vxlan_gbp,
+ /* is_ip4 */ 1);
+ udp_unregister_dst_port (vxm->vlib_main, UDP_DST_PORT_vxlan6_gbp,
+ /* is_ip4 */ 0);
+ }
+
+ vxm->udp_ports_registered -= 1;
+}
+
int vnet_vxlan_gbp_tunnel_add_del
(vnet_vxlan_gbp_tunnel_add_del_args_t * a, u32 * sw_if_indexp)
{
int not_found;
if (!is_ip6)
{
- key4.key[0] = a->dst.ip4.as_u32;
+ key4.key[0] = ip46_address_is_multicast (&a->dst) ?
+ a->dst.ip4.as_u32 :
+ a->dst.ip4.as_u32 | (((u64) a->src.ip4.as_u32) << 32);
key4.key[1] = (((u64) a->encap_fib_index) << 32)
| clib_host_to_net_u32 (a->vni << 8);
not_found =
/* adding a tunnel: tunnel must not already exist */
if (p)
- return VNET_API_ERROR_TUNNEL_EXIST;
-
- /* if not set explicitly, default to l2 */
- if (a->decap_next_index == ~0)
- a->decap_next_index = VXLAN_GBP_INPUT_NEXT_L2_INPUT;
- if (!vxlan_gbp_decap_next_is_valid (vxm, is_ip6, a->decap_next_index))
- return VNET_API_ERROR_INVALID_DECAP_NEXT;
-
+ {
+ t = pool_elt_at_index (vxm->tunnels, *p);
+ *sw_if_indexp = t->sw_if_index;
+ return VNET_API_ERROR_TUNNEL_EXIST;
+ }
pool_get_aligned (vxm->tunnels, t, CLIB_CACHE_LINE_BYTES);
- memset (t, 0, sizeof (*t));
+ clib_memset (t, 0, sizeof (*t));
dev_instance = t - vxm->tunnels;
/* copy from arg structure */
return VNET_API_ERROR_INVALID_REGISTRATION;
}
+ vxlan_gbp_register_udp_ports ();
+
t->hw_if_index = vnet_register_interface
(vnm, vxlan_gbp_device_class.index, dev_instance,
vxlan_gbp_hw_class.index, dev_instance);
t->sw_if_index = sw_if_index = hi->sw_if_index;
+ if (VXLAN_GBP_TUNNEL_MODE_L3 == t->mode)
+ {
+ ip4_sw_interface_enable_disable (t->sw_if_index, 1);
+ ip6_sw_interface_enable_disable (t->sw_if_index, 1);
+ }
+
vec_validate_init_empty (vxm->tunnel_index_by_sw_if_index, sw_if_index,
~0);
vxm->tunnel_index_by_sw_if_index[sw_if_index] = dev_instance;
* re-stack accordingly
*/
vtep_addr_ref (&t->src);
- t->fib_entry_index = fib_table_entry_special_add
- (t->encap_fib_index, &tun_dst_pfx, FIB_SOURCE_RR,
- FIB_ENTRY_FLAG_NONE);
- t->sibling_index = fib_entry_child_add
- (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_GBP_TUNNEL,
- dev_instance);
+ t->fib_entry_index = fib_entry_track (t->encap_fib_index,
+ &tun_dst_pfx,
+ FIB_NODE_TYPE_VXLAN_GBP_TUNNEL,
+ dev_instance,
+ &t->sibling_index);
vxlan_gbp_tunnel_restack_dpo (t);
}
else
{
/* Multicast tunnel -
- * as the same mcast group can be used for mutiple mcast tunnels
- * with different VNIs, create the output fib adjecency only if
+ * as the same mcast group can be used for multiple mcast tunnels
+ * with different VNIs, create the output fib adjacency only if
* it does not already exist
*/
fib_protocol_t fp = fib_ip_proto (is_ip6);
.frp_fib_index = ~0,
.frp_weight = 0,
.frp_flags = FIB_ROUTE_PATH_LOCAL,
+ .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
};
const mfib_prefix_t mpfx = {
.fp_proto = fp,
*/
mfib_table_entry_path_update (t->encap_fib_index,
&mpfx,
- MFIB_SOURCE_VXLAN_GBP,
- &path, MFIB_ITF_FLAG_FORWARD);
+ MFIB_SOURCE_VXLAN_GBP, &path);
path.frp_sw_if_index = a->mcast_sw_if_index;
path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
+ path.frp_mitf_flags = MFIB_ITF_FLAG_ACCEPT;
mfei = mfib_table_entry_path_update (t->encap_fib_index,
&mpfx,
MFIB_SOURCE_VXLAN_GBP,
- &path,
- MFIB_ITF_FLAG_ACCEPT);
+ &path);
/*
* Create the mcast adjacency to send traffic to the group
sw_if_index = t->sw_if_index;
vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */ );
+ if (VXLAN_GBP_TUNNEL_MODE_L3 == t->mode)
+ {
+ ip4_sw_interface_enable_disable (t->sw_if_index, 0);
+ ip6_sw_interface_enable_disable (t->sw_if_index, 0);
+ }
+
vxm->tunnel_index_by_sw_if_index[sw_if_index] = ~0;
if (!is_ip6)
if (!ip46_address_is_multicast (&t->dst))
{
vtep_addr_unref (&t->src);
- fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
- fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
+ fib_entry_untrack (t->fib_entry_index, t->sibling_index);
}
else if (vtep_addr_unref (&t->dst) == 0)
{
mcast_shared_remove (&t->dst);
}
+ vxlan_gbp_unregister_udp_ports ();
vnet_delete_hw_interface (vnm, t->hw_if_index);
hash_unset (vxm->instance_used, t->user_instance);
return 0;
}
+int
+vnet_vxlan_gbp_tunnel_del (u32 sw_if_index)
+{
+ vxlan_gbp_main_t *vxm = &vxlan_gbp_main;
+ vxlan_gbp_tunnel_t *t = 0;
+ u32 ti;
+
+ if (sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index))
+ return VNET_API_ERROR_NO_SUCH_ENTRY;
+
+ ti = vxm->tunnel_index_by_sw_if_index[sw_if_index];
+ if (~0 != ti)
+ {
+ t = pool_elt_at_index (vxm->tunnels, ti);
+
+ vnet_vxlan_gbp_tunnel_add_del_args_t args = {
+ .is_add = 0,
+ .is_ip6 = !ip46_address_is_ip4 (&t->src),
+ .vni = t->vni,
+ .src = t->src,
+ .dst = t->dst,
+ .instance = ~0,
+ };
+
+ return (vnet_vxlan_gbp_tunnel_add_del (&args, NULL));
+ }
+
+ return VNET_API_ERROR_NO_SUCH_ENTRY;
+}
+
static uword
get_decap_next_for_node (u32 node_index, u32 ipv4_set)
{
unformat_input_t _line_input, *line_input = &_line_input;
ip46_address_t src = ip46_address_initializer, dst =
ip46_address_initializer;
+ vxlan_gbp_tunnel_mode_t mode = VXLAN_GBP_TUNNEL_MODE_L2;
u8 is_add = 1;
u8 src_set = 0;
u8 dst_set = 0;
* Example of how to create a VXLAN Tunnel with a known name, vxlan_gbp_tunnel42:
* @cliexcmd{create vxlan_gbp tunnel src 10.0.3.1 dst 10.0.3.3 instance 42}
* Example of how to create a multicast VXLAN Tunnel with a known name, vxlan_gbp_tunnel23:
- * @cliexcmd{create vxlan_gbp tunnel src 10.0.3.1 group 239.1.1.1 GigabitEtherner0/8/0 instance 23}
+ * @cliexcmd{create vxlan_gbp tunnel src 10.0.3.1 group 239.1.1.1 GigabitEthernet0/8/0 instance 23}
* Example of how to delete a VXLAN Tunnel:
* @cliexcmd{create vxlan_gbp tunnel src 10.0.3.1 dst 10.0.3.3 vni 13 del}
?*/
* ip4-lookup [2]
* @cliexend
*
- * Example of how to display the feature enabed on an interface:
+ * Example of how to display the feature enabled on an interface:
* @cliexstart{show ip interface features GigabitEthernet2/0/0}
* IP feature paths configured on GigabitEthernet2/0/0...
* ...
* ip6-lookup [2]
* @cliexend
*
- * Example of how to display the feature enabed on an interface:
+ * Example of how to display the feature enabled on an interface:
* @cliexstart{show ip interface features GigabitEthernet2/0/0}
* IP feature paths configured on GigabitEthernet2/0/0...
* ...
VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gbp_bypass_command, static) = {
.path = "set interface ip6 vxlan-gbp-bypass",
.function = set_ip6_vxlan_gbp_bypass,
- .short_help = "set interface ip vxlan-gbp-bypass <interface> [del]",
+ .short_help = "set interface ip6 vxlan-gbp-bypass <interface> [del]",
};
/* *INDENT-ON* */
sizeof (ip46_address_t),
sizeof (mcast_shared_t));
- udp_register_dst_port (vm, UDP_DST_PORT_vxlan_gbp,
- vxlan4_gbp_input_node.index, /* is_ip4 */ 1);
- udp_register_dst_port (vm, UDP_DST_PORT_vxlan6_gbp,
- vxlan6_gbp_input_node.index, /* is_ip4 */ 0);
-
fib_node_register_type (FIB_NODE_TYPE_VXLAN_GBP_TUNNEL, &vxlan_gbp_vft);
- return 0;
+ punt_hdl = vlib_punt_client_register ("vxlan-gbp");
+
+ vlib_punt_reason_alloc (punt_hdl,
+ "VXLAN-GBP-no-such-v4-tunnel",
+ &vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4]);
+ vlib_punt_reason_alloc (punt_hdl,
+ "VXLAN-GBP-no-such-v6-tunnel",
+ &vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6]);
+
+ return (0);
}
-VLIB_INIT_FUNCTION (vxlan_gbp_init);
+/* *INDENT-OFF* */
+VLIB_INIT_FUNCTION (vxlan_gbp_init) =
+{
+ .runs_after = VLIB_INITS("punt_init"),
+};
+/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON