*/
#include <vnet/vnet.h>
-#include <vnet/pg/pg.h>
#include <vnet/gre/gre.h>
#include <vnet/ip/format.h>
#include <vnet/fib/ip4_fib.h>
#include <vnet/adj/adj_nbr.h>
#include <vnet/mpls/mpls.h>
#include <vnet/l2/l2_input.h>
-#include <vnet/nhrp/nhrp.h>
+#include <vnet/teib/teib.h>
u8 *
format_gre_tunnel_type (u8 * s, va_list * args)
return (s);
}
-u8 *
-format_gre_tunnel_mode (u8 * s, va_list * args)
-{
- gre_tunnel_mode_t mode = va_arg (*args, int);
-
- switch (mode)
- {
-#define _(n, v) case GRE_TUNNEL_MODE_##n: \
- s = format (s, "%s", v); \
- break;
- foreach_gre_tunnel_mode
-#undef _
- }
-
- return (s);
-}
-
static u8 *
format_gre_tunnel (u8 * s, va_list * args)
{
t->outer_fib_index, t->sw_if_index);
s = format (s, "payload %U ", format_gre_tunnel_type, t->type);
- s = format (s, "%U ", format_gre_tunnel_mode, t->mode);
+ s = format (s, "%U ", format_tunnel_mode, t->mode);
if (t->type == GRE_TUNNEL_TYPE_ERSPAN)
s = format (s, "session %d ", t->session_id);
}
static void
-gre_nhrp_mk_key (const gre_tunnel_t * t,
- const nhrp_entry_t * ne, gre_tunnel_key_t * key)
+gre_teib_mk_key (const gre_tunnel_t * t,
+ const teib_entry_t * ne, gre_tunnel_key_t * key)
{
const fib_prefix_t *nh;
- nh = nhrp_entry_get_nh (ne);
+ nh = teib_entry_get_nh (ne);
/* construct the key using mode P2P so it can be found in the DP */
if (FIB_PROTOCOL_IP4 == nh->fp_proto)
gre_mk_key4 (t->tunnel_src.ip4,
nh->fp_addr.ip4,
- nhrp_entry_get_fib_index (ne),
- t->type, GRE_TUNNEL_MODE_P2P, 0, &key->gtk_v4);
+ teib_entry_get_fib_index (ne),
+ t->type, TUNNEL_MODE_P2P, 0, &key->gtk_v4);
else
gre_mk_key6 (&t->tunnel_src.ip6,
&nh->fp_addr.ip6,
- nhrp_entry_get_fib_index (ne),
- t->type, GRE_TUNNEL_MODE_P2P, 0, &key->gtk_v6);
+ teib_entry_get_fib_index (ne),
+ t->type, TUNNEL_MODE_P2P, 0, &key->gtk_v6);
}
+/**
+ * An NHRP entry has been added
+ */
static void
-gre_nhrp_entry_added (const nhrp_entry_t * ne)
+gre_teib_entry_added (const teib_entry_t * ne)
{
gre_main_t *gm = &gre_main;
+ const ip_address_t *nh;
gre_tunnel_key_t key;
gre_tunnel_t *t;
u32 sw_if_index;
u32 t_idx;
- sw_if_index = nhrp_entry_get_sw_if_index (ne);
+ sw_if_index = teib_entry_get_sw_if_index (ne);
if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index)
return;
if (INDEX_INVALID == t_idx)
return;
+ /* entry has been added on an interface for which there is a GRE tunnel */
t = pool_elt_at_index (gm->tunnels, t_idx);
- gre_nhrp_mk_key (t, ne, &key);
+ if (t->mode != TUNNEL_MODE_MP)
+ return;
+
+ /* the next-hop (underlay) of the NHRP entry will form part of the key for
+ * ingress lookup to match packets to this interface */
+ gre_teib_mk_key (t, ne, &key);
gre_tunnel_db_add (t, &key);
+
+ /* update the rewrites for each of the adjacencies for this peer (overlay)
+ * using the next-hop (underlay) */
+ mgre_walk_ctx_t ctx = {
+ .t = t,
+ .ne = ne
+ };
+ nh = teib_entry_get_peer (ne);
+ adj_nbr_walk_nh (teib_entry_get_sw_if_index (ne),
+ (AF_IP4 == ip_addr_version (nh) ?
+ FIB_PROTOCOL_IP4 :
+ FIB_PROTOCOL_IP6),
+ &ip_addr_46 (nh), mgre_mk_complete_walk, &ctx);
}
static void
-gre_nhrp_entry_deleted (const nhrp_entry_t * ne)
+gre_teib_entry_deleted (const teib_entry_t * ne)
{
gre_main_t *gm = &gre_main;
+ const ip_address_t *nh;
gre_tunnel_key_t key;
gre_tunnel_t *t;
u32 sw_if_index;
u32 t_idx;
- sw_if_index = nhrp_entry_get_sw_if_index (ne);
+ sw_if_index = teib_entry_get_sw_if_index (ne);
if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index)
return;
t = pool_elt_at_index (gm->tunnels, t_idx);
- gre_nhrp_mk_key (t, ne, &key);
+ /* remove the next-hop as an ingress lookup key */
+ gre_teib_mk_key (t, ne, &key);
gre_tunnel_db_remove (t, &key);
+
+ nh = teib_entry_get_peer (ne);
+
+ /* make all the adjacencies incomplete */
+ adj_nbr_walk_nh (teib_entry_get_sw_if_index (ne),
+ (AF_IP4 == ip_addr_version (nh) ?
+ FIB_PROTOCOL_IP4 :
+ FIB_PROTOCOL_IP6),
+ &ip_addr_46 (nh), mgre_mk_incomplete_walk, t);
}
static walk_rc_t
-gre_tunnel_delete_nhrp_walk (index_t nei, void *ctx)
+gre_tunnel_delete_teib_walk (index_t nei, void *ctx)
{
gre_tunnel_t *t = ctx;
gre_tunnel_key_t key;
- gre_nhrp_mk_key (t, nhrp_entry_get (nei), &key);
+ gre_teib_mk_key (t, teib_entry_get (nei), &key);
gre_tunnel_db_remove (t, &key);
return (WALK_CONTINUE);
}
static walk_rc_t
-gre_tunnel_add_nhrp_walk (index_t nei, void *ctx)
+gre_tunnel_add_teib_walk (index_t nei, void *ctx)
{
gre_tunnel_t *t = ctx;
gre_tunnel_key_t key;
- gre_nhrp_mk_key (t, nhrp_entry_get (nei), &key);
+ gre_teib_mk_key (t, teib_entry_get (nei), &key);
gre_tunnel_db_add (t, &key);
return (WALK_CONTINUE);
t->type = a->type;
t->mode = a->mode;
+ t->flags = a->flags;
if (t->type == GRE_TUNNEL_TYPE_ERSPAN)
t->session_id = a->session_id;
if (t->type == GRE_TUNNEL_TYPE_L3)
{
- if (t->mode == GRE_TUNNEL_MODE_P2P)
+ if (t->mode == TUNNEL_MODE_P2P)
hw_if_index =
vnet_register_interface (vnm, gre_device_class.index, t_idx,
gre_hw_interface_class.index, t_idx);
}
/* Set GRE tunnel interface output node (not used for L3 payload) */
- vnet_set_interface_output_node (vnm, hw_if_index, gre_encap_node.index);
+ if (GRE_TUNNEL_TYPE_ERSPAN == t->type)
+ vnet_set_interface_output_node (vnm, hw_if_index,
+ gre_erspan_encap_node.index);
+ else
+ vnet_set_interface_output_node (vnm, hw_if_index,
+ gre_teb_encap_node.index);
hi = vnet_get_hw_interface (vnm, hw_if_index);
sw_if_index = hi->sw_if_index;
gre_tunnel_db_add (t, &key);
- if (t->mode == GRE_TUNNEL_MODE_MP)
- nhrp_walk_itf (t->sw_if_index, gre_tunnel_add_nhrp_walk, t);
+ if (t->mode == TUNNEL_MODE_MP)
+ teib_walk_itf (t->sw_if_index, gre_tunnel_add_teib_walk, t);
if (t->type == GRE_TUNNEL_TYPE_ERSPAN)
{
if (NULL == t)
return VNET_API_ERROR_NO_SUCH_ENTRY;
- if (t->mode == GRE_TUNNEL_MODE_MP)
- nhrp_walk_itf (t->sw_if_index, gre_tunnel_delete_nhrp_walk, t);
+ if (t->mode == TUNNEL_MODE_MP)
+ teib_walk_itf (t->sw_if_index, gre_tunnel_delete_teib_walk, t);
sw_if_index = t->sw_if_index;
vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */ );
if (a->session_id > GTK_SESSION_ID_MAX)
return VNET_API_ERROR_INVALID_SESSION_ID;
- if (a->mode == GRE_TUNNEL_MODE_MP && !ip46_address_is_zero (&a->dst))
+ if (a->mode == TUNNEL_MODE_MP && !ip46_address_is_zero (&a->dst))
return (VNET_API_ERROR_INVALID_DST_ADDRESS);
if (a->is_add)
u32 instance = ~0;
u32 outer_table_id = 0;
gre_tunnel_type_t t_type = GRE_TUNNEL_TYPE_L3;
- gre_tunnel_mode_t t_mode = GRE_TUNNEL_MODE_P2P;
+ tunnel_mode_t t_mode = TUNNEL_MODE_P2P;
u32 session_id = 0;
int rv;
u8 is_add = 1;
else if (unformat (line_input, "outer-table-id %d", &outer_table_id))
;
else if (unformat (line_input, "multipoint"))
- t_mode = GRE_TUNNEL_MODE_MP;
+ t_mode = TUNNEL_MODE_MP;
else if (unformat (line_input, "teb"))
t_type = GRE_TUNNEL_TYPE_TEB;
else if (unformat (line_input, "erspan %d", &session_id))
goto done;
}
- if (t_mode != GRE_TUNNEL_MODE_MP && ip46_address_is_zero (&dst))
+ if (t_mode != TUNNEL_MODE_MP && ip46_address_is_zero (&dst))
{
error = clib_error_return (0, "destination address not specified");
goto done;
VLIB_CLI_COMMAND (create_gre_tunnel_command, static) = {
.path = "create gre tunnel",
.short_help = "create gre tunnel src <addr> dst <addr> [instance <n>] "
- "[outer-fib-id <fib>] [teb | erspan <session-id>] [del]",
+ "[outer-fib-id <fib>] [teb | erspan <session-id>] [del] "
+ "[multipoint]",
.function = create_gre_tunnel_command_fn,
};
/* *INDENT-ON* */
};
/* *INDENT-ON* */
-const static nhrp_vft_t gre_nhrp_vft = {
- .nv_added = gre_nhrp_entry_added,
- .nv_deleted = gre_nhrp_entry_deleted,
+const static teib_vft_t gre_teib_vft = {
+ .nv_added = gre_teib_entry_added,
+ .nv_deleted = gre_teib_entry_deleted,
};
/* force inclusion from application's main.c */
clib_error_t *
gre_interface_init (vlib_main_t * vm)
{
- nhrp_register (&gre_nhrp_vft);
+ teib_register (&gre_teib_vft);
return (NULL);
}