api: binary api cleanup
[vpp.git] / src / vnet / l2 / l2_fib.c
index 46c041e..600d0c9 100644 (file)
 
 l2fib_main_t l2fib_main;
 
+u8 *
+format_l2fib_entry_result_flags (u8 * s, va_list * args)
+{
+  l2fib_entry_result_flags_t flags = va_arg (*args, int);
+
+  if (L2FIB_ENTRY_RESULT_FLAG_NONE == flags)
+    {
+      s = format (s, "none");
+    }
+  else
+    {
+#define _(a,v,t) {                              \
+      if (flags & L2FIB_ENTRY_RESULT_FLAG_##a)  \
+        s = format (s, "%s ", t);               \
+    }
+      foreach_l2fib_entry_result_attr
+#undef _
+    }
+  return (s);
+}
+
 static void
 incr_mac_address (u8 * mac)
 {
@@ -62,7 +83,7 @@ incr_mac_address (u8 * mac)
   tmp += 1 << 16;              /* skip unused (least significant) octets */
   tmp = clib_host_to_net_u64 (tmp);
 
-  clib_memcpy (mac, &tmp, 6);
+  clib_memcpy_fast (mac, &tmp, 6);
 }
 
 /** Format sw_if_index. If the value is ~0, use the text "N/A" */
@@ -74,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_
@@ -563,7 +585,7 @@ l2fib_test_command_fn (vlib_main_t * vm,
     return clib_error_return (0,
                              "noop: pick at least one of (add,del,check)");
 
-  clib_memcpy (save_mac, mac, 6);
+  clib_memcpy_fast (save_mac, mac, 6);
 
   if (is_add)
     {
@@ -580,7 +602,7 @@ l2fib_test_command_fn (vlib_main_t * vm,
       BVT (clib_bihash_kv) kv;
       l2fib_main_t *mp = &l2fib_main;
 
-      clib_memcpy (mac, save_mac, 6);
+      clib_memcpy_fast (mac, save_mac, 6);
 
       for (i = 0; i < count; i++)
        {
@@ -596,7 +618,7 @@ l2fib_test_command_fn (vlib_main_t * vm,
 
   if (is_del)
     {
-      clib_memcpy (mac, save_mac, 6);
+      clib_memcpy_fast (mac, save_mac, 6);
 
       for (i = 0; i < count; i++)
        {
@@ -979,6 +1001,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);
@@ -1050,8 +1076,8 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
                  if (l2fib_entry_result_is_set_LRN_EVT (&result))
                    {
                      /* copy mac entry to event msg */
-                     clib_memcpy (mp->mac[evt_idx].mac_addr, key.fields.mac,
-                                  6);
+                     clib_memcpy_fast (mp->mac[evt_idx].mac_addr,
+                                       key.fields.mac, 6);
                      mp->mac[evt_idx].action =
                        l2fib_entry_result_is_set_LRN_MOV (&result) ?
                        MAC_EVENT_ACTION_MOVE : MAC_EVENT_ACTION_ADD;
@@ -1095,7 +1121,8 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
              if (client)
                {
                  /* copy mac entry to event msg */
-                 clib_memcpy (mp->mac[evt_idx].mac_addr, key.fields.mac, 6);
+                 clib_memcpy_fast (mp->mac[evt_idx].mac_addr, key.fields.mac,
+                                   6);
                  mp->mac[evt_idx].action = MAC_EVENT_ACTION_DELETE;
                  mp->mac[evt_idx].sw_if_index =
                    htonl (result.fields.sw_if_index);