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/l2tp/l2tp.h>
53 #include <vnet/ip/ip.h>
54 #include <vnet/ip/ip6.h>
55 #include <vnet/unix/tuntap.h>
56 #include <vnet/unix/tapcli.h>
57 #include <vnet/mpls/mpls.h>
58 #include <vnet/dhcp/proxy.h>
59 #include <vnet/dhcp/client.h>
61 #include <vnet/sr/sr.h>
63 #include <vnet/dhcpv6/proxy.h>
64 #include <vlib/vlib.h>
65 #include <vlib/unix/unix.h>
66 #include <vlibapi/api.h>
67 #include <vlibmemory/api.h>
68 #include <vnet/classify/vnet_classify.h>
69 #include <vnet/classify/input_acl.h>
70 #include <vnet/classify/policer_classify.h>
71 #include <vnet/l2/l2_classify.h>
72 #include <vnet/vxlan/vxlan.h>
73 #include <vnet/gre/gre.h>
74 #include <vnet/l2/l2_vtr.h>
75 #include <vnet/vxlan-gpe/vxlan_gpe.h>
76 #include <vnet/lisp-gpe/lisp_gpe.h>
77 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
78 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
79 #include <vnet/lisp-cp/control.h>
80 #include <vnet/map/map.h>
81 #include <vnet/cop/cop.h>
82 #include <vnet/ip/ip6_hop_by_hop.h>
83 #include <vnet/ip/ip_source_and_port_range_check.h>
84 #include <vnet/devices/af_packet/af_packet.h>
85 #include <vnet/policer/policer.h>
86 #include <vnet/devices/netmap/netmap.h>
87 #include <vnet/flow/flow_report.h>
88 #include <vnet/ipsec-gre/ipsec_gre.h>
89 #include <vnet/flow/flow_report_classify.h>
90 #include <vnet/ip/punt.h>
93 #undef __included_bihash_template_h__
94 #include <vnet/l2/l2_fib.h>
97 #include <vnet/ipsec/ipsec.h>
98 #include <vnet/ipsec/ikev2.h>
100 #include <vnet/devices/virtio/vhost-user.h>
102 #include <stats/stats.h>
105 #include <vnet/ethernet/ethernet.h>
106 #include <vnet/ethernet/arp_packet.h>
107 #include <vnet/interface.h>
109 #include <vnet/l2/l2_fib.h>
110 #include <vnet/l2/l2_bd.h>
111 #include <vpp-api/vpe_msg_enum.h>
113 #include <vnet/fib/ip6_fib.h>
114 #include <vnet/fib/ip4_fib.h>
115 #include <vnet/dpo/drop_dpo.h>
116 #include <vnet/dpo/receive_dpo.h>
117 #include <vnet/dpo/lookup_dpo.h>
118 #include <vnet/dpo/classify_dpo.h>
120 #define f64_endian(a)
121 #define f64_print(a,b)
123 #define vl_typedefs /* define message structures */
124 #include <vpp-api/vpe_all_api_h.h>
127 #define vl_endianfun /* define message structures */
128 #include <vpp-api/vpe_all_api_h.h>
131 /* instantiate all the print functions we know about */
132 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
134 #include <vpp-api/vpe_all_api_h.h>
137 #define REPLY_MACRO(t) \
139 unix_shared_memory_queue_t * q; \
140 rv = vl_msg_api_pd_handler (mp, rv); \
141 q = vl_api_client_index_to_input_queue (mp->client_index); \
145 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
146 rmp->_vl_msg_id = ntohs((t)); \
147 rmp->context = mp->context; \
148 rmp->retval = ntohl(rv); \
150 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
153 #define REPLY_MACRO2(t, body) \
155 unix_shared_memory_queue_t * q; \
156 rv = vl_msg_api_pd_handler (mp, rv); \
157 q = vl_api_client_index_to_input_queue (mp->client_index); \
161 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
162 rmp->_vl_msg_id = ntohs((t)); \
163 rmp->context = mp->context; \
164 rmp->retval = ntohl(rv); \
165 do {body;} while (0); \
166 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
169 #define REPLY_MACRO3(t, n, body) \
171 unix_shared_memory_queue_t * q; \
172 rv = vl_msg_api_pd_handler (mp, rv); \
173 q = vl_api_client_index_to_input_queue (mp->client_index); \
177 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
178 rmp->_vl_msg_id = ntohs((t)); \
179 rmp->context = mp->context; \
180 rmp->retval = ntohl(rv); \
181 do {body;} while (0); \
182 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
185 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
187 #define VALIDATE_SW_IF_INDEX(mp) \
188 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
189 vnet_main_t *__vnm = vnet_get_main(); \
190 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
192 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
193 goto bad_sw_if_index; \
197 #define BAD_SW_IF_INDEX_LABEL \
203 #define VALIDATE_RX_SW_IF_INDEX(mp) \
204 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
205 vnet_main_t *__vnm = vnet_get_main(); \
206 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
207 __rx_sw_if_index)) { \
208 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
209 goto bad_rx_sw_if_index; \
213 #define BAD_RX_SW_IF_INDEX_LABEL \
215 bad_rx_sw_if_index: \
219 #define VALIDATE_TX_SW_IF_INDEX(mp) \
220 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
221 vnet_main_t *__vnm = vnet_get_main(); \
222 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
223 __tx_sw_if_index)) { \
224 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
225 goto bad_tx_sw_if_index; \
229 #define BAD_TX_SW_IF_INDEX_LABEL \
231 bad_tx_sw_if_index: \
237 #define VALIDATE_SW_IF_INDEX(mp)
238 #define BAD_SW_IF_INDEX_LABEL
239 #define VALIDATE_RX_SW_IF_INDEX(mp)
240 #define BAD_RX_SW_IF_INDEX_LABEL
241 #define VALIDATE_TX_SW_IF_INDEX(mp)
242 #define BAD_TX_SW_IF_INDEX_LABEL
244 #endif /* CLIB_DEBUG > 0 */
246 #define foreach_vpe_api_msg \
247 _(WANT_INTERFACE_EVENTS, want_interface_events) \
248 _(WANT_OAM_EVENTS, want_oam_events) \
249 _(OAM_ADD_DEL, oam_add_del) \
250 _(SW_INTERFACE_DUMP, sw_interface_dump) \
251 _(SW_INTERFACE_DETAILS, sw_interface_details) \
252 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
253 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
254 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
255 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
256 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
257 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
258 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
259 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
260 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
261 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
262 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
263 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
264 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
265 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
266 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
267 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
268 _(L2FIB_ADD_DEL, l2fib_add_del) \
269 _(L2_FLAGS, l2_flags) \
270 _(BRIDGE_FLAGS, bridge_flags) \
271 _(TAP_CONNECT, tap_connect) \
272 _(TAP_MODIFY, tap_modify) \
273 _(TAP_DELETE, tap_delete) \
274 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
275 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
276 _(CREATE_SUBIF, create_subif) \
277 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
278 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
279 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
280 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
281 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
282 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
283 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
284 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
285 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
286 _(RESET_FIB, reset_fib) \
287 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
288 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
289 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
290 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
291 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
292 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
293 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
294 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
295 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
296 sw_interface_ip6_set_link_local_address) \
297 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
298 _(CREATE_LOOPBACK, create_loopback) \
299 _(CONTROL_PING, control_ping) \
300 _(CLI_REQUEST, cli_request) \
301 _(CLI_INBAND, cli_inband) \
302 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
303 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
304 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
305 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
306 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
307 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
308 _(GET_NODE_INDEX, get_node_index) \
309 _(ADD_NODE_NEXT, add_node_next) \
310 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
311 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
312 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
313 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
314 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
315 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
316 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
317 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
318 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
319 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
320 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
321 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
322 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
323 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
324 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
325 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
326 _(IP_ADDRESS_DUMP, ip_address_dump) \
327 _(IP_DUMP, ip_dump) \
328 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
329 _(SHOW_VERSION, show_version) \
330 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
331 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
332 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
333 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
334 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
335 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
336 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
337 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
338 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
339 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
340 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
341 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
342 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
343 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
344 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
345 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
346 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
347 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
348 _(DELETE_LOOPBACK, delete_loopback) \
349 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
350 _(MAP_ADD_DOMAIN, map_add_domain) \
351 _(MAP_DEL_DOMAIN, map_del_domain) \
352 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
353 _(MAP_DOMAIN_DUMP, map_domain_dump) \
354 _(MAP_RULE_DUMP, map_rule_dump) \
355 _(MAP_SUMMARY_STATS, map_summary_stats) \
356 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
357 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
358 _(GET_NODE_GRAPH, get_node_graph) \
359 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
360 _(IOAM_ENABLE, ioam_enable) \
361 _(IOAM_DISABLE, ioam_disable) \
362 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
363 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
364 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
365 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
366 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
367 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
368 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
369 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
370 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
371 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
372 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
373 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
374 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
375 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
376 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
377 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
378 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
379 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
380 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
381 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
382 _(SHOW_LISP_STATUS, show_lisp_status) \
383 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
384 lisp_add_del_map_request_itr_rlocs) \
385 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
386 _(SHOW_LISP_PITR, show_lisp_pitr) \
387 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
388 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
389 _(AF_PACKET_CREATE, af_packet_create) \
390 _(AF_PACKET_DELETE, af_packet_delete) \
391 _(POLICER_ADD_DEL, policer_add_del) \
392 _(POLICER_DUMP, policer_dump) \
393 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
394 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
395 _(NETMAP_CREATE, netmap_create) \
396 _(NETMAP_DELETE, netmap_delete) \
397 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
398 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
399 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
400 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
401 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
402 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
403 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
404 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
405 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
406 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
407 _(CLASSIFY_TABLE_INFO,classify_table_info) \
408 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
409 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
410 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
411 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
412 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
413 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
414 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
415 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
416 _(GET_NEXT_INDEX, get_next_index) \
417 _(PG_CREATE_INTERFACE, pg_create_interface) \
418 _(PG_CAPTURE, pg_capture) \
419 _(PG_ENABLE_DISABLE, pg_enable_disable) \
420 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
421 ip_source_and_port_range_check_add_del) \
422 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
423 ip_source_and_port_range_check_interface_add_del) \
424 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
425 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
426 _(DELETE_SUBIF, delete_subif) \
427 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
431 #define QUOTE(x) QUOTE_(x)
433 #define foreach_registration_hash \
434 _(interface_events) \
435 _(to_netconf_server) \
436 _(from_netconf_server) \
437 _(to_netconf_client) \
438 _(from_netconf_client) \
443 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
444 RESOLVE_IP6_ADD_DEL_ROUTE,
445 RESOLVE_MPLS_ETHERNET_ADD_DEL,
453 vl_api_ip_add_del_route_t r;
454 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
461 #define _(a) uword *a##_registration_hash; \
462 vpe_client_registration_t * a##_registrations;
463 foreach_registration_hash
465 /* notifications happen really early in the game */
466 u8 link_state_process_up;
468 /* ip4 and ip6 pending route adds */
469 pending_route_t *pending_routes;
471 /* ip4 arp event registration pool */
472 vl_api_ip4_arp_event_t *arp_events;
474 /* ip6 nd event registration pool */
475 vl_api_ip6_nd_event_t *nd_events;
478 vlib_main_t *vlib_main;
479 vnet_main_t *vnet_main;
482 static vlib_node_registration_t vpe_resolver_process_node;
483 static vpe_api_main_t vpe_api_main;
485 static void send_sw_interface_flags (vpe_api_main_t * am,
486 unix_shared_memory_queue_t * q,
487 vnet_sw_interface_t * swif);
488 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
489 unix_shared_memory_queue_t * q,
492 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
493 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
496 /* Clean up all registrations belonging to the indicated client */
498 vl_api_memclnt_delete_callback (u32 client_index)
500 vpe_api_main_t *vam = &vpe_api_main;
501 vpe_client_registration_t *rp;
503 int stats_memclnt_delete_callback (u32 client_index);
505 stats_memclnt_delete_callback (client_index);
508 p = hash_get (vam->a##_registration_hash, client_index); \
510 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
511 pool_put (vam->a##_registrations, rp); \
512 hash_unset (vam->a##_registration_hash, client_index); \
514 foreach_registration_hash;
519 #define API_LINK_STATE_EVENT 1
520 #define API_ADMIN_UP_DOWN_EVENT 2
523 event_data_cmp (void *a1, void *a2)
528 return (word) e1[0] - (word) e2[0];
532 link_state_process (vlib_main_t * vm,
533 vlib_node_runtime_t * rt, vlib_frame_t * f)
535 vpe_api_main_t *vam = &vpe_api_main;
536 vnet_main_t *vnm = vam->vnet_main;
537 vnet_sw_interface_t *swif;
538 uword *event_data = 0;
539 vpe_client_registration_t *reg;
541 u32 prev_sw_if_index;
542 unix_shared_memory_queue_t *q;
544 vam->link_state_process_up = 1;
548 vlib_process_wait_for_event (vm);
550 /* Unified list of changed link or admin state sw_if_indices */
551 vlib_process_get_events_with_type
552 (vm, &event_data, API_LINK_STATE_EVENT);
553 vlib_process_get_events_with_type
554 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
556 /* Sort, so we can eliminate duplicates */
557 vec_sort_with_function (event_data, event_data_cmp);
559 prev_sw_if_index = ~0;
561 for (i = 0; i < vec_len (event_data); i++)
563 /* Only one message per swif */
564 if (prev_sw_if_index == event_data[i])
566 prev_sw_if_index = event_data[i];
569 pool_foreach(reg, vam->interface_events_registrations,
571 q = vl_api_client_index_to_input_queue (reg->client_index);
574 /* sw_interface may be deleted already */
575 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
578 swif = vnet_get_sw_interface (vnm, event_data[i]);
579 send_sw_interface_flags (vam, q, swif);
585 vec_reset_length (event_data);
591 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
593 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
594 u32 hw_if_index, u32 flags);
597 VLIB_REGISTER_NODE (link_state_process_node,static) = {
598 .function = link_state_process,
599 .type = VLIB_NODE_TYPE_PROCESS,
600 .name = "vpe-link-state-process",
604 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
605 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
607 static clib_error_t *
608 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
610 vpe_api_main_t *vam = &vpe_api_main;
611 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
613 if (vam->link_state_process_up)
614 vlib_process_signal_event (vam->vlib_main,
615 link_state_process_node.index,
616 API_LINK_STATE_EVENT, hi->sw_if_index);
620 static clib_error_t *
621 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
623 vpe_api_main_t *vam = &vpe_api_main;
626 * Note: it's perfectly fair to set a subif admin up / admin down.
627 * Note the subtle distinction between this routine and the previous
630 if (vam->link_state_process_up)
631 vlib_process_signal_event (vam->vlib_main,
632 link_state_process_node.index,
633 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
637 #define pub_sub_handler(lca,UCA) \
638 static void vl_api_want_##lca##_t_handler ( \
639 vl_api_want_##lca##_t *mp) \
641 vpe_api_main_t *vam = &vpe_api_main; \
642 vpe_client_registration_t *rp; \
643 vl_api_want_##lca##_reply_t *rmp; \
647 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
649 if (mp->enable_disable) { \
650 clib_warning ("pid %d: already enabled...", mp->pid); \
651 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
654 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
655 pool_put (vam->lca##_registrations, rp); \
656 hash_unset (vam->lca##_registration_hash, \
661 if (mp->enable_disable == 0) { \
662 clib_warning ("pid %d: already disabled...", mp->pid); \
663 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
666 pool_get (vam->lca##_registrations, rp); \
667 rp->client_index = mp->client_index; \
668 rp->client_pid = mp->pid; \
669 hash_set (vam->lca##_registration_hash, rp->client_index, \
670 rp - vam->lca##_registrations); \
673 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
677 pub_sub_handler (interface_events, INTERFACE_EVENTS)
678 pub_sub_handler (oam_events, OAM_EVENTS)
681 #define RESOLUTION_EVENT 1
682 #define RESOLUTION_PENDING_EVENT 2
683 #define IP4_ARP_EVENT 3
684 #define IP6_ND_EVENT 4
686 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
688 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
690 static int mpls_ethernet_add_del_tunnel_2_t_handler
691 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
694 handle_ip4_arp_event (u32 pool_index)
696 vpe_api_main_t *vam = &vpe_api_main;
697 vnet_main_t *vnm = vam->vnet_main;
698 vlib_main_t *vm = vam->vlib_main;
699 vl_api_ip4_arp_event_t *event;
700 vl_api_ip4_arp_event_t *mp;
701 unix_shared_memory_queue_t *q;
703 /* Client can cancel, die, etc. */
704 if (pool_is_free_index (vam->arp_events, pool_index))
707 event = pool_elt_at_index (vam->arp_events, pool_index);
709 q = vl_api_client_index_to_input_queue (event->client_index);
712 (void) vnet_add_del_ip4_arp_change_event
713 (vnm, arp_change_delete_callback,
714 event->pid, &event->address,
715 vpe_resolver_process_node.index, IP4_ARP_EVENT,
716 ~0 /* pool index, notused */ , 0 /* is_add */ );
720 if (q->cursize < q->maxsize)
722 mp = vl_msg_api_alloc (sizeof (*mp));
723 clib_memcpy (mp, event, sizeof (*mp));
724 vl_msg_api_send_shmem (q, (u8 *) & mp);
728 static f64 last_time;
730 * Throttle syslog msgs.
731 * It's pretty tempting to just revoke the registration...
733 if (vlib_time_now (vm) > last_time + 10.0)
735 clib_warning ("arp event for %U to pid %d: queue stuffed!",
736 format_ip4_address, &event->address, event->pid);
737 last_time = vlib_time_now (vm);
743 handle_ip6_nd_event (u32 pool_index)
745 vpe_api_main_t *vam = &vpe_api_main;
746 vnet_main_t *vnm = vam->vnet_main;
747 vlib_main_t *vm = vam->vlib_main;
748 vl_api_ip6_nd_event_t *event;
749 vl_api_ip6_nd_event_t *mp;
750 unix_shared_memory_queue_t *q;
752 /* Client can cancel, die, etc. */
753 if (pool_is_free_index (vam->nd_events, pool_index))
756 event = pool_elt_at_index (vam->nd_events, pool_index);
758 q = vl_api_client_index_to_input_queue (event->client_index);
761 (void) vnet_add_del_ip6_nd_change_event
762 (vnm, nd_change_delete_callback,
763 event->pid, &event->address,
764 vpe_resolver_process_node.index, IP6_ND_EVENT,
765 ~0 /* pool index, notused */ , 0 /* is_add */ );
769 if (q->cursize < q->maxsize)
771 mp = vl_msg_api_alloc (sizeof (*mp));
772 clib_memcpy (mp, event, sizeof (*mp));
773 vl_msg_api_send_shmem (q, (u8 *) & mp);
777 static f64 last_time;
779 * Throttle syslog msgs.
780 * It's pretty tempting to just revoke the registration...
782 if (vlib_time_now (vm) > last_time + 10.0)
784 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
785 format_ip6_address, &event->address, event->pid);
786 last_time = vlib_time_now (vm);
792 resolver_process (vlib_main_t * vm,
793 vlib_node_runtime_t * rt, vlib_frame_t * f)
796 uword *event_data = 0;
798 vpe_api_main_t *vam = &vpe_api_main;
800 vl_api_ip_add_del_route_t *adr;
801 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
802 u32 *resolution_failures = 0;
808 vlib_process_wait_for_event_or_clock (vm, timeout);
810 event_type = vlib_process_get_events (vm, &event_data);
814 case RESOLUTION_PENDING_EVENT:
818 case RESOLUTION_EVENT:
819 for (i = 0; i < vec_len (event_data); i++)
822 * Resolution events can occur long after the
823 * original request has timed out. $$$ add a cancel
826 if (pool_is_free_index (vam->pending_routes, event_data[i]))
829 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
833 switch (pr->resolve_type)
835 case RESOLVE_IP4_ADD_DEL_ROUTE:
836 rv = ip4_add_del_route_t_handler (adr);
837 clib_warning ("resolver: add %U/%d via %U %s",
839 (ip4_address_t *) & (adr->dst_address),
840 adr->dst_address_length,
842 (ip4_address_t *) & (adr->next_hop_address),
843 (rv >= 0) ? "succeeded" : "failed");
846 case RESOLVE_IP6_ADD_DEL_ROUTE:
847 rv = ip6_add_del_route_t_handler (adr);
848 clib_warning ("resolver: add %U/%d via %U %s",
850 (ip6_address_t *) & (adr->dst_address),
851 adr->dst_address_length,
853 (ip6_address_t *) & (adr->next_hop_address),
854 (rv >= 0) ? "succeeded" : "failed");
857 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
858 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
859 clib_warning ("resolver: add mpls-o-e via %U %s",
862 (pme->next_hop_ip4_address_in_outer_vrf),
863 (rv >= 0) ? "succeeded" : "failed");
867 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
869 pool_put (vam->pending_routes, pr);
874 for (i = 0; i < vec_len (event_data); i++)
875 handle_ip4_arp_event (event_data[i]);
879 for (i = 0; i < vec_len (event_data); i++)
880 handle_ip6_nd_event (event_data[i]);
883 case ~0: /* timeout, retry pending resolutions */
885 pool_foreach (pr, vam->pending_routes,
891 /* May fail, e.g. due to interface down */
892 switch (pr->resolve_type)
894 case RESOLVE_IP4_ADD_DEL_ROUTE:
895 e = ip4_probe_neighbor
896 (vm, (ip4_address_t *)&(adr->next_hop_address),
897 ntohl(adr->next_hop_sw_if_index));
900 case RESOLVE_IP6_ADD_DEL_ROUTE:
901 e = ip6_probe_neighbor
902 (vm, (ip6_address_t *)&(adr->next_hop_address),
903 ntohl(adr->next_hop_sw_if_index));
906 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
908 e = ip4_probe_neighbor
910 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
911 pme->resolve_opaque);
915 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
920 clib_error_report (e);
922 adr->resolve_attempts = 1;
924 pme->resolve_attempts = 1;
928 adr->resolve_attempts -= 1;
929 if (adr->resolve_attempts == 0)
930 vec_add1 (resolution_failures,
931 pr - vam->pending_routes);
935 pme->resolve_attempts -= 1;
936 if (pme->resolve_attempts == 0)
937 vec_add1 (resolution_failures,
938 pr - vam->pending_routes);
942 for (i = 0; i < vec_len (resolution_failures); i++)
944 pr = pool_elt_at_index (vam->pending_routes,
945 resolution_failures[i]);
949 switch (pr->resolve_type)
951 case RESOLVE_IP4_ADD_DEL_ROUTE:
952 clib_warning ("resolver: add %U/%d via %U retry failure",
954 (ip4_address_t *) & (adr->dst_address),
955 adr->dst_address_length,
957 (ip4_address_t *) & (adr->next_hop_address));
960 case RESOLVE_IP6_ADD_DEL_ROUTE:
961 clib_warning ("resolver: add %U/%d via %U retry failure",
963 (ip6_address_t *) & (adr->dst_address),
964 adr->dst_address_length,
966 (ip6_address_t *) & (adr->next_hop_address));
969 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
970 clib_warning ("resolver: add mpls-o-e via %U retry failure",
973 (pme->next_hop_ip4_address_in_outer_vrf));
977 clib_warning ("BUG");
979 pool_put (vam->pending_routes, pr);
981 vec_reset_length (resolution_failures);
984 if (pool_elts (vam->pending_routes) == 0)
986 vec_reset_length (event_data);
988 return 0; /* or not */
992 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
993 .function = resolver_process,
994 .type = VLIB_NODE_TYPE_PROCESS,
995 .name = "vpe-route-resolver-process",
1000 ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp,
1002 const fib_prefix_t * prefix,
1003 const ip46_address_t * next_hop,
1004 u32 next_hop_sw_if_index,
1005 u32 next_hop_fib_index, u32 next_hop_weight)
1007 vnet_classify_main_t *cm = &vnet_classify_main;
1008 fib_protocol_t proto = prefix->fp_proto;
1009 stats_main_t *sm = &stats_main;
1011 if (mp->is_multipath)
1013 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1015 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1017 if (mp->is_resolve_host)
1018 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1019 if (mp->is_resolve_attached)
1020 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1023 fib_table_entry_path_add (fib_index,
1026 FIB_ENTRY_FLAG_NONE,
1029 next_hop_sw_if_index,
1032 MPLS_LABEL_INVALID, path_flags);
1034 fib_table_entry_path_remove (fib_index,
1039 next_hop_sw_if_index,
1041 next_hop_weight, path_flags);
1047 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1049 if (mp->is_drop || mp->is_local || mp->is_classify || mp->lookup_in_vrf)
1052 * special route types that link directly to the adj
1056 dpo_id_t dpo = DPO_NULL;
1059 dproto = fib_proto_to_dpo (prefix->fp_proto);
1062 dpo_copy (&dpo, drop_dpo_get (dproto));
1063 else if (mp->is_local)
1064 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
1065 else if (mp->is_classify)
1067 if (pool_is_free_index (cm->tables,
1068 ntohl (mp->classify_table_index)))
1071 return VNET_API_ERROR_NO_SUCH_TABLE;
1074 dpo_set (&dpo, DPO_CLASSIFY, proto,
1075 classify_dpo_create (prefix->fp_proto,
1077 (mp->classify_table_index)));
1079 else if (mp->lookup_in_vrf)
1081 next_hop_fib_index =
1082 fib_table_id_find_fib_index (dproto,
1083 ntohl (mp->lookup_in_vrf));
1084 if (~0 == next_hop_fib_index)
1087 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1090 lookup_dpo_add_or_lock_w_fib_index (next_hop_fib_index,
1092 LOOKUP_INPUT_DST_ADDR,
1093 LOOKUP_TABLE_FROM_CONFIG,
1099 return VNET_API_ERROR_NO_SUCH_TABLE;
1102 fib_table_entry_special_dpo_add (fib_index,
1105 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
1110 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
1117 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1119 if (mp->is_resolve_host)
1120 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1121 if (mp->is_resolve_attached)
1122 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1124 fib_table_entry_update_one_path (fib_index,
1127 FIB_ENTRY_FLAG_NONE,
1130 next_hop_sw_if_index,
1133 MPLS_LABEL_INVALID, path_flags);
1137 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
1146 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1148 vpe_api_main_t *vam = &vpe_api_main;
1149 vnet_main_t *vnm = vam->vnet_main;
1152 fib_index = ip4_fib_index_from_table_id (ntohl (mp->vrf_id));
1153 if (~0 == fib_index)
1155 if (mp->create_vrf_if_needed)
1157 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1158 ntohl (mp->vrf_id));
1162 /* No such VRF, and we weren't asked to create one */
1163 return VNET_API_ERROR_NO_SUCH_FIB;
1167 if (~0 != ntohl (mp->next_hop_sw_if_index) &&
1168 pool_is_free_index (vnm->interface_main.sw_interfaces,
1169 ntohl (mp->next_hop_sw_if_index)))
1170 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1172 fib_prefix_t pfx = {
1173 .fp_len = mp->dst_address_length,
1174 .fp_proto = FIB_PROTOCOL_IP4,
1176 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
1179 memset (&nh, 0, sizeof (nh));
1180 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
1182 return (ip_add_del_route_t_handler (mp, fib_index, &pfx, &nh,
1183 ntohl (mp->next_hop_sw_if_index),
1184 fib_index, (u32) mp->next_hop_weight));
1188 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1190 vnet_main_t *vnm = vnet_get_main ();
1193 fib_index = ip6_fib_index_from_table_id (ntohl (mp->vrf_id));
1194 if (~0 == fib_index)
1196 if (mp->create_vrf_if_needed)
1198 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1199 ntohl (mp->vrf_id));
1203 /* No such VRF, and we weren't asked to create one */
1204 return VNET_API_ERROR_NO_SUCH_FIB;
1208 if (~0 != ntohl (mp->next_hop_sw_if_index) &&
1209 pool_is_free_index (vnm->interface_main.sw_interfaces,
1210 ntohl (mp->next_hop_sw_if_index)))
1211 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1213 fib_prefix_t pfx = {
1214 .fp_len = mp->dst_address_length,
1215 .fp_proto = FIB_PROTOCOL_IP6,
1217 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
1220 memset (&nh, 0, sizeof (nh));
1221 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
1223 return (ip_add_del_route_t_handler (mp, fib_index, &pfx,
1224 &nh, ntohl (mp->next_hop_sw_if_index),
1225 fib_index, (u32) mp->next_hop_weight));
1229 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1231 vl_api_ip_add_del_route_reply_t *rmp;
1233 vnet_main_t *vnm = vnet_get_main ();
1238 rv = ip6_add_del_route_t_handler (mp);
1240 rv = ip4_add_del_route_t_handler (mp);
1242 rv = (rv == 0) ? vnm->api_errno : rv;
1244 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1248 vl_api_sw_interface_add_del_address_t_handler
1249 (vl_api_sw_interface_add_del_address_t * mp)
1251 vlib_main_t *vm = vlib_get_main ();
1252 vl_api_sw_interface_add_del_address_reply_t *rmp;
1256 VALIDATE_SW_IF_INDEX (mp);
1258 is_del = mp->is_add == 0;
1261 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1262 else if (mp->is_ipv6)
1263 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1264 (void *) mp->address,
1265 mp->address_length, is_del);
1267 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1268 (void *) mp->address,
1269 mp->address_length, is_del);
1271 BAD_SW_IF_INDEX_LABEL;
1273 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1277 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1280 u32 table_id = ntohl (mp->vrf_id);
1281 u32 sw_if_index = ntohl (mp->sw_if_index);
1282 vl_api_sw_interface_set_table_reply_t *rmp;
1283 stats_main_t *sm = &stats_main;
1286 VALIDATE_SW_IF_INDEX (mp);
1288 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1292 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1295 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
1296 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1301 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1304 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
1305 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1309 BAD_SW_IF_INDEX_LABEL;
1311 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1315 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1317 vlib_main_t *vm = vlib_get_main ();
1318 ip4_main_t *im4 = &ip4_main;
1319 ip6_main_t *im6 = &ip6_main;
1320 vl_api_sw_interface_set_vpath_reply_t *rmp;
1323 u32 sw_if_index = ntohl (mp->sw_if_index);
1324 ip4_main_t *ip4m = &ip4_main;
1325 ip6_main_t *ip6m = &ip6_main;
1326 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1327 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1328 ip_config_main_t *rx_cm4u =
1329 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1330 ip_config_main_t *rx_cm4m =
1331 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1332 ip_config_main_t *rx_cm6u =
1333 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1334 ip_config_main_t *rx_cm6m =
1335 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1337 VALIDATE_SW_IF_INDEX (mp);
1339 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1342 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1343 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1345 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1346 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1347 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1348 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1350 im4->ip4_multicast_rx_feature_vpath,
1352 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1353 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1354 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1356 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1357 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1358 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1359 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1361 im6->ip6_multicast_rx_feature_vpath,
1363 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1367 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1368 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1370 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1371 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1372 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1373 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1375 im4->ip4_multicast_rx_feature_vpath,
1377 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1378 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1379 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1381 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1382 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1383 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1384 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1386 im6->ip6_multicast_rx_feature_vpath,
1388 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1391 BAD_SW_IF_INDEX_LABEL;
1393 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1397 vl_api_sw_interface_set_l2_xconnect_t_handler
1398 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1400 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1402 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1403 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1404 vlib_main_t *vm = vlib_get_main ();
1405 vnet_main_t *vnm = vnet_get_main ();
1407 VALIDATE_RX_SW_IF_INDEX (mp);
1411 VALIDATE_TX_SW_IF_INDEX (mp);
1412 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1413 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1417 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1420 BAD_RX_SW_IF_INDEX_LABEL;
1421 BAD_TX_SW_IF_INDEX_LABEL;
1423 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1427 vl_api_sw_interface_set_l2_bridge_t_handler
1428 (vl_api_sw_interface_set_l2_bridge_t * mp)
1430 bd_main_t *bdm = &bd_main;
1431 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1433 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1434 u32 bd_id = ntohl (mp->bd_id);
1438 vlib_main_t *vm = vlib_get_main ();
1439 vnet_main_t *vnm = vnet_get_main ();
1441 VALIDATE_RX_SW_IF_INDEX (mp);
1443 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1447 //VALIDATE_TX_SW_IF_INDEX(mp);
1448 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1449 rx_sw_if_index, bd_index, bvi, shg, 0);
1453 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1456 BAD_RX_SW_IF_INDEX_LABEL;
1458 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1462 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1463 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1465 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1469 dpdk_main_t *dm = &dpdk_main;
1472 u32 sw_if_index = ntohl (mp->sw_if_index);
1473 u32 subport = ntohl (mp->subport);
1474 u32 pipe = ntohl (mp->pipe);
1475 u32 profile = ntohl (mp->profile);
1476 vnet_hw_interface_t *hw;
1478 VALIDATE_SW_IF_INDEX (mp);
1480 /* hw_if & dpdk device */
1481 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1483 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1485 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1487 BAD_SW_IF_INDEX_LABEL;
1489 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1490 rv = VNET_API_ERROR_UNIMPLEMENTED;
1493 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1497 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1498 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1500 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1504 dpdk_main_t *dm = &dpdk_main;
1506 struct rte_sched_subport_params p;
1508 u32 sw_if_index = ntohl (mp->sw_if_index);
1509 u32 subport = ntohl (mp->subport);
1510 p.tb_rate = ntohl (mp->tb_rate);
1511 p.tb_size = ntohl (mp->tb_size);
1512 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1513 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1514 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1515 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1516 p.tc_period = ntohl (mp->tc_period);
1518 vnet_hw_interface_t *hw;
1520 VALIDATE_SW_IF_INDEX (mp);
1522 /* hw_if & dpdk device */
1523 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1525 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1527 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1529 BAD_SW_IF_INDEX_LABEL;
1532 ("setting HQoS subport parameters without DPDK not implemented");
1533 rv = VNET_API_ERROR_UNIMPLEMENTED;
1536 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1540 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1541 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1543 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1547 dpdk_main_t *dm = &dpdk_main;
1548 vlib_thread_main_t *tm = vlib_get_thread_main ();
1551 u32 sw_if_index = ntohl (mp->sw_if_index);
1552 u32 entry = ntohl (mp->entry);
1553 u32 tc = ntohl (mp->tc);
1554 u32 queue = ntohl (mp->queue);
1557 vnet_hw_interface_t *hw;
1559 VALIDATE_SW_IF_INDEX (mp);
1561 /* hw_if & dpdk device */
1562 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1564 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1566 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1568 clib_warning ("invalid traffic class !!");
1569 rv = VNET_API_ERROR_INVALID_VALUE;
1572 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1574 clib_warning ("invalid queue !!");
1575 rv = VNET_API_ERROR_INVALID_VALUE;
1579 /* Detect the set of worker threads */
1580 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1581 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1582 int worker_thread_first = tr->first_index;
1583 int worker_thread_count = tr->count;
1585 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1586 for (i = 0; i < worker_thread_count; i++)
1587 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1589 BAD_SW_IF_INDEX_LABEL;
1592 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1593 rv = VNET_API_ERROR_UNIMPLEMENTED;
1596 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1600 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1602 vlib_main_t *vm = vlib_get_main ();
1603 bd_main_t *bdm = &bd_main;
1604 vl_api_bridge_domain_add_del_reply_t *rmp;
1606 u32 enable_flags = 0, disable_flags = 0;
1607 u32 bd_id = ntohl (mp->bd_id);
1612 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1615 enable_flags |= L2_FLOOD;
1617 disable_flags |= L2_FLOOD;
1620 enable_flags |= L2_UU_FLOOD;
1622 disable_flags |= L2_UU_FLOOD;
1625 enable_flags |= L2_FWD;
1627 disable_flags |= L2_FWD;
1630 enable_flags |= L2_ARP_TERM;
1632 disable_flags |= L2_ARP_TERM;
1635 enable_flags |= L2_LEARN;
1637 disable_flags |= L2_LEARN;
1640 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1643 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1647 rv = bd_delete_bd_index (bdm, bd_id);
1649 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1653 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1655 clib_warning ("BUG");
1659 vl_api_bridge_domain_sw_if_details_t_handler
1660 (vl_api_bridge_domain_sw_if_details_t * mp)
1662 clib_warning ("BUG");
1666 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1667 l2_bridge_domain_t * bd_config,
1668 u32 n_sw_ifs, u32 context)
1670 vl_api_bridge_domain_details_t *mp;
1672 mp = vl_msg_api_alloc (sizeof (*mp));
1673 memset (mp, 0, sizeof (*mp));
1674 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1675 mp->bd_id = ntohl (bd_config->bd_id);
1676 mp->flood = bd_feature_flood (bd_config);
1677 mp->uu_flood = bd_feature_uu_flood (bd_config);
1678 mp->forward = bd_feature_forward (bd_config);
1679 mp->learn = bd_feature_learn (bd_config);
1680 mp->arp_term = bd_feature_arp_term (bd_config);
1681 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1682 mp->n_sw_ifs = ntohl (n_sw_ifs);
1683 mp->context = context;
1685 vl_msg_api_send_shmem (q, (u8 *) & mp);
1689 send_bd_sw_if_details (l2input_main_t * l2im,
1690 unix_shared_memory_queue_t * q,
1691 l2_flood_member_t * member, u32 bd_id, u32 context)
1693 vl_api_bridge_domain_sw_if_details_t *mp;
1694 l2_input_config_t *input_cfg;
1696 mp = vl_msg_api_alloc (sizeof (*mp));
1697 memset (mp, 0, sizeof (*mp));
1698 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1699 mp->bd_id = ntohl (bd_id);
1700 mp->sw_if_index = ntohl (member->sw_if_index);
1701 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1702 mp->shg = input_cfg->shg;
1703 mp->context = context;
1705 vl_msg_api_send_shmem (q, (u8 *) & mp);
1709 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1711 bd_main_t *bdm = &bd_main;
1712 l2input_main_t *l2im = &l2input_main;
1713 unix_shared_memory_queue_t *q;
1714 l2_bridge_domain_t *bd_config;
1715 u32 bd_id, bd_index;
1718 q = vl_api_client_index_to_input_queue (mp->client_index);
1723 bd_id = ntohl (mp->bd_id);
1725 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1726 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1727 for (; bd_index < end; bd_index++)
1729 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1730 /* skip dummy bd_id 0 */
1731 if (bd_config && (bd_config->bd_id > 0))
1734 l2_flood_member_t *m;
1736 n_sw_ifs = vec_len (bd_config->members);
1737 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1739 vec_foreach (m, bd_config->members)
1741 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1748 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1750 bd_main_t *bdm = &bd_main;
1751 l2input_main_t *l2im = &l2input_main;
1752 vl_api_l2fib_add_del_reply_t *rmp;
1755 u32 sw_if_index = ntohl (mp->sw_if_index);
1756 u32 bd_id = ntohl (mp->bd_id);
1765 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1768 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1769 goto bad_sw_if_index;
1775 VALIDATE_SW_IF_INDEX (mp);
1776 if (vec_len (l2im->configs) <= sw_if_index)
1778 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1779 goto bad_sw_if_index;
1783 l2_input_config_t *config;
1784 config = vec_elt_at_index (l2im->configs, sw_if_index);
1785 if (config->bridge == 0)
1787 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1788 goto bad_sw_if_index;
1791 static_mac = mp->static_mac ? 1 : 0;
1792 filter_mac = mp->filter_mac ? 1 : 0;
1793 bvi_mac = mp->bvi_mac ? 1 : 0;
1794 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1799 l2fib_del_entry (mac, bd_index);
1802 BAD_SW_IF_INDEX_LABEL;
1804 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1808 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1810 vl_api_l2_flags_reply_t *rmp;
1812 u32 sw_if_index = ntohl (mp->sw_if_index);
1813 u32 flags = ntohl (mp->feature_bitmap);
1816 VALIDATE_SW_IF_INDEX (mp);
1819 if (flags & L2INPUT_FEAT_ ## a) \
1820 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1821 foreach_l2input_feat;
1824 BAD_SW_IF_INDEX_LABEL;
1827 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1829 rmp->resulting_feature_bitmap = ntohl(rbm);
1835 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1837 vlib_main_t *vm = vlib_get_main ();
1838 bd_main_t *bdm = &bd_main;
1839 vl_api_bridge_flags_reply_t *rmp;
1841 u32 bd_id = ntohl (mp->bd_id);
1843 u32 flags = ntohl (mp->feature_bitmap);
1846 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1849 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1855 bd_set_flags (vm, bd_index, flags, mp->is_set);
1859 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1861 rmp->resulting_feature_bitmap = ntohl(flags);
1867 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1869 bd_main_t *bdm = &bd_main;
1870 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1872 u32 bd_id = ntohl (mp->bd_id);
1876 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1879 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1884 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1885 mp->mac_address, mp->is_ipv6, mp->is_add))
1886 rv = VNET_API_ERROR_UNSPECIFIED;
1889 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1893 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1896 vl_api_tap_connect_reply_t *rmp;
1897 unix_shared_memory_queue_t *q;
1898 u32 sw_if_index = (u32) ~ 0;
1900 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1901 mp->use_random_mac ? 0 : mp->mac_address,
1902 &sw_if_index, mp->renumber,
1903 ntohl (mp->custom_dev_instance));
1905 q = vl_api_client_index_to_input_queue (mp->client_index);
1909 rmp = vl_msg_api_alloc (sizeof (*rmp));
1910 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1911 rmp->context = mp->context;
1912 rmp->retval = ntohl (rv);
1913 rmp->sw_if_index = ntohl (sw_if_index);
1915 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1919 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
1922 vl_api_tap_modify_reply_t *rmp;
1923 unix_shared_memory_queue_t *q;
1924 u32 sw_if_index = (u32) ~ 0;
1926 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1927 mp->use_random_mac ? 0 : mp->mac_address,
1928 &sw_if_index, mp->renumber,
1929 ntohl (mp->custom_dev_instance));
1931 q = vl_api_client_index_to_input_queue (mp->client_index);
1935 rmp = vl_msg_api_alloc (sizeof (*rmp));
1936 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1937 rmp->context = mp->context;
1938 rmp->retval = ntohl (rv);
1939 rmp->sw_if_index = ntohl (sw_if_index);
1941 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1945 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
1948 vpe_api_main_t *vam = &vpe_api_main;
1949 vl_api_tap_delete_reply_t *rmp;
1950 unix_shared_memory_queue_t *q;
1951 u32 sw_if_index = ntohl (mp->sw_if_index);
1953 rv = vnet_tap_delete (vm, sw_if_index);
1955 q = vl_api_client_index_to_input_queue (mp->client_index);
1959 rmp = vl_msg_api_alloc (sizeof (*rmp));
1960 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1961 rmp->context = mp->context;
1962 rmp->retval = ntohl (rv);
1964 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1967 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1971 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1973 vl_api_create_vlan_subif_reply_t *rmp;
1974 vnet_main_t *vnm = vnet_get_main ();
1975 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1976 vnet_hw_interface_t *hi;
1979 vnet_sw_interface_t template;
1981 vnet_interface_main_t *im = &vnm->interface_main;
1982 u64 sup_and_sub_key;
1984 unix_shared_memory_queue_t *q;
1985 clib_error_t *error;
1987 VALIDATE_SW_IF_INDEX (mp);
1989 hw_if_index = ntohl (mp->sw_if_index);
1990 hi = vnet_get_hw_interface (vnm, hw_if_index);
1992 id = ntohl (mp->vlan_id);
1993 if (id == 0 || id > 4095)
1995 rv = VNET_API_ERROR_INVALID_VLAN;
1999 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2001 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2004 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2008 kp = clib_mem_alloc (sizeof (*kp));
2009 *kp = sup_and_sub_key;
2011 memset (&template, 0, sizeof (template));
2012 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2013 template.sup_sw_if_index = hi->sw_if_index;
2014 template.sub.id = id;
2015 template.sub.eth.raw_flags = 0;
2016 template.sub.eth.flags.one_tag = 1;
2017 template.sub.eth.outer_vlan_id = id;
2018 template.sub.eth.flags.exact_match = 1;
2020 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2023 clib_error_report (error);
2024 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2027 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2028 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2030 BAD_SW_IF_INDEX_LABEL;
2033 q = vl_api_client_index_to_input_queue (mp->client_index);
2037 rmp = vl_msg_api_alloc (sizeof (*rmp));
2038 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2039 rmp->context = mp->context;
2040 rmp->retval = ntohl (rv);
2041 rmp->sw_if_index = ntohl (sw_if_index);
2042 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2046 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2048 vl_api_create_subif_reply_t *rmp;
2049 vnet_main_t *vnm = vnet_get_main ();
2050 u32 sw_if_index = ~0;
2053 vnet_sw_interface_t *si;
2054 vnet_hw_interface_t *hi;
2055 vnet_sw_interface_t template;
2057 vnet_interface_main_t *im = &vnm->interface_main;
2058 u64 sup_and_sub_key;
2060 clib_error_t *error;
2062 VALIDATE_SW_IF_INDEX (mp);
2064 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2065 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2067 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2069 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2073 sw_if_index = si->sw_if_index;
2074 sub_id = ntohl (mp->sub_id);
2076 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2078 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2082 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2083 sw_if_index, sub_id);
2084 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2088 kp = clib_mem_alloc (sizeof (*kp));
2089 *kp = sup_and_sub_key;
2091 memset (&template, 0, sizeof (template));
2092 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2093 template.sup_sw_if_index = sw_if_index;
2094 template.sub.id = sub_id;
2095 template.sub.eth.flags.no_tags = mp->no_tags;
2096 template.sub.eth.flags.one_tag = mp->one_tag;
2097 template.sub.eth.flags.two_tags = mp->two_tags;
2098 template.sub.eth.flags.dot1ad = mp->dot1ad;
2099 template.sub.eth.flags.exact_match = mp->exact_match;
2100 template.sub.eth.flags.default_sub = mp->default_sub;
2101 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2102 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2103 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2104 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2106 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2109 clib_error_report (error);
2110 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2114 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2115 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2117 BAD_SW_IF_INDEX_LABEL;
2122 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2124 rmp->sw_if_index = ntohl(sw_if_index);
2130 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2133 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2135 stats_main_t *sm = &stats_main;
2136 u32 tunnel_sw_if_index = ~0;
2138 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2140 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2141 (ip4_address_t *) (mp->dst_address),
2142 (ip4_address_t *) (mp->intfc_address),
2143 (u32) (mp->intfc_address_length),
2144 ntohl (mp->inner_vrf_id),
2145 ntohl (mp->outer_vrf_id),
2146 &tunnel_sw_if_index,
2147 mp->l2_only, mp->is_add);
2151 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2153 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2159 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2160 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2162 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2164 stats_main_t *sm = &stats_main;
2165 u32 tunnel_sw_if_index;
2167 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2169 rv = vnet_mpls_ethernet_add_del_tunnel
2170 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2171 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2172 ntohl (mp->tx_sw_if_index),
2173 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2178 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2180 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2186 * This piece of misery brought to you because the control-plane
2187 * can't figure out the tx interface + dst-mac address all by itself
2189 static int mpls_ethernet_add_del_tunnel_2_t_handler
2190 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2192 pending_route_t *pr;
2193 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2194 vnet_main_t *vnm = vnet_get_main ();
2195 vlib_main_t *vm = vlib_get_main ();
2196 stats_main_t *sm = &stats_main;
2197 vpe_api_main_t *vam = &vpe_api_main;
2198 u32 inner_fib_index, outer_fib_index;
2199 ip4_main_t *im = &ip4_main;
2200 ip_lookup_main_t *lm = &im->lookup_main;
2201 ip_adjacency_t *adj = 0;
2204 u8 *dst_mac_address;
2208 u32 tunnel_sw_if_index;
2210 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2212 return VNET_API_ERROR_NO_SUCH_FIB;
2214 outer_fib_index = p[0];
2217 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2219 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2221 inner_fib_index = p[0];
2223 if (inner_fib_index == outer_fib_index)
2224 return VNET_API_ERROR_INVALID_VALUE;
2227 lookup_result = ip4_fib_table_lookup_lb (ip4_fib_get (outer_fib_index),
2229 mp->next_hop_ip4_address_in_outer_vrf);
2231 adj = ip_get_adjacency (lm, lookup_result);
2232 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2234 if (mp->is_add && mp->resolve_if_needed)
2236 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2238 pool_get (vam->pending_routes, pr);
2239 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2241 clib_memcpy (pme, mp, sizeof (*pme));
2242 /* recursion block, "just in case" */
2243 pme->resolve_if_needed = 0;
2244 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2245 pme->resolve_opaque = tx_sw_if_index;
2246 vnet_register_ip4_arp_resolution_event
2248 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2249 vpe_resolver_process_node.index,
2250 RESOLUTION_EVENT, pr - vam->pending_routes);
2252 vlib_process_signal_event
2253 (vm, vpe_resolver_process_node.index,
2254 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2256 /* The interface may be down, etc. */
2257 e = ip4_probe_neighbor
2258 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2262 clib_error_report (e);
2264 return VNET_API_ERROR_IN_PROGRESS;
2268 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2269 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2272 vnet_rewrite_get_data_internal
2273 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2275 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2277 rv = vnet_mpls_ethernet_add_del_tunnel
2278 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2279 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2280 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2288 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2289 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2291 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2294 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2296 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2301 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2303 vl_api_mpls_add_del_encap_reply_t *rmp;
2308 vec_reset_length (labels);
2310 for (i = 0; i < mp->nlabels; i++)
2311 vec_add1 (labels, ntohl (mp->labels[i]));
2314 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2315 ntohl (mp->vrf_id), labels,
2316 ~0 /* policy_tunnel_index */ ,
2317 0 /* no_dst_hash */ ,
2321 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2325 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2327 vl_api_mpls_add_del_decap_reply_t *rmp;
2330 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2331 ntohl (mp->label), ntohl (mp->next_index),
2332 mp->s_bit, mp->is_add);
2334 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2338 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2340 vl_api_proxy_arp_add_del_reply_t *rmp;
2343 ip4_main_t *im = &ip4_main;
2344 stats_main_t *sm = &stats_main;
2345 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2346 ip4_address_t * hi_addr,
2347 u32 fib_index, int is_del);
2350 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2352 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2356 rv = VNET_API_ERROR_NO_SUCH_FIB;
2362 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2363 (ip4_address_t *) mp->hi_address,
2364 fib_index, mp->is_add == 0);
2368 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2372 vl_api_proxy_arp_intfc_enable_disable_t_handler
2373 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2376 vnet_main_t *vnm = vnet_get_main ();
2377 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2378 vnet_sw_interface_t *si;
2381 VALIDATE_SW_IF_INDEX (mp);
2383 sw_if_index = ntohl (mp->sw_if_index);
2385 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2387 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2391 si = vnet_get_sw_interface (vnm, sw_if_index);
2395 if (mp->enable_disable)
2396 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2398 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2400 BAD_SW_IF_INDEX_LABEL;
2403 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2407 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2410 vl_api_ip_neighbor_add_del_reply_t *rmp;
2411 vnet_main_t *vnm = vnet_get_main ();
2412 stats_main_t *sm = &stats_main;
2415 VALIDATE_SW_IF_INDEX (mp);
2417 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2420 * there's no validation here of the ND/ARP entry being added.
2421 * The expectation is that the FIB will ensure that nothing bad
2422 * will come of adding bogus entries.
2427 rv = vnet_set_ip6_ethernet_neighbor
2428 (vm, ntohl (mp->sw_if_index),
2429 (ip6_address_t *) (mp->dst_address),
2430 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2432 rv = vnet_unset_ip6_ethernet_neighbor
2433 (vm, ntohl (mp->sw_if_index),
2434 (ip6_address_t *) (mp->dst_address),
2435 mp->mac_address, sizeof (mp->mac_address));
2439 ethernet_arp_ip4_over_ethernet_address_t a;
2441 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2442 clib_memcpy (&a.ip4, mp->dst_address, 4);
2445 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2449 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2452 BAD_SW_IF_INDEX_LABEL;
2455 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2459 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2462 vpe_main_t *rm = &vpe_main;
2463 ip4_main_t *im4 = &ip4_main;
2464 ip6_main_t *im6 = &ip6_main;
2465 ip_lookup_main_t *lm;
2471 u32 adj_index, sw_if_index;
2472 vl_api_is_address_reachable_t *rmp;
2473 ip_adjacency_t *adj;
2474 unix_shared_memory_queue_t *q;
2476 q = vl_api_client_index_to_input_queue (mp->client_index);
2479 increment_missing_api_client_counter (rm->vlib_main);
2483 rmp = vl_msg_api_alloc (sizeof (*rmp));
2484 clib_memcpy (rmp, mp, sizeof (*rmp));
2486 sw_if_index = mp->next_hop_sw_if_index;
2487 clib_memcpy (&addr, mp->address, sizeof (addr));
2490 lm = &im6->lookup_main;
2491 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2495 lm = &im4->lookup_main;
2497 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2499 if (adj_index == ~0)
2504 adj = ip_get_adjacency (lm, adj_index);
2506 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2507 && adj->rewrite_header.sw_if_index == sw_if_index)
2513 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2514 && adj->rewrite_header.sw_if_index == sw_if_index)
2517 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2519 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2521 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2530 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2535 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2537 clib_warning ("BUG");
2541 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2543 vl_api_sw_interface_set_flags_reply_t *rmp;
2544 vnet_main_t *vnm = vnet_get_main ();
2546 clib_error_t *error;
2549 VALIDATE_SW_IF_INDEX (mp);
2551 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2553 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2557 clib_error_report (error);
2560 BAD_SW_IF_INDEX_LABEL;
2561 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2565 vl_api_sw_interface_set_mpls_enable_t_handler
2566 (vl_api_sw_interface_set_mpls_enable_t * mp)
2568 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2571 VALIDATE_SW_IF_INDEX (mp);
2573 mpls_sw_interface_enable_disable (&mpls_main,
2574 ntohl (mp->sw_if_index), mp->enable);
2576 BAD_SW_IF_INDEX_LABEL;
2577 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2581 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2584 vl_api_sw_interface_clear_stats_reply_t *rmp;
2586 vnet_main_t *vnm = vnet_get_main ();
2587 vnet_interface_main_t *im = &vnm->interface_main;
2588 vlib_simple_counter_main_t *sm;
2589 vlib_combined_counter_main_t *cm;
2590 static vnet_main_t **my_vnet_mains;
2591 int i, j, n_counters;
2594 if (mp->sw_if_index != ~0)
2595 VALIDATE_SW_IF_INDEX (mp);
2597 vec_reset_length (my_vnet_mains);
2599 for (i = 0; i < vec_len (vnet_mains); i++)
2602 vec_add1 (my_vnet_mains, vnet_mains[i]);
2605 if (vec_len (vnet_mains) == 0)
2606 vec_add1 (my_vnet_mains, vnm);
2608 n_counters = vec_len (im->combined_sw_if_counters);
2610 for (j = 0; j < n_counters; j++)
2612 for (i = 0; i < vec_len (my_vnet_mains); i++)
2614 im = &my_vnet_mains[i]->interface_main;
2615 cm = im->combined_sw_if_counters + j;
2616 if (mp->sw_if_index == (u32) ~ 0)
2617 vlib_clear_combined_counters (cm);
2619 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2623 n_counters = vec_len (im->sw_if_counters);
2625 for (j = 0; j < n_counters; j++)
2627 for (i = 0; i < vec_len (my_vnet_mains); i++)
2629 im = &my_vnet_mains[i]->interface_main;
2630 sm = im->sw_if_counters + j;
2631 if (mp->sw_if_index == (u32) ~ 0)
2632 vlib_clear_simple_counters (sm);
2634 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2638 BAD_SW_IF_INDEX_LABEL;
2640 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2644 send_sw_interface_details (vpe_api_main_t * am,
2645 unix_shared_memory_queue_t * q,
2646 vnet_sw_interface_t * swif,
2647 u8 * interface_name, u32 context)
2649 vl_api_sw_interface_details_t *mp;
2650 vnet_hw_interface_t *hi;
2652 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2654 mp = vl_msg_api_alloc (sizeof (*mp));
2655 memset (mp, 0, sizeof (*mp));
2656 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2657 mp->sw_if_index = ntohl (swif->sw_if_index);
2658 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2659 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2660 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2661 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2662 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2663 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2664 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2665 mp->link_mtu = ntohs (hi->max_packet_bytes);
2666 mp->context = context;
2668 strncpy ((char *) mp->interface_name,
2669 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2671 /* Send the L2 address for ethernet physical intfcs */
2672 if (swif->sup_sw_if_index == swif->sw_if_index
2673 && hi->hw_class_index == ethernet_hw_interface_class.index)
2675 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2676 ethernet_interface_t *ei;
2678 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2679 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2680 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2681 mp->l2_address_length = ntohl (sizeof (ei->address));
2683 else if (swif->sup_sw_if_index != swif->sw_if_index)
2685 vnet_sub_interface_t *sub = &swif->sub;
2686 mp->sub_id = ntohl (sub->id);
2687 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2688 mp->sub_number_of_tags =
2689 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2690 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2691 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2692 mp->sub_exact_match = sub->eth.flags.exact_match;
2693 mp->sub_default = sub->eth.flags.default_sub;
2694 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2695 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2697 /* vlan tag rewrite data */
2698 u32 vtr_op = L2_VTR_DISABLED;
2699 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2701 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2702 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2704 // error - default to disabled
2705 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2706 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2711 mp->vtr_op = ntohl (vtr_op);
2712 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2713 mp->vtr_tag1 = ntohl (vtr_tag1);
2714 mp->vtr_tag2 = ntohl (vtr_tag2);
2718 vl_msg_api_send_shmem (q, (u8 *) & mp);
2722 send_sw_interface_flags (vpe_api_main_t * am,
2723 unix_shared_memory_queue_t * q,
2724 vnet_sw_interface_t * swif)
2726 vl_api_sw_interface_set_flags_t *mp;
2727 vnet_main_t *vnm = am->vnet_main;
2729 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2731 mp = vl_msg_api_alloc (sizeof (*mp));
2732 memset (mp, 0, sizeof (*mp));
2733 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2734 mp->sw_if_index = ntohl (swif->sw_if_index);
2736 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2737 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2738 vl_msg_api_send_shmem (q, (u8 *) & mp);
2741 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2742 unix_shared_memory_queue_t * q,
2744 __attribute__ ((unused));
2747 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2748 unix_shared_memory_queue_t * q,
2751 vl_api_sw_interface_set_flags_t *mp;
2753 mp = vl_msg_api_alloc (sizeof (*mp));
2754 memset (mp, 0, sizeof (*mp));
2755 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2756 mp->sw_if_index = ntohl (sw_if_index);
2758 mp->admin_up_down = 0;
2759 mp->link_up_down = 0;
2761 vl_msg_api_send_shmem (q, (u8 *) & mp);
2765 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2767 vpe_api_main_t *am = &vpe_api_main;
2768 vnet_sw_interface_t *swif;
2769 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2770 u8 *filter_string = 0, *name_string = 0;
2771 unix_shared_memory_queue_t *q;
2772 char *strcasestr (char *, char *); /* lnx hdr file botch */
2774 q = vl_api_client_index_to_input_queue (mp->client_index);
2779 if (mp->name_filter_valid)
2781 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2782 filter_string = format (0, "%s%c", mp->name_filter, 0);
2786 pool_foreach (swif, im->sw_interfaces,
2788 name_string = format (name_string, "%U%c",
2789 format_vnet_sw_interface_name,
2790 am->vnet_main, swif, 0);
2792 if (mp->name_filter_valid == 0 ||
2793 strcasestr((char *) name_string, (char *) filter_string)) {
2795 send_sw_interface_details (am, q, swif, name_string, mp->context);
2797 _vec_len (name_string) = 0;
2801 vec_free (name_string);
2802 vec_free (filter_string);
2806 send_oam_event (oam_target_t * t)
2808 vpe_api_main_t *vam = &vpe_api_main;
2809 unix_shared_memory_queue_t *q;
2810 vpe_client_registration_t *reg;
2811 vl_api_oam_event_t *mp;
2814 pool_foreach(reg, vam->oam_events_registrations,
2816 q = vl_api_client_index_to_input_queue (reg->client_index);
2819 mp = vl_msg_api_alloc (sizeof (*mp));
2820 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2821 clib_memcpy (mp->dst_address, &t->dst_address,
2822 sizeof (mp->dst_address));
2823 mp->state = t->state;
2824 vl_msg_api_send_shmem (q, (u8 *)&mp);
2831 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2833 vl_api_oam_add_del_reply_t *rmp;
2836 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2837 (ip4_address_t *) mp->dst_address,
2838 ntohl (mp->vrf_id), (int) (mp->is_add));
2840 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2844 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2846 stats_main_t *sm = &stats_main;
2847 vnet_interface_main_t *im = sm->interface_main;
2848 vl_api_vnet_summary_stats_reply_t *rmp;
2849 vlib_combined_counter_main_t *cm;
2852 u64 total_pkts[VLIB_N_RX_TX];
2853 u64 total_bytes[VLIB_N_RX_TX];
2855 unix_shared_memory_queue_t *q =
2856 vl_api_client_index_to_input_queue (mp->client_index);
2861 rmp = vl_msg_api_alloc (sizeof (*rmp));
2862 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2863 rmp->context = mp->context;
2866 memset (total_pkts, 0, sizeof (total_pkts));
2867 memset (total_bytes, 0, sizeof (total_bytes));
2869 vnet_interface_counter_lock (im);
2871 vec_foreach (cm, im->combined_sw_if_counters)
2873 which = cm - im->combined_sw_if_counters;
2875 for (i = 0; i < vec_len (cm->maxi); i++)
2877 vlib_get_combined_counter (cm, i, &v);
2878 total_pkts[which] += v.packets;
2879 total_bytes[which] += v.bytes;
2882 vnet_interface_counter_unlock (im);
2884 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2885 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2886 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2887 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2889 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2891 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2895 typedef CLIB_PACKED (struct {
2896 ip4_address_t address;
2897 u32 address_length: 6;
2903 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2905 vnet_main_t *vnm = vnet_get_main ();
2906 vnet_interface_main_t *im = &vnm->interface_main;
2907 ip4_main_t *im4 = &ip4_main;
2908 static u32 *sw_if_indices_to_shut;
2909 stats_main_t *sm = &stats_main;
2910 fib_table_t *fib_table;
2914 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2915 u32 target_fib_id = ntohl (mp->vrf_id);
2917 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2920 pool_foreach (fib_table, im4->fibs,
2922 fib = &fib_table->v4;
2923 vnet_sw_interface_t * si;
2925 if (fib->table_id != target_fib_id)
2928 /* remove any mpls/gre tunnels in this fib */
2929 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2931 /* remove any mpls encap/decap labels */
2932 mpls_fib_reset_labels (fib->table_id);
2934 /* remove any proxy arps in this fib */
2935 vnet_proxy_arp_fib_reset (fib->table_id);
2937 /* Set the flow hash for this fib to the default */
2938 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2940 vec_reset_length (sw_if_indices_to_shut);
2942 /* Shut down interfaces in this FIB / clean out intfc routes */
2943 pool_foreach (si, im->sw_interfaces,
2945 u32 sw_if_index = si->sw_if_index;
2947 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2948 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2950 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2953 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2954 sw_if_index = sw_if_indices_to_shut[i];
2955 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2957 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2958 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2959 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2962 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
2963 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
2967 })); /* pool_foreach (fib) */
2975 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2977 vnet_main_t *vnm = vnet_get_main ();
2978 vnet_interface_main_t *im = &vnm->interface_main;
2979 ip6_main_t *im6 = &ip6_main;
2980 stats_main_t *sm = &stats_main;
2981 static u32 *sw_if_indices_to_shut;
2982 fib_table_t *fib_table;
2986 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2987 u32 target_fib_id = ntohl (mp->vrf_id);
2989 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
2992 pool_foreach (fib_table, im6->fibs,
2994 vnet_sw_interface_t * si;
2995 fib = &(fib_table->v6);
2997 if (fib->table_id != target_fib_id)
3000 vec_reset_length (sw_if_indices_to_shut);
3002 /* Shut down interfaces in this FIB / clean out intfc routes */
3003 pool_foreach (si, im->sw_interfaces,
3005 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3007 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3010 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3011 sw_if_index = sw_if_indices_to_shut[i];
3012 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3014 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3015 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3016 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3019 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
3020 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
3024 })); /* pool_foreach (fib) */
3032 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3035 vl_api_reset_fib_reply_t *rmp;
3038 rv = ip6_reset_fib_t_handler (mp);
3040 rv = ip4_reset_fib_t_handler (mp);
3042 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3047 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3049 vl_api_dhcp_proxy_config_reply_t *rmp;
3052 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3053 (ip4_address_t *) (&mp->dhcp_src_address),
3054 (u32) ntohl (mp->vrf_id),
3055 (int) mp->insert_circuit_id,
3056 (int) (mp->is_add == 0));
3058 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3063 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3065 vl_api_dhcp_proxy_config_reply_t *rmp;
3068 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3069 (ip6_address_t *) (&mp->dhcp_src_address),
3070 (u32) ntohl (mp->vrf_id),
3071 (int) mp->insert_circuit_id,
3072 (int) (mp->is_add == 0));
3074 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3078 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3080 vl_api_dhcp_proxy_config_reply_t *rmp;
3083 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3084 (ip4_address_t *) (&mp->dhcp_src_address),
3085 (u32) ntohl (mp->rx_vrf_id),
3086 (u32) ntohl (mp->server_vrf_id),
3087 (int) mp->insert_circuit_id,
3088 (int) (mp->is_add == 0));
3090 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3095 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3097 vl_api_dhcp_proxy_config_reply_t *rmp;
3101 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3102 (ip6_address_t *) (&mp->dhcp_src_address),
3103 (u32) ntohl (mp->rx_vrf_id),
3104 (u32) ntohl (mp->server_vrf_id),
3105 (int) mp->insert_circuit_id,
3106 (int) (mp->is_add == 0));
3108 rv = VNET_API_ERROR_UNIMPLEMENTED;
3111 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3116 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3118 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3121 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3124 (int) mp->is_add == 0);
3126 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3128 ntohl (mp->fib_id), (int) mp->is_add == 0);
3130 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3134 static void vl_api_dhcp_proxy_config_t_handler
3135 (vl_api_dhcp_proxy_config_t * mp)
3137 if (mp->is_ipv6 == 0)
3138 dhcpv4_proxy_config (mp);
3140 dhcpv6_proxy_config (mp);
3143 static void vl_api_dhcp_proxy_config_2_t_handler
3144 (vl_api_dhcp_proxy_config_2_t * mp)
3146 if (mp->is_ipv6 == 0)
3147 dhcpv4_proxy_config_2 (mp);
3149 dhcpv6_proxy_config_2 (mp);
3153 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3154 u8 is_ipv6, u8 * host_address, u8 * router_address,
3157 unix_shared_memory_queue_t *q;
3158 vl_api_dhcp_compl_event_t *mp;
3160 q = vl_api_client_index_to_input_queue (client_index);
3164 mp = vl_msg_api_alloc (sizeof (*mp));
3165 mp->client_index = client_index;
3167 mp->is_ipv6 = is_ipv6;
3168 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3169 mp->hostname[vec_len (hostname) + 1] = '\n';
3170 clib_memcpy (&mp->host_address[0], host_address, 16);
3171 clib_memcpy (&mp->router_address[0], router_address, 16);
3172 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3174 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3176 vl_msg_api_send_shmem (q, (u8 *) & mp);
3179 static void vl_api_dhcp_client_config_t_handler
3180 (vl_api_dhcp_client_config_t * mp)
3182 vlib_main_t *vm = vlib_get_main ();
3183 vl_api_dhcp_client_config_reply_t *rmp;
3186 VALIDATE_SW_IF_INDEX (mp);
3188 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3189 mp->hostname, mp->is_add, mp->client_index,
3190 mp->want_dhcp_event ? dhcp_compl_event_callback :
3193 BAD_SW_IF_INDEX_LABEL;
3195 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3199 vl_api_sw_interface_ip6nd_ra_config_t_handler
3200 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3202 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3204 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3207 is_no = mp->is_no == 1;
3208 suppress = mp->suppress == 1;
3209 managed = mp->managed == 1;
3210 other = mp->other == 1;
3211 ll_option = mp->ll_option == 1;
3212 send_unicast = mp->send_unicast == 1;
3213 cease = mp->cease == 1;
3214 default_router = mp->default_router == 1;
3216 VALIDATE_SW_IF_INDEX (mp);
3218 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3219 suppress, managed, other,
3220 ll_option, send_unicast, cease,
3221 default_router, ntohl (mp->lifetime),
3222 ntohl (mp->initial_count),
3223 ntohl (mp->initial_interval),
3224 ntohl (mp->max_interval),
3225 ntohl (mp->min_interval), is_no);
3227 BAD_SW_IF_INDEX_LABEL;
3229 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3233 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3234 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3236 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3238 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3240 VALIDATE_SW_IF_INDEX (mp);
3242 is_no = mp->is_no == 1;
3243 use_default = mp->use_default == 1;
3244 no_advertise = mp->no_advertise == 1;
3245 off_link = mp->off_link == 1;
3246 no_autoconfig = mp->no_autoconfig == 1;
3247 no_onlink = mp->no_onlink == 1;
3249 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3250 (ip6_address_t *) mp->address,
3251 mp->address_length, use_default,
3252 ntohl (mp->val_lifetime),
3253 ntohl (mp->pref_lifetime), no_advertise,
3254 off_link, no_autoconfig, no_onlink, is_no);
3256 BAD_SW_IF_INDEX_LABEL;
3257 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3261 vl_api_sw_interface_ip6_enable_disable_t_handler
3262 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3264 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3265 vnet_main_t *vnm = vnet_get_main ();
3267 clib_error_t *error;
3271 VALIDATE_SW_IF_INDEX (mp);
3274 (mp->enable == 1) ? enable_ip6_interface (vm,
3275 ntohl (mp->sw_if_index)) :
3276 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3280 clib_error_report (error);
3281 rv = VNET_API_ERROR_UNSPECIFIED;
3285 rv = vnm->api_errno;
3288 BAD_SW_IF_INDEX_LABEL;
3290 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3294 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3295 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3297 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3299 clib_error_t *error;
3300 vnet_main_t *vnm = vnet_get_main ();
3304 VALIDATE_SW_IF_INDEX (mp);
3306 error = set_ip6_link_local_address (vm,
3307 ntohl (mp->sw_if_index),
3308 (ip6_address_t *) mp->address,
3309 mp->address_length);
3312 clib_error_report (error);
3313 rv = VNET_API_ERROR_UNSPECIFIED;
3317 rv = vnm->api_errno;
3320 BAD_SW_IF_INDEX_LABEL;
3322 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3326 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3328 vl_api_set_ip_flow_hash_reply_t *rmp;
3329 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3331 clib_warning ("unimplemented...");
3333 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3337 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3339 vl_api_set_ip_flow_hash_reply_t *rmp;
3342 flow_hash_config_t flow_hash_config = 0;
3344 table_id = ntohl (mp->vrf_id);
3346 #define _(a,b) if (mp->a) flow_hash_config |= b;
3347 foreach_flow_hash_bit;
3350 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3352 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3357 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3359 if (mp->is_ipv6 == 0)
3360 set_ip4_flow_hash (mp);
3362 set_ip6_flow_hash (mp);
3365 static void vl_api_sw_interface_set_unnumbered_t_handler
3366 (vl_api_sw_interface_set_unnumbered_t * mp)
3368 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3370 vnet_sw_interface_t *si;
3371 vnet_main_t *vnm = vnet_get_main ();
3372 u32 sw_if_index, unnumbered_sw_if_index;
3374 sw_if_index = ntohl (mp->sw_if_index);
3375 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3378 * The API message field names are backwards from
3379 * the underlying data structure names.
3380 * It's not worth changing them now.
3382 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3383 unnumbered_sw_if_index))
3385 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3389 /* Only check the "use loop0" field when setting the binding */
3391 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3393 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3397 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3401 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3402 si->unnumbered_sw_if_index = sw_if_index;
3403 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3404 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3408 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3409 si->unnumbered_sw_if_index = (u32) ~ 0;
3410 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3411 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3415 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3419 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3421 vl_api_create_loopback_reply_t *rmp;
3425 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3428 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3430 rmp->sw_if_index = ntohl (sw_if_index);
3436 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3438 vl_api_delete_loopback_reply_t *rmp;
3442 sw_if_index = ntohl (mp->sw_if_index);
3443 rv = vnet_delete_loopback_interface (sw_if_index);
3445 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3449 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3451 vl_api_control_ping_reply_t *rmp;
3455 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3457 rmp->vpe_pid = ntohl (getpid());
3463 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3465 u8 **shmem_vecp = (u8 **) arg;
3468 api_main_t *am = &api_main;
3471 shmem_vec = *shmem_vecp;
3473 offset = vec_len (shmem_vec);
3475 pthread_mutex_lock (&am->vlib_rp->mutex);
3476 oldheap = svm_push_data_heap (am->vlib_rp);
3478 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3480 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3482 svm_pop_heap (oldheap);
3483 pthread_mutex_unlock (&am->vlib_rp->mutex);
3485 *shmem_vecp = shmem_vec;
3490 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3492 vl_api_cli_reply_t *rp;
3493 unix_shared_memory_queue_t *q;
3494 vlib_main_t *vm = vlib_get_main ();
3495 api_main_t *am = &api_main;
3496 unformat_input_t input;
3500 q = vl_api_client_index_to_input_queue (mp->client_index);
3504 rp = vl_msg_api_alloc (sizeof (*rp));
3505 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3506 rp->context = mp->context;
3508 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3510 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3512 pthread_mutex_lock (&am->vlib_rp->mutex);
3513 oldheap = svm_push_data_heap (am->vlib_rp);
3515 vec_add1 (shmem_vec, 0);
3517 svm_pop_heap (oldheap);
3518 pthread_mutex_unlock (&am->vlib_rp->mutex);
3520 rp->reply_in_shmem = (uword) shmem_vec;
3522 vl_msg_api_send_shmem (q, (u8 *) & rp);
3526 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3528 u8 **mem_vecp = (u8 **) arg;
3529 u8 *mem_vec = *mem_vecp;
3530 u32 offset = vec_len (mem_vec);
3532 vec_validate (mem_vec, offset + buffer_bytes - 1);
3533 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3534 *mem_vecp = mem_vec;
3538 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3540 vl_api_cli_inband_reply_t *rmp;
3542 unix_shared_memory_queue_t *q;
3543 vlib_main_t *vm = vlib_get_main ();
3544 unformat_input_t input;
3547 q = vl_api_client_index_to_input_queue (mp->client_index);
3551 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3552 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3554 u32 len = vec_len (out_vec);
3556 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3558 rmp->length = htonl (len);
3559 clib_memcpy (rmp->reply, out_vec, len);
3566 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3569 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3570 vnet_main_t *vnm = vnet_get_main ();
3571 clib_error_t *error;
3576 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3578 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3582 clib_error_report (error);
3583 rv = VNET_API_ERROR_UNSPECIFIED;
3587 rv = vnm->api_errno;
3590 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3593 static void vl_api_sr_tunnel_add_del_t_handler
3594 (vl_api_sr_tunnel_add_del_t * mp)
3597 clib_warning ("unimplemented");
3599 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3601 vl_api_sr_tunnel_add_del_reply_t *rmp;
3602 ip6_address_t *segments = 0, *seg;
3603 ip6_address_t *tags = 0, *tag;
3604 ip6_address_t *this_address;
3607 if (mp->n_segments == 0)
3613 memset (a, 0, sizeof (*a));
3614 a->src_address = (ip6_address_t *) & mp->src_address;
3615 a->dst_address = (ip6_address_t *) & mp->dst_address;
3616 a->dst_mask_width = mp->dst_mask_width;
3617 a->flags_net_byte_order = mp->flags_net_byte_order;
3618 a->is_del = (mp->is_add == 0);
3619 a->rx_table_id = ntohl (mp->outer_vrf_id);
3620 a->tx_table_id = ntohl (mp->inner_vrf_id);
3622 a->name = format (0, "%s", mp->name);
3623 if (!(vec_len (a->name)))
3626 a->policy_name = format (0, "%s", mp->policy_name);
3627 if (!(vec_len (a->policy_name)))
3630 /* Yank segments and tags out of the API message */
3631 this_address = (ip6_address_t *) mp->segs_and_tags;
3632 for (i = 0; i < mp->n_segments; i++)
3634 vec_add2 (segments, seg, 1);
3635 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3638 for (i = 0; i < mp->n_tags; i++)
3640 vec_add2 (tags, tag, 1);
3641 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3645 a->segments = segments;
3648 rv = ip6_sr_add_del_tunnel (a);
3652 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3656 static void vl_api_sr_policy_add_del_t_handler
3657 (vl_api_sr_policy_add_del_t * mp)
3660 clib_warning ("unimplemented");
3662 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3664 vl_api_sr_policy_add_del_reply_t *rmp;
3667 memset (a, 0, sizeof (*a));
3668 a->is_del = (mp->is_add == 0);
3670 a->name = format (0, "%s", mp->name);
3671 if (!(vec_len (a->name)))
3673 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3677 if (!(mp->tunnel_names[0]))
3679 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3683 // start deserializing tunnel_names
3684 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3685 u8 *deser_tun_names = mp->tunnel_names;
3686 deser_tun_names += 1; //moving along
3689 int tun_name_len = 0;
3691 for (i = 0; i < num_tunnels; i++)
3693 tun_name_len = *deser_tun_names;
3694 deser_tun_names += 1;
3695 vec_resize (tun_name, tun_name_len);
3696 memcpy (tun_name, deser_tun_names, tun_name_len);
3697 vec_add1 (a->tunnel_names, tun_name);
3698 deser_tun_names += tun_name_len;
3702 rv = ip6_sr_add_del_policy (a);
3706 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3710 static void vl_api_sr_multicast_map_add_del_t_handler
3711 (vl_api_sr_multicast_map_add_del_t * mp)
3714 clib_warning ("unimplemented");
3716 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3718 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3720 memset (a, 0, sizeof (*a));
3721 a->is_del = (mp->is_add == 0);
3723 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3724 a->policy_name = format (0, "%s", mp->policy_name);
3726 if (a->multicast_address == 0)
3732 if (!(a->policy_name))
3738 #if DPDK > 0 /* Cannot call replicate without DPDK */
3739 rv = ip6_sr_add_del_multicastmap (a);
3741 clib_warning ("multicast replication without DPDK not implemented");
3742 rv = VNET_API_ERROR_UNIMPLEMENTED;
3747 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3751 #define foreach_classify_add_del_table_field \
3756 _(match_n_vectors) \
3757 _(next_table_index) \
3760 static void vl_api_classify_add_del_table_t_handler
3761 (vl_api_classify_add_del_table_t * mp)
3763 vl_api_classify_add_del_table_reply_t *rmp;
3764 vnet_classify_main_t *cm = &vnet_classify_main;
3765 vnet_classify_table_t *t;
3769 foreach_classify_add_del_table_field;
3772 #define _(a) a = ntohl(mp->a);
3773 foreach_classify_add_del_table_field;
3776 /* The underlying API fails silently, on purpose, so check here */
3777 if (mp->is_add == 0)
3778 if (pool_is_free_index (cm->tables, table_index))
3780 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3784 rv = vnet_classify_add_del_table
3785 (cm, mp->mask, nbuckets, memory_size,
3786 skip_n_vectors, match_n_vectors,
3787 next_table_index, miss_next_index, &table_index, mp->is_add);
3791 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3793 if (rv == 0 && mp->is_add)
3795 t = pool_elt_at_index (cm->tables, table_index);
3796 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3797 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3798 rmp->new_table_index = ntohl(table_index);
3802 rmp->skip_n_vectors = ~0;
3803 rmp->match_n_vectors = ~0;
3804 rmp->new_table_index = ~0;
3810 static void vl_api_classify_add_del_session_t_handler
3811 (vl_api_classify_add_del_session_t * mp)
3813 vnet_classify_main_t *cm = &vnet_classify_main;
3814 vl_api_classify_add_del_session_reply_t *rmp;
3816 u32 table_index, hit_next_index, opaque_index;
3819 table_index = ntohl (mp->table_index);
3820 hit_next_index = ntohl (mp->hit_next_index);
3821 opaque_index = ntohl (mp->opaque_index);
3822 advance = ntohl (mp->advance);
3824 rv = vnet_classify_add_del_session
3825 (cm, table_index, mp->match, hit_next_index, opaque_index,
3826 advance, mp->is_add);
3828 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3831 static void vl_api_classify_set_interface_ip_table_t_handler
3832 (vl_api_classify_set_interface_ip_table_t * mp)
3834 vlib_main_t *vm = vlib_get_main ();
3835 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3837 u32 table_index, sw_if_index;
3839 table_index = ntohl (mp->table_index);
3840 sw_if_index = ntohl (mp->sw_if_index);
3842 VALIDATE_SW_IF_INDEX (mp);
3845 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3847 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3849 BAD_SW_IF_INDEX_LABEL;
3851 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3854 static void vl_api_classify_set_interface_l2_tables_t_handler
3855 (vl_api_classify_set_interface_l2_tables_t * mp)
3857 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3859 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3862 ip4_table_index = ntohl (mp->ip4_table_index);
3863 ip6_table_index = ntohl (mp->ip6_table_index);
3864 other_table_index = ntohl (mp->other_table_index);
3865 sw_if_index = ntohl (mp->sw_if_index);
3867 VALIDATE_SW_IF_INDEX (mp);
3870 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
3874 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
3880 if (ip4_table_index != ~0 || ip6_table_index != ~0
3881 || other_table_index != ~0)
3887 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
3889 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
3892 BAD_SW_IF_INDEX_LABEL;
3894 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3898 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3901 vl_api_l2_fib_clear_table_reply_t *rmp;
3903 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3904 * that is not currently implemented. When that TODO is fixed
3905 * this call should be changed to pass 1 instead of 0.
3907 l2fib_clear_table (0);
3909 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3912 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3913 u32 sw_if_index, u32 enable);
3916 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3920 vl_api_l2_interface_efp_filter_reply_t *rmp;
3921 vnet_main_t *vnm = vnet_get_main ();
3923 // enable/disable the feature
3924 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3925 rv = vnm->api_errno;
3927 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3931 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3932 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3935 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3936 vnet_main_t *vnm = vnet_get_main ();
3937 vlib_main_t *vm = vlib_get_main ();
3940 VALIDATE_SW_IF_INDEX (mp);
3942 vtr_op = ntohl (mp->vtr_op);
3944 /* The L2 code is unsuspicious */
3947 case L2_VTR_DISABLED:
3952 case L2_VTR_TRANSLATE_1_1:
3953 case L2_VTR_TRANSLATE_1_2:
3954 case L2_VTR_TRANSLATE_2_1:
3955 case L2_VTR_TRANSLATE_2_2:
3959 rv = VNET_API_ERROR_INVALID_VALUE;
3960 goto bad_sw_if_index;
3963 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
3964 ntohl (mp->push_dot1q), ntohl (mp->tag1),
3967 BAD_SW_IF_INDEX_LABEL;
3969 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3973 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
3976 vl_api_create_vhost_user_if_reply_t *rmp;
3977 u32 sw_if_index = (u32) ~ 0;
3979 vnet_main_t *vnm = vnet_get_main ();
3980 vlib_main_t *vm = vlib_get_main ();
3982 #if DPDK > 0 && DPDK_VHOST_USER
3983 rv = dpdk_vhost_user_create_if (
3985 rv = vhost_user_create_if (
3987 vnm, vm, (char *) mp->sock_filename,
3988 mp->is_server, &sw_if_index, (u64) ~ 0,
3989 mp->renumber, ntohl (mp->custom_dev_instance),
3990 (mp->use_custom_mac) ? mp->mac_address : NULL);
3993 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3995 rmp->sw_if_index = ntohl (sw_if_index);
4001 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4004 vl_api_modify_vhost_user_if_reply_t *rmp;
4005 u32 sw_if_index = ntohl (mp->sw_if_index);
4007 vnet_main_t *vnm = vnet_get_main ();
4008 vlib_main_t *vm = vlib_get_main ();
4010 #if DPDK > 0 && DPDK_VHOST_USER
4011 rv = dpdk_vhost_user_modify_if (
4013 rv = vhost_user_modify_if (
4015 vnm, vm, (char *) mp->sock_filename,
4016 mp->is_server, sw_if_index, (u64) ~ 0,
4017 mp->renumber, ntohl (mp->custom_dev_instance));
4018 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4022 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4025 vl_api_delete_vhost_user_if_reply_t *rmp;
4026 vpe_api_main_t *vam = &vpe_api_main;
4027 u32 sw_if_index = ntohl (mp->sw_if_index);
4029 vnet_main_t *vnm = vnet_get_main ();
4030 vlib_main_t *vm = vlib_get_main ();
4032 #if DPDK > 0 && DPDK_VHOST_USER
4033 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4035 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4038 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4041 unix_shared_memory_queue_t *q =
4042 vl_api_client_index_to_input_queue (mp->client_index);
4046 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4051 vl_api_sw_interface_vhost_user_details_t_handler
4052 (vl_api_sw_interface_vhost_user_details_t * mp)
4054 clib_warning ("BUG");
4058 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4059 unix_shared_memory_queue_t * q,
4060 vhost_user_intf_details_t * vui,
4063 vl_api_sw_interface_vhost_user_details_t *mp;
4065 mp = vl_msg_api_alloc (sizeof (*mp));
4066 memset (mp, 0, sizeof (*mp));
4067 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4068 mp->sw_if_index = ntohl (vui->sw_if_index);
4069 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4070 mp->features = clib_net_to_host_u64 (vui->features);
4071 mp->is_server = vui->is_server;
4072 mp->num_regions = ntohl (vui->num_regions);
4073 mp->sock_errno = ntohl (vui->sock_errno);
4074 mp->context = context;
4076 strncpy ((char *) mp->sock_filename,
4077 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4078 strncpy ((char *) mp->interface_name,
4079 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4081 vl_msg_api_send_shmem (q, (u8 *) & mp);
4085 vl_api_sw_interface_vhost_user_dump_t_handler
4086 (vl_api_sw_interface_vhost_user_dump_t * mp)
4089 vpe_api_main_t *am = &vpe_api_main;
4090 vnet_main_t *vnm = vnet_get_main ();
4091 vlib_main_t *vm = vlib_get_main ();
4092 vhost_user_intf_details_t *ifaces = NULL;
4093 vhost_user_intf_details_t *vuid = NULL;
4094 unix_shared_memory_queue_t *q;
4096 q = vl_api_client_index_to_input_queue (mp->client_index);
4100 #if DPDK > 0 && DPDK_VHOST_USER
4101 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4103 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4108 vec_foreach (vuid, ifaces)
4110 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4116 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4117 unix_shared_memory_queue_t * q,
4119 l2t_main_t * lm, u32 context)
4121 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4123 vnet_sw_interface_t *si = NULL;
4125 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4127 if_name = format (if_name, "%U",
4128 format_vnet_sw_interface_name, lm->vnet_main, si);
4130 mp = vl_msg_api_alloc (sizeof (*mp));
4131 memset (mp, 0, sizeof (*mp));
4132 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4133 strncpy ((char *) mp->interface_name,
4134 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4135 mp->sw_if_index = ntohl (si->sw_if_index);
4136 mp->local_session_id = s->local_session_id;
4137 mp->remote_session_id = s->remote_session_id;
4138 mp->local_cookie[0] = s->local_cookie[0];
4139 mp->local_cookie[1] = s->local_cookie[1];
4140 mp->remote_cookie = s->remote_cookie;
4141 clib_memcpy (mp->client_address, &s->client_address,
4142 sizeof (s->client_address));
4143 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4144 mp->l2_sublayer_present = s->l2_sublayer_present;
4145 mp->context = context;
4147 vl_msg_api_send_shmem (q, (u8 *) & mp);
4151 send_ip_address_details (vpe_api_main_t * am,
4152 unix_shared_memory_queue_t * q,
4153 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4155 vl_api_ip_address_details_t *mp;
4157 mp = vl_msg_api_alloc (sizeof (*mp));
4158 memset (mp, 0, sizeof (*mp));
4159 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4163 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4167 u32 *tp = (u32 *) mp->ip;
4168 *tp = ntohl (*(u32 *) ip);
4170 mp->prefix_length = prefix_length;
4171 mp->context = context;
4173 vl_msg_api_send_shmem (q, (u8 *) & mp);
4177 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4179 vpe_api_main_t *am = &vpe_api_main;
4180 unix_shared_memory_queue_t *q;
4183 ip6_main_t *im6 = &ip6_main;
4184 ip4_main_t *im4 = &ip4_main;
4185 ip_lookup_main_t *lm6 = &im6->lookup_main;
4186 ip_lookup_main_t *lm4 = &im4->lookup_main;
4187 ip_interface_address_t *ia = 0;
4188 u32 sw_if_index = ~0;
4189 int rv __attribute__ ((unused)) = 0;
4191 VALIDATE_SW_IF_INDEX (mp);
4193 sw_if_index = ntohl (mp->sw_if_index);
4195 q = vl_api_client_index_to_input_queue (mp->client_index);
4204 foreach_ip_interface_address (lm6, ia, sw_if_index,
4205 1 /* honor unnumbered */,
4207 r6 = ip_interface_address_get_address (lm6, ia);
4208 u16 prefix_length = ia->address_length;
4209 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4216 foreach_ip_interface_address (lm4, ia, sw_if_index,
4217 1 /* honor unnumbered */,
4219 r4 = ip_interface_address_get_address (lm4, ia);
4220 u16 prefix_length = ia->address_length;
4221 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4225 BAD_SW_IF_INDEX_LABEL;
4229 send_ip_details (vpe_api_main_t * am,
4230 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4232 vl_api_ip_details_t *mp;
4234 mp = vl_msg_api_alloc (sizeof (*mp));
4235 memset (mp, 0, sizeof (*mp));
4236 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4238 mp->sw_if_index = ntohl (sw_if_index);
4239 mp->context = context;
4241 vl_msg_api_send_shmem (q, (u8 *) & mp);
4245 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4248 vpe_api_main_t *am = &vpe_api_main;
4249 l2t_main_t *lm = &l2t_main;
4250 unix_shared_memory_queue_t *q;
4251 l2t_session_t *session;
4253 q = vl_api_client_index_to_input_queue (mp->client_index);
4258 pool_foreach (session, lm->sessions,
4260 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4267 send_sw_interface_tap_details (vpe_api_main_t * am,
4268 unix_shared_memory_queue_t * q,
4269 tapcli_interface_details_t * tap_if,
4272 vl_api_sw_interface_tap_details_t *mp;
4273 mp = vl_msg_api_alloc (sizeof (*mp));
4274 memset (mp, 0, sizeof (*mp));
4275 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4276 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4277 strncpy ((char *) mp->dev_name,
4278 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4279 mp->context = context;
4281 vl_msg_api_send_shmem (q, (u8 *) & mp);
4285 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4288 vpe_api_main_t *am = &vpe_api_main;
4289 unix_shared_memory_queue_t *q;
4290 tapcli_interface_details_t *tapifs = NULL;
4291 tapcli_interface_details_t *tap_if = NULL;
4293 q = vl_api_client_index_to_input_queue (mp->client_index);
4297 rv = vnet_tap_dump_ifs (&tapifs);
4301 vec_foreach (tap_if, tapifs)
4303 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4310 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4312 vpe_api_main_t *am = &vpe_api_main;
4313 vnet_main_t *vnm = vnet_get_main ();
4314 vlib_main_t *vm = vlib_get_main ();
4315 vnet_interface_main_t *im = &vnm->interface_main;
4316 unix_shared_memory_queue_t *q;
4317 vnet_sw_interface_t *si, *sorted_sis;
4318 u32 sw_if_index = ~0;
4320 q = vl_api_client_index_to_input_queue (mp->client_index);
4326 /* Gather interfaces. */
4327 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4328 _vec_len (sorted_sis) = 0;
4330 pool_foreach (si, im->sw_interfaces,
4332 vec_add1 (sorted_sis, si[0]);
4336 vec_foreach (si, sorted_sis)
4338 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4340 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4344 sw_if_index = si->sw_if_index;
4345 send_ip_details (am, q, sw_if_index, mp->context);
4351 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4353 clib_warning ("BUG");
4357 send_l2fib_table_entry (vpe_api_main_t * am,
4358 unix_shared_memory_queue_t * q,
4359 l2fib_entry_key_t * l2fe_key,
4360 l2fib_entry_result_t * l2fe_res, u32 context)
4362 vl_api_l2_fib_table_entry_t *mp;
4364 mp = vl_msg_api_alloc (sizeof (*mp));
4365 memset (mp, 0, sizeof (*mp));
4366 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4369 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4371 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4372 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4373 mp->static_mac = l2fe_res->fields.static_mac;
4374 mp->filter_mac = l2fe_res->fields.filter;
4375 mp->bvi_mac = l2fe_res->fields.bvi;
4376 mp->context = context;
4378 vl_msg_api_send_shmem (q, (u8 *) & mp);
4382 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4384 vpe_api_main_t *am = &vpe_api_main;
4385 bd_main_t *bdm = &bd_main;
4386 l2fib_entry_key_t *l2fe_key = NULL;
4387 l2fib_entry_result_t *l2fe_res = NULL;
4388 u32 ni, bd_id = ntohl (mp->bd_id);
4390 unix_shared_memory_queue_t *q;
4393 q = vl_api_client_index_to_input_queue (mp->client_index);
4397 /* see l2fib_table_dump: ~0 means "any" */
4402 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4409 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4411 vec_foreach_index (ni, l2fe_key)
4413 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4414 vec_elt_at_index (l2fe_res, ni), mp->context);
4416 vec_free (l2fe_key);
4417 vec_free (l2fe_res);
4421 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4423 vl_api_show_version_reply_t *rmp;
4425 char *vpe_api_get_build_directory (void);
4426 char *vpe_api_get_version (void);
4427 char *vpe_api_get_build_date (void);
4429 unix_shared_memory_queue_t *q =
4430 vl_api_client_index_to_input_queue (mp->client_index);
4436 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4438 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4439 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4440 ARRAY_LEN(rmp->build_directory)-1);
4441 strncpy ((char *) rmp->version, vpe_api_get_version(),
4442 ARRAY_LEN(rmp->version)-1);
4443 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4444 ARRAY_LEN(rmp->build_date)-1);
4450 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4452 vlib_main_t *vm = vlib_get_main ();
4453 vl_api_get_node_index_reply_t *rmp;
4456 u32 node_index = ~0;
4458 n = vlib_get_node_by_name (vm, mp->node_name);
4461 rv = VNET_API_ERROR_NO_SUCH_NODE;
4463 node_index = n->index;
4466 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4468 rmp->node_index = ntohl(node_index);
4474 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4476 vlib_main_t *vm = vlib_get_main ();
4477 vl_api_get_next_index_reply_t *rmp;
4478 vlib_node_t *node, *next_node;
4480 u32 next_node_index = ~0, next_index = ~0;
4483 node = vlib_get_node_by_name (vm, mp->node_name);
4487 rv = VNET_API_ERROR_NO_SUCH_NODE;
4491 next_node = vlib_get_node_by_name (vm, mp->next_name);
4495 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4499 next_node_index = next_node->index;
4501 p = hash_get (node->next_slot_by_node, next_node_index);
4505 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4513 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4515 rmp->next_index = ntohl(next_index);
4521 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4523 vlib_main_t *vm = vlib_get_main ();
4524 vl_api_add_node_next_reply_t *rmp;
4525 vlib_node_t *n, *next;
4527 u32 next_index = ~0;
4529 n = vlib_get_node_by_name (vm, mp->node_name);
4533 rv = VNET_API_ERROR_NO_SUCH_NODE;
4537 next = vlib_get_node_by_name (vm, mp->next_name);
4540 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4542 next_index = vlib_node_add_next (vm, n->index, next->index);
4546 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4548 rmp->next_index = ntohl(next_index);
4553 static void vl_api_l2tpv3_create_tunnel_t_handler
4554 (vl_api_l2tpv3_create_tunnel_t * mp)
4556 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4557 l2t_main_t *lm = &l2t_main;
4558 u32 sw_if_index = (u32) ~ 0;
4561 if (mp->is_ipv6 != 1)
4563 rv = VNET_API_ERROR_UNIMPLEMENTED;
4567 u32 encap_fib_index;
4569 if (mp->encap_vrf_id != ~0)
4572 ip6_main_t *im = &ip6_main;
4575 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4577 rv = VNET_API_ERROR_NO_SUCH_FIB;
4580 encap_fib_index = p[0];
4584 encap_fib_index = ~0;
4587 rv = create_l2tpv3_ipv6_tunnel (lm,
4588 (ip6_address_t *) mp->client_address,
4589 (ip6_address_t *) mp->our_address,
4590 ntohl (mp->local_session_id),
4591 ntohl (mp->remote_session_id),
4592 clib_net_to_host_u64 (mp->local_cookie),
4593 clib_net_to_host_u64 (mp->remote_cookie),
4594 mp->l2_sublayer_present,
4595 encap_fib_index, &sw_if_index);
4599 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4601 rmp->sw_if_index = ntohl (sw_if_index);
4606 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4607 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4609 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4610 l2t_main_t *lm = &l2t_main;
4613 VALIDATE_SW_IF_INDEX (mp);
4615 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4616 clib_net_to_host_u64 (mp->new_local_cookie),
4617 clib_net_to_host_u64
4618 (mp->new_remote_cookie));
4620 BAD_SW_IF_INDEX_LABEL;
4622 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4625 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4626 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4629 vnet_main_t *vnm = vnet_get_main ();
4630 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4632 VALIDATE_SW_IF_INDEX (mp);
4634 rv = l2tpv3_interface_enable_disable
4635 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4637 BAD_SW_IF_INDEX_LABEL;
4639 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4642 static void vl_api_l2tpv3_set_lookup_key_t_handler
4643 (vl_api_l2tpv3_set_lookup_key_t * mp)
4646 l2t_main_t *lm = &l2t_main;
4647 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4649 if (mp->key > L2T_LOOKUP_SESSION_ID)
4651 rv = VNET_API_ERROR_INVALID_VALUE;
4655 lm->lookup_type = mp->key;
4658 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4661 static void vl_api_vxlan_add_del_tunnel_t_handler
4662 (vl_api_vxlan_add_del_tunnel_t * mp)
4664 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4666 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4667 u32 encap_fib_index;
4669 ip4_main_t *im = &ip4_main;
4670 u32 sw_if_index = ~0;
4672 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4675 rv = VNET_API_ERROR_NO_SUCH_FIB;
4678 encap_fib_index = p[0];
4680 /* Check src & dst are different */
4681 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4682 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4684 rv = VNET_API_ERROR_SAME_SRC_DST;
4687 memset (a, 0, sizeof (*a));
4689 a->is_add = mp->is_add;
4690 a->is_ip6 = mp->is_ipv6;
4692 /* ip addresses sent in network byte order */
4695 memcpy (&(a->src.ip6), mp->src_address, 16);
4696 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4700 memcpy (&(a->src.ip4), mp->src_address, 4);
4701 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4704 a->encap_fib_index = encap_fib_index;
4705 a->decap_next_index = ntohl (mp->decap_next_index);
4706 a->vni = ntohl (mp->vni);
4707 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4711 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4713 rmp->sw_if_index = ntohl (sw_if_index);
4718 static void send_vxlan_tunnel_details
4719 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4721 vl_api_vxlan_tunnel_details_t *rmp;
4722 ip4_main_t *im4 = &ip4_main;
4723 ip6_main_t *im6 = &ip6_main;
4724 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4726 rmp = vl_msg_api_alloc (sizeof (*rmp));
4727 memset (rmp, 0, sizeof (*rmp));
4728 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4731 memcpy (rmp->src_address, &(t->src.ip6), 16);
4732 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4733 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4737 memcpy (rmp->src_address, &(t->src.ip4), 4);
4738 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4739 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4741 rmp->vni = htonl (t->vni);
4742 rmp->decap_next_index = htonl (t->decap_next_index);
4743 rmp->sw_if_index = htonl (t->sw_if_index);
4744 rmp->is_ipv6 = is_ipv6;
4745 rmp->context = context;
4747 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4750 static void vl_api_vxlan_tunnel_dump_t_handler
4751 (vl_api_vxlan_tunnel_dump_t * mp)
4753 unix_shared_memory_queue_t *q;
4754 vxlan_main_t *vxm = &vxlan_main;
4758 q = vl_api_client_index_to_input_queue (mp->client_index);
4764 sw_if_index = ntohl (mp->sw_if_index);
4766 if (~0 == sw_if_index)
4769 pool_foreach (t, vxm->tunnels,
4771 send_vxlan_tunnel_details(t, q, mp->context);
4777 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4778 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4782 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4783 send_vxlan_tunnel_details (t, q, mp->context);
4787 static void vl_api_gre_add_del_tunnel_t_handler
4788 (vl_api_gre_add_del_tunnel_t * mp)
4790 vl_api_gre_add_del_tunnel_reply_t *rmp;
4792 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4795 ip4_main_t *im = &ip4_main;
4796 u32 sw_if_index = ~0;
4798 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4801 rv = VNET_API_ERROR_NO_SUCH_FIB;
4804 outer_fib_id = p[0];
4806 /* Check src & dst are different */
4807 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4808 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4810 rv = VNET_API_ERROR_SAME_SRC_DST;
4813 memset (a, 0, sizeof (*a));
4815 a->is_add = mp->is_add;
4818 /* ip addresses sent in network byte order */
4819 clib_memcpy (&(a->src), mp->src_address, 4);
4820 clib_memcpy (&(a->dst), mp->dst_address, 4);
4822 a->outer_fib_id = outer_fib_id;
4823 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4827 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4829 rmp->sw_if_index = ntohl (sw_if_index);
4834 static void send_gre_tunnel_details
4835 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4837 vl_api_gre_tunnel_details_t *rmp;
4838 ip4_main_t *im = &ip4_main;
4840 rmp = vl_msg_api_alloc (sizeof (*rmp));
4841 memset (rmp, 0, sizeof (*rmp));
4842 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4843 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4844 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4845 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4847 rmp->sw_if_index = htonl (t->sw_if_index);
4848 rmp->context = context;
4850 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4854 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4856 unix_shared_memory_queue_t *q;
4857 gre_main_t *gm = &gre_main;
4861 q = vl_api_client_index_to_input_queue (mp->client_index);
4867 sw_if_index = ntohl (mp->sw_if_index);
4869 if (~0 == sw_if_index)
4872 pool_foreach (t, gm->tunnels,
4874 send_gre_tunnel_details(t, q, mp->context);
4880 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4881 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4885 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4886 send_gre_tunnel_details (t, q, mp->context);
4891 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4893 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4895 vl_api_l2_patch_add_del_reply_t *rmp;
4896 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4900 VALIDATE_RX_SW_IF_INDEX (mp);
4901 VALIDATE_TX_SW_IF_INDEX (mp);
4903 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4904 ntohl (mp->tx_sw_if_index),
4905 (int) (mp->is_add != 0));
4907 BAD_RX_SW_IF_INDEX_LABEL;
4908 BAD_TX_SW_IF_INDEX_LABEL;
4910 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4914 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4915 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4917 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4919 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4920 u32 encap_fib_index, decap_fib_index;
4923 ip4_main_t *im = &ip4_main;
4924 u32 sw_if_index = ~0;
4927 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4930 rv = VNET_API_ERROR_NO_SUCH_FIB;
4933 encap_fib_index = p[0];
4935 protocol = mp->protocol;
4937 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4938 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4940 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4943 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4946 decap_fib_index = p[0];
4950 decap_fib_index = ntohl (mp->decap_vrf_id);
4953 /* Check src & dst are different */
4954 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4955 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
4957 rv = VNET_API_ERROR_SAME_SRC_DST;
4960 memset (a, 0, sizeof (*a));
4962 a->is_add = mp->is_add;
4963 a->is_ip6 = mp->is_ipv6;
4964 /* ip addresses sent in network byte order */
4967 clib_memcpy (&(a->local.ip6), mp->local, 16);
4968 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
4972 clib_memcpy (&(a->local.ip4), mp->local, 4);
4973 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
4975 a->encap_fib_index = encap_fib_index;
4976 a->decap_fib_index = decap_fib_index;
4977 a->protocol = protocol;
4978 a->vni = ntohl (mp->vni);
4979 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4983 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4985 rmp->sw_if_index = ntohl (sw_if_index);
4990 static void send_vxlan_gpe_tunnel_details
4991 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4993 vl_api_vxlan_gpe_tunnel_details_t *rmp;
4994 ip4_main_t *im4 = &ip4_main;
4995 ip6_main_t *im6 = &ip6_main;
4996 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4998 rmp = vl_msg_api_alloc (sizeof (*rmp));
4999 memset (rmp, 0, sizeof (*rmp));
5000 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5003 memcpy (rmp->local, &(t->local.ip6), 16);
5004 memcpy (rmp->remote, &(t->remote.ip6), 16);
5005 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
5006 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
5010 memcpy (rmp->local, &(t->local.ip4), 4);
5011 memcpy (rmp->remote, &(t->remote.ip4), 4);
5012 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
5013 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
5015 rmp->vni = htonl (t->vni);
5016 rmp->protocol = t->protocol;
5017 rmp->sw_if_index = htonl (t->sw_if_index);
5018 rmp->is_ipv6 = is_ipv6;
5019 rmp->context = context;
5021 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5024 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5025 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5027 unix_shared_memory_queue_t *q;
5028 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5029 vxlan_gpe_tunnel_t *t;
5032 q = vl_api_client_index_to_input_queue (mp->client_index);
5038 sw_if_index = ntohl (mp->sw_if_index);
5040 if (~0 == sw_if_index)
5043 pool_foreach (t, vgm->tunnels,
5045 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5051 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5052 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5056 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5057 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5061 /** Used for transferring locators via VPP API */
5063 typedef CLIB_PACKED (struct {
5064 u32 sw_if_index; /**< locator sw_if_index */
5065 u8 priority; /**< locator priority */
5066 u8 weight; /**< locator weight */
5071 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5074 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5076 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5078 ls_locator_t *ls_loc;
5079 u32 ls_index = ~0, locator_num;
5080 u8 *locator_name = NULL;
5083 memset (a, 0, sizeof (a[0]));
5085 locator_name = format (0, "%s", mp->locator_set_name);
5087 a->name = locator_name;
5088 a->is_add = mp->is_add;
5090 locator_num = clib_net_to_host_u32 (mp->locator_num);
5092 memset (&locator, 0, sizeof (locator));
5093 for (i = 0; i < locator_num; i++)
5095 ls_loc = &((ls_locator_t *) mp->locators)[i];
5096 VALIDATE_SW_IF_INDEX (ls_loc);
5098 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5099 locator.priority = ls_loc->priority;
5100 locator.weight = ls_loc->weight;
5102 vec_add1 (a->locators, locator);
5105 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5107 BAD_SW_IF_INDEX_LABEL;
5109 vec_free (locator_name);
5110 vec_free (a->locators);
5113 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5115 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5121 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5123 vl_api_lisp_add_del_locator_reply_t *rmp;
5125 locator_t locator, *locators = NULL;
5126 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5128 u8 *locator_name = NULL;
5130 memset (&locator, 0, sizeof (locator));
5131 memset (a, 0, sizeof (a[0]));
5133 locator.sw_if_index = ntohl (mp->sw_if_index);
5134 locator.priority = mp->priority;
5135 locator.weight = mp->weight;
5137 vec_add1 (locators, locator);
5139 locator_name = format (0, "%s", mp->locator_set_name);
5141 a->name = locator_name;
5142 a->locators = locators;
5143 a->is_add = mp->is_add;
5146 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5148 vec_free (locators);
5149 vec_free (locator_name);
5151 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5155 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5161 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5162 gid_address_ip_set (dst, src, IP4);
5163 gid_address_ippref_len (dst) = len;
5164 ip_prefix_normalize (&gid_address_ippref (dst));
5167 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5168 gid_address_ip_set (dst, src, IP6);
5169 gid_address_ippref_len (dst) = len;
5170 ip_prefix_normalize (&gid_address_ippref (dst));
5172 case 2: /* l2 mac */
5173 gid_address_type (dst) = GID_ADDR_MAC;
5174 clib_memcpy (&gid_address_mac (dst), src, 6);
5178 return VNET_API_ERROR_INVALID_VALUE;
5181 gid_address_vni (dst) = vni;
5187 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5189 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5190 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5192 gid_address_t _eid, *eid = &_eid;
5194 u32 locator_set_index = ~0, map_index = ~0;
5195 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5197 memset (a, 0, sizeof (a[0]));
5198 memset (eid, 0, sizeof (eid[0]));
5200 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5201 mp->eid_type, mp->eid, mp->prefix_len);
5205 name = format (0, "%s", mp->locator_set_name);
5206 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5209 rv = VNET_API_ERROR_INVALID_VALUE;
5212 locator_set_index = p[0];
5214 /* XXX treat batch configuration */
5215 a->is_add = mp->is_add;
5216 gid_address_copy (&a->eid, eid);
5217 a->locator_set_index = locator_set_index;
5219 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5223 gid_address_free (&a->eid);
5225 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5229 vl_api_lisp_eid_table_add_del_map_t_handler
5230 (vl_api_lisp_eid_table_add_del_map_t * mp)
5232 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5234 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5235 clib_net_to_host_u32 (mp->dp_table),
5236 mp->is_l2, mp->is_add);
5237 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5239 /** Used for transferring locators via VPP API */
5241 typedef CLIB_PACKED (struct {
5242 u8 is_ip4; /**< is locator an IPv4 address */
5243 u8 priority; /**< locator priority */
5244 u8 weight; /**< locator weight */
5245 u8 addr[16]; /**< IPv4/IPv6 address */
5249 static locator_pair_t *
5250 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5253 locator_pair_t *pairs = 0, pair;
5256 for (i = 0; i < rloc_num; i++)
5259 r = &((rloc_t *) lcl_locs)[i];
5260 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5261 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5263 /* remote locators */
5264 r = &((rloc_t *) rmt_locs)[i];
5265 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5266 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5268 pair.priority = r->priority;
5269 pair.weight = r->weight;
5271 vec_add1 (pairs, pair);
5277 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5280 locator_t *locs = 0, loc;
5283 for (i = 0; i < rloc_num; i++)
5285 /* remote locators */
5286 r = &((rloc_t *) rmt_locs)[i];
5287 memset (&loc, 0, sizeof (loc));
5288 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5290 loc.priority = r->priority;
5291 loc.weight = r->weight;
5293 vec_add1 (locs, loc);
5299 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5300 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5302 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5303 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5304 locator_pair_t *pairs = 0;
5307 memset (a, 0, sizeof (a[0]));
5309 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5310 mp->rmt_eid, mp->rmt_len);
5311 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5312 mp->lcl_eid, mp->lcl_len);
5314 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5316 if (rv || 0 == pairs)
5319 a->is_add = mp->is_add;
5320 a->locator_pairs = pairs;
5321 a->dp_table = mp->dp_table;
5323 a->action = mp->action;
5325 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5328 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5332 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5335 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5337 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5339 memset (a, 0, sizeof (a[0]));
5341 a->is_add = mp->is_add;
5342 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5344 rv = vnet_lisp_add_del_map_resolver (a);
5346 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5350 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5353 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5355 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5357 a->is_en = mp->is_en;
5358 vnet_lisp_gpe_enable_disable (a);
5360 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5364 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5366 vl_api_lisp_enable_disable_reply_t *rmp;
5369 vnet_lisp_enable_disable (mp->is_en);
5370 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5374 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5376 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5384 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
5388 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
5395 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
5399 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
5402 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5406 vl_api_show_lisp_map_request_mode_t_handler
5407 (vl_api_show_lisp_map_request_mode_t * mp)
5410 vl_api_show_lisp_map_request_mode_reply_t *rmp;
5413 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
5415 rmp->mode = vnet_lisp_get_map_request_mode ();
5421 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
5423 vl_api_lisp_map_request_mode_reply_t *rmp;
5426 rv = vnet_lisp_set_map_request_mode (mp->mode);
5428 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
5432 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5435 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5439 ls_name = format (0, "%s", mp->ls_name);
5440 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5443 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5447 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5448 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5450 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5452 u8 *locator_set_name = NULL;
5453 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5455 locator_set_name = format (0, "%s", mp->locator_set_name);
5457 a->is_add = mp->is_add;
5458 a->locator_set_name = locator_set_name;
5460 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5462 vec_free (locator_set_name);
5464 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5468 vl_api_lisp_add_del_remote_mapping_t_handler
5469 (vl_api_lisp_add_del_remote_mapping_t * mp)
5471 locator_t *rlocs = 0;
5472 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5474 gid_address_t _eid, *eid = &_eid;
5475 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5477 memset (eid, 0, sizeof (eid[0]));
5479 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5480 mp->eid_type, mp->eid, mp->eid_len);
5484 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5488 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5489 gid_address_copy (&a->reid, eid);
5491 rv = vnet_lisp_add_del_adjacency (a);
5498 /* NOTE: for now this works as a static remote mapping, i.e.,
5499 * not authoritative and ttl infinite. */
5500 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5501 mp->is_add, 1 /* is_static */ , 0);
5504 vnet_lisp_clear_all_remote_adjacencies ();
5509 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5513 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5515 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5516 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5519 memset (a, 0, sizeof (a[0]));
5521 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
5522 mp->eid_type, mp->leid, mp->leid_len);
5523 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
5524 mp->eid_type, mp->reid, mp->reid_len);
5529 a->is_add = mp->is_add;
5530 rv = vnet_lisp_add_del_adjacency (a);
5533 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5537 send_lisp_locator_details (lisp_cp_main_t * lcm,
5539 unix_shared_memory_queue_t * q, u32 context)
5541 vl_api_lisp_locator_details_t *rmp;
5543 rmp = vl_msg_api_alloc (sizeof (*rmp));
5544 memset (rmp, 0, sizeof (*rmp));
5545 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5546 rmp->context = context;
5548 rmp->local = loc->local;
5551 rmp->sw_if_index = ntohl (loc->sw_if_index);
5555 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5556 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5558 rmp->priority = loc->priority;
5559 rmp->weight = loc->weight;
5561 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5565 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5568 unix_shared_memory_queue_t *q = 0;
5569 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5570 locator_set_t *lsit = 0;
5572 u32 ls_index = ~0, *locit = 0;
5575 q = vl_api_client_index_to_input_queue (mp->client_index);
5581 if (mp->is_index_set)
5582 ls_index = htonl (mp->ls_index);
5585 /* make sure we get a proper C-string */
5586 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
5587 ls_name = format (0, "%s", mp->ls_name);
5588 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
5594 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
5597 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5599 vec_foreach (locit, lsit->locator_indices)
5601 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5602 send_lisp_locator_details (lcm, loc, q, mp->context);
5609 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5610 locator_set_t * lsit,
5611 unix_shared_memory_queue_t * q,
5612 u32 context, u32 ls_index)
5614 vl_api_lisp_locator_set_details_t *rmp;
5617 rmp = vl_msg_api_alloc (sizeof (*rmp));
5618 memset (rmp, 0, sizeof (*rmp));
5619 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5620 rmp->context = context;
5622 rmp->ls_index = htonl (ls_index);
5625 ASSERT (lsit->name != NULL);
5626 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
5627 vec_len (lsit->name));
5631 str = format (0, "<remote-%d>", ls_index);
5632 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
5636 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5640 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5642 unix_shared_memory_queue_t *q = NULL;
5643 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5644 locator_set_t *lsit = NULL;
5647 q = vl_api_client_index_to_input_queue (mp->client_index);
5653 filter = mp->filter;
5655 pool_foreach (lsit, lcm->locator_set_pool,
5657 if (filter && !((1 == filter && lsit->local) ||
5658 (2 == filter && !lsit->local)))
5662 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
5663 lsit - lcm->locator_set_pool);
5669 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5671 ASSERT (prefix_length);
5672 ip_prefix_t *ippref = &fid_addr_ippref (src);
5674 switch (fid_addr_type (src))
5676 case FID_ADDR_IP_PREF:
5677 if (ip_prefix_version (ippref) == IP4)
5678 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5680 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5681 prefix_length[0] = ip_prefix_len (ippref);
5685 prefix_length[0] = 0;
5686 clib_memcpy (dst, fid_addr_mac (src), 6);
5690 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5696 fid_type_to_api_type (fid_address_t * fid)
5698 ip_prefix_t *ippref;
5700 switch (fid_addr_type (fid))
5702 case FID_ADDR_IP_PREF:
5703 ippref = &fid_addr_ippref (fid);
5704 if (ip_prefix_version (ippref) == IP4)
5706 else if (ip_prefix_version (ippref) == IP6)
5719 send_lisp_eid_table_details (mapping_t * mapit,
5720 unix_shared_memory_queue_t * q,
5721 u32 context, u8 filter)
5724 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5725 locator_set_t *ls = 0;
5726 vl_api_lisp_eid_table_details_t *rmp = NULL;
5727 gid_address_t *gid = NULL;
5729 ip_prefix_t *ip_prefix = NULL;
5733 case 0: /* all mappings */
5736 case 1: /* local only */
5740 case 2: /* remote only */
5745 clib_warning ("Filter error, unknown filter: %d", filter);
5750 ip_prefix = &gid_address_ippref (gid);
5751 mac = gid_address_mac (gid);
5753 rmp = vl_msg_api_alloc (sizeof (*rmp));
5754 memset (rmp, 0, sizeof (*rmp));
5755 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5757 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5758 if (vec_len (ls->locator_indices) == 0)
5759 rmp->locator_set_index = ~0;
5761 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5763 rmp->is_local = mapit->local;
5764 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5765 rmp->action = mapit->action;
5766 rmp->authoritative = mapit->authoritative;
5768 switch (gid_address_type (gid))
5770 case GID_ADDR_SRC_DST:
5771 rmp->is_src_dst = 1;
5772 fid = &gid_address_sd_src (gid);
5773 rmp->eid_type = fid_type_to_api_type (fid);
5774 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5775 &rmp->seid_prefix_len);
5776 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5777 &rmp->eid_prefix_len);
5779 case GID_ADDR_IP_PREFIX:
5780 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5781 if (ip_prefix_version (ip_prefix) == IP4)
5783 rmp->eid_type = 0; /* ipv4 type */
5784 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5785 sizeof (ip_prefix_v4 (ip_prefix)));
5789 rmp->eid_type = 1; /* ipv6 type */
5790 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5791 sizeof (ip_prefix_v6 (ip_prefix)));
5795 rmp->eid_type = 2; /* l2 mac type */
5796 clib_memcpy (rmp->eid, mac, 6);
5801 rmp->context = context;
5802 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5803 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5807 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5810 unix_shared_memory_queue_t *q = NULL;
5811 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5812 mapping_t *mapit = NULL;
5813 gid_address_t _eid, *eid = &_eid;
5815 q = vl_api_client_index_to_input_queue (mp->client_index);
5823 memset (eid, 0, sizeof (*eid));
5825 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5826 mp->eid_type, mp->eid, mp->prefix_length);
5828 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5829 if ((u32) ~ 0 == mi)
5832 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5833 send_lisp_eid_table_details (mapit, q, mp->context,
5834 0 /* ignore filter */ );
5839 pool_foreach (mapit, lcm->mapping_pool,
5841 send_lisp_eid_table_details(mapit, q, mp->context,
5849 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
5850 unix_shared_memory_queue_t * q, u32 context)
5852 vl_api_lisp_gpe_tunnel_details_t *rmp;
5853 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5855 rmp = vl_msg_api_alloc (sizeof (*rmp));
5856 memset (rmp, 0, sizeof (*rmp));
5857 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5859 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
5861 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
5862 ip_address_copy_addr (rmp->source_ip,
5863 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5864 ip_address_copy_addr (rmp->destination_ip,
5865 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5867 rmp->encap_fib_id = htonl (0);
5868 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
5869 rmp->iid = htonl (lfe->key->vni);
5870 rmp->context = context;
5872 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5876 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5878 unix_shared_memory_queue_t *q = NULL;
5879 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5880 lisp_gpe_fwd_entry_t *lfe = NULL;
5882 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
5887 q = vl_api_client_index_to_input_queue (mp->client_index);
5894 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
5896 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
5902 send_lisp_map_resolver_details (ip_address_t * ip,
5903 unix_shared_memory_queue_t * q, u32 context)
5905 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5907 rmp = vl_msg_api_alloc (sizeof (*rmp));
5908 memset (rmp, 0, sizeof (*rmp));
5909 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5911 switch (ip_addr_version (ip))
5915 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5916 sizeof (ip_addr_v4 (ip)));
5921 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5922 sizeof (ip_addr_v6 (ip)));
5928 rmp->context = context;
5930 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5934 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5936 unix_shared_memory_queue_t *q = NULL;
5937 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5940 q = vl_api_client_index_to_input_queue (mp->client_index);
5946 vec_foreach (mr, lcm->map_resolvers)
5948 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5953 send_eid_table_map_pair (hash_pair_t * p,
5954 unix_shared_memory_queue_t * q, u32 context)
5956 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5958 rmp = vl_msg_api_alloc (sizeof (*rmp));
5959 memset (rmp, 0, sizeof (*rmp));
5960 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5962 rmp->vni = clib_host_to_net_u32 (p->key);
5963 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5964 rmp->context = context;
5965 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5969 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5972 unix_shared_memory_queue_t *q = NULL;
5973 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5975 uword *vni_table = 0;
5977 q = vl_api_client_index_to_input_queue (mp->client_index);
5985 vni_table = lcm->bd_id_by_vni;
5989 vni_table = lcm->table_id_by_vni;
5993 hash_foreach_pair (p, vni_table,
5995 send_eid_table_map_pair (p, q, mp->context);
6001 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6003 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6005 rmp = vl_msg_api_alloc (sizeof (*rmp));
6006 memset (rmp, 0, sizeof (*rmp));
6007 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6008 rmp->context = context;
6009 rmp->vni = clib_host_to_net_u32 (vni);
6010 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6014 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6019 unix_shared_memory_queue_t *q = 0;
6020 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6022 q = vl_api_client_index_to_input_queue (mp->client_index);
6029 hash_foreach_pair (p, lcm->table_id_by_vni,
6031 hash_set (vnis, p->key, 0);
6034 hash_foreach_pair (p, lcm->bd_id_by_vni,
6036 hash_set (vnis, p->key, 0);
6039 hash_foreach_pair (p, vnis,
6041 send_eid_table_vni (p->key, q, mp->context);
6049 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6051 unix_shared_memory_queue_t *q = NULL;
6052 vl_api_show_lisp_status_reply_t *rmp = NULL;
6055 q = vl_api_client_index_to_input_queue (mp->client_index);
6062 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6064 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6065 rmp->feature_status = vnet_lisp_enable_disable_status ();
6071 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6072 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6074 unix_shared_memory_queue_t *q = NULL;
6075 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6076 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6077 locator_set_t *loc_set = 0;
6081 q = vl_api_client_index_to_input_queue (mp->client_index);
6087 if (~0 == lcm->mreq_itr_rlocs)
6089 tmp_str = format (0, " ");
6094 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6095 tmp_str = format (0, "%s", loc_set->name);
6099 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6101 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6102 ARRAY_LEN(rmp->locator_set_name) - 1);
6110 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6112 unix_shared_memory_queue_t *q = NULL;
6113 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6114 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6116 locator_set_t *ls = 0;
6120 q = vl_api_client_index_to_input_queue (mp->client_index);
6126 if (!lcm->lisp_pitr)
6128 tmp_str = format (0, "N/A");
6132 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6133 if (~0 != m->locator_set_index)
6136 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6137 tmp_str = format (0, "%s", ls->name);
6141 tmp_str = format (0, "N/A");
6144 vec_add1 (tmp_str, 0);
6147 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6149 rmp->status = lcm->lisp_pitr;
6150 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6151 ARRAY_LEN(rmp->locator_set_name) - 1);
6157 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6160 vl_api_interface_name_renumber_reply_t *rmp;
6163 VALIDATE_SW_IF_INDEX (mp);
6165 rv = vnet_interface_name_renumber
6166 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6168 BAD_SW_IF_INDEX_LABEL;
6170 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6174 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6175 u32 sw_if_index, u32 address)
6177 vpe_api_main_t *am = &vpe_api_main;
6178 vlib_main_t *vm = am->vlib_main;
6179 vl_api_ip4_arp_event_t *event;
6180 static f64 arp_event_last_time;
6181 f64 now = vlib_time_now (vm);
6183 if (pool_is_free_index (am->arp_events, pool_index))
6186 event = pool_elt_at_index (am->arp_events, pool_index);
6188 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6190 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6194 if (sw_if_index == event->sw_if_index &&
6196 /* for BD case, also check IP address with 10 sec timeout */
6197 (address == event->address &&
6198 (now - arp_event_last_time) < 10.0)))
6203 arp_event_last_time = now;
6204 event->sw_if_index = sw_if_index;
6206 event->address = address;
6211 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6212 u32 sw_if_index, ip6_address_t * address)
6214 vpe_api_main_t *am = &vpe_api_main;
6215 vlib_main_t *vm = am->vlib_main;
6216 vl_api_ip6_nd_event_t *event;
6217 static f64 nd_event_last_time;
6218 f64 now = vlib_time_now (vm);
6220 if (pool_is_free_index (am->nd_events, pool_index))
6223 event = pool_elt_at_index (am->nd_events, pool_index);
6226 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6228 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6232 if (sw_if_index == event->sw_if_index &&
6234 /* for BD case, also check IP address with 10 sec timeout */
6235 (ip6_address_is_equal (address,
6236 (ip6_address_t *) event->address) &&
6237 (now - nd_event_last_time) < 10.0)))
6242 nd_event_last_time = now;
6243 event->sw_if_index = sw_if_index;
6245 clib_memcpy (event->address, address, sizeof (event->address));
6250 arp_change_delete_callback (u32 pool_index, u8 * notused)
6252 vpe_api_main_t *am = &vpe_api_main;
6254 if (pool_is_free_index (am->arp_events, pool_index))
6257 pool_put_index (am->arp_events, pool_index);
6262 nd_change_delete_callback (u32 pool_index, u8 * notused)
6264 vpe_api_main_t *am = &vpe_api_main;
6266 if (pool_is_free_index (am->nd_events, pool_index))
6269 pool_put_index (am->nd_events, pool_index);
6274 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6276 vpe_api_main_t *am = &vpe_api_main;
6277 vnet_main_t *vnm = vnet_get_main ();
6278 vl_api_want_ip4_arp_events_reply_t *rmp;
6279 vl_api_ip4_arp_event_t *event;
6282 if (mp->enable_disable)
6284 pool_get (am->arp_events, event);
6285 memset (event, 0, sizeof (*event));
6287 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6288 event->client_index = mp->client_index;
6289 event->context = mp->context;
6290 event->address = mp->address;
6291 event->pid = mp->pid;
6292 if (mp->address == 0)
6295 rv = vnet_add_del_ip4_arp_change_event
6296 (vnm, arp_change_data_callback,
6297 mp->pid, &mp->address /* addr, in net byte order */ ,
6298 vpe_resolver_process_node.index,
6299 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6303 rv = vnet_add_del_ip4_arp_change_event
6304 (vnm, arp_change_delete_callback,
6305 mp->pid, &mp->address /* addr, in net byte order */ ,
6306 vpe_resolver_process_node.index,
6307 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6309 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6313 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6315 vpe_api_main_t *am = &vpe_api_main;
6316 vnet_main_t *vnm = vnet_get_main ();
6317 vl_api_want_ip6_nd_events_reply_t *rmp;
6318 vl_api_ip6_nd_event_t *event;
6321 if (mp->enable_disable)
6323 pool_get (am->nd_events, event);
6324 memset (event, 0, sizeof (*event));
6326 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6327 event->client_index = mp->client_index;
6328 event->context = mp->context;
6329 clib_memcpy (event->address, mp->address, 16);
6330 event->pid = mp->pid;
6331 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6334 rv = vnet_add_del_ip6_nd_change_event
6335 (vnm, nd_change_data_callback,
6336 mp->pid, mp->address /* addr, in net byte order */ ,
6337 vpe_resolver_process_node.index,
6338 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6342 rv = vnet_add_del_ip6_nd_change_event
6343 (vnm, nd_change_delete_callback,
6344 mp->pid, mp->address /* addr, in net byte order */ ,
6345 vpe_resolver_process_node.index,
6346 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6348 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6351 static void vl_api_input_acl_set_interface_t_handler
6352 (vl_api_input_acl_set_interface_t * mp)
6354 vlib_main_t *vm = vlib_get_main ();
6355 vl_api_input_acl_set_interface_reply_t *rmp;
6357 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6359 ip4_table_index = ntohl (mp->ip4_table_index);
6360 ip6_table_index = ntohl (mp->ip6_table_index);
6361 l2_table_index = ntohl (mp->l2_table_index);
6362 sw_if_index = ntohl (mp->sw_if_index);
6364 VALIDATE_SW_IF_INDEX (mp);
6366 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6367 ip6_table_index, l2_table_index, mp->is_add);
6369 BAD_SW_IF_INDEX_LABEL;
6371 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6374 static void vl_api_ipsec_spd_add_del_t_handler
6375 (vl_api_ipsec_spd_add_del_t * mp)
6378 clib_warning ("unimplemented");
6381 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6382 vl_api_ipsec_spd_add_del_reply_t *rmp;
6386 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6388 rv = VNET_API_ERROR_UNIMPLEMENTED;
6391 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6395 static void vl_api_ipsec_interface_add_del_spd_t_handler
6396 (vl_api_ipsec_interface_add_del_spd_t * mp)
6398 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6399 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6401 u32 sw_if_index __attribute__ ((unused));
6402 u32 spd_id __attribute__ ((unused));
6404 sw_if_index = ntohl (mp->sw_if_index);
6405 spd_id = ntohl (mp->spd_id);
6407 VALIDATE_SW_IF_INDEX (mp);
6410 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6412 rv = VNET_API_ERROR_UNIMPLEMENTED;
6415 BAD_SW_IF_INDEX_LABEL;
6417 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6420 static void vl_api_ipsec_spd_add_del_entry_t_handler
6421 (vl_api_ipsec_spd_add_del_entry_t * mp)
6423 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6424 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6430 memset (&p, 0, sizeof (p));
6432 p.id = ntohl (mp->spd_id);
6433 p.priority = ntohl (mp->priority);
6434 p.is_outbound = mp->is_outbound;
6435 p.is_ipv6 = mp->is_ipv6;
6437 if (mp->is_ipv6 || mp->is_ip_any)
6439 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6440 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6441 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6442 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6446 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6447 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6448 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6449 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6451 p.protocol = mp->protocol;
6452 p.rport.start = ntohs (mp->remote_port_start);
6453 p.rport.stop = ntohs (mp->remote_port_stop);
6454 p.lport.start = ntohs (mp->local_port_start);
6455 p.lport.stop = ntohs (mp->local_port_stop);
6456 /* policy action resolve unsupported */
6457 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6459 clib_warning ("unsupported action: 'resolve'");
6460 rv = VNET_API_ERROR_UNIMPLEMENTED;
6463 p.policy = mp->policy;
6464 p.sa_id = ntohl (mp->sa_id);
6466 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6473 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6476 rv = VNET_API_ERROR_UNIMPLEMENTED;
6481 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6484 static void vl_api_ipsec_sad_add_del_entry_t_handler
6485 (vl_api_ipsec_sad_add_del_entry_t * mp)
6487 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6488 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6493 memset (&sa, 0, sizeof (sa));
6495 sa.id = ntohl (mp->sad_id);
6496 sa.spi = ntohl (mp->spi);
6497 /* security protocol AH unsupported */
6498 if (mp->protocol == IPSEC_PROTOCOL_AH)
6500 clib_warning ("unsupported security protocol 'AH'");
6501 rv = VNET_API_ERROR_UNIMPLEMENTED;
6504 sa.protocol = mp->protocol;
6505 /* check for unsupported crypto-alg */
6506 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6507 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6509 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6510 mp->crypto_algorithm);
6511 rv = VNET_API_ERROR_UNIMPLEMENTED;
6514 sa.crypto_alg = mp->crypto_algorithm;
6515 sa.crypto_key_len = mp->crypto_key_length;
6516 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6517 /* check for unsupported integ-alg */
6518 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6519 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6521 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6522 mp->integrity_algorithm);
6523 rv = VNET_API_ERROR_UNIMPLEMENTED;
6526 sa.integ_alg = mp->integrity_algorithm;
6527 sa.integ_key_len = mp->integrity_key_length;
6528 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6529 sa.use_esn = mp->use_extended_sequence_number;
6530 sa.is_tunnel = mp->is_tunnel;
6531 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6532 if (sa.is_tunnel_ip6)
6534 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6535 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6539 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6540 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6543 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6545 rv = VNET_API_ERROR_UNIMPLEMENTED;
6550 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6554 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6556 vl_api_ikev2_profile_add_del_reply_t *rmp;
6560 vlib_main_t *vm = vlib_get_main ();
6561 clib_error_t *error;
6562 u8 *tmp = format (0, "%s", mp->name);
6563 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6566 rv = VNET_API_ERROR_UNSPECIFIED;
6568 rv = VNET_API_ERROR_UNIMPLEMENTED;
6571 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6575 vl_api_ikev2_profile_set_auth_t_handler
6576 (vl_api_ikev2_profile_set_auth_t * mp)
6578 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6582 vlib_main_t *vm = vlib_get_main ();
6583 clib_error_t *error;
6584 u8 *tmp = format (0, "%s", mp->name);
6585 u8 *data = vec_new (u8, mp->data_len);
6586 clib_memcpy (data, mp->data, mp->data_len);
6587 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6591 rv = VNET_API_ERROR_UNSPECIFIED;
6593 rv = VNET_API_ERROR_UNIMPLEMENTED;
6596 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6600 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6602 vl_api_ikev2_profile_add_del_reply_t *rmp;
6606 vlib_main_t *vm = vlib_get_main ();
6607 clib_error_t *error;
6608 u8 *tmp = format (0, "%s", mp->name);
6609 u8 *data = vec_new (u8, mp->data_len);
6610 clib_memcpy (data, mp->data, mp->data_len);
6611 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6615 rv = VNET_API_ERROR_UNSPECIFIED;
6617 rv = VNET_API_ERROR_UNIMPLEMENTED;
6620 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6624 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6626 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6630 vlib_main_t *vm = vlib_get_main ();
6631 clib_error_t *error;
6632 u8 *tmp = format (0, "%s", mp->name);
6633 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6634 mp->end_port, (ip4_address_t) mp->start_addr,
6635 (ip4_address_t) mp->end_addr, mp->is_local);
6638 rv = VNET_API_ERROR_UNSPECIFIED;
6640 rv = VNET_API_ERROR_UNIMPLEMENTED;
6643 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6647 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6649 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6653 vlib_main_t *vm = vlib_get_main ();
6654 clib_error_t *error;
6656 error = ikev2_set_local_key (vm, mp->key_file);
6658 rv = VNET_API_ERROR_UNSPECIFIED;
6660 rv = VNET_API_ERROR_UNIMPLEMENTED;
6663 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6667 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6669 vl_api_map_add_domain_reply_t *rmp;
6672 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6674 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6675 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6676 (ip6_address_t *) & mp->ip6_src,
6677 mp->ip6_src_prefix_len, mp->ea_bits_len,
6678 mp->psid_offset, mp->psid_length, &index,
6679 ntohs (mp->mtu), flags);
6682 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6684 rmp->index = ntohl(index);
6690 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6692 vl_api_map_del_domain_reply_t *rmp;
6695 rv = map_delete_domain (ntohl (mp->index));
6697 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6701 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6703 vl_api_map_del_domain_reply_t *rmp;
6707 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6708 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6710 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6714 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6716 vl_api_map_domain_details_t *rmp;
6717 map_main_t *mm = &map_main;
6719 unix_shared_memory_queue_t *q;
6721 if (pool_elts (mm->domains) == 0)
6724 q = vl_api_client_index_to_input_queue (mp->client_index);
6731 pool_foreach(d, mm->domains,
6733 /* Make sure every field is initiated (or don't skip the memset()) */
6734 rmp = vl_msg_api_alloc (sizeof (*rmp));
6735 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6736 rmp->domain_index = htonl(d - mm->domains);
6737 rmp->ea_bits_len = d->ea_bits_len;
6738 rmp->psid_offset = d->psid_offset;
6739 rmp->psid_length = d->psid_length;
6740 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6741 rmp->ip4_prefix_len = d->ip4_prefix_len;
6742 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6743 rmp->ip6_prefix_len = d->ip6_prefix_len;
6744 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6745 rmp->ip6_src_len = d->ip6_src_len;
6746 rmp->mtu = htons(d->mtu);
6747 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6748 rmp->context = mp->context;
6750 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6756 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6758 unix_shared_memory_queue_t *q;
6761 vl_api_map_rule_details_t *rmp;
6762 map_main_t *mm = &map_main;
6763 u32 domain_index = ntohl (mp->domain_index);
6766 if (pool_elts (mm->domains) == 0)
6769 d = pool_elt_at_index (mm->domains, domain_index);
6770 if (!d || !d->rules)
6775 q = vl_api_client_index_to_input_queue (mp->client_index);
6781 for (i = 0; i < (0x1 << d->psid_length); i++)
6784 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6788 rmp = vl_msg_api_alloc (sizeof (*rmp));
6789 memset (rmp, 0, sizeof (*rmp));
6790 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6791 rmp->psid = htons (i);
6792 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6793 rmp->context = mp->context;
6794 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6799 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6801 vl_api_map_summary_stats_reply_t *rmp;
6802 vlib_combined_counter_main_t *cm;
6805 u64 total_pkts[VLIB_N_RX_TX];
6806 u64 total_bytes[VLIB_N_RX_TX];
6807 map_main_t *mm = &map_main;
6808 unix_shared_memory_queue_t *q =
6809 vl_api_client_index_to_input_queue (mp->client_index);
6814 rmp = vl_msg_api_alloc (sizeof (*rmp));
6815 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6816 rmp->context = mp->context;
6819 memset (total_pkts, 0, sizeof (total_pkts));
6820 memset (total_bytes, 0, sizeof (total_bytes));
6822 map_domain_counter_lock (mm);
6823 vec_foreach (cm, mm->domain_counters)
6825 which = cm - mm->domain_counters;
6827 for (i = 0; i < vec_len (cm->maxi); i++)
6829 vlib_get_combined_counter (cm, i, &v);
6830 total_pkts[which] += v.packets;
6831 total_bytes[which] += v.bytes;
6835 map_domain_counter_unlock (mm);
6837 /* Note: in network byte order! */
6838 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6839 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6840 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6841 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6842 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6843 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6844 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6845 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6846 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6847 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6848 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6849 clib_host_to_net_u64 (map_error_counter_get
6850 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6851 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6852 clib_host_to_net_u64 (map_error_counter_get
6853 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6855 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6859 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6861 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6862 vl_api_ipsec_sa_set_key_reply_t *rmp;
6866 sa.id = ntohl (mp->sa_id);
6867 sa.crypto_key_len = mp->crypto_key_length;
6868 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6869 sa.integ_key_len = mp->integrity_key_length;
6870 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6872 rv = ipsec_set_sa_key (vm, &sa);
6874 rv = VNET_API_ERROR_UNIMPLEMENTED;
6877 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6880 static void vl_api_cop_interface_enable_disable_t_handler
6881 (vl_api_cop_interface_enable_disable_t * mp)
6883 vl_api_cop_interface_enable_disable_reply_t *rmp;
6885 u32 sw_if_index = ntohl (mp->sw_if_index);
6888 VALIDATE_SW_IF_INDEX (mp);
6890 enable_disable = (int) mp->enable_disable;
6892 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6894 BAD_SW_IF_INDEX_LABEL;
6896 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6899 static void vl_api_cop_whitelist_enable_disable_t_handler
6900 (vl_api_cop_whitelist_enable_disable_t * mp)
6902 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6903 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6904 u32 sw_if_index = ntohl (mp->sw_if_index);
6907 VALIDATE_SW_IF_INDEX (mp);
6909 a->sw_if_index = sw_if_index;
6912 a->default_cop = mp->default_cop;
6913 a->fib_id = ntohl (mp->fib_id);
6915 rv = cop_whitelist_enable_disable (a);
6917 BAD_SW_IF_INDEX_LABEL;
6919 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6923 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6927 api_main_t *am = &api_main;
6928 vlib_main_t *vm = vlib_get_main ();
6930 vl_api_get_node_graph_reply_t *rmp;
6932 pthread_mutex_lock (&am->vlib_rp->mutex);
6933 oldheap = svm_push_data_heap (am->vlib_rp);
6936 * Keep the number of memcpy ops to a minimum (e.g. 1).
6938 vec_validate (vector, 16384);
6939 vec_reset_length (vector);
6942 vector = vlib_node_serialize (&vm->node_main, vector,
6943 (u32) ~ 0 /* all threads */ ,
6944 1 /* include nexts */ ,
6945 1 /* include stats */ );
6947 svm_pop_heap (oldheap);
6948 pthread_mutex_unlock (&am->vlib_rp->mutex);
6951 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6953 rmp->reply_in_shmem = (uword) vector;
6959 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
6962 vl_api_ioam_enable_reply_t *rmp;
6963 clib_error_t *error;
6965 /* Ignoring the profile id as currently a single profile
6967 error = ip6_ioam_enable (mp->trace_enable, mp->pow_enable, mp->trace_ppc);
6970 clib_error_report (error);
6971 rv = clib_error_get_code (error);
6974 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
6978 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
6981 vl_api_ioam_disable_reply_t *rmp;
6982 clib_error_t *error;
6984 error = clear_ioam_rewrite_fn ();
6987 clib_error_report (error);
6988 rv = clib_error_get_code (error);
6991 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
6995 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6997 vlib_main_t *vm = vlib_get_main ();
6998 vl_api_af_packet_create_reply_t *rmp;
7000 u8 *host_if_name = NULL;
7003 host_if_name = format (0, "%s", mp->host_if_name);
7004 vec_add1 (host_if_name, 0);
7006 rv = af_packet_create_if (vm, host_if_name,
7007 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7010 vec_free (host_if_name);
7013 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7015 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7021 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7023 vlib_main_t *vm = vlib_get_main ();
7024 vl_api_af_packet_delete_reply_t *rmp;
7026 u8 *host_if_name = NULL;
7028 host_if_name = format (0, "%s", mp->host_if_name);
7029 vec_add1 (host_if_name, 0);
7031 rv = af_packet_delete_if (vm, host_if_name);
7033 vec_free (host_if_name);
7035 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7039 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7041 vlib_main_t *vm = vlib_get_main ();
7042 vl_api_policer_add_del_reply_t *rmp;
7045 sse2_qos_pol_cfg_params_st cfg;
7046 clib_error_t *error;
7049 name = format (0, "%s", mp->name);
7051 memset (&cfg, 0, sizeof (cfg));
7053 cfg.rnd_type = mp->round_type;
7054 cfg.rate_type = mp->rate_type;
7055 cfg.rb.kbps.cir_kbps = mp->cir;
7056 cfg.rb.kbps.eir_kbps = mp->eir;
7057 cfg.rb.kbps.cb_bytes = mp->cb;
7058 cfg.rb.kbps.eb_bytes = mp->eb;
7059 cfg.conform_action.action_type = mp->conform_action_type;
7060 cfg.conform_action.dscp = mp->conform_dscp;
7061 cfg.exceed_action.action_type = mp->exceed_action_type;
7062 cfg.exceed_action.dscp = mp->exceed_dscp;
7063 cfg.violate_action.action_type = mp->violate_action_type;
7064 cfg.violate_action.dscp = mp->violate_dscp;
7065 cfg.color_aware = mp->color_aware;
7067 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7070 rv = VNET_API_ERROR_UNSPECIFIED;
7073 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7075 if (rv == 0 && mp->is_add)
7076 rmp->policer_index = ntohl(policer_index);
7078 rmp->policer_index = ~0;
7084 send_policer_details (u8 * name,
7085 sse2_qos_pol_cfg_params_st * config,
7086 policer_read_response_type_st * templ,
7087 unix_shared_memory_queue_t * q, u32 context)
7089 vl_api_policer_details_t *mp;
7091 mp = vl_msg_api_alloc (sizeof (*mp));
7092 memset (mp, 0, sizeof (*mp));
7093 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7094 mp->context = context;
7095 mp->cir = htonl (config->rb.kbps.cir_kbps);
7096 mp->eir = htonl (config->rb.kbps.eir_kbps);
7097 mp->cb = htonl (config->rb.kbps.cb_bytes);
7098 mp->eb = htonl (config->rb.kbps.eb_bytes);
7099 mp->rate_type = config->rate_type;
7100 mp->round_type = config->rnd_type;
7101 mp->type = config->rfc;
7102 mp->conform_action_type = config->conform_action.action_type;
7103 mp->conform_dscp = config->conform_action.dscp;
7104 mp->exceed_action_type = config->exceed_action.action_type;
7105 mp->exceed_dscp = config->exceed_action.dscp;
7106 mp->violate_action_type = config->violate_action.action_type;
7107 mp->violate_dscp = config->violate_action.dscp;
7108 mp->single_rate = templ->single_rate ? 1 : 0;
7109 mp->color_aware = templ->color_aware ? 1 : 0;
7110 mp->scale = htonl (templ->scale);
7111 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7112 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7113 mp->current_limit = htonl (templ->current_limit);
7114 mp->current_bucket = htonl (templ->current_bucket);
7115 mp->extended_limit = htonl (templ->extended_limit);
7116 mp->extended_bucket = htonl (templ->extended_bucket);
7117 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7119 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7121 vl_msg_api_send_shmem (q, (u8 *) & mp);
7125 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7127 unix_shared_memory_queue_t *q;
7128 vnet_policer_main_t *pm = &vnet_policer_main;
7134 sse2_qos_pol_cfg_params_st *config;
7135 policer_read_response_type_st *templ;
7137 q = vl_api_client_index_to_input_queue (mp->client_index);
7141 if (mp->match_name_valid)
7143 match_name = format (0, "%s%c", mp->match_name, 0);
7146 if (mp->match_name_valid)
7148 p = hash_get_mem (pm->policer_config_by_name, match_name);
7152 config = pool_elt_at_index (pm->configs, pool_index);
7153 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7154 send_policer_details (match_name, config, templ, q, mp->context);
7160 hash_foreach_pair (hp, pm->policer_config_by_name,
7162 name = (u8 *) hp->key;
7163 pool_index = hp->value[0];
7164 config = pool_elt_at_index (pm->configs, pool_index);
7165 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7166 send_policer_details(name, config, templ, q, mp->context);
7173 vl_api_policer_classify_set_interface_t_handler
7174 (vl_api_policer_classify_set_interface_t * mp)
7176 vlib_main_t *vm = vlib_get_main ();
7177 vl_api_policer_classify_set_interface_reply_t *rmp;
7179 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7181 ip4_table_index = ntohl (mp->ip4_table_index);
7182 ip6_table_index = ntohl (mp->ip6_table_index);
7183 l2_table_index = ntohl (mp->l2_table_index);
7184 sw_if_index = ntohl (mp->sw_if_index);
7186 VALIDATE_SW_IF_INDEX (mp);
7188 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7189 ip6_table_index, l2_table_index,
7192 BAD_SW_IF_INDEX_LABEL;
7194 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7198 send_policer_classify_details (u32 sw_if_index,
7200 unix_shared_memory_queue_t * q, u32 context)
7202 vl_api_policer_classify_details_t *mp;
7204 mp = vl_msg_api_alloc (sizeof (*mp));
7205 memset (mp, 0, sizeof (*mp));
7206 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7207 mp->context = context;
7208 mp->sw_if_index = htonl (sw_if_index);
7209 mp->table_index = htonl (table_index);
7211 vl_msg_api_send_shmem (q, (u8 *) & mp);
7215 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7217 unix_shared_memory_queue_t *q;
7218 policer_classify_main_t *pcm = &policer_classify_main;
7222 q = vl_api_client_index_to_input_queue (mp->client_index);
7226 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7228 if (vec_len (vec_tbl))
7230 for (i = 0; i < vec_len (vec_tbl); i++)
7232 if (vec_elt (vec_tbl, i) == ~0)
7235 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7242 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7244 vlib_main_t *vm = vlib_get_main ();
7245 vl_api_netmap_create_reply_t *rmp;
7249 if_name = format (0, "%s", mp->netmap_if_name);
7250 vec_add1 (if_name, 0);
7253 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7254 mp->is_pipe, mp->is_master, 0);
7258 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7262 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7264 vlib_main_t *vm = vlib_get_main ();
7265 vl_api_netmap_delete_reply_t *rmp;
7269 if_name = format (0, "%s", mp->netmap_if_name);
7270 vec_add1 (if_name, 0);
7272 rv = netmap_delete_if (vm, if_name);
7276 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7280 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7283 clib_warning ("BUG");
7287 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7288 unix_shared_memory_queue_t * q,
7289 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7291 vl_api_mpls_gre_tunnel_details_t *mp;
7292 mpls_main_t *mm = &mpls_main;
7297 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7298 nlabels = vec_len (e->labels);
7300 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7301 memset (mp, 0, sizeof (*mp));
7302 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7303 mp->context = context;
7305 mp->tunnel_index = htonl (index);
7306 mp->tunnel_src = gt->tunnel_src.as_u32;
7307 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7308 mp->intfc_address = gt->intfc_address.as_u32;
7309 mp->mask_width = htonl (gt->mask_width);
7310 mp->inner_fib_index = htonl (gt->inner_fib_index);
7311 mp->outer_fib_index = htonl (gt->outer_fib_index);
7312 mp->encap_index = htonl (gt->encap_index);
7313 mp->hw_if_index = htonl (gt->hw_if_index);
7314 mp->l2_only = htonl (gt->l2_only);
7315 mp->nlabels = htonl (nlabels);
7317 for (i = 0; i < nlabels; i++)
7320 htonl (vnet_mpls_uc_get_label
7321 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7324 vl_msg_api_send_shmem (q, (u8 *) & mp);
7328 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7330 vpe_api_main_t *am = &vpe_api_main;
7331 unix_shared_memory_queue_t *q;
7332 mpls_main_t *mm = &mpls_main;
7333 mpls_gre_tunnel_t *gt;
7334 u32 index = ntohl (mp->tunnel_index);
7336 q = vl_api_client_index_to_input_queue (mp->client_index);
7342 if (!pool_is_free_index (mm->gre_tunnels, index))
7344 gt = pool_elt_at_index (mm->gre_tunnels, index);
7345 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7352 pool_foreach (gt, mm->gre_tunnels,
7354 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7362 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7365 clib_warning ("BUG");
7369 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7370 unix_shared_memory_queue_t * q,
7371 mpls_eth_tunnel_t * et, u32 index, u32 context)
7373 mpls_main_t *mm = &mpls_main;
7377 vl_api_mpls_eth_tunnel_details_t *mp;
7379 e = pool_elt_at_index (mm->encaps, et->encap_index);
7380 nlabels = vec_len (e->labels);
7382 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7383 memset (mp, 0, sizeof (*mp));
7384 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7385 mp->context = context;
7387 mp->tunnel_index = htonl (index);
7388 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7389 mp->intfc_address = et->intfc_address.as_u32;
7390 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7391 mp->inner_fib_index = htonl (et->inner_fib_index);
7392 mp->mask_width = htonl (et->mask_width);
7393 mp->encap_index = htonl (et->encap_index);
7394 mp->hw_if_index = htonl (et->hw_if_index);
7395 mp->l2_only = htonl (et->l2_only);
7396 mp->nlabels = htonl (nlabels);
7398 for (i = 0; i < nlabels; i++)
7401 htonl (vnet_mpls_uc_get_label
7402 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7405 vl_msg_api_send_shmem (q, (u8 *) & mp);
7409 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7411 vpe_api_main_t *am = &vpe_api_main;
7412 unix_shared_memory_queue_t *q;
7413 mpls_main_t *mm = &mpls_main;
7414 mpls_eth_tunnel_t *et;
7415 u32 index = ntohl (mp->tunnel_index);
7417 q = vl_api_client_index_to_input_queue (mp->client_index);
7423 if (!pool_is_free_index (mm->eth_tunnels, index))
7425 et = pool_elt_at_index (mm->eth_tunnels, index);
7426 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7433 pool_foreach (et, mm->eth_tunnels,
7435 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7443 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7445 clib_warning ("BUG");
7449 send_mpls_fib_encap_details (vpe_api_main_t * am,
7450 unix_shared_memory_queue_t * q,
7451 show_mpls_fib_t * s, u32 context)
7453 vl_api_mpls_fib_encap_details_t *mp;
7454 mpls_main_t *mm = &mpls_main;
7459 e = pool_elt_at_index (mm->encaps, s->entry_index);
7460 nlabels = vec_len (e->labels);
7462 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7463 memset (mp, 0, sizeof (*mp));
7464 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7465 mp->context = context;
7467 mp->fib_index = htonl (s->fib_index);
7468 mp->entry_index = htonl (s->entry_index);
7470 mp->s_bit = htonl (s->s_bit);
7472 mp->nlabels = htonl (nlabels);
7474 for (i = 0; i < nlabels; i++)
7477 htonl (vnet_mpls_uc_get_label
7478 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7481 vl_msg_api_send_shmem (q, (u8 *) & mp);
7485 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7487 vpe_api_main_t *am = &vpe_api_main;
7488 unix_shared_memory_queue_t *q;
7489 vlib_main_t *vm = &vlib_global_main;
7492 show_mpls_fib_t *records = 0;
7494 mpls_main_t *mm = &mpls_main;
7497 q = vl_api_client_index_to_input_queue (mp->client_index);
7502 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7504 vec_add2 (records, s, 1);
7505 s->fib_index = (u32)(key>>32);
7506 s->dest = (u32)(key & 0xFFFFFFFF);
7507 s->entry_index = (u32) value;
7511 if (0 == vec_len (records))
7513 vlib_cli_output (vm, "MPLS encap table empty");
7517 /* sort output by dst address within fib */
7518 vec_sort_with_function (records, mpls_dest_cmp);
7519 vec_sort_with_function (records, mpls_fib_index_cmp);
7520 vlib_cli_output (vm, "MPLS encap table");
7521 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7522 vec_foreach (s, records)
7524 rx_fib = ip4_fib_get (s->fib_index);
7525 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7526 format_ip4_address, &s->dest, format_mpls_encap_index,
7527 mm, s->entry_index);
7528 send_mpls_fib_encap_details (am, q, s, mp->context);
7536 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7538 clib_warning ("BUG");
7542 send_mpls_fib_decap_details (vpe_api_main_t * am,
7543 unix_shared_memory_queue_t * q,
7544 show_mpls_fib_t * s,
7546 u32 tx_table_id, char *swif_tag, u32 context)
7548 vl_api_mpls_fib_decap_details_t *mp;
7550 mp = vl_msg_api_alloc (sizeof (*mp));
7551 memset (mp, 0, sizeof (*mp));
7552 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7553 mp->context = context;
7555 mp->fib_index = htonl (s->fib_index);
7556 mp->entry_index = htonl (s->entry_index);
7558 mp->s_bit = htonl (s->s_bit);
7559 mp->label = htonl (s->label);
7560 mp->rx_table_id = htonl (rx_table_id);
7561 mp->tx_table_id = htonl (tx_table_id);
7562 strncpy ((char *) mp->swif_tag,
7563 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7565 vl_msg_api_send_shmem (q, (u8 *) & mp);
7569 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7571 vpe_api_main_t *am = &vpe_api_main;
7572 unix_shared_memory_queue_t *q;
7573 vlib_main_t *vm = &vlib_global_main;
7576 show_mpls_fib_t *records = 0;
7578 mpls_main_t *mm = &mpls_main;
7584 q = vl_api_client_index_to_input_queue (mp->client_index);
7589 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7591 vec_add2 (records, s, 1);
7592 s->fib_index = (u32)(key>>32);
7593 s->entry_index = (u32) value;
7594 s->label = ((u32) key)>>12;
7595 s->s_bit = (key & (1<<8)) != 0;
7599 if (!vec_len (records))
7601 vlib_cli_output (vm, "MPLS decap table empty");
7605 vec_sort_with_function (records, mpls_label_cmp);
7606 vlib_cli_output (vm, "MPLS decap table");
7607 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7609 vec_foreach (s, records)
7612 d = pool_elt_at_index (mm->decaps, s->entry_index);
7613 if (d->next_index == MPLS_LOOKUP_NEXT_IP4_INPUT)
7615 tx_fib = ip4_fib_get (d->tx_fib_index);
7616 tx_table_id = tx_fib->table_id;
7621 tx_table_id = d->tx_fib_index;
7624 rx_fib = ip4_fib_get (s->fib_index);
7626 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7627 tx_table_id, swif_tag, s->label, s->s_bit);
7629 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7630 tx_table_id, swif_tag, mp->context);
7638 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7640 unix_shared_memory_queue_t *q;
7642 q = vl_api_client_index_to_input_queue (mp->client_index);
7646 vnet_classify_main_t *cm = &vnet_classify_main;
7647 vnet_classify_table_t *t;
7652 pool_foreach (t, cm->tables,
7654 vec_add1 (table_ids, ntohl(t - cm->tables));
7657 count = vec_len (table_ids);
7659 vl_api_classify_table_ids_reply_t *rmp;
7660 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7661 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7662 rmp->context = mp->context;
7663 rmp->count = ntohl (count);
7664 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7667 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7669 vec_free (table_ids);
7673 vl_api_classify_table_by_interface_t_handler
7674 (vl_api_classify_table_by_interface_t * mp)
7676 vl_api_classify_table_by_interface_reply_t *rmp;
7679 u32 sw_if_index = ntohl (mp->sw_if_index);
7682 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7685 VALIDATE_SW_IF_INDEX (mp);
7687 input_acl_main_t *am = &input_acl_main;
7692 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7694 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7695 if (vec_len (vec_tbl))
7697 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7699 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7703 acl[type] = vec_elt (vec_tbl, if_idx);
7708 BAD_SW_IF_INDEX_LABEL;
7711 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7713 rmp->sw_if_index = ntohl(sw_if_index);
7714 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7715 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7716 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7723 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7725 unix_shared_memory_queue_t *q;
7727 q = vl_api_client_index_to_input_queue (mp->client_index);
7731 vl_api_classify_table_info_reply_t *rmp = 0;
7733 vnet_classify_main_t *cm = &vnet_classify_main;
7734 u32 table_id = ntohl (mp->table_id);
7735 vnet_classify_table_t *t;
7738 pool_foreach (t, cm->tables,
7740 if (table_id == t - cm->tables)
7742 rmp = vl_msg_api_alloc_as_if_client
7743 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7744 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7745 rmp->context = mp->context;
7746 rmp->table_id = ntohl(table_id);
7747 rmp->nbuckets = ntohl(t->nbuckets);
7748 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7749 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7750 rmp->active_sessions = ntohl(t->active_elements);
7751 rmp->next_table_index = ntohl(t->next_table_index);
7752 rmp->miss_next_index = ntohl(t->miss_next_index);
7753 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7754 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7763 rmp = vl_msg_api_alloc (sizeof (*rmp));
7764 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7765 rmp->context = mp->context;
7766 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7769 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7773 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7776 clib_warning ("BUG");
7780 send_classify_session_details (unix_shared_memory_queue_t * q,
7783 vnet_classify_entry_t * e, u32 context)
7785 vl_api_classify_session_details_t *rmp;
7787 rmp = vl_msg_api_alloc (sizeof (*rmp));
7788 memset (rmp, 0, sizeof (*rmp));
7789 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7790 rmp->context = context;
7791 rmp->table_id = ntohl (table_id);
7792 rmp->hit_next_index = ntohl (e->next_index);
7793 rmp->advance = ntohl (e->advance);
7794 rmp->opaque_index = ntohl (e->opaque_index);
7795 rmp->match_length = ntohl (match_length);
7796 clib_memcpy (rmp->match, e->key, match_length);
7798 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7802 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7804 vnet_classify_main_t *cm = &vnet_classify_main;
7805 unix_shared_memory_queue_t *q;
7807 u32 table_id = ntohl (mp->table_id);
7808 vnet_classify_table_t *t;
7810 q = vl_api_client_index_to_input_queue (mp->client_index);
7815 pool_foreach (t, cm->tables,
7817 if (table_id == t - cm->tables)
7819 vnet_classify_bucket_t * b;
7820 vnet_classify_entry_t * v, * save_v;
7823 for (i = 0; i < t->nbuckets; i++)
7825 b = &t->buckets [i];
7829 save_v = vnet_classify_get_entry (t, b->offset);
7830 for (j = 0; j < (1<<b->log2_pages); j++)
7832 for (k = 0; k < t->entries_per_page; k++)
7834 v = vnet_classify_entry_at_index
7835 (t, save_v, j*t->entries_per_page + k);
7836 if (vnet_classify_entry_is_free (v))
7839 send_classify_session_details
7840 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7852 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7854 vlib_main_t *vm = vlib_get_main ();
7855 flow_report_main_t *frm = &flow_report_main;
7856 vl_api_set_ipfix_exporter_reply_t *rmp;
7857 ip4_address_t collector, src;
7858 u16 collector_port = UDP_DST_PORT_ipfix;
7860 u32 template_interval;
7866 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7867 collector_port = ntohs (mp->collector_port);
7868 if (collector_port == (u16) ~ 0)
7869 collector_port = UDP_DST_PORT_ipfix;
7870 memcpy (src.data, mp->src_address, sizeof (src.data));
7871 fib_id = ntohl (mp->vrf_id);
7873 ip4_main_t *im = &ip4_main;
7880 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7883 rv = VNET_API_ERROR_NO_SUCH_FIB;
7889 path_mtu = ntohl (mp->path_mtu);
7891 path_mtu = 512; // RFC 7011 section 10.3.3.
7892 template_interval = ntohl (mp->template_interval);
7893 if (template_interval == ~0)
7894 template_interval = 20;
7895 udp_checksum = mp->udp_checksum;
7897 if (collector.as_u32 == 0)
7899 rv = VNET_API_ERROR_INVALID_VALUE;
7903 if (src.as_u32 == 0)
7905 rv = VNET_API_ERROR_INVALID_VALUE;
7909 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7911 rv = VNET_API_ERROR_INVALID_VALUE;
7917 rv = VNET_API_ERROR_INVALID_VALUE;
7921 /* Reset report streams if we are reconfiguring IP addresses */
7922 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7923 frm->src_address.as_u32 != src.as_u32 ||
7924 frm->collector_port != collector_port)
7925 vnet_flow_reports_reset (frm);
7927 frm->ipfix_collector.as_u32 = collector.as_u32;
7928 frm->collector_port = collector_port;
7929 frm->src_address.as_u32 = src.as_u32;
7930 frm->fib_index = fib_index;
7931 frm->path_mtu = path_mtu;
7932 frm->template_interval = template_interval;
7933 frm->udp_checksum = udp_checksum;
7935 /* Turn on the flow reporting process */
7936 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7939 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
7943 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
7945 flow_report_main_t *frm = &flow_report_main;
7946 unix_shared_memory_queue_t *q;
7947 vl_api_ipfix_exporter_details_t *rmp;
7948 ip4_main_t *im = &ip4_main;
7951 q = vl_api_client_index_to_input_queue (mp->client_index);
7955 rmp = vl_msg_api_alloc (sizeof (*rmp));
7956 memset (rmp, 0, sizeof (*rmp));
7957 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
7958 rmp->context = mp->context;
7959 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7960 sizeof (frm->ipfix_collector.data));
7961 rmp->collector_port = htons (frm->collector_port);
7962 memcpy (rmp->src_address, frm->src_address.data,
7963 sizeof (frm->src_address.data));
7964 if (frm->fib_index == ~0)
7967 vrf_id = im->fibs[frm->fib_index].ft_table_id;
7968 rmp->vrf_id = htonl (vrf_id);
7969 rmp->path_mtu = htonl (frm->path_mtu);
7970 rmp->template_interval = htonl (frm->template_interval);
7971 rmp->udp_checksum = (frm->udp_checksum != 0);
7973 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7977 vl_api_set_ipfix_classify_stream_t_handler
7978 (vl_api_set_ipfix_classify_stream_t * mp)
7980 vl_api_set_ipfix_classify_stream_reply_t *rmp;
7981 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7982 flow_report_main_t *frm = &flow_report_main;
7984 u32 src_port = UDP_DST_PORT_ipfix;
7987 domain_id = ntohl (mp->domain_id);
7988 src_port = ntohs (mp->src_port);
7990 if (fcm->src_port != 0 &&
7991 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
7993 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
7994 domain_id, (u16) src_port);
7998 fcm->domain_id = domain_id;
7999 fcm->src_port = (u16) src_port;
8001 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8005 vl_api_ipfix_classify_stream_dump_t_handler
8006 (vl_api_ipfix_classify_stream_dump_t * mp)
8008 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8009 unix_shared_memory_queue_t *q;
8010 vl_api_ipfix_classify_stream_details_t *rmp;
8012 q = vl_api_client_index_to_input_queue (mp->client_index);
8016 rmp = vl_msg_api_alloc (sizeof (*rmp));
8017 memset (rmp, 0, sizeof (*rmp));
8018 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
8019 rmp->context = mp->context;
8020 rmp->domain_id = htonl (fcm->domain_id);
8021 rmp->src_port = htons (fcm->src_port);
8023 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8027 vl_api_ipfix_classify_table_add_del_t_handler
8028 (vl_api_ipfix_classify_table_add_del_t * mp)
8030 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
8031 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8032 flow_report_main_t *frm = &flow_report_main;
8033 vnet_flow_report_add_del_args_t args;
8034 ipfix_classify_table_t *table;
8036 u32 classify_table_index;
8038 u8 transport_protocol;
8041 classify_table_index = ntohl (mp->table_id);
8042 ip_version = mp->ip_version;
8043 transport_protocol = mp->transport_protocol;
8044 is_add = mp->is_add;
8046 if (fcm->src_port == 0)
8048 /* call set_ipfix_classify_stream first */
8049 rv = VNET_API_ERROR_UNSPECIFIED;
8053 memset (&args, 0, sizeof (args));
8057 for (i = 0; i < vec_len (fcm->tables); i++)
8058 if (ipfix_classify_table_index_valid (i))
8059 if (fcm->tables[i].classify_table_index == classify_table_index)
8061 table = &fcm->tables[i];
8069 rv = VNET_API_ERROR_VALUE_EXIST;
8072 table = ipfix_classify_add_table ();
8073 table->classify_table_index = classify_table_index;
8079 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
8084 table->ip_version = ip_version;
8085 table->transport_protocol = transport_protocol;
8087 args.opaque.as_uword = table - fcm->tables;
8088 args.rewrite_callback = ipfix_classify_template_rewrite;
8089 args.flow_data_callback = ipfix_classify_send_flows;
8090 args.is_add = is_add;
8091 args.domain_id = fcm->domain_id;
8092 args.src_port = fcm->src_port;
8094 rv = vnet_flow_report_add_del (frm, &args);
8096 /* If deleting, or add failed */
8097 if (is_add == 0 || (rv && is_add))
8098 ipfix_classify_delete_table (table - fcm->tables);
8101 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8105 send_ipfix_classify_table_details (u32 table_index,
8106 unix_shared_memory_queue_t * q,
8109 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8110 vl_api_ipfix_classify_table_details_t *mp;
8112 ipfix_classify_table_t *table = &fcm->tables[table_index];
8114 mp = vl_msg_api_alloc (sizeof (*mp));
8115 memset (mp, 0, sizeof (*mp));
8116 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
8117 mp->context = context;
8118 mp->table_id = htonl (table->classify_table_index);
8119 mp->ip_version = table->ip_version;
8120 mp->transport_protocol = table->transport_protocol;
8122 vl_msg_api_send_shmem (q, (u8 *) & mp);
8126 vl_api_ipfix_classify_table_dump_t_handler
8127 (vl_api_ipfix_classify_table_dump_t * mp)
8129 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8130 unix_shared_memory_queue_t *q;
8133 q = vl_api_client_index_to_input_queue (mp->client_index);
8137 for (i = 0; i < vec_len (fcm->tables); i++)
8138 if (ipfix_classify_table_index_valid (i))
8139 send_ipfix_classify_table_details (i, q, mp->context);
8143 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8145 vl_api_pg_create_interface_reply_t *rmp;
8148 pg_main_t *pg = &pg_main;
8149 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8150 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
8153 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8155 rmp->sw_if_index = ntohl(pi->sw_if_index);
8161 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8163 vl_api_pg_capture_reply_t *rmp;
8166 vnet_main_t *vnm = vnet_get_main ();
8167 vnet_interface_main_t *im = &vnm->interface_main;
8168 vnet_hw_interface_t *hi = 0;
8170 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8171 u32 hw_if_index = ~0;
8172 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8175 vec_free (intf_name);
8177 if (hw_if_index != ~0)
8179 pg_capture_args_t _a, *a = &_a;
8181 u32 len = ntohl (mp->pcap_name_length);
8182 u8 *pcap_file_name = vec_new (u8, len);
8183 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8185 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8186 a->hw_if_index = hw_if_index;
8187 a->dev_instance = hi->dev_instance;
8188 a->is_enabled = mp->is_enabled;
8189 a->pcap_file_name = pcap_file_name;
8190 a->count = ntohl (mp->count);
8192 clib_error_t *e = pg_capture (a);
8195 clib_error_report (e);
8196 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8199 vec_free (pcap_file_name);
8201 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8205 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8207 vl_api_pg_enable_disable_reply_t *rmp;
8210 pg_main_t *pg = &pg_main;
8211 u32 stream_index = ~0;
8213 int is_enable = mp->is_enabled != 0;
8214 u32 len = ntohl (mp->stream_name_length) - 1;
8218 u8 *stream_name = vec_new (u8, len);
8219 clib_memcpy (stream_name, mp->stream_name, len);
8220 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8223 vec_free (stream_name);
8226 pg_enable_disable (stream_index, is_enable);
8228 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8232 vl_api_ip_source_and_port_range_check_add_del_t_handler
8233 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8235 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8238 u8 is_ipv6 = mp->is_ipv6;
8239 u8 is_add = mp->is_add;
8240 u8 mask_length = mp->mask_length;
8241 ip4_address_t ip4_addr;
8242 ip6_address_t ip6_addr;
8244 u16 *high_ports = 0;
8246 u16 tmp_low, tmp_high;
8250 // Validate port range
8251 num_ranges = mp->number_of_ranges;
8252 if (num_ranges > 32)
8253 { // This is size of array in VPE.API
8254 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8258 vec_reset_length (low_ports);
8259 vec_reset_length (high_ports);
8261 for (i = 0; i < num_ranges; i++)
8263 tmp_low = mp->low_ports[i];
8264 tmp_high = mp->high_ports[i];
8265 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8266 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8267 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8269 rv = VNET_API_ERROR_INVALID_VALUE;
8272 vec_add1 (low_ports, tmp_low);
8273 vec_add1 (high_ports, tmp_high + 1);
8276 // Validate mask_length
8277 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8279 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8283 vrf_id = ntohl (mp->vrf_id);
8287 rv = VNET_API_ERROR_INVALID_VALUE;
8294 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8295 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8299 high_ports, is_add);
8303 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8304 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8308 high_ports, is_add);
8312 vec_free (low_ports);
8313 vec_free (high_ports);
8314 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8318 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8319 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8321 vlib_main_t *vm = vlib_get_main ();
8322 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8323 ip4_main_t *im = &ip4_main;
8326 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8327 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8331 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8332 ntohl (mp->tcp_out_vrf_id);
8333 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8334 ntohl (mp->udp_out_vrf_id);
8335 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8336 ntohl (mp->tcp_in_vrf_id);
8337 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8338 ntohl (mp->udp_in_vrf_id);
8341 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8343 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8345 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8349 rv = VNET_API_ERROR_INVALID_VALUE;
8353 fib_index[i] = p[0];
8358 sw_if_index = ntohl (mp->sw_if_index);
8360 VALIDATE_SW_IF_INDEX (mp);
8363 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8366 BAD_SW_IF_INDEX_LABEL;
8369 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8373 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8376 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8378 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8379 u32 sw_if_index = ~0;
8381 /* Check src & dst are different */
8382 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8384 rv = VNET_API_ERROR_SAME_SRC_DST;
8388 memset (a, 0, sizeof (*a));
8390 /* ip addresses sent in network byte order */
8391 clib_memcpy (&(a->src), mp->src_address, 4);
8392 clib_memcpy (&(a->dst), mp->dst_address, 4);
8393 a->is_add = mp->is_add;
8394 a->lsa = ntohl (mp->local_sa_id);
8395 a->rsa = ntohl (mp->remote_sa_id);
8397 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8401 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8403 rmp->sw_if_index = ntohl (sw_if_index);
8408 static void send_ipsec_gre_tunnel_details
8409 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8411 vl_api_ipsec_gre_tunnel_details_t *rmp;
8413 rmp = vl_msg_api_alloc (sizeof (*rmp));
8414 memset (rmp, 0, sizeof (*rmp));
8415 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8416 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8417 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8418 rmp->sw_if_index = htonl (t->sw_if_index);
8419 rmp->local_sa_id = htonl (t->local_sa_id);
8420 rmp->remote_sa_id = htonl (t->remote_sa_id);
8421 rmp->context = context;
8423 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8426 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8427 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8429 unix_shared_memory_queue_t *q;
8430 ipsec_gre_main_t *igm = &ipsec_gre_main;
8431 ipsec_gre_tunnel_t *t;
8434 q = vl_api_client_index_to_input_queue (mp->client_index);
8440 sw_if_index = ntohl (mp->sw_if_index);
8442 if (~0 == sw_if_index)
8445 pool_foreach (t, igm->tunnels,
8447 send_ipsec_gre_tunnel_details(t, q, mp->context);
8453 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8454 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8458 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8459 send_ipsec_gre_tunnel_details (t, q, mp->context);
8464 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8466 vl_api_delete_subif_reply_t *rmp;
8469 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8471 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8475 vl_api_l2_interface_pbb_tag_rewrite_t_handler
8476 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
8478 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
8479 vnet_main_t *vnm = vnet_get_main ();
8480 vlib_main_t *vm = vlib_get_main ();
8484 VALIDATE_SW_IF_INDEX (mp);
8486 vtr_op = ntohl (mp->vtr_op);
8490 case L2_VTR_DISABLED:
8493 case L2_VTR_TRANSLATE_2_1:
8497 rv = VNET_API_ERROR_INVALID_VALUE;
8498 goto bad_sw_if_index;
8501 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
8502 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
8503 ntohl (mp->i_sid), ntohs (mp->outer_tag));
8505 BAD_SW_IF_INDEX_LABEL;
8507 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
8511 vl_api_punt_t_handler (vl_api_punt_t * mp)
8513 vl_api_punt_reply_t *rmp;
8514 vlib_main_t *vm = vlib_get_main ();
8516 clib_error_t *error;
8518 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8519 ntohs (mp->l4_port), mp->is_add);
8523 clib_error_report (error);
8526 REPLY_MACRO (VL_API_PUNT_REPLY);
8529 #define BOUNCE_HANDLER(nn) \
8530 static void vl_api_##nn##_t_handler ( \
8531 vl_api_##nn##_t *mp) \
8533 vpe_client_registration_t *reg; \
8534 vpe_api_main_t * vam = &vpe_api_main; \
8535 unix_shared_memory_queue_t * q; \
8537 /* One registration only... */ \
8538 pool_foreach(reg, vam->nn##_registrations, \
8540 q = vl_api_client_index_to_input_queue (reg->client_index); \
8543 * If the queue is stuffed, turf the msg and complain \
8544 * It's unlikely that the intended recipient is \
8545 * alive; avoid deadlock at all costs. \
8547 if (q->cursize == q->maxsize) { \
8548 clib_warning ("ERROR: receiver queue full, drop msg"); \
8549 vl_msg_api_free (mp); \
8552 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8556 vl_msg_api_free (mp); \
8561 * Add vpe's API message handlers to the table.
8562 * vlib has alread mapped shared memory and
8563 * added the client registration handlers.
8564 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8567 static clib_error_t *
8568 vpe_api_hookup (vlib_main_t * vm)
8570 api_main_t *am = &api_main;
8573 vl_msg_api_set_handlers(VL_API_##N, #n, \
8574 vl_api_##n##_t_handler, \
8576 vl_api_##n##_t_endian, \
8577 vl_api_##n##_t_print, \
8578 sizeof(vl_api_##n##_t), 1);
8579 foreach_vpe_api_msg;
8583 * Manually register the sr tunnel add del msg, so we trace
8584 * enough bytes to capture a typical segment list
8586 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8587 "sr_tunnel_add_del",
8588 vl_api_sr_tunnel_add_del_t_handler,
8590 vl_api_sr_tunnel_add_del_t_endian,
8591 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8595 * Manually register the sr policy add del msg, so we trace
8596 * enough bytes to capture a typical tunnel name list
8598 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8599 "sr_policy_add_del",
8600 vl_api_sr_policy_add_del_t_handler,
8602 vl_api_sr_policy_add_del_t_endian,
8603 vl_api_sr_policy_add_del_t_print, 256, 1);
8606 * Trace space for 8 MPLS encap labels, classifier mask+match
8608 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8609 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8610 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8611 += 5 * sizeof (u32x4);
8612 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8615 * Thread-safe API messages
8617 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8618 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8623 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8625 static clib_error_t *
8626 vpe_api_init (vlib_main_t * vm)
8628 vpe_api_main_t *am = &vpe_api_main;
8631 am->vnet_main = vnet_get_main ();
8632 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8633 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8634 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8635 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8636 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8637 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8640 vl_set_memory_region_name ("/vpe-api");
8641 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8646 VLIB_INIT_FUNCTION (vpe_api_init);
8649 static clib_error_t *
8650 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8653 u64 baseva, size, pvt_heap_size;
8655 const int max_buf_size = 4096;
8657 struct passwd _pw, *pw;
8658 struct group _grp, *grp;
8660 buf = vec_new (char, 128);
8661 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8663 if (unformat (input, "prefix %s", &chroot_path))
8665 vec_add1 (chroot_path, 0);
8666 vl_set_memory_root_path ((char *) chroot_path);
8668 else if (unformat (input, "uid %d", &uid))
8669 vl_set_memory_uid (uid);
8670 else if (unformat (input, "gid %d", &gid))
8671 vl_set_memory_gid (gid);
8672 else if (unformat (input, "baseva %llx", &baseva))
8673 vl_set_global_memory_baseva (baseva);
8674 else if (unformat (input, "global-size %lldM", &size))
8675 vl_set_global_memory_size (size * (1ULL << 20));
8676 else if (unformat (input, "global-size %lldG", &size))
8677 vl_set_global_memory_size (size * (1ULL << 30));
8678 else if (unformat (input, "global-size %lld", &size))
8679 vl_set_global_memory_size (size);
8680 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8681 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8682 else if (unformat (input, "global-pvt-heap-size size %lld",
8684 vl_set_global_pvt_heap_size (pvt_heap_size);
8685 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8686 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8687 else if (unformat (input, "api-pvt-heap-size size %lld",
8689 vl_set_api_pvt_heap_size (pvt_heap_size);
8690 else if (unformat (input, "api-size %lldM", &size))
8691 vl_set_api_memory_size (size * (1ULL << 20));
8692 else if (unformat (input, "api-size %lldG", &size))
8693 vl_set_api_memory_size (size * (1ULL << 30));
8694 else if (unformat (input, "api-size %lld", &size))
8695 vl_set_api_memory_size (size);
8696 else if (unformat (input, "uid %s", &s))
8698 /* lookup the username */
8701 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8702 && (vec_len (buf) <= max_buf_size))
8704 vec_resize (buf, vec_len (buf) * 2);
8708 e = clib_error_return_code (0, rv,
8709 CLIB_ERROR_ERRNO_VALID |
8711 "cannot fetch username %s", s);
8719 clib_error_return_fatal (0, "username %s does not exist", s);
8725 vl_set_memory_uid (pw->pw_uid);
8727 else if (unformat (input, "gid %s", &s))
8729 /* lookup the group name */
8732 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8733 && (vec_len (buf) <= max_buf_size))
8735 vec_resize (buf, vec_len (buf) * 2);
8739 e = clib_error_return_code (0, rv,
8740 CLIB_ERROR_ERRNO_VALID |
8742 "cannot fetch group %s", s);
8749 e = clib_error_return_fatal (0, "group %s does not exist", s);
8756 vl_set_memory_gid (grp->gr_gid);
8759 return clib_error_return (0, "unknown input `%U'",
8760 format_unformat_error, input);
8765 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8768 get_unformat_vnet_sw_interface (void)
8770 return (void *) &unformat_vnet_sw_interface;
8773 #undef vl_api_version
8774 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8775 #include <vpp-api/vpe.api.h>
8776 #undef vl_api_version
8779 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8781 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8783 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8784 clib_host_to_net_u32 (mp->api_versions[0]),
8792 format_arp_event (u8 * s, va_list * args)
8794 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8796 s = format (s, "pid %d: ", event->pid);
8798 s = format (s, "bd mac/ip4 binding events");
8800 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8805 format_nd_event (u8 * s, va_list * args)
8807 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8809 s = format (s, "pid %d: ", event->pid);
8811 s = format (s, "bd mac/ip6 binding events");
8813 s = format (s, "resolution for %U", format_ip6_address, event->address);
8817 static clib_error_t *
8818 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8819 unformat_input_t * input, vlib_cli_command_t * cmd)
8821 vpe_api_main_t *am = &vpe_api_main;
8822 vl_api_ip4_arp_event_t *arp_event;
8823 vl_api_ip6_nd_event_t *nd_event;
8825 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8827 vlib_cli_output (vm, "No active arp or nd event registrations");
8832 pool_foreach (arp_event, am->arp_events,
8834 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8837 pool_foreach (nd_event, am->nd_events,
8839 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8847 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8848 .path = "show arp-nd-event registrations",
8849 .function = show_ip_arp_nd_events_fn,
8850 .short_help = "Show ip4 arp and ip6 nd event registrations",
8855 * fd.io coding-style-patch-verification: ON
8858 * eval: (c-set-style "gnu")