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>
30 #include <vnet/vnet_msg_enum.h>
32 #define vl_typedefs /* define message structures */
33 #include <vnet/vnet_all_api_h.h>
36 #define vl_endianfun /* define message structures */
37 #include <vnet/vnet_all_api_h.h>
40 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
41 #define vl_api_bridge_domain_details_t_print vl_noop_handler
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #include <vnet/vnet_all_api_h.h>
49 #include <vlibapi/api_helper_macros.h>
51 #define foreach_vpe_api_msg \
52 _(L2_XCONNECT_DUMP, l2_xconnect_dump) \
53 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
54 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
55 _(L2FIB_FLUSH_ALL, l2fib_flush_all) \
56 _(L2FIB_FLUSH_INT, l2fib_flush_int) \
57 _(L2FIB_FLUSH_BD, l2fib_flush_bd) \
58 _(L2FIB_ADD_DEL, l2fib_add_del) \
59 _(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
60 _(L2_FLAGS, l2_flags) \
61 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
62 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
63 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
64 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
65 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
66 _(BD_IP_MAC_DUMP, bd_ip_mac_dump) \
67 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
68 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
69 _(BRIDGE_FLAGS, bridge_flags) \
70 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
71 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
72 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
73 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath)
76 send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
77 u32 rx_sw_if_index, u32 tx_sw_if_index)
79 vl_api_l2_xconnect_details_t *mp;
81 mp = vl_msg_api_alloc (sizeof (*mp));
82 memset (mp, 0, sizeof (*mp));
83 mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
84 mp->context = context;
85 mp->rx_sw_if_index = htonl (rx_sw_if_index);
86 mp->tx_sw_if_index = htonl (tx_sw_if_index);
88 vl_api_send_msg (reg, (u8 *) mp);
92 vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
94 vl_api_registration_t *reg;
95 vnet_main_t *vnm = vnet_get_main ();
96 vnet_interface_main_t *im = &vnm->interface_main;
97 l2input_main_t *l2im = &l2input_main;
98 vnet_sw_interface_t *swif;
99 l2_input_config_t *config;
101 reg = vl_api_client_index_to_registration (mp->client_index);
106 pool_foreach (swif, im->sw_interfaces,
108 config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
109 if (config->xconnect)
110 send_l2_xconnect_details (reg, mp->context, swif->sw_if_index,
111 config->output_sw_if_index);
117 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
120 vl_api_l2_fib_clear_table_reply_t *rmp;
122 /* Clear all MACs including static MACs */
123 l2fib_clear_table ();
125 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
129 send_l2fib_table_entry (vpe_api_main_t * am,
130 vl_api_registration_t * reg,
131 l2fib_entry_key_t * l2fe_key,
132 l2fib_entry_result_t * l2fe_res, u32 context)
134 vl_api_l2_fib_table_details_t *mp;
136 mp = vl_msg_api_alloc (sizeof (*mp));
137 memset (mp, 0, sizeof (*mp));
138 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
141 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
143 clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
144 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
145 mp->static_mac = l2fe_res->fields.static_mac;
146 mp->filter_mac = l2fe_res->fields.filter;
147 mp->bvi_mac = l2fe_res->fields.bvi;
148 mp->context = context;
150 vl_api_send_msg (reg, (u8 *) mp);
154 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
156 vpe_api_main_t *am = &vpe_api_main;
157 bd_main_t *bdm = &bd_main;
158 l2fib_entry_key_t *l2fe_key = NULL;
159 l2fib_entry_result_t *l2fe_res = NULL;
160 u32 ni, bd_id = ntohl (mp->bd_id);
162 vl_api_registration_t *reg;
165 reg = vl_api_client_index_to_registration (mp->client_index);
169 /* see l2fib_table_dump: ~0 means "any" */
174 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
181 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
183 vec_foreach_index (ni, l2fe_key)
185 send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
186 vec_elt_at_index (l2fe_res, ni), mp->context);
193 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
195 bd_main_t *bdm = &bd_main;
196 l2input_main_t *l2im = &l2input_main;
197 vl_api_l2fib_add_del_reply_t *rmp;
199 u32 bd_id = ntohl (mp->bd_id);
200 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
204 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
205 goto bad_sw_if_index;
211 clib_memcpy (mac, mp->mac, 6);
215 l2fib_add_filter_entry (mac, bd_index);
218 u32 sw_if_index = ntohl (mp->sw_if_index);
219 VALIDATE_SW_IF_INDEX (mp);
220 if (vec_len (l2im->configs) <= sw_if_index)
222 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
223 goto bad_sw_if_index;
227 l2_input_config_t *config;
228 config = vec_elt_at_index (l2im->configs, sw_if_index);
229 if (config->bridge == 0)
231 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
232 goto bad_sw_if_index;
235 u8 static_mac = mp->static_mac ? 1 : 0;
236 u8 bvi_mac = mp->bvi_mac ? 1 : 0;
237 l2fib_add_fwd_entry (mac, bd_index, sw_if_index, static_mac,
243 u32 sw_if_index = ntohl (mp->sw_if_index);
244 if (l2fib_del_entry (mac, bd_index, sw_if_index))
245 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
248 BAD_SW_IF_INDEX_LABEL;
250 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
254 vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
257 vl_api_want_l2_macs_events_reply_t *rmp;
258 l2learn_main_t *lm = &l2learn_main;
259 l2fib_main_t *fm = &l2fib_main;
260 u32 pid = ntohl (mp->pid);
261 u32 learn_limit = ntohl (mp->learn_limit);
263 if (mp->enable_disable)
265 if (lm->client_pid == 0)
267 lm->client_pid = pid;
268 lm->client_index = mp->client_index;
270 if (mp->max_macs_in_event)
271 fm->max_macs_in_event = mp->max_macs_in_event * 10;
273 fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
276 fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
278 fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
280 /* change learn limit and flush all learned MACs */
281 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
282 lm->global_learn_limit = learn_limit;
284 lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
286 l2fib_flush_all_mac (vlib_get_main ());
288 else if (lm->client_pid != pid)
290 rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
294 else if (lm->client_pid)
297 lm->client_index = 0;
298 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
299 lm->global_learn_limit = learn_limit;
301 lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
305 REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
309 vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
312 vlib_main_t *vm = vlib_get_main ();
313 vl_api_l2fib_flush_int_reply_t *rmp;
315 VALIDATE_SW_IF_INDEX (mp);
317 u32 sw_if_index = ntohl (mp->sw_if_index);
318 l2fib_flush_int_mac (vm, sw_if_index);
320 BAD_SW_IF_INDEX_LABEL;
321 REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
325 vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
328 vl_api_l2fib_flush_all_reply_t *rmp;
330 l2fib_flush_all_mac (vlib_get_main ());
331 REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
335 vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
338 vlib_main_t *vm = vlib_get_main ();
339 bd_main_t *bdm = &bd_main;
340 vl_api_l2fib_flush_bd_reply_t *rmp;
342 u32 bd_id = ntohl (mp->bd_id);
343 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
346 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
349 l2fib_flush_bd_mac (vm, *p);
351 REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
355 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
357 vl_api_l2_flags_reply_t *rmp;
361 VALIDATE_SW_IF_INDEX (mp);
363 u32 sw_if_index = ntohl (mp->sw_if_index);
364 u32 flags = ntohl (mp->feature_bitmap);
367 if (flags & L2_LEARN)
368 bitmap |= L2INPUT_FEAT_LEARN;
371 bitmap |= L2INPUT_FEAT_FWD;
373 if (flags & L2_FLOOD)
374 bitmap |= L2INPUT_FEAT_FLOOD;
376 if (flags & L2_UU_FLOOD)
377 bitmap |= L2INPUT_FEAT_UU_FLOOD;
379 if (flags & L2_ARP_TERM)
380 bitmap |= L2INPUT_FEAT_ARP_TERM;
382 rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
384 BAD_SW_IF_INDEX_LABEL;
387 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
389 rmp->resulting_feature_bitmap = ntohl(rbm);
395 vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
398 vlib_main_t *vm = vlib_get_main ();
399 bd_main_t *bdm = &bd_main;
400 vl_api_bridge_domain_set_mac_age_reply_t *rmp;
402 u32 bd_id = ntohl (mp->bd_id);
407 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
411 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
414 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
417 bd_set_mac_age (vm, *p, mp->mac_age);
419 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
423 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
425 l2_bridge_domain_add_del_args_t a = {
426 .is_add = mp->is_add,
428 .uu_flood = mp->uu_flood,
429 .forward = mp->forward,
431 .arp_term = mp->arp_term,
432 .mac_age = mp->mac_age,
433 .bd_id = ntohl (mp->bd_id),
437 int rv = bd_add_del (&a);
439 vl_api_bridge_domain_add_del_reply_t *rmp;
440 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
444 send_bridge_domain_details (l2input_main_t * l2im,
445 vl_api_registration_t * reg,
446 l2_bridge_domain_t * bd_config,
447 u32 n_sw_ifs, u32 context)
449 vl_api_bridge_domain_details_t *mp;
450 l2_flood_member_t *m;
451 vl_api_bridge_domain_sw_if_t *sw_ifs;
452 l2_input_config_t *input_cfg;
454 mp = vl_msg_api_alloc (sizeof (*mp) +
455 (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
456 memset (mp, 0, sizeof (*mp));
457 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
458 mp->bd_id = ntohl (bd_config->bd_id);
459 mp->flood = bd_feature_flood (bd_config);
460 mp->uu_flood = bd_feature_uu_flood (bd_config);
461 mp->forward = bd_feature_forward (bd_config);
462 mp->learn = bd_feature_learn (bd_config);
463 mp->arp_term = bd_feature_arp_term (bd_config);
464 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
465 mp->mac_age = bd_config->mac_age;
466 if (bd_config->bd_tag)
468 strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
469 ARRAY_LEN (mp->bd_tag) - 1);
470 mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
473 mp->context = context;
475 sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
476 vec_foreach (m, bd_config->members)
478 sw_ifs->sw_if_index = ntohl (m->sw_if_index);
479 input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
480 sw_ifs->shg = input_cfg->shg;
484 mp->n_sw_ifs = htonl (mp->n_sw_ifs);
486 vl_api_send_msg (reg, (u8 *) mp);
490 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
492 bd_main_t *bdm = &bd_main;
493 l2input_main_t *l2im = &l2input_main;
494 vl_api_registration_t *reg;
495 u32 bd_id, bd_index, end;
497 reg = vl_api_client_index_to_registration (mp->client_index);
501 bd_id = ntohl (mp->bd_id);
506 bd_index = 0, end = vec_len (l2im->bd_configs);
509 bd_index = bd_find_index (bdm, bd_id);
516 for (; bd_index < end; bd_index++)
518 l2_bridge_domain_t *bd_config =
519 l2input_bd_config_from_index (l2im, bd_index);
520 /* skip dummy bd_id 0 */
521 if (bd_config && (bd_config->bd_id > 0))
522 send_bridge_domain_details (l2im, reg, bd_config,
523 vec_len (bd_config->members),
529 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
531 vlib_main_t *vm = vlib_get_main ();
532 bd_main_t *bdm = &bd_main;
533 vl_api_bridge_flags_reply_t *rmp;
536 u32 flags = ntohl (mp->feature_bitmap);
537 u32 bd_id = ntohl (mp->bd_id);
540 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
544 u32 bd_index = bd_find_index (bdm, bd_id);
547 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
551 u32 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
555 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
557 rmp->resulting_feature_bitmap = ntohl(bitmap);
563 vl_api_l2_interface_vlan_tag_rewrite_t_handler
564 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
567 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
568 vnet_main_t *vnm = vnet_get_main ();
569 vlib_main_t *vm = vlib_get_main ();
572 VALIDATE_SW_IF_INDEX (mp);
574 vtr_op = ntohl (mp->vtr_op);
576 /* The L2 code is unsuspicious */
579 case L2_VTR_DISABLED:
584 case L2_VTR_TRANSLATE_1_1:
585 case L2_VTR_TRANSLATE_1_2:
586 case L2_VTR_TRANSLATE_2_1:
587 case L2_VTR_TRANSLATE_2_2:
591 rv = VNET_API_ERROR_INVALID_VALUE;
592 goto bad_sw_if_index;
595 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
596 ntohl (mp->push_dot1q), ntohl (mp->tag1),
599 BAD_SW_IF_INDEX_LABEL;
601 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
605 vl_api_l2_interface_pbb_tag_rewrite_t_handler
606 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
608 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
609 vnet_main_t *vnm = vnet_get_main ();
610 vlib_main_t *vm = vlib_get_main ();
614 VALIDATE_SW_IF_INDEX (mp);
616 vtr_op = ntohl (mp->vtr_op);
620 case L2_VTR_DISABLED:
623 case L2_VTR_TRANSLATE_2_1:
627 rv = VNET_API_ERROR_INVALID_VALUE;
628 goto bad_sw_if_index;
631 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
632 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
633 ntohl (mp->i_sid), ntohs (mp->outer_tag));
635 BAD_SW_IF_INDEX_LABEL;
637 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
641 vl_api_sw_interface_set_l2_xconnect_t_handler
642 (vl_api_sw_interface_set_l2_xconnect_t * mp)
644 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
646 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
647 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
648 vlib_main_t *vm = vlib_get_main ();
649 vnet_main_t *vnm = vnet_get_main ();
651 VALIDATE_RX_SW_IF_INDEX (mp);
655 VALIDATE_TX_SW_IF_INDEX (mp);
656 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
657 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
661 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
664 BAD_RX_SW_IF_INDEX_LABEL;
665 BAD_TX_SW_IF_INDEX_LABEL;
667 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
671 vl_api_sw_interface_set_l2_bridge_t_handler
672 (vl_api_sw_interface_set_l2_bridge_t * mp)
674 bd_main_t *bdm = &bd_main;
675 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
677 vlib_main_t *vm = vlib_get_main ();
678 vnet_main_t *vnm = vnet_get_main ();
680 VALIDATE_RX_SW_IF_INDEX (mp);
681 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
687 u32 bd_id = ntohl (mp->bd_id);
688 u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
691 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
692 rx_sw_if_index, bd_index, bvi, shg, 0);
696 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
699 BAD_RX_SW_IF_INDEX_LABEL;
702 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
706 send_bd_ip_mac_entry (vpe_api_main_t * am,
707 vl_api_registration_t * reg,
708 u32 bd_id, u8 is_ipv6,
709 u8 * ip_address, u8 * mac_address, u32 context)
711 vl_api_bd_ip_mac_details_t *mp;
713 mp = vl_msg_api_alloc (sizeof (*mp));
714 memset (mp, 0, sizeof (*mp));
715 mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
717 mp->bd_id = ntohl (bd_id);
719 clib_memcpy (mp->mac_address, mac_address, 6);
720 mp->is_ipv6 = is_ipv6;
721 clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
722 mp->context = context;
724 vl_api_send_msg (reg, (u8 *) mp);
728 vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
730 vpe_api_main_t *am = &vpe_api_main;
731 bd_main_t *bdm = &bd_main;
732 l2_bridge_domain_t *bd_config;
733 u32 bd_id = ntohl (mp->bd_id);
734 u32 bd_index, start, end;
735 vl_api_registration_t *reg;
738 reg = vl_api_client_index_to_registration (mp->client_index);
742 /* see bd_id: ~0 means "any" */
746 end = vec_len (l2input_main.bd_configs);
750 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
755 vec_validate (l2input_main.bd_configs, bd_index);
760 for (bd_index = start; bd_index < end; bd_index++)
762 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
763 if (bd_is_valid (bd_config))
765 ip4_address_t ip4_addr;
766 ip6_address_t *ip6_addr;
768 bd_id = bd_config->bd_id;
771 hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4,
773 send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context);
776 hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
778 send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context);
786 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
788 bd_main_t *bdm = &bd_main;
789 vl_api_bd_ip_mac_add_del_reply_t *rmp;
791 u32 bd_id = ntohl (mp->bd_id);
797 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
801 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
804 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
809 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
810 mp->mac_address, mp->is_ipv6, mp->is_add))
811 rv = VNET_API_ERROR_UNSPECIFIED;
814 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
817 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
818 u32 sw_if_index, u8 enable);
821 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
825 vl_api_l2_interface_efp_filter_reply_t *rmp;
826 vnet_main_t *vnm = vnet_get_main ();
828 VALIDATE_SW_IF_INDEX (mp);
830 // enable/disable the feature
831 l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
834 BAD_SW_IF_INDEX_LABEL;
835 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
839 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
841 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
843 vl_api_l2_patch_add_del_reply_t *rmp;
844 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
848 VALIDATE_RX_SW_IF_INDEX (mp);
849 VALIDATE_TX_SW_IF_INDEX (mp);
851 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
852 ntohl (mp->tx_sw_if_index),
853 (int) (mp->is_add != 0));
855 BAD_RX_SW_IF_INDEX_LABEL;
856 BAD_TX_SW_IF_INDEX_LABEL;
858 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
862 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
864 vl_api_sw_interface_set_vpath_reply_t *rmp;
866 u32 sw_if_index = ntohl (mp->sw_if_index);
868 VALIDATE_SW_IF_INDEX (mp);
870 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
871 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
872 sw_if_index, mp->enable, 0, 0);
873 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
874 sw_if_index, mp->enable, 0, 0);
875 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
876 sw_if_index, mp->enable, 0, 0);
877 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
878 sw_if_index, mp->enable, 0, 0);
880 BAD_SW_IF_INDEX_LABEL;
882 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
887 * Add vpe's API message handlers to the table.
888 * vlib has alread mapped shared memory and
889 * added the client registration handlers.
890 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
892 #define vl_msg_name_crc_list
893 #include <vnet/vnet_all_api_h.h>
894 #undef vl_msg_name_crc_list
897 setup_message_id_table (api_main_t * am)
899 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
900 foreach_vl_msg_name_crc_l2;
904 static clib_error_t *
905 l2_api_hookup (vlib_main_t * vm)
907 api_main_t *am = &api_main;
910 vl_msg_api_set_handlers(VL_API_##N, #n, \
911 vl_api_##n##_t_handler, \
913 vl_api_##n##_t_endian, \
914 vl_api_##n##_t_print, \
915 sizeof(vl_api_##n##_t), 1);
920 * Set up the (msg_name, crc, message-id) table
922 setup_message_id_table (am);
927 VLIB_API_INIT_FUNCTION (l2_api_hookup);
930 * fd.io coding-style-patch-verification: ON
933 * eval: (c-set-style "gnu")