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 hw_if_index, 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 hw_if_index = ntohl (mp->sw_if_index);
510 hi = vnet_get_hw_interface (vnm, hw_if_index);
512 id = ntohl (mp->vlan_id);
513 if (id == 0 || id > 4095)
515 rv = VNET_API_ERROR_INVALID_VLAN;
519 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
521 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
524 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
528 kp = clib_mem_alloc (sizeof (*kp));
529 *kp = sup_and_sub_key;
531 memset (&template, 0, sizeof (template));
532 template.type = VNET_SW_INTERFACE_TYPE_SUB;
533 template.sup_sw_if_index = hi->sw_if_index;
534 template.sub.id = id;
535 template.sub.eth.raw_flags = 0;
536 template.sub.eth.flags.one_tag = 1;
537 template.sub.eth.outer_vlan_id = id;
538 template.sub.eth.flags.exact_match = 1;
540 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
543 clib_error_report (error);
544 rv = VNET_API_ERROR_INVALID_REGISTRATION;
547 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
548 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
550 BAD_SW_IF_INDEX_LABEL;
553 q = vl_api_client_index_to_input_queue (mp->client_index);
557 rmp = vl_msg_api_alloc (sizeof (*rmp));
558 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
559 rmp->context = mp->context;
560 rmp->retval = ntohl (rv);
561 rmp->sw_if_index = ntohl (sw_if_index);
562 vl_msg_api_send_shmem (q, (u8 *) & rmp);
566 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
568 vl_api_create_subif_reply_t *rmp;
569 vnet_main_t *vnm = vnet_get_main ();
570 u32 sw_if_index = ~0;
573 vnet_sw_interface_t *si;
574 vnet_hw_interface_t *hi;
575 vnet_sw_interface_t template;
577 vnet_interface_main_t *im = &vnm->interface_main;
582 VALIDATE_SW_IF_INDEX (mp);
584 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
585 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
587 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
589 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
593 sw_if_index = si->sw_if_index;
594 sub_id = ntohl (mp->sub_id);
596 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
598 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
602 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
603 sw_if_index, sub_id);
604 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
608 kp = clib_mem_alloc (sizeof (*kp));
609 *kp = sup_and_sub_key;
611 memset (&template, 0, sizeof (template));
612 template.type = VNET_SW_INTERFACE_TYPE_SUB;
613 template.sup_sw_if_index = sw_if_index;
614 template.sub.id = sub_id;
615 template.sub.eth.flags.no_tags = mp->no_tags;
616 template.sub.eth.flags.one_tag = mp->one_tag;
617 template.sub.eth.flags.two_tags = mp->two_tags;
618 template.sub.eth.flags.dot1ad = mp->dot1ad;
619 template.sub.eth.flags.exact_match = mp->exact_match;
620 template.sub.eth.flags.default_sub = mp->default_sub;
621 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
622 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
623 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
624 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
626 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
629 clib_error_report (error);
630 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
634 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
635 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
637 BAD_SW_IF_INDEX_LABEL;
642 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
644 rmp->sw_if_index = ntohl(sw_if_index);
650 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
652 vl_api_proxy_arp_add_del_reply_t *rmp;
655 ip4_main_t *im = &ip4_main;
656 stats_main_t *sm = &stats_main;
657 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
658 ip4_address_t * hi_addr,
659 u32 fib_index, int is_del);
662 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
664 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
668 rv = VNET_API_ERROR_NO_SUCH_FIB;
674 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
675 (ip4_address_t *) mp->hi_address,
676 fib_index, mp->is_add == 0);
680 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
684 vl_api_proxy_arp_intfc_enable_disable_t_handler
685 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
688 vnet_main_t *vnm = vnet_get_main ();
689 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
690 vnet_sw_interface_t *si;
693 VALIDATE_SW_IF_INDEX (mp);
695 sw_if_index = ntohl (mp->sw_if_index);
697 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
699 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
703 si = vnet_get_sw_interface (vnm, sw_if_index);
707 if (mp->enable_disable)
708 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
710 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
712 BAD_SW_IF_INDEX_LABEL;
715 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
719 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
722 vpe_main_t *rm = &vpe_main;
723 ip4_main_t *im4 = &ip4_main;
724 ip6_main_t *im6 = &ip6_main;
725 ip_lookup_main_t *lm;
731 u32 adj_index, sw_if_index;
732 vl_api_is_address_reachable_t *rmp;
734 unix_shared_memory_queue_t *q;
736 q = vl_api_client_index_to_input_queue (mp->client_index);
739 increment_missing_api_client_counter (rm->vlib_main);
743 rmp = vl_msg_api_alloc (sizeof (*rmp));
744 clib_memcpy (rmp, mp, sizeof (*rmp));
746 sw_if_index = mp->next_hop_sw_if_index;
747 clib_memcpy (&addr, mp->address, sizeof (addr));
750 lm = &im6->lookup_main;
751 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
755 lm = &im4->lookup_main;
757 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
764 adj = ip_get_adjacency (lm, adj_index);
766 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
767 && adj->rewrite_header.sw_if_index == sw_if_index)
773 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
774 && adj->rewrite_header.sw_if_index == sw_if_index)
777 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
779 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
781 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
790 vl_msg_api_send_shmem (q, (u8 *) & rmp);
795 vl_api_sw_interface_set_mpls_enable_t_handler
796 (vl_api_sw_interface_set_mpls_enable_t * mp)
798 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
801 VALIDATE_SW_IF_INDEX (mp);
803 mpls_sw_interface_enable_disable (&mpls_main,
804 ntohl (mp->sw_if_index), mp->enable);
806 BAD_SW_IF_INDEX_LABEL;
807 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
811 send_oam_event (oam_target_t * t)
813 vpe_api_main_t *vam = &vpe_api_main;
814 unix_shared_memory_queue_t *q;
815 vpe_client_registration_t *reg;
816 vl_api_oam_event_t *mp;
819 pool_foreach(reg, vam->oam_events_registrations,
821 q = vl_api_client_index_to_input_queue (reg->client_index);
824 mp = vl_msg_api_alloc (sizeof (*mp));
825 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
826 clib_memcpy (mp->dst_address, &t->dst_address,
827 sizeof (mp->dst_address));
828 mp->state = t->state;
829 vl_msg_api_send_shmem (q, (u8 *)&mp);
836 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
838 vl_api_oam_add_del_reply_t *rmp;
841 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
842 (ip4_address_t *) mp->dst_address,
843 ntohl (mp->vrf_id), (int) (mp->is_add));
845 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
849 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
851 stats_main_t *sm = &stats_main;
852 vnet_interface_main_t *im = sm->interface_main;
853 vl_api_vnet_summary_stats_reply_t *rmp;
854 vlib_combined_counter_main_t *cm;
857 u64 total_pkts[VLIB_N_RX_TX];
858 u64 total_bytes[VLIB_N_RX_TX];
860 unix_shared_memory_queue_t *q =
861 vl_api_client_index_to_input_queue (mp->client_index);
866 rmp = vl_msg_api_alloc (sizeof (*rmp));
867 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
868 rmp->context = mp->context;
871 memset (total_pkts, 0, sizeof (total_pkts));
872 memset (total_bytes, 0, sizeof (total_bytes));
874 vnet_interface_counter_lock (im);
876 vec_foreach (cm, im->combined_sw_if_counters)
878 which = cm - im->combined_sw_if_counters;
880 for (i = 0; i < vec_len (cm->maxi); i++)
882 vlib_get_combined_counter (cm, i, &v);
883 total_pkts[which] += v.packets;
884 total_bytes[which] += v.bytes;
887 vnet_interface_counter_unlock (im);
889 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
890 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
891 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
892 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
894 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
896 vl_msg_api_send_shmem (q, (u8 *) & rmp);
900 typedef CLIB_PACKED (struct {
901 ip4_address_t address;
902 u32 address_length: 6;
908 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
910 vnet_main_t *vnm = vnet_get_main ();
911 vnet_interface_main_t *im = &vnm->interface_main;
912 ip4_main_t *im4 = &ip4_main;
913 static u32 *sw_if_indices_to_shut;
914 stats_main_t *sm = &stats_main;
915 fib_table_t *fib_table;
919 int rv = VNET_API_ERROR_NO_SUCH_FIB;
920 u32 target_fib_id = ntohl (mp->vrf_id);
922 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
925 pool_foreach (fib_table, im4->fibs,
927 fib = &fib_table->v4;
928 vnet_sw_interface_t * si;
930 if (fib->table_id != target_fib_id)
933 /* remove any mpls encap/decap labels */
934 mpls_fib_reset_labels (fib->table_id);
936 /* remove any proxy arps in this fib */
937 vnet_proxy_arp_fib_reset (fib->table_id);
939 /* Set the flow hash for this fib to the default */
940 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
942 vec_reset_length (sw_if_indices_to_shut);
944 /* Shut down interfaces in this FIB / clean out intfc routes */
945 pool_foreach (si, im->sw_interfaces,
947 u32 sw_if_index = si->sw_if_index;
949 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
950 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
952 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
955 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
956 sw_if_index = sw_if_indices_to_shut[i];
958 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
959 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
960 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
963 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
967 })); /* pool_foreach (fib) */
975 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
977 vnet_main_t *vnm = vnet_get_main ();
978 vnet_interface_main_t *im = &vnm->interface_main;
979 ip6_main_t *im6 = &ip6_main;
980 stats_main_t *sm = &stats_main;
981 static u32 *sw_if_indices_to_shut;
982 fib_table_t *fib_table;
986 int rv = VNET_API_ERROR_NO_SUCH_FIB;
987 u32 target_fib_id = ntohl (mp->vrf_id);
989 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
992 pool_foreach (fib_table, im6->fibs,
994 vnet_sw_interface_t * si;
995 fib = &(fib_table->v6);
997 if (fib->table_id != target_fib_id)
1000 vec_reset_length (sw_if_indices_to_shut);
1002 /* Shut down interfaces in this FIB / clean out intfc routes */
1003 pool_foreach (si, im->sw_interfaces,
1005 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1007 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1010 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1011 sw_if_index = sw_if_indices_to_shut[i];
1013 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1014 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1015 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1018 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1022 })); /* pool_foreach (fib) */
1030 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1033 vl_api_reset_fib_reply_t *rmp;
1036 rv = ip6_reset_fib_t_handler (mp);
1038 rv = ip4_reset_fib_t_handler (mp);
1040 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1044 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1046 vl_api_create_loopback_reply_t *rmp;
1050 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1053 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1055 rmp->sw_if_index = ntohl (sw_if_index);
1061 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1063 vl_api_delete_loopback_reply_t *rmp;
1067 sw_if_index = ntohl (mp->sw_if_index);
1068 rv = vnet_delete_loopback_interface (sw_if_index);
1070 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1074 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1076 vl_api_control_ping_reply_t *rmp;
1080 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1082 rmp->vpe_pid = ntohl (getpid());
1088 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1090 u8 **shmem_vecp = (u8 **) arg;
1093 api_main_t *am = &api_main;
1096 shmem_vec = *shmem_vecp;
1098 offset = vec_len (shmem_vec);
1100 pthread_mutex_lock (&am->vlib_rp->mutex);
1101 oldheap = svm_push_data_heap (am->vlib_rp);
1103 vec_validate (shmem_vec, offset + buffer_bytes - 1);
1105 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
1107 svm_pop_heap (oldheap);
1108 pthread_mutex_unlock (&am->vlib_rp->mutex);
1110 *shmem_vecp = shmem_vec;
1115 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
1117 vl_api_cli_reply_t *rp;
1118 unix_shared_memory_queue_t *q;
1119 vlib_main_t *vm = vlib_get_main ();
1120 api_main_t *am = &api_main;
1121 unformat_input_t input;
1125 q = vl_api_client_index_to_input_queue (mp->client_index);
1129 rp = vl_msg_api_alloc (sizeof (*rp));
1130 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
1131 rp->context = mp->context;
1133 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
1135 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
1137 pthread_mutex_lock (&am->vlib_rp->mutex);
1138 oldheap = svm_push_data_heap (am->vlib_rp);
1140 vec_add1 (shmem_vec, 0);
1142 svm_pop_heap (oldheap);
1143 pthread_mutex_unlock (&am->vlib_rp->mutex);
1145 rp->reply_in_shmem = (uword) shmem_vec;
1147 vl_msg_api_send_shmem (q, (u8 *) & rp);
1151 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1153 u8 **mem_vecp = (u8 **) arg;
1154 u8 *mem_vec = *mem_vecp;
1155 u32 offset = vec_len (mem_vec);
1157 vec_validate (mem_vec, offset + buffer_bytes - 1);
1158 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
1159 *mem_vecp = mem_vec;
1163 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
1165 vl_api_cli_inband_reply_t *rmp;
1167 unix_shared_memory_queue_t *q;
1168 vlib_main_t *vm = vlib_get_main ();
1169 unformat_input_t input;
1172 q = vl_api_client_index_to_input_queue (mp->client_index);
1176 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
1177 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
1179 u32 len = vec_len (out_vec);
1181 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
1183 rmp->length = htonl (len);
1184 clib_memcpy (rmp->reply, out_vec, len);
1191 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
1194 vl_api_set_arp_neighbor_limit_reply_t *rmp;
1195 vnet_main_t *vnm = vnet_get_main ();
1196 clib_error_t *error;
1201 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
1203 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
1207 clib_error_report (error);
1208 rv = VNET_API_ERROR_UNSPECIFIED;
1212 rv = vnm->api_errno;
1215 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
1218 static void vl_api_classify_set_interface_ip_table_t_handler
1219 (vl_api_classify_set_interface_ip_table_t * mp)
1221 vlib_main_t *vm = vlib_get_main ();
1222 vl_api_classify_set_interface_ip_table_reply_t *rmp;
1224 u32 table_index, sw_if_index;
1226 table_index = ntohl (mp->table_index);
1227 sw_if_index = ntohl (mp->sw_if_index);
1229 VALIDATE_SW_IF_INDEX (mp);
1232 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
1234 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
1236 BAD_SW_IF_INDEX_LABEL;
1238 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
1241 static void vl_api_classify_set_interface_l2_tables_t_handler
1242 (vl_api_classify_set_interface_l2_tables_t * mp)
1244 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
1246 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
1249 ip4_table_index = ntohl (mp->ip4_table_index);
1250 ip6_table_index = ntohl (mp->ip6_table_index);
1251 other_table_index = ntohl (mp->other_table_index);
1252 sw_if_index = ntohl (mp->sw_if_index);
1254 VALIDATE_SW_IF_INDEX (mp);
1257 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
1261 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
1267 if (ip4_table_index != ~0 || ip6_table_index != ~0
1268 || other_table_index != ~0)
1274 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
1276 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
1279 BAD_SW_IF_INDEX_LABEL;
1281 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
1284 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1285 u32 sw_if_index, u32 enable);
1288 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1292 vl_api_l2_interface_efp_filter_reply_t *rmp;
1293 vnet_main_t *vnm = vnet_get_main ();
1295 // enable/disable the feature
1296 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
1297 rv = vnm->api_errno;
1299 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1303 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
1305 vl_api_show_version_reply_t *rmp;
1307 char *vpe_api_get_build_directory (void);
1308 char *vpe_api_get_version (void);
1309 char *vpe_api_get_build_date (void);
1311 unix_shared_memory_queue_t *q =
1312 vl_api_client_index_to_input_queue (mp->client_index);
1318 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
1320 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
1321 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
1322 ARRAY_LEN(rmp->build_directory)-1);
1323 strncpy ((char *) rmp->version, vpe_api_get_version(),
1324 ARRAY_LEN(rmp->version)-1);
1325 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
1326 ARRAY_LEN(rmp->build_date)-1);
1332 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
1334 vlib_main_t *vm = vlib_get_main ();
1335 vl_api_get_node_index_reply_t *rmp;
1338 u32 node_index = ~0;
1340 n = vlib_get_node_by_name (vm, mp->node_name);
1343 rv = VNET_API_ERROR_NO_SUCH_NODE;
1345 node_index = n->index;
1348 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1350 rmp->node_index = ntohl(node_index);
1356 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
1358 vlib_main_t *vm = vlib_get_main ();
1359 vl_api_get_next_index_reply_t *rmp;
1360 vlib_node_t *node, *next_node;
1362 u32 next_node_index = ~0, next_index = ~0;
1365 node = vlib_get_node_by_name (vm, mp->node_name);
1369 rv = VNET_API_ERROR_NO_SUCH_NODE;
1373 next_node = vlib_get_node_by_name (vm, mp->next_name);
1377 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1381 next_node_index = next_node->index;
1383 p = hash_get (node->next_slot_by_node, next_node_index);
1387 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1395 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
1397 rmp->next_index = ntohl(next_index);
1403 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
1405 vlib_main_t *vm = vlib_get_main ();
1406 vl_api_add_node_next_reply_t *rmp;
1407 vlib_node_t *n, *next;
1409 u32 next_index = ~0;
1411 n = vlib_get_node_by_name (vm, mp->node_name);
1415 rv = VNET_API_ERROR_NO_SUCH_NODE;
1419 next = vlib_get_node_by_name (vm, mp->next_name);
1422 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1424 next_index = vlib_node_add_next (vm, n->index, next->index);
1428 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1430 rmp->next_index = ntohl(next_index);
1435 static void send_vxlan_tunnel_details
1436 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1438 vl_api_vxlan_tunnel_details_t *rmp;
1439 ip4_main_t *im4 = &ip4_main;
1440 ip6_main_t *im6 = &ip6_main;
1441 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
1443 rmp = vl_msg_api_alloc (sizeof (*rmp));
1444 memset (rmp, 0, sizeof (*rmp));
1445 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
1448 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
1449 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
1450 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1454 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
1455 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
1456 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1458 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
1459 rmp->vni = htonl (t->vni);
1460 rmp->decap_next_index = htonl (t->decap_next_index);
1461 rmp->sw_if_index = htonl (t->sw_if_index);
1462 rmp->is_ipv6 = is_ipv6;
1463 rmp->context = context;
1465 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1469 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1471 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1473 vl_api_l2_patch_add_del_reply_t *rmp;
1474 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1478 VALIDATE_RX_SW_IF_INDEX (mp);
1479 VALIDATE_TX_SW_IF_INDEX (mp);
1481 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1482 ntohl (mp->tx_sw_if_index),
1483 (int) (mp->is_add != 0));
1485 BAD_RX_SW_IF_INDEX_LABEL;
1486 BAD_TX_SW_IF_INDEX_LABEL;
1488 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1491 static void send_vxlan_gpe_tunnel_details
1492 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1494 vl_api_vxlan_gpe_tunnel_details_t *rmp;
1495 ip4_main_t *im4 = &ip4_main;
1496 ip6_main_t *im6 = &ip6_main;
1497 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
1499 rmp = vl_msg_api_alloc (sizeof (*rmp));
1500 memset (rmp, 0, sizeof (*rmp));
1501 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
1504 memcpy (rmp->local, &(t->local.ip6), 16);
1505 memcpy (rmp->remote, &(t->remote.ip6), 16);
1506 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1507 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
1511 memcpy (rmp->local, &(t->local.ip4), 4);
1512 memcpy (rmp->remote, &(t->remote.ip4), 4);
1513 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1514 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
1516 rmp->vni = htonl (t->vni);
1517 rmp->protocol = t->protocol;
1518 rmp->sw_if_index = htonl (t->sw_if_index);
1519 rmp->is_ipv6 = is_ipv6;
1520 rmp->context = context;
1522 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1526 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1529 vl_api_interface_name_renumber_reply_t *rmp;
1532 VALIDATE_SW_IF_INDEX (mp);
1534 rv = vnet_interface_name_renumber
1535 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1537 BAD_SW_IF_INDEX_LABEL;
1539 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1543 arp_change_data_callback (u32 pool_index, u8 * new_mac,
1544 u32 sw_if_index, u32 address)
1546 vpe_api_main_t *am = &vpe_api_main;
1547 vlib_main_t *vm = am->vlib_main;
1548 vl_api_ip4_arp_event_t *event;
1549 static f64 arp_event_last_time;
1550 f64 now = vlib_time_now (vm);
1552 if (pool_is_free_index (am->arp_events, pool_index))
1555 event = pool_elt_at_index (am->arp_events, pool_index);
1557 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1559 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1563 if (sw_if_index == event->sw_if_index &&
1565 /* for BD case, also check IP address with 10 sec timeout */
1566 (address == event->address &&
1567 (now - arp_event_last_time) < 10.0)))
1572 arp_event_last_time = now;
1573 event->sw_if_index = sw_if_index;
1575 event->address = address;
1580 nd_change_data_callback (u32 pool_index, u8 * new_mac,
1581 u32 sw_if_index, ip6_address_t * address)
1583 vpe_api_main_t *am = &vpe_api_main;
1584 vlib_main_t *vm = am->vlib_main;
1585 vl_api_ip6_nd_event_t *event;
1586 static f64 nd_event_last_time;
1587 f64 now = vlib_time_now (vm);
1589 if (pool_is_free_index (am->nd_events, pool_index))
1592 event = pool_elt_at_index (am->nd_events, pool_index);
1595 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1597 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1601 if (sw_if_index == event->sw_if_index &&
1603 /* for BD case, also check IP address with 10 sec timeout */
1604 (ip6_address_is_equal (address,
1605 (ip6_address_t *) event->address) &&
1606 (now - nd_event_last_time) < 10.0)))
1611 nd_event_last_time = now;
1612 event->sw_if_index = sw_if_index;
1614 clib_memcpy (event->address, address, sizeof (event->address));
1619 arp_change_delete_callback (u32 pool_index, u8 * notused)
1621 vpe_api_main_t *am = &vpe_api_main;
1623 if (pool_is_free_index (am->arp_events, pool_index))
1626 pool_put_index (am->arp_events, pool_index);
1631 nd_change_delete_callback (u32 pool_index, u8 * notused)
1633 vpe_api_main_t *am = &vpe_api_main;
1635 if (pool_is_free_index (am->nd_events, pool_index))
1638 pool_put_index (am->nd_events, pool_index);
1643 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
1645 vpe_api_main_t *am = &vpe_api_main;
1646 vnet_main_t *vnm = vnet_get_main ();
1647 vl_api_want_ip4_arp_events_reply_t *rmp;
1648 vl_api_ip4_arp_event_t *event;
1651 if (mp->enable_disable)
1653 pool_get (am->arp_events, event);
1654 memset (event, 0, sizeof (*event));
1656 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
1657 event->client_index = mp->client_index;
1658 event->context = mp->context;
1659 event->address = mp->address;
1660 event->pid = mp->pid;
1661 if (mp->address == 0)
1664 rv = vnet_add_del_ip4_arp_change_event
1665 (vnm, arp_change_data_callback,
1666 mp->pid, &mp->address /* addr, in net byte order */ ,
1667 vpe_resolver_process_node.index,
1668 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
1672 rv = vnet_add_del_ip4_arp_change_event
1673 (vnm, arp_change_delete_callback,
1674 mp->pid, &mp->address /* addr, in net byte order */ ,
1675 vpe_resolver_process_node.index,
1676 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1678 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
1682 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
1684 vpe_api_main_t *am = &vpe_api_main;
1685 vnet_main_t *vnm = vnet_get_main ();
1686 vl_api_want_ip6_nd_events_reply_t *rmp;
1687 vl_api_ip6_nd_event_t *event;
1690 if (mp->enable_disable)
1692 pool_get (am->nd_events, event);
1693 memset (event, 0, sizeof (*event));
1695 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
1696 event->client_index = mp->client_index;
1697 event->context = mp->context;
1698 clib_memcpy (event->address, mp->address, 16);
1699 event->pid = mp->pid;
1700 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
1703 rv = vnet_add_del_ip6_nd_change_event
1704 (vnm, nd_change_data_callback,
1705 mp->pid, mp->address /* addr, in net byte order */ ,
1706 vpe_resolver_process_node.index,
1707 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
1711 rv = vnet_add_del_ip6_nd_change_event
1712 (vnm, nd_change_delete_callback,
1713 mp->pid, mp->address /* addr, in net byte order */ ,
1714 vpe_resolver_process_node.index,
1715 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1717 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
1720 static void vl_api_input_acl_set_interface_t_handler
1721 (vl_api_input_acl_set_interface_t * mp)
1723 vlib_main_t *vm = vlib_get_main ();
1724 vl_api_input_acl_set_interface_reply_t *rmp;
1726 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
1728 ip4_table_index = ntohl (mp->ip4_table_index);
1729 ip6_table_index = ntohl (mp->ip6_table_index);
1730 l2_table_index = ntohl (mp->l2_table_index);
1731 sw_if_index = ntohl (mp->sw_if_index);
1733 VALIDATE_SW_IF_INDEX (mp);
1735 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
1736 ip6_table_index, l2_table_index, mp->is_add);
1738 BAD_SW_IF_INDEX_LABEL;
1740 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
1744 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
1748 api_main_t *am = &api_main;
1749 vlib_main_t *vm = vlib_get_main ();
1751 vl_api_get_node_graph_reply_t *rmp;
1753 pthread_mutex_lock (&am->vlib_rp->mutex);
1754 oldheap = svm_push_data_heap (am->vlib_rp);
1757 * Keep the number of memcpy ops to a minimum (e.g. 1).
1759 vec_validate (vector, 16384);
1760 vec_reset_length (vector);
1763 vector = vlib_node_serialize (&vm->node_main, vector,
1764 (u32) ~ 0 /* all threads */ ,
1765 1 /* include nexts */ ,
1766 1 /* include stats */ );
1768 svm_pop_heap (oldheap);
1769 pthread_mutex_unlock (&am->vlib_rp->mutex);
1772 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
1774 rmp->reply_in_shmem = (uword) vector;
1780 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1783 vl_api_ioam_enable_reply_t *rmp;
1784 clib_error_t *error;
1786 /* Ignoring the profile id as currently a single profile
1788 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
1789 mp->seqno, mp->analyse);
1792 clib_error_report (error);
1793 rv = clib_error_get_code (error);
1796 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
1800 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
1803 vl_api_ioam_disable_reply_t *rmp;
1804 clib_error_t *error;
1806 error = clear_ioam_rewrite_fn ();
1809 clib_error_report (error);
1810 rv = clib_error_get_code (error);
1813 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
1817 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
1819 vl_api_pg_create_interface_reply_t *rmp;
1822 pg_main_t *pg = &pg_main;
1823 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
1824 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
1827 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
1829 rmp->sw_if_index = ntohl(pi->sw_if_index);
1835 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
1837 vl_api_pg_capture_reply_t *rmp;
1840 vnet_main_t *vnm = vnet_get_main ();
1841 vnet_interface_main_t *im = &vnm->interface_main;
1842 vnet_hw_interface_t *hi = 0;
1844 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
1845 u32 hw_if_index = ~0;
1846 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
1849 vec_free (intf_name);
1851 if (hw_if_index != ~0)
1853 pg_capture_args_t _a, *a = &_a;
1855 u32 len = ntohl (mp->pcap_name_length);
1856 u8 *pcap_file_name = vec_new (u8, len);
1857 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
1859 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
1860 a->hw_if_index = hw_if_index;
1861 a->dev_instance = hi->dev_instance;
1862 a->is_enabled = mp->is_enabled;
1863 a->pcap_file_name = pcap_file_name;
1864 a->count = ntohl (mp->count);
1866 clib_error_t *e = pg_capture (a);
1869 clib_error_report (e);
1870 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
1873 vec_free (pcap_file_name);
1875 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
1879 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
1881 vl_api_pg_enable_disable_reply_t *rmp;
1884 pg_main_t *pg = &pg_main;
1885 u32 stream_index = ~0;
1887 int is_enable = mp->is_enabled != 0;
1888 u32 len = ntohl (mp->stream_name_length) - 1;
1892 u8 *stream_name = vec_new (u8, len);
1893 clib_memcpy (stream_name, mp->stream_name, len);
1894 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
1897 vec_free (stream_name);
1900 pg_enable_disable (stream_index, is_enable);
1902 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
1906 vl_api_ip_source_and_port_range_check_add_del_t_handler
1907 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
1909 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
1912 u8 is_ipv6 = mp->is_ipv6;
1913 u8 is_add = mp->is_add;
1914 u8 mask_length = mp->mask_length;
1915 ip4_address_t ip4_addr;
1916 ip6_address_t ip6_addr;
1918 u16 *high_ports = 0;
1920 u16 tmp_low, tmp_high;
1924 // Validate port range
1925 num_ranges = mp->number_of_ranges;
1926 if (num_ranges > 32)
1927 { // This is size of array in VPE.API
1928 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1932 vec_reset_length (low_ports);
1933 vec_reset_length (high_ports);
1935 for (i = 0; i < num_ranges; i++)
1937 tmp_low = mp->low_ports[i];
1938 tmp_high = mp->high_ports[i];
1939 // If tmp_low <= tmp_high then only need to check tmp_low = 0
1940 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
1941 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
1943 rv = VNET_API_ERROR_INVALID_VALUE;
1946 vec_add1 (low_ports, tmp_low);
1947 vec_add1 (high_ports, tmp_high + 1);
1950 // Validate mask_length
1951 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
1953 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
1957 vrf_id = ntohl (mp->vrf_id);
1961 rv = VNET_API_ERROR_INVALID_VALUE;
1968 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
1969 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
1973 high_ports, is_add);
1977 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
1978 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
1982 high_ports, is_add);
1986 vec_free (low_ports);
1987 vec_free (high_ports);
1988 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
1992 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
1993 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
1995 vlib_main_t *vm = vlib_get_main ();
1996 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
1997 ip4_main_t *im = &ip4_main;
2000 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2001 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2005 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
2006 ntohl (mp->tcp_out_vrf_id);
2007 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
2008 ntohl (mp->udp_out_vrf_id);
2009 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
2010 ntohl (mp->tcp_in_vrf_id);
2011 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
2012 ntohl (mp->udp_in_vrf_id);
2015 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
2017 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
2019 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
2023 rv = VNET_API_ERROR_INVALID_VALUE;
2027 fib_index[i] = p[0];
2032 sw_if_index = ntohl (mp->sw_if_index);
2034 VALIDATE_SW_IF_INDEX (mp);
2037 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
2040 BAD_SW_IF_INDEX_LABEL;
2043 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
2047 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
2049 vl_api_delete_subif_reply_t *rmp;
2052 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
2054 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
2058 vl_api_punt_t_handler (vl_api_punt_t * mp)
2060 vl_api_punt_reply_t *rmp;
2061 vlib_main_t *vm = vlib_get_main ();
2063 clib_error_t *error;
2065 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
2066 ntohs (mp->l4_port), mp->is_add);
2070 clib_error_report (error);
2073 REPLY_MACRO (VL_API_PUNT_REPLY);
2077 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
2079 vl_api_feature_enable_disable_reply_t *rmp;
2081 u8 *arc_name, *feature_name;
2083 VALIDATE_SW_IF_INDEX (mp);
2085 arc_name = format (0, "%s%c", mp->arc_name, 0);
2086 feature_name = format (0, "%s%c", mp->feature_name, 0);
2088 vnet_feature_registration_t *reg;
2090 vnet_get_feature_reg ((const char *) arc_name,
2091 (const char *) feature_name);
2093 rv = VNET_API_ERROR_INVALID_VALUE;
2097 clib_error_t *error = 0;
2099 sw_if_index = ntohl (mp->sw_if_index);
2100 if (reg->enable_disable_cb)
2101 error = reg->enable_disable_cb (sw_if_index, mp->enable);
2103 vnet_feature_enable_disable ((const char *) arc_name,
2104 (const char *) feature_name,
2105 sw_if_index, mp->enable, 0, 0);
2108 clib_error_report (error);
2109 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
2113 vec_free (feature_name);
2114 vec_free (arc_name);
2116 BAD_SW_IF_INDEX_LABEL;
2118 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
2121 #define BOUNCE_HANDLER(nn) \
2122 static void vl_api_##nn##_t_handler ( \
2123 vl_api_##nn##_t *mp) \
2125 vpe_client_registration_t *reg; \
2126 vpe_api_main_t * vam = &vpe_api_main; \
2127 unix_shared_memory_queue_t * q; \
2129 /* One registration only... */ \
2130 pool_foreach(reg, vam->nn##_registrations, \
2132 q = vl_api_client_index_to_input_queue (reg->client_index); \
2135 * If the queue is stuffed, turf the msg and complain \
2136 * It's unlikely that the intended recipient is \
2137 * alive; avoid deadlock at all costs. \
2139 if (q->cursize == q->maxsize) { \
2140 clib_warning ("ERROR: receiver queue full, drop msg"); \
2141 vl_msg_api_free (mp); \
2144 vl_msg_api_send_shmem (q, (u8 *)&mp); \
2148 vl_msg_api_free (mp); \
2151 static void setup_message_id_table (api_main_t * am);
2155 * Add vpe's API message handlers to the table.
2156 * vlib has alread mapped shared memory and
2157 * added the client registration handlers.
2158 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
2160 static clib_error_t *
2161 vpe_api_hookup (vlib_main_t * vm)
2163 api_main_t *am = &api_main;
2166 vl_msg_api_set_handlers(VL_API_##N, #n, \
2167 vl_api_##n##_t_handler, \
2169 vl_api_##n##_t_endian, \
2170 vl_api_##n##_t_print, \
2171 sizeof(vl_api_##n##_t), 1);
2172 foreach_vpe_api_msg;
2176 * Trace space for classifier mask+match
2178 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
2179 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
2180 += 5 * sizeof (u32x4);
2181 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
2184 * Thread-safe API messages
2186 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
2187 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
2190 * Set up the (msg_name, crc, message-id) table
2192 setup_message_id_table (am);
2197 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
2199 static clib_error_t *
2200 vpe_api_init (vlib_main_t * vm)
2202 vpe_api_main_t *am = &vpe_api_main;
2205 am->vnet_main = vnet_get_main ();
2206 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
2207 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2208 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2209 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2210 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2211 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
2212 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
2215 vl_set_memory_region_name ("/vpe-api");
2216 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
2221 VLIB_INIT_FUNCTION (vpe_api_init);
2224 static clib_error_t *
2225 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
2228 u64 baseva, size, pvt_heap_size;
2230 const int max_buf_size = 4096;
2232 struct passwd _pw, *pw;
2233 struct group _grp, *grp;
2235 buf = vec_new (char, 128);
2236 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2238 if (unformat (input, "prefix %s", &chroot_path))
2240 vec_add1 (chroot_path, 0);
2241 vl_set_memory_root_path ((char *) chroot_path);
2243 else if (unformat (input, "uid %d", &uid))
2244 vl_set_memory_uid (uid);
2245 else if (unformat (input, "gid %d", &gid))
2246 vl_set_memory_gid (gid);
2247 else if (unformat (input, "baseva %llx", &baseva))
2248 vl_set_global_memory_baseva (baseva);
2249 else if (unformat (input, "global-size %lldM", &size))
2250 vl_set_global_memory_size (size * (1ULL << 20));
2251 else if (unformat (input, "global-size %lldG", &size))
2252 vl_set_global_memory_size (size * (1ULL << 30));
2253 else if (unformat (input, "global-size %lld", &size))
2254 vl_set_global_memory_size (size);
2255 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
2256 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2257 else if (unformat (input, "global-pvt-heap-size size %lld",
2259 vl_set_global_pvt_heap_size (pvt_heap_size);
2260 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
2261 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2262 else if (unformat (input, "api-pvt-heap-size size %lld",
2264 vl_set_api_pvt_heap_size (pvt_heap_size);
2265 else if (unformat (input, "api-size %lldM", &size))
2266 vl_set_api_memory_size (size * (1ULL << 20));
2267 else if (unformat (input, "api-size %lldG", &size))
2268 vl_set_api_memory_size (size * (1ULL << 30));
2269 else if (unformat (input, "api-size %lld", &size))
2270 vl_set_api_memory_size (size);
2271 else if (unformat (input, "uid %s", &s))
2273 /* lookup the username */
2276 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
2277 && (vec_len (buf) <= max_buf_size))
2279 vec_resize (buf, vec_len (buf) * 2);
2283 e = clib_error_return_code (0, rv,
2284 CLIB_ERROR_ERRNO_VALID |
2286 "cannot fetch username %s", s);
2294 clib_error_return_fatal (0, "username %s does not exist", s);
2300 vl_set_memory_uid (pw->pw_uid);
2302 else if (unformat (input, "gid %s", &s))
2304 /* lookup the group name */
2307 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
2308 && (vec_len (buf) <= max_buf_size))
2310 vec_resize (buf, vec_len (buf) * 2);
2314 e = clib_error_return_code (0, rv,
2315 CLIB_ERROR_ERRNO_VALID |
2317 "cannot fetch group %s", s);
2324 e = clib_error_return_fatal (0, "group %s does not exist", s);
2331 vl_set_memory_gid (grp->gr_gid);
2334 return clib_error_return (0, "unknown input `%U'",
2335 format_unformat_error, input);
2340 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
2343 get_unformat_vnet_sw_interface (void)
2345 return (void *) &unformat_vnet_sw_interface;
2349 format_arp_event (u8 * s, va_list * args)
2351 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
2353 s = format (s, "pid %d: ", event->pid);
2355 s = format (s, "bd mac/ip4 binding events");
2357 s = format (s, "resolution for %U", format_ip4_address, &event->address);
2362 format_nd_event (u8 * s, va_list * args)
2364 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
2366 s = format (s, "pid %d: ", event->pid);
2368 s = format (s, "bd mac/ip6 binding events");
2370 s = format (s, "resolution for %U", format_ip6_address, event->address);
2374 static clib_error_t *
2375 show_ip_arp_nd_events_fn (vlib_main_t * vm,
2376 unformat_input_t * input, vlib_cli_command_t * cmd)
2378 vpe_api_main_t *am = &vpe_api_main;
2379 vl_api_ip4_arp_event_t *arp_event;
2380 vl_api_ip6_nd_event_t *nd_event;
2382 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
2384 vlib_cli_output (vm, "No active arp or nd event registrations");
2389 pool_foreach (arp_event, am->arp_events,
2391 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
2394 pool_foreach (nd_event, am->nd_events,
2396 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
2404 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
2405 .path = "show arp-nd-event registrations",
2406 .function = show_ip_arp_nd_events_fn,
2407 .short_help = "Show ip4 arp and ip6 nd event registrations",
2411 #define vl_msg_name_crc_list
2412 #include <vpp/api/vpe_all_api_h.h>
2413 #undef vl_msg_name_crc_list
2416 setup_message_id_table (api_main_t * am)
2418 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2419 foreach_vl_msg_name_crc_memclnt;
2420 foreach_vl_msg_name_crc_vpe;
2426 * fd.io coding-style-patch-verification: ON
2429 * eval: (c-set-style "gnu")