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>
31 #include <vnet/vnet_msg_enum.h>
33 #define vl_typedefs /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
37 #define vl_endianfun /* define message structures */
38 #include <vnet/vnet_all_api_h.h>
41 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
42 #define vl_api_bridge_domain_details_t_print vl_noop_handler
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
47 #include <vnet/vnet_all_api_h.h>
50 #include <vlibapi/api_helper_macros.h>
52 #define foreach_vpe_api_msg \
53 _(L2_XCONNECT_DUMP, l2_xconnect_dump) \
54 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
55 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
56 _(L2FIB_FLUSH_ALL, l2fib_flush_all) \
57 _(L2FIB_FLUSH_INT, l2fib_flush_int) \
58 _(L2FIB_FLUSH_BD, l2fib_flush_bd) \
59 _(L2FIB_ADD_DEL, l2fib_add_del) \
60 _(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
61 _(L2_FLAGS, l2_flags) \
62 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
63 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
64 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
65 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
66 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
67 _(BD_IP_MAC_DUMP, bd_ip_mac_dump) \
68 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
69 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
70 _(BRIDGE_FLAGS, bridge_flags) \
71 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
72 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
73 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
74 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath)
77 send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
78 u32 rx_sw_if_index, u32 tx_sw_if_index)
80 vl_api_l2_xconnect_details_t *mp;
82 mp = vl_msg_api_alloc (sizeof (*mp));
83 memset (mp, 0, sizeof (*mp));
84 mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
85 mp->context = context;
86 mp->rx_sw_if_index = htonl (rx_sw_if_index);
87 mp->tx_sw_if_index = htonl (tx_sw_if_index);
89 vl_api_send_msg (reg, (u8 *) mp);
93 vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
95 vl_api_registration_t *reg;
96 vnet_main_t *vnm = vnet_get_main ();
97 vnet_interface_main_t *im = &vnm->interface_main;
98 l2input_main_t *l2im = &l2input_main;
99 vnet_sw_interface_t *swif;
100 l2_input_config_t *config;
102 reg = vl_api_client_index_to_registration (mp->client_index);
107 pool_foreach (swif, im->sw_interfaces,
109 config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
110 if (config->xconnect)
111 send_l2_xconnect_details (reg, mp->context, swif->sw_if_index,
112 config->output_sw_if_index);
118 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
121 vl_api_l2_fib_clear_table_reply_t *rmp;
123 /* Clear all MACs including static MACs */
124 l2fib_clear_table ();
126 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
130 send_l2fib_table_entry (vpe_api_main_t * am,
131 vl_api_registration_t * reg,
132 l2fib_entry_key_t * l2fe_key,
133 l2fib_entry_result_t * l2fe_res, u32 context)
135 vl_api_l2_fib_table_details_t *mp;
137 mp = vl_msg_api_alloc (sizeof (*mp));
138 memset (mp, 0, sizeof (*mp));
139 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
142 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
144 clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
145 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
146 mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
147 mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
148 mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
149 mp->context = context;
151 vl_api_send_msg (reg, (u8 *) mp);
155 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
157 vpe_api_main_t *am = &vpe_api_main;
158 bd_main_t *bdm = &bd_main;
159 l2fib_entry_key_t *l2fe_key = NULL;
160 l2fib_entry_result_t *l2fe_res = NULL;
161 u32 ni, bd_id = ntohl (mp->bd_id);
163 vl_api_registration_t *reg;
166 reg = vl_api_client_index_to_registration (mp->client_index);
170 /* see l2fib_table_dump: ~0 means "any" */
175 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
182 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
184 vec_foreach_index (ni, l2fe_key)
186 send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
187 vec_elt_at_index (l2fe_res, ni), mp->context);
194 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
196 bd_main_t *bdm = &bd_main;
197 l2input_main_t *l2im = &l2input_main;
198 vl_api_l2fib_add_del_reply_t *rmp;
200 u32 bd_id = ntohl (mp->bd_id);
201 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
205 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
206 goto bad_sw_if_index;
212 clib_memcpy (mac, mp->mac, 6);
216 l2fib_add_filter_entry (mac, bd_index);
219 l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE;
220 u32 sw_if_index = ntohl (mp->sw_if_index);
221 VALIDATE_SW_IF_INDEX (mp);
222 if (vec_len (l2im->configs) <= sw_if_index)
224 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
225 goto bad_sw_if_index;
229 l2_input_config_t *config;
230 config = vec_elt_at_index (l2im->configs, sw_if_index);
231 if (config->bridge == 0)
233 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
234 goto bad_sw_if_index;
238 flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
240 flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
241 l2fib_add_entry (mac, bd_index, sw_if_index, flags);
246 u32 sw_if_index = ntohl (mp->sw_if_index);
247 if (l2fib_del_entry (mac, bd_index, sw_if_index))
248 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
251 BAD_SW_IF_INDEX_LABEL;
253 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
257 vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
260 vl_api_want_l2_macs_events_reply_t *rmp;
261 l2learn_main_t *lm = &l2learn_main;
262 l2fib_main_t *fm = &l2fib_main;
263 u32 pid = ntohl (mp->pid);
264 u32 learn_limit = ntohl (mp->learn_limit);
266 if (mp->enable_disable)
268 if (lm->client_pid == 0)
270 lm->client_pid = pid;
271 lm->client_index = mp->client_index;
273 if (mp->max_macs_in_event)
274 fm->max_macs_in_event = mp->max_macs_in_event * 10;
276 fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
279 fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
281 fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
283 /* change learn limit and flush all learned MACs */
284 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
285 lm->global_learn_limit = learn_limit;
287 lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
289 l2fib_flush_all_mac (vlib_get_main ());
291 else if (lm->client_pid != pid)
293 rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
297 else if (lm->client_pid)
300 lm->client_index = 0;
301 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
302 lm->global_learn_limit = learn_limit;
304 lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
308 REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
312 vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
315 vlib_main_t *vm = vlib_get_main ();
316 vl_api_l2fib_flush_int_reply_t *rmp;
318 VALIDATE_SW_IF_INDEX (mp);
320 u32 sw_if_index = ntohl (mp->sw_if_index);
321 l2fib_flush_int_mac (vm, sw_if_index);
323 BAD_SW_IF_INDEX_LABEL;
324 REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
328 vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
331 vl_api_l2fib_flush_all_reply_t *rmp;
333 l2fib_flush_all_mac (vlib_get_main ());
334 REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
338 vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
341 vlib_main_t *vm = vlib_get_main ();
342 bd_main_t *bdm = &bd_main;
343 vl_api_l2fib_flush_bd_reply_t *rmp;
345 u32 bd_id = ntohl (mp->bd_id);
346 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
349 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
352 l2fib_flush_bd_mac (vm, *p);
354 REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
358 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
360 vl_api_l2_flags_reply_t *rmp;
364 VALIDATE_SW_IF_INDEX (mp);
366 u32 sw_if_index = ntohl (mp->sw_if_index);
367 u32 flags = ntohl (mp->feature_bitmap);
370 if (flags & L2_LEARN)
371 bitmap |= L2INPUT_FEAT_LEARN;
374 bitmap |= L2INPUT_FEAT_FWD;
376 if (flags & L2_FLOOD)
377 bitmap |= L2INPUT_FEAT_FLOOD;
379 if (flags & L2_UU_FLOOD)
380 bitmap |= L2INPUT_FEAT_UU_FLOOD;
382 if (flags & L2_ARP_TERM)
383 bitmap |= L2INPUT_FEAT_ARP_TERM;
385 rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
387 BAD_SW_IF_INDEX_LABEL;
390 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
392 rmp->resulting_feature_bitmap = ntohl(rbm);
398 vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
401 vlib_main_t *vm = vlib_get_main ();
402 bd_main_t *bdm = &bd_main;
403 vl_api_bridge_domain_set_mac_age_reply_t *rmp;
405 u32 bd_id = ntohl (mp->bd_id);
410 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
414 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
417 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
420 bd_set_mac_age (vm, *p, mp->mac_age);
422 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
426 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
428 l2_bridge_domain_add_del_args_t a = {
429 .is_add = mp->is_add,
431 .uu_flood = mp->uu_flood,
432 .forward = mp->forward,
434 .arp_term = mp->arp_term,
435 .mac_age = mp->mac_age,
436 .bd_id = ntohl (mp->bd_id),
440 int rv = bd_add_del (&a);
442 vl_api_bridge_domain_add_del_reply_t *rmp;
443 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
447 send_bridge_domain_details (l2input_main_t * l2im,
448 vl_api_registration_t * reg,
449 l2_bridge_domain_t * bd_config,
450 u32 n_sw_ifs, u32 context)
452 vl_api_bridge_domain_details_t *mp;
453 l2_flood_member_t *m;
454 vl_api_bridge_domain_sw_if_t *sw_ifs;
455 l2_input_config_t *input_cfg;
457 mp = vl_msg_api_alloc (sizeof (*mp) +
458 (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
459 memset (mp, 0, sizeof (*mp));
460 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
461 mp->bd_id = ntohl (bd_config->bd_id);
462 mp->flood = bd_feature_flood (bd_config);
463 mp->uu_flood = bd_feature_uu_flood (bd_config);
464 mp->forward = bd_feature_forward (bd_config);
465 mp->learn = bd_feature_learn (bd_config);
466 mp->arp_term = bd_feature_arp_term (bd_config);
467 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
468 mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index);
469 mp->mac_age = bd_config->mac_age;
470 if (bd_config->bd_tag)
472 strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
473 ARRAY_LEN (mp->bd_tag) - 1);
474 mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
477 mp->context = context;
479 sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
480 vec_foreach (m, bd_config->members)
482 sw_ifs->sw_if_index = ntohl (m->sw_if_index);
483 input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
484 sw_ifs->shg = input_cfg->shg;
488 mp->n_sw_ifs = htonl (mp->n_sw_ifs);
490 vl_api_send_msg (reg, (u8 *) mp);
494 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
496 bd_main_t *bdm = &bd_main;
497 l2input_main_t *l2im = &l2input_main;
498 vl_api_registration_t *reg;
499 u32 bd_id, bd_index, end;
501 reg = vl_api_client_index_to_registration (mp->client_index);
505 bd_id = ntohl (mp->bd_id);
510 bd_index = 0, end = vec_len (l2im->bd_configs);
513 bd_index = bd_find_index (bdm, bd_id);
520 for (; bd_index < end; bd_index++)
522 l2_bridge_domain_t *bd_config =
523 l2input_bd_config_from_index (l2im, bd_index);
524 /* skip dummy bd_id 0 */
525 if (bd_config && (bd_config->bd_id > 0))
526 send_bridge_domain_details (l2im, reg, bd_config,
527 vec_len (bd_config->members),
533 bd_flags_decode (vl_api_bd_flags_t v)
535 bd_flags_t f = L2_NONE;
539 if (v & BRIDGE_API_FLAG_LEARN)
541 if (v & BRIDGE_API_FLAG_FWD)
543 if (v & BRIDGE_API_FLAG_FLOOD)
545 if (v & BRIDGE_API_FLAG_UU_FLOOD)
547 if (v & BRIDGE_API_FLAG_ARP_TERM)
554 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
556 vlib_main_t *vm = vlib_get_main ();
557 bd_main_t *bdm = &bd_main;
558 vl_api_bridge_flags_reply_t *rmp;
561 bd_flags_t flags = bd_flags_decode (mp->flags);
562 u32 bd_id = ntohl (mp->bd_id);
565 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
569 u32 bd_index = bd_find_index (bdm, bd_id);
572 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
576 u32 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
580 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
582 rmp->resulting_feature_bitmap = ntohl(bitmap);
588 vl_api_l2_interface_vlan_tag_rewrite_t_handler
589 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
592 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
593 vnet_main_t *vnm = vnet_get_main ();
594 vlib_main_t *vm = vlib_get_main ();
597 VALIDATE_SW_IF_INDEX (mp);
599 vtr_op = ntohl (mp->vtr_op);
601 /* The L2 code is unsuspicious */
604 case L2_VTR_DISABLED:
609 case L2_VTR_TRANSLATE_1_1:
610 case L2_VTR_TRANSLATE_1_2:
611 case L2_VTR_TRANSLATE_2_1:
612 case L2_VTR_TRANSLATE_2_2:
616 rv = VNET_API_ERROR_INVALID_VALUE;
617 goto bad_sw_if_index;
620 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
621 ntohl (mp->push_dot1q), ntohl (mp->tag1),
624 BAD_SW_IF_INDEX_LABEL;
626 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
630 vl_api_l2_interface_pbb_tag_rewrite_t_handler
631 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
633 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
634 vnet_main_t *vnm = vnet_get_main ();
635 vlib_main_t *vm = vlib_get_main ();
639 VALIDATE_SW_IF_INDEX (mp);
641 vtr_op = ntohl (mp->vtr_op);
645 case L2_VTR_DISABLED:
648 case L2_VTR_TRANSLATE_2_1:
652 rv = VNET_API_ERROR_INVALID_VALUE;
653 goto bad_sw_if_index;
656 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
657 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
658 ntohl (mp->i_sid), ntohs (mp->outer_tag));
660 BAD_SW_IF_INDEX_LABEL;
662 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
666 vl_api_sw_interface_set_l2_xconnect_t_handler
667 (vl_api_sw_interface_set_l2_xconnect_t * mp)
669 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
671 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
672 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
673 vlib_main_t *vm = vlib_get_main ();
674 vnet_main_t *vnm = vnet_get_main ();
676 VALIDATE_RX_SW_IF_INDEX (mp);
680 VALIDATE_TX_SW_IF_INDEX (mp);
681 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
683 L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index);
687 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0,
688 L2_BD_PORT_TYPE_NORMAL, 0, 0);
691 BAD_RX_SW_IF_INDEX_LABEL;
692 BAD_TX_SW_IF_INDEX_LABEL;
694 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
698 l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l)
700 v = clib_net_to_host_u32 (v);
704 case L2_API_PORT_TYPE_NORMAL:
705 *l = L2_BD_PORT_TYPE_NORMAL;
707 case L2_API_PORT_TYPE_BVI:
708 *l = L2_BD_PORT_TYPE_BVI;
710 case L2_API_PORT_TYPE_UU_FWD:
711 *l = L2_BD_PORT_TYPE_UU_FWD;
715 return (VNET_API_ERROR_INVALID_VALUE);
719 vl_api_sw_interface_set_l2_bridge_t_handler
720 (vl_api_sw_interface_set_l2_bridge_t * mp)
722 bd_main_t *bdm = &bd_main;
723 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
725 vlib_main_t *vm = vlib_get_main ();
726 vnet_main_t *vnm = vnet_get_main ();
727 l2_bd_port_type_t pt;
729 VALIDATE_RX_SW_IF_INDEX (mp);
730 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
731 rv = l2_bd_port_type_decode (mp->port_type, &pt);
738 u32 bd_id = ntohl (mp->bd_id);
739 u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
741 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
742 rx_sw_if_index, bd_index, pt, mp->shg, 0);
746 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
749 BAD_RX_SW_IF_INDEX_LABEL;
752 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
756 send_bd_ip_mac_entry (vpe_api_main_t * am,
757 vl_api_registration_t * reg,
758 u32 bd_id, u8 is_ipv6,
759 u8 * ip_address, u8 * mac_address, u32 context)
761 vl_api_bd_ip_mac_details_t *mp;
763 mp = vl_msg_api_alloc (sizeof (*mp));
764 memset (mp, 0, sizeof (*mp));
765 mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
767 mp->bd_id = ntohl (bd_id);
769 clib_memcpy (mp->mac_address, mac_address, 6);
770 mp->is_ipv6 = is_ipv6;
771 clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
772 mp->context = context;
774 vl_api_send_msg (reg, (u8 *) mp);
778 vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
780 vpe_api_main_t *am = &vpe_api_main;
781 bd_main_t *bdm = &bd_main;
782 l2_bridge_domain_t *bd_config;
783 u32 bd_id = ntohl (mp->bd_id);
784 u32 bd_index, start, end;
785 vl_api_registration_t *reg;
788 reg = vl_api_client_index_to_registration (mp->client_index);
792 /* see bd_id: ~0 means "any" */
796 end = vec_len (l2input_main.bd_configs);
800 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
805 vec_validate (l2input_main.bd_configs, bd_index);
810 for (bd_index = start; bd_index < end; bd_index++)
812 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
813 if (bd_is_valid (bd_config))
815 ip4_address_t ip4_addr;
816 ip6_address_t *ip6_addr;
818 bd_id = bd_config->bd_id;
821 hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4,
823 send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context);
826 hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
828 send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context);
836 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
838 bd_main_t *bdm = &bd_main;
839 vl_api_bd_ip_mac_add_del_reply_t *rmp;
841 u32 bd_id = ntohl (mp->bd_id);
847 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
851 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
854 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
859 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
860 mp->mac_address, mp->is_ipv6, mp->is_add))
861 rv = VNET_API_ERROR_UNSPECIFIED;
864 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
867 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
868 u32 sw_if_index, u8 enable);
871 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
875 vl_api_l2_interface_efp_filter_reply_t *rmp;
876 vnet_main_t *vnm = vnet_get_main ();
878 VALIDATE_SW_IF_INDEX (mp);
880 // enable/disable the feature
881 l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
884 BAD_SW_IF_INDEX_LABEL;
885 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
889 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
891 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
893 vl_api_l2_patch_add_del_reply_t *rmp;
894 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
898 VALIDATE_RX_SW_IF_INDEX (mp);
899 VALIDATE_TX_SW_IF_INDEX (mp);
901 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
902 ntohl (mp->tx_sw_if_index),
903 (int) (mp->is_add != 0));
905 BAD_RX_SW_IF_INDEX_LABEL;
906 BAD_TX_SW_IF_INDEX_LABEL;
908 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
912 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
914 vl_api_sw_interface_set_vpath_reply_t *rmp;
916 u32 sw_if_index = ntohl (mp->sw_if_index);
918 VALIDATE_SW_IF_INDEX (mp);
920 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
921 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
922 sw_if_index, mp->enable, 0, 0);
923 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
924 sw_if_index, mp->enable, 0, 0);
925 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
926 sw_if_index, mp->enable, 0, 0);
927 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
928 sw_if_index, mp->enable, 0, 0);
930 BAD_SW_IF_INDEX_LABEL;
932 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
937 * Add vpe's API message handlers to the table.
938 * vlib has already mapped shared memory and
939 * added the client registration handlers.
940 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
942 #define vl_msg_name_crc_list
943 #include <vnet/vnet_all_api_h.h>
944 #undef vl_msg_name_crc_list
947 setup_message_id_table (api_main_t * am)
949 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
950 foreach_vl_msg_name_crc_l2;
954 static clib_error_t *
955 l2_api_hookup (vlib_main_t * vm)
957 api_main_t *am = &api_main;
960 vl_msg_api_set_handlers(VL_API_##N, #n, \
961 vl_api_##n##_t_handler, \
963 vl_api_##n##_t_endian, \
964 vl_api_##n##_t_print, \
965 sizeof(vl_api_##n##_t), 1);
970 * Set up the (msg_name, crc, message-id) table
972 setup_message_id_table (am);
977 VLIB_API_INIT_FUNCTION (l2_api_hookup);
980 * fd.io coding-style-patch-verification: ON
983 * eval: (c-set-style "gnu")