2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010-2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
48 #include <vnet/api_errno.h>
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/ip/ip.h>
53 #include <vnet/ip/ip6.h>
54 #include <vnet/ip/ip6_neighbor.h>
56 #include <vnet/sr/sr.h>
58 #include <vlib/vlib.h>
59 #include <vlib/unix/unix.h>
60 #include <vlibapi/api.h>
61 #include <vlibmemory/api.h>
62 #include <vnet/classify/input_acl.h>
63 #include <vnet/l2/l2_classify.h>
64 #include <vnet/vxlan/vxlan.h>
65 #include <vnet/vxlan-gpe/vxlan_gpe.h>
66 #include <vnet/map/map.h>
67 #include <vnet/ip/ip6_hop_by_hop.h>
68 #include <vnet/ip/ip_source_and_port_range_check.h>
69 #include <vnet/policer/policer.h>
70 #include <vnet/ip/punt.h>
71 #include <vnet/feature/feature.h>
74 #undef __included_bihash_template_h__
75 #include <vnet/l2/l2_fib.h>
77 #include <vpp/stats/stats.h>
78 #include <vpp/oam/oam.h>
80 #include <vnet/ethernet/ethernet.h>
81 #include <vnet/ethernet/arp_packet.h>
82 #include <vnet/interface.h>
83 #include <vnet/l2/l2_fib.h>
84 #include <vnet/l2/l2_bd.h>
85 #include <vpp/api/vpe_msg_enum.h>
86 #include <vnet/span/span.h>
87 #include <vnet/fib/ip6_fib.h>
88 #include <vnet/fib/ip4_fib.h>
89 #include <vnet/fib/fib_api.h>
90 #include <vnet/dpo/drop_dpo.h>
91 #include <vnet/dpo/receive_dpo.h>
92 #include <vnet/dpo/lookup_dpo.h>
93 #include <vnet/dpo/classify_dpo.h>
94 #include <vnet/dpo/ip_null_dpo.h>
95 #define vl_typedefs /* define message structures */
96 #include <vpp/api/vpe_all_api_h.h>
98 #define vl_endianfun /* define message structures */
99 #include <vpp/api/vpe_all_api_h.h>
101 /* instantiate all the print functions we know about */
102 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
104 #include <vpp/api/vpe_all_api_h.h>
106 #include <vlibapi/api_helper_macros.h>
107 #define foreach_vpe_api_msg \
108 _(WANT_OAM_EVENTS, want_oam_events) \
109 _(OAM_ADD_DEL, oam_add_del) \
110 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
111 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
112 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
113 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
114 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
115 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
116 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
117 _(CREATE_SUBIF, create_subif) \
118 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
119 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
120 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
121 _(RESET_FIB, reset_fib) \
122 _(CREATE_LOOPBACK, create_loopback) \
123 _(CONTROL_PING, control_ping) \
124 _(CLI_REQUEST, cli_request) \
125 _(CLI_INBAND, cli_inband) \
126 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
127 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
128 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
129 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
130 _(GET_NODE_INDEX, get_node_index) \
131 _(ADD_NODE_NEXT, add_node_next) \
132 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
133 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
134 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
135 _(SHOW_VERSION, show_version) \
136 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
137 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
138 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
139 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
140 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
141 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
142 _(DELETE_LOOPBACK, delete_loopback) \
143 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
144 _(GET_NODE_GRAPH, get_node_graph) \
145 _(IOAM_ENABLE, ioam_enable) \
146 _(IOAM_DISABLE, ioam_disable) \
147 _(POLICER_ADD_DEL, policer_add_del) \
148 _(POLICER_DUMP, policer_dump) \
149 _(GET_NEXT_INDEX, get_next_index) \
150 _(PG_CREATE_INTERFACE, pg_create_interface) \
151 _(PG_CAPTURE, pg_capture) \
152 _(PG_ENABLE_DISABLE, pg_enable_disable) \
153 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
154 ip_source_and_port_range_check_add_del) \
155 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
156 ip_source_and_port_range_check_interface_add_del) \
157 _(DELETE_SUBIF, delete_subif) \
159 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
162 #define QUOTE(x) QUOTE_(x)
165 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
166 RESOLVE_IP6_ADD_DEL_ROUTE,
169 static vlib_node_registration_t vpe_resolver_process_node;
170 vpe_api_main_t vpe_api_main;
172 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
173 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
175 /* Clean up all registrations belonging to the indicated client */
177 vl_api_memclnt_delete_callback (u32 client_index)
179 vpe_api_main_t *vam = &vpe_api_main;
180 vpe_client_registration_t *rp;
182 int stats_memclnt_delete_callback (u32 client_index);
184 stats_memclnt_delete_callback (client_index);
187 p = hash_get (vam->a##_registration_hash, client_index); \
189 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
190 pool_put (vam->a##_registrations, rp); \
191 hash_unset (vam->a##_registration_hash, client_index); \
193 foreach_registration_hash;
198 pub_sub_handler (oam_events, OAM_EVENTS);
200 #define RESOLUTION_EVENT 1
201 #define RESOLUTION_PENDING_EVENT 2
202 #define IP4_ARP_EVENT 3
203 #define IP6_ND_EVENT 4
205 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
207 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
210 handle_ip4_arp_event (u32 pool_index)
212 vpe_api_main_t *vam = &vpe_api_main;
213 vnet_main_t *vnm = vam->vnet_main;
214 vlib_main_t *vm = vam->vlib_main;
215 vl_api_ip4_arp_event_t *event;
216 vl_api_ip4_arp_event_t *mp;
217 unix_shared_memory_queue_t *q;
219 /* Client can cancel, die, etc. */
220 if (pool_is_free_index (vam->arp_events, pool_index))
223 event = pool_elt_at_index (vam->arp_events, pool_index);
225 q = vl_api_client_index_to_input_queue (event->client_index);
228 (void) vnet_add_del_ip4_arp_change_event
229 (vnm, arp_change_delete_callback,
230 event->pid, &event->address,
231 vpe_resolver_process_node.index, IP4_ARP_EVENT,
232 ~0 /* pool index, notused */ , 0 /* is_add */ );
236 if (q->cursize < q->maxsize)
238 mp = vl_msg_api_alloc (sizeof (*mp));
239 clib_memcpy (mp, event, sizeof (*mp));
240 vl_msg_api_send_shmem (q, (u8 *) & mp);
244 static f64 last_time;
246 * Throttle syslog msgs.
247 * It's pretty tempting to just revoke the registration...
249 if (vlib_time_now (vm) > last_time + 10.0)
251 clib_warning ("arp event for %U to pid %d: queue stuffed!",
252 format_ip4_address, &event->address, event->pid);
253 last_time = vlib_time_now (vm);
259 handle_ip6_nd_event (u32 pool_index)
261 vpe_api_main_t *vam = &vpe_api_main;
262 vnet_main_t *vnm = vam->vnet_main;
263 vlib_main_t *vm = vam->vlib_main;
264 vl_api_ip6_nd_event_t *event;
265 vl_api_ip6_nd_event_t *mp;
266 unix_shared_memory_queue_t *q;
268 /* Client can cancel, die, etc. */
269 if (pool_is_free_index (vam->nd_events, pool_index))
272 event = pool_elt_at_index (vam->nd_events, pool_index);
274 q = vl_api_client_index_to_input_queue (event->client_index);
277 (void) vnet_add_del_ip6_nd_change_event
278 (vnm, nd_change_delete_callback,
279 event->pid, &event->address,
280 vpe_resolver_process_node.index, IP6_ND_EVENT,
281 ~0 /* pool index, notused */ , 0 /* is_add */ );
285 if (q->cursize < q->maxsize)
287 mp = vl_msg_api_alloc (sizeof (*mp));
288 clib_memcpy (mp, event, sizeof (*mp));
289 vl_msg_api_send_shmem (q, (u8 *) & mp);
293 static f64 last_time;
295 * Throttle syslog msgs.
296 * It's pretty tempting to just revoke the registration...
298 if (vlib_time_now (vm) > last_time + 10.0)
300 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
301 format_ip6_address, &event->address, event->pid);
302 last_time = vlib_time_now (vm);
308 resolver_process (vlib_main_t * vm,
309 vlib_node_runtime_t * rt, vlib_frame_t * f)
312 uword *event_data = 0;
318 vlib_process_wait_for_event_or_clock (vm, timeout);
320 event_type = vlib_process_get_events (vm, &event_data);
324 case RESOLUTION_PENDING_EVENT:
328 case RESOLUTION_EVENT:
329 clib_warning ("resolver: BOGUS TYPE");
333 for (i = 0; i < vec_len (event_data); i++)
334 handle_ip4_arp_event (event_data[i]);
338 for (i = 0; i < vec_len (event_data); i++)
339 handle_ip6_nd_event (event_data[i]);
342 case ~0: /* timeout */
346 vec_reset_length (event_data);
348 return 0; /* or not */
352 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
353 .function = resolver_process,
354 .type = VLIB_NODE_TYPE_PROCESS,
355 .name = "vpe-route-resolver-process",
360 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
362 vl_api_sw_interface_set_vpath_reply_t *rmp;
364 u32 sw_if_index = ntohl (mp->sw_if_index);
366 VALIDATE_SW_IF_INDEX (mp);
368 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
369 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
370 sw_if_index, mp->enable, 0, 0);
371 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
372 sw_if_index, mp->enable, 0, 0);
373 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
374 sw_if_index, mp->enable, 0, 0);
375 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
376 sw_if_index, mp->enable, 0, 0);
378 BAD_SW_IF_INDEX_LABEL;
380 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
384 vl_api_sw_interface_set_vxlan_bypass_t_handler
385 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
387 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
389 u32 sw_if_index = ntohl (mp->sw_if_index);
391 VALIDATE_SW_IF_INDEX (mp);
395 /* not yet implemented */
398 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
399 sw_if_index, mp->enable, 0, 0);
401 BAD_SW_IF_INDEX_LABEL;
403 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
407 vl_api_sw_interface_set_l2_xconnect_t_handler
408 (vl_api_sw_interface_set_l2_xconnect_t * mp)
410 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
412 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
413 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
414 vlib_main_t *vm = vlib_get_main ();
415 vnet_main_t *vnm = vnet_get_main ();
417 VALIDATE_RX_SW_IF_INDEX (mp);
421 VALIDATE_TX_SW_IF_INDEX (mp);
422 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
423 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
427 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
430 BAD_RX_SW_IF_INDEX_LABEL;
431 BAD_TX_SW_IF_INDEX_LABEL;
433 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
437 vl_api_sw_interface_set_l2_bridge_t_handler
438 (vl_api_sw_interface_set_l2_bridge_t * mp)
440 bd_main_t *bdm = &bd_main;
441 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
443 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
444 u32 bd_id = ntohl (mp->bd_id);
448 vlib_main_t *vm = vlib_get_main ();
449 vnet_main_t *vnm = vnet_get_main ();
451 VALIDATE_RX_SW_IF_INDEX (mp);
453 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
457 //VALIDATE_TX_SW_IF_INDEX(mp);
458 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
459 rx_sw_if_index, bd_index, bvi, shg, 0);
463 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
466 BAD_RX_SW_IF_INDEX_LABEL;
468 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
472 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
474 bd_main_t *bdm = &bd_main;
475 vl_api_bd_ip_mac_add_del_reply_t *rmp;
477 u32 bd_id = ntohl (mp->bd_id);
481 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
484 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
489 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
490 mp->mac_address, mp->is_ipv6, mp->is_add))
491 rv = VNET_API_ERROR_UNSPECIFIED;
494 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
498 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
500 vl_api_create_vlan_subif_reply_t *rmp;
501 vnet_main_t *vnm = vnet_get_main ();
502 u32 hw_if_index, sw_if_index = (u32) ~ 0;
503 vnet_hw_interface_t *hi;
506 vnet_sw_interface_t template;
508 vnet_interface_main_t *im = &vnm->interface_main;
511 unix_shared_memory_queue_t *q;
514 VALIDATE_SW_IF_INDEX (mp);
516 hw_if_index = ntohl (mp->sw_if_index);
517 hi = vnet_get_hw_interface (vnm, hw_if_index);
519 id = ntohl (mp->vlan_id);
520 if (id == 0 || id > 4095)
522 rv = VNET_API_ERROR_INVALID_VLAN;
526 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
528 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
531 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
535 kp = clib_mem_alloc (sizeof (*kp));
536 *kp = sup_and_sub_key;
538 memset (&template, 0, sizeof (template));
539 template.type = VNET_SW_INTERFACE_TYPE_SUB;
540 template.sup_sw_if_index = hi->sw_if_index;
541 template.sub.id = id;
542 template.sub.eth.raw_flags = 0;
543 template.sub.eth.flags.one_tag = 1;
544 template.sub.eth.outer_vlan_id = id;
545 template.sub.eth.flags.exact_match = 1;
547 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
550 clib_error_report (error);
551 rv = VNET_API_ERROR_INVALID_REGISTRATION;
554 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
555 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
557 BAD_SW_IF_INDEX_LABEL;
560 q = vl_api_client_index_to_input_queue (mp->client_index);
564 rmp = vl_msg_api_alloc (sizeof (*rmp));
565 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
566 rmp->context = mp->context;
567 rmp->retval = ntohl (rv);
568 rmp->sw_if_index = ntohl (sw_if_index);
569 vl_msg_api_send_shmem (q, (u8 *) & rmp);
573 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
575 vl_api_create_subif_reply_t *rmp;
576 vnet_main_t *vnm = vnet_get_main ();
577 u32 sw_if_index = ~0;
580 vnet_sw_interface_t *si;
581 vnet_hw_interface_t *hi;
582 vnet_sw_interface_t template;
584 vnet_interface_main_t *im = &vnm->interface_main;
589 VALIDATE_SW_IF_INDEX (mp);
591 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
592 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
594 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
596 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
600 sw_if_index = si->sw_if_index;
601 sub_id = ntohl (mp->sub_id);
603 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
605 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
609 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
610 sw_if_index, sub_id);
611 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
615 kp = clib_mem_alloc (sizeof (*kp));
616 *kp = sup_and_sub_key;
618 memset (&template, 0, sizeof (template));
619 template.type = VNET_SW_INTERFACE_TYPE_SUB;
620 template.sup_sw_if_index = sw_if_index;
621 template.sub.id = sub_id;
622 template.sub.eth.flags.no_tags = mp->no_tags;
623 template.sub.eth.flags.one_tag = mp->one_tag;
624 template.sub.eth.flags.two_tags = mp->two_tags;
625 template.sub.eth.flags.dot1ad = mp->dot1ad;
626 template.sub.eth.flags.exact_match = mp->exact_match;
627 template.sub.eth.flags.default_sub = mp->default_sub;
628 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
629 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
630 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
631 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
633 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
636 clib_error_report (error);
637 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
641 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
642 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
644 BAD_SW_IF_INDEX_LABEL;
649 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
651 rmp->sw_if_index = ntohl(sw_if_index);
657 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
659 vl_api_proxy_arp_add_del_reply_t *rmp;
662 ip4_main_t *im = &ip4_main;
663 stats_main_t *sm = &stats_main;
664 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
665 ip4_address_t * hi_addr,
666 u32 fib_index, int is_del);
669 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
671 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
675 rv = VNET_API_ERROR_NO_SUCH_FIB;
681 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
682 (ip4_address_t *) mp->hi_address,
683 fib_index, mp->is_add == 0);
687 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
691 vl_api_proxy_arp_intfc_enable_disable_t_handler
692 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
695 vnet_main_t *vnm = vnet_get_main ();
696 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
697 vnet_sw_interface_t *si;
700 VALIDATE_SW_IF_INDEX (mp);
702 sw_if_index = ntohl (mp->sw_if_index);
704 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
706 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
710 si = vnet_get_sw_interface (vnm, sw_if_index);
714 if (mp->enable_disable)
715 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
717 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
719 BAD_SW_IF_INDEX_LABEL;
722 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
726 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
729 vpe_main_t *rm = &vpe_main;
730 ip4_main_t *im4 = &ip4_main;
731 ip6_main_t *im6 = &ip6_main;
732 ip_lookup_main_t *lm;
738 u32 adj_index, sw_if_index;
739 vl_api_is_address_reachable_t *rmp;
741 unix_shared_memory_queue_t *q;
743 q = vl_api_client_index_to_input_queue (mp->client_index);
746 increment_missing_api_client_counter (rm->vlib_main);
750 rmp = vl_msg_api_alloc (sizeof (*rmp));
751 clib_memcpy (rmp, mp, sizeof (*rmp));
753 sw_if_index = mp->next_hop_sw_if_index;
754 clib_memcpy (&addr, mp->address, sizeof (addr));
757 lm = &im6->lookup_main;
758 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
762 lm = &im4->lookup_main;
764 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
771 adj = ip_get_adjacency (lm, adj_index);
773 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
774 && adj->rewrite_header.sw_if_index == sw_if_index)
780 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
781 && adj->rewrite_header.sw_if_index == sw_if_index)
784 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
786 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
788 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
797 vl_msg_api_send_shmem (q, (u8 *) & rmp);
802 vl_api_sw_interface_set_mpls_enable_t_handler
803 (vl_api_sw_interface_set_mpls_enable_t * mp)
805 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
808 VALIDATE_SW_IF_INDEX (mp);
810 mpls_sw_interface_enable_disable (&mpls_main,
811 ntohl (mp->sw_if_index), mp->enable);
813 BAD_SW_IF_INDEX_LABEL;
814 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
818 send_oam_event (oam_target_t * t)
820 vpe_api_main_t *vam = &vpe_api_main;
821 unix_shared_memory_queue_t *q;
822 vpe_client_registration_t *reg;
823 vl_api_oam_event_t *mp;
826 pool_foreach(reg, vam->oam_events_registrations,
828 q = vl_api_client_index_to_input_queue (reg->client_index);
831 mp = vl_msg_api_alloc (sizeof (*mp));
832 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
833 clib_memcpy (mp->dst_address, &t->dst_address,
834 sizeof (mp->dst_address));
835 mp->state = t->state;
836 vl_msg_api_send_shmem (q, (u8 *)&mp);
843 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
845 vl_api_oam_add_del_reply_t *rmp;
848 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
849 (ip4_address_t *) mp->dst_address,
850 ntohl (mp->vrf_id), (int) (mp->is_add));
852 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
856 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
858 stats_main_t *sm = &stats_main;
859 vnet_interface_main_t *im = sm->interface_main;
860 vl_api_vnet_summary_stats_reply_t *rmp;
861 vlib_combined_counter_main_t *cm;
864 u64 total_pkts[VLIB_N_RX_TX];
865 u64 total_bytes[VLIB_N_RX_TX];
867 unix_shared_memory_queue_t *q =
868 vl_api_client_index_to_input_queue (mp->client_index);
873 rmp = vl_msg_api_alloc (sizeof (*rmp));
874 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
875 rmp->context = mp->context;
878 memset (total_pkts, 0, sizeof (total_pkts));
879 memset (total_bytes, 0, sizeof (total_bytes));
881 vnet_interface_counter_lock (im);
883 vec_foreach (cm, im->combined_sw_if_counters)
885 which = cm - im->combined_sw_if_counters;
887 for (i = 0; i < vec_len (cm->maxi); i++)
889 vlib_get_combined_counter (cm, i, &v);
890 total_pkts[which] += v.packets;
891 total_bytes[which] += v.bytes;
894 vnet_interface_counter_unlock (im);
896 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
897 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
898 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
899 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
901 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
903 vl_msg_api_send_shmem (q, (u8 *) & rmp);
907 typedef CLIB_PACKED (struct {
908 ip4_address_t address;
909 u32 address_length: 6;
915 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
917 vnet_main_t *vnm = vnet_get_main ();
918 vnet_interface_main_t *im = &vnm->interface_main;
919 ip4_main_t *im4 = &ip4_main;
920 static u32 *sw_if_indices_to_shut;
921 stats_main_t *sm = &stats_main;
922 fib_table_t *fib_table;
926 int rv = VNET_API_ERROR_NO_SUCH_FIB;
927 u32 target_fib_id = ntohl (mp->vrf_id);
929 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
932 pool_foreach (fib_table, im4->fibs,
934 fib = &fib_table->v4;
935 vnet_sw_interface_t * si;
937 if (fib->table_id != target_fib_id)
940 /* remove any mpls encap/decap labels */
941 mpls_fib_reset_labels (fib->table_id);
943 /* remove any proxy arps in this fib */
944 vnet_proxy_arp_fib_reset (fib->table_id);
946 /* Set the flow hash for this fib to the default */
947 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
949 vec_reset_length (sw_if_indices_to_shut);
951 /* Shut down interfaces in this FIB / clean out intfc routes */
952 pool_foreach (si, im->sw_interfaces,
954 u32 sw_if_index = si->sw_if_index;
956 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
957 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
959 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
962 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
963 sw_if_index = sw_if_indices_to_shut[i];
965 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
966 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
967 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
970 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
974 })); /* pool_foreach (fib) */
982 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
984 vnet_main_t *vnm = vnet_get_main ();
985 vnet_interface_main_t *im = &vnm->interface_main;
986 ip6_main_t *im6 = &ip6_main;
987 stats_main_t *sm = &stats_main;
988 static u32 *sw_if_indices_to_shut;
989 fib_table_t *fib_table;
993 int rv = VNET_API_ERROR_NO_SUCH_FIB;
994 u32 target_fib_id = ntohl (mp->vrf_id);
996 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
999 pool_foreach (fib_table, im6->fibs,
1001 vnet_sw_interface_t * si;
1002 fib = &(fib_table->v6);
1004 if (fib->table_id != target_fib_id)
1007 vec_reset_length (sw_if_indices_to_shut);
1009 /* Shut down interfaces in this FIB / clean out intfc routes */
1010 pool_foreach (si, im->sw_interfaces,
1012 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1014 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1017 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1018 sw_if_index = sw_if_indices_to_shut[i];
1020 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1021 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1022 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1025 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1029 })); /* pool_foreach (fib) */
1037 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1040 vl_api_reset_fib_reply_t *rmp;
1043 rv = ip6_reset_fib_t_handler (mp);
1045 rv = ip4_reset_fib_t_handler (mp);
1047 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1051 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1053 vl_api_create_loopback_reply_t *rmp;
1057 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1060 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1062 rmp->sw_if_index = ntohl (sw_if_index);
1068 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1070 vl_api_delete_loopback_reply_t *rmp;
1074 sw_if_index = ntohl (mp->sw_if_index);
1075 rv = vnet_delete_loopback_interface (sw_if_index);
1077 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1081 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1083 vl_api_control_ping_reply_t *rmp;
1087 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1089 rmp->vpe_pid = ntohl (getpid());
1095 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1097 u8 **shmem_vecp = (u8 **) arg;
1100 api_main_t *am = &api_main;
1103 shmem_vec = *shmem_vecp;
1105 offset = vec_len (shmem_vec);
1107 pthread_mutex_lock (&am->vlib_rp->mutex);
1108 oldheap = svm_push_data_heap (am->vlib_rp);
1110 vec_validate (shmem_vec, offset + buffer_bytes - 1);
1112 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
1114 svm_pop_heap (oldheap);
1115 pthread_mutex_unlock (&am->vlib_rp->mutex);
1117 *shmem_vecp = shmem_vec;
1122 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
1124 vl_api_cli_reply_t *rp;
1125 unix_shared_memory_queue_t *q;
1126 vlib_main_t *vm = vlib_get_main ();
1127 api_main_t *am = &api_main;
1128 unformat_input_t input;
1132 q = vl_api_client_index_to_input_queue (mp->client_index);
1136 rp = vl_msg_api_alloc (sizeof (*rp));
1137 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
1138 rp->context = mp->context;
1140 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
1142 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
1144 pthread_mutex_lock (&am->vlib_rp->mutex);
1145 oldheap = svm_push_data_heap (am->vlib_rp);
1147 vec_add1 (shmem_vec, 0);
1149 svm_pop_heap (oldheap);
1150 pthread_mutex_unlock (&am->vlib_rp->mutex);
1152 rp->reply_in_shmem = (uword) shmem_vec;
1154 vl_msg_api_send_shmem (q, (u8 *) & rp);
1158 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1160 u8 **mem_vecp = (u8 **) arg;
1161 u8 *mem_vec = *mem_vecp;
1162 u32 offset = vec_len (mem_vec);
1164 vec_validate (mem_vec, offset + buffer_bytes - 1);
1165 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
1166 *mem_vecp = mem_vec;
1170 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
1172 vl_api_cli_inband_reply_t *rmp;
1174 unix_shared_memory_queue_t *q;
1175 vlib_main_t *vm = vlib_get_main ();
1176 unformat_input_t input;
1179 q = vl_api_client_index_to_input_queue (mp->client_index);
1183 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
1184 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
1186 u32 len = vec_len (out_vec);
1188 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
1190 rmp->length = htonl (len);
1191 clib_memcpy (rmp->reply, out_vec, len);
1198 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
1201 vl_api_set_arp_neighbor_limit_reply_t *rmp;
1202 vnet_main_t *vnm = vnet_get_main ();
1203 clib_error_t *error;
1208 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
1210 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
1214 clib_error_report (error);
1215 rv = VNET_API_ERROR_UNSPECIFIED;
1219 rv = vnm->api_errno;
1222 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
1225 static void vl_api_classify_set_interface_ip_table_t_handler
1226 (vl_api_classify_set_interface_ip_table_t * mp)
1228 vlib_main_t *vm = vlib_get_main ();
1229 vl_api_classify_set_interface_ip_table_reply_t *rmp;
1231 u32 table_index, sw_if_index;
1233 table_index = ntohl (mp->table_index);
1234 sw_if_index = ntohl (mp->sw_if_index);
1236 VALIDATE_SW_IF_INDEX (mp);
1239 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
1241 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
1243 BAD_SW_IF_INDEX_LABEL;
1245 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
1248 static void vl_api_classify_set_interface_l2_tables_t_handler
1249 (vl_api_classify_set_interface_l2_tables_t * mp)
1251 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
1253 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
1256 ip4_table_index = ntohl (mp->ip4_table_index);
1257 ip6_table_index = ntohl (mp->ip6_table_index);
1258 other_table_index = ntohl (mp->other_table_index);
1259 sw_if_index = ntohl (mp->sw_if_index);
1261 VALIDATE_SW_IF_INDEX (mp);
1264 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
1268 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
1274 if (ip4_table_index != ~0 || ip6_table_index != ~0
1275 || other_table_index != ~0)
1281 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
1283 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
1286 BAD_SW_IF_INDEX_LABEL;
1288 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
1291 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1292 u32 sw_if_index, u32 enable);
1295 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1299 vl_api_l2_interface_efp_filter_reply_t *rmp;
1300 vnet_main_t *vnm = vnet_get_main ();
1302 // enable/disable the feature
1303 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
1304 rv = vnm->api_errno;
1306 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1310 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
1312 vl_api_show_version_reply_t *rmp;
1314 char *vpe_api_get_build_directory (void);
1315 char *vpe_api_get_version (void);
1316 char *vpe_api_get_build_date (void);
1318 unix_shared_memory_queue_t *q =
1319 vl_api_client_index_to_input_queue (mp->client_index);
1325 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
1327 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
1328 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
1329 ARRAY_LEN(rmp->build_directory)-1);
1330 strncpy ((char *) rmp->version, vpe_api_get_version(),
1331 ARRAY_LEN(rmp->version)-1);
1332 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
1333 ARRAY_LEN(rmp->build_date)-1);
1339 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
1341 vlib_main_t *vm = vlib_get_main ();
1342 vl_api_get_node_index_reply_t *rmp;
1345 u32 node_index = ~0;
1347 n = vlib_get_node_by_name (vm, mp->node_name);
1350 rv = VNET_API_ERROR_NO_SUCH_NODE;
1352 node_index = n->index;
1355 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1357 rmp->node_index = ntohl(node_index);
1363 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
1365 vlib_main_t *vm = vlib_get_main ();
1366 vl_api_get_next_index_reply_t *rmp;
1367 vlib_node_t *node, *next_node;
1369 u32 next_node_index = ~0, next_index = ~0;
1372 node = vlib_get_node_by_name (vm, mp->node_name);
1376 rv = VNET_API_ERROR_NO_SUCH_NODE;
1380 next_node = vlib_get_node_by_name (vm, mp->next_name);
1384 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1388 next_node_index = next_node->index;
1390 p = hash_get (node->next_slot_by_node, next_node_index);
1394 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1402 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
1404 rmp->next_index = ntohl(next_index);
1410 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
1412 vlib_main_t *vm = vlib_get_main ();
1413 vl_api_add_node_next_reply_t *rmp;
1414 vlib_node_t *n, *next;
1416 u32 next_index = ~0;
1418 n = vlib_get_node_by_name (vm, mp->node_name);
1422 rv = VNET_API_ERROR_NO_SUCH_NODE;
1426 next = vlib_get_node_by_name (vm, mp->next_name);
1429 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1431 next_index = vlib_node_add_next (vm, n->index, next->index);
1435 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1437 rmp->next_index = ntohl(next_index);
1442 static void vl_api_vxlan_add_del_tunnel_t_handler
1443 (vl_api_vxlan_add_del_tunnel_t * mp)
1445 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
1447 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
1448 u32 encap_fib_index;
1450 ip4_main_t *im = &ip4_main;
1451 vnet_main_t *vnm = vnet_get_main ();
1452 u32 sw_if_index = ~0;
1454 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1457 rv = VNET_API_ERROR_NO_SUCH_FIB;
1460 encap_fib_index = p[0];
1461 memset (a, 0, sizeof (*a));
1463 a->is_add = mp->is_add;
1464 a->is_ip6 = mp->is_ipv6;
1466 /* ip addresses sent in network byte order */
1467 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
1468 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
1470 /* Check src & dst are different */
1471 if (ip46_address_cmp (&a->dst, &a->src) == 0)
1473 rv = VNET_API_ERROR_SAME_SRC_DST;
1476 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
1477 if (ip46_address_is_multicast (&a->dst) &&
1478 pool_is_free_index (vnm->interface_main.sw_interfaces,
1479 a->mcast_sw_if_index))
1481 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1484 a->encap_fib_index = encap_fib_index;
1485 a->decap_next_index = ntohl (mp->decap_next_index);
1486 a->vni = ntohl (mp->vni);
1487 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
1491 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
1493 rmp->sw_if_index = ntohl (sw_if_index);
1498 static void send_vxlan_tunnel_details
1499 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1501 vl_api_vxlan_tunnel_details_t *rmp;
1502 ip4_main_t *im4 = &ip4_main;
1503 ip6_main_t *im6 = &ip6_main;
1504 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
1506 rmp = vl_msg_api_alloc (sizeof (*rmp));
1507 memset (rmp, 0, sizeof (*rmp));
1508 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
1511 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
1512 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
1513 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1517 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
1518 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
1519 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1521 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
1522 rmp->vni = htonl (t->vni);
1523 rmp->decap_next_index = htonl (t->decap_next_index);
1524 rmp->sw_if_index = htonl (t->sw_if_index);
1525 rmp->is_ipv6 = is_ipv6;
1526 rmp->context = context;
1528 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1531 static void vl_api_vxlan_tunnel_dump_t_handler
1532 (vl_api_vxlan_tunnel_dump_t * mp)
1534 unix_shared_memory_queue_t *q;
1535 vxlan_main_t *vxm = &vxlan_main;
1539 q = vl_api_client_index_to_input_queue (mp->client_index);
1545 sw_if_index = ntohl (mp->sw_if_index);
1547 if (~0 == sw_if_index)
1550 pool_foreach (t, vxm->tunnels,
1552 send_vxlan_tunnel_details(t, q, mp->context);
1558 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
1559 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
1563 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
1564 send_vxlan_tunnel_details (t, q, mp->context);
1569 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1571 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1573 vl_api_l2_patch_add_del_reply_t *rmp;
1574 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1578 VALIDATE_RX_SW_IF_INDEX (mp);
1579 VALIDATE_TX_SW_IF_INDEX (mp);
1581 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1582 ntohl (mp->tx_sw_if_index),
1583 (int) (mp->is_add != 0));
1585 BAD_RX_SW_IF_INDEX_LABEL;
1586 BAD_TX_SW_IF_INDEX_LABEL;
1588 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1592 vl_api_vxlan_gpe_add_del_tunnel_t_handler
1593 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
1595 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
1597 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
1598 u32 encap_fib_index, decap_fib_index;
1601 ip4_main_t *im = &ip4_main;
1602 u32 sw_if_index = ~0;
1605 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1608 rv = VNET_API_ERROR_NO_SUCH_FIB;
1611 encap_fib_index = p[0];
1613 protocol = mp->protocol;
1615 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
1616 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
1618 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
1621 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
1624 decap_fib_index = p[0];
1628 decap_fib_index = ntohl (mp->decap_vrf_id);
1631 /* Check src & dst are different */
1632 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
1633 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
1635 rv = VNET_API_ERROR_SAME_SRC_DST;
1638 memset (a, 0, sizeof (*a));
1640 a->is_add = mp->is_add;
1641 a->is_ip6 = mp->is_ipv6;
1642 /* ip addresses sent in network byte order */
1645 clib_memcpy (&(a->local.ip6), mp->local, 16);
1646 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
1650 clib_memcpy (&(a->local.ip4), mp->local, 4);
1651 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
1653 a->encap_fib_index = encap_fib_index;
1654 a->decap_fib_index = decap_fib_index;
1655 a->protocol = protocol;
1656 a->vni = ntohl (mp->vni);
1657 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
1661 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
1663 rmp->sw_if_index = ntohl (sw_if_index);
1668 static void send_vxlan_gpe_tunnel_details
1669 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1671 vl_api_vxlan_gpe_tunnel_details_t *rmp;
1672 ip4_main_t *im4 = &ip4_main;
1673 ip6_main_t *im6 = &ip6_main;
1674 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
1676 rmp = vl_msg_api_alloc (sizeof (*rmp));
1677 memset (rmp, 0, sizeof (*rmp));
1678 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
1681 memcpy (rmp->local, &(t->local.ip6), 16);
1682 memcpy (rmp->remote, &(t->remote.ip6), 16);
1683 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1684 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
1688 memcpy (rmp->local, &(t->local.ip4), 4);
1689 memcpy (rmp->remote, &(t->remote.ip4), 4);
1690 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1691 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
1693 rmp->vni = htonl (t->vni);
1694 rmp->protocol = t->protocol;
1695 rmp->sw_if_index = htonl (t->sw_if_index);
1696 rmp->is_ipv6 = is_ipv6;
1697 rmp->context = context;
1699 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1702 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
1703 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
1705 unix_shared_memory_queue_t *q;
1706 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
1707 vxlan_gpe_tunnel_t *t;
1710 q = vl_api_client_index_to_input_queue (mp->client_index);
1716 sw_if_index = ntohl (mp->sw_if_index);
1718 if (~0 == sw_if_index)
1721 pool_foreach (t, vgm->tunnels,
1723 send_vxlan_gpe_tunnel_details(t, q, mp->context);
1729 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
1730 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
1734 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
1735 send_vxlan_gpe_tunnel_details (t, q, mp->context);
1740 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
1743 vl_api_interface_name_renumber_reply_t *rmp;
1746 VALIDATE_SW_IF_INDEX (mp);
1748 rv = vnet_interface_name_renumber
1749 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1751 BAD_SW_IF_INDEX_LABEL;
1753 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1757 arp_change_data_callback (u32 pool_index, u8 * new_mac,
1758 u32 sw_if_index, u32 address)
1760 vpe_api_main_t *am = &vpe_api_main;
1761 vlib_main_t *vm = am->vlib_main;
1762 vl_api_ip4_arp_event_t *event;
1763 static f64 arp_event_last_time;
1764 f64 now = vlib_time_now (vm);
1766 if (pool_is_free_index (am->arp_events, pool_index))
1769 event = pool_elt_at_index (am->arp_events, pool_index);
1771 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1773 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1777 if (sw_if_index == event->sw_if_index &&
1779 /* for BD case, also check IP address with 10 sec timeout */
1780 (address == event->address &&
1781 (now - arp_event_last_time) < 10.0)))
1786 arp_event_last_time = now;
1787 event->sw_if_index = sw_if_index;
1789 event->address = address;
1794 nd_change_data_callback (u32 pool_index, u8 * new_mac,
1795 u32 sw_if_index, ip6_address_t * address)
1797 vpe_api_main_t *am = &vpe_api_main;
1798 vlib_main_t *vm = am->vlib_main;
1799 vl_api_ip6_nd_event_t *event;
1800 static f64 nd_event_last_time;
1801 f64 now = vlib_time_now (vm);
1803 if (pool_is_free_index (am->nd_events, pool_index))
1806 event = pool_elt_at_index (am->nd_events, pool_index);
1809 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
1811 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
1815 if (sw_if_index == event->sw_if_index &&
1817 /* for BD case, also check IP address with 10 sec timeout */
1818 (ip6_address_is_equal (address,
1819 (ip6_address_t *) event->address) &&
1820 (now - nd_event_last_time) < 10.0)))
1825 nd_event_last_time = now;
1826 event->sw_if_index = sw_if_index;
1828 clib_memcpy (event->address, address, sizeof (event->address));
1833 arp_change_delete_callback (u32 pool_index, u8 * notused)
1835 vpe_api_main_t *am = &vpe_api_main;
1837 if (pool_is_free_index (am->arp_events, pool_index))
1840 pool_put_index (am->arp_events, pool_index);
1845 nd_change_delete_callback (u32 pool_index, u8 * notused)
1847 vpe_api_main_t *am = &vpe_api_main;
1849 if (pool_is_free_index (am->nd_events, pool_index))
1852 pool_put_index (am->nd_events, pool_index);
1857 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
1859 vpe_api_main_t *am = &vpe_api_main;
1860 vnet_main_t *vnm = vnet_get_main ();
1861 vl_api_want_ip4_arp_events_reply_t *rmp;
1862 vl_api_ip4_arp_event_t *event;
1865 if (mp->enable_disable)
1867 pool_get (am->arp_events, event);
1868 memset (event, 0, sizeof (*event));
1870 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
1871 event->client_index = mp->client_index;
1872 event->context = mp->context;
1873 event->address = mp->address;
1874 event->pid = mp->pid;
1875 if (mp->address == 0)
1878 rv = vnet_add_del_ip4_arp_change_event
1879 (vnm, arp_change_data_callback,
1880 mp->pid, &mp->address /* addr, in net byte order */ ,
1881 vpe_resolver_process_node.index,
1882 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
1886 rv = vnet_add_del_ip4_arp_change_event
1887 (vnm, arp_change_delete_callback,
1888 mp->pid, &mp->address /* addr, in net byte order */ ,
1889 vpe_resolver_process_node.index,
1890 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1892 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
1896 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
1898 vpe_api_main_t *am = &vpe_api_main;
1899 vnet_main_t *vnm = vnet_get_main ();
1900 vl_api_want_ip6_nd_events_reply_t *rmp;
1901 vl_api_ip6_nd_event_t *event;
1904 if (mp->enable_disable)
1906 pool_get (am->nd_events, event);
1907 memset (event, 0, sizeof (*event));
1909 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
1910 event->client_index = mp->client_index;
1911 event->context = mp->context;
1912 clib_memcpy (event->address, mp->address, 16);
1913 event->pid = mp->pid;
1914 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
1917 rv = vnet_add_del_ip6_nd_change_event
1918 (vnm, nd_change_data_callback,
1919 mp->pid, mp->address /* addr, in net byte order */ ,
1920 vpe_resolver_process_node.index,
1921 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
1925 rv = vnet_add_del_ip6_nd_change_event
1926 (vnm, nd_change_delete_callback,
1927 mp->pid, mp->address /* addr, in net byte order */ ,
1928 vpe_resolver_process_node.index,
1929 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
1931 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
1934 static void vl_api_input_acl_set_interface_t_handler
1935 (vl_api_input_acl_set_interface_t * mp)
1937 vlib_main_t *vm = vlib_get_main ();
1938 vl_api_input_acl_set_interface_reply_t *rmp;
1940 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
1942 ip4_table_index = ntohl (mp->ip4_table_index);
1943 ip6_table_index = ntohl (mp->ip6_table_index);
1944 l2_table_index = ntohl (mp->l2_table_index);
1945 sw_if_index = ntohl (mp->sw_if_index);
1947 VALIDATE_SW_IF_INDEX (mp);
1949 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
1950 ip6_table_index, l2_table_index, mp->is_add);
1952 BAD_SW_IF_INDEX_LABEL;
1954 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
1958 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
1962 api_main_t *am = &api_main;
1963 vlib_main_t *vm = vlib_get_main ();
1965 vl_api_get_node_graph_reply_t *rmp;
1967 pthread_mutex_lock (&am->vlib_rp->mutex);
1968 oldheap = svm_push_data_heap (am->vlib_rp);
1971 * Keep the number of memcpy ops to a minimum (e.g. 1).
1973 vec_validate (vector, 16384);
1974 vec_reset_length (vector);
1977 vector = vlib_node_serialize (&vm->node_main, vector,
1978 (u32) ~ 0 /* all threads */ ,
1979 1 /* include nexts */ ,
1980 1 /* include stats */ );
1982 svm_pop_heap (oldheap);
1983 pthread_mutex_unlock (&am->vlib_rp->mutex);
1986 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
1988 rmp->reply_in_shmem = (uword) vector;
1994 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
1997 vl_api_ioam_enable_reply_t *rmp;
1998 clib_error_t *error;
2000 /* Ignoring the profile id as currently a single profile
2002 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
2003 mp->seqno, mp->analyse);
2006 clib_error_report (error);
2007 rv = clib_error_get_code (error);
2010 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
2014 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
2017 vl_api_ioam_disable_reply_t *rmp;
2018 clib_error_t *error;
2020 error = clear_ioam_rewrite_fn ();
2023 clib_error_report (error);
2024 rv = clib_error_get_code (error);
2027 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
2031 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
2033 vlib_main_t *vm = vlib_get_main ();
2034 vl_api_policer_add_del_reply_t *rmp;
2037 sse2_qos_pol_cfg_params_st cfg;
2038 clib_error_t *error;
2041 name = format (0, "%s", mp->name);
2043 memset (&cfg, 0, sizeof (cfg));
2045 cfg.rnd_type = mp->round_type;
2046 cfg.rate_type = mp->rate_type;
2047 cfg.rb.kbps.cir_kbps = mp->cir;
2048 cfg.rb.kbps.eir_kbps = mp->eir;
2049 cfg.rb.kbps.cb_bytes = mp->cb;
2050 cfg.rb.kbps.eb_bytes = mp->eb;
2051 cfg.conform_action.action_type = mp->conform_action_type;
2052 cfg.conform_action.dscp = mp->conform_dscp;
2053 cfg.exceed_action.action_type = mp->exceed_action_type;
2054 cfg.exceed_action.dscp = mp->exceed_dscp;
2055 cfg.violate_action.action_type = mp->violate_action_type;
2056 cfg.violate_action.dscp = mp->violate_dscp;
2057 cfg.color_aware = mp->color_aware;
2059 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
2062 rv = VNET_API_ERROR_UNSPECIFIED;
2065 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
2067 if (rv == 0 && mp->is_add)
2068 rmp->policer_index = ntohl(policer_index);
2070 rmp->policer_index = ~0;
2076 send_policer_details (u8 * name,
2077 sse2_qos_pol_cfg_params_st * config,
2078 policer_read_response_type_st * templ,
2079 unix_shared_memory_queue_t * q, u32 context)
2081 vl_api_policer_details_t *mp;
2083 mp = vl_msg_api_alloc (sizeof (*mp));
2084 memset (mp, 0, sizeof (*mp));
2085 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
2086 mp->context = context;
2087 mp->cir = htonl (config->rb.kbps.cir_kbps);
2088 mp->eir = htonl (config->rb.kbps.eir_kbps);
2089 mp->cb = htonl (config->rb.kbps.cb_bytes);
2090 mp->eb = htonl (config->rb.kbps.eb_bytes);
2091 mp->rate_type = config->rate_type;
2092 mp->round_type = config->rnd_type;
2093 mp->type = config->rfc;
2094 mp->conform_action_type = config->conform_action.action_type;
2095 mp->conform_dscp = config->conform_action.dscp;
2096 mp->exceed_action_type = config->exceed_action.action_type;
2097 mp->exceed_dscp = config->exceed_action.dscp;
2098 mp->violate_action_type = config->violate_action.action_type;
2099 mp->violate_dscp = config->violate_action.dscp;
2100 mp->single_rate = templ->single_rate ? 1 : 0;
2101 mp->color_aware = templ->color_aware ? 1 : 0;
2102 mp->scale = htonl (templ->scale);
2103 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
2104 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
2105 mp->current_limit = htonl (templ->current_limit);
2106 mp->current_bucket = htonl (templ->current_bucket);
2107 mp->extended_limit = htonl (templ->extended_limit);
2108 mp->extended_bucket = htonl (templ->extended_bucket);
2109 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
2111 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
2113 vl_msg_api_send_shmem (q, (u8 *) & mp);
2117 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
2119 unix_shared_memory_queue_t *q;
2120 vnet_policer_main_t *pm = &vnet_policer_main;
2126 sse2_qos_pol_cfg_params_st *config;
2127 policer_read_response_type_st *templ;
2129 q = vl_api_client_index_to_input_queue (mp->client_index);
2133 if (mp->match_name_valid)
2135 match_name = format (0, "%s%c", mp->match_name, 0);
2138 if (mp->match_name_valid)
2140 p = hash_get_mem (pm->policer_config_by_name, match_name);
2144 config = pool_elt_at_index (pm->configs, pool_index);
2145 templ = pool_elt_at_index (pm->policer_templates, pool_index);
2146 send_policer_details (match_name, config, templ, q, mp->context);
2152 hash_foreach_pair (hp, pm->policer_config_by_name,
2154 name = (u8 *) hp->key;
2155 pool_index = hp->value[0];
2156 config = pool_elt_at_index (pm->configs, pool_index);
2157 templ = pool_elt_at_index (pm->policer_templates, pool_index);
2158 send_policer_details(name, config, templ, q, mp->context);
2166 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
2168 vl_api_pg_create_interface_reply_t *rmp;
2171 pg_main_t *pg = &pg_main;
2172 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
2173 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
2176 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
2178 rmp->sw_if_index = ntohl(pi->sw_if_index);
2184 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
2186 vl_api_pg_capture_reply_t *rmp;
2189 vnet_main_t *vnm = vnet_get_main ();
2190 vnet_interface_main_t *im = &vnm->interface_main;
2191 vnet_hw_interface_t *hi = 0;
2193 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
2194 u32 hw_if_index = ~0;
2195 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
2198 vec_free (intf_name);
2200 if (hw_if_index != ~0)
2202 pg_capture_args_t _a, *a = &_a;
2204 u32 len = ntohl (mp->pcap_name_length);
2205 u8 *pcap_file_name = vec_new (u8, len);
2206 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
2208 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
2209 a->hw_if_index = hw_if_index;
2210 a->dev_instance = hi->dev_instance;
2211 a->is_enabled = mp->is_enabled;
2212 a->pcap_file_name = pcap_file_name;
2213 a->count = ntohl (mp->count);
2215 clib_error_t *e = pg_capture (a);
2218 clib_error_report (e);
2219 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
2222 vec_free (pcap_file_name);
2224 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
2228 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
2230 vl_api_pg_enable_disable_reply_t *rmp;
2233 pg_main_t *pg = &pg_main;
2234 u32 stream_index = ~0;
2236 int is_enable = mp->is_enabled != 0;
2237 u32 len = ntohl (mp->stream_name_length) - 1;
2241 u8 *stream_name = vec_new (u8, len);
2242 clib_memcpy (stream_name, mp->stream_name, len);
2243 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
2246 vec_free (stream_name);
2249 pg_enable_disable (stream_index, is_enable);
2251 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
2255 vl_api_ip_source_and_port_range_check_add_del_t_handler
2256 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
2258 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
2261 u8 is_ipv6 = mp->is_ipv6;
2262 u8 is_add = mp->is_add;
2263 u8 mask_length = mp->mask_length;
2264 ip4_address_t ip4_addr;
2265 ip6_address_t ip6_addr;
2267 u16 *high_ports = 0;
2269 u16 tmp_low, tmp_high;
2273 // Validate port range
2274 num_ranges = mp->number_of_ranges;
2275 if (num_ranges > 32)
2276 { // This is size of array in VPE.API
2277 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
2281 vec_reset_length (low_ports);
2282 vec_reset_length (high_ports);
2284 for (i = 0; i < num_ranges; i++)
2286 tmp_low = mp->low_ports[i];
2287 tmp_high = mp->high_ports[i];
2288 // If tmp_low <= tmp_high then only need to check tmp_low = 0
2289 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
2290 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
2292 rv = VNET_API_ERROR_INVALID_VALUE;
2295 vec_add1 (low_ports, tmp_low);
2296 vec_add1 (high_ports, tmp_high + 1);
2299 // Validate mask_length
2300 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
2302 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
2306 vrf_id = ntohl (mp->vrf_id);
2310 rv = VNET_API_ERROR_INVALID_VALUE;
2317 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
2318 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
2322 high_ports, is_add);
2326 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
2327 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
2331 high_ports, is_add);
2335 vec_free (low_ports);
2336 vec_free (high_ports);
2337 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
2341 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
2342 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
2344 vlib_main_t *vm = vlib_get_main ();
2345 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
2346 ip4_main_t *im = &ip4_main;
2349 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2350 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
2354 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
2355 ntohl (mp->tcp_out_vrf_id);
2356 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
2357 ntohl (mp->udp_out_vrf_id);
2358 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
2359 ntohl (mp->tcp_in_vrf_id);
2360 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
2361 ntohl (mp->udp_in_vrf_id);
2364 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
2366 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
2368 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
2372 rv = VNET_API_ERROR_INVALID_VALUE;
2376 fib_index[i] = p[0];
2381 sw_if_index = ntohl (mp->sw_if_index);
2383 VALIDATE_SW_IF_INDEX (mp);
2386 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
2389 BAD_SW_IF_INDEX_LABEL;
2392 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
2396 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
2398 vl_api_delete_subif_reply_t *rmp;
2401 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
2403 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
2407 vl_api_punt_t_handler (vl_api_punt_t * mp)
2409 vl_api_punt_reply_t *rmp;
2410 vlib_main_t *vm = vlib_get_main ();
2412 clib_error_t *error;
2414 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
2415 ntohs (mp->l4_port), mp->is_add);
2419 clib_error_report (error);
2422 REPLY_MACRO (VL_API_PUNT_REPLY);
2426 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
2428 vl_api_feature_enable_disable_reply_t *rmp;
2430 u8 *arc_name, *feature_name;
2432 VALIDATE_SW_IF_INDEX (mp);
2434 arc_name = format (0, "%s%c", mp->arc_name, 0);
2435 feature_name = format (0, "%s%c", mp->feature_name, 0);
2437 vnet_feature_registration_t *reg;
2439 vnet_get_feature_reg ((const char *) arc_name,
2440 (const char *) feature_name);
2442 rv = VNET_API_ERROR_INVALID_VALUE;
2446 clib_error_t *error = 0;
2448 sw_if_index = ntohl (mp->sw_if_index);
2449 if (reg->enable_disable_cb)
2450 error = reg->enable_disable_cb (sw_if_index, mp->enable);
2452 vnet_feature_enable_disable ((const char *) arc_name,
2453 (const char *) feature_name,
2454 sw_if_index, mp->enable, 0, 0);
2457 clib_error_report (error);
2458 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
2462 vec_free (feature_name);
2463 vec_free (arc_name);
2465 BAD_SW_IF_INDEX_LABEL;
2467 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
2470 #define BOUNCE_HANDLER(nn) \
2471 static void vl_api_##nn##_t_handler ( \
2472 vl_api_##nn##_t *mp) \
2474 vpe_client_registration_t *reg; \
2475 vpe_api_main_t * vam = &vpe_api_main; \
2476 unix_shared_memory_queue_t * q; \
2478 /* One registration only... */ \
2479 pool_foreach(reg, vam->nn##_registrations, \
2481 q = vl_api_client_index_to_input_queue (reg->client_index); \
2484 * If the queue is stuffed, turf the msg and complain \
2485 * It's unlikely that the intended recipient is \
2486 * alive; avoid deadlock at all costs. \
2488 if (q->cursize == q->maxsize) { \
2489 clib_warning ("ERROR: receiver queue full, drop msg"); \
2490 vl_msg_api_free (mp); \
2493 vl_msg_api_send_shmem (q, (u8 *)&mp); \
2497 vl_msg_api_free (mp); \
2500 static void setup_message_id_table (api_main_t * am);
2504 * Add vpe's API message handlers to the table.
2505 * vlib has alread mapped shared memory and
2506 * added the client registration handlers.
2507 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
2509 static clib_error_t *
2510 vpe_api_hookup (vlib_main_t * vm)
2512 api_main_t *am = &api_main;
2515 vl_msg_api_set_handlers(VL_API_##N, #n, \
2516 vl_api_##n##_t_handler, \
2518 vl_api_##n##_t_endian, \
2519 vl_api_##n##_t_print, \
2520 sizeof(vl_api_##n##_t), 1);
2521 foreach_vpe_api_msg;
2525 * Trace space for classifier mask+match
2527 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
2528 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
2529 += 5 * sizeof (u32x4);
2530 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
2533 * Thread-safe API messages
2535 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
2536 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
2539 * Set up the (msg_name, crc, message-id) table
2541 setup_message_id_table (am);
2546 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
2548 static clib_error_t *
2549 vpe_api_init (vlib_main_t * vm)
2551 vpe_api_main_t *am = &vpe_api_main;
2554 am->vnet_main = vnet_get_main ();
2555 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
2556 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2557 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
2558 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2559 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
2560 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
2561 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
2564 vl_set_memory_region_name ("/vpe-api");
2565 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
2570 VLIB_INIT_FUNCTION (vpe_api_init);
2573 static clib_error_t *
2574 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
2577 u64 baseva, size, pvt_heap_size;
2579 const int max_buf_size = 4096;
2581 struct passwd _pw, *pw;
2582 struct group _grp, *grp;
2584 buf = vec_new (char, 128);
2585 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2587 if (unformat (input, "prefix %s", &chroot_path))
2589 vec_add1 (chroot_path, 0);
2590 vl_set_memory_root_path ((char *) chroot_path);
2592 else if (unformat (input, "uid %d", &uid))
2593 vl_set_memory_uid (uid);
2594 else if (unformat (input, "gid %d", &gid))
2595 vl_set_memory_gid (gid);
2596 else if (unformat (input, "baseva %llx", &baseva))
2597 vl_set_global_memory_baseva (baseva);
2598 else if (unformat (input, "global-size %lldM", &size))
2599 vl_set_global_memory_size (size * (1ULL << 20));
2600 else if (unformat (input, "global-size %lldG", &size))
2601 vl_set_global_memory_size (size * (1ULL << 30));
2602 else if (unformat (input, "global-size %lld", &size))
2603 vl_set_global_memory_size (size);
2604 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
2605 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2606 else if (unformat (input, "global-pvt-heap-size size %lld",
2608 vl_set_global_pvt_heap_size (pvt_heap_size);
2609 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
2610 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
2611 else if (unformat (input, "api-pvt-heap-size size %lld",
2613 vl_set_api_pvt_heap_size (pvt_heap_size);
2614 else if (unformat (input, "api-size %lldM", &size))
2615 vl_set_api_memory_size (size * (1ULL << 20));
2616 else if (unformat (input, "api-size %lldG", &size))
2617 vl_set_api_memory_size (size * (1ULL << 30));
2618 else if (unformat (input, "api-size %lld", &size))
2619 vl_set_api_memory_size (size);
2620 else if (unformat (input, "uid %s", &s))
2622 /* lookup the username */
2625 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
2626 && (vec_len (buf) <= max_buf_size))
2628 vec_resize (buf, vec_len (buf) * 2);
2632 e = clib_error_return_code (0, rv,
2633 CLIB_ERROR_ERRNO_VALID |
2635 "cannot fetch username %s", s);
2643 clib_error_return_fatal (0, "username %s does not exist", s);
2649 vl_set_memory_uid (pw->pw_uid);
2651 else if (unformat (input, "gid %s", &s))
2653 /* lookup the group name */
2656 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
2657 && (vec_len (buf) <= max_buf_size))
2659 vec_resize (buf, vec_len (buf) * 2);
2663 e = clib_error_return_code (0, rv,
2664 CLIB_ERROR_ERRNO_VALID |
2666 "cannot fetch group %s", s);
2673 e = clib_error_return_fatal (0, "group %s does not exist", s);
2680 vl_set_memory_gid (grp->gr_gid);
2683 return clib_error_return (0, "unknown input `%U'",
2684 format_unformat_error, input);
2689 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
2692 get_unformat_vnet_sw_interface (void)
2694 return (void *) &unformat_vnet_sw_interface;
2698 format_arp_event (u8 * s, va_list * args)
2700 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
2702 s = format (s, "pid %d: ", event->pid);
2704 s = format (s, "bd mac/ip4 binding events");
2706 s = format (s, "resolution for %U", format_ip4_address, &event->address);
2711 format_nd_event (u8 * s, va_list * args)
2713 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
2715 s = format (s, "pid %d: ", event->pid);
2717 s = format (s, "bd mac/ip6 binding events");
2719 s = format (s, "resolution for %U", format_ip6_address, event->address);
2723 static clib_error_t *
2724 show_ip_arp_nd_events_fn (vlib_main_t * vm,
2725 unformat_input_t * input, vlib_cli_command_t * cmd)
2727 vpe_api_main_t *am = &vpe_api_main;
2728 vl_api_ip4_arp_event_t *arp_event;
2729 vl_api_ip6_nd_event_t *nd_event;
2731 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
2733 vlib_cli_output (vm, "No active arp or nd event registrations");
2738 pool_foreach (arp_event, am->arp_events,
2740 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
2743 pool_foreach (nd_event, am->nd_events,
2745 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
2753 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
2754 .path = "show arp-nd-event registrations",
2755 .function = show_ip_arp_nd_events_fn,
2756 .short_help = "Show ip4 arp and ip6 nd event registrations",
2760 #define vl_msg_name_crc_list
2761 #include <vpp/api/vpe_all_api_h.h>
2762 #undef vl_msg_name_crc_list
2765 setup_message_id_table (api_main_t * am)
2767 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
2768 foreach_vl_msg_name_crc_memclnt;
2769 foreach_vl_msg_name_crc_vpe;
2775 * fd.io coding-style-patch-verification: ON
2778 * eval: (c-set-style "gnu")