2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010-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 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
48 #include <vnet/api_errno.h>
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/ip/ip.h>
53 #include <vnet/ip/ip6.h>
54 #include <vnet/ip/ip6_neighbor.h>
56 #include <vnet/srv6/sr.h>
58 #include <vlib/vlib.h>
59 #include <vlib/unix/unix.h>
60 #include <vlibapi/api.h>
61 #include <vlibmemory/api.h>
62 #include <vnet/classify/input_acl.h>
63 #include <vnet/l2/l2_classify.h>
64 #include <vnet/map/map.h>
65 #include <vnet/ip/ip6_hop_by_hop.h>
66 #include <vnet/ip/ip_source_and_port_range_check.h>
67 #include <vnet/ip/punt.h>
68 #include <vnet/feature/feature.h>
71 #undef __included_bihash_template_h__
72 #include <vnet/l2/l2_fib.h>
74 #include <vpp/stats/stats.h>
75 #include <vpp/oam/oam.h>
77 #include <vnet/ethernet/ethernet.h>
78 #include <vnet/ethernet/arp_packet.h>
79 #include <vnet/interface.h>
80 #include <vnet/l2/l2_fib.h>
81 #include <vnet/l2/l2_bd.h>
82 #include <vpp/api/vpe_msg_enum.h>
83 #include <vnet/span/span.h>
84 #include <vnet/fib/fib_api.h>
85 #include <vnet/dpo/drop_dpo.h>
86 #include <vnet/dpo/receive_dpo.h>
87 #include <vnet/dpo/lookup_dpo.h>
88 #include <vnet/dpo/classify_dpo.h>
89 #include <vnet/dpo/ip_null_dpo.h>
91 #define vl_typedefs /* define message structures */
92 #include <vpp/api/vpe_all_api_h.h>
94 #define vl_endianfun /* define message structures */
95 #include <vpp/api/vpe_all_api_h.h>
97 /* instantiate all the print functions we know about */
98 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
100 #include <vpp/api/vpe_all_api_h.h>
102 #include <vlibapi/api_helper_macros.h>
103 #define foreach_vpe_api_msg \
104 _(WANT_OAM_EVENTS, want_oam_events) \
105 _(OAM_ADD_DEL, oam_add_del) \
106 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
107 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
108 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
109 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
110 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
111 _(CREATE_SUBIF, create_subif) \
112 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
113 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
114 _(RESET_FIB, reset_fib) \
115 _(CREATE_LOOPBACK, create_loopback) \
116 _(CREATE_LOOPBACK_INSTANCE, create_loopback_instance) \
117 _(CONTROL_PING, control_ping) \
119 _(CLI_INBAND, cli_inband) \
120 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
121 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
122 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
123 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
124 _(GET_NODE_INDEX, get_node_index) \
125 _(ADD_NODE_NEXT, add_node_next) \
126 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
127 _(SHOW_VERSION, show_version) \
128 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
129 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
130 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
131 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
132 _(DELETE_LOOPBACK, delete_loopback) \
133 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
134 _(GET_NODE_GRAPH, get_node_graph) \
135 _(IOAM_ENABLE, ioam_enable) \
136 _(IOAM_DISABLE, ioam_disable) \
137 _(GET_NEXT_INDEX, get_next_index) \
138 _(PG_CREATE_INTERFACE, pg_create_interface) \
139 _(PG_CAPTURE, pg_capture) \
140 _(PG_ENABLE_DISABLE, pg_enable_disable) \
141 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
142 ip_source_and_port_range_check_add_del) \
143 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
144 ip_source_and_port_range_check_interface_add_del) \
145 _(DELETE_SUBIF, delete_subif) \
147 _(PUNT_SOCKET_REGISTER, punt_socket_register) \
148 _(PUNT_SOCKET_DEREGISTER, punt_socket_deregister) \
149 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
152 #define QUOTE(x) QUOTE_(x)
155 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
156 RESOLVE_IP6_ADD_DEL_ROUTE,
159 static vlib_node_registration_t vpe_resolver_process_node;
160 extern vpe_api_main_t vpe_api_main;
162 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
163 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
165 /* Clean up all registrations belonging to the indicated client */
166 static clib_error_t *
167 memclnt_delete_callback (u32 client_index)
169 vpe_api_main_t *vam = &vpe_api_main;
170 vpe_client_registration_t *rp;
172 int stats_memclnt_delete_callback (u32 client_index);
174 stats_memclnt_delete_callback (client_index);
177 p = hash_get (vam->a##_registration_hash, client_index); \
179 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
180 pool_put (vam->a##_registrations, rp); \
181 hash_unset (vam->a##_registration_hash, client_index); \
183 foreach_registration_hash;
188 VL_MSG_API_REAPER_FUNCTION (memclnt_delete_callback);
190 pub_sub_handler (oam_events, OAM_EVENTS);
192 #define RESOLUTION_EVENT 1
193 #define RESOLUTION_PENDING_EVENT 2
194 #define IP4_ARP_EVENT 3
195 #define IP6_ND_EVENT 4
197 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
199 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
202 handle_ip4_arp_event (u32 pool_index)
204 vpe_api_main_t *vam = &vpe_api_main;
205 vnet_main_t *vnm = vam->vnet_main;
206 vlib_main_t *vm = vam->vlib_main;
207 vl_api_ip4_arp_event_t *event;
208 vl_api_ip4_arp_event_t *mp;
209 unix_shared_memory_queue_t *q;
211 /* Client can cancel, die, etc. */
212 if (pool_is_free_index (vam->arp_events, pool_index))
215 event = pool_elt_at_index (vam->arp_events, pool_index);
217 q = vl_api_client_index_to_input_queue (event->client_index);
220 (void) vnet_add_del_ip4_arp_change_event
221 (vnm, arp_change_delete_callback,
222 event->pid, &event->address,
223 vpe_resolver_process_node.index, IP4_ARP_EVENT,
224 ~0 /* pool index, notused */ , 0 /* is_add */ );
228 if (q->cursize < q->maxsize)
230 mp = vl_msg_api_alloc (sizeof (*mp));
231 clib_memcpy (mp, event, sizeof (*mp));
232 vl_msg_api_send_shmem (q, (u8 *) & mp);
236 static f64 last_time;
238 * Throttle syslog msgs.
239 * It's pretty tempting to just revoke the registration...
241 if (vlib_time_now (vm) > last_time + 10.0)
243 clib_warning ("arp event for %U to pid %d: queue stuffed!",
244 format_ip4_address, &event->address, event->pid);
245 last_time = vlib_time_now (vm);
251 handle_ip6_nd_event (u32 pool_index)
253 vpe_api_main_t *vam = &vpe_api_main;
254 vnet_main_t *vnm = vam->vnet_main;
255 vlib_main_t *vm = vam->vlib_main;
256 vl_api_ip6_nd_event_t *event;
257 vl_api_ip6_nd_event_t *mp;
258 unix_shared_memory_queue_t *q;
260 /* Client can cancel, die, etc. */
261 if (pool_is_free_index (vam->nd_events, pool_index))
264 event = pool_elt_at_index (vam->nd_events, pool_index);
266 q = vl_api_client_index_to_input_queue (event->client_index);
269 (void) vnet_add_del_ip6_nd_change_event
270 (vnm, nd_change_delete_callback,
271 event->pid, &event->address,
272 vpe_resolver_process_node.index, IP6_ND_EVENT,
273 ~0 /* pool index, notused */ , 0 /* is_add */ );
277 if (q->cursize < q->maxsize)
279 mp = vl_msg_api_alloc (sizeof (*mp));
280 clib_memcpy (mp, event, sizeof (*mp));
281 vl_msg_api_send_shmem (q, (u8 *) & mp);
285 static f64 last_time;
287 * Throttle syslog msgs.
288 * It's pretty tempting to just revoke the registration...
290 if (vlib_time_now (vm) > last_time + 10.0)
292 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
293 format_ip6_address, &event->address, event->pid);
294 last_time = vlib_time_now (vm);
300 resolver_process (vlib_main_t * vm,
301 vlib_node_runtime_t * rt, vlib_frame_t * f)
303 volatile f64 timeout = 100.0;
304 volatile uword *event_data = 0;
308 vlib_process_wait_for_event_or_clock (vm, timeout);
311 vlib_process_get_events (vm, (uword **) & event_data);
316 case RESOLUTION_PENDING_EVENT:
320 case RESOLUTION_EVENT:
321 clib_warning ("resolver: BOGUS TYPE");
325 for (i = 0; i < vec_len (event_data); i++)
326 handle_ip4_arp_event (event_data[i]);
330 for (i = 0; i < vec_len (event_data); i++)
331 handle_ip6_nd_event (event_data[i]);
334 case ~0: /* timeout */
338 vec_reset_length (event_data);
340 return 0; /* or not */
344 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
345 .function = resolver_process,
346 .type = VLIB_NODE_TYPE_PROCESS,
347 .name = "vpe-route-resolver-process",
352 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
354 vl_api_sw_interface_set_vpath_reply_t *rmp;
356 u32 sw_if_index = ntohl (mp->sw_if_index);
358 VALIDATE_SW_IF_INDEX (mp);
360 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
361 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
362 sw_if_index, mp->enable, 0, 0);
363 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
364 sw_if_index, mp->enable, 0, 0);
365 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
366 sw_if_index, mp->enable, 0, 0);
367 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
368 sw_if_index, mp->enable, 0, 0);
370 BAD_SW_IF_INDEX_LABEL;
372 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
376 vl_api_sw_interface_set_l2_xconnect_t_handler
377 (vl_api_sw_interface_set_l2_xconnect_t * mp)
379 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
381 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
382 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
383 vlib_main_t *vm = vlib_get_main ();
384 vnet_main_t *vnm = vnet_get_main ();
386 VALIDATE_RX_SW_IF_INDEX (mp);
390 VALIDATE_TX_SW_IF_INDEX (mp);
391 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
392 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
396 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
399 BAD_RX_SW_IF_INDEX_LABEL;
400 BAD_TX_SW_IF_INDEX_LABEL;
402 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
406 vl_api_sw_interface_set_l2_bridge_t_handler
407 (vl_api_sw_interface_set_l2_bridge_t * mp)
409 bd_main_t *bdm = &bd_main;
410 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
412 vlib_main_t *vm = vlib_get_main ();
413 vnet_main_t *vnm = vnet_get_main ();
415 VALIDATE_RX_SW_IF_INDEX (mp);
416 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
422 u32 bd_id = ntohl (mp->bd_id);
423 u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
426 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
427 rx_sw_if_index, bd_index, bvi, shg, 0);
431 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
434 BAD_RX_SW_IF_INDEX_LABEL;
437 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
441 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
443 bd_main_t *bdm = &bd_main;
444 vl_api_bd_ip_mac_add_del_reply_t *rmp;
446 u32 bd_id = ntohl (mp->bd_id);
452 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
456 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
459 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
464 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
465 mp->mac_address, mp->is_ipv6, mp->is_add))
466 rv = VNET_API_ERROR_UNSPECIFIED;
469 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
473 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
475 vl_api_create_vlan_subif_reply_t *rmp;
476 vnet_main_t *vnm = vnet_get_main ();
477 u32 sw_if_index = (u32) ~ 0;
478 vnet_hw_interface_t *hi;
481 vnet_sw_interface_t template;
483 vnet_interface_main_t *im = &vnm->interface_main;
485 unix_shared_memory_queue_t *q;
488 VALIDATE_SW_IF_INDEX (mp);
490 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
492 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
494 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
498 id = ntohl (mp->vlan_id);
499 if (id == 0 || id > 4095)
501 rv = VNET_API_ERROR_INVALID_VLAN;
505 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
507 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
510 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
514 memset (&template, 0, sizeof (template));
515 template.type = VNET_SW_INTERFACE_TYPE_SUB;
516 template.sup_sw_if_index = hi->sw_if_index;
517 template.sub.id = id;
518 template.sub.eth.raw_flags = 0;
519 template.sub.eth.flags.one_tag = 1;
520 template.sub.eth.outer_vlan_id = id;
521 template.sub.eth.flags.exact_match = 1;
523 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
526 clib_error_report (error);
527 rv = VNET_API_ERROR_INVALID_REGISTRATION;
531 u64 *kp = clib_mem_alloc (sizeof (*kp));
532 *kp = sup_and_sub_key;
534 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
535 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
537 BAD_SW_IF_INDEX_LABEL;
540 q = vl_api_client_index_to_input_queue (mp->client_index);
544 rmp = vl_msg_api_alloc (sizeof (*rmp));
545 rmp->_vl_msg_id = htons (VL_API_CREATE_VLAN_SUBIF_REPLY);
546 rmp->context = mp->context;
547 rmp->retval = htonl (rv);
548 rmp->sw_if_index = htonl (sw_if_index);
549 vl_msg_api_send_shmem (q, (u8 *) & rmp);
553 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
555 vl_api_create_subif_reply_t *rmp;
556 vnet_main_t *vnm = vnet_get_main ();
557 u32 sw_if_index = ~0;
560 vnet_sw_interface_t *si;
561 vnet_hw_interface_t *hi;
562 vnet_sw_interface_t template;
564 vnet_interface_main_t *im = &vnm->interface_main;
568 VALIDATE_SW_IF_INDEX (mp);
570 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
571 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
573 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
575 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
579 sw_if_index = si->sw_if_index;
580 sub_id = ntohl (mp->sub_id);
582 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
584 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
588 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
589 sw_if_index, sub_id);
590 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
594 memset (&template, 0, sizeof (template));
595 template.type = VNET_SW_INTERFACE_TYPE_SUB;
596 template.sup_sw_if_index = sw_if_index;
597 template.sub.id = sub_id;
598 template.sub.eth.flags.no_tags = mp->no_tags;
599 template.sub.eth.flags.one_tag = mp->one_tag;
600 template.sub.eth.flags.two_tags = mp->two_tags;
601 template.sub.eth.flags.dot1ad = mp->dot1ad;
602 template.sub.eth.flags.exact_match = mp->exact_match;
603 template.sub.eth.flags.default_sub = mp->default_sub;
604 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
605 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
606 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
607 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
609 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
612 clib_error_report (error);
613 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
617 u64 *kp = clib_mem_alloc (sizeof (*kp));
618 *kp = sup_and_sub_key;
620 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
621 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
623 BAD_SW_IF_INDEX_LABEL;
628 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
630 rmp->sw_if_index = ntohl(sw_if_index);
636 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
638 vl_api_proxy_arp_add_del_reply_t *rmp;
641 ip4_main_t *im = &ip4_main;
642 stats_main_t *sm = &stats_main;
643 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
644 ip4_address_t * hi_addr,
645 u32 fib_index, int is_del);
648 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
650 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
654 rv = VNET_API_ERROR_NO_SUCH_FIB;
660 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
661 (ip4_address_t *) mp->hi_address,
662 fib_index, mp->is_add == 0);
666 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
670 vl_api_proxy_arp_intfc_enable_disable_t_handler
671 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
674 vnet_main_t *vnm = vnet_get_main ();
675 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
677 VALIDATE_SW_IF_INDEX (mp);
679 vnet_sw_interface_t *si =
680 vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
684 if (mp->enable_disable)
685 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
687 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
689 BAD_SW_IF_INDEX_LABEL;
691 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
695 vl_api_sw_interface_set_mpls_enable_t_handler
696 (vl_api_sw_interface_set_mpls_enable_t * mp)
698 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
701 VALIDATE_SW_IF_INDEX (mp);
703 rv = mpls_sw_interface_enable_disable (&mpls_main,
704 ntohl (mp->sw_if_index),
707 BAD_SW_IF_INDEX_LABEL;
708 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
712 send_oam_event (oam_target_t * t)
714 vpe_api_main_t *vam = &vpe_api_main;
715 unix_shared_memory_queue_t *q;
716 vpe_client_registration_t *reg;
717 vl_api_oam_event_t *mp;
720 pool_foreach(reg, vam->oam_events_registrations,
722 q = vl_api_client_index_to_input_queue (reg->client_index);
725 mp = vl_msg_api_alloc (sizeof (*mp));
726 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
727 clib_memcpy (mp->dst_address, &t->dst_address,
728 sizeof (mp->dst_address));
729 mp->state = t->state;
730 vl_msg_api_send_shmem (q, (u8 *)&mp);
737 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
739 vl_api_oam_add_del_reply_t *rmp;
742 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
743 (ip4_address_t *) mp->dst_address,
744 ntohl (mp->vrf_id), (int) (mp->is_add));
746 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
751 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
753 vnet_main_t *vnm = vnet_get_main ();
754 vnet_interface_main_t *im = &vnm->interface_main;
755 ip4_main_t *im4 = &ip4_main;
756 static u32 *sw_if_indices_to_shut;
757 stats_main_t *sm = &stats_main;
758 fib_table_t *fib_table;
762 int rv = VNET_API_ERROR_NO_SUCH_FIB;
763 u32 target_fib_id = ntohl (mp->vrf_id);
765 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
768 pool_foreach (fib_table, im4->fibs,
770 vnet_sw_interface_t * si;
772 fib = pool_elt_at_index (im4->v4_fibs, fib_table->ft_index);
774 if (fib->table_id != target_fib_id)
777 /* remove any mpls encap/decap labels */
778 mpls_fib_reset_labels (fib->table_id);
780 /* remove any proxy arps in this fib */
781 vnet_proxy_arp_fib_reset (fib->table_id);
783 /* Set the flow hash for this fib to the default */
784 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
786 vec_reset_length (sw_if_indices_to_shut);
788 /* Shut down interfaces in this FIB / clean out intfc routes */
789 pool_foreach (si, im->sw_interfaces,
791 u32 sw_if_index = si->sw_if_index;
793 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
794 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
796 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
799 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
800 sw_if_index = sw_if_indices_to_shut[i];
802 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
803 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
804 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
807 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
811 })); /* pool_foreach (fib) */
819 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
821 vnet_main_t *vnm = vnet_get_main ();
822 vnet_interface_main_t *im = &vnm->interface_main;
823 ip6_main_t *im6 = &ip6_main;
824 stats_main_t *sm = &stats_main;
825 static u32 *sw_if_indices_to_shut;
826 fib_table_t *fib_table;
830 int rv = VNET_API_ERROR_NO_SUCH_FIB;
831 u32 target_fib_id = ntohl (mp->vrf_id);
833 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
836 pool_foreach (fib_table, im6->fibs,
838 vnet_sw_interface_t * si;
840 fib = pool_elt_at_index (im6->v6_fibs, fib_table->ft_index);
842 if (fib->table_id != target_fib_id)
845 vec_reset_length (sw_if_indices_to_shut);
847 /* Set the flow hash for this fib to the default */
848 vnet_set_ip6_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
850 /* Shut down interfaces in this FIB / clean out intfc routes */
851 pool_foreach (si, im->sw_interfaces,
853 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
855 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
858 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
859 sw_if_index = sw_if_indices_to_shut[i];
861 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
862 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
863 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
866 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
870 })); /* pool_foreach (fib) */
878 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
881 vl_api_reset_fib_reply_t *rmp;
884 rv = ip6_reset_fib_t_handler (mp);
886 rv = ip4_reset_fib_t_handler (mp);
888 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
892 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
894 vl_api_create_loopback_reply_t *rmp;
898 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address, 0, 0);
901 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
903 rmp->sw_if_index = ntohl (sw_if_index);
908 static void vl_api_create_loopback_instance_t_handler
909 (vl_api_create_loopback_instance_t * mp)
911 vl_api_create_loopback_instance_reply_t *rmp;
913 u8 is_specified = mp->is_specified;
914 u32 user_instance = ntohl (mp->user_instance);
917 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address,
918 is_specified, user_instance);
921 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_INSTANCE_REPLY,
923 rmp->sw_if_index = ntohl (sw_if_index);
929 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
931 vl_api_delete_loopback_reply_t *rmp;
935 sw_if_index = ntohl (mp->sw_if_index);
936 rv = vnet_delete_loopback_interface (sw_if_index);
938 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
942 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
944 vl_api_control_ping_reply_t *rmp;
948 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
950 rmp->vpe_pid = ntohl (getpid());
956 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
958 u8 **shmem_vecp = (u8 **) arg;
961 api_main_t *am = &api_main;
964 shmem_vec = *shmem_vecp;
966 offset = vec_len (shmem_vec);
968 pthread_mutex_lock (&am->vlib_rp->mutex);
969 oldheap = svm_push_data_heap (am->vlib_rp);
971 vec_validate (shmem_vec, offset + buffer_bytes - 1);
973 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
975 svm_pop_heap (oldheap);
976 pthread_mutex_unlock (&am->vlib_rp->mutex);
978 *shmem_vecp = shmem_vec;
983 vl_api_cli_t_handler (vl_api_cli_t * mp)
985 vl_api_cli_reply_t *rp;
986 unix_shared_memory_queue_t *q;
987 vlib_main_t *vm = vlib_get_main ();
988 api_main_t *am = &api_main;
989 unformat_input_t input;
993 q = vl_api_client_index_to_input_queue (mp->client_index);
997 rp = vl_msg_api_alloc (sizeof (*rp));
998 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
999 rp->context = mp->context;
1001 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
1003 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
1005 pthread_mutex_lock (&am->vlib_rp->mutex);
1006 oldheap = svm_push_data_heap (am->vlib_rp);
1008 vec_add1 (shmem_vec, 0);
1010 svm_pop_heap (oldheap);
1011 pthread_mutex_unlock (&am->vlib_rp->mutex);
1013 rp->reply_in_shmem = (uword) shmem_vec;
1015 vl_msg_api_send_shmem (q, (u8 *) & rp);
1019 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1021 u8 **mem_vecp = (u8 **) arg;
1022 u8 *mem_vec = *mem_vecp;
1023 u32 offset = vec_len (mem_vec);
1025 vec_validate (mem_vec, offset + buffer_bytes - 1);
1026 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
1027 *mem_vecp = mem_vec;
1031 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
1033 vl_api_cli_inband_reply_t *rmp;
1035 vlib_main_t *vm = vlib_get_main ();
1036 unformat_input_t input;
1039 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
1040 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
1042 u32 len = vec_len (out_vec);
1044 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
1046 rmp->length = htonl (len);
1047 clib_memcpy (rmp->reply, out_vec, len);
1054 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
1057 vl_api_set_arp_neighbor_limit_reply_t *rmp;
1058 vnet_main_t *vnm = vnet_get_main ();
1059 clib_error_t *error;
1064 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
1066 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
1070 clib_error_report (error);
1071 rv = VNET_API_ERROR_UNSPECIFIED;
1075 rv = vnm->api_errno;
1078 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
1081 static void vl_api_classify_set_interface_ip_table_t_handler
1082 (vl_api_classify_set_interface_ip_table_t * mp)
1084 vlib_main_t *vm = vlib_get_main ();
1085 vl_api_classify_set_interface_ip_table_reply_t *rmp;
1088 VALIDATE_SW_IF_INDEX (mp);
1090 u32 table_index = ntohl (mp->table_index);
1091 u32 sw_if_index = ntohl (mp->sw_if_index);
1094 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
1096 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
1098 BAD_SW_IF_INDEX_LABEL;
1100 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
1103 static void vl_api_classify_set_interface_l2_tables_t_handler
1104 (vl_api_classify_set_interface_l2_tables_t * mp)
1106 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
1108 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
1111 ip4_table_index = ntohl (mp->ip4_table_index);
1112 ip6_table_index = ntohl (mp->ip6_table_index);
1113 other_table_index = ntohl (mp->other_table_index);
1114 sw_if_index = ntohl (mp->sw_if_index);
1116 VALIDATE_SW_IF_INDEX (mp);
1119 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
1123 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
1129 if (ip4_table_index != ~0 || ip6_table_index != ~0
1130 || other_table_index != ~0)
1136 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
1138 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
1141 BAD_SW_IF_INDEX_LABEL;
1143 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
1146 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1147 u32 sw_if_index, u32 enable);
1150 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1154 vl_api_l2_interface_efp_filter_reply_t *rmp;
1155 vnet_main_t *vnm = vnet_get_main ();
1157 // enable/disable the feature
1158 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
1159 rv = vnm->api_errno;
1161 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1165 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
1167 vl_api_show_version_reply_t *rmp;
1169 char *vpe_api_get_build_directory (void);
1170 char *vpe_api_get_version (void);
1171 char *vpe_api_get_build_date (void);
1174 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
1176 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
1177 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
1178 ARRAY_LEN(rmp->build_directory)-1);
1179 strncpy ((char *) rmp->version, vpe_api_get_version(),
1180 ARRAY_LEN(rmp->version)-1);
1181 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
1182 ARRAY_LEN(rmp->build_date)-1);
1188 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
1190 vlib_main_t *vm = vlib_get_main ();
1191 vl_api_get_node_index_reply_t *rmp;
1194 u32 node_index = ~0;
1196 n = vlib_get_node_by_name (vm, mp->node_name);
1199 rv = VNET_API_ERROR_NO_SUCH_NODE;
1201 node_index = n->index;
1204 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1206 rmp->node_index = ntohl(node_index);
1212 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
1214 vlib_main_t *vm = vlib_get_main ();
1215 vl_api_get_next_index_reply_t *rmp;
1216 vlib_node_t *node, *next_node;
1218 u32 next_node_index = ~0, next_index = ~0;
1221 node = vlib_get_node_by_name (vm, mp->node_name);
1225 rv = VNET_API_ERROR_NO_SUCH_NODE;
1229 next_node = vlib_get_node_by_name (vm, mp->next_name);
1233 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1237 next_node_index = next_node->index;
1239 p = hash_get (node->next_slot_by_node, next_node_index);
1243 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1251 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
1253 rmp->next_index = ntohl(next_index);
1259 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
1261 vlib_main_t *vm = vlib_get_main ();
1262 vl_api_add_node_next_reply_t *rmp;
1263 vlib_node_t *n, *next;
1265 u32 next_index = ~0;
1267 n = vlib_get_node_by_name (vm, mp->node_name);
1271 rv = VNET_API_ERROR_NO_SUCH_NODE;
1275 next = vlib_get_node_by_name (vm, mp->next_name);
1278 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1280 next_index = vlib_node_add_next (vm, n->index, next->index);
1284 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1286 rmp->next_index = ntohl(next_index);
1292 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1294 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1296 vl_api_l2_patch_add_del_reply_t *rmp;
1297 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1301 VALIDATE_RX_SW_IF_INDEX (mp);
1302 VALIDATE_TX_SW_IF_INDEX (mp);
1304 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1305 ntohl (mp->tx_sw_if_index),
1306 (int) (mp->is_add != 0));
1308 BAD_RX_SW_IF_INDEX_LABEL;
1309 BAD_TX_SW_IF_INDEX_LABEL;
1311 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1315 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1318 vl_api_interface_name_renumber_reply_t *rmp;
1321 VALIDATE_SW_IF_INDEX (mp);
1323 rv = vnet_interface_name_renumber
1324 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1326 BAD_SW_IF_INDEX_LABEL;
1328 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1332 arp_change_data_callback (u32 pool_index, u8 * new_mac,
1333 u32 sw_if_index, u32 address)
1335 vpe_api_main_t *am = &vpe_api_main;
1336 vlib_main_t *vm = am->vlib_main;
1337 vl_api_ip4_arp_event_t *event;
1339 if (pool_is_free_index (am->arp_events, pool_index))
1342 event = pool_elt_at_index (am->arp_events, pool_index);
1343 if (eth_mac_equal (event->new_mac, new_mac) &&
1344 sw_if_index == ntohl (event->sw_if_index))
1349 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1350 event->sw_if_index = htonl (sw_if_index);
1355 nd_change_data_callback (u32 pool_index, u8 * new_mac,
1356 u32 sw_if_index, ip6_address_t * address)
1358 vpe_api_main_t *am = &vpe_api_main;
1359 vlib_main_t *vm = am->vlib_main;
1360 vl_api_ip6_nd_event_t *event;
1362 if (pool_is_free_index (am->nd_events, pool_index))
1365 event = pool_elt_at_index (am->nd_events, pool_index);
1366 if (eth_mac_equal (event->new_mac, new_mac) &&
1367 sw_if_index == ntohl (event->sw_if_index))
1372 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1373 event->sw_if_index = htonl (sw_if_index);
1378 arp_change_delete_callback (u32 pool_index, u8 * notused)
1380 vpe_api_main_t *am = &vpe_api_main;
1382 if (pool_is_free_index (am->arp_events, pool_index))
1385 pool_put_index (am->arp_events, pool_index);
1390 nd_change_delete_callback (u32 pool_index, u8 * notused)
1392 vpe_api_main_t *am = &vpe_api_main;
1394 if (pool_is_free_index (am->nd_events, pool_index))
1397 pool_put_index (am->nd_events, pool_index);
1401 static vlib_node_registration_t wc_arp_process_node;
1404 { WC_ARP_REPORT, WC_ND_REPORT };
1407 wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
1409 /* These cross the longjmp boundry (vlib_process_wait_for_event)
1410 * and need to be volatile - to prevent them from being optimized into
1411 * a register - which could change during suspension */
1413 volatile wc_arp_report_t arp_prev = { 0 };
1414 volatile wc_nd_report_t nd_prev = { 0 };
1415 volatile f64 last_arp = vlib_time_now (vm);
1416 volatile f64 last_nd = vlib_time_now (vm);
1420 vlib_process_wait_for_event (vm);
1422 void *event_data = vlib_process_get_event_data (vm, &event_type);
1424 f64 now = vlib_time_now (vm);
1426 if (event_type == WC_ARP_REPORT)
1428 wc_arp_report_t *arp_events = event_data;
1429 for (i = 0; i < vec_len (arp_events); i++)
1431 /* discard dup event */
1432 if (arp_prev.ip4 == arp_events[i].ip4 &&
1433 eth_mac_equal ((u8 *) arp_prev.mac, arp_events[i].mac) &&
1434 arp_prev.sw_if_index == arp_events[i].sw_if_index &&
1435 (now - last_arp) < 10.0)
1439 arp_prev = arp_events[i];
1441 vpe_client_registration_t *reg;
1443 pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations,
1445 unix_shared_memory_queue_t *q;
1446 q = vl_api_client_index_to_input_queue (reg->client_index);
1447 if (q && q->cursize < q->maxsize)
1449 vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event);
1450 memset (event, 0, sizeof *event);
1451 event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
1452 event->client_index = reg->client_index;
1453 event->pid = reg->client_pid;
1455 event->address = arp_events[i].ip4;
1456 event->sw_if_index = htonl(arp_events[i].sw_if_index);
1457 memcpy(event->new_mac, arp_events[i].mac, sizeof event->new_mac);
1458 vl_msg_api_send_shmem (q, (u8 *) &event);
1464 else if (event_type == WC_ND_REPORT)
1466 wc_nd_report_t *nd_events = event_data;
1467 for (i = 0; i < vec_len (nd_events); i++)
1469 /* discard dup event */
1470 if (ip6_address_is_equal
1471 ((ip6_address_t *) & nd_prev.ip6, &nd_events[i].ip6)
1472 && eth_mac_equal ((u8 *) nd_prev.mac, nd_events[i].mac)
1473 && nd_prev.sw_if_index == nd_events[i].sw_if_index
1474 && (now - last_nd) < 10.0)
1478 nd_prev = nd_events[i];
1480 vpe_client_registration_t *reg;
1482 pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations,
1484 unix_shared_memory_queue_t *q;
1485 q = vl_api_client_index_to_input_queue (reg->client_index);
1486 if (q && q->cursize < q->maxsize)
1488 vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event);
1489 memset (event, 0, sizeof *event);
1490 event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT);
1491 event->client_index = reg->client_index;
1492 event->pid = reg->client_pid;
1494 memcpy(event->address, nd_events[i].ip6.as_u8, sizeof event->address);
1495 event->sw_if_index = htonl(nd_events[i].sw_if_index);
1496 memcpy(event->new_mac, nd_events[i].mac, sizeof event->new_mac);
1497 vl_msg_api_send_shmem (q, (u8 *) &event);
1503 vlib_process_put_event_data (vm, event_data);
1510 VLIB_REGISTER_NODE (wc_arp_process_node,static) = {
1511 .function = wc_arp_process,
1512 .type = VLIB_NODE_TYPE_PROCESS,
1513 .name = "wildcard-ip4-arp-publisher-process",
1518 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
1520 vpe_api_main_t *am = &vpe_api_main;
1521 vnet_main_t *vnm = vnet_get_main ();
1522 vl_api_want_ip4_arp_events_reply_t *rmp;
1525 if (mp->address == 0)
1528 hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index);
1529 vpe_client_registration_t *rp;
1532 if (mp->enable_disable)
1534 clib_warning ("pid %d: already enabled...", mp->pid);
1535 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1541 pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]);
1542 pool_put (am->wc_ip4_arp_events_registrations, rp);
1543 hash_unset (am->wc_ip4_arp_events_registration_hash,
1545 if (pool_elts (am->wc_ip4_arp_events_registrations) == 0)
1546 wc_arp_set_publisher_node (~0, WC_ARP_REPORT);
1550 if (mp->enable_disable == 0)
1552 clib_warning ("pid %d: already disabled...", mp->pid);
1553 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1556 pool_get (am->wc_ip4_arp_events_registrations, rp);
1557 rp->client_index = mp->client_index;
1558 rp->client_pid = mp->pid;
1559 hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index,
1560 rp - am->wc_ip4_arp_events_registrations);
1561 wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT);
1565 if (mp->enable_disable)
1567 vl_api_ip4_arp_event_t *event;
1568 pool_get (am->arp_events, event);
1569 rv = vnet_add_del_ip4_arp_change_event
1570 (vnm, arp_change_data_callback,
1571 mp->pid, &mp->address /* addr, in net byte order */ ,
1572 vpe_resolver_process_node.index,
1573 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
1577 pool_put (am->arp_events, event);
1580 memset (event, 0, sizeof (*event));
1582 /* Python API expects events to have no context */
1583 event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT);
1584 event->client_index = mp->client_index;
1585 event->address = mp->address;
1586 event->pid = mp->pid;
1587 if (mp->address == 0)
1592 rv = vnet_add_del_ip4_arp_change_event
1593 (vnm, arp_change_delete_callback,
1594 mp->pid, &mp->address /* addr, in net byte order */ ,
1595 vpe_resolver_process_node.index,
1596 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1599 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
1603 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
1605 vpe_api_main_t *am = &vpe_api_main;
1606 vnet_main_t *vnm = vnet_get_main ();
1607 vl_api_want_ip6_nd_events_reply_t *rmp;
1610 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
1613 hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index);
1614 vpe_client_registration_t *rp;
1617 if (mp->enable_disable)
1619 clib_warning ("pid %d: already enabled...", mp->pid);
1620 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1626 pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]);
1627 pool_put (am->wc_ip6_nd_events_registrations, rp);
1628 hash_unset (am->wc_ip6_nd_events_registration_hash,
1630 if (pool_elts (am->wc_ip6_nd_events_registrations) == 0)
1631 wc_nd_set_publisher_node (~0, 2);
1635 if (mp->enable_disable == 0)
1637 clib_warning ("pid %d: already disabled...", mp->pid);
1638 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1641 pool_get (am->wc_ip6_nd_events_registrations, rp);
1642 rp->client_index = mp->client_index;
1643 rp->client_pid = mp->pid;
1644 hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index,
1645 rp - am->wc_ip6_nd_events_registrations);
1646 wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT);
1650 if (mp->enable_disable)
1652 vl_api_ip6_nd_event_t *event;
1653 pool_get (am->nd_events, event);
1655 rv = vnet_add_del_ip6_nd_change_event
1656 (vnm, nd_change_data_callback,
1657 mp->pid, mp->address /* addr, in net byte order */ ,
1658 vpe_resolver_process_node.index,
1659 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
1663 pool_put (am->nd_events, event);
1666 memset (event, 0, sizeof (*event));
1668 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
1669 event->client_index = mp->client_index;
1670 clib_memcpy (event->address, mp->address, sizeof event->address);
1671 event->pid = mp->pid;
1675 rv = vnet_add_del_ip6_nd_change_event
1676 (vnm, nd_change_delete_callback,
1677 mp->pid, mp->address /* addr, in net byte order */ ,
1678 vpe_resolver_process_node.index,
1679 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1682 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
1685 static void vl_api_input_acl_set_interface_t_handler
1686 (vl_api_input_acl_set_interface_t * mp)
1688 vlib_main_t *vm = vlib_get_main ();
1689 vl_api_input_acl_set_interface_reply_t *rmp;
1692 VALIDATE_SW_IF_INDEX (mp);
1694 u32 ip4_table_index = ntohl (mp->ip4_table_index);
1695 u32 ip6_table_index = ntohl (mp->ip6_table_index);
1696 u32 l2_table_index = ntohl (mp->l2_table_index);
1697 u32 sw_if_index = ntohl (mp->sw_if_index);
1699 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
1700 ip6_table_index, l2_table_index, mp->is_add);
1702 BAD_SW_IF_INDEX_LABEL;
1704 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
1708 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
1712 api_main_t *am = &api_main;
1713 vlib_main_t *vm = vlib_get_main ();
1715 vl_api_get_node_graph_reply_t *rmp;
1717 pthread_mutex_lock (&am->vlib_rp->mutex);
1718 oldheap = svm_push_data_heap (am->vlib_rp);
1721 * Keep the number of memcpy ops to a minimum (e.g. 1).
1723 vec_validate (vector, 16384);
1724 vec_reset_length (vector);
1727 vector = vlib_node_serialize (&vm->node_main, vector,
1728 (u32) ~ 0 /* all threads */ ,
1729 1 /* include nexts */ ,
1730 1 /* include stats */ );
1732 svm_pop_heap (oldheap);
1733 pthread_mutex_unlock (&am->vlib_rp->mutex);
1736 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
1738 rmp->reply_in_shmem = (uword) vector;
1744 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1747 vl_api_ioam_enable_reply_t *rmp;
1748 clib_error_t *error;
1750 /* Ignoring the profile id as currently a single profile
1752 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1753 mp->seqno, mp->analyse);
1756 clib_error_report (error);
1757 rv = clib_error_get_code (error);
1760 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1764 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1767 vl_api_ioam_disable_reply_t *rmp;
1768 clib_error_t *error;
1770 error = clear_ioam_rewrite_fn ();
1773 clib_error_report (error);
1774 rv = clib_error_get_code (error);
1777 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1781 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
1783 vl_api_pg_create_interface_reply_t *rmp;
1786 pg_main_t *pg = &pg_main;
1787 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
1788 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
1791 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
1793 rmp->sw_if_index = ntohl(pi->sw_if_index);
1799 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
1801 vl_api_pg_capture_reply_t *rmp;
1804 vnet_main_t *vnm = vnet_get_main ();
1805 vnet_interface_main_t *im = &vnm->interface_main;
1806 vnet_hw_interface_t *hi = 0;
1808 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
1809 vec_terminate_c_string (intf_name);
1810 u32 hw_if_index = ~0;
1811 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
1814 vec_free (intf_name);
1816 if (hw_if_index != ~0)
1818 pg_capture_args_t _a, *a = &_a;
1820 u32 len = ntohl (mp->pcap_name_length);
1821 u8 *pcap_file_name = vec_new (u8, len);
1822 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
1824 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
1825 a->hw_if_index = hw_if_index;
1826 a->dev_instance = hi->dev_instance;
1827 a->is_enabled = mp->is_enabled;
1828 a->pcap_file_name = pcap_file_name;
1829 a->count = ntohl (mp->count);
1831 clib_error_t *e = pg_capture (a);
1834 clib_error_report (e);
1835 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
1838 vec_free (pcap_file_name);
1840 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
1844 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
1846 vl_api_pg_enable_disable_reply_t *rmp;
1849 pg_main_t *pg = &pg_main;
1850 u32 stream_index = ~0;
1852 int is_enable = mp->is_enabled != 0;
1853 u32 len = ntohl (mp->stream_name_length) - 1;
1857 u8 *stream_name = vec_new (u8, len);
1858 clib_memcpy (stream_name, mp->stream_name, len);
1859 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
1862 vec_free (stream_name);
1865 pg_enable_disable (stream_index, is_enable);
1867 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
1871 vl_api_ip_source_and_port_range_check_add_del_t_handler
1872 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1874 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1877 u8 is_ipv6 = mp->is_ipv6;
1878 u8 is_add = mp->is_add;
1879 u8 mask_length = mp->mask_length;
1880 ip4_address_t ip4_addr;
1881 ip6_address_t ip6_addr;
1883 u16 *high_ports = 0;
1885 u16 tmp_low, tmp_high;
1889 // Validate port range
1890 num_ranges = mp->number_of_ranges;
1891 if (num_ranges > 32)
1892 { // This is size of array in VPE.API
1893 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1897 vec_reset_length (low_ports);
1898 vec_reset_length (high_ports);
1900 for (i = 0; i < num_ranges; i++)
1902 tmp_low = mp->low_ports[i];
1903 tmp_high = mp->high_ports[i];
1904 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1905 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1906 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1908 rv = VNET_API_ERROR_INVALID_VALUE;
1911 vec_add1 (low_ports, tmp_low);
1912 vec_add1 (high_ports, tmp_high + 1);
1915 // Validate mask_length
1916 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
1918 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
1922 vrf_id = ntohl (mp->vrf_id);
1926 rv = VNET_API_ERROR_INVALID_VALUE;
1933 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
1934 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
1938 high_ports, is_add);
1942 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
1943 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
1947 high_ports, is_add);
1951 vec_free (low_ports);
1952 vec_free (high_ports);
1953 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1957 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1958 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
1960 vlib_main_t *vm = vlib_get_main ();
1961 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
1962 ip4_main_t *im = &ip4_main;
1965 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1966 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
1970 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
1971 ntohl (mp->tcp_out_vrf_id);
1972 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
1973 ntohl (mp->udp_out_vrf_id);
1974 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
1975 ntohl (mp->tcp_in_vrf_id);
1976 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
1977 ntohl (mp->udp_in_vrf_id);
1980 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
1982 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
1984 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
1988 rv = VNET_API_ERROR_INVALID_VALUE;
1992 fib_index[i] = p[0];
1997 sw_if_index = ntohl (mp->sw_if_index);
1999 VALIDATE_SW_IF_INDEX (mp);
2002 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
2005 BAD_SW_IF_INDEX_LABEL;
2008 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
2012 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
2014 vl_api_delete_subif_reply_t *rmp;
2017 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
2019 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
2023 vl_api_punt_t_handler (vl_api_punt_t * mp)
2025 vl_api_punt_reply_t *rmp;
2026 vlib_main_t *vm = vlib_get_main ();
2028 clib_error_t *error;
2030 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
2031 ntohs (mp->l4_port), mp->is_add);
2035 clib_error_report (error);
2038 REPLY_MACRO (VL_API_PUNT_REPLY);
2042 vl_api_punt_socket_register_t_handler (vl_api_punt_socket_register_t * mp)
2044 vl_api_punt_socket_register_reply_t *rmp;
2045 vlib_main_t *vm = vlib_get_main ();
2047 clib_error_t *error;
2048 unix_shared_memory_queue_t *q;
2051 error = vnet_punt_socket_add (vm, ntohl (mp->header_version),
2052 mp->is_ip4, mp->l4_protocol,
2053 ntohs (mp->l4_port), (char *) mp->pathname);
2057 clib_error_report (error);
2060 q = vl_api_client_index_to_input_queue (mp->client_index);
2064 rmp = vl_msg_api_alloc (sizeof (*rmp));
2065 rmp->_vl_msg_id = htons (VL_API_PUNT_SOCKET_REGISTER_REPLY);
2066 rmp->context = mp->context;
2067 rmp->retval = htonl (rv);
2068 char *p = vnet_punt_get_server_pathname ();
2069 /* Abstract pathnames start with \0 */
2070 memcpy ((char *) rmp->pathname, p, sizeof (rmp->pathname));
2071 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2075 vl_api_punt_socket_deregister_t_handler (vl_api_punt_socket_deregister_t * mp)
2077 vl_api_punt_socket_deregister_reply_t *rmp;
2078 vlib_main_t *vm = vlib_get_main ();
2080 clib_error_t *error;
2081 unix_shared_memory_queue_t *q;
2084 error = vnet_punt_socket_del (vm, mp->is_ip4, mp->l4_protocol,
2085 ntohs (mp->l4_port));
2089 clib_error_report (error);
2092 q = vl_api_client_index_to_input_queue (mp->client_index);
2096 rmp = vl_msg_api_alloc (sizeof (*rmp));
2097 rmp->_vl_msg_id = htons (VL_API_PUNT_SOCKET_DEREGISTER_REPLY);
2098 rmp->context = mp->context;
2099 rmp->retval = htonl (rv);
2100 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2104 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
2106 vl_api_feature_enable_disable_reply_t *rmp;
2109 VALIDATE_SW_IF_INDEX (mp);
2111 u8 *arc_name = format (0, "%s%c", mp->arc_name, 0);
2112 u8 *feature_name = format (0, "%s%c", mp->feature_name, 0);
2114 vec_terminate_c_string (arc_name);
2115 vec_terminate_c_string (feature_name);
2117 vnet_feature_registration_t *reg =
2118 vnet_get_feature_reg ((const char *) arc_name,
2119 (const char *) feature_name);
2121 rv = VNET_API_ERROR_INVALID_VALUE;
2124 u32 sw_if_index = ntohl (mp->sw_if_index);
2125 clib_error_t *error = 0;
2127 if (reg->enable_disable_cb)
2128 error = reg->enable_disable_cb (sw_if_index, mp->enable);
2130 vnet_feature_enable_disable ((const char *) arc_name,
2131 (const char *) feature_name,
2132 sw_if_index, mp->enable, 0, 0);
2135 clib_error_report (error);
2136 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
2140 vec_free (feature_name);
2141 vec_free (arc_name);
2143 BAD_SW_IF_INDEX_LABEL;
2145 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
2148 #define BOUNCE_HANDLER(nn) \
2149 static void vl_api_##nn##_t_handler ( \
2150 vl_api_##nn##_t *mp) \
2152 vpe_client_registration_t *reg; \
2153 vpe_api_main_t * vam = &vpe_api_main; \
2154 unix_shared_memory_queue_t * q; \
2156 /* One registration only... */ \
2157 pool_foreach(reg, vam->nn##_registrations, \
2159 q = vl_api_client_index_to_input_queue (reg->client_index); \
2162 * If the queue is stuffed, turf the msg and complain \
2163 * It's unlikely that the intended recipient is \
2164 * alive; avoid deadlock at all costs. \
2166 if (q->cursize == q->maxsize) { \
2167 clib_warning ("ERROR: receiver queue full, drop msg"); \
2168 vl_msg_api_free (mp); \
2171 vl_msg_api_send_shmem (q, (u8 *)&mp); \
2175 vl_msg_api_free (mp); \
2178 static void setup_message_id_table (api_main_t * am);
2182 * Add vpe's API message handlers to the table.
2183 * vlib has alread mapped shared memory and
2184 * added the client registration handlers.
2185 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
2187 static clib_error_t *
2188 vpe_api_hookup (vlib_main_t * vm)
2190 api_main_t *am = &api_main;
2193 vl_msg_api_set_handlers(VL_API_##N, #n, \
2194 vl_api_##n##_t_handler, \
2196 vl_api_##n##_t_endian, \
2197 vl_api_##n##_t_print, \
2198 sizeof(vl_api_##n##_t), 1);
2199 foreach_vpe_api_msg;
2203 * Trace space for classifier mask+match
2205 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
2206 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
2207 += 5 * sizeof (u32x4);
2210 * Thread-safe API messages
2212 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
2213 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
2216 * Set up the (msg_name, crc, message-id) table
2218 setup_message_id_table (am);
2223 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
2225 static clib_error_t *
2226 vpe_api_init (vlib_main_t * vm)
2228 vpe_api_main_t *am = &vpe_api_main;
2231 am->vnet_main = vnet_get_main ();
2233 am->a##_registration_hash = hash_create (0, sizeof (uword));
2234 foreach_registration_hash;
2237 vl_set_memory_region_name ("/vpe-api");
2238 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
2243 VLIB_INIT_FUNCTION (vpe_api_init);
2246 static clib_error_t *
2247 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
2250 u64 baseva, size, pvt_heap_size;
2252 const int max_buf_size = 4096;
2254 struct passwd _pw, *pw;
2255 struct group _grp, *grp;
2257 buf = vec_new (char, 128);
2258 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2260 if (unformat (input, "prefix %s", &chroot_path))
2262 vec_add1 (chroot_path, 0);
2263 vl_set_memory_root_path ((char *) chroot_path);
2265 else if (unformat (input, "uid %d", &uid))
2266 vl_set_memory_uid (uid);
2267 else if (unformat (input, "gid %d", &gid))
2268 vl_set_memory_gid (gid);
2269 else if (unformat (input, "baseva %llx", &baseva))
2270 vl_set_global_memory_baseva (baseva);
2271 else if (unformat (input, "global-size %lldM", &size))
2272 vl_set_global_memory_size (size * (1ULL << 20));
2273 else if (unformat (input, "global-size %lldG", &size))
2274 vl_set_global_memory_size (size * (1ULL << 30));
2275 else if (unformat (input, "global-size %lld", &size))
2276 vl_set_global_memory_size (size);
2277 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
2278 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2279 else if (unformat (input, "global-pvt-heap-size size %lld",
2281 vl_set_global_pvt_heap_size (pvt_heap_size);
2282 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
2283 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2284 else if (unformat (input, "api-pvt-heap-size size %lld",
2286 vl_set_api_pvt_heap_size (pvt_heap_size);
2287 else if (unformat (input, "api-size %lldM", &size))
2288 vl_set_api_memory_size (size * (1ULL << 20));
2289 else if (unformat (input, "api-size %lldG", &size))
2290 vl_set_api_memory_size (size * (1ULL << 30));
2291 else if (unformat (input, "api-size %lld", &size))
2292 vl_set_api_memory_size (size);
2293 else if (unformat (input, "uid %s", &s))
2295 /* lookup the username */
2298 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
2299 && (vec_len (buf) <= max_buf_size))
2301 vec_resize (buf, vec_len (buf) * 2);
2305 e = clib_error_return_code (0, rv,
2306 CLIB_ERROR_ERRNO_VALID |
2308 "cannot fetch username %s", s);
2316 clib_error_return_fatal (0, "username %s does not exist", s);
2322 vl_set_memory_uid (pw->pw_uid);
2324 else if (unformat (input, "gid %s", &s))
2326 /* lookup the group name */
2329 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
2330 && (vec_len (buf) <= max_buf_size))
2332 vec_resize (buf, vec_len (buf) * 2);
2336 e = clib_error_return_code (0, rv,
2337 CLIB_ERROR_ERRNO_VALID |
2339 "cannot fetch group %s", s);
2346 e = clib_error_return_fatal (0, "group %s does not exist", s);
2353 vl_set_memory_gid (grp->gr_gid);
2356 return clib_error_return (0, "unknown input `%U'",
2357 format_unformat_error, input);
2362 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
2365 get_unformat_vnet_sw_interface (void)
2367 return (void *) &unformat_vnet_sw_interface;
2371 format_arp_event (u8 * s, va_list * args)
2373 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
2375 s = format (s, "pid %d: ", ntohl (event->pid));
2376 s = format (s, "resolution for %U", format_ip4_address, &event->address);
2381 format_nd_event (u8 * s, va_list * args)
2383 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
2385 s = format (s, "pid %d: ", ntohl (event->pid));
2386 s = format (s, "resolution for %U", format_ip6_address, event->address);
2390 static clib_error_t *
2391 show_ip_arp_nd_events_fn (vlib_main_t * vm,
2392 unformat_input_t * input, vlib_cli_command_t * cmd)
2394 vpe_api_main_t *am = &vpe_api_main;
2395 vl_api_ip4_arp_event_t *arp_event;
2396 vl_api_ip6_nd_event_t *nd_event;
2398 if (pool_elts (am->arp_events) == 0 && pool_elts (am->nd_events) == 0 &&
2399 pool_elts (am->wc_ip4_arp_events_registrations) == 0 &&
2400 pool_elts (am->wc_ip6_nd_events_registrations) == 0)
2402 vlib_cli_output (vm, "No active arp or nd event registrations");
2407 pool_foreach (arp_event, am->arp_events,
2409 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
2412 vpe_client_registration_t *reg;
2413 pool_foreach(reg, am->wc_ip4_arp_events_registrations,
2415 vlib_cli_output (vm, "pid %d: bd mac/ip4 binding events",
2416 ntohl (reg->client_pid));
2419 pool_foreach (nd_event, am->nd_events,
2421 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
2424 pool_foreach(reg, am->wc_ip6_nd_events_registrations,
2426 vlib_cli_output (vm, "pid %d: bd mac/ip6 binding events",
2427 ntohl (reg->client_pid));
2435 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
2436 .path = "show arp-nd-event registrations",
2437 .function = show_ip_arp_nd_events_fn,
2438 .short_help = "Show ip4 arp and ip6 nd event registrations",
2442 #define vl_msg_name_crc_list
2443 #include <vpp/api/vpe_all_api_h.h>
2444 #undef vl_msg_name_crc_list
2447 setup_message_id_table (api_main_t * am)
2449 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2450 foreach_vl_msg_name_crc_memclnt;
2451 foreach_vl_msg_name_crc_vpe;
2454 #define vl_api_version_tuple(n,mj, mi, p) \
2455 vl_msg_api_add_version (am, #n, mj, mi, p);
2456 #include <vpp/api/vpe_all_api_h.h>
2457 #undef vl_api_version_tuple
2462 * fd.io coding-style-patch-verification: ON
2465 * eval: (c-set-style "gnu")