#include <vnet/l2/l2_input.h>
#include <vnet/l2/l2_fib.h>
#include <vnet/l2/l2_vtr.h>
+#include <vnet/l2/l2_learn.h>
#include <vnet/vnet_msg_enum.h>
#include <vnet/vnet_all_api_h.h>
#undef vl_endianfun
+#define vl_api_bridge_domain_details_t_endian vl_noop_handler
+#define vl_api_bridge_domain_details_t_print vl_noop_handler
+
/* instantiate all the print functions we know about */
#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
#define vl_printfun
_(L2_XCONNECT_DUMP, l2_xconnect_dump) \
_(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
_(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
+_(L2FIB_FLUSH_ALL, l2fib_flush_all) \
+_(L2FIB_FLUSH_INT, l2fib_flush_int) \
+_(L2FIB_FLUSH_BD, l2fib_flush_bd) \
_(L2FIB_ADD_DEL, l2fib_add_del) \
+_(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
_(L2_FLAGS, l2_flags) \
_(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
_(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
_(BRIDGE_FLAGS, bridge_flags) \
_(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
-_(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite)
+_(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
+_(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age)
static void
send_l2_xconnect_details (unix_shared_memory_queue_t * q, u32 context,
int rv = 0;
vl_api_l2_fib_clear_table_reply_t *rmp;
- /* DAW-FIXME: This API should only clear non-static l2fib entries, but
- * that is not currently implemented. When that TODO is fixed
- * this call should be changed to pass 1 instead of 0.
- */
- l2fib_clear_table (0);
+ /* Clear all MACs including static MACs */
+ l2fib_clear_table ();
REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
}
l2fib_entry_key_t * l2fe_key,
l2fib_entry_result_t * l2fe_res, u32 context)
{
- vl_api_l2_fib_table_entry_t *mp;
+ vl_api_l2_fib_table_details_t *mp;
mp = vl_msg_api_alloc (sizeof (*mp));
memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
+ mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
mp->bd_id =
ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
- mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
+ clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
mp->static_mac = l2fe_res->fields.static_mac;
mp->filter_mac = l2fe_res->fields.filter;
l2input_main_t *l2im = &l2input_main;
vl_api_l2fib_add_del_reply_t *rmp;
int rv = 0;
- u64 mac = 0;
- u32 sw_if_index = ntohl (mp->sw_if_index);
u32 bd_id = ntohl (mp->bd_id);
- u32 bd_index;
- u32 static_mac;
- u32 filter_mac;
- u32 bvi_mac;
- uword *p;
+ uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
- mac = mp->mac;
-
- p = hash_get (bdm->bd_index_by_bd_id, bd_id);
if (!p)
{
rv = VNET_API_ERROR_NO_SUCH_ENTRY;
goto bad_sw_if_index;
}
- bd_index = p[0];
+ u32 bd_index = p[0];
+
+ u8 mac[6];
+ clib_memcpy (mac, mp->mac, 6);
if (mp->is_add)
{
- filter_mac = mp->filter_mac ? 1 : 0;
- if (filter_mac == 0)
+ if (mp->filter_mac)
+ l2fib_add_filter_entry (mac, bd_index);
+ else
{
+ u32 sw_if_index = ntohl (mp->sw_if_index);
VALIDATE_SW_IF_INDEX (mp);
if (vec_len (l2im->configs) <= sw_if_index)
{
goto bad_sw_if_index;
}
}
+ u8 static_mac = mp->static_mac ? 1 : 0;
+ u8 bvi_mac = mp->bvi_mac ? 1 : 0;
+ l2fib_add_fwd_entry (mac, bd_index, sw_if_index, static_mac,
+ bvi_mac);
}
- static_mac = mp->static_mac ? 1 : 0;
- bvi_mac = mp->bvi_mac ? 1 : 0;
- l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
- bvi_mac);
}
else
{
REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
}
+static void
+vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
+{
+ int rv = 0;
+ vl_api_want_l2_macs_events_reply_t *rmp;
+ l2learn_main_t *lm = &l2learn_main;
+ l2fib_main_t *fm = &l2fib_main;
+ u32 pid = ntohl (mp->pid);
+ u32 learn_limit = ntohl (mp->learn_limit);
+
+ if (mp->enable_disable)
+ {
+ if (lm->client_pid == 0)
+ {
+ lm->client_pid = pid;
+ lm->client_index = mp->client_index;
+
+ if (mp->max_macs_in_event)
+ fm->max_macs_in_event = mp->max_macs_in_event * 10;
+ else
+ fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
+
+ if (mp->scan_delay)
+ fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
+ else
+ fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
+
+ /* change learn limit and flush all learned MACs */
+ if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
+ lm->global_learn_limit = learn_limit;
+ else
+ lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
+
+ l2fib_flush_all_mac (vlib_get_main ());
+ }
+ else if (lm->client_pid != pid)
+ {
+ rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
+ goto exit;
+ }
+ }
+ else if (lm->client_pid)
+ {
+ lm->client_pid = 0;
+ lm->client_index = 0;
+ if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
+ lm->global_learn_limit = learn_limit;
+ else
+ lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
+ }
+
+exit:
+ REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
+}
+
+static void
+vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
+{
+ int rv = 0;
+ vlib_main_t *vm = vlib_get_main ();
+ vl_api_l2fib_flush_int_reply_t *rmp;
+
+ VALIDATE_SW_IF_INDEX (mp);
+
+ u32 sw_if_index = ntohl (mp->sw_if_index);
+ l2fib_flush_int_mac (vm, sw_if_index);
+
+ BAD_SW_IF_INDEX_LABEL;
+ REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
+}
+
+static void
+vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
+{
+ int rv = 0;
+ vl_api_l2fib_flush_all_reply_t *rmp;
+
+ l2fib_flush_all_mac (vlib_get_main ());
+ REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
+}
+
+static void
+vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
+{
+ int rv = 0;
+ vlib_main_t *vm = vlib_get_main ();
+ bd_main_t *bdm = &bd_main;
+ vl_api_l2fib_flush_bd_reply_t *rmp;
+
+ u32 bd_id = ntohl (mp->bd_id);
+ uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
+ if (p == 0)
+ {
+ rv = VNET_API_ERROR_NO_SUCH_ENTRY;
+ goto out;
+ }
+ l2fib_flush_bd_mac (vm, *p);
+out:
+ REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
+}
+
static void
vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
{
vl_api_l2_flags_reply_t *rmp;
int rv = 0;
- u32 sw_if_index = ntohl (mp->sw_if_index);
- u32 flags = ntohl (mp->feature_bitmap);
u32 rbm = 0;
VALIDATE_SW_IF_INDEX (mp);
-#define _(a,b) \
- if (flags & L2INPUT_FEAT_ ## a) \
- rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
- foreach_l2input_feat;
-#undef _
+ u32 sw_if_index = ntohl (mp->sw_if_index);
+ u32 flags = ntohl (mp->feature_bitmap);
+ u32 bitmap = 0;
+
+ if (flags & L2_LEARN)
+ bitmap |= L2INPUT_FEAT_LEARN;
+
+ if (flags & L2_FWD)
+ bitmap |= L2INPUT_FEAT_FWD;
+
+ if (flags & L2_FLOOD)
+ bitmap |= L2INPUT_FEAT_FLOOD;
+
+ if (flags & L2_UU_FLOOD)
+ bitmap |= L2INPUT_FEAT_UU_FLOOD;
+
+ if (flags & L2_ARP_TERM)
+ bitmap |= L2INPUT_FEAT_ARP_TERM;
+
+ rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
BAD_SW_IF_INDEX_LABEL;
}
static void
-vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
+vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
+ * mp)
{
vlib_main_t *vm = vlib_get_main ();
bd_main_t *bdm = &bd_main;
- vl_api_bridge_domain_add_del_reply_t *rmp;
+ vl_api_bridge_domain_set_mac_age_reply_t *rmp;
int rv = 0;
- u32 enable_flags = 0, disable_flags = 0;
u32 bd_id = ntohl (mp->bd_id);
- u32 bd_index;
+ uword *p;
- if (mp->is_add)
+ if (bd_id == 0)
{
- bd_index = bd_find_or_add_bd_index (bdm, bd_id);
-
- if (mp->flood)
- enable_flags |= L2_FLOOD;
- else
- disable_flags |= L2_FLOOD;
-
- if (mp->uu_flood)
- enable_flags |= L2_UU_FLOOD;
- else
- disable_flags |= L2_UU_FLOOD;
-
- if (mp->forward)
- enable_flags |= L2_FWD;
- else
- disable_flags |= L2_FWD;
-
- if (mp->arp_term)
- enable_flags |= L2_ARP_TERM;
- else
- disable_flags |= L2_ARP_TERM;
-
- if (mp->learn)
- enable_flags |= L2_LEARN;
- else
- disable_flags |= L2_LEARN;
-
- if (enable_flags)
- bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
-
- if (disable_flags)
- bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
+ rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
+ goto out;
+ }
- bd_set_mac_age (vm, bd_index, mp->mac_age);
+ p = hash_get (bdm->bd_index_by_bd_id, bd_id);
+ if (p == 0)
+ {
+ rv = VNET_API_ERROR_NO_SUCH_ENTRY;
+ goto out;
}
- else
- rv = bd_delete_bd_index (bdm, bd_id);
+ bd_set_mac_age (vm, *p, mp->mac_age);
+out:
+ REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
+}
+static void
+vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
+{
+ l2_bridge_domain_add_del_args_t a = {
+ .is_add = mp->is_add,
+ .flood = mp->flood,
+ .uu_flood = mp->uu_flood,
+ .forward = mp->forward,
+ .learn = mp->learn,
+ .arp_term = mp->arp_term,
+ .mac_age = mp->mac_age,
+ .bd_id = ntohl (mp->bd_id),
+ .bd_tag = mp->bd_tag
+ };
+
+ int rv = bd_add_del (&a);
+
+ vl_api_bridge_domain_add_del_reply_t *rmp;
REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
}
static void
-send_bridge_domain_details (unix_shared_memory_queue_t * q,
+send_bridge_domain_details (l2input_main_t * l2im,
+ unix_shared_memory_queue_t * q,
l2_bridge_domain_t * bd_config,
u32 n_sw_ifs, u32 context)
{
vl_api_bridge_domain_details_t *mp;
+ l2_flood_member_t *m;
+ vl_api_bridge_domain_sw_if_t *sw_ifs;
+ l2_input_config_t *input_cfg;
- mp = vl_msg_api_alloc (sizeof (*mp));
+ mp = vl_msg_api_alloc (sizeof (*mp) +
+ (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
memset (mp, 0, sizeof (*mp));
mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
mp->bd_id = ntohl (bd_config->bd_id);
mp->arp_term = bd_feature_arp_term (bd_config);
mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
mp->mac_age = bd_config->mac_age;
- mp->n_sw_ifs = ntohl (n_sw_ifs);
- mp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
-send_bd_sw_if_details (l2input_main_t * l2im,
- unix_shared_memory_queue_t * q,
- l2_flood_member_t * member, u32 bd_id, u32 context)
-{
- vl_api_bridge_domain_sw_if_details_t *mp;
- l2_input_config_t *input_cfg;
+ if (bd_config->bd_tag)
+ {
+ strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
+ ARRAY_LEN (mp->bd_tag) - 1);
+ mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
+ }
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
- mp->bd_id = ntohl (bd_id);
- mp->sw_if_index = ntohl (member->sw_if_index);
- input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
- mp->shg = input_cfg->shg;
mp->context = context;
+ sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
+ vec_foreach (m, bd_config->members)
+ {
+ sw_ifs->sw_if_index = ntohl (m->sw_if_index);
+ input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
+ sw_ifs->shg = input_cfg->shg;
+ sw_ifs++;
+ mp->n_sw_ifs++;
+ }
+ mp->n_sw_ifs = htonl (mp->n_sw_ifs);
+
vl_msg_api_send_shmem (q, (u8 *) & mp);
}
{
bd_main_t *bdm = &bd_main;
l2input_main_t *l2im = &l2input_main;
- unix_shared_memory_queue_t *q;
- l2_bridge_domain_t *bd_config;
- u32 bd_id, bd_index;
- u32 end;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
+ unix_shared_memory_queue_t *q =
+ vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
return;
- bd_id = ntohl (mp->bd_id);
+ u32 bd_id = ntohl (mp->bd_id);
+ if (bd_id == 0)
+ return;
+
+ u32 bd_index, end;
+ if (bd_id == ~0)
+ bd_index = 0, end = vec_len (l2im->bd_configs);
+ else
+ {
+ bd_index = bd_find_index (bdm, bd_id);
+ if (bd_index == ~0)
+ return;
+
+ end = bd_index + 1;
+ }
- bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
- end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
for (; bd_index < end; bd_index++)
{
- bd_config = l2input_bd_config_from_index (l2im, bd_index);
+ l2_bridge_domain_t *bd_config =
+ l2input_bd_config_from_index (l2im, bd_index);
/* skip dummy bd_id 0 */
if (bd_config && (bd_config->bd_id > 0))
- {
- u32 n_sw_ifs;
- l2_flood_member_t *m;
-
- n_sw_ifs = vec_len (bd_config->members);
- send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
-
- vec_foreach (m, bd_config->members)
- {
- send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
- }
- }
+ send_bridge_domain_details (l2im, q, bd_config,
+ vec_len (bd_config->members),
+ mp->context);
}
}
bd_main_t *bdm = &bd_main;
vl_api_bridge_flags_reply_t *rmp;
int rv = 0;
- u32 bd_id = ntohl (mp->bd_id);
- u32 bd_index;
+
u32 flags = ntohl (mp->feature_bitmap);
- uword *p;
+ u32 bd_id = ntohl (mp->bd_id);
+ if (bd_id == 0)
+ {
+ rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
+ goto out;
+ }
- p = hash_get (bdm->bd_index_by_bd_id, bd_id);
- if (p == 0)
+ u32 bd_index = bd_find_index (bdm, bd_id);
+ if (bd_index == ~0)
{
rv = VNET_API_ERROR_NO_SUCH_ENTRY;
goto out;
}
- bd_index = p[0];
-
- bd_set_flags (vm, bd_index, flags, mp->is_set);
+ u32 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
out:
/* *INDENT-OFF* */
REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
({
- rmp->resulting_feature_bitmap = ntohl(flags);
+ rmp->resulting_feature_bitmap = ntohl(bitmap);
}));
/* *INDENT-ON* */
}