vnet: allow format deleted swifidx 78/40078/3
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Wed, 6 Dec 2023 16:34:57 +0000 (17:34 +0100)
committerDamjan Marion <dmarion@0xa5.net>
Thu, 7 Dec 2023 10:14:49 +0000 (10:14 +0000)
This patch prevents the sw interfaces format
function to fail when the interface was deleted.
It also prints the swifindex alongside the 'DELETED'
keyword.

Printing deleted swifindex should not happen, but it is still
helpful to have these safeguards for troubleshooting in the case
invariants get corrupted (e.g. fib entry refcounts, ...)

Type: improvement

Change-Id: I66711049db2eebe0ad17e37c3a260ac81d1e5134
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
src/vnet/fib/fib_path.c
src/vnet/interface.c
src/vnet/interface_format.c

index 1cc65b6..ee2cc8e 100644 (file)
@@ -501,11 +501,9 @@ format_fib_path (u8 * s, va_list * args)
        else
        {
            s = format (s, " %U",
-                       format_vnet_sw_interface_name,
+                       format_vnet_sw_if_index_name,
                        vnm,
-                       vnet_get_sw_interface(
-                           vnm,
-                           path->attached_next_hop.fp_interface));
+                       path->attached_next_hop.fp_interface);
            if (vnet_sw_interface_is_p2p(vnet_get_main(),
                                         path->attached_next_hop.fp_interface))
            {
index b21170f..44bcc39 100644 (file)
@@ -1359,7 +1359,10 @@ vnet_hw_interface_compare (vnet_main_t * vnm,
 int
 vnet_sw_interface_is_p2p (vnet_main_t * vnm, u32 sw_if_index)
 {
-  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
+  vnet_sw_interface_t *si = vnet_get_sw_interface_or_null (vnm, sw_if_index);
+  if (si == NULL)
+    return -1;
+
   if ((si->type == VNET_SW_INTERFACE_TYPE_P2P) ||
       (si->type == VNET_SW_INTERFACE_TYPE_PIPE))
     return 1;
index 0c051dd..f74a4ea 100644 (file)
@@ -290,7 +290,7 @@ format_vnet_sw_if_index_name (u8 * s, va_list * args)
 
   if (NULL == si)
     {
-      return format (s, "DELETED");
+      return format (s, "DELETED (%u)", sw_if_index);
     }
   return format (s, "%U", format_vnet_sw_interface_name, vnm, si);
 }
@@ -305,7 +305,7 @@ format_vnet_hw_if_index_name (u8 * s, va_list * args)
   hi = vnet_get_hw_interface (vnm, hw_if_index);
 
   if (hi == 0)
-    return format (s, "DELETED");
+    return format (s, "DELETED (%u)", hw_if_index);
 
   return format (s, "%v", hi->name);
 }