summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2020-09-02 14:46:53 +0000
committerNeale Ranns <nranns@cisco.com>2020-09-17 12:55:53 +0000
commit256b67bc8873f268d2cecd16183398352b9fcd16 (patch)
treebf8cf5055de239b1b91739fc33554c93382d72d5 /src/vnet
parentfc639ff2d7abd8599f59078fac99f731026215b3 (diff)
teib: Add adj-fibs for peers/adjacencies on p2mp interface
Type: fix Change-Id: I6fdc4e952097e92ac3aa53e0be3ef99e0d801b28 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/gre/gre.c3
-rw-r--r--src/vnet/ipip/ipip.c3
-rw-r--r--src/vnet/ipsec/ipsec_tun.c4
-rw-r--r--src/vnet/teib/teib.c237
-rw-r--r--src/vnet/teib/teib.h7
-rw-r--r--src/vnet/teib/teib_api.c17
-rw-r--r--src/vnet/teib/teib_cli.c22
7 files changed, 258 insertions, 35 deletions
diff --git a/src/vnet/gre/gre.c b/src/vnet/gre/gre.c
index 83f12833611..f4c41bd09b4 100644
--- a/src/vnet/gre/gre.c
+++ b/src/vnet/gre/gre.c
@@ -472,7 +472,8 @@ mgre_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
t = pool_elt_at_index (gm->tunnels, ti);
- ne = teib_entry_find (sw_if_index, &adj->sub_type.nbr.next_hop);
+ ne = teib_entry_find (sw_if_index,
+ adj->ia_nh_proto, &adj->sub_type.nbr.next_hop);
if (NULL == ne)
// no NHRP entry to provide the next-hop
diff --git a/src/vnet/ipip/ipip.c b/src/vnet/ipip/ipip.c
index 089e2b659c7..138f4d22326 100644
--- a/src/vnet/ipip/ipip.c
+++ b/src/vnet/ipip/ipip.c
@@ -364,7 +364,8 @@ mipip_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
t = pool_elt_at_index (gm->tunnels, ti);
- ne = teib_entry_find (sw_if_index, &adj->sub_type.nbr.next_hop);
+ ne = teib_entry_find (sw_if_index,
+ adj->ia_nh_proto, &adj->sub_type.nbr.next_hop);
if (NULL == ne)
{
diff --git a/src/vnet/ipsec/ipsec_tun.c b/src/vnet/ipsec/ipsec_tun.c
index fb530c8dc9f..ac8b24ec232 100644
--- a/src/vnet/ipsec/ipsec_tun.c
+++ b/src/vnet/ipsec/ipsec_tun.c
@@ -718,7 +718,9 @@ ipsec_tun_protect_update (u32 sw_if_index,
ip_address_to_46 (nh, &peer);
ipsec_tun_protect_update_from_teib
- (itp, teib_entry_find (sw_if_index, &peer));
+ (itp, teib_entry_find (sw_if_index,
+ ip_address_family_to_fib_proto
+ (ip_addr_version (nh)), &peer));
}
if (is_l2)
diff --git a/src/vnet/teib/teib.c b/src/vnet/teib/teib.c
index e392b49e86b..0f33d087a50 100644
--- a/src/vnet/teib/teib.c
+++ b/src/vnet/teib/teib.c
@@ -19,12 +19,14 @@
#include <vnet/teib/teib.h>
#include <vnet/fib/fib_table.h>
#include <vnet/adj/adj_midchain.h>
+#include <vnet/ip/ip6_ll_table.h>
typedef struct teib_key_t_
{
ip46_address_t tk_peer;
u32 tk_sw_if_index;
-} teib_key_t;
+ fib_protocol_t tk_proto;
+} __clib_packed teib_key_t;
struct teib_entry_t_
{
@@ -33,9 +35,10 @@ struct teib_entry_t_
u32 te_fib_index;
};
-static uword *teib_db;
+static uword *teib_db[FIB_PROTOCOL_IP_MAX];
static teib_entry_t *teib_pool;
static teib_vft_t *teib_vfts;
+static vlib_log_class_t teib_logger;
#define TEIB_NOTIFY(_te, _fn) { \
teib_vft_t *_vft; \
@@ -46,12 +49,29 @@ static teib_vft_t *teib_vfts;
} \
}
+#define TEIB_DBG(...) \
+ vlib_log_debug (teib_logger, __VA_ARGS__);
+
+#define TEIB_INFO(...) \
+ vlib_log_notice (teib_logger, __VA_ARGS__);
+
+#define TEIB_TE_DBG(_te, _fmt, _args...) \
+ vlib_log_debug (teib_logger, "[%U]: " _fmt, format_teib_entry, _te - teib_pool, ##_args)
+#define TEIB_TE_INFO(_te, _fmt, _args...) \
+ vlib_log_notice (teib_logger, "[%U]: " _fmt, format_teib_entry, _te - teib_pool, ##_args)
+
u32
teib_entry_get_sw_if_index (const teib_entry_t * te)
{
return (te->te_key->tk_sw_if_index);
}
+fib_protocol_t
+teib_entry_get_proto (const teib_entry_t * te)
+{
+ return (te->te_key->tk_proto);
+}
+
u32
teib_entry_get_fib_index (const teib_entry_t * te)
{
@@ -83,15 +103,17 @@ teib_entry_get (index_t tei)
}
teib_entry_t *
-teib_entry_find (u32 sw_if_index, const ip46_address_t * peer)
+teib_entry_find (u32 sw_if_index,
+ fib_protocol_t fproto, const ip46_address_t * peer)
{
teib_key_t nk = {
.tk_peer = *peer,
+ .tk_proto = fproto,
.tk_sw_if_index = sw_if_index,
};
uword *p;
- p = hash_get_mem (teib_db, &nk);
+ p = hash_get_mem (teib_db[fproto], &nk);
if (NULL != p)
return teib_entry_get (p[0]);
@@ -99,34 +121,104 @@ teib_entry_find (u32 sw_if_index, const ip46_address_t * peer)
return (NULL);
}
+static void
+teib_adj_fib_add (fib_protocol_t fproto,
+ const ip46_address_t * ip, u32 sw_if_index, u32 fib_index)
+{
+ if (FIB_PROTOCOL_IP6 == fproto &&
+ ip6_address_is_link_local_unicast (&ip->ip6))
+ {
+ ip6_ll_prefix_t pfx = {
+ .ilp_addr = ip->ip6,
+ .ilp_sw_if_index = sw_if_index,
+ };
+ ip6_ll_table_entry_update (&pfx, FIB_ROUTE_PATH_FLAG_NONE);
+ }
+ else
+ {
+ fib_prefix_t pfx = {
+ .fp_len = (FIB_PROTOCOL_IP4 == fproto ? 32 : 128),
+ .fp_proto = fproto,
+ .fp_addr = *ip,
+ };
+ fib_table_entry_path_add (fib_index, &pfx, FIB_SOURCE_ADJ,
+ FIB_ENTRY_FLAG_ATTACHED,
+ fib_proto_to_dpo (pfx.fp_proto),
+ &pfx.fp_addr,
+ sw_if_index,
+ ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
+
+
+ if (1 == hash_elts (teib_db[pfx.fp_proto]))
+ fib_table_lock (fib_index, pfx.fp_proto, FIB_SOURCE_ADJ);
+ }
+}
+
+static void
+teib_adj_fib_remove (fib_protocol_t fproto,
+ ip46_address_t * ip, u32 sw_if_index, u32 fib_index)
+{
+ if (FIB_PROTOCOL_IP6 == fproto &&
+ ip6_address_is_link_local_unicast (&ip->ip6))
+ {
+ ip6_ll_prefix_t pfx = {
+ .ilp_addr = ip->ip6,
+ .ilp_sw_if_index = sw_if_index,
+ };
+ ip6_ll_table_entry_delete (&pfx);
+ }
+ else
+ {
+ fib_prefix_t pfx = {
+ .fp_len = (FIB_PROTOCOL_IP4 == fproto ? 32 : 128),
+ .fp_proto = fproto,
+ .fp_addr = *ip,
+ };
+
+ fib_table_entry_path_remove (fib_index, &pfx, FIB_SOURCE_ADJ,
+ fib_proto_to_dpo (pfx.fp_proto),
+ &pfx.fp_addr,
+ sw_if_index,
+ ~0, 1, FIB_ROUTE_PATH_FLAG_NONE);
+
+ if (0 == hash_elts (teib_db[pfx.fp_proto]))
+ fib_table_unlock (fib_index, pfx.fp_proto, FIB_SOURCE_ADJ);
+ }
+}
+
int
teib_entry_add (u32 sw_if_index,
+ fib_protocol_t fproto,
const ip46_address_t * peer,
u32 nh_table_id, const ip46_address_t * nh)
{
- fib_protocol_t fproto;
+ fib_protocol_t nh_proto;
teib_entry_t *te;
u32 fib_index;
index_t tei;
- fproto = (ip46_address_is_ip4 (nh) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
+ nh_proto = (ip46_address_is_ip4 (nh) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
- fib_index = fib_table_find (fproto, nh_table_id);
+ fib_index = fib_table_find (nh_proto, nh_table_id);
if (~0 == fib_index)
{
return (VNET_API_ERROR_NO_SUCH_FIB);
}
- te = teib_entry_find (sw_if_index, peer);
+ te = teib_entry_find (sw_if_index, fproto, peer);
if (NULL == te)
{
teib_key_t nk = {
.tk_peer = *peer,
+ .tk_proto = fproto,
.tk_sw_if_index = sw_if_index,
};
teib_entry_t *te;
+ u32 fib_index;
+
+ fib_index = fib_table_get_index_for_sw_if_index (fproto, sw_if_index);
pool_get_zero (teib_pool, te);
@@ -139,26 +231,43 @@ teib_entry_add (u32 sw_if_index,
te->te_nh.fp_len = (te->te_nh.fp_proto == FIB_PROTOCOL_IP4 ? 32 : 128);
te->te_fib_index = fib_index;
- hash_set_mem (teib_db, te->te_key, tei);
+ hash_set_mem (teib_db[fproto], te->te_key, tei);
+
+ /* we how have a /32 in the overlay, add an adj-fib */
+ teib_adj_fib_add (te->te_key->tk_proto,
+ &te->te_key->tk_peer, sw_if_index, fib_index);
TEIB_NOTIFY (te, nv_added);
+ TEIB_TE_INFO (te, "created");
}
else
- return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);
-
+ {
+ TEIB_TE_INFO (te, "exists");
+ return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);
+ }
return 0;
}
int
-teib_entry_del (u32 sw_if_index, const ip46_address_t * peer)
+teib_entry_del (u32 sw_if_index,
+ fib_protocol_t fproto, const ip46_address_t * peer)
{
teib_entry_t *te;
- te = teib_entry_find (sw_if_index, peer);
+ te = teib_entry_find (sw_if_index, fproto, peer);
if (te != NULL)
{
- hash_unset_mem (teib_db, te->te_key);
+ TEIB_TE_INFO (te, "removed");
+
+ u32 fib_index;
+
+ fib_index = fib_table_get_index_for_sw_if_index (fproto, sw_if_index);
+
+ teib_adj_fib_remove (te->te_key->tk_proto,
+ &te->te_key->tk_peer, sw_if_index, fib_index);
+
+ hash_unset_mem (teib_db[fproto], te->te_key);
TEIB_NOTIFY (te, nv_deleted);
@@ -166,8 +275,14 @@ teib_entry_del (u32 sw_if_index, const ip46_address_t * peer)
pool_put (teib_pool, te);
}
else
- return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);
-
+ {
+ TEIB_INFO ("no such entry: %U, %U, %U",
+ format_vnet_sw_if_index_name,
+ vnet_get_main (), sw_if_index,
+ format_fib_protocol, fproto,
+ format_ip46_address, peer, IP46_TYPE_ANY);
+ return (VNET_API_ERROR_NO_SUCH_ENTRY);
+ }
return 0;
}
@@ -183,7 +298,8 @@ format_teib_entry (u8 * s, va_list * args)
s = format (s, "[%d] ", tei);
s = format (s, "%U:", format_vnet_sw_if_index_name,
vnm, te->te_key->tk_sw_if_index);
- s = format (s, " %U", format_ip46_address,
+ s = format (s, " %U:", format_fib_protocol, te->te_key->tk_proto);
+ s = format (s, "%U", format_ip46_address,
&te->te_key->tk_peer, IP46_TYPE_ANY);
s = format (s, " via [%d]:%U",
fib_table_get_table_id (te->te_fib_index, te->te_nh.fp_proto),
@@ -219,6 +335,76 @@ teib_walk_itf (u32 sw_if_index, teib_walk_cb_t fn, void *ctx)
/* *INDENT-ON* */
}
+static void
+teib_walk_itf_proto (u32 sw_if_index,
+ fib_protocol_t fproto, teib_walk_cb_t fn, void *ctx)
+{
+ index_t tei;
+
+ /* *INDENT-OFF* */
+ pool_foreach_index(tei, teib_pool,
+ ({
+ if (sw_if_index == teib_entry_get_sw_if_index(teib_entry_get(tei)) &&
+ fproto == teib_entry_get_proto(teib_entry_get(tei)))
+ fn(tei, ctx);
+ }));
+ /* *INDENT-ON* */
+}
+
+typedef struct teib_table_bind_ctx_t_
+{
+ u32 new_fib_index;
+ u32 old_fib_index;
+} teib_table_bind_ctx_t;
+
+static walk_rc_t
+teib_walk_table_bind (index_t tei, void *arg)
+{
+ teib_table_bind_ctx_t *ctx = arg;
+ teib_entry_t *te;
+
+ te = teib_entry_get (tei);
+
+ TEIB_TE_INFO (te, "bind: %d -> %d", ctx->old_fib_index, ctx->new_fib_index);
+
+ teib_adj_fib_remove (te->te_key->tk_proto,
+ &te->te_key->tk_peer,
+ te->te_key->tk_sw_if_index, ctx->old_fib_index);
+ teib_adj_fib_add (te->te_key->tk_proto,
+ &te->te_key->tk_peer,
+ te->te_key->tk_sw_if_index, ctx->new_fib_index);
+
+ return (WALK_CONTINUE);
+}
+
+static void
+teib_table_bind_v4 (ip4_main_t * im,
+ uword opaque,
+ u32 sw_if_index, u32 new_fib_index, u32 old_fib_index)
+{
+ teib_table_bind_ctx_t ctx = {
+ .old_fib_index = old_fib_index,
+ .new_fib_index = new_fib_index,
+ };
+
+ teib_walk_itf_proto (sw_if_index,
+ FIB_PROTOCOL_IP4, teib_walk_table_bind, &ctx);
+}
+
+static void
+teib_table_bind_v6 (ip6_main_t * im,
+ uword opaque,
+ u32 sw_if_index, u32 new_fib_index, u32 old_fib_index)
+{
+ teib_table_bind_ctx_t ctx = {
+ .old_fib_index = old_fib_index,
+ .new_fib_index = new_fib_index,
+ };
+
+ teib_walk_itf_proto (sw_if_index,
+ FIB_PROTOCOL_IP6, teib_walk_table_bind, &ctx);
+}
+
void
teib_register (const teib_vft_t * vft)
{
@@ -228,7 +414,22 @@ teib_register (const teib_vft_t * vft)
static clib_error_t *
teib_init (vlib_main_t * vm)
{
- teib_db = hash_create_mem (0, sizeof (teib_key_t), sizeof (u32));
+ fib_protocol_t fproto;
+
+ FOR_EACH_FIB_IP_PROTOCOL (fproto)
+ teib_db[fproto] = hash_create_mem (0, sizeof (teib_key_t), sizeof (u32));
+
+ ip4_table_bind_callback_t cb4 = {
+ .function = teib_table_bind_v4,
+ };
+ vec_add1 (ip4_main.table_bind_callbacks, cb4);
+
+ ip6_table_bind_callback_t cb6 = {
+ .function = teib_table_bind_v6,
+ };
+ vec_add1 (ip6_main.table_bind_callbacks, cb6);
+
+ teib_logger = vlib_log_register_class ("teib", "teib");
return (NULL);
}
diff --git a/src/vnet/teib/teib.h b/src/vnet/teib/teib.h
index 4a03eee844f..2a5da76ef93 100644
--- a/src/vnet/teib/teib.h
+++ b/src/vnet/teib/teib.h
@@ -37,6 +37,7 @@ typedef struct teib_entry_t_ teib_entry_t;
extern u32 teib_entry_get_sw_if_index (const teib_entry_t * ne);
extern u32 teib_entry_get_fib_index (const teib_entry_t * ne);
extern const ip46_address_t *teib_entry_get_peer (const teib_entry_t * ne);
+extern fib_protocol_t teib_entry_get_proto (const teib_entry_t * ne);
extern const fib_prefix_t *teib_entry_get_nh (const teib_entry_t * ne);
extern u8 *format_teib_entry (u8 * s, va_list * args);
@@ -44,12 +45,16 @@ extern u8 *format_teib_entry (u8 * s, va_list * args);
* Create a new TEIB entry
*/
extern int teib_entry_add (u32 sw_if_index,
+ fib_protocol_t fproto,
const ip46_address_t * peer,
u32 nh_table_id, const ip46_address_t * nh);
-extern int teib_entry_del (u32 sw_if_index, const ip46_address_t * peer);
+extern int teib_entry_del (u32 sw_if_index,
+ fib_protocol_t fproto,
+ const ip46_address_t * peer);
extern teib_entry_t *teib_entry_find (u32 sw_if_index,
+ fib_protocol_t fproto,
const ip46_address_t * peer);
extern teib_entry_t *teib_entry_get (index_t nei);
diff --git a/src/vnet/teib/teib_api.c b/src/vnet/teib/teib_api.c
index 48bfee34fda..b885128baf4 100644
--- a/src/vnet/teib/teib_api.c
+++ b/src/vnet/teib/teib_api.c
@@ -39,19 +39,26 @@ static void
vl_api_teib_entry_add_del_t_handler (vl_api_teib_entry_add_del_t * mp)
{
vl_api_teib_entry_add_del_reply_t *rmp;
- ip46_address_t peer, nh;
+ ip46_address_t nh;
+ ip_address_t peer;
int rv;
VALIDATE_SW_IF_INDEX ((&mp->entry));
- ip_address_decode (&mp->entry.peer, &peer);
+ ip_address_decode2 (&mp->entry.peer, &peer);
ip_address_decode (&mp->entry.nh, &nh);
if (mp->is_add)
- rv = teib_entry_add (ntohl (mp->entry.sw_if_index), &peer,
- ntohl (mp->entry.nh_table_id), &nh);
+ rv = teib_entry_add (ntohl (mp->entry.sw_if_index),
+ ip_address_family_to_fib_proto (ip_addr_version
+ (&peer)),
+ &ip_addr_46 (&peer), ntohl (mp->entry.nh_table_id),
+ &nh);
else
- rv = teib_entry_del (ntohl (mp->entry.sw_if_index), &peer);
+ rv = teib_entry_del (ntohl (mp->entry.sw_if_index),
+ ip_address_family_to_fib_proto (ip_addr_version
+ (&peer)),
+ &ip_addr_46 (&peer));
BAD_SW_IF_INDEX_LABEL;
diff --git a/src/vnet/teib/teib_cli.c b/src/vnet/teib/teib_cli.c
index faf0d828963..63e3645f14a 100644
--- a/src/vnet/teib/teib_cli.c
+++ b/src/vnet/teib/teib_cli.c
@@ -20,8 +20,8 @@ teib_add (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
- ip46_address_t peer = ip46_address_initializer;
ip46_address_t nh = ip46_address_initializer;
+ ip_address_t peer = IP_ADDRESS_V6_ALL_0S;
u32 sw_if_index, nh_table_id;
clib_error_t *error = NULL;
int rv;
@@ -38,7 +38,7 @@ teib_add (vlib_main_t * vm,
if (unformat (line_input, "%U", unformat_vnet_sw_interface,
vnet_get_main (), &sw_if_index))
;
- else if (unformat (line_input, "peer %U", unformat_ip46_address, &peer))
+ else if (unformat (line_input, "peer %U", unformat_ip_address, &peer))
;
else if (unformat (line_input, "nh %U", unformat_ip46_address, &nh))
;
@@ -58,7 +58,7 @@ teib_add (vlib_main_t * vm,
format_unformat_error, line_input);
goto done;
}
- if (ip46_address_is_zero (&peer))
+ if (ip_address_is_zero (&peer))
{
error = clib_error_return (0, "peer required'",
format_unformat_error, line_input);
@@ -71,7 +71,10 @@ teib_add (vlib_main_t * vm,
goto done;
}
- rv = teib_entry_add (sw_if_index, &peer, nh_table_id, &nh);
+ rv = teib_entry_add (sw_if_index,
+ ip_address_family_to_fib_proto (ip_addr_version
+ (&peer)),
+ &ip_addr_46 (&peer), nh_table_id, &nh);
if (rv)
{
@@ -99,7 +102,7 @@ teib_del (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
- ip46_address_t peer = ip46_address_initializer;
+ ip_address_t peer = IP_ADDRESS_V6_ALL_0S;
clib_error_t *error = NULL;
u32 sw_if_index;
int rv;
@@ -115,7 +118,7 @@ teib_del (vlib_main_t * vm,
if (unformat (line_input, "%U", unformat_vnet_sw_interface,
vnet_get_main (), &sw_if_index))
;
- else if (unformat (line_input, "peer %U", unformat_ip46_address, &peer))
+ else if (unformat (line_input, "peer %U", unformat_ip_address, &peer))
;
else
{
@@ -130,14 +133,17 @@ teib_del (vlib_main_t * vm,
error = clib_error_return (0, "interface required'",
format_unformat_error, line_input);
}
- if (ip46_address_is_zero (&peer))
+ if (ip_address_is_zero (&peer))
{
error = clib_error_return (0, "peer required'",
format_unformat_error, line_input);
goto done;
}
- rv = teib_entry_del (sw_if_index, &peer);
+ rv = teib_entry_del (sw_if_index,
+ ip_address_family_to_fib_proto (ip_addr_version
+ (&peer)),
+ &ip_addr_46 (&peer));
if (rv)
{