fib: do not dump no-longer valid adjacencies 32/21932/4
authorBenoît Ganne <bganne@cisco.com>
Thu, 18 Jul 2019 15:34:28 +0000 (17:34 +0200)
committerNeale Ranns <nranns@cisco.com>
Mon, 23 Sep 2019 09:14:52 +0000 (09:14 +0000)
In some cases, we can refer to no-longer adjacencies (eg. in traces). Do
not dump them in this case as they are probably incorrect (memory can be
reused).

Type: fix

Change-Id: Ib653ba066bb6595ec6ec37d313a3124bce0eeed3
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/vnet/adj/adj.c
src/vnet/adj/adj.h
src/vnet/adj/adj_mcast.c
src/vnet/ip/lookup.c

index bafa336..0966d97 100644 (file)
@@ -139,6 +139,10 @@ format_ip_adjacency (u8 * s, va_list * args)
 
     adj_index = va_arg (*args, u32);
     fiaf = va_arg (*args, format_ip_adjacency_flags_t);
+
+    if (!adj_is_valid(adj_index))
+      return format(s, "<invalid adjacency>");
+
     adj = adj_get(adj_index);
 
     switch (adj->lookup_next_index)
index fb3dc36..4c38b04 100644 (file)
@@ -432,7 +432,13 @@ extern int adj_per_adj_counters;
 static inline ip_adjacency_t *
 adj_get (adj_index_t adj_index)
 {
-    return (vec_elt_at_index(adj_pool, adj_index));
+    return (pool_elt_at_index(adj_pool, adj_index));
+}
+
+static inline int
+adj_is_valid(adj_index_t adj_index)
+{
+  return !(pool_is_free_index(adj_pool, adj_index));
 }
 
 /**
index 4454afe..c94d28e 100644 (file)
@@ -329,7 +329,12 @@ format_adj_mcast (u8* s, va_list *ap)
 {
     index_t index = va_arg(*ap, index_t);
     CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
-    ip_adjacency_t * adj = adj_get(index);
+    ip_adjacency_t * adj;
+
+    if (!adj_is_valid(index))
+      return format(s, "<invalid adjacency>");
+
+    adj = adj_get(index);
 
     s = format(s, "%U-mcast: ",
                format_fib_protocol, adj->ia_nh_proto);
index 60cedac..43d61d3 100644 (file)
@@ -261,7 +261,12 @@ format_ip_adjacency_packet_data (u8 * s, va_list * args)
   u32 adj_index = va_arg (*args, u32);
   u8 *packet_data = va_arg (*args, u8 *);
   u32 n_packet_data_bytes = va_arg (*args, u32);
-  ip_adjacency_t *adj = adj_get (adj_index);
+  ip_adjacency_t *adj;
+
+  if (!adj_is_valid (adj_index))
+    return format (s, "<invalid adjacency>");
+
+  adj = adj_get (adj_index);
 
   switch (adj->lookup_next_index)
     {