2 *------------------------------------------------------------------
3 * l2_api.c - layer 2 forwarding api
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/l2/l2_input.h>
26 #include <vnet/l2/l2_fib.h>
27 #include <vnet/l2/l2_vtr.h>
28 #include <vnet/l2/l2_learn.h>
29 #include <vnet/l2/l2_bd.h>
30 #include <vnet/l2/l2_bvi.h>
31 #include <vnet/ip/ip_types_api.h>
32 #include <vnet/ethernet/ethernet_types_api.h>
34 #include <vnet/vnet_msg_enum.h>
36 #define vl_typedefs /* define message structures */
37 #include <vnet/vnet_all_api_h.h>
40 #define vl_endianfun /* define message structures */
41 #include <vnet/vnet_all_api_h.h>
44 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
45 #define vl_api_bridge_domain_details_t_print vl_noop_handler
47 /* instantiate all the print functions we know about */
48 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
50 #include <vnet/vnet_all_api_h.h>
53 #include <vlibapi/api_helper_macros.h>
55 #define foreach_vpe_api_msg \
56 _(L2_XCONNECT_DUMP, l2_xconnect_dump) \
57 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
58 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
59 _(L2FIB_FLUSH_ALL, l2fib_flush_all) \
60 _(L2FIB_FLUSH_INT, l2fib_flush_int) \
61 _(L2FIB_FLUSH_BD, l2fib_flush_bd) \
62 _(L2FIB_ADD_DEL, l2fib_add_del) \
63 _(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
64 _(L2_FLAGS, l2_flags) \
65 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
66 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
67 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
68 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
69 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
70 _(BD_IP_MAC_FLUSH, bd_ip_mac_flush) \
71 _(BD_IP_MAC_DUMP, bd_ip_mac_dump) \
72 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
73 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
74 _(BRIDGE_FLAGS, bridge_flags) \
75 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
76 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
77 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
78 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
79 _(BVI_CREATE, bvi_create) \
80 _(BVI_DELETE, bvi_delete)
83 send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
84 u32 rx_sw_if_index, u32 tx_sw_if_index)
86 vl_api_l2_xconnect_details_t *mp;
88 mp = vl_msg_api_alloc (sizeof (*mp));
89 clib_memset (mp, 0, sizeof (*mp));
90 mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
91 mp->context = context;
92 mp->rx_sw_if_index = htonl (rx_sw_if_index);
93 mp->tx_sw_if_index = htonl (tx_sw_if_index);
95 vl_api_send_msg (reg, (u8 *) mp);
99 vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
101 vl_api_registration_t *reg;
102 vnet_main_t *vnm = vnet_get_main ();
103 vnet_interface_main_t *im = &vnm->interface_main;
104 l2input_main_t *l2im = &l2input_main;
105 vnet_sw_interface_t *swif;
106 l2_input_config_t *config;
108 reg = vl_api_client_index_to_registration (mp->client_index);
113 pool_foreach (swif, im->sw_interfaces,
115 config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
116 if (config->xconnect)
117 send_l2_xconnect_details (reg, mp->context, swif->sw_if_index,
118 config->output_sw_if_index);
124 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
127 vl_api_l2_fib_clear_table_reply_t *rmp;
129 /* Clear all MACs including static MACs */
130 l2fib_clear_table ();
132 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
136 send_l2fib_table_entry (vpe_api_main_t * am,
137 vl_api_registration_t * reg,
138 l2fib_entry_key_t * l2fe_key,
139 l2fib_entry_result_t * l2fe_res, u32 context)
141 vl_api_l2_fib_table_details_t *mp;
143 mp = vl_msg_api_alloc (sizeof (*mp));
144 clib_memset (mp, 0, sizeof (*mp));
145 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
148 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
150 clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
151 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
152 mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
153 mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
154 mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
155 mp->context = context;
157 vl_api_send_msg (reg, (u8 *) mp);
161 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
163 vpe_api_main_t *am = &vpe_api_main;
164 bd_main_t *bdm = &bd_main;
165 l2fib_entry_key_t *l2fe_key = NULL;
166 l2fib_entry_result_t *l2fe_res = NULL;
167 u32 ni, bd_id = ntohl (mp->bd_id);
169 vl_api_registration_t *reg;
172 reg = vl_api_client_index_to_registration (mp->client_index);
176 /* see l2fib_table_dump: ~0 means "any" */
181 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
188 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
190 vec_foreach_index (ni, l2fe_key)
192 send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
193 vec_elt_at_index (l2fe_res, ni), mp->context);
200 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
202 bd_main_t *bdm = &bd_main;
203 l2input_main_t *l2im = &l2input_main;
204 vl_api_l2fib_add_del_reply_t *rmp;
206 u32 bd_id = ntohl (mp->bd_id);
207 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
211 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
212 goto bad_sw_if_index;
218 clib_memcpy (mac, mp->mac, 6);
222 l2fib_add_filter_entry (mac, bd_index);
225 l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE;
226 u32 sw_if_index = ntohl (mp->sw_if_index);
227 VALIDATE_SW_IF_INDEX (mp);
228 if (vec_len (l2im->configs) <= sw_if_index)
230 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
231 goto bad_sw_if_index;
235 l2_input_config_t *config;
236 config = vec_elt_at_index (l2im->configs, sw_if_index);
237 if (config->bridge == 0)
239 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
240 goto bad_sw_if_index;
244 flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
246 flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
247 l2fib_add_entry (mac, bd_index, sw_if_index, flags);
252 u32 sw_if_index = ntohl (mp->sw_if_index);
253 if (l2fib_del_entry (mac, bd_index, sw_if_index))
254 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
257 BAD_SW_IF_INDEX_LABEL;
259 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
263 vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
266 vl_api_want_l2_macs_events_reply_t *rmp;
267 l2learn_main_t *lm = &l2learn_main;
268 l2fib_main_t *fm = &l2fib_main;
269 u32 pid = ntohl (mp->pid);
270 u32 learn_limit = ntohl (mp->learn_limit);
272 if (mp->enable_disable)
274 if (lm->client_pid == 0)
276 lm->client_pid = pid;
277 lm->client_index = mp->client_index;
279 if (mp->max_macs_in_event)
280 fm->max_macs_in_event = mp->max_macs_in_event * 10;
282 fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
285 fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
287 fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
289 /* change learn limit and flush all learned MACs */
290 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
291 lm->global_learn_limit = learn_limit;
293 lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
295 l2fib_flush_all_mac (vlib_get_main ());
297 else if (lm->client_pid != pid)
299 rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
303 else if (lm->client_pid)
306 lm->client_index = 0;
307 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
308 lm->global_learn_limit = learn_limit;
310 lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
314 REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
318 vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
321 vlib_main_t *vm = vlib_get_main ();
322 vl_api_l2fib_flush_int_reply_t *rmp;
324 VALIDATE_SW_IF_INDEX (mp);
326 u32 sw_if_index = ntohl (mp->sw_if_index);
327 l2fib_flush_int_mac (vm, sw_if_index);
329 BAD_SW_IF_INDEX_LABEL;
330 REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
334 vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
337 vl_api_l2fib_flush_all_reply_t *rmp;
339 l2fib_flush_all_mac (vlib_get_main ());
340 REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
344 vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
347 vlib_main_t *vm = vlib_get_main ();
348 bd_main_t *bdm = &bd_main;
349 vl_api_l2fib_flush_bd_reply_t *rmp;
351 u32 bd_id = ntohl (mp->bd_id);
352 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
355 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
358 l2fib_flush_bd_mac (vm, *p);
360 REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
364 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
366 vl_api_l2_flags_reply_t *rmp;
370 VALIDATE_SW_IF_INDEX (mp);
372 u32 sw_if_index = ntohl (mp->sw_if_index);
373 u32 flags = ntohl (mp->feature_bitmap);
376 if (flags & L2_LEARN)
377 bitmap |= L2INPUT_FEAT_LEARN;
380 bitmap |= L2INPUT_FEAT_FWD;
382 if (flags & L2_FLOOD)
383 bitmap |= L2INPUT_FEAT_FLOOD;
385 if (flags & L2_UU_FLOOD)
386 bitmap |= L2INPUT_FEAT_UU_FLOOD;
388 if (flags & L2_ARP_TERM)
389 bitmap |= L2INPUT_FEAT_ARP_TERM;
391 rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
393 BAD_SW_IF_INDEX_LABEL;
396 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
398 rmp->resulting_feature_bitmap = ntohl(rbm);
404 vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
407 vlib_main_t *vm = vlib_get_main ();
408 bd_main_t *bdm = &bd_main;
409 vl_api_bridge_domain_set_mac_age_reply_t *rmp;
411 u32 bd_id = ntohl (mp->bd_id);
416 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
420 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
423 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
426 bd_set_mac_age (vm, *p, mp->mac_age);
428 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
432 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
434 l2_bridge_domain_add_del_args_t a = {
435 .is_add = mp->is_add,
437 .uu_flood = mp->uu_flood,
438 .forward = mp->forward,
440 .arp_term = mp->arp_term,
441 .arp_ufwd = mp->arp_ufwd,
442 .mac_age = mp->mac_age,
443 .bd_id = ntohl (mp->bd_id),
447 int rv = bd_add_del (&a);
449 vl_api_bridge_domain_add_del_reply_t *rmp;
450 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
454 send_bridge_domain_details (l2input_main_t * l2im,
455 vl_api_registration_t * reg,
456 l2_bridge_domain_t * bd_config,
457 u32 n_sw_ifs, u32 context)
459 vl_api_bridge_domain_details_t *mp;
460 l2_flood_member_t *m;
461 vl_api_bridge_domain_sw_if_t *sw_ifs;
462 l2_input_config_t *input_cfg;
464 mp = vl_msg_api_alloc (sizeof (*mp) +
465 (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
466 clib_memset (mp, 0, sizeof (*mp));
467 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
468 mp->bd_id = ntohl (bd_config->bd_id);
469 mp->flood = bd_feature_flood (bd_config);
470 mp->uu_flood = bd_feature_uu_flood (bd_config);
471 mp->forward = bd_feature_forward (bd_config);
472 mp->learn = bd_feature_learn (bd_config);
473 mp->arp_term = bd_feature_arp_term (bd_config);
474 mp->arp_ufwd = bd_feature_arp_ufwd (bd_config);
475 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
476 mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index);
477 mp->mac_age = bd_config->mac_age;
478 if (bd_config->bd_tag)
480 strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
481 ARRAY_LEN (mp->bd_tag) - 1);
482 mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
485 mp->context = context;
487 sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
488 vec_foreach (m, bd_config->members)
490 sw_ifs->sw_if_index = ntohl (m->sw_if_index);
491 input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
492 sw_ifs->shg = input_cfg->shg;
496 mp->n_sw_ifs = htonl (mp->n_sw_ifs);
498 vl_api_send_msg (reg, (u8 *) mp);
502 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
504 bd_main_t *bdm = &bd_main;
505 l2input_main_t *l2im = &l2input_main;
506 vl_api_registration_t *reg;
507 u32 bd_id, bd_index, end;
509 reg = vl_api_client_index_to_registration (mp->client_index);
513 bd_id = ntohl (mp->bd_id);
518 bd_index = 0, end = vec_len (l2im->bd_configs);
521 bd_index = bd_find_index (bdm, bd_id);
528 for (; bd_index < end; bd_index++)
530 l2_bridge_domain_t *bd_config =
531 l2input_bd_config_from_index (l2im, bd_index);
532 /* skip dummy bd_id 0 */
533 if (bd_config && (bd_config->bd_id > 0))
534 send_bridge_domain_details (l2im, reg, bd_config,
535 vec_len (bd_config->members),
541 bd_flags_decode (vl_api_bd_flags_t v)
543 bd_flags_t f = L2_NONE;
547 if (v & BRIDGE_API_FLAG_LEARN)
549 if (v & BRIDGE_API_FLAG_FWD)
551 if (v & BRIDGE_API_FLAG_FLOOD)
553 if (v & BRIDGE_API_FLAG_UU_FLOOD)
555 if (v & BRIDGE_API_FLAG_ARP_TERM)
557 if (v & BRIDGE_API_FLAG_ARP_UFWD)
564 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
566 vlib_main_t *vm = vlib_get_main ();
567 bd_main_t *bdm = &bd_main;
568 vl_api_bridge_flags_reply_t *rmp;
572 bd_flags_t flags = bd_flags_decode (mp->flags);
573 u32 bd_id = ntohl (mp->bd_id);
576 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
580 u32 bd_index = bd_find_index (bdm, bd_id);
583 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
587 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
591 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
593 rmp->resulting_feature_bitmap = ntohl(bitmap);
599 vl_api_l2_interface_vlan_tag_rewrite_t_handler
600 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
603 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
604 vnet_main_t *vnm = vnet_get_main ();
605 vlib_main_t *vm = vlib_get_main ();
608 VALIDATE_SW_IF_INDEX (mp);
610 vtr_op = ntohl (mp->vtr_op);
612 /* The L2 code is unsuspicious */
615 case L2_VTR_DISABLED:
620 case L2_VTR_TRANSLATE_1_1:
621 case L2_VTR_TRANSLATE_1_2:
622 case L2_VTR_TRANSLATE_2_1:
623 case L2_VTR_TRANSLATE_2_2:
627 rv = VNET_API_ERROR_INVALID_VALUE;
628 goto bad_sw_if_index;
631 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
632 ntohl (mp->push_dot1q), ntohl (mp->tag1),
635 BAD_SW_IF_INDEX_LABEL;
637 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
641 vl_api_l2_interface_pbb_tag_rewrite_t_handler
642 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
644 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
645 vnet_main_t *vnm = vnet_get_main ();
646 vlib_main_t *vm = vlib_get_main ();
650 VALIDATE_SW_IF_INDEX (mp);
652 vtr_op = ntohl (mp->vtr_op);
656 case L2_VTR_DISABLED:
659 case L2_VTR_TRANSLATE_2_1:
663 rv = VNET_API_ERROR_INVALID_VALUE;
664 goto bad_sw_if_index;
667 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
668 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
669 ntohl (mp->i_sid), ntohs (mp->outer_tag));
671 BAD_SW_IF_INDEX_LABEL;
673 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
677 vl_api_sw_interface_set_l2_xconnect_t_handler
678 (vl_api_sw_interface_set_l2_xconnect_t * mp)
680 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
682 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
683 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
684 vlib_main_t *vm = vlib_get_main ();
685 vnet_main_t *vnm = vnet_get_main ();
687 VALIDATE_RX_SW_IF_INDEX (mp);
691 VALIDATE_TX_SW_IF_INDEX (mp);
692 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
694 L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index);
698 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0,
699 L2_BD_PORT_TYPE_NORMAL, 0, 0);
705 rv = VNET_API_ERROR_NON_ETHERNET;
707 case MODE_ERROR_BVI_DEF:
708 rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
712 BAD_RX_SW_IF_INDEX_LABEL;
713 BAD_TX_SW_IF_INDEX_LABEL;
715 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
719 l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l)
721 v = clib_net_to_host_u32 (v);
725 case L2_API_PORT_TYPE_NORMAL:
726 *l = L2_BD_PORT_TYPE_NORMAL;
728 case L2_API_PORT_TYPE_BVI:
729 *l = L2_BD_PORT_TYPE_BVI;
731 case L2_API_PORT_TYPE_UU_FWD:
732 *l = L2_BD_PORT_TYPE_UU_FWD;
736 return (VNET_API_ERROR_INVALID_VALUE);
740 vl_api_sw_interface_set_l2_bridge_t_handler
741 (vl_api_sw_interface_set_l2_bridge_t * mp)
743 bd_main_t *bdm = &bd_main;
744 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
746 vlib_main_t *vm = vlib_get_main ();
747 vnet_main_t *vnm = vnet_get_main ();
748 l2_bd_port_type_t pt;
750 VALIDATE_RX_SW_IF_INDEX (mp);
751 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
752 rv = l2_bd_port_type_decode (mp->port_type, &pt);
759 u32 bd_id = ntohl (mp->bd_id);
760 u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
762 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
763 rx_sw_if_index, bd_index, pt, mp->shg, 0);
767 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
773 rv = VNET_API_ERROR_NON_ETHERNET;
775 case MODE_ERROR_BVI_DEF:
776 rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
780 BAD_RX_SW_IF_INDEX_LABEL;
783 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
787 send_bd_ip_mac_entry (vpe_api_main_t * am,
788 vl_api_registration_t * reg,
790 const ip46_address_t * ip,
792 const mac_address_t * mac, u32 context)
794 vl_api_bd_ip_mac_details_t *mp;
796 mp = vl_msg_api_alloc (sizeof (*mp));
797 clib_memset (mp, 0, sizeof (*mp));
798 mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
800 mp->context = context;
801 mp->entry.bd_id = ntohl (bd_id);
803 ip_address_encode (ip, itype, &mp->entry.ip);
804 mac_address_encode (mac, mp->entry.mac);
806 vl_api_send_msg (reg, (u8 *) mp);
810 vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
812 vpe_api_main_t *am = &vpe_api_main;
813 bd_main_t *bdm = &bd_main;
814 l2_bridge_domain_t *bd_config;
815 u32 bd_id = ntohl (mp->bd_id);
816 u32 bd_index, start, end;
817 vl_api_registration_t *reg;
820 reg = vl_api_client_index_to_registration (mp->client_index);
824 /* see bd_id: ~0 means "any" */
828 end = vec_len (l2input_main.bd_configs);
832 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
837 vec_validate (l2input_main.bd_configs, bd_index);
842 for (bd_index = start; bd_index < end; bd_index++)
844 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
845 if (bd_is_valid (bd_config))
847 ip4_address_t ip4_addr;
848 ip6_address_t *ip6_addr;
851 bd_id = bd_config->bd_id;
854 hash_foreach (ip4_addr.as_u32, mac64, bd_config->mac_by_ip4,
856 ip46_address_t ip = {
859 mac_address_from_u64(&mac, mac64);
861 send_bd_ip_mac_entry (am, reg, bd_id, &ip, IP46_TYPE_IP4,
865 hash_foreach_mem (ip6_addr, mac64, bd_config->mac_by_ip6,
867 ip46_address_t ip = {
870 mac_address_from_u64(&mac, mac64);
872 send_bd_ip_mac_entry (am, reg, bd_id, &ip, IP46_TYPE_IP6,
881 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
883 ip46_address_t ip_addr = ip46_address_initializer;
884 vl_api_bd_ip_mac_add_del_reply_t *rmp;
885 bd_main_t *bdm = &bd_main;
892 bd_id = ntohl (mp->entry.bd_id);
896 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
900 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
903 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
908 type = ip_address_decode (&mp->entry.ip, &ip_addr);
909 mac_address_decode (mp->entry.mac, &mac);
911 if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add))
912 rv = VNET_API_ERROR_UNSPECIFIED;
915 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
919 vl_api_bd_ip_mac_flush_t_handler (vl_api_bd_ip_mac_flush_t * mp)
921 vl_api_bd_ip_mac_flush_reply_t *rmp;
922 bd_main_t *bdm = &bd_main;
927 bd_id = ntohl (mp->bd_id);
931 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
935 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
938 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
943 bd_flush_ip_mac (bd_index);
946 REPLY_MACRO (VL_API_BD_IP_MAC_FLUSH_REPLY);
949 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
950 u32 sw_if_index, u8 enable);
953 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
957 vl_api_l2_interface_efp_filter_reply_t *rmp;
958 vnet_main_t *vnm = vnet_get_main ();
960 VALIDATE_SW_IF_INDEX (mp);
962 // enable/disable the feature
963 l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
966 BAD_SW_IF_INDEX_LABEL;
967 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
971 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
973 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
975 vl_api_l2_patch_add_del_reply_t *rmp;
976 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
980 VALIDATE_RX_SW_IF_INDEX (mp);
981 VALIDATE_TX_SW_IF_INDEX (mp);
983 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
984 ntohl (mp->tx_sw_if_index),
985 (int) (mp->is_add != 0));
987 BAD_RX_SW_IF_INDEX_LABEL;
988 BAD_TX_SW_IF_INDEX_LABEL;
990 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
994 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
996 vl_api_sw_interface_set_vpath_reply_t *rmp;
998 u32 sw_if_index = ntohl (mp->sw_if_index);
1000 VALIDATE_SW_IF_INDEX (mp);
1002 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1003 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
1004 sw_if_index, mp->enable, 0, 0);
1005 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
1006 sw_if_index, mp->enable, 0, 0);
1007 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
1008 sw_if_index, mp->enable, 0, 0);
1009 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
1010 sw_if_index, mp->enable, 0, 0);
1012 BAD_SW_IF_INDEX_LABEL;
1014 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1018 vl_api_bvi_create_t_handler (vl_api_bvi_create_t * mp)
1020 vl_api_bvi_create_reply_t *rmp;
1025 mac_address_decode (mp->mac, &mac);
1027 rv = l2_bvi_create (ntohl (mp->user_instance), &mac, &sw_if_index);
1030 REPLY_MACRO2(VL_API_BVI_CREATE_REPLY,
1032 rmp->sw_if_index = ntohl (sw_if_index);
1038 vl_api_bvi_delete_t_handler (vl_api_bvi_delete_t * mp)
1040 vl_api_bvi_delete_reply_t *rmp;
1043 rv = l2_bvi_delete (ntohl (mp->sw_if_index));
1045 REPLY_MACRO (VL_API_BVI_DELETE_REPLY);
1050 * Add vpe's API message handlers to the table.
1051 * vlib has already mapped shared memory and
1052 * added the client registration handlers.
1053 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1055 #define vl_msg_name_crc_list
1056 #include <vnet/vnet_all_api_h.h>
1057 #undef vl_msg_name_crc_list
1060 setup_message_id_table (api_main_t * am)
1062 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1063 foreach_vl_msg_name_crc_l2;
1067 static clib_error_t *
1068 l2_api_hookup (vlib_main_t * vm)
1070 api_main_t *am = &api_main;
1073 vl_msg_api_set_handlers(VL_API_##N, #n, \
1074 vl_api_##n##_t_handler, \
1076 vl_api_##n##_t_endian, \
1077 vl_api_##n##_t_print, \
1078 sizeof(vl_api_##n##_t), 1);
1079 foreach_vpe_api_msg;
1082 /* Mark VL_API_BRIDGE_DOMAIN_DUMP as mp safe */
1083 am->is_mp_safe[VL_API_BRIDGE_DOMAIN_DUMP] = 1;
1086 * Set up the (msg_name, crc, message-id) table
1088 setup_message_id_table (am);
1093 VLIB_API_INIT_FUNCTION (l2_api_hookup);
1096 * fd.io coding-style-patch-verification: ON
1099 * eval: (c-set-style "gnu")