2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010 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-gre/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-cp/control.h>
78 #include <vnet/map/map.h>
79 #include <vnet/cop/cop.h>
80 #include <vnet/ip/ip6_hop_by_hop.h>
81 #include <vnet/ip/ip_source_and_port_range_check.h>
82 #include <vnet/devices/af_packet/af_packet.h>
83 #include <vnet/policer/policer.h>
84 #include <vnet/devices/netmap/netmap.h>
85 #include <vnet/flow/flow_report.h>
86 #include <vnet/ipsec-gre/ipsec_gre.h>
87 #include <vnet/flow/flow_report_classify.h>
90 #undef __included_bihash_template_h__
91 #include <vnet/l2/l2_fib.h>
94 #include <vnet/ipsec/ipsec.h>
95 #include <vnet/ipsec/ikev2.h>
97 #include <vnet/devices/virtio/vhost-user.h>
99 #include <stats/stats.h>
102 #include <vnet/ethernet/ethernet.h>
103 #include <vnet/ethernet/arp_packet.h>
104 #include <vnet/interface.h>
106 #include <vnet/l2/l2_fib.h>
107 #include <vnet/l2/l2_bd.h>
108 #include <vpp-api/vpe_msg_enum.h>
110 #define f64_endian(a)
111 #define f64_print(a,b)
113 #define vl_typedefs /* define message structures */
114 #include <vpp-api/vpe_all_api_h.h>
117 #define vl_endianfun /* define message structures */
118 #include <vpp-api/vpe_all_api_h.h>
121 /* instantiate all the print functions we know about */
122 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
124 #include <vpp-api/vpe_all_api_h.h>
127 #define REPLY_MACRO(t) \
129 unix_shared_memory_queue_t * q; \
130 rv = vl_msg_api_pd_handler (mp, rv); \
131 q = vl_api_client_index_to_input_queue (mp->client_index); \
135 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
136 rmp->_vl_msg_id = ntohs((t)); \
137 rmp->context = mp->context; \
138 rmp->retval = ntohl(rv); \
140 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
143 #define REPLY_MACRO2(t, body) \
145 unix_shared_memory_queue_t * q; \
146 rv = vl_msg_api_pd_handler (mp, rv); \
147 q = vl_api_client_index_to_input_queue (mp->client_index); \
151 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
152 rmp->_vl_msg_id = ntohs((t)); \
153 rmp->context = mp->context; \
154 rmp->retval = ntohl(rv); \
155 do {body;} while (0); \
156 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
159 #define REPLY_MACRO3(t, n, body) \
161 unix_shared_memory_queue_t * q; \
162 rv = vl_msg_api_pd_handler (mp, rv); \
163 q = vl_api_client_index_to_input_queue (mp->client_index); \
167 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
168 rmp->_vl_msg_id = ntohs((t)); \
169 rmp->context = mp->context; \
170 rmp->retval = ntohl(rv); \
171 do {body;} while (0); \
172 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
175 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
177 #define VALIDATE_SW_IF_INDEX(mp) \
178 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
179 vnet_main_t *__vnm = vnet_get_main(); \
180 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
182 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
183 goto bad_sw_if_index; \
187 #define BAD_SW_IF_INDEX_LABEL \
193 #define VALIDATE_RX_SW_IF_INDEX(mp) \
194 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
195 vnet_main_t *__vnm = vnet_get_main(); \
196 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
197 __rx_sw_if_index)) { \
198 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
199 goto bad_rx_sw_if_index; \
203 #define BAD_RX_SW_IF_INDEX_LABEL \
205 bad_rx_sw_if_index: \
209 #define VALIDATE_TX_SW_IF_INDEX(mp) \
210 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
211 vnet_main_t *__vnm = vnet_get_main(); \
212 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
213 __tx_sw_if_index)) { \
214 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
215 goto bad_tx_sw_if_index; \
219 #define BAD_TX_SW_IF_INDEX_LABEL \
221 bad_tx_sw_if_index: \
227 #define VALIDATE_SW_IF_INDEX(mp)
228 #define BAD_SW_IF_INDEX_LABEL
229 #define VALIDATE_RX_SW_IF_INDEX(mp)
230 #define BAD_RX_SW_IF_INDEX_LABEL
231 #define VALIDATE_TX_SW_IF_INDEX(mp)
232 #define BAD_TX_SW_IF_INDEX_LABEL
234 #endif /* CLIB_DEBUG > 0 */
236 #define foreach_vpe_api_msg \
237 _(WANT_INTERFACE_EVENTS, want_interface_events) \
238 _(WANT_OAM_EVENTS, want_oam_events) \
239 _(OAM_ADD_DEL, oam_add_del) \
240 _(SW_INTERFACE_DUMP, sw_interface_dump) \
241 _(SW_INTERFACE_DETAILS, sw_interface_details) \
242 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
243 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
244 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
245 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
246 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
247 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
248 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
249 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
250 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
251 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
252 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
253 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
254 _(L2FIB_ADD_DEL, l2fib_add_del) \
255 _(L2_FLAGS, l2_flags) \
256 _(BRIDGE_FLAGS, bridge_flags) \
257 _(TAP_CONNECT, tap_connect) \
258 _(TAP_MODIFY, tap_modify) \
259 _(TAP_DELETE, tap_delete) \
260 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
261 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
262 _(CREATE_SUBIF, create_subif) \
263 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
264 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
265 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
266 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
267 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
268 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
269 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
270 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
271 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
272 _(RESET_FIB, reset_fib) \
273 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
274 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
275 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
276 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
277 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
278 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
279 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
280 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
281 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
282 sw_interface_ip6_set_link_local_address) \
283 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
284 _(CREATE_LOOPBACK, create_loopback) \
285 _(CONTROL_PING, control_ping) \
286 _(CLI_REQUEST, cli_request) \
287 _(CLI_INBAND, cli_inband) \
288 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
289 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
290 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
291 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
292 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
293 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
294 _(GET_NODE_INDEX, get_node_index) \
295 _(ADD_NODE_NEXT, add_node_next) \
296 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
297 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
298 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
299 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
300 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
301 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
302 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
303 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
304 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
305 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
306 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
307 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
308 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
309 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
310 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
311 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
312 _(IP_ADDRESS_DUMP, ip_address_dump) \
313 _(IP_DUMP, ip_dump) \
314 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
315 _(SHOW_VERSION, show_version) \
316 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
317 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
318 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
319 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
320 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
321 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
322 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
323 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
324 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
325 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
326 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
327 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
328 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
329 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
330 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
331 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
332 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
333 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
334 _(DELETE_LOOPBACK, delete_loopback) \
335 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
336 _(MAP_ADD_DOMAIN, map_add_domain) \
337 _(MAP_DEL_DOMAIN, map_del_domain) \
338 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
339 _(MAP_DOMAIN_DUMP, map_domain_dump) \
340 _(MAP_RULE_DUMP, map_rule_dump) \
341 _(MAP_SUMMARY_STATS, map_summary_stats) \
342 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
343 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
344 _(GET_NODE_GRAPH, get_node_graph) \
345 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
346 _(IOAM_ENABLE, ioam_enable) \
347 _(IOAM_DISABLE, ioam_disable) \
348 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
349 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
350 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
351 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
352 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
353 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
354 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
355 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
356 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
357 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
358 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
359 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
360 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
361 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
362 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
363 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
364 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
365 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
366 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
367 _(SHOW_LISP_STATUS, show_lisp_status) \
368 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
369 lisp_add_del_map_request_itr_rlocs) \
370 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
371 _(SHOW_LISP_PITR, show_lisp_pitr) \
372 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
373 _(AF_PACKET_CREATE, af_packet_create) \
374 _(AF_PACKET_DELETE, af_packet_delete) \
375 _(POLICER_ADD_DEL, policer_add_del) \
376 _(POLICER_DUMP, policer_dump) \
377 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
378 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
379 _(NETMAP_CREATE, netmap_create) \
380 _(NETMAP_DELETE, netmap_delete) \
381 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
382 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
383 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
384 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
385 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
386 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
387 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
388 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
389 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
390 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
391 _(CLASSIFY_TABLE_INFO,classify_table_info) \
392 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
393 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
394 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
395 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
396 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
397 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
398 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
399 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
400 _(GET_NEXT_INDEX, get_next_index) \
401 _(PG_CREATE_INTERFACE, pg_create_interface) \
402 _(PG_CAPTURE, pg_capture) \
403 _(PG_ENABLE_DISABLE, pg_enable_disable) \
404 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
405 ip_source_and_port_range_check_add_del) \
406 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
407 ip_source_and_port_range_check_interface_add_del) \
408 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
409 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
410 _(DELETE_SUBIF, delete_subif)
413 #define QUOTE(x) QUOTE_(x)
415 #define foreach_registration_hash \
416 _(interface_events) \
417 _(to_netconf_server) \
418 _(from_netconf_server) \
419 _(to_netconf_client) \
420 _(from_netconf_client) \
425 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
426 RESOLVE_IP6_ADD_DEL_ROUTE,
427 RESOLVE_MPLS_ETHERNET_ADD_DEL,
435 vl_api_ip_add_del_route_t r;
436 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
443 #define _(a) uword *a##_registration_hash; \
444 vpe_client_registration_t * a##_registrations;
445 foreach_registration_hash
447 /* notifications happen really early in the game */
448 u8 link_state_process_up;
450 /* ip4 and ip6 pending route adds */
451 pending_route_t *pending_routes;
453 /* ip4 arp event registration pool */
454 vl_api_ip4_arp_event_t *arp_events;
456 /* ip6 nd event registration pool */
457 vl_api_ip6_nd_event_t *nd_events;
460 vlib_main_t *vlib_main;
461 vnet_main_t *vnet_main;
464 static vlib_node_registration_t vpe_resolver_process_node;
465 static vpe_api_main_t vpe_api_main;
467 static void send_sw_interface_flags (vpe_api_main_t * am,
468 unix_shared_memory_queue_t * q,
469 vnet_sw_interface_t * swif);
470 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
471 unix_shared_memory_queue_t * q,
474 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
475 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
478 /* Clean up all registrations belonging to the indicated client */
480 vl_api_memclnt_delete_callback (u32 client_index)
482 vpe_api_main_t *vam = &vpe_api_main;
483 vpe_client_registration_t *rp;
485 int stats_memclnt_delete_callback (u32 client_index);
487 stats_memclnt_delete_callback (client_index);
490 p = hash_get (vam->a##_registration_hash, client_index); \
492 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
493 pool_put (vam->a##_registrations, rp); \
494 hash_unset (vam->a##_registration_hash, client_index); \
496 foreach_registration_hash;
501 #define API_LINK_STATE_EVENT 1
502 #define API_ADMIN_UP_DOWN_EVENT 2
505 event_data_cmp (void *a1, void *a2)
510 return (word) e1[0] - (word) e2[0];
514 link_state_process (vlib_main_t * vm,
515 vlib_node_runtime_t * rt, vlib_frame_t * f)
517 vpe_api_main_t *vam = &vpe_api_main;
518 vnet_main_t *vnm = vam->vnet_main;
519 vnet_sw_interface_t *swif;
520 uword *event_data = 0;
521 vpe_client_registration_t *reg;
523 u32 prev_sw_if_index;
524 unix_shared_memory_queue_t *q;
526 vam->link_state_process_up = 1;
530 vlib_process_wait_for_event (vm);
532 /* Unified list of changed link or admin state sw_if_indices */
533 vlib_process_get_events_with_type
534 (vm, &event_data, API_LINK_STATE_EVENT);
535 vlib_process_get_events_with_type
536 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
538 /* Sort, so we can eliminate duplicates */
539 vec_sort_with_function (event_data, event_data_cmp);
541 prev_sw_if_index = ~0;
543 for (i = 0; i < vec_len (event_data); i++)
545 /* Only one message per swif */
546 if (prev_sw_if_index == event_data[i])
548 prev_sw_if_index = event_data[i];
551 pool_foreach(reg, vam->interface_events_registrations,
553 q = vl_api_client_index_to_input_queue (reg->client_index);
556 /* sw_interface may be deleted already */
557 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
560 swif = vnet_get_sw_interface (vnm, event_data[i]);
561 send_sw_interface_flags (vam, q, swif);
567 vec_reset_length (event_data);
573 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
575 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
576 u32 hw_if_index, u32 flags);
579 VLIB_REGISTER_NODE (link_state_process_node,static) = {
580 .function = link_state_process,
581 .type = VLIB_NODE_TYPE_PROCESS,
582 .name = "vpe-link-state-process",
586 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
587 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
589 static clib_error_t *
590 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
592 vpe_api_main_t *vam = &vpe_api_main;
593 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
595 if (vam->link_state_process_up)
596 vlib_process_signal_event (vam->vlib_main,
597 link_state_process_node.index,
598 API_LINK_STATE_EVENT, hi->sw_if_index);
602 static clib_error_t *
603 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
605 vpe_api_main_t *vam = &vpe_api_main;
608 * Note: it's perfectly fair to set a subif admin up / admin down.
609 * Note the subtle distinction between this routine and the previous
612 if (vam->link_state_process_up)
613 vlib_process_signal_event (vam->vlib_main,
614 link_state_process_node.index,
615 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
619 #define pub_sub_handler(lca,UCA) \
620 static void vl_api_want_##lca##_t_handler ( \
621 vl_api_want_##lca##_t *mp) \
623 vpe_api_main_t *vam = &vpe_api_main; \
624 vpe_client_registration_t *rp; \
625 vl_api_want_##lca##_reply_t *rmp; \
629 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
631 if (mp->enable_disable) { \
632 clib_warning ("pid %d: already enabled...", mp->pid); \
633 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
636 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
637 pool_put (vam->lca##_registrations, rp); \
638 hash_unset (vam->lca##_registration_hash, \
643 if (mp->enable_disable == 0) { \
644 clib_warning ("pid %d: already disabled...", mp->pid); \
645 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
648 pool_get (vam->lca##_registrations, rp); \
649 rp->client_index = mp->client_index; \
650 rp->client_pid = mp->pid; \
651 hash_set (vam->lca##_registration_hash, rp->client_index, \
652 rp - vam->lca##_registrations); \
655 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
659 pub_sub_handler (interface_events, INTERFACE_EVENTS)
660 pub_sub_handler (oam_events, OAM_EVENTS)
663 #define RESOLUTION_EVENT 1
664 #define RESOLUTION_PENDING_EVENT 2
665 #define IP4_ARP_EVENT 3
666 #define IP6_ND_EVENT 4
668 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
670 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
672 static int mpls_ethernet_add_del_tunnel_2_t_handler
673 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
676 handle_ip4_arp_event (u32 pool_index)
678 vpe_api_main_t *vam = &vpe_api_main;
679 vnet_main_t *vnm = vam->vnet_main;
680 vlib_main_t *vm = vam->vlib_main;
681 vl_api_ip4_arp_event_t *event;
682 vl_api_ip4_arp_event_t *mp;
683 unix_shared_memory_queue_t *q;
685 /* Client can cancel, die, etc. */
686 if (pool_is_free_index (vam->arp_events, pool_index))
689 event = pool_elt_at_index (vam->arp_events, pool_index);
691 q = vl_api_client_index_to_input_queue (event->client_index);
694 (void) vnet_add_del_ip4_arp_change_event
695 (vnm, arp_change_delete_callback,
696 event->pid, &event->address,
697 vpe_resolver_process_node.index, IP4_ARP_EVENT,
698 ~0 /* pool index, notused */ , 0 /* is_add */ );
702 if (q->cursize < q->maxsize)
704 mp = vl_msg_api_alloc (sizeof (*mp));
705 clib_memcpy (mp, event, sizeof (*mp));
706 vl_msg_api_send_shmem (q, (u8 *) & mp);
710 static f64 last_time;
712 * Throttle syslog msgs.
713 * It's pretty tempting to just revoke the registration...
715 if (vlib_time_now (vm) > last_time + 10.0)
717 clib_warning ("arp event for %U to pid %d: queue stuffed!",
718 format_ip4_address, &event->address, event->pid);
719 last_time = vlib_time_now (vm);
725 handle_ip6_nd_event (u32 pool_index)
727 vpe_api_main_t *vam = &vpe_api_main;
728 vnet_main_t *vnm = vam->vnet_main;
729 vlib_main_t *vm = vam->vlib_main;
730 vl_api_ip6_nd_event_t *event;
731 vl_api_ip6_nd_event_t *mp;
732 unix_shared_memory_queue_t *q;
734 /* Client can cancel, die, etc. */
735 if (pool_is_free_index (vam->nd_events, pool_index))
738 event = pool_elt_at_index (vam->nd_events, pool_index);
740 q = vl_api_client_index_to_input_queue (event->client_index);
743 (void) vnet_add_del_ip6_nd_change_event
744 (vnm, nd_change_delete_callback,
745 event->pid, &event->address,
746 vpe_resolver_process_node.index, IP6_ND_EVENT,
747 ~0 /* pool index, notused */ , 0 /* is_add */ );
751 if (q->cursize < q->maxsize)
753 mp = vl_msg_api_alloc (sizeof (*mp));
754 clib_memcpy (mp, event, sizeof (*mp));
755 vl_msg_api_send_shmem (q, (u8 *) & mp);
759 static f64 last_time;
761 * Throttle syslog msgs.
762 * It's pretty tempting to just revoke the registration...
764 if (vlib_time_now (vm) > last_time + 10.0)
766 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
767 format_ip6_address, &event->address, event->pid);
768 last_time = vlib_time_now (vm);
774 resolver_process (vlib_main_t * vm,
775 vlib_node_runtime_t * rt, vlib_frame_t * f)
778 uword *event_data = 0;
780 vpe_api_main_t *vam = &vpe_api_main;
782 vl_api_ip_add_del_route_t *adr;
783 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
784 u32 *resolution_failures = 0;
790 vlib_process_wait_for_event_or_clock (vm, timeout);
792 event_type = vlib_process_get_events (vm, &event_data);
796 case RESOLUTION_PENDING_EVENT:
800 case RESOLUTION_EVENT:
801 for (i = 0; i < vec_len (event_data); i++)
804 * Resolution events can occur long after the
805 * original request has timed out. $$$ add a cancel
808 if (pool_is_free_index (vam->pending_routes, event_data[i]))
811 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
815 switch (pr->resolve_type)
817 case RESOLVE_IP4_ADD_DEL_ROUTE:
818 rv = ip4_add_del_route_t_handler (adr);
819 clib_warning ("resolver: add %U/%d via %U %s",
821 (ip4_address_t *) & (adr->dst_address),
822 adr->dst_address_length,
824 (ip4_address_t *) & (adr->next_hop_address),
825 (rv >= 0) ? "succeeded" : "failed");
828 case RESOLVE_IP6_ADD_DEL_ROUTE:
829 rv = ip6_add_del_route_t_handler (adr);
830 clib_warning ("resolver: add %U/%d via %U %s",
832 (ip6_address_t *) & (adr->dst_address),
833 adr->dst_address_length,
835 (ip6_address_t *) & (adr->next_hop_address),
836 (rv >= 0) ? "succeeded" : "failed");
839 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
840 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
841 clib_warning ("resolver: add mpls-o-e via %U %s",
844 (pme->next_hop_ip4_address_in_outer_vrf),
845 (rv >= 0) ? "succeeded" : "failed");
849 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
851 pool_put (vam->pending_routes, pr);
856 for (i = 0; i < vec_len (event_data); i++)
857 handle_ip4_arp_event (event_data[i]);
861 for (i = 0; i < vec_len (event_data); i++)
862 handle_ip6_nd_event (event_data[i]);
865 case ~0: /* timeout, retry pending resolutions */
867 pool_foreach (pr, vam->pending_routes,
873 /* May fail, e.g. due to interface down */
874 switch (pr->resolve_type)
876 case RESOLVE_IP4_ADD_DEL_ROUTE:
877 e = ip4_probe_neighbor
878 (vm, (ip4_address_t *)&(adr->next_hop_address),
879 ntohl(adr->next_hop_sw_if_index));
882 case RESOLVE_IP6_ADD_DEL_ROUTE:
883 e = ip6_probe_neighbor
884 (vm, (ip6_address_t *)&(adr->next_hop_address),
885 ntohl(adr->next_hop_sw_if_index));
888 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
890 e = ip4_probe_neighbor
892 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
893 pme->resolve_opaque);
897 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
902 clib_error_report (e);
904 adr->resolve_attempts = 1;
906 pme->resolve_attempts = 1;
910 adr->resolve_attempts -= 1;
911 if (adr->resolve_attempts == 0)
912 vec_add1 (resolution_failures,
913 pr - vam->pending_routes);
917 pme->resolve_attempts -= 1;
918 if (pme->resolve_attempts == 0)
919 vec_add1 (resolution_failures,
920 pr - vam->pending_routes);
924 for (i = 0; i < vec_len (resolution_failures); i++)
926 pr = pool_elt_at_index (vam->pending_routes,
927 resolution_failures[i]);
931 switch (pr->resolve_type)
933 case RESOLVE_IP4_ADD_DEL_ROUTE:
934 clib_warning ("resolver: add %U/%d via %U retry failure",
936 (ip4_address_t *) & (adr->dst_address),
937 adr->dst_address_length,
939 (ip4_address_t *) & (adr->next_hop_address));
942 case RESOLVE_IP6_ADD_DEL_ROUTE:
943 clib_warning ("resolver: add %U/%d via %U retry failure",
945 (ip6_address_t *) & (adr->dst_address),
946 adr->dst_address_length,
948 (ip6_address_t *) & (adr->next_hop_address));
951 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
952 clib_warning ("resolver: add mpls-o-e via %U retry failure",
955 (pme->next_hop_ip4_address_in_outer_vrf));
959 clib_warning ("BUG");
961 pool_put (vam->pending_routes, pr);
963 vec_reset_length (resolution_failures);
966 if (pool_elts (vam->pending_routes) == 0)
968 vec_reset_length (event_data);
970 return 0; /* or not */
974 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
975 .function = resolver_process,
976 .type = VLIB_NODE_TYPE_PROCESS,
977 .name = "vpe-route-resolver-process",
982 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
984 ip4_main_t *im = &ip4_main;
985 ip_lookup_main_t *lm = &im->lookup_main;
986 vnet_classify_main_t *cm = &vnet_classify_main;
987 stats_main_t *sm = &stats_main;
988 ip4_add_del_route_args_t a;
989 ip4_address_t next_hop_address;
991 vpe_api_main_t *vam = &vpe_api_main;
992 vnet_main_t *vnm = vam->vnet_main;
993 vlib_main_t *vm = vlib_get_main ();
995 vl_api_ip_add_del_route_t *adr;
1001 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1004 if (mp->create_vrf_if_needed)
1007 f = find_ip4_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1009 fib_index = f->index;
1013 /* No such VRF, and we weren't asked to create one */
1014 return VNET_API_ERROR_NO_SUCH_FIB;
1022 if (~0 != mp->next_hop_sw_if_index &&
1023 pool_is_free_index (vnm->interface_main.sw_interfaces,
1024 ntohl (mp->next_hop_sw_if_index)))
1025 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1027 clib_memcpy (next_hop_address.data, mp->next_hop_address,
1028 sizeof (next_hop_address.data));
1030 /* Arp for the next_hop if necessary */
1031 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1034 ip_adjacency_t *adj;
1036 lookup_result = ip4_fib_lookup_with_table
1037 (im, fib_index, &next_hop_address, 1 /* disable default route */ );
1039 adj = ip_get_adjacency (lm, lookup_result);
1041 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1043 pool_get (vam->pending_routes, pr);
1044 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
1046 clib_memcpy (adr, mp, sizeof (*adr));
1047 /* recursion block, "just in case" */
1048 adr->resolve_if_needed = 0;
1049 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1050 vnet_register_ip4_arp_resolution_event
1051 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1052 RESOLUTION_EVENT, pr - vam->pending_routes);
1054 vlib_process_signal_event
1055 (vm, vpe_resolver_process_node.index,
1056 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1058 /* The interface may be down, etc. */
1059 e = ip4_probe_neighbor
1060 (vm, (ip4_address_t *) & (mp->next_hop_address),
1061 ntohl (mp->next_hop_sw_if_index));
1064 clib_error_report (e);
1066 return VNET_API_ERROR_IN_PROGRESS;
1070 if (mp->is_multipath)
1074 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1077 flags = IP4_ROUTE_FLAG_ADD;
1079 flags = IP4_ROUTE_FLAG_DEL;
1082 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1084 ip4_add_del_route_next_hop (im, flags,
1085 (ip4_address_t *) mp->dst_address,
1086 (u32) mp->dst_address_length,
1087 (ip4_address_t *) mp->next_hop_address,
1088 ntohl (mp->next_hop_sw_if_index),
1089 (u32) mp->next_hop_weight,
1090 ~0 /* adj_index */ ,
1096 memset (&a, 0, sizeof (a));
1097 clib_memcpy (a.dst_address.data, mp->dst_address,
1098 sizeof (a.dst_address.data));
1100 a.dst_address_length = mp->dst_address_length;
1102 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
1103 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
1104 a.table_index_or_table_id = fib_index;
1109 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1111 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1116 ai = lm->drop_adj_index;
1117 else if (mp->is_local)
1118 ai = lm->local_adj_index;
1119 else if (mp->is_classify)
1121 if (pool_is_free_index
1122 (cm->tables, ntohl (mp->classify_table_index)))
1125 return VNET_API_ERROR_NO_SUCH_TABLE;
1127 adj = ip_add_adjacency (lm,
1132 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
1133 adj->classify.table_index = ntohl (mp->classify_table_index);
1135 else if (mp->lookup_in_vrf)
1137 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1140 adj = ip_add_adjacency (lm,
1144 adj->explicit_fib_index = p[0];
1149 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1153 ai = ip4_route_get_next_hop_adj (im,
1156 ntohl (mp->next_hop_sw_if_index),
1159 if (ai == lm->miss_adj_index)
1162 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1167 ip_adjacency_t *adj;
1168 int disable_default_route = 1;
1170 /* Trying to delete the default route? */
1171 if (a.dst_address.as_u32 == 0 && a.dst_address_length == 0)
1172 disable_default_route = 0;
1174 ai = ip4_fib_lookup_with_table
1175 (im, fib_index, &a.dst_address, disable_default_route);
1176 if (ai == lm->miss_adj_index)
1179 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1182 adj = ip_get_adjacency (lm, ai);
1183 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1186 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1191 ip4_add_del_route (im, &a);
1198 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1200 ip6_main_t *im = &ip6_main;
1201 ip_lookup_main_t *lm = &im->lookup_main;
1202 vnet_main_t *vnm = vnet_get_main ();
1203 vlib_main_t *vm = vlib_get_main ();
1204 vpe_api_main_t *vam = &vpe_api_main;
1205 stats_main_t *sm = &stats_main;
1206 ip6_add_del_route_args_t a;
1207 ip6_address_t next_hop_address;
1208 pending_route_t *pr;
1209 vl_api_ip_add_del_route_t *adr;
1214 ip_adjacency_t *adj = 0;
1217 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1221 if (mp->create_vrf_if_needed)
1224 f = find_ip6_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1226 fib_index = f->index;
1230 /* No such VRF, and we weren't asked to create one */
1231 return VNET_API_ERROR_NO_SUCH_FIB;
1239 if (~0 != mp->next_hop_sw_if_index &&
1240 pool_is_free_index (vnm->interface_main.sw_interfaces,
1241 ntohl (mp->next_hop_sw_if_index)))
1242 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1244 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1245 sizeof (next_hop_address.as_u8));
1247 /* Arp for the next_hop if necessary */
1248 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1251 ip_adjacency_t *adj;
1253 lookup_result = ip6_fib_lookup_with_table
1254 (im, fib_index, &next_hop_address);
1256 adj = ip_get_adjacency (lm, lookup_result);
1258 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1260 pool_get (vam->pending_routes, pr);
1262 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1263 clib_memcpy (adr, mp, sizeof (*adr));
1264 /* recursion block, "just in case" */
1265 adr->resolve_if_needed = 0;
1266 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1267 vnet_register_ip6_neighbor_resolution_event
1268 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1269 RESOLUTION_EVENT, pr - vam->pending_routes);
1271 vlib_process_signal_event
1272 (vm, vpe_resolver_process_node.index,
1273 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1275 /* The interface may be down, etc. */
1276 e = ip6_probe_neighbor
1277 (vm, (ip6_address_t *) & (mp->next_hop_address),
1278 ntohl (mp->next_hop_sw_if_index));
1281 clib_error_report (e);
1283 return VNET_API_ERROR_IN_PROGRESS;
1287 if (mp->is_multipath)
1291 dslock (sm, 1 /* release hint */ , 11 /* tag */ );
1294 flags = IP6_ROUTE_FLAG_ADD;
1296 flags = IP6_ROUTE_FLAG_DEL;
1299 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1301 ip6_add_del_route_next_hop (im, flags,
1302 (ip6_address_t *) mp->dst_address,
1303 (u32) mp->dst_address_length,
1304 (ip6_address_t *) mp->next_hop_address,
1305 ntohl (mp->next_hop_sw_if_index),
1306 (u32) mp->next_hop_weight,
1307 ~0 /* adj_index */ ,
1313 memset (&a, 0, sizeof (a));
1314 clib_memcpy (a.dst_address.as_u8, mp->dst_address,
1315 sizeof (a.dst_address.as_u8));
1317 a.dst_address_length = mp->dst_address_length;
1319 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1320 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1321 a.table_index_or_table_id = fib_index;
1326 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1328 dslock (sm, 1 /* release hint */ , 3 /* tag */ );
1333 ai = lm->drop_adj_index;
1334 else if (mp->is_local)
1335 ai = lm->local_adj_index;
1336 else if (mp->lookup_in_vrf)
1338 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1341 adj = ip_add_adjacency (lm,
1345 adj->explicit_fib_index = p[0];
1350 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1354 ai = ip6_route_get_next_hop_adj (im,
1357 ntohl (mp->next_hop_sw_if_index),
1359 if (ai == lm->miss_adj_index)
1362 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1367 ip_adjacency_t *adj;
1369 ai = ip6_fib_lookup_with_table (im, fib_index, &a.dst_address);
1370 if (ai == lm->miss_adj_index)
1373 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1375 adj = ip_get_adjacency (lm, ai);
1376 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1379 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1384 ip6_add_del_route (im, &a);
1391 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1393 vl_api_ip_add_del_route_reply_t *rmp;
1395 vnet_main_t *vnm = vnet_get_main ();
1400 rv = ip6_add_del_route_t_handler (mp);
1402 rv = ip4_add_del_route_t_handler (mp);
1404 rv = (rv == 0) ? vnm->api_errno : rv;
1406 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1410 api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1411 u32 sw_if_index, u8 * next_hop_addr)
1413 vl_api_ip_add_del_route_t mp;
1416 memset (&mp, 0, sizeof (vl_api_ip_add_del_route_t));
1419 * Configure default IP route:
1420 * - ip route add 0.0.0.0/1 via <GW IP>
1421 * - ip route add 128.0.0.0/1 via <GW IP>
1423 mp.next_hop_sw_if_index = ntohl (sw_if_index);
1425 mp.resolve_attempts = ~0;
1426 mp.resolve_if_needed = 1;
1428 mp.is_ipv6 = is_ipv6;
1429 mp.next_hop_weight = 1;
1431 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1434 rv = ip6_add_del_route_t_handler (&mp);
1437 mp.dst_address_length = 1;
1439 mp.dst_address[0] = 0;
1440 rv = ip4_add_del_route_t_handler (&mp);
1442 mp.dst_address[0] = 128;
1443 rv |= ip4_add_del_route_t_handler (&mp);
1447 clib_error_return (0, "failed to config default IP route");
1452 vl_api_sw_interface_add_del_address_t_handler
1453 (vl_api_sw_interface_add_del_address_t * mp)
1455 vlib_main_t *vm = vlib_get_main ();
1456 vl_api_sw_interface_add_del_address_reply_t *rmp;
1460 VALIDATE_SW_IF_INDEX (mp);
1462 is_del = mp->is_add == 0;
1465 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1466 else if (mp->is_ipv6)
1467 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1468 (void *) mp->address,
1469 mp->address_length, is_del);
1471 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1472 (void *) mp->address,
1473 mp->address_length, is_del);
1475 BAD_SW_IF_INDEX_LABEL;
1477 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1481 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1484 u32 table_id = ntohl (mp->vrf_id);
1485 u32 sw_if_index = ntohl (mp->sw_if_index);
1486 vl_api_sw_interface_set_table_reply_t *rmp;
1487 stats_main_t *sm = &stats_main;
1489 VALIDATE_SW_IF_INDEX (mp);
1491 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1495 ip6_main_t *im = &ip6_main;
1496 ip6_fib_t *fib = find_ip6_fib_by_table_index_or_id (im, table_id,
1497 IP6_ROUTE_FLAG_TABLE_ID);
1500 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1501 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1505 rv = VNET_API_ERROR_NO_SUCH_FIB;
1510 ip4_main_t *im = &ip4_main;
1511 ip4_fib_t *fib = find_ip4_fib_by_table_index_or_id
1512 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1514 /* Truthfully this can't fail */
1517 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1518 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1522 rv = VNET_API_ERROR_NO_SUCH_FIB;
1527 BAD_SW_IF_INDEX_LABEL;
1529 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1533 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1535 vlib_main_t *vm = vlib_get_main ();
1536 ip4_main_t *im4 = &ip4_main;
1537 ip6_main_t *im6 = &ip6_main;
1538 vl_api_sw_interface_set_vpath_reply_t *rmp;
1541 u32 sw_if_index = ntohl (mp->sw_if_index);
1542 ip4_main_t *ip4m = &ip4_main;
1543 ip6_main_t *ip6m = &ip6_main;
1544 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1545 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1546 ip_config_main_t *rx_cm4u =
1547 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1548 ip_config_main_t *rx_cm4m =
1549 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1550 ip_config_main_t *rx_cm6u =
1551 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1552 ip_config_main_t *rx_cm6m =
1553 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1555 VALIDATE_SW_IF_INDEX (mp);
1557 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1560 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1561 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1563 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1564 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1565 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1566 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1568 im4->ip4_multicast_rx_feature_vpath,
1570 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1571 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1572 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1574 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1575 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1576 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1577 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1579 im6->ip6_multicast_rx_feature_vpath,
1581 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1585 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1586 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1588 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1589 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1590 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1591 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1593 im4->ip4_multicast_rx_feature_vpath,
1595 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1596 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1597 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1599 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1600 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1601 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1602 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1604 im6->ip6_multicast_rx_feature_vpath,
1606 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1609 BAD_SW_IF_INDEX_LABEL;
1611 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1615 vl_api_sw_interface_set_l2_xconnect_t_handler
1616 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1618 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1620 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1621 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1622 vlib_main_t *vm = vlib_get_main ();
1623 vnet_main_t *vnm = vnet_get_main ();
1625 VALIDATE_RX_SW_IF_INDEX (mp);
1629 VALIDATE_TX_SW_IF_INDEX (mp);
1630 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1631 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1635 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1638 BAD_RX_SW_IF_INDEX_LABEL;
1639 BAD_TX_SW_IF_INDEX_LABEL;
1641 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1645 vl_api_sw_interface_set_l2_bridge_t_handler
1646 (vl_api_sw_interface_set_l2_bridge_t * mp)
1648 bd_main_t *bdm = &bd_main;
1649 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1651 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1652 u32 bd_id = ntohl (mp->bd_id);
1656 vlib_main_t *vm = vlib_get_main ();
1657 vnet_main_t *vnm = vnet_get_main ();
1659 VALIDATE_RX_SW_IF_INDEX (mp);
1661 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1665 //VALIDATE_TX_SW_IF_INDEX(mp);
1666 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1667 rx_sw_if_index, bd_index, bvi, shg, 0);
1671 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1674 BAD_RX_SW_IF_INDEX_LABEL;
1676 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1680 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1682 vlib_main_t *vm = vlib_get_main ();
1683 bd_main_t *bdm = &bd_main;
1684 vl_api_bridge_domain_add_del_reply_t *rmp;
1686 u32 enable_flags = 0, disable_flags = 0;
1687 u32 bd_id = ntohl (mp->bd_id);
1692 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1695 enable_flags |= L2_FLOOD;
1697 disable_flags |= L2_FLOOD;
1700 enable_flags |= L2_UU_FLOOD;
1702 disable_flags |= L2_UU_FLOOD;
1705 enable_flags |= L2_FWD;
1707 disable_flags |= L2_FWD;
1710 enable_flags |= L2_ARP_TERM;
1712 disable_flags |= L2_ARP_TERM;
1715 enable_flags |= L2_LEARN;
1717 disable_flags |= L2_LEARN;
1720 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1723 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1727 rv = bd_delete_bd_index (bdm, bd_id);
1729 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1733 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1735 clib_warning ("BUG");
1739 vl_api_bridge_domain_sw_if_details_t_handler
1740 (vl_api_bridge_domain_sw_if_details_t * mp)
1742 clib_warning ("BUG");
1746 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1747 l2_bridge_domain_t * bd_config,
1748 u32 n_sw_ifs, u32 context)
1750 vl_api_bridge_domain_details_t *mp;
1752 mp = vl_msg_api_alloc (sizeof (*mp));
1753 memset (mp, 0, sizeof (*mp));
1754 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1755 mp->bd_id = ntohl (bd_config->bd_id);
1756 mp->flood = bd_feature_flood (bd_config);
1757 mp->uu_flood = bd_feature_uu_flood (bd_config);
1758 mp->forward = bd_feature_forward (bd_config);
1759 mp->learn = bd_feature_learn (bd_config);
1760 mp->arp_term = bd_feature_arp_term (bd_config);
1761 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1762 mp->n_sw_ifs = ntohl (n_sw_ifs);
1763 mp->context = context;
1765 vl_msg_api_send_shmem (q, (u8 *) & mp);
1769 send_bd_sw_if_details (l2input_main_t * l2im,
1770 unix_shared_memory_queue_t * q,
1771 l2_flood_member_t * member, u32 bd_id, u32 context)
1773 vl_api_bridge_domain_sw_if_details_t *mp;
1774 l2_input_config_t *input_cfg;
1776 mp = vl_msg_api_alloc (sizeof (*mp));
1777 memset (mp, 0, sizeof (*mp));
1778 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1779 mp->bd_id = ntohl (bd_id);
1780 mp->sw_if_index = ntohl (member->sw_if_index);
1781 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1782 mp->shg = input_cfg->shg;
1783 mp->context = context;
1785 vl_msg_api_send_shmem (q, (u8 *) & mp);
1789 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1791 bd_main_t *bdm = &bd_main;
1792 l2input_main_t *l2im = &l2input_main;
1793 unix_shared_memory_queue_t *q;
1794 l2_bridge_domain_t *bd_config;
1795 u32 bd_id, bd_index;
1798 q = vl_api_client_index_to_input_queue (mp->client_index);
1803 bd_id = ntohl (mp->bd_id);
1805 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1806 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1807 for (; bd_index < end; bd_index++)
1809 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1810 /* skip dummy bd_id 0 */
1811 if (bd_config && (bd_config->bd_id > 0))
1814 l2_flood_member_t *m;
1816 n_sw_ifs = vec_len (bd_config->members);
1817 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1819 vec_foreach (m, bd_config->members)
1821 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1828 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1830 bd_main_t *bdm = &bd_main;
1831 l2input_main_t *l2im = &l2input_main;
1832 vl_api_l2fib_add_del_reply_t *rmp;
1835 u32 sw_if_index = ntohl (mp->sw_if_index);
1836 u32 bd_id = ntohl (mp->bd_id);
1845 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1848 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1849 goto bad_sw_if_index;
1855 VALIDATE_SW_IF_INDEX (mp);
1856 if (vec_len (l2im->configs) <= sw_if_index)
1858 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1859 goto bad_sw_if_index;
1863 l2_input_config_t *config;
1864 config = vec_elt_at_index (l2im->configs, sw_if_index);
1865 if (config->bridge == 0)
1867 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1868 goto bad_sw_if_index;
1871 static_mac = mp->static_mac ? 1 : 0;
1872 filter_mac = mp->filter_mac ? 1 : 0;
1873 bvi_mac = mp->bvi_mac ? 1 : 0;
1874 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1879 l2fib_del_entry (mac, bd_index);
1882 BAD_SW_IF_INDEX_LABEL;
1884 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1888 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1890 vl_api_l2_flags_reply_t *rmp;
1892 u32 sw_if_index = ntohl (mp->sw_if_index);
1893 u32 flags = ntohl (mp->feature_bitmap);
1896 VALIDATE_SW_IF_INDEX (mp);
1899 if (flags & L2INPUT_FEAT_ ## a) \
1900 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1901 foreach_l2input_feat;
1904 BAD_SW_IF_INDEX_LABEL;
1907 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1909 rmp->resulting_feature_bitmap = ntohl(rbm);
1915 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1917 vlib_main_t *vm = vlib_get_main ();
1918 bd_main_t *bdm = &bd_main;
1919 vl_api_bridge_flags_reply_t *rmp;
1921 u32 bd_id = ntohl (mp->bd_id);
1923 u32 flags = ntohl (mp->feature_bitmap);
1926 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1929 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1935 bd_set_flags (vm, bd_index, flags, mp->is_set);
1939 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1941 rmp->resulting_feature_bitmap = ntohl(flags);
1947 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1949 bd_main_t *bdm = &bd_main;
1950 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1952 u32 bd_id = ntohl (mp->bd_id);
1956 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1959 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1964 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1965 mp->mac_address, mp->is_ipv6, mp->is_add))
1966 rv = VNET_API_ERROR_UNSPECIFIED;
1969 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1973 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1976 vl_api_tap_connect_reply_t *rmp;
1977 unix_shared_memory_queue_t *q;
1978 u32 sw_if_index = (u32) ~ 0;
1980 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1981 mp->use_random_mac ? 0 : mp->mac_address,
1982 &sw_if_index, mp->renumber,
1983 ntohl (mp->custom_dev_instance));
1985 q = vl_api_client_index_to_input_queue (mp->client_index);
1989 rmp = vl_msg_api_alloc (sizeof (*rmp));
1990 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1991 rmp->context = mp->context;
1992 rmp->retval = ntohl (rv);
1993 rmp->sw_if_index = ntohl (sw_if_index);
1995 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1999 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
2002 vl_api_tap_modify_reply_t *rmp;
2003 unix_shared_memory_queue_t *q;
2004 u32 sw_if_index = (u32) ~ 0;
2006 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
2007 mp->use_random_mac ? 0 : mp->mac_address,
2008 &sw_if_index, mp->renumber,
2009 ntohl (mp->custom_dev_instance));
2011 q = vl_api_client_index_to_input_queue (mp->client_index);
2015 rmp = vl_msg_api_alloc (sizeof (*rmp));
2016 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
2017 rmp->context = mp->context;
2018 rmp->retval = ntohl (rv);
2019 rmp->sw_if_index = ntohl (sw_if_index);
2021 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2025 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
2028 vpe_api_main_t *vam = &vpe_api_main;
2029 vl_api_tap_delete_reply_t *rmp;
2030 unix_shared_memory_queue_t *q;
2031 u32 sw_if_index = ntohl (mp->sw_if_index);
2033 rv = vnet_tap_delete (vm, sw_if_index);
2035 q = vl_api_client_index_to_input_queue (mp->client_index);
2039 rmp = vl_msg_api_alloc (sizeof (*rmp));
2040 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
2041 rmp->context = mp->context;
2042 rmp->retval = ntohl (rv);
2044 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2047 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2051 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
2053 vl_api_create_vlan_subif_reply_t *rmp;
2054 vnet_main_t *vnm = vnet_get_main ();
2055 u32 hw_if_index, sw_if_index = (u32) ~ 0;
2056 vnet_hw_interface_t *hi;
2059 vnet_sw_interface_t template;
2061 vnet_interface_main_t *im = &vnm->interface_main;
2062 u64 sup_and_sub_key;
2064 unix_shared_memory_queue_t *q;
2065 clib_error_t *error;
2067 VALIDATE_SW_IF_INDEX (mp);
2069 hw_if_index = ntohl (mp->sw_if_index);
2070 hi = vnet_get_hw_interface (vnm, hw_if_index);
2072 id = ntohl (mp->vlan_id);
2073 if (id == 0 || id > 4095)
2075 rv = VNET_API_ERROR_INVALID_VLAN;
2079 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2081 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2084 rv = VNET_API_ERROR_VLAN_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 = hi->sw_if_index;
2094 template.sub.id = id;
2095 template.sub.eth.raw_flags = 0;
2096 template.sub.eth.flags.one_tag = 1;
2097 template.sub.eth.outer_vlan_id = id;
2098 template.sub.eth.flags.exact_match = 1;
2100 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2103 clib_error_report (error);
2104 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2107 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2108 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2110 BAD_SW_IF_INDEX_LABEL;
2113 q = vl_api_client_index_to_input_queue (mp->client_index);
2117 rmp = vl_msg_api_alloc (sizeof (*rmp));
2118 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2119 rmp->context = mp->context;
2120 rmp->retval = ntohl (rv);
2121 rmp->sw_if_index = ntohl (sw_if_index);
2122 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2126 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2128 vl_api_create_subif_reply_t *rmp;
2129 vnet_main_t *vnm = vnet_get_main ();
2130 u32 sw_if_index = ~0;
2133 vnet_sw_interface_t *si;
2134 vnet_hw_interface_t *hi;
2135 vnet_sw_interface_t template;
2137 vnet_interface_main_t *im = &vnm->interface_main;
2138 u64 sup_and_sub_key;
2140 clib_error_t *error;
2142 VALIDATE_SW_IF_INDEX (mp);
2144 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2145 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2147 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2149 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2153 sw_if_index = si->sw_if_index;
2154 sub_id = ntohl (mp->sub_id);
2156 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2158 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2162 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2163 sw_if_index, sub_id);
2164 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2168 kp = clib_mem_alloc (sizeof (*kp));
2169 *kp = sup_and_sub_key;
2171 memset (&template, 0, sizeof (template));
2172 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2173 template.sup_sw_if_index = sw_if_index;
2174 template.sub.id = sub_id;
2175 template.sub.eth.flags.no_tags = mp->no_tags;
2176 template.sub.eth.flags.one_tag = mp->one_tag;
2177 template.sub.eth.flags.two_tags = mp->two_tags;
2178 template.sub.eth.flags.dot1ad = mp->dot1ad;
2179 template.sub.eth.flags.exact_match = mp->exact_match;
2180 template.sub.eth.flags.default_sub = mp->default_sub;
2181 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2182 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2183 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2184 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2186 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2189 clib_error_report (error);
2190 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2194 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2195 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2197 BAD_SW_IF_INDEX_LABEL;
2202 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2204 rmp->sw_if_index = ntohl(sw_if_index);
2210 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2213 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2215 stats_main_t *sm = &stats_main;
2216 u32 tunnel_sw_if_index = ~0;
2218 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2220 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2221 (ip4_address_t *) (mp->dst_address),
2222 (ip4_address_t *) (mp->intfc_address),
2223 (u32) (mp->intfc_address_length),
2224 ntohl (mp->inner_vrf_id),
2225 ntohl (mp->outer_vrf_id),
2226 &tunnel_sw_if_index,
2227 mp->l2_only, mp->is_add);
2231 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2233 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2239 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2240 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2242 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2244 stats_main_t *sm = &stats_main;
2245 u32 tunnel_sw_if_index;
2247 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2249 rv = vnet_mpls_ethernet_add_del_tunnel
2250 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2251 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2252 ntohl (mp->tx_sw_if_index),
2253 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2258 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2260 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2266 * This piece of misery brought to you because the control-plane
2267 * can't figure out the tx interface + dst-mac address all by itself
2269 static int mpls_ethernet_add_del_tunnel_2_t_handler
2270 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2272 pending_route_t *pr;
2273 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2274 vnet_main_t *vnm = vnet_get_main ();
2275 vlib_main_t *vm = vlib_get_main ();
2276 stats_main_t *sm = &stats_main;
2277 vpe_api_main_t *vam = &vpe_api_main;
2278 u32 inner_fib_index, outer_fib_index;
2279 ip4_main_t *im = &ip4_main;
2280 ip_lookup_main_t *lm = &im->lookup_main;
2281 ip_adjacency_t *adj = 0;
2284 u8 *dst_mac_address;
2288 u32 tunnel_sw_if_index;
2290 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2292 return VNET_API_ERROR_NO_SUCH_FIB;
2294 outer_fib_index = p[0];
2297 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2299 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2301 inner_fib_index = p[0];
2303 if (inner_fib_index == outer_fib_index)
2304 return VNET_API_ERROR_INVALID_VALUE;
2306 lookup_result = ip4_fib_lookup_with_table
2307 (im, outer_fib_index,
2308 (ip4_address_t *) mp->next_hop_ip4_address_in_outer_vrf,
2309 1 /* disable default route */ );
2311 adj = ip_get_adjacency (lm, lookup_result);
2312 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2314 if (mp->is_add && mp->resolve_if_needed)
2316 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2318 pool_get (vam->pending_routes, pr);
2319 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2321 clib_memcpy (pme, mp, sizeof (*pme));
2322 /* recursion block, "just in case" */
2323 pme->resolve_if_needed = 0;
2324 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2325 pme->resolve_opaque = tx_sw_if_index;
2326 vnet_register_ip4_arp_resolution_event
2328 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2329 vpe_resolver_process_node.index,
2330 RESOLUTION_EVENT, pr - vam->pending_routes);
2332 vlib_process_signal_event
2333 (vm, vpe_resolver_process_node.index,
2334 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2336 /* The interface may be down, etc. */
2337 e = ip4_probe_neighbor
2338 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2342 clib_error_report (e);
2344 return VNET_API_ERROR_IN_PROGRESS;
2348 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2349 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2352 vnet_rewrite_get_data_internal
2353 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2355 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2357 rv = vnet_mpls_ethernet_add_del_tunnel
2358 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2359 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2360 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2368 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2369 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2371 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2374 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2376 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2381 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2383 vl_api_mpls_add_del_encap_reply_t *rmp;
2388 vec_reset_length (labels);
2390 for (i = 0; i < mp->nlabels; i++)
2391 vec_add1 (labels, ntohl (mp->labels[i]));
2394 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2395 ntohl (mp->vrf_id), labels,
2396 ~0 /* policy_tunnel_index */ ,
2397 0 /* no_dst_hash */ ,
2401 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2405 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2407 vl_api_mpls_add_del_decap_reply_t *rmp;
2410 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2411 ntohl (mp->label), ntohl (mp->next_index),
2412 mp->s_bit, mp->is_add);
2414 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2418 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2420 vl_api_proxy_arp_add_del_reply_t *rmp;
2423 ip4_main_t *im = &ip4_main;
2424 stats_main_t *sm = &stats_main;
2425 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2426 ip4_address_t * hi_addr,
2427 u32 fib_index, int is_del);
2430 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2432 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2436 rv = VNET_API_ERROR_NO_SUCH_FIB;
2442 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2443 (ip4_address_t *) mp->hi_address,
2444 fib_index, mp->is_add == 0);
2448 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2452 vl_api_proxy_arp_intfc_enable_disable_t_handler
2453 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2456 vnet_main_t *vnm = vnet_get_main ();
2457 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2458 vnet_sw_interface_t *si;
2461 VALIDATE_SW_IF_INDEX (mp);
2463 sw_if_index = ntohl (mp->sw_if_index);
2465 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2467 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2471 si = vnet_get_sw_interface (vnm, sw_if_index);
2475 if (mp->enable_disable)
2476 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2478 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2480 BAD_SW_IF_INDEX_LABEL;
2483 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2487 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2490 vl_api_ip_neighbor_add_del_reply_t *rmp;
2491 vnet_main_t *vnm = vnet_get_main ();
2494 stats_main_t *sm = &stats_main;
2496 VALIDATE_SW_IF_INDEX (mp);
2498 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2503 rv = vnet_set_ip6_ethernet_neighbor
2504 (vm, ntohl (mp->sw_if_index),
2505 (ip6_address_t *) (mp->dst_address),
2506 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2508 rv = vnet_unset_ip6_ethernet_neighbor
2509 (vm, ntohl (mp->sw_if_index),
2510 (ip6_address_t *) (mp->dst_address),
2511 mp->mac_address, sizeof (mp->mac_address));
2515 ip4_main_t *im = &ip4_main;
2516 ip_lookup_main_t *lm = &im->lookup_main;
2517 ethernet_arp_ip4_over_ethernet_address_t a;
2519 ip_adjacency_t *nh_adj;
2521 uword *p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2524 rv = VNET_API_ERROR_NO_SUCH_FIB;
2530 * Unfortunately, folks have a penchant for
2531 * adding interface addresses to the ARP cache, and
2532 * wondering why the forwarder eventually ASSERTs...
2534 ai = ip4_fib_lookup_with_table
2535 (im, fib_index, (ip4_address_t *) (mp->dst_address),
2536 1 /* disable default route */ );
2540 nh_adj = ip_get_adjacency (lm, ai);
2541 /* Never allow manipulation of a local adj! */
2542 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL)
2544 clib_warning ("%U matches local adj",
2546 (ip4_address_t *) (mp->dst_address));
2547 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2552 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2553 clib_memcpy (&a.ip4, mp->dst_address, 4);
2556 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2557 fib_index, &a, mp->is_static);
2559 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2563 BAD_SW_IF_INDEX_LABEL;
2566 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2570 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2573 vpe_main_t *rm = &vpe_main;
2574 ip4_main_t *im4 = &ip4_main;
2575 ip6_main_t *im6 = &ip6_main;
2576 ip_lookup_main_t *lm;
2582 u32 adj_index, sw_if_index;
2583 vl_api_is_address_reachable_t *rmp;
2584 ip_adjacency_t *adj;
2585 unix_shared_memory_queue_t *q;
2587 q = vl_api_client_index_to_input_queue (mp->client_index);
2590 increment_missing_api_client_counter (rm->vlib_main);
2594 rmp = vl_msg_api_alloc (sizeof (*rmp));
2595 clib_memcpy (rmp, mp, sizeof (*rmp));
2597 sw_if_index = mp->next_hop_sw_if_index;
2598 clib_memcpy (&addr, mp->address, sizeof (addr));
2601 lm = &im6->lookup_main;
2602 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2606 lm = &im4->lookup_main;
2607 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2609 if (adj_index == ~0)
2614 adj = ip_get_adjacency (lm, adj_index);
2616 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2617 && adj->rewrite_header.sw_if_index == sw_if_index)
2623 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2624 && adj->rewrite_header.sw_if_index == sw_if_index)
2627 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2629 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2631 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2640 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2645 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2647 clib_warning ("BUG");
2651 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2653 vl_api_sw_interface_set_flags_reply_t *rmp;
2654 vnet_main_t *vnm = vnet_get_main ();
2656 clib_error_t *error;
2659 VALIDATE_SW_IF_INDEX (mp);
2661 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2663 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2667 clib_error_report (error);
2670 BAD_SW_IF_INDEX_LABEL;
2671 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2675 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2678 vl_api_sw_interface_clear_stats_reply_t *rmp;
2680 vnet_main_t *vnm = vnet_get_main ();
2681 vnet_interface_main_t *im = &vnm->interface_main;
2682 vlib_simple_counter_main_t *sm;
2683 vlib_combined_counter_main_t *cm;
2684 static vnet_main_t **my_vnet_mains;
2685 int i, j, n_counters;
2688 if (mp->sw_if_index != ~0)
2689 VALIDATE_SW_IF_INDEX (mp);
2691 vec_reset_length (my_vnet_mains);
2693 for (i = 0; i < vec_len (vnet_mains); i++)
2696 vec_add1 (my_vnet_mains, vnet_mains[i]);
2699 if (vec_len (vnet_mains) == 0)
2700 vec_add1 (my_vnet_mains, vnm);
2702 n_counters = vec_len (im->combined_sw_if_counters);
2704 for (j = 0; j < n_counters; j++)
2706 for (i = 0; i < vec_len (my_vnet_mains); i++)
2708 im = &my_vnet_mains[i]->interface_main;
2709 cm = im->combined_sw_if_counters + j;
2710 if (mp->sw_if_index == (u32) ~ 0)
2711 vlib_clear_combined_counters (cm);
2713 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2717 n_counters = vec_len (im->sw_if_counters);
2719 for (j = 0; j < n_counters; j++)
2721 for (i = 0; i < vec_len (my_vnet_mains); i++)
2723 im = &my_vnet_mains[i]->interface_main;
2724 sm = im->sw_if_counters + j;
2725 if (mp->sw_if_index == (u32) ~ 0)
2726 vlib_clear_simple_counters (sm);
2728 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2732 BAD_SW_IF_INDEX_LABEL;
2734 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2738 send_sw_interface_details (vpe_api_main_t * am,
2739 unix_shared_memory_queue_t * q,
2740 vnet_sw_interface_t * swif,
2741 u8 * interface_name, u32 context)
2743 vl_api_sw_interface_details_t *mp;
2744 vnet_hw_interface_t *hi;
2746 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2748 mp = vl_msg_api_alloc (sizeof (*mp));
2749 memset (mp, 0, sizeof (*mp));
2750 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2751 mp->sw_if_index = ntohl (swif->sw_if_index);
2752 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2753 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2754 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2755 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2756 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2757 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2758 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2759 mp->link_mtu = ntohs (hi->max_packet_bytes);
2760 mp->context = context;
2762 strncpy ((char *) mp->interface_name,
2763 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2765 /* Send the L2 address for ethernet physical intfcs */
2766 if (swif->sup_sw_if_index == swif->sw_if_index
2767 && hi->hw_class_index == ethernet_hw_interface_class.index)
2769 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2770 ethernet_interface_t *ei;
2772 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2773 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2774 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2775 mp->l2_address_length = ntohl (sizeof (ei->address));
2777 else if (swif->sup_sw_if_index != swif->sw_if_index)
2779 vnet_sub_interface_t *sub = &swif->sub;
2780 mp->sub_id = ntohl (sub->id);
2781 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2782 mp->sub_number_of_tags =
2783 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2784 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2785 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2786 mp->sub_exact_match = sub->eth.flags.exact_match;
2787 mp->sub_default = sub->eth.flags.default_sub;
2788 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2789 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2791 /* vlan tag rewrite data */
2792 u32 vtr_op = L2_VTR_DISABLED;
2793 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2795 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2796 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2798 // error - default to disabled
2799 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2800 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2805 mp->vtr_op = ntohl (vtr_op);
2806 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2807 mp->vtr_tag1 = ntohl (vtr_tag1);
2808 mp->vtr_tag2 = ntohl (vtr_tag2);
2812 vl_msg_api_send_shmem (q, (u8 *) & mp);
2816 send_sw_interface_flags (vpe_api_main_t * am,
2817 unix_shared_memory_queue_t * q,
2818 vnet_sw_interface_t * swif)
2820 vl_api_sw_interface_set_flags_t *mp;
2821 vnet_main_t *vnm = am->vnet_main;
2823 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2825 mp = vl_msg_api_alloc (sizeof (*mp));
2826 memset (mp, 0, sizeof (*mp));
2827 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2828 mp->sw_if_index = ntohl (swif->sw_if_index);
2830 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2831 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2832 vl_msg_api_send_shmem (q, (u8 *) & mp);
2835 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2836 unix_shared_memory_queue_t * q,
2838 __attribute__ ((unused));
2841 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2842 unix_shared_memory_queue_t * q,
2845 vl_api_sw_interface_set_flags_t *mp;
2847 mp = vl_msg_api_alloc (sizeof (*mp));
2848 memset (mp, 0, sizeof (*mp));
2849 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2850 mp->sw_if_index = ntohl (sw_if_index);
2852 mp->admin_up_down = 0;
2853 mp->link_up_down = 0;
2855 vl_msg_api_send_shmem (q, (u8 *) & mp);
2859 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2861 vpe_api_main_t *am = &vpe_api_main;
2862 vnet_sw_interface_t *swif;
2863 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2864 u8 *filter_string = 0, *name_string = 0;
2865 unix_shared_memory_queue_t *q;
2866 char *strcasestr (char *, char *); /* lnx hdr file botch */
2868 q = vl_api_client_index_to_input_queue (mp->client_index);
2873 if (mp->name_filter_valid)
2875 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2876 filter_string = format (0, "%s%c", mp->name_filter, 0);
2880 pool_foreach (swif, im->sw_interfaces,
2882 name_string = format (name_string, "%U%c",
2883 format_vnet_sw_interface_name,
2884 am->vnet_main, swif, 0);
2886 if (mp->name_filter_valid == 0 ||
2887 strcasestr((char *) name_string, (char *) filter_string)) {
2889 send_sw_interface_details (am, q, swif, name_string, mp->context);
2891 _vec_len (name_string) = 0;
2895 vec_free (name_string);
2896 vec_free (filter_string);
2900 send_oam_event (oam_target_t * t)
2902 vpe_api_main_t *vam = &vpe_api_main;
2903 unix_shared_memory_queue_t *q;
2904 vpe_client_registration_t *reg;
2905 vl_api_oam_event_t *mp;
2908 pool_foreach(reg, vam->oam_events_registrations,
2910 q = vl_api_client_index_to_input_queue (reg->client_index);
2913 mp = vl_msg_api_alloc (sizeof (*mp));
2914 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2915 clib_memcpy (mp->dst_address, &t->dst_address,
2916 sizeof (mp->dst_address));
2917 mp->state = t->state;
2918 vl_msg_api_send_shmem (q, (u8 *)&mp);
2925 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2927 vl_api_oam_add_del_reply_t *rmp;
2930 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2931 (ip4_address_t *) mp->dst_address,
2932 ntohl (mp->vrf_id), (int) (mp->is_add));
2934 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2938 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2940 stats_main_t *sm = &stats_main;
2941 vnet_interface_main_t *im = sm->interface_main;
2942 vl_api_vnet_summary_stats_reply_t *rmp;
2943 vlib_combined_counter_main_t *cm;
2946 u64 total_pkts[VLIB_N_RX_TX];
2947 u64 total_bytes[VLIB_N_RX_TX];
2949 unix_shared_memory_queue_t *q =
2950 vl_api_client_index_to_input_queue (mp->client_index);
2955 rmp = vl_msg_api_alloc (sizeof (*rmp));
2956 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2957 rmp->context = mp->context;
2960 memset (total_pkts, 0, sizeof (total_pkts));
2961 memset (total_bytes, 0, sizeof (total_bytes));
2963 vnet_interface_counter_lock (im);
2965 vec_foreach (cm, im->combined_sw_if_counters)
2967 which = cm - im->combined_sw_if_counters;
2969 for (i = 0; i < vec_len (cm->maxi); i++)
2971 vlib_get_combined_counter (cm, i, &v);
2972 total_pkts[which] += v.packets;
2973 total_bytes[which] += v.bytes;
2976 vnet_interface_counter_unlock (im);
2978 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2979 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2980 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2981 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2983 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2985 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2989 typedef CLIB_PACKED (struct {
2990 ip4_address_t address;
2991 u32 address_length: 6;
2997 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2999 vnet_main_t *vnm = vnet_get_main ();
3000 vnet_interface_main_t *im = &vnm->interface_main;
3001 ip4_main_t *im4 = &ip4_main;
3002 static ip4_route_t *routes;
3003 static u32 *sw_if_indices_to_shut;
3004 stats_main_t *sm = &stats_main;
3009 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3010 u32 target_fib_id = ntohl (mp->vrf_id);
3012 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
3014 vec_foreach (fib, im4->fibs)
3016 vnet_sw_interface_t *si;
3018 if (fib->table_id != target_fib_id)
3021 /* remove any mpls/gre tunnels in this fib */
3022 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
3024 /* remove any mpls encap/decap labels */
3025 mpls_fib_reset_labels (fib->table_id);
3027 /* remove any proxy arps in this fib */
3028 vnet_proxy_arp_fib_reset (fib->table_id);
3030 /* Set the flow hash for this fib to the default */
3031 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3033 vec_reset_length (sw_if_indices_to_shut);
3035 /* Shut down interfaces in this FIB / clean out intfc routes */
3037 pool_foreach (si, im->sw_interfaces,
3039 u32 sw_if_index = si->sw_if_index;
3041 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
3042 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
3044 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3048 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3050 sw_if_index = sw_if_indices_to_shut[i];
3051 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3053 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3054 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3055 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3058 vec_reset_length (routes);
3060 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++)
3062 uword *hash = fib->adj_index_by_dst_address[i];
3066 x.address_length = i;
3069 hash_foreach_pair (p, hash,
3071 x.address.data_u32 = p->key;
3072 vec_add1 (routes, x);
3077 vec_foreach (r, routes)
3079 ip4_add_del_route_args_t a;
3081 memset (&a, 0, sizeof (a));
3082 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
3083 a.table_index_or_table_id = fib - im4->fibs;
3084 a.dst_address = r->address;
3085 a.dst_address_length = r->address_length;
3088 ip4_add_del_route (im4, &a);
3089 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
3090 IP4_ROUTE_FLAG_FIB_INDEX);
3094 } /* vec_foreach (fib) */
3102 ip6_address_t address;
3110 ip6_route_t **routep;
3111 } add_routes_in_fib_arg_t;
3114 add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
3116 add_routes_in_fib_arg_t *ap = arg;
3118 if (kvp->key[2] >> 32 == ap->fib_index)
3120 ip6_address_t *addr;
3122 addr = (ip6_address_t *) kvp;
3123 vec_add2 (*ap->routep, r, 1);
3124 r->address = addr[0];
3125 r->address_length = kvp->key[2] & 0xFF;
3126 r->index = kvp->value;
3131 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3133 vnet_main_t *vnm = vnet_get_main ();
3134 vnet_interface_main_t *im = &vnm->interface_main;
3135 ip6_main_t *im6 = &ip6_main;
3136 stats_main_t *sm = &stats_main;
3137 static ip6_route_t *routes;
3138 static u32 *sw_if_indices_to_shut;
3143 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3144 u32 target_fib_id = ntohl (mp->vrf_id);
3145 add_routes_in_fib_arg_t _a, *a = &_a;
3146 clib_bihash_24_8_t *h = &im6->ip6_lookup_table;
3148 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3150 vec_foreach (fib, im6->fibs)
3152 vnet_sw_interface_t *si;
3154 if (fib->table_id != target_fib_id)
3157 vec_reset_length (sw_if_indices_to_shut);
3159 /* Shut down interfaces in this FIB / clean out intfc routes */
3161 pool_foreach (si, im->sw_interfaces,
3163 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3165 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3169 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3171 sw_if_index = sw_if_indices_to_shut[i];
3172 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3174 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3175 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3176 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3179 vec_reset_length (routes);
3181 a->fib_index = fib - im6->fibs;
3182 a->routep = &routes;
3184 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
3186 vec_foreach (r, routes)
3188 ip6_add_del_route_args_t a;
3190 memset (&a, 0, sizeof (a));
3191 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
3192 a.table_index_or_table_id = fib - im6->fibs;
3193 a.dst_address = r->address;
3194 a.dst_address_length = r->address_length;
3197 ip6_add_del_route (im6, &a);
3198 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
3199 IP6_ROUTE_FLAG_FIB_INDEX);
3202 /* Reinstall the neighbor / router discovery routes */
3203 vnet_ip6_fib_init (im6, fib - im6->fibs);
3205 } /* vec_foreach (fib) */
3212 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3215 vl_api_reset_fib_reply_t *rmp;
3218 rv = ip6_reset_fib_t_handler (mp);
3220 rv = ip4_reset_fib_t_handler (mp);
3222 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3227 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3229 vl_api_dhcp_proxy_config_reply_t *rmp;
3232 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3233 (ip4_address_t *) (&mp->dhcp_src_address),
3234 (u32) ntohl (mp->vrf_id),
3235 (int) mp->insert_circuit_id,
3236 (int) (mp->is_add == 0));
3238 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3243 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3245 vl_api_dhcp_proxy_config_reply_t *rmp;
3248 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3249 (ip6_address_t *) (&mp->dhcp_src_address),
3250 (u32) ntohl (mp->vrf_id),
3251 (int) mp->insert_circuit_id,
3252 (int) (mp->is_add == 0));
3254 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3258 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3260 vl_api_dhcp_proxy_config_reply_t *rmp;
3263 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3264 (ip4_address_t *) (&mp->dhcp_src_address),
3265 (u32) ntohl (mp->rx_vrf_id),
3266 (u32) ntohl (mp->server_vrf_id),
3267 (int) mp->insert_circuit_id,
3268 (int) (mp->is_add == 0));
3270 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3275 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3277 vl_api_dhcp_proxy_config_reply_t *rmp;
3281 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3282 (ip6_address_t *) (&mp->dhcp_src_address),
3283 (u32) ntohl (mp->rx_vrf_id),
3284 (u32) ntohl (mp->server_vrf_id),
3285 (int) mp->insert_circuit_id,
3286 (int) (mp->is_add == 0));
3288 rv = VNET_API_ERROR_UNIMPLEMENTED;
3291 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3296 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3298 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3301 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3304 (int) mp->is_add == 0);
3306 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3308 ntohl (mp->fib_id), (int) mp->is_add == 0);
3310 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3314 static void vl_api_dhcp_proxy_config_t_handler
3315 (vl_api_dhcp_proxy_config_t * mp)
3317 if (mp->is_ipv6 == 0)
3318 dhcpv4_proxy_config (mp);
3320 dhcpv6_proxy_config (mp);
3323 static void vl_api_dhcp_proxy_config_2_t_handler
3324 (vl_api_dhcp_proxy_config_2_t * mp)
3326 if (mp->is_ipv6 == 0)
3327 dhcpv4_proxy_config_2 (mp);
3329 dhcpv6_proxy_config_2 (mp);
3333 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3334 u8 is_ipv6, u8 * host_address, u8 * router_address,
3337 unix_shared_memory_queue_t *q;
3338 vl_api_dhcp_compl_event_t *mp;
3340 q = vl_api_client_index_to_input_queue (client_index);
3344 mp = vl_msg_api_alloc (sizeof (*mp));
3345 mp->client_index = client_index;
3347 mp->is_ipv6 = is_ipv6;
3348 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3349 mp->hostname[vec_len (hostname) + 1] = '\n';
3350 clib_memcpy (&mp->host_address[0], host_address, 16);
3351 clib_memcpy (&mp->router_address[0], router_address, 16);
3352 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3354 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3356 vl_msg_api_send_shmem (q, (u8 *) & mp);
3359 static void vl_api_dhcp_client_config_t_handler
3360 (vl_api_dhcp_client_config_t * mp)
3362 vlib_main_t *vm = vlib_get_main ();
3363 vl_api_dhcp_client_config_reply_t *rmp;
3366 VALIDATE_SW_IF_INDEX (mp);
3368 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3369 mp->hostname, mp->is_add, mp->client_index,
3370 mp->want_dhcp_event ? dhcp_compl_event_callback :
3373 BAD_SW_IF_INDEX_LABEL;
3375 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3379 vl_api_sw_interface_ip6nd_ra_config_t_handler
3380 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3382 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3384 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3387 is_no = mp->is_no == 1;
3388 suppress = mp->suppress == 1;
3389 managed = mp->managed == 1;
3390 other = mp->other == 1;
3391 ll_option = mp->ll_option == 1;
3392 send_unicast = mp->send_unicast == 1;
3393 cease = mp->cease == 1;
3394 default_router = mp->default_router == 1;
3396 VALIDATE_SW_IF_INDEX (mp);
3398 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3399 suppress, managed, other,
3400 ll_option, send_unicast, cease,
3401 default_router, ntohl (mp->lifetime),
3402 ntohl (mp->initial_count),
3403 ntohl (mp->initial_interval),
3404 ntohl (mp->max_interval),
3405 ntohl (mp->min_interval), is_no);
3407 BAD_SW_IF_INDEX_LABEL;
3409 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3413 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3414 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3416 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3418 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3420 VALIDATE_SW_IF_INDEX (mp);
3422 is_no = mp->is_no == 1;
3423 use_default = mp->use_default == 1;
3424 no_advertise = mp->no_advertise == 1;
3425 off_link = mp->off_link == 1;
3426 no_autoconfig = mp->no_autoconfig == 1;
3427 no_onlink = mp->no_onlink == 1;
3429 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3430 (ip6_address_t *) mp->address,
3431 mp->address_length, use_default,
3432 ntohl (mp->val_lifetime),
3433 ntohl (mp->pref_lifetime), no_advertise,
3434 off_link, no_autoconfig, no_onlink, is_no);
3436 BAD_SW_IF_INDEX_LABEL;
3437 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3441 vl_api_sw_interface_ip6_enable_disable_t_handler
3442 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3444 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3445 vnet_main_t *vnm = vnet_get_main ();
3447 clib_error_t *error;
3451 VALIDATE_SW_IF_INDEX (mp);
3454 (mp->enable == 1) ? enable_ip6_interface (vm,
3455 ntohl (mp->sw_if_index)) :
3456 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3460 clib_error_report (error);
3461 rv = VNET_API_ERROR_UNSPECIFIED;
3465 rv = vnm->api_errno;
3468 BAD_SW_IF_INDEX_LABEL;
3470 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3474 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3475 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3477 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3479 clib_error_t *error;
3480 vnet_main_t *vnm = vnet_get_main ();
3484 VALIDATE_SW_IF_INDEX (mp);
3486 error = set_ip6_link_local_address (vm,
3487 ntohl (mp->sw_if_index),
3488 (ip6_address_t *) mp->address,
3489 mp->address_length);
3492 clib_error_report (error);
3493 rv = VNET_API_ERROR_UNSPECIFIED;
3497 rv = vnm->api_errno;
3500 BAD_SW_IF_INDEX_LABEL;
3502 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3506 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3508 vl_api_set_ip_flow_hash_reply_t *rmp;
3509 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3511 clib_warning ("unimplemented...");
3513 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3517 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3519 vl_api_set_ip_flow_hash_reply_t *rmp;
3522 u32 flow_hash_config = 0;
3524 table_id = ntohl (mp->vrf_id);
3526 #define _(a,b) if (mp->a) flow_hash_config |= b;
3527 foreach_flow_hash_bit;
3530 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3532 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3537 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3539 if (mp->is_ipv6 == 0)
3540 set_ip4_flow_hash (mp);
3542 set_ip6_flow_hash (mp);
3545 static void vl_api_sw_interface_set_unnumbered_t_handler
3546 (vl_api_sw_interface_set_unnumbered_t * mp)
3548 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3550 vnet_sw_interface_t *si;
3551 vnet_main_t *vnm = vnet_get_main ();
3552 u32 sw_if_index, unnumbered_sw_if_index;
3554 sw_if_index = ntohl (mp->sw_if_index);
3555 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3558 * The API message field names are backwards from
3559 * the underlying data structure names.
3560 * It's not worth changing them now.
3562 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3563 unnumbered_sw_if_index))
3565 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3569 /* Only check the "use loop0" field when setting the binding */
3571 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3573 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3577 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3581 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3582 si->unnumbered_sw_if_index = sw_if_index;
3586 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3587 si->unnumbered_sw_if_index = (u32) ~ 0;
3591 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3595 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3597 vl_api_create_loopback_reply_t *rmp;
3601 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3604 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3606 rmp->sw_if_index = ntohl (sw_if_index);
3612 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3614 vl_api_delete_loopback_reply_t *rmp;
3618 sw_if_index = ntohl (mp->sw_if_index);
3619 rv = vnet_delete_loopback_interface (sw_if_index);
3621 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3625 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3627 vl_api_control_ping_reply_t *rmp;
3631 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3633 rmp->vpe_pid = ntohl (getpid());
3639 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3641 u8 **shmem_vecp = (u8 **) arg;
3644 api_main_t *am = &api_main;
3647 shmem_vec = *shmem_vecp;
3649 offset = vec_len (shmem_vec);
3651 pthread_mutex_lock (&am->vlib_rp->mutex);
3652 oldheap = svm_push_data_heap (am->vlib_rp);
3654 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3656 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3658 svm_pop_heap (oldheap);
3659 pthread_mutex_unlock (&am->vlib_rp->mutex);
3661 *shmem_vecp = shmem_vec;
3666 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3668 vl_api_cli_reply_t *rp;
3669 unix_shared_memory_queue_t *q;
3670 vlib_main_t *vm = vlib_get_main ();
3671 api_main_t *am = &api_main;
3672 unformat_input_t input;
3676 q = vl_api_client_index_to_input_queue (mp->client_index);
3680 rp = vl_msg_api_alloc (sizeof (*rp));
3681 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3682 rp->context = mp->context;
3684 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3686 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3688 pthread_mutex_lock (&am->vlib_rp->mutex);
3689 oldheap = svm_push_data_heap (am->vlib_rp);
3691 vec_add1 (shmem_vec, 0);
3693 svm_pop_heap (oldheap);
3694 pthread_mutex_unlock (&am->vlib_rp->mutex);
3696 rp->reply_in_shmem = (uword) shmem_vec;
3698 vl_msg_api_send_shmem (q, (u8 *) & rp);
3702 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3704 u8 **mem_vecp = (u8 **) arg;
3705 u8 *mem_vec = *mem_vecp;
3706 u32 offset = vec_len (mem_vec);
3708 vec_validate (mem_vec, offset + buffer_bytes - 1);
3709 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3710 *mem_vecp = mem_vec;
3714 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3716 vl_api_cli_inband_reply_t *rmp;
3718 unix_shared_memory_queue_t *q;
3719 vlib_main_t *vm = vlib_get_main ();
3720 unformat_input_t input;
3723 q = vl_api_client_index_to_input_queue (mp->client_index);
3727 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3728 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3730 u32 len = vec_len (out_vec);
3732 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3734 rmp->length = htonl (len);
3735 clib_memcpy (rmp->reply, out_vec, len);
3742 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3745 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3746 vnet_main_t *vnm = vnet_get_main ();
3747 clib_error_t *error;
3752 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3754 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3758 clib_error_report (error);
3759 rv = VNET_API_ERROR_UNSPECIFIED;
3763 rv = vnm->api_errno;
3766 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3769 static void vl_api_sr_tunnel_add_del_t_handler
3770 (vl_api_sr_tunnel_add_del_t * mp)
3773 clib_warning ("unimplemented");
3775 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3777 vl_api_sr_tunnel_add_del_reply_t *rmp;
3778 ip6_address_t *segments = 0, *seg;
3779 ip6_address_t *tags = 0, *tag;
3780 ip6_address_t *this_address;
3783 if (mp->n_segments == 0)
3789 memset (a, 0, sizeof (*a));
3790 a->src_address = (ip6_address_t *) & mp->src_address;
3791 a->dst_address = (ip6_address_t *) & mp->dst_address;
3792 a->dst_mask_width = mp->dst_mask_width;
3793 a->flags_net_byte_order = mp->flags_net_byte_order;
3794 a->is_del = (mp->is_add == 0);
3795 a->rx_table_id = ntohl (mp->outer_vrf_id);
3796 a->tx_table_id = ntohl (mp->inner_vrf_id);
3798 a->name = format (0, "%s", mp->name);
3799 if (!(vec_len (a->name)))
3802 a->policy_name = format (0, "%s", mp->policy_name);
3803 if (!(vec_len (a->policy_name)))
3806 /* Yank segments and tags out of the API message */
3807 this_address = (ip6_address_t *) mp->segs_and_tags;
3808 for (i = 0; i < mp->n_segments; i++)
3810 vec_add2 (segments, seg, 1);
3811 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3814 for (i = 0; i < mp->n_tags; i++)
3816 vec_add2 (tags, tag, 1);
3817 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3821 a->segments = segments;
3824 rv = ip6_sr_add_del_tunnel (a);
3828 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3832 static void vl_api_sr_policy_add_del_t_handler
3833 (vl_api_sr_policy_add_del_t * mp)
3836 clib_warning ("unimplemented");
3838 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3840 vl_api_sr_policy_add_del_reply_t *rmp;
3843 memset (a, 0, sizeof (*a));
3844 a->is_del = (mp->is_add == 0);
3846 a->name = format (0, "%s", mp->name);
3847 if (!(vec_len (a->name)))
3849 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3853 if (!(mp->tunnel_names[0]))
3855 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3859 // start deserializing tunnel_names
3860 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3861 u8 *deser_tun_names = mp->tunnel_names;
3862 deser_tun_names += 1; //moving along
3865 int tun_name_len = 0;
3867 for (i = 0; i < num_tunnels; i++)
3869 tun_name_len = *deser_tun_names;
3870 deser_tun_names += 1;
3871 vec_resize (tun_name, tun_name_len);
3872 memcpy (tun_name, deser_tun_names, tun_name_len);
3873 vec_add1 (a->tunnel_names, tun_name);
3874 deser_tun_names += tun_name_len;
3878 rv = ip6_sr_add_del_policy (a);
3882 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3886 static void vl_api_sr_multicast_map_add_del_t_handler
3887 (vl_api_sr_multicast_map_add_del_t * mp)
3890 clib_warning ("unimplemented");
3892 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3894 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3896 memset (a, 0, sizeof (*a));
3897 a->is_del = (mp->is_add == 0);
3899 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3900 a->policy_name = format (0, "%s", mp->policy_name);
3902 if (a->multicast_address == 0)
3908 if (!(a->policy_name))
3914 #if DPDK > 0 /* Cannot call replicate without DPDK */
3915 rv = ip6_sr_add_del_multicastmap (a);
3917 clib_warning ("multicast replication without DPDK not implemented");
3918 rv = VNET_API_ERROR_UNIMPLEMENTED;
3923 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3927 #define foreach_classify_add_del_table_field \
3932 _(match_n_vectors) \
3933 _(next_table_index) \
3936 static void vl_api_classify_add_del_table_t_handler
3937 (vl_api_classify_add_del_table_t * mp)
3939 vl_api_classify_add_del_table_reply_t *rmp;
3940 vnet_classify_main_t *cm = &vnet_classify_main;
3941 vnet_classify_table_t *t;
3945 foreach_classify_add_del_table_field;
3948 #define _(a) a = ntohl(mp->a);
3949 foreach_classify_add_del_table_field;
3952 /* The underlying API fails silently, on purpose, so check here */
3953 if (mp->is_add == 0)
3954 if (pool_is_free_index (cm->tables, table_index))
3956 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3960 rv = vnet_classify_add_del_table
3961 (cm, mp->mask, nbuckets, memory_size,
3962 skip_n_vectors, match_n_vectors,
3963 next_table_index, miss_next_index, &table_index, mp->is_add);
3967 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3969 if (rv == 0 && mp->is_add)
3971 t = pool_elt_at_index (cm->tables, table_index);
3972 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3973 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3974 rmp->new_table_index = ntohl(table_index);
3978 rmp->skip_n_vectors = ~0;
3979 rmp->match_n_vectors = ~0;
3980 rmp->new_table_index = ~0;
3986 static void vl_api_classify_add_del_session_t_handler
3987 (vl_api_classify_add_del_session_t * mp)
3989 vnet_classify_main_t *cm = &vnet_classify_main;
3990 vl_api_classify_add_del_session_reply_t *rmp;
3992 u32 table_index, hit_next_index, opaque_index;
3995 table_index = ntohl (mp->table_index);
3996 hit_next_index = ntohl (mp->hit_next_index);
3997 opaque_index = ntohl (mp->opaque_index);
3998 advance = ntohl (mp->advance);
4000 rv = vnet_classify_add_del_session
4001 (cm, table_index, mp->match, hit_next_index, opaque_index,
4002 advance, mp->is_add);
4004 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
4007 static void vl_api_classify_set_interface_ip_table_t_handler
4008 (vl_api_classify_set_interface_ip_table_t * mp)
4010 vlib_main_t *vm = vlib_get_main ();
4011 vl_api_classify_set_interface_ip_table_reply_t *rmp;
4013 u32 table_index, sw_if_index;
4015 table_index = ntohl (mp->table_index);
4016 sw_if_index = ntohl (mp->sw_if_index);
4018 VALIDATE_SW_IF_INDEX (mp);
4021 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
4023 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
4025 BAD_SW_IF_INDEX_LABEL;
4027 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
4030 static void vl_api_classify_set_interface_l2_tables_t_handler
4031 (vl_api_classify_set_interface_l2_tables_t * mp)
4033 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
4035 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
4038 ip4_table_index = ntohl (mp->ip4_table_index);
4039 ip6_table_index = ntohl (mp->ip6_table_index);
4040 other_table_index = ntohl (mp->other_table_index);
4041 sw_if_index = ntohl (mp->sw_if_index);
4043 VALIDATE_SW_IF_INDEX (mp);
4046 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
4050 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
4056 if (ip4_table_index != ~0 || ip6_table_index != ~0
4057 || other_table_index != ~0)
4063 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
4065 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
4068 BAD_SW_IF_INDEX_LABEL;
4070 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
4074 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
4077 vl_api_l2_fib_clear_table_reply_t *rmp;
4079 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
4080 * that is not currently implemented. When that TODO is fixed
4081 * this call should be changed to pass 1 instead of 0.
4083 l2fib_clear_table (0);
4085 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
4088 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
4089 u32 sw_if_index, u32 enable);
4092 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
4096 vl_api_l2_interface_efp_filter_reply_t *rmp;
4097 vnet_main_t *vnm = vnet_get_main ();
4099 // enable/disable the feature
4100 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
4101 rv = vnm->api_errno;
4103 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
4107 vl_api_l2_interface_vlan_tag_rewrite_t_handler
4108 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
4111 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
4112 vnet_main_t *vnm = vnet_get_main ();
4113 vlib_main_t *vm = vlib_get_main ();
4116 VALIDATE_SW_IF_INDEX (mp);
4118 vtr_op = ntohl (mp->vtr_op);
4120 /* The L2 code is unsuspicious */
4123 case L2_VTR_DISABLED:
4128 case L2_VTR_TRANSLATE_1_1:
4129 case L2_VTR_TRANSLATE_1_2:
4130 case L2_VTR_TRANSLATE_2_1:
4131 case L2_VTR_TRANSLATE_2_2:
4135 rv = VNET_API_ERROR_INVALID_VALUE;
4136 goto bad_sw_if_index;
4139 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4140 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4143 BAD_SW_IF_INDEX_LABEL;
4145 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4149 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4152 vl_api_create_vhost_user_if_reply_t *rmp;
4153 u32 sw_if_index = (u32) ~ 0;
4155 vnet_main_t *vnm = vnet_get_main ();
4156 vlib_main_t *vm = vlib_get_main ();
4158 #if DPDK > 0 && DPDK_VHOST_USER
4159 rv = dpdk_vhost_user_create_if (
4161 rv = vhost_user_create_if (
4163 vnm, vm, (char *) mp->sock_filename,
4164 mp->is_server, &sw_if_index, (u64) ~ 0,
4165 mp->renumber, ntohl (mp->custom_dev_instance),
4166 (mp->use_custom_mac) ? mp->mac_address : NULL);
4169 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4171 rmp->sw_if_index = ntohl (sw_if_index);
4177 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4180 vl_api_modify_vhost_user_if_reply_t *rmp;
4181 u32 sw_if_index = ntohl (mp->sw_if_index);
4183 vnet_main_t *vnm = vnet_get_main ();
4184 vlib_main_t *vm = vlib_get_main ();
4186 #if DPDK > 0 && DPDK_VHOST_USER
4187 rv = dpdk_vhost_user_modify_if (
4189 rv = vhost_user_modify_if (
4191 vnm, vm, (char *) mp->sock_filename,
4192 mp->is_server, sw_if_index, (u64) ~ 0,
4193 mp->renumber, ntohl (mp->custom_dev_instance));
4194 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4198 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4201 vl_api_delete_vhost_user_if_reply_t *rmp;
4202 vpe_api_main_t *vam = &vpe_api_main;
4203 u32 sw_if_index = ntohl (mp->sw_if_index);
4205 vnet_main_t *vnm = vnet_get_main ();
4206 vlib_main_t *vm = vlib_get_main ();
4208 #if DPDK > 0 && DPDK_VHOST_USER
4209 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4211 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4214 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4217 unix_shared_memory_queue_t *q =
4218 vl_api_client_index_to_input_queue (mp->client_index);
4222 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4227 vl_api_sw_interface_vhost_user_details_t_handler
4228 (vl_api_sw_interface_vhost_user_details_t * mp)
4230 clib_warning ("BUG");
4234 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4235 unix_shared_memory_queue_t * q,
4236 vhost_user_intf_details_t * vui,
4239 vl_api_sw_interface_vhost_user_details_t *mp;
4241 mp = vl_msg_api_alloc (sizeof (*mp));
4242 memset (mp, 0, sizeof (*mp));
4243 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4244 mp->sw_if_index = ntohl (vui->sw_if_index);
4245 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4246 mp->features = clib_net_to_host_u64 (vui->features);
4247 mp->is_server = vui->is_server;
4248 mp->num_regions = ntohl (vui->num_regions);
4249 mp->sock_errno = ntohl (vui->sock_errno);
4250 mp->context = context;
4252 strncpy ((char *) mp->sock_filename,
4253 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4254 strncpy ((char *) mp->interface_name,
4255 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4257 vl_msg_api_send_shmem (q, (u8 *) & mp);
4261 vl_api_sw_interface_vhost_user_dump_t_handler
4262 (vl_api_sw_interface_vhost_user_dump_t * mp)
4265 vpe_api_main_t *am = &vpe_api_main;
4266 vnet_main_t *vnm = vnet_get_main ();
4267 vlib_main_t *vm = vlib_get_main ();
4268 vhost_user_intf_details_t *ifaces = NULL;
4269 vhost_user_intf_details_t *vuid = NULL;
4270 unix_shared_memory_queue_t *q;
4272 q = vl_api_client_index_to_input_queue (mp->client_index);
4276 #if DPDK > 0 && DPDK_VHOST_USER
4277 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4279 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4284 vec_foreach (vuid, ifaces)
4286 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4292 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4293 unix_shared_memory_queue_t * q,
4295 l2t_main_t * lm, u32 context)
4297 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4299 vnet_sw_interface_t *si = NULL;
4301 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4303 if_name = format (if_name, "%U",
4304 format_vnet_sw_interface_name, lm->vnet_main, si);
4306 mp = vl_msg_api_alloc (sizeof (*mp));
4307 memset (mp, 0, sizeof (*mp));
4308 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4309 strncpy ((char *) mp->interface_name,
4310 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4311 mp->sw_if_index = ntohl (si->sw_if_index);
4312 mp->local_session_id = s->local_session_id;
4313 mp->remote_session_id = s->remote_session_id;
4314 mp->local_cookie[0] = s->local_cookie[0];
4315 mp->local_cookie[1] = s->local_cookie[1];
4316 mp->remote_cookie = s->remote_cookie;
4317 clib_memcpy (mp->client_address, &s->client_address,
4318 sizeof (s->client_address));
4319 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4320 mp->l2_sublayer_present = s->l2_sublayer_present;
4321 mp->context = context;
4323 vl_msg_api_send_shmem (q, (u8 *) & mp);
4327 send_ip_address_details (vpe_api_main_t * am,
4328 unix_shared_memory_queue_t * q,
4329 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4331 vl_api_ip_address_details_t *mp;
4333 mp = vl_msg_api_alloc (sizeof (*mp));
4334 memset (mp, 0, sizeof (*mp));
4335 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4339 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4343 u32 *tp = (u32 *) mp->ip;
4344 *tp = ntohl (*(u32 *) ip);
4346 mp->prefix_length = prefix_length;
4347 mp->context = context;
4349 vl_msg_api_send_shmem (q, (u8 *) & mp);
4353 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4355 vpe_api_main_t *am = &vpe_api_main;
4356 unix_shared_memory_queue_t *q;
4359 ip6_main_t *im6 = &ip6_main;
4360 ip4_main_t *im4 = &ip4_main;
4361 ip_lookup_main_t *lm6 = &im6->lookup_main;
4362 ip_lookup_main_t *lm4 = &im4->lookup_main;
4363 ip_interface_address_t *ia = 0;
4364 u32 sw_if_index = ~0;
4365 int rv __attribute__ ((unused)) = 0;
4367 VALIDATE_SW_IF_INDEX (mp);
4369 sw_if_index = ntohl (mp->sw_if_index);
4371 q = vl_api_client_index_to_input_queue (mp->client_index);
4380 foreach_ip_interface_address (lm6, ia, sw_if_index,
4381 1 /* honor unnumbered */,
4383 r6 = ip_interface_address_get_address (lm6, ia);
4384 u16 prefix_length = ia->address_length;
4385 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4392 foreach_ip_interface_address (lm4, ia, sw_if_index,
4393 1 /* honor unnumbered */,
4395 r4 = ip_interface_address_get_address (lm4, ia);
4396 u16 prefix_length = ia->address_length;
4397 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4401 BAD_SW_IF_INDEX_LABEL;
4405 send_ip_details (vpe_api_main_t * am,
4406 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4408 vl_api_ip_details_t *mp;
4410 mp = vl_msg_api_alloc (sizeof (*mp));
4411 memset (mp, 0, sizeof (*mp));
4412 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4414 mp->sw_if_index = ntohl (sw_if_index);
4415 mp->context = context;
4417 vl_msg_api_send_shmem (q, (u8 *) & mp);
4421 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4424 vpe_api_main_t *am = &vpe_api_main;
4425 l2t_main_t *lm = &l2t_main;
4426 unix_shared_memory_queue_t *q;
4427 l2t_session_t *session;
4429 q = vl_api_client_index_to_input_queue (mp->client_index);
4434 pool_foreach (session, lm->sessions,
4436 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4443 send_sw_interface_tap_details (vpe_api_main_t * am,
4444 unix_shared_memory_queue_t * q,
4445 tapcli_interface_details_t * tap_if,
4448 vl_api_sw_interface_tap_details_t *mp;
4449 mp = vl_msg_api_alloc (sizeof (*mp));
4450 memset (mp, 0, sizeof (*mp));
4451 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4452 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4453 strncpy ((char *) mp->dev_name,
4454 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4455 mp->context = context;
4457 vl_msg_api_send_shmem (q, (u8 *) & mp);
4461 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4464 vpe_api_main_t *am = &vpe_api_main;
4465 unix_shared_memory_queue_t *q;
4466 tapcli_interface_details_t *tapifs = NULL;
4467 tapcli_interface_details_t *tap_if = NULL;
4469 q = vl_api_client_index_to_input_queue (mp->client_index);
4473 rv = vnet_tap_dump_ifs (&tapifs);
4477 vec_foreach (tap_if, tapifs)
4479 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4486 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4488 vpe_api_main_t *am = &vpe_api_main;
4489 vnet_main_t *vnm = vnet_get_main ();
4490 vlib_main_t *vm = vlib_get_main ();
4491 vnet_interface_main_t *im = &vnm->interface_main;
4492 unix_shared_memory_queue_t *q;
4493 vnet_sw_interface_t *si, *sorted_sis;
4494 u32 sw_if_index = ~0;
4496 q = vl_api_client_index_to_input_queue (mp->client_index);
4502 /* Gather interfaces. */
4503 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4504 _vec_len (sorted_sis) = 0;
4506 pool_foreach (si, im->sw_interfaces,
4508 vec_add1 (sorted_sis, si[0]);
4512 vec_foreach (si, sorted_sis)
4514 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4516 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4520 sw_if_index = si->sw_if_index;
4521 send_ip_details (am, q, sw_if_index, mp->context);
4527 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4529 clib_warning ("BUG");
4533 send_l2fib_table_entry (vpe_api_main_t * am,
4534 unix_shared_memory_queue_t * q,
4535 l2fib_entry_key_t * l2fe_key,
4536 l2fib_entry_result_t * l2fe_res, u32 context)
4538 vl_api_l2_fib_table_entry_t *mp;
4540 mp = vl_msg_api_alloc (sizeof (*mp));
4541 memset (mp, 0, sizeof (*mp));
4542 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4545 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4547 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4548 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4549 mp->static_mac = l2fe_res->fields.static_mac;
4550 mp->filter_mac = l2fe_res->fields.filter;
4551 mp->bvi_mac = l2fe_res->fields.bvi;
4552 mp->context = context;
4554 vl_msg_api_send_shmem (q, (u8 *) & mp);
4558 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4560 vpe_api_main_t *am = &vpe_api_main;
4561 bd_main_t *bdm = &bd_main;
4562 l2fib_entry_key_t *l2fe_key = NULL;
4563 l2fib_entry_result_t *l2fe_res = NULL;
4564 u32 ni, bd_id = ntohl (mp->bd_id);
4566 unix_shared_memory_queue_t *q;
4569 q = vl_api_client_index_to_input_queue (mp->client_index);
4573 /* see l2fib_table_dump: ~0 means "any" */
4578 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4585 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4587 vec_foreach_index (ni, l2fe_key)
4589 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4590 vec_elt_at_index (l2fe_res, ni), mp->context);
4592 vec_free (l2fe_key);
4593 vec_free (l2fe_res);
4597 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4599 vl_api_show_version_reply_t *rmp;
4601 char *vpe_api_get_build_directory (void);
4602 char *vpe_api_get_version (void);
4603 char *vpe_api_get_build_date (void);
4605 unix_shared_memory_queue_t *q =
4606 vl_api_client_index_to_input_queue (mp->client_index);
4612 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4614 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4615 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4616 ARRAY_LEN(rmp->build_directory)-1);
4617 strncpy ((char *) rmp->version, vpe_api_get_version(),
4618 ARRAY_LEN(rmp->version)-1);
4619 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4620 ARRAY_LEN(rmp->build_date)-1);
4626 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4628 vlib_main_t *vm = vlib_get_main ();
4629 vl_api_get_node_index_reply_t *rmp;
4632 u32 node_index = ~0;
4634 n = vlib_get_node_by_name (vm, mp->node_name);
4637 rv = VNET_API_ERROR_NO_SUCH_NODE;
4639 node_index = n->index;
4642 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4644 rmp->node_index = ntohl(node_index);
4650 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4652 vlib_main_t *vm = vlib_get_main ();
4653 vl_api_get_next_index_reply_t *rmp;
4654 vlib_node_t *node, *next_node;
4656 u32 next_node_index = ~0, next_index = ~0;
4659 node = vlib_get_node_by_name (vm, mp->node_name);
4663 rv = VNET_API_ERROR_NO_SUCH_NODE;
4667 next_node = vlib_get_node_by_name (vm, mp->next_name);
4671 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4675 next_node_index = next_node->index;
4677 p = hash_get (node->next_slot_by_node, next_node_index);
4681 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4689 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4691 rmp->next_index = ntohl(next_index);
4697 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4699 vlib_main_t *vm = vlib_get_main ();
4700 vl_api_add_node_next_reply_t *rmp;
4701 vlib_node_t *n, *next;
4703 u32 next_index = ~0;
4705 n = vlib_get_node_by_name (vm, mp->node_name);
4709 rv = VNET_API_ERROR_NO_SUCH_NODE;
4713 next = vlib_get_node_by_name (vm, mp->next_name);
4716 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4718 next_index = vlib_node_add_next (vm, n->index, next->index);
4722 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4724 rmp->next_index = ntohl(next_index);
4729 static void vl_api_l2tpv3_create_tunnel_t_handler
4730 (vl_api_l2tpv3_create_tunnel_t * mp)
4732 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4733 l2t_main_t *lm = &l2t_main;
4734 u32 sw_if_index = (u32) ~ 0;
4737 if (mp->is_ipv6 != 1)
4739 rv = VNET_API_ERROR_UNIMPLEMENTED;
4743 u32 encap_fib_index;
4745 if (mp->encap_vrf_id != ~0)
4748 ip6_main_t *im = &ip6_main;
4751 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4753 rv = VNET_API_ERROR_NO_SUCH_FIB;
4756 encap_fib_index = p[0];
4760 encap_fib_index = ~0;
4763 rv = create_l2tpv3_ipv6_tunnel (lm,
4764 (ip6_address_t *) mp->client_address,
4765 (ip6_address_t *) mp->our_address,
4766 ntohl (mp->local_session_id),
4767 ntohl (mp->remote_session_id),
4768 clib_net_to_host_u64 (mp->local_cookie),
4769 clib_net_to_host_u64 (mp->remote_cookie),
4770 mp->l2_sublayer_present,
4771 encap_fib_index, &sw_if_index);
4775 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4777 rmp->sw_if_index = ntohl (sw_if_index);
4782 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4783 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4785 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4786 l2t_main_t *lm = &l2t_main;
4789 VALIDATE_SW_IF_INDEX (mp);
4791 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4792 clib_net_to_host_u64 (mp->new_local_cookie),
4793 clib_net_to_host_u64
4794 (mp->new_remote_cookie));
4796 BAD_SW_IF_INDEX_LABEL;
4798 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4801 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4802 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4805 vnet_main_t *vnm = vnet_get_main ();
4806 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4808 VALIDATE_SW_IF_INDEX (mp);
4810 rv = l2tpv3_interface_enable_disable
4811 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4813 BAD_SW_IF_INDEX_LABEL;
4815 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4818 static void vl_api_l2tpv3_set_lookup_key_t_handler
4819 (vl_api_l2tpv3_set_lookup_key_t * mp)
4822 l2t_main_t *lm = &l2t_main;
4823 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4825 if (mp->key > L2T_LOOKUP_SESSION_ID)
4827 rv = VNET_API_ERROR_INVALID_VALUE;
4831 lm->lookup_type = mp->key;
4834 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4837 static void vl_api_vxlan_add_del_tunnel_t_handler
4838 (vl_api_vxlan_add_del_tunnel_t * mp)
4840 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4842 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4843 u32 encap_fib_index;
4845 ip4_main_t *im = &ip4_main;
4846 u32 sw_if_index = ~0;
4848 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4851 rv = VNET_API_ERROR_NO_SUCH_FIB;
4854 encap_fib_index = p[0];
4856 /* Check src & dst are different */
4857 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4858 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4860 rv = VNET_API_ERROR_SAME_SRC_DST;
4863 memset (a, 0, sizeof (*a));
4865 a->is_add = mp->is_add;
4866 a->is_ip6 = mp->is_ipv6;
4868 /* ip addresses sent in network byte order */
4871 memcpy (&(a->src.ip6), mp->src_address, 16);
4872 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4876 memcpy (&(a->src.ip4), mp->src_address, 4);
4877 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4880 a->encap_fib_index = encap_fib_index;
4881 a->decap_next_index = ntohl (mp->decap_next_index);
4882 a->vni = ntohl (mp->vni);
4883 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4887 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4889 rmp->sw_if_index = ntohl (sw_if_index);
4894 static void send_vxlan_tunnel_details
4895 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4897 vl_api_vxlan_tunnel_details_t *rmp;
4898 ip4_main_t *im4 = &ip4_main;
4899 ip6_main_t *im6 = &ip6_main;
4900 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4902 rmp = vl_msg_api_alloc (sizeof (*rmp));
4903 memset (rmp, 0, sizeof (*rmp));
4904 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4907 memcpy (rmp->src_address, &(t->src.ip6), 16);
4908 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4909 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
4913 memcpy (rmp->src_address, &(t->src.ip4), 4);
4914 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4915 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
4917 rmp->vni = htonl (t->vni);
4918 rmp->decap_next_index = htonl (t->decap_next_index);
4919 rmp->sw_if_index = htonl (t->sw_if_index);
4920 rmp->is_ipv6 = is_ipv6;
4921 rmp->context = context;
4923 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4926 static void vl_api_vxlan_tunnel_dump_t_handler
4927 (vl_api_vxlan_tunnel_dump_t * mp)
4929 unix_shared_memory_queue_t *q;
4930 vxlan_main_t *vxm = &vxlan_main;
4934 q = vl_api_client_index_to_input_queue (mp->client_index);
4940 sw_if_index = ntohl (mp->sw_if_index);
4942 if (~0 == sw_if_index)
4945 pool_foreach (t, vxm->tunnels,
4947 send_vxlan_tunnel_details(t, q, mp->context);
4953 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4954 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4958 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4959 send_vxlan_tunnel_details (t, q, mp->context);
4963 static void vl_api_gre_add_del_tunnel_t_handler
4964 (vl_api_gre_add_del_tunnel_t * mp)
4966 vl_api_gre_add_del_tunnel_reply_t *rmp;
4968 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4971 ip4_main_t *im = &ip4_main;
4972 u32 sw_if_index = ~0;
4974 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4977 rv = VNET_API_ERROR_NO_SUCH_FIB;
4980 outer_fib_id = p[0];
4982 /* Check src & dst are different */
4983 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4984 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4986 rv = VNET_API_ERROR_SAME_SRC_DST;
4989 memset (a, 0, sizeof (*a));
4991 a->is_add = mp->is_add;
4993 /* ip addresses sent in network byte order */
4994 clib_memcpy (&(a->src), mp->src_address, 4);
4995 clib_memcpy (&(a->dst), mp->dst_address, 4);
4997 a->outer_fib_id = outer_fib_id;
4998 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
5002 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
5004 rmp->sw_if_index = ntohl (sw_if_index);
5009 static void send_gre_tunnel_details
5010 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5012 vl_api_gre_tunnel_details_t *rmp;
5013 ip4_main_t *im = &ip4_main;
5015 rmp = vl_msg_api_alloc (sizeof (*rmp));
5016 memset (rmp, 0, sizeof (*rmp));
5017 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
5018 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
5019 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
5020 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
5021 rmp->sw_if_index = htonl (t->sw_if_index);
5022 rmp->context = context;
5024 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5028 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
5030 unix_shared_memory_queue_t *q;
5031 gre_main_t *gm = &gre_main;
5035 q = vl_api_client_index_to_input_queue (mp->client_index);
5041 sw_if_index = ntohl (mp->sw_if_index);
5043 if (~0 == sw_if_index)
5046 pool_foreach (t, gm->tunnels,
5048 send_gre_tunnel_details(t, q, mp->context);
5054 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
5055 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
5059 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
5060 send_gre_tunnel_details (t, q, mp->context);
5065 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
5067 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5069 vl_api_l2_patch_add_del_reply_t *rmp;
5070 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5074 VALIDATE_RX_SW_IF_INDEX (mp);
5075 VALIDATE_TX_SW_IF_INDEX (mp);
5077 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
5078 ntohl (mp->tx_sw_if_index),
5079 (int) (mp->is_add != 0));
5081 BAD_RX_SW_IF_INDEX_LABEL;
5082 BAD_TX_SW_IF_INDEX_LABEL;
5084 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
5088 vl_api_vxlan_gpe_add_del_tunnel_t_handler
5089 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
5091 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
5093 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
5094 u32 encap_fib_index, decap_fib_index;
5097 ip4_main_t *im = &ip4_main;
5098 u32 sw_if_index = ~0;
5101 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
5104 rv = VNET_API_ERROR_NO_SUCH_FIB;
5107 encap_fib_index = p[0];
5109 protocol = mp->protocol;
5111 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
5112 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
5114 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
5117 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
5120 decap_fib_index = p[0];
5124 decap_fib_index = ntohl (mp->decap_vrf_id);
5127 /* Check src & dst are different */
5128 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5129 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5131 rv = VNET_API_ERROR_SAME_SRC_DST;
5134 memset (a, 0, sizeof (*a));
5136 a->is_add = mp->is_add;
5137 a->is_ip6 = mp->is_ipv6;
5138 /* ip addresses sent in network byte order */
5141 clib_memcpy (&(a->local.ip6), mp->local, 16);
5142 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5146 clib_memcpy (&(a->local.ip4), mp->local, 4);
5147 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5149 a->encap_fib_index = encap_fib_index;
5150 a->decap_fib_index = decap_fib_index;
5151 a->protocol = protocol;
5152 a->vni = ntohl (mp->vni);
5153 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5157 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5159 rmp->sw_if_index = ntohl (sw_if_index);
5164 static void send_vxlan_gpe_tunnel_details
5165 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5167 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5168 ip4_main_t *im4 = &ip4_main;
5169 ip6_main_t *im6 = &ip6_main;
5170 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5172 rmp = vl_msg_api_alloc (sizeof (*rmp));
5173 memset (rmp, 0, sizeof (*rmp));
5174 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5177 memcpy (rmp->local, &(t->local.ip6), 16);
5178 memcpy (rmp->remote, &(t->remote.ip6), 16);
5179 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
5180 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].table_id);
5184 memcpy (rmp->local, &(t->local.ip4), 4);
5185 memcpy (rmp->remote, &(t->remote.ip4), 4);
5186 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
5187 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].table_id);
5189 rmp->vni = htonl (t->vni);
5190 rmp->protocol = t->protocol;
5191 rmp->sw_if_index = htonl (t->sw_if_index);
5192 rmp->is_ipv6 = is_ipv6;
5193 rmp->context = context;
5195 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5198 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5199 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5201 unix_shared_memory_queue_t *q;
5202 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5203 vxlan_gpe_tunnel_t *t;
5206 q = vl_api_client_index_to_input_queue (mp->client_index);
5212 sw_if_index = ntohl (mp->sw_if_index);
5214 if (~0 == sw_if_index)
5217 pool_foreach (t, vgm->tunnels,
5219 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5225 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5226 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5230 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5231 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5235 /** Used for transferring locators via VPP API */
5237 typedef CLIB_PACKED (struct {
5238 u32 sw_if_index; /**< locator sw_if_index */
5239 u8 priority; /**< locator priority */
5240 u8 weight; /**< locator weight */
5245 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5248 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5250 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5252 ls_locator_t *ls_loc;
5253 u32 ls_index = ~0, locator_num;
5254 u8 *locator_name = NULL;
5257 memset (a, 0, sizeof (a[0]));
5259 locator_name = format (0, "%s", mp->locator_set_name);
5261 a->name = locator_name;
5262 a->is_add = mp->is_add;
5264 locator_num = clib_net_to_host_u32 (mp->locator_num);
5266 memset (&locator, 0, sizeof (locator));
5267 for (i = 0; i < locator_num; i++)
5269 ls_loc = &((ls_locator_t *) mp->locators)[i];
5270 VALIDATE_SW_IF_INDEX (ls_loc);
5272 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5273 locator.priority = ls_loc->priority;
5274 locator.weight = ls_loc->weight;
5276 vec_add1 (a->locators, locator);
5279 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5281 BAD_SW_IF_INDEX_LABEL;
5283 vec_free (locator_name);
5284 vec_free (a->locators);
5287 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5289 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5295 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5297 vl_api_lisp_add_del_locator_reply_t *rmp;
5299 locator_t locator, *locators = NULL;
5300 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5302 u8 *locator_name = NULL;
5304 memset (&locator, 0, sizeof (locator));
5305 memset (a, 0, sizeof (a[0]));
5307 locator.sw_if_index = ntohl (mp->sw_if_index);
5308 locator.priority = mp->priority;
5309 locator.weight = mp->weight;
5311 vec_add1 (locators, locator);
5313 locator_name = format (0, "%s", mp->locator_set_name);
5315 a->name = locator_name;
5316 a->locators = locators;
5317 a->is_add = mp->is_add;
5320 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5322 vec_free (locators);
5323 vec_free (locator_name);
5325 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5329 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5335 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5336 gid_address_ip_set (dst, src, IP4);
5337 gid_address_ippref_len (dst) = len;
5338 ip_prefix_normalize (&gid_address_ippref (dst));
5341 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5342 gid_address_ip_set (dst, src, IP6);
5343 gid_address_ippref_len (dst) = len;
5344 ip_prefix_normalize (&gid_address_ippref (dst));
5346 case 2: /* l2 mac */
5347 gid_address_type (dst) = GID_ADDR_MAC;
5348 clib_memcpy (&gid_address_mac (dst), src, 6);
5352 return VNET_API_ERROR_INVALID_VALUE;
5355 gid_address_vni (dst) = vni;
5361 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5363 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5364 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5366 gid_address_t _eid, *eid = &_eid;
5368 u32 locator_set_index = ~0, map_index = ~0;
5369 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5371 memset (a, 0, sizeof (a[0]));
5372 memset (eid, 0, sizeof (eid[0]));
5374 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5375 mp->eid_type, mp->eid, mp->prefix_len);
5379 name = format (0, "%s", mp->locator_set_name);
5380 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5383 rv = VNET_API_ERROR_INVALID_VALUE;
5386 locator_set_index = p[0];
5388 /* XXX treat batch configuration */
5389 a->is_add = mp->is_add;
5390 gid_address_copy (&a->eid, eid);
5391 a->locator_set_index = locator_set_index;
5393 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5397 gid_address_free (&a->eid);
5399 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5403 vl_api_lisp_eid_table_add_del_map_t_handler
5404 (vl_api_lisp_eid_table_add_del_map_t * mp)
5406 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5408 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5409 clib_net_to_host_u32 (mp->dp_table),
5410 mp->is_l2, mp->is_add);
5411 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5413 /** Used for transferring locators via VPP API */
5415 typedef CLIB_PACKED (struct {
5416 u8 is_ip4; /**< is locator an IPv4 address */
5417 u8 priority; /**< locator priority */
5418 u8 weight; /**< locator weight */
5419 u8 addr[16]; /**< IPv4/IPv6 address */
5423 static locator_pair_t *
5424 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5427 locator_pair_t *pairs = 0, pair;
5430 for (i = 0; i < rloc_num; i++)
5433 r = &((rloc_t *) lcl_locs)[i];
5434 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5435 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5437 /* remote locators */
5438 r = &((rloc_t *) rmt_locs)[i];
5439 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5440 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5442 pair.priority = r->priority;
5443 pair.weight = r->weight;
5445 vec_add1 (pairs, pair);
5451 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5454 locator_t *locs = 0, loc;
5457 for (i = 0; i < rloc_num; i++)
5459 /* remote locators */
5460 r = &((rloc_t *) rmt_locs)[i];
5461 memset (&loc, 0, sizeof (loc));
5462 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5464 loc.priority = r->priority;
5465 loc.weight = r->weight;
5467 vec_add1 (locs, loc);
5473 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5474 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5476 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5477 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5478 locator_pair_t *pairs = 0;
5481 memset (a, 0, sizeof (a[0]));
5483 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5484 mp->rmt_eid, mp->rmt_len);
5485 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5486 mp->lcl_eid, mp->lcl_len);
5488 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5490 if (rv || 0 == pairs)
5493 a->is_add = mp->is_add;
5494 a->locator_pairs = pairs;
5495 a->dp_table = mp->dp_table;
5497 a->action = mp->action;
5499 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5502 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5506 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5509 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5511 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5513 memset (a, 0, sizeof (a[0]));
5515 a->is_add = mp->is_add;
5516 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5518 rv = vnet_lisp_add_del_map_resolver (a);
5520 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5524 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5527 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5529 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5531 a->is_en = mp->is_en;
5532 vnet_lisp_gpe_enable_disable (a);
5534 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5538 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5540 vl_api_lisp_enable_disable_reply_t *rmp;
5543 vnet_lisp_enable_disable (mp->is_en);
5544 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5548 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5550 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5552 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5554 a->is_add = mp->is_add;
5555 a->dp_table = mp->dp_table;
5557 a->is_l2 = mp->is_l2;
5558 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5560 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5564 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5567 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5571 ls_name = format (0, "%s", mp->ls_name);
5572 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5575 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5579 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5580 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5582 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5584 u8 *locator_set_name = NULL;
5585 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5587 locator_set_name = format (0, "%s", mp->locator_set_name);
5589 a->is_add = mp->is_add;
5590 a->locator_set_name = locator_set_name;
5592 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5594 vec_free (locator_set_name);
5596 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5600 vl_api_lisp_add_del_remote_mapping_t_handler
5601 (vl_api_lisp_add_del_remote_mapping_t * mp)
5603 locator_t *rlocs = 0;
5604 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5606 gid_address_t _eid, *eid = &_eid;
5607 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5609 memset (eid, 0, sizeof (eid[0]));
5611 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5612 mp->eid_type, mp->eid, mp->eid_len);
5616 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5620 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5621 gid_address_copy (&a->deid, eid);
5623 rv = vnet_lisp_add_del_adjacency (a);
5630 /* NOTE: for now this works as a static remote mapping, i.e.,
5631 * not authoritative and ttl infinite. */
5632 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5633 mp->is_add, 1 /* is_static */ , 0);
5636 vnet_lisp_clear_all_remote_adjacencies ();
5641 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5645 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5647 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5648 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5651 memset (a, 0, sizeof (a[0]));
5653 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5654 mp->eid_type, mp->seid, mp->seid_len);
5655 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5656 mp->eid_type, mp->deid, mp->deid_len);
5661 a->is_add = mp->is_add;
5662 rv = vnet_lisp_add_del_adjacency (a);
5665 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5669 send_lisp_locator_details (lisp_cp_main_t * lcm,
5671 unix_shared_memory_queue_t * q, u32 context)
5673 vl_api_lisp_locator_details_t *rmp;
5675 rmp = vl_msg_api_alloc (sizeof (*rmp));
5676 memset (rmp, 0, sizeof (*rmp));
5677 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5678 rmp->context = context;
5680 rmp->local = loc->local;
5683 rmp->sw_if_index = ntohl (loc->sw_if_index);
5687 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5688 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5690 rmp->priority = loc->priority;
5691 rmp->weight = loc->weight;
5693 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5697 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5700 unix_shared_memory_queue_t *q = 0;
5701 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5702 locator_set_t *lsit = 0;
5704 u32 ls_index = ~0, *locit = 0;
5707 q = vl_api_client_index_to_input_queue (mp->client_index);
5713 if (mp->is_index_set)
5714 ls_index = htonl (mp->ls_index);
5717 ls_name = format (0, "%s", mp->ls_name);
5718 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
5724 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
5727 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5729 vec_foreach (locit, lsit->locator_indices)
5731 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5732 send_lisp_locator_details (lcm, loc, q, mp->context);
5739 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5740 locator_set_t * lsit,
5741 unix_shared_memory_queue_t * q,
5742 u32 context, u32 ls_index)
5744 vl_api_lisp_locator_set_details_t *rmp;
5747 rmp = vl_msg_api_alloc (sizeof (*rmp));
5748 memset (rmp, 0, sizeof (*rmp));
5749 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5750 rmp->context = context;
5752 rmp->ls_index = htonl (ls_index);
5755 ASSERT (lsit->name != NULL);
5756 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
5757 vec_len (lsit->name));
5761 str = format (0, "<remote-%d>", ls_index);
5762 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
5766 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5770 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5772 unix_shared_memory_queue_t *q = NULL;
5773 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5774 locator_set_t *lsit = NULL;
5777 q = vl_api_client_index_to_input_queue (mp->client_index);
5783 filter = mp->filter;
5785 pool_foreach (lsit, lcm->locator_set_pool,
5787 if (filter && !((1 == filter && lsit->local) ||
5788 (2 == filter && !lsit->local)))
5792 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
5793 lsit - lcm->locator_set_pool);
5799 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5801 ASSERT (prefix_length);
5802 ip_prefix_t *ippref = &fid_addr_ippref (src);
5804 switch (fid_addr_type (src))
5806 case FID_ADDR_IP_PREF:
5807 if (ip_prefix_version (ippref) == IP4)
5808 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5810 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5811 prefix_length[0] = ip_prefix_len (ippref);
5815 prefix_length[0] = 0;
5816 clib_memcpy (dst, fid_addr_mac (src), 6);
5820 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5826 fid_type_to_api_type (fid_address_t * fid)
5828 ip_prefix_t *ippref;
5830 switch (fid_addr_type (fid))
5832 case FID_ADDR_IP_PREF:
5833 ippref = &fid_addr_ippref (fid);
5834 if (ip_prefix_version (ippref) == IP4)
5836 else if (ip_prefix_version (ippref) == IP6)
5849 send_lisp_eid_table_details (mapping_t * mapit,
5850 unix_shared_memory_queue_t * q,
5851 u32 context, u8 filter)
5854 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5855 locator_set_t *ls = 0;
5856 vl_api_lisp_eid_table_details_t *rmp = NULL;
5857 gid_address_t *gid = NULL;
5859 ip_prefix_t *ip_prefix = NULL;
5863 case 0: /* all mappings */
5866 case 1: /* local only */
5870 case 2: /* remote only */
5875 clib_warning ("Filter error, unknown filter: %d", filter);
5880 ip_prefix = &gid_address_ippref (gid);
5881 mac = gid_address_mac (gid);
5883 rmp = vl_msg_api_alloc (sizeof (*rmp));
5884 memset (rmp, 0, sizeof (*rmp));
5885 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5887 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5888 if (vec_len (ls->locator_indices) == 0)
5889 rmp->locator_set_index = ~0;
5891 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5893 rmp->is_local = mapit->local;
5894 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5895 rmp->action = mapit->action;
5896 rmp->authoritative = mapit->authoritative;
5898 switch (gid_address_type (gid))
5900 case GID_ADDR_SRC_DST:
5901 rmp->is_src_dst = 1;
5902 fid = &gid_address_sd_src (gid);
5903 rmp->eid_type = fid_type_to_api_type (fid);
5904 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5905 &rmp->seid_prefix_len);
5906 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5907 &rmp->eid_prefix_len);
5909 case GID_ADDR_IP_PREFIX:
5910 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5911 if (ip_prefix_version (ip_prefix) == IP4)
5913 rmp->eid_type = 0; /* ipv4 type */
5914 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5915 sizeof (ip_prefix_v4 (ip_prefix)));
5919 rmp->eid_type = 1; /* ipv6 type */
5920 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5921 sizeof (ip_prefix_v6 (ip_prefix)));
5925 rmp->eid_type = 2; /* l2 mac type */
5926 clib_memcpy (rmp->eid, mac, 6);
5931 rmp->context = context;
5932 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5933 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5937 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5940 unix_shared_memory_queue_t *q = NULL;
5941 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5942 mapping_t *mapit = NULL;
5943 gid_address_t _eid, *eid = &_eid;
5945 q = vl_api_client_index_to_input_queue (mp->client_index);
5953 memset (eid, 0, sizeof (*eid));
5955 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5956 mp->eid_type, mp->eid, mp->prefix_length);
5958 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5959 if ((u32) ~ 0 == mi)
5962 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5963 send_lisp_eid_table_details (mapit, q, mp->context,
5964 0 /* ignore filter */ );
5969 pool_foreach (mapit, lcm->mapping_pool,
5971 send_lisp_eid_table_details(mapit, q, mp->context,
5979 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5980 unix_shared_memory_queue_t * q, u32 context)
5982 vl_api_lisp_gpe_tunnel_details_t *rmp;
5983 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5985 rmp = vl_msg_api_alloc (sizeof (*rmp));
5986 memset (rmp, 0, sizeof (*rmp));
5987 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5989 rmp->tunnels = tunnel - lgm->tunnels;
5991 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5992 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5993 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5995 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5996 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5997 rmp->dcap_next = htonl (tunnel->decap_next_index);
5998 rmp->lisp_ver = tunnel->ver_res;
5999 rmp->next_protocol = tunnel->next_protocol;
6000 rmp->flags = tunnel->flags;
6001 rmp->ver_res = tunnel->ver_res;
6002 rmp->res = tunnel->res;
6003 rmp->iid = htonl (tunnel->vni);
6004 rmp->context = context;
6006 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6010 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
6012 unix_shared_memory_queue_t *q = NULL;
6013 lisp_gpe_main_t *lgm = &lisp_gpe_main;
6014 lisp_gpe_tunnel_t *tunnel = NULL;
6016 if (pool_elts (lgm->tunnels) == 0)
6021 q = vl_api_client_index_to_input_queue (mp->client_index);
6028 pool_foreach(tunnel, lgm->tunnels,
6030 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
6036 send_lisp_map_resolver_details (ip_address_t * ip,
6037 unix_shared_memory_queue_t * q, u32 context)
6039 vl_api_lisp_map_resolver_details_t *rmp = NULL;
6041 rmp = vl_msg_api_alloc (sizeof (*rmp));
6042 memset (rmp, 0, sizeof (*rmp));
6043 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
6045 switch (ip_addr_version (ip))
6049 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
6050 sizeof (ip_addr_v4 (ip)));
6055 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
6056 sizeof (ip_addr_v6 (ip)));
6062 rmp->context = context;
6064 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6068 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
6070 unix_shared_memory_queue_t *q = NULL;
6071 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6074 q = vl_api_client_index_to_input_queue (mp->client_index);
6080 vec_foreach (mr, lcm->map_resolvers)
6082 send_lisp_map_resolver_details (&mr->address, q, mp->context);
6087 send_eid_table_map_pair (hash_pair_t * p,
6088 unix_shared_memory_queue_t * q, u32 context)
6090 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
6092 rmp = vl_msg_api_alloc (sizeof (*rmp));
6093 memset (rmp, 0, sizeof (*rmp));
6094 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
6096 rmp->vni = clib_host_to_net_u32 (p->key);
6097 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
6098 rmp->context = context;
6099 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6103 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
6106 unix_shared_memory_queue_t *q = NULL;
6107 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6109 uword *vni_table = 0;
6111 q = vl_api_client_index_to_input_queue (mp->client_index);
6119 vni_table = lcm->bd_id_by_vni;
6123 vni_table = lcm->table_id_by_vni;
6127 hash_foreach_pair (p, vni_table,
6129 send_eid_table_map_pair (p, q, mp->context);
6135 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6137 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6139 rmp = vl_msg_api_alloc (sizeof (*rmp));
6140 memset (rmp, 0, sizeof (*rmp));
6141 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6142 rmp->context = context;
6143 rmp->vni = clib_host_to_net_u32 (vni);
6144 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6148 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6153 unix_shared_memory_queue_t *q = 0;
6154 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6156 q = vl_api_client_index_to_input_queue (mp->client_index);
6163 hash_foreach_pair (p, lcm->table_id_by_vni,
6165 hash_set (vnis, p->key, 0);
6168 hash_foreach_pair (p, lcm->bd_id_by_vni,
6170 hash_set (vnis, p->key, 0);
6173 hash_foreach_pair (p, vnis,
6175 send_eid_table_vni (p->key, q, mp->context);
6183 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6185 unix_shared_memory_queue_t *q = NULL;
6186 vl_api_show_lisp_status_reply_t *rmp = NULL;
6189 q = vl_api_client_index_to_input_queue (mp->client_index);
6196 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6198 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6199 rmp->feature_status = vnet_lisp_enable_disable_status ();
6205 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6206 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6208 unix_shared_memory_queue_t *q = NULL;
6209 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6210 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6211 locator_set_t *loc_set = 0;
6215 q = vl_api_client_index_to_input_queue (mp->client_index);
6221 if (~0 == lcm->mreq_itr_rlocs)
6223 tmp_str = format (0, " ");
6228 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6229 tmp_str = format (0, "%s", loc_set->name);
6233 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6235 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6236 ARRAY_LEN(rmp->locator_set_name) - 1);
6244 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6246 unix_shared_memory_queue_t *q = NULL;
6247 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6248 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6250 locator_set_t *ls = 0;
6254 q = vl_api_client_index_to_input_queue (mp->client_index);
6260 if (!lcm->lisp_pitr)
6262 tmp_str = format (0, "N/A");
6266 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6267 if (~0 != m->locator_set_index)
6270 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6271 tmp_str = format (0, "%s", ls->name);
6275 tmp_str = format (0, "N/A");
6278 vec_add1 (tmp_str, 0);
6281 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6283 rmp->status = lcm->lisp_pitr;
6284 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6285 ARRAY_LEN(rmp->locator_set_name) - 1);
6291 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6294 vl_api_interface_name_renumber_reply_t *rmp;
6297 VALIDATE_SW_IF_INDEX (mp);
6299 rv = vnet_interface_name_renumber
6300 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6302 BAD_SW_IF_INDEX_LABEL;
6304 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6308 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6309 u32 sw_if_index, u32 address)
6311 vpe_api_main_t *am = &vpe_api_main;
6312 vlib_main_t *vm = am->vlib_main;
6313 vl_api_ip4_arp_event_t *event;
6314 static f64 arp_event_last_time;
6315 f64 now = vlib_time_now (vm);
6317 if (pool_is_free_index (am->arp_events, pool_index))
6320 event = pool_elt_at_index (am->arp_events, pool_index);
6322 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6324 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6328 if (sw_if_index == event->sw_if_index &&
6330 /* for BD case, also check IP address with 10 sec timeout */
6331 (address == event->address &&
6332 (now - arp_event_last_time) < 10.0)))
6337 arp_event_last_time = now;
6338 event->sw_if_index = sw_if_index;
6340 event->address = address;
6345 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6346 u32 sw_if_index, ip6_address_t * address)
6348 vpe_api_main_t *am = &vpe_api_main;
6349 vlib_main_t *vm = am->vlib_main;
6350 vl_api_ip6_nd_event_t *event;
6351 static f64 nd_event_last_time;
6352 f64 now = vlib_time_now (vm);
6354 if (pool_is_free_index (am->nd_events, pool_index))
6357 event = pool_elt_at_index (am->nd_events, pool_index);
6360 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6362 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6366 if (sw_if_index == event->sw_if_index &&
6368 /* for BD case, also check IP address with 10 sec timeout */
6369 (ip6_address_is_equal (address,
6370 (ip6_address_t *) event->address) &&
6371 (now - nd_event_last_time) < 10.0)))
6376 nd_event_last_time = now;
6377 event->sw_if_index = sw_if_index;
6379 clib_memcpy (event->address, address, sizeof (event->address));
6384 arp_change_delete_callback (u32 pool_index, u8 * notused)
6386 vpe_api_main_t *am = &vpe_api_main;
6388 if (pool_is_free_index (am->arp_events, pool_index))
6391 pool_put_index (am->arp_events, pool_index);
6396 nd_change_delete_callback (u32 pool_index, u8 * notused)
6398 vpe_api_main_t *am = &vpe_api_main;
6400 if (pool_is_free_index (am->nd_events, pool_index))
6403 pool_put_index (am->nd_events, pool_index);
6408 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6410 vpe_api_main_t *am = &vpe_api_main;
6411 vnet_main_t *vnm = vnet_get_main ();
6412 vl_api_want_ip4_arp_events_reply_t *rmp;
6413 vl_api_ip4_arp_event_t *event;
6416 if (mp->enable_disable)
6418 pool_get (am->arp_events, event);
6419 memset (event, 0, sizeof (*event));
6421 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6422 event->client_index = mp->client_index;
6423 event->context = mp->context;
6424 event->address = mp->address;
6425 event->pid = mp->pid;
6426 if (mp->address == 0)
6429 rv = vnet_add_del_ip4_arp_change_event
6430 (vnm, arp_change_data_callback,
6431 mp->pid, &mp->address /* addr, in net byte order */ ,
6432 vpe_resolver_process_node.index,
6433 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6437 rv = vnet_add_del_ip4_arp_change_event
6438 (vnm, arp_change_delete_callback,
6439 mp->pid, &mp->address /* addr, in net byte order */ ,
6440 vpe_resolver_process_node.index,
6441 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6443 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6447 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6449 vpe_api_main_t *am = &vpe_api_main;
6450 vnet_main_t *vnm = vnet_get_main ();
6451 vl_api_want_ip6_nd_events_reply_t *rmp;
6452 vl_api_ip6_nd_event_t *event;
6455 if (mp->enable_disable)
6457 pool_get (am->nd_events, event);
6458 memset (event, 0, sizeof (*event));
6460 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6461 event->client_index = mp->client_index;
6462 event->context = mp->context;
6463 clib_memcpy (event->address, mp->address, 16);
6464 event->pid = mp->pid;
6465 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6468 rv = vnet_add_del_ip6_nd_change_event
6469 (vnm, nd_change_data_callback,
6470 mp->pid, mp->address /* addr, in net byte order */ ,
6471 vpe_resolver_process_node.index,
6472 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6476 rv = vnet_add_del_ip6_nd_change_event
6477 (vnm, nd_change_delete_callback,
6478 mp->pid, mp->address /* addr, in net byte order */ ,
6479 vpe_resolver_process_node.index,
6480 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6482 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6485 static void vl_api_input_acl_set_interface_t_handler
6486 (vl_api_input_acl_set_interface_t * mp)
6488 vlib_main_t *vm = vlib_get_main ();
6489 vl_api_input_acl_set_interface_reply_t *rmp;
6491 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6493 ip4_table_index = ntohl (mp->ip4_table_index);
6494 ip6_table_index = ntohl (mp->ip6_table_index);
6495 l2_table_index = ntohl (mp->l2_table_index);
6496 sw_if_index = ntohl (mp->sw_if_index);
6498 VALIDATE_SW_IF_INDEX (mp);
6500 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6501 ip6_table_index, l2_table_index, mp->is_add);
6503 BAD_SW_IF_INDEX_LABEL;
6505 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6508 static void vl_api_ipsec_spd_add_del_t_handler
6509 (vl_api_ipsec_spd_add_del_t * mp)
6512 clib_warning ("unimplemented");
6515 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6516 vl_api_ipsec_spd_add_del_reply_t *rmp;
6520 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6522 rv = VNET_API_ERROR_UNIMPLEMENTED;
6525 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6529 static void vl_api_ipsec_interface_add_del_spd_t_handler
6530 (vl_api_ipsec_interface_add_del_spd_t * mp)
6532 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6533 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6535 u32 sw_if_index __attribute__ ((unused));
6536 u32 spd_id __attribute__ ((unused));
6538 sw_if_index = ntohl (mp->sw_if_index);
6539 spd_id = ntohl (mp->spd_id);
6541 VALIDATE_SW_IF_INDEX (mp);
6544 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6546 rv = VNET_API_ERROR_UNIMPLEMENTED;
6549 BAD_SW_IF_INDEX_LABEL;
6551 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6554 static void vl_api_ipsec_spd_add_del_entry_t_handler
6555 (vl_api_ipsec_spd_add_del_entry_t * mp)
6557 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6558 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6564 memset (&p, 0, sizeof (p));
6566 p.id = ntohl (mp->spd_id);
6567 p.priority = ntohl (mp->priority);
6568 p.is_outbound = mp->is_outbound;
6569 p.is_ipv6 = mp->is_ipv6;
6571 if (mp->is_ipv6 || mp->is_ip_any)
6573 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6574 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6575 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6576 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6580 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6581 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6582 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6583 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6585 p.protocol = mp->protocol;
6586 p.rport.start = ntohs (mp->remote_port_start);
6587 p.rport.stop = ntohs (mp->remote_port_stop);
6588 p.lport.start = ntohs (mp->local_port_start);
6589 p.lport.stop = ntohs (mp->local_port_stop);
6590 /* policy action resolve unsupported */
6591 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6593 clib_warning ("unsupported action: 'resolve'");
6594 rv = VNET_API_ERROR_UNIMPLEMENTED;
6597 p.policy = mp->policy;
6598 p.sa_id = ntohl (mp->sa_id);
6600 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6607 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6610 rv = VNET_API_ERROR_UNIMPLEMENTED;
6615 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6618 static void vl_api_ipsec_sad_add_del_entry_t_handler
6619 (vl_api_ipsec_sad_add_del_entry_t * mp)
6621 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6622 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6627 memset (&sa, 0, sizeof (sa));
6629 sa.id = ntohl (mp->sad_id);
6630 sa.spi = ntohl (mp->spi);
6631 /* security protocol AH unsupported */
6632 if (mp->protocol == IPSEC_PROTOCOL_AH)
6634 clib_warning ("unsupported security protocol 'AH'");
6635 rv = VNET_API_ERROR_UNIMPLEMENTED;
6638 sa.protocol = mp->protocol;
6639 /* check for unsupported crypto-alg */
6640 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6641 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6643 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6644 mp->crypto_algorithm);
6645 rv = VNET_API_ERROR_UNIMPLEMENTED;
6648 sa.crypto_alg = mp->crypto_algorithm;
6649 sa.crypto_key_len = mp->crypto_key_length;
6650 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6651 /* check for unsupported integ-alg */
6652 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6653 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6655 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6656 mp->integrity_algorithm);
6657 rv = VNET_API_ERROR_UNIMPLEMENTED;
6660 sa.integ_alg = mp->integrity_algorithm;
6661 sa.integ_key_len = mp->integrity_key_length;
6662 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6663 sa.use_esn = mp->use_extended_sequence_number;
6664 sa.is_tunnel = mp->is_tunnel;
6665 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6666 if (sa.is_tunnel_ip6)
6668 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6669 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6673 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6674 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6677 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6679 rv = VNET_API_ERROR_UNIMPLEMENTED;
6684 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6688 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6690 vl_api_ikev2_profile_add_del_reply_t *rmp;
6694 vlib_main_t *vm = vlib_get_main ();
6695 clib_error_t *error;
6696 u8 *tmp = format (0, "%s", mp->name);
6697 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6700 rv = VNET_API_ERROR_UNSPECIFIED;
6702 rv = VNET_API_ERROR_UNIMPLEMENTED;
6705 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6709 vl_api_ikev2_profile_set_auth_t_handler
6710 (vl_api_ikev2_profile_set_auth_t * mp)
6712 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6716 vlib_main_t *vm = vlib_get_main ();
6717 clib_error_t *error;
6718 u8 *tmp = format (0, "%s", mp->name);
6719 u8 *data = vec_new (u8, mp->data_len);
6720 clib_memcpy (data, mp->data, mp->data_len);
6721 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6725 rv = VNET_API_ERROR_UNSPECIFIED;
6727 rv = VNET_API_ERROR_UNIMPLEMENTED;
6730 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6734 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6736 vl_api_ikev2_profile_add_del_reply_t *rmp;
6740 vlib_main_t *vm = vlib_get_main ();
6741 clib_error_t *error;
6742 u8 *tmp = format (0, "%s", mp->name);
6743 u8 *data = vec_new (u8, mp->data_len);
6744 clib_memcpy (data, mp->data, mp->data_len);
6745 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6749 rv = VNET_API_ERROR_UNSPECIFIED;
6751 rv = VNET_API_ERROR_UNIMPLEMENTED;
6754 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6758 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6760 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6764 vlib_main_t *vm = vlib_get_main ();
6765 clib_error_t *error;
6766 u8 *tmp = format (0, "%s", mp->name);
6767 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6768 mp->end_port, (ip4_address_t) mp->start_addr,
6769 (ip4_address_t) mp->end_addr, mp->is_local);
6772 rv = VNET_API_ERROR_UNSPECIFIED;
6774 rv = VNET_API_ERROR_UNIMPLEMENTED;
6777 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6781 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6783 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6787 vlib_main_t *vm = vlib_get_main ();
6788 clib_error_t *error;
6790 error = ikev2_set_local_key (vm, mp->key_file);
6792 rv = VNET_API_ERROR_UNSPECIFIED;
6794 rv = VNET_API_ERROR_UNIMPLEMENTED;
6797 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6801 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6803 vl_api_map_add_domain_reply_t *rmp;
6806 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6808 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6809 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6810 (ip6_address_t *) & mp->ip6_src,
6811 mp->ip6_src_prefix_len, mp->ea_bits_len,
6812 mp->psid_offset, mp->psid_length, &index,
6813 ntohs (mp->mtu), flags);
6816 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6818 rmp->index = ntohl(index);
6824 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6826 vl_api_map_del_domain_reply_t *rmp;
6829 rv = map_delete_domain (ntohl (mp->index));
6831 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6835 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6837 vl_api_map_del_domain_reply_t *rmp;
6841 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6842 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6844 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6848 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6850 vl_api_map_domain_details_t *rmp;
6851 map_main_t *mm = &map_main;
6853 unix_shared_memory_queue_t *q;
6855 if (pool_elts (mm->domains) == 0)
6858 q = vl_api_client_index_to_input_queue (mp->client_index);
6865 pool_foreach(d, mm->domains,
6867 /* Make sure every field is initiated (or don't skip the memset()) */
6868 rmp = vl_msg_api_alloc (sizeof (*rmp));
6869 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6870 rmp->domain_index = htonl(d - mm->domains);
6871 rmp->ea_bits_len = d->ea_bits_len;
6872 rmp->psid_offset = d->psid_offset;
6873 rmp->psid_length = d->psid_length;
6874 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6875 rmp->ip4_prefix_len = d->ip4_prefix_len;
6876 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6877 rmp->ip6_prefix_len = d->ip6_prefix_len;
6878 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6879 rmp->ip6_src_len = d->ip6_src_len;
6880 rmp->mtu = htons(d->mtu);
6881 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6882 rmp->context = mp->context;
6884 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6890 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6892 unix_shared_memory_queue_t *q;
6895 vl_api_map_rule_details_t *rmp;
6896 map_main_t *mm = &map_main;
6897 u32 domain_index = ntohl (mp->domain_index);
6900 if (pool_elts (mm->domains) == 0)
6903 d = pool_elt_at_index (mm->domains, domain_index);
6904 if (!d || !d->rules)
6909 q = vl_api_client_index_to_input_queue (mp->client_index);
6915 for (i = 0; i < (0x1 << d->psid_length); i++)
6918 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6922 rmp = vl_msg_api_alloc (sizeof (*rmp));
6923 memset (rmp, 0, sizeof (*rmp));
6924 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6925 rmp->psid = htons (i);
6926 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6927 rmp->context = mp->context;
6928 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6933 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6935 vl_api_map_summary_stats_reply_t *rmp;
6936 vlib_combined_counter_main_t *cm;
6939 u64 total_pkts[VLIB_N_RX_TX];
6940 u64 total_bytes[VLIB_N_RX_TX];
6941 map_main_t *mm = &map_main;
6942 unix_shared_memory_queue_t *q =
6943 vl_api_client_index_to_input_queue (mp->client_index);
6948 rmp = vl_msg_api_alloc (sizeof (*rmp));
6949 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6950 rmp->context = mp->context;
6953 memset (total_pkts, 0, sizeof (total_pkts));
6954 memset (total_bytes, 0, sizeof (total_bytes));
6956 map_domain_counter_lock (mm);
6957 vec_foreach (cm, mm->domain_counters)
6959 which = cm - mm->domain_counters;
6961 for (i = 0; i < vec_len (cm->maxi); i++)
6963 vlib_get_combined_counter (cm, i, &v);
6964 total_pkts[which] += v.packets;
6965 total_bytes[which] += v.bytes;
6969 map_domain_counter_unlock (mm);
6971 /* Note: in network byte order! */
6972 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6973 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6974 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6975 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6976 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6977 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6978 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6979 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6980 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6981 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6982 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6983 clib_host_to_net_u64 (map_error_counter_get
6984 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6985 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6986 clib_host_to_net_u64 (map_error_counter_get
6987 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6989 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6993 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6995 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6996 vl_api_ipsec_sa_set_key_reply_t *rmp;
7000 sa.id = ntohl (mp->sa_id);
7001 sa.crypto_key_len = mp->crypto_key_length;
7002 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
7003 sa.integ_key_len = mp->integrity_key_length;
7004 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
7006 rv = ipsec_set_sa_key (vm, &sa);
7008 rv = VNET_API_ERROR_UNIMPLEMENTED;
7011 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
7014 static void vl_api_cop_interface_enable_disable_t_handler
7015 (vl_api_cop_interface_enable_disable_t * mp)
7017 vl_api_cop_interface_enable_disable_reply_t *rmp;
7019 u32 sw_if_index = ntohl (mp->sw_if_index);
7022 VALIDATE_SW_IF_INDEX (mp);
7024 enable_disable = (int) mp->enable_disable;
7026 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
7028 BAD_SW_IF_INDEX_LABEL;
7030 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
7033 static void vl_api_cop_whitelist_enable_disable_t_handler
7034 (vl_api_cop_whitelist_enable_disable_t * mp)
7036 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
7037 cop_whitelist_enable_disable_args_t _a, *a = &_a;
7038 u32 sw_if_index = ntohl (mp->sw_if_index);
7041 VALIDATE_SW_IF_INDEX (mp);
7043 a->sw_if_index = sw_if_index;
7046 a->default_cop = mp->default_cop;
7047 a->fib_id = ntohl (mp->fib_id);
7049 rv = cop_whitelist_enable_disable (a);
7051 BAD_SW_IF_INDEX_LABEL;
7053 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
7057 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
7061 api_main_t *am = &api_main;
7062 vlib_main_t *vm = vlib_get_main ();
7064 vl_api_get_node_graph_reply_t *rmp;
7066 pthread_mutex_lock (&am->vlib_rp->mutex);
7067 oldheap = svm_push_data_heap (am->vlib_rp);
7070 * Keep the number of memcpy ops to a minimum (e.g. 1).
7072 vec_validate (vector, 16384);
7073 vec_reset_length (vector);
7076 vector = vlib_node_serialize (&vm->node_main, vector,
7077 (u32) ~ 0 /* all threads */ ,
7078 1 /* include nexts */ ,
7079 1 /* include stats */ );
7081 svm_pop_heap (oldheap);
7082 pthread_mutex_unlock (&am->vlib_rp->mutex);
7085 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
7087 rmp->reply_in_shmem = (uword) vector;
7093 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
7096 vl_api_ioam_enable_reply_t *rmp;
7097 clib_error_t *error;
7099 /* Ignoring the profile id as currently a single profile
7101 error = ip6_ioam_enable (mp->trace_enable, mp->pow_enable, mp->trace_ppc);
7104 clib_error_report (error);
7105 rv = clib_error_get_code (error);
7108 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
7112 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
7115 vl_api_ioam_disable_reply_t *rmp;
7116 clib_error_t *error;
7118 error = clear_ioam_rewrite_fn ();
7121 clib_error_report (error);
7122 rv = clib_error_get_code (error);
7125 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
7129 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7131 vlib_main_t *vm = vlib_get_main ();
7132 vl_api_af_packet_create_reply_t *rmp;
7134 u8 *host_if_name = NULL;
7137 host_if_name = format (0, "%s", mp->host_if_name);
7138 vec_add1 (host_if_name, 0);
7140 rv = af_packet_create_if (vm, host_if_name,
7141 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7144 vec_free (host_if_name);
7147 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7149 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7155 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7157 vlib_main_t *vm = vlib_get_main ();
7158 vl_api_af_packet_delete_reply_t *rmp;
7160 u8 *host_if_name = NULL;
7162 host_if_name = format (0, "%s", mp->host_if_name);
7163 vec_add1 (host_if_name, 0);
7165 rv = af_packet_delete_if (vm, host_if_name);
7167 vec_free (host_if_name);
7169 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7173 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7175 vlib_main_t *vm = vlib_get_main ();
7176 vl_api_policer_add_del_reply_t *rmp;
7179 sse2_qos_pol_cfg_params_st cfg;
7180 clib_error_t *error;
7183 name = format (0, "%s", mp->name);
7185 memset (&cfg, 0, sizeof (cfg));
7187 cfg.rnd_type = mp->round_type;
7188 cfg.rate_type = mp->rate_type;
7189 cfg.rb.kbps.cir_kbps = mp->cir;
7190 cfg.rb.kbps.eir_kbps = mp->eir;
7191 cfg.rb.kbps.cb_bytes = mp->cb;
7192 cfg.rb.kbps.eb_bytes = mp->eb;
7193 cfg.conform_action.action_type = mp->conform_action_type;
7194 cfg.conform_action.dscp = mp->conform_dscp;
7195 cfg.exceed_action.action_type = mp->exceed_action_type;
7196 cfg.exceed_action.dscp = mp->exceed_dscp;
7197 cfg.violate_action.action_type = mp->violate_action_type;
7198 cfg.violate_action.dscp = mp->violate_dscp;
7199 cfg.color_aware = mp->color_aware;
7201 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7204 rv = VNET_API_ERROR_UNSPECIFIED;
7207 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7209 if (rv == 0 && mp->is_add)
7210 rmp->policer_index = ntohl(policer_index);
7212 rmp->policer_index = ~0;
7218 send_policer_details (u8 * name,
7219 sse2_qos_pol_cfg_params_st * config,
7220 policer_read_response_type_st * templ,
7221 unix_shared_memory_queue_t * q, u32 context)
7223 vl_api_policer_details_t *mp;
7225 mp = vl_msg_api_alloc (sizeof (*mp));
7226 memset (mp, 0, sizeof (*mp));
7227 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7228 mp->context = context;
7229 mp->cir = htonl (config->rb.kbps.cir_kbps);
7230 mp->eir = htonl (config->rb.kbps.eir_kbps);
7231 mp->cb = htonl (config->rb.kbps.cb_bytes);
7232 mp->eb = htonl (config->rb.kbps.eb_bytes);
7233 mp->rate_type = config->rate_type;
7234 mp->round_type = config->rnd_type;
7235 mp->type = config->rfc;
7236 mp->conform_action_type = config->conform_action.action_type;
7237 mp->conform_dscp = config->conform_action.dscp;
7238 mp->exceed_action_type = config->exceed_action.action_type;
7239 mp->exceed_dscp = config->exceed_action.dscp;
7240 mp->violate_action_type = config->violate_action.action_type;
7241 mp->violate_dscp = config->violate_action.dscp;
7242 mp->single_rate = templ->single_rate ? 1 : 0;
7243 mp->color_aware = templ->color_aware ? 1 : 0;
7244 mp->scale = htonl (templ->scale);
7245 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7246 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7247 mp->current_limit = htonl (templ->current_limit);
7248 mp->current_bucket = htonl (templ->current_bucket);
7249 mp->extended_limit = htonl (templ->extended_limit);
7250 mp->extended_bucket = htonl (templ->extended_bucket);
7251 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7253 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7255 vl_msg_api_send_shmem (q, (u8 *) & mp);
7259 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7261 unix_shared_memory_queue_t *q;
7262 vnet_policer_main_t *pm = &vnet_policer_main;
7268 sse2_qos_pol_cfg_params_st *config;
7269 policer_read_response_type_st *templ;
7271 q = vl_api_client_index_to_input_queue (mp->client_index);
7275 if (mp->match_name_valid)
7277 match_name = format (0, "%s%c", mp->match_name, 0);
7280 if (mp->match_name_valid)
7282 p = hash_get_mem (pm->policer_config_by_name, match_name);
7286 config = pool_elt_at_index (pm->configs, pool_index);
7287 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7288 send_policer_details (match_name, config, templ, q, mp->context);
7294 hash_foreach_pair (hp, pm->policer_config_by_name,
7296 name = (u8 *) hp->key;
7297 pool_index = hp->value[0];
7298 config = pool_elt_at_index (pm->configs, pool_index);
7299 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7300 send_policer_details(name, config, templ, q, mp->context);
7307 vl_api_policer_classify_set_interface_t_handler
7308 (vl_api_policer_classify_set_interface_t * mp)
7310 vlib_main_t *vm = vlib_get_main ();
7311 vl_api_policer_classify_set_interface_reply_t *rmp;
7313 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7315 ip4_table_index = ntohl (mp->ip4_table_index);
7316 ip6_table_index = ntohl (mp->ip6_table_index);
7317 l2_table_index = ntohl (mp->l2_table_index);
7318 sw_if_index = ntohl (mp->sw_if_index);
7320 VALIDATE_SW_IF_INDEX (mp);
7322 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7323 ip6_table_index, l2_table_index,
7326 BAD_SW_IF_INDEX_LABEL;
7328 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7332 send_policer_classify_details (u32 sw_if_index,
7334 unix_shared_memory_queue_t * q, u32 context)
7336 vl_api_policer_classify_details_t *mp;
7338 mp = vl_msg_api_alloc (sizeof (*mp));
7339 memset (mp, 0, sizeof (*mp));
7340 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7341 mp->context = context;
7342 mp->sw_if_index = htonl (sw_if_index);
7343 mp->table_index = htonl (table_index);
7345 vl_msg_api_send_shmem (q, (u8 *) & mp);
7349 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7351 unix_shared_memory_queue_t *q;
7352 policer_classify_main_t *pcm = &policer_classify_main;
7356 q = vl_api_client_index_to_input_queue (mp->client_index);
7360 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7362 if (vec_len (vec_tbl))
7364 for (i = 0; i < vec_len (vec_tbl); i++)
7366 if (vec_elt (vec_tbl, i) == ~0)
7369 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7376 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7378 vlib_main_t *vm = vlib_get_main ();
7379 vl_api_netmap_create_reply_t *rmp;
7383 if_name = format (0, "%s", mp->netmap_if_name);
7384 vec_add1 (if_name, 0);
7387 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7388 mp->is_pipe, mp->is_master, 0);
7392 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7396 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7398 vlib_main_t *vm = vlib_get_main ();
7399 vl_api_netmap_delete_reply_t *rmp;
7403 if_name = format (0, "%s", mp->netmap_if_name);
7404 vec_add1 (if_name, 0);
7406 rv = netmap_delete_if (vm, if_name);
7410 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7414 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7417 clib_warning ("BUG");
7421 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7422 unix_shared_memory_queue_t * q,
7423 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7425 vl_api_mpls_gre_tunnel_details_t *mp;
7426 mpls_main_t *mm = &mpls_main;
7431 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7432 nlabels = vec_len (e->labels);
7434 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7435 memset (mp, 0, sizeof (*mp));
7436 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7437 mp->context = context;
7439 mp->tunnel_index = htonl (index);
7440 mp->tunnel_src = gt->tunnel_src.as_u32;
7441 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7442 mp->intfc_address = gt->intfc_address.as_u32;
7443 mp->mask_width = htonl (gt->mask_width);
7444 mp->inner_fib_index = htonl (gt->inner_fib_index);
7445 mp->outer_fib_index = htonl (gt->outer_fib_index);
7446 mp->encap_index = htonl (gt->encap_index);
7447 mp->hw_if_index = htonl (gt->hw_if_index);
7448 mp->l2_only = htonl (gt->l2_only);
7449 mp->nlabels = htonl (nlabels);
7451 for (i = 0; i < nlabels; i++)
7454 htonl (vnet_mpls_uc_get_label
7455 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7458 vl_msg_api_send_shmem (q, (u8 *) & mp);
7462 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7464 vpe_api_main_t *am = &vpe_api_main;
7465 unix_shared_memory_queue_t *q;
7466 mpls_main_t *mm = &mpls_main;
7467 mpls_gre_tunnel_t *gt;
7468 u32 index = ntohl (mp->tunnel_index);
7470 q = vl_api_client_index_to_input_queue (mp->client_index);
7476 if (!pool_is_free_index (mm->gre_tunnels, index))
7478 gt = pool_elt_at_index (mm->gre_tunnels, index);
7479 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7486 pool_foreach (gt, mm->gre_tunnels,
7488 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7496 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7499 clib_warning ("BUG");
7503 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7504 unix_shared_memory_queue_t * q,
7505 mpls_eth_tunnel_t * et, u32 index, u32 context)
7507 mpls_main_t *mm = &mpls_main;
7511 vl_api_mpls_eth_tunnel_details_t *mp;
7513 e = pool_elt_at_index (mm->encaps, et->encap_index);
7514 nlabels = vec_len (e->labels);
7516 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7517 memset (mp, 0, sizeof (*mp));
7518 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7519 mp->context = context;
7521 mp->tunnel_index = htonl (index);
7522 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7523 mp->intfc_address = et->intfc_address.as_u32;
7524 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7525 mp->inner_fib_index = htonl (et->inner_fib_index);
7526 mp->mask_width = htonl (et->mask_width);
7527 mp->encap_index = htonl (et->encap_index);
7528 mp->hw_if_index = htonl (et->hw_if_index);
7529 mp->l2_only = htonl (et->l2_only);
7530 mp->nlabels = htonl (nlabels);
7532 for (i = 0; i < nlabels; i++)
7535 htonl (vnet_mpls_uc_get_label
7536 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7539 vl_msg_api_send_shmem (q, (u8 *) & mp);
7543 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7545 vpe_api_main_t *am = &vpe_api_main;
7546 unix_shared_memory_queue_t *q;
7547 mpls_main_t *mm = &mpls_main;
7548 mpls_eth_tunnel_t *et;
7549 u32 index = ntohl (mp->tunnel_index);
7551 q = vl_api_client_index_to_input_queue (mp->client_index);
7557 if (!pool_is_free_index (mm->eth_tunnels, index))
7559 et = pool_elt_at_index (mm->eth_tunnels, index);
7560 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7567 pool_foreach (et, mm->eth_tunnels,
7569 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7577 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7579 clib_warning ("BUG");
7583 send_mpls_fib_encap_details (vpe_api_main_t * am,
7584 unix_shared_memory_queue_t * q,
7585 show_mpls_fib_t * s, u32 context)
7587 vl_api_mpls_fib_encap_details_t *mp;
7588 mpls_main_t *mm = &mpls_main;
7593 e = pool_elt_at_index (mm->encaps, s->entry_index);
7594 nlabels = vec_len (e->labels);
7596 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7597 memset (mp, 0, sizeof (*mp));
7598 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7599 mp->context = context;
7601 mp->fib_index = htonl (s->fib_index);
7602 mp->entry_index = htonl (s->entry_index);
7604 mp->s_bit = htonl (s->s_bit);
7606 mp->nlabels = htonl (nlabels);
7608 for (i = 0; i < nlabels; i++)
7611 htonl (vnet_mpls_uc_get_label
7612 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7615 vl_msg_api_send_shmem (q, (u8 *) & mp);
7619 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7621 vpe_api_main_t *am = &vpe_api_main;
7622 unix_shared_memory_queue_t *q;
7623 vlib_main_t *vm = &vlib_global_main;
7626 show_mpls_fib_t *records = 0;
7628 mpls_main_t *mm = &mpls_main;
7629 ip4_main_t *im = &ip4_main;
7632 q = vl_api_client_index_to_input_queue (mp->client_index);
7637 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7639 vec_add2 (records, s, 1);
7640 s->fib_index = (u32)(key>>32);
7641 s->dest = (u32)(key & 0xFFFFFFFF);
7642 s->entry_index = (u32) value;
7646 if (0 == vec_len (records))
7648 vlib_cli_output (vm, "MPLS encap table empty");
7652 /* sort output by dst address within fib */
7653 vec_sort_with_function (records, mpls_dest_cmp);
7654 vec_sort_with_function (records, mpls_fib_index_cmp);
7655 vlib_cli_output (vm, "MPLS encap table");
7656 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7657 vec_foreach (s, records)
7659 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7660 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7661 format_ip4_address, &s->dest, format_mpls_encap_index,
7662 mm, s->entry_index);
7663 send_mpls_fib_encap_details (am, q, s, mp->context);
7671 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7673 clib_warning ("BUG");
7677 send_mpls_fib_decap_details (vpe_api_main_t * am,
7678 unix_shared_memory_queue_t * q,
7679 show_mpls_fib_t * s,
7681 u32 tx_table_id, char *swif_tag, u32 context)
7683 vl_api_mpls_fib_decap_details_t *mp;
7685 mp = vl_msg_api_alloc (sizeof (*mp));
7686 memset (mp, 0, sizeof (*mp));
7687 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7688 mp->context = context;
7690 mp->fib_index = htonl (s->fib_index);
7691 mp->entry_index = htonl (s->entry_index);
7693 mp->s_bit = htonl (s->s_bit);
7694 mp->label = htonl (s->label);
7695 mp->rx_table_id = htonl (rx_table_id);
7696 mp->tx_table_id = htonl (tx_table_id);
7697 strncpy ((char *) mp->swif_tag,
7698 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7700 vl_msg_api_send_shmem (q, (u8 *) & mp);
7704 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7706 vpe_api_main_t *am = &vpe_api_main;
7707 unix_shared_memory_queue_t *q;
7708 vlib_main_t *vm = &vlib_global_main;
7711 show_mpls_fib_t *records = 0;
7713 mpls_main_t *mm = &mpls_main;
7714 ip4_main_t *im = &ip4_main;
7720 q = vl_api_client_index_to_input_queue (mp->client_index);
7725 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7727 vec_add2 (records, s, 1);
7728 s->fib_index = (u32)(key>>32);
7729 s->entry_index = (u32) value;
7730 s->label = ((u32) key)>>12;
7731 s->s_bit = (key & (1<<8)) != 0;
7735 if (!vec_len (records))
7737 vlib_cli_output (vm, "MPLS decap table empty");
7741 vec_sort_with_function (records, mpls_label_cmp);
7742 vlib_cli_output (vm, "MPLS decap table");
7743 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7745 vec_foreach (s, records)
7748 d = pool_elt_at_index (mm->decaps, s->entry_index);
7749 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT)
7751 tx_fib = vec_elt_at_index (im->fibs, d->tx_fib_index);
7752 tx_table_id = tx_fib->table_id;
7757 tx_table_id = d->tx_fib_index;
7760 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7762 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7763 tx_table_id, swif_tag, s->label, s->s_bit);
7765 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7766 tx_table_id, swif_tag, mp->context);
7774 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7776 unix_shared_memory_queue_t *q;
7778 q = vl_api_client_index_to_input_queue (mp->client_index);
7782 vnet_classify_main_t *cm = &vnet_classify_main;
7783 vnet_classify_table_t *t;
7788 pool_foreach (t, cm->tables,
7790 vec_add1 (table_ids, ntohl(t - cm->tables));
7793 count = vec_len (table_ids);
7795 vl_api_classify_table_ids_reply_t *rmp;
7796 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7797 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7798 rmp->context = mp->context;
7799 rmp->count = ntohl (count);
7800 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7803 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7805 vec_free (table_ids);
7809 vl_api_classify_table_by_interface_t_handler
7810 (vl_api_classify_table_by_interface_t * mp)
7812 vl_api_classify_table_by_interface_reply_t *rmp;
7815 u32 sw_if_index = ntohl (mp->sw_if_index);
7818 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7821 VALIDATE_SW_IF_INDEX (mp);
7823 input_acl_main_t *am = &input_acl_main;
7828 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7830 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7831 if (vec_len (vec_tbl))
7833 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7835 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7839 acl[type] = vec_elt (vec_tbl, if_idx);
7844 BAD_SW_IF_INDEX_LABEL;
7847 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7849 rmp->sw_if_index = ntohl(sw_if_index);
7850 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7851 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7852 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7859 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7861 unix_shared_memory_queue_t *q;
7863 q = vl_api_client_index_to_input_queue (mp->client_index);
7867 vl_api_classify_table_info_reply_t *rmp = 0;
7869 vnet_classify_main_t *cm = &vnet_classify_main;
7870 u32 table_id = ntohl (mp->table_id);
7871 vnet_classify_table_t *t;
7874 pool_foreach (t, cm->tables,
7876 if (table_id == t - cm->tables)
7878 rmp = vl_msg_api_alloc_as_if_client
7879 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7880 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7881 rmp->context = mp->context;
7882 rmp->table_id = ntohl(table_id);
7883 rmp->nbuckets = ntohl(t->nbuckets);
7884 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7885 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7886 rmp->active_sessions = ntohl(t->active_elements);
7887 rmp->next_table_index = ntohl(t->next_table_index);
7888 rmp->miss_next_index = ntohl(t->miss_next_index);
7889 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7890 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7899 rmp = vl_msg_api_alloc (sizeof (*rmp));
7900 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7901 rmp->context = mp->context;
7902 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7905 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7909 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7912 clib_warning ("BUG");
7916 send_classify_session_details (unix_shared_memory_queue_t * q,
7919 vnet_classify_entry_t * e, u32 context)
7921 vl_api_classify_session_details_t *rmp;
7923 rmp = vl_msg_api_alloc (sizeof (*rmp));
7924 memset (rmp, 0, sizeof (*rmp));
7925 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7926 rmp->context = context;
7927 rmp->table_id = ntohl (table_id);
7928 rmp->hit_next_index = ntohl (e->next_index);
7929 rmp->advance = ntohl (e->advance);
7930 rmp->opaque_index = ntohl (e->opaque_index);
7931 rmp->match_length = ntohl (match_length);
7932 clib_memcpy (rmp->match, e->key, match_length);
7934 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7938 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7940 vnet_classify_main_t *cm = &vnet_classify_main;
7941 unix_shared_memory_queue_t *q;
7943 u32 table_id = ntohl (mp->table_id);
7944 vnet_classify_table_t *t;
7946 q = vl_api_client_index_to_input_queue (mp->client_index);
7951 pool_foreach (t, cm->tables,
7953 if (table_id == t - cm->tables)
7955 vnet_classify_bucket_t * b;
7956 vnet_classify_entry_t * v, * save_v;
7959 for (i = 0; i < t->nbuckets; i++)
7961 b = &t->buckets [i];
7965 save_v = vnet_classify_get_entry (t, b->offset);
7966 for (j = 0; j < (1<<b->log2_pages); j++)
7968 for (k = 0; k < t->entries_per_page; k++)
7970 v = vnet_classify_entry_at_index
7971 (t, save_v, j*t->entries_per_page + k);
7972 if (vnet_classify_entry_is_free (v))
7975 send_classify_session_details
7976 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7988 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7990 vlib_main_t *vm = vlib_get_main ();
7991 flow_report_main_t *frm = &flow_report_main;
7992 vl_api_set_ipfix_exporter_reply_t *rmp;
7993 ip4_address_t collector, src;
7994 u16 collector_port = UDP_DST_PORT_ipfix;
7996 u32 template_interval;
8002 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
8003 collector_port = ntohs (mp->collector_port);
8004 if (collector_port == (u16) ~ 0)
8005 collector_port = UDP_DST_PORT_ipfix;
8006 memcpy (src.data, mp->src_address, sizeof (src.data));
8007 fib_id = ntohl (mp->vrf_id);
8009 ip4_main_t *im = &ip4_main;
8016 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
8019 rv = VNET_API_ERROR_NO_SUCH_FIB;
8025 path_mtu = ntohl (mp->path_mtu);
8027 path_mtu = 512; // RFC 7011 section 10.3.3.
8028 template_interval = ntohl (mp->template_interval);
8029 if (template_interval == ~0)
8030 template_interval = 20;
8031 udp_checksum = mp->udp_checksum;
8033 if (collector.as_u32 == 0)
8035 rv = VNET_API_ERROR_INVALID_VALUE;
8039 if (src.as_u32 == 0)
8041 rv = VNET_API_ERROR_INVALID_VALUE;
8045 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
8047 rv = VNET_API_ERROR_INVALID_VALUE;
8053 rv = VNET_API_ERROR_INVALID_VALUE;
8057 /* Reset report streams if we are reconfiguring IP addresses */
8058 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
8059 frm->src_address.as_u32 != src.as_u32 ||
8060 frm->collector_port != collector_port)
8061 vnet_flow_reports_reset (frm);
8063 frm->ipfix_collector.as_u32 = collector.as_u32;
8064 frm->collector_port = collector_port;
8065 frm->src_address.as_u32 = src.as_u32;
8066 frm->fib_index = fib_index;
8067 frm->path_mtu = path_mtu;
8068 frm->template_interval = template_interval;
8069 frm->udp_checksum = udp_checksum;
8071 /* Turn on the flow reporting process */
8072 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
8075 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
8079 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
8081 flow_report_main_t *frm = &flow_report_main;
8082 unix_shared_memory_queue_t *q;
8083 vl_api_ipfix_exporter_details_t *rmp;
8084 ip4_main_t *im = &ip4_main;
8087 q = vl_api_client_index_to_input_queue (mp->client_index);
8091 rmp = vl_msg_api_alloc (sizeof (*rmp));
8092 memset (rmp, 0, sizeof (*rmp));
8093 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
8094 rmp->context = mp->context;
8095 memcpy (rmp->collector_address, frm->ipfix_collector.data,
8096 sizeof (frm->ipfix_collector.data));
8097 rmp->collector_port = htons (frm->collector_port);
8098 memcpy (rmp->src_address, frm->src_address.data,
8099 sizeof (frm->src_address.data));
8100 if (frm->fib_index == ~0)
8103 vrf_id = im->fibs[frm->fib_index].table_id;
8104 rmp->vrf_id = htonl (vrf_id);
8105 rmp->path_mtu = htonl (frm->path_mtu);
8106 rmp->template_interval = htonl (frm->template_interval);
8107 rmp->udp_checksum = (frm->udp_checksum != 0);
8109 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8113 vl_api_set_ipfix_classify_stream_t_handler
8114 (vl_api_set_ipfix_classify_stream_t * mp)
8116 vl_api_set_ipfix_classify_stream_reply_t *rmp;
8117 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8118 flow_report_main_t *frm = &flow_report_main;
8120 u32 src_port = UDP_DST_PORT_ipfix;
8123 domain_id = ntohl (mp->domain_id);
8124 src_port = ntohs (mp->src_port);
8126 if (fcm->src_port != 0 &&
8127 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
8129 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
8130 domain_id, (u16) src_port);
8134 fcm->domain_id = domain_id;
8135 fcm->src_port = (u16) src_port;
8137 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8141 vl_api_ipfix_classify_stream_dump_t_handler
8142 (vl_api_ipfix_classify_stream_dump_t * mp)
8144 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8145 unix_shared_memory_queue_t *q;
8146 vl_api_ipfix_classify_stream_details_t *rmp;
8148 q = vl_api_client_index_to_input_queue (mp->client_index);
8152 rmp = vl_msg_api_alloc (sizeof (*rmp));
8153 memset (rmp, 0, sizeof (*rmp));
8154 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
8155 rmp->context = mp->context;
8156 rmp->domain_id = htonl (fcm->domain_id);
8157 rmp->src_port = htons (fcm->src_port);
8159 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8163 vl_api_ipfix_classify_table_add_del_t_handler
8164 (vl_api_ipfix_classify_table_add_del_t * mp)
8166 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
8167 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8168 flow_report_main_t *frm = &flow_report_main;
8169 vnet_flow_report_add_del_args_t args;
8170 ipfix_classify_table_t *table;
8172 u32 classify_table_index;
8174 u8 transport_protocol;
8177 classify_table_index = ntohl (mp->table_id);
8178 ip_version = mp->ip_version;
8179 transport_protocol = mp->transport_protocol;
8180 is_add = mp->is_add;
8182 if (fcm->src_port == 0)
8184 /* call set_ipfix_classify_stream first */
8185 rv = VNET_API_ERROR_UNSPECIFIED;
8189 memset (&args, 0, sizeof (args));
8193 for (i = 0; i < vec_len (fcm->tables); i++)
8194 if (ipfix_classify_table_index_valid (i))
8195 if (fcm->tables[i].classify_table_index == classify_table_index)
8197 table = &fcm->tables[i];
8205 rv = VNET_API_ERROR_VALUE_EXIST;
8208 table = ipfix_classify_add_table ();
8209 table->classify_table_index = classify_table_index;
8215 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
8220 table->ip_version = ip_version;
8221 table->transport_protocol = transport_protocol;
8223 args.opaque.as_uword = table - fcm->tables;
8224 args.rewrite_callback = ipfix_classify_template_rewrite;
8225 args.flow_data_callback = ipfix_classify_send_flows;
8226 args.is_add = is_add;
8227 args.domain_id = fcm->domain_id;
8228 args.src_port = fcm->src_port;
8230 rv = vnet_flow_report_add_del (frm, &args);
8232 /* If deleting, or add failed */
8233 if (is_add == 0 || (rv && is_add))
8234 ipfix_classify_delete_table (table - fcm->tables);
8237 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8241 send_ipfix_classify_table_details (u32 table_index,
8242 unix_shared_memory_queue_t * q,
8245 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8246 vl_api_ipfix_classify_table_details_t *mp;
8248 ipfix_classify_table_t *table = &fcm->tables[table_index];
8250 mp = vl_msg_api_alloc (sizeof (*mp));
8251 memset (mp, 0, sizeof (*mp));
8252 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
8253 mp->context = context;
8254 mp->table_id = htonl (table->classify_table_index);
8255 mp->ip_version = table->ip_version;
8256 mp->transport_protocol = table->transport_protocol;
8258 vl_msg_api_send_shmem (q, (u8 *) & mp);
8262 vl_api_ipfix_classify_table_dump_t_handler
8263 (vl_api_ipfix_classify_table_dump_t * mp)
8265 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8266 unix_shared_memory_queue_t *q;
8269 q = vl_api_client_index_to_input_queue (mp->client_index);
8273 for (i = 0; i < vec_len (fcm->tables); i++)
8274 if (ipfix_classify_table_index_valid (i))
8275 send_ipfix_classify_table_details (i, q, mp->context);
8279 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8281 vl_api_pg_create_interface_reply_t *rmp;
8284 pg_main_t *pg = &pg_main;
8285 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8288 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8290 rmp->sw_if_index = ntohl(sw_if_index);
8296 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8298 vl_api_pg_capture_reply_t *rmp;
8301 vnet_main_t *vnm = vnet_get_main ();
8302 vnet_interface_main_t *im = &vnm->interface_main;
8303 vnet_hw_interface_t *hi = 0;
8305 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8306 u32 hw_if_index = ~0;
8307 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8310 vec_free (intf_name);
8312 if (hw_if_index != ~0)
8314 pg_capture_args_t _a, *a = &_a;
8316 u32 len = ntohl (mp->pcap_name_length);
8317 u8 *pcap_file_name = vec_new (u8, len);
8318 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8320 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8321 a->hw_if_index = hw_if_index;
8322 a->dev_instance = hi->dev_instance;
8323 a->is_enabled = mp->is_enabled;
8324 a->pcap_file_name = pcap_file_name;
8325 a->count = ntohl (mp->count);
8327 clib_error_t *e = pg_capture (a);
8330 clib_error_report (e);
8331 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8334 vec_free (pcap_file_name);
8336 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8340 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8342 vl_api_pg_enable_disable_reply_t *rmp;
8345 pg_main_t *pg = &pg_main;
8346 u32 stream_index = ~0;
8348 int is_enable = mp->is_enabled != 0;
8349 u32 len = ntohl (mp->stream_name_length) - 1;
8353 u8 *stream_name = vec_new (u8, len);
8354 clib_memcpy (stream_name, mp->stream_name, len);
8355 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8358 vec_free (stream_name);
8361 pg_enable_disable (stream_index, is_enable);
8363 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8367 vl_api_ip_source_and_port_range_check_add_del_t_handler
8368 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8370 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8373 u8 is_ipv6 = mp->is_ipv6;
8374 u8 is_add = mp->is_add;
8375 u8 mask_length = mp->mask_length;
8376 ip4_address_t ip4_addr;
8377 ip6_address_t ip6_addr;
8379 u16 *high_ports = 0;
8381 u16 tmp_low, tmp_high;
8385 // Validate port range
8386 num_ranges = mp->number_of_ranges;
8387 if (num_ranges > 32)
8388 { // This is size of array in VPE.API
8389 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8393 vec_reset_length (low_ports);
8394 vec_reset_length (high_ports);
8396 for (i = 0; i < num_ranges; i++)
8398 tmp_low = mp->low_ports[i];
8399 tmp_high = mp->high_ports[i];
8400 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8401 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8402 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8404 rv = VNET_API_ERROR_INVALID_VALUE;
8407 vec_add1 (low_ports, tmp_low);
8408 vec_add1 (high_ports, tmp_high + 1);
8411 // Validate mask_length
8412 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8414 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8418 vrf_id = ntohl (mp->vrf_id);
8422 rv = VNET_API_ERROR_INVALID_VALUE;
8429 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8430 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8434 high_ports, is_add);
8438 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8439 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8443 high_ports, is_add);
8447 vec_free (low_ports);
8448 vec_free (high_ports);
8449 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8453 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8454 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8456 vlib_main_t *vm = vlib_get_main ();
8457 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8458 ip4_main_t *im = &ip4_main;
8461 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8462 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8466 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8467 ntohl (mp->tcp_out_vrf_id);
8468 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8469 ntohl (mp->udp_out_vrf_id);
8470 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8471 ntohl (mp->tcp_in_vrf_id);
8472 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8473 ntohl (mp->udp_in_vrf_id);
8476 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8478 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8480 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8484 rv = VNET_API_ERROR_INVALID_VALUE;
8488 fib_index[i] = p[0];
8493 sw_if_index = ntohl (mp->sw_if_index);
8495 VALIDATE_SW_IF_INDEX (mp);
8498 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8501 BAD_SW_IF_INDEX_LABEL;
8504 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8508 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8511 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8513 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8514 u32 sw_if_index = ~0;
8516 /* Check src & dst are different */
8517 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8519 rv = VNET_API_ERROR_SAME_SRC_DST;
8523 memset (a, 0, sizeof (*a));
8525 /* ip addresses sent in network byte order */
8526 clib_memcpy (&(a->src), mp->src_address, 4);
8527 clib_memcpy (&(a->dst), mp->dst_address, 4);
8528 a->is_add = mp->is_add;
8529 a->lsa = ntohl (mp->local_sa_id);
8530 a->rsa = ntohl (mp->remote_sa_id);
8532 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8536 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8538 rmp->sw_if_index = ntohl (sw_if_index);
8543 static void send_ipsec_gre_tunnel_details
8544 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8546 vl_api_ipsec_gre_tunnel_details_t *rmp;
8548 rmp = vl_msg_api_alloc (sizeof (*rmp));
8549 memset (rmp, 0, sizeof (*rmp));
8550 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8551 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8552 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8553 rmp->sw_if_index = htonl (t->sw_if_index);
8554 rmp->local_sa_id = htonl (t->local_sa_id);
8555 rmp->remote_sa_id = htonl (t->remote_sa_id);
8556 rmp->context = context;
8558 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8561 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8562 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8564 unix_shared_memory_queue_t *q;
8565 ipsec_gre_main_t *igm = &ipsec_gre_main;
8566 ipsec_gre_tunnel_t *t;
8569 q = vl_api_client_index_to_input_queue (mp->client_index);
8575 sw_if_index = ntohl (mp->sw_if_index);
8577 if (~0 == sw_if_index)
8580 pool_foreach (t, igm->tunnels,
8582 send_ipsec_gre_tunnel_details(t, q, mp->context);
8588 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8589 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8593 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8594 send_ipsec_gre_tunnel_details (t, q, mp->context);
8599 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8601 vl_api_delete_subif_reply_t *rmp;
8604 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8606 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8609 #define BOUNCE_HANDLER(nn) \
8610 static void vl_api_##nn##_t_handler ( \
8611 vl_api_##nn##_t *mp) \
8613 vpe_client_registration_t *reg; \
8614 vpe_api_main_t * vam = &vpe_api_main; \
8615 unix_shared_memory_queue_t * q; \
8617 /* One registration only... */ \
8618 pool_foreach(reg, vam->nn##_registrations, \
8620 q = vl_api_client_index_to_input_queue (reg->client_index); \
8623 * If the queue is stuffed, turf the msg and complain \
8624 * It's unlikely that the intended recipient is \
8625 * alive; avoid deadlock at all costs. \
8627 if (q->cursize == q->maxsize) { \
8628 clib_warning ("ERROR: receiver queue full, drop msg"); \
8629 vl_msg_api_free (mp); \
8632 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8636 vl_msg_api_free (mp); \
8641 * Add vpe's API message handlers to the table.
8642 * vlib has alread mapped shared memory and
8643 * added the client registration handlers.
8644 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8647 static clib_error_t *
8648 vpe_api_hookup (vlib_main_t * vm)
8650 api_main_t *am = &api_main;
8653 vl_msg_api_set_handlers(VL_API_##N, #n, \
8654 vl_api_##n##_t_handler, \
8656 vl_api_##n##_t_endian, \
8657 vl_api_##n##_t_print, \
8658 sizeof(vl_api_##n##_t), 1);
8659 foreach_vpe_api_msg;
8663 * Manually register the sr tunnel add del msg, so we trace
8664 * enough bytes to capture a typical segment list
8666 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8667 "sr_tunnel_add_del",
8668 vl_api_sr_tunnel_add_del_t_handler,
8670 vl_api_sr_tunnel_add_del_t_endian,
8671 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8675 * Manually register the sr policy add del msg, so we trace
8676 * enough bytes to capture a typical tunnel name list
8678 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8679 "sr_policy_add_del",
8680 vl_api_sr_policy_add_del_t_handler,
8682 vl_api_sr_policy_add_del_t_endian,
8683 vl_api_sr_policy_add_del_t_print, 256, 1);
8686 * Trace space for 8 MPLS encap labels, classifier mask+match
8688 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8689 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8690 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8691 += 5 * sizeof (u32x4);
8692 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8695 * Thread-safe API messages
8697 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8698 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8703 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8705 static clib_error_t *
8706 vpe_api_init (vlib_main_t * vm)
8708 vpe_api_main_t *am = &vpe_api_main;
8711 am->vnet_main = vnet_get_main ();
8712 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8713 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8714 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8715 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8716 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8717 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8720 vl_set_memory_region_name ("/vpe-api");
8721 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8726 VLIB_INIT_FUNCTION (vpe_api_init);
8729 static clib_error_t *
8730 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8733 u64 baseva, size, pvt_heap_size;
8735 const int max_buf_size = 4096;
8737 struct passwd _pw, *pw;
8738 struct group _grp, *grp;
8740 buf = vec_new (char, 128);
8741 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8743 if (unformat (input, "prefix %s", &chroot_path))
8745 vec_add1 (chroot_path, 0);
8746 vl_set_memory_root_path ((char *) chroot_path);
8748 else if (unformat (input, "uid %d", &uid))
8749 vl_set_memory_uid (uid);
8750 else if (unformat (input, "gid %d", &gid))
8751 vl_set_memory_gid (gid);
8752 else if (unformat (input, "baseva %llx", &baseva))
8753 vl_set_global_memory_baseva (baseva);
8754 else if (unformat (input, "global-size %lldM", &size))
8755 vl_set_global_memory_size (size * (1ULL << 20));
8756 else if (unformat (input, "global-size %lldG", &size))
8757 vl_set_global_memory_size (size * (1ULL << 30));
8758 else if (unformat (input, "global-size %lld", &size))
8759 vl_set_global_memory_size (size);
8760 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8761 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8762 else if (unformat (input, "global-pvt-heap-size size %lld",
8764 vl_set_global_pvt_heap_size (pvt_heap_size);
8765 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8766 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8767 else if (unformat (input, "api-pvt-heap-size size %lld",
8769 vl_set_api_pvt_heap_size (pvt_heap_size);
8770 else if (unformat (input, "api-size %lldM", &size))
8771 vl_set_api_memory_size (size * (1ULL << 20));
8772 else if (unformat (input, "api-size %lldG", &size))
8773 vl_set_api_memory_size (size * (1ULL << 30));
8774 else if (unformat (input, "api-size %lld", &size))
8775 vl_set_api_memory_size (size);
8776 else if (unformat (input, "uid %s", &s))
8778 /* lookup the username */
8781 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8782 && (vec_len (buf) <= max_buf_size))
8784 vec_resize (buf, vec_len (buf) * 2);
8788 e = clib_error_return_code (0, rv,
8789 CLIB_ERROR_ERRNO_VALID |
8791 "cannot fetch username %s", s);
8799 clib_error_return_fatal (0, "username %s does not exist", s);
8805 vl_set_memory_uid (pw->pw_uid);
8807 else if (unformat (input, "gid %s", &s))
8809 /* lookup the group name */
8812 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8813 && (vec_len (buf) <= max_buf_size))
8815 vec_resize (buf, vec_len (buf) * 2);
8819 e = clib_error_return_code (0, rv,
8820 CLIB_ERROR_ERRNO_VALID |
8822 "cannot fetch group %s", s);
8829 e = clib_error_return_fatal (0, "group %s does not exist", s);
8836 vl_set_memory_gid (grp->gr_gid);
8839 return clib_error_return (0, "unknown input `%U'",
8840 format_unformat_error, input);
8845 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8848 get_unformat_vnet_sw_interface (void)
8850 return (void *) &unformat_vnet_sw_interface;
8853 #undef vl_api_version
8854 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8855 #include <vpp-api/vpe.api.h>
8856 #undef vl_api_version
8859 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8861 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8863 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8864 clib_host_to_net_u32 (mp->api_versions[0]),
8872 format_arp_event (u8 * s, va_list * args)
8874 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8876 s = format (s, "pid %d: ", event->pid);
8878 s = format (s, "bd mac/ip4 binding events");
8880 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8885 format_nd_event (u8 * s, va_list * args)
8887 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8889 s = format (s, "pid %d: ", event->pid);
8891 s = format (s, "bd mac/ip6 binding events");
8893 s = format (s, "resolution for %U", format_ip6_address, event->address);
8897 static clib_error_t *
8898 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8899 unformat_input_t * input, vlib_cli_command_t * cmd)
8901 vpe_api_main_t *am = &vpe_api_main;
8902 vl_api_ip4_arp_event_t *arp_event;
8903 vl_api_ip6_nd_event_t *nd_event;
8905 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8907 vlib_cli_output (vm, "No active arp or nd event registrations");
8912 pool_foreach (arp_event, am->arp_events,
8914 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8917 pool_foreach (nd_event, am->nd_events,
8919 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8927 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8928 .path = "show arp-nd-event registrations",
8929 .function = show_ip_arp_nd_events_fn,
8930 .short_help = "Show ip4 arp and ip6 nd event registrations",
8935 * fd.io coding-style-patch-verification: ON
8938 * eval: (c-set-style "gnu")