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/sr/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/vxlan/vxlan.h>
65 #include <vnet/vxlan-gpe/vxlan_gpe.h>
66 #include <vnet/map/map.h>
67 #include <vnet/ip/ip6_hop_by_hop.h>
68 #include <vnet/ip/ip_source_and_port_range_check.h>
69 #include <vnet/ip/punt.h>
70 #include <vnet/feature/feature.h>
73 #undef __included_bihash_template_h__
74 #include <vnet/l2/l2_fib.h>
76 #include <vpp/stats/stats.h>
77 #include <vpp/oam/oam.h>
79 #include <vnet/ethernet/ethernet.h>
80 #include <vnet/ethernet/arp_packet.h>
81 #include <vnet/interface.h>
82 #include <vnet/l2/l2_fib.h>
83 #include <vnet/l2/l2_bd.h>
84 #include <vpp/api/vpe_msg_enum.h>
85 #include <vnet/span/span.h>
86 #include <vnet/fib/ip6_fib.h>
87 #include <vnet/fib/ip4_fib.h>
88 #include <vnet/fib/fib_api.h>
89 #include <vnet/dpo/drop_dpo.h>
90 #include <vnet/dpo/receive_dpo.h>
91 #include <vnet/dpo/lookup_dpo.h>
92 #include <vnet/dpo/classify_dpo.h>
93 #include <vnet/dpo/ip_null_dpo.h>
94 #define vl_typedefs /* define message structures */
95 #include <vpp/api/vpe_all_api_h.h>
97 #define vl_endianfun /* define message structures */
98 #include <vpp/api/vpe_all_api_h.h>
100 /* instantiate all the print functions we know about */
101 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
103 #include <vpp/api/vpe_all_api_h.h>
105 #include <vlibapi/api_helper_macros.h>
106 #define foreach_vpe_api_msg \
107 _(WANT_OAM_EVENTS, want_oam_events) \
108 _(OAM_ADD_DEL, oam_add_del) \
109 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
110 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
111 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
112 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
113 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
114 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
115 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
116 _(CREATE_SUBIF, create_subif) \
117 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
118 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
119 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
120 _(RESET_FIB, reset_fib) \
121 _(CREATE_LOOPBACK, create_loopback) \
122 _(CONTROL_PING, control_ping) \
123 _(CLI_REQUEST, cli_request) \
124 _(CLI_INBAND, cli_inband) \
125 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
126 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
127 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
128 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
129 _(GET_NODE_INDEX, get_node_index) \
130 _(ADD_NODE_NEXT, add_node_next) \
131 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
132 _(SHOW_VERSION, show_version) \
133 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
134 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
135 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
136 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
137 _(DELETE_LOOPBACK, delete_loopback) \
138 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
139 _(GET_NODE_GRAPH, get_node_graph) \
140 _(IOAM_ENABLE, ioam_enable) \
141 _(IOAM_DISABLE, ioam_disable) \
142 _(GET_NEXT_INDEX, get_next_index) \
143 _(PG_CREATE_INTERFACE, pg_create_interface) \
144 _(PG_CAPTURE, pg_capture) \
145 _(PG_ENABLE_DISABLE, pg_enable_disable) \
146 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
147 ip_source_and_port_range_check_add_del) \
148 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
149 ip_source_and_port_range_check_interface_add_del) \
150 _(DELETE_SUBIF, delete_subif) \
152 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
155 #define QUOTE(x) QUOTE_(x)
158 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
159 RESOLVE_IP6_ADD_DEL_ROUTE,
162 static vlib_node_registration_t vpe_resolver_process_node;
163 vpe_api_main_t vpe_api_main;
165 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
166 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
168 /* Clean up all registrations belonging to the indicated client */
170 vl_api_memclnt_delete_callback (u32 client_index)
172 vpe_api_main_t *vam = &vpe_api_main;
173 vpe_client_registration_t *rp;
175 int stats_memclnt_delete_callback (u32 client_index);
177 stats_memclnt_delete_callback (client_index);
180 p = hash_get (vam->a##_registration_hash, client_index); \
182 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
183 pool_put (vam->a##_registrations, rp); \
184 hash_unset (vam->a##_registration_hash, client_index); \
186 foreach_registration_hash;
191 pub_sub_handler (oam_events, OAM_EVENTS);
193 #define RESOLUTION_EVENT 1
194 #define RESOLUTION_PENDING_EVENT 2
195 #define IP4_ARP_EVENT 3
196 #define IP6_ND_EVENT 4
198 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
200 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
203 handle_ip4_arp_event (u32 pool_index)
205 vpe_api_main_t *vam = &vpe_api_main;
206 vnet_main_t *vnm = vam->vnet_main;
207 vlib_main_t *vm = vam->vlib_main;
208 vl_api_ip4_arp_event_t *event;
209 vl_api_ip4_arp_event_t *mp;
210 unix_shared_memory_queue_t *q;
212 /* Client can cancel, die, etc. */
213 if (pool_is_free_index (vam->arp_events, pool_index))
216 event = pool_elt_at_index (vam->arp_events, pool_index);
218 q = vl_api_client_index_to_input_queue (event->client_index);
221 (void) vnet_add_del_ip4_arp_change_event
222 (vnm, arp_change_delete_callback,
223 event->pid, &event->address,
224 vpe_resolver_process_node.index, IP4_ARP_EVENT,
225 ~0 /* pool index, notused */ , 0 /* is_add */ );
229 if (q->cursize < q->maxsize)
231 mp = vl_msg_api_alloc (sizeof (*mp));
232 clib_memcpy (mp, event, sizeof (*mp));
233 vl_msg_api_send_shmem (q, (u8 *) & mp);
237 static f64 last_time;
239 * Throttle syslog msgs.
240 * It's pretty tempting to just revoke the registration...
242 if (vlib_time_now (vm) > last_time + 10.0)
244 clib_warning ("arp event for %U to pid %d: queue stuffed!",
245 format_ip4_address, &event->address, event->pid);
246 last_time = vlib_time_now (vm);
252 handle_ip6_nd_event (u32 pool_index)
254 vpe_api_main_t *vam = &vpe_api_main;
255 vnet_main_t *vnm = vam->vnet_main;
256 vlib_main_t *vm = vam->vlib_main;
257 vl_api_ip6_nd_event_t *event;
258 vl_api_ip6_nd_event_t *mp;
259 unix_shared_memory_queue_t *q;
261 /* Client can cancel, die, etc. */
262 if (pool_is_free_index (vam->nd_events, pool_index))
265 event = pool_elt_at_index (vam->nd_events, pool_index);
267 q = vl_api_client_index_to_input_queue (event->client_index);
270 (void) vnet_add_del_ip6_nd_change_event
271 (vnm, nd_change_delete_callback,
272 event->pid, &event->address,
273 vpe_resolver_process_node.index, IP6_ND_EVENT,
274 ~0 /* pool index, notused */ , 0 /* is_add */ );
278 if (q->cursize < q->maxsize)
280 mp = vl_msg_api_alloc (sizeof (*mp));
281 clib_memcpy (mp, event, sizeof (*mp));
282 vl_msg_api_send_shmem (q, (u8 *) & mp);
286 static f64 last_time;
288 * Throttle syslog msgs.
289 * It's pretty tempting to just revoke the registration...
291 if (vlib_time_now (vm) > last_time + 10.0)
293 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
294 format_ip6_address, &event->address, event->pid);
295 last_time = vlib_time_now (vm);
301 resolver_process (vlib_main_t * vm,
302 vlib_node_runtime_t * rt, vlib_frame_t * f)
305 uword *event_data = 0;
311 vlib_process_wait_for_event_or_clock (vm, timeout);
313 event_type = vlib_process_get_events (vm, &event_data);
317 case RESOLUTION_PENDING_EVENT:
321 case RESOLUTION_EVENT:
322 clib_warning ("resolver: BOGUS TYPE");
326 for (i = 0; i < vec_len (event_data); i++)
327 handle_ip4_arp_event (event_data[i]);
331 for (i = 0; i < vec_len (event_data); i++)
332 handle_ip6_nd_event (event_data[i]);
335 case ~0: /* timeout */
339 vec_reset_length (event_data);
341 return 0; /* or not */
345 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
346 .function = resolver_process,
347 .type = VLIB_NODE_TYPE_PROCESS,
348 .name = "vpe-route-resolver-process",
353 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
355 vl_api_sw_interface_set_vpath_reply_t *rmp;
357 u32 sw_if_index = ntohl (mp->sw_if_index);
359 VALIDATE_SW_IF_INDEX (mp);
361 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
362 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
363 sw_if_index, mp->enable, 0, 0);
364 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
365 sw_if_index, mp->enable, 0, 0);
366 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
367 sw_if_index, mp->enable, 0, 0);
368 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
369 sw_if_index, mp->enable, 0, 0);
371 BAD_SW_IF_INDEX_LABEL;
373 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
377 vl_api_sw_interface_set_vxlan_bypass_t_handler
378 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
380 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
382 u32 sw_if_index = ntohl (mp->sw_if_index);
384 VALIDATE_SW_IF_INDEX (mp);
388 /* not yet implemented */
391 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
392 sw_if_index, mp->enable, 0, 0);
394 BAD_SW_IF_INDEX_LABEL;
396 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
400 vl_api_sw_interface_set_l2_xconnect_t_handler
401 (vl_api_sw_interface_set_l2_xconnect_t * mp)
403 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
405 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
406 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
407 vlib_main_t *vm = vlib_get_main ();
408 vnet_main_t *vnm = vnet_get_main ();
410 VALIDATE_RX_SW_IF_INDEX (mp);
414 VALIDATE_TX_SW_IF_INDEX (mp);
415 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
416 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
420 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
423 BAD_RX_SW_IF_INDEX_LABEL;
424 BAD_TX_SW_IF_INDEX_LABEL;
426 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
430 vl_api_sw_interface_set_l2_bridge_t_handler
431 (vl_api_sw_interface_set_l2_bridge_t * mp)
433 bd_main_t *bdm = &bd_main;
434 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
436 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
437 u32 bd_id = ntohl (mp->bd_id);
441 vlib_main_t *vm = vlib_get_main ();
442 vnet_main_t *vnm = vnet_get_main ();
444 VALIDATE_RX_SW_IF_INDEX (mp);
446 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
450 //VALIDATE_TX_SW_IF_INDEX(mp);
451 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
452 rx_sw_if_index, bd_index, bvi, shg, 0);
456 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
459 BAD_RX_SW_IF_INDEX_LABEL;
461 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
465 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
467 bd_main_t *bdm = &bd_main;
468 vl_api_bd_ip_mac_add_del_reply_t *rmp;
470 u32 bd_id = ntohl (mp->bd_id);
474 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
477 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
482 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
483 mp->mac_address, mp->is_ipv6, mp->is_add))
484 rv = VNET_API_ERROR_UNSPECIFIED;
487 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
491 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
493 vl_api_create_vlan_subif_reply_t *rmp;
494 vnet_main_t *vnm = vnet_get_main ();
495 u32 sw_if_index = (u32) ~ 0;
496 vnet_hw_interface_t *hi;
499 vnet_sw_interface_t template;
501 vnet_interface_main_t *im = &vnm->interface_main;
504 unix_shared_memory_queue_t *q;
507 VALIDATE_SW_IF_INDEX (mp);
509 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
511 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
513 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
517 id = ntohl (mp->vlan_id);
518 if (id == 0 || id > 4095)
520 rv = VNET_API_ERROR_INVALID_VLAN;
524 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
526 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
529 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
533 kp = clib_mem_alloc (sizeof (*kp));
534 *kp = sup_and_sub_key;
536 memset (&template, 0, sizeof (template));
537 template.type = VNET_SW_INTERFACE_TYPE_SUB;
538 template.sup_sw_if_index = hi->sw_if_index;
539 template.sub.id = id;
540 template.sub.eth.raw_flags = 0;
541 template.sub.eth.flags.one_tag = 1;
542 template.sub.eth.outer_vlan_id = id;
543 template.sub.eth.flags.exact_match = 1;
545 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
548 clib_error_report (error);
549 rv = VNET_API_ERROR_INVALID_REGISTRATION;
552 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
553 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
555 BAD_SW_IF_INDEX_LABEL;
558 q = vl_api_client_index_to_input_queue (mp->client_index);
562 rmp = vl_msg_api_alloc (sizeof (*rmp));
563 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
564 rmp->context = mp->context;
565 rmp->retval = ntohl (rv);
566 rmp->sw_if_index = ntohl (sw_if_index);
567 vl_msg_api_send_shmem (q, (u8 *) & rmp);
571 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
573 vl_api_create_subif_reply_t *rmp;
574 vnet_main_t *vnm = vnet_get_main ();
575 u32 sw_if_index = ~0;
578 vnet_sw_interface_t *si;
579 vnet_hw_interface_t *hi;
580 vnet_sw_interface_t template;
582 vnet_interface_main_t *im = &vnm->interface_main;
587 VALIDATE_SW_IF_INDEX (mp);
589 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
590 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
592 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
594 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
598 sw_if_index = si->sw_if_index;
599 sub_id = ntohl (mp->sub_id);
601 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
603 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
607 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
608 sw_if_index, sub_id);
609 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
613 kp = clib_mem_alloc (sizeof (*kp));
614 *kp = sup_and_sub_key;
616 memset (&template, 0, sizeof (template));
617 template.type = VNET_SW_INTERFACE_TYPE_SUB;
618 template.sup_sw_if_index = sw_if_index;
619 template.sub.id = sub_id;
620 template.sub.eth.flags.no_tags = mp->no_tags;
621 template.sub.eth.flags.one_tag = mp->one_tag;
622 template.sub.eth.flags.two_tags = mp->two_tags;
623 template.sub.eth.flags.dot1ad = mp->dot1ad;
624 template.sub.eth.flags.exact_match = mp->exact_match;
625 template.sub.eth.flags.default_sub = mp->default_sub;
626 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
627 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
628 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
629 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
631 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
634 clib_error_report (error);
635 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
639 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
640 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
642 BAD_SW_IF_INDEX_LABEL;
647 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
649 rmp->sw_if_index = ntohl(sw_if_index);
655 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
657 vl_api_proxy_arp_add_del_reply_t *rmp;
660 ip4_main_t *im = &ip4_main;
661 stats_main_t *sm = &stats_main;
662 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
663 ip4_address_t * hi_addr,
664 u32 fib_index, int is_del);
667 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
669 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
673 rv = VNET_API_ERROR_NO_SUCH_FIB;
679 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
680 (ip4_address_t *) mp->hi_address,
681 fib_index, mp->is_add == 0);
685 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
689 vl_api_proxy_arp_intfc_enable_disable_t_handler
690 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
693 vnet_main_t *vnm = vnet_get_main ();
694 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
695 vnet_sw_interface_t *si;
698 VALIDATE_SW_IF_INDEX (mp);
700 sw_if_index = ntohl (mp->sw_if_index);
702 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
704 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
708 si = vnet_get_sw_interface (vnm, sw_if_index);
712 if (mp->enable_disable)
713 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
715 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
717 BAD_SW_IF_INDEX_LABEL;
720 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
724 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
727 vpe_main_t *rm = &vpe_main;
728 ip4_main_t *im4 = &ip4_main;
729 ip6_main_t *im6 = &ip6_main;
730 ip_lookup_main_t *lm;
736 u32 adj_index, sw_if_index;
737 vl_api_is_address_reachable_t *rmp;
739 unix_shared_memory_queue_t *q;
741 q = vl_api_client_index_to_input_queue (mp->client_index);
744 increment_missing_api_client_counter (rm->vlib_main);
748 rmp = vl_msg_api_alloc (sizeof (*rmp));
749 clib_memcpy (rmp, mp, sizeof (*rmp));
751 sw_if_index = mp->next_hop_sw_if_index;
752 clib_memcpy (&addr, mp->address, sizeof (addr));
755 lm = &im6->lookup_main;
756 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
760 lm = &im4->lookup_main;
762 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
769 adj = ip_get_adjacency (lm, adj_index);
771 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
772 && adj->rewrite_header.sw_if_index == sw_if_index)
778 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
779 && adj->rewrite_header.sw_if_index == sw_if_index)
782 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
784 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
786 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
795 vl_msg_api_send_shmem (q, (u8 *) & rmp);
800 vl_api_sw_interface_set_mpls_enable_t_handler
801 (vl_api_sw_interface_set_mpls_enable_t * mp)
803 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
806 VALIDATE_SW_IF_INDEX (mp);
808 mpls_sw_interface_enable_disable (&mpls_main,
809 ntohl (mp->sw_if_index), mp->enable);
811 BAD_SW_IF_INDEX_LABEL;
812 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
816 send_oam_event (oam_target_t * t)
818 vpe_api_main_t *vam = &vpe_api_main;
819 unix_shared_memory_queue_t *q;
820 vpe_client_registration_t *reg;
821 vl_api_oam_event_t *mp;
824 pool_foreach(reg, vam->oam_events_registrations,
826 q = vl_api_client_index_to_input_queue (reg->client_index);
829 mp = vl_msg_api_alloc (sizeof (*mp));
830 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
831 clib_memcpy (mp->dst_address, &t->dst_address,
832 sizeof (mp->dst_address));
833 mp->state = t->state;
834 vl_msg_api_send_shmem (q, (u8 *)&mp);
841 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
843 vl_api_oam_add_del_reply_t *rmp;
846 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
847 (ip4_address_t *) mp->dst_address,
848 ntohl (mp->vrf_id), (int) (mp->is_add));
850 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
854 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
856 stats_main_t *sm = &stats_main;
857 vnet_interface_main_t *im = sm->interface_main;
858 vl_api_vnet_summary_stats_reply_t *rmp;
859 vlib_combined_counter_main_t *cm;
862 u64 total_pkts[VLIB_N_RX_TX];
863 u64 total_bytes[VLIB_N_RX_TX];
865 unix_shared_memory_queue_t *q =
866 vl_api_client_index_to_input_queue (mp->client_index);
871 rmp = vl_msg_api_alloc (sizeof (*rmp));
872 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
873 rmp->context = mp->context;
876 memset (total_pkts, 0, sizeof (total_pkts));
877 memset (total_bytes, 0, sizeof (total_bytes));
879 vnet_interface_counter_lock (im);
881 vec_foreach (cm, im->combined_sw_if_counters)
883 which = cm - im->combined_sw_if_counters;
885 for (i = 0; i < vec_len (cm->maxi); i++)
887 vlib_get_combined_counter (cm, i, &v);
888 total_pkts[which] += v.packets;
889 total_bytes[which] += v.bytes;
892 vnet_interface_counter_unlock (im);
894 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
895 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
896 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
897 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
899 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
901 vl_msg_api_send_shmem (q, (u8 *) & rmp);
905 typedef CLIB_PACKED (struct {
906 ip4_address_t address;
907 u32 address_length: 6;
913 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
915 vnet_main_t *vnm = vnet_get_main ();
916 vnet_interface_main_t *im = &vnm->interface_main;
917 ip4_main_t *im4 = &ip4_main;
918 static u32 *sw_if_indices_to_shut;
919 stats_main_t *sm = &stats_main;
920 fib_table_t *fib_table;
924 int rv = VNET_API_ERROR_NO_SUCH_FIB;
925 u32 target_fib_id = ntohl (mp->vrf_id);
927 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
930 pool_foreach (fib_table, im4->fibs,
932 fib = &fib_table->v4;
933 vnet_sw_interface_t * si;
935 if (fib->table_id != target_fib_id)
938 /* remove any mpls encap/decap labels */
939 mpls_fib_reset_labels (fib->table_id);
941 /* remove any proxy arps in this fib */
942 vnet_proxy_arp_fib_reset (fib->table_id);
944 /* Set the flow hash for this fib to the default */
945 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
947 vec_reset_length (sw_if_indices_to_shut);
949 /* Shut down interfaces in this FIB / clean out intfc routes */
950 pool_foreach (si, im->sw_interfaces,
952 u32 sw_if_index = si->sw_if_index;
954 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
955 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
957 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
960 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
961 sw_if_index = sw_if_indices_to_shut[i];
963 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
964 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
965 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
968 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
972 })); /* pool_foreach (fib) */
980 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
982 vnet_main_t *vnm = vnet_get_main ();
983 vnet_interface_main_t *im = &vnm->interface_main;
984 ip6_main_t *im6 = &ip6_main;
985 stats_main_t *sm = &stats_main;
986 static u32 *sw_if_indices_to_shut;
987 fib_table_t *fib_table;
991 int rv = VNET_API_ERROR_NO_SUCH_FIB;
992 u32 target_fib_id = ntohl (mp->vrf_id);
994 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
997 pool_foreach (fib_table, im6->fibs,
999 vnet_sw_interface_t * si;
1000 fib = &(fib_table->v6);
1002 if (fib->table_id != target_fib_id)
1005 vec_reset_length (sw_if_indices_to_shut);
1007 /* Shut down interfaces in this FIB / clean out intfc routes */
1008 pool_foreach (si, im->sw_interfaces,
1010 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1012 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1015 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1016 sw_if_index = sw_if_indices_to_shut[i];
1018 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1019 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1020 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1023 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1027 })); /* pool_foreach (fib) */
1035 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1038 vl_api_reset_fib_reply_t *rmp;
1041 rv = ip6_reset_fib_t_handler (mp);
1043 rv = ip4_reset_fib_t_handler (mp);
1045 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1049 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1051 vl_api_create_loopback_reply_t *rmp;
1055 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1058 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1060 rmp->sw_if_index = ntohl (sw_if_index);
1066 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1068 vl_api_delete_loopback_reply_t *rmp;
1072 sw_if_index = ntohl (mp->sw_if_index);
1073 rv = vnet_delete_loopback_interface (sw_if_index);
1075 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1079 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1081 vl_api_control_ping_reply_t *rmp;
1085 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1087 rmp->vpe_pid = ntohl (getpid());
1093 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1095 u8 **shmem_vecp = (u8 **) arg;
1098 api_main_t *am = &api_main;
1101 shmem_vec = *shmem_vecp;
1103 offset = vec_len (shmem_vec);
1105 pthread_mutex_lock (&am->vlib_rp->mutex);
1106 oldheap = svm_push_data_heap (am->vlib_rp);
1108 vec_validate (shmem_vec, offset + buffer_bytes - 1);
1110 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
1112 svm_pop_heap (oldheap);
1113 pthread_mutex_unlock (&am->vlib_rp->mutex);
1115 *shmem_vecp = shmem_vec;
1120 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
1122 vl_api_cli_reply_t *rp;
1123 unix_shared_memory_queue_t *q;
1124 vlib_main_t *vm = vlib_get_main ();
1125 api_main_t *am = &api_main;
1126 unformat_input_t input;
1130 q = vl_api_client_index_to_input_queue (mp->client_index);
1134 rp = vl_msg_api_alloc (sizeof (*rp));
1135 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
1136 rp->context = mp->context;
1138 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
1140 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
1142 pthread_mutex_lock (&am->vlib_rp->mutex);
1143 oldheap = svm_push_data_heap (am->vlib_rp);
1145 vec_add1 (shmem_vec, 0);
1147 svm_pop_heap (oldheap);
1148 pthread_mutex_unlock (&am->vlib_rp->mutex);
1150 rp->reply_in_shmem = (uword) shmem_vec;
1152 vl_msg_api_send_shmem (q, (u8 *) & rp);
1156 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1158 u8 **mem_vecp = (u8 **) arg;
1159 u8 *mem_vec = *mem_vecp;
1160 u32 offset = vec_len (mem_vec);
1162 vec_validate (mem_vec, offset + buffer_bytes - 1);
1163 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
1164 *mem_vecp = mem_vec;
1168 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
1170 vl_api_cli_inband_reply_t *rmp;
1172 unix_shared_memory_queue_t *q;
1173 vlib_main_t *vm = vlib_get_main ();
1174 unformat_input_t input;
1177 q = vl_api_client_index_to_input_queue (mp->client_index);
1181 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
1182 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
1184 u32 len = vec_len (out_vec);
1186 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
1188 rmp->length = htonl (len);
1189 clib_memcpy (rmp->reply, out_vec, len);
1196 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
1199 vl_api_set_arp_neighbor_limit_reply_t *rmp;
1200 vnet_main_t *vnm = vnet_get_main ();
1201 clib_error_t *error;
1206 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
1208 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
1212 clib_error_report (error);
1213 rv = VNET_API_ERROR_UNSPECIFIED;
1217 rv = vnm->api_errno;
1220 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
1223 static void vl_api_classify_set_interface_ip_table_t_handler
1224 (vl_api_classify_set_interface_ip_table_t * mp)
1226 vlib_main_t *vm = vlib_get_main ();
1227 vl_api_classify_set_interface_ip_table_reply_t *rmp;
1229 u32 table_index, sw_if_index;
1231 table_index = ntohl (mp->table_index);
1232 sw_if_index = ntohl (mp->sw_if_index);
1234 VALIDATE_SW_IF_INDEX (mp);
1237 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
1239 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
1241 BAD_SW_IF_INDEX_LABEL;
1243 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
1246 static void vl_api_classify_set_interface_l2_tables_t_handler
1247 (vl_api_classify_set_interface_l2_tables_t * mp)
1249 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
1251 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
1254 ip4_table_index = ntohl (mp->ip4_table_index);
1255 ip6_table_index = ntohl (mp->ip6_table_index);
1256 other_table_index = ntohl (mp->other_table_index);
1257 sw_if_index = ntohl (mp->sw_if_index);
1259 VALIDATE_SW_IF_INDEX (mp);
1262 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
1266 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
1272 if (ip4_table_index != ~0 || ip6_table_index != ~0
1273 || other_table_index != ~0)
1279 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
1281 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
1284 BAD_SW_IF_INDEX_LABEL;
1286 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
1289 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1290 u32 sw_if_index, u32 enable);
1293 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1297 vl_api_l2_interface_efp_filter_reply_t *rmp;
1298 vnet_main_t *vnm = vnet_get_main ();
1300 // enable/disable the feature
1301 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
1302 rv = vnm->api_errno;
1304 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1308 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
1310 vl_api_show_version_reply_t *rmp;
1312 char *vpe_api_get_build_directory (void);
1313 char *vpe_api_get_version (void);
1314 char *vpe_api_get_build_date (void);
1316 unix_shared_memory_queue_t *q =
1317 vl_api_client_index_to_input_queue (mp->client_index);
1323 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
1325 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
1326 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
1327 ARRAY_LEN(rmp->build_directory)-1);
1328 strncpy ((char *) rmp->version, vpe_api_get_version(),
1329 ARRAY_LEN(rmp->version)-1);
1330 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
1331 ARRAY_LEN(rmp->build_date)-1);
1337 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
1339 vlib_main_t *vm = vlib_get_main ();
1340 vl_api_get_node_index_reply_t *rmp;
1343 u32 node_index = ~0;
1345 n = vlib_get_node_by_name (vm, mp->node_name);
1348 rv = VNET_API_ERROR_NO_SUCH_NODE;
1350 node_index = n->index;
1353 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1355 rmp->node_index = ntohl(node_index);
1361 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
1363 vlib_main_t *vm = vlib_get_main ();
1364 vl_api_get_next_index_reply_t *rmp;
1365 vlib_node_t *node, *next_node;
1367 u32 next_node_index = ~0, next_index = ~0;
1370 node = vlib_get_node_by_name (vm, mp->node_name);
1374 rv = VNET_API_ERROR_NO_SUCH_NODE;
1378 next_node = vlib_get_node_by_name (vm, mp->next_name);
1382 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1386 next_node_index = next_node->index;
1388 p = hash_get (node->next_slot_by_node, next_node_index);
1392 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1400 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
1402 rmp->next_index = ntohl(next_index);
1408 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
1410 vlib_main_t *vm = vlib_get_main ();
1411 vl_api_add_node_next_reply_t *rmp;
1412 vlib_node_t *n, *next;
1414 u32 next_index = ~0;
1416 n = vlib_get_node_by_name (vm, mp->node_name);
1420 rv = VNET_API_ERROR_NO_SUCH_NODE;
1424 next = vlib_get_node_by_name (vm, mp->next_name);
1427 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1429 next_index = vlib_node_add_next (vm, n->index, next->index);
1433 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1435 rmp->next_index = ntohl(next_index);
1440 static void send_vxlan_tunnel_details
1441 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1443 vl_api_vxlan_tunnel_details_t *rmp;
1444 ip4_main_t *im4 = &ip4_main;
1445 ip6_main_t *im6 = &ip6_main;
1446 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
1448 rmp = vl_msg_api_alloc (sizeof (*rmp));
1449 memset (rmp, 0, sizeof (*rmp));
1450 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
1453 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
1454 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
1455 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1459 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
1460 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
1461 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1463 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
1464 rmp->vni = htonl (t->vni);
1465 rmp->decap_next_index = htonl (t->decap_next_index);
1466 rmp->sw_if_index = htonl (t->sw_if_index);
1467 rmp->is_ipv6 = is_ipv6;
1468 rmp->context = context;
1470 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1474 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1476 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1478 vl_api_l2_patch_add_del_reply_t *rmp;
1479 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1483 VALIDATE_RX_SW_IF_INDEX (mp);
1484 VALIDATE_TX_SW_IF_INDEX (mp);
1486 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1487 ntohl (mp->tx_sw_if_index),
1488 (int) (mp->is_add != 0));
1490 BAD_RX_SW_IF_INDEX_LABEL;
1491 BAD_TX_SW_IF_INDEX_LABEL;
1493 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1496 static void send_vxlan_gpe_tunnel_details
1497 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1499 vl_api_vxlan_gpe_tunnel_details_t *rmp;
1500 ip4_main_t *im4 = &ip4_main;
1501 ip6_main_t *im6 = &ip6_main;
1502 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
1504 rmp = vl_msg_api_alloc (sizeof (*rmp));
1505 memset (rmp, 0, sizeof (*rmp));
1506 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
1509 memcpy (rmp->local, &(t->local.ip6), 16);
1510 memcpy (rmp->remote, &(t->remote.ip6), 16);
1511 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1512 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
1516 memcpy (rmp->local, &(t->local.ip4), 4);
1517 memcpy (rmp->remote, &(t->remote.ip4), 4);
1518 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1519 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
1521 rmp->vni = htonl (t->vni);
1522 rmp->protocol = t->protocol;
1523 rmp->sw_if_index = htonl (t->sw_if_index);
1524 rmp->is_ipv6 = is_ipv6;
1525 rmp->context = context;
1527 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1531 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1534 vl_api_interface_name_renumber_reply_t *rmp;
1537 VALIDATE_SW_IF_INDEX (mp);
1539 rv = vnet_interface_name_renumber
1540 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1542 BAD_SW_IF_INDEX_LABEL;
1544 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1548 arp_change_data_callback (u32 pool_index, u8 * new_mac,
1549 u32 sw_if_index, u32 address)
1551 vpe_api_main_t *am = &vpe_api_main;
1552 vlib_main_t *vm = am->vlib_main;
1553 vl_api_ip4_arp_event_t *event;
1554 static f64 arp_event_last_time;
1555 f64 now = vlib_time_now (vm);
1557 if (pool_is_free_index (am->arp_events, pool_index))
1560 event = pool_elt_at_index (am->arp_events, pool_index);
1562 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1564 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1568 if (sw_if_index == event->sw_if_index &&
1570 /* for BD case, also check IP address with 10 sec timeout */
1571 (address == event->address &&
1572 (now - arp_event_last_time) < 10.0)))
1577 arp_event_last_time = now;
1578 event->sw_if_index = sw_if_index;
1580 event->address = address;
1585 nd_change_data_callback (u32 pool_index, u8 * new_mac,
1586 u32 sw_if_index, ip6_address_t * address)
1588 vpe_api_main_t *am = &vpe_api_main;
1589 vlib_main_t *vm = am->vlib_main;
1590 vl_api_ip6_nd_event_t *event;
1591 static f64 nd_event_last_time;
1592 f64 now = vlib_time_now (vm);
1594 if (pool_is_free_index (am->nd_events, pool_index))
1597 event = pool_elt_at_index (am->nd_events, pool_index);
1600 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1602 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1606 if (sw_if_index == event->sw_if_index &&
1608 /* for BD case, also check IP address with 10 sec timeout */
1609 (ip6_address_is_equal (address,
1610 (ip6_address_t *) event->address) &&
1611 (now - nd_event_last_time) < 10.0)))
1616 nd_event_last_time = now;
1617 event->sw_if_index = sw_if_index;
1619 clib_memcpy (event->address, address, sizeof (event->address));
1624 arp_change_delete_callback (u32 pool_index, u8 * notused)
1626 vpe_api_main_t *am = &vpe_api_main;
1628 if (pool_is_free_index (am->arp_events, pool_index))
1631 pool_put_index (am->arp_events, pool_index);
1636 nd_change_delete_callback (u32 pool_index, u8 * notused)
1638 vpe_api_main_t *am = &vpe_api_main;
1640 if (pool_is_free_index (am->nd_events, pool_index))
1643 pool_put_index (am->nd_events, pool_index);
1648 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
1650 vpe_api_main_t *am = &vpe_api_main;
1651 vnet_main_t *vnm = vnet_get_main ();
1652 vl_api_want_ip4_arp_events_reply_t *rmp;
1653 vl_api_ip4_arp_event_t *event;
1656 if (mp->enable_disable)
1658 pool_get (am->arp_events, event);
1659 memset (event, 0, sizeof (*event));
1661 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
1662 event->client_index = mp->client_index;
1663 event->context = mp->context;
1664 event->address = mp->address;
1665 event->pid = mp->pid;
1666 if (mp->address == 0)
1669 rv = vnet_add_del_ip4_arp_change_event
1670 (vnm, arp_change_data_callback,
1671 mp->pid, &mp->address /* addr, in net byte order */ ,
1672 vpe_resolver_process_node.index,
1673 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
1677 rv = vnet_add_del_ip4_arp_change_event
1678 (vnm, arp_change_delete_callback,
1679 mp->pid, &mp->address /* addr, in net byte order */ ,
1680 vpe_resolver_process_node.index,
1681 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1683 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
1687 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
1689 vpe_api_main_t *am = &vpe_api_main;
1690 vnet_main_t *vnm = vnet_get_main ();
1691 vl_api_want_ip6_nd_events_reply_t *rmp;
1692 vl_api_ip6_nd_event_t *event;
1695 if (mp->enable_disable)
1697 pool_get (am->nd_events, event);
1698 memset (event, 0, sizeof (*event));
1700 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
1701 event->client_index = mp->client_index;
1702 event->context = mp->context;
1703 clib_memcpy (event->address, mp->address, 16);
1704 event->pid = mp->pid;
1705 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
1708 rv = vnet_add_del_ip6_nd_change_event
1709 (vnm, nd_change_data_callback,
1710 mp->pid, mp->address /* addr, in net byte order */ ,
1711 vpe_resolver_process_node.index,
1712 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
1716 rv = vnet_add_del_ip6_nd_change_event
1717 (vnm, nd_change_delete_callback,
1718 mp->pid, mp->address /* addr, in net byte order */ ,
1719 vpe_resolver_process_node.index,
1720 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1722 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
1725 static void vl_api_input_acl_set_interface_t_handler
1726 (vl_api_input_acl_set_interface_t * mp)
1728 vlib_main_t *vm = vlib_get_main ();
1729 vl_api_input_acl_set_interface_reply_t *rmp;
1731 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
1733 ip4_table_index = ntohl (mp->ip4_table_index);
1734 ip6_table_index = ntohl (mp->ip6_table_index);
1735 l2_table_index = ntohl (mp->l2_table_index);
1736 sw_if_index = ntohl (mp->sw_if_index);
1738 VALIDATE_SW_IF_INDEX (mp);
1740 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
1741 ip6_table_index, l2_table_index, mp->is_add);
1743 BAD_SW_IF_INDEX_LABEL;
1745 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
1749 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
1753 api_main_t *am = &api_main;
1754 vlib_main_t *vm = vlib_get_main ();
1756 vl_api_get_node_graph_reply_t *rmp;
1758 pthread_mutex_lock (&am->vlib_rp->mutex);
1759 oldheap = svm_push_data_heap (am->vlib_rp);
1762 * Keep the number of memcpy ops to a minimum (e.g. 1).
1764 vec_validate (vector, 16384);
1765 vec_reset_length (vector);
1768 vector = vlib_node_serialize (&vm->node_main, vector,
1769 (u32) ~ 0 /* all threads */ ,
1770 1 /* include nexts */ ,
1771 1 /* include stats */ );
1773 svm_pop_heap (oldheap);
1774 pthread_mutex_unlock (&am->vlib_rp->mutex);
1777 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
1779 rmp->reply_in_shmem = (uword) vector;
1785 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1788 vl_api_ioam_enable_reply_t *rmp;
1789 clib_error_t *error;
1791 /* Ignoring the profile id as currently a single profile
1793 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1794 mp->seqno, mp->analyse);
1797 clib_error_report (error);
1798 rv = clib_error_get_code (error);
1801 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1805 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1808 vl_api_ioam_disable_reply_t *rmp;
1809 clib_error_t *error;
1811 error = clear_ioam_rewrite_fn ();
1814 clib_error_report (error);
1815 rv = clib_error_get_code (error);
1818 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1822 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
1824 vl_api_pg_create_interface_reply_t *rmp;
1827 pg_main_t *pg = &pg_main;
1828 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
1829 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
1832 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
1834 rmp->sw_if_index = ntohl(pi->sw_if_index);
1840 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
1842 vl_api_pg_capture_reply_t *rmp;
1845 vnet_main_t *vnm = vnet_get_main ();
1846 vnet_interface_main_t *im = &vnm->interface_main;
1847 vnet_hw_interface_t *hi = 0;
1849 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
1850 u32 hw_if_index = ~0;
1851 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
1854 vec_free (intf_name);
1856 if (hw_if_index != ~0)
1858 pg_capture_args_t _a, *a = &_a;
1860 u32 len = ntohl (mp->pcap_name_length);
1861 u8 *pcap_file_name = vec_new (u8, len);
1862 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
1864 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
1865 a->hw_if_index = hw_if_index;
1866 a->dev_instance = hi->dev_instance;
1867 a->is_enabled = mp->is_enabled;
1868 a->pcap_file_name = pcap_file_name;
1869 a->count = ntohl (mp->count);
1871 clib_error_t *e = pg_capture (a);
1874 clib_error_report (e);
1875 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
1878 vec_free (pcap_file_name);
1880 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
1884 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
1886 vl_api_pg_enable_disable_reply_t *rmp;
1889 pg_main_t *pg = &pg_main;
1890 u32 stream_index = ~0;
1892 int is_enable = mp->is_enabled != 0;
1893 u32 len = ntohl (mp->stream_name_length) - 1;
1897 u8 *stream_name = vec_new (u8, len);
1898 clib_memcpy (stream_name, mp->stream_name, len);
1899 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
1902 vec_free (stream_name);
1905 pg_enable_disable (stream_index, is_enable);
1907 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
1911 vl_api_ip_source_and_port_range_check_add_del_t_handler
1912 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1914 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1917 u8 is_ipv6 = mp->is_ipv6;
1918 u8 is_add = mp->is_add;
1919 u8 mask_length = mp->mask_length;
1920 ip4_address_t ip4_addr;
1921 ip6_address_t ip6_addr;
1923 u16 *high_ports = 0;
1925 u16 tmp_low, tmp_high;
1929 // Validate port range
1930 num_ranges = mp->number_of_ranges;
1931 if (num_ranges > 32)
1932 { // This is size of array in VPE.API
1933 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1937 vec_reset_length (low_ports);
1938 vec_reset_length (high_ports);
1940 for (i = 0; i < num_ranges; i++)
1942 tmp_low = mp->low_ports[i];
1943 tmp_high = mp->high_ports[i];
1944 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1945 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1946 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1948 rv = VNET_API_ERROR_INVALID_VALUE;
1951 vec_add1 (low_ports, tmp_low);
1952 vec_add1 (high_ports, tmp_high + 1);
1955 // Validate mask_length
1956 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
1958 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
1962 vrf_id = ntohl (mp->vrf_id);
1966 rv = VNET_API_ERROR_INVALID_VALUE;
1973 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
1974 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
1978 high_ports, is_add);
1982 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
1983 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
1987 high_ports, is_add);
1991 vec_free (low_ports);
1992 vec_free (high_ports);
1993 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1997 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1998 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
2000 vlib_main_t *vm = vlib_get_main ();
2001 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
2002 ip4_main_t *im = &ip4_main;
2005 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2006 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2010 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
2011 ntohl (mp->tcp_out_vrf_id);
2012 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
2013 ntohl (mp->udp_out_vrf_id);
2014 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
2015 ntohl (mp->tcp_in_vrf_id);
2016 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
2017 ntohl (mp->udp_in_vrf_id);
2020 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
2022 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
2024 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
2028 rv = VNET_API_ERROR_INVALID_VALUE;
2032 fib_index[i] = p[0];
2037 sw_if_index = ntohl (mp->sw_if_index);
2039 VALIDATE_SW_IF_INDEX (mp);
2042 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
2045 BAD_SW_IF_INDEX_LABEL;
2048 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
2052 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
2054 vl_api_delete_subif_reply_t *rmp;
2057 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
2059 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
2063 vl_api_punt_t_handler (vl_api_punt_t * mp)
2065 vl_api_punt_reply_t *rmp;
2066 vlib_main_t *vm = vlib_get_main ();
2068 clib_error_t *error;
2070 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
2071 ntohs (mp->l4_port), mp->is_add);
2075 clib_error_report (error);
2078 REPLY_MACRO (VL_API_PUNT_REPLY);
2082 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
2084 vl_api_feature_enable_disable_reply_t *rmp;
2086 u8 *arc_name, *feature_name;
2088 VALIDATE_SW_IF_INDEX (mp);
2090 arc_name = format (0, "%s%c", mp->arc_name, 0);
2091 feature_name = format (0, "%s%c", mp->feature_name, 0);
2093 vnet_feature_registration_t *reg;
2095 vnet_get_feature_reg ((const char *) arc_name,
2096 (const char *) feature_name);
2098 rv = VNET_API_ERROR_INVALID_VALUE;
2102 clib_error_t *error = 0;
2104 sw_if_index = ntohl (mp->sw_if_index);
2105 if (reg->enable_disable_cb)
2106 error = reg->enable_disable_cb (sw_if_index, mp->enable);
2108 vnet_feature_enable_disable ((const char *) arc_name,
2109 (const char *) feature_name,
2110 sw_if_index, mp->enable, 0, 0);
2113 clib_error_report (error);
2114 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
2118 vec_free (feature_name);
2119 vec_free (arc_name);
2121 BAD_SW_IF_INDEX_LABEL;
2123 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
2126 #define BOUNCE_HANDLER(nn) \
2127 static void vl_api_##nn##_t_handler ( \
2128 vl_api_##nn##_t *mp) \
2130 vpe_client_registration_t *reg; \
2131 vpe_api_main_t * vam = &vpe_api_main; \
2132 unix_shared_memory_queue_t * q; \
2134 /* One registration only... */ \
2135 pool_foreach(reg, vam->nn##_registrations, \
2137 q = vl_api_client_index_to_input_queue (reg->client_index); \
2140 * If the queue is stuffed, turf the msg and complain \
2141 * It's unlikely that the intended recipient is \
2142 * alive; avoid deadlock at all costs. \
2144 if (q->cursize == q->maxsize) { \
2145 clib_warning ("ERROR: receiver queue full, drop msg"); \
2146 vl_msg_api_free (mp); \
2149 vl_msg_api_send_shmem (q, (u8 *)&mp); \
2153 vl_msg_api_free (mp); \
2156 static void setup_message_id_table (api_main_t * am);
2160 * Add vpe's API message handlers to the table.
2161 * vlib has alread mapped shared memory and
2162 * added the client registration handlers.
2163 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
2165 static clib_error_t *
2166 vpe_api_hookup (vlib_main_t * vm)
2168 api_main_t *am = &api_main;
2171 vl_msg_api_set_handlers(VL_API_##N, #n, \
2172 vl_api_##n##_t_handler, \
2174 vl_api_##n##_t_endian, \
2175 vl_api_##n##_t_print, \
2176 sizeof(vl_api_##n##_t), 1);
2177 foreach_vpe_api_msg;
2181 * Trace space for classifier mask+match
2183 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
2184 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
2185 += 5 * sizeof (u32x4);
2186 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
2189 * Thread-safe API messages
2191 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
2192 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
2195 * Set up the (msg_name, crc, message-id) table
2197 setup_message_id_table (am);
2202 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
2204 static clib_error_t *
2205 vpe_api_init (vlib_main_t * vm)
2207 vpe_api_main_t *am = &vpe_api_main;
2210 am->vnet_main = vnet_get_main ();
2211 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
2212 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2213 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2214 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2215 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2216 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
2217 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
2220 vl_set_memory_region_name ("/vpe-api");
2221 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
2226 VLIB_INIT_FUNCTION (vpe_api_init);
2229 static clib_error_t *
2230 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
2233 u64 baseva, size, pvt_heap_size;
2235 const int max_buf_size = 4096;
2237 struct passwd _pw, *pw;
2238 struct group _grp, *grp;
2240 buf = vec_new (char, 128);
2241 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2243 if (unformat (input, "prefix %s", &chroot_path))
2245 vec_add1 (chroot_path, 0);
2246 vl_set_memory_root_path ((char *) chroot_path);
2248 else if (unformat (input, "uid %d", &uid))
2249 vl_set_memory_uid (uid);
2250 else if (unformat (input, "gid %d", &gid))
2251 vl_set_memory_gid (gid);
2252 else if (unformat (input, "baseva %llx", &baseva))
2253 vl_set_global_memory_baseva (baseva);
2254 else if (unformat (input, "global-size %lldM", &size))
2255 vl_set_global_memory_size (size * (1ULL << 20));
2256 else if (unformat (input, "global-size %lldG", &size))
2257 vl_set_global_memory_size (size * (1ULL << 30));
2258 else if (unformat (input, "global-size %lld", &size))
2259 vl_set_global_memory_size (size);
2260 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
2261 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2262 else if (unformat (input, "global-pvt-heap-size size %lld",
2264 vl_set_global_pvt_heap_size (pvt_heap_size);
2265 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
2266 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2267 else if (unformat (input, "api-pvt-heap-size size %lld",
2269 vl_set_api_pvt_heap_size (pvt_heap_size);
2270 else if (unformat (input, "api-size %lldM", &size))
2271 vl_set_api_memory_size (size * (1ULL << 20));
2272 else if (unformat (input, "api-size %lldG", &size))
2273 vl_set_api_memory_size (size * (1ULL << 30));
2274 else if (unformat (input, "api-size %lld", &size))
2275 vl_set_api_memory_size (size);
2276 else if (unformat (input, "uid %s", &s))
2278 /* lookup the username */
2281 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
2282 && (vec_len (buf) <= max_buf_size))
2284 vec_resize (buf, vec_len (buf) * 2);
2288 e = clib_error_return_code (0, rv,
2289 CLIB_ERROR_ERRNO_VALID |
2291 "cannot fetch username %s", s);
2299 clib_error_return_fatal (0, "username %s does not exist", s);
2305 vl_set_memory_uid (pw->pw_uid);
2307 else if (unformat (input, "gid %s", &s))
2309 /* lookup the group name */
2312 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
2313 && (vec_len (buf) <= max_buf_size))
2315 vec_resize (buf, vec_len (buf) * 2);
2319 e = clib_error_return_code (0, rv,
2320 CLIB_ERROR_ERRNO_VALID |
2322 "cannot fetch group %s", s);
2329 e = clib_error_return_fatal (0, "group %s does not exist", s);
2336 vl_set_memory_gid (grp->gr_gid);
2339 return clib_error_return (0, "unknown input `%U'",
2340 format_unformat_error, input);
2345 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
2348 get_unformat_vnet_sw_interface (void)
2350 return (void *) &unformat_vnet_sw_interface;
2354 format_arp_event (u8 * s, va_list * args)
2356 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
2358 s = format (s, "pid %d: ", event->pid);
2360 s = format (s, "bd mac/ip4 binding events");
2362 s = format (s, "resolution for %U", format_ip4_address, &event->address);
2367 format_nd_event (u8 * s, va_list * args)
2369 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
2371 s = format (s, "pid %d: ", event->pid);
2373 s = format (s, "bd mac/ip6 binding events");
2375 s = format (s, "resolution for %U", format_ip6_address, event->address);
2379 static clib_error_t *
2380 show_ip_arp_nd_events_fn (vlib_main_t * vm,
2381 unformat_input_t * input, vlib_cli_command_t * cmd)
2383 vpe_api_main_t *am = &vpe_api_main;
2384 vl_api_ip4_arp_event_t *arp_event;
2385 vl_api_ip6_nd_event_t *nd_event;
2387 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
2389 vlib_cli_output (vm, "No active arp or nd event registrations");
2394 pool_foreach (arp_event, am->arp_events,
2396 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
2399 pool_foreach (nd_event, am->nd_events,
2401 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
2409 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
2410 .path = "show arp-nd-event registrations",
2411 .function = show_ip_arp_nd_events_fn,
2412 .short_help = "Show ip4 arp and ip6 nd event registrations",
2416 #define vl_msg_name_crc_list
2417 #include <vpp/api/vpe_all_api_h.h>
2418 #undef vl_msg_name_crc_list
2421 setup_message_id_table (api_main_t * am)
2423 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2424 foreach_vl_msg_name_crc_memclnt;
2425 foreach_vl_msg_name_crc_vpe;
2431 * fd.io coding-style-patch-verification: ON
2434 * eval: (c-set-style "gnu")