2 *------------------------------------------------------------------
3 * interface_api.c - vnet interface 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/ethernet/ethernet.h>
26 #include <vnet/ip/ip.h>
27 #include <vnet/fib/fib_table.h>
28 #include <vnet/mfib/mfib_table.h>
29 #include <vnet/l2/l2_vtr.h>
30 #include <vnet/vnet_msg_enum.h>
31 #include <vnet/fib/fib_api.h>
32 #include <vnet/mfib/mfib_table.h>
34 #define vl_typedefs /* define message structures */
35 #include <vnet/vnet_all_api_h.h>
38 #define vl_endianfun /* define message structures */
39 #include <vnet/vnet_all_api_h.h>
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 #include <vnet/vnet_all_api_h.h>
48 #include <vlibapi/api_helper_macros.h>
49 vpe_api_main_t vpe_api_main;
51 #define foreach_vpe_api_msg \
52 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
53 _(SW_INTERFACE_SET_MTU, sw_interface_set_mtu) \
54 _(WANT_INTERFACE_EVENTS, want_interface_events) \
55 _(SW_INTERFACE_DUMP, sw_interface_dump) \
56 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
57 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
58 _(SW_INTERFACE_GET_TABLE, sw_interface_get_table) \
59 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
60 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
61 _(SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del) \
62 _(SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address)
65 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
67 vl_api_sw_interface_set_flags_reply_t *rmp;
68 vnet_main_t *vnm = vnet_get_main ();
73 VALIDATE_SW_IF_INDEX (mp);
75 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
77 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
81 clib_error_report (error);
84 BAD_SW_IF_INDEX_LABEL;
85 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
89 vl_api_sw_interface_set_mtu_t_handler (vl_api_sw_interface_set_mtu_t * mp)
91 vl_api_sw_interface_set_mtu_reply_t *rmp;
92 vnet_main_t *vnm = vnet_get_main ();
93 u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
94 u32 sw_if_index = ntohl (mp->sw_if_index);
95 u16 mtu = ntohs (mp->mtu);
96 ethernet_main_t *em = ðernet_main;
99 VALIDATE_SW_IF_INDEX (mp);
101 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, sw_if_index);
102 ethernet_interface_t *eif = ethernet_get_interface (em, sw_if_index);
106 rv = VNET_API_ERROR_FEATURE_DISABLED;
107 goto bad_sw_if_index;
110 if (mtu < hi->min_supported_packet_bytes)
112 rv = VNET_API_ERROR_INVALID_VALUE;
113 goto bad_sw_if_index;
116 if (mtu > hi->max_supported_packet_bytes)
118 rv = VNET_API_ERROR_INVALID_VALUE;
119 goto bad_sw_if_index;
122 if (hi->max_packet_bytes != mtu)
124 hi->max_packet_bytes = mtu;
125 ethernet_set_flags (vnm, sw_if_index, flags);
128 BAD_SW_IF_INDEX_LABEL;
129 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY);
133 send_sw_interface_details (vpe_api_main_t * am,
134 unix_shared_memory_queue_t * q,
135 vnet_sw_interface_t * swif,
136 u8 * interface_name, u32 context)
138 vnet_hw_interface_t *hi =
139 vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
141 vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
142 memset (mp, 0, sizeof (*mp));
143 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
144 mp->sw_if_index = ntohl (swif->sw_if_index);
145 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
146 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
147 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
148 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
149 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
150 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
151 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
152 mp->link_mtu = ntohs (hi->max_packet_bytes);
153 mp->context = context;
155 strncpy ((char *) mp->interface_name,
156 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
158 /* Send the L2 address for ethernet physical intfcs */
159 if (swif->sup_sw_if_index == swif->sw_if_index
160 && hi->hw_class_index == ethernet_hw_interface_class.index)
162 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
163 ethernet_interface_t *ei;
165 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
166 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
167 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
168 mp->l2_address_length = ntohl (sizeof (ei->address));
170 else if (swif->sup_sw_if_index != swif->sw_if_index)
172 vnet_sub_interface_t *sub = &swif->sub;
173 mp->sub_id = ntohl (sub->id);
174 mp->sub_dot1ad = sub->eth.flags.dot1ad;
175 mp->sub_number_of_tags =
176 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
177 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
178 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
179 mp->sub_exact_match = sub->eth.flags.exact_match;
180 mp->sub_default = sub->eth.flags.default_sub;
181 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
182 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
184 /* vlan tag rewrite data */
185 u32 vtr_op = L2_VTR_DISABLED;
186 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
188 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
189 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
191 // error - default to disabled
192 mp->vtr_op = ntohl (L2_VTR_DISABLED);
193 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
198 mp->vtr_op = ntohl (vtr_op);
199 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
200 mp->vtr_tag1 = ntohl (vtr_tag1);
201 mp->vtr_tag2 = ntohl (vtr_tag2);
205 /* pbb tag rewrite data */
206 ethernet_header_t eth_hdr;
207 u32 vtr_op = L2_VTR_DISABLED;
211 memset (ð_hdr, 0, sizeof (eth_hdr));
213 if (!l2pbb_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
214 &vtr_op, &outer_tag, ð_hdr, &b_vlanid, &i_sid))
217 clib_memcpy (mp->b_dmac, eth_hdr.dst_address,
218 sizeof (eth_hdr.dst_address));
219 clib_memcpy (mp->b_smac, eth_hdr.src_address,
220 sizeof (eth_hdr.src_address));
221 mp->b_vlanid = b_vlanid;
225 u8 *tag = vnet_get_sw_interface_tag (vnet_get_main (), swif->sw_if_index);
227 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
229 vl_msg_api_send_shmem (q, (u8 *) & mp);
233 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
235 vpe_api_main_t *am = &vpe_api_main;
236 vnet_sw_interface_t *swif;
237 vnet_interface_main_t *im = &am->vnet_main->interface_main;
239 unix_shared_memory_queue_t *q =
240 vl_api_client_index_to_input_queue (mp->client_index);
244 u8 *filter = 0, *name = 0;
245 if (mp->name_filter_valid)
247 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
248 filter = format (0, "%s%c", mp->name_filter, 0);
251 char *strcasestr (char *, char *); /* lnx hdr file botch */
253 pool_foreach (swif, im->sw_interfaces,
255 if (!vnet_swif_is_api_visible (swif))
257 vec_reset_length(name);
258 name = format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main,
261 if (filter && !strcasestr((char *) name, (char *) filter))
264 send_sw_interface_details (am, q, swif, name, mp->context);
273 vl_api_sw_interface_add_del_address_t_handler
274 (vl_api_sw_interface_add_del_address_t * mp)
276 vlib_main_t *vm = vlib_get_main ();
277 vl_api_sw_interface_add_del_address_reply_t *rmp;
281 VALIDATE_SW_IF_INDEX (mp);
283 is_del = mp->is_add == 0;
286 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
287 else if (mp->is_ipv6)
288 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
289 (void *) mp->address,
290 mp->address_length, is_del);
292 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
293 (void *) mp->address,
294 mp->address_length, is_del);
296 BAD_SW_IF_INDEX_LABEL;
298 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
301 void stats_dslock_with_hint (int hint, int tag) __attribute__ ((weak));
303 stats_dslock_with_hint (int hint, int tag)
307 void stats_dsunlock (void) __attribute__ ((weak));
309 stats_dsunlock (void)
314 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
317 u32 table_id = ntohl (mp->vrf_id);
318 u32 sw_if_index = ntohl (mp->sw_if_index);
319 vl_api_sw_interface_set_table_reply_t *rmp;
320 CLIB_UNUSED (ip_interface_address_t * ia);
323 VALIDATE_SW_IF_INDEX (mp);
325 stats_dslock_with_hint (1 /* release hint */ , 4 /* tag */ );
330 foreach_ip_interface_address (&ip6_main.lookup_main,
332 1 /* honor unnumbered */ ,
334 rv = VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE;
339 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
341 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
342 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
344 fib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
346 vec_validate (ip6_main.mfib_index_by_sw_if_index, sw_if_index);
347 ip6_main.mfib_index_by_sw_if_index[sw_if_index] = fib_index;
352 foreach_ip_interface_address (&ip4_main.lookup_main,
354 1 /* honor unnumbered */ ,
356 rv = VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE;
361 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
363 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
364 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
366 fib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
368 vec_validate (ip4_main.mfib_index_by_sw_if_index, sw_if_index);
369 ip4_main.mfib_index_by_sw_if_index[sw_if_index] = fib_index;
375 BAD_SW_IF_INDEX_LABEL;
377 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
381 send_sw_interface_get_table_reply (unix_shared_memory_queue_t * q,
382 u32 context, int retval, u32 vrf_id)
384 vl_api_sw_interface_get_table_reply_t *mp;
386 mp = vl_msg_api_alloc (sizeof (*mp));
387 memset (mp, 0, sizeof (*mp));
388 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_GET_TABLE_REPLY);
389 mp->context = context;
390 mp->retval = htonl (retval);
391 mp->vrf_id = htonl (vrf_id);
393 vl_msg_api_send_shmem (q, (u8 *) & mp);
397 vl_api_sw_interface_get_table_t_handler (vl_api_sw_interface_get_table_t * mp)
399 unix_shared_memory_queue_t *q;
400 fib_table_t *fib_table = 0;
401 u32 sw_if_index = ~0;
404 fib_protocol_t fib_proto = FIB_PROTOCOL_IP4;
407 q = vl_api_client_index_to_input_queue (mp->client_index);
411 VALIDATE_SW_IF_INDEX (mp);
413 sw_if_index = ntohl (mp->sw_if_index);
416 fib_proto = FIB_PROTOCOL_IP6;
418 fib_index = fib_table_get_index_for_sw_if_index (fib_proto, sw_if_index);
421 fib_table = fib_table_get (fib_index, fib_proto);
422 table_id = fib_table->ft_table_id;
425 BAD_SW_IF_INDEX_LABEL;
427 send_sw_interface_get_table_reply (q, mp->context, rv, table_id);
430 static void vl_api_sw_interface_set_unnumbered_t_handler
431 (vl_api_sw_interface_set_unnumbered_t * mp)
433 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
435 vnet_main_t *vnm = vnet_get_main ();
436 u32 sw_if_index = ntohl (mp->sw_if_index);
437 u32 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
441 * The API message field names are backwards from
442 * the underlying data structure names.
443 * It's not worth changing them now.
445 if (!vnet_sw_interface_is_api_valid (vnm, unnumbered_sw_if_index))
447 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
451 /* Only check the "use loop0" field when setting the binding */
452 if (mp->is_add && !vnet_sw_interface_is_api_valid (vnm, sw_if_index))
454 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
458 vnet_sw_interface_t *si =
459 vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
460 was_unnum = (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED);
464 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
465 si->unnumbered_sw_if_index = sw_if_index;
467 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
468 [unnumbered_sw_if_index] =
470 lookup_main.if_address_pool_index_by_sw_if_index[sw_if_index];
472 lookup_main.if_address_pool_index_by_sw_if_index
473 [unnumbered_sw_if_index] =
475 lookup_main.if_address_pool_index_by_sw_if_index[sw_if_index];
479 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
480 si->unnumbered_sw_if_index = (u32) ~ 0;
482 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
483 [unnumbered_sw_if_index] = ~0;
484 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
485 [unnumbered_sw_if_index] = ~0;
488 if (was_unnum != (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
490 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, mp->is_add);
491 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, mp->is_add);
495 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
499 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
502 vl_api_sw_interface_clear_stats_reply_t *rmp;
504 vnet_main_t *vnm = vnet_get_main ();
505 vnet_interface_main_t *im = &vnm->interface_main;
506 vlib_simple_counter_main_t *sm;
507 vlib_combined_counter_main_t *cm;
508 static vnet_main_t **my_vnet_mains;
509 int i, j, n_counters;
512 if (mp->sw_if_index != ~0)
513 VALIDATE_SW_IF_INDEX (mp);
515 vec_reset_length (my_vnet_mains);
517 for (i = 0; i < vec_len (vnet_mains); i++)
520 vec_add1 (my_vnet_mains, vnet_mains[i]);
523 if (vec_len (vnet_mains) == 0)
524 vec_add1 (my_vnet_mains, vnm);
526 n_counters = vec_len (im->combined_sw_if_counters);
528 for (j = 0; j < n_counters; j++)
530 for (i = 0; i < vec_len (my_vnet_mains); i++)
532 im = &my_vnet_mains[i]->interface_main;
533 cm = im->combined_sw_if_counters + j;
534 if (mp->sw_if_index == (u32) ~ 0)
535 vlib_clear_combined_counters (cm);
537 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
541 n_counters = vec_len (im->sw_if_counters);
543 for (j = 0; j < n_counters; j++)
545 for (i = 0; i < vec_len (my_vnet_mains); i++)
547 im = &my_vnet_mains[i]->interface_main;
548 sm = im->sw_if_counters + j;
549 if (mp->sw_if_index == (u32) ~ 0)
550 vlib_clear_simple_counters (sm);
552 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
556 BAD_SW_IF_INDEX_LABEL;
558 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
561 #define API_LINK_STATE_EVENT 1
562 #define API_ADMIN_UP_DOWN_EVENT 2
565 event_data_cmp (void *a1, void *a2)
570 return (word) e1[0] - (word) e2[0];
574 send_sw_interface_flags (vpe_api_main_t * am,
575 unix_shared_memory_queue_t * q,
576 vnet_sw_interface_t * swif)
578 vl_api_sw_interface_set_flags_t *mp;
579 vnet_main_t *vnm = am->vnet_main;
581 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
583 mp = vl_msg_api_alloc (sizeof (*mp));
584 memset (mp, 0, sizeof (*mp));
585 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
586 mp->sw_if_index = ntohl (swif->sw_if_index);
588 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
589 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
590 vl_msg_api_send_shmem (q, (u8 *) & mp);
594 link_state_process (vlib_main_t * vm,
595 vlib_node_runtime_t * rt, vlib_frame_t * f)
597 vpe_api_main_t *vam = &vpe_api_main;
598 vnet_main_t *vnm = vam->vnet_main;
599 vnet_sw_interface_t *swif;
600 uword *event_data = 0;
601 vpe_client_registration_t *reg;
603 u32 prev_sw_if_index;
604 unix_shared_memory_queue_t *q;
606 vam->link_state_process_up = 1;
610 vlib_process_wait_for_event (vm);
612 /* Unified list of changed link or admin state sw_if_indices */
613 vlib_process_get_events_with_type
614 (vm, &event_data, API_LINK_STATE_EVENT);
615 vlib_process_get_events_with_type
616 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
618 /* Sort, so we can eliminate duplicates */
619 vec_sort_with_function (event_data, event_data_cmp);
621 prev_sw_if_index = ~0;
623 for (i = 0; i < vec_len (event_data); i++)
625 /* Only one message per swif */
626 if (prev_sw_if_index == event_data[i])
628 prev_sw_if_index = event_data[i];
631 pool_foreach(reg, vam->interface_events_registrations,
633 q = vl_api_client_index_to_input_queue (reg->client_index);
636 /* sw_interface may be deleted already */
637 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
640 swif = vnet_get_sw_interface (vnm, event_data[i]);
641 send_sw_interface_flags (vam, q, swif);
647 vec_reset_length (event_data);
653 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
655 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
656 u32 hw_if_index, u32 flags);
659 VLIB_REGISTER_NODE (link_state_process_node,static) = {
660 .function = link_state_process,
661 .type = VLIB_NODE_TYPE_PROCESS,
662 .name = "vpe-link-state-process",
666 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
667 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
669 static clib_error_t *
670 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
672 vpe_api_main_t *vam = &vpe_api_main;
673 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
675 if (vam->link_state_process_up)
676 vlib_process_signal_event (vam->vlib_main,
677 link_state_process_node.index,
678 API_LINK_STATE_EVENT, hi->sw_if_index);
682 static clib_error_t *
683 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
685 vpe_api_main_t *vam = &vpe_api_main;
688 * Note: it's perfectly fair to set a subif admin up / admin down.
689 * Note the subtle distinction between this routine and the previous
692 if (vam->link_state_process_up)
693 vlib_process_signal_event (vam->vlib_main,
694 link_state_process_node.index,
695 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
699 static void vl_api_sw_interface_tag_add_del_t_handler
700 (vl_api_sw_interface_tag_add_del_t * mp)
702 vnet_main_t *vnm = vnet_get_main ();
703 vl_api_sw_interface_tag_add_del_reply_t *rmp;
706 u32 sw_if_index = ntohl (mp->sw_if_index);
708 VALIDATE_SW_IF_INDEX (mp);
714 rv = VNET_API_ERROR_INVALID_VALUE;
718 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
719 tag = format (0, "%s%c", mp->tag, 0);
720 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
723 vnet_clear_sw_interface_tag (vnm, sw_if_index);
725 BAD_SW_IF_INDEX_LABEL;
727 REPLY_MACRO (VL_API_SW_INTERFACE_TAG_ADD_DEL_REPLY);
730 static void vl_api_sw_interface_set_mac_address_t_handler
731 (vl_api_sw_interface_set_mac_address_t * mp)
733 vl_api_sw_interface_set_mac_address_reply_t *rmp;
734 vnet_main_t *vnm = vnet_get_main ();
735 u32 sw_if_index = ntohl (mp->sw_if_index);
740 VALIDATE_SW_IF_INDEX (mp);
742 mac = ((u64) mp->mac_address[0] << (8 * 0)
743 | (u64) mp->mac_address[1] << (8 * 1)
744 | (u64) mp->mac_address[2] << (8 * 2)
745 | (u64) mp->mac_address[3] << (8 * 3)
746 | (u64) mp->mac_address[4] << (8 * 4)
747 | (u64) mp->mac_address[5] << (8 * 5));
749 error = vnet_hw_interface_change_mac_address (vnm, sw_if_index, mac);
752 rv = VNET_API_ERROR_UNIMPLEMENTED;
753 clib_error_report (error);
757 BAD_SW_IF_INDEX_LABEL;
759 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MAC_ADDRESS_REPLY);
764 * Add vpe's API message handlers to the table.
765 * vlib has alread mapped shared memory and
766 * added the client registration handlers.
767 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
769 #define vl_msg_name_crc_list
770 #include <vnet/interface.api.h>
771 #undef vl_msg_name_crc_list
774 setup_message_id_table (api_main_t * am)
776 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
777 foreach_vl_msg_name_crc_interface;
781 pub_sub_handler (interface_events, INTERFACE_EVENTS);
783 static clib_error_t *
784 interface_api_hookup (vlib_main_t * vm)
786 api_main_t *am = &api_main;
789 vl_msg_api_set_handlers(VL_API_##N, #n, \
790 vl_api_##n##_t_handler, \
792 vl_api_##n##_t_endian, \
793 vl_api_##n##_t_print, \
794 sizeof(vl_api_##n##_t), 1);
799 * Set up the (msg_name, crc, message-id) table
801 setup_message_id_table (am);
806 VLIB_API_INIT_FUNCTION (interface_api_hookup);
809 * fd.io coding-style-patch-verification: ON
812 * eval: (c-set-style "gnu")