2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010-2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
48 #include <vnet/api_errno.h>
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/l2tp/l2tp.h>
53 #include <vnet/ip/ip.h>
54 #include <vnet/ip/ip6.h>
55 #include <vnet/unix/tuntap.h>
56 #include <vnet/unix/tapcli.h>
57 #include <vnet/mpls/mpls.h>
58 #include <vnet/dhcp/proxy.h>
59 #include <vnet/dhcp/client.h>
61 #include <vnet/sr/sr.h>
63 #include <vnet/dhcpv6/proxy.h>
64 #include <vlib/vlib.h>
65 #include <vlib/unix/unix.h>
66 #include <vlibapi/api.h>
67 #include <vlibmemory/api.h>
68 #include <vnet/classify/vnet_classify.h>
69 #include <vnet/classify/input_acl.h>
70 #include <vnet/classify/policer_classify.h>
71 #include <vnet/classify/flow_classify.h>
72 #include <vnet/l2/l2_classify.h>
73 #include <vnet/vxlan/vxlan.h>
74 #include <vnet/gre/gre.h>
75 #include <vnet/l2/l2_vtr.h>
76 #include <vnet/vxlan-gpe/vxlan_gpe.h>
77 #include <vnet/lisp-gpe/lisp_gpe.h>
78 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
79 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
80 #include <vnet/lisp-cp/control.h>
81 #include <vnet/map/map.h>
82 #include <vnet/cop/cop.h>
83 #include <vnet/ip/ip6_hop_by_hop.h>
84 #include <vnet/ip/ip_source_and_port_range_check.h>
85 #include <vnet/devices/af_packet/af_packet.h>
86 #include <vnet/policer/policer.h>
87 #include <vnet/devices/netmap/netmap.h>
88 #include <vnet/flow/flow_report.h>
89 #include <vnet/ipsec-gre/ipsec_gre.h>
90 #include <vnet/flow/flow_report_classify.h>
91 #include <vnet/ip/punt.h>
94 #undef __included_bihash_template_h__
95 #include <vnet/l2/l2_fib.h>
98 #include <vnet/ipsec/ipsec.h>
99 #include <vnet/ipsec/ikev2.h>
101 #include <vnet/devices/virtio/vhost-user.h>
103 #include <stats/stats.h>
106 #include <vnet/ethernet/ethernet.h>
107 #include <vnet/ethernet/arp_packet.h>
108 #include <vnet/interface.h>
110 #include <vnet/l2/l2_fib.h>
111 #include <vnet/l2/l2_bd.h>
112 #include <vpp-api/vpe_msg_enum.h>
114 #include <vnet/fib/ip6_fib.h>
115 #include <vnet/fib/ip4_fib.h>
116 #include <vnet/dpo/drop_dpo.h>
117 #include <vnet/dpo/receive_dpo.h>
118 #include <vnet/dpo/lookup_dpo.h>
119 #include <vnet/dpo/classify_dpo.h>
120 #include <vnet/dpo/ip_null_dpo.h>
122 #define f64_endian(a)
123 #define f64_print(a,b)
125 #define vl_typedefs /* define message structures */
126 #include <vpp-api/vpe_all_api_h.h>
129 #define vl_endianfun /* define message structures */
130 #include <vpp-api/vpe_all_api_h.h>
133 /* instantiate all the print functions we know about */
134 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
136 #include <vpp-api/vpe_all_api_h.h>
139 #define REPLY_MACRO(t) \
141 unix_shared_memory_queue_t * q; \
142 rv = vl_msg_api_pd_handler (mp, rv); \
143 q = vl_api_client_index_to_input_queue (mp->client_index); \
147 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
148 rmp->_vl_msg_id = ntohs((t)); \
149 rmp->context = mp->context; \
150 rmp->retval = ntohl(rv); \
152 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
155 #define REPLY_MACRO2(t, body) \
157 unix_shared_memory_queue_t * q; \
158 rv = vl_msg_api_pd_handler (mp, rv); \
159 q = vl_api_client_index_to_input_queue (mp->client_index); \
163 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
164 rmp->_vl_msg_id = ntohs((t)); \
165 rmp->context = mp->context; \
166 rmp->retval = ntohl(rv); \
167 do {body;} while (0); \
168 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
171 #define REPLY_MACRO3(t, n, body) \
173 unix_shared_memory_queue_t * q; \
174 rv = vl_msg_api_pd_handler (mp, rv); \
175 q = vl_api_client_index_to_input_queue (mp->client_index); \
179 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
180 rmp->_vl_msg_id = ntohs((t)); \
181 rmp->context = mp->context; \
182 rmp->retval = ntohl(rv); \
183 do {body;} while (0); \
184 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
187 #define REPLY_MACRO4(t, n, body) \
189 unix_shared_memory_queue_t * q; \
191 rv = vl_msg_api_pd_handler (mp, rv); \
192 q = vl_api_client_index_to_input_queue (mp->client_index); \
196 rmp = vl_msg_api_alloc_or_null (sizeof (*rmp) + n); \
199 /* if there isn't enough memory, try to allocate */ \
200 /* some at least for returning an error */ \
201 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
205 memset (rmp, 0, sizeof (*rmp)); \
206 rv = VNET_API_ERROR_TABLE_TOO_BIG; \
209 rmp->_vl_msg_id = ntohs((t)); \
210 rmp->context = mp->context; \
211 rmp->retval = ntohl(rv); \
213 do {body;} while (0); \
214 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
217 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
219 #define VALIDATE_SW_IF_INDEX(mp) \
220 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
221 vnet_main_t *__vnm = vnet_get_main(); \
222 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
224 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
225 goto bad_sw_if_index; \
229 #define BAD_SW_IF_INDEX_LABEL \
235 #define VALIDATE_RX_SW_IF_INDEX(mp) \
236 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
237 vnet_main_t *__vnm = vnet_get_main(); \
238 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
239 __rx_sw_if_index)) { \
240 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
241 goto bad_rx_sw_if_index; \
245 #define BAD_RX_SW_IF_INDEX_LABEL \
247 bad_rx_sw_if_index: \
251 #define VALIDATE_TX_SW_IF_INDEX(mp) \
252 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
253 vnet_main_t *__vnm = vnet_get_main(); \
254 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
255 __tx_sw_if_index)) { \
256 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
257 goto bad_tx_sw_if_index; \
261 #define BAD_TX_SW_IF_INDEX_LABEL \
263 bad_tx_sw_if_index: \
269 #define VALIDATE_SW_IF_INDEX(mp)
270 #define BAD_SW_IF_INDEX_LABEL
271 #define VALIDATE_RX_SW_IF_INDEX(mp)
272 #define BAD_RX_SW_IF_INDEX_LABEL
273 #define VALIDATE_TX_SW_IF_INDEX(mp)
274 #define BAD_TX_SW_IF_INDEX_LABEL
276 #endif /* CLIB_DEBUG > 0 */
278 #define foreach_vpe_api_msg \
279 _(WANT_INTERFACE_EVENTS, want_interface_events) \
280 _(WANT_OAM_EVENTS, want_oam_events) \
281 _(OAM_ADD_DEL, oam_add_del) \
282 _(SW_INTERFACE_DUMP, sw_interface_dump) \
283 _(SW_INTERFACE_DETAILS, sw_interface_details) \
284 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
285 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
286 _(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \
287 _(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \
288 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
289 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
290 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
291 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
292 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
293 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
294 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
295 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
296 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
297 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
298 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
299 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
300 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
301 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
302 _(L2FIB_ADD_DEL, l2fib_add_del) \
303 _(L2_FLAGS, l2_flags) \
304 _(BRIDGE_FLAGS, bridge_flags) \
305 _(TAP_CONNECT, tap_connect) \
306 _(TAP_MODIFY, tap_modify) \
307 _(TAP_DELETE, tap_delete) \
308 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
309 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
310 _(CREATE_SUBIF, create_subif) \
311 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
312 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
313 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
314 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
315 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
316 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
317 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
318 _(RESET_FIB, reset_fib) \
319 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
320 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
321 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
322 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
323 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
324 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
325 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
326 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
327 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
328 sw_interface_ip6_set_link_local_address) \
329 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
330 _(CREATE_LOOPBACK, create_loopback) \
331 _(CONTROL_PING, control_ping) \
332 _(CLI_REQUEST, cli_request) \
333 _(CLI_INBAND, cli_inband) \
334 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
335 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
336 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
337 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
338 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
339 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
340 _(GET_NODE_INDEX, get_node_index) \
341 _(ADD_NODE_NEXT, add_node_next) \
342 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
343 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
344 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
345 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
346 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
347 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
348 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
349 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
350 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
351 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
352 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
353 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
354 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
355 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
356 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
357 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
358 _(IP_ADDRESS_DUMP, ip_address_dump) \
359 _(IP_DUMP, ip_dump) \
360 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
361 _(SHOW_VERSION, show_version) \
362 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
363 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
364 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
365 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
366 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
367 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
368 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
369 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
370 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
371 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
372 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
373 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
374 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
375 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
376 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
377 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
378 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
379 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
380 _(DELETE_LOOPBACK, delete_loopback) \
381 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
382 _(MAP_ADD_DOMAIN, map_add_domain) \
383 _(MAP_DEL_DOMAIN, map_del_domain) \
384 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
385 _(MAP_DOMAIN_DUMP, map_domain_dump) \
386 _(MAP_RULE_DUMP, map_rule_dump) \
387 _(MAP_SUMMARY_STATS, map_summary_stats) \
388 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
389 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
390 _(GET_NODE_GRAPH, get_node_graph) \
391 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
392 _(IOAM_ENABLE, ioam_enable) \
393 _(IOAM_DISABLE, ioam_disable) \
394 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
395 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
396 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
397 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
398 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
399 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
400 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
401 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
402 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
403 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
404 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
405 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
406 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
407 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
408 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
409 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
410 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
411 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
412 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
413 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
414 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
415 _(SHOW_LISP_STATUS, show_lisp_status) \
416 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
417 lisp_add_del_map_request_itr_rlocs) \
418 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
419 _(SHOW_LISP_PITR, show_lisp_pitr) \
420 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
421 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
422 _(AF_PACKET_CREATE, af_packet_create) \
423 _(AF_PACKET_DELETE, af_packet_delete) \
424 _(POLICER_ADD_DEL, policer_add_del) \
425 _(POLICER_DUMP, policer_dump) \
426 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
427 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
428 _(NETMAP_CREATE, netmap_create) \
429 _(NETMAP_DELETE, netmap_delete) \
430 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
431 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
432 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
433 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
434 _(MPLS_FIB_DUMP, mpls_fib_dump) \
435 _(MPLS_FIB_DETAILS, mpls_fib_details) \
436 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
437 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
438 _(CLASSIFY_TABLE_INFO,classify_table_info) \
439 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
440 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
441 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
442 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
443 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
444 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
445 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
446 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
447 _(GET_NEXT_INDEX, get_next_index) \
448 _(PG_CREATE_INTERFACE, pg_create_interface) \
449 _(PG_CAPTURE, pg_capture) \
450 _(PG_ENABLE_DISABLE, pg_enable_disable) \
451 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
452 ip_source_and_port_range_check_add_del) \
453 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
454 ip_source_and_port_range_check_interface_add_del) \
455 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
456 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
457 _(DELETE_SUBIF, delete_subif) \
458 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
460 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
461 _(FLOW_CLASSIFY_DUMP, flow_classify_dump)
464 #define QUOTE(x) QUOTE_(x)
466 #define foreach_registration_hash \
467 _(interface_events) \
468 _(to_netconf_server) \
469 _(from_netconf_server) \
470 _(to_netconf_client) \
471 _(from_netconf_client) \
476 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
477 RESOLVE_IP6_ADD_DEL_ROUTE,
478 RESOLVE_MPLS_ETHERNET_ADD_DEL,
486 vl_api_ip_add_del_route_t r;
487 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
494 #define _(a) uword *a##_registration_hash; \
495 vpe_client_registration_t * a##_registrations;
496 foreach_registration_hash
498 /* notifications happen really early in the game */
499 u8 link_state_process_up;
501 /* ip4 and ip6 pending route adds */
502 pending_route_t *pending_routes;
504 /* ip4 arp event registration pool */
505 vl_api_ip4_arp_event_t *arp_events;
507 /* ip6 nd event registration pool */
508 vl_api_ip6_nd_event_t *nd_events;
511 vlib_main_t *vlib_main;
512 vnet_main_t *vnet_main;
515 static vlib_node_registration_t vpe_resolver_process_node;
516 static vpe_api_main_t vpe_api_main;
518 static void send_sw_interface_flags (vpe_api_main_t * am,
519 unix_shared_memory_queue_t * q,
520 vnet_sw_interface_t * swif);
521 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
522 unix_shared_memory_queue_t * q,
525 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
526 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
529 /* Clean up all registrations belonging to the indicated client */
531 vl_api_memclnt_delete_callback (u32 client_index)
533 vpe_api_main_t *vam = &vpe_api_main;
534 vpe_client_registration_t *rp;
536 int stats_memclnt_delete_callback (u32 client_index);
538 stats_memclnt_delete_callback (client_index);
541 p = hash_get (vam->a##_registration_hash, client_index); \
543 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
544 pool_put (vam->a##_registrations, rp); \
545 hash_unset (vam->a##_registration_hash, client_index); \
547 foreach_registration_hash;
552 #define API_LINK_STATE_EVENT 1
553 #define API_ADMIN_UP_DOWN_EVENT 2
556 event_data_cmp (void *a1, void *a2)
561 return (word) e1[0] - (word) e2[0];
565 link_state_process (vlib_main_t * vm,
566 vlib_node_runtime_t * rt, vlib_frame_t * f)
568 vpe_api_main_t *vam = &vpe_api_main;
569 vnet_main_t *vnm = vam->vnet_main;
570 vnet_sw_interface_t *swif;
571 uword *event_data = 0;
572 vpe_client_registration_t *reg;
574 u32 prev_sw_if_index;
575 unix_shared_memory_queue_t *q;
577 vam->link_state_process_up = 1;
581 vlib_process_wait_for_event (vm);
583 /* Unified list of changed link or admin state sw_if_indices */
584 vlib_process_get_events_with_type
585 (vm, &event_data, API_LINK_STATE_EVENT);
586 vlib_process_get_events_with_type
587 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
589 /* Sort, so we can eliminate duplicates */
590 vec_sort_with_function (event_data, event_data_cmp);
592 prev_sw_if_index = ~0;
594 for (i = 0; i < vec_len (event_data); i++)
596 /* Only one message per swif */
597 if (prev_sw_if_index == event_data[i])
599 prev_sw_if_index = event_data[i];
602 pool_foreach(reg, vam->interface_events_registrations,
604 q = vl_api_client_index_to_input_queue (reg->client_index);
607 /* sw_interface may be deleted already */
608 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
611 swif = vnet_get_sw_interface (vnm, event_data[i]);
612 send_sw_interface_flags (vam, q, swif);
618 vec_reset_length (event_data);
624 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
626 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
627 u32 hw_if_index, u32 flags);
630 VLIB_REGISTER_NODE (link_state_process_node,static) = {
631 .function = link_state_process,
632 .type = VLIB_NODE_TYPE_PROCESS,
633 .name = "vpe-link-state-process",
637 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
638 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
640 static clib_error_t *
641 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
643 vpe_api_main_t *vam = &vpe_api_main;
644 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
646 if (vam->link_state_process_up)
647 vlib_process_signal_event (vam->vlib_main,
648 link_state_process_node.index,
649 API_LINK_STATE_EVENT, hi->sw_if_index);
653 static clib_error_t *
654 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
656 vpe_api_main_t *vam = &vpe_api_main;
659 * Note: it's perfectly fair to set a subif admin up / admin down.
660 * Note the subtle distinction between this routine and the previous
663 if (vam->link_state_process_up)
664 vlib_process_signal_event (vam->vlib_main,
665 link_state_process_node.index,
666 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
670 #define pub_sub_handler(lca,UCA) \
671 static void vl_api_want_##lca##_t_handler ( \
672 vl_api_want_##lca##_t *mp) \
674 vpe_api_main_t *vam = &vpe_api_main; \
675 vpe_client_registration_t *rp; \
676 vl_api_want_##lca##_reply_t *rmp; \
680 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
682 if (mp->enable_disable) { \
683 clib_warning ("pid %d: already enabled...", mp->pid); \
684 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
687 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
688 pool_put (vam->lca##_registrations, rp); \
689 hash_unset (vam->lca##_registration_hash, \
694 if (mp->enable_disable == 0) { \
695 clib_warning ("pid %d: already disabled...", mp->pid); \
696 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
699 pool_get (vam->lca##_registrations, rp); \
700 rp->client_index = mp->client_index; \
701 rp->client_pid = mp->pid; \
702 hash_set (vam->lca##_registration_hash, rp->client_index, \
703 rp - vam->lca##_registrations); \
706 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
710 pub_sub_handler (interface_events, INTERFACE_EVENTS)
711 pub_sub_handler (oam_events, OAM_EVENTS)
714 #define RESOLUTION_EVENT 1
715 #define RESOLUTION_PENDING_EVENT 2
716 #define IP4_ARP_EVENT 3
717 #define IP6_ND_EVENT 4
719 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
721 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
723 static int mpls_ethernet_add_del_tunnel_2_t_handler
724 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
727 handle_ip4_arp_event (u32 pool_index)
729 vpe_api_main_t *vam = &vpe_api_main;
730 vnet_main_t *vnm = vam->vnet_main;
731 vlib_main_t *vm = vam->vlib_main;
732 vl_api_ip4_arp_event_t *event;
733 vl_api_ip4_arp_event_t *mp;
734 unix_shared_memory_queue_t *q;
736 /* Client can cancel, die, etc. */
737 if (pool_is_free_index (vam->arp_events, pool_index))
740 event = pool_elt_at_index (vam->arp_events, pool_index);
742 q = vl_api_client_index_to_input_queue (event->client_index);
745 (void) vnet_add_del_ip4_arp_change_event
746 (vnm, arp_change_delete_callback,
747 event->pid, &event->address,
748 vpe_resolver_process_node.index, IP4_ARP_EVENT,
749 ~0 /* pool index, notused */ , 0 /* is_add */ );
753 if (q->cursize < q->maxsize)
755 mp = vl_msg_api_alloc (sizeof (*mp));
756 clib_memcpy (mp, event, sizeof (*mp));
757 vl_msg_api_send_shmem (q, (u8 *) & mp);
761 static f64 last_time;
763 * Throttle syslog msgs.
764 * It's pretty tempting to just revoke the registration...
766 if (vlib_time_now (vm) > last_time + 10.0)
768 clib_warning ("arp event for %U to pid %d: queue stuffed!",
769 format_ip4_address, &event->address, event->pid);
770 last_time = vlib_time_now (vm);
776 handle_ip6_nd_event (u32 pool_index)
778 vpe_api_main_t *vam = &vpe_api_main;
779 vnet_main_t *vnm = vam->vnet_main;
780 vlib_main_t *vm = vam->vlib_main;
781 vl_api_ip6_nd_event_t *event;
782 vl_api_ip6_nd_event_t *mp;
783 unix_shared_memory_queue_t *q;
785 /* Client can cancel, die, etc. */
786 if (pool_is_free_index (vam->nd_events, pool_index))
789 event = pool_elt_at_index (vam->nd_events, pool_index);
791 q = vl_api_client_index_to_input_queue (event->client_index);
794 (void) vnet_add_del_ip6_nd_change_event
795 (vnm, nd_change_delete_callback,
796 event->pid, &event->address,
797 vpe_resolver_process_node.index, IP6_ND_EVENT,
798 ~0 /* pool index, notused */ , 0 /* is_add */ );
802 if (q->cursize < q->maxsize)
804 mp = vl_msg_api_alloc (sizeof (*mp));
805 clib_memcpy (mp, event, sizeof (*mp));
806 vl_msg_api_send_shmem (q, (u8 *) & mp);
810 static f64 last_time;
812 * Throttle syslog msgs.
813 * It's pretty tempting to just revoke the registration...
815 if (vlib_time_now (vm) > last_time + 10.0)
817 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
818 format_ip6_address, &event->address, event->pid);
819 last_time = vlib_time_now (vm);
825 resolver_process (vlib_main_t * vm,
826 vlib_node_runtime_t * rt, vlib_frame_t * f)
829 uword *event_data = 0;
831 vpe_api_main_t *vam = &vpe_api_main;
833 vl_api_ip_add_del_route_t *adr;
834 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
835 u32 *resolution_failures = 0;
841 vlib_process_wait_for_event_or_clock (vm, timeout);
843 event_type = vlib_process_get_events (vm, &event_data);
847 case RESOLUTION_PENDING_EVENT:
851 case RESOLUTION_EVENT:
852 for (i = 0; i < vec_len (event_data); i++)
855 * Resolution events can occur long after the
856 * original request has timed out. $$$ add a cancel
859 if (pool_is_free_index (vam->pending_routes, event_data[i]))
862 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
866 switch (pr->resolve_type)
868 case RESOLVE_IP4_ADD_DEL_ROUTE:
869 rv = ip4_add_del_route_t_handler (adr);
870 clib_warning ("resolver: add %U/%d via %U %s",
872 (ip4_address_t *) & (adr->dst_address),
873 adr->dst_address_length,
875 (ip4_address_t *) & (adr->next_hop_address),
876 (rv >= 0) ? "succeeded" : "failed");
879 case RESOLVE_IP6_ADD_DEL_ROUTE:
880 rv = ip6_add_del_route_t_handler (adr);
881 clib_warning ("resolver: add %U/%d via %U %s",
883 (ip6_address_t *) & (adr->dst_address),
884 adr->dst_address_length,
886 (ip6_address_t *) & (adr->next_hop_address),
887 (rv >= 0) ? "succeeded" : "failed");
890 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
891 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
892 clib_warning ("resolver: add mpls-o-e via %U %s",
895 (pme->next_hop_ip4_address_in_outer_vrf),
896 (rv >= 0) ? "succeeded" : "failed");
900 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
902 pool_put (vam->pending_routes, pr);
907 for (i = 0; i < vec_len (event_data); i++)
908 handle_ip4_arp_event (event_data[i]);
912 for (i = 0; i < vec_len (event_data); i++)
913 handle_ip6_nd_event (event_data[i]);
916 case ~0: /* timeout, retry pending resolutions */
918 pool_foreach (pr, vam->pending_routes,
924 /* May fail, e.g. due to interface down */
925 switch (pr->resolve_type)
927 case RESOLVE_IP4_ADD_DEL_ROUTE:
928 e = ip4_probe_neighbor
929 (vm, (ip4_address_t *)&(adr->next_hop_address),
930 ntohl(adr->next_hop_sw_if_index));
933 case RESOLVE_IP6_ADD_DEL_ROUTE:
934 e = ip6_probe_neighbor
935 (vm, (ip6_address_t *)&(adr->next_hop_address),
936 ntohl(adr->next_hop_sw_if_index));
939 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
941 e = ip4_probe_neighbor
943 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
944 pme->resolve_opaque);
948 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
953 clib_error_report (e);
955 adr->resolve_attempts = 1;
957 pme->resolve_attempts = 1;
961 adr->resolve_attempts -= 1;
962 if (adr->resolve_attempts == 0)
963 vec_add1 (resolution_failures,
964 pr - vam->pending_routes);
968 pme->resolve_attempts -= 1;
969 if (pme->resolve_attempts == 0)
970 vec_add1 (resolution_failures,
971 pr - vam->pending_routes);
975 for (i = 0; i < vec_len (resolution_failures); i++)
977 pr = pool_elt_at_index (vam->pending_routes,
978 resolution_failures[i]);
982 switch (pr->resolve_type)
984 case RESOLVE_IP4_ADD_DEL_ROUTE:
985 clib_warning ("resolver: add %U/%d via %U retry failure",
987 (ip4_address_t *) & (adr->dst_address),
988 adr->dst_address_length,
990 (ip4_address_t *) & (adr->next_hop_address));
993 case RESOLVE_IP6_ADD_DEL_ROUTE:
994 clib_warning ("resolver: add %U/%d via %U retry failure",
996 (ip6_address_t *) & (adr->dst_address),
997 adr->dst_address_length,
999 (ip6_address_t *) & (adr->next_hop_address));
1002 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
1003 clib_warning ("resolver: add mpls-o-e via %U retry failure",
1006 (pme->next_hop_ip4_address_in_outer_vrf));
1010 clib_warning ("BUG");
1012 pool_put (vam->pending_routes, pr);
1014 vec_reset_length (resolution_failures);
1017 if (pool_elts (vam->pending_routes) == 0)
1019 vec_reset_length (event_data);
1021 return 0; /* or not */
1025 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
1026 .function = resolver_process,
1027 .type = VLIB_NODE_TYPE_PROCESS,
1028 .name = "vpe-route-resolver-process",
1033 add_del_route_t_handler (u8 is_multipath,
1040 u32 classify_table_index,
1042 u8 is_resolve_attached,
1044 const fib_prefix_t * prefix,
1045 u8 next_hop_proto_is_ip4,
1046 const ip46_address_t * next_hop,
1047 u32 next_hop_sw_if_index,
1048 u8 next_hop_fib_index,
1049 u32 next_hop_weight, u32 next_hop_out_label)
1051 vnet_classify_main_t *cm = &vnet_classify_main;
1052 stats_main_t *sm = &stats_main;
1056 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1058 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1060 if (is_resolve_host)
1061 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1062 if (is_resolve_attached)
1063 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1066 fib_table_entry_path_add (fib_index,
1069 FIB_ENTRY_FLAG_NONE,
1070 (next_hop_proto_is_ip4 ?
1074 next_hop_sw_if_index,
1077 next_hop_out_label, path_flags);
1079 fib_table_entry_path_remove (fib_index,
1082 (next_hop_proto_is_ip4 ?
1086 next_hop_sw_if_index,
1088 next_hop_weight, path_flags);
1094 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1096 if (is_drop || is_local || is_classify || is_unreach || is_prohibit)
1099 * special route types that link directly to the adj
1103 dpo_id_t dpo = DPO_INVALID;
1106 dproto = fib_proto_to_dpo (prefix->fp_proto);
1109 ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo);
1111 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
1112 else if (is_unreach)
1113 ip_null_dpo_add_and_lock (dproto,
1114 IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo);
1115 else if (is_prohibit)
1116 ip_null_dpo_add_and_lock (dproto,
1117 IP_NULL_ACTION_SEND_ICMP_PROHIBIT,
1119 else if (is_classify)
1121 if (pool_is_free_index (cm->tables,
1122 ntohl (classify_table_index)))
1125 return VNET_API_ERROR_NO_SUCH_TABLE;
1128 dpo_set (&dpo, DPO_CLASSIFY, dproto,
1129 classify_dpo_create (prefix->fp_proto,
1130 ntohl (classify_table_index)));
1135 return VNET_API_ERROR_NO_SUCH_TABLE;
1138 fib_table_entry_special_dpo_update (fib_index,
1141 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
1146 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
1153 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1155 if (is_resolve_host)
1156 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1157 if (is_resolve_attached)
1158 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1160 fib_table_entry_update_one_path (fib_index,
1163 FIB_ENTRY_FLAG_NONE,
1164 (next_hop_proto_is_ip4 ?
1168 next_hop_sw_if_index,
1171 next_hop_out_label, path_flags);
1175 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
1184 add_del_route_check (fib_protocol_t table_proto,
1186 u32 next_hop_sw_if_index,
1187 fib_protocol_t next_hop_table_proto,
1188 u32 next_hop_table_id,
1189 u8 create_missing_tables,
1190 u32 * fib_index, u32 * next_hop_fib_index)
1192 vnet_main_t *vnm = vnet_get_main ();
1194 *fib_index = fib_table_find (table_proto, ntohl (table_id));
1195 if (~0 == *fib_index)
1197 if (create_missing_tables)
1199 *fib_index = fib_table_find_or_create_and_lock (table_proto,
1204 /* No such VRF, and we weren't asked to create one */
1205 return VNET_API_ERROR_NO_SUCH_FIB;
1209 if (~0 != ntohl (next_hop_sw_if_index))
1211 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1212 ntohl (next_hop_sw_if_index)))
1214 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1219 *next_hop_fib_index = fib_table_find (next_hop_table_proto,
1220 ntohl (next_hop_table_id));
1222 if (~0 == *next_hop_fib_index)
1224 if (create_missing_tables)
1226 *next_hop_fib_index =
1227 fib_table_find_or_create_and_lock (next_hop_table_proto,
1228 ntohl (next_hop_table_id));
1232 /* No such VRF, and we weren't asked to create one */
1233 return VNET_API_ERROR_NO_SUCH_FIB;
1242 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1244 u32 fib_index, next_hop_fib_index;
1247 rv = add_del_route_check (FIB_PROTOCOL_IP4,
1249 mp->next_hop_sw_if_index,
1251 mp->next_hop_table_id,
1252 mp->create_vrf_if_needed,
1253 &fib_index, &next_hop_fib_index);
1258 fib_prefix_t pfx = {
1259 .fp_len = mp->dst_address_length,
1260 .fp_proto = FIB_PROTOCOL_IP4,
1262 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
1265 memset (&nh, 0, sizeof (nh));
1266 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
1268 return (add_del_route_t_handler (mp->is_multipath,
1275 mp->classify_table_index,
1276 mp->is_resolve_host,
1277 mp->is_resolve_attached,
1280 ntohl (mp->next_hop_sw_if_index),
1282 mp->next_hop_weight,
1283 ntohl (mp->next_hop_out_label)));
1287 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1289 u32 fib_index, next_hop_fib_index;
1292 rv = add_del_route_check (FIB_PROTOCOL_IP6,
1294 mp->next_hop_sw_if_index,
1296 mp->next_hop_table_id,
1297 mp->create_vrf_if_needed,
1298 &fib_index, &next_hop_fib_index);
1303 fib_prefix_t pfx = {
1304 .fp_len = mp->dst_address_length,
1305 .fp_proto = FIB_PROTOCOL_IP6,
1307 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
1310 memset (&nh, 0, sizeof (nh));
1311 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
1313 return (add_del_route_t_handler (mp->is_multipath,
1320 mp->classify_table_index,
1321 mp->is_resolve_host,
1322 mp->is_resolve_attached,
1324 &nh, ntohl (mp->next_hop_sw_if_index),
1326 mp->next_hop_weight,
1327 ntohl (mp->next_hop_out_label)));
1331 mpls_route_add_del_t_handler (vnet_main_t * vnm,
1332 vl_api_mpls_route_add_del_t * mp)
1334 u32 fib_index, next_hop_fib_index;
1338 fib_prefix_t pfx = {
1340 .fp_proto = FIB_PROTOCOL_MPLS,
1341 .fp_eos = mp->mr_eos,
1342 .fp_label = ntohl (mp->mr_label),
1346 if (mp->mr_next_hop_proto_is_ip4)
1348 pfx.fp_payload_proto = DPO_PROTO_IP4;
1352 pfx.fp_payload_proto = DPO_PROTO_IP6;
1357 pfx.fp_payload_proto = DPO_PROTO_MPLS;
1360 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
1362 mp->mr_next_hop_sw_if_index,
1363 dpo_proto_to_fib (pfx.fp_payload_proto),
1364 mp->mr_next_hop_table_id,
1365 mp->mr_create_table_if_needed,
1366 &fib_index, &next_hop_fib_index);
1372 memset (&nh, 0, sizeof (nh));
1374 if (mp->mr_next_hop_proto_is_ip4)
1375 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
1377 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
1379 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
1380 0, // mp->is_unreach,
1381 0, // mp->is_prohibit,
1384 mp->mr_classify_table_index,
1385 mp->mr_is_resolve_host,
1386 mp->mr_is_resolve_attached,
1388 mp->mr_next_hop_proto_is_ip4,
1389 &nh, ntohl (mp->mr_next_hop_sw_if_index),
1391 mp->mr_next_hop_weight,
1392 ntohl (mp->mr_next_hop_out_label)));
1396 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1398 vl_api_ip_add_del_route_reply_t *rmp;
1400 vnet_main_t *vnm = vnet_get_main ();
1405 rv = ip6_add_del_route_t_handler (mp);
1407 rv = ip4_add_del_route_t_handler (mp);
1409 rv = (rv == 0) ? vnm->api_errno : rv;
1411 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1415 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
1417 vl_api_mpls_route_add_del_reply_t *rmp;
1421 vnm = vnet_get_main ();
1424 rv = mpls_route_add_del_t_handler (vnm, mp);
1426 rv = (rv == 0) ? vnm->api_errno : rv;
1428 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1432 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
1433 vl_api_mpls_ip_bind_unbind_t * mp)
1435 u32 mpls_fib_index, ip_fib_index;
1438 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
1440 if (~0 == mpls_fib_index)
1442 if (mp->mb_create_table_if_needed)
1445 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
1446 ntohl (mp->mb_mpls_table_id));
1449 return VNET_API_ERROR_NO_SUCH_FIB;
1452 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
1455 ntohl (mp->mb_ip_table_id));
1456 if (~0 == ip_fib_index)
1457 return VNET_API_ERROR_NO_SUCH_FIB;
1459 fib_prefix_t pfx = {
1460 .fp_len = mp->mb_address_length,
1465 pfx.fp_proto = FIB_PROTOCOL_IP4;
1466 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
1467 sizeof (pfx.fp_addr.ip4));
1471 pfx.fp_proto = FIB_PROTOCOL_IP6;
1472 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
1473 sizeof (pfx.fp_addr.ip6));
1477 fib_table_entry_local_label_add (ip_fib_index, &pfx,
1478 ntohl (mp->mb_label));
1480 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
1481 ntohl (mp->mb_label));
1487 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
1489 vl_api_mpls_route_add_del_reply_t *rmp;
1493 vnm = vnet_get_main ();
1496 rv = mpls_ip_bind_unbind_handler (vnm, mp);
1498 rv = (rv == 0) ? vnm->api_errno : rv;
1500 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1504 vl_api_sw_interface_add_del_address_t_handler
1505 (vl_api_sw_interface_add_del_address_t * mp)
1507 vlib_main_t *vm = vlib_get_main ();
1508 vl_api_sw_interface_add_del_address_reply_t *rmp;
1512 VALIDATE_SW_IF_INDEX (mp);
1514 is_del = mp->is_add == 0;
1517 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1518 else if (mp->is_ipv6)
1519 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1520 (void *) mp->address,
1521 mp->address_length, is_del);
1523 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1524 (void *) mp->address,
1525 mp->address_length, is_del);
1527 BAD_SW_IF_INDEX_LABEL;
1529 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1533 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1536 u32 table_id = ntohl (mp->vrf_id);
1537 u32 sw_if_index = ntohl (mp->sw_if_index);
1538 vl_api_sw_interface_set_table_reply_t *rmp;
1539 stats_main_t *sm = &stats_main;
1542 VALIDATE_SW_IF_INDEX (mp);
1544 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1548 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1551 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
1552 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1557 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1560 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
1561 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1565 BAD_SW_IF_INDEX_LABEL;
1567 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1571 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1573 vlib_main_t *vm = vlib_get_main ();
1574 ip4_main_t *im4 = &ip4_main;
1575 ip6_main_t *im6 = &ip6_main;
1576 vl_api_sw_interface_set_vpath_reply_t *rmp;
1579 u32 sw_if_index = ntohl (mp->sw_if_index);
1580 ip4_main_t *ip4m = &ip4_main;
1581 ip6_main_t *ip6m = &ip6_main;
1582 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1583 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1584 ip_config_main_t *rx_cm4u =
1585 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1586 ip_config_main_t *rx_cm4m =
1587 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1588 ip_config_main_t *rx_cm6u =
1589 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1590 ip_config_main_t *rx_cm6m =
1591 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1593 VALIDATE_SW_IF_INDEX (mp);
1595 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1598 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1599 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1601 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1602 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1603 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1604 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1606 im4->ip4_multicast_rx_feature_vpath,
1608 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1609 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1610 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1612 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1613 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1614 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1615 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1617 im6->ip6_multicast_rx_feature_vpath,
1619 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1623 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1624 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1626 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1627 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1628 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1629 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1631 im4->ip4_multicast_rx_feature_vpath,
1633 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1634 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1635 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1637 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1638 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1639 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1640 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1642 im6->ip6_multicast_rx_feature_vpath,
1644 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1647 BAD_SW_IF_INDEX_LABEL;
1649 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1653 vl_api_sw_interface_set_l2_xconnect_t_handler
1654 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1656 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1658 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1659 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1660 vlib_main_t *vm = vlib_get_main ();
1661 vnet_main_t *vnm = vnet_get_main ();
1663 VALIDATE_RX_SW_IF_INDEX (mp);
1667 VALIDATE_TX_SW_IF_INDEX (mp);
1668 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1669 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1673 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1676 BAD_RX_SW_IF_INDEX_LABEL;
1677 BAD_TX_SW_IF_INDEX_LABEL;
1679 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1683 vl_api_sw_interface_set_l2_bridge_t_handler
1684 (vl_api_sw_interface_set_l2_bridge_t * mp)
1686 bd_main_t *bdm = &bd_main;
1687 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1689 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1690 u32 bd_id = ntohl (mp->bd_id);
1694 vlib_main_t *vm = vlib_get_main ();
1695 vnet_main_t *vnm = vnet_get_main ();
1697 VALIDATE_RX_SW_IF_INDEX (mp);
1699 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1703 //VALIDATE_TX_SW_IF_INDEX(mp);
1704 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1705 rx_sw_if_index, bd_index, bvi, shg, 0);
1709 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1712 BAD_RX_SW_IF_INDEX_LABEL;
1714 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1718 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1719 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1721 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1725 dpdk_main_t *dm = &dpdk_main;
1728 u32 sw_if_index = ntohl (mp->sw_if_index);
1729 u32 subport = ntohl (mp->subport);
1730 u32 pipe = ntohl (mp->pipe);
1731 u32 profile = ntohl (mp->profile);
1732 vnet_hw_interface_t *hw;
1734 VALIDATE_SW_IF_INDEX (mp);
1736 /* hw_if & dpdk device */
1737 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1739 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1741 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1743 BAD_SW_IF_INDEX_LABEL;
1745 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1746 rv = VNET_API_ERROR_UNIMPLEMENTED;
1749 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1753 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1754 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1756 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1760 dpdk_main_t *dm = &dpdk_main;
1762 struct rte_sched_subport_params p;
1764 u32 sw_if_index = ntohl (mp->sw_if_index);
1765 u32 subport = ntohl (mp->subport);
1766 p.tb_rate = ntohl (mp->tb_rate);
1767 p.tb_size = ntohl (mp->tb_size);
1768 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1769 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1770 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1771 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1772 p.tc_period = ntohl (mp->tc_period);
1774 vnet_hw_interface_t *hw;
1776 VALIDATE_SW_IF_INDEX (mp);
1778 /* hw_if & dpdk device */
1779 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1781 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1783 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1785 BAD_SW_IF_INDEX_LABEL;
1788 ("setting HQoS subport parameters without DPDK not implemented");
1789 rv = VNET_API_ERROR_UNIMPLEMENTED;
1792 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1796 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1797 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1799 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1803 dpdk_main_t *dm = &dpdk_main;
1804 vlib_thread_main_t *tm = vlib_get_thread_main ();
1807 u32 sw_if_index = ntohl (mp->sw_if_index);
1808 u32 entry = ntohl (mp->entry);
1809 u32 tc = ntohl (mp->tc);
1810 u32 queue = ntohl (mp->queue);
1813 vnet_hw_interface_t *hw;
1815 VALIDATE_SW_IF_INDEX (mp);
1817 /* hw_if & dpdk device */
1818 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1820 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1822 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1824 clib_warning ("invalid traffic class !!");
1825 rv = VNET_API_ERROR_INVALID_VALUE;
1828 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1830 clib_warning ("invalid queue !!");
1831 rv = VNET_API_ERROR_INVALID_VALUE;
1835 /* Detect the set of worker threads */
1836 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1840 clib_warning ("worker thread registration AWOL !!");
1841 rv = VNET_API_ERROR_INVALID_VALUE_2;
1845 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1846 int worker_thread_first = tr->first_index;
1847 int worker_thread_count = tr->count;
1849 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1850 for (i = 0; i < worker_thread_count; i++)
1851 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1853 BAD_SW_IF_INDEX_LABEL;
1856 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1857 rv = VNET_API_ERROR_UNIMPLEMENTED;
1860 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1864 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1866 vlib_main_t *vm = vlib_get_main ();
1867 bd_main_t *bdm = &bd_main;
1868 vl_api_bridge_domain_add_del_reply_t *rmp;
1870 u32 enable_flags = 0, disable_flags = 0;
1871 u32 bd_id = ntohl (mp->bd_id);
1876 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1879 enable_flags |= L2_FLOOD;
1881 disable_flags |= L2_FLOOD;
1884 enable_flags |= L2_UU_FLOOD;
1886 disable_flags |= L2_UU_FLOOD;
1889 enable_flags |= L2_FWD;
1891 disable_flags |= L2_FWD;
1894 enable_flags |= L2_ARP_TERM;
1896 disable_flags |= L2_ARP_TERM;
1899 enable_flags |= L2_LEARN;
1901 disable_flags |= L2_LEARN;
1904 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1907 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1911 rv = bd_delete_bd_index (bdm, bd_id);
1913 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1917 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1919 clib_warning ("BUG");
1923 vl_api_bridge_domain_sw_if_details_t_handler
1924 (vl_api_bridge_domain_sw_if_details_t * mp)
1926 clib_warning ("BUG");
1930 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1931 l2_bridge_domain_t * bd_config,
1932 u32 n_sw_ifs, u32 context)
1934 vl_api_bridge_domain_details_t *mp;
1936 mp = vl_msg_api_alloc (sizeof (*mp));
1937 memset (mp, 0, sizeof (*mp));
1938 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1939 mp->bd_id = ntohl (bd_config->bd_id);
1940 mp->flood = bd_feature_flood (bd_config);
1941 mp->uu_flood = bd_feature_uu_flood (bd_config);
1942 mp->forward = bd_feature_forward (bd_config);
1943 mp->learn = bd_feature_learn (bd_config);
1944 mp->arp_term = bd_feature_arp_term (bd_config);
1945 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1946 mp->n_sw_ifs = ntohl (n_sw_ifs);
1947 mp->context = context;
1949 vl_msg_api_send_shmem (q, (u8 *) & mp);
1953 send_bd_sw_if_details (l2input_main_t * l2im,
1954 unix_shared_memory_queue_t * q,
1955 l2_flood_member_t * member, u32 bd_id, u32 context)
1957 vl_api_bridge_domain_sw_if_details_t *mp;
1958 l2_input_config_t *input_cfg;
1960 mp = vl_msg_api_alloc (sizeof (*mp));
1961 memset (mp, 0, sizeof (*mp));
1962 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1963 mp->bd_id = ntohl (bd_id);
1964 mp->sw_if_index = ntohl (member->sw_if_index);
1965 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1966 mp->shg = input_cfg->shg;
1967 mp->context = context;
1969 vl_msg_api_send_shmem (q, (u8 *) & mp);
1973 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1975 bd_main_t *bdm = &bd_main;
1976 l2input_main_t *l2im = &l2input_main;
1977 unix_shared_memory_queue_t *q;
1978 l2_bridge_domain_t *bd_config;
1979 u32 bd_id, bd_index;
1982 q = vl_api_client_index_to_input_queue (mp->client_index);
1987 bd_id = ntohl (mp->bd_id);
1989 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1990 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1991 for (; bd_index < end; bd_index++)
1993 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1994 /* skip dummy bd_id 0 */
1995 if (bd_config && (bd_config->bd_id > 0))
1998 l2_flood_member_t *m;
2000 n_sw_ifs = vec_len (bd_config->members);
2001 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
2003 vec_foreach (m, bd_config->members)
2005 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
2012 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
2014 bd_main_t *bdm = &bd_main;
2015 l2input_main_t *l2im = &l2input_main;
2016 vl_api_l2fib_add_del_reply_t *rmp;
2019 u32 sw_if_index = ntohl (mp->sw_if_index);
2020 u32 bd_id = ntohl (mp->bd_id);
2029 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2032 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2033 goto bad_sw_if_index;
2039 VALIDATE_SW_IF_INDEX (mp);
2040 if (vec_len (l2im->configs) <= sw_if_index)
2042 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2043 goto bad_sw_if_index;
2047 l2_input_config_t *config;
2048 config = vec_elt_at_index (l2im->configs, sw_if_index);
2049 if (config->bridge == 0)
2051 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2052 goto bad_sw_if_index;
2055 static_mac = mp->static_mac ? 1 : 0;
2056 filter_mac = mp->filter_mac ? 1 : 0;
2057 bvi_mac = mp->bvi_mac ? 1 : 0;
2058 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
2063 l2fib_del_entry (mac, bd_index);
2066 BAD_SW_IF_INDEX_LABEL;
2068 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
2072 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
2074 vl_api_l2_flags_reply_t *rmp;
2076 u32 sw_if_index = ntohl (mp->sw_if_index);
2077 u32 flags = ntohl (mp->feature_bitmap);
2080 VALIDATE_SW_IF_INDEX (mp);
2083 if (flags & L2INPUT_FEAT_ ## a) \
2084 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
2085 foreach_l2input_feat;
2088 BAD_SW_IF_INDEX_LABEL;
2091 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
2093 rmp->resulting_feature_bitmap = ntohl(rbm);
2099 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
2101 vlib_main_t *vm = vlib_get_main ();
2102 bd_main_t *bdm = &bd_main;
2103 vl_api_bridge_flags_reply_t *rmp;
2105 u32 bd_id = ntohl (mp->bd_id);
2107 u32 flags = ntohl (mp->feature_bitmap);
2110 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2113 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2119 bd_set_flags (vm, bd_index, flags, mp->is_set);
2123 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
2125 rmp->resulting_feature_bitmap = ntohl(flags);
2131 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
2133 bd_main_t *bdm = &bd_main;
2134 vl_api_bd_ip_mac_add_del_reply_t *rmp;
2136 u32 bd_id = ntohl (mp->bd_id);
2140 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2143 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2148 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
2149 mp->mac_address, mp->is_ipv6, mp->is_add))
2150 rv = VNET_API_ERROR_UNSPECIFIED;
2153 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
2157 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
2160 vl_api_tap_connect_reply_t *rmp;
2161 unix_shared_memory_queue_t *q;
2162 u32 sw_if_index = (u32) ~ 0;
2164 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
2165 mp->use_random_mac ? 0 : mp->mac_address,
2166 &sw_if_index, mp->renumber,
2167 ntohl (mp->custom_dev_instance));
2169 q = vl_api_client_index_to_input_queue (mp->client_index);
2173 rmp = vl_msg_api_alloc (sizeof (*rmp));
2174 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
2175 rmp->context = mp->context;
2176 rmp->retval = ntohl (rv);
2177 rmp->sw_if_index = ntohl (sw_if_index);
2179 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2183 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
2186 vl_api_tap_modify_reply_t *rmp;
2187 unix_shared_memory_queue_t *q;
2188 u32 sw_if_index = (u32) ~ 0;
2190 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
2191 mp->use_random_mac ? 0 : mp->mac_address,
2192 &sw_if_index, mp->renumber,
2193 ntohl (mp->custom_dev_instance));
2195 q = vl_api_client_index_to_input_queue (mp->client_index);
2199 rmp = vl_msg_api_alloc (sizeof (*rmp));
2200 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
2201 rmp->context = mp->context;
2202 rmp->retval = ntohl (rv);
2203 rmp->sw_if_index = ntohl (sw_if_index);
2205 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2209 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
2212 vpe_api_main_t *vam = &vpe_api_main;
2213 vl_api_tap_delete_reply_t *rmp;
2214 unix_shared_memory_queue_t *q;
2215 u32 sw_if_index = ntohl (mp->sw_if_index);
2217 rv = vnet_tap_delete (vm, sw_if_index);
2219 q = vl_api_client_index_to_input_queue (mp->client_index);
2223 rmp = vl_msg_api_alloc (sizeof (*rmp));
2224 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
2225 rmp->context = mp->context;
2226 rmp->retval = ntohl (rv);
2228 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2231 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2235 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
2237 vl_api_create_vlan_subif_reply_t *rmp;
2238 vnet_main_t *vnm = vnet_get_main ();
2239 u32 hw_if_index, sw_if_index = (u32) ~ 0;
2240 vnet_hw_interface_t *hi;
2243 vnet_sw_interface_t template;
2245 vnet_interface_main_t *im = &vnm->interface_main;
2246 u64 sup_and_sub_key;
2248 unix_shared_memory_queue_t *q;
2249 clib_error_t *error;
2251 VALIDATE_SW_IF_INDEX (mp);
2253 hw_if_index = ntohl (mp->sw_if_index);
2254 hi = vnet_get_hw_interface (vnm, hw_if_index);
2256 id = ntohl (mp->vlan_id);
2257 if (id == 0 || id > 4095)
2259 rv = VNET_API_ERROR_INVALID_VLAN;
2263 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2265 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2268 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2272 kp = clib_mem_alloc (sizeof (*kp));
2273 *kp = sup_and_sub_key;
2275 memset (&template, 0, sizeof (template));
2276 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2277 template.sup_sw_if_index = hi->sw_if_index;
2278 template.sub.id = id;
2279 template.sub.eth.raw_flags = 0;
2280 template.sub.eth.flags.one_tag = 1;
2281 template.sub.eth.outer_vlan_id = id;
2282 template.sub.eth.flags.exact_match = 1;
2284 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2287 clib_error_report (error);
2288 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2291 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2292 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2294 BAD_SW_IF_INDEX_LABEL;
2297 q = vl_api_client_index_to_input_queue (mp->client_index);
2301 rmp = vl_msg_api_alloc (sizeof (*rmp));
2302 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2303 rmp->context = mp->context;
2304 rmp->retval = ntohl (rv);
2305 rmp->sw_if_index = ntohl (sw_if_index);
2306 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2310 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2312 vl_api_create_subif_reply_t *rmp;
2313 vnet_main_t *vnm = vnet_get_main ();
2314 u32 sw_if_index = ~0;
2317 vnet_sw_interface_t *si;
2318 vnet_hw_interface_t *hi;
2319 vnet_sw_interface_t template;
2321 vnet_interface_main_t *im = &vnm->interface_main;
2322 u64 sup_and_sub_key;
2324 clib_error_t *error;
2326 VALIDATE_SW_IF_INDEX (mp);
2328 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2329 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2331 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2333 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2337 sw_if_index = si->sw_if_index;
2338 sub_id = ntohl (mp->sub_id);
2340 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2342 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2346 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2347 sw_if_index, sub_id);
2348 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2352 kp = clib_mem_alloc (sizeof (*kp));
2353 *kp = sup_and_sub_key;
2355 memset (&template, 0, sizeof (template));
2356 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2357 template.sup_sw_if_index = sw_if_index;
2358 template.sub.id = sub_id;
2359 template.sub.eth.flags.no_tags = mp->no_tags;
2360 template.sub.eth.flags.one_tag = mp->one_tag;
2361 template.sub.eth.flags.two_tags = mp->two_tags;
2362 template.sub.eth.flags.dot1ad = mp->dot1ad;
2363 template.sub.eth.flags.exact_match = mp->exact_match;
2364 template.sub.eth.flags.default_sub = mp->default_sub;
2365 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2366 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2367 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2368 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2370 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2373 clib_error_report (error);
2374 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2378 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2379 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2381 BAD_SW_IF_INDEX_LABEL;
2386 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2388 rmp->sw_if_index = ntohl(sw_if_index);
2394 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2395 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2397 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2399 stats_main_t *sm = &stats_main;
2400 u32 tunnel_sw_if_index;
2402 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2404 rv = vnet_mpls_ethernet_add_del_tunnel
2405 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2406 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2407 ntohl (mp->tx_sw_if_index),
2408 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2413 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2415 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2421 * This piece of misery brought to you because the control-plane
2422 * can't figure out the tx interface + dst-mac address all by itself
2424 static int mpls_ethernet_add_del_tunnel_2_t_handler
2425 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2427 pending_route_t *pr;
2428 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2429 vnet_main_t *vnm = vnet_get_main ();
2430 vlib_main_t *vm = vlib_get_main ();
2431 stats_main_t *sm = &stats_main;
2432 vpe_api_main_t *vam = &vpe_api_main;
2433 u32 inner_fib_index, outer_fib_index;
2434 ip4_main_t *im = &ip4_main;
2435 ip_lookup_main_t *lm = &im->lookup_main;
2436 ip_adjacency_t *adj = 0;
2439 u8 *dst_mac_address;
2443 u32 tunnel_sw_if_index;
2445 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2447 return VNET_API_ERROR_NO_SUCH_FIB;
2449 outer_fib_index = p[0];
2452 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2454 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2456 inner_fib_index = p[0];
2458 if (inner_fib_index == outer_fib_index)
2459 return VNET_API_ERROR_INVALID_VALUE;
2462 lookup_result = ip4_fib_table_lookup_lb (ip4_fib_get (outer_fib_index),
2464 mp->next_hop_ip4_address_in_outer_vrf);
2466 adj = ip_get_adjacency (lm, lookup_result);
2467 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2469 if (mp->is_add && mp->resolve_if_needed)
2471 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2473 pool_get (vam->pending_routes, pr);
2474 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2476 clib_memcpy (pme, mp, sizeof (*pme));
2477 /* recursion block, "just in case" */
2478 pme->resolve_if_needed = 0;
2479 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2480 pme->resolve_opaque = tx_sw_if_index;
2481 vnet_register_ip4_arp_resolution_event
2483 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2484 vpe_resolver_process_node.index,
2485 RESOLUTION_EVENT, pr - vam->pending_routes);
2487 vlib_process_signal_event
2488 (vm, vpe_resolver_process_node.index,
2489 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2491 /* The interface may be down, etc. */
2492 e = ip4_probe_neighbor
2493 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2497 clib_error_report (e);
2499 return VNET_API_ERROR_IN_PROGRESS;
2503 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2504 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2507 vnet_rewrite_get_data_internal
2508 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2510 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2512 rv = vnet_mpls_ethernet_add_del_tunnel
2513 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2514 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2515 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2523 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2524 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2526 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2529 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2531 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2536 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2538 vl_api_mpls_add_del_encap_reply_t *rmp;
2543 vec_reset_length (labels);
2545 for (i = 0; i < mp->nlabels; i++)
2546 vec_add1 (labels, ntohl (mp->labels[i]));
2549 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2550 ntohl (mp->vrf_id), labels,
2551 ~0 /* policy_tunnel_index */ ,
2552 0 /* no_dst_hash */ ,
2556 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2560 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2562 vl_api_proxy_arp_add_del_reply_t *rmp;
2565 ip4_main_t *im = &ip4_main;
2566 stats_main_t *sm = &stats_main;
2567 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2568 ip4_address_t * hi_addr,
2569 u32 fib_index, int is_del);
2572 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2574 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2578 rv = VNET_API_ERROR_NO_SUCH_FIB;
2584 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2585 (ip4_address_t *) mp->hi_address,
2586 fib_index, mp->is_add == 0);
2590 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2594 vl_api_proxy_arp_intfc_enable_disable_t_handler
2595 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2598 vnet_main_t *vnm = vnet_get_main ();
2599 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2600 vnet_sw_interface_t *si;
2603 VALIDATE_SW_IF_INDEX (mp);
2605 sw_if_index = ntohl (mp->sw_if_index);
2607 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2609 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2613 si = vnet_get_sw_interface (vnm, sw_if_index);
2617 if (mp->enable_disable)
2618 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2620 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2622 BAD_SW_IF_INDEX_LABEL;
2625 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2629 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2632 vl_api_ip_neighbor_add_del_reply_t *rmp;
2633 vnet_main_t *vnm = vnet_get_main ();
2634 stats_main_t *sm = &stats_main;
2637 VALIDATE_SW_IF_INDEX (mp);
2639 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2642 * there's no validation here of the ND/ARP entry being added.
2643 * The expectation is that the FIB will ensure that nothing bad
2644 * will come of adding bogus entries.
2649 rv = vnet_set_ip6_ethernet_neighbor
2650 (vm, ntohl (mp->sw_if_index),
2651 (ip6_address_t *) (mp->dst_address),
2652 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2654 rv = vnet_unset_ip6_ethernet_neighbor
2655 (vm, ntohl (mp->sw_if_index),
2656 (ip6_address_t *) (mp->dst_address),
2657 mp->mac_address, sizeof (mp->mac_address));
2661 ethernet_arp_ip4_over_ethernet_address_t a;
2663 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2664 clib_memcpy (&a.ip4, mp->dst_address, 4);
2667 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2671 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2674 BAD_SW_IF_INDEX_LABEL;
2677 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2681 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2684 vpe_main_t *rm = &vpe_main;
2685 ip4_main_t *im4 = &ip4_main;
2686 ip6_main_t *im6 = &ip6_main;
2687 ip_lookup_main_t *lm;
2693 u32 adj_index, sw_if_index;
2694 vl_api_is_address_reachable_t *rmp;
2695 ip_adjacency_t *adj;
2696 unix_shared_memory_queue_t *q;
2698 q = vl_api_client_index_to_input_queue (mp->client_index);
2701 increment_missing_api_client_counter (rm->vlib_main);
2705 rmp = vl_msg_api_alloc (sizeof (*rmp));
2706 clib_memcpy (rmp, mp, sizeof (*rmp));
2708 sw_if_index = mp->next_hop_sw_if_index;
2709 clib_memcpy (&addr, mp->address, sizeof (addr));
2712 lm = &im6->lookup_main;
2713 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2717 lm = &im4->lookup_main;
2719 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2721 if (adj_index == ~0)
2726 adj = ip_get_adjacency (lm, adj_index);
2728 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2729 && adj->rewrite_header.sw_if_index == sw_if_index)
2735 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2736 && adj->rewrite_header.sw_if_index == sw_if_index)
2739 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2741 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2743 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2752 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2757 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2759 clib_warning ("BUG");
2763 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2765 vl_api_sw_interface_set_flags_reply_t *rmp;
2766 vnet_main_t *vnm = vnet_get_main ();
2768 clib_error_t *error;
2771 VALIDATE_SW_IF_INDEX (mp);
2773 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2775 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2779 clib_error_report (error);
2782 BAD_SW_IF_INDEX_LABEL;
2783 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2787 vl_api_sw_interface_set_mpls_enable_t_handler
2788 (vl_api_sw_interface_set_mpls_enable_t * mp)
2790 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2793 VALIDATE_SW_IF_INDEX (mp);
2795 mpls_sw_interface_enable_disable (&mpls_main,
2796 ntohl (mp->sw_if_index), mp->enable);
2798 BAD_SW_IF_INDEX_LABEL;
2799 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2803 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2806 vl_api_sw_interface_clear_stats_reply_t *rmp;
2808 vnet_main_t *vnm = vnet_get_main ();
2809 vnet_interface_main_t *im = &vnm->interface_main;
2810 vlib_simple_counter_main_t *sm;
2811 vlib_combined_counter_main_t *cm;
2812 static vnet_main_t **my_vnet_mains;
2813 int i, j, n_counters;
2816 if (mp->sw_if_index != ~0)
2817 VALIDATE_SW_IF_INDEX (mp);
2819 vec_reset_length (my_vnet_mains);
2821 for (i = 0; i < vec_len (vnet_mains); i++)
2824 vec_add1 (my_vnet_mains, vnet_mains[i]);
2827 if (vec_len (vnet_mains) == 0)
2828 vec_add1 (my_vnet_mains, vnm);
2830 n_counters = vec_len (im->combined_sw_if_counters);
2832 for (j = 0; j < n_counters; j++)
2834 for (i = 0; i < vec_len (my_vnet_mains); i++)
2836 im = &my_vnet_mains[i]->interface_main;
2837 cm = im->combined_sw_if_counters + j;
2838 if (mp->sw_if_index == (u32) ~ 0)
2839 vlib_clear_combined_counters (cm);
2841 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2845 n_counters = vec_len (im->sw_if_counters);
2847 for (j = 0; j < n_counters; j++)
2849 for (i = 0; i < vec_len (my_vnet_mains); i++)
2851 im = &my_vnet_mains[i]->interface_main;
2852 sm = im->sw_if_counters + j;
2853 if (mp->sw_if_index == (u32) ~ 0)
2854 vlib_clear_simple_counters (sm);
2856 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2860 BAD_SW_IF_INDEX_LABEL;
2862 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2866 send_sw_interface_details (vpe_api_main_t * am,
2867 unix_shared_memory_queue_t * q,
2868 vnet_sw_interface_t * swif,
2869 u8 * interface_name, u32 context)
2871 vl_api_sw_interface_details_t *mp;
2872 vnet_hw_interface_t *hi;
2874 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2876 mp = vl_msg_api_alloc (sizeof (*mp));
2877 memset (mp, 0, sizeof (*mp));
2878 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2879 mp->sw_if_index = ntohl (swif->sw_if_index);
2880 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2881 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2882 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2883 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2884 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2885 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2886 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2887 mp->link_mtu = ntohs (hi->max_packet_bytes);
2888 mp->context = context;
2890 strncpy ((char *) mp->interface_name,
2891 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2893 /* Send the L2 address for ethernet physical intfcs */
2894 if (swif->sup_sw_if_index == swif->sw_if_index
2895 && hi->hw_class_index == ethernet_hw_interface_class.index)
2897 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2898 ethernet_interface_t *ei;
2900 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2901 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2902 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2903 mp->l2_address_length = ntohl (sizeof (ei->address));
2905 else if (swif->sup_sw_if_index != swif->sw_if_index)
2907 vnet_sub_interface_t *sub = &swif->sub;
2908 mp->sub_id = ntohl (sub->id);
2909 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2910 mp->sub_number_of_tags =
2911 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2912 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2913 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2914 mp->sub_exact_match = sub->eth.flags.exact_match;
2915 mp->sub_default = sub->eth.flags.default_sub;
2916 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2917 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2919 /* vlan tag rewrite data */
2920 u32 vtr_op = L2_VTR_DISABLED;
2921 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2923 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2924 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2926 // error - default to disabled
2927 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2928 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2933 mp->vtr_op = ntohl (vtr_op);
2934 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2935 mp->vtr_tag1 = ntohl (vtr_tag1);
2936 mp->vtr_tag2 = ntohl (vtr_tag2);
2940 vl_msg_api_send_shmem (q, (u8 *) & mp);
2944 send_sw_interface_flags (vpe_api_main_t * am,
2945 unix_shared_memory_queue_t * q,
2946 vnet_sw_interface_t * swif)
2948 vl_api_sw_interface_set_flags_t *mp;
2949 vnet_main_t *vnm = am->vnet_main;
2951 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2953 mp = vl_msg_api_alloc (sizeof (*mp));
2954 memset (mp, 0, sizeof (*mp));
2955 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2956 mp->sw_if_index = ntohl (swif->sw_if_index);
2958 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2959 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2960 vl_msg_api_send_shmem (q, (u8 *) & mp);
2963 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2964 unix_shared_memory_queue_t * q,
2966 __attribute__ ((unused));
2969 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2970 unix_shared_memory_queue_t * q,
2973 vl_api_sw_interface_set_flags_t *mp;
2975 mp = vl_msg_api_alloc (sizeof (*mp));
2976 memset (mp, 0, sizeof (*mp));
2977 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2978 mp->sw_if_index = ntohl (sw_if_index);
2980 mp->admin_up_down = 0;
2981 mp->link_up_down = 0;
2983 vl_msg_api_send_shmem (q, (u8 *) & mp);
2987 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2989 vpe_api_main_t *am = &vpe_api_main;
2990 vnet_sw_interface_t *swif;
2991 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2992 u8 *filter_string = 0, *name_string = 0;
2993 unix_shared_memory_queue_t *q;
2994 char *strcasestr (char *, char *); /* lnx hdr file botch */
2996 q = vl_api_client_index_to_input_queue (mp->client_index);
3001 if (mp->name_filter_valid)
3003 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
3004 filter_string = format (0, "%s%c", mp->name_filter, 0);
3008 pool_foreach (swif, im->sw_interfaces,
3010 name_string = format (name_string, "%U%c",
3011 format_vnet_sw_interface_name,
3012 am->vnet_main, swif, 0);
3014 if (mp->name_filter_valid == 0 ||
3015 strcasestr((char *) name_string, (char *) filter_string)) {
3017 send_sw_interface_details (am, q, swif, name_string, mp->context);
3019 _vec_len (name_string) = 0;
3023 vec_free (name_string);
3024 vec_free (filter_string);
3028 send_oam_event (oam_target_t * t)
3030 vpe_api_main_t *vam = &vpe_api_main;
3031 unix_shared_memory_queue_t *q;
3032 vpe_client_registration_t *reg;
3033 vl_api_oam_event_t *mp;
3036 pool_foreach(reg, vam->oam_events_registrations,
3038 q = vl_api_client_index_to_input_queue (reg->client_index);
3041 mp = vl_msg_api_alloc (sizeof (*mp));
3042 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
3043 clib_memcpy (mp->dst_address, &t->dst_address,
3044 sizeof (mp->dst_address));
3045 mp->state = t->state;
3046 vl_msg_api_send_shmem (q, (u8 *)&mp);
3053 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
3055 vl_api_oam_add_del_reply_t *rmp;
3058 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
3059 (ip4_address_t *) mp->dst_address,
3060 ntohl (mp->vrf_id), (int) (mp->is_add));
3062 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
3066 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
3068 stats_main_t *sm = &stats_main;
3069 vnet_interface_main_t *im = sm->interface_main;
3070 vl_api_vnet_summary_stats_reply_t *rmp;
3071 vlib_combined_counter_main_t *cm;
3074 u64 total_pkts[VLIB_N_RX_TX];
3075 u64 total_bytes[VLIB_N_RX_TX];
3077 unix_shared_memory_queue_t *q =
3078 vl_api_client_index_to_input_queue (mp->client_index);
3083 rmp = vl_msg_api_alloc (sizeof (*rmp));
3084 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
3085 rmp->context = mp->context;
3088 memset (total_pkts, 0, sizeof (total_pkts));
3089 memset (total_bytes, 0, sizeof (total_bytes));
3091 vnet_interface_counter_lock (im);
3093 vec_foreach (cm, im->combined_sw_if_counters)
3095 which = cm - im->combined_sw_if_counters;
3097 for (i = 0; i < vec_len (cm->maxi); i++)
3099 vlib_get_combined_counter (cm, i, &v);
3100 total_pkts[which] += v.packets;
3101 total_bytes[which] += v.bytes;
3104 vnet_interface_counter_unlock (im);
3106 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
3107 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
3108 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
3109 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
3111 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
3113 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3117 typedef CLIB_PACKED (struct {
3118 ip4_address_t address;
3119 u32 address_length: 6;
3125 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3127 vnet_main_t *vnm = vnet_get_main ();
3128 vnet_interface_main_t *im = &vnm->interface_main;
3129 ip4_main_t *im4 = &ip4_main;
3130 static u32 *sw_if_indices_to_shut;
3131 stats_main_t *sm = &stats_main;
3132 fib_table_t *fib_table;
3136 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3137 u32 target_fib_id = ntohl (mp->vrf_id);
3139 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
3142 pool_foreach (fib_table, im4->fibs,
3144 fib = &fib_table->v4;
3145 vnet_sw_interface_t * si;
3147 if (fib->table_id != target_fib_id)
3150 /* remove any mpls encap/decap labels */
3151 mpls_fib_reset_labels (fib->table_id);
3153 /* remove any proxy arps in this fib */
3154 vnet_proxy_arp_fib_reset (fib->table_id);
3156 /* Set the flow hash for this fib to the default */
3157 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3159 vec_reset_length (sw_if_indices_to_shut);
3161 /* Shut down interfaces in this FIB / clean out intfc routes */
3162 pool_foreach (si, im->sw_interfaces,
3164 u32 sw_if_index = si->sw_if_index;
3166 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
3167 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
3169 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3172 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3173 sw_if_index = sw_if_indices_to_shut[i];
3174 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3176 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3177 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3178 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3181 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
3182 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
3186 })); /* pool_foreach (fib) */
3194 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3196 vnet_main_t *vnm = vnet_get_main ();
3197 vnet_interface_main_t *im = &vnm->interface_main;
3198 ip6_main_t *im6 = &ip6_main;
3199 stats_main_t *sm = &stats_main;
3200 static u32 *sw_if_indices_to_shut;
3201 fib_table_t *fib_table;
3205 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3206 u32 target_fib_id = ntohl (mp->vrf_id);
3208 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3211 pool_foreach (fib_table, im6->fibs,
3213 vnet_sw_interface_t * si;
3214 fib = &(fib_table->v6);
3216 if (fib->table_id != target_fib_id)
3219 vec_reset_length (sw_if_indices_to_shut);
3221 /* Shut down interfaces in this FIB / clean out intfc routes */
3222 pool_foreach (si, im->sw_interfaces,
3224 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3226 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3229 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3230 sw_if_index = sw_if_indices_to_shut[i];
3231 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3233 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3234 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3235 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3238 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
3239 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
3243 })); /* pool_foreach (fib) */
3251 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3254 vl_api_reset_fib_reply_t *rmp;
3257 rv = ip6_reset_fib_t_handler (mp);
3259 rv = ip4_reset_fib_t_handler (mp);
3261 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3266 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3268 vl_api_dhcp_proxy_config_reply_t *rmp;
3271 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3272 (ip4_address_t *) (&mp->dhcp_src_address),
3273 (u32) ntohl (mp->vrf_id),
3274 (int) mp->insert_circuit_id,
3275 (int) (mp->is_add == 0));
3277 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3282 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3284 vl_api_dhcp_proxy_config_reply_t *rmp;
3287 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3288 (ip6_address_t *) (&mp->dhcp_src_address),
3289 (u32) ntohl (mp->vrf_id),
3290 (int) mp->insert_circuit_id,
3291 (int) (mp->is_add == 0));
3293 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3297 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3299 vl_api_dhcp_proxy_config_reply_t *rmp;
3302 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3303 (ip4_address_t *) (&mp->dhcp_src_address),
3304 (u32) ntohl (mp->rx_vrf_id),
3305 (u32) ntohl (mp->server_vrf_id),
3306 (int) mp->insert_circuit_id,
3307 (int) (mp->is_add == 0));
3309 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3314 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3316 vl_api_dhcp_proxy_config_reply_t *rmp;
3320 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3321 (ip6_address_t *) (&mp->dhcp_src_address),
3322 (u32) ntohl (mp->rx_vrf_id),
3323 (u32) ntohl (mp->server_vrf_id),
3324 (int) mp->insert_circuit_id,
3325 (int) (mp->is_add == 0));
3327 rv = VNET_API_ERROR_UNIMPLEMENTED;
3330 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3335 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3337 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3340 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3343 (int) mp->is_add == 0);
3345 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3347 ntohl (mp->fib_id), (int) mp->is_add == 0);
3349 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3353 static void vl_api_dhcp_proxy_config_t_handler
3354 (vl_api_dhcp_proxy_config_t * mp)
3356 if (mp->is_ipv6 == 0)
3357 dhcpv4_proxy_config (mp);
3359 dhcpv6_proxy_config (mp);
3362 static void vl_api_dhcp_proxy_config_2_t_handler
3363 (vl_api_dhcp_proxy_config_2_t * mp)
3365 if (mp->is_ipv6 == 0)
3366 dhcpv4_proxy_config_2 (mp);
3368 dhcpv6_proxy_config_2 (mp);
3372 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3373 u8 is_ipv6, u8 * host_address, u8 * router_address,
3376 unix_shared_memory_queue_t *q;
3377 vl_api_dhcp_compl_event_t *mp;
3379 q = vl_api_client_index_to_input_queue (client_index);
3383 mp = vl_msg_api_alloc (sizeof (*mp));
3384 mp->client_index = client_index;
3386 mp->is_ipv6 = is_ipv6;
3387 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3388 mp->hostname[vec_len (hostname) + 1] = '\n';
3389 clib_memcpy (&mp->host_address[0], host_address, 16);
3390 clib_memcpy (&mp->router_address[0], router_address, 16);
3392 if (NULL != host_mac)
3393 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3395 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3397 vl_msg_api_send_shmem (q, (u8 *) & mp);
3400 static void vl_api_dhcp_client_config_t_handler
3401 (vl_api_dhcp_client_config_t * mp)
3403 vlib_main_t *vm = vlib_get_main ();
3404 vl_api_dhcp_client_config_reply_t *rmp;
3407 VALIDATE_SW_IF_INDEX (mp);
3409 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3410 mp->hostname, mp->is_add, mp->client_index,
3411 mp->want_dhcp_event ? dhcp_compl_event_callback :
3414 BAD_SW_IF_INDEX_LABEL;
3416 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3420 vl_api_sw_interface_ip6nd_ra_config_t_handler
3421 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3423 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3425 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3428 is_no = mp->is_no == 1;
3429 suppress = mp->suppress == 1;
3430 managed = mp->managed == 1;
3431 other = mp->other == 1;
3432 ll_option = mp->ll_option == 1;
3433 send_unicast = mp->send_unicast == 1;
3434 cease = mp->cease == 1;
3435 default_router = mp->default_router == 1;
3437 VALIDATE_SW_IF_INDEX (mp);
3439 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3440 suppress, managed, other,
3441 ll_option, send_unicast, cease,
3442 default_router, ntohl (mp->lifetime),
3443 ntohl (mp->initial_count),
3444 ntohl (mp->initial_interval),
3445 ntohl (mp->max_interval),
3446 ntohl (mp->min_interval), is_no);
3448 BAD_SW_IF_INDEX_LABEL;
3450 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3454 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3455 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3457 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3459 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3461 VALIDATE_SW_IF_INDEX (mp);
3463 is_no = mp->is_no == 1;
3464 use_default = mp->use_default == 1;
3465 no_advertise = mp->no_advertise == 1;
3466 off_link = mp->off_link == 1;
3467 no_autoconfig = mp->no_autoconfig == 1;
3468 no_onlink = mp->no_onlink == 1;
3470 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3471 (ip6_address_t *) mp->address,
3472 mp->address_length, use_default,
3473 ntohl (mp->val_lifetime),
3474 ntohl (mp->pref_lifetime), no_advertise,
3475 off_link, no_autoconfig, no_onlink, is_no);
3477 BAD_SW_IF_INDEX_LABEL;
3478 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3482 vl_api_sw_interface_ip6_enable_disable_t_handler
3483 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3485 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3486 vnet_main_t *vnm = vnet_get_main ();
3488 clib_error_t *error;
3492 VALIDATE_SW_IF_INDEX (mp);
3495 (mp->enable == 1) ? enable_ip6_interface (vm,
3496 ntohl (mp->sw_if_index)) :
3497 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3501 clib_error_report (error);
3502 rv = VNET_API_ERROR_UNSPECIFIED;
3506 rv = vnm->api_errno;
3509 BAD_SW_IF_INDEX_LABEL;
3511 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3515 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3516 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3518 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3520 clib_error_t *error;
3521 vnet_main_t *vnm = vnet_get_main ();
3525 VALIDATE_SW_IF_INDEX (mp);
3527 error = set_ip6_link_local_address (vm,
3528 ntohl (mp->sw_if_index),
3529 (ip6_address_t *) mp->address,
3530 mp->address_length);
3533 clib_error_report (error);
3534 rv = VNET_API_ERROR_UNSPECIFIED;
3538 rv = vnm->api_errno;
3541 BAD_SW_IF_INDEX_LABEL;
3543 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3547 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3549 vl_api_set_ip_flow_hash_reply_t *rmp;
3550 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3552 clib_warning ("unimplemented...");
3554 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3558 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3560 vl_api_set_ip_flow_hash_reply_t *rmp;
3563 flow_hash_config_t flow_hash_config = 0;
3565 table_id = ntohl (mp->vrf_id);
3567 #define _(a,b) if (mp->a) flow_hash_config |= b;
3568 foreach_flow_hash_bit;
3571 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3573 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3578 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3580 if (mp->is_ipv6 == 0)
3581 set_ip4_flow_hash (mp);
3583 set_ip6_flow_hash (mp);
3586 static void vl_api_sw_interface_set_unnumbered_t_handler
3587 (vl_api_sw_interface_set_unnumbered_t * mp)
3589 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3591 vnet_sw_interface_t *si;
3592 vnet_main_t *vnm = vnet_get_main ();
3593 u32 sw_if_index, unnumbered_sw_if_index;
3595 sw_if_index = ntohl (mp->sw_if_index);
3596 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3599 * The API message field names are backwards from
3600 * the underlying data structure names.
3601 * It's not worth changing them now.
3603 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3604 unnumbered_sw_if_index))
3606 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3610 /* Only check the "use loop0" field when setting the binding */
3612 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3614 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3618 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3622 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3623 si->unnumbered_sw_if_index = sw_if_index;
3624 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3625 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3629 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3630 si->unnumbered_sw_if_index = (u32) ~ 0;
3631 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3632 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3636 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3640 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3642 vl_api_create_loopback_reply_t *rmp;
3646 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3649 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3651 rmp->sw_if_index = ntohl (sw_if_index);
3657 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3659 vl_api_delete_loopback_reply_t *rmp;
3663 sw_if_index = ntohl (mp->sw_if_index);
3664 rv = vnet_delete_loopback_interface (sw_if_index);
3666 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3670 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3672 vl_api_control_ping_reply_t *rmp;
3676 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3678 rmp->vpe_pid = ntohl (getpid());
3684 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3686 u8 **shmem_vecp = (u8 **) arg;
3689 api_main_t *am = &api_main;
3692 shmem_vec = *shmem_vecp;
3694 offset = vec_len (shmem_vec);
3696 pthread_mutex_lock (&am->vlib_rp->mutex);
3697 oldheap = svm_push_data_heap (am->vlib_rp);
3699 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3701 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3703 svm_pop_heap (oldheap);
3704 pthread_mutex_unlock (&am->vlib_rp->mutex);
3706 *shmem_vecp = shmem_vec;
3711 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3713 vl_api_cli_reply_t *rp;
3714 unix_shared_memory_queue_t *q;
3715 vlib_main_t *vm = vlib_get_main ();
3716 api_main_t *am = &api_main;
3717 unformat_input_t input;
3721 q = vl_api_client_index_to_input_queue (mp->client_index);
3725 rp = vl_msg_api_alloc (sizeof (*rp));
3726 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3727 rp->context = mp->context;
3729 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3731 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3733 pthread_mutex_lock (&am->vlib_rp->mutex);
3734 oldheap = svm_push_data_heap (am->vlib_rp);
3736 vec_add1 (shmem_vec, 0);
3738 svm_pop_heap (oldheap);
3739 pthread_mutex_unlock (&am->vlib_rp->mutex);
3741 rp->reply_in_shmem = (uword) shmem_vec;
3743 vl_msg_api_send_shmem (q, (u8 *) & rp);
3747 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3749 u8 **mem_vecp = (u8 **) arg;
3750 u8 *mem_vec = *mem_vecp;
3751 u32 offset = vec_len (mem_vec);
3753 vec_validate (mem_vec, offset + buffer_bytes - 1);
3754 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3755 *mem_vecp = mem_vec;
3759 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3761 vl_api_cli_inband_reply_t *rmp;
3763 unix_shared_memory_queue_t *q;
3764 vlib_main_t *vm = vlib_get_main ();
3765 unformat_input_t input;
3768 q = vl_api_client_index_to_input_queue (mp->client_index);
3772 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3773 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3775 u32 len = vec_len (out_vec);
3777 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3779 rmp->length = htonl (len);
3780 clib_memcpy (rmp->reply, out_vec, len);
3787 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3790 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3791 vnet_main_t *vnm = vnet_get_main ();
3792 clib_error_t *error;
3797 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3799 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3803 clib_error_report (error);
3804 rv = VNET_API_ERROR_UNSPECIFIED;
3808 rv = vnm->api_errno;
3811 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3814 static void vl_api_sr_tunnel_add_del_t_handler
3815 (vl_api_sr_tunnel_add_del_t * mp)
3818 clib_warning ("unimplemented");
3820 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3822 vl_api_sr_tunnel_add_del_reply_t *rmp;
3823 ip6_address_t *segments = 0, *seg;
3824 ip6_address_t *tags = 0, *tag;
3825 ip6_address_t *this_address;
3828 if (mp->n_segments == 0)
3834 memset (a, 0, sizeof (*a));
3835 a->src_address = (ip6_address_t *) & mp->src_address;
3836 a->dst_address = (ip6_address_t *) & mp->dst_address;
3837 a->dst_mask_width = mp->dst_mask_width;
3838 a->flags_net_byte_order = mp->flags_net_byte_order;
3839 a->is_del = (mp->is_add == 0);
3840 a->rx_table_id = ntohl (mp->outer_vrf_id);
3841 a->tx_table_id = ntohl (mp->inner_vrf_id);
3843 a->name = format (0, "%s", mp->name);
3844 if (!(vec_len (a->name)))
3847 a->policy_name = format (0, "%s", mp->policy_name);
3848 if (!(vec_len (a->policy_name)))
3851 /* Yank segments and tags out of the API message */
3852 this_address = (ip6_address_t *) mp->segs_and_tags;
3853 for (i = 0; i < mp->n_segments; i++)
3855 vec_add2 (segments, seg, 1);
3856 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3859 for (i = 0; i < mp->n_tags; i++)
3861 vec_add2 (tags, tag, 1);
3862 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3866 a->segments = segments;
3869 rv = ip6_sr_add_del_tunnel (a);
3873 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3877 static void vl_api_sr_policy_add_del_t_handler
3878 (vl_api_sr_policy_add_del_t * mp)
3881 clib_warning ("unimplemented");
3883 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3885 vl_api_sr_policy_add_del_reply_t *rmp;
3888 memset (a, 0, sizeof (*a));
3889 a->is_del = (mp->is_add == 0);
3891 a->name = format (0, "%s", mp->name);
3892 if (!(vec_len (a->name)))
3894 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3898 if (!(mp->tunnel_names[0]))
3900 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3904 // start deserializing tunnel_names
3905 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3906 u8 *deser_tun_names = mp->tunnel_names;
3907 deser_tun_names += 1; //moving along
3910 int tun_name_len = 0;
3912 for (i = 0; i < num_tunnels; i++)
3914 tun_name_len = *deser_tun_names;
3915 deser_tun_names += 1;
3916 vec_resize (tun_name, tun_name_len);
3917 memcpy (tun_name, deser_tun_names, tun_name_len);
3918 vec_add1 (a->tunnel_names, tun_name);
3919 deser_tun_names += tun_name_len;
3923 rv = ip6_sr_add_del_policy (a);
3927 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3931 static void vl_api_sr_multicast_map_add_del_t_handler
3932 (vl_api_sr_multicast_map_add_del_t * mp)
3935 clib_warning ("unimplemented");
3937 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3939 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3941 memset (a, 0, sizeof (*a));
3942 a->is_del = (mp->is_add == 0);
3944 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3945 a->policy_name = format (0, "%s", mp->policy_name);
3947 if (a->multicast_address == 0)
3953 if (!(a->policy_name))
3959 #if DPDK > 0 /* Cannot call replicate without DPDK */
3960 rv = ip6_sr_add_del_multicastmap (a);
3962 clib_warning ("multicast replication without DPDK not implemented");
3963 rv = VNET_API_ERROR_UNIMPLEMENTED;
3968 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3972 #define foreach_classify_add_del_table_field \
3977 _(match_n_vectors) \
3978 _(next_table_index) \
3981 static void vl_api_classify_add_del_table_t_handler
3982 (vl_api_classify_add_del_table_t * mp)
3984 vl_api_classify_add_del_table_reply_t *rmp;
3985 vnet_classify_main_t *cm = &vnet_classify_main;
3986 vnet_classify_table_t *t;
3990 foreach_classify_add_del_table_field;
3993 #define _(a) a = ntohl(mp->a);
3994 foreach_classify_add_del_table_field;
3997 /* The underlying API fails silently, on purpose, so check here */
3998 if (mp->is_add == 0)
3999 if (pool_is_free_index (cm->tables, table_index))
4001 rv = VNET_API_ERROR_NO_SUCH_TABLE;
4005 rv = vnet_classify_add_del_table
4006 (cm, mp->mask, nbuckets, memory_size,
4007 skip_n_vectors, match_n_vectors,
4008 next_table_index, miss_next_index, &table_index, mp->is_add);
4012 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
4014 if (rv == 0 && mp->is_add)
4016 t = pool_elt_at_index (cm->tables, table_index);
4017 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
4018 rmp->match_n_vectors = ntohl(t->match_n_vectors);
4019 rmp->new_table_index = ntohl(table_index);
4023 rmp->skip_n_vectors = ~0;
4024 rmp->match_n_vectors = ~0;
4025 rmp->new_table_index = ~0;
4031 static void vl_api_classify_add_del_session_t_handler
4032 (vl_api_classify_add_del_session_t * mp)
4034 vnet_classify_main_t *cm = &vnet_classify_main;
4035 vl_api_classify_add_del_session_reply_t *rmp;
4037 u32 table_index, hit_next_index, opaque_index;
4040 table_index = ntohl (mp->table_index);
4041 hit_next_index = ntohl (mp->hit_next_index);
4042 opaque_index = ntohl (mp->opaque_index);
4043 advance = ntohl (mp->advance);
4045 rv = vnet_classify_add_del_session
4046 (cm, table_index, mp->match, hit_next_index, opaque_index,
4047 advance, mp->is_add);
4049 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
4052 static void vl_api_classify_set_interface_ip_table_t_handler
4053 (vl_api_classify_set_interface_ip_table_t * mp)
4055 vlib_main_t *vm = vlib_get_main ();
4056 vl_api_classify_set_interface_ip_table_reply_t *rmp;
4058 u32 table_index, sw_if_index;
4060 table_index = ntohl (mp->table_index);
4061 sw_if_index = ntohl (mp->sw_if_index);
4063 VALIDATE_SW_IF_INDEX (mp);
4066 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
4068 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
4070 BAD_SW_IF_INDEX_LABEL;
4072 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
4075 static void vl_api_classify_set_interface_l2_tables_t_handler
4076 (vl_api_classify_set_interface_l2_tables_t * mp)
4078 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
4080 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
4083 ip4_table_index = ntohl (mp->ip4_table_index);
4084 ip6_table_index = ntohl (mp->ip6_table_index);
4085 other_table_index = ntohl (mp->other_table_index);
4086 sw_if_index = ntohl (mp->sw_if_index);
4088 VALIDATE_SW_IF_INDEX (mp);
4091 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
4095 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
4101 if (ip4_table_index != ~0 || ip6_table_index != ~0
4102 || other_table_index != ~0)
4108 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
4110 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
4113 BAD_SW_IF_INDEX_LABEL;
4115 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
4119 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
4122 vl_api_l2_fib_clear_table_reply_t *rmp;
4124 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
4125 * that is not currently implemented. When that TODO is fixed
4126 * this call should be changed to pass 1 instead of 0.
4128 l2fib_clear_table (0);
4130 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
4133 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
4134 u32 sw_if_index, u32 enable);
4137 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
4141 vl_api_l2_interface_efp_filter_reply_t *rmp;
4142 vnet_main_t *vnm = vnet_get_main ();
4144 // enable/disable the feature
4145 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
4146 rv = vnm->api_errno;
4148 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
4152 vl_api_l2_interface_vlan_tag_rewrite_t_handler
4153 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
4156 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
4157 vnet_main_t *vnm = vnet_get_main ();
4158 vlib_main_t *vm = vlib_get_main ();
4161 VALIDATE_SW_IF_INDEX (mp);
4163 vtr_op = ntohl (mp->vtr_op);
4165 /* The L2 code is unsuspicious */
4168 case L2_VTR_DISABLED:
4173 case L2_VTR_TRANSLATE_1_1:
4174 case L2_VTR_TRANSLATE_1_2:
4175 case L2_VTR_TRANSLATE_2_1:
4176 case L2_VTR_TRANSLATE_2_2:
4180 rv = VNET_API_ERROR_INVALID_VALUE;
4181 goto bad_sw_if_index;
4184 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4185 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4188 BAD_SW_IF_INDEX_LABEL;
4190 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4194 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4197 vl_api_create_vhost_user_if_reply_t *rmp;
4198 u32 sw_if_index = (u32) ~ 0;
4200 vnet_main_t *vnm = vnet_get_main ();
4201 vlib_main_t *vm = vlib_get_main ();
4203 #if DPDK > 0 && DPDK_VHOST_USER
4204 rv = dpdk_vhost_user_create_if (
4206 rv = vhost_user_create_if (
4208 vnm, vm, (char *) mp->sock_filename,
4209 mp->is_server, &sw_if_index, (u64) ~ 0,
4210 mp->renumber, ntohl (mp->custom_dev_instance),
4211 (mp->use_custom_mac) ? mp->mac_address : NULL);
4214 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4216 rmp->sw_if_index = ntohl (sw_if_index);
4222 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4225 vl_api_modify_vhost_user_if_reply_t *rmp;
4226 u32 sw_if_index = ntohl (mp->sw_if_index);
4228 vnet_main_t *vnm = vnet_get_main ();
4229 vlib_main_t *vm = vlib_get_main ();
4231 #if DPDK > 0 && DPDK_VHOST_USER
4232 rv = dpdk_vhost_user_modify_if (
4234 rv = vhost_user_modify_if (
4236 vnm, vm, (char *) mp->sock_filename,
4237 mp->is_server, sw_if_index, (u64) ~ 0,
4238 mp->renumber, ntohl (mp->custom_dev_instance));
4239 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4243 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4246 vl_api_delete_vhost_user_if_reply_t *rmp;
4247 vpe_api_main_t *vam = &vpe_api_main;
4248 u32 sw_if_index = ntohl (mp->sw_if_index);
4250 vnet_main_t *vnm = vnet_get_main ();
4251 vlib_main_t *vm = vlib_get_main ();
4253 #if DPDK > 0 && DPDK_VHOST_USER
4254 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4256 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4259 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4262 unix_shared_memory_queue_t *q =
4263 vl_api_client_index_to_input_queue (mp->client_index);
4267 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4272 vl_api_sw_interface_vhost_user_details_t_handler
4273 (vl_api_sw_interface_vhost_user_details_t * mp)
4275 clib_warning ("BUG");
4279 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4280 unix_shared_memory_queue_t * q,
4281 vhost_user_intf_details_t * vui,
4284 vl_api_sw_interface_vhost_user_details_t *mp;
4286 mp = vl_msg_api_alloc (sizeof (*mp));
4287 memset (mp, 0, sizeof (*mp));
4288 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4289 mp->sw_if_index = ntohl (vui->sw_if_index);
4290 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4291 mp->features = clib_net_to_host_u64 (vui->features);
4292 mp->is_server = vui->is_server;
4293 mp->num_regions = ntohl (vui->num_regions);
4294 mp->sock_errno = ntohl (vui->sock_errno);
4295 mp->context = context;
4297 strncpy ((char *) mp->sock_filename,
4298 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4299 strncpy ((char *) mp->interface_name,
4300 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4302 vl_msg_api_send_shmem (q, (u8 *) & mp);
4306 vl_api_sw_interface_vhost_user_dump_t_handler
4307 (vl_api_sw_interface_vhost_user_dump_t * mp)
4310 vpe_api_main_t *am = &vpe_api_main;
4311 vnet_main_t *vnm = vnet_get_main ();
4312 vlib_main_t *vm = vlib_get_main ();
4313 vhost_user_intf_details_t *ifaces = NULL;
4314 vhost_user_intf_details_t *vuid = NULL;
4315 unix_shared_memory_queue_t *q;
4317 q = vl_api_client_index_to_input_queue (mp->client_index);
4321 #if DPDK > 0 && DPDK_VHOST_USER
4322 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4324 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4329 vec_foreach (vuid, ifaces)
4331 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4337 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4338 unix_shared_memory_queue_t * q,
4340 l2t_main_t * lm, u32 context)
4342 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4344 vnet_sw_interface_t *si = NULL;
4346 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4348 if_name = format (if_name, "%U",
4349 format_vnet_sw_interface_name, lm->vnet_main, si);
4351 mp = vl_msg_api_alloc (sizeof (*mp));
4352 memset (mp, 0, sizeof (*mp));
4353 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4354 strncpy ((char *) mp->interface_name,
4355 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4356 mp->sw_if_index = ntohl (si->sw_if_index);
4357 mp->local_session_id = s->local_session_id;
4358 mp->remote_session_id = s->remote_session_id;
4359 mp->local_cookie[0] = s->local_cookie[0];
4360 mp->local_cookie[1] = s->local_cookie[1];
4361 mp->remote_cookie = s->remote_cookie;
4362 clib_memcpy (mp->client_address, &s->client_address,
4363 sizeof (s->client_address));
4364 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4365 mp->l2_sublayer_present = s->l2_sublayer_present;
4366 mp->context = context;
4368 vl_msg_api_send_shmem (q, (u8 *) & mp);
4372 send_ip_address_details (vpe_api_main_t * am,
4373 unix_shared_memory_queue_t * q,
4374 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4376 vl_api_ip_address_details_t *mp;
4378 mp = vl_msg_api_alloc (sizeof (*mp));
4379 memset (mp, 0, sizeof (*mp));
4380 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4384 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4388 u32 *tp = (u32 *) mp->ip;
4389 *tp = ntohl (*(u32 *) ip);
4391 mp->prefix_length = prefix_length;
4392 mp->context = context;
4394 vl_msg_api_send_shmem (q, (u8 *) & mp);
4398 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4400 vpe_api_main_t *am = &vpe_api_main;
4401 unix_shared_memory_queue_t *q;
4404 ip6_main_t *im6 = &ip6_main;
4405 ip4_main_t *im4 = &ip4_main;
4406 ip_lookup_main_t *lm6 = &im6->lookup_main;
4407 ip_lookup_main_t *lm4 = &im4->lookup_main;
4408 ip_interface_address_t *ia = 0;
4409 u32 sw_if_index = ~0;
4410 int rv __attribute__ ((unused)) = 0;
4412 VALIDATE_SW_IF_INDEX (mp);
4414 sw_if_index = ntohl (mp->sw_if_index);
4416 q = vl_api_client_index_to_input_queue (mp->client_index);
4425 foreach_ip_interface_address (lm6, ia, sw_if_index,
4426 1 /* honor unnumbered */,
4428 r6 = ip_interface_address_get_address (lm6, ia);
4429 u16 prefix_length = ia->address_length;
4430 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4437 foreach_ip_interface_address (lm4, ia, sw_if_index,
4438 1 /* honor unnumbered */,
4440 r4 = ip_interface_address_get_address (lm4, ia);
4441 u16 prefix_length = ia->address_length;
4442 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4446 BAD_SW_IF_INDEX_LABEL;
4450 send_ip_details (vpe_api_main_t * am,
4451 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4453 vl_api_ip_details_t *mp;
4455 mp = vl_msg_api_alloc (sizeof (*mp));
4456 memset (mp, 0, sizeof (*mp));
4457 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4459 mp->sw_if_index = ntohl (sw_if_index);
4460 mp->context = context;
4462 vl_msg_api_send_shmem (q, (u8 *) & mp);
4466 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4469 vpe_api_main_t *am = &vpe_api_main;
4470 l2t_main_t *lm = &l2t_main;
4471 unix_shared_memory_queue_t *q;
4472 l2t_session_t *session;
4474 q = vl_api_client_index_to_input_queue (mp->client_index);
4479 pool_foreach (session, lm->sessions,
4481 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4488 send_sw_interface_tap_details (vpe_api_main_t * am,
4489 unix_shared_memory_queue_t * q,
4490 tapcli_interface_details_t * tap_if,
4493 vl_api_sw_interface_tap_details_t *mp;
4494 mp = vl_msg_api_alloc (sizeof (*mp));
4495 memset (mp, 0, sizeof (*mp));
4496 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4497 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4498 strncpy ((char *) mp->dev_name,
4499 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4500 mp->context = context;
4502 vl_msg_api_send_shmem (q, (u8 *) & mp);
4506 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4509 vpe_api_main_t *am = &vpe_api_main;
4510 unix_shared_memory_queue_t *q;
4511 tapcli_interface_details_t *tapifs = NULL;
4512 tapcli_interface_details_t *tap_if = NULL;
4514 q = vl_api_client_index_to_input_queue (mp->client_index);
4518 rv = vnet_tap_dump_ifs (&tapifs);
4522 vec_foreach (tap_if, tapifs)
4524 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4531 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4533 vpe_api_main_t *am = &vpe_api_main;
4534 vnet_main_t *vnm = vnet_get_main ();
4535 vlib_main_t *vm = vlib_get_main ();
4536 vnet_interface_main_t *im = &vnm->interface_main;
4537 unix_shared_memory_queue_t *q;
4538 vnet_sw_interface_t *si, *sorted_sis;
4539 u32 sw_if_index = ~0;
4541 q = vl_api_client_index_to_input_queue (mp->client_index);
4547 /* Gather interfaces. */
4548 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4549 _vec_len (sorted_sis) = 0;
4551 pool_foreach (si, im->sw_interfaces,
4553 vec_add1 (sorted_sis, si[0]);
4557 vec_foreach (si, sorted_sis)
4559 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4561 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4565 sw_if_index = si->sw_if_index;
4566 send_ip_details (am, q, sw_if_index, mp->context);
4572 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4574 clib_warning ("BUG");
4578 send_l2fib_table_entry (vpe_api_main_t * am,
4579 unix_shared_memory_queue_t * q,
4580 l2fib_entry_key_t * l2fe_key,
4581 l2fib_entry_result_t * l2fe_res, u32 context)
4583 vl_api_l2_fib_table_entry_t *mp;
4585 mp = vl_msg_api_alloc (sizeof (*mp));
4586 memset (mp, 0, sizeof (*mp));
4587 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4590 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4592 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4593 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4594 mp->static_mac = l2fe_res->fields.static_mac;
4595 mp->filter_mac = l2fe_res->fields.filter;
4596 mp->bvi_mac = l2fe_res->fields.bvi;
4597 mp->context = context;
4599 vl_msg_api_send_shmem (q, (u8 *) & mp);
4603 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4605 vpe_api_main_t *am = &vpe_api_main;
4606 bd_main_t *bdm = &bd_main;
4607 l2fib_entry_key_t *l2fe_key = NULL;
4608 l2fib_entry_result_t *l2fe_res = NULL;
4609 u32 ni, bd_id = ntohl (mp->bd_id);
4611 unix_shared_memory_queue_t *q;
4614 q = vl_api_client_index_to_input_queue (mp->client_index);
4618 /* see l2fib_table_dump: ~0 means "any" */
4623 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4630 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4632 vec_foreach_index (ni, l2fe_key)
4634 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4635 vec_elt_at_index (l2fe_res, ni), mp->context);
4637 vec_free (l2fe_key);
4638 vec_free (l2fe_res);
4642 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4644 vl_api_show_version_reply_t *rmp;
4646 char *vpe_api_get_build_directory (void);
4647 char *vpe_api_get_version (void);
4648 char *vpe_api_get_build_date (void);
4650 unix_shared_memory_queue_t *q =
4651 vl_api_client_index_to_input_queue (mp->client_index);
4657 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4659 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4660 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4661 ARRAY_LEN(rmp->build_directory)-1);
4662 strncpy ((char *) rmp->version, vpe_api_get_version(),
4663 ARRAY_LEN(rmp->version)-1);
4664 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4665 ARRAY_LEN(rmp->build_date)-1);
4671 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4673 vlib_main_t *vm = vlib_get_main ();
4674 vl_api_get_node_index_reply_t *rmp;
4677 u32 node_index = ~0;
4679 n = vlib_get_node_by_name (vm, mp->node_name);
4682 rv = VNET_API_ERROR_NO_SUCH_NODE;
4684 node_index = n->index;
4687 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4689 rmp->node_index = ntohl(node_index);
4695 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4697 vlib_main_t *vm = vlib_get_main ();
4698 vl_api_get_next_index_reply_t *rmp;
4699 vlib_node_t *node, *next_node;
4701 u32 next_node_index = ~0, next_index = ~0;
4704 node = vlib_get_node_by_name (vm, mp->node_name);
4708 rv = VNET_API_ERROR_NO_SUCH_NODE;
4712 next_node = vlib_get_node_by_name (vm, mp->next_name);
4716 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4720 next_node_index = next_node->index;
4722 p = hash_get (node->next_slot_by_node, next_node_index);
4726 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4734 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4736 rmp->next_index = ntohl(next_index);
4742 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4744 vlib_main_t *vm = vlib_get_main ();
4745 vl_api_add_node_next_reply_t *rmp;
4746 vlib_node_t *n, *next;
4748 u32 next_index = ~0;
4750 n = vlib_get_node_by_name (vm, mp->node_name);
4754 rv = VNET_API_ERROR_NO_SUCH_NODE;
4758 next = vlib_get_node_by_name (vm, mp->next_name);
4761 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4763 next_index = vlib_node_add_next (vm, n->index, next->index);
4767 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4769 rmp->next_index = ntohl(next_index);
4774 static void vl_api_l2tpv3_create_tunnel_t_handler
4775 (vl_api_l2tpv3_create_tunnel_t * mp)
4777 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4778 l2t_main_t *lm = &l2t_main;
4779 u32 sw_if_index = (u32) ~ 0;
4782 if (mp->is_ipv6 != 1)
4784 rv = VNET_API_ERROR_UNIMPLEMENTED;
4788 u32 encap_fib_index;
4790 if (mp->encap_vrf_id != ~0)
4793 ip6_main_t *im = &ip6_main;
4796 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4798 rv = VNET_API_ERROR_NO_SUCH_FIB;
4801 encap_fib_index = p[0];
4805 encap_fib_index = ~0;
4808 rv = create_l2tpv3_ipv6_tunnel (lm,
4809 (ip6_address_t *) mp->client_address,
4810 (ip6_address_t *) mp->our_address,
4811 ntohl (mp->local_session_id),
4812 ntohl (mp->remote_session_id),
4813 clib_net_to_host_u64 (mp->local_cookie),
4814 clib_net_to_host_u64 (mp->remote_cookie),
4815 mp->l2_sublayer_present,
4816 encap_fib_index, &sw_if_index);
4820 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4822 rmp->sw_if_index = ntohl (sw_if_index);
4827 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4828 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4830 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4831 l2t_main_t *lm = &l2t_main;
4834 VALIDATE_SW_IF_INDEX (mp);
4836 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4837 clib_net_to_host_u64 (mp->new_local_cookie),
4838 clib_net_to_host_u64
4839 (mp->new_remote_cookie));
4841 BAD_SW_IF_INDEX_LABEL;
4843 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4846 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4847 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4850 vnet_main_t *vnm = vnet_get_main ();
4851 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4853 VALIDATE_SW_IF_INDEX (mp);
4855 rv = l2tpv3_interface_enable_disable
4856 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4858 BAD_SW_IF_INDEX_LABEL;
4860 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4863 static void vl_api_l2tpv3_set_lookup_key_t_handler
4864 (vl_api_l2tpv3_set_lookup_key_t * mp)
4867 l2t_main_t *lm = &l2t_main;
4868 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4870 if (mp->key > L2T_LOOKUP_SESSION_ID)
4872 rv = VNET_API_ERROR_INVALID_VALUE;
4876 lm->lookup_type = mp->key;
4879 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4882 static void vl_api_vxlan_add_del_tunnel_t_handler
4883 (vl_api_vxlan_add_del_tunnel_t * mp)
4885 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4887 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4888 u32 encap_fib_index;
4890 ip4_main_t *im = &ip4_main;
4891 u32 sw_if_index = ~0;
4893 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4896 rv = VNET_API_ERROR_NO_SUCH_FIB;
4899 encap_fib_index = p[0];
4901 /* Check src & dst are different */
4902 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4903 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4905 rv = VNET_API_ERROR_SAME_SRC_DST;
4908 memset (a, 0, sizeof (*a));
4910 a->is_add = mp->is_add;
4911 a->is_ip6 = mp->is_ipv6;
4913 /* ip addresses sent in network byte order */
4916 memcpy (&(a->src.ip6), mp->src_address, 16);
4917 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4921 memcpy (&(a->src.ip4), mp->src_address, 4);
4922 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4925 a->encap_fib_index = encap_fib_index;
4926 a->decap_next_index = ntohl (mp->decap_next_index);
4927 a->vni = ntohl (mp->vni);
4928 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4932 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4934 rmp->sw_if_index = ntohl (sw_if_index);
4939 static void send_vxlan_tunnel_details
4940 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4942 vl_api_vxlan_tunnel_details_t *rmp;
4943 ip4_main_t *im4 = &ip4_main;
4944 ip6_main_t *im6 = &ip6_main;
4945 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4947 rmp = vl_msg_api_alloc (sizeof (*rmp));
4948 memset (rmp, 0, sizeof (*rmp));
4949 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4952 memcpy (rmp->src_address, &(t->src.ip6), 16);
4953 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4954 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4958 memcpy (rmp->src_address, &(t->src.ip4), 4);
4959 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4960 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4962 rmp->vni = htonl (t->vni);
4963 rmp->decap_next_index = htonl (t->decap_next_index);
4964 rmp->sw_if_index = htonl (t->sw_if_index);
4965 rmp->is_ipv6 = is_ipv6;
4966 rmp->context = context;
4968 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4971 static void vl_api_vxlan_tunnel_dump_t_handler
4972 (vl_api_vxlan_tunnel_dump_t * mp)
4974 unix_shared_memory_queue_t *q;
4975 vxlan_main_t *vxm = &vxlan_main;
4979 q = vl_api_client_index_to_input_queue (mp->client_index);
4985 sw_if_index = ntohl (mp->sw_if_index);
4987 if (~0 == sw_if_index)
4990 pool_foreach (t, vxm->tunnels,
4992 send_vxlan_tunnel_details(t, q, mp->context);
4998 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4999 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
5003 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
5004 send_vxlan_tunnel_details (t, q, mp->context);
5008 static void vl_api_gre_add_del_tunnel_t_handler
5009 (vl_api_gre_add_del_tunnel_t * mp)
5011 vl_api_gre_add_del_tunnel_reply_t *rmp;
5013 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
5016 ip4_main_t *im = &ip4_main;
5017 u32 sw_if_index = ~0;
5019 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
5022 rv = VNET_API_ERROR_NO_SUCH_FIB;
5025 outer_fib_id = p[0];
5027 /* Check src & dst are different */
5028 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
5029 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
5031 rv = VNET_API_ERROR_SAME_SRC_DST;
5034 memset (a, 0, sizeof (*a));
5036 a->is_add = mp->is_add;
5039 /* ip addresses sent in network byte order */
5040 clib_memcpy (&(a->src), mp->src_address, 4);
5041 clib_memcpy (&(a->dst), mp->dst_address, 4);
5043 a->outer_fib_id = outer_fib_id;
5044 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
5048 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
5050 rmp->sw_if_index = ntohl (sw_if_index);
5055 static void send_gre_tunnel_details
5056 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5058 vl_api_gre_tunnel_details_t *rmp;
5059 ip4_main_t *im = &ip4_main;
5061 rmp = vl_msg_api_alloc (sizeof (*rmp));
5062 memset (rmp, 0, sizeof (*rmp));
5063 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
5064 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
5065 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
5066 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
5068 rmp->sw_if_index = htonl (t->sw_if_index);
5069 rmp->context = context;
5071 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5075 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
5077 unix_shared_memory_queue_t *q;
5078 gre_main_t *gm = &gre_main;
5082 q = vl_api_client_index_to_input_queue (mp->client_index);
5088 sw_if_index = ntohl (mp->sw_if_index);
5090 if (~0 == sw_if_index)
5093 pool_foreach (t, gm->tunnels,
5095 send_gre_tunnel_details(t, q, mp->context);
5101 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
5102 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
5106 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
5107 send_gre_tunnel_details (t, q, mp->context);
5112 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
5114 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5116 vl_api_l2_patch_add_del_reply_t *rmp;
5117 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5121 VALIDATE_RX_SW_IF_INDEX (mp);
5122 VALIDATE_TX_SW_IF_INDEX (mp);
5124 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
5125 ntohl (mp->tx_sw_if_index),
5126 (int) (mp->is_add != 0));
5128 BAD_RX_SW_IF_INDEX_LABEL;
5129 BAD_TX_SW_IF_INDEX_LABEL;
5131 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
5135 vl_api_vxlan_gpe_add_del_tunnel_t_handler
5136 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
5138 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
5140 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
5141 u32 encap_fib_index, decap_fib_index;
5144 ip4_main_t *im = &ip4_main;
5145 u32 sw_if_index = ~0;
5148 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
5151 rv = VNET_API_ERROR_NO_SUCH_FIB;
5154 encap_fib_index = p[0];
5156 protocol = mp->protocol;
5158 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
5159 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
5161 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
5164 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
5167 decap_fib_index = p[0];
5171 decap_fib_index = ntohl (mp->decap_vrf_id);
5174 /* Check src & dst are different */
5175 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5176 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5178 rv = VNET_API_ERROR_SAME_SRC_DST;
5181 memset (a, 0, sizeof (*a));
5183 a->is_add = mp->is_add;
5184 a->is_ip6 = mp->is_ipv6;
5185 /* ip addresses sent in network byte order */
5188 clib_memcpy (&(a->local.ip6), mp->local, 16);
5189 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5193 clib_memcpy (&(a->local.ip4), mp->local, 4);
5194 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5196 a->encap_fib_index = encap_fib_index;
5197 a->decap_fib_index = decap_fib_index;
5198 a->protocol = protocol;
5199 a->vni = ntohl (mp->vni);
5200 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5204 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5206 rmp->sw_if_index = ntohl (sw_if_index);
5211 static void send_vxlan_gpe_tunnel_details
5212 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5214 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5215 ip4_main_t *im4 = &ip4_main;
5216 ip6_main_t *im6 = &ip6_main;
5217 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5219 rmp = vl_msg_api_alloc (sizeof (*rmp));
5220 memset (rmp, 0, sizeof (*rmp));
5221 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5224 memcpy (rmp->local, &(t->local.ip6), 16);
5225 memcpy (rmp->remote, &(t->remote.ip6), 16);
5226 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
5227 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
5231 memcpy (rmp->local, &(t->local.ip4), 4);
5232 memcpy (rmp->remote, &(t->remote.ip4), 4);
5233 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
5234 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
5236 rmp->vni = htonl (t->vni);
5237 rmp->protocol = t->protocol;
5238 rmp->sw_if_index = htonl (t->sw_if_index);
5239 rmp->is_ipv6 = is_ipv6;
5240 rmp->context = context;
5242 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5245 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5246 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5248 unix_shared_memory_queue_t *q;
5249 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5250 vxlan_gpe_tunnel_t *t;
5253 q = vl_api_client_index_to_input_queue (mp->client_index);
5259 sw_if_index = ntohl (mp->sw_if_index);
5261 if (~0 == sw_if_index)
5264 pool_foreach (t, vgm->tunnels,
5266 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5272 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5273 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5277 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5278 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5282 /** Used for transferring locators via VPP API */
5284 typedef CLIB_PACKED (struct {
5285 u32 sw_if_index; /**< locator sw_if_index */
5286 u8 priority; /**< locator priority */
5287 u8 weight; /**< locator weight */
5292 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5295 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5297 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5299 ls_locator_t *ls_loc;
5300 u32 ls_index = ~0, locator_num;
5301 u8 *locator_name = NULL;
5304 memset (a, 0, sizeof (a[0]));
5306 locator_name = format (0, "%s", mp->locator_set_name);
5308 a->name = locator_name;
5309 a->is_add = mp->is_add;
5311 locator_num = clib_net_to_host_u32 (mp->locator_num);
5313 memset (&locator, 0, sizeof (locator));
5314 for (i = 0; i < locator_num; i++)
5316 ls_loc = &((ls_locator_t *) mp->locators)[i];
5317 VALIDATE_SW_IF_INDEX (ls_loc);
5319 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5320 locator.priority = ls_loc->priority;
5321 locator.weight = ls_loc->weight;
5323 vec_add1 (a->locators, locator);
5326 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5328 BAD_SW_IF_INDEX_LABEL;
5330 vec_free (locator_name);
5331 vec_free (a->locators);
5334 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5336 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5342 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5344 vl_api_lisp_add_del_locator_reply_t *rmp;
5346 locator_t locator, *locators = NULL;
5347 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5349 u8 *locator_name = NULL;
5351 memset (&locator, 0, sizeof (locator));
5352 memset (a, 0, sizeof (a[0]));
5354 locator.sw_if_index = ntohl (mp->sw_if_index);
5355 locator.priority = mp->priority;
5356 locator.weight = mp->weight;
5358 vec_add1 (locators, locator);
5360 locator_name = format (0, "%s", mp->locator_set_name);
5362 a->name = locator_name;
5363 a->locators = locators;
5364 a->is_add = mp->is_add;
5367 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5369 vec_free (locators);
5370 vec_free (locator_name);
5372 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5376 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5382 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5383 gid_address_ip_set (dst, src, IP4);
5384 gid_address_ippref_len (dst) = len;
5385 ip_prefix_normalize (&gid_address_ippref (dst));
5388 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5389 gid_address_ip_set (dst, src, IP6);
5390 gid_address_ippref_len (dst) = len;
5391 ip_prefix_normalize (&gid_address_ippref (dst));
5393 case 2: /* l2 mac */
5394 gid_address_type (dst) = GID_ADDR_MAC;
5395 clib_memcpy (&gid_address_mac (dst), src, 6);
5399 return VNET_API_ERROR_INVALID_VALUE;
5402 gid_address_vni (dst) = vni;
5408 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5410 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5411 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5413 gid_address_t _eid, *eid = &_eid;
5415 u32 locator_set_index = ~0, map_index = ~0;
5416 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5418 memset (a, 0, sizeof (a[0]));
5419 memset (eid, 0, sizeof (eid[0]));
5421 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5422 mp->eid_type, mp->eid, mp->prefix_len);
5426 name = format (0, "%s", mp->locator_set_name);
5427 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5430 rv = VNET_API_ERROR_INVALID_VALUE;
5433 locator_set_index = p[0];
5435 /* XXX treat batch configuration */
5436 a->is_add = mp->is_add;
5437 gid_address_copy (&a->eid, eid);
5438 a->locator_set_index = locator_set_index;
5440 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5444 gid_address_free (&a->eid);
5446 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5450 vl_api_lisp_eid_table_add_del_map_t_handler
5451 (vl_api_lisp_eid_table_add_del_map_t * mp)
5453 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5455 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5456 clib_net_to_host_u32 (mp->dp_table),
5457 mp->is_l2, mp->is_add);
5458 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5460 /** Used for transferring locators via VPP API */
5462 typedef CLIB_PACKED (struct {
5463 u8 is_ip4; /**< is locator an IPv4 address */
5464 u8 priority; /**< locator priority */
5465 u8 weight; /**< locator weight */
5466 u8 addr[16]; /**< IPv4/IPv6 address */
5470 static locator_pair_t *
5471 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5474 locator_pair_t *pairs = 0, pair;
5477 for (i = 0; i < rloc_num; i++)
5480 r = &((rloc_t *) lcl_locs)[i];
5481 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5482 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5484 /* remote locators */
5485 r = &((rloc_t *) rmt_locs)[i];
5486 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5487 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5489 pair.priority = r->priority;
5490 pair.weight = r->weight;
5492 vec_add1 (pairs, pair);
5498 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5501 locator_t *locs = 0, loc;
5504 for (i = 0; i < rloc_num; i++)
5506 /* remote locators */
5507 r = &((rloc_t *) rmt_locs)[i];
5508 memset (&loc, 0, sizeof (loc));
5509 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5511 loc.priority = r->priority;
5512 loc.weight = r->weight;
5514 vec_add1 (locs, loc);
5520 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5521 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5523 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5524 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5525 locator_pair_t *pairs = 0;
5528 memset (a, 0, sizeof (a[0]));
5530 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5531 mp->rmt_eid, mp->rmt_len);
5532 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5533 mp->lcl_eid, mp->lcl_len);
5535 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5537 if (rv || 0 == pairs)
5540 a->is_add = mp->is_add;
5541 a->locator_pairs = pairs;
5542 a->dp_table = mp->dp_table;
5544 a->action = mp->action;
5546 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5549 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5553 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5556 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5558 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5560 memset (a, 0, sizeof (a[0]));
5562 a->is_add = mp->is_add;
5563 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5565 rv = vnet_lisp_add_del_map_resolver (a);
5567 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5571 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5574 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5576 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5578 a->is_en = mp->is_en;
5579 vnet_lisp_gpe_enable_disable (a);
5581 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5585 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5587 vl_api_lisp_enable_disable_reply_t *rmp;
5590 vnet_lisp_enable_disable (mp->is_en);
5591 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5595 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5597 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5605 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
5609 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
5616 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
5620 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
5623 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5627 vl_api_show_lisp_map_request_mode_t_handler
5628 (vl_api_show_lisp_map_request_mode_t * mp)
5631 vl_api_show_lisp_map_request_mode_reply_t *rmp;
5634 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
5636 rmp->mode = vnet_lisp_get_map_request_mode ();
5642 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
5644 vl_api_lisp_map_request_mode_reply_t *rmp;
5647 rv = vnet_lisp_set_map_request_mode (mp->mode);
5649 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
5653 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5656 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5660 ls_name = format (0, "%s", mp->ls_name);
5661 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5664 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5668 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5669 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5671 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5673 u8 *locator_set_name = NULL;
5674 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5676 locator_set_name = format (0, "%s", mp->locator_set_name);
5678 a->is_add = mp->is_add;
5679 a->locator_set_name = locator_set_name;
5681 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5683 vec_free (locator_set_name);
5685 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5689 vl_api_lisp_add_del_remote_mapping_t_handler
5690 (vl_api_lisp_add_del_remote_mapping_t * mp)
5692 locator_t *rlocs = 0;
5693 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5695 gid_address_t _eid, *eid = &_eid;
5696 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5698 memset (eid, 0, sizeof (eid[0]));
5700 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5701 mp->eid_type, mp->eid, mp->eid_len);
5705 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5709 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5710 gid_address_copy (&a->reid, eid);
5712 rv = vnet_lisp_add_del_adjacency (a);
5719 /* NOTE: for now this works as a static remote mapping, i.e.,
5720 * not authoritative and ttl infinite. */
5721 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5722 mp->is_add, 1 /* is_static */ , 0);
5725 vnet_lisp_clear_all_remote_adjacencies ();
5730 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5734 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5736 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5737 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5740 memset (a, 0, sizeof (a[0]));
5742 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
5743 mp->eid_type, mp->leid, mp->leid_len);
5744 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
5745 mp->eid_type, mp->reid, mp->reid_len);
5750 a->is_add = mp->is_add;
5751 rv = vnet_lisp_add_del_adjacency (a);
5754 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5758 send_lisp_locator_details (lisp_cp_main_t * lcm,
5760 unix_shared_memory_queue_t * q, u32 context)
5762 vl_api_lisp_locator_details_t *rmp;
5764 rmp = vl_msg_api_alloc (sizeof (*rmp));
5765 memset (rmp, 0, sizeof (*rmp));
5766 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5767 rmp->context = context;
5769 rmp->local = loc->local;
5772 rmp->sw_if_index = ntohl (loc->sw_if_index);
5776 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5777 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5779 rmp->priority = loc->priority;
5780 rmp->weight = loc->weight;
5782 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5786 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5789 unix_shared_memory_queue_t *q = 0;
5790 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5791 locator_set_t *lsit = 0;
5793 u32 ls_index = ~0, *locit = 0;
5796 q = vl_api_client_index_to_input_queue (mp->client_index);
5802 if (mp->is_index_set)
5803 ls_index = htonl (mp->ls_index);
5806 /* make sure we get a proper C-string */
5807 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
5808 ls_name = format (0, "%s", mp->ls_name);
5809 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
5815 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
5818 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5820 vec_foreach (locit, lsit->locator_indices)
5822 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5823 send_lisp_locator_details (lcm, loc, q, mp->context);
5830 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5831 locator_set_t * lsit,
5832 unix_shared_memory_queue_t * q,
5833 u32 context, u32 ls_index)
5835 vl_api_lisp_locator_set_details_t *rmp;
5838 rmp = vl_msg_api_alloc (sizeof (*rmp));
5839 memset (rmp, 0, sizeof (*rmp));
5840 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5841 rmp->context = context;
5843 rmp->ls_index = htonl (ls_index);
5846 ASSERT (lsit->name != NULL);
5847 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
5848 vec_len (lsit->name));
5852 str = format (0, "<remote-%d>", ls_index);
5853 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
5857 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5861 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5863 unix_shared_memory_queue_t *q = NULL;
5864 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5865 locator_set_t *lsit = NULL;
5868 q = vl_api_client_index_to_input_queue (mp->client_index);
5874 filter = mp->filter;
5876 pool_foreach (lsit, lcm->locator_set_pool,
5878 if (filter && !((1 == filter && lsit->local) ||
5879 (2 == filter && !lsit->local)))
5883 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
5884 lsit - lcm->locator_set_pool);
5890 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5892 ASSERT (prefix_length);
5893 ip_prefix_t *ippref = &fid_addr_ippref (src);
5895 switch (fid_addr_type (src))
5897 case FID_ADDR_IP_PREF:
5898 if (ip_prefix_version (ippref) == IP4)
5899 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5901 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5902 prefix_length[0] = ip_prefix_len (ippref);
5906 prefix_length[0] = 0;
5907 clib_memcpy (dst, fid_addr_mac (src), 6);
5911 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5917 fid_type_to_api_type (fid_address_t * fid)
5919 ip_prefix_t *ippref;
5921 switch (fid_addr_type (fid))
5923 case FID_ADDR_IP_PREF:
5924 ippref = &fid_addr_ippref (fid);
5925 if (ip_prefix_version (ippref) == IP4)
5927 else if (ip_prefix_version (ippref) == IP6)
5940 send_lisp_eid_table_details (mapping_t * mapit,
5941 unix_shared_memory_queue_t * q,
5942 u32 context, u8 filter)
5945 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5946 locator_set_t *ls = 0;
5947 vl_api_lisp_eid_table_details_t *rmp = NULL;
5948 gid_address_t *gid = NULL;
5950 ip_prefix_t *ip_prefix = NULL;
5954 case 0: /* all mappings */
5957 case 1: /* local only */
5961 case 2: /* remote only */
5966 clib_warning ("Filter error, unknown filter: %d", filter);
5971 ip_prefix = &gid_address_ippref (gid);
5972 mac = gid_address_mac (gid);
5974 rmp = vl_msg_api_alloc (sizeof (*rmp));
5975 memset (rmp, 0, sizeof (*rmp));
5976 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5978 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5979 if (vec_len (ls->locator_indices) == 0)
5980 rmp->locator_set_index = ~0;
5982 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5984 rmp->is_local = mapit->local;
5985 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5986 rmp->action = mapit->action;
5987 rmp->authoritative = mapit->authoritative;
5989 switch (gid_address_type (gid))
5991 case GID_ADDR_SRC_DST:
5992 rmp->is_src_dst = 1;
5993 fid = &gid_address_sd_src (gid);
5994 rmp->eid_type = fid_type_to_api_type (fid);
5995 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5996 &rmp->seid_prefix_len);
5997 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5998 &rmp->eid_prefix_len);
6000 case GID_ADDR_IP_PREFIX:
6001 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
6002 if (ip_prefix_version (ip_prefix) == IP4)
6004 rmp->eid_type = 0; /* ipv4 type */
6005 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
6006 sizeof (ip_prefix_v4 (ip_prefix)));
6010 rmp->eid_type = 1; /* ipv6 type */
6011 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
6012 sizeof (ip_prefix_v6 (ip_prefix)));
6016 rmp->eid_type = 2; /* l2 mac type */
6017 clib_memcpy (rmp->eid, mac, 6);
6022 rmp->context = context;
6023 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
6024 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6028 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
6031 unix_shared_memory_queue_t *q = NULL;
6032 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6033 mapping_t *mapit = NULL;
6034 gid_address_t _eid, *eid = &_eid;
6036 q = vl_api_client_index_to_input_queue (mp->client_index);
6044 memset (eid, 0, sizeof (*eid));
6046 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
6047 mp->eid_type, mp->eid, mp->prefix_length);
6049 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
6050 if ((u32) ~ 0 == mi)
6053 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
6054 send_lisp_eid_table_details (mapit, q, mp->context,
6055 0 /* ignore filter */ );
6060 pool_foreach (mapit, lcm->mapping_pool,
6062 send_lisp_eid_table_details(mapit, q, mp->context,
6070 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
6071 unix_shared_memory_queue_t * q, u32 context)
6073 vl_api_lisp_gpe_tunnel_details_t *rmp;
6074 lisp_gpe_main_t *lgm = &lisp_gpe_main;
6076 rmp = vl_msg_api_alloc (sizeof (*rmp));
6077 memset (rmp, 0, sizeof (*rmp));
6078 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
6080 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
6082 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
6083 ip_address_copy_addr (rmp->source_ip,
6084 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
6085 ip_address_copy_addr (rmp->destination_ip,
6086 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
6088 rmp->encap_fib_id = htonl (0);
6089 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
6090 rmp->iid = htonl (lfe->key->vni);
6091 rmp->context = context;
6093 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6097 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
6099 unix_shared_memory_queue_t *q = NULL;
6100 lisp_gpe_main_t *lgm = &lisp_gpe_main;
6101 lisp_gpe_fwd_entry_t *lfe = NULL;
6103 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
6108 q = vl_api_client_index_to_input_queue (mp->client_index);
6115 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
6117 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
6123 send_lisp_map_resolver_details (ip_address_t * ip,
6124 unix_shared_memory_queue_t * q, u32 context)
6126 vl_api_lisp_map_resolver_details_t *rmp = NULL;
6128 rmp = vl_msg_api_alloc (sizeof (*rmp));
6129 memset (rmp, 0, sizeof (*rmp));
6130 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
6132 switch (ip_addr_version (ip))
6136 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
6137 sizeof (ip_addr_v4 (ip)));
6142 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
6143 sizeof (ip_addr_v6 (ip)));
6149 rmp->context = context;
6151 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6155 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
6157 unix_shared_memory_queue_t *q = NULL;
6158 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6161 q = vl_api_client_index_to_input_queue (mp->client_index);
6167 vec_foreach (mr, lcm->map_resolvers)
6169 send_lisp_map_resolver_details (&mr->address, q, mp->context);
6174 send_eid_table_map_pair (hash_pair_t * p,
6175 unix_shared_memory_queue_t * q, u32 context)
6177 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
6179 rmp = vl_msg_api_alloc (sizeof (*rmp));
6180 memset (rmp, 0, sizeof (*rmp));
6181 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
6183 rmp->vni = clib_host_to_net_u32 (p->key);
6184 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
6185 rmp->context = context;
6186 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6190 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
6193 unix_shared_memory_queue_t *q = NULL;
6194 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6196 uword *vni_table = 0;
6198 q = vl_api_client_index_to_input_queue (mp->client_index);
6206 vni_table = lcm->bd_id_by_vni;
6210 vni_table = lcm->table_id_by_vni;
6214 hash_foreach_pair (p, vni_table,
6216 send_eid_table_map_pair (p, q, mp->context);
6222 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6224 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6226 rmp = vl_msg_api_alloc (sizeof (*rmp));
6227 memset (rmp, 0, sizeof (*rmp));
6228 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6229 rmp->context = context;
6230 rmp->vni = clib_host_to_net_u32 (vni);
6231 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6235 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
6237 lisp_adjacency_t *adj;
6238 vl_api_lisp_adjacency_t a;
6239 u32 i, n = vec_len (adjs);
6241 for (i = 0; i < n; i++)
6243 adj = vec_elt_at_index (adjs, i);
6244 memset (&a, 0, sizeof (a));
6246 switch (gid_address_type (&adj->reid))
6248 case GID_ADDR_IP_PREFIX:
6249 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
6250 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
6251 if (gid_address_ip_version (&adj->reid) == IP4)
6253 a.eid_type = 0; /* ipv4 type */
6254 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
6255 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
6259 a.eid_type = 1; /* ipv6 type */
6260 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
6261 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
6265 a.eid_type = 2; /* l2 mac type */
6266 mac_copy (a.reid, gid_address_mac (&adj->reid));
6267 mac_copy (a.leid, gid_address_mac (&adj->leid));
6277 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
6279 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
6280 lisp_adjacency_t *adjs = 0;
6282 vl_api_lisp_adjacency_t a;
6284 u32 vni = clib_net_to_host_u32 (mp->vni);
6286 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
6287 size = vec_len (adjs) * sizeof (a);
6290 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
6292 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
6293 lisp_adjacency_copy (rmp->adjacencies, adjs);
6301 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6306 unix_shared_memory_queue_t *q = 0;
6307 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6309 q = vl_api_client_index_to_input_queue (mp->client_index);
6316 hash_foreach_pair (p, lcm->table_id_by_vni,
6318 hash_set (vnis, p->key, 0);
6321 hash_foreach_pair (p, lcm->bd_id_by_vni,
6323 hash_set (vnis, p->key, 0);
6326 hash_foreach_pair (p, vnis,
6328 send_eid_table_vni (p->key, q, mp->context);
6336 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6338 unix_shared_memory_queue_t *q = NULL;
6339 vl_api_show_lisp_status_reply_t *rmp = NULL;
6342 q = vl_api_client_index_to_input_queue (mp->client_index);
6349 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6351 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6352 rmp->feature_status = vnet_lisp_enable_disable_status ();
6358 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6359 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6361 unix_shared_memory_queue_t *q = NULL;
6362 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6363 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6364 locator_set_t *loc_set = 0;
6368 q = vl_api_client_index_to_input_queue (mp->client_index);
6374 if (~0 == lcm->mreq_itr_rlocs)
6376 tmp_str = format (0, " ");
6381 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6382 tmp_str = format (0, "%s", loc_set->name);
6386 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6388 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6389 ARRAY_LEN(rmp->locator_set_name) - 1);
6397 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6399 unix_shared_memory_queue_t *q = NULL;
6400 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6401 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6403 locator_set_t *ls = 0;
6407 q = vl_api_client_index_to_input_queue (mp->client_index);
6413 if (!lcm->lisp_pitr)
6415 tmp_str = format (0, "N/A");
6419 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6420 if (~0 != m->locator_set_index)
6423 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6424 tmp_str = format (0, "%s", ls->name);
6428 tmp_str = format (0, "N/A");
6431 vec_add1 (tmp_str, 0);
6434 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6436 rmp->status = lcm->lisp_pitr;
6437 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6438 ARRAY_LEN(rmp->locator_set_name) - 1);
6444 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6447 vl_api_interface_name_renumber_reply_t *rmp;
6450 VALIDATE_SW_IF_INDEX (mp);
6452 rv = vnet_interface_name_renumber
6453 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6455 BAD_SW_IF_INDEX_LABEL;
6457 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6461 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6462 u32 sw_if_index, u32 address)
6464 vpe_api_main_t *am = &vpe_api_main;
6465 vlib_main_t *vm = am->vlib_main;
6466 vl_api_ip4_arp_event_t *event;
6467 static f64 arp_event_last_time;
6468 f64 now = vlib_time_now (vm);
6470 if (pool_is_free_index (am->arp_events, pool_index))
6473 event = pool_elt_at_index (am->arp_events, pool_index);
6475 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6477 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6481 if (sw_if_index == event->sw_if_index &&
6483 /* for BD case, also check IP address with 10 sec timeout */
6484 (address == event->address &&
6485 (now - arp_event_last_time) < 10.0)))
6490 arp_event_last_time = now;
6491 event->sw_if_index = sw_if_index;
6493 event->address = address;
6498 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6499 u32 sw_if_index, ip6_address_t * address)
6501 vpe_api_main_t *am = &vpe_api_main;
6502 vlib_main_t *vm = am->vlib_main;
6503 vl_api_ip6_nd_event_t *event;
6504 static f64 nd_event_last_time;
6505 f64 now = vlib_time_now (vm);
6507 if (pool_is_free_index (am->nd_events, pool_index))
6510 event = pool_elt_at_index (am->nd_events, pool_index);
6513 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6515 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6519 if (sw_if_index == event->sw_if_index &&
6521 /* for BD case, also check IP address with 10 sec timeout */
6522 (ip6_address_is_equal (address,
6523 (ip6_address_t *) event->address) &&
6524 (now - nd_event_last_time) < 10.0)))
6529 nd_event_last_time = now;
6530 event->sw_if_index = sw_if_index;
6532 clib_memcpy (event->address, address, sizeof (event->address));
6537 arp_change_delete_callback (u32 pool_index, u8 * notused)
6539 vpe_api_main_t *am = &vpe_api_main;
6541 if (pool_is_free_index (am->arp_events, pool_index))
6544 pool_put_index (am->arp_events, pool_index);
6549 nd_change_delete_callback (u32 pool_index, u8 * notused)
6551 vpe_api_main_t *am = &vpe_api_main;
6553 if (pool_is_free_index (am->nd_events, pool_index))
6556 pool_put_index (am->nd_events, pool_index);
6561 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6563 vpe_api_main_t *am = &vpe_api_main;
6564 vnet_main_t *vnm = vnet_get_main ();
6565 vl_api_want_ip4_arp_events_reply_t *rmp;
6566 vl_api_ip4_arp_event_t *event;
6569 if (mp->enable_disable)
6571 pool_get (am->arp_events, event);
6572 memset (event, 0, sizeof (*event));
6574 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6575 event->client_index = mp->client_index;
6576 event->context = mp->context;
6577 event->address = mp->address;
6578 event->pid = mp->pid;
6579 if (mp->address == 0)
6582 rv = vnet_add_del_ip4_arp_change_event
6583 (vnm, arp_change_data_callback,
6584 mp->pid, &mp->address /* addr, in net byte order */ ,
6585 vpe_resolver_process_node.index,
6586 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6590 rv = vnet_add_del_ip4_arp_change_event
6591 (vnm, arp_change_delete_callback,
6592 mp->pid, &mp->address /* addr, in net byte order */ ,
6593 vpe_resolver_process_node.index,
6594 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6596 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6600 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6602 vpe_api_main_t *am = &vpe_api_main;
6603 vnet_main_t *vnm = vnet_get_main ();
6604 vl_api_want_ip6_nd_events_reply_t *rmp;
6605 vl_api_ip6_nd_event_t *event;
6608 if (mp->enable_disable)
6610 pool_get (am->nd_events, event);
6611 memset (event, 0, sizeof (*event));
6613 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6614 event->client_index = mp->client_index;
6615 event->context = mp->context;
6616 clib_memcpy (event->address, mp->address, 16);
6617 event->pid = mp->pid;
6618 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6621 rv = vnet_add_del_ip6_nd_change_event
6622 (vnm, nd_change_data_callback,
6623 mp->pid, mp->address /* addr, in net byte order */ ,
6624 vpe_resolver_process_node.index,
6625 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6629 rv = vnet_add_del_ip6_nd_change_event
6630 (vnm, nd_change_delete_callback,
6631 mp->pid, mp->address /* addr, in net byte order */ ,
6632 vpe_resolver_process_node.index,
6633 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6635 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6638 static void vl_api_input_acl_set_interface_t_handler
6639 (vl_api_input_acl_set_interface_t * mp)
6641 vlib_main_t *vm = vlib_get_main ();
6642 vl_api_input_acl_set_interface_reply_t *rmp;
6644 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6646 ip4_table_index = ntohl (mp->ip4_table_index);
6647 ip6_table_index = ntohl (mp->ip6_table_index);
6648 l2_table_index = ntohl (mp->l2_table_index);
6649 sw_if_index = ntohl (mp->sw_if_index);
6651 VALIDATE_SW_IF_INDEX (mp);
6653 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6654 ip6_table_index, l2_table_index, mp->is_add);
6656 BAD_SW_IF_INDEX_LABEL;
6658 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6661 static void vl_api_ipsec_spd_add_del_t_handler
6662 (vl_api_ipsec_spd_add_del_t * mp)
6665 clib_warning ("unimplemented");
6668 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6669 vl_api_ipsec_spd_add_del_reply_t *rmp;
6673 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6675 rv = VNET_API_ERROR_UNIMPLEMENTED;
6678 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6682 static void vl_api_ipsec_interface_add_del_spd_t_handler
6683 (vl_api_ipsec_interface_add_del_spd_t * mp)
6685 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6686 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6688 u32 sw_if_index __attribute__ ((unused));
6689 u32 spd_id __attribute__ ((unused));
6691 sw_if_index = ntohl (mp->sw_if_index);
6692 spd_id = ntohl (mp->spd_id);
6694 VALIDATE_SW_IF_INDEX (mp);
6697 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6699 rv = VNET_API_ERROR_UNIMPLEMENTED;
6702 BAD_SW_IF_INDEX_LABEL;
6704 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6707 static void vl_api_ipsec_spd_add_del_entry_t_handler
6708 (vl_api_ipsec_spd_add_del_entry_t * mp)
6710 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6711 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6717 memset (&p, 0, sizeof (p));
6719 p.id = ntohl (mp->spd_id);
6720 p.priority = ntohl (mp->priority);
6721 p.is_outbound = mp->is_outbound;
6722 p.is_ipv6 = mp->is_ipv6;
6724 if (mp->is_ipv6 || mp->is_ip_any)
6726 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6727 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6728 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6729 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6733 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6734 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6735 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6736 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6738 p.protocol = mp->protocol;
6739 p.rport.start = ntohs (mp->remote_port_start);
6740 p.rport.stop = ntohs (mp->remote_port_stop);
6741 p.lport.start = ntohs (mp->local_port_start);
6742 p.lport.stop = ntohs (mp->local_port_stop);
6743 /* policy action resolve unsupported */
6744 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6746 clib_warning ("unsupported action: 'resolve'");
6747 rv = VNET_API_ERROR_UNIMPLEMENTED;
6750 p.policy = mp->policy;
6751 p.sa_id = ntohl (mp->sa_id);
6753 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6760 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6763 rv = VNET_API_ERROR_UNIMPLEMENTED;
6768 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6771 static void vl_api_ipsec_sad_add_del_entry_t_handler
6772 (vl_api_ipsec_sad_add_del_entry_t * mp)
6774 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6775 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6780 memset (&sa, 0, sizeof (sa));
6782 sa.id = ntohl (mp->sad_id);
6783 sa.spi = ntohl (mp->spi);
6784 /* security protocol AH unsupported */
6785 if (mp->protocol == IPSEC_PROTOCOL_AH)
6787 clib_warning ("unsupported security protocol 'AH'");
6788 rv = VNET_API_ERROR_UNIMPLEMENTED;
6791 sa.protocol = mp->protocol;
6792 /* check for unsupported crypto-alg */
6793 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6794 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6796 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6797 mp->crypto_algorithm);
6798 rv = VNET_API_ERROR_UNIMPLEMENTED;
6801 sa.crypto_alg = mp->crypto_algorithm;
6802 sa.crypto_key_len = mp->crypto_key_length;
6803 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6804 /* check for unsupported integ-alg */
6805 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6806 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6808 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6809 mp->integrity_algorithm);
6810 rv = VNET_API_ERROR_UNIMPLEMENTED;
6813 sa.integ_alg = mp->integrity_algorithm;
6814 sa.integ_key_len = mp->integrity_key_length;
6815 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6816 sa.use_esn = mp->use_extended_sequence_number;
6817 sa.is_tunnel = mp->is_tunnel;
6818 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6819 if (sa.is_tunnel_ip6)
6821 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6822 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6826 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6827 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6830 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6832 rv = VNET_API_ERROR_UNIMPLEMENTED;
6837 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6841 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6843 vl_api_ikev2_profile_add_del_reply_t *rmp;
6847 vlib_main_t *vm = vlib_get_main ();
6848 clib_error_t *error;
6849 u8 *tmp = format (0, "%s", mp->name);
6850 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6853 rv = VNET_API_ERROR_UNSPECIFIED;
6855 rv = VNET_API_ERROR_UNIMPLEMENTED;
6858 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6862 vl_api_ikev2_profile_set_auth_t_handler
6863 (vl_api_ikev2_profile_set_auth_t * mp)
6865 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6869 vlib_main_t *vm = vlib_get_main ();
6870 clib_error_t *error;
6871 u8 *tmp = format (0, "%s", mp->name);
6872 u8 *data = vec_new (u8, mp->data_len);
6873 clib_memcpy (data, mp->data, mp->data_len);
6874 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6878 rv = VNET_API_ERROR_UNSPECIFIED;
6880 rv = VNET_API_ERROR_UNIMPLEMENTED;
6883 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6887 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6889 vl_api_ikev2_profile_add_del_reply_t *rmp;
6893 vlib_main_t *vm = vlib_get_main ();
6894 clib_error_t *error;
6895 u8 *tmp = format (0, "%s", mp->name);
6896 u8 *data = vec_new (u8, mp->data_len);
6897 clib_memcpy (data, mp->data, mp->data_len);
6898 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6902 rv = VNET_API_ERROR_UNSPECIFIED;
6904 rv = VNET_API_ERROR_UNIMPLEMENTED;
6907 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6911 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6913 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6917 vlib_main_t *vm = vlib_get_main ();
6918 clib_error_t *error;
6919 u8 *tmp = format (0, "%s", mp->name);
6920 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6921 mp->end_port, (ip4_address_t) mp->start_addr,
6922 (ip4_address_t) mp->end_addr, mp->is_local);
6925 rv = VNET_API_ERROR_UNSPECIFIED;
6927 rv = VNET_API_ERROR_UNIMPLEMENTED;
6930 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6934 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6936 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6940 vlib_main_t *vm = vlib_get_main ();
6941 clib_error_t *error;
6943 error = ikev2_set_local_key (vm, mp->key_file);
6945 rv = VNET_API_ERROR_UNSPECIFIED;
6947 rv = VNET_API_ERROR_UNIMPLEMENTED;
6950 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6954 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6956 vl_api_map_add_domain_reply_t *rmp;
6959 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6961 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6962 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6963 (ip6_address_t *) & mp->ip6_src,
6964 mp->ip6_src_prefix_len, mp->ea_bits_len,
6965 mp->psid_offset, mp->psid_length, &index,
6966 ntohs (mp->mtu), flags);
6969 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6971 rmp->index = ntohl(index);
6977 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6979 vl_api_map_del_domain_reply_t *rmp;
6982 rv = map_delete_domain (ntohl (mp->index));
6984 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6988 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6990 vl_api_map_del_domain_reply_t *rmp;
6994 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6995 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6997 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
7001 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
7003 vl_api_map_domain_details_t *rmp;
7004 map_main_t *mm = &map_main;
7006 unix_shared_memory_queue_t *q;
7008 if (pool_elts (mm->domains) == 0)
7011 q = vl_api_client_index_to_input_queue (mp->client_index);
7018 pool_foreach(d, mm->domains,
7020 /* Make sure every field is initiated (or don't skip the memset()) */
7021 rmp = vl_msg_api_alloc (sizeof (*rmp));
7022 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
7023 rmp->domain_index = htonl(d - mm->domains);
7024 rmp->ea_bits_len = d->ea_bits_len;
7025 rmp->psid_offset = d->psid_offset;
7026 rmp->psid_length = d->psid_length;
7027 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
7028 rmp->ip4_prefix_len = d->ip4_prefix_len;
7029 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
7030 rmp->ip6_prefix_len = d->ip6_prefix_len;
7031 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
7032 rmp->ip6_src_len = d->ip6_src_len;
7033 rmp->mtu = htons(d->mtu);
7034 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
7035 rmp->context = mp->context;
7037 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7043 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
7045 unix_shared_memory_queue_t *q;
7048 vl_api_map_rule_details_t *rmp;
7049 map_main_t *mm = &map_main;
7050 u32 domain_index = ntohl (mp->domain_index);
7053 if (pool_elts (mm->domains) == 0)
7056 d = pool_elt_at_index (mm->domains, domain_index);
7057 if (!d || !d->rules)
7062 q = vl_api_client_index_to_input_queue (mp->client_index);
7068 for (i = 0; i < (0x1 << d->psid_length); i++)
7071 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
7075 rmp = vl_msg_api_alloc (sizeof (*rmp));
7076 memset (rmp, 0, sizeof (*rmp));
7077 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
7078 rmp->psid = htons (i);
7079 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
7080 rmp->context = mp->context;
7081 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7086 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
7088 vl_api_map_summary_stats_reply_t *rmp;
7089 vlib_combined_counter_main_t *cm;
7092 u64 total_pkts[VLIB_N_RX_TX];
7093 u64 total_bytes[VLIB_N_RX_TX];
7094 map_main_t *mm = &map_main;
7095 unix_shared_memory_queue_t *q =
7096 vl_api_client_index_to_input_queue (mp->client_index);
7101 rmp = vl_msg_api_alloc (sizeof (*rmp));
7102 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
7103 rmp->context = mp->context;
7106 memset (total_pkts, 0, sizeof (total_pkts));
7107 memset (total_bytes, 0, sizeof (total_bytes));
7109 map_domain_counter_lock (mm);
7110 vec_foreach (cm, mm->domain_counters)
7112 which = cm - mm->domain_counters;
7114 for (i = 0; i < vec_len (cm->maxi); i++)
7116 vlib_get_combined_counter (cm, i, &v);
7117 total_pkts[which] += v.packets;
7118 total_bytes[which] += v.bytes;
7122 map_domain_counter_unlock (mm);
7124 /* Note: in network byte order! */
7125 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
7126 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
7127 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
7128 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
7129 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
7130 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
7131 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
7132 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
7133 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
7134 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
7135 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
7136 clib_host_to_net_u64 (map_error_counter_get
7137 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
7138 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
7139 clib_host_to_net_u64 (map_error_counter_get
7140 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
7142 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7146 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
7148 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
7149 vl_api_ipsec_sa_set_key_reply_t *rmp;
7153 sa.id = ntohl (mp->sa_id);
7154 sa.crypto_key_len = mp->crypto_key_length;
7155 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
7156 sa.integ_key_len = mp->integrity_key_length;
7157 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
7159 rv = ipsec_set_sa_key (vm, &sa);
7161 rv = VNET_API_ERROR_UNIMPLEMENTED;
7164 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
7167 static void vl_api_cop_interface_enable_disable_t_handler
7168 (vl_api_cop_interface_enable_disable_t * mp)
7170 vl_api_cop_interface_enable_disable_reply_t *rmp;
7172 u32 sw_if_index = ntohl (mp->sw_if_index);
7175 VALIDATE_SW_IF_INDEX (mp);
7177 enable_disable = (int) mp->enable_disable;
7179 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
7181 BAD_SW_IF_INDEX_LABEL;
7183 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
7186 static void vl_api_cop_whitelist_enable_disable_t_handler
7187 (vl_api_cop_whitelist_enable_disable_t * mp)
7189 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
7190 cop_whitelist_enable_disable_args_t _a, *a = &_a;
7191 u32 sw_if_index = ntohl (mp->sw_if_index);
7194 VALIDATE_SW_IF_INDEX (mp);
7196 a->sw_if_index = sw_if_index;
7199 a->default_cop = mp->default_cop;
7200 a->fib_id = ntohl (mp->fib_id);
7202 rv = cop_whitelist_enable_disable (a);
7204 BAD_SW_IF_INDEX_LABEL;
7206 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
7210 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
7214 api_main_t *am = &api_main;
7215 vlib_main_t *vm = vlib_get_main ();
7217 vl_api_get_node_graph_reply_t *rmp;
7219 pthread_mutex_lock (&am->vlib_rp->mutex);
7220 oldheap = svm_push_data_heap (am->vlib_rp);
7223 * Keep the number of memcpy ops to a minimum (e.g. 1).
7225 vec_validate (vector, 16384);
7226 vec_reset_length (vector);
7229 vector = vlib_node_serialize (&vm->node_main, vector,
7230 (u32) ~ 0 /* all threads */ ,
7231 1 /* include nexts */ ,
7232 1 /* include stats */ );
7234 svm_pop_heap (oldheap);
7235 pthread_mutex_unlock (&am->vlib_rp->mutex);
7238 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
7240 rmp->reply_in_shmem = (uword) vector;
7246 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
7249 vl_api_ioam_enable_reply_t *rmp;
7250 clib_error_t *error;
7252 /* Ignoring the profile id as currently a single profile
7254 error = ip6_ioam_enable (mp->trace_enable, mp->pow_enable, mp->trace_ppc);
7257 clib_error_report (error);
7258 rv = clib_error_get_code (error);
7261 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
7265 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
7268 vl_api_ioam_disable_reply_t *rmp;
7269 clib_error_t *error;
7271 error = clear_ioam_rewrite_fn ();
7274 clib_error_report (error);
7275 rv = clib_error_get_code (error);
7278 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
7282 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7284 vlib_main_t *vm = vlib_get_main ();
7285 vl_api_af_packet_create_reply_t *rmp;
7287 u8 *host_if_name = NULL;
7290 host_if_name = format (0, "%s", mp->host_if_name);
7291 vec_add1 (host_if_name, 0);
7293 rv = af_packet_create_if (vm, host_if_name,
7294 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7297 vec_free (host_if_name);
7300 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7302 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7308 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7310 vlib_main_t *vm = vlib_get_main ();
7311 vl_api_af_packet_delete_reply_t *rmp;
7313 u8 *host_if_name = NULL;
7315 host_if_name = format (0, "%s", mp->host_if_name);
7316 vec_add1 (host_if_name, 0);
7318 rv = af_packet_delete_if (vm, host_if_name);
7320 vec_free (host_if_name);
7322 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7326 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7328 vlib_main_t *vm = vlib_get_main ();
7329 vl_api_policer_add_del_reply_t *rmp;
7332 sse2_qos_pol_cfg_params_st cfg;
7333 clib_error_t *error;
7336 name = format (0, "%s", mp->name);
7338 memset (&cfg, 0, sizeof (cfg));
7340 cfg.rnd_type = mp->round_type;
7341 cfg.rate_type = mp->rate_type;
7342 cfg.rb.kbps.cir_kbps = mp->cir;
7343 cfg.rb.kbps.eir_kbps = mp->eir;
7344 cfg.rb.kbps.cb_bytes = mp->cb;
7345 cfg.rb.kbps.eb_bytes = mp->eb;
7346 cfg.conform_action.action_type = mp->conform_action_type;
7347 cfg.conform_action.dscp = mp->conform_dscp;
7348 cfg.exceed_action.action_type = mp->exceed_action_type;
7349 cfg.exceed_action.dscp = mp->exceed_dscp;
7350 cfg.violate_action.action_type = mp->violate_action_type;
7351 cfg.violate_action.dscp = mp->violate_dscp;
7352 cfg.color_aware = mp->color_aware;
7354 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7357 rv = VNET_API_ERROR_UNSPECIFIED;
7360 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7362 if (rv == 0 && mp->is_add)
7363 rmp->policer_index = ntohl(policer_index);
7365 rmp->policer_index = ~0;
7371 send_policer_details (u8 * name,
7372 sse2_qos_pol_cfg_params_st * config,
7373 policer_read_response_type_st * templ,
7374 unix_shared_memory_queue_t * q, u32 context)
7376 vl_api_policer_details_t *mp;
7378 mp = vl_msg_api_alloc (sizeof (*mp));
7379 memset (mp, 0, sizeof (*mp));
7380 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7381 mp->context = context;
7382 mp->cir = htonl (config->rb.kbps.cir_kbps);
7383 mp->eir = htonl (config->rb.kbps.eir_kbps);
7384 mp->cb = htonl (config->rb.kbps.cb_bytes);
7385 mp->eb = htonl (config->rb.kbps.eb_bytes);
7386 mp->rate_type = config->rate_type;
7387 mp->round_type = config->rnd_type;
7388 mp->type = config->rfc;
7389 mp->conform_action_type = config->conform_action.action_type;
7390 mp->conform_dscp = config->conform_action.dscp;
7391 mp->exceed_action_type = config->exceed_action.action_type;
7392 mp->exceed_dscp = config->exceed_action.dscp;
7393 mp->violate_action_type = config->violate_action.action_type;
7394 mp->violate_dscp = config->violate_action.dscp;
7395 mp->single_rate = templ->single_rate ? 1 : 0;
7396 mp->color_aware = templ->color_aware ? 1 : 0;
7397 mp->scale = htonl (templ->scale);
7398 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7399 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7400 mp->current_limit = htonl (templ->current_limit);
7401 mp->current_bucket = htonl (templ->current_bucket);
7402 mp->extended_limit = htonl (templ->extended_limit);
7403 mp->extended_bucket = htonl (templ->extended_bucket);
7404 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7406 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7408 vl_msg_api_send_shmem (q, (u8 *) & mp);
7412 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7414 unix_shared_memory_queue_t *q;
7415 vnet_policer_main_t *pm = &vnet_policer_main;
7421 sse2_qos_pol_cfg_params_st *config;
7422 policer_read_response_type_st *templ;
7424 q = vl_api_client_index_to_input_queue (mp->client_index);
7428 if (mp->match_name_valid)
7430 match_name = format (0, "%s%c", mp->match_name, 0);
7433 if (mp->match_name_valid)
7435 p = hash_get_mem (pm->policer_config_by_name, match_name);
7439 config = pool_elt_at_index (pm->configs, pool_index);
7440 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7441 send_policer_details (match_name, config, templ, q, mp->context);
7447 hash_foreach_pair (hp, pm->policer_config_by_name,
7449 name = (u8 *) hp->key;
7450 pool_index = hp->value[0];
7451 config = pool_elt_at_index (pm->configs, pool_index);
7452 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7453 send_policer_details(name, config, templ, q, mp->context);
7460 vl_api_policer_classify_set_interface_t_handler
7461 (vl_api_policer_classify_set_interface_t * mp)
7463 vlib_main_t *vm = vlib_get_main ();
7464 vl_api_policer_classify_set_interface_reply_t *rmp;
7466 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7468 ip4_table_index = ntohl (mp->ip4_table_index);
7469 ip6_table_index = ntohl (mp->ip6_table_index);
7470 l2_table_index = ntohl (mp->l2_table_index);
7471 sw_if_index = ntohl (mp->sw_if_index);
7473 VALIDATE_SW_IF_INDEX (mp);
7475 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7476 ip6_table_index, l2_table_index,
7479 BAD_SW_IF_INDEX_LABEL;
7481 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7485 send_policer_classify_details (u32 sw_if_index,
7487 unix_shared_memory_queue_t * q, u32 context)
7489 vl_api_policer_classify_details_t *mp;
7491 mp = vl_msg_api_alloc (sizeof (*mp));
7492 memset (mp, 0, sizeof (*mp));
7493 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7494 mp->context = context;
7495 mp->sw_if_index = htonl (sw_if_index);
7496 mp->table_index = htonl (table_index);
7498 vl_msg_api_send_shmem (q, (u8 *) & mp);
7502 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7504 unix_shared_memory_queue_t *q;
7505 policer_classify_main_t *pcm = &policer_classify_main;
7509 q = vl_api_client_index_to_input_queue (mp->client_index);
7513 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7515 if (vec_len (vec_tbl))
7517 for (i = 0; i < vec_len (vec_tbl); i++)
7519 if (vec_elt (vec_tbl, i) == ~0)
7522 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7529 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7531 vlib_main_t *vm = vlib_get_main ();
7532 vl_api_netmap_create_reply_t *rmp;
7536 if_name = format (0, "%s", mp->netmap_if_name);
7537 vec_add1 (if_name, 0);
7540 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7541 mp->is_pipe, mp->is_master, 0);
7545 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7549 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7551 vlib_main_t *vm = vlib_get_main ();
7552 vl_api_netmap_delete_reply_t *rmp;
7556 if_name = format (0, "%s", mp->netmap_if_name);
7557 vec_add1 (if_name, 0);
7559 rv = netmap_delete_if (vm, if_name);
7563 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7567 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7570 clib_warning ("BUG");
7574 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7575 unix_shared_memory_queue_t * q,
7576 mpls_eth_tunnel_t * et, u32 index, u32 context)
7578 mpls_main_t *mm = &mpls_main;
7582 vl_api_mpls_eth_tunnel_details_t *mp;
7584 e = pool_elt_at_index (mm->encaps, et->encap_index);
7585 nlabels = vec_len (e->labels);
7587 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7588 memset (mp, 0, sizeof (*mp));
7589 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7590 mp->context = context;
7592 mp->tunnel_index = htonl (index);
7593 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7594 mp->intfc_address = et->intfc_address.as_u32;
7595 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7596 mp->inner_fib_index = htonl (et->inner_fib_index);
7597 mp->mask_width = htonl (et->mask_width);
7598 mp->encap_index = htonl (et->encap_index);
7599 mp->hw_if_index = htonl (et->hw_if_index);
7600 mp->l2_only = htonl (et->l2_only);
7601 mp->nlabels = htonl (nlabels);
7603 for (i = 0; i < nlabels; i++)
7606 htonl (vnet_mpls_uc_get_label
7607 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7610 vl_msg_api_send_shmem (q, (u8 *) & mp);
7614 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7616 vpe_api_main_t *am = &vpe_api_main;
7617 unix_shared_memory_queue_t *q;
7618 mpls_main_t *mm = &mpls_main;
7619 mpls_eth_tunnel_t *et;
7620 u32 index = ntohl (mp->tunnel_index);
7622 q = vl_api_client_index_to_input_queue (mp->client_index);
7628 if (!pool_is_free_index (mm->eth_tunnels, index))
7630 et = pool_elt_at_index (mm->eth_tunnels, index);
7631 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7638 pool_foreach (et, mm->eth_tunnels,
7640 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7648 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
7650 clib_warning ("BUG");
7654 send_mpls_fib_details (vpe_api_main_t * am,
7655 unix_shared_memory_queue_t * q,
7656 u32 table_id, u32 label, u32 eos, u32 context)
7658 vl_api_mpls_fib_details_t *mp;
7660 mp = vl_msg_api_alloc (sizeof (*mp));
7661 memset (mp, 0, sizeof (*mp));
7662 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
7663 mp->context = context;
7665 mp->table_id = htonl (table_id);
7667 mp->label = htonl (label);
7669 vl_msg_api_send_shmem (q, (u8 *) & mp);
7673 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
7675 vpe_api_main_t *am = &vpe_api_main;
7676 unix_shared_memory_queue_t *q;
7677 mpls_main_t *mm = &mpls_main;
7678 fib_table_t *fib_table;
7679 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
7684 q = vl_api_client_index_to_input_queue (mp->client_index);
7689 pool_foreach (fib_table, mm->fibs,
7691 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
7693 vec_add1(lfeis, lfei);
7696 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
7698 vec_foreach(lfeip, lfeis)
7700 fib_entry_get_prefix(*lfeip, &pfx);
7701 fib_index = fib_entry_get_fib_index(*lfeip);
7703 fib_table = fib_table_get(fib_index, pfx.fp_proto);
7705 send_mpls_fib_details (am, q,
7706 fib_table->ft_table_id,
7716 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7718 clib_warning ("BUG");
7722 send_mpls_fib_encap_details (vpe_api_main_t * am,
7723 unix_shared_memory_queue_t * q,
7724 show_mpls_fib_t * s, u32 context)
7726 vl_api_mpls_fib_encap_details_t *mp;
7727 mpls_main_t *mm = &mpls_main;
7732 e = pool_elt_at_index (mm->encaps, s->entry_index);
7733 nlabels = vec_len (e->labels);
7735 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7736 memset (mp, 0, sizeof (*mp));
7737 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7738 mp->context = context;
7740 mp->fib_index = htonl (s->fib_index);
7741 mp->entry_index = htonl (s->entry_index);
7743 mp->s_bit = htonl (s->s_bit);
7745 mp->nlabels = htonl (nlabels);
7747 for (i = 0; i < nlabels; i++)
7750 htonl (vnet_mpls_uc_get_label
7751 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7754 vl_msg_api_send_shmem (q, (u8 *) & mp);
7758 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7760 vpe_api_main_t *am = &vpe_api_main;
7761 unix_shared_memory_queue_t *q;
7762 vlib_main_t *vm = &vlib_global_main;
7765 show_mpls_fib_t *records = 0;
7767 mpls_main_t *mm = &mpls_main;
7770 q = vl_api_client_index_to_input_queue (mp->client_index);
7775 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7777 vec_add2 (records, s, 1);
7778 s->fib_index = (u32)(key>>32);
7779 s->dest = (u32)(key & 0xFFFFFFFF);
7780 s->entry_index = (u32) value;
7784 if (0 == vec_len (records))
7786 vlib_cli_output (vm, "MPLS encap table empty");
7790 /* sort output by dst address within fib */
7791 vec_sort_with_function (records, mpls_dest_cmp);
7792 vec_sort_with_function (records, mpls_fib_index_cmp);
7793 vlib_cli_output (vm, "MPLS encap table");
7794 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7795 vec_foreach (s, records)
7797 rx_fib = ip4_fib_get (s->fib_index);
7798 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7799 format_ip4_address, &s->dest, format_mpls_encap_index,
7800 mm, s->entry_index);
7801 send_mpls_fib_encap_details (am, q, s, mp->context);
7809 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7811 unix_shared_memory_queue_t *q;
7813 q = vl_api_client_index_to_input_queue (mp->client_index);
7817 vnet_classify_main_t *cm = &vnet_classify_main;
7818 vnet_classify_table_t *t;
7823 pool_foreach (t, cm->tables,
7825 vec_add1 (table_ids, ntohl(t - cm->tables));
7828 count = vec_len (table_ids);
7830 vl_api_classify_table_ids_reply_t *rmp;
7831 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7832 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7833 rmp->context = mp->context;
7834 rmp->count = ntohl (count);
7835 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7838 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7840 vec_free (table_ids);
7844 vl_api_classify_table_by_interface_t_handler
7845 (vl_api_classify_table_by_interface_t * mp)
7847 vl_api_classify_table_by_interface_reply_t *rmp;
7850 u32 sw_if_index = ntohl (mp->sw_if_index);
7853 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7856 VALIDATE_SW_IF_INDEX (mp);
7858 input_acl_main_t *am = &input_acl_main;
7863 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7865 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7866 if (vec_len (vec_tbl))
7868 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7870 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7874 acl[type] = vec_elt (vec_tbl, if_idx);
7879 BAD_SW_IF_INDEX_LABEL;
7882 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7884 rmp->sw_if_index = ntohl(sw_if_index);
7885 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7886 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7887 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7894 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7896 unix_shared_memory_queue_t *q;
7898 q = vl_api_client_index_to_input_queue (mp->client_index);
7902 vl_api_classify_table_info_reply_t *rmp = 0;
7904 vnet_classify_main_t *cm = &vnet_classify_main;
7905 u32 table_id = ntohl (mp->table_id);
7906 vnet_classify_table_t *t;
7909 pool_foreach (t, cm->tables,
7911 if (table_id == t - cm->tables)
7913 rmp = vl_msg_api_alloc_as_if_client
7914 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7915 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7916 rmp->context = mp->context;
7917 rmp->table_id = ntohl(table_id);
7918 rmp->nbuckets = ntohl(t->nbuckets);
7919 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7920 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7921 rmp->active_sessions = ntohl(t->active_elements);
7922 rmp->next_table_index = ntohl(t->next_table_index);
7923 rmp->miss_next_index = ntohl(t->miss_next_index);
7924 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7925 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7934 rmp = vl_msg_api_alloc (sizeof (*rmp));
7935 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7936 rmp->context = mp->context;
7937 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7940 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7944 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7947 clib_warning ("BUG");
7951 send_classify_session_details (unix_shared_memory_queue_t * q,
7954 vnet_classify_entry_t * e, u32 context)
7956 vl_api_classify_session_details_t *rmp;
7958 rmp = vl_msg_api_alloc (sizeof (*rmp));
7959 memset (rmp, 0, sizeof (*rmp));
7960 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7961 rmp->context = context;
7962 rmp->table_id = ntohl (table_id);
7963 rmp->hit_next_index = ntohl (e->next_index);
7964 rmp->advance = ntohl (e->advance);
7965 rmp->opaque_index = ntohl (e->opaque_index);
7966 rmp->match_length = ntohl (match_length);
7967 clib_memcpy (rmp->match, e->key, match_length);
7969 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7973 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7975 vnet_classify_main_t *cm = &vnet_classify_main;
7976 unix_shared_memory_queue_t *q;
7978 u32 table_id = ntohl (mp->table_id);
7979 vnet_classify_table_t *t;
7981 q = vl_api_client_index_to_input_queue (mp->client_index);
7986 pool_foreach (t, cm->tables,
7988 if (table_id == t - cm->tables)
7990 vnet_classify_bucket_t * b;
7991 vnet_classify_entry_t * v, * save_v;
7994 for (i = 0; i < t->nbuckets; i++)
7996 b = &t->buckets [i];
8000 save_v = vnet_classify_get_entry (t, b->offset);
8001 for (j = 0; j < (1<<b->log2_pages); j++)
8003 for (k = 0; k < t->entries_per_page; k++)
8005 v = vnet_classify_entry_at_index
8006 (t, save_v, j*t->entries_per_page + k);
8007 if (vnet_classify_entry_is_free (v))
8010 send_classify_session_details
8011 (q, table_id, t->match_n_vectors * sizeof (u32x4),
8023 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
8025 vlib_main_t *vm = vlib_get_main ();
8026 flow_report_main_t *frm = &flow_report_main;
8027 vl_api_set_ipfix_exporter_reply_t *rmp;
8028 ip4_address_t collector, src;
8029 u16 collector_port = UDP_DST_PORT_ipfix;
8031 u32 template_interval;
8037 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
8038 collector_port = ntohs (mp->collector_port);
8039 if (collector_port == (u16) ~ 0)
8040 collector_port = UDP_DST_PORT_ipfix;
8041 memcpy (src.data, mp->src_address, sizeof (src.data));
8042 fib_id = ntohl (mp->vrf_id);
8044 ip4_main_t *im = &ip4_main;
8051 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
8054 rv = VNET_API_ERROR_NO_SUCH_FIB;
8060 path_mtu = ntohl (mp->path_mtu);
8062 path_mtu = 512; // RFC 7011 section 10.3.3.
8063 template_interval = ntohl (mp->template_interval);
8064 if (template_interval == ~0)
8065 template_interval = 20;
8066 udp_checksum = mp->udp_checksum;
8068 if (collector.as_u32 == 0)
8070 rv = VNET_API_ERROR_INVALID_VALUE;
8074 if (src.as_u32 == 0)
8076 rv = VNET_API_ERROR_INVALID_VALUE;
8080 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
8082 rv = VNET_API_ERROR_INVALID_VALUE;
8088 rv = VNET_API_ERROR_INVALID_VALUE;
8092 /* Reset report streams if we are reconfiguring IP addresses */
8093 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
8094 frm->src_address.as_u32 != src.as_u32 ||
8095 frm->collector_port != collector_port)
8096 vnet_flow_reports_reset (frm);
8098 frm->ipfix_collector.as_u32 = collector.as_u32;
8099 frm->collector_port = collector_port;
8100 frm->src_address.as_u32 = src.as_u32;
8101 frm->fib_index = fib_index;
8102 frm->path_mtu = path_mtu;
8103 frm->template_interval = template_interval;
8104 frm->udp_checksum = udp_checksum;
8106 /* Turn on the flow reporting process */
8107 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
8110 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
8114 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
8116 flow_report_main_t *frm = &flow_report_main;
8117 unix_shared_memory_queue_t *q;
8118 vl_api_ipfix_exporter_details_t *rmp;
8119 ip4_main_t *im = &ip4_main;
8122 q = vl_api_client_index_to_input_queue (mp->client_index);
8126 rmp = vl_msg_api_alloc (sizeof (*rmp));
8127 memset (rmp, 0, sizeof (*rmp));
8128 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
8129 rmp->context = mp->context;
8130 memcpy (rmp->collector_address, frm->ipfix_collector.data,
8131 sizeof (frm->ipfix_collector.data));
8132 rmp->collector_port = htons (frm->collector_port);
8133 memcpy (rmp->src_address, frm->src_address.data,
8134 sizeof (frm->src_address.data));
8135 if (frm->fib_index == ~0)
8138 vrf_id = im->fibs[frm->fib_index].ft_table_id;
8139 rmp->vrf_id = htonl (vrf_id);
8140 rmp->path_mtu = htonl (frm->path_mtu);
8141 rmp->template_interval = htonl (frm->template_interval);
8142 rmp->udp_checksum = (frm->udp_checksum != 0);
8144 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8148 vl_api_set_ipfix_classify_stream_t_handler
8149 (vl_api_set_ipfix_classify_stream_t * mp)
8151 vl_api_set_ipfix_classify_stream_reply_t *rmp;
8152 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8153 flow_report_main_t *frm = &flow_report_main;
8155 u32 src_port = UDP_DST_PORT_ipfix;
8158 domain_id = ntohl (mp->domain_id);
8159 src_port = ntohs (mp->src_port);
8161 if (fcm->src_port != 0 &&
8162 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
8164 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
8165 domain_id, (u16) src_port);
8169 fcm->domain_id = domain_id;
8170 fcm->src_port = (u16) src_port;
8172 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8176 vl_api_ipfix_classify_stream_dump_t_handler
8177 (vl_api_ipfix_classify_stream_dump_t * mp)
8179 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8180 unix_shared_memory_queue_t *q;
8181 vl_api_ipfix_classify_stream_details_t *rmp;
8183 q = vl_api_client_index_to_input_queue (mp->client_index);
8187 rmp = vl_msg_api_alloc (sizeof (*rmp));
8188 memset (rmp, 0, sizeof (*rmp));
8189 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
8190 rmp->context = mp->context;
8191 rmp->domain_id = htonl (fcm->domain_id);
8192 rmp->src_port = htons (fcm->src_port);
8194 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8198 vl_api_ipfix_classify_table_add_del_t_handler
8199 (vl_api_ipfix_classify_table_add_del_t * mp)
8201 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
8202 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8203 flow_report_main_t *frm = &flow_report_main;
8204 vnet_flow_report_add_del_args_t args;
8205 ipfix_classify_table_t *table;
8207 u32 classify_table_index;
8209 u8 transport_protocol;
8212 classify_table_index = ntohl (mp->table_id);
8213 ip_version = mp->ip_version;
8214 transport_protocol = mp->transport_protocol;
8215 is_add = mp->is_add;
8217 if (fcm->src_port == 0)
8219 /* call set_ipfix_classify_stream first */
8220 rv = VNET_API_ERROR_UNSPECIFIED;
8224 memset (&args, 0, sizeof (args));
8228 for (i = 0; i < vec_len (fcm->tables); i++)
8229 if (ipfix_classify_table_index_valid (i))
8230 if (fcm->tables[i].classify_table_index == classify_table_index)
8232 table = &fcm->tables[i];
8240 rv = VNET_API_ERROR_VALUE_EXIST;
8243 table = ipfix_classify_add_table ();
8244 table->classify_table_index = classify_table_index;
8250 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
8255 table->ip_version = ip_version;
8256 table->transport_protocol = transport_protocol;
8258 args.opaque.as_uword = table - fcm->tables;
8259 args.rewrite_callback = ipfix_classify_template_rewrite;
8260 args.flow_data_callback = ipfix_classify_send_flows;
8261 args.is_add = is_add;
8262 args.domain_id = fcm->domain_id;
8263 args.src_port = fcm->src_port;
8265 rv = vnet_flow_report_add_del (frm, &args);
8267 /* If deleting, or add failed */
8268 if (is_add == 0 || (rv && is_add))
8269 ipfix_classify_delete_table (table - fcm->tables);
8272 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8276 send_ipfix_classify_table_details (u32 table_index,
8277 unix_shared_memory_queue_t * q,
8280 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8281 vl_api_ipfix_classify_table_details_t *mp;
8283 ipfix_classify_table_t *table = &fcm->tables[table_index];
8285 mp = vl_msg_api_alloc (sizeof (*mp));
8286 memset (mp, 0, sizeof (*mp));
8287 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
8288 mp->context = context;
8289 mp->table_id = htonl (table->classify_table_index);
8290 mp->ip_version = table->ip_version;
8291 mp->transport_protocol = table->transport_protocol;
8293 vl_msg_api_send_shmem (q, (u8 *) & mp);
8297 vl_api_ipfix_classify_table_dump_t_handler
8298 (vl_api_ipfix_classify_table_dump_t * mp)
8300 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8301 unix_shared_memory_queue_t *q;
8304 q = vl_api_client_index_to_input_queue (mp->client_index);
8308 for (i = 0; i < vec_len (fcm->tables); i++)
8309 if (ipfix_classify_table_index_valid (i))
8310 send_ipfix_classify_table_details (i, q, mp->context);
8314 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8316 vl_api_pg_create_interface_reply_t *rmp;
8319 pg_main_t *pg = &pg_main;
8320 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8321 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
8324 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8326 rmp->sw_if_index = ntohl(pi->sw_if_index);
8332 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8334 vl_api_pg_capture_reply_t *rmp;
8337 vnet_main_t *vnm = vnet_get_main ();
8338 vnet_interface_main_t *im = &vnm->interface_main;
8339 vnet_hw_interface_t *hi = 0;
8341 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8342 u32 hw_if_index = ~0;
8343 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8346 vec_free (intf_name);
8348 if (hw_if_index != ~0)
8350 pg_capture_args_t _a, *a = &_a;
8352 u32 len = ntohl (mp->pcap_name_length);
8353 u8 *pcap_file_name = vec_new (u8, len);
8354 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8356 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8357 a->hw_if_index = hw_if_index;
8358 a->dev_instance = hi->dev_instance;
8359 a->is_enabled = mp->is_enabled;
8360 a->pcap_file_name = pcap_file_name;
8361 a->count = ntohl (mp->count);
8363 clib_error_t *e = pg_capture (a);
8366 clib_error_report (e);
8367 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8370 vec_free (pcap_file_name);
8372 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8376 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8378 vl_api_pg_enable_disable_reply_t *rmp;
8381 pg_main_t *pg = &pg_main;
8382 u32 stream_index = ~0;
8384 int is_enable = mp->is_enabled != 0;
8385 u32 len = ntohl (mp->stream_name_length) - 1;
8389 u8 *stream_name = vec_new (u8, len);
8390 clib_memcpy (stream_name, mp->stream_name, len);
8391 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8394 vec_free (stream_name);
8397 pg_enable_disable (stream_index, is_enable);
8399 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8403 vl_api_ip_source_and_port_range_check_add_del_t_handler
8404 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8406 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8409 u8 is_ipv6 = mp->is_ipv6;
8410 u8 is_add = mp->is_add;
8411 u8 mask_length = mp->mask_length;
8412 ip4_address_t ip4_addr;
8413 ip6_address_t ip6_addr;
8415 u16 *high_ports = 0;
8417 u16 tmp_low, tmp_high;
8421 // Validate port range
8422 num_ranges = mp->number_of_ranges;
8423 if (num_ranges > 32)
8424 { // This is size of array in VPE.API
8425 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8429 vec_reset_length (low_ports);
8430 vec_reset_length (high_ports);
8432 for (i = 0; i < num_ranges; i++)
8434 tmp_low = mp->low_ports[i];
8435 tmp_high = mp->high_ports[i];
8436 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8437 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8438 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8440 rv = VNET_API_ERROR_INVALID_VALUE;
8443 vec_add1 (low_ports, tmp_low);
8444 vec_add1 (high_ports, tmp_high + 1);
8447 // Validate mask_length
8448 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8450 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8454 vrf_id = ntohl (mp->vrf_id);
8458 rv = VNET_API_ERROR_INVALID_VALUE;
8465 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8466 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8470 high_ports, is_add);
8474 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8475 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8479 high_ports, is_add);
8483 vec_free (low_ports);
8484 vec_free (high_ports);
8485 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8489 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8490 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8492 vlib_main_t *vm = vlib_get_main ();
8493 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8494 ip4_main_t *im = &ip4_main;
8497 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8498 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8502 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8503 ntohl (mp->tcp_out_vrf_id);
8504 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8505 ntohl (mp->udp_out_vrf_id);
8506 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8507 ntohl (mp->tcp_in_vrf_id);
8508 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8509 ntohl (mp->udp_in_vrf_id);
8512 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8514 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8516 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8520 rv = VNET_API_ERROR_INVALID_VALUE;
8524 fib_index[i] = p[0];
8529 sw_if_index = ntohl (mp->sw_if_index);
8531 VALIDATE_SW_IF_INDEX (mp);
8534 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8537 BAD_SW_IF_INDEX_LABEL;
8540 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8544 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8547 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8549 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8550 u32 sw_if_index = ~0;
8552 /* Check src & dst are different */
8553 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8555 rv = VNET_API_ERROR_SAME_SRC_DST;
8559 memset (a, 0, sizeof (*a));
8561 /* ip addresses sent in network byte order */
8562 clib_memcpy (&(a->src), mp->src_address, 4);
8563 clib_memcpy (&(a->dst), mp->dst_address, 4);
8564 a->is_add = mp->is_add;
8565 a->lsa = ntohl (mp->local_sa_id);
8566 a->rsa = ntohl (mp->remote_sa_id);
8568 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8572 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8574 rmp->sw_if_index = ntohl (sw_if_index);
8579 static void send_ipsec_gre_tunnel_details
8580 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8582 vl_api_ipsec_gre_tunnel_details_t *rmp;
8584 rmp = vl_msg_api_alloc (sizeof (*rmp));
8585 memset (rmp, 0, sizeof (*rmp));
8586 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8587 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8588 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8589 rmp->sw_if_index = htonl (t->sw_if_index);
8590 rmp->local_sa_id = htonl (t->local_sa_id);
8591 rmp->remote_sa_id = htonl (t->remote_sa_id);
8592 rmp->context = context;
8594 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8597 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8598 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8600 unix_shared_memory_queue_t *q;
8601 ipsec_gre_main_t *igm = &ipsec_gre_main;
8602 ipsec_gre_tunnel_t *t;
8605 q = vl_api_client_index_to_input_queue (mp->client_index);
8611 sw_if_index = ntohl (mp->sw_if_index);
8613 if (~0 == sw_if_index)
8616 pool_foreach (t, igm->tunnels,
8618 send_ipsec_gre_tunnel_details(t, q, mp->context);
8624 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8625 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8629 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8630 send_ipsec_gre_tunnel_details (t, q, mp->context);
8635 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8637 vl_api_delete_subif_reply_t *rmp;
8640 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8642 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8646 vl_api_l2_interface_pbb_tag_rewrite_t_handler
8647 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
8649 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
8650 vnet_main_t *vnm = vnet_get_main ();
8651 vlib_main_t *vm = vlib_get_main ();
8655 VALIDATE_SW_IF_INDEX (mp);
8657 vtr_op = ntohl (mp->vtr_op);
8661 case L2_VTR_DISABLED:
8664 case L2_VTR_TRANSLATE_2_1:
8668 rv = VNET_API_ERROR_INVALID_VALUE;
8669 goto bad_sw_if_index;
8672 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
8673 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
8674 ntohl (mp->i_sid), ntohs (mp->outer_tag));
8676 BAD_SW_IF_INDEX_LABEL;
8678 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
8682 vl_api_punt_t_handler (vl_api_punt_t * mp)
8684 vl_api_punt_reply_t *rmp;
8685 vlib_main_t *vm = vlib_get_main ();
8687 clib_error_t *error;
8689 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8690 ntohs (mp->l4_port), mp->is_add);
8694 clib_error_report (error);
8697 REPLY_MACRO (VL_API_PUNT_REPLY);
8701 vl_api_flow_classify_set_interface_t_handler
8702 (vl_api_flow_classify_set_interface_t * mp)
8704 vlib_main_t *vm = vlib_get_main ();
8705 vl_api_flow_classify_set_interface_reply_t *rmp;
8707 u32 sw_if_index, ip4_table_index, ip6_table_index;
8709 ip4_table_index = ntohl (mp->ip4_table_index);
8710 ip6_table_index = ntohl (mp->ip6_table_index);
8711 sw_if_index = ntohl (mp->sw_if_index);
8713 VALIDATE_SW_IF_INDEX (mp);
8715 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
8716 ip6_table_index, mp->is_add);
8718 BAD_SW_IF_INDEX_LABEL;
8720 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
8724 send_flow_classify_details (u32 sw_if_index,
8726 unix_shared_memory_queue_t * q, u32 context)
8728 vl_api_flow_classify_details_t *mp;
8730 mp = vl_msg_api_alloc (sizeof (*mp));
8731 memset (mp, 0, sizeof (*mp));
8732 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
8733 mp->context = context;
8734 mp->sw_if_index = htonl (sw_if_index);
8735 mp->table_index = htonl (table_index);
8737 vl_msg_api_send_shmem (q, (u8 *) & mp);
8741 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8743 unix_shared_memory_queue_t *q;
8744 flow_classify_main_t *pcm = &flow_classify_main;
8748 q = vl_api_client_index_to_input_queue (mp->client_index);
8752 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8754 if (vec_len (vec_tbl))
8756 for (i = 0; i < vec_len (vec_tbl); i++)
8758 if (vec_elt (vec_tbl, i) == ~0)
8761 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8767 #define BOUNCE_HANDLER(nn) \
8768 static void vl_api_##nn##_t_handler ( \
8769 vl_api_##nn##_t *mp) \
8771 vpe_client_registration_t *reg; \
8772 vpe_api_main_t * vam = &vpe_api_main; \
8773 unix_shared_memory_queue_t * q; \
8775 /* One registration only... */ \
8776 pool_foreach(reg, vam->nn##_registrations, \
8778 q = vl_api_client_index_to_input_queue (reg->client_index); \
8781 * If the queue is stuffed, turf the msg and complain \
8782 * It's unlikely that the intended recipient is \
8783 * alive; avoid deadlock at all costs. \
8785 if (q->cursize == q->maxsize) { \
8786 clib_warning ("ERROR: receiver queue full, drop msg"); \
8787 vl_msg_api_free (mp); \
8790 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8794 vl_msg_api_free (mp); \
8799 * Add vpe's API message handlers to the table.
8800 * vlib has alread mapped shared memory and
8801 * added the client registration handlers.
8802 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8805 static clib_error_t *
8806 vpe_api_hookup (vlib_main_t * vm)
8808 api_main_t *am = &api_main;
8811 vl_msg_api_set_handlers(VL_API_##N, #n, \
8812 vl_api_##n##_t_handler, \
8814 vl_api_##n##_t_endian, \
8815 vl_api_##n##_t_print, \
8816 sizeof(vl_api_##n##_t), 1);
8817 foreach_vpe_api_msg;
8821 * Manually register the sr tunnel add del msg, so we trace
8822 * enough bytes to capture a typical segment list
8824 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8825 "sr_tunnel_add_del",
8826 vl_api_sr_tunnel_add_del_t_handler,
8828 vl_api_sr_tunnel_add_del_t_endian,
8829 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8833 * Manually register the sr policy add del msg, so we trace
8834 * enough bytes to capture a typical tunnel name list
8836 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8837 "sr_policy_add_del",
8838 vl_api_sr_policy_add_del_t_handler,
8840 vl_api_sr_policy_add_del_t_endian,
8841 vl_api_sr_policy_add_del_t_print, 256, 1);
8844 * Trace space for 8 MPLS encap labels, classifier mask+match
8846 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8847 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8848 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8849 += 5 * sizeof (u32x4);
8850 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8853 * Thread-safe API messages
8855 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8856 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8861 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8863 static clib_error_t *
8864 vpe_api_init (vlib_main_t * vm)
8866 vpe_api_main_t *am = &vpe_api_main;
8869 am->vnet_main = vnet_get_main ();
8870 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8871 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8872 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8873 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8874 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8875 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8878 vl_set_memory_region_name ("/vpe-api");
8879 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8884 VLIB_INIT_FUNCTION (vpe_api_init);
8887 static clib_error_t *
8888 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8891 u64 baseva, size, pvt_heap_size;
8893 const int max_buf_size = 4096;
8895 struct passwd _pw, *pw;
8896 struct group _grp, *grp;
8898 buf = vec_new (char, 128);
8899 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8901 if (unformat (input, "prefix %s", &chroot_path))
8903 vec_add1 (chroot_path, 0);
8904 vl_set_memory_root_path ((char *) chroot_path);
8906 else if (unformat (input, "uid %d", &uid))
8907 vl_set_memory_uid (uid);
8908 else if (unformat (input, "gid %d", &gid))
8909 vl_set_memory_gid (gid);
8910 else if (unformat (input, "baseva %llx", &baseva))
8911 vl_set_global_memory_baseva (baseva);
8912 else if (unformat (input, "global-size %lldM", &size))
8913 vl_set_global_memory_size (size * (1ULL << 20));
8914 else if (unformat (input, "global-size %lldG", &size))
8915 vl_set_global_memory_size (size * (1ULL << 30));
8916 else if (unformat (input, "global-size %lld", &size))
8917 vl_set_global_memory_size (size);
8918 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8919 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8920 else if (unformat (input, "global-pvt-heap-size size %lld",
8922 vl_set_global_pvt_heap_size (pvt_heap_size);
8923 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8924 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8925 else if (unformat (input, "api-pvt-heap-size size %lld",
8927 vl_set_api_pvt_heap_size (pvt_heap_size);
8928 else if (unformat (input, "api-size %lldM", &size))
8929 vl_set_api_memory_size (size * (1ULL << 20));
8930 else if (unformat (input, "api-size %lldG", &size))
8931 vl_set_api_memory_size (size * (1ULL << 30));
8932 else if (unformat (input, "api-size %lld", &size))
8933 vl_set_api_memory_size (size);
8934 else if (unformat (input, "uid %s", &s))
8936 /* lookup the username */
8939 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8940 && (vec_len (buf) <= max_buf_size))
8942 vec_resize (buf, vec_len (buf) * 2);
8946 e = clib_error_return_code (0, rv,
8947 CLIB_ERROR_ERRNO_VALID |
8949 "cannot fetch username %s", s);
8957 clib_error_return_fatal (0, "username %s does not exist", s);
8963 vl_set_memory_uid (pw->pw_uid);
8965 else if (unformat (input, "gid %s", &s))
8967 /* lookup the group name */
8970 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8971 && (vec_len (buf) <= max_buf_size))
8973 vec_resize (buf, vec_len (buf) * 2);
8977 e = clib_error_return_code (0, rv,
8978 CLIB_ERROR_ERRNO_VALID |
8980 "cannot fetch group %s", s);
8987 e = clib_error_return_fatal (0, "group %s does not exist", s);
8994 vl_set_memory_gid (grp->gr_gid);
8997 return clib_error_return (0, "unknown input `%U'",
8998 format_unformat_error, input);
9003 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
9006 get_unformat_vnet_sw_interface (void)
9008 return (void *) &unformat_vnet_sw_interface;
9011 #undef vl_api_version
9012 #define vl_api_version(n,v) static u32 vpe_api_version = v;
9013 #include <vpp-api/vpe.api.h>
9014 #undef vl_api_version
9017 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
9019 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
9021 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
9022 clib_host_to_net_u32 (mp->api_versions[0]),
9030 format_arp_event (u8 * s, va_list * args)
9032 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
9034 s = format (s, "pid %d: ", event->pid);
9036 s = format (s, "bd mac/ip4 binding events");
9038 s = format (s, "resolution for %U", format_ip4_address, &event->address);
9043 format_nd_event (u8 * s, va_list * args)
9045 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
9047 s = format (s, "pid %d: ", event->pid);
9049 s = format (s, "bd mac/ip6 binding events");
9051 s = format (s, "resolution for %U", format_ip6_address, event->address);
9055 static clib_error_t *
9056 show_ip_arp_nd_events_fn (vlib_main_t * vm,
9057 unformat_input_t * input, vlib_cli_command_t * cmd)
9059 vpe_api_main_t *am = &vpe_api_main;
9060 vl_api_ip4_arp_event_t *arp_event;
9061 vl_api_ip6_nd_event_t *nd_event;
9063 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
9065 vlib_cli_output (vm, "No active arp or nd event registrations");
9070 pool_foreach (arp_event, am->arp_events,
9072 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
9075 pool_foreach (nd_event, am->nd_events,
9077 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
9085 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
9086 .path = "show arp-nd-event registrations",
9087 .function = show_ip_arp_nd_events_fn,
9088 .short_help = "Show ip4 arp and ip6 nd event registrations",
9093 * fd.io coding-style-patch-verification: ON
9096 * eval: (c-set-style "gnu")