vppinfra: bihash walk cb typedef and continue/stop controls
[vpp.git] / src / vnet / l2 / l2_fib.c
index fc518fe..3e71f77 100644 (file)
@@ -95,12 +95,13 @@ format_vnet_sw_if_index_name_with_NA (u8 * s, va_list * args)
   if (sw_if_index == ~0)
     return format (s, "N/A");
 
-  vnet_sw_interface_t *swif = vnet_get_sw_interface_safe (vnm, sw_if_index);
+  vnet_sw_interface_t *swif =
+    vnet_get_sw_interface_or_null (vnm, sw_if_index);
   if (!swif)
     return format (s, "Stale");
 
   return format (s, "%U", format_vnet_sw_interface_name, vnm,
-                vnet_get_sw_interface_safe (vnm, sw_if_index));
+                vnet_get_sw_interface_or_null (vnm, sw_if_index));
 }
 
 typedef struct l2fib_dump_walk_ctx_t_
@@ -110,7 +111,7 @@ typedef struct l2fib_dump_walk_ctx_t_
   l2fib_entry_result_t *l2fe_res;
 } l2fib_dump_walk_ctx_t;
 
-static void
+static int
 l2fib_dump_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   l2fib_dump_walk_ctx_t *ctx = arg;
@@ -125,6 +126,8 @@ l2fib_dump_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
       vec_add1 (ctx->l2fe_key, key);
       vec_add1 (ctx->l2fe_res, result);
     }
+
+  return (BIHASH_WALK_CONTINUE);
 }
 
 void
@@ -157,7 +160,7 @@ typedef struct l2fib_show_walk_ctx_t_
   u8 now;
 } l2fib_show_walk_ctx_t;
 
-static void
+static int
 l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
 {
   l2fib_show_walk_ctx_t *ctx = arg;
@@ -185,10 +188,10 @@ l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
       u8 *s = NULL;
 
       if (ctx->learn && l2fib_entry_result_is_set_AGE_NOT (&result))
-       return;                 /* skip provisioned macs */
+       return (BIHASH_WALK_CONTINUE);  /* skip provisioned macs */
 
       if (ctx->add && !l2fib_entry_result_is_set_AGE_NOT (&result))
-       return;                 /* skip learned macs */
+       return (BIHASH_WALK_CONTINUE);  /* skip learned macs */
 
       bd_config = vec_elt_at_index (l2input_main.bd_configs,
                                    key.fields.bd_index);
@@ -218,6 +221,8 @@ l2fib_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
                       ctx->vnm, result.fields.sw_if_index);
       vec_free (s);
     }
+
+  return (BIHASH_WALK_CONTINUE);
 }
 
 /** Display the contents of the l2fib. */
@@ -1000,6 +1005,10 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
   vl_api_l2_macs_event_t *mp = 0;
   vl_api_registration_t *reg = 0;
 
+  /* Don't scan the l2 fib if it hasn't been instantiated yet */
+  if (alloc_arena (h) == 0)
+    return 0.0;
+
   if (client)
     {
       mp = allocate_mac_evt_buf (client, cl_idx);