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/ip/ip_types_api.h>
31 #include <vnet/ethernet/ethernet_types_api.h>
33 #include <vnet/vnet_msg_enum.h>
35 #define vl_typedefs /* define message structures */
36 #include <vnet/vnet_all_api_h.h>
39 #define vl_endianfun /* define message structures */
40 #include <vnet/vnet_all_api_h.h>
43 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
44 #define vl_api_bridge_domain_details_t_print vl_noop_handler
46 /* instantiate all the print functions we know about */
47 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
49 #include <vnet/vnet_all_api_h.h>
52 #include <vlibapi/api_helper_macros.h>
54 #define foreach_vpe_api_msg \
55 _(L2_XCONNECT_DUMP, l2_xconnect_dump) \
56 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
57 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
58 _(L2FIB_FLUSH_ALL, l2fib_flush_all) \
59 _(L2FIB_FLUSH_INT, l2fib_flush_int) \
60 _(L2FIB_FLUSH_BD, l2fib_flush_bd) \
61 _(L2FIB_ADD_DEL, l2fib_add_del) \
62 _(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
63 _(L2_FLAGS, l2_flags) \
64 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
65 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
66 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
67 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
68 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
69 _(BD_IP_MAC_DUMP, bd_ip_mac_dump) \
70 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
71 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
72 _(BRIDGE_FLAGS, bridge_flags) \
73 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
74 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
75 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
76 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath)
79 send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
80 u32 rx_sw_if_index, u32 tx_sw_if_index)
82 vl_api_l2_xconnect_details_t *mp;
84 mp = vl_msg_api_alloc (sizeof (*mp));
85 clib_memset (mp, 0, sizeof (*mp));
86 mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
87 mp->context = context;
88 mp->rx_sw_if_index = htonl (rx_sw_if_index);
89 mp->tx_sw_if_index = htonl (tx_sw_if_index);
91 vl_api_send_msg (reg, (u8 *) mp);
95 vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
97 vl_api_registration_t *reg;
98 vnet_main_t *vnm = vnet_get_main ();
99 vnet_interface_main_t *im = &vnm->interface_main;
100 l2input_main_t *l2im = &l2input_main;
101 vnet_sw_interface_t *swif;
102 l2_input_config_t *config;
104 reg = vl_api_client_index_to_registration (mp->client_index);
109 pool_foreach (swif, im->sw_interfaces,
111 config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
112 if (config->xconnect)
113 send_l2_xconnect_details (reg, mp->context, swif->sw_if_index,
114 config->output_sw_if_index);
120 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
123 vl_api_l2_fib_clear_table_reply_t *rmp;
125 /* Clear all MACs including static MACs */
126 l2fib_clear_table ();
128 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
132 send_l2fib_table_entry (vpe_api_main_t * am,
133 vl_api_registration_t * reg,
134 l2fib_entry_key_t * l2fe_key,
135 l2fib_entry_result_t * l2fe_res, u32 context)
137 vl_api_l2_fib_table_details_t *mp;
139 mp = vl_msg_api_alloc (sizeof (*mp));
140 clib_memset (mp, 0, sizeof (*mp));
141 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
144 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
146 clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
147 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
148 mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
149 mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
150 mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
151 mp->context = context;
153 vl_api_send_msg (reg, (u8 *) mp);
157 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
159 vpe_api_main_t *am = &vpe_api_main;
160 bd_main_t *bdm = &bd_main;
161 l2fib_entry_key_t *l2fe_key = NULL;
162 l2fib_entry_result_t *l2fe_res = NULL;
163 u32 ni, bd_id = ntohl (mp->bd_id);
165 vl_api_registration_t *reg;
168 reg = vl_api_client_index_to_registration (mp->client_index);
172 /* see l2fib_table_dump: ~0 means "any" */
177 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
184 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
186 vec_foreach_index (ni, l2fe_key)
188 send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
189 vec_elt_at_index (l2fe_res, ni), mp->context);
196 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
198 bd_main_t *bdm = &bd_main;
199 l2input_main_t *l2im = &l2input_main;
200 vl_api_l2fib_add_del_reply_t *rmp;
202 u32 bd_id = ntohl (mp->bd_id);
203 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
207 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
208 goto bad_sw_if_index;
214 clib_memcpy (mac, mp->mac, 6);
218 l2fib_add_filter_entry (mac, bd_index);
221 l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE;
222 u32 sw_if_index = ntohl (mp->sw_if_index);
223 VALIDATE_SW_IF_INDEX (mp);
224 if (vec_len (l2im->configs) <= sw_if_index)
226 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
227 goto bad_sw_if_index;
231 l2_input_config_t *config;
232 config = vec_elt_at_index (l2im->configs, sw_if_index);
233 if (config->bridge == 0)
235 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
236 goto bad_sw_if_index;
240 flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
242 flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
243 l2fib_add_entry (mac, bd_index, sw_if_index, flags);
248 u32 sw_if_index = ntohl (mp->sw_if_index);
249 if (l2fib_del_entry (mac, bd_index, sw_if_index))
250 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
253 BAD_SW_IF_INDEX_LABEL;
255 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
259 vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
262 vl_api_want_l2_macs_events_reply_t *rmp;
263 l2learn_main_t *lm = &l2learn_main;
264 l2fib_main_t *fm = &l2fib_main;
265 u32 pid = ntohl (mp->pid);
266 u32 learn_limit = ntohl (mp->learn_limit);
268 if (mp->enable_disable)
270 if (lm->client_pid == 0)
272 lm->client_pid = pid;
273 lm->client_index = mp->client_index;
275 if (mp->max_macs_in_event)
276 fm->max_macs_in_event = mp->max_macs_in_event * 10;
278 fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
281 fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
283 fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
285 /* change learn limit and flush all learned MACs */
286 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
287 lm->global_learn_limit = learn_limit;
289 lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
291 l2fib_flush_all_mac (vlib_get_main ());
293 else if (lm->client_pid != pid)
295 rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
299 else if (lm->client_pid)
302 lm->client_index = 0;
303 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
304 lm->global_learn_limit = learn_limit;
306 lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
310 REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
314 vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
317 vlib_main_t *vm = vlib_get_main ();
318 vl_api_l2fib_flush_int_reply_t *rmp;
320 VALIDATE_SW_IF_INDEX (mp);
322 u32 sw_if_index = ntohl (mp->sw_if_index);
323 l2fib_flush_int_mac (vm, sw_if_index);
325 BAD_SW_IF_INDEX_LABEL;
326 REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
330 vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
333 vl_api_l2fib_flush_all_reply_t *rmp;
335 l2fib_flush_all_mac (vlib_get_main ());
336 REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
340 vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
343 vlib_main_t *vm = vlib_get_main ();
344 bd_main_t *bdm = &bd_main;
345 vl_api_l2fib_flush_bd_reply_t *rmp;
347 u32 bd_id = ntohl (mp->bd_id);
348 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
351 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
354 l2fib_flush_bd_mac (vm, *p);
356 REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
360 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
362 vl_api_l2_flags_reply_t *rmp;
366 VALIDATE_SW_IF_INDEX (mp);
368 u32 sw_if_index = ntohl (mp->sw_if_index);
369 u32 flags = ntohl (mp->feature_bitmap);
372 if (flags & L2_LEARN)
373 bitmap |= L2INPUT_FEAT_LEARN;
376 bitmap |= L2INPUT_FEAT_FWD;
378 if (flags & L2_FLOOD)
379 bitmap |= L2INPUT_FEAT_FLOOD;
381 if (flags & L2_UU_FLOOD)
382 bitmap |= L2INPUT_FEAT_UU_FLOOD;
384 if (flags & L2_ARP_TERM)
385 bitmap |= L2INPUT_FEAT_ARP_TERM;
387 rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
389 BAD_SW_IF_INDEX_LABEL;
392 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
394 rmp->resulting_feature_bitmap = ntohl(rbm);
400 vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
403 vlib_main_t *vm = vlib_get_main ();
404 bd_main_t *bdm = &bd_main;
405 vl_api_bridge_domain_set_mac_age_reply_t *rmp;
407 u32 bd_id = ntohl (mp->bd_id);
412 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
416 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
419 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
422 bd_set_mac_age (vm, *p, mp->mac_age);
424 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
428 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
430 l2_bridge_domain_add_del_args_t a = {
431 .is_add = mp->is_add,
433 .uu_flood = mp->uu_flood,
434 .forward = mp->forward,
436 .arp_term = mp->arp_term,
437 .mac_age = mp->mac_age,
438 .bd_id = ntohl (mp->bd_id),
442 int rv = bd_add_del (&a);
444 vl_api_bridge_domain_add_del_reply_t *rmp;
445 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
449 send_bridge_domain_details (l2input_main_t * l2im,
450 vl_api_registration_t * reg,
451 l2_bridge_domain_t * bd_config,
452 u32 n_sw_ifs, u32 context)
454 vl_api_bridge_domain_details_t *mp;
455 l2_flood_member_t *m;
456 vl_api_bridge_domain_sw_if_t *sw_ifs;
457 l2_input_config_t *input_cfg;
459 mp = vl_msg_api_alloc (sizeof (*mp) +
460 (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
461 clib_memset (mp, 0, sizeof (*mp));
462 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
463 mp->bd_id = ntohl (bd_config->bd_id);
464 mp->flood = bd_feature_flood (bd_config);
465 mp->uu_flood = bd_feature_uu_flood (bd_config);
466 mp->forward = bd_feature_forward (bd_config);
467 mp->learn = bd_feature_learn (bd_config);
468 mp->arp_term = bd_feature_arp_term (bd_config);
469 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
470 mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index);
471 mp->mac_age = bd_config->mac_age;
472 if (bd_config->bd_tag)
474 strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
475 ARRAY_LEN (mp->bd_tag) - 1);
476 mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
479 mp->context = context;
481 sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
482 vec_foreach (m, bd_config->members)
484 sw_ifs->sw_if_index = ntohl (m->sw_if_index);
485 input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
486 sw_ifs->shg = input_cfg->shg;
490 mp->n_sw_ifs = htonl (mp->n_sw_ifs);
492 vl_api_send_msg (reg, (u8 *) mp);
496 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
498 bd_main_t *bdm = &bd_main;
499 l2input_main_t *l2im = &l2input_main;
500 vl_api_registration_t *reg;
501 u32 bd_id, bd_index, end;
503 reg = vl_api_client_index_to_registration (mp->client_index);
507 bd_id = ntohl (mp->bd_id);
512 bd_index = 0, end = vec_len (l2im->bd_configs);
515 bd_index = bd_find_index (bdm, bd_id);
522 for (; bd_index < end; bd_index++)
524 l2_bridge_domain_t *bd_config =
525 l2input_bd_config_from_index (l2im, bd_index);
526 /* skip dummy bd_id 0 */
527 if (bd_config && (bd_config->bd_id > 0))
528 send_bridge_domain_details (l2im, reg, bd_config,
529 vec_len (bd_config->members),
535 bd_flags_decode (vl_api_bd_flags_t v)
537 bd_flags_t f = L2_NONE;
541 if (v & BRIDGE_API_FLAG_LEARN)
543 if (v & BRIDGE_API_FLAG_FWD)
545 if (v & BRIDGE_API_FLAG_FLOOD)
547 if (v & BRIDGE_API_FLAG_UU_FLOOD)
549 if (v & BRIDGE_API_FLAG_ARP_TERM)
556 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
558 vlib_main_t *vm = vlib_get_main ();
559 bd_main_t *bdm = &bd_main;
560 vl_api_bridge_flags_reply_t *rmp;
563 bd_flags_t flags = bd_flags_decode (mp->flags);
564 u32 bd_id = ntohl (mp->bd_id);
567 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
571 u32 bd_index = bd_find_index (bdm, bd_id);
574 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
578 u32 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
582 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
584 rmp->resulting_feature_bitmap = ntohl(bitmap);
590 vl_api_l2_interface_vlan_tag_rewrite_t_handler
591 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
594 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
595 vnet_main_t *vnm = vnet_get_main ();
596 vlib_main_t *vm = vlib_get_main ();
599 VALIDATE_SW_IF_INDEX (mp);
601 vtr_op = ntohl (mp->vtr_op);
603 /* The L2 code is unsuspicious */
606 case L2_VTR_DISABLED:
611 case L2_VTR_TRANSLATE_1_1:
612 case L2_VTR_TRANSLATE_1_2:
613 case L2_VTR_TRANSLATE_2_1:
614 case L2_VTR_TRANSLATE_2_2:
618 rv = VNET_API_ERROR_INVALID_VALUE;
619 goto bad_sw_if_index;
622 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
623 ntohl (mp->push_dot1q), ntohl (mp->tag1),
626 BAD_SW_IF_INDEX_LABEL;
628 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
632 vl_api_l2_interface_pbb_tag_rewrite_t_handler
633 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
635 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
636 vnet_main_t *vnm = vnet_get_main ();
637 vlib_main_t *vm = vlib_get_main ();
641 VALIDATE_SW_IF_INDEX (mp);
643 vtr_op = ntohl (mp->vtr_op);
647 case L2_VTR_DISABLED:
650 case L2_VTR_TRANSLATE_2_1:
654 rv = VNET_API_ERROR_INVALID_VALUE;
655 goto bad_sw_if_index;
658 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
659 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
660 ntohl (mp->i_sid), ntohs (mp->outer_tag));
662 BAD_SW_IF_INDEX_LABEL;
664 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
668 vl_api_sw_interface_set_l2_xconnect_t_handler
669 (vl_api_sw_interface_set_l2_xconnect_t * mp)
671 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
673 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
674 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
675 vlib_main_t *vm = vlib_get_main ();
676 vnet_main_t *vnm = vnet_get_main ();
678 VALIDATE_RX_SW_IF_INDEX (mp);
682 VALIDATE_TX_SW_IF_INDEX (mp);
683 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
685 L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index);
689 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0,
690 L2_BD_PORT_TYPE_NORMAL, 0, 0);
696 rv = VNET_API_ERROR_NON_ETHERNET;
698 case MODE_ERROR_BVI_DEF:
699 rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
703 BAD_RX_SW_IF_INDEX_LABEL;
704 BAD_TX_SW_IF_INDEX_LABEL;
706 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
710 l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l)
712 v = clib_net_to_host_u32 (v);
716 case L2_API_PORT_TYPE_NORMAL:
717 *l = L2_BD_PORT_TYPE_NORMAL;
719 case L2_API_PORT_TYPE_BVI:
720 *l = L2_BD_PORT_TYPE_BVI;
722 case L2_API_PORT_TYPE_UU_FWD:
723 *l = L2_BD_PORT_TYPE_UU_FWD;
727 return (VNET_API_ERROR_INVALID_VALUE);
731 vl_api_sw_interface_set_l2_bridge_t_handler
732 (vl_api_sw_interface_set_l2_bridge_t * mp)
734 bd_main_t *bdm = &bd_main;
735 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
737 vlib_main_t *vm = vlib_get_main ();
738 vnet_main_t *vnm = vnet_get_main ();
739 l2_bd_port_type_t pt;
741 VALIDATE_RX_SW_IF_INDEX (mp);
742 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
743 rv = l2_bd_port_type_decode (mp->port_type, &pt);
750 u32 bd_id = ntohl (mp->bd_id);
751 u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
753 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
754 rx_sw_if_index, bd_index, pt, mp->shg, 0);
758 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
764 rv = VNET_API_ERROR_NON_ETHERNET;
766 case MODE_ERROR_BVI_DEF:
767 rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
771 BAD_RX_SW_IF_INDEX_LABEL;
774 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
778 send_bd_ip_mac_entry (vpe_api_main_t * am,
779 vl_api_registration_t * reg,
780 u32 bd_id, u8 is_ipv6,
781 u8 * ip_address, u8 * mac_address, u32 context)
783 vl_api_bd_ip_mac_details_t *mp;
785 mp = vl_msg_api_alloc (sizeof (*mp));
786 clib_memset (mp, 0, sizeof (*mp));
787 mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
789 mp->bd_id = ntohl (bd_id);
791 clib_memcpy (mp->mac_address, mac_address, 6);
792 mp->is_ipv6 = is_ipv6;
793 clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
794 mp->context = context;
796 vl_api_send_msg (reg, (u8 *) mp);
800 vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
802 vpe_api_main_t *am = &vpe_api_main;
803 bd_main_t *bdm = &bd_main;
804 l2_bridge_domain_t *bd_config;
805 u32 bd_id = ntohl (mp->bd_id);
806 u32 bd_index, start, end;
807 vl_api_registration_t *reg;
810 reg = vl_api_client_index_to_registration (mp->client_index);
814 /* see bd_id: ~0 means "any" */
818 end = vec_len (l2input_main.bd_configs);
822 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
827 vec_validate (l2input_main.bd_configs, bd_index);
832 for (bd_index = start; bd_index < end; bd_index++)
834 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
835 if (bd_is_valid (bd_config))
837 ip4_address_t ip4_addr;
838 ip6_address_t *ip6_addr;
840 bd_id = bd_config->bd_id;
843 hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4,
845 send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context);
848 hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
850 send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context);
858 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
860 ip46_address_t ip_addr = ip46_address_initializer;
861 vl_api_bd_ip_mac_add_del_reply_t *rmp;
862 bd_main_t *bdm = &bd_main;
869 bd_id = ntohl (mp->bd_id);
873 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
877 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
880 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
885 type = ip_address_decode (&mp->ip, &ip_addr);
886 mac_address_decode (&mp->mac, &mac);
888 if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add))
889 rv = VNET_API_ERROR_UNSPECIFIED;
892 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
895 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
896 u32 sw_if_index, u8 enable);
899 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
903 vl_api_l2_interface_efp_filter_reply_t *rmp;
904 vnet_main_t *vnm = vnet_get_main ();
906 VALIDATE_SW_IF_INDEX (mp);
908 // enable/disable the feature
909 l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
912 BAD_SW_IF_INDEX_LABEL;
913 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
917 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
919 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
921 vl_api_l2_patch_add_del_reply_t *rmp;
922 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
926 VALIDATE_RX_SW_IF_INDEX (mp);
927 VALIDATE_TX_SW_IF_INDEX (mp);
929 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
930 ntohl (mp->tx_sw_if_index),
931 (int) (mp->is_add != 0));
933 BAD_RX_SW_IF_INDEX_LABEL;
934 BAD_TX_SW_IF_INDEX_LABEL;
936 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
940 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
942 vl_api_sw_interface_set_vpath_reply_t *rmp;
944 u32 sw_if_index = ntohl (mp->sw_if_index);
946 VALIDATE_SW_IF_INDEX (mp);
948 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
949 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
950 sw_if_index, mp->enable, 0, 0);
951 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
952 sw_if_index, mp->enable, 0, 0);
953 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
954 sw_if_index, mp->enable, 0, 0);
955 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
956 sw_if_index, mp->enable, 0, 0);
958 BAD_SW_IF_INDEX_LABEL;
960 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
965 * Add vpe's API message handlers to the table.
966 * vlib has already mapped shared memory and
967 * added the client registration handlers.
968 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
970 #define vl_msg_name_crc_list
971 #include <vnet/vnet_all_api_h.h>
972 #undef vl_msg_name_crc_list
975 setup_message_id_table (api_main_t * am)
977 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
978 foreach_vl_msg_name_crc_l2;
982 static clib_error_t *
983 l2_api_hookup (vlib_main_t * vm)
985 api_main_t *am = &api_main;
988 vl_msg_api_set_handlers(VL_API_##N, #n, \
989 vl_api_##n##_t_handler, \
991 vl_api_##n##_t_endian, \
992 vl_api_##n##_t_print, \
993 sizeof(vl_api_##n##_t), 1);
998 * Set up the (msg_name, crc, message-id) table
1000 setup_message_id_table (am);
1005 VLIB_API_INIT_FUNCTION (l2_api_hookup);
1008 * fd.io coding-style-patch-verification: ON
1011 * eval: (c-set-style "gnu")