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>
55 #include <vnet/dhcp/proxy.h>
56 #include <vnet/dhcp/client.h>
58 #include <vnet/sr/sr.h>
60 #include <vnet/dhcpv6/proxy.h>
61 #include <vlib/vlib.h>
62 #include <vlib/unix/unix.h>
63 #include <vlibapi/api.h>
64 #include <vlibmemory/api.h>
65 #include <vnet/classify/vnet_classify.h>
66 #include <vnet/classify/input_acl.h>
67 #include <vnet/classify/policer_classify.h>
68 #include <vnet/classify/flow_classify.h>
69 #include <vnet/l2/l2_classify.h>
70 #include <vnet/vxlan/vxlan.h>
71 #include <vnet/l2/l2_vtr.h>
72 #include <vnet/vxlan-gpe/vxlan_gpe.h>
73 #include <vnet/map/map.h>
74 #include <vnet/cop/cop.h>
75 #include <vnet/ip/ip6_hop_by_hop.h>
76 #include <vnet/ip/ip_source_and_port_range_check.h>
77 #include <vnet/policer/policer.h>
78 #include <vnet/flow/flow_report.h>
79 #include <vnet/flow/flow_report_classify.h>
80 #include <vnet/ip/punt.h>
81 #include <vnet/feature/feature.h>
84 #undef __included_bihash_template_h__
85 #include <vnet/l2/l2_fib.h>
87 #include <vpp/stats/stats.h>
88 #include <vpp/oam/oam.h>
90 #include <vnet/ethernet/ethernet.h>
91 #include <vnet/ethernet/arp_packet.h>
92 #include <vnet/interface.h>
93 #include <vnet/l2/l2_fib.h>
94 #include <vnet/l2/l2_bd.h>
95 #include <vpp/api/vpe_msg_enum.h>
96 #include <vnet/span/span.h>
97 #include <vnet/fib/ip6_fib.h>
98 #include <vnet/fib/ip4_fib.h>
99 #include <vnet/fib/fib_api.h>
100 #include <vnet/dpo/drop_dpo.h>
101 #include <vnet/dpo/receive_dpo.h>
102 #include <vnet/dpo/lookup_dpo.h>
103 #include <vnet/dpo/classify_dpo.h>
104 #include <vnet/dpo/ip_null_dpo.h>
105 #define vl_typedefs /* define message structures */
106 #include <vpp/api/vpe_all_api_h.h>
108 #define vl_endianfun /* define message structures */
109 #include <vpp/api/vpe_all_api_h.h>
111 /* instantiate all the print functions we know about */
112 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
114 #include <vpp/api/vpe_all_api_h.h>
116 #include <vlibapi/api_helper_macros.h>
117 #define foreach_vpe_api_msg \
118 _(WANT_OAM_EVENTS, want_oam_events) \
119 _(OAM_ADD_DEL, oam_add_del) \
120 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
121 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
122 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
123 _(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
124 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
125 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
126 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
127 _(CREATE_SUBIF, create_subif) \
128 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
129 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
130 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
131 _(RESET_FIB, reset_fib) \
132 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
133 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
134 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
135 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
136 _(CREATE_LOOPBACK, create_loopback) \
137 _(CONTROL_PING, control_ping) \
138 _(CLI_REQUEST, cli_request) \
139 _(CLI_INBAND, cli_inband) \
140 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
141 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
142 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
143 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
144 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
145 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
146 _(GET_NODE_INDEX, get_node_index) \
147 _(ADD_NODE_NEXT, add_node_next) \
148 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
149 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
150 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
151 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
152 _(SHOW_VERSION, show_version) \
153 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
154 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
155 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
156 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
157 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
158 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
159 _(DELETE_LOOPBACK, delete_loopback) \
160 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
161 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
162 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
163 _(GET_NODE_GRAPH, get_node_graph) \
164 _(IOAM_ENABLE, ioam_enable) \
165 _(IOAM_DISABLE, ioam_disable) \
166 _(POLICER_ADD_DEL, policer_add_del) \
167 _(POLICER_DUMP, policer_dump) \
168 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
169 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
170 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
171 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
172 _(CLASSIFY_TABLE_INFO,classify_table_info) \
173 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
174 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
175 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
176 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
177 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
178 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
179 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
180 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
181 _(GET_NEXT_INDEX, get_next_index) \
182 _(PG_CREATE_INTERFACE, pg_create_interface) \
183 _(PG_CAPTURE, pg_capture) \
184 _(PG_ENABLE_DISABLE, pg_enable_disable) \
185 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
186 ip_source_and_port_range_check_add_del) \
187 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
188 ip_source_and_port_range_check_interface_add_del) \
189 _(DELETE_SUBIF, delete_subif) \
190 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
192 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
193 _(FLOW_CLASSIFY_DUMP, flow_classify_dump) \
194 _(FEATURE_ENABLE_DISABLE, feature_enable_disable)
197 #define QUOTE(x) QUOTE_(x)
200 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
201 RESOLVE_IP6_ADD_DEL_ROUTE,
204 static vlib_node_registration_t vpe_resolver_process_node;
205 vpe_api_main_t vpe_api_main;
207 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
208 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
210 /* Clean up all registrations belonging to the indicated client */
212 vl_api_memclnt_delete_callback (u32 client_index)
214 vpe_api_main_t *vam = &vpe_api_main;
215 vpe_client_registration_t *rp;
217 int stats_memclnt_delete_callback (u32 client_index);
219 stats_memclnt_delete_callback (client_index);
222 p = hash_get (vam->a##_registration_hash, client_index); \
224 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
225 pool_put (vam->a##_registrations, rp); \
226 hash_unset (vam->a##_registration_hash, client_index); \
228 foreach_registration_hash;
233 pub_sub_handler (oam_events, OAM_EVENTS);
235 #define RESOLUTION_EVENT 1
236 #define RESOLUTION_PENDING_EVENT 2
237 #define IP4_ARP_EVENT 3
238 #define IP6_ND_EVENT 4
240 int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
242 int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
245 handle_ip4_arp_event (u32 pool_index)
247 vpe_api_main_t *vam = &vpe_api_main;
248 vnet_main_t *vnm = vam->vnet_main;
249 vlib_main_t *vm = vam->vlib_main;
250 vl_api_ip4_arp_event_t *event;
251 vl_api_ip4_arp_event_t *mp;
252 unix_shared_memory_queue_t *q;
254 /* Client can cancel, die, etc. */
255 if (pool_is_free_index (vam->arp_events, pool_index))
258 event = pool_elt_at_index (vam->arp_events, pool_index);
260 q = vl_api_client_index_to_input_queue (event->client_index);
263 (void) vnet_add_del_ip4_arp_change_event
264 (vnm, arp_change_delete_callback,
265 event->pid, &event->address,
266 vpe_resolver_process_node.index, IP4_ARP_EVENT,
267 ~0 /* pool index, notused */ , 0 /* is_add */ );
271 if (q->cursize < q->maxsize)
273 mp = vl_msg_api_alloc (sizeof (*mp));
274 clib_memcpy (mp, event, sizeof (*mp));
275 vl_msg_api_send_shmem (q, (u8 *) & mp);
279 static f64 last_time;
281 * Throttle syslog msgs.
282 * It's pretty tempting to just revoke the registration...
284 if (vlib_time_now (vm) > last_time + 10.0)
286 clib_warning ("arp event for %U to pid %d: queue stuffed!",
287 format_ip4_address, &event->address, event->pid);
288 last_time = vlib_time_now (vm);
294 handle_ip6_nd_event (u32 pool_index)
296 vpe_api_main_t *vam = &vpe_api_main;
297 vnet_main_t *vnm = vam->vnet_main;
298 vlib_main_t *vm = vam->vlib_main;
299 vl_api_ip6_nd_event_t *event;
300 vl_api_ip6_nd_event_t *mp;
301 unix_shared_memory_queue_t *q;
303 /* Client can cancel, die, etc. */
304 if (pool_is_free_index (vam->nd_events, pool_index))
307 event = pool_elt_at_index (vam->nd_events, pool_index);
309 q = vl_api_client_index_to_input_queue (event->client_index);
312 (void) vnet_add_del_ip6_nd_change_event
313 (vnm, nd_change_delete_callback,
314 event->pid, &event->address,
315 vpe_resolver_process_node.index, IP6_ND_EVENT,
316 ~0 /* pool index, notused */ , 0 /* is_add */ );
320 if (q->cursize < q->maxsize)
322 mp = vl_msg_api_alloc (sizeof (*mp));
323 clib_memcpy (mp, event, sizeof (*mp));
324 vl_msg_api_send_shmem (q, (u8 *) & mp);
328 static f64 last_time;
330 * Throttle syslog msgs.
331 * It's pretty tempting to just revoke the registration...
333 if (vlib_time_now (vm) > last_time + 10.0)
335 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
336 format_ip6_address, &event->address, event->pid);
337 last_time = vlib_time_now (vm);
343 resolver_process (vlib_main_t * vm,
344 vlib_node_runtime_t * rt, vlib_frame_t * f)
347 uword *event_data = 0;
353 vlib_process_wait_for_event_or_clock (vm, timeout);
355 event_type = vlib_process_get_events (vm, &event_data);
359 case RESOLUTION_PENDING_EVENT:
363 case RESOLUTION_EVENT:
364 clib_warning ("resolver: BOGUS TYPE");
368 for (i = 0; i < vec_len (event_data); i++)
369 handle_ip4_arp_event (event_data[i]);
373 for (i = 0; i < vec_len (event_data); i++)
374 handle_ip6_nd_event (event_data[i]);
377 case ~0: /* timeout */
381 vec_reset_length (event_data);
383 return 0; /* or not */
387 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
388 .function = resolver_process,
389 .type = VLIB_NODE_TYPE_PROCESS,
390 .name = "vpe-route-resolver-process",
395 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
397 vl_api_sw_interface_set_vpath_reply_t *rmp;
399 u32 sw_if_index = ntohl (mp->sw_if_index);
401 VALIDATE_SW_IF_INDEX (mp);
403 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
404 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
405 sw_if_index, mp->enable, 0, 0);
406 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
407 sw_if_index, mp->enable, 0, 0);
408 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
409 sw_if_index, mp->enable, 0, 0);
410 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
411 sw_if_index, mp->enable, 0, 0);
413 BAD_SW_IF_INDEX_LABEL;
415 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
419 vl_api_sw_interface_set_vxlan_bypass_t_handler
420 (vl_api_sw_interface_set_vxlan_bypass_t * mp)
422 vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp;
424 u32 sw_if_index = ntohl (mp->sw_if_index);
426 VALIDATE_SW_IF_INDEX (mp);
430 /* not yet implemented */
433 vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass",
434 sw_if_index, mp->enable, 0, 0);
436 BAD_SW_IF_INDEX_LABEL;
438 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY);
442 vl_api_sw_interface_set_l2_xconnect_t_handler
443 (vl_api_sw_interface_set_l2_xconnect_t * mp)
445 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
447 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
448 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
449 vlib_main_t *vm = vlib_get_main ();
450 vnet_main_t *vnm = vnet_get_main ();
452 VALIDATE_RX_SW_IF_INDEX (mp);
456 VALIDATE_TX_SW_IF_INDEX (mp);
457 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
458 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
462 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
465 BAD_RX_SW_IF_INDEX_LABEL;
466 BAD_TX_SW_IF_INDEX_LABEL;
468 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
472 vl_api_sw_interface_set_l2_bridge_t_handler
473 (vl_api_sw_interface_set_l2_bridge_t * mp)
475 bd_main_t *bdm = &bd_main;
476 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
478 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
479 u32 bd_id = ntohl (mp->bd_id);
483 vlib_main_t *vm = vlib_get_main ();
484 vnet_main_t *vnm = vnet_get_main ();
486 VALIDATE_RX_SW_IF_INDEX (mp);
488 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
492 //VALIDATE_TX_SW_IF_INDEX(mp);
493 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
494 rx_sw_if_index, bd_index, bvi, shg, 0);
498 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
501 BAD_RX_SW_IF_INDEX_LABEL;
503 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
507 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
509 bd_main_t *bdm = &bd_main;
510 vl_api_bd_ip_mac_add_del_reply_t *rmp;
512 u32 bd_id = ntohl (mp->bd_id);
516 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
519 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
524 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
525 mp->mac_address, mp->is_ipv6, mp->is_add))
526 rv = VNET_API_ERROR_UNSPECIFIED;
529 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
533 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
535 vl_api_create_vlan_subif_reply_t *rmp;
536 vnet_main_t *vnm = vnet_get_main ();
537 u32 hw_if_index, sw_if_index = (u32) ~ 0;
538 vnet_hw_interface_t *hi;
541 vnet_sw_interface_t template;
543 vnet_interface_main_t *im = &vnm->interface_main;
546 unix_shared_memory_queue_t *q;
549 VALIDATE_SW_IF_INDEX (mp);
551 hw_if_index = ntohl (mp->sw_if_index);
552 hi = vnet_get_hw_interface (vnm, hw_if_index);
554 id = ntohl (mp->vlan_id);
555 if (id == 0 || id > 4095)
557 rv = VNET_API_ERROR_INVALID_VLAN;
561 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
563 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
566 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
570 kp = clib_mem_alloc (sizeof (*kp));
571 *kp = sup_and_sub_key;
573 memset (&template, 0, sizeof (template));
574 template.type = VNET_SW_INTERFACE_TYPE_SUB;
575 template.sup_sw_if_index = hi->sw_if_index;
576 template.sub.id = id;
577 template.sub.eth.raw_flags = 0;
578 template.sub.eth.flags.one_tag = 1;
579 template.sub.eth.outer_vlan_id = id;
580 template.sub.eth.flags.exact_match = 1;
582 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
585 clib_error_report (error);
586 rv = VNET_API_ERROR_INVALID_REGISTRATION;
589 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
590 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
592 BAD_SW_IF_INDEX_LABEL;
595 q = vl_api_client_index_to_input_queue (mp->client_index);
599 rmp = vl_msg_api_alloc (sizeof (*rmp));
600 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
601 rmp->context = mp->context;
602 rmp->retval = ntohl (rv);
603 rmp->sw_if_index = ntohl (sw_if_index);
604 vl_msg_api_send_shmem (q, (u8 *) & rmp);
608 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
610 vl_api_create_subif_reply_t *rmp;
611 vnet_main_t *vnm = vnet_get_main ();
612 u32 sw_if_index = ~0;
615 vnet_sw_interface_t *si;
616 vnet_hw_interface_t *hi;
617 vnet_sw_interface_t template;
619 vnet_interface_main_t *im = &vnm->interface_main;
624 VALIDATE_SW_IF_INDEX (mp);
626 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
627 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
629 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
631 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
635 sw_if_index = si->sw_if_index;
636 sub_id = ntohl (mp->sub_id);
638 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
640 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
644 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
645 sw_if_index, sub_id);
646 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
650 kp = clib_mem_alloc (sizeof (*kp));
651 *kp = sup_and_sub_key;
653 memset (&template, 0, sizeof (template));
654 template.type = VNET_SW_INTERFACE_TYPE_SUB;
655 template.sup_sw_if_index = sw_if_index;
656 template.sub.id = sub_id;
657 template.sub.eth.flags.no_tags = mp->no_tags;
658 template.sub.eth.flags.one_tag = mp->one_tag;
659 template.sub.eth.flags.two_tags = mp->two_tags;
660 template.sub.eth.flags.dot1ad = mp->dot1ad;
661 template.sub.eth.flags.exact_match = mp->exact_match;
662 template.sub.eth.flags.default_sub = mp->default_sub;
663 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
664 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
665 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
666 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
668 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
671 clib_error_report (error);
672 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
676 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
677 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
679 BAD_SW_IF_INDEX_LABEL;
684 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
686 rmp->sw_if_index = ntohl(sw_if_index);
692 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
694 vl_api_proxy_arp_add_del_reply_t *rmp;
697 ip4_main_t *im = &ip4_main;
698 stats_main_t *sm = &stats_main;
699 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
700 ip4_address_t * hi_addr,
701 u32 fib_index, int is_del);
704 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
706 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
710 rv = VNET_API_ERROR_NO_SUCH_FIB;
716 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
717 (ip4_address_t *) mp->hi_address,
718 fib_index, mp->is_add == 0);
722 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
726 vl_api_proxy_arp_intfc_enable_disable_t_handler
727 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
730 vnet_main_t *vnm = vnet_get_main ();
731 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
732 vnet_sw_interface_t *si;
735 VALIDATE_SW_IF_INDEX (mp);
737 sw_if_index = ntohl (mp->sw_if_index);
739 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
741 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
745 si = vnet_get_sw_interface (vnm, sw_if_index);
749 if (mp->enable_disable)
750 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
752 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
754 BAD_SW_IF_INDEX_LABEL;
757 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
761 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
764 vpe_main_t *rm = &vpe_main;
765 ip4_main_t *im4 = &ip4_main;
766 ip6_main_t *im6 = &ip6_main;
767 ip_lookup_main_t *lm;
773 u32 adj_index, sw_if_index;
774 vl_api_is_address_reachable_t *rmp;
776 unix_shared_memory_queue_t *q;
778 q = vl_api_client_index_to_input_queue (mp->client_index);
781 increment_missing_api_client_counter (rm->vlib_main);
785 rmp = vl_msg_api_alloc (sizeof (*rmp));
786 clib_memcpy (rmp, mp, sizeof (*rmp));
788 sw_if_index = mp->next_hop_sw_if_index;
789 clib_memcpy (&addr, mp->address, sizeof (addr));
792 lm = &im6->lookup_main;
793 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
797 lm = &im4->lookup_main;
799 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
806 adj = ip_get_adjacency (lm, adj_index);
808 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
809 && adj->rewrite_header.sw_if_index == sw_if_index)
815 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
816 && adj->rewrite_header.sw_if_index == sw_if_index)
819 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
821 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
823 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
832 vl_msg_api_send_shmem (q, (u8 *) & rmp);
837 vl_api_sw_interface_set_mpls_enable_t_handler
838 (vl_api_sw_interface_set_mpls_enable_t * mp)
840 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
843 VALIDATE_SW_IF_INDEX (mp);
845 mpls_sw_interface_enable_disable (&mpls_main,
846 ntohl (mp->sw_if_index), mp->enable);
848 BAD_SW_IF_INDEX_LABEL;
849 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
853 send_oam_event (oam_target_t * t)
855 vpe_api_main_t *vam = &vpe_api_main;
856 unix_shared_memory_queue_t *q;
857 vpe_client_registration_t *reg;
858 vl_api_oam_event_t *mp;
861 pool_foreach(reg, vam->oam_events_registrations,
863 q = vl_api_client_index_to_input_queue (reg->client_index);
866 mp = vl_msg_api_alloc (sizeof (*mp));
867 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
868 clib_memcpy (mp->dst_address, &t->dst_address,
869 sizeof (mp->dst_address));
870 mp->state = t->state;
871 vl_msg_api_send_shmem (q, (u8 *)&mp);
878 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
880 vl_api_oam_add_del_reply_t *rmp;
883 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
884 (ip4_address_t *) mp->dst_address,
885 ntohl (mp->vrf_id), (int) (mp->is_add));
887 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
891 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
893 stats_main_t *sm = &stats_main;
894 vnet_interface_main_t *im = sm->interface_main;
895 vl_api_vnet_summary_stats_reply_t *rmp;
896 vlib_combined_counter_main_t *cm;
899 u64 total_pkts[VLIB_N_RX_TX];
900 u64 total_bytes[VLIB_N_RX_TX];
902 unix_shared_memory_queue_t *q =
903 vl_api_client_index_to_input_queue (mp->client_index);
908 rmp = vl_msg_api_alloc (sizeof (*rmp));
909 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
910 rmp->context = mp->context;
913 memset (total_pkts, 0, sizeof (total_pkts));
914 memset (total_bytes, 0, sizeof (total_bytes));
916 vnet_interface_counter_lock (im);
918 vec_foreach (cm, im->combined_sw_if_counters)
920 which = cm - im->combined_sw_if_counters;
922 for (i = 0; i < vec_len (cm->maxi); i++)
924 vlib_get_combined_counter (cm, i, &v);
925 total_pkts[which] += v.packets;
926 total_bytes[which] += v.bytes;
929 vnet_interface_counter_unlock (im);
931 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
932 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
933 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
934 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
936 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
938 vl_msg_api_send_shmem (q, (u8 *) & rmp);
942 typedef CLIB_PACKED (struct {
943 ip4_address_t address;
944 u32 address_length: 6;
950 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
952 vnet_main_t *vnm = vnet_get_main ();
953 vnet_interface_main_t *im = &vnm->interface_main;
954 ip4_main_t *im4 = &ip4_main;
955 static u32 *sw_if_indices_to_shut;
956 stats_main_t *sm = &stats_main;
957 fib_table_t *fib_table;
961 int rv = VNET_API_ERROR_NO_SUCH_FIB;
962 u32 target_fib_id = ntohl (mp->vrf_id);
964 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
967 pool_foreach (fib_table, im4->fibs,
969 fib = &fib_table->v4;
970 vnet_sw_interface_t * si;
972 if (fib->table_id != target_fib_id)
975 /* remove any mpls encap/decap labels */
976 mpls_fib_reset_labels (fib->table_id);
978 /* remove any proxy arps in this fib */
979 vnet_proxy_arp_fib_reset (fib->table_id);
981 /* Set the flow hash for this fib to the default */
982 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
984 vec_reset_length (sw_if_indices_to_shut);
986 /* Shut down interfaces in this FIB / clean out intfc routes */
987 pool_foreach (si, im->sw_interfaces,
989 u32 sw_if_index = si->sw_if_index;
991 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
992 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
994 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
997 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
998 sw_if_index = sw_if_indices_to_shut[i];
999 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1001 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1002 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1003 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1006 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
1007 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
1011 })); /* pool_foreach (fib) */
1019 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1021 vnet_main_t *vnm = vnet_get_main ();
1022 vnet_interface_main_t *im = &vnm->interface_main;
1023 ip6_main_t *im6 = &ip6_main;
1024 stats_main_t *sm = &stats_main;
1025 static u32 *sw_if_indices_to_shut;
1026 fib_table_t *fib_table;
1030 int rv = VNET_API_ERROR_NO_SUCH_FIB;
1031 u32 target_fib_id = ntohl (mp->vrf_id);
1033 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
1036 pool_foreach (fib_table, im6->fibs,
1038 vnet_sw_interface_t * si;
1039 fib = &(fib_table->v6);
1041 if (fib->table_id != target_fib_id)
1044 vec_reset_length (sw_if_indices_to_shut);
1046 /* Shut down interfaces in this FIB / clean out intfc routes */
1047 pool_foreach (si, im->sw_interfaces,
1049 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
1051 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
1054 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
1055 sw_if_index = sw_if_indices_to_shut[i];
1056 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
1058 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
1059 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
1060 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
1063 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
1064 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
1068 })); /* pool_foreach (fib) */
1076 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
1079 vl_api_reset_fib_reply_t *rmp;
1082 rv = ip6_reset_fib_t_handler (mp);
1084 rv = ip4_reset_fib_t_handler (mp);
1086 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
1091 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1093 vl_api_dhcp_proxy_config_reply_t *rmp;
1096 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
1097 (ip4_address_t *) (&mp->dhcp_src_address),
1098 (u32) ntohl (mp->vrf_id),
1099 (int) mp->insert_circuit_id,
1100 (int) (mp->is_add == 0));
1102 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1107 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
1109 vl_api_dhcp_proxy_config_reply_t *rmp;
1112 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
1113 (ip6_address_t *) (&mp->dhcp_src_address),
1114 (u32) ntohl (mp->vrf_id),
1115 (int) mp->insert_circuit_id,
1116 (int) (mp->is_add == 0));
1118 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
1122 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1124 vl_api_dhcp_proxy_config_reply_t *rmp;
1127 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
1128 (ip4_address_t *) (&mp->dhcp_src_address),
1129 (u32) ntohl (mp->rx_vrf_id),
1130 (u32) ntohl (mp->server_vrf_id),
1131 (int) mp->insert_circuit_id,
1132 (int) (mp->is_add == 0));
1134 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1139 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
1141 vl_api_dhcp_proxy_config_reply_t *rmp;
1144 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
1145 (ip6_address_t *) (&mp->dhcp_src_address),
1146 (u32) ntohl (mp->rx_vrf_id),
1147 (u32) ntohl (mp->server_vrf_id),
1148 (int) mp->insert_circuit_id,
1149 (int) (mp->is_add == 0));
1151 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
1156 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
1158 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
1161 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
1164 (int) mp->is_add == 0);
1166 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
1168 ntohl (mp->fib_id), (int) mp->is_add == 0);
1170 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
1174 static void vl_api_dhcp_proxy_config_t_handler
1175 (vl_api_dhcp_proxy_config_t * mp)
1177 if (mp->is_ipv6 == 0)
1178 dhcpv4_proxy_config (mp);
1180 dhcpv6_proxy_config (mp);
1183 static void vl_api_dhcp_proxy_config_2_t_handler
1184 (vl_api_dhcp_proxy_config_2_t * mp)
1186 if (mp->is_ipv6 == 0)
1187 dhcpv4_proxy_config_2 (mp);
1189 dhcpv6_proxy_config_2 (mp);
1193 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
1194 u8 is_ipv6, u8 * host_address, u8 * router_address,
1197 unix_shared_memory_queue_t *q;
1198 vl_api_dhcp_compl_event_t *mp;
1200 q = vl_api_client_index_to_input_queue (client_index);
1204 mp = vl_msg_api_alloc (sizeof (*mp));
1205 mp->client_index = client_index;
1207 mp->is_ipv6 = is_ipv6;
1208 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
1209 mp->hostname[vec_len (hostname) + 1] = '\n';
1210 clib_memcpy (&mp->host_address[0], host_address, 16);
1211 clib_memcpy (&mp->router_address[0], router_address, 16);
1213 if (NULL != host_mac)
1214 clib_memcpy (&mp->host_mac[0], host_mac, 6);
1216 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
1218 vl_msg_api_send_shmem (q, (u8 *) & mp);
1221 static void vl_api_dhcp_client_config_t_handler
1222 (vl_api_dhcp_client_config_t * mp)
1224 vlib_main_t *vm = vlib_get_main ();
1225 vl_api_dhcp_client_config_reply_t *rmp;
1228 VALIDATE_SW_IF_INDEX (mp);
1230 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
1231 mp->hostname, mp->is_add, mp->client_index,
1232 mp->want_dhcp_event ? dhcp_compl_event_callback :
1235 BAD_SW_IF_INDEX_LABEL;
1237 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
1241 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
1243 vl_api_create_loopback_reply_t *rmp;
1247 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
1250 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1252 rmp->sw_if_index = ntohl (sw_if_index);
1258 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
1260 vl_api_delete_loopback_reply_t *rmp;
1264 sw_if_index = ntohl (mp->sw_if_index);
1265 rv = vnet_delete_loopback_interface (sw_if_index);
1267 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1271 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
1273 vl_api_control_ping_reply_t *rmp;
1277 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
1279 rmp->vpe_pid = ntohl (getpid());
1285 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1287 u8 **shmem_vecp = (u8 **) arg;
1290 api_main_t *am = &api_main;
1293 shmem_vec = *shmem_vecp;
1295 offset = vec_len (shmem_vec);
1297 pthread_mutex_lock (&am->vlib_rp->mutex);
1298 oldheap = svm_push_data_heap (am->vlib_rp);
1300 vec_validate (shmem_vec, offset + buffer_bytes - 1);
1302 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
1304 svm_pop_heap (oldheap);
1305 pthread_mutex_unlock (&am->vlib_rp->mutex);
1307 *shmem_vecp = shmem_vec;
1312 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
1314 vl_api_cli_reply_t *rp;
1315 unix_shared_memory_queue_t *q;
1316 vlib_main_t *vm = vlib_get_main ();
1317 api_main_t *am = &api_main;
1318 unformat_input_t input;
1322 q = vl_api_client_index_to_input_queue (mp->client_index);
1326 rp = vl_msg_api_alloc (sizeof (*rp));
1327 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
1328 rp->context = mp->context;
1330 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
1332 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
1334 pthread_mutex_lock (&am->vlib_rp->mutex);
1335 oldheap = svm_push_data_heap (am->vlib_rp);
1337 vec_add1 (shmem_vec, 0);
1339 svm_pop_heap (oldheap);
1340 pthread_mutex_unlock (&am->vlib_rp->mutex);
1342 rp->reply_in_shmem = (uword) shmem_vec;
1344 vl_msg_api_send_shmem (q, (u8 *) & rp);
1348 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
1350 u8 **mem_vecp = (u8 **) arg;
1351 u8 *mem_vec = *mem_vecp;
1352 u32 offset = vec_len (mem_vec);
1354 vec_validate (mem_vec, offset + buffer_bytes - 1);
1355 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
1356 *mem_vecp = mem_vec;
1360 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
1362 vl_api_cli_inband_reply_t *rmp;
1364 unix_shared_memory_queue_t *q;
1365 vlib_main_t *vm = vlib_get_main ();
1366 unformat_input_t input;
1369 q = vl_api_client_index_to_input_queue (mp->client_index);
1373 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
1374 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
1376 u32 len = vec_len (out_vec);
1378 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
1380 rmp->length = htonl (len);
1381 clib_memcpy (rmp->reply, out_vec, len);
1388 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
1391 vl_api_set_arp_neighbor_limit_reply_t *rmp;
1392 vnet_main_t *vnm = vnet_get_main ();
1393 clib_error_t *error;
1398 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
1400 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
1404 clib_error_report (error);
1405 rv = VNET_API_ERROR_UNSPECIFIED;
1409 rv = vnm->api_errno;
1412 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
1415 #define foreach_classify_add_del_table_field \
1420 _(match_n_vectors) \
1421 _(next_table_index) \
1422 _(miss_next_index) \
1423 _(current_data_flag) \
1424 _(current_data_offset)
1426 static void vl_api_classify_add_del_table_t_handler
1427 (vl_api_classify_add_del_table_t * mp)
1429 vl_api_classify_add_del_table_reply_t *rmp;
1430 vnet_classify_main_t *cm = &vnet_classify_main;
1431 vnet_classify_table_t *t;
1435 foreach_classify_add_del_table_field;
1438 #define _(a) a = ntohl(mp->a);
1439 foreach_classify_add_del_table_field;
1442 /* The underlying API fails silently, on purpose, so check here */
1443 if (mp->is_add == 0) /* delete */
1445 if (pool_is_free_index (cm->tables, table_index))
1447 rv = VNET_API_ERROR_NO_SUCH_TABLE;
1451 else /* add or update */
1453 if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
1457 rv = vnet_classify_add_del_table
1458 (cm, mp->mask, nbuckets, memory_size,
1459 skip_n_vectors, match_n_vectors,
1460 next_table_index, miss_next_index, &table_index,
1461 current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
1465 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
1467 if (rv == 0 && mp->is_add)
1469 t = pool_elt_at_index (cm->tables, table_index);
1470 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
1471 rmp->match_n_vectors = ntohl(t->match_n_vectors);
1472 rmp->new_table_index = ntohl(table_index);
1476 rmp->skip_n_vectors = ~0;
1477 rmp->match_n_vectors = ~0;
1478 rmp->new_table_index = ~0;
1484 static void vl_api_classify_add_del_session_t_handler
1485 (vl_api_classify_add_del_session_t * mp)
1487 vnet_classify_main_t *cm = &vnet_classify_main;
1488 vl_api_classify_add_del_session_reply_t *rmp;
1490 u32 table_index, hit_next_index, opaque_index, metadata;
1494 table_index = ntohl (mp->table_index);
1495 hit_next_index = ntohl (mp->hit_next_index);
1496 opaque_index = ntohl (mp->opaque_index);
1497 advance = ntohl (mp->advance);
1498 action = mp->action;
1499 metadata = ntohl (mp->metadata);
1501 rv = vnet_classify_add_del_session
1502 (cm, table_index, mp->match, hit_next_index, opaque_index,
1503 advance, action, metadata, mp->is_add);
1505 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
1508 static void vl_api_classify_set_interface_ip_table_t_handler
1509 (vl_api_classify_set_interface_ip_table_t * mp)
1511 vlib_main_t *vm = vlib_get_main ();
1512 vl_api_classify_set_interface_ip_table_reply_t *rmp;
1514 u32 table_index, sw_if_index;
1516 table_index = ntohl (mp->table_index);
1517 sw_if_index = ntohl (mp->sw_if_index);
1519 VALIDATE_SW_IF_INDEX (mp);
1522 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
1524 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
1526 BAD_SW_IF_INDEX_LABEL;
1528 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
1531 static void vl_api_classify_set_interface_l2_tables_t_handler
1532 (vl_api_classify_set_interface_l2_tables_t * mp)
1534 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
1536 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
1539 ip4_table_index = ntohl (mp->ip4_table_index);
1540 ip6_table_index = ntohl (mp->ip6_table_index);
1541 other_table_index = ntohl (mp->other_table_index);
1542 sw_if_index = ntohl (mp->sw_if_index);
1544 VALIDATE_SW_IF_INDEX (mp);
1547 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
1551 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
1557 if (ip4_table_index != ~0 || ip6_table_index != ~0
1558 || other_table_index != ~0)
1564 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
1566 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
1569 BAD_SW_IF_INDEX_LABEL;
1571 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
1574 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1575 u32 sw_if_index, u32 enable);
1578 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1582 vl_api_l2_interface_efp_filter_reply_t *rmp;
1583 vnet_main_t *vnm = vnet_get_main ();
1585 // enable/disable the feature
1586 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
1587 rv = vnm->api_errno;
1589 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1593 vl_api_l2_interface_vlan_tag_rewrite_t_handler
1594 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
1597 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
1598 vnet_main_t *vnm = vnet_get_main ();
1599 vlib_main_t *vm = vlib_get_main ();
1602 VALIDATE_SW_IF_INDEX (mp);
1604 vtr_op = ntohl (mp->vtr_op);
1606 /* The L2 code is unsuspicious */
1609 case L2_VTR_DISABLED:
1614 case L2_VTR_TRANSLATE_1_1:
1615 case L2_VTR_TRANSLATE_1_2:
1616 case L2_VTR_TRANSLATE_2_1:
1617 case L2_VTR_TRANSLATE_2_2:
1621 rv = VNET_API_ERROR_INVALID_VALUE;
1622 goto bad_sw_if_index;
1625 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
1626 ntohl (mp->push_dot1q), ntohl (mp->tag1),
1629 BAD_SW_IF_INDEX_LABEL;
1631 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
1635 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
1637 vl_api_show_version_reply_t *rmp;
1639 char *vpe_api_get_build_directory (void);
1640 char *vpe_api_get_version (void);
1641 char *vpe_api_get_build_date (void);
1643 unix_shared_memory_queue_t *q =
1644 vl_api_client_index_to_input_queue (mp->client_index);
1650 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
1652 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
1653 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
1654 ARRAY_LEN(rmp->build_directory)-1);
1655 strncpy ((char *) rmp->version, vpe_api_get_version(),
1656 ARRAY_LEN(rmp->version)-1);
1657 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
1658 ARRAY_LEN(rmp->build_date)-1);
1664 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
1666 vlib_main_t *vm = vlib_get_main ();
1667 vl_api_get_node_index_reply_t *rmp;
1670 u32 node_index = ~0;
1672 n = vlib_get_node_by_name (vm, mp->node_name);
1675 rv = VNET_API_ERROR_NO_SUCH_NODE;
1677 node_index = n->index;
1680 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1682 rmp->node_index = ntohl(node_index);
1688 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
1690 vlib_main_t *vm = vlib_get_main ();
1691 vl_api_get_next_index_reply_t *rmp;
1692 vlib_node_t *node, *next_node;
1694 u32 next_node_index = ~0, next_index = ~0;
1697 node = vlib_get_node_by_name (vm, mp->node_name);
1701 rv = VNET_API_ERROR_NO_SUCH_NODE;
1705 next_node = vlib_get_node_by_name (vm, mp->next_name);
1709 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1713 next_node_index = next_node->index;
1715 p = hash_get (node->next_slot_by_node, next_node_index);
1719 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1727 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
1729 rmp->next_index = ntohl(next_index);
1735 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
1737 vlib_main_t *vm = vlib_get_main ();
1738 vl_api_add_node_next_reply_t *rmp;
1739 vlib_node_t *n, *next;
1741 u32 next_index = ~0;
1743 n = vlib_get_node_by_name (vm, mp->node_name);
1747 rv = VNET_API_ERROR_NO_SUCH_NODE;
1751 next = vlib_get_node_by_name (vm, mp->next_name);
1754 rv = VNET_API_ERROR_NO_SUCH_NODE2;
1756 next_index = vlib_node_add_next (vm, n->index, next->index);
1760 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
1762 rmp->next_index = ntohl(next_index);
1767 static void vl_api_vxlan_add_del_tunnel_t_handler
1768 (vl_api_vxlan_add_del_tunnel_t * mp)
1770 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
1772 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
1773 u32 encap_fib_index;
1775 ip4_main_t *im = &ip4_main;
1776 vnet_main_t *vnm = vnet_get_main ();
1777 u32 sw_if_index = ~0;
1779 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1782 rv = VNET_API_ERROR_NO_SUCH_FIB;
1785 encap_fib_index = p[0];
1786 memset (a, 0, sizeof (*a));
1788 a->is_add = mp->is_add;
1789 a->is_ip6 = mp->is_ipv6;
1791 /* ip addresses sent in network byte order */
1792 ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
1793 ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
1795 /* Check src & dst are different */
1796 if (ip46_address_cmp (&a->dst, &a->src) == 0)
1798 rv = VNET_API_ERROR_SAME_SRC_DST;
1801 a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
1802 if (ip46_address_is_multicast (&a->dst) &&
1803 pool_is_free_index (vnm->interface_main.sw_interfaces,
1804 a->mcast_sw_if_index))
1806 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1809 a->encap_fib_index = encap_fib_index;
1810 a->decap_next_index = ntohl (mp->decap_next_index);
1811 a->vni = ntohl (mp->vni);
1812 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
1816 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
1818 rmp->sw_if_index = ntohl (sw_if_index);
1823 static void send_vxlan_tunnel_details
1824 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1826 vl_api_vxlan_tunnel_details_t *rmp;
1827 ip4_main_t *im4 = &ip4_main;
1828 ip6_main_t *im6 = &ip6_main;
1829 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
1831 rmp = vl_msg_api_alloc (sizeof (*rmp));
1832 memset (rmp, 0, sizeof (*rmp));
1833 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
1836 memcpy (rmp->src_address, t->src.ip6.as_u8, 16);
1837 memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16);
1838 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
1842 memcpy (rmp->src_address, t->src.ip4.as_u8, 4);
1843 memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4);
1844 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
1846 rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
1847 rmp->vni = htonl (t->vni);
1848 rmp->decap_next_index = htonl (t->decap_next_index);
1849 rmp->sw_if_index = htonl (t->sw_if_index);
1850 rmp->is_ipv6 = is_ipv6;
1851 rmp->context = context;
1853 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1856 static void vl_api_vxlan_tunnel_dump_t_handler
1857 (vl_api_vxlan_tunnel_dump_t * mp)
1859 unix_shared_memory_queue_t *q;
1860 vxlan_main_t *vxm = &vxlan_main;
1864 q = vl_api_client_index_to_input_queue (mp->client_index);
1870 sw_if_index = ntohl (mp->sw_if_index);
1872 if (~0 == sw_if_index)
1875 pool_foreach (t, vxm->tunnels,
1877 send_vxlan_tunnel_details(t, q, mp->context);
1883 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
1884 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
1888 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
1889 send_vxlan_tunnel_details (t, q, mp->context);
1894 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1896 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1898 vl_api_l2_patch_add_del_reply_t *rmp;
1899 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1903 VALIDATE_RX_SW_IF_INDEX (mp);
1904 VALIDATE_TX_SW_IF_INDEX (mp);
1906 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1907 ntohl (mp->tx_sw_if_index),
1908 (int) (mp->is_add != 0));
1910 BAD_RX_SW_IF_INDEX_LABEL;
1911 BAD_TX_SW_IF_INDEX_LABEL;
1913 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1917 vl_api_vxlan_gpe_add_del_tunnel_t_handler
1918 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
1920 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
1922 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
1923 u32 encap_fib_index, decap_fib_index;
1926 ip4_main_t *im = &ip4_main;
1927 u32 sw_if_index = ~0;
1930 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
1933 rv = VNET_API_ERROR_NO_SUCH_FIB;
1936 encap_fib_index = p[0];
1938 protocol = mp->protocol;
1940 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
1941 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
1943 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
1946 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
1949 decap_fib_index = p[0];
1953 decap_fib_index = ntohl (mp->decap_vrf_id);
1956 /* Check src & dst are different */
1957 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
1958 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
1960 rv = VNET_API_ERROR_SAME_SRC_DST;
1963 memset (a, 0, sizeof (*a));
1965 a->is_add = mp->is_add;
1966 a->is_ip6 = mp->is_ipv6;
1967 /* ip addresses sent in network byte order */
1970 clib_memcpy (&(a->local.ip6), mp->local, 16);
1971 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
1975 clib_memcpy (&(a->local.ip4), mp->local, 4);
1976 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
1978 a->encap_fib_index = encap_fib_index;
1979 a->decap_fib_index = decap_fib_index;
1980 a->protocol = protocol;
1981 a->vni = ntohl (mp->vni);
1982 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
1986 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
1988 rmp->sw_if_index = ntohl (sw_if_index);
1993 static void send_vxlan_gpe_tunnel_details
1994 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
1996 vl_api_vxlan_gpe_tunnel_details_t *rmp;
1997 ip4_main_t *im4 = &ip4_main;
1998 ip6_main_t *im6 = &ip6_main;
1999 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
2001 rmp = vl_msg_api_alloc (sizeof (*rmp));
2002 memset (rmp, 0, sizeof (*rmp));
2003 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
2006 memcpy (rmp->local, &(t->local.ip6), 16);
2007 memcpy (rmp->remote, &(t->remote.ip6), 16);
2008 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
2009 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
2013 memcpy (rmp->local, &(t->local.ip4), 4);
2014 memcpy (rmp->remote, &(t->remote.ip4), 4);
2015 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
2016 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
2018 rmp->vni = htonl (t->vni);
2019 rmp->protocol = t->protocol;
2020 rmp->sw_if_index = htonl (t->sw_if_index);
2021 rmp->is_ipv6 = is_ipv6;
2022 rmp->context = context;
2024 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2027 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
2028 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
2030 unix_shared_memory_queue_t *q;
2031 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
2032 vxlan_gpe_tunnel_t *t;
2035 q = vl_api_client_index_to_input_queue (mp->client_index);
2041 sw_if_index = ntohl (mp->sw_if_index);
2043 if (~0 == sw_if_index)
2046 pool_foreach (t, vgm->tunnels,
2048 send_vxlan_gpe_tunnel_details(t, q, mp->context);
2054 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
2055 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
2059 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
2060 send_vxlan_gpe_tunnel_details (t, q, mp->context);
2065 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
2068 vl_api_interface_name_renumber_reply_t *rmp;
2071 VALIDATE_SW_IF_INDEX (mp);
2073 rv = vnet_interface_name_renumber
2074 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
2076 BAD_SW_IF_INDEX_LABEL;
2078 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
2082 arp_change_data_callback (u32 pool_index, u8 * new_mac,
2083 u32 sw_if_index, u32 address)
2085 vpe_api_main_t *am = &vpe_api_main;
2086 vlib_main_t *vm = am->vlib_main;
2087 vl_api_ip4_arp_event_t *event;
2088 static f64 arp_event_last_time;
2089 f64 now = vlib_time_now (vm);
2091 if (pool_is_free_index (am->arp_events, pool_index))
2094 event = pool_elt_at_index (am->arp_events, pool_index);
2096 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
2098 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
2102 if (sw_if_index == event->sw_if_index &&
2104 /* for BD case, also check IP address with 10 sec timeout */
2105 (address == event->address &&
2106 (now - arp_event_last_time) < 10.0)))
2111 arp_event_last_time = now;
2112 event->sw_if_index = sw_if_index;
2114 event->address = address;
2119 nd_change_data_callback (u32 pool_index, u8 * new_mac,
2120 u32 sw_if_index, ip6_address_t * address)
2122 vpe_api_main_t *am = &vpe_api_main;
2123 vlib_main_t *vm = am->vlib_main;
2124 vl_api_ip6_nd_event_t *event;
2125 static f64 nd_event_last_time;
2126 f64 now = vlib_time_now (vm);
2128 if (pool_is_free_index (am->nd_events, pool_index))
2131 event = pool_elt_at_index (am->nd_events, pool_index);
2134 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
2136 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
2140 if (sw_if_index == event->sw_if_index &&
2142 /* for BD case, also check IP address with 10 sec timeout */
2143 (ip6_address_is_equal (address,
2144 (ip6_address_t *) event->address) &&
2145 (now - nd_event_last_time) < 10.0)))
2150 nd_event_last_time = now;
2151 event->sw_if_index = sw_if_index;
2153 clib_memcpy (event->address, address, sizeof (event->address));
2158 arp_change_delete_callback (u32 pool_index, u8 * notused)
2160 vpe_api_main_t *am = &vpe_api_main;
2162 if (pool_is_free_index (am->arp_events, pool_index))
2165 pool_put_index (am->arp_events, pool_index);
2170 nd_change_delete_callback (u32 pool_index, u8 * notused)
2172 vpe_api_main_t *am = &vpe_api_main;
2174 if (pool_is_free_index (am->nd_events, pool_index))
2177 pool_put_index (am->nd_events, pool_index);
2182 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
2184 vpe_api_main_t *am = &vpe_api_main;
2185 vnet_main_t *vnm = vnet_get_main ();
2186 vl_api_want_ip4_arp_events_reply_t *rmp;
2187 vl_api_ip4_arp_event_t *event;
2190 if (mp->enable_disable)
2192 pool_get (am->arp_events, event);
2193 memset (event, 0, sizeof (*event));
2195 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
2196 event->client_index = mp->client_index;
2197 event->context = mp->context;
2198 event->address = mp->address;
2199 event->pid = mp->pid;
2200 if (mp->address == 0)
2203 rv = vnet_add_del_ip4_arp_change_event
2204 (vnm, arp_change_data_callback,
2205 mp->pid, &mp->address /* addr, in net byte order */ ,
2206 vpe_resolver_process_node.index,
2207 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
2211 rv = vnet_add_del_ip4_arp_change_event
2212 (vnm, arp_change_delete_callback,
2213 mp->pid, &mp->address /* addr, in net byte order */ ,
2214 vpe_resolver_process_node.index,
2215 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
2217 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
2221 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
2223 vpe_api_main_t *am = &vpe_api_main;
2224 vnet_main_t *vnm = vnet_get_main ();
2225 vl_api_want_ip6_nd_events_reply_t *rmp;
2226 vl_api_ip6_nd_event_t *event;
2229 if (mp->enable_disable)
2231 pool_get (am->nd_events, event);
2232 memset (event, 0, sizeof (*event));
2234 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
2235 event->client_index = mp->client_index;
2236 event->context = mp->context;
2237 clib_memcpy (event->address, mp->address, 16);
2238 event->pid = mp->pid;
2239 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
2242 rv = vnet_add_del_ip6_nd_change_event
2243 (vnm, nd_change_data_callback,
2244 mp->pid, mp->address /* addr, in net byte order */ ,
2245 vpe_resolver_process_node.index,
2246 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
2250 rv = vnet_add_del_ip6_nd_change_event
2251 (vnm, nd_change_delete_callback,
2252 mp->pid, mp->address /* addr, in net byte order */ ,
2253 vpe_resolver_process_node.index,
2254 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
2256 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
2259 static void vl_api_input_acl_set_interface_t_handler
2260 (vl_api_input_acl_set_interface_t * mp)
2262 vlib_main_t *vm = vlib_get_main ();
2263 vl_api_input_acl_set_interface_reply_t *rmp;
2265 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
2267 ip4_table_index = ntohl (mp->ip4_table_index);
2268 ip6_table_index = ntohl (mp->ip6_table_index);
2269 l2_table_index = ntohl (mp->l2_table_index);
2270 sw_if_index = ntohl (mp->sw_if_index);
2272 VALIDATE_SW_IF_INDEX (mp);
2274 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
2275 ip6_table_index, l2_table_index, mp->is_add);
2277 BAD_SW_IF_INDEX_LABEL;
2279 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
2282 static void vl_api_cop_interface_enable_disable_t_handler
2283 (vl_api_cop_interface_enable_disable_t * mp)
2285 vl_api_cop_interface_enable_disable_reply_t *rmp;
2287 u32 sw_if_index = ntohl (mp->sw_if_index);
2290 VALIDATE_SW_IF_INDEX (mp);
2292 enable_disable = (int) mp->enable_disable;
2294 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
2296 BAD_SW_IF_INDEX_LABEL;
2298 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
2301 static void vl_api_cop_whitelist_enable_disable_t_handler
2302 (vl_api_cop_whitelist_enable_disable_t * mp)
2304 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
2305 cop_whitelist_enable_disable_args_t _a, *a = &_a;
2306 u32 sw_if_index = ntohl (mp->sw_if_index);
2309 VALIDATE_SW_IF_INDEX (mp);
2311 a->sw_if_index = sw_if_index;
2314 a->default_cop = mp->default_cop;
2315 a->fib_id = ntohl (mp->fib_id);
2317 rv = cop_whitelist_enable_disable (a);
2319 BAD_SW_IF_INDEX_LABEL;
2321 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
2325 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
2329 api_main_t *am = &api_main;
2330 vlib_main_t *vm = vlib_get_main ();
2332 vl_api_get_node_graph_reply_t *rmp;
2334 pthread_mutex_lock (&am->vlib_rp->mutex);
2335 oldheap = svm_push_data_heap (am->vlib_rp);
2338 * Keep the number of memcpy ops to a minimum (e.g. 1).
2340 vec_validate (vector, 16384);
2341 vec_reset_length (vector);
2344 vector = vlib_node_serialize (&vm->node_main, vector,
2345 (u32) ~ 0 /* all threads */ ,
2346 1 /* include nexts */ ,
2347 1 /* include stats */ );
2349 svm_pop_heap (oldheap);
2350 pthread_mutex_unlock (&am->vlib_rp->mutex);
2353 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
2355 rmp->reply_in_shmem = (uword) vector;
2361 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
2364 vl_api_ioam_enable_reply_t *rmp;
2365 clib_error_t *error;
2367 /* Ignoring the profile id as currently a single profile
2369 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
2370 mp->seqno, mp->analyse);
2373 clib_error_report (error);
2374 rv = clib_error_get_code (error);
2377 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
2381 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
2384 vl_api_ioam_disable_reply_t *rmp;
2385 clib_error_t *error;
2387 error = clear_ioam_rewrite_fn ();
2390 clib_error_report (error);
2391 rv = clib_error_get_code (error);
2394 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
2398 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
2400 vlib_main_t *vm = vlib_get_main ();
2401 vl_api_policer_add_del_reply_t *rmp;
2404 sse2_qos_pol_cfg_params_st cfg;
2405 clib_error_t *error;
2408 name = format (0, "%s", mp->name);
2410 memset (&cfg, 0, sizeof (cfg));
2412 cfg.rnd_type = mp->round_type;
2413 cfg.rate_type = mp->rate_type;
2414 cfg.rb.kbps.cir_kbps = mp->cir;
2415 cfg.rb.kbps.eir_kbps = mp->eir;
2416 cfg.rb.kbps.cb_bytes = mp->cb;
2417 cfg.rb.kbps.eb_bytes = mp->eb;
2418 cfg.conform_action.action_type = mp->conform_action_type;
2419 cfg.conform_action.dscp = mp->conform_dscp;
2420 cfg.exceed_action.action_type = mp->exceed_action_type;
2421 cfg.exceed_action.dscp = mp->exceed_dscp;
2422 cfg.violate_action.action_type = mp->violate_action_type;
2423 cfg.violate_action.dscp = mp->violate_dscp;
2424 cfg.color_aware = mp->color_aware;
2426 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
2429 rv = VNET_API_ERROR_UNSPECIFIED;
2432 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
2434 if (rv == 0 && mp->is_add)
2435 rmp->policer_index = ntohl(policer_index);
2437 rmp->policer_index = ~0;
2443 send_policer_details (u8 * name,
2444 sse2_qos_pol_cfg_params_st * config,
2445 policer_read_response_type_st * templ,
2446 unix_shared_memory_queue_t * q, u32 context)
2448 vl_api_policer_details_t *mp;
2450 mp = vl_msg_api_alloc (sizeof (*mp));
2451 memset (mp, 0, sizeof (*mp));
2452 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
2453 mp->context = context;
2454 mp->cir = htonl (config->rb.kbps.cir_kbps);
2455 mp->eir = htonl (config->rb.kbps.eir_kbps);
2456 mp->cb = htonl (config->rb.kbps.cb_bytes);
2457 mp->eb = htonl (config->rb.kbps.eb_bytes);
2458 mp->rate_type = config->rate_type;
2459 mp->round_type = config->rnd_type;
2460 mp->type = config->rfc;
2461 mp->conform_action_type = config->conform_action.action_type;
2462 mp->conform_dscp = config->conform_action.dscp;
2463 mp->exceed_action_type = config->exceed_action.action_type;
2464 mp->exceed_dscp = config->exceed_action.dscp;
2465 mp->violate_action_type = config->violate_action.action_type;
2466 mp->violate_dscp = config->violate_action.dscp;
2467 mp->single_rate = templ->single_rate ? 1 : 0;
2468 mp->color_aware = templ->color_aware ? 1 : 0;
2469 mp->scale = htonl (templ->scale);
2470 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
2471 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
2472 mp->current_limit = htonl (templ->current_limit);
2473 mp->current_bucket = htonl (templ->current_bucket);
2474 mp->extended_limit = htonl (templ->extended_limit);
2475 mp->extended_bucket = htonl (templ->extended_bucket);
2476 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
2478 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
2480 vl_msg_api_send_shmem (q, (u8 *) & mp);
2484 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
2486 unix_shared_memory_queue_t *q;
2487 vnet_policer_main_t *pm = &vnet_policer_main;
2493 sse2_qos_pol_cfg_params_st *config;
2494 policer_read_response_type_st *templ;
2496 q = vl_api_client_index_to_input_queue (mp->client_index);
2500 if (mp->match_name_valid)
2502 match_name = format (0, "%s%c", mp->match_name, 0);
2505 if (mp->match_name_valid)
2507 p = hash_get_mem (pm->policer_config_by_name, match_name);
2511 config = pool_elt_at_index (pm->configs, pool_index);
2512 templ = pool_elt_at_index (pm->policer_templates, pool_index);
2513 send_policer_details (match_name, config, templ, q, mp->context);
2519 hash_foreach_pair (hp, pm->policer_config_by_name,
2521 name = (u8 *) hp->key;
2522 pool_index = hp->value[0];
2523 config = pool_elt_at_index (pm->configs, pool_index);
2524 templ = pool_elt_at_index (pm->policer_templates, pool_index);
2525 send_policer_details(name, config, templ, q, mp->context);
2532 vl_api_policer_classify_set_interface_t_handler
2533 (vl_api_policer_classify_set_interface_t * mp)
2535 vlib_main_t *vm = vlib_get_main ();
2536 vl_api_policer_classify_set_interface_reply_t *rmp;
2538 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
2540 ip4_table_index = ntohl (mp->ip4_table_index);
2541 ip6_table_index = ntohl (mp->ip6_table_index);
2542 l2_table_index = ntohl (mp->l2_table_index);
2543 sw_if_index = ntohl (mp->sw_if_index);
2545 VALIDATE_SW_IF_INDEX (mp);
2547 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
2548 ip6_table_index, l2_table_index,
2551 BAD_SW_IF_INDEX_LABEL;
2553 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
2557 send_policer_classify_details (u32 sw_if_index,
2559 unix_shared_memory_queue_t * q, u32 context)
2561 vl_api_policer_classify_details_t *mp;
2563 mp = vl_msg_api_alloc (sizeof (*mp));
2564 memset (mp, 0, sizeof (*mp));
2565 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
2566 mp->context = context;
2567 mp->sw_if_index = htonl (sw_if_index);
2568 mp->table_index = htonl (table_index);
2570 vl_msg_api_send_shmem (q, (u8 *) & mp);
2574 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
2576 unix_shared_memory_queue_t *q;
2577 policer_classify_main_t *pcm = &policer_classify_main;
2581 q = vl_api_client_index_to_input_queue (mp->client_index);
2585 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
2587 if (vec_len (vec_tbl))
2589 for (i = 0; i < vec_len (vec_tbl); i++)
2591 if (vec_elt (vec_tbl, i) == ~0)
2594 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
2601 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
2603 unix_shared_memory_queue_t *q;
2605 q = vl_api_client_index_to_input_queue (mp->client_index);
2609 vnet_classify_main_t *cm = &vnet_classify_main;
2610 vnet_classify_table_t *t;
2615 pool_foreach (t, cm->tables,
2617 vec_add1 (table_ids, ntohl(t - cm->tables));
2620 count = vec_len (table_ids);
2622 vl_api_classify_table_ids_reply_t *rmp;
2623 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
2624 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
2625 rmp->context = mp->context;
2626 rmp->count = ntohl (count);
2627 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
2630 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2632 vec_free (table_ids);
2636 vl_api_classify_table_by_interface_t_handler
2637 (vl_api_classify_table_by_interface_t * mp)
2639 vl_api_classify_table_by_interface_reply_t *rmp;
2642 u32 sw_if_index = ntohl (mp->sw_if_index);
2645 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
2648 VALIDATE_SW_IF_INDEX (mp);
2650 input_acl_main_t *am = &input_acl_main;
2655 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
2657 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
2658 if (vec_len (vec_tbl))
2660 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
2662 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
2666 acl[type] = vec_elt (vec_tbl, if_idx);
2671 BAD_SW_IF_INDEX_LABEL;
2674 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
2676 rmp->sw_if_index = ntohl(sw_if_index);
2677 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
2678 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
2679 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
2686 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
2688 unix_shared_memory_queue_t *q;
2690 q = vl_api_client_index_to_input_queue (mp->client_index);
2694 vl_api_classify_table_info_reply_t *rmp = 0;
2696 vnet_classify_main_t *cm = &vnet_classify_main;
2697 u32 table_id = ntohl (mp->table_id);
2698 vnet_classify_table_t *t;
2701 pool_foreach (t, cm->tables,
2703 if (table_id == t - cm->tables)
2705 rmp = vl_msg_api_alloc_as_if_client
2706 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
2707 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
2708 rmp->context = mp->context;
2709 rmp->table_id = ntohl(table_id);
2710 rmp->nbuckets = ntohl(t->nbuckets);
2711 rmp->match_n_vectors = ntohl(t->match_n_vectors);
2712 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
2713 rmp->active_sessions = ntohl(t->active_elements);
2714 rmp->next_table_index = ntohl(t->next_table_index);
2715 rmp->miss_next_index = ntohl(t->miss_next_index);
2716 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
2717 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
2726 rmp = vl_msg_api_alloc (sizeof (*rmp));
2727 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
2728 rmp->context = mp->context;
2729 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
2732 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2736 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
2739 clib_warning ("BUG");
2743 send_classify_session_details (unix_shared_memory_queue_t * q,
2746 vnet_classify_entry_t * e, u32 context)
2748 vl_api_classify_session_details_t *rmp;
2750 rmp = vl_msg_api_alloc (sizeof (*rmp));
2751 memset (rmp, 0, sizeof (*rmp));
2752 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
2753 rmp->context = context;
2754 rmp->table_id = ntohl (table_id);
2755 rmp->hit_next_index = ntohl (e->next_index);
2756 rmp->advance = ntohl (e->advance);
2757 rmp->opaque_index = ntohl (e->opaque_index);
2758 rmp->match_length = ntohl (match_length);
2759 clib_memcpy (rmp->match, e->key, match_length);
2761 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2765 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
2767 vnet_classify_main_t *cm = &vnet_classify_main;
2768 unix_shared_memory_queue_t *q;
2770 u32 table_id = ntohl (mp->table_id);
2771 vnet_classify_table_t *t;
2773 q = vl_api_client_index_to_input_queue (mp->client_index);
2778 pool_foreach (t, cm->tables,
2780 if (table_id == t - cm->tables)
2782 vnet_classify_bucket_t * b;
2783 vnet_classify_entry_t * v, * save_v;
2786 for (i = 0; i < t->nbuckets; i++)
2788 b = &t->buckets [i];
2792 save_v = vnet_classify_get_entry (t, b->offset);
2793 for (j = 0; j < (1<<b->log2_pages); j++)
2795 for (k = 0; k < t->entries_per_page; k++)
2797 v = vnet_classify_entry_at_index
2798 (t, save_v, j*t->entries_per_page + k);
2799 if (vnet_classify_entry_is_free (v))
2802 send_classify_session_details
2803 (q, table_id, t->match_n_vectors * sizeof (u32x4),
2815 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
2817 vlib_main_t *vm = vlib_get_main ();
2818 flow_report_main_t *frm = &flow_report_main;
2819 vl_api_set_ipfix_exporter_reply_t *rmp;
2820 ip4_address_t collector, src;
2821 u16 collector_port = UDP_DST_PORT_ipfix;
2823 u32 template_interval;
2829 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
2830 collector_port = ntohs (mp->collector_port);
2831 if (collector_port == (u16) ~ 0)
2832 collector_port = UDP_DST_PORT_ipfix;
2833 memcpy (src.data, mp->src_address, sizeof (src.data));
2834 fib_id = ntohl (mp->vrf_id);
2836 ip4_main_t *im = &ip4_main;
2843 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
2846 rv = VNET_API_ERROR_NO_SUCH_FIB;
2852 path_mtu = ntohl (mp->path_mtu);
2854 path_mtu = 512; // RFC 7011 section 10.3.3.
2855 template_interval = ntohl (mp->template_interval);
2856 if (template_interval == ~0)
2857 template_interval = 20;
2858 udp_checksum = mp->udp_checksum;
2860 if (collector.as_u32 == 0)
2862 rv = VNET_API_ERROR_INVALID_VALUE;
2866 if (src.as_u32 == 0)
2868 rv = VNET_API_ERROR_INVALID_VALUE;
2872 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
2874 rv = VNET_API_ERROR_INVALID_VALUE;
2880 rv = VNET_API_ERROR_INVALID_VALUE;
2884 /* Reset report streams if we are reconfiguring IP addresses */
2885 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
2886 frm->src_address.as_u32 != src.as_u32 ||
2887 frm->collector_port != collector_port)
2888 vnet_flow_reports_reset (frm);
2890 frm->ipfix_collector.as_u32 = collector.as_u32;
2891 frm->collector_port = collector_port;
2892 frm->src_address.as_u32 = src.as_u32;
2893 frm->fib_index = fib_index;
2894 frm->path_mtu = path_mtu;
2895 frm->template_interval = template_interval;
2896 frm->udp_checksum = udp_checksum;
2898 /* Turn on the flow reporting process */
2899 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
2902 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
2906 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
2908 flow_report_main_t *frm = &flow_report_main;
2909 unix_shared_memory_queue_t *q;
2910 vl_api_ipfix_exporter_details_t *rmp;
2911 ip4_main_t *im = &ip4_main;
2914 q = vl_api_client_index_to_input_queue (mp->client_index);
2918 rmp = vl_msg_api_alloc (sizeof (*rmp));
2919 memset (rmp, 0, sizeof (*rmp));
2920 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
2921 rmp->context = mp->context;
2922 memcpy (rmp->collector_address, frm->ipfix_collector.data,
2923 sizeof (frm->ipfix_collector.data));
2924 rmp->collector_port = htons (frm->collector_port);
2925 memcpy (rmp->src_address, frm->src_address.data,
2926 sizeof (frm->src_address.data));
2927 if (frm->fib_index == ~0)
2930 vrf_id = im->fibs[frm->fib_index].ft_table_id;
2931 rmp->vrf_id = htonl (vrf_id);
2932 rmp->path_mtu = htonl (frm->path_mtu);
2933 rmp->template_interval = htonl (frm->template_interval);
2934 rmp->udp_checksum = (frm->udp_checksum != 0);
2936 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2940 vl_api_set_ipfix_classify_stream_t_handler
2941 (vl_api_set_ipfix_classify_stream_t * mp)
2943 vl_api_set_ipfix_classify_stream_reply_t *rmp;
2944 flow_report_classify_main_t *fcm = &flow_report_classify_main;
2945 flow_report_main_t *frm = &flow_report_main;
2947 u32 src_port = UDP_DST_PORT_ipfix;
2950 domain_id = ntohl (mp->domain_id);
2951 src_port = ntohs (mp->src_port);
2953 if (fcm->src_port != 0 &&
2954 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
2956 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
2957 domain_id, (u16) src_port);
2961 fcm->domain_id = domain_id;
2962 fcm->src_port = (u16) src_port;
2964 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
2968 vl_api_ipfix_classify_stream_dump_t_handler
2969 (vl_api_ipfix_classify_stream_dump_t * mp)
2971 flow_report_classify_main_t *fcm = &flow_report_classify_main;
2972 unix_shared_memory_queue_t *q;
2973 vl_api_ipfix_classify_stream_details_t *rmp;
2975 q = vl_api_client_index_to_input_queue (mp->client_index);
2979 rmp = vl_msg_api_alloc (sizeof (*rmp));
2980 memset (rmp, 0, sizeof (*rmp));
2981 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
2982 rmp->context = mp->context;
2983 rmp->domain_id = htonl (fcm->domain_id);
2984 rmp->src_port = htons (fcm->src_port);
2986 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2990 vl_api_ipfix_classify_table_add_del_t_handler
2991 (vl_api_ipfix_classify_table_add_del_t * mp)
2993 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
2994 flow_report_classify_main_t *fcm = &flow_report_classify_main;
2995 flow_report_main_t *frm = &flow_report_main;
2996 vnet_flow_report_add_del_args_t args;
2997 ipfix_classify_table_t *table;
2999 u32 classify_table_index;
3001 u8 transport_protocol;
3004 classify_table_index = ntohl (mp->table_id);
3005 ip_version = mp->ip_version;
3006 transport_protocol = mp->transport_protocol;
3007 is_add = mp->is_add;
3009 if (fcm->src_port == 0)
3011 /* call set_ipfix_classify_stream first */
3012 rv = VNET_API_ERROR_UNSPECIFIED;
3016 memset (&args, 0, sizeof (args));
3020 for (i = 0; i < vec_len (fcm->tables); i++)
3021 if (ipfix_classify_table_index_valid (i))
3022 if (fcm->tables[i].classify_table_index == classify_table_index)
3024 table = &fcm->tables[i];
3032 rv = VNET_API_ERROR_VALUE_EXIST;
3035 table = ipfix_classify_add_table ();
3036 table->classify_table_index = classify_table_index;
3042 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
3047 table->ip_version = ip_version;
3048 table->transport_protocol = transport_protocol;
3050 args.opaque.as_uword = table - fcm->tables;
3051 args.rewrite_callback = ipfix_classify_template_rewrite;
3052 args.flow_data_callback = ipfix_classify_send_flows;
3053 args.is_add = is_add;
3054 args.domain_id = fcm->domain_id;
3055 args.src_port = fcm->src_port;
3057 rv = vnet_flow_report_add_del (frm, &args);
3059 /* If deleting, or add failed */
3060 if (is_add == 0 || (rv && is_add))
3061 ipfix_classify_delete_table (table - fcm->tables);
3064 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
3068 send_ipfix_classify_table_details (u32 table_index,
3069 unix_shared_memory_queue_t * q,
3072 flow_report_classify_main_t *fcm = &flow_report_classify_main;
3073 vl_api_ipfix_classify_table_details_t *mp;
3075 ipfix_classify_table_t *table = &fcm->tables[table_index];
3077 mp = vl_msg_api_alloc (sizeof (*mp));
3078 memset (mp, 0, sizeof (*mp));
3079 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
3080 mp->context = context;
3081 mp->table_id = htonl (table->classify_table_index);
3082 mp->ip_version = table->ip_version;
3083 mp->transport_protocol = table->transport_protocol;
3085 vl_msg_api_send_shmem (q, (u8 *) & mp);
3089 vl_api_ipfix_classify_table_dump_t_handler
3090 (vl_api_ipfix_classify_table_dump_t * mp)
3092 flow_report_classify_main_t *fcm = &flow_report_classify_main;
3093 unix_shared_memory_queue_t *q;
3096 q = vl_api_client_index_to_input_queue (mp->client_index);
3100 for (i = 0; i < vec_len (fcm->tables); i++)
3101 if (ipfix_classify_table_index_valid (i))
3102 send_ipfix_classify_table_details (i, q, mp->context);
3106 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
3108 vl_api_pg_create_interface_reply_t *rmp;
3111 pg_main_t *pg = &pg_main;
3112 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
3113 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
3116 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
3118 rmp->sw_if_index = ntohl(pi->sw_if_index);
3124 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
3126 vl_api_pg_capture_reply_t *rmp;
3129 vnet_main_t *vnm = vnet_get_main ();
3130 vnet_interface_main_t *im = &vnm->interface_main;
3131 vnet_hw_interface_t *hi = 0;
3133 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
3134 u32 hw_if_index = ~0;
3135 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
3138 vec_free (intf_name);
3140 if (hw_if_index != ~0)
3142 pg_capture_args_t _a, *a = &_a;
3144 u32 len = ntohl (mp->pcap_name_length);
3145 u8 *pcap_file_name = vec_new (u8, len);
3146 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
3148 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
3149 a->hw_if_index = hw_if_index;
3150 a->dev_instance = hi->dev_instance;
3151 a->is_enabled = mp->is_enabled;
3152 a->pcap_file_name = pcap_file_name;
3153 a->count = ntohl (mp->count);
3155 clib_error_t *e = pg_capture (a);
3158 clib_error_report (e);
3159 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
3162 vec_free (pcap_file_name);
3164 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
3168 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
3170 vl_api_pg_enable_disable_reply_t *rmp;
3173 pg_main_t *pg = &pg_main;
3174 u32 stream_index = ~0;
3176 int is_enable = mp->is_enabled != 0;
3177 u32 len = ntohl (mp->stream_name_length) - 1;
3181 u8 *stream_name = vec_new (u8, len);
3182 clib_memcpy (stream_name, mp->stream_name, len);
3183 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
3186 vec_free (stream_name);
3189 pg_enable_disable (stream_index, is_enable);
3191 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
3195 vl_api_ip_source_and_port_range_check_add_del_t_handler
3196 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
3198 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
3201 u8 is_ipv6 = mp->is_ipv6;
3202 u8 is_add = mp->is_add;
3203 u8 mask_length = mp->mask_length;
3204 ip4_address_t ip4_addr;
3205 ip6_address_t ip6_addr;
3207 u16 *high_ports = 0;
3209 u16 tmp_low, tmp_high;
3213 // Validate port range
3214 num_ranges = mp->number_of_ranges;
3215 if (num_ranges > 32)
3216 { // This is size of array in VPE.API
3217 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
3221 vec_reset_length (low_ports);
3222 vec_reset_length (high_ports);
3224 for (i = 0; i < num_ranges; i++)
3226 tmp_low = mp->low_ports[i];
3227 tmp_high = mp->high_ports[i];
3228 // If tmp_low <= tmp_high then only need to check tmp_low = 0
3229 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
3230 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
3232 rv = VNET_API_ERROR_INVALID_VALUE;
3235 vec_add1 (low_ports, tmp_low);
3236 vec_add1 (high_ports, tmp_high + 1);
3239 // Validate mask_length
3240 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
3242 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
3246 vrf_id = ntohl (mp->vrf_id);
3250 rv = VNET_API_ERROR_INVALID_VALUE;
3257 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
3258 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
3262 high_ports, is_add);
3266 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
3267 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
3271 high_ports, is_add);
3275 vec_free (low_ports);
3276 vec_free (high_ports);
3277 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
3281 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
3282 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
3284 vlib_main_t *vm = vlib_get_main ();
3285 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
3286 ip4_main_t *im = &ip4_main;
3289 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
3290 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
3294 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
3295 ntohl (mp->tcp_out_vrf_id);
3296 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
3297 ntohl (mp->udp_out_vrf_id);
3298 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
3299 ntohl (mp->tcp_in_vrf_id);
3300 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
3301 ntohl (mp->udp_in_vrf_id);
3304 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
3306 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
3308 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
3312 rv = VNET_API_ERROR_INVALID_VALUE;
3316 fib_index[i] = p[0];
3321 sw_if_index = ntohl (mp->sw_if_index);
3323 VALIDATE_SW_IF_INDEX (mp);
3326 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
3329 BAD_SW_IF_INDEX_LABEL;
3332 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
3336 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
3338 vl_api_delete_subif_reply_t *rmp;
3341 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
3343 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
3347 vl_api_l2_interface_pbb_tag_rewrite_t_handler
3348 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
3350 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
3351 vnet_main_t *vnm = vnet_get_main ();
3352 vlib_main_t *vm = vlib_get_main ();
3356 VALIDATE_SW_IF_INDEX (mp);
3358 vtr_op = ntohl (mp->vtr_op);
3362 case L2_VTR_DISABLED:
3365 case L2_VTR_TRANSLATE_2_1:
3369 rv = VNET_API_ERROR_INVALID_VALUE;
3370 goto bad_sw_if_index;
3373 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
3374 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
3375 ntohl (mp->i_sid), ntohs (mp->outer_tag));
3377 BAD_SW_IF_INDEX_LABEL;
3379 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
3384 vl_api_punt_t_handler (vl_api_punt_t * mp)
3386 vl_api_punt_reply_t *rmp;
3387 vlib_main_t *vm = vlib_get_main ();
3389 clib_error_t *error;
3391 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
3392 ntohs (mp->l4_port), mp->is_add);
3396 clib_error_report (error);
3399 REPLY_MACRO (VL_API_PUNT_REPLY);
3403 vl_api_flow_classify_set_interface_t_handler
3404 (vl_api_flow_classify_set_interface_t * mp)
3406 vlib_main_t *vm = vlib_get_main ();
3407 vl_api_flow_classify_set_interface_reply_t *rmp;
3409 u32 sw_if_index, ip4_table_index, ip6_table_index;
3411 ip4_table_index = ntohl (mp->ip4_table_index);
3412 ip6_table_index = ntohl (mp->ip6_table_index);
3413 sw_if_index = ntohl (mp->sw_if_index);
3415 VALIDATE_SW_IF_INDEX (mp);
3417 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
3418 ip6_table_index, mp->is_add);
3420 BAD_SW_IF_INDEX_LABEL;
3422 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
3426 send_flow_classify_details (u32 sw_if_index,
3428 unix_shared_memory_queue_t * q, u32 context)
3430 vl_api_flow_classify_details_t *mp;
3432 mp = vl_msg_api_alloc (sizeof (*mp));
3433 memset (mp, 0, sizeof (*mp));
3434 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
3435 mp->context = context;
3436 mp->sw_if_index = htonl (sw_if_index);
3437 mp->table_index = htonl (table_index);
3439 vl_msg_api_send_shmem (q, (u8 *) & mp);
3443 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
3445 unix_shared_memory_queue_t *q;
3446 flow_classify_main_t *pcm = &flow_classify_main;
3450 q = vl_api_client_index_to_input_queue (mp->client_index);
3454 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
3456 if (vec_len (vec_tbl))
3458 for (i = 0; i < vec_len (vec_tbl); i++)
3460 if (vec_elt (vec_tbl, i) == ~0)
3463 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
3470 vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
3472 vl_api_feature_enable_disable_reply_t *rmp;
3474 u8 *arc_name, *feature_name;
3476 VALIDATE_SW_IF_INDEX (mp);
3478 arc_name = format (0, "%s%c", mp->arc_name, 0);
3479 feature_name = format (0, "%s%c", mp->feature_name, 0);
3481 vnet_feature_registration_t *reg;
3483 vnet_get_feature_reg ((const char *) arc_name,
3484 (const char *) feature_name);
3486 rv = VNET_API_ERROR_INVALID_VALUE;
3490 clib_error_t *error = 0;
3492 sw_if_index = ntohl (mp->sw_if_index);
3493 if (reg->enable_disable_cb)
3494 error = reg->enable_disable_cb (sw_if_index, mp->enable);
3496 vnet_feature_enable_disable ((const char *) arc_name,
3497 (const char *) feature_name,
3498 sw_if_index, mp->enable, 0, 0);
3501 clib_error_report (error);
3502 rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
3506 vec_free (feature_name);
3507 vec_free (arc_name);
3509 BAD_SW_IF_INDEX_LABEL;
3511 REPLY_MACRO (VL_API_FEATURE_ENABLE_DISABLE_REPLY);
3514 #define BOUNCE_HANDLER(nn) \
3515 static void vl_api_##nn##_t_handler ( \
3516 vl_api_##nn##_t *mp) \
3518 vpe_client_registration_t *reg; \
3519 vpe_api_main_t * vam = &vpe_api_main; \
3520 unix_shared_memory_queue_t * q; \
3522 /* One registration only... */ \
3523 pool_foreach(reg, vam->nn##_registrations, \
3525 q = vl_api_client_index_to_input_queue (reg->client_index); \
3528 * If the queue is stuffed, turf the msg and complain \
3529 * It's unlikely that the intended recipient is \
3530 * alive; avoid deadlock at all costs. \
3532 if (q->cursize == q->maxsize) { \
3533 clib_warning ("ERROR: receiver queue full, drop msg"); \
3534 vl_msg_api_free (mp); \
3537 vl_msg_api_send_shmem (q, (u8 *)&mp); \
3541 vl_msg_api_free (mp); \
3544 static void setup_message_id_table (api_main_t * am);
3548 * Add vpe's API message handlers to the table.
3549 * vlib has alread mapped shared memory and
3550 * added the client registration handlers.
3551 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
3553 static clib_error_t *
3554 vpe_api_hookup (vlib_main_t * vm)
3556 api_main_t *am = &api_main;
3559 vl_msg_api_set_handlers(VL_API_##N, #n, \
3560 vl_api_##n##_t_handler, \
3562 vl_api_##n##_t_endian, \
3563 vl_api_##n##_t_print, \
3564 sizeof(vl_api_##n##_t), 1);
3565 foreach_vpe_api_msg;
3569 * Trace space for classifier mask+match
3571 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
3572 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
3573 += 5 * sizeof (u32x4);
3574 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
3577 * Thread-safe API messages
3579 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
3580 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
3583 * Set up the (msg_name, crc, message-id) table
3585 setup_message_id_table (am);
3590 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
3592 static clib_error_t *
3593 vpe_api_init (vlib_main_t * vm)
3595 vpe_api_main_t *am = &vpe_api_main;
3598 am->vnet_main = vnet_get_main ();
3599 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
3600 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
3601 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
3602 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
3603 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
3604 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
3605 am->bfd_events_registration_hash = hash_create (0, sizeof (uword));
3608 vl_set_memory_region_name ("/vpe-api");
3609 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
3614 VLIB_INIT_FUNCTION (vpe_api_init);
3617 static clib_error_t *
3618 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
3621 u64 baseva, size, pvt_heap_size;
3623 const int max_buf_size = 4096;
3625 struct passwd _pw, *pw;
3626 struct group _grp, *grp;
3628 buf = vec_new (char, 128);
3629 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3631 if (unformat (input, "prefix %s", &chroot_path))
3633 vec_add1 (chroot_path, 0);
3634 vl_set_memory_root_path ((char *) chroot_path);
3636 else if (unformat (input, "uid %d", &uid))
3637 vl_set_memory_uid (uid);
3638 else if (unformat (input, "gid %d", &gid))
3639 vl_set_memory_gid (gid);
3640 else if (unformat (input, "baseva %llx", &baseva))
3641 vl_set_global_memory_baseva (baseva);
3642 else if (unformat (input, "global-size %lldM", &size))
3643 vl_set_global_memory_size (size * (1ULL << 20));
3644 else if (unformat (input, "global-size %lldG", &size))
3645 vl_set_global_memory_size (size * (1ULL << 30));
3646 else if (unformat (input, "global-size %lld", &size))
3647 vl_set_global_memory_size (size);
3648 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
3649 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
3650 else if (unformat (input, "global-pvt-heap-size size %lld",
3652 vl_set_global_pvt_heap_size (pvt_heap_size);
3653 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
3654 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
3655 else if (unformat (input, "api-pvt-heap-size size %lld",
3657 vl_set_api_pvt_heap_size (pvt_heap_size);
3658 else if (unformat (input, "api-size %lldM", &size))
3659 vl_set_api_memory_size (size * (1ULL << 20));
3660 else if (unformat (input, "api-size %lldG", &size))
3661 vl_set_api_memory_size (size * (1ULL << 30));
3662 else if (unformat (input, "api-size %lld", &size))
3663 vl_set_api_memory_size (size);
3664 else if (unformat (input, "uid %s", &s))
3666 /* lookup the username */
3669 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
3670 && (vec_len (buf) <= max_buf_size))
3672 vec_resize (buf, vec_len (buf) * 2);
3676 e = clib_error_return_code (0, rv,
3677 CLIB_ERROR_ERRNO_VALID |
3679 "cannot fetch username %s", s);
3687 clib_error_return_fatal (0, "username %s does not exist", s);
3693 vl_set_memory_uid (pw->pw_uid);
3695 else if (unformat (input, "gid %s", &s))
3697 /* lookup the group name */
3700 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
3701 && (vec_len (buf) <= max_buf_size))
3703 vec_resize (buf, vec_len (buf) * 2);
3707 e = clib_error_return_code (0, rv,
3708 CLIB_ERROR_ERRNO_VALID |
3710 "cannot fetch group %s", s);
3717 e = clib_error_return_fatal (0, "group %s does not exist", s);
3724 vl_set_memory_gid (grp->gr_gid);
3727 return clib_error_return (0, "unknown input `%U'",
3728 format_unformat_error, input);
3733 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
3736 get_unformat_vnet_sw_interface (void)
3738 return (void *) &unformat_vnet_sw_interface;
3742 format_arp_event (u8 * s, va_list * args)
3744 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
3746 s = format (s, "pid %d: ", event->pid);
3748 s = format (s, "bd mac/ip4 binding events");
3750 s = format (s, "resolution for %U", format_ip4_address, &event->address);
3755 format_nd_event (u8 * s, va_list * args)
3757 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
3759 s = format (s, "pid %d: ", event->pid);
3761 s = format (s, "bd mac/ip6 binding events");
3763 s = format (s, "resolution for %U", format_ip6_address, event->address);
3767 static clib_error_t *
3768 show_ip_arp_nd_events_fn (vlib_main_t * vm,
3769 unformat_input_t * input, vlib_cli_command_t * cmd)
3771 vpe_api_main_t *am = &vpe_api_main;
3772 vl_api_ip4_arp_event_t *arp_event;
3773 vl_api_ip6_nd_event_t *nd_event;
3775 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
3777 vlib_cli_output (vm, "No active arp or nd event registrations");
3782 pool_foreach (arp_event, am->arp_events,
3784 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
3787 pool_foreach (nd_event, am->nd_events,
3789 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
3797 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
3798 .path = "show arp-nd-event registrations",
3799 .function = show_ip_arp_nd_events_fn,
3800 .short_help = "Show ip4 arp and ip6 nd event registrations",
3804 #define vl_msg_name_crc_list
3805 #include <vpp/api/vpe_all_api_h.h>
3806 #undef vl_msg_name_crc_list
3809 setup_message_id_table (api_main_t * am)
3811 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
3812 foreach_vl_msg_name_crc_memclnt;
3813 foreach_vl_msg_name_crc_vpe;
3819 * fd.io coding-style-patch-verification: ON
3822 * eval: (c-set-style "gnu")