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/interface/rx_queue_funcs.h>
25 #include <vnet/api_errno.h>
26 #include <vnet/ethernet/ethernet.h>
27 #include <vnet/ip/ip.h>
28 #include <vnet/fib/fib_table.h>
29 #include <vnet/mfib/mfib_table.h>
30 #include <vnet/l2/l2_vtr.h>
31 #include <vnet/vnet_msg_enum.h>
32 #include <vnet/fib/fib_api.h>
33 #include <vnet/mfib/mfib_table.h>
35 #include <vlibapi/api_types.h>
37 #include <vnet/ip/ip_types_api.h>
38 #include <vnet/ethernet/ethernet_types_api.h>
40 #define vl_typedefs /* define message structures */
41 #include <vnet/vnet_all_api_h.h>
44 #define vl_endianfun /* define message structures */
45 #include <vnet/vnet_all_api_h.h>
48 /* instantiate all the print functions we know about */
49 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
51 #include <vnet/vnet_all_api_h.h>
54 #include <vlibapi/api_helper_macros.h>
55 vpe_api_main_t vpe_api_main;
57 #define foreach_vpe_api_msg \
58 _ (SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
59 _ (SW_INTERFACE_SET_PROMISC, sw_interface_set_promisc) \
60 _ (HW_INTERFACE_SET_MTU, hw_interface_set_mtu) \
61 _ (SW_INTERFACE_SET_MTU, sw_interface_set_mtu) \
62 _ (WANT_INTERFACE_EVENTS, want_interface_events) \
63 _ (SW_INTERFACE_DUMP, sw_interface_dump) \
64 _ (SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
65 _ (SW_INTERFACE_SET_RX_MODE, sw_interface_set_rx_mode) \
66 _ (SW_INTERFACE_RX_PLACEMENT_DUMP, sw_interface_rx_placement_dump) \
67 _ (SW_INTERFACE_SET_RX_PLACEMENT, sw_interface_set_rx_placement) \
68 _ (SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
69 _ (SW_INTERFACE_GET_TABLE, sw_interface_get_table) \
70 _ (SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
71 _ (SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
72 _ (SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del) \
73 _ (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, sw_interface_add_del_mac_address) \
74 _ (SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address) \
75 _ (SW_INTERFACE_GET_MAC_ADDRESS, sw_interface_get_mac_address) \
76 _ (CREATE_VLAN_SUBIF, create_vlan_subif) \
77 _ (CREATE_SUBIF, create_subif) \
78 _ (DELETE_SUBIF, delete_subif) \
79 _ (CREATE_LOOPBACK, create_loopback) \
80 _ (CREATE_LOOPBACK_INSTANCE, create_loopback_instance) \
81 _ (DELETE_LOOPBACK, delete_loopback) \
82 _ (INTERFACE_NAME_RENUMBER, interface_name_renumber) \
83 _ (COLLECT_DETAILED_INTERFACE_STATS, collect_detailed_interface_stats) \
84 _ (SW_INTERFACE_SET_IP_DIRECTED_BROADCAST, \
85 sw_interface_set_ip_directed_broadcast) \
86 _ (SW_INTERFACE_ADDRESS_REPLACE_BEGIN, sw_interface_address_replace_begin) \
87 _ (SW_INTERFACE_ADDRESS_REPLACE_END, sw_interface_address_replace_end)
90 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
92 vl_api_sw_interface_set_flags_reply_t *rmp;
93 vnet_main_t *vnm = vnet_get_main ();
98 VALIDATE_SW_IF_INDEX (mp);
101 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
102 VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
104 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
108 clib_error_report (error);
111 BAD_SW_IF_INDEX_LABEL;
112 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
116 vl_api_sw_interface_set_promisc_t_handler (
117 vl_api_sw_interface_set_promisc_t *mp)
119 vl_api_sw_interface_set_promisc_reply_t *rmp;
120 vnet_main_t *vnm = vnet_get_main ();
121 ethernet_main_t *em = ðernet_main;
123 ethernet_interface_t *eif;
124 vnet_sw_interface_t *swif;
125 u32 flags, sw_if_index;
127 VALIDATE_SW_IF_INDEX (mp);
129 sw_if_index = ntohl (mp->sw_if_index);
130 swif = vnet_get_sw_interface (vnm, sw_if_index);
131 eif = ethernet_get_interface (em, swif->hw_if_index);
134 rv = VNET_API_ERROR_INVALID_VALUE;
138 flags = mp->promisc_on ? ETHERNET_INTERFACE_FLAG_ACCEPT_ALL : 0;
139 rv = ethernet_set_flags (vnm, swif->hw_if_index, flags);
142 BAD_SW_IF_INDEX_LABEL;
143 REPLY_MACRO (VL_API_SW_INTERFACE_SET_PROMISC_REPLY);
147 vl_api_hw_interface_set_mtu_t_handler (vl_api_hw_interface_set_mtu_t * mp)
149 vl_api_hw_interface_set_mtu_reply_t *rmp;
150 vnet_main_t *vnm = vnet_get_main ();
151 u32 sw_if_index = ntohl (mp->sw_if_index);
152 u16 mtu = ntohs (mp->mtu);
153 ethernet_main_t *em = ðernet_main;
156 VALIDATE_SW_IF_INDEX (mp);
158 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
159 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
161 rv = VNET_API_ERROR_INVALID_VALUE;
162 goto bad_sw_if_index;
165 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, si->hw_if_index);
166 ethernet_interface_t *eif = ethernet_get_interface (em, si->hw_if_index);
170 rv = VNET_API_ERROR_FEATURE_DISABLED;
171 goto bad_sw_if_index;
174 if (mtu < hi->min_supported_packet_bytes)
176 rv = VNET_API_ERROR_INVALID_VALUE;
177 goto bad_sw_if_index;
180 if (mtu > hi->max_supported_packet_bytes)
182 rv = VNET_API_ERROR_INVALID_VALUE;
183 goto bad_sw_if_index;
186 vnet_hw_interface_set_mtu (vnm, si->hw_if_index, mtu);
188 BAD_SW_IF_INDEX_LABEL;
189 REPLY_MACRO (VL_API_HW_INTERFACE_SET_MTU_REPLY);
193 vl_api_sw_interface_set_mtu_t_handler (vl_api_sw_interface_set_mtu_t * mp)
195 vl_api_sw_interface_set_mtu_reply_t *rmp;
196 vnet_main_t *vnm = vnet_get_main ();
197 u32 sw_if_index = ntohl (mp->sw_if_index);
200 u32 per_protocol_mtu[VNET_N_MTU];
202 VALIDATE_SW_IF_INDEX (mp);
204 for (i = 0; i < VNET_N_MTU; i++)
206 per_protocol_mtu[i] = ntohl (mp->mtu[i]);
208 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, per_protocol_mtu);
210 BAD_SW_IF_INDEX_LABEL;
211 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY);
215 vl_api_sw_interface_set_ip_directed_broadcast_t_handler
216 (vl_api_sw_interface_set_ip_directed_broadcast_t * mp)
218 vl_api_sw_interface_set_ip_directed_broadcast_reply_t *rmp;
219 u32 sw_if_index = ntohl (mp->sw_if_index);
222 VALIDATE_SW_IF_INDEX (mp);
224 vnet_sw_interface_ip_directed_broadcast (vnet_get_main (),
225 sw_if_index, mp->enable);
227 BAD_SW_IF_INDEX_LABEL;
228 REPLY_MACRO (VL_API_SW_INTERFACE_SET_IP_DIRECTED_BROADCAST_REPLY);
232 send_sw_interface_details (vpe_api_main_t * am,
233 vl_api_registration_t * rp,
234 vnet_sw_interface_t * swif,
235 u8 * interface_name, u32 context)
237 vnet_hw_interface_t *hi =
238 vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
239 vnet_device_class_t *dev_class =
240 vnet_get_device_class (am->vnet_main, hi->dev_class_index);
242 vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
243 clib_memset (mp, 0, sizeof (*mp));
244 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
245 mp->sw_if_index = ntohl (swif->sw_if_index);
246 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
248 mp->flags |= (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
249 IF_STATUS_API_FLAG_ADMIN_UP : 0;
250 mp->flags |= (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
251 IF_STATUS_API_FLAG_LINK_UP : 0;
252 mp->flags = ntohl (mp->flags);
256 case VNET_SW_INTERFACE_TYPE_SUB:
257 mp->type = IF_API_TYPE_SUB;
259 case VNET_SW_INTERFACE_TYPE_P2P:
260 mp->type = IF_API_TYPE_P2P;
262 case VNET_SW_INTERFACE_TYPE_PIPE:
263 mp->type = IF_API_TYPE_PIPE;
266 mp->type = IF_API_TYPE_HARDWARE;
268 mp->type = ntohl (mp->type);
270 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
271 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
272 mp->link_speed = ntohl (hi->link_speed);
273 mp->link_mtu = ntohs (hi->max_packet_bytes);
274 mp->mtu[VNET_MTU_L3] = ntohl (swif->mtu[VNET_MTU_L3]);
275 mp->mtu[VNET_MTU_IP4] = ntohl (swif->mtu[VNET_MTU_IP4]);
276 mp->mtu[VNET_MTU_IP6] = ntohl (swif->mtu[VNET_MTU_IP6]);
277 mp->mtu[VNET_MTU_MPLS] = ntohl (swif->mtu[VNET_MTU_MPLS]);
279 mp->context = context;
281 strncpy ((char *) mp->interface_name,
282 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
284 if (dev_class && dev_class->name)
285 strncpy ((char *) mp->interface_dev_type, (char *) dev_class->name,
286 ARRAY_LEN (mp->interface_dev_type) - 1);
288 /* Send the L2 address for ethernet physical intfcs */
289 if (swif->sup_sw_if_index == swif->sw_if_index
290 && hi->hw_class_index == ethernet_hw_interface_class.index)
292 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
293 ethernet_interface_t *ei;
295 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
296 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address.mac));
297 mac_address_encode (&ei->address.mac, mp->l2_address);
299 else if (swif->sup_sw_if_index != swif->sw_if_index)
301 vnet_sub_interface_t *sub = &swif->sub;
302 mp->sub_id = ntohl (sub->id);
303 mp->sub_number_of_tags =
304 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
305 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
306 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
308 ntohl (sub->eth.raw_flags & SUB_IF_API_FLAG_MASK_VNET);
311 /* vlan tag rewrite data */
312 u32 vtr_op = L2_VTR_DISABLED;
313 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
315 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
316 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
318 // error - default to disabled
319 mp->vtr_op = ntohl (L2_VTR_DISABLED);
320 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
325 mp->vtr_op = ntohl (vtr_op);
326 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
327 mp->vtr_tag1 = ntohl (vtr_tag1);
328 mp->vtr_tag2 = ntohl (vtr_tag2);
331 /* pbb tag rewrite data */
332 ethernet_header_t eth_hdr;
333 u32 pbb_vtr_op = L2_VTR_DISABLED;
337 clib_memset (ð_hdr, 0, sizeof (eth_hdr));
339 if (!l2pbb_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
340 &pbb_vtr_op, &outer_tag, ð_hdr, &b_vlanid, &i_sid))
342 mp->sub_if_flags |= ntohl (SUB_IF_API_FLAG_DOT1AH);
343 mac_address_encode ((mac_address_t *) eth_hdr.dst_address, mp->b_dmac);
344 mac_address_encode ((mac_address_t *) eth_hdr.src_address, mp->b_smac);
345 mp->b_vlanid = b_vlanid;
349 u8 *tag = vnet_get_sw_interface_tag (vnet_get_main (), swif->sw_if_index);
351 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
353 vl_api_send_msg (rp, (u8 *) mp);
357 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
359 vpe_api_main_t *am = &vpe_api_main;
360 vnet_sw_interface_t *swif;
361 vnet_interface_main_t *im = &am->vnet_main->interface_main;
362 vl_api_registration_t *rp;
365 rp = vl_api_client_index_to_registration (mp->client_index);
369 clib_warning ("Client %d AWOL", mp->client_index);
373 u8 *filter = 0, *name = 0;
374 sw_if_index = ntohl (mp->sw_if_index);
376 if (!mp->name_filter_valid && sw_if_index != ~0 && sw_if_index != 0)
378 /* is it a valid sw_if_index? */
379 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
382 swif = vec_elt_at_index (im->sw_interfaces, sw_if_index);
384 vec_reset_length (name);
386 format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main,
388 send_sw_interface_details (am, rp, swif, name, mp->context);
393 if (mp->name_filter_valid)
395 filter = vl_api_from_api_to_new_vec (mp, &mp->name_filter);
396 vec_add1 (filter, 0); /* Ensure it's a C string for strcasecmp() */
399 char *strcasestr (char *, char *); /* lnx hdr file botch */
401 pool_foreach (swif, im->sw_interfaces)
403 if (!vnet_swif_is_api_visible (swif))
405 vec_reset_length(name);
406 name = format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main,
409 if (filter && !strcasestr((char *) name, (char *) filter))
412 send_sw_interface_details (am, rp, swif, name, mp->context);
421 vl_api_sw_interface_add_del_address_t_handler
422 (vl_api_sw_interface_add_del_address_t * mp)
424 vlib_main_t *vm = vlib_get_main ();
425 vnet_main_t *vnm = vnet_get_main ();
426 vl_api_sw_interface_add_del_address_reply_t *rmp;
429 clib_error_t *error = 0;
430 ip46_address_t address;
432 VALIDATE_SW_IF_INDEX (mp);
434 is_del = mp->is_add == 0;
438 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
439 else if (ip_address_decode (&mp->prefix.address, &address) == IP46_TYPE_IP6)
440 error = ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
441 (void *) &address.ip6,
442 mp->prefix.len, is_del);
444 error = ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
445 (void *) &address.ip4,
446 mp->prefix.len, is_del);
451 clib_error_report (error);
455 BAD_SW_IF_INDEX_LABEL;
458 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
462 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
464 vl_api_sw_interface_set_table_reply_t *rmp;
465 u32 sw_if_index = ntohl (mp->sw_if_index);
466 u32 table_id = ntohl (mp->vrf_id);
469 VALIDATE_SW_IF_INDEX (mp);
472 rv = ip_table_bind (FIB_PROTOCOL_IP6, sw_if_index, table_id, 1);
474 rv = ip_table_bind (FIB_PROTOCOL_IP4, sw_if_index, table_id, 1);
476 BAD_SW_IF_INDEX_LABEL;
478 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
482 ip_table_bind (fib_protocol_t fproto,
483 u32 sw_if_index, u32 table_id, u8 is_api)
485 CLIB_UNUSED (ip_interface_address_t * ia);
486 u32 fib_index, mfib_index;
492 src = FIB_SOURCE_API;
493 msrc = MFIB_SOURCE_API;
497 src = FIB_SOURCE_CLI;
498 msrc = MFIB_SOURCE_CLI;
502 * This if table does not exist = error is what we want in the end.
504 fib_index = fib_table_find (fproto, table_id);
505 mfib_index = mfib_table_find (fproto, table_id);
507 if (~0 == fib_index || ~0 == mfib_index)
509 return (VNET_API_ERROR_NO_SUCH_FIB);
512 if (FIB_PROTOCOL_IP6 == fproto)
515 * If the interface already has in IP address, then a change int
516 * VRF is not allowed. The IP address applied must first be removed.
517 * We do not do that automatically here, since VPP has no knowledge
518 * of whether those subnets are valid in the destination VRF.
521 foreach_ip_interface_address (&ip6_main.lookup_main,
523 1 /* honor unnumbered */ ,
525 return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE);
529 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
530 vec_validate (ip6_main.mfib_index_by_sw_if_index, sw_if_index);
533 * tell those that are interested that the binding is changing.
535 ip6_table_bind_callback_t *cb;
536 vec_foreach (cb, ip6_main.table_bind_callbacks)
537 cb->function (&ip6_main, cb->function_opaque,
540 ip6_main.fib_index_by_sw_if_index[sw_if_index]);
544 /* reset back to default */
545 if (0 != ip6_main.fib_index_by_sw_if_index[sw_if_index])
546 fib_table_unlock (ip6_main.fib_index_by_sw_if_index[sw_if_index],
547 FIB_PROTOCOL_IP6, src);
548 if (0 != ip6_main.mfib_index_by_sw_if_index[sw_if_index])
549 mfib_table_unlock (ip6_main.mfib_index_by_sw_if_index
550 [sw_if_index], FIB_PROTOCOL_IP6, msrc);
555 /* we need to lock the table now it's inuse */
556 fib_table_lock (fib_index, FIB_PROTOCOL_IP6, src);
557 mfib_table_lock (mfib_index, FIB_PROTOCOL_IP6, msrc);
560 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
561 ip6_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index;
566 * If the interface already has in IP address, then a change int
567 * VRF is not allowed. The IP address applied must first be removed.
568 * We do not do that automatically here, since VPP has no knowledge
569 * of whether those subnets are valid in the destination VRF.
572 foreach_ip_interface_address (&ip4_main.lookup_main,
574 1 /* honor unnumbered */ ,
576 return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE);
580 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
581 vec_validate (ip4_main.mfib_index_by_sw_if_index, sw_if_index);
584 * tell those that are interested that the binding is changing.
586 ip4_table_bind_callback_t *cb;
587 vec_foreach (cb, ip4_main.table_bind_callbacks)
588 cb->function (&ip4_main, cb->function_opaque,
591 ip4_main.fib_index_by_sw_if_index[sw_if_index]);
595 /* reset back to default */
596 if (0 != ip4_main.fib_index_by_sw_if_index[sw_if_index])
597 fib_table_unlock (ip4_main.fib_index_by_sw_if_index[sw_if_index],
598 FIB_PROTOCOL_IP4, src);
599 if (0 != ip4_main.mfib_index_by_sw_if_index[sw_if_index])
600 mfib_table_unlock (ip4_main.mfib_index_by_sw_if_index
601 [sw_if_index], FIB_PROTOCOL_IP4, msrc);
606 /* we need to lock the table now it's inuse */
607 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
610 mfib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
614 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
615 ip4_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index;
622 send_sw_interface_get_table_reply (vl_api_registration_t * reg,
623 u32 context, int retval, u32 vrf_id)
625 vl_api_sw_interface_get_table_reply_t *mp;
627 mp = vl_msg_api_alloc (sizeof (*mp));
628 clib_memset (mp, 0, sizeof (*mp));
629 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_GET_TABLE_REPLY);
630 mp->context = context;
631 mp->retval = htonl (retval);
632 mp->vrf_id = htonl (vrf_id);
634 vl_api_send_msg (reg, (u8 *) mp);
638 vl_api_sw_interface_get_table_t_handler (vl_api_sw_interface_get_table_t * mp)
640 vl_api_registration_t *reg;
641 fib_table_t *fib_table = 0;
642 u32 sw_if_index = ~0;
645 fib_protocol_t fib_proto = FIB_PROTOCOL_IP4;
648 reg = vl_api_client_index_to_registration (mp->client_index);
652 VALIDATE_SW_IF_INDEX (mp);
654 sw_if_index = ntohl (mp->sw_if_index);
657 fib_proto = FIB_PROTOCOL_IP6;
659 fib_index = fib_table_get_index_for_sw_if_index (fib_proto, sw_if_index);
662 fib_table = fib_table_get (fib_index, fib_proto);
663 table_id = fib_table->ft_table_id;
666 BAD_SW_IF_INDEX_LABEL;
668 send_sw_interface_get_table_reply (reg, mp->context, rv, table_id);
671 static void vl_api_sw_interface_set_unnumbered_t_handler
672 (vl_api_sw_interface_set_unnumbered_t * mp)
674 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
676 vnet_main_t *vnm = vnet_get_main ();
677 u32 sw_if_index = ntohl (mp->sw_if_index);
678 u32 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
681 * The API message field names are backwards from
682 * the underlying data structure names.
683 * It's not worth changing them now.
685 if (!vnet_sw_interface_is_api_valid (vnm, unnumbered_sw_if_index))
687 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
691 /* Only check the "use loop0" field when setting the binding */
692 if (mp->is_add && !vnet_sw_interface_is_api_valid (vnm, sw_if_index))
694 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
698 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
699 sw_if_index, mp->is_add);
701 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
705 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
708 vl_api_sw_interface_clear_stats_reply_t *rmp;
710 vnet_main_t *vnm = vnet_get_main ();
711 vnet_interface_main_t *im = &vnm->interface_main;
712 vlib_simple_counter_main_t *sm;
713 vlib_combined_counter_main_t *cm;
717 if (mp->sw_if_index != ~0)
718 VALIDATE_SW_IF_INDEX (mp);
720 n_counters = vec_len (im->combined_sw_if_counters);
722 for (j = 0; j < n_counters; j++)
724 im = &vnm->interface_main;
725 cm = im->combined_sw_if_counters + j;
726 if (mp->sw_if_index == (u32) ~ 0)
727 vlib_clear_combined_counters (cm);
729 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
732 n_counters = vec_len (im->sw_if_counters);
734 for (j = 0; j < n_counters; j++)
736 im = &vnm->interface_main;
737 sm = im->sw_if_counters + j;
738 if (mp->sw_if_index == (u32) ~ 0)
739 vlib_clear_simple_counters (sm);
741 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
744 BAD_SW_IF_INDEX_LABEL;
746 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
750 * Events used for sw_interface_events
754 API_LINK_STATE_UP_EVENT = 1 << 1,
755 API_LINK_STATE_DOWN_EVENT = 1 << 2,
756 API_ADMIN_UP_EVENT = 1 << 3,
757 API_ADMIN_DOWN_EVENT = 1 << 4,
758 API_SW_INTERFACE_ADD_EVENT = 1 << 5,
759 API_SW_INTERFACE_DEL_EVENT = 1 << 6,
763 send_sw_interface_event (vpe_api_main_t * am,
764 vpe_client_registration_t * reg,
765 vl_api_registration_t * vl_reg,
766 u32 sw_if_index, enum api_events events)
768 vl_api_sw_interface_event_t *mp;
770 mp = vl_msg_api_alloc (sizeof (*mp));
771 clib_memset (mp, 0, sizeof (*mp));
772 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_EVENT);
773 mp->sw_if_index = ntohl (sw_if_index);
774 mp->client_index = reg->client_index;
775 mp->pid = reg->client_pid;
777 mp->flags |= (events & API_ADMIN_UP_EVENT) ?
778 IF_STATUS_API_FLAG_ADMIN_UP : 0;
779 mp->flags |= (events & API_LINK_STATE_UP_EVENT) ?
780 IF_STATUS_API_FLAG_LINK_UP : 0;
781 mp->flags = ntohl (mp->flags);
782 mp->deleted = events & API_SW_INTERFACE_DEL_EVENT ? true : false;
783 vl_api_send_msg (vl_reg, (u8 *) mp);
787 link_state_process (vlib_main_t * vm,
788 vlib_node_runtime_t * rt, vlib_frame_t * f)
790 vpe_api_main_t *vam = &vpe_api_main;
791 uword *event_by_sw_if_index = 0;
792 vpe_client_registration_t *reg;
794 vl_api_registration_t *vl_reg;
796 uword *event_data = 0;
799 vam->link_state_process_up = 1;
803 vlib_process_wait_for_event (vm);
805 /* Batch up events */
806 while ((event_type = vlib_process_get_events (vm, &event_data)) != ~0)
808 for (i = 0; i < vec_len (event_data); i++)
810 sw_if_index = event_data[i];
811 vec_validate_init_empty (event_by_sw_if_index, sw_if_index, 0);
812 event_by_sw_if_index[sw_if_index] |= event_type;
814 vec_reset_length (event_data);
817 for (i = 0; i < vec_len (event_by_sw_if_index); i++)
819 if (event_by_sw_if_index[i] == 0)
823 pool_foreach (reg, vam->interface_events_registrations)
825 vl_reg = vl_api_client_index_to_registration (reg->client_index);
827 send_sw_interface_event (vam, reg, vl_reg, i, event_by_sw_if_index[i]);
831 vec_reset_length (event_by_sw_if_index);
837 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
839 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
840 u32 hw_if_index, u32 flags);
841 static clib_error_t *sw_interface_add_del_function (vnet_main_t * vm,
846 VLIB_REGISTER_NODE (link_state_process_node,static) = {
847 .function = link_state_process,
848 .type = VLIB_NODE_TYPE_PROCESS,
849 .name = "vpe-link-state-process",
853 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
854 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
855 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (sw_interface_add_del_function);
857 static clib_error_t *
858 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
860 vpe_api_main_t *vam = &vpe_api_main;
861 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
863 if (vam->link_state_process_up)
865 enum api_events event = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
866 API_LINK_STATE_UP_EVENT :
867 API_LINK_STATE_DOWN_EVENT);
868 vlib_process_signal_event (vam->vlib_main,
869 link_state_process_node.index, event,
875 static clib_error_t *
876 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
878 vpe_api_main_t *vam = &vpe_api_main;
881 * Note: it's perfectly fair to set a subif admin up / admin down.
882 * Note the subtle distinction between this routine and the previous
885 if (vam->link_state_process_up)
887 enum api_events event = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
888 API_ADMIN_UP_EVENT : API_ADMIN_DOWN_EVENT);
889 vlib_process_signal_event (vam->vlib_main,
890 link_state_process_node.index, event,
896 static clib_error_t *
897 sw_interface_add_del_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
899 vpe_api_main_t *vam = &vpe_api_main;
901 if (vam->link_state_process_up)
903 enum api_events event =
904 flags ? API_SW_INTERFACE_ADD_EVENT : API_SW_INTERFACE_DEL_EVENT;
905 vlib_process_signal_event (vam->vlib_main,
906 link_state_process_node.index, event,
912 static void vl_api_sw_interface_tag_add_del_t_handler
913 (vl_api_sw_interface_tag_add_del_t * mp)
915 vnet_main_t *vnm = vnet_get_main ();
916 vl_api_sw_interface_tag_add_del_reply_t *rmp;
919 u32 sw_if_index = ntohl (mp->sw_if_index);
921 VALIDATE_SW_IF_INDEX (mp);
927 rv = VNET_API_ERROR_INVALID_VALUE;
931 mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
932 tag = format (0, "%s%c", mp->tag, 0);
933 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
936 vnet_clear_sw_interface_tag (vnm, sw_if_index);
938 BAD_SW_IF_INDEX_LABEL;
940 REPLY_MACRO (VL_API_SW_INTERFACE_TAG_ADD_DEL_REPLY);
943 static void vl_api_sw_interface_add_del_mac_address_t_handler
944 (vl_api_sw_interface_add_del_mac_address_t * mp)
946 vl_api_sw_interface_add_del_mac_address_reply_t *rmp;
947 vnet_main_t *vnm = vnet_get_main ();
948 u32 sw_if_index = ntohl (mp->sw_if_index);
949 vnet_hw_interface_t *hi;
953 VALIDATE_SW_IF_INDEX (mp);
955 /* for subifs, the MAC should be changed on the actual hw if */
956 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
957 error = vnet_hw_interface_add_del_mac_address (vnm, hi->hw_if_index,
958 mp->addr, mp->is_add);
961 rv = VNET_API_ERROR_UNIMPLEMENTED;
962 clib_error_report (error);
966 BAD_SW_IF_INDEX_LABEL;
968 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY);
971 static void vl_api_sw_interface_set_mac_address_t_handler
972 (vl_api_sw_interface_set_mac_address_t * mp)
974 vl_api_sw_interface_set_mac_address_reply_t *rmp;
975 vnet_main_t *vnm = vnet_get_main ();
976 u32 sw_if_index = ntohl (mp->sw_if_index);
977 vnet_sw_interface_t *si;
982 VALIDATE_SW_IF_INDEX (mp);
984 si = vnet_get_sw_interface (vnm, sw_if_index);
985 mac_address_decode (mp->mac_address, &mac);
987 vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, (u8 *) & mac);
990 rv = VNET_API_ERROR_UNIMPLEMENTED;
991 clib_error_report (error);
995 BAD_SW_IF_INDEX_LABEL;
997 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MAC_ADDRESS_REPLY);
1000 static void vl_api_sw_interface_get_mac_address_t_handler
1001 (vl_api_sw_interface_get_mac_address_t * mp)
1003 vl_api_sw_interface_get_mac_address_reply_t *rmp;
1004 vl_api_registration_t *reg;
1005 vnet_main_t *vnm = vnet_get_main ();
1006 u32 sw_if_index = ntohl (mp->sw_if_index);
1007 vnet_sw_interface_t *si;
1008 ethernet_interface_t *eth_if = 0;
1011 VALIDATE_SW_IF_INDEX (mp);
1013 si = vnet_get_sup_sw_interface (vnm, sw_if_index);
1014 if (si->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
1015 eth_if = ethernet_get_interface (ðernet_main, si->hw_if_index);
1017 BAD_SW_IF_INDEX_LABEL;
1019 reg = vl_api_client_index_to_registration (mp->client_index);
1022 rmp = vl_msg_api_alloc (sizeof (*rmp));
1023 rmp->_vl_msg_id = htons (VL_API_SW_INTERFACE_GET_MAC_ADDRESS_REPLY);
1024 rmp->context = mp->context;
1025 rmp->retval = htonl (rv);
1027 mac_address_encode (ð_if->address.mac, rmp->mac_address);
1028 vl_api_send_msg (reg, (u8 *) rmp);
1031 static void vl_api_sw_interface_set_rx_mode_t_handler
1032 (vl_api_sw_interface_set_rx_mode_t * mp)
1034 vl_api_sw_interface_set_rx_mode_reply_t *rmp;
1035 vnet_main_t *vnm = vnet_get_main ();
1036 u32 sw_if_index = ntohl (mp->sw_if_index);
1037 vnet_sw_interface_t *si;
1038 clib_error_t *error;
1040 vnet_hw_if_rx_mode rx_mode;
1042 VALIDATE_SW_IF_INDEX (mp);
1044 si = vnet_get_sw_interface (vnm, sw_if_index);
1045 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
1047 rv = VNET_API_ERROR_INVALID_VALUE;
1048 goto bad_sw_if_index;
1051 rx_mode = (vnet_hw_if_rx_mode) ntohl (mp->mode);
1052 error = set_hw_interface_change_rx_mode (vnm, si->hw_if_index,
1054 ntohl (mp->queue_id),
1055 (vnet_hw_if_rx_mode) rx_mode);
1059 rv = VNET_API_ERROR_UNIMPLEMENTED;
1060 clib_error_report (error);
1064 BAD_SW_IF_INDEX_LABEL;
1066 REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_MODE_REPLY);
1070 send_interface_rx_placement_details (vpe_api_main_t * am,
1071 vl_api_registration_t * rp,
1072 u32 sw_if_index, u32 worker_id,
1073 u32 queue_id, u8 mode, u32 context)
1075 vl_api_sw_interface_rx_placement_details_t *mp;
1076 mp = vl_msg_api_alloc (sizeof (*mp));
1077 clib_memset (mp, 0, sizeof (*mp));
1079 mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_RX_PLACEMENT_DETAILS);
1080 mp->sw_if_index = htonl (sw_if_index);
1081 mp->queue_id = htonl (queue_id);
1082 mp->worker_id = htonl (worker_id);
1083 mp->mode = htonl (mode);
1084 mp->context = context;
1086 vl_api_send_msg (rp, (u8 *) mp);
1089 static void vl_api_sw_interface_rx_placement_dump_t_handler
1090 (vl_api_sw_interface_rx_placement_dump_t * mp)
1092 vnet_main_t *vnm = vnet_get_main ();
1093 vpe_api_main_t *am = &vpe_api_main;
1094 u32 sw_if_index = ntohl (mp->sw_if_index);
1095 vl_api_registration_t *reg;
1097 reg = vl_api_client_index_to_registration (mp->client_index);
1101 if (sw_if_index == ~0)
1103 vnet_hw_if_rx_queue_t **all_queues = 0;
1104 vnet_hw_if_rx_queue_t **qptr;
1105 vnet_hw_if_rx_queue_t *q;
1106 vec_foreach (q, vnm->interface_main.hw_if_rx_queues)
1107 vec_add1 (all_queues, q);
1108 vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api);
1110 vec_foreach (qptr, all_queues)
1112 u32 current_thread = qptr[0]->thread_index;
1113 u32 hw_if_index = qptr[0]->hw_if_index;
1114 vnet_hw_interface_t *hw_if =
1115 vnet_get_hw_interface (vnm, hw_if_index);
1116 send_interface_rx_placement_details (
1117 am, reg, hw_if->sw_if_index, current_thread, qptr[0]->queue_id,
1118 qptr[0]->mode, mp->context);
1120 vec_free (all_queues);
1125 vnet_sw_interface_t *si;
1127 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
1129 clib_warning ("sw_if_index %u does not exist", sw_if_index);
1130 goto bad_sw_if_index;
1133 si = vnet_get_sw_interface (vnm, sw_if_index);
1134 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
1136 clib_warning ("interface type is not HARDWARE! P2P, PIPE and SUB"
1137 " interfaces are not supported");
1138 goto bad_sw_if_index;
1141 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, si->hw_if_index);
1143 for (i = 0; i < vec_len (hw->rx_queue_indices); i++)
1145 vnet_hw_if_rx_queue_t *rxq =
1146 vnet_hw_if_get_rx_queue (vnm, hw->rx_queue_indices[i]);
1147 send_interface_rx_placement_details (
1148 am, reg, hw->sw_if_index, rxq->thread_index, rxq->queue_id,
1149 rxq->mode, mp->context);
1153 BAD_SW_IF_INDEX_LABEL;
1156 static void vl_api_sw_interface_set_rx_placement_t_handler
1157 (vl_api_sw_interface_set_rx_placement_t * mp)
1159 vl_api_sw_interface_set_rx_placement_reply_t *rmp;
1160 vnet_main_t *vnm = vnet_get_main ();
1161 u32 sw_if_index = ntohl (mp->sw_if_index);
1162 vnet_sw_interface_t *si;
1163 clib_error_t *error = 0;
1166 VALIDATE_SW_IF_INDEX (mp);
1168 si = vnet_get_sw_interface (vnm, sw_if_index);
1169 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
1171 rv = VNET_API_ERROR_INVALID_VALUE;
1172 goto bad_sw_if_index;
1175 error = set_hw_interface_rx_placement (si->hw_if_index,
1176 ntohl (mp->queue_id),
1177 ntohl (mp->worker_id), mp->is_main);
1180 rv = VNET_API_ERROR_UNIMPLEMENTED;
1181 clib_error_report (error);
1185 BAD_SW_IF_INDEX_LABEL;
1187 REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_PLACEMENT_REPLY);
1191 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1193 vl_api_create_vlan_subif_reply_t *rmp;
1194 vnet_main_t *vnm = vnet_get_main ();
1195 u32 sw_if_index = (u32) ~ 0;
1196 vnet_hw_interface_t *hi;
1199 vnet_sw_interface_t template;
1201 vnet_interface_main_t *im = &vnm->interface_main;
1202 u64 sup_and_sub_key;
1203 vl_api_registration_t *reg;
1204 clib_error_t *error;
1206 VALIDATE_SW_IF_INDEX (mp);
1208 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1210 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1212 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1216 id = ntohl (mp->vlan_id);
1217 if (id == 0 || id > 4095)
1219 rv = VNET_API_ERROR_INVALID_VLAN;
1223 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1225 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1228 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1232 clib_memset (&template, 0, sizeof (template));
1233 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1234 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
1235 template.sup_sw_if_index = hi->sw_if_index;
1236 template.sub.id = id;
1237 template.sub.eth.raw_flags = 0;
1238 template.sub.eth.flags.one_tag = 1;
1239 template.sub.eth.outer_vlan_id = id;
1240 template.sub.eth.flags.exact_match = 1;
1242 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1245 clib_error_report (error);
1246 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1250 u64 *kp = clib_mem_alloc (sizeof (*kp));
1251 *kp = sup_and_sub_key;
1253 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1254 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1256 BAD_SW_IF_INDEX_LABEL;
1259 reg = vl_api_client_index_to_registration (mp->client_index);
1263 rmp = vl_msg_api_alloc (sizeof (*rmp));
1264 rmp->_vl_msg_id = htons (VL_API_CREATE_VLAN_SUBIF_REPLY);
1265 rmp->context = mp->context;
1266 rmp->retval = htonl (rv);
1267 rmp->sw_if_index = htonl (sw_if_index);
1268 vl_api_send_msg (reg, (u8 *) rmp);
1272 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1274 vl_api_create_subif_reply_t *rmp;
1275 vnet_main_t *vnm = vnet_get_main ();
1276 u32 sub_sw_if_index = ~0;
1277 vnet_hw_interface_t *hi;
1280 VALIDATE_SW_IF_INDEX (mp);
1282 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1284 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1285 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1287 rv = vnet_create_sub_interface (ntohl (mp->sw_if_index),
1289 ntohl (mp->sub_if_flags),
1290 ntohs (mp->inner_vlan_id),
1291 ntohs (mp->outer_vlan_id),
1294 BAD_SW_IF_INDEX_LABEL;
1297 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1299 rmp->sw_if_index = ntohl(sub_sw_if_index);
1305 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
1307 vl_api_delete_subif_reply_t *rmp;
1310 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
1312 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
1316 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1319 vl_api_interface_name_renumber_reply_t *rmp;
1322 VALIDATE_SW_IF_INDEX (mp);
1324 rv = vnet_interface_name_renumber
1325 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1327 BAD_SW_IF_INDEX_LABEL;
1329 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1333 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1335 vl_api_create_loopback_reply_t *rmp;
1340 mac_address_decode (mp->mac_address, &mac);
1341 rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac, 0, 0);
1344 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1346 rmp->sw_if_index = ntohl (sw_if_index);
1351 static void vl_api_create_loopback_instance_t_handler
1352 (vl_api_create_loopback_instance_t * mp)
1354 vl_api_create_loopback_instance_reply_t *rmp;
1356 u8 is_specified = mp->is_specified;
1357 u32 user_instance = ntohl (mp->user_instance);
1361 mac_address_decode (mp->mac_address, &mac);
1362 rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac,
1363 is_specified, user_instance);
1366 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_INSTANCE_REPLY,
1368 rmp->sw_if_index = ntohl (sw_if_index);
1374 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1376 vl_api_delete_loopback_reply_t *rmp;
1380 sw_if_index = ntohl (mp->sw_if_index);
1381 rv = vnet_delete_loopback_interface (sw_if_index);
1383 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1387 vl_api_collect_detailed_interface_stats_t_handler
1388 (vl_api_collect_detailed_interface_stats_t * mp)
1390 vl_api_collect_detailed_interface_stats_reply_t *rmp;
1394 vnet_sw_interface_stats_collect_enable_disable (ntohl (mp->sw_if_index),
1395 mp->enable_disable);
1397 REPLY_MACRO (VL_API_COLLECT_DETAILED_INTERFACE_STATS_REPLY);
1401 vl_api_sw_interface_address_replace_begin_t_handler
1402 (vl_api_sw_interface_address_replace_begin_t * mp)
1404 vl_api_sw_interface_address_replace_begin_reply_t *rmp;
1407 ip_interface_address_mark ();
1409 REPLY_MACRO (VL_API_SW_INTERFACE_ADDRESS_REPLACE_BEGIN_REPLY);
1413 vl_api_sw_interface_address_replace_end_t_handler
1414 (vl_api_sw_interface_address_replace_end_t * mp)
1416 vl_api_sw_interface_address_replace_end_reply_t *rmp;
1419 ip_interface_address_sweep ();
1421 REPLY_MACRO (VL_API_SW_INTERFACE_ADDRESS_REPLACE_END_REPLY);
1426 * Add vpe's API message handlers to the table.
1427 * vlib has already mapped shared memory and
1428 * added the client registration handlers.
1429 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1431 #define vl_msg_name_crc_list
1432 #include <vnet/interface.api.h>
1433 #undef vl_msg_name_crc_list
1436 setup_message_id_table (api_main_t * am)
1438 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1439 foreach_vl_msg_name_crc_interface;
1443 pub_sub_handler (interface_events, INTERFACE_EVENTS);
1445 static clib_error_t *
1446 interface_api_hookup (vlib_main_t * vm)
1448 api_main_t *am = vlibapi_get_main ();
1451 vl_msg_api_set_handlers(VL_API_##N, #n, \
1452 vl_api_##n##_t_handler, \
1454 vl_api_##n##_t_endian, \
1455 vl_api_##n##_t_print, \
1456 sizeof(vl_api_##n##_t), 1);
1457 foreach_vpe_api_msg;
1460 /* Mark these APIs as mp safe */
1461 am->is_mp_safe[VL_API_SW_INTERFACE_DUMP] = 1;
1462 am->is_mp_safe[VL_API_SW_INTERFACE_DETAILS] = 1;
1463 am->is_mp_safe[VL_API_SW_INTERFACE_TAG_ADD_DEL] = 1;
1465 /* Do not replay VL_API_SW_INTERFACE_DUMP messages */
1466 am->api_trace_cfg[VL_API_SW_INTERFACE_DUMP].replay_enable = 0;
1469 * Set up the (msg_name, crc, message-id) table
1471 setup_message_id_table (am);
1476 VLIB_API_INIT_FUNCTION (interface_api_hookup);
1479 * fd.io coding-style-patch-verification: ON
1482 * eval: (c-set-style "gnu")