summaryrefslogtreecommitdiffstats
path: root/src/vnet/adj/adj_nbr.c
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2020-08-13 11:16:56 +0200
committerNeale Ranns <nranns@cisco.com>2020-09-01 11:43:13 +0000
commitfaec38f3e1574fb22b1ccd6d475e2ec9b10b2e01 (patch)
treeb1864a5495171f73b62394acc3a00a68380eabae /src/vnet/adj/adj_nbr.c
parent4069f41c6e2616adadc8f31ac41a66fae47c5735 (diff)
fib: detect wrong adj neighbour bugs
Type: improvement Change-Id: Ie063ee0a0c59a9ad632200ce2b23703bc0d936e6 Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vnet/adj/adj_nbr.c')
-rw-r--r--src/vnet/adj/adj_nbr.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/vnet/adj/adj_nbr.c b/src/vnet/adj/adj_nbr.c
index 78bf6df5324..ddaab14ee11 100644
--- a/src/vnet/adj/adj_nbr.c
+++ b/src/vnet/adj/adj_nbr.c
@@ -41,6 +41,19 @@ typedef struct adj_nbr_key_t_
(((_itf) < vec_len(adj_nbr_tables[_proto])) && \
(NULL != adj_nbr_tables[_proto][sw_if_index]))
+#define ADJ_NBR_ASSERT_NH_PROTO(nh_proto, err) \
+ do { \
+ ASSERT (nh_proto < FIB_PROTOCOL_IP_MAX); \
+ const fib_protocol_t nh_proto__ = (nh_proto); \
+ if (nh_proto__ >= FIB_PROTOCOL_IP_MAX) \
+ { \
+ clib_warning ("BUG: protocol %d > %d\n", \
+ (int)nh_proto__, \
+ FIB_PROTOCOL_IP_MAX); \
+ return err; \
+ } \
+ } while (0)
+
static void
adj_nbr_insert (fib_protocol_t nh_proto,
vnet_link_t link_type,
@@ -50,6 +63,8 @@ adj_nbr_insert (fib_protocol_t nh_proto,
{
adj_nbr_key_t kv;
+ ADJ_NBR_ASSERT_NH_PROTO (nh_proto,);
+
if (sw_if_index >= vec_len(adj_nbr_tables[nh_proto]))
{
vec_validate(adj_nbr_tables[nh_proto], sw_if_index);
@@ -75,6 +90,8 @@ adj_nbr_remove (adj_index_t ai,
{
adj_nbr_key_t kv;
+ ADJ_NBR_ASSERT_NH_PROTO (nh_proto,);
+
if (!ADJ_NBR_ITF_OK(nh_proto, sw_if_index))
return;
@@ -97,6 +114,8 @@ adj_nbr_find (fib_protocol_t nh_proto,
adj_nbr_key_t kv;
uword *p;
+ ADJ_NBR_ASSERT_NH_PROTO (nh_proto, ADJ_INDEX_INVALID);
+
ADJ_NBR_SET_KEY(kv, link_type, nh_addr);
if (!ADJ_NBR_ITF_OK(nh_proto, sw_if_index))
@@ -557,6 +576,8 @@ adj_nbr_walk (u32 sw_if_index,
adj_index_t ai, *ais, *aip;
adj_nbr_key_t *key;
+ ADJ_NBR_ASSERT_NH_PROTO (adj_nh_proto,);
+
if (!ADJ_NBR_ITF_OK(adj_nh_proto, sw_if_index))
return;
@@ -645,6 +666,8 @@ adj_nbr_walk_nh (u32 sw_if_index,
adj_walk_cb_t cb,
void *ctx)
{
+ ADJ_NBR_ASSERT_NH_PROTO (adj_nh_proto,);
+
if (!ADJ_NBR_ITF_OK(adj_nh_proto, sw_if_index))
return;