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/cop/cop.h>
68 #include <vnet/ip/ip6_hop_by_hop.h>
69 #include <vnet/ip/ip_source_and_port_range_check.h>
70 #include <vnet/policer/policer.h>
71 #include <vnet/ip/punt.h>
72 #include <vnet/feature/feature.h>
75 #undef __included_bihash_template_h__
76 #include <vnet/l2/l2_fib.h>
78 #include <vpp/stats/stats.h>
79 #include <vpp/oam/oam.h>
81 #include <vnet/ethernet/ethernet.h>
82 #include <vnet/ethernet/arp_packet.h>
83 #include <vnet/interface.h>
84 #include <vnet/l2/l2_fib.h>
85 #include <vnet/l2/l2_bd.h>
86 #include <vpp/api/vpe_msg_enum.h>
87 #include <vnet/span/span.h>
88 #include <vnet/fib/ip6_fib.h>
89 #include <vnet/fib/ip4_fib.h>
90 #include <vnet/fib/fib_api.h>
91 #include <vnet/dpo/drop_dpo.h>
92 #include <vnet/dpo/receive_dpo.h>
93 #include <vnet/dpo/lookup_dpo.h>
94 #include <vnet/dpo/classify_dpo.h>
95 #include <vnet/dpo/ip_null_dpo.h>
96 #define vl_typedefs /* define message structures */
97 #include <vpp/api/vpe_all_api_h.h>
99 #define vl_endianfun /* define message structures */
100 #include <vpp/api/vpe_all_api_h.h>
102 /* instantiate all the print functions we know about */
103 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
105 #include <vpp/api/vpe_all_api_h.h>
107 #include <vlibapi/api_helper_macros.h>
108 #define foreach_vpe_api_msg \
109 _(WANT_OAM_EVENTS, want_oam_events) \
110 _(OAM_ADD_DEL, oam_add_del) \
111 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
112 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
113 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
114 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
115 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
116 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
117 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
118 _(CREATE_SUBIF, create_subif) \
119 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
120 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
121 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
122 _(RESET_FIB, reset_fib) \
123 _(CREATE_LOOPBACK, create_loopback) \
124 _(CONTROL_PING, control_ping) \
125 _(CLI_REQUEST, cli_request) \
126 _(CLI_INBAND, cli_inband) \
127 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
128 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
129 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
130 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
131 _(GET_NODE_INDEX, get_node_index) \
132 _(ADD_NODE_NEXT, add_node_next) \
133 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
134 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
135 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
136 _(SHOW_VERSION, show_version) \
137 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
138 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
139 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
140 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
141 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
142 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
143 _(DELETE_LOOPBACK, delete_loopback) \
144 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
145 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
146 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
147 _(GET_NODE_GRAPH, get_node_graph) \
148 _(IOAM_ENABLE, ioam_enable) \
149 _(IOAM_DISABLE, ioam_disable) \
150 _(POLICER_ADD_DEL, policer_add_del) \
151 _(POLICER_DUMP, policer_dump) \
152 _(GET_NEXT_INDEX, get_next_index) \
153 _(PG_CREATE_INTERFACE, pg_create_interface) \
154 _(PG_CAPTURE, pg_capture) \
155 _(PG_ENABLE_DISABLE, pg_enable_disable) \
156 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
157 ip_source_and_port_range_check_add_del) \
158 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
159 ip_source_and_port_range_check_interface_add_del) \
160 _(DELETE_SUBIF, delete_subif) \
162 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
165 #define QUOTE(x) QUOTE_(x)
168 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
169 RESOLVE_IP6_ADD_DEL_ROUTE,
172 static vlib_node_registration_t vpe_resolver_process_node;
173 vpe_api_main_t vpe_api_main;
175 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
176 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
178 /* Clean up all registrations belonging to the indicated client */
180 vl_api_memclnt_delete_callback (u32 client_index)
182 vpe_api_main_t *vam = &vpe_api_main;
183 vpe_client_registration_t *rp;
185 int stats_memclnt_delete_callback (u32 client_index);
187 stats_memclnt_delete_callback (client_index);
190 p = hash_get (vam->a##_registration_hash, client_index); \
192 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
193 pool_put (vam->a##_registrations, rp); \
194 hash_unset (vam->a##_registration_hash, client_index); \
196 foreach_registration_hash;
201 pub_sub_handler (oam_events, OAM_EVENTS);
203 #define RESOLUTION_EVENT 1
204 #define RESOLUTION_PENDING_EVENT 2
205 #define IP4_ARP_EVENT 3
206 #define IP6_ND_EVENT 4
208 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
210 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
213 handle_ip4_arp_event (u32 pool_index)
215 vpe_api_main_t *vam = &vpe_api_main;
216 vnet_main_t *vnm = vam->vnet_main;
217 vlib_main_t *vm = vam->vlib_main;
218 vl_api_ip4_arp_event_t *event;
219 vl_api_ip4_arp_event_t *mp;
220 unix_shared_memory_queue_t *q;
222 /* Client can cancel, die, etc. */
223 if (pool_is_free_index (vam->arp_events, pool_index))
226 event = pool_elt_at_index (vam->arp_events, pool_index);
228 q = vl_api_client_index_to_input_queue (event->client_index);
231 (void) vnet_add_del_ip4_arp_change_event
232 (vnm, arp_change_delete_callback,
233 event->pid, &event->address,
234 vpe_resolver_process_node.index, IP4_ARP_EVENT,
235 ~0 /* pool index, notused */ , 0 /* is_add */ );
239 if (q->cursize < q->maxsize)
241 mp = vl_msg_api_alloc (sizeof (*mp));
242 clib_memcpy (mp, event, sizeof (*mp));
243 vl_msg_api_send_shmem (q, (u8 *) & mp);
247 static f64 last_time;
249 * Throttle syslog msgs.
250 * It's pretty tempting to just revoke the registration...
252 if (vlib_time_now (vm) > last_time + 10.0)
254 clib_warning ("arp event for %U to pid %d: queue stuffed!",
255 format_ip4_address, &event->address, event->pid);
256 last_time = vlib_time_now (vm);
262 handle_ip6_nd_event (u32 pool_index)
264 vpe_api_main_t *vam = &vpe_api_main;
265 vnet_main_t *vnm = vam->vnet_main;
266 vlib_main_t *vm = vam->vlib_main;
267 vl_api_ip6_nd_event_t *event;
268 vl_api_ip6_nd_event_t *mp;
269 unix_shared_memory_queue_t *q;
271 /* Client can cancel, die, etc. */
272 if (pool_is_free_index (vam->nd_events, pool_index))
275 event = pool_elt_at_index (vam->nd_events, pool_index);
277 q = vl_api_client_index_to_input_queue (event->client_index);
280 (void) vnet_add_del_ip6_nd_change_event
281 (vnm, nd_change_delete_callback,
282 event->pid, &event->address,
283 vpe_resolver_process_node.index, IP6_ND_EVENT,
284 ~0 /* pool index, notused */ , 0 /* is_add */ );
288 if (q->cursize < q->maxsize)
290 mp = vl_msg_api_alloc (sizeof (*mp));
291 clib_memcpy (mp, event, sizeof (*mp));
292 vl_msg_api_send_shmem (q, (u8 *) & mp);
296 static f64 last_time;
298 * Throttle syslog msgs.
299 * It's pretty tempting to just revoke the registration...
301 if (vlib_time_now (vm) > last_time + 10.0)
303 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
304 format_ip6_address, &event->address, event->pid);
305 last_time = vlib_time_now (vm);
311 resolver_process (vlib_main_t * vm,
312 vlib_node_runtime_t * rt, vlib_frame_t * f)
315 uword *event_data = 0;
321 vlib_process_wait_for_event_or_clock (vm, timeout);
323 event_type = vlib_process_get_events (vm, &event_data);
327 case RESOLUTION_PENDING_EVENT:
331 case RESOLUTION_EVENT:
332 clib_warning ("resolver: BOGUS TYPE");
336 for (i = 0; i < vec_len (event_data); i++)
337 handle_ip4_arp_event (event_data[i]);
341 for (i = 0; i < vec_len (event_data); i++)
342 handle_ip6_nd_event (event_data[i]);
345 case ~0: /* timeout */
349 vec_reset_length (event_data);
351 return 0; /* or not */
355 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
356 .function = resolver_process,
357 .type = VLIB_NODE_TYPE_PROCESS,
358 .name = "vpe-route-resolver-process",
363 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
365 vl_api_sw_interface_set_vpath_reply_t *rmp;
367 u32 sw_if_index = ntohl (mp->sw_if_index);
369 VALIDATE_SW_IF_INDEX (mp);
371 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
372 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
373 sw_if_index, mp->enable, 0, 0);
374 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
375 sw_if_index, mp->enable, 0, 0);
376 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
377 sw_if_index, mp->enable, 0, 0);
378 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
379 sw_if_index, mp->enable, 0, 0);
381 BAD_SW_IF_INDEX_LABEL;
383 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
387 vl_api_sw_interface_set_vxlan_bypass_t_handler
388 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
390 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
392 u32 sw_if_index = ntohl (mp->sw_if_index);
394 VALIDATE_SW_IF_INDEX (mp);
398 /* not yet implemented */
401 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
402 sw_if_index, mp->enable, 0, 0);
404 BAD_SW_IF_INDEX_LABEL;
406 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
410 vl_api_sw_interface_set_l2_xconnect_t_handler
411 (vl_api_sw_interface_set_l2_xconnect_t * mp)
413 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
415 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
416 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
417 vlib_main_t *vm = vlib_get_main ();
418 vnet_main_t *vnm = vnet_get_main ();
420 VALIDATE_RX_SW_IF_INDEX (mp);
424 VALIDATE_TX_SW_IF_INDEX (mp);
425 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
426 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
430 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
433 BAD_RX_SW_IF_INDEX_LABEL;
434 BAD_TX_SW_IF_INDEX_LABEL;
436 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
440 vl_api_sw_interface_set_l2_bridge_t_handler
441 (vl_api_sw_interface_set_l2_bridge_t * mp)
443 bd_main_t *bdm = &bd_main;
444 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
446 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
447 u32 bd_id = ntohl (mp->bd_id);
451 vlib_main_t *vm = vlib_get_main ();
452 vnet_main_t *vnm = vnet_get_main ();
454 VALIDATE_RX_SW_IF_INDEX (mp);
456 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
460 //VALIDATE_TX_SW_IF_INDEX(mp);
461 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
462 rx_sw_if_index, bd_index, bvi, shg, 0);
466 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
469 BAD_RX_SW_IF_INDEX_LABEL;
471 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
475 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
477 bd_main_t *bdm = &bd_main;
478 vl_api_bd_ip_mac_add_del_reply_t *rmp;
480 u32 bd_id = ntohl (mp->bd_id);
484 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
487 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
492 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
493 mp->mac_address, mp->is_ipv6, mp->is_add))
494 rv = VNET_API_ERROR_UNSPECIFIED;
497 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
501 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
503 vl_api_create_vlan_subif_reply_t *rmp;
504 vnet_main_t *vnm = vnet_get_main ();
505 u32 hw_if_index, sw_if_index = (u32) ~ 0;
506 vnet_hw_interface_t *hi;
509 vnet_sw_interface_t template;
511 vnet_interface_main_t *im = &vnm->interface_main;
514 unix_shared_memory_queue_t *q;
517 VALIDATE_SW_IF_INDEX (mp);
519 hw_if_index = ntohl (mp->sw_if_index);
520 hi = vnet_get_hw_interface (vnm, hw_if_index);
522 id = ntohl (mp->vlan_id);
523 if (id == 0 || id > 4095)
525 rv = VNET_API_ERROR_INVALID_VLAN;
529 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
531 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
534 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
538 kp = clib_mem_alloc (sizeof (*kp));
539 *kp = sup_and_sub_key;
541 memset (&template, 0, sizeof (template));
542 template.type = VNET_SW_INTERFACE_TYPE_SUB;
543 template.sup_sw_if_index = hi->sw_if_index;
544 template.sub.id = id;
545 template.sub.eth.raw_flags = 0;
546 template.sub.eth.flags.one_tag = 1;
547 template.sub.eth.outer_vlan_id = id;
548 template.sub.eth.flags.exact_match = 1;
550 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
553 clib_error_report (error);
554 rv = VNET_API_ERROR_INVALID_REGISTRATION;
557 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
558 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
560 BAD_SW_IF_INDEX_LABEL;
563 q = vl_api_client_index_to_input_queue (mp->client_index);
567 rmp = vl_msg_api_alloc (sizeof (*rmp));
568 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
569 rmp->context = mp->context;
570 rmp->retval = ntohl (rv);
571 rmp->sw_if_index = ntohl (sw_if_index);
572 vl_msg_api_send_shmem (q, (u8 *) & rmp);
576 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
578 vl_api_create_subif_reply_t *rmp;
579 vnet_main_t *vnm = vnet_get_main ();
580 u32 sw_if_index = ~0;
583 vnet_sw_interface_t *si;
584 vnet_hw_interface_t *hi;
585 vnet_sw_interface_t template;
587 vnet_interface_main_t *im = &vnm->interface_main;
592 VALIDATE_SW_IF_INDEX (mp);
594 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
595 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
597 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
599 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
603 sw_if_index = si->sw_if_index;
604 sub_id = ntohl (mp->sub_id);
606 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
608 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
612 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
613 sw_if_index, sub_id);
614 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
618 kp = clib_mem_alloc (sizeof (*kp));
619 *kp = sup_and_sub_key;
621 memset (&template, 0, sizeof (template));
622 template.type = VNET_SW_INTERFACE_TYPE_SUB;
623 template.sup_sw_if_index = sw_if_index;
624 template.sub.id = sub_id;
625 template.sub.eth.flags.no_tags = mp->no_tags;
626 template.sub.eth.flags.one_tag = mp->one_tag;
627 template.sub.eth.flags.two_tags = mp->two_tags;
628 template.sub.eth.flags.dot1ad = mp->dot1ad;
629 template.sub.eth.flags.exact_match = mp->exact_match;
630 template.sub.eth.flags.default_sub = mp->default_sub;
631 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
632 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
633 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
634 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
636 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
639 clib_error_report (error);
640 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
644 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
645 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
647 BAD_SW_IF_INDEX_LABEL;
652 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
654 rmp->sw_if_index = ntohl(sw_if_index);
660 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
662 vl_api_proxy_arp_add_del_reply_t *rmp;
665 ip4_main_t *im = &ip4_main;
666 stats_main_t *sm = &stats_main;
667 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
668 ip4_address_t * hi_addr,
669 u32 fib_index, int is_del);
672 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
674 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
678 rv = VNET_API_ERROR_NO_SUCH_FIB;
684 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
685 (ip4_address_t *) mp->hi_address,
686 fib_index, mp->is_add == 0);
690 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
694 vl_api_proxy_arp_intfc_enable_disable_t_handler
695 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
698 vnet_main_t *vnm = vnet_get_main ();
699 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
700 vnet_sw_interface_t *si;
703 VALIDATE_SW_IF_INDEX (mp);
705 sw_if_index = ntohl (mp->sw_if_index);
707 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
709 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
713 si = vnet_get_sw_interface (vnm, sw_if_index);
717 if (mp->enable_disable)
718 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
720 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
722 BAD_SW_IF_INDEX_LABEL;
725 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
729 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
732 vpe_main_t *rm = &vpe_main;
733 ip4_main_t *im4 = &ip4_main;
734 ip6_main_t *im6 = &ip6_main;
735 ip_lookup_main_t *lm;
741 u32 adj_index, sw_if_index;
742 vl_api_is_address_reachable_t *rmp;
744 unix_shared_memory_queue_t *q;
746 q = vl_api_client_index_to_input_queue (mp->client_index);
749 increment_missing_api_client_counter (rm->vlib_main);
753 rmp = vl_msg_api_alloc (sizeof (*rmp));
754 clib_memcpy (rmp, mp, sizeof (*rmp));
756 sw_if_index = mp->next_hop_sw_if_index;
757 clib_memcpy (&addr, mp->address, sizeof (addr));
760 lm = &im6->lookup_main;
761 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
765 lm = &im4->lookup_main;
767 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
774 adj = ip_get_adjacency (lm, adj_index);
776 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
777 && adj->rewrite_header.sw_if_index == sw_if_index)
783 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
784 && adj->rewrite_header.sw_if_index == sw_if_index)
787 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
789 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
791 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
800 vl_msg_api_send_shmem (q, (u8 *) & rmp);
805 vl_api_sw_interface_set_mpls_enable_t_handler
806 (vl_api_sw_interface_set_mpls_enable_t * mp)
808 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
811 VALIDATE_SW_IF_INDEX (mp);
813 mpls_sw_interface_enable_disable (&mpls_main,
814 ntohl (mp->sw_if_index), mp->enable);
816 BAD_SW_IF_INDEX_LABEL;
817 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
821 send_oam_event (oam_target_t * t)
823 vpe_api_main_t *vam = &vpe_api_main;
824 unix_shared_memory_queue_t *q;
825 vpe_client_registration_t *reg;
826 vl_api_oam_event_t *mp;
829 pool_foreach(reg, vam->oam_events_registrations,
831 q = vl_api_client_index_to_input_queue (reg->client_index);
834 mp = vl_msg_api_alloc (sizeof (*mp));
835 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
836 clib_memcpy (mp->dst_address, &t->dst_address,
837 sizeof (mp->dst_address));
838 mp->state = t->state;
839 vl_msg_api_send_shmem (q, (u8 *)&mp);
846 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
848 vl_api_oam_add_del_reply_t *rmp;
851 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
852 (ip4_address_t *) mp->dst_address,
853 ntohl (mp->vrf_id), (int) (mp->is_add));
855 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
859 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
861 stats_main_t *sm = &stats_main;
862 vnet_interface_main_t *im = sm->interface_main;
863 vl_api_vnet_summary_stats_reply_t *rmp;
864 vlib_combined_counter_main_t *cm;
867 u64 total_pkts[VLIB_N_RX_TX];
868 u64 total_bytes[VLIB_N_RX_TX];
870 unix_shared_memory_queue_t *q =
871 vl_api_client_index_to_input_queue (mp->client_index);
876 rmp = vl_msg_api_alloc (sizeof (*rmp));
877 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
878 rmp->context = mp->context;
881 memset (total_pkts, 0, sizeof (total_pkts));
882 memset (total_bytes, 0, sizeof (total_bytes));
884 vnet_interface_counter_lock (im);
886 vec_foreach (cm, im->combined_sw_if_counters)
888 which = cm - im->combined_sw_if_counters;
890 for (i = 0; i < vec_len (cm->maxi); i++)
892 vlib_get_combined_counter (cm, i, &v);
893 total_pkts[which] += v.packets;
894 total_bytes[which] += v.bytes;
897 vnet_interface_counter_unlock (im);
899 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
900 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
901 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
902 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
904 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
906 vl_msg_api_send_shmem (q, (u8 *) & rmp);
910 typedef CLIB_PACKED (struct {
911 ip4_address_t address;
912 u32 address_length: 6;
918 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
920 vnet_main_t *vnm = vnet_get_main ();
921 vnet_interface_main_t *im = &vnm->interface_main;
922 ip4_main_t *im4 = &ip4_main;
923 static u32 *sw_if_indices_to_shut;
924 stats_main_t *sm = &stats_main;
925 fib_table_t *fib_table;
929 int rv = VNET_API_ERROR_NO_SUCH_FIB;
930 u32 target_fib_id = ntohl (mp->vrf_id);
932 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
935 pool_foreach (fib_table, im4->fibs,
937 fib = &fib_table->v4;
938 vnet_sw_interface_t * si;
940 if (fib->table_id != target_fib_id)
943 /* remove any mpls encap/decap labels */
944 mpls_fib_reset_labels (fib->table_id);
946 /* remove any proxy arps in this fib */
947 vnet_proxy_arp_fib_reset (fib->table_id);
949 /* Set the flow hash for this fib to the default */
950 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
952 vec_reset_length (sw_if_indices_to_shut);
954 /* Shut down interfaces in this FIB / clean out intfc routes */
955 pool_foreach (si, im->sw_interfaces,
957 u32 sw_if_index = si->sw_if_index;
959 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
960 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
962 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
965 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
966 sw_if_index = sw_if_indices_to_shut[i];
967 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
969 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
970 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
971 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
974 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
975 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
979 })); /* pool_foreach (fib) */
987 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
989 vnet_main_t *vnm = vnet_get_main ();
990 vnet_interface_main_t *im = &vnm->interface_main;
991 ip6_main_t *im6 = &ip6_main;
992 stats_main_t *sm = &stats_main;
993 static u32 *sw_if_indices_to_shut;
994 fib_table_t *fib_table;
998 int rv = VNET_API_ERROR_NO_SUCH_FIB;
999 u32 target_fib_id = ntohl (mp->vrf_id);
1001 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
1004 pool_foreach (fib_table, im6->fibs,
1006 vnet_sw_interface_t * si;
1007 fib = &(fib_table->v6);
1009 if (fib->table_id != target_fib_id)
1012 vec_reset_length (sw_if_indices_to_shut);
1014 /* Shut down interfaces in this FIB / clean out intfc routes */
1015 pool_foreach (si, im->sw_interfaces,
1017 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1019 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1022 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1023 sw_if_index = sw_if_indices_to_shut[i];
1024 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1026 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1027 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1028 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1031 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1032 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
1036 })); /* pool_foreach (fib) */
1044 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1047 vl_api_reset_fib_reply_t *rmp;
1050 rv = ip6_reset_fib_t_handler (mp);
1052 rv = ip4_reset_fib_t_handler (mp);
1054 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1058 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1060 vl_api_create_loopback_reply_t *rmp;
1064 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1067 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1069 rmp->sw_if_index = ntohl (sw_if_index);
1075 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1077 vl_api_delete_loopback_reply_t *rmp;
1081 sw_if_index = ntohl (mp->sw_if_index);
1082 rv = vnet_delete_loopback_interface (sw_if_index);
1084 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1088 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1090 vl_api_control_ping_reply_t *rmp;
1094 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1096 rmp->vpe_pid = ntohl (getpid());
1102 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1104 u8 **shmem_vecp = (u8 **) arg;
1107 api_main_t *am = &api_main;
1110 shmem_vec = *shmem_vecp;
1112 offset = vec_len (shmem_vec);
1114 pthread_mutex_lock (&am->vlib_rp->mutex);
1115 oldheap = svm_push_data_heap (am->vlib_rp);
1117 vec_validate (shmem_vec, offset + buffer_bytes - 1);
1119 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
1121 svm_pop_heap (oldheap);
1122 pthread_mutex_unlock (&am->vlib_rp->mutex);
1124 *shmem_vecp = shmem_vec;
1129 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
1131 vl_api_cli_reply_t *rp;
1132 unix_shared_memory_queue_t *q;
1133 vlib_main_t *vm = vlib_get_main ();
1134 api_main_t *am = &api_main;
1135 unformat_input_t input;
1139 q = vl_api_client_index_to_input_queue (mp->client_index);
1143 rp = vl_msg_api_alloc (sizeof (*rp));
1144 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
1145 rp->context = mp->context;
1147 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
1149 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
1151 pthread_mutex_lock (&am->vlib_rp->mutex);
1152 oldheap = svm_push_data_heap (am->vlib_rp);
1154 vec_add1 (shmem_vec, 0);
1156 svm_pop_heap (oldheap);
1157 pthread_mutex_unlock (&am->vlib_rp->mutex);
1159 rp->reply_in_shmem = (uword) shmem_vec;
1161 vl_msg_api_send_shmem (q, (u8 *) & rp);
1165 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1167 u8 **mem_vecp = (u8 **) arg;
1168 u8 *mem_vec = *mem_vecp;
1169 u32 offset = vec_len (mem_vec);
1171 vec_validate (mem_vec, offset + buffer_bytes - 1);
1172 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
1173 *mem_vecp = mem_vec;
1177 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
1179 vl_api_cli_inband_reply_t *rmp;
1181 unix_shared_memory_queue_t *q;
1182 vlib_main_t *vm = vlib_get_main ();
1183 unformat_input_t input;
1186 q = vl_api_client_index_to_input_queue (mp->client_index);
1190 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
1191 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
1193 u32 len = vec_len (out_vec);
1195 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
1197 rmp->length = htonl (len);
1198 clib_memcpy (rmp->reply, out_vec, len);
1205 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
1208 vl_api_set_arp_neighbor_limit_reply_t *rmp;
1209 vnet_main_t *vnm = vnet_get_main ();
1210 clib_error_t *error;
1215 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
1217 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
1221 clib_error_report (error);
1222 rv = VNET_API_ERROR_UNSPECIFIED;
1226 rv = vnm->api_errno;
1229 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
1232 static void vl_api_classify_set_interface_ip_table_t_handler
1233 (vl_api_classify_set_interface_ip_table_t * mp)
1235 vlib_main_t *vm = vlib_get_main ();
1236 vl_api_classify_set_interface_ip_table_reply_t *rmp;
1238 u32 table_index, sw_if_index;
1240 table_index = ntohl (mp->table_index);
1241 sw_if_index = ntohl (mp->sw_if_index);
1243 VALIDATE_SW_IF_INDEX (mp);
1246 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
1248 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
1250 BAD_SW_IF_INDEX_LABEL;
1252 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
1255 static void vl_api_classify_set_interface_l2_tables_t_handler
1256 (vl_api_classify_set_interface_l2_tables_t * mp)
1258 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
1260 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
1263 ip4_table_index = ntohl (mp->ip4_table_index);
1264 ip6_table_index = ntohl (mp->ip6_table_index);
1265 other_table_index = ntohl (mp->other_table_index);
1266 sw_if_index = ntohl (mp->sw_if_index);
1268 VALIDATE_SW_IF_INDEX (mp);
1271 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
1275 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
1281 if (ip4_table_index != ~0 || ip6_table_index != ~0
1282 || other_table_index != ~0)
1288 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
1290 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
1293 BAD_SW_IF_INDEX_LABEL;
1295 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
1298 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1299 u32 sw_if_index, u32 enable);
1302 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1306 vl_api_l2_interface_efp_filter_reply_t *rmp;
1307 vnet_main_t *vnm = vnet_get_main ();
1309 // enable/disable the feature
1310 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
1311 rv = vnm->api_errno;
1313 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1317 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
1319 vl_api_show_version_reply_t *rmp;
1321 char *vpe_api_get_build_directory (void);
1322 char *vpe_api_get_version (void);
1323 char *vpe_api_get_build_date (void);
1325 unix_shared_memory_queue_t *q =
1326 vl_api_client_index_to_input_queue (mp->client_index);
1332 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
1334 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
1335 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
1336 ARRAY_LEN(rmp->build_directory)-1);
1337 strncpy ((char *) rmp->version, vpe_api_get_version(),
1338 ARRAY_LEN(rmp->version)-1);
1339 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
1340 ARRAY_LEN(rmp->build_date)-1);
1346 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
1348 vlib_main_t *vm = vlib_get_main ();
1349 vl_api_get_node_index_reply_t *rmp;
1352 u32 node_index = ~0;
1354 n = vlib_get_node_by_name (vm, mp->node_name);
1357 rv = VNET_API_ERROR_NO_SUCH_NODE;
1359 node_index = n->index;
1362 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1364 rmp->node_index = ntohl(node_index);
1370 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
1372 vlib_main_t *vm = vlib_get_main ();
1373 vl_api_get_next_index_reply_t *rmp;
1374 vlib_node_t *node, *next_node;
1376 u32 next_node_index = ~0, next_index = ~0;
1379 node = vlib_get_node_by_name (vm, mp->node_name);
1383 rv = VNET_API_ERROR_NO_SUCH_NODE;
1387 next_node = vlib_get_node_by_name (vm, mp->next_name);
1391 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1395 next_node_index = next_node->index;
1397 p = hash_get (node->next_slot_by_node, next_node_index);
1401 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1409 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
1411 rmp->next_index = ntohl(next_index);
1417 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
1419 vlib_main_t *vm = vlib_get_main ();
1420 vl_api_add_node_next_reply_t *rmp;
1421 vlib_node_t *n, *next;
1423 u32 next_index = ~0;
1425 n = vlib_get_node_by_name (vm, mp->node_name);
1429 rv = VNET_API_ERROR_NO_SUCH_NODE;
1433 next = vlib_get_node_by_name (vm, mp->next_name);
1436 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1438 next_index = vlib_node_add_next (vm, n->index, next->index);
1442 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1444 rmp->next_index = ntohl(next_index);
1449 static void vl_api_vxlan_add_del_tunnel_t_handler
1450 (vl_api_vxlan_add_del_tunnel_t * mp)
1452 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
1454 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
1455 u32 encap_fib_index;
1457 ip4_main_t *im = &ip4_main;
1458 vnet_main_t *vnm = vnet_get_main ();
1459 u32 sw_if_index = ~0;
1461 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1464 rv = VNET_API_ERROR_NO_SUCH_FIB;
1467 encap_fib_index = p[0];
1468 memset (a, 0, sizeof (*a));
1470 a->is_add = mp->is_add;
1471 a->is_ip6 = mp->is_ipv6;
1473 /* ip addresses sent in network byte order */
1474 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
1475 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
1477 /* Check src & dst are different */
1478 if (ip46_address_cmp (&a->dst, &a->src) == 0)
1480 rv = VNET_API_ERROR_SAME_SRC_DST;
1483 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
1484 if (ip46_address_is_multicast (&a->dst) &&
1485 pool_is_free_index (vnm->interface_main.sw_interfaces,
1486 a->mcast_sw_if_index))
1488 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1491 a->encap_fib_index = encap_fib_index;
1492 a->decap_next_index = ntohl (mp->decap_next_index);
1493 a->vni = ntohl (mp->vni);
1494 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
1498 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
1500 rmp->sw_if_index = ntohl (sw_if_index);
1505 static void send_vxlan_tunnel_details
1506 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1508 vl_api_vxlan_tunnel_details_t *rmp;
1509 ip4_main_t *im4 = &ip4_main;
1510 ip6_main_t *im6 = &ip6_main;
1511 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
1513 rmp = vl_msg_api_alloc (sizeof (*rmp));
1514 memset (rmp, 0, sizeof (*rmp));
1515 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
1518 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
1519 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
1520 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1524 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
1525 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
1526 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1528 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
1529 rmp->vni = htonl (t->vni);
1530 rmp->decap_next_index = htonl (t->decap_next_index);
1531 rmp->sw_if_index = htonl (t->sw_if_index);
1532 rmp->is_ipv6 = is_ipv6;
1533 rmp->context = context;
1535 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1538 static void vl_api_vxlan_tunnel_dump_t_handler
1539 (vl_api_vxlan_tunnel_dump_t * mp)
1541 unix_shared_memory_queue_t *q;
1542 vxlan_main_t *vxm = &vxlan_main;
1546 q = vl_api_client_index_to_input_queue (mp->client_index);
1552 sw_if_index = ntohl (mp->sw_if_index);
1554 if (~0 == sw_if_index)
1557 pool_foreach (t, vxm->tunnels,
1559 send_vxlan_tunnel_details(t, q, mp->context);
1565 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
1566 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
1570 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
1571 send_vxlan_tunnel_details (t, q, mp->context);
1576 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1578 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1580 vl_api_l2_patch_add_del_reply_t *rmp;
1581 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1585 VALIDATE_RX_SW_IF_INDEX (mp);
1586 VALIDATE_TX_SW_IF_INDEX (mp);
1588 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1589 ntohl (mp->tx_sw_if_index),
1590 (int) (mp->is_add != 0));
1592 BAD_RX_SW_IF_INDEX_LABEL;
1593 BAD_TX_SW_IF_INDEX_LABEL;
1595 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1599 vl_api_vxlan_gpe_add_del_tunnel_t_handler
1600 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
1602 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
1604 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
1605 u32 encap_fib_index, decap_fib_index;
1608 ip4_main_t *im = &ip4_main;
1609 u32 sw_if_index = ~0;
1612 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1615 rv = VNET_API_ERROR_NO_SUCH_FIB;
1618 encap_fib_index = p[0];
1620 protocol = mp->protocol;
1622 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
1623 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
1625 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
1628 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
1631 decap_fib_index = p[0];
1635 decap_fib_index = ntohl (mp->decap_vrf_id);
1638 /* Check src & dst are different */
1639 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
1640 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
1642 rv = VNET_API_ERROR_SAME_SRC_DST;
1645 memset (a, 0, sizeof (*a));
1647 a->is_add = mp->is_add;
1648 a->is_ip6 = mp->is_ipv6;
1649 /* ip addresses sent in network byte order */
1652 clib_memcpy (&(a->local.ip6), mp->local, 16);
1653 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
1657 clib_memcpy (&(a->local.ip4), mp->local, 4);
1658 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
1660 a->encap_fib_index = encap_fib_index;
1661 a->decap_fib_index = decap_fib_index;
1662 a->protocol = protocol;
1663 a->vni = ntohl (mp->vni);
1664 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
1668 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
1670 rmp->sw_if_index = ntohl (sw_if_index);
1675 static void send_vxlan_gpe_tunnel_details
1676 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1678 vl_api_vxlan_gpe_tunnel_details_t *rmp;
1679 ip4_main_t *im4 = &ip4_main;
1680 ip6_main_t *im6 = &ip6_main;
1681 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
1683 rmp = vl_msg_api_alloc (sizeof (*rmp));
1684 memset (rmp, 0, sizeof (*rmp));
1685 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
1688 memcpy (rmp->local, &(t->local.ip6), 16);
1689 memcpy (rmp->remote, &(t->remote.ip6), 16);
1690 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1691 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
1695 memcpy (rmp->local, &(t->local.ip4), 4);
1696 memcpy (rmp->remote, &(t->remote.ip4), 4);
1697 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1698 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
1700 rmp->vni = htonl (t->vni);
1701 rmp->protocol = t->protocol;
1702 rmp->sw_if_index = htonl (t->sw_if_index);
1703 rmp->is_ipv6 = is_ipv6;
1704 rmp->context = context;
1706 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1709 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
1710 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
1712 unix_shared_memory_queue_t *q;
1713 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
1714 vxlan_gpe_tunnel_t *t;
1717 q = vl_api_client_index_to_input_queue (mp->client_index);
1723 sw_if_index = ntohl (mp->sw_if_index);
1725 if (~0 == sw_if_index)
1728 pool_foreach (t, vgm->tunnels,
1730 send_vxlan_gpe_tunnel_details(t, q, mp->context);
1736 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
1737 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
1741 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
1742 send_vxlan_gpe_tunnel_details (t, q, mp->context);
1747 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1750 vl_api_interface_name_renumber_reply_t *rmp;
1753 VALIDATE_SW_IF_INDEX (mp);
1755 rv = vnet_interface_name_renumber
1756 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1758 BAD_SW_IF_INDEX_LABEL;
1760 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1764 arp_change_data_callback (u32 pool_index, u8 * new_mac,
1765 u32 sw_if_index, u32 address)
1767 vpe_api_main_t *am = &vpe_api_main;
1768 vlib_main_t *vm = am->vlib_main;
1769 vl_api_ip4_arp_event_t *event;
1770 static f64 arp_event_last_time;
1771 f64 now = vlib_time_now (vm);
1773 if (pool_is_free_index (am->arp_events, pool_index))
1776 event = pool_elt_at_index (am->arp_events, pool_index);
1778 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1780 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1784 if (sw_if_index == event->sw_if_index &&
1786 /* for BD case, also check IP address with 10 sec timeout */
1787 (address == event->address &&
1788 (now - arp_event_last_time) < 10.0)))
1793 arp_event_last_time = now;
1794 event->sw_if_index = sw_if_index;
1796 event->address = address;
1801 nd_change_data_callback (u32 pool_index, u8 * new_mac,
1802 u32 sw_if_index, ip6_address_t * address)
1804 vpe_api_main_t *am = &vpe_api_main;
1805 vlib_main_t *vm = am->vlib_main;
1806 vl_api_ip6_nd_event_t *event;
1807 static f64 nd_event_last_time;
1808 f64 now = vlib_time_now (vm);
1810 if (pool_is_free_index (am->nd_events, pool_index))
1813 event = pool_elt_at_index (am->nd_events, pool_index);
1816 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1818 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1822 if (sw_if_index == event->sw_if_index &&
1824 /* for BD case, also check IP address with 10 sec timeout */
1825 (ip6_address_is_equal (address,
1826 (ip6_address_t *) event->address) &&
1827 (now - nd_event_last_time) < 10.0)))
1832 nd_event_last_time = now;
1833 event->sw_if_index = sw_if_index;
1835 clib_memcpy (event->address, address, sizeof (event->address));
1840 arp_change_delete_callback (u32 pool_index, u8 * notused)
1842 vpe_api_main_t *am = &vpe_api_main;
1844 if (pool_is_free_index (am->arp_events, pool_index))
1847 pool_put_index (am->arp_events, pool_index);
1852 nd_change_delete_callback (u32 pool_index, u8 * notused)
1854 vpe_api_main_t *am = &vpe_api_main;
1856 if (pool_is_free_index (am->nd_events, pool_index))
1859 pool_put_index (am->nd_events, pool_index);
1864 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
1866 vpe_api_main_t *am = &vpe_api_main;
1867 vnet_main_t *vnm = vnet_get_main ();
1868 vl_api_want_ip4_arp_events_reply_t *rmp;
1869 vl_api_ip4_arp_event_t *event;
1872 if (mp->enable_disable)
1874 pool_get (am->arp_events, event);
1875 memset (event, 0, sizeof (*event));
1877 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
1878 event->client_index = mp->client_index;
1879 event->context = mp->context;
1880 event->address = mp->address;
1881 event->pid = mp->pid;
1882 if (mp->address == 0)
1885 rv = vnet_add_del_ip4_arp_change_event
1886 (vnm, arp_change_data_callback,
1887 mp->pid, &mp->address /* addr, in net byte order */ ,
1888 vpe_resolver_process_node.index,
1889 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
1893 rv = vnet_add_del_ip4_arp_change_event
1894 (vnm, arp_change_delete_callback,
1895 mp->pid, &mp->address /* addr, in net byte order */ ,
1896 vpe_resolver_process_node.index,
1897 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1899 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
1903 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
1905 vpe_api_main_t *am = &vpe_api_main;
1906 vnet_main_t *vnm = vnet_get_main ();
1907 vl_api_want_ip6_nd_events_reply_t *rmp;
1908 vl_api_ip6_nd_event_t *event;
1911 if (mp->enable_disable)
1913 pool_get (am->nd_events, event);
1914 memset (event, 0, sizeof (*event));
1916 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
1917 event->client_index = mp->client_index;
1918 event->context = mp->context;
1919 clib_memcpy (event->address, mp->address, 16);
1920 event->pid = mp->pid;
1921 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
1924 rv = vnet_add_del_ip6_nd_change_event
1925 (vnm, nd_change_data_callback,
1926 mp->pid, mp->address /* addr, in net byte order */ ,
1927 vpe_resolver_process_node.index,
1928 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
1932 rv = vnet_add_del_ip6_nd_change_event
1933 (vnm, nd_change_delete_callback,
1934 mp->pid, mp->address /* addr, in net byte order */ ,
1935 vpe_resolver_process_node.index,
1936 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1938 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
1941 static void vl_api_input_acl_set_interface_t_handler
1942 (vl_api_input_acl_set_interface_t * mp)
1944 vlib_main_t *vm = vlib_get_main ();
1945 vl_api_input_acl_set_interface_reply_t *rmp;
1947 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
1949 ip4_table_index = ntohl (mp->ip4_table_index);
1950 ip6_table_index = ntohl (mp->ip6_table_index);
1951 l2_table_index = ntohl (mp->l2_table_index);
1952 sw_if_index = ntohl (mp->sw_if_index);
1954 VALIDATE_SW_IF_INDEX (mp);
1956 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
1957 ip6_table_index, l2_table_index, mp->is_add);
1959 BAD_SW_IF_INDEX_LABEL;
1961 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
1964 static void vl_api_cop_interface_enable_disable_t_handler
1965 (vl_api_cop_interface_enable_disable_t * mp)
1967 vl_api_cop_interface_enable_disable_reply_t *rmp;
1969 u32 sw_if_index = ntohl (mp->sw_if_index);
1972 VALIDATE_SW_IF_INDEX (mp);
1974 enable_disable = (int) mp->enable_disable;
1976 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
1978 BAD_SW_IF_INDEX_LABEL;
1980 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
1983 static void vl_api_cop_whitelist_enable_disable_t_handler
1984 (vl_api_cop_whitelist_enable_disable_t * mp)
1986 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
1987 cop_whitelist_enable_disable_args_t _a, *a = &_a;
1988 u32 sw_if_index = ntohl (mp->sw_if_index);
1991 VALIDATE_SW_IF_INDEX (mp);
1993 a->sw_if_index = sw_if_index;
1996 a->default_cop = mp->default_cop;
1997 a->fib_id = ntohl (mp->fib_id);
1999 rv = cop_whitelist_enable_disable (a);
2001 BAD_SW_IF_INDEX_LABEL;
2003 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
2007 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
2011 api_main_t *am = &api_main;
2012 vlib_main_t *vm = vlib_get_main ();
2014 vl_api_get_node_graph_reply_t *rmp;
2016 pthread_mutex_lock (&am->vlib_rp->mutex);
2017 oldheap = svm_push_data_heap (am->vlib_rp);
2020 * Keep the number of memcpy ops to a minimum (e.g. 1).
2022 vec_validate (vector, 16384);
2023 vec_reset_length (vector);
2026 vector = vlib_node_serialize (&vm->node_main, vector,
2027 (u32) ~ 0 /* all threads */ ,
2028 1 /* include nexts */ ,
2029 1 /* include stats */ );
2031 svm_pop_heap (oldheap);
2032 pthread_mutex_unlock (&am->vlib_rp->mutex);
2035 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
2037 rmp->reply_in_shmem = (uword) vector;
2043 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
2046 vl_api_ioam_enable_reply_t *rmp;
2047 clib_error_t *error;
2049 /* Ignoring the profile id as currently a single profile
2051 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
2052 mp->seqno, mp->analyse);
2055 clib_error_report (error);
2056 rv = clib_error_get_code (error);
2059 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
2063 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
2066 vl_api_ioam_disable_reply_t *rmp;
2067 clib_error_t *error;
2069 error = clear_ioam_rewrite_fn ();
2072 clib_error_report (error);
2073 rv = clib_error_get_code (error);
2076 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
2080 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
2082 vlib_main_t *vm = vlib_get_main ();
2083 vl_api_policer_add_del_reply_t *rmp;
2086 sse2_qos_pol_cfg_params_st cfg;
2087 clib_error_t *error;
2090 name = format (0, "%s", mp->name);
2092 memset (&cfg, 0, sizeof (cfg));
2094 cfg.rnd_type = mp->round_type;
2095 cfg.rate_type = mp->rate_type;
2096 cfg.rb.kbps.cir_kbps = mp->cir;
2097 cfg.rb.kbps.eir_kbps = mp->eir;
2098 cfg.rb.kbps.cb_bytes = mp->cb;
2099 cfg.rb.kbps.eb_bytes = mp->eb;
2100 cfg.conform_action.action_type = mp->conform_action_type;
2101 cfg.conform_action.dscp = mp->conform_dscp;
2102 cfg.exceed_action.action_type = mp->exceed_action_type;
2103 cfg.exceed_action.dscp = mp->exceed_dscp;
2104 cfg.violate_action.action_type = mp->violate_action_type;
2105 cfg.violate_action.dscp = mp->violate_dscp;
2106 cfg.color_aware = mp->color_aware;
2108 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
2111 rv = VNET_API_ERROR_UNSPECIFIED;
2114 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
2116 if (rv == 0 && mp->is_add)
2117 rmp->policer_index = ntohl(policer_index);
2119 rmp->policer_index = ~0;
2125 send_policer_details (u8 * name,
2126 sse2_qos_pol_cfg_params_st * config,
2127 policer_read_response_type_st * templ,
2128 unix_shared_memory_queue_t * q, u32 context)
2130 vl_api_policer_details_t *mp;
2132 mp = vl_msg_api_alloc (sizeof (*mp));
2133 memset (mp, 0, sizeof (*mp));
2134 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
2135 mp->context = context;
2136 mp->cir = htonl (config->rb.kbps.cir_kbps);
2137 mp->eir = htonl (config->rb.kbps.eir_kbps);
2138 mp->cb = htonl (config->rb.kbps.cb_bytes);
2139 mp->eb = htonl (config->rb.kbps.eb_bytes);
2140 mp->rate_type = config->rate_type;
2141 mp->round_type = config->rnd_type;
2142 mp->type = config->rfc;
2143 mp->conform_action_type = config->conform_action.action_type;
2144 mp->conform_dscp = config->conform_action.dscp;
2145 mp->exceed_action_type = config->exceed_action.action_type;
2146 mp->exceed_dscp = config->exceed_action.dscp;
2147 mp->violate_action_type = config->violate_action.action_type;
2148 mp->violate_dscp = config->violate_action.dscp;
2149 mp->single_rate = templ->single_rate ? 1 : 0;
2150 mp->color_aware = templ->color_aware ? 1 : 0;
2151 mp->scale = htonl (templ->scale);
2152 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
2153 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
2154 mp->current_limit = htonl (templ->current_limit);
2155 mp->current_bucket = htonl (templ->current_bucket);
2156 mp->extended_limit = htonl (templ->extended_limit);
2157 mp->extended_bucket = htonl (templ->extended_bucket);
2158 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
2160 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
2162 vl_msg_api_send_shmem (q, (u8 *) & mp);
2166 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
2168 unix_shared_memory_queue_t *q;
2169 vnet_policer_main_t *pm = &vnet_policer_main;
2175 sse2_qos_pol_cfg_params_st *config;
2176 policer_read_response_type_st *templ;
2178 q = vl_api_client_index_to_input_queue (mp->client_index);
2182 if (mp->match_name_valid)
2184 match_name = format (0, "%s%c", mp->match_name, 0);
2187 if (mp->match_name_valid)
2189 p = hash_get_mem (pm->policer_config_by_name, match_name);
2193 config = pool_elt_at_index (pm->configs, pool_index);
2194 templ = pool_elt_at_index (pm->policer_templates, pool_index);
2195 send_policer_details (match_name, config, templ, q, mp->context);
2201 hash_foreach_pair (hp, pm->policer_config_by_name,
2203 name = (u8 *) hp->key;
2204 pool_index = hp->value[0];
2205 config = pool_elt_at_index (pm->configs, pool_index);
2206 templ = pool_elt_at_index (pm->policer_templates, pool_index);
2207 send_policer_details(name, config, templ, q, mp->context);
2215 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
2217 vl_api_pg_create_interface_reply_t *rmp;
2220 pg_main_t *pg = &pg_main;
2221 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
2222 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
2225 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
2227 rmp->sw_if_index = ntohl(pi->sw_if_index);
2233 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
2235 vl_api_pg_capture_reply_t *rmp;
2238 vnet_main_t *vnm = vnet_get_main ();
2239 vnet_interface_main_t *im = &vnm->interface_main;
2240 vnet_hw_interface_t *hi = 0;
2242 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
2243 u32 hw_if_index = ~0;
2244 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
2247 vec_free (intf_name);
2249 if (hw_if_index != ~0)
2251 pg_capture_args_t _a, *a = &_a;
2253 u32 len = ntohl (mp->pcap_name_length);
2254 u8 *pcap_file_name = vec_new (u8, len);
2255 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
2257 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
2258 a->hw_if_index = hw_if_index;
2259 a->dev_instance = hi->dev_instance;
2260 a->is_enabled = mp->is_enabled;
2261 a->pcap_file_name = pcap_file_name;
2262 a->count = ntohl (mp->count);
2264 clib_error_t *e = pg_capture (a);
2267 clib_error_report (e);
2268 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
2271 vec_free (pcap_file_name);
2273 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
2277 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
2279 vl_api_pg_enable_disable_reply_t *rmp;
2282 pg_main_t *pg = &pg_main;
2283 u32 stream_index = ~0;
2285 int is_enable = mp->is_enabled != 0;
2286 u32 len = ntohl (mp->stream_name_length) - 1;
2290 u8 *stream_name = vec_new (u8, len);
2291 clib_memcpy (stream_name, mp->stream_name, len);
2292 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
2295 vec_free (stream_name);
2298 pg_enable_disable (stream_index, is_enable);
2300 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
2304 vl_api_ip_source_and_port_range_check_add_del_t_handler
2305 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
2307 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
2310 u8 is_ipv6 = mp->is_ipv6;
2311 u8 is_add = mp->is_add;
2312 u8 mask_length = mp->mask_length;
2313 ip4_address_t ip4_addr;
2314 ip6_address_t ip6_addr;
2316 u16 *high_ports = 0;
2318 u16 tmp_low, tmp_high;
2322 // Validate port range
2323 num_ranges = mp->number_of_ranges;
2324 if (num_ranges > 32)
2325 { // This is size of array in VPE.API
2326 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
2330 vec_reset_length (low_ports);
2331 vec_reset_length (high_ports);
2333 for (i = 0; i < num_ranges; i++)
2335 tmp_low = mp->low_ports[i];
2336 tmp_high = mp->high_ports[i];
2337 // If tmp_low <= tmp_high then only need to check tmp_low = 0
2338 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
2339 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
2341 rv = VNET_API_ERROR_INVALID_VALUE;
2344 vec_add1 (low_ports, tmp_low);
2345 vec_add1 (high_ports, tmp_high + 1);
2348 // Validate mask_length
2349 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
2351 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
2355 vrf_id = ntohl (mp->vrf_id);
2359 rv = VNET_API_ERROR_INVALID_VALUE;
2366 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
2367 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
2371 high_ports, is_add);
2375 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
2376 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
2380 high_ports, is_add);
2384 vec_free (low_ports);
2385 vec_free (high_ports);
2386 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
2390 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
2391 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
2393 vlib_main_t *vm = vlib_get_main ();
2394 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
2395 ip4_main_t *im = &ip4_main;
2398 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2399 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2403 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
2404 ntohl (mp->tcp_out_vrf_id);
2405 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
2406 ntohl (mp->udp_out_vrf_id);
2407 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
2408 ntohl (mp->tcp_in_vrf_id);
2409 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
2410 ntohl (mp->udp_in_vrf_id);
2413 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
2415 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
2417 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
2421 rv = VNET_API_ERROR_INVALID_VALUE;
2425 fib_index[i] = p[0];
2430 sw_if_index = ntohl (mp->sw_if_index);
2432 VALIDATE_SW_IF_INDEX (mp);
2435 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
2438 BAD_SW_IF_INDEX_LABEL;
2441 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
2445 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
2447 vl_api_delete_subif_reply_t *rmp;
2450 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
2452 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
2456 vl_api_punt_t_handler (vl_api_punt_t * mp)
2458 vl_api_punt_reply_t *rmp;
2459 vlib_main_t *vm = vlib_get_main ();
2461 clib_error_t *error;
2463 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
2464 ntohs (mp->l4_port), mp->is_add);
2468 clib_error_report (error);
2471 REPLY_MACRO (VL_API_PUNT_REPLY);
2475 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
2477 vl_api_feature_enable_disable_reply_t *rmp;
2479 u8 *arc_name, *feature_name;
2481 VALIDATE_SW_IF_INDEX (mp);
2483 arc_name = format (0, "%s%c", mp->arc_name, 0);
2484 feature_name = format (0, "%s%c", mp->feature_name, 0);
2486 vnet_feature_registration_t *reg;
2488 vnet_get_feature_reg ((const char *) arc_name,
2489 (const char *) feature_name);
2491 rv = VNET_API_ERROR_INVALID_VALUE;
2495 clib_error_t *error = 0;
2497 sw_if_index = ntohl (mp->sw_if_index);
2498 if (reg->enable_disable_cb)
2499 error = reg->enable_disable_cb (sw_if_index, mp->enable);
2501 vnet_feature_enable_disable ((const char *) arc_name,
2502 (const char *) feature_name,
2503 sw_if_index, mp->enable, 0, 0);
2506 clib_error_report (error);
2507 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
2511 vec_free (feature_name);
2512 vec_free (arc_name);
2514 BAD_SW_IF_INDEX_LABEL;
2516 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
2519 #define BOUNCE_HANDLER(nn) \
2520 static void vl_api_##nn##_t_handler ( \
2521 vl_api_##nn##_t *mp) \
2523 vpe_client_registration_t *reg; \
2524 vpe_api_main_t * vam = &vpe_api_main; \
2525 unix_shared_memory_queue_t * q; \
2527 /* One registration only... */ \
2528 pool_foreach(reg, vam->nn##_registrations, \
2530 q = vl_api_client_index_to_input_queue (reg->client_index); \
2533 * If the queue is stuffed, turf the msg and complain \
2534 * It's unlikely that the intended recipient is \
2535 * alive; avoid deadlock at all costs. \
2537 if (q->cursize == q->maxsize) { \
2538 clib_warning ("ERROR: receiver queue full, drop msg"); \
2539 vl_msg_api_free (mp); \
2542 vl_msg_api_send_shmem (q, (u8 *)&mp); \
2546 vl_msg_api_free (mp); \
2549 static void setup_message_id_table (api_main_t * am);
2553 * Add vpe's API message handlers to the table.
2554 * vlib has alread mapped shared memory and
2555 * added the client registration handlers.
2556 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
2558 static clib_error_t *
2559 vpe_api_hookup (vlib_main_t * vm)
2561 api_main_t *am = &api_main;
2564 vl_msg_api_set_handlers(VL_API_##N, #n, \
2565 vl_api_##n##_t_handler, \
2567 vl_api_##n##_t_endian, \
2568 vl_api_##n##_t_print, \
2569 sizeof(vl_api_##n##_t), 1);
2570 foreach_vpe_api_msg;
2574 * Trace space for classifier mask+match
2576 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
2577 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
2578 += 5 * sizeof (u32x4);
2579 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
2582 * Thread-safe API messages
2584 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
2585 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
2588 * Set up the (msg_name, crc, message-id) table
2590 setup_message_id_table (am);
2595 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
2597 static clib_error_t *
2598 vpe_api_init (vlib_main_t * vm)
2600 vpe_api_main_t *am = &vpe_api_main;
2603 am->vnet_main = vnet_get_main ();
2604 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
2605 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2606 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2607 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2608 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2609 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
2610 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
2613 vl_set_memory_region_name ("/vpe-api");
2614 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
2619 VLIB_INIT_FUNCTION (vpe_api_init);
2622 static clib_error_t *
2623 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
2626 u64 baseva, size, pvt_heap_size;
2628 const int max_buf_size = 4096;
2630 struct passwd _pw, *pw;
2631 struct group _grp, *grp;
2633 buf = vec_new (char, 128);
2634 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2636 if (unformat (input, "prefix %s", &chroot_path))
2638 vec_add1 (chroot_path, 0);
2639 vl_set_memory_root_path ((char *) chroot_path);
2641 else if (unformat (input, "uid %d", &uid))
2642 vl_set_memory_uid (uid);
2643 else if (unformat (input, "gid %d", &gid))
2644 vl_set_memory_gid (gid);
2645 else if (unformat (input, "baseva %llx", &baseva))
2646 vl_set_global_memory_baseva (baseva);
2647 else if (unformat (input, "global-size %lldM", &size))
2648 vl_set_global_memory_size (size * (1ULL << 20));
2649 else if (unformat (input, "global-size %lldG", &size))
2650 vl_set_global_memory_size (size * (1ULL << 30));
2651 else if (unformat (input, "global-size %lld", &size))
2652 vl_set_global_memory_size (size);
2653 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
2654 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2655 else if (unformat (input, "global-pvt-heap-size size %lld",
2657 vl_set_global_pvt_heap_size (pvt_heap_size);
2658 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
2659 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2660 else if (unformat (input, "api-pvt-heap-size size %lld",
2662 vl_set_api_pvt_heap_size (pvt_heap_size);
2663 else if (unformat (input, "api-size %lldM", &size))
2664 vl_set_api_memory_size (size * (1ULL << 20));
2665 else if (unformat (input, "api-size %lldG", &size))
2666 vl_set_api_memory_size (size * (1ULL << 30));
2667 else if (unformat (input, "api-size %lld", &size))
2668 vl_set_api_memory_size (size);
2669 else if (unformat (input, "uid %s", &s))
2671 /* lookup the username */
2674 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
2675 && (vec_len (buf) <= max_buf_size))
2677 vec_resize (buf, vec_len (buf) * 2);
2681 e = clib_error_return_code (0, rv,
2682 CLIB_ERROR_ERRNO_VALID |
2684 "cannot fetch username %s", s);
2692 clib_error_return_fatal (0, "username %s does not exist", s);
2698 vl_set_memory_uid (pw->pw_uid);
2700 else if (unformat (input, "gid %s", &s))
2702 /* lookup the group name */
2705 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
2706 && (vec_len (buf) <= max_buf_size))
2708 vec_resize (buf, vec_len (buf) * 2);
2712 e = clib_error_return_code (0, rv,
2713 CLIB_ERROR_ERRNO_VALID |
2715 "cannot fetch group %s", s);
2722 e = clib_error_return_fatal (0, "group %s does not exist", s);
2729 vl_set_memory_gid (grp->gr_gid);
2732 return clib_error_return (0, "unknown input `%U'",
2733 format_unformat_error, input);
2738 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
2741 get_unformat_vnet_sw_interface (void)
2743 return (void *) &unformat_vnet_sw_interface;
2747 format_arp_event (u8 * s, va_list * args)
2749 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
2751 s = format (s, "pid %d: ", event->pid);
2753 s = format (s, "bd mac/ip4 binding events");
2755 s = format (s, "resolution for %U", format_ip4_address, &event->address);
2760 format_nd_event (u8 * s, va_list * args)
2762 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
2764 s = format (s, "pid %d: ", event->pid);
2766 s = format (s, "bd mac/ip6 binding events");
2768 s = format (s, "resolution for %U", format_ip6_address, event->address);
2772 static clib_error_t *
2773 show_ip_arp_nd_events_fn (vlib_main_t * vm,
2774 unformat_input_t * input, vlib_cli_command_t * cmd)
2776 vpe_api_main_t *am = &vpe_api_main;
2777 vl_api_ip4_arp_event_t *arp_event;
2778 vl_api_ip6_nd_event_t *nd_event;
2780 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
2782 vlib_cli_output (vm, "No active arp or nd event registrations");
2787 pool_foreach (arp_event, am->arp_events,
2789 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
2792 pool_foreach (nd_event, am->nd_events,
2794 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
2802 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
2803 .path = "show arp-nd-event registrations",
2804 .function = show_ip_arp_nd_events_fn,
2805 .short_help = "Show ip4 arp and ip6 nd event registrations",
2809 #define vl_msg_name_crc_list
2810 #include <vpp/api/vpe_all_api_h.h>
2811 #undef vl_msg_name_crc_list
2814 setup_message_id_table (api_main_t * am)
2816 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2817 foreach_vl_msg_name_crc_memclnt;
2818 foreach_vl_msg_name_crc_vpe;
2824 * fd.io coding-style-patch-verification: ON
2827 * eval: (c-set-style "gnu")