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];
968 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
969 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
970 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
973 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
977 })); /* pool_foreach (fib) */
985 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
987 vnet_main_t *vnm = vnet_get_main ();
988 vnet_interface_main_t *im = &vnm->interface_main;
989 ip6_main_t *im6 = &ip6_main;
990 stats_main_t *sm = &stats_main;
991 static u32 *sw_if_indices_to_shut;
992 fib_table_t *fib_table;
996 int rv = VNET_API_ERROR_NO_SUCH_FIB;
997 u32 target_fib_id = ntohl (mp->vrf_id);
999 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
1002 pool_foreach (fib_table, im6->fibs,
1004 vnet_sw_interface_t * si;
1005 fib = &(fib_table->v6);
1007 if (fib->table_id != target_fib_id)
1010 vec_reset_length (sw_if_indices_to_shut);
1012 /* Shut down interfaces in this FIB / clean out intfc routes */
1013 pool_foreach (si, im->sw_interfaces,
1015 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1017 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1020 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1021 sw_if_index = sw_if_indices_to_shut[i];
1023 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1024 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1025 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1028 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1032 })); /* pool_foreach (fib) */
1040 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1043 vl_api_reset_fib_reply_t *rmp;
1046 rv = ip6_reset_fib_t_handler (mp);
1048 rv = ip4_reset_fib_t_handler (mp);
1050 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1054 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1056 vl_api_create_loopback_reply_t *rmp;
1060 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1063 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1065 rmp->sw_if_index = ntohl (sw_if_index);
1071 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1073 vl_api_delete_loopback_reply_t *rmp;
1077 sw_if_index = ntohl (mp->sw_if_index);
1078 rv = vnet_delete_loopback_interface (sw_if_index);
1080 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1084 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1086 vl_api_control_ping_reply_t *rmp;
1090 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1092 rmp->vpe_pid = ntohl (getpid());
1098 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1100 u8 **shmem_vecp = (u8 **) arg;
1103 api_main_t *am = &api_main;
1106 shmem_vec = *shmem_vecp;
1108 offset = vec_len (shmem_vec);
1110 pthread_mutex_lock (&am->vlib_rp->mutex);
1111 oldheap = svm_push_data_heap (am->vlib_rp);
1113 vec_validate (shmem_vec, offset + buffer_bytes - 1);
1115 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
1117 svm_pop_heap (oldheap);
1118 pthread_mutex_unlock (&am->vlib_rp->mutex);
1120 *shmem_vecp = shmem_vec;
1125 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
1127 vl_api_cli_reply_t *rp;
1128 unix_shared_memory_queue_t *q;
1129 vlib_main_t *vm = vlib_get_main ();
1130 api_main_t *am = &api_main;
1131 unformat_input_t input;
1135 q = vl_api_client_index_to_input_queue (mp->client_index);
1139 rp = vl_msg_api_alloc (sizeof (*rp));
1140 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
1141 rp->context = mp->context;
1143 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
1145 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
1147 pthread_mutex_lock (&am->vlib_rp->mutex);
1148 oldheap = svm_push_data_heap (am->vlib_rp);
1150 vec_add1 (shmem_vec, 0);
1152 svm_pop_heap (oldheap);
1153 pthread_mutex_unlock (&am->vlib_rp->mutex);
1155 rp->reply_in_shmem = (uword) shmem_vec;
1157 vl_msg_api_send_shmem (q, (u8 *) & rp);
1161 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1163 u8 **mem_vecp = (u8 **) arg;
1164 u8 *mem_vec = *mem_vecp;
1165 u32 offset = vec_len (mem_vec);
1167 vec_validate (mem_vec, offset + buffer_bytes - 1);
1168 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
1169 *mem_vecp = mem_vec;
1173 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
1175 vl_api_cli_inband_reply_t *rmp;
1177 unix_shared_memory_queue_t *q;
1178 vlib_main_t *vm = vlib_get_main ();
1179 unformat_input_t input;
1182 q = vl_api_client_index_to_input_queue (mp->client_index);
1186 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
1187 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
1189 u32 len = vec_len (out_vec);
1191 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
1193 rmp->length = htonl (len);
1194 clib_memcpy (rmp->reply, out_vec, len);
1201 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
1204 vl_api_set_arp_neighbor_limit_reply_t *rmp;
1205 vnet_main_t *vnm = vnet_get_main ();
1206 clib_error_t *error;
1211 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
1213 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
1217 clib_error_report (error);
1218 rv = VNET_API_ERROR_UNSPECIFIED;
1222 rv = vnm->api_errno;
1225 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
1228 static void vl_api_classify_set_interface_ip_table_t_handler
1229 (vl_api_classify_set_interface_ip_table_t * mp)
1231 vlib_main_t *vm = vlib_get_main ();
1232 vl_api_classify_set_interface_ip_table_reply_t *rmp;
1234 u32 table_index, sw_if_index;
1236 table_index = ntohl (mp->table_index);
1237 sw_if_index = ntohl (mp->sw_if_index);
1239 VALIDATE_SW_IF_INDEX (mp);
1242 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
1244 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
1246 BAD_SW_IF_INDEX_LABEL;
1248 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
1251 static void vl_api_classify_set_interface_l2_tables_t_handler
1252 (vl_api_classify_set_interface_l2_tables_t * mp)
1254 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
1256 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
1259 ip4_table_index = ntohl (mp->ip4_table_index);
1260 ip6_table_index = ntohl (mp->ip6_table_index);
1261 other_table_index = ntohl (mp->other_table_index);
1262 sw_if_index = ntohl (mp->sw_if_index);
1264 VALIDATE_SW_IF_INDEX (mp);
1267 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
1271 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
1277 if (ip4_table_index != ~0 || ip6_table_index != ~0
1278 || other_table_index != ~0)
1284 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
1286 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
1289 BAD_SW_IF_INDEX_LABEL;
1291 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
1294 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1295 u32 sw_if_index, u32 enable);
1298 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1302 vl_api_l2_interface_efp_filter_reply_t *rmp;
1303 vnet_main_t *vnm = vnet_get_main ();
1305 // enable/disable the feature
1306 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
1307 rv = vnm->api_errno;
1309 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1313 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
1315 vl_api_show_version_reply_t *rmp;
1317 char *vpe_api_get_build_directory (void);
1318 char *vpe_api_get_version (void);
1319 char *vpe_api_get_build_date (void);
1321 unix_shared_memory_queue_t *q =
1322 vl_api_client_index_to_input_queue (mp->client_index);
1328 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
1330 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
1331 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
1332 ARRAY_LEN(rmp->build_directory)-1);
1333 strncpy ((char *) rmp->version, vpe_api_get_version(),
1334 ARRAY_LEN(rmp->version)-1);
1335 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
1336 ARRAY_LEN(rmp->build_date)-1);
1342 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
1344 vlib_main_t *vm = vlib_get_main ();
1345 vl_api_get_node_index_reply_t *rmp;
1348 u32 node_index = ~0;
1350 n = vlib_get_node_by_name (vm, mp->node_name);
1353 rv = VNET_API_ERROR_NO_SUCH_NODE;
1355 node_index = n->index;
1358 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1360 rmp->node_index = ntohl(node_index);
1366 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
1368 vlib_main_t *vm = vlib_get_main ();
1369 vl_api_get_next_index_reply_t *rmp;
1370 vlib_node_t *node, *next_node;
1372 u32 next_node_index = ~0, next_index = ~0;
1375 node = vlib_get_node_by_name (vm, mp->node_name);
1379 rv = VNET_API_ERROR_NO_SUCH_NODE;
1383 next_node = vlib_get_node_by_name (vm, mp->next_name);
1387 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1391 next_node_index = next_node->index;
1393 p = hash_get (node->next_slot_by_node, next_node_index);
1397 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1405 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
1407 rmp->next_index = ntohl(next_index);
1413 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
1415 vlib_main_t *vm = vlib_get_main ();
1416 vl_api_add_node_next_reply_t *rmp;
1417 vlib_node_t *n, *next;
1419 u32 next_index = ~0;
1421 n = vlib_get_node_by_name (vm, mp->node_name);
1425 rv = VNET_API_ERROR_NO_SUCH_NODE;
1429 next = vlib_get_node_by_name (vm, mp->next_name);
1432 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1434 next_index = vlib_node_add_next (vm, n->index, next->index);
1438 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1440 rmp->next_index = ntohl(next_index);
1445 static void vl_api_vxlan_add_del_tunnel_t_handler
1446 (vl_api_vxlan_add_del_tunnel_t * mp)
1448 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
1450 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
1451 u32 encap_fib_index;
1453 ip4_main_t *im = &ip4_main;
1454 vnet_main_t *vnm = vnet_get_main ();
1455 u32 sw_if_index = ~0;
1457 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1460 rv = VNET_API_ERROR_NO_SUCH_FIB;
1463 encap_fib_index = p[0];
1464 memset (a, 0, sizeof (*a));
1466 a->is_add = mp->is_add;
1467 a->is_ip6 = mp->is_ipv6;
1469 /* ip addresses sent in network byte order */
1470 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
1471 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
1473 /* Check src & dst are different */
1474 if (ip46_address_cmp (&a->dst, &a->src) == 0)
1476 rv = VNET_API_ERROR_SAME_SRC_DST;
1479 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
1480 if (ip46_address_is_multicast (&a->dst) &&
1481 pool_is_free_index (vnm->interface_main.sw_interfaces,
1482 a->mcast_sw_if_index))
1484 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1487 a->encap_fib_index = encap_fib_index;
1488 a->decap_next_index = ntohl (mp->decap_next_index);
1489 a->vni = ntohl (mp->vni);
1490 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
1494 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
1496 rmp->sw_if_index = ntohl (sw_if_index);
1501 static void send_vxlan_tunnel_details
1502 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1504 vl_api_vxlan_tunnel_details_t *rmp;
1505 ip4_main_t *im4 = &ip4_main;
1506 ip6_main_t *im6 = &ip6_main;
1507 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
1509 rmp = vl_msg_api_alloc (sizeof (*rmp));
1510 memset (rmp, 0, sizeof (*rmp));
1511 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
1514 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
1515 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
1516 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1520 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
1521 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
1522 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1524 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
1525 rmp->vni = htonl (t->vni);
1526 rmp->decap_next_index = htonl (t->decap_next_index);
1527 rmp->sw_if_index = htonl (t->sw_if_index);
1528 rmp->is_ipv6 = is_ipv6;
1529 rmp->context = context;
1531 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1534 static void vl_api_vxlan_tunnel_dump_t_handler
1535 (vl_api_vxlan_tunnel_dump_t * mp)
1537 unix_shared_memory_queue_t *q;
1538 vxlan_main_t *vxm = &vxlan_main;
1542 q = vl_api_client_index_to_input_queue (mp->client_index);
1548 sw_if_index = ntohl (mp->sw_if_index);
1550 if (~0 == sw_if_index)
1553 pool_foreach (t, vxm->tunnels,
1555 send_vxlan_tunnel_details(t, q, mp->context);
1561 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
1562 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
1566 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
1567 send_vxlan_tunnel_details (t, q, mp->context);
1572 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1574 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1576 vl_api_l2_patch_add_del_reply_t *rmp;
1577 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1581 VALIDATE_RX_SW_IF_INDEX (mp);
1582 VALIDATE_TX_SW_IF_INDEX (mp);
1584 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1585 ntohl (mp->tx_sw_if_index),
1586 (int) (mp->is_add != 0));
1588 BAD_RX_SW_IF_INDEX_LABEL;
1589 BAD_TX_SW_IF_INDEX_LABEL;
1591 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1595 vl_api_vxlan_gpe_add_del_tunnel_t_handler
1596 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
1598 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
1600 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
1601 u32 encap_fib_index, decap_fib_index;
1604 ip4_main_t *im = &ip4_main;
1605 u32 sw_if_index = ~0;
1608 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1611 rv = VNET_API_ERROR_NO_SUCH_FIB;
1614 encap_fib_index = p[0];
1616 protocol = mp->protocol;
1618 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
1619 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
1621 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
1624 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
1627 decap_fib_index = p[0];
1631 decap_fib_index = ntohl (mp->decap_vrf_id);
1634 /* Check src & dst are different */
1635 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
1636 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
1638 rv = VNET_API_ERROR_SAME_SRC_DST;
1641 memset (a, 0, sizeof (*a));
1643 a->is_add = mp->is_add;
1644 a->is_ip6 = mp->is_ipv6;
1645 /* ip addresses sent in network byte order */
1648 clib_memcpy (&(a->local.ip6), mp->local, 16);
1649 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
1653 clib_memcpy (&(a->local.ip4), mp->local, 4);
1654 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
1656 a->encap_fib_index = encap_fib_index;
1657 a->decap_fib_index = decap_fib_index;
1658 a->protocol = protocol;
1659 a->vni = ntohl (mp->vni);
1660 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
1664 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
1666 rmp->sw_if_index = ntohl (sw_if_index);
1671 static void send_vxlan_gpe_tunnel_details
1672 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1674 vl_api_vxlan_gpe_tunnel_details_t *rmp;
1675 ip4_main_t *im4 = &ip4_main;
1676 ip6_main_t *im6 = &ip6_main;
1677 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
1679 rmp = vl_msg_api_alloc (sizeof (*rmp));
1680 memset (rmp, 0, sizeof (*rmp));
1681 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
1684 memcpy (rmp->local, &(t->local.ip6), 16);
1685 memcpy (rmp->remote, &(t->remote.ip6), 16);
1686 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1687 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
1691 memcpy (rmp->local, &(t->local.ip4), 4);
1692 memcpy (rmp->remote, &(t->remote.ip4), 4);
1693 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1694 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
1696 rmp->vni = htonl (t->vni);
1697 rmp->protocol = t->protocol;
1698 rmp->sw_if_index = htonl (t->sw_if_index);
1699 rmp->is_ipv6 = is_ipv6;
1700 rmp->context = context;
1702 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1705 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
1706 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
1708 unix_shared_memory_queue_t *q;
1709 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
1710 vxlan_gpe_tunnel_t *t;
1713 q = vl_api_client_index_to_input_queue (mp->client_index);
1719 sw_if_index = ntohl (mp->sw_if_index);
1721 if (~0 == sw_if_index)
1724 pool_foreach (t, vgm->tunnels,
1726 send_vxlan_gpe_tunnel_details(t, q, mp->context);
1732 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
1733 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
1737 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
1738 send_vxlan_gpe_tunnel_details (t, q, mp->context);
1743 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1746 vl_api_interface_name_renumber_reply_t *rmp;
1749 VALIDATE_SW_IF_INDEX (mp);
1751 rv = vnet_interface_name_renumber
1752 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1754 BAD_SW_IF_INDEX_LABEL;
1756 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1760 arp_change_data_callback (u32 pool_index, u8 * new_mac,
1761 u32 sw_if_index, u32 address)
1763 vpe_api_main_t *am = &vpe_api_main;
1764 vlib_main_t *vm = am->vlib_main;
1765 vl_api_ip4_arp_event_t *event;
1766 static f64 arp_event_last_time;
1767 f64 now = vlib_time_now (vm);
1769 if (pool_is_free_index (am->arp_events, pool_index))
1772 event = pool_elt_at_index (am->arp_events, pool_index);
1774 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1776 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1780 if (sw_if_index == event->sw_if_index &&
1782 /* for BD case, also check IP address with 10 sec timeout */
1783 (address == event->address &&
1784 (now - arp_event_last_time) < 10.0)))
1789 arp_event_last_time = now;
1790 event->sw_if_index = sw_if_index;
1792 event->address = address;
1797 nd_change_data_callback (u32 pool_index, u8 * new_mac,
1798 u32 sw_if_index, ip6_address_t * address)
1800 vpe_api_main_t *am = &vpe_api_main;
1801 vlib_main_t *vm = am->vlib_main;
1802 vl_api_ip6_nd_event_t *event;
1803 static f64 nd_event_last_time;
1804 f64 now = vlib_time_now (vm);
1806 if (pool_is_free_index (am->nd_events, pool_index))
1809 event = pool_elt_at_index (am->nd_events, pool_index);
1812 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1814 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1818 if (sw_if_index == event->sw_if_index &&
1820 /* for BD case, also check IP address with 10 sec timeout */
1821 (ip6_address_is_equal (address,
1822 (ip6_address_t *) event->address) &&
1823 (now - nd_event_last_time) < 10.0)))
1828 nd_event_last_time = now;
1829 event->sw_if_index = sw_if_index;
1831 clib_memcpy (event->address, address, sizeof (event->address));
1836 arp_change_delete_callback (u32 pool_index, u8 * notused)
1838 vpe_api_main_t *am = &vpe_api_main;
1840 if (pool_is_free_index (am->arp_events, pool_index))
1843 pool_put_index (am->arp_events, pool_index);
1848 nd_change_delete_callback (u32 pool_index, u8 * notused)
1850 vpe_api_main_t *am = &vpe_api_main;
1852 if (pool_is_free_index (am->nd_events, pool_index))
1855 pool_put_index (am->nd_events, pool_index);
1860 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
1862 vpe_api_main_t *am = &vpe_api_main;
1863 vnet_main_t *vnm = vnet_get_main ();
1864 vl_api_want_ip4_arp_events_reply_t *rmp;
1865 vl_api_ip4_arp_event_t *event;
1868 if (mp->enable_disable)
1870 pool_get (am->arp_events, event);
1871 memset (event, 0, sizeof (*event));
1873 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
1874 event->client_index = mp->client_index;
1875 event->context = mp->context;
1876 event->address = mp->address;
1877 event->pid = mp->pid;
1878 if (mp->address == 0)
1881 rv = vnet_add_del_ip4_arp_change_event
1882 (vnm, arp_change_data_callback,
1883 mp->pid, &mp->address /* addr, in net byte order */ ,
1884 vpe_resolver_process_node.index,
1885 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
1889 rv = vnet_add_del_ip4_arp_change_event
1890 (vnm, arp_change_delete_callback,
1891 mp->pid, &mp->address /* addr, in net byte order */ ,
1892 vpe_resolver_process_node.index,
1893 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1895 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
1899 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
1901 vpe_api_main_t *am = &vpe_api_main;
1902 vnet_main_t *vnm = vnet_get_main ();
1903 vl_api_want_ip6_nd_events_reply_t *rmp;
1904 vl_api_ip6_nd_event_t *event;
1907 if (mp->enable_disable)
1909 pool_get (am->nd_events, event);
1910 memset (event, 0, sizeof (*event));
1912 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
1913 event->client_index = mp->client_index;
1914 event->context = mp->context;
1915 clib_memcpy (event->address, mp->address, 16);
1916 event->pid = mp->pid;
1917 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
1920 rv = vnet_add_del_ip6_nd_change_event
1921 (vnm, nd_change_data_callback,
1922 mp->pid, mp->address /* addr, in net byte order */ ,
1923 vpe_resolver_process_node.index,
1924 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
1928 rv = vnet_add_del_ip6_nd_change_event
1929 (vnm, nd_change_delete_callback,
1930 mp->pid, mp->address /* addr, in net byte order */ ,
1931 vpe_resolver_process_node.index,
1932 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1934 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
1937 static void vl_api_input_acl_set_interface_t_handler
1938 (vl_api_input_acl_set_interface_t * mp)
1940 vlib_main_t *vm = vlib_get_main ();
1941 vl_api_input_acl_set_interface_reply_t *rmp;
1943 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
1945 ip4_table_index = ntohl (mp->ip4_table_index);
1946 ip6_table_index = ntohl (mp->ip6_table_index);
1947 l2_table_index = ntohl (mp->l2_table_index);
1948 sw_if_index = ntohl (mp->sw_if_index);
1950 VALIDATE_SW_IF_INDEX (mp);
1952 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
1953 ip6_table_index, l2_table_index, mp->is_add);
1955 BAD_SW_IF_INDEX_LABEL;
1957 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
1960 static void vl_api_cop_interface_enable_disable_t_handler
1961 (vl_api_cop_interface_enable_disable_t * mp)
1963 vl_api_cop_interface_enable_disable_reply_t *rmp;
1965 u32 sw_if_index = ntohl (mp->sw_if_index);
1968 VALIDATE_SW_IF_INDEX (mp);
1970 enable_disable = (int) mp->enable_disable;
1972 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
1974 BAD_SW_IF_INDEX_LABEL;
1976 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
1979 static void vl_api_cop_whitelist_enable_disable_t_handler
1980 (vl_api_cop_whitelist_enable_disable_t * mp)
1982 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
1983 cop_whitelist_enable_disable_args_t _a, *a = &_a;
1984 u32 sw_if_index = ntohl (mp->sw_if_index);
1987 VALIDATE_SW_IF_INDEX (mp);
1989 a->sw_if_index = sw_if_index;
1992 a->default_cop = mp->default_cop;
1993 a->fib_id = ntohl (mp->fib_id);
1995 rv = cop_whitelist_enable_disable (a);
1997 BAD_SW_IF_INDEX_LABEL;
1999 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
2003 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
2007 api_main_t *am = &api_main;
2008 vlib_main_t *vm = vlib_get_main ();
2010 vl_api_get_node_graph_reply_t *rmp;
2012 pthread_mutex_lock (&am->vlib_rp->mutex);
2013 oldheap = svm_push_data_heap (am->vlib_rp);
2016 * Keep the number of memcpy ops to a minimum (e.g. 1).
2018 vec_validate (vector, 16384);
2019 vec_reset_length (vector);
2022 vector = vlib_node_serialize (&vm->node_main, vector,
2023 (u32) ~ 0 /* all threads */ ,
2024 1 /* include nexts */ ,
2025 1 /* include stats */ );
2027 svm_pop_heap (oldheap);
2028 pthread_mutex_unlock (&am->vlib_rp->mutex);
2031 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
2033 rmp->reply_in_shmem = (uword) vector;
2039 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
2042 vl_api_ioam_enable_reply_t *rmp;
2043 clib_error_t *error;
2045 /* Ignoring the profile id as currently a single profile
2047 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
2048 mp->seqno, mp->analyse);
2051 clib_error_report (error);
2052 rv = clib_error_get_code (error);
2055 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
2059 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
2062 vl_api_ioam_disable_reply_t *rmp;
2063 clib_error_t *error;
2065 error = clear_ioam_rewrite_fn ();
2068 clib_error_report (error);
2069 rv = clib_error_get_code (error);
2072 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
2076 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
2078 vlib_main_t *vm = vlib_get_main ();
2079 vl_api_policer_add_del_reply_t *rmp;
2082 sse2_qos_pol_cfg_params_st cfg;
2083 clib_error_t *error;
2086 name = format (0, "%s", mp->name);
2088 memset (&cfg, 0, sizeof (cfg));
2090 cfg.rnd_type = mp->round_type;
2091 cfg.rate_type = mp->rate_type;
2092 cfg.rb.kbps.cir_kbps = mp->cir;
2093 cfg.rb.kbps.eir_kbps = mp->eir;
2094 cfg.rb.kbps.cb_bytes = mp->cb;
2095 cfg.rb.kbps.eb_bytes = mp->eb;
2096 cfg.conform_action.action_type = mp->conform_action_type;
2097 cfg.conform_action.dscp = mp->conform_dscp;
2098 cfg.exceed_action.action_type = mp->exceed_action_type;
2099 cfg.exceed_action.dscp = mp->exceed_dscp;
2100 cfg.violate_action.action_type = mp->violate_action_type;
2101 cfg.violate_action.dscp = mp->violate_dscp;
2102 cfg.color_aware = mp->color_aware;
2104 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
2107 rv = VNET_API_ERROR_UNSPECIFIED;
2110 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
2112 if (rv == 0 && mp->is_add)
2113 rmp->policer_index = ntohl(policer_index);
2115 rmp->policer_index = ~0;
2121 send_policer_details (u8 * name,
2122 sse2_qos_pol_cfg_params_st * config,
2123 policer_read_response_type_st * templ,
2124 unix_shared_memory_queue_t * q, u32 context)
2126 vl_api_policer_details_t *mp;
2128 mp = vl_msg_api_alloc (sizeof (*mp));
2129 memset (mp, 0, sizeof (*mp));
2130 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
2131 mp->context = context;
2132 mp->cir = htonl (config->rb.kbps.cir_kbps);
2133 mp->eir = htonl (config->rb.kbps.eir_kbps);
2134 mp->cb = htonl (config->rb.kbps.cb_bytes);
2135 mp->eb = htonl (config->rb.kbps.eb_bytes);
2136 mp->rate_type = config->rate_type;
2137 mp->round_type = config->rnd_type;
2138 mp->type = config->rfc;
2139 mp->conform_action_type = config->conform_action.action_type;
2140 mp->conform_dscp = config->conform_action.dscp;
2141 mp->exceed_action_type = config->exceed_action.action_type;
2142 mp->exceed_dscp = config->exceed_action.dscp;
2143 mp->violate_action_type = config->violate_action.action_type;
2144 mp->violate_dscp = config->violate_action.dscp;
2145 mp->single_rate = templ->single_rate ? 1 : 0;
2146 mp->color_aware = templ->color_aware ? 1 : 0;
2147 mp->scale = htonl (templ->scale);
2148 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
2149 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
2150 mp->current_limit = htonl (templ->current_limit);
2151 mp->current_bucket = htonl (templ->current_bucket);
2152 mp->extended_limit = htonl (templ->extended_limit);
2153 mp->extended_bucket = htonl (templ->extended_bucket);
2154 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
2156 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
2158 vl_msg_api_send_shmem (q, (u8 *) & mp);
2162 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
2164 unix_shared_memory_queue_t *q;
2165 vnet_policer_main_t *pm = &vnet_policer_main;
2171 sse2_qos_pol_cfg_params_st *config;
2172 policer_read_response_type_st *templ;
2174 q = vl_api_client_index_to_input_queue (mp->client_index);
2178 if (mp->match_name_valid)
2180 match_name = format (0, "%s%c", mp->match_name, 0);
2183 if (mp->match_name_valid)
2185 p = hash_get_mem (pm->policer_config_by_name, match_name);
2189 config = pool_elt_at_index (pm->configs, pool_index);
2190 templ = pool_elt_at_index (pm->policer_templates, pool_index);
2191 send_policer_details (match_name, config, templ, q, mp->context);
2197 hash_foreach_pair (hp, pm->policer_config_by_name,
2199 name = (u8 *) hp->key;
2200 pool_index = hp->value[0];
2201 config = pool_elt_at_index (pm->configs, pool_index);
2202 templ = pool_elt_at_index (pm->policer_templates, pool_index);
2203 send_policer_details(name, config, templ, q, mp->context);
2211 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
2213 vl_api_pg_create_interface_reply_t *rmp;
2216 pg_main_t *pg = &pg_main;
2217 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
2218 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
2221 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
2223 rmp->sw_if_index = ntohl(pi->sw_if_index);
2229 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
2231 vl_api_pg_capture_reply_t *rmp;
2234 vnet_main_t *vnm = vnet_get_main ();
2235 vnet_interface_main_t *im = &vnm->interface_main;
2236 vnet_hw_interface_t *hi = 0;
2238 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
2239 u32 hw_if_index = ~0;
2240 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
2243 vec_free (intf_name);
2245 if (hw_if_index != ~0)
2247 pg_capture_args_t _a, *a = &_a;
2249 u32 len = ntohl (mp->pcap_name_length);
2250 u8 *pcap_file_name = vec_new (u8, len);
2251 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
2253 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
2254 a->hw_if_index = hw_if_index;
2255 a->dev_instance = hi->dev_instance;
2256 a->is_enabled = mp->is_enabled;
2257 a->pcap_file_name = pcap_file_name;
2258 a->count = ntohl (mp->count);
2260 clib_error_t *e = pg_capture (a);
2263 clib_error_report (e);
2264 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
2267 vec_free (pcap_file_name);
2269 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
2273 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
2275 vl_api_pg_enable_disable_reply_t *rmp;
2278 pg_main_t *pg = &pg_main;
2279 u32 stream_index = ~0;
2281 int is_enable = mp->is_enabled != 0;
2282 u32 len = ntohl (mp->stream_name_length) - 1;
2286 u8 *stream_name = vec_new (u8, len);
2287 clib_memcpy (stream_name, mp->stream_name, len);
2288 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
2291 vec_free (stream_name);
2294 pg_enable_disable (stream_index, is_enable);
2296 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
2300 vl_api_ip_source_and_port_range_check_add_del_t_handler
2301 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
2303 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
2306 u8 is_ipv6 = mp->is_ipv6;
2307 u8 is_add = mp->is_add;
2308 u8 mask_length = mp->mask_length;
2309 ip4_address_t ip4_addr;
2310 ip6_address_t ip6_addr;
2312 u16 *high_ports = 0;
2314 u16 tmp_low, tmp_high;
2318 // Validate port range
2319 num_ranges = mp->number_of_ranges;
2320 if (num_ranges > 32)
2321 { // This is size of array in VPE.API
2322 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
2326 vec_reset_length (low_ports);
2327 vec_reset_length (high_ports);
2329 for (i = 0; i < num_ranges; i++)
2331 tmp_low = mp->low_ports[i];
2332 tmp_high = mp->high_ports[i];
2333 // If tmp_low <= tmp_high then only need to check tmp_low = 0
2334 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
2335 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
2337 rv = VNET_API_ERROR_INVALID_VALUE;
2340 vec_add1 (low_ports, tmp_low);
2341 vec_add1 (high_ports, tmp_high + 1);
2344 // Validate mask_length
2345 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
2347 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
2351 vrf_id = ntohl (mp->vrf_id);
2355 rv = VNET_API_ERROR_INVALID_VALUE;
2362 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
2363 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
2367 high_ports, is_add);
2371 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
2372 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
2376 high_ports, is_add);
2380 vec_free (low_ports);
2381 vec_free (high_ports);
2382 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
2386 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
2387 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
2389 vlib_main_t *vm = vlib_get_main ();
2390 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
2391 ip4_main_t *im = &ip4_main;
2394 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2395 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2399 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
2400 ntohl (mp->tcp_out_vrf_id);
2401 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
2402 ntohl (mp->udp_out_vrf_id);
2403 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
2404 ntohl (mp->tcp_in_vrf_id);
2405 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
2406 ntohl (mp->udp_in_vrf_id);
2409 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
2411 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
2413 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
2417 rv = VNET_API_ERROR_INVALID_VALUE;
2421 fib_index[i] = p[0];
2426 sw_if_index = ntohl (mp->sw_if_index);
2428 VALIDATE_SW_IF_INDEX (mp);
2431 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
2434 BAD_SW_IF_INDEX_LABEL;
2437 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
2441 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
2443 vl_api_delete_subif_reply_t *rmp;
2446 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
2448 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
2452 vl_api_punt_t_handler (vl_api_punt_t * mp)
2454 vl_api_punt_reply_t *rmp;
2455 vlib_main_t *vm = vlib_get_main ();
2457 clib_error_t *error;
2459 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
2460 ntohs (mp->l4_port), mp->is_add);
2464 clib_error_report (error);
2467 REPLY_MACRO (VL_API_PUNT_REPLY);
2471 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
2473 vl_api_feature_enable_disable_reply_t *rmp;
2475 u8 *arc_name, *feature_name;
2477 VALIDATE_SW_IF_INDEX (mp);
2479 arc_name = format (0, "%s%c", mp->arc_name, 0);
2480 feature_name = format (0, "%s%c", mp->feature_name, 0);
2482 vnet_feature_registration_t *reg;
2484 vnet_get_feature_reg ((const char *) arc_name,
2485 (const char *) feature_name);
2487 rv = VNET_API_ERROR_INVALID_VALUE;
2491 clib_error_t *error = 0;
2493 sw_if_index = ntohl (mp->sw_if_index);
2494 if (reg->enable_disable_cb)
2495 error = reg->enable_disable_cb (sw_if_index, mp->enable);
2497 vnet_feature_enable_disable ((const char *) arc_name,
2498 (const char *) feature_name,
2499 sw_if_index, mp->enable, 0, 0);
2502 clib_error_report (error);
2503 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
2507 vec_free (feature_name);
2508 vec_free (arc_name);
2510 BAD_SW_IF_INDEX_LABEL;
2512 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
2515 #define BOUNCE_HANDLER(nn) \
2516 static void vl_api_##nn##_t_handler ( \
2517 vl_api_##nn##_t *mp) \
2519 vpe_client_registration_t *reg; \
2520 vpe_api_main_t * vam = &vpe_api_main; \
2521 unix_shared_memory_queue_t * q; \
2523 /* One registration only... */ \
2524 pool_foreach(reg, vam->nn##_registrations, \
2526 q = vl_api_client_index_to_input_queue (reg->client_index); \
2529 * If the queue is stuffed, turf the msg and complain \
2530 * It's unlikely that the intended recipient is \
2531 * alive; avoid deadlock at all costs. \
2533 if (q->cursize == q->maxsize) { \
2534 clib_warning ("ERROR: receiver queue full, drop msg"); \
2535 vl_msg_api_free (mp); \
2538 vl_msg_api_send_shmem (q, (u8 *)&mp); \
2542 vl_msg_api_free (mp); \
2545 static void setup_message_id_table (api_main_t * am);
2549 * Add vpe's API message handlers to the table.
2550 * vlib has alread mapped shared memory and
2551 * added the client registration handlers.
2552 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
2554 static clib_error_t *
2555 vpe_api_hookup (vlib_main_t * vm)
2557 api_main_t *am = &api_main;
2560 vl_msg_api_set_handlers(VL_API_##N, #n, \
2561 vl_api_##n##_t_handler, \
2563 vl_api_##n##_t_endian, \
2564 vl_api_##n##_t_print, \
2565 sizeof(vl_api_##n##_t), 1);
2566 foreach_vpe_api_msg;
2570 * Trace space for classifier mask+match
2572 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
2573 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
2574 += 5 * sizeof (u32x4);
2575 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
2578 * Thread-safe API messages
2580 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
2581 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
2584 * Set up the (msg_name, crc, message-id) table
2586 setup_message_id_table (am);
2591 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
2593 static clib_error_t *
2594 vpe_api_init (vlib_main_t * vm)
2596 vpe_api_main_t *am = &vpe_api_main;
2599 am->vnet_main = vnet_get_main ();
2600 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
2601 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2602 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2603 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2604 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2605 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
2606 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
2609 vl_set_memory_region_name ("/vpe-api");
2610 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
2615 VLIB_INIT_FUNCTION (vpe_api_init);
2618 static clib_error_t *
2619 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
2622 u64 baseva, size, pvt_heap_size;
2624 const int max_buf_size = 4096;
2626 struct passwd _pw, *pw;
2627 struct group _grp, *grp;
2629 buf = vec_new (char, 128);
2630 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2632 if (unformat (input, "prefix %s", &chroot_path))
2634 vec_add1 (chroot_path, 0);
2635 vl_set_memory_root_path ((char *) chroot_path);
2637 else if (unformat (input, "uid %d", &uid))
2638 vl_set_memory_uid (uid);
2639 else if (unformat (input, "gid %d", &gid))
2640 vl_set_memory_gid (gid);
2641 else if (unformat (input, "baseva %llx", &baseva))
2642 vl_set_global_memory_baseva (baseva);
2643 else if (unformat (input, "global-size %lldM", &size))
2644 vl_set_global_memory_size (size * (1ULL << 20));
2645 else if (unformat (input, "global-size %lldG", &size))
2646 vl_set_global_memory_size (size * (1ULL << 30));
2647 else if (unformat (input, "global-size %lld", &size))
2648 vl_set_global_memory_size (size);
2649 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
2650 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2651 else if (unformat (input, "global-pvt-heap-size size %lld",
2653 vl_set_global_pvt_heap_size (pvt_heap_size);
2654 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
2655 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2656 else if (unformat (input, "api-pvt-heap-size size %lld",
2658 vl_set_api_pvt_heap_size (pvt_heap_size);
2659 else if (unformat (input, "api-size %lldM", &size))
2660 vl_set_api_memory_size (size * (1ULL << 20));
2661 else if (unformat (input, "api-size %lldG", &size))
2662 vl_set_api_memory_size (size * (1ULL << 30));
2663 else if (unformat (input, "api-size %lld", &size))
2664 vl_set_api_memory_size (size);
2665 else if (unformat (input, "uid %s", &s))
2667 /* lookup the username */
2670 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
2671 && (vec_len (buf) <= max_buf_size))
2673 vec_resize (buf, vec_len (buf) * 2);
2677 e = clib_error_return_code (0, rv,
2678 CLIB_ERROR_ERRNO_VALID |
2680 "cannot fetch username %s", s);
2688 clib_error_return_fatal (0, "username %s does not exist", s);
2694 vl_set_memory_uid (pw->pw_uid);
2696 else if (unformat (input, "gid %s", &s))
2698 /* lookup the group name */
2701 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
2702 && (vec_len (buf) <= max_buf_size))
2704 vec_resize (buf, vec_len (buf) * 2);
2708 e = clib_error_return_code (0, rv,
2709 CLIB_ERROR_ERRNO_VALID |
2711 "cannot fetch group %s", s);
2718 e = clib_error_return_fatal (0, "group %s does not exist", s);
2725 vl_set_memory_gid (grp->gr_gid);
2728 return clib_error_return (0, "unknown input `%U'",
2729 format_unformat_error, input);
2734 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
2737 get_unformat_vnet_sw_interface (void)
2739 return (void *) &unformat_vnet_sw_interface;
2743 format_arp_event (u8 * s, va_list * args)
2745 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
2747 s = format (s, "pid %d: ", event->pid);
2749 s = format (s, "bd mac/ip4 binding events");
2751 s = format (s, "resolution for %U", format_ip4_address, &event->address);
2756 format_nd_event (u8 * s, va_list * args)
2758 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
2760 s = format (s, "pid %d: ", event->pid);
2762 s = format (s, "bd mac/ip6 binding events");
2764 s = format (s, "resolution for %U", format_ip6_address, event->address);
2768 static clib_error_t *
2769 show_ip_arp_nd_events_fn (vlib_main_t * vm,
2770 unformat_input_t * input, vlib_cli_command_t * cmd)
2772 vpe_api_main_t *am = &vpe_api_main;
2773 vl_api_ip4_arp_event_t *arp_event;
2774 vl_api_ip6_nd_event_t *nd_event;
2776 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
2778 vlib_cli_output (vm, "No active arp or nd event registrations");
2783 pool_foreach (arp_event, am->arp_events,
2785 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
2788 pool_foreach (nd_event, am->nd_events,
2790 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
2798 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
2799 .path = "show arp-nd-event registrations",
2800 .function = show_ip_arp_nd_events_fn,
2801 .short_help = "Show ip4 arp and ip6 nd event registrations",
2805 #define vl_msg_name_crc_list
2806 #include <vpp/api/vpe_all_api_h.h>
2807 #undef vl_msg_name_crc_list
2810 setup_message_id_table (api_main_t * am)
2812 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2813 foreach_vl_msg_name_crc_memclnt;
2814 foreach_vl_msg_name_crc_vpe;
2820 * fd.io coding-style-patch-verification: ON
2823 * eval: (c-set-style "gnu")