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)
{
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" */
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_
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;
vec_add1 (ctx->l2fe_key, key);
vec_add1 (ctx->l2fe_res, result);
}
+
+ return (BIHASH_WALK_CONTINUE);
}
void
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;
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);
ctx->vnm, result.fields.sw_if_index);
vec_free (s);
}
+
+ return (BIHASH_WALK_CONTINUE);
}
/** Display the contents of the l2fib. */
}
/*?
- * This command dispays the MAC Address entries of the L2 FIB table.
+ * This command displays the MAC Address entries of the L2 FIB table.
* Output can be filtered to just get the number of MAC Addresses or display
* each MAC Address for all bridge domains or just a single bridge domain.
*
/* set up key */
key.raw = l2fib_make_key (mac, bd_index);
+ kv.key = key.raw;
- /* check if entry alread exist */
+ /* check if entry already exist */
if (BV (clib_bihash_search) (&fm->mac_table, &kv, &kv))
{
/* decrement counter if overwriting a learned mac */
/* no aging for provisioned entry */
l2fib_entry_result_set_AGE_NOT (&result);
- kv.key = key.raw;
kv.value = result.raw;
BV (clib_bihash_add_del) (&fm->mac_table, &kv, 1 /* is_add */ );
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)
{
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++)
{
if (is_del)
{
- clib_memcpy (mac, save_mac, 6);
+ clib_memcpy_fast (mac, save_mac, 6);
for (i = 0; i < count; i++)
{
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);
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;
+ (vl_api_mac_event_action_t) MAC_EVENT_ACTION_MOVE
+ : (vl_api_mac_event_action_t) MAC_EVENT_ACTION_ADD;
+ mp->mac[evt_idx].action =
+ htonl (mp->mac[evt_idx].action);
mp->mac[evt_idx].sw_if_index =
htonl (result.fields.sw_if_index);
/* clear event bits and update mac entry */
}
if (event_only || l2fib_entry_result_is_set_AGE_NOT (&result))
- continue; /* skip aging - static_mac alsways age_not */
+ continue; /* skip aging - static_mac always age_not */
/* start aging processing */
u32 bd_index = key.fields.bd_index;
if (client)
{
/* copy mac entry to event msg */
- clib_memcpy (mp->mac[evt_idx].mac_addr, key.fields.mac, 6);
- mp->mac[evt_idx].action = MAC_EVENT_ACTION_DELETE;
+ clib_memcpy_fast (mp->mac[evt_idx].mac_addr, key.fields.mac,
+ 6);
+ mp->mac[evt_idx].action =
+ (vl_api_mac_event_action_t) MAC_EVENT_ACTION_DELETE;
+ mp->mac[evt_idx].action = htonl (mp->mac[evt_idx].action);
mp->mac[evt_idx].sw_if_index =
htonl (result.fields.sw_if_index);
evt_idx++;
L2FIB_NUM_BUCKETS, L2FIB_MEMORY_SIZE);
/* verify the key constructor is good, since it is endian-sensitive */
- memset (test_mac, 0, sizeof (test_mac));
+ clib_memset (test_mac, 0, sizeof (test_mac));
test_mac[0] = 0x11;
test_key.raw = 0;
test_key.raw = l2fib_make_key ((u8 *) & test_mac, 0x1234);