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 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
132 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
133 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
134 _(SHOW_VERSION, show_version) \
135 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
136 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
137 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
138 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
139 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
140 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
141 _(DELETE_LOOPBACK, delete_loopback) \
142 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
143 _(GET_NODE_GRAPH, get_node_graph) \
144 _(IOAM_ENABLE, ioam_enable) \
145 _(IOAM_DISABLE, ioam_disable) \
146 _(GET_NEXT_INDEX, get_next_index) \
147 _(PG_CREATE_INTERFACE, pg_create_interface) \
148 _(PG_CAPTURE, pg_capture) \
149 _(PG_ENABLE_DISABLE, pg_enable_disable) \
150 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
151 ip_source_and_port_range_check_add_del) \
152 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
153 ip_source_and_port_range_check_interface_add_del) \
154 _(DELETE_SUBIF, delete_subif) \
156 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
159 #define QUOTE(x) QUOTE_(x)
162 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
163 RESOLVE_IP6_ADD_DEL_ROUTE,
166 static vlib_node_registration_t vpe_resolver_process_node;
167 vpe_api_main_t vpe_api_main;
169 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
170 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
172 /* Clean up all registrations belonging to the indicated client */
174 vl_api_memclnt_delete_callback (u32 client_index)
176 vpe_api_main_t *vam = &vpe_api_main;
177 vpe_client_registration_t *rp;
179 int stats_memclnt_delete_callback (u32 client_index);
181 stats_memclnt_delete_callback (client_index);
184 p = hash_get (vam->a##_registration_hash, client_index); \
186 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
187 pool_put (vam->a##_registrations, rp); \
188 hash_unset (vam->a##_registration_hash, client_index); \
190 foreach_registration_hash;
195 pub_sub_handler (oam_events, OAM_EVENTS);
197 #define RESOLUTION_EVENT 1
198 #define RESOLUTION_PENDING_EVENT 2
199 #define IP4_ARP_EVENT 3
200 #define IP6_ND_EVENT 4
202 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
204 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
207 handle_ip4_arp_event (u32 pool_index)
209 vpe_api_main_t *vam = &vpe_api_main;
210 vnet_main_t *vnm = vam->vnet_main;
211 vlib_main_t *vm = vam->vlib_main;
212 vl_api_ip4_arp_event_t *event;
213 vl_api_ip4_arp_event_t *mp;
214 unix_shared_memory_queue_t *q;
216 /* Client can cancel, die, etc. */
217 if (pool_is_free_index (vam->arp_events, pool_index))
220 event = pool_elt_at_index (vam->arp_events, pool_index);
222 q = vl_api_client_index_to_input_queue (event->client_index);
225 (void) vnet_add_del_ip4_arp_change_event
226 (vnm, arp_change_delete_callback,
227 event->pid, &event->address,
228 vpe_resolver_process_node.index, IP4_ARP_EVENT,
229 ~0 /* pool index, notused */ , 0 /* is_add */ );
233 if (q->cursize < q->maxsize)
235 mp = vl_msg_api_alloc (sizeof (*mp));
236 clib_memcpy (mp, event, sizeof (*mp));
237 vl_msg_api_send_shmem (q, (u8 *) & mp);
241 static f64 last_time;
243 * Throttle syslog msgs.
244 * It's pretty tempting to just revoke the registration...
246 if (vlib_time_now (vm) > last_time + 10.0)
248 clib_warning ("arp event for %U to pid %d: queue stuffed!",
249 format_ip4_address, &event->address, event->pid);
250 last_time = vlib_time_now (vm);
256 handle_ip6_nd_event (u32 pool_index)
258 vpe_api_main_t *vam = &vpe_api_main;
259 vnet_main_t *vnm = vam->vnet_main;
260 vlib_main_t *vm = vam->vlib_main;
261 vl_api_ip6_nd_event_t *event;
262 vl_api_ip6_nd_event_t *mp;
263 unix_shared_memory_queue_t *q;
265 /* Client can cancel, die, etc. */
266 if (pool_is_free_index (vam->nd_events, pool_index))
269 event = pool_elt_at_index (vam->nd_events, pool_index);
271 q = vl_api_client_index_to_input_queue (event->client_index);
274 (void) vnet_add_del_ip6_nd_change_event
275 (vnm, nd_change_delete_callback,
276 event->pid, &event->address,
277 vpe_resolver_process_node.index, IP6_ND_EVENT,
278 ~0 /* pool index, notused */ , 0 /* is_add */ );
282 if (q->cursize < q->maxsize)
284 mp = vl_msg_api_alloc (sizeof (*mp));
285 clib_memcpy (mp, event, sizeof (*mp));
286 vl_msg_api_send_shmem (q, (u8 *) & mp);
290 static f64 last_time;
292 * Throttle syslog msgs.
293 * It's pretty tempting to just revoke the registration...
295 if (vlib_time_now (vm) > last_time + 10.0)
297 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
298 format_ip6_address, &event->address, event->pid);
299 last_time = vlib_time_now (vm);
305 resolver_process (vlib_main_t * vm,
306 vlib_node_runtime_t * rt, vlib_frame_t * f)
309 uword *event_data = 0;
315 vlib_process_wait_for_event_or_clock (vm, timeout);
317 event_type = vlib_process_get_events (vm, &event_data);
321 case RESOLUTION_PENDING_EVENT:
325 case RESOLUTION_EVENT:
326 clib_warning ("resolver: BOGUS TYPE");
330 for (i = 0; i < vec_len (event_data); i++)
331 handle_ip4_arp_event (event_data[i]);
335 for (i = 0; i < vec_len (event_data); i++)
336 handle_ip6_nd_event (event_data[i]);
339 case ~0: /* timeout */
343 vec_reset_length (event_data);
345 return 0; /* or not */
349 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
350 .function = resolver_process,
351 .type = VLIB_NODE_TYPE_PROCESS,
352 .name = "vpe-route-resolver-process",
357 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
359 vl_api_sw_interface_set_vpath_reply_t *rmp;
361 u32 sw_if_index = ntohl (mp->sw_if_index);
363 VALIDATE_SW_IF_INDEX (mp);
365 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
366 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
367 sw_if_index, mp->enable, 0, 0);
368 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
369 sw_if_index, mp->enable, 0, 0);
370 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
371 sw_if_index, mp->enable, 0, 0);
372 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
373 sw_if_index, mp->enable, 0, 0);
375 BAD_SW_IF_INDEX_LABEL;
377 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
381 vl_api_sw_interface_set_vxlan_bypass_t_handler
382 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
384 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
386 u32 sw_if_index = ntohl (mp->sw_if_index);
388 VALIDATE_SW_IF_INDEX (mp);
392 /* not yet implemented */
395 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
396 sw_if_index, mp->enable, 0, 0);
398 BAD_SW_IF_INDEX_LABEL;
400 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
404 vl_api_sw_interface_set_l2_xconnect_t_handler
405 (vl_api_sw_interface_set_l2_xconnect_t * mp)
407 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
409 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
410 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
411 vlib_main_t *vm = vlib_get_main ();
412 vnet_main_t *vnm = vnet_get_main ();
414 VALIDATE_RX_SW_IF_INDEX (mp);
418 VALIDATE_TX_SW_IF_INDEX (mp);
419 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
420 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
424 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
427 BAD_RX_SW_IF_INDEX_LABEL;
428 BAD_TX_SW_IF_INDEX_LABEL;
430 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
434 vl_api_sw_interface_set_l2_bridge_t_handler
435 (vl_api_sw_interface_set_l2_bridge_t * mp)
437 bd_main_t *bdm = &bd_main;
438 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
440 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
441 u32 bd_id = ntohl (mp->bd_id);
445 vlib_main_t *vm = vlib_get_main ();
446 vnet_main_t *vnm = vnet_get_main ();
448 VALIDATE_RX_SW_IF_INDEX (mp);
450 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
454 //VALIDATE_TX_SW_IF_INDEX(mp);
455 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
456 rx_sw_if_index, bd_index, bvi, shg, 0);
460 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
463 BAD_RX_SW_IF_INDEX_LABEL;
465 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
469 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
471 bd_main_t *bdm = &bd_main;
472 vl_api_bd_ip_mac_add_del_reply_t *rmp;
474 u32 bd_id = ntohl (mp->bd_id);
478 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
481 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
486 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
487 mp->mac_address, mp->is_ipv6, mp->is_add))
488 rv = VNET_API_ERROR_UNSPECIFIED;
491 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
495 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
497 vl_api_create_vlan_subif_reply_t *rmp;
498 vnet_main_t *vnm = vnet_get_main ();
499 u32 hw_if_index, sw_if_index = (u32) ~ 0;
500 vnet_hw_interface_t *hi;
503 vnet_sw_interface_t template;
505 vnet_interface_main_t *im = &vnm->interface_main;
508 unix_shared_memory_queue_t *q;
511 VALIDATE_SW_IF_INDEX (mp);
513 hw_if_index = ntohl (mp->sw_if_index);
514 hi = vnet_get_hw_interface (vnm, hw_if_index);
516 id = ntohl (mp->vlan_id);
517 if (id == 0 || id > 4095)
519 rv = VNET_API_ERROR_INVALID_VLAN;
523 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
525 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
528 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
532 kp = clib_mem_alloc (sizeof (*kp));
533 *kp = sup_and_sub_key;
535 memset (&template, 0, sizeof (template));
536 template.type = VNET_SW_INTERFACE_TYPE_SUB;
537 template.sup_sw_if_index = hi->sw_if_index;
538 template.sub.id = id;
539 template.sub.eth.raw_flags = 0;
540 template.sub.eth.flags.one_tag = 1;
541 template.sub.eth.outer_vlan_id = id;
542 template.sub.eth.flags.exact_match = 1;
544 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
547 clib_error_report (error);
548 rv = VNET_API_ERROR_INVALID_REGISTRATION;
551 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
552 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
554 BAD_SW_IF_INDEX_LABEL;
557 q = vl_api_client_index_to_input_queue (mp->client_index);
561 rmp = vl_msg_api_alloc (sizeof (*rmp));
562 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
563 rmp->context = mp->context;
564 rmp->retval = ntohl (rv);
565 rmp->sw_if_index = ntohl (sw_if_index);
566 vl_msg_api_send_shmem (q, (u8 *) & rmp);
570 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
572 vl_api_create_subif_reply_t *rmp;
573 vnet_main_t *vnm = vnet_get_main ();
574 u32 sw_if_index = ~0;
577 vnet_sw_interface_t *si;
578 vnet_hw_interface_t *hi;
579 vnet_sw_interface_t template;
581 vnet_interface_main_t *im = &vnm->interface_main;
586 VALIDATE_SW_IF_INDEX (mp);
588 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
589 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
591 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
593 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
597 sw_if_index = si->sw_if_index;
598 sub_id = ntohl (mp->sub_id);
600 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
602 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
606 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
607 sw_if_index, sub_id);
608 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
612 kp = clib_mem_alloc (sizeof (*kp));
613 *kp = sup_and_sub_key;
615 memset (&template, 0, sizeof (template));
616 template.type = VNET_SW_INTERFACE_TYPE_SUB;
617 template.sup_sw_if_index = sw_if_index;
618 template.sub.id = sub_id;
619 template.sub.eth.flags.no_tags = mp->no_tags;
620 template.sub.eth.flags.one_tag = mp->one_tag;
621 template.sub.eth.flags.two_tags = mp->two_tags;
622 template.sub.eth.flags.dot1ad = mp->dot1ad;
623 template.sub.eth.flags.exact_match = mp->exact_match;
624 template.sub.eth.flags.default_sub = mp->default_sub;
625 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
626 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
627 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
628 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
630 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
633 clib_error_report (error);
634 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
638 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
639 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
641 BAD_SW_IF_INDEX_LABEL;
646 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
648 rmp->sw_if_index = ntohl(sw_if_index);
654 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
656 vl_api_proxy_arp_add_del_reply_t *rmp;
659 ip4_main_t *im = &ip4_main;
660 stats_main_t *sm = &stats_main;
661 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
662 ip4_address_t * hi_addr,
663 u32 fib_index, int is_del);
666 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
668 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
672 rv = VNET_API_ERROR_NO_SUCH_FIB;
678 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
679 (ip4_address_t *) mp->hi_address,
680 fib_index, mp->is_add == 0);
684 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
688 vl_api_proxy_arp_intfc_enable_disable_t_handler
689 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
692 vnet_main_t *vnm = vnet_get_main ();
693 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
694 vnet_sw_interface_t *si;
697 VALIDATE_SW_IF_INDEX (mp);
699 sw_if_index = ntohl (mp->sw_if_index);
701 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
703 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
707 si = vnet_get_sw_interface (vnm, sw_if_index);
711 if (mp->enable_disable)
712 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
714 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
716 BAD_SW_IF_INDEX_LABEL;
719 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
723 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
726 vpe_main_t *rm = &vpe_main;
727 ip4_main_t *im4 = &ip4_main;
728 ip6_main_t *im6 = &ip6_main;
729 ip_lookup_main_t *lm;
735 u32 adj_index, sw_if_index;
736 vl_api_is_address_reachable_t *rmp;
738 unix_shared_memory_queue_t *q;
740 q = vl_api_client_index_to_input_queue (mp->client_index);
743 increment_missing_api_client_counter (rm->vlib_main);
747 rmp = vl_msg_api_alloc (sizeof (*rmp));
748 clib_memcpy (rmp, mp, sizeof (*rmp));
750 sw_if_index = mp->next_hop_sw_if_index;
751 clib_memcpy (&addr, mp->address, sizeof (addr));
754 lm = &im6->lookup_main;
755 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
759 lm = &im4->lookup_main;
761 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
768 adj = ip_get_adjacency (lm, adj_index);
770 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
771 && adj->rewrite_header.sw_if_index == sw_if_index)
777 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
778 && adj->rewrite_header.sw_if_index == sw_if_index)
781 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
783 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
785 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
794 vl_msg_api_send_shmem (q, (u8 *) & rmp);
799 vl_api_sw_interface_set_mpls_enable_t_handler
800 (vl_api_sw_interface_set_mpls_enable_t * mp)
802 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
805 VALIDATE_SW_IF_INDEX (mp);
807 mpls_sw_interface_enable_disable (&mpls_main,
808 ntohl (mp->sw_if_index), mp->enable);
810 BAD_SW_IF_INDEX_LABEL;
811 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
815 send_oam_event (oam_target_t * t)
817 vpe_api_main_t *vam = &vpe_api_main;
818 unix_shared_memory_queue_t *q;
819 vpe_client_registration_t *reg;
820 vl_api_oam_event_t *mp;
823 pool_foreach(reg, vam->oam_events_registrations,
825 q = vl_api_client_index_to_input_queue (reg->client_index);
828 mp = vl_msg_api_alloc (sizeof (*mp));
829 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
830 clib_memcpy (mp->dst_address, &t->dst_address,
831 sizeof (mp->dst_address));
832 mp->state = t->state;
833 vl_msg_api_send_shmem (q, (u8 *)&mp);
840 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
842 vl_api_oam_add_del_reply_t *rmp;
845 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
846 (ip4_address_t *) mp->dst_address,
847 ntohl (mp->vrf_id), (int) (mp->is_add));
849 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
853 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
855 stats_main_t *sm = &stats_main;
856 vnet_interface_main_t *im = sm->interface_main;
857 vl_api_vnet_summary_stats_reply_t *rmp;
858 vlib_combined_counter_main_t *cm;
861 u64 total_pkts[VLIB_N_RX_TX];
862 u64 total_bytes[VLIB_N_RX_TX];
864 unix_shared_memory_queue_t *q =
865 vl_api_client_index_to_input_queue (mp->client_index);
870 rmp = vl_msg_api_alloc (sizeof (*rmp));
871 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
872 rmp->context = mp->context;
875 memset (total_pkts, 0, sizeof (total_pkts));
876 memset (total_bytes, 0, sizeof (total_bytes));
878 vnet_interface_counter_lock (im);
880 vec_foreach (cm, im->combined_sw_if_counters)
882 which = cm - im->combined_sw_if_counters;
884 for (i = 0; i < vec_len (cm->maxi); i++)
886 vlib_get_combined_counter (cm, i, &v);
887 total_pkts[which] += v.packets;
888 total_bytes[which] += v.bytes;
891 vnet_interface_counter_unlock (im);
893 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
894 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
895 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
896 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
898 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
900 vl_msg_api_send_shmem (q, (u8 *) & rmp);
904 typedef CLIB_PACKED (struct {
905 ip4_address_t address;
906 u32 address_length: 6;
912 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
914 vnet_main_t *vnm = vnet_get_main ();
915 vnet_interface_main_t *im = &vnm->interface_main;
916 ip4_main_t *im4 = &ip4_main;
917 static u32 *sw_if_indices_to_shut;
918 stats_main_t *sm = &stats_main;
919 fib_table_t *fib_table;
923 int rv = VNET_API_ERROR_NO_SUCH_FIB;
924 u32 target_fib_id = ntohl (mp->vrf_id);
926 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
929 pool_foreach (fib_table, im4->fibs,
931 fib = &fib_table->v4;
932 vnet_sw_interface_t * si;
934 if (fib->table_id != target_fib_id)
937 /* remove any mpls encap/decap labels */
938 mpls_fib_reset_labels (fib->table_id);
940 /* remove any proxy arps in this fib */
941 vnet_proxy_arp_fib_reset (fib->table_id);
943 /* Set the flow hash for this fib to the default */
944 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
946 vec_reset_length (sw_if_indices_to_shut);
948 /* Shut down interfaces in this FIB / clean out intfc routes */
949 pool_foreach (si, im->sw_interfaces,
951 u32 sw_if_index = si->sw_if_index;
953 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
954 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
956 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
959 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
960 sw_if_index = sw_if_indices_to_shut[i];
962 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
963 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
964 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
967 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
971 })); /* pool_foreach (fib) */
979 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
981 vnet_main_t *vnm = vnet_get_main ();
982 vnet_interface_main_t *im = &vnm->interface_main;
983 ip6_main_t *im6 = &ip6_main;
984 stats_main_t *sm = &stats_main;
985 static u32 *sw_if_indices_to_shut;
986 fib_table_t *fib_table;
990 int rv = VNET_API_ERROR_NO_SUCH_FIB;
991 u32 target_fib_id = ntohl (mp->vrf_id);
993 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
996 pool_foreach (fib_table, im6->fibs,
998 vnet_sw_interface_t * si;
999 fib = &(fib_table->v6);
1001 if (fib->table_id != target_fib_id)
1004 vec_reset_length (sw_if_indices_to_shut);
1006 /* Shut down interfaces in this FIB / clean out intfc routes */
1007 pool_foreach (si, im->sw_interfaces,
1009 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1011 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1014 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1015 sw_if_index = sw_if_indices_to_shut[i];
1017 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1018 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1019 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1022 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1026 })); /* pool_foreach (fib) */
1034 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1037 vl_api_reset_fib_reply_t *rmp;
1040 rv = ip6_reset_fib_t_handler (mp);
1042 rv = ip4_reset_fib_t_handler (mp);
1044 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1048 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1050 vl_api_create_loopback_reply_t *rmp;
1054 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1057 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1059 rmp->sw_if_index = ntohl (sw_if_index);
1065 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1067 vl_api_delete_loopback_reply_t *rmp;
1071 sw_if_index = ntohl (mp->sw_if_index);
1072 rv = vnet_delete_loopback_interface (sw_if_index);
1074 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1078 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1080 vl_api_control_ping_reply_t *rmp;
1084 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1086 rmp->vpe_pid = ntohl (getpid());
1092 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1094 u8 **shmem_vecp = (u8 **) arg;
1097 api_main_t *am = &api_main;
1100 shmem_vec = *shmem_vecp;
1102 offset = vec_len (shmem_vec);
1104 pthread_mutex_lock (&am->vlib_rp->mutex);
1105 oldheap = svm_push_data_heap (am->vlib_rp);
1107 vec_validate (shmem_vec, offset + buffer_bytes - 1);
1109 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
1111 svm_pop_heap (oldheap);
1112 pthread_mutex_unlock (&am->vlib_rp->mutex);
1114 *shmem_vecp = shmem_vec;
1119 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
1121 vl_api_cli_reply_t *rp;
1122 unix_shared_memory_queue_t *q;
1123 vlib_main_t *vm = vlib_get_main ();
1124 api_main_t *am = &api_main;
1125 unformat_input_t input;
1129 q = vl_api_client_index_to_input_queue (mp->client_index);
1133 rp = vl_msg_api_alloc (sizeof (*rp));
1134 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
1135 rp->context = mp->context;
1137 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
1139 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
1141 pthread_mutex_lock (&am->vlib_rp->mutex);
1142 oldheap = svm_push_data_heap (am->vlib_rp);
1144 vec_add1 (shmem_vec, 0);
1146 svm_pop_heap (oldheap);
1147 pthread_mutex_unlock (&am->vlib_rp->mutex);
1149 rp->reply_in_shmem = (uword) shmem_vec;
1151 vl_msg_api_send_shmem (q, (u8 *) & rp);
1155 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1157 u8 **mem_vecp = (u8 **) arg;
1158 u8 *mem_vec = *mem_vecp;
1159 u32 offset = vec_len (mem_vec);
1161 vec_validate (mem_vec, offset + buffer_bytes - 1);
1162 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
1163 *mem_vecp = mem_vec;
1167 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
1169 vl_api_cli_inband_reply_t *rmp;
1171 unix_shared_memory_queue_t *q;
1172 vlib_main_t *vm = vlib_get_main ();
1173 unformat_input_t input;
1176 q = vl_api_client_index_to_input_queue (mp->client_index);
1180 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
1181 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
1183 u32 len = vec_len (out_vec);
1185 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
1187 rmp->length = htonl (len);
1188 clib_memcpy (rmp->reply, out_vec, len);
1195 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
1198 vl_api_set_arp_neighbor_limit_reply_t *rmp;
1199 vnet_main_t *vnm = vnet_get_main ();
1200 clib_error_t *error;
1205 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
1207 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
1211 clib_error_report (error);
1212 rv = VNET_API_ERROR_UNSPECIFIED;
1216 rv = vnm->api_errno;
1219 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
1222 static void vl_api_classify_set_interface_ip_table_t_handler
1223 (vl_api_classify_set_interface_ip_table_t * mp)
1225 vlib_main_t *vm = vlib_get_main ();
1226 vl_api_classify_set_interface_ip_table_reply_t *rmp;
1228 u32 table_index, sw_if_index;
1230 table_index = ntohl (mp->table_index);
1231 sw_if_index = ntohl (mp->sw_if_index);
1233 VALIDATE_SW_IF_INDEX (mp);
1236 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
1238 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
1240 BAD_SW_IF_INDEX_LABEL;
1242 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
1245 static void vl_api_classify_set_interface_l2_tables_t_handler
1246 (vl_api_classify_set_interface_l2_tables_t * mp)
1248 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
1250 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
1253 ip4_table_index = ntohl (mp->ip4_table_index);
1254 ip6_table_index = ntohl (mp->ip6_table_index);
1255 other_table_index = ntohl (mp->other_table_index);
1256 sw_if_index = ntohl (mp->sw_if_index);
1258 VALIDATE_SW_IF_INDEX (mp);
1261 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
1265 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
1271 if (ip4_table_index != ~0 || ip6_table_index != ~0
1272 || other_table_index != ~0)
1278 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
1280 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
1283 BAD_SW_IF_INDEX_LABEL;
1285 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
1288 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1289 u32 sw_if_index, u32 enable);
1292 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1296 vl_api_l2_interface_efp_filter_reply_t *rmp;
1297 vnet_main_t *vnm = vnet_get_main ();
1299 // enable/disable the feature
1300 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
1301 rv = vnm->api_errno;
1303 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1307 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
1309 vl_api_show_version_reply_t *rmp;
1311 char *vpe_api_get_build_directory (void);
1312 char *vpe_api_get_version (void);
1313 char *vpe_api_get_build_date (void);
1315 unix_shared_memory_queue_t *q =
1316 vl_api_client_index_to_input_queue (mp->client_index);
1322 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
1324 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
1325 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
1326 ARRAY_LEN(rmp->build_directory)-1);
1327 strncpy ((char *) rmp->version, vpe_api_get_version(),
1328 ARRAY_LEN(rmp->version)-1);
1329 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
1330 ARRAY_LEN(rmp->build_date)-1);
1336 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
1338 vlib_main_t *vm = vlib_get_main ();
1339 vl_api_get_node_index_reply_t *rmp;
1342 u32 node_index = ~0;
1344 n = vlib_get_node_by_name (vm, mp->node_name);
1347 rv = VNET_API_ERROR_NO_SUCH_NODE;
1349 node_index = n->index;
1352 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1354 rmp->node_index = ntohl(node_index);
1360 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
1362 vlib_main_t *vm = vlib_get_main ();
1363 vl_api_get_next_index_reply_t *rmp;
1364 vlib_node_t *node, *next_node;
1366 u32 next_node_index = ~0, next_index = ~0;
1369 node = vlib_get_node_by_name (vm, mp->node_name);
1373 rv = VNET_API_ERROR_NO_SUCH_NODE;
1377 next_node = vlib_get_node_by_name (vm, mp->next_name);
1381 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1385 next_node_index = next_node->index;
1387 p = hash_get (node->next_slot_by_node, next_node_index);
1391 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1399 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
1401 rmp->next_index = ntohl(next_index);
1407 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
1409 vlib_main_t *vm = vlib_get_main ();
1410 vl_api_add_node_next_reply_t *rmp;
1411 vlib_node_t *n, *next;
1413 u32 next_index = ~0;
1415 n = vlib_get_node_by_name (vm, mp->node_name);
1419 rv = VNET_API_ERROR_NO_SUCH_NODE;
1423 next = vlib_get_node_by_name (vm, mp->next_name);
1426 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1428 next_index = vlib_node_add_next (vm, n->index, next->index);
1432 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1434 rmp->next_index = ntohl(next_index);
1439 static void vl_api_vxlan_add_del_tunnel_t_handler
1440 (vl_api_vxlan_add_del_tunnel_t * mp)
1442 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
1444 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
1445 u32 encap_fib_index;
1447 ip4_main_t *im = &ip4_main;
1448 vnet_main_t *vnm = vnet_get_main ();
1449 u32 sw_if_index = ~0;
1451 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1454 rv = VNET_API_ERROR_NO_SUCH_FIB;
1457 encap_fib_index = p[0];
1458 memset (a, 0, sizeof (*a));
1460 a->is_add = mp->is_add;
1461 a->is_ip6 = mp->is_ipv6;
1463 /* ip addresses sent in network byte order */
1464 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
1465 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
1467 /* Check src & dst are different */
1468 if (ip46_address_cmp (&a->dst, &a->src) == 0)
1470 rv = VNET_API_ERROR_SAME_SRC_DST;
1473 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
1474 if (ip46_address_is_multicast (&a->dst) &&
1475 pool_is_free_index (vnm->interface_main.sw_interfaces,
1476 a->mcast_sw_if_index))
1478 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1481 a->encap_fib_index = encap_fib_index;
1482 a->decap_next_index = ntohl (mp->decap_next_index);
1483 a->vni = ntohl (mp->vni);
1484 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
1488 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
1490 rmp->sw_if_index = ntohl (sw_if_index);
1495 static void send_vxlan_tunnel_details
1496 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1498 vl_api_vxlan_tunnel_details_t *rmp;
1499 ip4_main_t *im4 = &ip4_main;
1500 ip6_main_t *im6 = &ip6_main;
1501 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
1503 rmp = vl_msg_api_alloc (sizeof (*rmp));
1504 memset (rmp, 0, sizeof (*rmp));
1505 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
1508 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
1509 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
1510 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1514 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
1515 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
1516 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1518 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
1519 rmp->vni = htonl (t->vni);
1520 rmp->decap_next_index = htonl (t->decap_next_index);
1521 rmp->sw_if_index = htonl (t->sw_if_index);
1522 rmp->is_ipv6 = is_ipv6;
1523 rmp->context = context;
1525 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1528 static void vl_api_vxlan_tunnel_dump_t_handler
1529 (vl_api_vxlan_tunnel_dump_t * mp)
1531 unix_shared_memory_queue_t *q;
1532 vxlan_main_t *vxm = &vxlan_main;
1536 q = vl_api_client_index_to_input_queue (mp->client_index);
1542 sw_if_index = ntohl (mp->sw_if_index);
1544 if (~0 == sw_if_index)
1547 pool_foreach (t, vxm->tunnels,
1549 send_vxlan_tunnel_details(t, q, mp->context);
1555 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
1556 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
1560 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
1561 send_vxlan_tunnel_details (t, q, mp->context);
1566 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1568 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1570 vl_api_l2_patch_add_del_reply_t *rmp;
1571 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1575 VALIDATE_RX_SW_IF_INDEX (mp);
1576 VALIDATE_TX_SW_IF_INDEX (mp);
1578 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1579 ntohl (mp->tx_sw_if_index),
1580 (int) (mp->is_add != 0));
1582 BAD_RX_SW_IF_INDEX_LABEL;
1583 BAD_TX_SW_IF_INDEX_LABEL;
1585 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1589 vl_api_vxlan_gpe_add_del_tunnel_t_handler
1590 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
1592 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
1594 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
1595 u32 encap_fib_index, decap_fib_index;
1598 ip4_main_t *im = &ip4_main;
1599 u32 sw_if_index = ~0;
1602 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1605 rv = VNET_API_ERROR_NO_SUCH_FIB;
1608 encap_fib_index = p[0];
1610 protocol = mp->protocol;
1612 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
1613 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
1615 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
1618 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
1621 decap_fib_index = p[0];
1625 decap_fib_index = ntohl (mp->decap_vrf_id);
1628 /* Check src & dst are different */
1629 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
1630 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
1632 rv = VNET_API_ERROR_SAME_SRC_DST;
1635 memset (a, 0, sizeof (*a));
1637 a->is_add = mp->is_add;
1638 a->is_ip6 = mp->is_ipv6;
1639 /* ip addresses sent in network byte order */
1642 clib_memcpy (&(a->local.ip6), mp->local, 16);
1643 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
1647 clib_memcpy (&(a->local.ip4), mp->local, 4);
1648 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
1650 a->encap_fib_index = encap_fib_index;
1651 a->decap_fib_index = decap_fib_index;
1652 a->protocol = protocol;
1653 a->vni = ntohl (mp->vni);
1654 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
1658 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
1660 rmp->sw_if_index = ntohl (sw_if_index);
1665 static void send_vxlan_gpe_tunnel_details
1666 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1668 vl_api_vxlan_gpe_tunnel_details_t *rmp;
1669 ip4_main_t *im4 = &ip4_main;
1670 ip6_main_t *im6 = &ip6_main;
1671 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
1673 rmp = vl_msg_api_alloc (sizeof (*rmp));
1674 memset (rmp, 0, sizeof (*rmp));
1675 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
1678 memcpy (rmp->local, &(t->local.ip6), 16);
1679 memcpy (rmp->remote, &(t->remote.ip6), 16);
1680 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1681 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
1685 memcpy (rmp->local, &(t->local.ip4), 4);
1686 memcpy (rmp->remote, &(t->remote.ip4), 4);
1687 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1688 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
1690 rmp->vni = htonl (t->vni);
1691 rmp->protocol = t->protocol;
1692 rmp->sw_if_index = htonl (t->sw_if_index);
1693 rmp->is_ipv6 = is_ipv6;
1694 rmp->context = context;
1696 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1699 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
1700 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
1702 unix_shared_memory_queue_t *q;
1703 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
1704 vxlan_gpe_tunnel_t *t;
1707 q = vl_api_client_index_to_input_queue (mp->client_index);
1713 sw_if_index = ntohl (mp->sw_if_index);
1715 if (~0 == sw_if_index)
1718 pool_foreach (t, vgm->tunnels,
1720 send_vxlan_gpe_tunnel_details(t, q, mp->context);
1726 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
1727 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
1731 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
1732 send_vxlan_gpe_tunnel_details (t, q, mp->context);
1737 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1740 vl_api_interface_name_renumber_reply_t *rmp;
1743 VALIDATE_SW_IF_INDEX (mp);
1745 rv = vnet_interface_name_renumber
1746 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1748 BAD_SW_IF_INDEX_LABEL;
1750 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1754 arp_change_data_callback (u32 pool_index, u8 * new_mac,
1755 u32 sw_if_index, u32 address)
1757 vpe_api_main_t *am = &vpe_api_main;
1758 vlib_main_t *vm = am->vlib_main;
1759 vl_api_ip4_arp_event_t *event;
1760 static f64 arp_event_last_time;
1761 f64 now = vlib_time_now (vm);
1763 if (pool_is_free_index (am->arp_events, pool_index))
1766 event = pool_elt_at_index (am->arp_events, pool_index);
1768 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1770 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1774 if (sw_if_index == event->sw_if_index &&
1776 /* for BD case, also check IP address with 10 sec timeout */
1777 (address == event->address &&
1778 (now - arp_event_last_time) < 10.0)))
1783 arp_event_last_time = now;
1784 event->sw_if_index = sw_if_index;
1786 event->address = address;
1791 nd_change_data_callback (u32 pool_index, u8 * new_mac,
1792 u32 sw_if_index, ip6_address_t * address)
1794 vpe_api_main_t *am = &vpe_api_main;
1795 vlib_main_t *vm = am->vlib_main;
1796 vl_api_ip6_nd_event_t *event;
1797 static f64 nd_event_last_time;
1798 f64 now = vlib_time_now (vm);
1800 if (pool_is_free_index (am->nd_events, pool_index))
1803 event = pool_elt_at_index (am->nd_events, pool_index);
1806 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1808 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1812 if (sw_if_index == event->sw_if_index &&
1814 /* for BD case, also check IP address with 10 sec timeout */
1815 (ip6_address_is_equal (address,
1816 (ip6_address_t *) event->address) &&
1817 (now - nd_event_last_time) < 10.0)))
1822 nd_event_last_time = now;
1823 event->sw_if_index = sw_if_index;
1825 clib_memcpy (event->address, address, sizeof (event->address));
1830 arp_change_delete_callback (u32 pool_index, u8 * notused)
1832 vpe_api_main_t *am = &vpe_api_main;
1834 if (pool_is_free_index (am->arp_events, pool_index))
1837 pool_put_index (am->arp_events, pool_index);
1842 nd_change_delete_callback (u32 pool_index, u8 * notused)
1844 vpe_api_main_t *am = &vpe_api_main;
1846 if (pool_is_free_index (am->nd_events, pool_index))
1849 pool_put_index (am->nd_events, pool_index);
1854 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
1856 vpe_api_main_t *am = &vpe_api_main;
1857 vnet_main_t *vnm = vnet_get_main ();
1858 vl_api_want_ip4_arp_events_reply_t *rmp;
1859 vl_api_ip4_arp_event_t *event;
1862 if (mp->enable_disable)
1864 pool_get (am->arp_events, event);
1865 memset (event, 0, sizeof (*event));
1867 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
1868 event->client_index = mp->client_index;
1869 event->context = mp->context;
1870 event->address = mp->address;
1871 event->pid = mp->pid;
1872 if (mp->address == 0)
1875 rv = vnet_add_del_ip4_arp_change_event
1876 (vnm, arp_change_data_callback,
1877 mp->pid, &mp->address /* addr, in net byte order */ ,
1878 vpe_resolver_process_node.index,
1879 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
1883 rv = vnet_add_del_ip4_arp_change_event
1884 (vnm, arp_change_delete_callback,
1885 mp->pid, &mp->address /* addr, in net byte order */ ,
1886 vpe_resolver_process_node.index,
1887 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1889 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
1893 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
1895 vpe_api_main_t *am = &vpe_api_main;
1896 vnet_main_t *vnm = vnet_get_main ();
1897 vl_api_want_ip6_nd_events_reply_t *rmp;
1898 vl_api_ip6_nd_event_t *event;
1901 if (mp->enable_disable)
1903 pool_get (am->nd_events, event);
1904 memset (event, 0, sizeof (*event));
1906 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
1907 event->client_index = mp->client_index;
1908 event->context = mp->context;
1909 clib_memcpy (event->address, mp->address, 16);
1910 event->pid = mp->pid;
1911 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
1914 rv = vnet_add_del_ip6_nd_change_event
1915 (vnm, nd_change_data_callback,
1916 mp->pid, mp->address /* addr, in net byte order */ ,
1917 vpe_resolver_process_node.index,
1918 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
1922 rv = vnet_add_del_ip6_nd_change_event
1923 (vnm, nd_change_delete_callback,
1924 mp->pid, mp->address /* addr, in net byte order */ ,
1925 vpe_resolver_process_node.index,
1926 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1928 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
1931 static void vl_api_input_acl_set_interface_t_handler
1932 (vl_api_input_acl_set_interface_t * mp)
1934 vlib_main_t *vm = vlib_get_main ();
1935 vl_api_input_acl_set_interface_reply_t *rmp;
1937 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
1939 ip4_table_index = ntohl (mp->ip4_table_index);
1940 ip6_table_index = ntohl (mp->ip6_table_index);
1941 l2_table_index = ntohl (mp->l2_table_index);
1942 sw_if_index = ntohl (mp->sw_if_index);
1944 VALIDATE_SW_IF_INDEX (mp);
1946 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
1947 ip6_table_index, l2_table_index, mp->is_add);
1949 BAD_SW_IF_INDEX_LABEL;
1951 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
1955 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
1959 api_main_t *am = &api_main;
1960 vlib_main_t *vm = vlib_get_main ();
1962 vl_api_get_node_graph_reply_t *rmp;
1964 pthread_mutex_lock (&am->vlib_rp->mutex);
1965 oldheap = svm_push_data_heap (am->vlib_rp);
1968 * Keep the number of memcpy ops to a minimum (e.g. 1).
1970 vec_validate (vector, 16384);
1971 vec_reset_length (vector);
1974 vector = vlib_node_serialize (&vm->node_main, vector,
1975 (u32) ~ 0 /* all threads */ ,
1976 1 /* include nexts */ ,
1977 1 /* include stats */ );
1979 svm_pop_heap (oldheap);
1980 pthread_mutex_unlock (&am->vlib_rp->mutex);
1983 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
1985 rmp->reply_in_shmem = (uword) vector;
1991 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1994 vl_api_ioam_enable_reply_t *rmp;
1995 clib_error_t *error;
1997 /* Ignoring the profile id as currently a single profile
1999 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
2000 mp->seqno, mp->analyse);
2003 clib_error_report (error);
2004 rv = clib_error_get_code (error);
2007 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
2011 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
2014 vl_api_ioam_disable_reply_t *rmp;
2015 clib_error_t *error;
2017 error = clear_ioam_rewrite_fn ();
2020 clib_error_report (error);
2021 rv = clib_error_get_code (error);
2024 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
2028 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
2030 vl_api_pg_create_interface_reply_t *rmp;
2033 pg_main_t *pg = &pg_main;
2034 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
2035 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
2038 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
2040 rmp->sw_if_index = ntohl(pi->sw_if_index);
2046 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
2048 vl_api_pg_capture_reply_t *rmp;
2051 vnet_main_t *vnm = vnet_get_main ();
2052 vnet_interface_main_t *im = &vnm->interface_main;
2053 vnet_hw_interface_t *hi = 0;
2055 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
2056 u32 hw_if_index = ~0;
2057 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
2060 vec_free (intf_name);
2062 if (hw_if_index != ~0)
2064 pg_capture_args_t _a, *a = &_a;
2066 u32 len = ntohl (mp->pcap_name_length);
2067 u8 *pcap_file_name = vec_new (u8, len);
2068 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
2070 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
2071 a->hw_if_index = hw_if_index;
2072 a->dev_instance = hi->dev_instance;
2073 a->is_enabled = mp->is_enabled;
2074 a->pcap_file_name = pcap_file_name;
2075 a->count = ntohl (mp->count);
2077 clib_error_t *e = pg_capture (a);
2080 clib_error_report (e);
2081 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
2084 vec_free (pcap_file_name);
2086 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
2090 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
2092 vl_api_pg_enable_disable_reply_t *rmp;
2095 pg_main_t *pg = &pg_main;
2096 u32 stream_index = ~0;
2098 int is_enable = mp->is_enabled != 0;
2099 u32 len = ntohl (mp->stream_name_length) - 1;
2103 u8 *stream_name = vec_new (u8, len);
2104 clib_memcpy (stream_name, mp->stream_name, len);
2105 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
2108 vec_free (stream_name);
2111 pg_enable_disable (stream_index, is_enable);
2113 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
2117 vl_api_ip_source_and_port_range_check_add_del_t_handler
2118 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
2120 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
2123 u8 is_ipv6 = mp->is_ipv6;
2124 u8 is_add = mp->is_add;
2125 u8 mask_length = mp->mask_length;
2126 ip4_address_t ip4_addr;
2127 ip6_address_t ip6_addr;
2129 u16 *high_ports = 0;
2131 u16 tmp_low, tmp_high;
2135 // Validate port range
2136 num_ranges = mp->number_of_ranges;
2137 if (num_ranges > 32)
2138 { // This is size of array in VPE.API
2139 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
2143 vec_reset_length (low_ports);
2144 vec_reset_length (high_ports);
2146 for (i = 0; i < num_ranges; i++)
2148 tmp_low = mp->low_ports[i];
2149 tmp_high = mp->high_ports[i];
2150 // If tmp_low <= tmp_high then only need to check tmp_low = 0
2151 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
2152 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
2154 rv = VNET_API_ERROR_INVALID_VALUE;
2157 vec_add1 (low_ports, tmp_low);
2158 vec_add1 (high_ports, tmp_high + 1);
2161 // Validate mask_length
2162 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
2164 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
2168 vrf_id = ntohl (mp->vrf_id);
2172 rv = VNET_API_ERROR_INVALID_VALUE;
2179 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
2180 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
2184 high_ports, is_add);
2188 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
2189 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
2193 high_ports, is_add);
2197 vec_free (low_ports);
2198 vec_free (high_ports);
2199 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
2203 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
2204 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
2206 vlib_main_t *vm = vlib_get_main ();
2207 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
2208 ip4_main_t *im = &ip4_main;
2211 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2212 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2216 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
2217 ntohl (mp->tcp_out_vrf_id);
2218 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
2219 ntohl (mp->udp_out_vrf_id);
2220 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
2221 ntohl (mp->tcp_in_vrf_id);
2222 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
2223 ntohl (mp->udp_in_vrf_id);
2226 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
2228 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
2230 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
2234 rv = VNET_API_ERROR_INVALID_VALUE;
2238 fib_index[i] = p[0];
2243 sw_if_index = ntohl (mp->sw_if_index);
2245 VALIDATE_SW_IF_INDEX (mp);
2248 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
2251 BAD_SW_IF_INDEX_LABEL;
2254 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
2258 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
2260 vl_api_delete_subif_reply_t *rmp;
2263 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
2265 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
2269 vl_api_punt_t_handler (vl_api_punt_t * mp)
2271 vl_api_punt_reply_t *rmp;
2272 vlib_main_t *vm = vlib_get_main ();
2274 clib_error_t *error;
2276 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
2277 ntohs (mp->l4_port), mp->is_add);
2281 clib_error_report (error);
2284 REPLY_MACRO (VL_API_PUNT_REPLY);
2288 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
2290 vl_api_feature_enable_disable_reply_t *rmp;
2292 u8 *arc_name, *feature_name;
2294 VALIDATE_SW_IF_INDEX (mp);
2296 arc_name = format (0, "%s%c", mp->arc_name, 0);
2297 feature_name = format (0, "%s%c", mp->feature_name, 0);
2299 vnet_feature_registration_t *reg;
2301 vnet_get_feature_reg ((const char *) arc_name,
2302 (const char *) feature_name);
2304 rv = VNET_API_ERROR_INVALID_VALUE;
2308 clib_error_t *error = 0;
2310 sw_if_index = ntohl (mp->sw_if_index);
2311 if (reg->enable_disable_cb)
2312 error = reg->enable_disable_cb (sw_if_index, mp->enable);
2314 vnet_feature_enable_disable ((const char *) arc_name,
2315 (const char *) feature_name,
2316 sw_if_index, mp->enable, 0, 0);
2319 clib_error_report (error);
2320 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
2324 vec_free (feature_name);
2325 vec_free (arc_name);
2327 BAD_SW_IF_INDEX_LABEL;
2329 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
2332 #define BOUNCE_HANDLER(nn) \
2333 static void vl_api_##nn##_t_handler ( \
2334 vl_api_##nn##_t *mp) \
2336 vpe_client_registration_t *reg; \
2337 vpe_api_main_t * vam = &vpe_api_main; \
2338 unix_shared_memory_queue_t * q; \
2340 /* One registration only... */ \
2341 pool_foreach(reg, vam->nn##_registrations, \
2343 q = vl_api_client_index_to_input_queue (reg->client_index); \
2346 * If the queue is stuffed, turf the msg and complain \
2347 * It's unlikely that the intended recipient is \
2348 * alive; avoid deadlock at all costs. \
2350 if (q->cursize == q->maxsize) { \
2351 clib_warning ("ERROR: receiver queue full, drop msg"); \
2352 vl_msg_api_free (mp); \
2355 vl_msg_api_send_shmem (q, (u8 *)&mp); \
2359 vl_msg_api_free (mp); \
2362 static void setup_message_id_table (api_main_t * am);
2366 * Add vpe's API message handlers to the table.
2367 * vlib has alread mapped shared memory and
2368 * added the client registration handlers.
2369 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
2371 static clib_error_t *
2372 vpe_api_hookup (vlib_main_t * vm)
2374 api_main_t *am = &api_main;
2377 vl_msg_api_set_handlers(VL_API_##N, #n, \
2378 vl_api_##n##_t_handler, \
2380 vl_api_##n##_t_endian, \
2381 vl_api_##n##_t_print, \
2382 sizeof(vl_api_##n##_t), 1);
2383 foreach_vpe_api_msg;
2387 * Trace space for classifier mask+match
2389 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
2390 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
2391 += 5 * sizeof (u32x4);
2392 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
2395 * Thread-safe API messages
2397 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
2398 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
2401 * Set up the (msg_name, crc, message-id) table
2403 setup_message_id_table (am);
2408 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
2410 static clib_error_t *
2411 vpe_api_init (vlib_main_t * vm)
2413 vpe_api_main_t *am = &vpe_api_main;
2416 am->vnet_main = vnet_get_main ();
2417 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
2418 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2419 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2420 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2421 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2422 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
2423 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
2426 vl_set_memory_region_name ("/vpe-api");
2427 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
2432 VLIB_INIT_FUNCTION (vpe_api_init);
2435 static clib_error_t *
2436 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
2439 u64 baseva, size, pvt_heap_size;
2441 const int max_buf_size = 4096;
2443 struct passwd _pw, *pw;
2444 struct group _grp, *grp;
2446 buf = vec_new (char, 128);
2447 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2449 if (unformat (input, "prefix %s", &chroot_path))
2451 vec_add1 (chroot_path, 0);
2452 vl_set_memory_root_path ((char *) chroot_path);
2454 else if (unformat (input, "uid %d", &uid))
2455 vl_set_memory_uid (uid);
2456 else if (unformat (input, "gid %d", &gid))
2457 vl_set_memory_gid (gid);
2458 else if (unformat (input, "baseva %llx", &baseva))
2459 vl_set_global_memory_baseva (baseva);
2460 else if (unformat (input, "global-size %lldM", &size))
2461 vl_set_global_memory_size (size * (1ULL << 20));
2462 else if (unformat (input, "global-size %lldG", &size))
2463 vl_set_global_memory_size (size * (1ULL << 30));
2464 else if (unformat (input, "global-size %lld", &size))
2465 vl_set_global_memory_size (size);
2466 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
2467 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2468 else if (unformat (input, "global-pvt-heap-size size %lld",
2470 vl_set_global_pvt_heap_size (pvt_heap_size);
2471 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
2472 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2473 else if (unformat (input, "api-pvt-heap-size size %lld",
2475 vl_set_api_pvt_heap_size (pvt_heap_size);
2476 else if (unformat (input, "api-size %lldM", &size))
2477 vl_set_api_memory_size (size * (1ULL << 20));
2478 else if (unformat (input, "api-size %lldG", &size))
2479 vl_set_api_memory_size (size * (1ULL << 30));
2480 else if (unformat (input, "api-size %lld", &size))
2481 vl_set_api_memory_size (size);
2482 else if (unformat (input, "uid %s", &s))
2484 /* lookup the username */
2487 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
2488 && (vec_len (buf) <= max_buf_size))
2490 vec_resize (buf, vec_len (buf) * 2);
2494 e = clib_error_return_code (0, rv,
2495 CLIB_ERROR_ERRNO_VALID |
2497 "cannot fetch username %s", s);
2505 clib_error_return_fatal (0, "username %s does not exist", s);
2511 vl_set_memory_uid (pw->pw_uid);
2513 else if (unformat (input, "gid %s", &s))
2515 /* lookup the group name */
2518 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
2519 && (vec_len (buf) <= max_buf_size))
2521 vec_resize (buf, vec_len (buf) * 2);
2525 e = clib_error_return_code (0, rv,
2526 CLIB_ERROR_ERRNO_VALID |
2528 "cannot fetch group %s", s);
2535 e = clib_error_return_fatal (0, "group %s does not exist", s);
2542 vl_set_memory_gid (grp->gr_gid);
2545 return clib_error_return (0, "unknown input `%U'",
2546 format_unformat_error, input);
2551 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
2554 get_unformat_vnet_sw_interface (void)
2556 return (void *) &unformat_vnet_sw_interface;
2560 format_arp_event (u8 * s, va_list * args)
2562 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
2564 s = format (s, "pid %d: ", event->pid);
2566 s = format (s, "bd mac/ip4 binding events");
2568 s = format (s, "resolution for %U", format_ip4_address, &event->address);
2573 format_nd_event (u8 * s, va_list * args)
2575 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
2577 s = format (s, "pid %d: ", event->pid);
2579 s = format (s, "bd mac/ip6 binding events");
2581 s = format (s, "resolution for %U", format_ip6_address, event->address);
2585 static clib_error_t *
2586 show_ip_arp_nd_events_fn (vlib_main_t * vm,
2587 unformat_input_t * input, vlib_cli_command_t * cmd)
2589 vpe_api_main_t *am = &vpe_api_main;
2590 vl_api_ip4_arp_event_t *arp_event;
2591 vl_api_ip6_nd_event_t *nd_event;
2593 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
2595 vlib_cli_output (vm, "No active arp or nd event registrations");
2600 pool_foreach (arp_event, am->arp_events,
2602 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
2605 pool_foreach (nd_event, am->nd_events,
2607 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
2615 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
2616 .path = "show arp-nd-event registrations",
2617 .function = show_ip_arp_nd_events_fn,
2618 .short_help = "Show ip4 arp and ip6 nd event registrations",
2622 #define vl_msg_name_crc_list
2623 #include <vpp/api/vpe_all_api_h.h>
2624 #undef vl_msg_name_crc_list
2627 setup_message_id_table (api_main_t * am)
2629 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2630 foreach_vl_msg_name_crc_memclnt;
2631 foreach_vl_msg_name_crc_vpe;
2637 * fd.io coding-style-patch-verification: ON
2640 * eval: (c-set-style "gnu")