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) \
462 _(IPSEC_SPD_DUMP, ipsec_spd_dump)
465 #define QUOTE(x) QUOTE_(x)
467 #define foreach_registration_hash \
468 _(interface_events) \
469 _(to_netconf_server) \
470 _(from_netconf_server) \
471 _(to_netconf_client) \
472 _(from_netconf_client) \
477 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
478 RESOLVE_IP6_ADD_DEL_ROUTE,
479 RESOLVE_MPLS_ETHERNET_ADD_DEL,
487 vl_api_ip_add_del_route_t r;
488 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
495 #define _(a) uword *a##_registration_hash; \
496 vpe_client_registration_t * a##_registrations;
497 foreach_registration_hash
499 /* notifications happen really early in the game */
500 u8 link_state_process_up;
502 /* ip4 and ip6 pending route adds */
503 pending_route_t *pending_routes;
505 /* ip4 arp event registration pool */
506 vl_api_ip4_arp_event_t *arp_events;
508 /* ip6 nd event registration pool */
509 vl_api_ip6_nd_event_t *nd_events;
512 vlib_main_t *vlib_main;
513 vnet_main_t *vnet_main;
516 static vlib_node_registration_t vpe_resolver_process_node;
517 static vpe_api_main_t vpe_api_main;
519 static void send_sw_interface_flags (vpe_api_main_t * am,
520 unix_shared_memory_queue_t * q,
521 vnet_sw_interface_t * swif);
522 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
523 unix_shared_memory_queue_t * q,
526 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
527 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
530 /* Clean up all registrations belonging to the indicated client */
532 vl_api_memclnt_delete_callback (u32 client_index)
534 vpe_api_main_t *vam = &vpe_api_main;
535 vpe_client_registration_t *rp;
537 int stats_memclnt_delete_callback (u32 client_index);
539 stats_memclnt_delete_callback (client_index);
542 p = hash_get (vam->a##_registration_hash, client_index); \
544 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
545 pool_put (vam->a##_registrations, rp); \
546 hash_unset (vam->a##_registration_hash, client_index); \
548 foreach_registration_hash;
553 #define API_LINK_STATE_EVENT 1
554 #define API_ADMIN_UP_DOWN_EVENT 2
557 event_data_cmp (void *a1, void *a2)
562 return (word) e1[0] - (word) e2[0];
566 link_state_process (vlib_main_t * vm,
567 vlib_node_runtime_t * rt, vlib_frame_t * f)
569 vpe_api_main_t *vam = &vpe_api_main;
570 vnet_main_t *vnm = vam->vnet_main;
571 vnet_sw_interface_t *swif;
572 uword *event_data = 0;
573 vpe_client_registration_t *reg;
575 u32 prev_sw_if_index;
576 unix_shared_memory_queue_t *q;
578 vam->link_state_process_up = 1;
582 vlib_process_wait_for_event (vm);
584 /* Unified list of changed link or admin state sw_if_indices */
585 vlib_process_get_events_with_type
586 (vm, &event_data, API_LINK_STATE_EVENT);
587 vlib_process_get_events_with_type
588 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
590 /* Sort, so we can eliminate duplicates */
591 vec_sort_with_function (event_data, event_data_cmp);
593 prev_sw_if_index = ~0;
595 for (i = 0; i < vec_len (event_data); i++)
597 /* Only one message per swif */
598 if (prev_sw_if_index == event_data[i])
600 prev_sw_if_index = event_data[i];
603 pool_foreach(reg, vam->interface_events_registrations,
605 q = vl_api_client_index_to_input_queue (reg->client_index);
608 /* sw_interface may be deleted already */
609 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
612 swif = vnet_get_sw_interface (vnm, event_data[i]);
613 send_sw_interface_flags (vam, q, swif);
619 vec_reset_length (event_data);
625 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
627 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
628 u32 hw_if_index, u32 flags);
631 VLIB_REGISTER_NODE (link_state_process_node,static) = {
632 .function = link_state_process,
633 .type = VLIB_NODE_TYPE_PROCESS,
634 .name = "vpe-link-state-process",
638 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
639 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
641 static clib_error_t *
642 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
644 vpe_api_main_t *vam = &vpe_api_main;
645 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
647 if (vam->link_state_process_up)
648 vlib_process_signal_event (vam->vlib_main,
649 link_state_process_node.index,
650 API_LINK_STATE_EVENT, hi->sw_if_index);
654 static clib_error_t *
655 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
657 vpe_api_main_t *vam = &vpe_api_main;
660 * Note: it's perfectly fair to set a subif admin up / admin down.
661 * Note the subtle distinction between this routine and the previous
664 if (vam->link_state_process_up)
665 vlib_process_signal_event (vam->vlib_main,
666 link_state_process_node.index,
667 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
671 #define pub_sub_handler(lca,UCA) \
672 static void vl_api_want_##lca##_t_handler ( \
673 vl_api_want_##lca##_t *mp) \
675 vpe_api_main_t *vam = &vpe_api_main; \
676 vpe_client_registration_t *rp; \
677 vl_api_want_##lca##_reply_t *rmp; \
681 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
683 if (mp->enable_disable) { \
684 clib_warning ("pid %d: already enabled...", mp->pid); \
685 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
688 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
689 pool_put (vam->lca##_registrations, rp); \
690 hash_unset (vam->lca##_registration_hash, \
695 if (mp->enable_disable == 0) { \
696 clib_warning ("pid %d: already disabled...", mp->pid); \
697 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
700 pool_get (vam->lca##_registrations, rp); \
701 rp->client_index = mp->client_index; \
702 rp->client_pid = mp->pid; \
703 hash_set (vam->lca##_registration_hash, rp->client_index, \
704 rp - vam->lca##_registrations); \
707 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
711 pub_sub_handler (interface_events, INTERFACE_EVENTS)
712 pub_sub_handler (oam_events, OAM_EVENTS)
715 #define RESOLUTION_EVENT 1
716 #define RESOLUTION_PENDING_EVENT 2
717 #define IP4_ARP_EVENT 3
718 #define IP6_ND_EVENT 4
720 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
722 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
724 static int mpls_ethernet_add_del_tunnel_2_t_handler
725 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
728 handle_ip4_arp_event (u32 pool_index)
730 vpe_api_main_t *vam = &vpe_api_main;
731 vnet_main_t *vnm = vam->vnet_main;
732 vlib_main_t *vm = vam->vlib_main;
733 vl_api_ip4_arp_event_t *event;
734 vl_api_ip4_arp_event_t *mp;
735 unix_shared_memory_queue_t *q;
737 /* Client can cancel, die, etc. */
738 if (pool_is_free_index (vam->arp_events, pool_index))
741 event = pool_elt_at_index (vam->arp_events, pool_index);
743 q = vl_api_client_index_to_input_queue (event->client_index);
746 (void) vnet_add_del_ip4_arp_change_event
747 (vnm, arp_change_delete_callback,
748 event->pid, &event->address,
749 vpe_resolver_process_node.index, IP4_ARP_EVENT,
750 ~0 /* pool index, notused */ , 0 /* is_add */ );
754 if (q->cursize < q->maxsize)
756 mp = vl_msg_api_alloc (sizeof (*mp));
757 clib_memcpy (mp, event, sizeof (*mp));
758 vl_msg_api_send_shmem (q, (u8 *) & mp);
762 static f64 last_time;
764 * Throttle syslog msgs.
765 * It's pretty tempting to just revoke the registration...
767 if (vlib_time_now (vm) > last_time + 10.0)
769 clib_warning ("arp event for %U to pid %d: queue stuffed!",
770 format_ip4_address, &event->address, event->pid);
771 last_time = vlib_time_now (vm);
777 handle_ip6_nd_event (u32 pool_index)
779 vpe_api_main_t *vam = &vpe_api_main;
780 vnet_main_t *vnm = vam->vnet_main;
781 vlib_main_t *vm = vam->vlib_main;
782 vl_api_ip6_nd_event_t *event;
783 vl_api_ip6_nd_event_t *mp;
784 unix_shared_memory_queue_t *q;
786 /* Client can cancel, die, etc. */
787 if (pool_is_free_index (vam->nd_events, pool_index))
790 event = pool_elt_at_index (vam->nd_events, pool_index);
792 q = vl_api_client_index_to_input_queue (event->client_index);
795 (void) vnet_add_del_ip6_nd_change_event
796 (vnm, nd_change_delete_callback,
797 event->pid, &event->address,
798 vpe_resolver_process_node.index, IP6_ND_EVENT,
799 ~0 /* pool index, notused */ , 0 /* is_add */ );
803 if (q->cursize < q->maxsize)
805 mp = vl_msg_api_alloc (sizeof (*mp));
806 clib_memcpy (mp, event, sizeof (*mp));
807 vl_msg_api_send_shmem (q, (u8 *) & mp);
811 static f64 last_time;
813 * Throttle syslog msgs.
814 * It's pretty tempting to just revoke the registration...
816 if (vlib_time_now (vm) > last_time + 10.0)
818 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
819 format_ip6_address, &event->address, event->pid);
820 last_time = vlib_time_now (vm);
826 resolver_process (vlib_main_t * vm,
827 vlib_node_runtime_t * rt, vlib_frame_t * f)
830 uword *event_data = 0;
832 vpe_api_main_t *vam = &vpe_api_main;
834 vl_api_ip_add_del_route_t *adr;
835 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
836 u32 *resolution_failures = 0;
842 vlib_process_wait_for_event_or_clock (vm, timeout);
844 event_type = vlib_process_get_events (vm, &event_data);
848 case RESOLUTION_PENDING_EVENT:
852 case RESOLUTION_EVENT:
853 for (i = 0; i < vec_len (event_data); i++)
856 * Resolution events can occur long after the
857 * original request has timed out. $$$ add a cancel
860 if (pool_is_free_index (vam->pending_routes, event_data[i]))
863 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
867 switch (pr->resolve_type)
869 case RESOLVE_IP4_ADD_DEL_ROUTE:
870 rv = ip4_add_del_route_t_handler (adr);
871 clib_warning ("resolver: add %U/%d via %U %s",
873 (ip4_address_t *) & (adr->dst_address),
874 adr->dst_address_length,
876 (ip4_address_t *) & (adr->next_hop_address),
877 (rv >= 0) ? "succeeded" : "failed");
880 case RESOLVE_IP6_ADD_DEL_ROUTE:
881 rv = ip6_add_del_route_t_handler (adr);
882 clib_warning ("resolver: add %U/%d via %U %s",
884 (ip6_address_t *) & (adr->dst_address),
885 adr->dst_address_length,
887 (ip6_address_t *) & (adr->next_hop_address),
888 (rv >= 0) ? "succeeded" : "failed");
891 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
892 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
893 clib_warning ("resolver: add mpls-o-e via %U %s",
896 (pme->next_hop_ip4_address_in_outer_vrf),
897 (rv >= 0) ? "succeeded" : "failed");
901 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
903 pool_put (vam->pending_routes, pr);
908 for (i = 0; i < vec_len (event_data); i++)
909 handle_ip4_arp_event (event_data[i]);
913 for (i = 0; i < vec_len (event_data); i++)
914 handle_ip6_nd_event (event_data[i]);
917 case ~0: /* timeout, retry pending resolutions */
919 pool_foreach (pr, vam->pending_routes,
925 /* May fail, e.g. due to interface down */
926 switch (pr->resolve_type)
928 case RESOLVE_IP4_ADD_DEL_ROUTE:
929 e = ip4_probe_neighbor
930 (vm, (ip4_address_t *)&(adr->next_hop_address),
931 ntohl(adr->next_hop_sw_if_index));
934 case RESOLVE_IP6_ADD_DEL_ROUTE:
935 e = ip6_probe_neighbor
936 (vm, (ip6_address_t *)&(adr->next_hop_address),
937 ntohl(adr->next_hop_sw_if_index));
940 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
942 e = ip4_probe_neighbor
944 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
945 pme->resolve_opaque);
949 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
954 clib_error_report (e);
956 adr->resolve_attempts = 1;
958 pme->resolve_attempts = 1;
962 adr->resolve_attempts -= 1;
963 if (adr->resolve_attempts == 0)
964 vec_add1 (resolution_failures,
965 pr - vam->pending_routes);
969 pme->resolve_attempts -= 1;
970 if (pme->resolve_attempts == 0)
971 vec_add1 (resolution_failures,
972 pr - vam->pending_routes);
976 for (i = 0; i < vec_len (resolution_failures); i++)
978 pr = pool_elt_at_index (vam->pending_routes,
979 resolution_failures[i]);
983 switch (pr->resolve_type)
985 case RESOLVE_IP4_ADD_DEL_ROUTE:
986 clib_warning ("resolver: add %U/%d via %U retry failure",
988 (ip4_address_t *) & (adr->dst_address),
989 adr->dst_address_length,
991 (ip4_address_t *) & (adr->next_hop_address));
994 case RESOLVE_IP6_ADD_DEL_ROUTE:
995 clib_warning ("resolver: add %U/%d via %U retry failure",
997 (ip6_address_t *) & (adr->dst_address),
998 adr->dst_address_length,
1000 (ip6_address_t *) & (adr->next_hop_address));
1003 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
1004 clib_warning ("resolver: add mpls-o-e via %U retry failure",
1007 (pme->next_hop_ip4_address_in_outer_vrf));
1011 clib_warning ("BUG");
1013 pool_put (vam->pending_routes, pr);
1015 vec_reset_length (resolution_failures);
1018 if (pool_elts (vam->pending_routes) == 0)
1020 vec_reset_length (event_data);
1022 return 0; /* or not */
1026 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
1027 .function = resolver_process,
1028 .type = VLIB_NODE_TYPE_PROCESS,
1029 .name = "vpe-route-resolver-process",
1034 add_del_route_t_handler (u8 is_multipath,
1041 u32 classify_table_index,
1043 u8 is_resolve_attached,
1045 const fib_prefix_t * prefix,
1046 u8 next_hop_proto_is_ip4,
1047 const ip46_address_t * next_hop,
1048 u32 next_hop_sw_if_index,
1049 u8 next_hop_fib_index,
1050 u32 next_hop_weight, u32 next_hop_out_label)
1052 vnet_classify_main_t *cm = &vnet_classify_main;
1053 stats_main_t *sm = &stats_main;
1057 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1059 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1061 if (is_resolve_host)
1062 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1063 if (is_resolve_attached)
1064 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1067 fib_table_entry_path_add (fib_index,
1070 FIB_ENTRY_FLAG_NONE,
1071 (next_hop_proto_is_ip4 ?
1075 next_hop_sw_if_index,
1078 next_hop_out_label, path_flags);
1080 fib_table_entry_path_remove (fib_index,
1083 (next_hop_proto_is_ip4 ?
1087 next_hop_sw_if_index,
1089 next_hop_weight, path_flags);
1095 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1097 if (is_drop || is_local || is_classify || is_unreach || is_prohibit)
1100 * special route types that link directly to the adj
1104 dpo_id_t dpo = DPO_INVALID;
1107 dproto = fib_proto_to_dpo (prefix->fp_proto);
1110 ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo);
1112 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
1113 else if (is_unreach)
1114 ip_null_dpo_add_and_lock (dproto,
1115 IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo);
1116 else if (is_prohibit)
1117 ip_null_dpo_add_and_lock (dproto,
1118 IP_NULL_ACTION_SEND_ICMP_PROHIBIT,
1120 else if (is_classify)
1122 if (pool_is_free_index (cm->tables,
1123 ntohl (classify_table_index)))
1126 return VNET_API_ERROR_NO_SUCH_TABLE;
1129 dpo_set (&dpo, DPO_CLASSIFY, dproto,
1130 classify_dpo_create (dproto,
1131 ntohl (classify_table_index)));
1136 return VNET_API_ERROR_NO_SUCH_TABLE;
1139 fib_table_entry_special_dpo_update (fib_index,
1142 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
1147 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
1154 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1156 if (is_resolve_host)
1157 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1158 if (is_resolve_attached)
1159 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1161 fib_table_entry_update_one_path (fib_index,
1164 FIB_ENTRY_FLAG_NONE,
1165 (next_hop_proto_is_ip4 ?
1169 next_hop_sw_if_index,
1172 next_hop_out_label, path_flags);
1176 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
1185 add_del_route_check (fib_protocol_t table_proto,
1187 u32 next_hop_sw_if_index,
1188 fib_protocol_t next_hop_table_proto,
1189 u32 next_hop_table_id,
1190 u8 create_missing_tables,
1191 u32 * fib_index, u32 * next_hop_fib_index)
1193 vnet_main_t *vnm = vnet_get_main ();
1195 *fib_index = fib_table_find (table_proto, ntohl (table_id));
1196 if (~0 == *fib_index)
1198 if (create_missing_tables)
1200 *fib_index = fib_table_find_or_create_and_lock (table_proto,
1205 /* No such VRF, and we weren't asked to create one */
1206 return VNET_API_ERROR_NO_SUCH_FIB;
1210 if (~0 != ntohl (next_hop_sw_if_index))
1212 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1213 ntohl (next_hop_sw_if_index)))
1215 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1220 *next_hop_fib_index = fib_table_find (next_hop_table_proto,
1221 ntohl (next_hop_table_id));
1223 if (~0 == *next_hop_fib_index)
1225 if (create_missing_tables)
1227 *next_hop_fib_index =
1228 fib_table_find_or_create_and_lock (next_hop_table_proto,
1229 ntohl (next_hop_table_id));
1233 /* No such VRF, and we weren't asked to create one */
1234 return VNET_API_ERROR_NO_SUCH_FIB;
1243 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1245 u32 fib_index, next_hop_fib_index;
1248 rv = add_del_route_check (FIB_PROTOCOL_IP4,
1250 mp->next_hop_sw_if_index,
1252 mp->next_hop_table_id,
1253 mp->create_vrf_if_needed,
1254 &fib_index, &next_hop_fib_index);
1259 fib_prefix_t pfx = {
1260 .fp_len = mp->dst_address_length,
1261 .fp_proto = FIB_PROTOCOL_IP4,
1263 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
1266 memset (&nh, 0, sizeof (nh));
1267 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
1269 return (add_del_route_t_handler (mp->is_multipath,
1276 mp->classify_table_index,
1277 mp->is_resolve_host,
1278 mp->is_resolve_attached,
1281 ntohl (mp->next_hop_sw_if_index),
1283 mp->next_hop_weight,
1284 ntohl (mp->next_hop_out_label)));
1288 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1290 u32 fib_index, next_hop_fib_index;
1293 rv = add_del_route_check (FIB_PROTOCOL_IP6,
1295 mp->next_hop_sw_if_index,
1297 mp->next_hop_table_id,
1298 mp->create_vrf_if_needed,
1299 &fib_index, &next_hop_fib_index);
1304 fib_prefix_t pfx = {
1305 .fp_len = mp->dst_address_length,
1306 .fp_proto = FIB_PROTOCOL_IP6,
1308 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
1311 memset (&nh, 0, sizeof (nh));
1312 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
1314 return (add_del_route_t_handler (mp->is_multipath,
1321 mp->classify_table_index,
1322 mp->is_resolve_host,
1323 mp->is_resolve_attached,
1325 &nh, ntohl (mp->next_hop_sw_if_index),
1327 mp->next_hop_weight,
1328 ntohl (mp->next_hop_out_label)));
1332 mpls_route_add_del_t_handler (vnet_main_t * vnm,
1333 vl_api_mpls_route_add_del_t * mp)
1335 u32 fib_index, next_hop_fib_index;
1339 fib_prefix_t pfx = {
1341 .fp_proto = FIB_PROTOCOL_MPLS,
1342 .fp_eos = mp->mr_eos,
1343 .fp_label = ntohl (mp->mr_label),
1347 if (mp->mr_next_hop_proto_is_ip4)
1349 pfx.fp_payload_proto = DPO_PROTO_IP4;
1353 pfx.fp_payload_proto = DPO_PROTO_IP6;
1358 pfx.fp_payload_proto = DPO_PROTO_MPLS;
1361 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
1363 mp->mr_next_hop_sw_if_index,
1364 dpo_proto_to_fib (pfx.fp_payload_proto),
1365 mp->mr_next_hop_table_id,
1366 mp->mr_create_table_if_needed,
1367 &fib_index, &next_hop_fib_index);
1373 memset (&nh, 0, sizeof (nh));
1375 if (mp->mr_next_hop_proto_is_ip4)
1376 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
1378 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
1380 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
1381 0, // mp->is_unreach,
1382 0, // mp->is_prohibit,
1385 mp->mr_classify_table_index,
1386 mp->mr_is_resolve_host,
1387 mp->mr_is_resolve_attached,
1389 mp->mr_next_hop_proto_is_ip4,
1390 &nh, ntohl (mp->mr_next_hop_sw_if_index),
1392 mp->mr_next_hop_weight,
1393 ntohl (mp->mr_next_hop_out_label)));
1397 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1399 vl_api_ip_add_del_route_reply_t *rmp;
1401 vnet_main_t *vnm = vnet_get_main ();
1406 rv = ip6_add_del_route_t_handler (mp);
1408 rv = ip4_add_del_route_t_handler (mp);
1410 rv = (rv == 0) ? vnm->api_errno : rv;
1412 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1416 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
1418 vl_api_mpls_route_add_del_reply_t *rmp;
1422 vnm = vnet_get_main ();
1425 rv = mpls_route_add_del_t_handler (vnm, mp);
1427 rv = (rv == 0) ? vnm->api_errno : rv;
1429 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1433 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
1434 vl_api_mpls_ip_bind_unbind_t * mp)
1436 u32 mpls_fib_index, ip_fib_index;
1439 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
1441 if (~0 == mpls_fib_index)
1443 if (mp->mb_create_table_if_needed)
1446 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
1447 ntohl (mp->mb_mpls_table_id));
1450 return VNET_API_ERROR_NO_SUCH_FIB;
1453 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
1456 ntohl (mp->mb_ip_table_id));
1457 if (~0 == ip_fib_index)
1458 return VNET_API_ERROR_NO_SUCH_FIB;
1460 fib_prefix_t pfx = {
1461 .fp_len = mp->mb_address_length,
1466 pfx.fp_proto = FIB_PROTOCOL_IP4;
1467 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
1468 sizeof (pfx.fp_addr.ip4));
1472 pfx.fp_proto = FIB_PROTOCOL_IP6;
1473 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
1474 sizeof (pfx.fp_addr.ip6));
1478 fib_table_entry_local_label_add (ip_fib_index, &pfx,
1479 ntohl (mp->mb_label));
1481 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
1482 ntohl (mp->mb_label));
1488 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
1490 vl_api_mpls_route_add_del_reply_t *rmp;
1494 vnm = vnet_get_main ();
1497 rv = mpls_ip_bind_unbind_handler (vnm, mp);
1499 rv = (rv == 0) ? vnm->api_errno : rv;
1501 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1505 vl_api_sw_interface_add_del_address_t_handler
1506 (vl_api_sw_interface_add_del_address_t * mp)
1508 vlib_main_t *vm = vlib_get_main ();
1509 vl_api_sw_interface_add_del_address_reply_t *rmp;
1513 VALIDATE_SW_IF_INDEX (mp);
1515 is_del = mp->is_add == 0;
1518 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1519 else if (mp->is_ipv6)
1520 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1521 (void *) mp->address,
1522 mp->address_length, is_del);
1524 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1525 (void *) mp->address,
1526 mp->address_length, is_del);
1528 BAD_SW_IF_INDEX_LABEL;
1530 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1534 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1537 u32 table_id = ntohl (mp->vrf_id);
1538 u32 sw_if_index = ntohl (mp->sw_if_index);
1539 vl_api_sw_interface_set_table_reply_t *rmp;
1540 stats_main_t *sm = &stats_main;
1543 VALIDATE_SW_IF_INDEX (mp);
1545 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1549 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1552 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
1553 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1558 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1561 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
1562 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1566 BAD_SW_IF_INDEX_LABEL;
1568 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1572 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1574 vl_api_sw_interface_set_vpath_reply_t *rmp;
1576 u32 sw_if_index = ntohl (mp->sw_if_index);
1578 VALIDATE_SW_IF_INDEX (mp);
1580 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1581 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
1582 sw_if_index, mp->enable, 0, 0);
1583 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
1584 sw_if_index, mp->enable, 0, 0);
1585 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
1586 sw_if_index, mp->enable, 0, 0);
1587 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
1588 sw_if_index, mp->enable, 0, 0);
1590 BAD_SW_IF_INDEX_LABEL;
1592 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1596 vl_api_sw_interface_set_l2_xconnect_t_handler
1597 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1599 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1601 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1602 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1603 vlib_main_t *vm = vlib_get_main ();
1604 vnet_main_t *vnm = vnet_get_main ();
1606 VALIDATE_RX_SW_IF_INDEX (mp);
1610 VALIDATE_TX_SW_IF_INDEX (mp);
1611 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1612 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1616 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1619 BAD_RX_SW_IF_INDEX_LABEL;
1620 BAD_TX_SW_IF_INDEX_LABEL;
1622 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1626 vl_api_sw_interface_set_l2_bridge_t_handler
1627 (vl_api_sw_interface_set_l2_bridge_t * mp)
1629 bd_main_t *bdm = &bd_main;
1630 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1632 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1633 u32 bd_id = ntohl (mp->bd_id);
1637 vlib_main_t *vm = vlib_get_main ();
1638 vnet_main_t *vnm = vnet_get_main ();
1640 VALIDATE_RX_SW_IF_INDEX (mp);
1642 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1646 //VALIDATE_TX_SW_IF_INDEX(mp);
1647 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1648 rx_sw_if_index, bd_index, bvi, shg, 0);
1652 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1655 BAD_RX_SW_IF_INDEX_LABEL;
1657 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1661 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1662 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1664 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1668 dpdk_main_t *dm = &dpdk_main;
1671 u32 sw_if_index = ntohl (mp->sw_if_index);
1672 u32 subport = ntohl (mp->subport);
1673 u32 pipe = ntohl (mp->pipe);
1674 u32 profile = ntohl (mp->profile);
1675 vnet_hw_interface_t *hw;
1677 VALIDATE_SW_IF_INDEX (mp);
1679 /* hw_if & dpdk device */
1680 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1682 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1684 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1686 BAD_SW_IF_INDEX_LABEL;
1688 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1689 rv = VNET_API_ERROR_UNIMPLEMENTED;
1692 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1696 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1697 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1699 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1703 dpdk_main_t *dm = &dpdk_main;
1705 struct rte_sched_subport_params p;
1707 u32 sw_if_index = ntohl (mp->sw_if_index);
1708 u32 subport = ntohl (mp->subport);
1709 p.tb_rate = ntohl (mp->tb_rate);
1710 p.tb_size = ntohl (mp->tb_size);
1711 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1712 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1713 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1714 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1715 p.tc_period = ntohl (mp->tc_period);
1717 vnet_hw_interface_t *hw;
1719 VALIDATE_SW_IF_INDEX (mp);
1721 /* hw_if & dpdk device */
1722 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1724 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1726 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1728 BAD_SW_IF_INDEX_LABEL;
1731 ("setting HQoS subport parameters without DPDK not implemented");
1732 rv = VNET_API_ERROR_UNIMPLEMENTED;
1735 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1739 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1740 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1742 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1746 dpdk_main_t *dm = &dpdk_main;
1747 vlib_thread_main_t *tm = vlib_get_thread_main ();
1750 u32 sw_if_index = ntohl (mp->sw_if_index);
1751 u32 entry = ntohl (mp->entry);
1752 u32 tc = ntohl (mp->tc);
1753 u32 queue = ntohl (mp->queue);
1756 vnet_hw_interface_t *hw;
1758 VALIDATE_SW_IF_INDEX (mp);
1760 /* hw_if & dpdk device */
1761 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1763 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1765 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1767 clib_warning ("invalid traffic class !!");
1768 rv = VNET_API_ERROR_INVALID_VALUE;
1771 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1773 clib_warning ("invalid queue !!");
1774 rv = VNET_API_ERROR_INVALID_VALUE;
1778 /* Detect the set of worker threads */
1779 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1783 clib_warning ("worker thread registration AWOL !!");
1784 rv = VNET_API_ERROR_INVALID_VALUE_2;
1788 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1789 int worker_thread_first = tr->first_index;
1790 int worker_thread_count = tr->count;
1792 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1793 for (i = 0; i < worker_thread_count; i++)
1794 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1796 BAD_SW_IF_INDEX_LABEL;
1799 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1800 rv = VNET_API_ERROR_UNIMPLEMENTED;
1803 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1807 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1809 vlib_main_t *vm = vlib_get_main ();
1810 bd_main_t *bdm = &bd_main;
1811 vl_api_bridge_domain_add_del_reply_t *rmp;
1813 u32 enable_flags = 0, disable_flags = 0;
1814 u32 bd_id = ntohl (mp->bd_id);
1819 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1822 enable_flags |= L2_FLOOD;
1824 disable_flags |= L2_FLOOD;
1827 enable_flags |= L2_UU_FLOOD;
1829 disable_flags |= L2_UU_FLOOD;
1832 enable_flags |= L2_FWD;
1834 disable_flags |= L2_FWD;
1837 enable_flags |= L2_ARP_TERM;
1839 disable_flags |= L2_ARP_TERM;
1842 enable_flags |= L2_LEARN;
1844 disable_flags |= L2_LEARN;
1847 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1850 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1854 rv = bd_delete_bd_index (bdm, bd_id);
1856 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1860 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1862 clib_warning ("BUG");
1866 vl_api_bridge_domain_sw_if_details_t_handler
1867 (vl_api_bridge_domain_sw_if_details_t * mp)
1869 clib_warning ("BUG");
1873 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1874 l2_bridge_domain_t * bd_config,
1875 u32 n_sw_ifs, u32 context)
1877 vl_api_bridge_domain_details_t *mp;
1879 mp = vl_msg_api_alloc (sizeof (*mp));
1880 memset (mp, 0, sizeof (*mp));
1881 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1882 mp->bd_id = ntohl (bd_config->bd_id);
1883 mp->flood = bd_feature_flood (bd_config);
1884 mp->uu_flood = bd_feature_uu_flood (bd_config);
1885 mp->forward = bd_feature_forward (bd_config);
1886 mp->learn = bd_feature_learn (bd_config);
1887 mp->arp_term = bd_feature_arp_term (bd_config);
1888 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1889 mp->n_sw_ifs = ntohl (n_sw_ifs);
1890 mp->context = context;
1892 vl_msg_api_send_shmem (q, (u8 *) & mp);
1896 send_bd_sw_if_details (l2input_main_t * l2im,
1897 unix_shared_memory_queue_t * q,
1898 l2_flood_member_t * member, u32 bd_id, u32 context)
1900 vl_api_bridge_domain_sw_if_details_t *mp;
1901 l2_input_config_t *input_cfg;
1903 mp = vl_msg_api_alloc (sizeof (*mp));
1904 memset (mp, 0, sizeof (*mp));
1905 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1906 mp->bd_id = ntohl (bd_id);
1907 mp->sw_if_index = ntohl (member->sw_if_index);
1908 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1909 mp->shg = input_cfg->shg;
1910 mp->context = context;
1912 vl_msg_api_send_shmem (q, (u8 *) & mp);
1916 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1918 bd_main_t *bdm = &bd_main;
1919 l2input_main_t *l2im = &l2input_main;
1920 unix_shared_memory_queue_t *q;
1921 l2_bridge_domain_t *bd_config;
1922 u32 bd_id, bd_index;
1925 q = vl_api_client_index_to_input_queue (mp->client_index);
1930 bd_id = ntohl (mp->bd_id);
1932 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1933 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1934 for (; bd_index < end; bd_index++)
1936 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1937 /* skip dummy bd_id 0 */
1938 if (bd_config && (bd_config->bd_id > 0))
1941 l2_flood_member_t *m;
1943 n_sw_ifs = vec_len (bd_config->members);
1944 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1946 vec_foreach (m, bd_config->members)
1948 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1955 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1957 bd_main_t *bdm = &bd_main;
1958 l2input_main_t *l2im = &l2input_main;
1959 vl_api_l2fib_add_del_reply_t *rmp;
1962 u32 sw_if_index = ntohl (mp->sw_if_index);
1963 u32 bd_id = ntohl (mp->bd_id);
1972 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1975 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1976 goto bad_sw_if_index;
1982 VALIDATE_SW_IF_INDEX (mp);
1983 if (vec_len (l2im->configs) <= sw_if_index)
1985 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1986 goto bad_sw_if_index;
1990 l2_input_config_t *config;
1991 config = vec_elt_at_index (l2im->configs, sw_if_index);
1992 if (config->bridge == 0)
1994 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1995 goto bad_sw_if_index;
1998 static_mac = mp->static_mac ? 1 : 0;
1999 filter_mac = mp->filter_mac ? 1 : 0;
2000 bvi_mac = mp->bvi_mac ? 1 : 0;
2001 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
2006 l2fib_del_entry (mac, bd_index);
2009 BAD_SW_IF_INDEX_LABEL;
2011 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
2015 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
2017 vl_api_l2_flags_reply_t *rmp;
2019 u32 sw_if_index = ntohl (mp->sw_if_index);
2020 u32 flags = ntohl (mp->feature_bitmap);
2023 VALIDATE_SW_IF_INDEX (mp);
2026 if (flags & L2INPUT_FEAT_ ## a) \
2027 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
2028 foreach_l2input_feat;
2031 BAD_SW_IF_INDEX_LABEL;
2034 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
2036 rmp->resulting_feature_bitmap = ntohl(rbm);
2042 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
2044 vlib_main_t *vm = vlib_get_main ();
2045 bd_main_t *bdm = &bd_main;
2046 vl_api_bridge_flags_reply_t *rmp;
2048 u32 bd_id = ntohl (mp->bd_id);
2050 u32 flags = ntohl (mp->feature_bitmap);
2053 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2056 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2062 bd_set_flags (vm, bd_index, flags, mp->is_set);
2066 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
2068 rmp->resulting_feature_bitmap = ntohl(flags);
2074 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
2076 bd_main_t *bdm = &bd_main;
2077 vl_api_bd_ip_mac_add_del_reply_t *rmp;
2079 u32 bd_id = ntohl (mp->bd_id);
2083 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2086 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2091 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
2092 mp->mac_address, mp->is_ipv6, mp->is_add))
2093 rv = VNET_API_ERROR_UNSPECIFIED;
2096 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
2100 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
2103 vl_api_tap_connect_reply_t *rmp;
2104 unix_shared_memory_queue_t *q;
2105 u32 sw_if_index = (u32) ~ 0;
2107 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
2108 mp->use_random_mac ? 0 : mp->mac_address,
2109 &sw_if_index, mp->renumber,
2110 ntohl (mp->custom_dev_instance));
2112 q = vl_api_client_index_to_input_queue (mp->client_index);
2116 rmp = vl_msg_api_alloc (sizeof (*rmp));
2117 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
2118 rmp->context = mp->context;
2119 rmp->retval = ntohl (rv);
2120 rmp->sw_if_index = ntohl (sw_if_index);
2122 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2126 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
2129 vl_api_tap_modify_reply_t *rmp;
2130 unix_shared_memory_queue_t *q;
2131 u32 sw_if_index = (u32) ~ 0;
2133 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
2134 mp->use_random_mac ? 0 : mp->mac_address,
2135 &sw_if_index, mp->renumber,
2136 ntohl (mp->custom_dev_instance));
2138 q = vl_api_client_index_to_input_queue (mp->client_index);
2142 rmp = vl_msg_api_alloc (sizeof (*rmp));
2143 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
2144 rmp->context = mp->context;
2145 rmp->retval = ntohl (rv);
2146 rmp->sw_if_index = ntohl (sw_if_index);
2148 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2152 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
2155 vpe_api_main_t *vam = &vpe_api_main;
2156 vl_api_tap_delete_reply_t *rmp;
2157 unix_shared_memory_queue_t *q;
2158 u32 sw_if_index = ntohl (mp->sw_if_index);
2160 rv = vnet_tap_delete (vm, sw_if_index);
2162 q = vl_api_client_index_to_input_queue (mp->client_index);
2166 rmp = vl_msg_api_alloc (sizeof (*rmp));
2167 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
2168 rmp->context = mp->context;
2169 rmp->retval = ntohl (rv);
2171 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2174 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2178 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
2180 vl_api_create_vlan_subif_reply_t *rmp;
2181 vnet_main_t *vnm = vnet_get_main ();
2182 u32 hw_if_index, sw_if_index = (u32) ~ 0;
2183 vnet_hw_interface_t *hi;
2186 vnet_sw_interface_t template;
2188 vnet_interface_main_t *im = &vnm->interface_main;
2189 u64 sup_and_sub_key;
2191 unix_shared_memory_queue_t *q;
2192 clib_error_t *error;
2194 VALIDATE_SW_IF_INDEX (mp);
2196 hw_if_index = ntohl (mp->sw_if_index);
2197 hi = vnet_get_hw_interface (vnm, hw_if_index);
2199 id = ntohl (mp->vlan_id);
2200 if (id == 0 || id > 4095)
2202 rv = VNET_API_ERROR_INVALID_VLAN;
2206 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2208 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2211 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2215 kp = clib_mem_alloc (sizeof (*kp));
2216 *kp = sup_and_sub_key;
2218 memset (&template, 0, sizeof (template));
2219 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2220 template.sup_sw_if_index = hi->sw_if_index;
2221 template.sub.id = id;
2222 template.sub.eth.raw_flags = 0;
2223 template.sub.eth.flags.one_tag = 1;
2224 template.sub.eth.outer_vlan_id = id;
2225 template.sub.eth.flags.exact_match = 1;
2227 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2230 clib_error_report (error);
2231 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2234 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2235 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2237 BAD_SW_IF_INDEX_LABEL;
2240 q = vl_api_client_index_to_input_queue (mp->client_index);
2244 rmp = vl_msg_api_alloc (sizeof (*rmp));
2245 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2246 rmp->context = mp->context;
2247 rmp->retval = ntohl (rv);
2248 rmp->sw_if_index = ntohl (sw_if_index);
2249 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2253 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2255 vl_api_create_subif_reply_t *rmp;
2256 vnet_main_t *vnm = vnet_get_main ();
2257 u32 sw_if_index = ~0;
2260 vnet_sw_interface_t *si;
2261 vnet_hw_interface_t *hi;
2262 vnet_sw_interface_t template;
2264 vnet_interface_main_t *im = &vnm->interface_main;
2265 u64 sup_and_sub_key;
2267 clib_error_t *error;
2269 VALIDATE_SW_IF_INDEX (mp);
2271 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2272 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2274 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2276 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2280 sw_if_index = si->sw_if_index;
2281 sub_id = ntohl (mp->sub_id);
2283 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2285 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2289 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2290 sw_if_index, sub_id);
2291 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2295 kp = clib_mem_alloc (sizeof (*kp));
2296 *kp = sup_and_sub_key;
2298 memset (&template, 0, sizeof (template));
2299 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2300 template.sup_sw_if_index = sw_if_index;
2301 template.sub.id = sub_id;
2302 template.sub.eth.flags.no_tags = mp->no_tags;
2303 template.sub.eth.flags.one_tag = mp->one_tag;
2304 template.sub.eth.flags.two_tags = mp->two_tags;
2305 template.sub.eth.flags.dot1ad = mp->dot1ad;
2306 template.sub.eth.flags.exact_match = mp->exact_match;
2307 template.sub.eth.flags.default_sub = mp->default_sub;
2308 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2309 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2310 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2311 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2313 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2316 clib_error_report (error);
2317 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2321 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2322 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2324 BAD_SW_IF_INDEX_LABEL;
2329 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2331 rmp->sw_if_index = ntohl(sw_if_index);
2337 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2338 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2340 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2342 stats_main_t *sm = &stats_main;
2343 u32 tunnel_sw_if_index;
2345 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2347 rv = vnet_mpls_ethernet_add_del_tunnel
2348 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2349 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2350 ntohl (mp->tx_sw_if_index),
2351 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2356 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2358 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2364 * This piece of misery brought to you because the control-plane
2365 * can't figure out the tx interface + dst-mac address all by itself
2367 static int mpls_ethernet_add_del_tunnel_2_t_handler
2368 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2370 pending_route_t *pr;
2371 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2372 vnet_main_t *vnm = vnet_get_main ();
2373 vlib_main_t *vm = vlib_get_main ();
2374 stats_main_t *sm = &stats_main;
2375 vpe_api_main_t *vam = &vpe_api_main;
2376 u32 inner_fib_index, outer_fib_index;
2377 ip4_main_t *im = &ip4_main;
2378 ip_lookup_main_t *lm = &im->lookup_main;
2379 ip_adjacency_t *adj = 0;
2382 u8 *dst_mac_address;
2386 u32 tunnel_sw_if_index;
2388 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2390 return VNET_API_ERROR_NO_SUCH_FIB;
2392 outer_fib_index = p[0];
2395 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2397 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2399 inner_fib_index = p[0];
2401 if (inner_fib_index == outer_fib_index)
2402 return VNET_API_ERROR_INVALID_VALUE;
2405 lookup_result = ip4_fib_table_lookup_lb (ip4_fib_get (outer_fib_index),
2407 mp->next_hop_ip4_address_in_outer_vrf);
2409 adj = ip_get_adjacency (lm, lookup_result);
2410 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2412 if (mp->is_add && mp->resolve_if_needed)
2414 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2416 pool_get (vam->pending_routes, pr);
2417 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2419 clib_memcpy (pme, mp, sizeof (*pme));
2420 /* recursion block, "just in case" */
2421 pme->resolve_if_needed = 0;
2422 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2423 pme->resolve_opaque = tx_sw_if_index;
2424 vnet_register_ip4_arp_resolution_event
2426 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2427 vpe_resolver_process_node.index,
2428 RESOLUTION_EVENT, pr - vam->pending_routes);
2430 vlib_process_signal_event
2431 (vm, vpe_resolver_process_node.index,
2432 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2434 /* The interface may be down, etc. */
2435 e = ip4_probe_neighbor
2436 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2440 clib_error_report (e);
2442 return VNET_API_ERROR_IN_PROGRESS;
2446 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2447 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2450 vnet_rewrite_get_data_internal
2451 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2453 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2455 rv = vnet_mpls_ethernet_add_del_tunnel
2456 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2457 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2458 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2466 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2467 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2469 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2472 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2474 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2479 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2481 vl_api_mpls_add_del_encap_reply_t *rmp;
2486 vec_reset_length (labels);
2488 for (i = 0; i < mp->nlabels; i++)
2489 vec_add1 (labels, ntohl (mp->labels[i]));
2492 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2493 ntohl (mp->vrf_id), labels,
2494 ~0 /* policy_tunnel_index */ ,
2495 0 /* no_dst_hash */ ,
2499 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2503 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2505 vl_api_proxy_arp_add_del_reply_t *rmp;
2508 ip4_main_t *im = &ip4_main;
2509 stats_main_t *sm = &stats_main;
2510 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2511 ip4_address_t * hi_addr,
2512 u32 fib_index, int is_del);
2515 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2517 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2521 rv = VNET_API_ERROR_NO_SUCH_FIB;
2527 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2528 (ip4_address_t *) mp->hi_address,
2529 fib_index, mp->is_add == 0);
2533 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2537 vl_api_proxy_arp_intfc_enable_disable_t_handler
2538 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2541 vnet_main_t *vnm = vnet_get_main ();
2542 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2543 vnet_sw_interface_t *si;
2546 VALIDATE_SW_IF_INDEX (mp);
2548 sw_if_index = ntohl (mp->sw_if_index);
2550 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2552 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2556 si = vnet_get_sw_interface (vnm, sw_if_index);
2560 if (mp->enable_disable)
2561 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2563 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2565 BAD_SW_IF_INDEX_LABEL;
2568 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2572 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2575 vl_api_ip_neighbor_add_del_reply_t *rmp;
2576 vnet_main_t *vnm = vnet_get_main ();
2577 stats_main_t *sm = &stats_main;
2580 VALIDATE_SW_IF_INDEX (mp);
2582 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2585 * there's no validation here of the ND/ARP entry being added.
2586 * The expectation is that the FIB will ensure that nothing bad
2587 * will come of adding bogus entries.
2592 rv = vnet_set_ip6_ethernet_neighbor
2593 (vm, ntohl (mp->sw_if_index),
2594 (ip6_address_t *) (mp->dst_address),
2595 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2597 rv = vnet_unset_ip6_ethernet_neighbor
2598 (vm, ntohl (mp->sw_if_index),
2599 (ip6_address_t *) (mp->dst_address),
2600 mp->mac_address, sizeof (mp->mac_address));
2604 ethernet_arp_ip4_over_ethernet_address_t a;
2606 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2607 clib_memcpy (&a.ip4, mp->dst_address, 4);
2610 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2614 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2617 BAD_SW_IF_INDEX_LABEL;
2620 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2624 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2627 vpe_main_t *rm = &vpe_main;
2628 ip4_main_t *im4 = &ip4_main;
2629 ip6_main_t *im6 = &ip6_main;
2630 ip_lookup_main_t *lm;
2636 u32 adj_index, sw_if_index;
2637 vl_api_is_address_reachable_t *rmp;
2638 ip_adjacency_t *adj;
2639 unix_shared_memory_queue_t *q;
2641 q = vl_api_client_index_to_input_queue (mp->client_index);
2644 increment_missing_api_client_counter (rm->vlib_main);
2648 rmp = vl_msg_api_alloc (sizeof (*rmp));
2649 clib_memcpy (rmp, mp, sizeof (*rmp));
2651 sw_if_index = mp->next_hop_sw_if_index;
2652 clib_memcpy (&addr, mp->address, sizeof (addr));
2655 lm = &im6->lookup_main;
2656 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2660 lm = &im4->lookup_main;
2662 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2664 if (adj_index == ~0)
2669 adj = ip_get_adjacency (lm, adj_index);
2671 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2672 && adj->rewrite_header.sw_if_index == sw_if_index)
2678 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2679 && adj->rewrite_header.sw_if_index == sw_if_index)
2682 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2684 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2686 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2695 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2700 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2702 clib_warning ("BUG");
2706 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2708 vl_api_sw_interface_set_flags_reply_t *rmp;
2709 vnet_main_t *vnm = vnet_get_main ();
2711 clib_error_t *error;
2714 VALIDATE_SW_IF_INDEX (mp);
2716 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2718 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2722 clib_error_report (error);
2725 BAD_SW_IF_INDEX_LABEL;
2726 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2730 vl_api_sw_interface_set_mpls_enable_t_handler
2731 (vl_api_sw_interface_set_mpls_enable_t * mp)
2733 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2736 VALIDATE_SW_IF_INDEX (mp);
2738 mpls_sw_interface_enable_disable (&mpls_main,
2739 ntohl (mp->sw_if_index), mp->enable);
2741 BAD_SW_IF_INDEX_LABEL;
2742 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2746 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2749 vl_api_sw_interface_clear_stats_reply_t *rmp;
2751 vnet_main_t *vnm = vnet_get_main ();
2752 vnet_interface_main_t *im = &vnm->interface_main;
2753 vlib_simple_counter_main_t *sm;
2754 vlib_combined_counter_main_t *cm;
2755 static vnet_main_t **my_vnet_mains;
2756 int i, j, n_counters;
2759 if (mp->sw_if_index != ~0)
2760 VALIDATE_SW_IF_INDEX (mp);
2762 vec_reset_length (my_vnet_mains);
2764 for (i = 0; i < vec_len (vnet_mains); i++)
2767 vec_add1 (my_vnet_mains, vnet_mains[i]);
2770 if (vec_len (vnet_mains) == 0)
2771 vec_add1 (my_vnet_mains, vnm);
2773 n_counters = vec_len (im->combined_sw_if_counters);
2775 for (j = 0; j < n_counters; j++)
2777 for (i = 0; i < vec_len (my_vnet_mains); i++)
2779 im = &my_vnet_mains[i]->interface_main;
2780 cm = im->combined_sw_if_counters + j;
2781 if (mp->sw_if_index == (u32) ~ 0)
2782 vlib_clear_combined_counters (cm);
2784 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2788 n_counters = vec_len (im->sw_if_counters);
2790 for (j = 0; j < n_counters; j++)
2792 for (i = 0; i < vec_len (my_vnet_mains); i++)
2794 im = &my_vnet_mains[i]->interface_main;
2795 sm = im->sw_if_counters + j;
2796 if (mp->sw_if_index == (u32) ~ 0)
2797 vlib_clear_simple_counters (sm);
2799 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2803 BAD_SW_IF_INDEX_LABEL;
2805 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2809 send_sw_interface_details (vpe_api_main_t * am,
2810 unix_shared_memory_queue_t * q,
2811 vnet_sw_interface_t * swif,
2812 u8 * interface_name, u32 context)
2814 vl_api_sw_interface_details_t *mp;
2815 vnet_hw_interface_t *hi;
2817 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2819 mp = vl_msg_api_alloc (sizeof (*mp));
2820 memset (mp, 0, sizeof (*mp));
2821 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2822 mp->sw_if_index = ntohl (swif->sw_if_index);
2823 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2824 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2825 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2826 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2827 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2828 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2829 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2830 mp->link_mtu = ntohs (hi->max_packet_bytes);
2831 mp->context = context;
2833 strncpy ((char *) mp->interface_name,
2834 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2836 /* Send the L2 address for ethernet physical intfcs */
2837 if (swif->sup_sw_if_index == swif->sw_if_index
2838 && hi->hw_class_index == ethernet_hw_interface_class.index)
2840 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2841 ethernet_interface_t *ei;
2843 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2844 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2845 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2846 mp->l2_address_length = ntohl (sizeof (ei->address));
2848 else if (swif->sup_sw_if_index != swif->sw_if_index)
2850 vnet_sub_interface_t *sub = &swif->sub;
2851 mp->sub_id = ntohl (sub->id);
2852 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2853 mp->sub_number_of_tags =
2854 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2855 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2856 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2857 mp->sub_exact_match = sub->eth.flags.exact_match;
2858 mp->sub_default = sub->eth.flags.default_sub;
2859 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2860 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2862 /* vlan tag rewrite data */
2863 u32 vtr_op = L2_VTR_DISABLED;
2864 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2866 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2867 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2869 // error - default to disabled
2870 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2871 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2876 mp->vtr_op = ntohl (vtr_op);
2877 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2878 mp->vtr_tag1 = ntohl (vtr_tag1);
2879 mp->vtr_tag2 = ntohl (vtr_tag2);
2883 vl_msg_api_send_shmem (q, (u8 *) & mp);
2887 send_sw_interface_flags (vpe_api_main_t * am,
2888 unix_shared_memory_queue_t * q,
2889 vnet_sw_interface_t * swif)
2891 vl_api_sw_interface_set_flags_t *mp;
2892 vnet_main_t *vnm = am->vnet_main;
2894 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2896 mp = vl_msg_api_alloc (sizeof (*mp));
2897 memset (mp, 0, sizeof (*mp));
2898 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2899 mp->sw_if_index = ntohl (swif->sw_if_index);
2901 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2902 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2903 vl_msg_api_send_shmem (q, (u8 *) & mp);
2906 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2907 unix_shared_memory_queue_t * q,
2909 __attribute__ ((unused));
2912 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2913 unix_shared_memory_queue_t * q,
2916 vl_api_sw_interface_set_flags_t *mp;
2918 mp = vl_msg_api_alloc (sizeof (*mp));
2919 memset (mp, 0, sizeof (*mp));
2920 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2921 mp->sw_if_index = ntohl (sw_if_index);
2923 mp->admin_up_down = 0;
2924 mp->link_up_down = 0;
2926 vl_msg_api_send_shmem (q, (u8 *) & mp);
2930 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2932 vpe_api_main_t *am = &vpe_api_main;
2933 vnet_sw_interface_t *swif;
2934 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2935 u8 *filter_string = 0, *name_string = 0;
2936 unix_shared_memory_queue_t *q;
2937 char *strcasestr (char *, char *); /* lnx hdr file botch */
2939 q = vl_api_client_index_to_input_queue (mp->client_index);
2944 if (mp->name_filter_valid)
2946 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2947 filter_string = format (0, "%s%c", mp->name_filter, 0);
2951 pool_foreach (swif, im->sw_interfaces,
2953 name_string = format (name_string, "%U%c",
2954 format_vnet_sw_interface_name,
2955 am->vnet_main, swif, 0);
2957 if (mp->name_filter_valid == 0 ||
2958 strcasestr((char *) name_string, (char *) filter_string)) {
2960 send_sw_interface_details (am, q, swif, name_string, mp->context);
2962 _vec_len (name_string) = 0;
2966 vec_free (name_string);
2967 vec_free (filter_string);
2971 send_oam_event (oam_target_t * t)
2973 vpe_api_main_t *vam = &vpe_api_main;
2974 unix_shared_memory_queue_t *q;
2975 vpe_client_registration_t *reg;
2976 vl_api_oam_event_t *mp;
2979 pool_foreach(reg, vam->oam_events_registrations,
2981 q = vl_api_client_index_to_input_queue (reg->client_index);
2984 mp = vl_msg_api_alloc (sizeof (*mp));
2985 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2986 clib_memcpy (mp->dst_address, &t->dst_address,
2987 sizeof (mp->dst_address));
2988 mp->state = t->state;
2989 vl_msg_api_send_shmem (q, (u8 *)&mp);
2996 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2998 vl_api_oam_add_del_reply_t *rmp;
3001 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
3002 (ip4_address_t *) mp->dst_address,
3003 ntohl (mp->vrf_id), (int) (mp->is_add));
3005 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
3009 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
3011 stats_main_t *sm = &stats_main;
3012 vnet_interface_main_t *im = sm->interface_main;
3013 vl_api_vnet_summary_stats_reply_t *rmp;
3014 vlib_combined_counter_main_t *cm;
3017 u64 total_pkts[VLIB_N_RX_TX];
3018 u64 total_bytes[VLIB_N_RX_TX];
3020 unix_shared_memory_queue_t *q =
3021 vl_api_client_index_to_input_queue (mp->client_index);
3026 rmp = vl_msg_api_alloc (sizeof (*rmp));
3027 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
3028 rmp->context = mp->context;
3031 memset (total_pkts, 0, sizeof (total_pkts));
3032 memset (total_bytes, 0, sizeof (total_bytes));
3034 vnet_interface_counter_lock (im);
3036 vec_foreach (cm, im->combined_sw_if_counters)
3038 which = cm - im->combined_sw_if_counters;
3040 for (i = 0; i < vec_len (cm->maxi); i++)
3042 vlib_get_combined_counter (cm, i, &v);
3043 total_pkts[which] += v.packets;
3044 total_bytes[which] += v.bytes;
3047 vnet_interface_counter_unlock (im);
3049 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
3050 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
3051 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
3052 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
3054 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
3056 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3060 typedef CLIB_PACKED (struct {
3061 ip4_address_t address;
3062 u32 address_length: 6;
3068 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3070 vnet_main_t *vnm = vnet_get_main ();
3071 vnet_interface_main_t *im = &vnm->interface_main;
3072 ip4_main_t *im4 = &ip4_main;
3073 static u32 *sw_if_indices_to_shut;
3074 stats_main_t *sm = &stats_main;
3075 fib_table_t *fib_table;
3079 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3080 u32 target_fib_id = ntohl (mp->vrf_id);
3082 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
3085 pool_foreach (fib_table, im4->fibs,
3087 fib = &fib_table->v4;
3088 vnet_sw_interface_t * si;
3090 if (fib->table_id != target_fib_id)
3093 /* remove any mpls encap/decap labels */
3094 mpls_fib_reset_labels (fib->table_id);
3096 /* remove any proxy arps in this fib */
3097 vnet_proxy_arp_fib_reset (fib->table_id);
3099 /* Set the flow hash for this fib to the default */
3100 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3102 vec_reset_length (sw_if_indices_to_shut);
3104 /* Shut down interfaces in this FIB / clean out intfc routes */
3105 pool_foreach (si, im->sw_interfaces,
3107 u32 sw_if_index = si->sw_if_index;
3109 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
3110 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
3112 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3115 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3116 sw_if_index = sw_if_indices_to_shut[i];
3117 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3119 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3120 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3121 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3124 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
3125 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
3129 })); /* pool_foreach (fib) */
3137 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3139 vnet_main_t *vnm = vnet_get_main ();
3140 vnet_interface_main_t *im = &vnm->interface_main;
3141 ip6_main_t *im6 = &ip6_main;
3142 stats_main_t *sm = &stats_main;
3143 static u32 *sw_if_indices_to_shut;
3144 fib_table_t *fib_table;
3148 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3149 u32 target_fib_id = ntohl (mp->vrf_id);
3151 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3154 pool_foreach (fib_table, im6->fibs,
3156 vnet_sw_interface_t * si;
3157 fib = &(fib_table->v6);
3159 if (fib->table_id != target_fib_id)
3162 vec_reset_length (sw_if_indices_to_shut);
3164 /* Shut down interfaces in this FIB / clean out intfc routes */
3165 pool_foreach (si, im->sw_interfaces,
3167 if (im6->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_IP6, FIB_SOURCE_API);
3182 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
3186 })); /* pool_foreach (fib) */
3194 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3197 vl_api_reset_fib_reply_t *rmp;
3200 rv = ip6_reset_fib_t_handler (mp);
3202 rv = ip4_reset_fib_t_handler (mp);
3204 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3209 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3211 vl_api_dhcp_proxy_config_reply_t *rmp;
3214 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3215 (ip4_address_t *) (&mp->dhcp_src_address),
3216 (u32) ntohl (mp->vrf_id),
3217 (int) mp->insert_circuit_id,
3218 (int) (mp->is_add == 0));
3220 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3225 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3227 vl_api_dhcp_proxy_config_reply_t *rmp;
3230 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3231 (ip6_address_t *) (&mp->dhcp_src_address),
3232 (u32) ntohl (mp->vrf_id),
3233 (int) mp->insert_circuit_id,
3234 (int) (mp->is_add == 0));
3236 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3240 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3242 vl_api_dhcp_proxy_config_reply_t *rmp;
3245 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3246 (ip4_address_t *) (&mp->dhcp_src_address),
3247 (u32) ntohl (mp->rx_vrf_id),
3248 (u32) ntohl (mp->server_vrf_id),
3249 (int) mp->insert_circuit_id,
3250 (int) (mp->is_add == 0));
3252 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3257 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3259 vl_api_dhcp_proxy_config_reply_t *rmp;
3263 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3264 (ip6_address_t *) (&mp->dhcp_src_address),
3265 (u32) ntohl (mp->rx_vrf_id),
3266 (u32) ntohl (mp->server_vrf_id),
3267 (int) mp->insert_circuit_id,
3268 (int) (mp->is_add == 0));
3270 rv = VNET_API_ERROR_UNIMPLEMENTED;
3273 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3278 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3280 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3283 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3286 (int) mp->is_add == 0);
3288 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3290 ntohl (mp->fib_id), (int) mp->is_add == 0);
3292 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3296 static void vl_api_dhcp_proxy_config_t_handler
3297 (vl_api_dhcp_proxy_config_t * mp)
3299 if (mp->is_ipv6 == 0)
3300 dhcpv4_proxy_config (mp);
3302 dhcpv6_proxy_config (mp);
3305 static void vl_api_dhcp_proxy_config_2_t_handler
3306 (vl_api_dhcp_proxy_config_2_t * mp)
3308 if (mp->is_ipv6 == 0)
3309 dhcpv4_proxy_config_2 (mp);
3311 dhcpv6_proxy_config_2 (mp);
3315 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3316 u8 is_ipv6, u8 * host_address, u8 * router_address,
3319 unix_shared_memory_queue_t *q;
3320 vl_api_dhcp_compl_event_t *mp;
3322 q = vl_api_client_index_to_input_queue (client_index);
3326 mp = vl_msg_api_alloc (sizeof (*mp));
3327 mp->client_index = client_index;
3329 mp->is_ipv6 = is_ipv6;
3330 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3331 mp->hostname[vec_len (hostname) + 1] = '\n';
3332 clib_memcpy (&mp->host_address[0], host_address, 16);
3333 clib_memcpy (&mp->router_address[0], router_address, 16);
3335 if (NULL != host_mac)
3336 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3338 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3340 vl_msg_api_send_shmem (q, (u8 *) & mp);
3343 static void vl_api_dhcp_client_config_t_handler
3344 (vl_api_dhcp_client_config_t * mp)
3346 vlib_main_t *vm = vlib_get_main ();
3347 vl_api_dhcp_client_config_reply_t *rmp;
3350 VALIDATE_SW_IF_INDEX (mp);
3352 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3353 mp->hostname, mp->is_add, mp->client_index,
3354 mp->want_dhcp_event ? dhcp_compl_event_callback :
3357 BAD_SW_IF_INDEX_LABEL;
3359 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3363 vl_api_sw_interface_ip6nd_ra_config_t_handler
3364 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3366 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3368 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3371 is_no = mp->is_no == 1;
3372 suppress = mp->suppress == 1;
3373 managed = mp->managed == 1;
3374 other = mp->other == 1;
3375 ll_option = mp->ll_option == 1;
3376 send_unicast = mp->send_unicast == 1;
3377 cease = mp->cease == 1;
3378 default_router = mp->default_router == 1;
3380 VALIDATE_SW_IF_INDEX (mp);
3382 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3383 suppress, managed, other,
3384 ll_option, send_unicast, cease,
3385 default_router, ntohl (mp->lifetime),
3386 ntohl (mp->initial_count),
3387 ntohl (mp->initial_interval),
3388 ntohl (mp->max_interval),
3389 ntohl (mp->min_interval), is_no);
3391 BAD_SW_IF_INDEX_LABEL;
3393 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3397 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3398 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3400 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3402 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3404 VALIDATE_SW_IF_INDEX (mp);
3406 is_no = mp->is_no == 1;
3407 use_default = mp->use_default == 1;
3408 no_advertise = mp->no_advertise == 1;
3409 off_link = mp->off_link == 1;
3410 no_autoconfig = mp->no_autoconfig == 1;
3411 no_onlink = mp->no_onlink == 1;
3413 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3414 (ip6_address_t *) mp->address,
3415 mp->address_length, use_default,
3416 ntohl (mp->val_lifetime),
3417 ntohl (mp->pref_lifetime), no_advertise,
3418 off_link, no_autoconfig, no_onlink, is_no);
3420 BAD_SW_IF_INDEX_LABEL;
3421 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3425 vl_api_sw_interface_ip6_enable_disable_t_handler
3426 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3428 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3429 vnet_main_t *vnm = vnet_get_main ();
3431 clib_error_t *error;
3435 VALIDATE_SW_IF_INDEX (mp);
3438 (mp->enable == 1) ? enable_ip6_interface (vm,
3439 ntohl (mp->sw_if_index)) :
3440 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3444 clib_error_report (error);
3445 rv = VNET_API_ERROR_UNSPECIFIED;
3449 rv = vnm->api_errno;
3452 BAD_SW_IF_INDEX_LABEL;
3454 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3458 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3459 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3461 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3463 clib_error_t *error;
3464 vnet_main_t *vnm = vnet_get_main ();
3468 VALIDATE_SW_IF_INDEX (mp);
3470 error = set_ip6_link_local_address (vm,
3471 ntohl (mp->sw_if_index),
3472 (ip6_address_t *) mp->address,
3473 mp->address_length);
3476 clib_error_report (error);
3477 rv = VNET_API_ERROR_UNSPECIFIED;
3481 rv = vnm->api_errno;
3484 BAD_SW_IF_INDEX_LABEL;
3486 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3490 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3492 vl_api_set_ip_flow_hash_reply_t *rmp;
3493 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3495 clib_warning ("unimplemented...");
3497 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3501 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3503 vl_api_set_ip_flow_hash_reply_t *rmp;
3506 flow_hash_config_t flow_hash_config = 0;
3508 table_id = ntohl (mp->vrf_id);
3510 #define _(a,b) if (mp->a) flow_hash_config |= b;
3511 foreach_flow_hash_bit;
3514 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3516 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3521 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3523 if (mp->is_ipv6 == 0)
3524 set_ip4_flow_hash (mp);
3526 set_ip6_flow_hash (mp);
3529 static void vl_api_sw_interface_set_unnumbered_t_handler
3530 (vl_api_sw_interface_set_unnumbered_t * mp)
3532 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3534 vnet_sw_interface_t *si;
3535 vnet_main_t *vnm = vnet_get_main ();
3536 u32 sw_if_index, unnumbered_sw_if_index;
3538 sw_if_index = ntohl (mp->sw_if_index);
3539 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3542 * The API message field names are backwards from
3543 * the underlying data structure names.
3544 * It's not worth changing them now.
3546 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3547 unnumbered_sw_if_index))
3549 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3553 /* Only check the "use loop0" field when setting the binding */
3555 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3557 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3561 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3565 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3566 si->unnumbered_sw_if_index = sw_if_index;
3567 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3568 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3572 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3573 si->unnumbered_sw_if_index = (u32) ~ 0;
3574 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3575 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3579 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3583 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3585 vl_api_create_loopback_reply_t *rmp;
3589 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3592 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3594 rmp->sw_if_index = ntohl (sw_if_index);
3600 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3602 vl_api_delete_loopback_reply_t *rmp;
3606 sw_if_index = ntohl (mp->sw_if_index);
3607 rv = vnet_delete_loopback_interface (sw_if_index);
3609 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3613 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3615 vl_api_control_ping_reply_t *rmp;
3619 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3621 rmp->vpe_pid = ntohl (getpid());
3627 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3629 u8 **shmem_vecp = (u8 **) arg;
3632 api_main_t *am = &api_main;
3635 shmem_vec = *shmem_vecp;
3637 offset = vec_len (shmem_vec);
3639 pthread_mutex_lock (&am->vlib_rp->mutex);
3640 oldheap = svm_push_data_heap (am->vlib_rp);
3642 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3644 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3646 svm_pop_heap (oldheap);
3647 pthread_mutex_unlock (&am->vlib_rp->mutex);
3649 *shmem_vecp = shmem_vec;
3654 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3656 vl_api_cli_reply_t *rp;
3657 unix_shared_memory_queue_t *q;
3658 vlib_main_t *vm = vlib_get_main ();
3659 api_main_t *am = &api_main;
3660 unformat_input_t input;
3664 q = vl_api_client_index_to_input_queue (mp->client_index);
3668 rp = vl_msg_api_alloc (sizeof (*rp));
3669 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3670 rp->context = mp->context;
3672 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3674 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3676 pthread_mutex_lock (&am->vlib_rp->mutex);
3677 oldheap = svm_push_data_heap (am->vlib_rp);
3679 vec_add1 (shmem_vec, 0);
3681 svm_pop_heap (oldheap);
3682 pthread_mutex_unlock (&am->vlib_rp->mutex);
3684 rp->reply_in_shmem = (uword) shmem_vec;
3686 vl_msg_api_send_shmem (q, (u8 *) & rp);
3690 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3692 u8 **mem_vecp = (u8 **) arg;
3693 u8 *mem_vec = *mem_vecp;
3694 u32 offset = vec_len (mem_vec);
3696 vec_validate (mem_vec, offset + buffer_bytes - 1);
3697 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3698 *mem_vecp = mem_vec;
3702 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3704 vl_api_cli_inband_reply_t *rmp;
3706 unix_shared_memory_queue_t *q;
3707 vlib_main_t *vm = vlib_get_main ();
3708 unformat_input_t input;
3711 q = vl_api_client_index_to_input_queue (mp->client_index);
3715 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3716 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3718 u32 len = vec_len (out_vec);
3720 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3722 rmp->length = htonl (len);
3723 clib_memcpy (rmp->reply, out_vec, len);
3730 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3733 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3734 vnet_main_t *vnm = vnet_get_main ();
3735 clib_error_t *error;
3740 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3742 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3746 clib_error_report (error);
3747 rv = VNET_API_ERROR_UNSPECIFIED;
3751 rv = vnm->api_errno;
3754 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3757 static void vl_api_sr_tunnel_add_del_t_handler
3758 (vl_api_sr_tunnel_add_del_t * mp)
3761 clib_warning ("unimplemented");
3763 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3765 vl_api_sr_tunnel_add_del_reply_t *rmp;
3766 ip6_address_t *segments = 0, *seg;
3767 ip6_address_t *tags = 0, *tag;
3768 ip6_address_t *this_address;
3771 if (mp->n_segments == 0)
3777 memset (a, 0, sizeof (*a));
3778 a->src_address = (ip6_address_t *) & mp->src_address;
3779 a->dst_address = (ip6_address_t *) & mp->dst_address;
3780 a->dst_mask_width = mp->dst_mask_width;
3781 a->flags_net_byte_order = mp->flags_net_byte_order;
3782 a->is_del = (mp->is_add == 0);
3783 a->rx_table_id = ntohl (mp->outer_vrf_id);
3784 a->tx_table_id = ntohl (mp->inner_vrf_id);
3786 a->name = format (0, "%s", mp->name);
3787 if (!(vec_len (a->name)))
3790 a->policy_name = format (0, "%s", mp->policy_name);
3791 if (!(vec_len (a->policy_name)))
3794 /* Yank segments and tags out of the API message */
3795 this_address = (ip6_address_t *) mp->segs_and_tags;
3796 for (i = 0; i < mp->n_segments; i++)
3798 vec_add2 (segments, seg, 1);
3799 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3802 for (i = 0; i < mp->n_tags; i++)
3804 vec_add2 (tags, tag, 1);
3805 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3809 a->segments = segments;
3812 rv = ip6_sr_add_del_tunnel (a);
3816 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3820 static void vl_api_sr_policy_add_del_t_handler
3821 (vl_api_sr_policy_add_del_t * mp)
3824 clib_warning ("unimplemented");
3826 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3828 vl_api_sr_policy_add_del_reply_t *rmp;
3831 memset (a, 0, sizeof (*a));
3832 a->is_del = (mp->is_add == 0);
3834 a->name = format (0, "%s", mp->name);
3835 if (!(vec_len (a->name)))
3837 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3841 if (!(mp->tunnel_names[0]))
3843 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3847 // start deserializing tunnel_names
3848 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3849 u8 *deser_tun_names = mp->tunnel_names;
3850 deser_tun_names += 1; //moving along
3853 int tun_name_len = 0;
3855 for (i = 0; i < num_tunnels; i++)
3857 tun_name_len = *deser_tun_names;
3858 deser_tun_names += 1;
3859 vec_resize (tun_name, tun_name_len);
3860 memcpy (tun_name, deser_tun_names, tun_name_len);
3861 vec_add1 (a->tunnel_names, tun_name);
3862 deser_tun_names += tun_name_len;
3866 rv = ip6_sr_add_del_policy (a);
3870 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3874 static void vl_api_sr_multicast_map_add_del_t_handler
3875 (vl_api_sr_multicast_map_add_del_t * mp)
3878 clib_warning ("unimplemented");
3880 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3882 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3884 memset (a, 0, sizeof (*a));
3885 a->is_del = (mp->is_add == 0);
3887 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3888 a->policy_name = format (0, "%s", mp->policy_name);
3890 if (a->multicast_address == 0)
3896 if (!(a->policy_name))
3902 #if DPDK > 0 /* Cannot call replicate without DPDK */
3903 rv = ip6_sr_add_del_multicastmap (a);
3905 clib_warning ("multicast replication without DPDK not implemented");
3906 rv = VNET_API_ERROR_UNIMPLEMENTED;
3911 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3915 #define foreach_classify_add_del_table_field \
3920 _(match_n_vectors) \
3921 _(next_table_index) \
3924 static void vl_api_classify_add_del_table_t_handler
3925 (vl_api_classify_add_del_table_t * mp)
3927 vl_api_classify_add_del_table_reply_t *rmp;
3928 vnet_classify_main_t *cm = &vnet_classify_main;
3929 vnet_classify_table_t *t;
3933 foreach_classify_add_del_table_field;
3936 #define _(a) a = ntohl(mp->a);
3937 foreach_classify_add_del_table_field;
3940 /* The underlying API fails silently, on purpose, so check here */
3941 if (mp->is_add == 0)
3942 if (pool_is_free_index (cm->tables, table_index))
3944 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3948 rv = vnet_classify_add_del_table
3949 (cm, mp->mask, nbuckets, memory_size,
3950 skip_n_vectors, match_n_vectors,
3951 next_table_index, miss_next_index, &table_index, mp->is_add);
3955 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3957 if (rv == 0 && mp->is_add)
3959 t = pool_elt_at_index (cm->tables, table_index);
3960 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3961 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3962 rmp->new_table_index = ntohl(table_index);
3966 rmp->skip_n_vectors = ~0;
3967 rmp->match_n_vectors = ~0;
3968 rmp->new_table_index = ~0;
3974 static void vl_api_classify_add_del_session_t_handler
3975 (vl_api_classify_add_del_session_t * mp)
3977 vnet_classify_main_t *cm = &vnet_classify_main;
3978 vl_api_classify_add_del_session_reply_t *rmp;
3980 u32 table_index, hit_next_index, opaque_index;
3983 table_index = ntohl (mp->table_index);
3984 hit_next_index = ntohl (mp->hit_next_index);
3985 opaque_index = ntohl (mp->opaque_index);
3986 advance = ntohl (mp->advance);
3988 rv = vnet_classify_add_del_session
3989 (cm, table_index, mp->match, hit_next_index, opaque_index,
3990 advance, mp->is_add);
3992 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3995 static void vl_api_classify_set_interface_ip_table_t_handler
3996 (vl_api_classify_set_interface_ip_table_t * mp)
3998 vlib_main_t *vm = vlib_get_main ();
3999 vl_api_classify_set_interface_ip_table_reply_t *rmp;
4001 u32 table_index, sw_if_index;
4003 table_index = ntohl (mp->table_index);
4004 sw_if_index = ntohl (mp->sw_if_index);
4006 VALIDATE_SW_IF_INDEX (mp);
4009 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
4011 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
4013 BAD_SW_IF_INDEX_LABEL;
4015 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
4018 static void vl_api_classify_set_interface_l2_tables_t_handler
4019 (vl_api_classify_set_interface_l2_tables_t * mp)
4021 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
4023 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
4026 ip4_table_index = ntohl (mp->ip4_table_index);
4027 ip6_table_index = ntohl (mp->ip6_table_index);
4028 other_table_index = ntohl (mp->other_table_index);
4029 sw_if_index = ntohl (mp->sw_if_index);
4031 VALIDATE_SW_IF_INDEX (mp);
4034 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
4038 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
4044 if (ip4_table_index != ~0 || ip6_table_index != ~0
4045 || other_table_index != ~0)
4051 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
4053 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
4056 BAD_SW_IF_INDEX_LABEL;
4058 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
4062 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
4065 vl_api_l2_fib_clear_table_reply_t *rmp;
4067 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
4068 * that is not currently implemented. When that TODO is fixed
4069 * this call should be changed to pass 1 instead of 0.
4071 l2fib_clear_table (0);
4073 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
4076 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
4077 u32 sw_if_index, u32 enable);
4080 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
4084 vl_api_l2_interface_efp_filter_reply_t *rmp;
4085 vnet_main_t *vnm = vnet_get_main ();
4087 // enable/disable the feature
4088 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
4089 rv = vnm->api_errno;
4091 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
4095 vl_api_l2_interface_vlan_tag_rewrite_t_handler
4096 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
4099 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
4100 vnet_main_t *vnm = vnet_get_main ();
4101 vlib_main_t *vm = vlib_get_main ();
4104 VALIDATE_SW_IF_INDEX (mp);
4106 vtr_op = ntohl (mp->vtr_op);
4108 /* The L2 code is unsuspicious */
4111 case L2_VTR_DISABLED:
4116 case L2_VTR_TRANSLATE_1_1:
4117 case L2_VTR_TRANSLATE_1_2:
4118 case L2_VTR_TRANSLATE_2_1:
4119 case L2_VTR_TRANSLATE_2_2:
4123 rv = VNET_API_ERROR_INVALID_VALUE;
4124 goto bad_sw_if_index;
4127 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4128 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4131 BAD_SW_IF_INDEX_LABEL;
4133 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4137 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4140 vl_api_create_vhost_user_if_reply_t *rmp;
4141 u32 sw_if_index = (u32) ~ 0;
4143 vnet_main_t *vnm = vnet_get_main ();
4144 vlib_main_t *vm = vlib_get_main ();
4146 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
4147 mp->is_server, &sw_if_index, (u64) ~ 0,
4148 mp->renumber, ntohl (mp->custom_dev_instance),
4149 (mp->use_custom_mac) ? mp->mac_address : NULL);
4152 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4154 rmp->sw_if_index = ntohl (sw_if_index);
4160 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4163 vl_api_modify_vhost_user_if_reply_t *rmp;
4164 u32 sw_if_index = ntohl (mp->sw_if_index);
4166 vnet_main_t *vnm = vnet_get_main ();
4167 vlib_main_t *vm = vlib_get_main ();
4169 rv = vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
4170 mp->is_server, sw_if_index, (u64) ~ 0,
4171 mp->renumber, ntohl (mp->custom_dev_instance));
4172 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4176 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4179 vl_api_delete_vhost_user_if_reply_t *rmp;
4180 vpe_api_main_t *vam = &vpe_api_main;
4181 u32 sw_if_index = ntohl (mp->sw_if_index);
4183 vnet_main_t *vnm = vnet_get_main ();
4184 vlib_main_t *vm = vlib_get_main ();
4186 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4188 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4191 unix_shared_memory_queue_t *q =
4192 vl_api_client_index_to_input_queue (mp->client_index);
4196 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4201 vl_api_sw_interface_vhost_user_details_t_handler
4202 (vl_api_sw_interface_vhost_user_details_t * mp)
4204 clib_warning ("BUG");
4208 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4209 unix_shared_memory_queue_t * q,
4210 vhost_user_intf_details_t * vui,
4213 vl_api_sw_interface_vhost_user_details_t *mp;
4215 mp = vl_msg_api_alloc (sizeof (*mp));
4216 memset (mp, 0, sizeof (*mp));
4217 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4218 mp->sw_if_index = ntohl (vui->sw_if_index);
4219 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4220 mp->features = clib_net_to_host_u64 (vui->features);
4221 mp->is_server = vui->is_server;
4222 mp->num_regions = ntohl (vui->num_regions);
4223 mp->sock_errno = ntohl (vui->sock_errno);
4224 mp->context = context;
4226 strncpy ((char *) mp->sock_filename,
4227 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4228 strncpy ((char *) mp->interface_name,
4229 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4231 vl_msg_api_send_shmem (q, (u8 *) & mp);
4235 vl_api_sw_interface_vhost_user_dump_t_handler
4236 (vl_api_sw_interface_vhost_user_dump_t * mp)
4239 vpe_api_main_t *am = &vpe_api_main;
4240 vnet_main_t *vnm = vnet_get_main ();
4241 vlib_main_t *vm = vlib_get_main ();
4242 vhost_user_intf_details_t *ifaces = NULL;
4243 vhost_user_intf_details_t *vuid = NULL;
4244 unix_shared_memory_queue_t *q;
4246 q = vl_api_client_index_to_input_queue (mp->client_index);
4250 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4254 vec_foreach (vuid, ifaces)
4256 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4262 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4263 unix_shared_memory_queue_t * q,
4265 l2t_main_t * lm, u32 context)
4267 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4269 vnet_sw_interface_t *si = NULL;
4271 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4273 if_name = format (if_name, "%U",
4274 format_vnet_sw_interface_name, lm->vnet_main, si);
4276 mp = vl_msg_api_alloc (sizeof (*mp));
4277 memset (mp, 0, sizeof (*mp));
4278 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4279 strncpy ((char *) mp->interface_name,
4280 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4281 mp->sw_if_index = ntohl (si->sw_if_index);
4282 mp->local_session_id = s->local_session_id;
4283 mp->remote_session_id = s->remote_session_id;
4284 mp->local_cookie[0] = s->local_cookie[0];
4285 mp->local_cookie[1] = s->local_cookie[1];
4286 mp->remote_cookie = s->remote_cookie;
4287 clib_memcpy (mp->client_address, &s->client_address,
4288 sizeof (s->client_address));
4289 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4290 mp->l2_sublayer_present = s->l2_sublayer_present;
4291 mp->context = context;
4293 vl_msg_api_send_shmem (q, (u8 *) & mp);
4297 send_ip_address_details (vpe_api_main_t * am,
4298 unix_shared_memory_queue_t * q,
4299 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4301 vl_api_ip_address_details_t *mp;
4303 mp = vl_msg_api_alloc (sizeof (*mp));
4304 memset (mp, 0, sizeof (*mp));
4305 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4309 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4313 u32 *tp = (u32 *) mp->ip;
4314 *tp = ntohl (*(u32 *) ip);
4316 mp->prefix_length = prefix_length;
4317 mp->context = context;
4319 vl_msg_api_send_shmem (q, (u8 *) & mp);
4323 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4325 vpe_api_main_t *am = &vpe_api_main;
4326 unix_shared_memory_queue_t *q;
4329 ip6_main_t *im6 = &ip6_main;
4330 ip4_main_t *im4 = &ip4_main;
4331 ip_lookup_main_t *lm6 = &im6->lookup_main;
4332 ip_lookup_main_t *lm4 = &im4->lookup_main;
4333 ip_interface_address_t *ia = 0;
4334 u32 sw_if_index = ~0;
4335 int rv __attribute__ ((unused)) = 0;
4337 VALIDATE_SW_IF_INDEX (mp);
4339 sw_if_index = ntohl (mp->sw_if_index);
4341 q = vl_api_client_index_to_input_queue (mp->client_index);
4350 foreach_ip_interface_address (lm6, ia, sw_if_index,
4351 1 /* honor unnumbered */,
4353 r6 = ip_interface_address_get_address (lm6, ia);
4354 u16 prefix_length = ia->address_length;
4355 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4362 foreach_ip_interface_address (lm4, ia, sw_if_index,
4363 1 /* honor unnumbered */,
4365 r4 = ip_interface_address_get_address (lm4, ia);
4366 u16 prefix_length = ia->address_length;
4367 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4371 BAD_SW_IF_INDEX_LABEL;
4375 send_ip_details (vpe_api_main_t * am,
4376 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4378 vl_api_ip_details_t *mp;
4380 mp = vl_msg_api_alloc (sizeof (*mp));
4381 memset (mp, 0, sizeof (*mp));
4382 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4384 mp->sw_if_index = ntohl (sw_if_index);
4385 mp->context = context;
4387 vl_msg_api_send_shmem (q, (u8 *) & mp);
4391 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4394 vpe_api_main_t *am = &vpe_api_main;
4395 l2t_main_t *lm = &l2t_main;
4396 unix_shared_memory_queue_t *q;
4397 l2t_session_t *session;
4399 q = vl_api_client_index_to_input_queue (mp->client_index);
4404 pool_foreach (session, lm->sessions,
4406 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4413 send_sw_interface_tap_details (vpe_api_main_t * am,
4414 unix_shared_memory_queue_t * q,
4415 tapcli_interface_details_t * tap_if,
4418 vl_api_sw_interface_tap_details_t *mp;
4419 mp = vl_msg_api_alloc (sizeof (*mp));
4420 memset (mp, 0, sizeof (*mp));
4421 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4422 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4423 strncpy ((char *) mp->dev_name,
4424 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4425 mp->context = context;
4427 vl_msg_api_send_shmem (q, (u8 *) & mp);
4431 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4434 vpe_api_main_t *am = &vpe_api_main;
4435 unix_shared_memory_queue_t *q;
4436 tapcli_interface_details_t *tapifs = NULL;
4437 tapcli_interface_details_t *tap_if = NULL;
4439 q = vl_api_client_index_to_input_queue (mp->client_index);
4443 rv = vnet_tap_dump_ifs (&tapifs);
4447 vec_foreach (tap_if, tapifs)
4449 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4456 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4458 vpe_api_main_t *am = &vpe_api_main;
4459 vnet_main_t *vnm = vnet_get_main ();
4460 vlib_main_t *vm = vlib_get_main ();
4461 vnet_interface_main_t *im = &vnm->interface_main;
4462 unix_shared_memory_queue_t *q;
4463 vnet_sw_interface_t *si, *sorted_sis;
4464 u32 sw_if_index = ~0;
4466 q = vl_api_client_index_to_input_queue (mp->client_index);
4472 /* Gather interfaces. */
4473 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4474 _vec_len (sorted_sis) = 0;
4476 pool_foreach (si, im->sw_interfaces,
4478 vec_add1 (sorted_sis, si[0]);
4482 vec_foreach (si, sorted_sis)
4484 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4486 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4490 sw_if_index = si->sw_if_index;
4491 send_ip_details (am, q, sw_if_index, mp->context);
4497 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4499 clib_warning ("BUG");
4503 send_l2fib_table_entry (vpe_api_main_t * am,
4504 unix_shared_memory_queue_t * q,
4505 l2fib_entry_key_t * l2fe_key,
4506 l2fib_entry_result_t * l2fe_res, u32 context)
4508 vl_api_l2_fib_table_entry_t *mp;
4510 mp = vl_msg_api_alloc (sizeof (*mp));
4511 memset (mp, 0, sizeof (*mp));
4512 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4515 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4517 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4518 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4519 mp->static_mac = l2fe_res->fields.static_mac;
4520 mp->filter_mac = l2fe_res->fields.filter;
4521 mp->bvi_mac = l2fe_res->fields.bvi;
4522 mp->context = context;
4524 vl_msg_api_send_shmem (q, (u8 *) & mp);
4528 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4530 vpe_api_main_t *am = &vpe_api_main;
4531 bd_main_t *bdm = &bd_main;
4532 l2fib_entry_key_t *l2fe_key = NULL;
4533 l2fib_entry_result_t *l2fe_res = NULL;
4534 u32 ni, bd_id = ntohl (mp->bd_id);
4536 unix_shared_memory_queue_t *q;
4539 q = vl_api_client_index_to_input_queue (mp->client_index);
4543 /* see l2fib_table_dump: ~0 means "any" */
4548 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4555 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4557 vec_foreach_index (ni, l2fe_key)
4559 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4560 vec_elt_at_index (l2fe_res, ni), mp->context);
4562 vec_free (l2fe_key);
4563 vec_free (l2fe_res);
4567 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4569 vl_api_show_version_reply_t *rmp;
4571 char *vpe_api_get_build_directory (void);
4572 char *vpe_api_get_version (void);
4573 char *vpe_api_get_build_date (void);
4575 unix_shared_memory_queue_t *q =
4576 vl_api_client_index_to_input_queue (mp->client_index);
4582 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4584 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4585 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4586 ARRAY_LEN(rmp->build_directory)-1);
4587 strncpy ((char *) rmp->version, vpe_api_get_version(),
4588 ARRAY_LEN(rmp->version)-1);
4589 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4590 ARRAY_LEN(rmp->build_date)-1);
4596 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4598 vlib_main_t *vm = vlib_get_main ();
4599 vl_api_get_node_index_reply_t *rmp;
4602 u32 node_index = ~0;
4604 n = vlib_get_node_by_name (vm, mp->node_name);
4607 rv = VNET_API_ERROR_NO_SUCH_NODE;
4609 node_index = n->index;
4612 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4614 rmp->node_index = ntohl(node_index);
4620 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4622 vlib_main_t *vm = vlib_get_main ();
4623 vl_api_get_next_index_reply_t *rmp;
4624 vlib_node_t *node, *next_node;
4626 u32 next_node_index = ~0, next_index = ~0;
4629 node = vlib_get_node_by_name (vm, mp->node_name);
4633 rv = VNET_API_ERROR_NO_SUCH_NODE;
4637 next_node = vlib_get_node_by_name (vm, mp->next_name);
4641 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4645 next_node_index = next_node->index;
4647 p = hash_get (node->next_slot_by_node, next_node_index);
4651 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4659 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4661 rmp->next_index = ntohl(next_index);
4667 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4669 vlib_main_t *vm = vlib_get_main ();
4670 vl_api_add_node_next_reply_t *rmp;
4671 vlib_node_t *n, *next;
4673 u32 next_index = ~0;
4675 n = vlib_get_node_by_name (vm, mp->node_name);
4679 rv = VNET_API_ERROR_NO_SUCH_NODE;
4683 next = vlib_get_node_by_name (vm, mp->next_name);
4686 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4688 next_index = vlib_node_add_next (vm, n->index, next->index);
4692 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4694 rmp->next_index = ntohl(next_index);
4699 static void vl_api_l2tpv3_create_tunnel_t_handler
4700 (vl_api_l2tpv3_create_tunnel_t * mp)
4702 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4703 l2t_main_t *lm = &l2t_main;
4704 u32 sw_if_index = (u32) ~ 0;
4707 if (mp->is_ipv6 != 1)
4709 rv = VNET_API_ERROR_UNIMPLEMENTED;
4713 u32 encap_fib_index;
4715 if (mp->encap_vrf_id != ~0)
4718 ip6_main_t *im = &ip6_main;
4721 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4723 rv = VNET_API_ERROR_NO_SUCH_FIB;
4726 encap_fib_index = p[0];
4730 encap_fib_index = ~0;
4733 rv = create_l2tpv3_ipv6_tunnel (lm,
4734 (ip6_address_t *) mp->client_address,
4735 (ip6_address_t *) mp->our_address,
4736 ntohl (mp->local_session_id),
4737 ntohl (mp->remote_session_id),
4738 clib_net_to_host_u64 (mp->local_cookie),
4739 clib_net_to_host_u64 (mp->remote_cookie),
4740 mp->l2_sublayer_present,
4741 encap_fib_index, &sw_if_index);
4745 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4747 rmp->sw_if_index = ntohl (sw_if_index);
4752 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4753 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4755 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4756 l2t_main_t *lm = &l2t_main;
4759 VALIDATE_SW_IF_INDEX (mp);
4761 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4762 clib_net_to_host_u64 (mp->new_local_cookie),
4763 clib_net_to_host_u64
4764 (mp->new_remote_cookie));
4766 BAD_SW_IF_INDEX_LABEL;
4768 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4771 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4772 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4775 vnet_main_t *vnm = vnet_get_main ();
4776 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4778 VALIDATE_SW_IF_INDEX (mp);
4780 rv = l2tpv3_interface_enable_disable
4781 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4783 BAD_SW_IF_INDEX_LABEL;
4785 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4788 static void vl_api_l2tpv3_set_lookup_key_t_handler
4789 (vl_api_l2tpv3_set_lookup_key_t * mp)
4792 l2t_main_t *lm = &l2t_main;
4793 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4795 if (mp->key > L2T_LOOKUP_SESSION_ID)
4797 rv = VNET_API_ERROR_INVALID_VALUE;
4801 lm->lookup_type = mp->key;
4804 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4807 static void vl_api_vxlan_add_del_tunnel_t_handler
4808 (vl_api_vxlan_add_del_tunnel_t * mp)
4810 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4812 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4813 u32 encap_fib_index;
4815 ip4_main_t *im = &ip4_main;
4816 u32 sw_if_index = ~0;
4818 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4821 rv = VNET_API_ERROR_NO_SUCH_FIB;
4824 encap_fib_index = p[0];
4826 /* Check src & dst are different */
4827 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4828 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4830 rv = VNET_API_ERROR_SAME_SRC_DST;
4833 memset (a, 0, sizeof (*a));
4835 a->is_add = mp->is_add;
4836 a->is_ip6 = mp->is_ipv6;
4838 /* ip addresses sent in network byte order */
4841 memcpy (&(a->src.ip6), mp->src_address, 16);
4842 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4846 memcpy (&(a->src.ip4), mp->src_address, 4);
4847 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4850 a->encap_fib_index = encap_fib_index;
4851 a->decap_next_index = ntohl (mp->decap_next_index);
4852 a->vni = ntohl (mp->vni);
4853 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4857 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4859 rmp->sw_if_index = ntohl (sw_if_index);
4864 static void send_vxlan_tunnel_details
4865 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4867 vl_api_vxlan_tunnel_details_t *rmp;
4868 ip4_main_t *im4 = &ip4_main;
4869 ip6_main_t *im6 = &ip6_main;
4870 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
4872 rmp = vl_msg_api_alloc (sizeof (*rmp));
4873 memset (rmp, 0, sizeof (*rmp));
4874 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4877 memcpy (rmp->src_address, &(t->src.ip6), 16);
4878 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4879 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4883 memcpy (rmp->src_address, &(t->src.ip4), 4);
4884 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4885 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4887 rmp->vni = htonl (t->vni);
4888 /* decap_next_index is deprecated, hard code to l2-input */
4889 rmp->decap_next_index = htonl (VXLAN_INPUT_NEXT_L2_INPUT);
4890 rmp->sw_if_index = htonl (t->sw_if_index);
4891 rmp->is_ipv6 = is_ipv6;
4892 rmp->context = context;
4894 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4897 static void vl_api_vxlan_tunnel_dump_t_handler
4898 (vl_api_vxlan_tunnel_dump_t * mp)
4900 unix_shared_memory_queue_t *q;
4901 vxlan_main_t *vxm = &vxlan_main;
4905 q = vl_api_client_index_to_input_queue (mp->client_index);
4911 sw_if_index = ntohl (mp->sw_if_index);
4913 if (~0 == sw_if_index)
4916 pool_foreach (t, vxm->tunnels,
4918 send_vxlan_tunnel_details(t, q, mp->context);
4924 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4925 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4929 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4930 send_vxlan_tunnel_details (t, q, mp->context);
4934 static void vl_api_gre_add_del_tunnel_t_handler
4935 (vl_api_gre_add_del_tunnel_t * mp)
4937 vl_api_gre_add_del_tunnel_reply_t *rmp;
4939 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4942 ip4_main_t *im = &ip4_main;
4943 u32 sw_if_index = ~0;
4945 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4948 rv = VNET_API_ERROR_NO_SUCH_FIB;
4951 outer_fib_id = p[0];
4953 /* Check src & dst are different */
4954 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4955 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4957 rv = VNET_API_ERROR_SAME_SRC_DST;
4960 memset (a, 0, sizeof (*a));
4962 a->is_add = mp->is_add;
4965 /* ip addresses sent in network byte order */
4966 clib_memcpy (&(a->src), mp->src_address, 4);
4967 clib_memcpy (&(a->dst), mp->dst_address, 4);
4969 a->outer_fib_id = outer_fib_id;
4970 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4974 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4976 rmp->sw_if_index = ntohl (sw_if_index);
4981 static void send_gre_tunnel_details
4982 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4984 vl_api_gre_tunnel_details_t *rmp;
4985 ip4_main_t *im = &ip4_main;
4987 rmp = vl_msg_api_alloc (sizeof (*rmp));
4988 memset (rmp, 0, sizeof (*rmp));
4989 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4990 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4991 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4992 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4994 rmp->sw_if_index = htonl (t->sw_if_index);
4995 rmp->context = context;
4997 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5001 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
5003 unix_shared_memory_queue_t *q;
5004 gre_main_t *gm = &gre_main;
5008 q = vl_api_client_index_to_input_queue (mp->client_index);
5014 sw_if_index = ntohl (mp->sw_if_index);
5016 if (~0 == sw_if_index)
5019 pool_foreach (t, gm->tunnels,
5021 send_gre_tunnel_details(t, q, mp->context);
5027 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
5028 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
5032 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
5033 send_gre_tunnel_details (t, q, mp->context);
5038 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
5040 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5042 vl_api_l2_patch_add_del_reply_t *rmp;
5043 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5047 VALIDATE_RX_SW_IF_INDEX (mp);
5048 VALIDATE_TX_SW_IF_INDEX (mp);
5050 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
5051 ntohl (mp->tx_sw_if_index),
5052 (int) (mp->is_add != 0));
5054 BAD_RX_SW_IF_INDEX_LABEL;
5055 BAD_TX_SW_IF_INDEX_LABEL;
5057 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
5061 vl_api_vxlan_gpe_add_del_tunnel_t_handler
5062 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
5064 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
5066 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
5067 u32 encap_fib_index, decap_fib_index;
5070 ip4_main_t *im = &ip4_main;
5071 u32 sw_if_index = ~0;
5074 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
5077 rv = VNET_API_ERROR_NO_SUCH_FIB;
5080 encap_fib_index = p[0];
5082 protocol = mp->protocol;
5084 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
5085 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
5087 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
5090 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
5093 decap_fib_index = p[0];
5097 decap_fib_index = ntohl (mp->decap_vrf_id);
5100 /* Check src & dst are different */
5101 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5102 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5104 rv = VNET_API_ERROR_SAME_SRC_DST;
5107 memset (a, 0, sizeof (*a));
5109 a->is_add = mp->is_add;
5110 a->is_ip6 = mp->is_ipv6;
5111 /* ip addresses sent in network byte order */
5114 clib_memcpy (&(a->local.ip6), mp->local, 16);
5115 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5119 clib_memcpy (&(a->local.ip4), mp->local, 4);
5120 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5122 a->encap_fib_index = encap_fib_index;
5123 a->decap_fib_index = decap_fib_index;
5124 a->protocol = protocol;
5125 a->vni = ntohl (mp->vni);
5126 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5130 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5132 rmp->sw_if_index = ntohl (sw_if_index);
5137 static void send_vxlan_gpe_tunnel_details
5138 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5140 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5141 ip4_main_t *im4 = &ip4_main;
5142 ip6_main_t *im6 = &ip6_main;
5143 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5145 rmp = vl_msg_api_alloc (sizeof (*rmp));
5146 memset (rmp, 0, sizeof (*rmp));
5147 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5150 memcpy (rmp->local, &(t->local.ip6), 16);
5151 memcpy (rmp->remote, &(t->remote.ip6), 16);
5152 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
5153 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
5157 memcpy (rmp->local, &(t->local.ip4), 4);
5158 memcpy (rmp->remote, &(t->remote.ip4), 4);
5159 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
5160 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
5162 rmp->vni = htonl (t->vni);
5163 rmp->protocol = t->protocol;
5164 rmp->sw_if_index = htonl (t->sw_if_index);
5165 rmp->is_ipv6 = is_ipv6;
5166 rmp->context = context;
5168 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5171 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5172 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5174 unix_shared_memory_queue_t *q;
5175 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5176 vxlan_gpe_tunnel_t *t;
5179 q = vl_api_client_index_to_input_queue (mp->client_index);
5185 sw_if_index = ntohl (mp->sw_if_index);
5187 if (~0 == sw_if_index)
5190 pool_foreach (t, vgm->tunnels,
5192 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5198 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5199 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5203 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5204 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5208 /** Used for transferring locators via VPP API */
5210 typedef CLIB_PACKED (struct {
5211 u32 sw_if_index; /**< locator sw_if_index */
5212 u8 priority; /**< locator priority */
5213 u8 weight; /**< locator weight */
5218 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5221 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5223 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5225 ls_locator_t *ls_loc;
5226 u32 ls_index = ~0, locator_num;
5227 u8 *locator_name = NULL;
5230 memset (a, 0, sizeof (a[0]));
5232 locator_name = format (0, "%s", mp->locator_set_name);
5234 a->name = locator_name;
5235 a->is_add = mp->is_add;
5237 locator_num = clib_net_to_host_u32 (mp->locator_num);
5239 memset (&locator, 0, sizeof (locator));
5240 for (i = 0; i < locator_num; i++)
5242 ls_loc = &((ls_locator_t *) mp->locators)[i];
5243 VALIDATE_SW_IF_INDEX (ls_loc);
5245 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5246 locator.priority = ls_loc->priority;
5247 locator.weight = ls_loc->weight;
5249 vec_add1 (a->locators, locator);
5252 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5254 BAD_SW_IF_INDEX_LABEL;
5256 vec_free (locator_name);
5257 vec_free (a->locators);
5260 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5262 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5268 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5270 vl_api_lisp_add_del_locator_reply_t *rmp;
5272 locator_t locator, *locators = NULL;
5273 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5275 u8 *locator_name = NULL;
5277 memset (&locator, 0, sizeof (locator));
5278 memset (a, 0, sizeof (a[0]));
5280 locator.sw_if_index = ntohl (mp->sw_if_index);
5281 locator.priority = mp->priority;
5282 locator.weight = mp->weight;
5284 vec_add1 (locators, locator);
5286 locator_name = format (0, "%s", mp->locator_set_name);
5288 a->name = locator_name;
5289 a->locators = locators;
5290 a->is_add = mp->is_add;
5293 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5295 vec_free (locators);
5296 vec_free (locator_name);
5298 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5302 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5308 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5309 gid_address_ip_set (dst, src, IP4);
5310 gid_address_ippref_len (dst) = len;
5311 ip_prefix_normalize (&gid_address_ippref (dst));
5314 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5315 gid_address_ip_set (dst, src, IP6);
5316 gid_address_ippref_len (dst) = len;
5317 ip_prefix_normalize (&gid_address_ippref (dst));
5319 case 2: /* l2 mac */
5320 gid_address_type (dst) = GID_ADDR_MAC;
5321 clib_memcpy (&gid_address_mac (dst), src, 6);
5325 return VNET_API_ERROR_INVALID_VALUE;
5328 gid_address_vni (dst) = vni;
5334 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5336 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5337 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5339 gid_address_t _eid, *eid = &_eid;
5341 u32 locator_set_index = ~0, map_index = ~0;
5342 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5344 memset (a, 0, sizeof (a[0]));
5345 memset (eid, 0, sizeof (eid[0]));
5347 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5348 mp->eid_type, mp->eid, mp->prefix_len);
5352 name = format (0, "%s", mp->locator_set_name);
5353 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5356 rv = VNET_API_ERROR_INVALID_VALUE;
5359 locator_set_index = p[0];
5361 /* XXX treat batch configuration */
5362 a->is_add = mp->is_add;
5363 gid_address_copy (&a->eid, eid);
5364 a->locator_set_index = locator_set_index;
5366 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5370 gid_address_free (&a->eid);
5372 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5376 vl_api_lisp_eid_table_add_del_map_t_handler
5377 (vl_api_lisp_eid_table_add_del_map_t * mp)
5379 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5381 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5382 clib_net_to_host_u32 (mp->dp_table),
5383 mp->is_l2, mp->is_add);
5384 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5386 /** Used for transferring locators via VPP API */
5388 typedef CLIB_PACKED (struct {
5389 u8 is_ip4; /**< is locator an IPv4 address */
5390 u8 priority; /**< locator priority */
5391 u8 weight; /**< locator weight */
5392 u8 addr[16]; /**< IPv4/IPv6 address */
5396 static locator_pair_t *
5397 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5400 locator_pair_t *pairs = 0, pair;
5403 for (i = 0; i < rloc_num; i++)
5406 r = &((rloc_t *) lcl_locs)[i];
5407 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5408 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5410 /* remote locators */
5411 r = &((rloc_t *) rmt_locs)[i];
5412 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5413 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5415 pair.priority = r->priority;
5416 pair.weight = r->weight;
5418 vec_add1 (pairs, pair);
5424 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5427 locator_t *locs = 0, loc;
5430 for (i = 0; i < rloc_num; i++)
5432 /* remote locators */
5433 r = &((rloc_t *) rmt_locs)[i];
5434 memset (&loc, 0, sizeof (loc));
5435 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5437 loc.priority = r->priority;
5438 loc.weight = r->weight;
5440 vec_add1 (locs, loc);
5446 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5447 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5449 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5450 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5451 locator_pair_t *pairs = 0;
5454 memset (a, 0, sizeof (a[0]));
5456 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5457 mp->rmt_eid, mp->rmt_len);
5458 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5459 mp->lcl_eid, mp->lcl_len);
5461 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5463 if (rv || 0 == pairs)
5466 a->is_add = mp->is_add;
5467 a->locator_pairs = pairs;
5468 a->dp_table = mp->dp_table;
5470 a->action = mp->action;
5472 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5475 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5479 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5482 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5484 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5486 memset (a, 0, sizeof (a[0]));
5488 a->is_add = mp->is_add;
5489 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5491 rv = vnet_lisp_add_del_map_resolver (a);
5493 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5497 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5500 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5502 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5504 a->is_en = mp->is_en;
5505 vnet_lisp_gpe_enable_disable (a);
5507 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5511 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5513 vl_api_lisp_enable_disable_reply_t *rmp;
5516 vnet_lisp_enable_disable (mp->is_en);
5517 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5521 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5523 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5531 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
5535 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
5542 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
5546 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
5549 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5553 vl_api_show_lisp_map_request_mode_t_handler
5554 (vl_api_show_lisp_map_request_mode_t * mp)
5557 vl_api_show_lisp_map_request_mode_reply_t *rmp;
5560 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
5562 rmp->mode = vnet_lisp_get_map_request_mode ();
5568 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
5570 vl_api_lisp_map_request_mode_reply_t *rmp;
5573 rv = vnet_lisp_set_map_request_mode (mp->mode);
5575 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
5579 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5582 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5586 ls_name = format (0, "%s", mp->ls_name);
5587 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5590 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5594 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5595 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5597 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5599 u8 *locator_set_name = NULL;
5600 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5602 locator_set_name = format (0, "%s", mp->locator_set_name);
5604 a->is_add = mp->is_add;
5605 a->locator_set_name = locator_set_name;
5607 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5609 vec_free (locator_set_name);
5611 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5615 vl_api_lisp_add_del_remote_mapping_t_handler
5616 (vl_api_lisp_add_del_remote_mapping_t * mp)
5618 locator_t *rlocs = 0;
5619 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5621 gid_address_t _eid, *eid = &_eid;
5622 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5624 memset (eid, 0, sizeof (eid[0]));
5626 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5627 mp->eid_type, mp->eid, mp->eid_len);
5631 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5635 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5636 gid_address_copy (&a->reid, eid);
5638 rv = vnet_lisp_add_del_adjacency (a);
5645 /* NOTE: for now this works as a static remote mapping, i.e.,
5646 * not authoritative and ttl infinite. */
5647 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5648 mp->is_add, 1 /* is_static */ , 0);
5651 vnet_lisp_clear_all_remote_adjacencies ();
5656 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5660 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5662 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5663 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5666 memset (a, 0, sizeof (a[0]));
5668 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
5669 mp->eid_type, mp->leid, mp->leid_len);
5670 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
5671 mp->eid_type, mp->reid, mp->reid_len);
5676 a->is_add = mp->is_add;
5677 rv = vnet_lisp_add_del_adjacency (a);
5680 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5684 send_lisp_locator_details (lisp_cp_main_t * lcm,
5686 unix_shared_memory_queue_t * q, u32 context)
5688 vl_api_lisp_locator_details_t *rmp;
5690 rmp = vl_msg_api_alloc (sizeof (*rmp));
5691 memset (rmp, 0, sizeof (*rmp));
5692 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5693 rmp->context = context;
5695 rmp->local = loc->local;
5698 rmp->sw_if_index = ntohl (loc->sw_if_index);
5702 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5703 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5705 rmp->priority = loc->priority;
5706 rmp->weight = loc->weight;
5708 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5712 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5715 unix_shared_memory_queue_t *q = 0;
5716 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5717 locator_set_t *lsit = 0;
5719 u32 ls_index = ~0, *locit = 0;
5722 q = vl_api_client_index_to_input_queue (mp->client_index);
5728 if (mp->is_index_set)
5729 ls_index = htonl (mp->ls_index);
5732 /* make sure we get a proper C-string */
5733 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
5734 ls_name = format (0, "%s", mp->ls_name);
5735 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
5741 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
5744 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5746 vec_foreach (locit, lsit->locator_indices)
5748 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5749 send_lisp_locator_details (lcm, loc, q, mp->context);
5756 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5757 locator_set_t * lsit,
5758 unix_shared_memory_queue_t * q,
5759 u32 context, u32 ls_index)
5761 vl_api_lisp_locator_set_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_SET_DETAILS);
5767 rmp->context = context;
5769 rmp->ls_index = htonl (ls_index);
5772 ASSERT (lsit->name != NULL);
5773 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
5774 vec_len (lsit->name));
5778 str = format (0, "<remote-%d>", ls_index);
5779 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
5783 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5787 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5789 unix_shared_memory_queue_t *q = NULL;
5790 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5791 locator_set_t *lsit = NULL;
5794 q = vl_api_client_index_to_input_queue (mp->client_index);
5800 filter = mp->filter;
5802 pool_foreach (lsit, lcm->locator_set_pool,
5804 if (filter && !((1 == filter && lsit->local) ||
5805 (2 == filter && !lsit->local)))
5809 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
5810 lsit - lcm->locator_set_pool);
5816 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5818 ASSERT (prefix_length);
5819 ip_prefix_t *ippref = &fid_addr_ippref (src);
5821 switch (fid_addr_type (src))
5823 case FID_ADDR_IP_PREF:
5824 if (ip_prefix_version (ippref) == IP4)
5825 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5827 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5828 prefix_length[0] = ip_prefix_len (ippref);
5832 prefix_length[0] = 0;
5833 clib_memcpy (dst, fid_addr_mac (src), 6);
5837 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5843 fid_type_to_api_type (fid_address_t * fid)
5845 ip_prefix_t *ippref;
5847 switch (fid_addr_type (fid))
5849 case FID_ADDR_IP_PREF:
5850 ippref = &fid_addr_ippref (fid);
5851 if (ip_prefix_version (ippref) == IP4)
5853 else if (ip_prefix_version (ippref) == IP6)
5866 send_lisp_eid_table_details (mapping_t * mapit,
5867 unix_shared_memory_queue_t * q,
5868 u32 context, u8 filter)
5871 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5872 locator_set_t *ls = 0;
5873 vl_api_lisp_eid_table_details_t *rmp = NULL;
5874 gid_address_t *gid = NULL;
5876 ip_prefix_t *ip_prefix = NULL;
5880 case 0: /* all mappings */
5883 case 1: /* local only */
5887 case 2: /* remote only */
5892 clib_warning ("Filter error, unknown filter: %d", filter);
5897 ip_prefix = &gid_address_ippref (gid);
5898 mac = gid_address_mac (gid);
5900 rmp = vl_msg_api_alloc (sizeof (*rmp));
5901 memset (rmp, 0, sizeof (*rmp));
5902 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5904 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5905 if (vec_len (ls->locator_indices) == 0)
5906 rmp->locator_set_index = ~0;
5908 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5910 rmp->is_local = mapit->local;
5911 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5912 rmp->action = mapit->action;
5913 rmp->authoritative = mapit->authoritative;
5915 switch (gid_address_type (gid))
5917 case GID_ADDR_SRC_DST:
5918 rmp->is_src_dst = 1;
5919 fid = &gid_address_sd_src (gid);
5920 rmp->eid_type = fid_type_to_api_type (fid);
5921 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5922 &rmp->seid_prefix_len);
5923 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5924 &rmp->eid_prefix_len);
5926 case GID_ADDR_IP_PREFIX:
5927 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5928 if (ip_prefix_version (ip_prefix) == IP4)
5930 rmp->eid_type = 0; /* ipv4 type */
5931 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5932 sizeof (ip_prefix_v4 (ip_prefix)));
5936 rmp->eid_type = 1; /* ipv6 type */
5937 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5938 sizeof (ip_prefix_v6 (ip_prefix)));
5942 rmp->eid_type = 2; /* l2 mac type */
5943 clib_memcpy (rmp->eid, mac, 6);
5948 rmp->context = context;
5949 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5950 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5954 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5957 unix_shared_memory_queue_t *q = NULL;
5958 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5959 mapping_t *mapit = NULL;
5960 gid_address_t _eid, *eid = &_eid;
5962 q = vl_api_client_index_to_input_queue (mp->client_index);
5970 memset (eid, 0, sizeof (*eid));
5972 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5973 mp->eid_type, mp->eid, mp->prefix_length);
5975 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5976 if ((u32) ~ 0 == mi)
5979 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5980 send_lisp_eid_table_details (mapit, q, mp->context,
5981 0 /* ignore filter */ );
5986 pool_foreach (mapit, lcm->mapping_pool,
5988 send_lisp_eid_table_details(mapit, q, mp->context,
5996 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
5997 unix_shared_memory_queue_t * q, u32 context)
5999 vl_api_lisp_gpe_tunnel_details_t *rmp;
6000 lisp_gpe_main_t *lgm = &lisp_gpe_main;
6002 rmp = vl_msg_api_alloc (sizeof (*rmp));
6003 memset (rmp, 0, sizeof (*rmp));
6004 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
6006 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
6008 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
6009 ip_address_copy_addr (rmp->source_ip,
6010 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
6011 ip_address_copy_addr (rmp->destination_ip,
6012 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
6014 rmp->encap_fib_id = htonl (0);
6015 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
6016 rmp->iid = htonl (lfe->key->vni);
6017 rmp->context = context;
6019 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6023 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
6025 unix_shared_memory_queue_t *q = NULL;
6026 lisp_gpe_main_t *lgm = &lisp_gpe_main;
6027 lisp_gpe_fwd_entry_t *lfe = NULL;
6029 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
6034 q = vl_api_client_index_to_input_queue (mp->client_index);
6041 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
6043 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
6049 send_lisp_map_resolver_details (ip_address_t * ip,
6050 unix_shared_memory_queue_t * q, u32 context)
6052 vl_api_lisp_map_resolver_details_t *rmp = NULL;
6054 rmp = vl_msg_api_alloc (sizeof (*rmp));
6055 memset (rmp, 0, sizeof (*rmp));
6056 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
6058 switch (ip_addr_version (ip))
6062 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
6063 sizeof (ip_addr_v4 (ip)));
6068 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
6069 sizeof (ip_addr_v6 (ip)));
6075 rmp->context = context;
6077 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6081 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
6083 unix_shared_memory_queue_t *q = NULL;
6084 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6087 q = vl_api_client_index_to_input_queue (mp->client_index);
6093 vec_foreach (mr, lcm->map_resolvers)
6095 send_lisp_map_resolver_details (&mr->address, q, mp->context);
6100 send_eid_table_map_pair (hash_pair_t * p,
6101 unix_shared_memory_queue_t * q, u32 context)
6103 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
6105 rmp = vl_msg_api_alloc (sizeof (*rmp));
6106 memset (rmp, 0, sizeof (*rmp));
6107 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
6109 rmp->vni = clib_host_to_net_u32 (p->key);
6110 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
6111 rmp->context = context;
6112 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6116 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
6119 unix_shared_memory_queue_t *q = NULL;
6120 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6122 uword *vni_table = 0;
6124 q = vl_api_client_index_to_input_queue (mp->client_index);
6132 vni_table = lcm->bd_id_by_vni;
6136 vni_table = lcm->table_id_by_vni;
6140 hash_foreach_pair (p, vni_table,
6142 send_eid_table_map_pair (p, q, mp->context);
6148 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6150 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6152 rmp = vl_msg_api_alloc (sizeof (*rmp));
6153 memset (rmp, 0, sizeof (*rmp));
6154 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6155 rmp->context = context;
6156 rmp->vni = clib_host_to_net_u32 (vni);
6157 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6161 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
6163 lisp_adjacency_t *adj;
6164 vl_api_lisp_adjacency_t a;
6165 u32 i, n = vec_len (adjs);
6167 for (i = 0; i < n; i++)
6169 adj = vec_elt_at_index (adjs, i);
6170 memset (&a, 0, sizeof (a));
6172 switch (gid_address_type (&adj->reid))
6174 case GID_ADDR_IP_PREFIX:
6175 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
6176 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
6177 if (gid_address_ip_version (&adj->reid) == IP4)
6179 a.eid_type = 0; /* ipv4 type */
6180 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
6181 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
6185 a.eid_type = 1; /* ipv6 type */
6186 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
6187 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
6191 a.eid_type = 2; /* l2 mac type */
6192 mac_copy (a.reid, gid_address_mac (&adj->reid));
6193 mac_copy (a.leid, gid_address_mac (&adj->leid));
6203 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
6205 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
6206 lisp_adjacency_t *adjs = 0;
6208 vl_api_lisp_adjacency_t a;
6210 u32 vni = clib_net_to_host_u32 (mp->vni);
6212 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
6213 size = vec_len (adjs) * sizeof (a);
6216 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
6218 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
6219 lisp_adjacency_copy (rmp->adjacencies, adjs);
6227 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6232 unix_shared_memory_queue_t *q = 0;
6233 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6235 q = vl_api_client_index_to_input_queue (mp->client_index);
6242 hash_foreach_pair (p, lcm->table_id_by_vni,
6244 hash_set (vnis, p->key, 0);
6247 hash_foreach_pair (p, lcm->bd_id_by_vni,
6249 hash_set (vnis, p->key, 0);
6252 hash_foreach_pair (p, vnis,
6254 send_eid_table_vni (p->key, q, mp->context);
6262 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6264 unix_shared_memory_queue_t *q = NULL;
6265 vl_api_show_lisp_status_reply_t *rmp = NULL;
6268 q = vl_api_client_index_to_input_queue (mp->client_index);
6275 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6277 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6278 rmp->feature_status = vnet_lisp_enable_disable_status ();
6284 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6285 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6287 unix_shared_memory_queue_t *q = NULL;
6288 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6289 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6290 locator_set_t *loc_set = 0;
6294 q = vl_api_client_index_to_input_queue (mp->client_index);
6300 if (~0 == lcm->mreq_itr_rlocs)
6302 tmp_str = format (0, " ");
6307 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6308 tmp_str = format (0, "%s", loc_set->name);
6312 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6314 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6315 ARRAY_LEN(rmp->locator_set_name) - 1);
6323 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6325 unix_shared_memory_queue_t *q = NULL;
6326 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6327 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6329 locator_set_t *ls = 0;
6333 q = vl_api_client_index_to_input_queue (mp->client_index);
6339 if (!lcm->lisp_pitr)
6341 tmp_str = format (0, "N/A");
6345 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6346 if (~0 != m->locator_set_index)
6349 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6350 tmp_str = format (0, "%s", ls->name);
6354 tmp_str = format (0, "N/A");
6357 vec_add1 (tmp_str, 0);
6360 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6362 rmp->status = lcm->lisp_pitr;
6363 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6364 ARRAY_LEN(rmp->locator_set_name) - 1);
6370 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6373 vl_api_interface_name_renumber_reply_t *rmp;
6376 VALIDATE_SW_IF_INDEX (mp);
6378 rv = vnet_interface_name_renumber
6379 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6381 BAD_SW_IF_INDEX_LABEL;
6383 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6387 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6388 u32 sw_if_index, u32 address)
6390 vpe_api_main_t *am = &vpe_api_main;
6391 vlib_main_t *vm = am->vlib_main;
6392 vl_api_ip4_arp_event_t *event;
6393 static f64 arp_event_last_time;
6394 f64 now = vlib_time_now (vm);
6396 if (pool_is_free_index (am->arp_events, pool_index))
6399 event = pool_elt_at_index (am->arp_events, pool_index);
6401 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6403 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6407 if (sw_if_index == event->sw_if_index &&
6409 /* for BD case, also check IP address with 10 sec timeout */
6410 (address == event->address &&
6411 (now - arp_event_last_time) < 10.0)))
6416 arp_event_last_time = now;
6417 event->sw_if_index = sw_if_index;
6419 event->address = address;
6424 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6425 u32 sw_if_index, ip6_address_t * address)
6427 vpe_api_main_t *am = &vpe_api_main;
6428 vlib_main_t *vm = am->vlib_main;
6429 vl_api_ip6_nd_event_t *event;
6430 static f64 nd_event_last_time;
6431 f64 now = vlib_time_now (vm);
6433 if (pool_is_free_index (am->nd_events, pool_index))
6436 event = pool_elt_at_index (am->nd_events, pool_index);
6439 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6441 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6445 if (sw_if_index == event->sw_if_index &&
6447 /* for BD case, also check IP address with 10 sec timeout */
6448 (ip6_address_is_equal (address,
6449 (ip6_address_t *) event->address) &&
6450 (now - nd_event_last_time) < 10.0)))
6455 nd_event_last_time = now;
6456 event->sw_if_index = sw_if_index;
6458 clib_memcpy (event->address, address, sizeof (event->address));
6463 arp_change_delete_callback (u32 pool_index, u8 * notused)
6465 vpe_api_main_t *am = &vpe_api_main;
6467 if (pool_is_free_index (am->arp_events, pool_index))
6470 pool_put_index (am->arp_events, pool_index);
6475 nd_change_delete_callback (u32 pool_index, u8 * notused)
6477 vpe_api_main_t *am = &vpe_api_main;
6479 if (pool_is_free_index (am->nd_events, pool_index))
6482 pool_put_index (am->nd_events, pool_index);
6487 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6489 vpe_api_main_t *am = &vpe_api_main;
6490 vnet_main_t *vnm = vnet_get_main ();
6491 vl_api_want_ip4_arp_events_reply_t *rmp;
6492 vl_api_ip4_arp_event_t *event;
6495 if (mp->enable_disable)
6497 pool_get (am->arp_events, event);
6498 memset (event, 0, sizeof (*event));
6500 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6501 event->client_index = mp->client_index;
6502 event->context = mp->context;
6503 event->address = mp->address;
6504 event->pid = mp->pid;
6505 if (mp->address == 0)
6508 rv = vnet_add_del_ip4_arp_change_event
6509 (vnm, arp_change_data_callback,
6510 mp->pid, &mp->address /* addr, in net byte order */ ,
6511 vpe_resolver_process_node.index,
6512 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6516 rv = vnet_add_del_ip4_arp_change_event
6517 (vnm, arp_change_delete_callback,
6518 mp->pid, &mp->address /* addr, in net byte order */ ,
6519 vpe_resolver_process_node.index,
6520 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6522 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6526 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6528 vpe_api_main_t *am = &vpe_api_main;
6529 vnet_main_t *vnm = vnet_get_main ();
6530 vl_api_want_ip6_nd_events_reply_t *rmp;
6531 vl_api_ip6_nd_event_t *event;
6534 if (mp->enable_disable)
6536 pool_get (am->nd_events, event);
6537 memset (event, 0, sizeof (*event));
6539 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6540 event->client_index = mp->client_index;
6541 event->context = mp->context;
6542 clib_memcpy (event->address, mp->address, 16);
6543 event->pid = mp->pid;
6544 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6547 rv = vnet_add_del_ip6_nd_change_event
6548 (vnm, nd_change_data_callback,
6549 mp->pid, mp->address /* addr, in net byte order */ ,
6550 vpe_resolver_process_node.index,
6551 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6555 rv = vnet_add_del_ip6_nd_change_event
6556 (vnm, nd_change_delete_callback,
6557 mp->pid, mp->address /* addr, in net byte order */ ,
6558 vpe_resolver_process_node.index,
6559 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6561 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6564 static void vl_api_input_acl_set_interface_t_handler
6565 (vl_api_input_acl_set_interface_t * mp)
6567 vlib_main_t *vm = vlib_get_main ();
6568 vl_api_input_acl_set_interface_reply_t *rmp;
6570 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6572 ip4_table_index = ntohl (mp->ip4_table_index);
6573 ip6_table_index = ntohl (mp->ip6_table_index);
6574 l2_table_index = ntohl (mp->l2_table_index);
6575 sw_if_index = ntohl (mp->sw_if_index);
6577 VALIDATE_SW_IF_INDEX (mp);
6579 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6580 ip6_table_index, l2_table_index, mp->is_add);
6582 BAD_SW_IF_INDEX_LABEL;
6584 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6587 static void vl_api_ipsec_spd_add_del_t_handler
6588 (vl_api_ipsec_spd_add_del_t * mp)
6591 clib_warning ("unimplemented");
6594 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6595 vl_api_ipsec_spd_add_del_reply_t *rmp;
6599 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6601 rv = VNET_API_ERROR_UNIMPLEMENTED;
6604 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6608 static void vl_api_ipsec_interface_add_del_spd_t_handler
6609 (vl_api_ipsec_interface_add_del_spd_t * mp)
6611 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6612 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6614 u32 sw_if_index __attribute__ ((unused));
6615 u32 spd_id __attribute__ ((unused));
6617 sw_if_index = ntohl (mp->sw_if_index);
6618 spd_id = ntohl (mp->spd_id);
6620 VALIDATE_SW_IF_INDEX (mp);
6623 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6625 rv = VNET_API_ERROR_UNIMPLEMENTED;
6628 BAD_SW_IF_INDEX_LABEL;
6630 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6633 static void vl_api_ipsec_spd_add_del_entry_t_handler
6634 (vl_api_ipsec_spd_add_del_entry_t * mp)
6636 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6637 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6643 memset (&p, 0, sizeof (p));
6645 p.id = ntohl (mp->spd_id);
6646 p.priority = ntohl (mp->priority);
6647 p.is_outbound = mp->is_outbound;
6648 p.is_ipv6 = mp->is_ipv6;
6650 if (mp->is_ipv6 || mp->is_ip_any)
6652 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6653 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6654 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6655 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6659 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6660 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6661 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6662 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6664 p.protocol = mp->protocol;
6665 p.rport.start = ntohs (mp->remote_port_start);
6666 p.rport.stop = ntohs (mp->remote_port_stop);
6667 p.lport.start = ntohs (mp->local_port_start);
6668 p.lport.stop = ntohs (mp->local_port_stop);
6669 /* policy action resolve unsupported */
6670 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6672 clib_warning ("unsupported action: 'resolve'");
6673 rv = VNET_API_ERROR_UNIMPLEMENTED;
6676 p.policy = mp->policy;
6677 p.sa_id = ntohl (mp->sa_id);
6679 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6686 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6689 rv = VNET_API_ERROR_UNIMPLEMENTED;
6694 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6697 static void vl_api_ipsec_sad_add_del_entry_t_handler
6698 (vl_api_ipsec_sad_add_del_entry_t * mp)
6700 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6701 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6706 memset (&sa, 0, sizeof (sa));
6708 sa.id = ntohl (mp->sad_id);
6709 sa.spi = ntohl (mp->spi);
6710 /* security protocol AH unsupported */
6711 if (mp->protocol == IPSEC_PROTOCOL_AH)
6713 clib_warning ("unsupported security protocol 'AH'");
6714 rv = VNET_API_ERROR_UNIMPLEMENTED;
6717 sa.protocol = mp->protocol;
6718 /* check for unsupported crypto-alg */
6719 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6720 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6722 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6723 mp->crypto_algorithm);
6724 rv = VNET_API_ERROR_UNIMPLEMENTED;
6727 sa.crypto_alg = mp->crypto_algorithm;
6728 sa.crypto_key_len = mp->crypto_key_length;
6729 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6730 /* check for unsupported integ-alg */
6731 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6732 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6734 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6735 mp->integrity_algorithm);
6736 rv = VNET_API_ERROR_UNIMPLEMENTED;
6739 sa.integ_alg = mp->integrity_algorithm;
6740 sa.integ_key_len = mp->integrity_key_length;
6741 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6742 sa.use_esn = mp->use_extended_sequence_number;
6743 sa.is_tunnel = mp->is_tunnel;
6744 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6745 if (sa.is_tunnel_ip6)
6747 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6748 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6752 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6753 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6756 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6758 rv = VNET_API_ERROR_UNIMPLEMENTED;
6763 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6767 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6769 vl_api_ikev2_profile_add_del_reply_t *rmp;
6773 vlib_main_t *vm = vlib_get_main ();
6774 clib_error_t *error;
6775 u8 *tmp = format (0, "%s", mp->name);
6776 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6779 rv = VNET_API_ERROR_UNSPECIFIED;
6781 rv = VNET_API_ERROR_UNIMPLEMENTED;
6784 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6788 vl_api_ikev2_profile_set_auth_t_handler
6789 (vl_api_ikev2_profile_set_auth_t * mp)
6791 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6795 vlib_main_t *vm = vlib_get_main ();
6796 clib_error_t *error;
6797 u8 *tmp = format (0, "%s", mp->name);
6798 u8 *data = vec_new (u8, mp->data_len);
6799 clib_memcpy (data, mp->data, mp->data_len);
6800 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6804 rv = VNET_API_ERROR_UNSPECIFIED;
6806 rv = VNET_API_ERROR_UNIMPLEMENTED;
6809 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6813 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6815 vl_api_ikev2_profile_add_del_reply_t *rmp;
6819 vlib_main_t *vm = vlib_get_main ();
6820 clib_error_t *error;
6821 u8 *tmp = format (0, "%s", mp->name);
6822 u8 *data = vec_new (u8, mp->data_len);
6823 clib_memcpy (data, mp->data, mp->data_len);
6824 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6828 rv = VNET_API_ERROR_UNSPECIFIED;
6830 rv = VNET_API_ERROR_UNIMPLEMENTED;
6833 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6837 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6839 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6843 vlib_main_t *vm = vlib_get_main ();
6844 clib_error_t *error;
6845 u8 *tmp = format (0, "%s", mp->name);
6846 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6847 mp->end_port, (ip4_address_t) mp->start_addr,
6848 (ip4_address_t) mp->end_addr, mp->is_local);
6851 rv = VNET_API_ERROR_UNSPECIFIED;
6853 rv = VNET_API_ERROR_UNIMPLEMENTED;
6856 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6860 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6862 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6866 vlib_main_t *vm = vlib_get_main ();
6867 clib_error_t *error;
6869 error = ikev2_set_local_key (vm, mp->key_file);
6871 rv = VNET_API_ERROR_UNSPECIFIED;
6873 rv = VNET_API_ERROR_UNIMPLEMENTED;
6876 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6880 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6882 vl_api_map_add_domain_reply_t *rmp;
6885 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6887 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6888 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6889 (ip6_address_t *) & mp->ip6_src,
6890 mp->ip6_src_prefix_len, mp->ea_bits_len,
6891 mp->psid_offset, mp->psid_length, &index,
6892 ntohs (mp->mtu), flags);
6895 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6897 rmp->index = ntohl(index);
6903 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6905 vl_api_map_del_domain_reply_t *rmp;
6908 rv = map_delete_domain (ntohl (mp->index));
6910 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6914 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6916 vl_api_map_del_domain_reply_t *rmp;
6920 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6921 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6923 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6927 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6929 vl_api_map_domain_details_t *rmp;
6930 map_main_t *mm = &map_main;
6932 unix_shared_memory_queue_t *q;
6934 if (pool_elts (mm->domains) == 0)
6937 q = vl_api_client_index_to_input_queue (mp->client_index);
6944 pool_foreach(d, mm->domains,
6946 /* Make sure every field is initiated (or don't skip the memset()) */
6947 rmp = vl_msg_api_alloc (sizeof (*rmp));
6948 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6949 rmp->domain_index = htonl(d - mm->domains);
6950 rmp->ea_bits_len = d->ea_bits_len;
6951 rmp->psid_offset = d->psid_offset;
6952 rmp->psid_length = d->psid_length;
6953 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6954 rmp->ip4_prefix_len = d->ip4_prefix_len;
6955 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6956 rmp->ip6_prefix_len = d->ip6_prefix_len;
6957 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6958 rmp->ip6_src_len = d->ip6_src_len;
6959 rmp->mtu = htons(d->mtu);
6960 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6961 rmp->context = mp->context;
6963 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6969 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6971 unix_shared_memory_queue_t *q;
6974 vl_api_map_rule_details_t *rmp;
6975 map_main_t *mm = &map_main;
6976 u32 domain_index = ntohl (mp->domain_index);
6979 if (pool_elts (mm->domains) == 0)
6982 d = pool_elt_at_index (mm->domains, domain_index);
6983 if (!d || !d->rules)
6988 q = vl_api_client_index_to_input_queue (mp->client_index);
6994 for (i = 0; i < (0x1 << d->psid_length); i++)
6997 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
7001 rmp = vl_msg_api_alloc (sizeof (*rmp));
7002 memset (rmp, 0, sizeof (*rmp));
7003 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
7004 rmp->psid = htons (i);
7005 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
7006 rmp->context = mp->context;
7007 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7012 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
7014 vl_api_map_summary_stats_reply_t *rmp;
7015 vlib_combined_counter_main_t *cm;
7018 u64 total_pkts[VLIB_N_RX_TX];
7019 u64 total_bytes[VLIB_N_RX_TX];
7020 map_main_t *mm = &map_main;
7021 unix_shared_memory_queue_t *q =
7022 vl_api_client_index_to_input_queue (mp->client_index);
7027 rmp = vl_msg_api_alloc (sizeof (*rmp));
7028 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
7029 rmp->context = mp->context;
7032 memset (total_pkts, 0, sizeof (total_pkts));
7033 memset (total_bytes, 0, sizeof (total_bytes));
7035 map_domain_counter_lock (mm);
7036 vec_foreach (cm, mm->domain_counters)
7038 which = cm - mm->domain_counters;
7040 for (i = 0; i < vec_len (cm->maxi); i++)
7042 vlib_get_combined_counter (cm, i, &v);
7043 total_pkts[which] += v.packets;
7044 total_bytes[which] += v.bytes;
7048 map_domain_counter_unlock (mm);
7050 /* Note: in network byte order! */
7051 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
7052 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
7053 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
7054 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
7055 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
7056 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
7057 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
7058 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
7059 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
7060 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
7061 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
7062 clib_host_to_net_u64 (map_error_counter_get
7063 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
7064 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
7065 clib_host_to_net_u64 (map_error_counter_get
7066 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
7068 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7072 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
7074 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
7075 vl_api_ipsec_sa_set_key_reply_t *rmp;
7079 sa.id = ntohl (mp->sa_id);
7080 sa.crypto_key_len = mp->crypto_key_length;
7081 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
7082 sa.integ_key_len = mp->integrity_key_length;
7083 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
7085 rv = ipsec_set_sa_key (vm, &sa);
7087 rv = VNET_API_ERROR_UNIMPLEMENTED;
7090 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
7093 static void vl_api_cop_interface_enable_disable_t_handler
7094 (vl_api_cop_interface_enable_disable_t * mp)
7096 vl_api_cop_interface_enable_disable_reply_t *rmp;
7098 u32 sw_if_index = ntohl (mp->sw_if_index);
7101 VALIDATE_SW_IF_INDEX (mp);
7103 enable_disable = (int) mp->enable_disable;
7105 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
7107 BAD_SW_IF_INDEX_LABEL;
7109 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
7112 static void vl_api_cop_whitelist_enable_disable_t_handler
7113 (vl_api_cop_whitelist_enable_disable_t * mp)
7115 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
7116 cop_whitelist_enable_disable_args_t _a, *a = &_a;
7117 u32 sw_if_index = ntohl (mp->sw_if_index);
7120 VALIDATE_SW_IF_INDEX (mp);
7122 a->sw_if_index = sw_if_index;
7125 a->default_cop = mp->default_cop;
7126 a->fib_id = ntohl (mp->fib_id);
7128 rv = cop_whitelist_enable_disable (a);
7130 BAD_SW_IF_INDEX_LABEL;
7132 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
7136 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
7140 api_main_t *am = &api_main;
7141 vlib_main_t *vm = vlib_get_main ();
7143 vl_api_get_node_graph_reply_t *rmp;
7145 pthread_mutex_lock (&am->vlib_rp->mutex);
7146 oldheap = svm_push_data_heap (am->vlib_rp);
7149 * Keep the number of memcpy ops to a minimum (e.g. 1).
7151 vec_validate (vector, 16384);
7152 vec_reset_length (vector);
7155 vector = vlib_node_serialize (&vm->node_main, vector,
7156 (u32) ~ 0 /* all threads */ ,
7157 1 /* include nexts */ ,
7158 1 /* include stats */ );
7160 svm_pop_heap (oldheap);
7161 pthread_mutex_unlock (&am->vlib_rp->mutex);
7164 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
7166 rmp->reply_in_shmem = (uword) vector;
7172 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
7175 vl_api_ioam_enable_reply_t *rmp;
7176 clib_error_t *error;
7178 /* Ignoring the profile id as currently a single profile
7180 error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable,
7181 mp->seqno, mp->analyse);
7184 clib_error_report (error);
7185 rv = clib_error_get_code (error);
7188 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
7192 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
7195 vl_api_ioam_disable_reply_t *rmp;
7196 clib_error_t *error;
7198 error = clear_ioam_rewrite_fn ();
7201 clib_error_report (error);
7202 rv = clib_error_get_code (error);
7205 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
7209 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7211 vlib_main_t *vm = vlib_get_main ();
7212 vl_api_af_packet_create_reply_t *rmp;
7214 u8 *host_if_name = NULL;
7217 host_if_name = format (0, "%s", mp->host_if_name);
7218 vec_add1 (host_if_name, 0);
7220 rv = af_packet_create_if (vm, host_if_name,
7221 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7224 vec_free (host_if_name);
7227 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7229 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7235 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7237 vlib_main_t *vm = vlib_get_main ();
7238 vl_api_af_packet_delete_reply_t *rmp;
7240 u8 *host_if_name = NULL;
7242 host_if_name = format (0, "%s", mp->host_if_name);
7243 vec_add1 (host_if_name, 0);
7245 rv = af_packet_delete_if (vm, host_if_name);
7247 vec_free (host_if_name);
7249 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7253 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7255 vlib_main_t *vm = vlib_get_main ();
7256 vl_api_policer_add_del_reply_t *rmp;
7259 sse2_qos_pol_cfg_params_st cfg;
7260 clib_error_t *error;
7263 name = format (0, "%s", mp->name);
7265 memset (&cfg, 0, sizeof (cfg));
7267 cfg.rnd_type = mp->round_type;
7268 cfg.rate_type = mp->rate_type;
7269 cfg.rb.kbps.cir_kbps = mp->cir;
7270 cfg.rb.kbps.eir_kbps = mp->eir;
7271 cfg.rb.kbps.cb_bytes = mp->cb;
7272 cfg.rb.kbps.eb_bytes = mp->eb;
7273 cfg.conform_action.action_type = mp->conform_action_type;
7274 cfg.conform_action.dscp = mp->conform_dscp;
7275 cfg.exceed_action.action_type = mp->exceed_action_type;
7276 cfg.exceed_action.dscp = mp->exceed_dscp;
7277 cfg.violate_action.action_type = mp->violate_action_type;
7278 cfg.violate_action.dscp = mp->violate_dscp;
7279 cfg.color_aware = mp->color_aware;
7281 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7284 rv = VNET_API_ERROR_UNSPECIFIED;
7287 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7289 if (rv == 0 && mp->is_add)
7290 rmp->policer_index = ntohl(policer_index);
7292 rmp->policer_index = ~0;
7298 send_policer_details (u8 * name,
7299 sse2_qos_pol_cfg_params_st * config,
7300 policer_read_response_type_st * templ,
7301 unix_shared_memory_queue_t * q, u32 context)
7303 vl_api_policer_details_t *mp;
7305 mp = vl_msg_api_alloc (sizeof (*mp));
7306 memset (mp, 0, sizeof (*mp));
7307 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7308 mp->context = context;
7309 mp->cir = htonl (config->rb.kbps.cir_kbps);
7310 mp->eir = htonl (config->rb.kbps.eir_kbps);
7311 mp->cb = htonl (config->rb.kbps.cb_bytes);
7312 mp->eb = htonl (config->rb.kbps.eb_bytes);
7313 mp->rate_type = config->rate_type;
7314 mp->round_type = config->rnd_type;
7315 mp->type = config->rfc;
7316 mp->conform_action_type = config->conform_action.action_type;
7317 mp->conform_dscp = config->conform_action.dscp;
7318 mp->exceed_action_type = config->exceed_action.action_type;
7319 mp->exceed_dscp = config->exceed_action.dscp;
7320 mp->violate_action_type = config->violate_action.action_type;
7321 mp->violate_dscp = config->violate_action.dscp;
7322 mp->single_rate = templ->single_rate ? 1 : 0;
7323 mp->color_aware = templ->color_aware ? 1 : 0;
7324 mp->scale = htonl (templ->scale);
7325 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7326 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7327 mp->current_limit = htonl (templ->current_limit);
7328 mp->current_bucket = htonl (templ->current_bucket);
7329 mp->extended_limit = htonl (templ->extended_limit);
7330 mp->extended_bucket = htonl (templ->extended_bucket);
7331 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7333 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7335 vl_msg_api_send_shmem (q, (u8 *) & mp);
7339 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7341 unix_shared_memory_queue_t *q;
7342 vnet_policer_main_t *pm = &vnet_policer_main;
7348 sse2_qos_pol_cfg_params_st *config;
7349 policer_read_response_type_st *templ;
7351 q = vl_api_client_index_to_input_queue (mp->client_index);
7355 if (mp->match_name_valid)
7357 match_name = format (0, "%s%c", mp->match_name, 0);
7360 if (mp->match_name_valid)
7362 p = hash_get_mem (pm->policer_config_by_name, match_name);
7366 config = pool_elt_at_index (pm->configs, pool_index);
7367 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7368 send_policer_details (match_name, config, templ, q, mp->context);
7374 hash_foreach_pair (hp, pm->policer_config_by_name,
7376 name = (u8 *) hp->key;
7377 pool_index = hp->value[0];
7378 config = pool_elt_at_index (pm->configs, pool_index);
7379 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7380 send_policer_details(name, config, templ, q, mp->context);
7387 vl_api_policer_classify_set_interface_t_handler
7388 (vl_api_policer_classify_set_interface_t * mp)
7390 vlib_main_t *vm = vlib_get_main ();
7391 vl_api_policer_classify_set_interface_reply_t *rmp;
7393 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7395 ip4_table_index = ntohl (mp->ip4_table_index);
7396 ip6_table_index = ntohl (mp->ip6_table_index);
7397 l2_table_index = ntohl (mp->l2_table_index);
7398 sw_if_index = ntohl (mp->sw_if_index);
7400 VALIDATE_SW_IF_INDEX (mp);
7402 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7403 ip6_table_index, l2_table_index,
7406 BAD_SW_IF_INDEX_LABEL;
7408 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7412 send_policer_classify_details (u32 sw_if_index,
7414 unix_shared_memory_queue_t * q, u32 context)
7416 vl_api_policer_classify_details_t *mp;
7418 mp = vl_msg_api_alloc (sizeof (*mp));
7419 memset (mp, 0, sizeof (*mp));
7420 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7421 mp->context = context;
7422 mp->sw_if_index = htonl (sw_if_index);
7423 mp->table_index = htonl (table_index);
7425 vl_msg_api_send_shmem (q, (u8 *) & mp);
7429 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7431 unix_shared_memory_queue_t *q;
7432 policer_classify_main_t *pcm = &policer_classify_main;
7436 q = vl_api_client_index_to_input_queue (mp->client_index);
7440 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7442 if (vec_len (vec_tbl))
7444 for (i = 0; i < vec_len (vec_tbl); i++)
7446 if (vec_elt (vec_tbl, i) == ~0)
7449 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7456 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7458 vlib_main_t *vm = vlib_get_main ();
7459 vl_api_netmap_create_reply_t *rmp;
7463 if_name = format (0, "%s", mp->netmap_if_name);
7464 vec_add1 (if_name, 0);
7467 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7468 mp->is_pipe, mp->is_master, 0);
7472 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7476 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7478 vlib_main_t *vm = vlib_get_main ();
7479 vl_api_netmap_delete_reply_t *rmp;
7483 if_name = format (0, "%s", mp->netmap_if_name);
7484 vec_add1 (if_name, 0);
7486 rv = netmap_delete_if (vm, if_name);
7490 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7494 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7497 clib_warning ("BUG");
7501 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7502 unix_shared_memory_queue_t * q,
7503 mpls_eth_tunnel_t * et, u32 index, u32 context)
7505 mpls_main_t *mm = &mpls_main;
7509 vl_api_mpls_eth_tunnel_details_t *mp;
7511 e = pool_elt_at_index (mm->encaps, et->encap_index);
7512 nlabels = vec_len (e->labels);
7514 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7515 memset (mp, 0, sizeof (*mp));
7516 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7517 mp->context = context;
7519 mp->tunnel_index = htonl (index);
7520 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7521 mp->intfc_address = et->intfc_address.as_u32;
7522 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7523 mp->inner_fib_index = htonl (et->inner_fib_index);
7524 mp->mask_width = htonl (et->mask_width);
7525 mp->encap_index = htonl (et->encap_index);
7526 mp->hw_if_index = htonl (et->hw_if_index);
7527 mp->l2_only = htonl (et->l2_only);
7528 mp->nlabels = htonl (nlabels);
7530 for (i = 0; i < nlabels; i++)
7533 htonl (vnet_mpls_uc_get_label
7534 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7537 vl_msg_api_send_shmem (q, (u8 *) & mp);
7541 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7543 vpe_api_main_t *am = &vpe_api_main;
7544 unix_shared_memory_queue_t *q;
7545 mpls_main_t *mm = &mpls_main;
7546 mpls_eth_tunnel_t *et;
7547 u32 index = ntohl (mp->tunnel_index);
7549 q = vl_api_client_index_to_input_queue (mp->client_index);
7555 if (!pool_is_free_index (mm->eth_tunnels, index))
7557 et = pool_elt_at_index (mm->eth_tunnels, index);
7558 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7565 pool_foreach (et, mm->eth_tunnels,
7567 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7575 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
7577 clib_warning ("BUG");
7581 send_mpls_fib_details (vpe_api_main_t * am,
7582 unix_shared_memory_queue_t * q,
7583 u32 table_id, u32 label, u32 eos, u32 context)
7585 vl_api_mpls_fib_details_t *mp;
7587 mp = vl_msg_api_alloc (sizeof (*mp));
7588 memset (mp, 0, sizeof (*mp));
7589 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
7590 mp->context = context;
7592 mp->table_id = htonl (table_id);
7594 mp->label = htonl (label);
7596 vl_msg_api_send_shmem (q, (u8 *) & mp);
7600 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
7602 vpe_api_main_t *am = &vpe_api_main;
7603 unix_shared_memory_queue_t *q;
7604 mpls_main_t *mm = &mpls_main;
7605 fib_table_t *fib_table;
7606 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
7611 q = vl_api_client_index_to_input_queue (mp->client_index);
7616 pool_foreach (fib_table, mm->fibs,
7618 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
7620 vec_add1(lfeis, lfei);
7623 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
7625 vec_foreach(lfeip, lfeis)
7627 fib_entry_get_prefix(*lfeip, &pfx);
7628 fib_index = fib_entry_get_fib_index(*lfeip);
7630 fib_table = fib_table_get(fib_index, pfx.fp_proto);
7632 send_mpls_fib_details (am, q,
7633 fib_table->ft_table_id,
7643 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7645 clib_warning ("BUG");
7649 send_mpls_fib_encap_details (vpe_api_main_t * am,
7650 unix_shared_memory_queue_t * q,
7651 show_mpls_fib_t * s, u32 context)
7653 vl_api_mpls_fib_encap_details_t *mp;
7654 mpls_main_t *mm = &mpls_main;
7659 e = pool_elt_at_index (mm->encaps, s->entry_index);
7660 nlabels = vec_len (e->labels);
7662 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7663 memset (mp, 0, sizeof (*mp));
7664 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7665 mp->context = context;
7667 mp->fib_index = htonl (s->fib_index);
7668 mp->entry_index = htonl (s->entry_index);
7670 mp->s_bit = htonl (s->s_bit);
7672 mp->nlabels = htonl (nlabels);
7674 for (i = 0; i < nlabels; i++)
7677 htonl (vnet_mpls_uc_get_label
7678 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7681 vl_msg_api_send_shmem (q, (u8 *) & mp);
7685 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7687 vpe_api_main_t *am = &vpe_api_main;
7688 unix_shared_memory_queue_t *q;
7689 vlib_main_t *vm = &vlib_global_main;
7692 show_mpls_fib_t *records = 0;
7694 mpls_main_t *mm = &mpls_main;
7697 q = vl_api_client_index_to_input_queue (mp->client_index);
7702 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7704 vec_add2 (records, s, 1);
7705 s->fib_index = (u32)(key>>32);
7706 s->dest = (u32)(key & 0xFFFFFFFF);
7707 s->entry_index = (u32) value;
7711 if (0 == vec_len (records))
7713 vlib_cli_output (vm, "MPLS encap table empty");
7717 /* sort output by dst address within fib */
7718 vec_sort_with_function (records, mpls_dest_cmp);
7719 vec_sort_with_function (records, mpls_fib_index_cmp);
7720 vlib_cli_output (vm, "MPLS encap table");
7721 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7722 vec_foreach (s, records)
7724 rx_fib = ip4_fib_get (s->fib_index);
7725 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7726 format_ip4_address, &s->dest, format_mpls_encap_index,
7727 mm, s->entry_index);
7728 send_mpls_fib_encap_details (am, q, s, mp->context);
7736 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7738 unix_shared_memory_queue_t *q;
7740 q = vl_api_client_index_to_input_queue (mp->client_index);
7744 vnet_classify_main_t *cm = &vnet_classify_main;
7745 vnet_classify_table_t *t;
7750 pool_foreach (t, cm->tables,
7752 vec_add1 (table_ids, ntohl(t - cm->tables));
7755 count = vec_len (table_ids);
7757 vl_api_classify_table_ids_reply_t *rmp;
7758 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7759 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7760 rmp->context = mp->context;
7761 rmp->count = ntohl (count);
7762 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7765 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7767 vec_free (table_ids);
7771 vl_api_classify_table_by_interface_t_handler
7772 (vl_api_classify_table_by_interface_t * mp)
7774 vl_api_classify_table_by_interface_reply_t *rmp;
7777 u32 sw_if_index = ntohl (mp->sw_if_index);
7780 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7783 VALIDATE_SW_IF_INDEX (mp);
7785 input_acl_main_t *am = &input_acl_main;
7790 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7792 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7793 if (vec_len (vec_tbl))
7795 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7797 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7801 acl[type] = vec_elt (vec_tbl, if_idx);
7806 BAD_SW_IF_INDEX_LABEL;
7809 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7811 rmp->sw_if_index = ntohl(sw_if_index);
7812 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7813 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7814 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7821 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7823 unix_shared_memory_queue_t *q;
7825 q = vl_api_client_index_to_input_queue (mp->client_index);
7829 vl_api_classify_table_info_reply_t *rmp = 0;
7831 vnet_classify_main_t *cm = &vnet_classify_main;
7832 u32 table_id = ntohl (mp->table_id);
7833 vnet_classify_table_t *t;
7836 pool_foreach (t, cm->tables,
7838 if (table_id == t - cm->tables)
7840 rmp = vl_msg_api_alloc_as_if_client
7841 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7842 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7843 rmp->context = mp->context;
7844 rmp->table_id = ntohl(table_id);
7845 rmp->nbuckets = ntohl(t->nbuckets);
7846 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7847 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7848 rmp->active_sessions = ntohl(t->active_elements);
7849 rmp->next_table_index = ntohl(t->next_table_index);
7850 rmp->miss_next_index = ntohl(t->miss_next_index);
7851 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7852 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7861 rmp = vl_msg_api_alloc (sizeof (*rmp));
7862 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7863 rmp->context = mp->context;
7864 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7867 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7871 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7874 clib_warning ("BUG");
7878 send_classify_session_details (unix_shared_memory_queue_t * q,
7881 vnet_classify_entry_t * e, u32 context)
7883 vl_api_classify_session_details_t *rmp;
7885 rmp = vl_msg_api_alloc (sizeof (*rmp));
7886 memset (rmp, 0, sizeof (*rmp));
7887 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7888 rmp->context = context;
7889 rmp->table_id = ntohl (table_id);
7890 rmp->hit_next_index = ntohl (e->next_index);
7891 rmp->advance = ntohl (e->advance);
7892 rmp->opaque_index = ntohl (e->opaque_index);
7893 rmp->match_length = ntohl (match_length);
7894 clib_memcpy (rmp->match, e->key, match_length);
7896 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7900 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7902 vnet_classify_main_t *cm = &vnet_classify_main;
7903 unix_shared_memory_queue_t *q;
7905 u32 table_id = ntohl (mp->table_id);
7906 vnet_classify_table_t *t;
7908 q = vl_api_client_index_to_input_queue (mp->client_index);
7913 pool_foreach (t, cm->tables,
7915 if (table_id == t - cm->tables)
7917 vnet_classify_bucket_t * b;
7918 vnet_classify_entry_t * v, * save_v;
7921 for (i = 0; i < t->nbuckets; i++)
7923 b = &t->buckets [i];
7927 save_v = vnet_classify_get_entry (t, b->offset);
7928 for (j = 0; j < (1<<b->log2_pages); j++)
7930 for (k = 0; k < t->entries_per_page; k++)
7932 v = vnet_classify_entry_at_index
7933 (t, save_v, j*t->entries_per_page + k);
7934 if (vnet_classify_entry_is_free (v))
7937 send_classify_session_details
7938 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7950 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7952 vlib_main_t *vm = vlib_get_main ();
7953 flow_report_main_t *frm = &flow_report_main;
7954 vl_api_set_ipfix_exporter_reply_t *rmp;
7955 ip4_address_t collector, src;
7956 u16 collector_port = UDP_DST_PORT_ipfix;
7958 u32 template_interval;
7964 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7965 collector_port = ntohs (mp->collector_port);
7966 if (collector_port == (u16) ~ 0)
7967 collector_port = UDP_DST_PORT_ipfix;
7968 memcpy (src.data, mp->src_address, sizeof (src.data));
7969 fib_id = ntohl (mp->vrf_id);
7971 ip4_main_t *im = &ip4_main;
7978 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7981 rv = VNET_API_ERROR_NO_SUCH_FIB;
7987 path_mtu = ntohl (mp->path_mtu);
7989 path_mtu = 512; // RFC 7011 section 10.3.3.
7990 template_interval = ntohl (mp->template_interval);
7991 if (template_interval == ~0)
7992 template_interval = 20;
7993 udp_checksum = mp->udp_checksum;
7995 if (collector.as_u32 == 0)
7997 rv = VNET_API_ERROR_INVALID_VALUE;
8001 if (src.as_u32 == 0)
8003 rv = VNET_API_ERROR_INVALID_VALUE;
8007 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
8009 rv = VNET_API_ERROR_INVALID_VALUE;
8015 rv = VNET_API_ERROR_INVALID_VALUE;
8019 /* Reset report streams if we are reconfiguring IP addresses */
8020 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
8021 frm->src_address.as_u32 != src.as_u32 ||
8022 frm->collector_port != collector_port)
8023 vnet_flow_reports_reset (frm);
8025 frm->ipfix_collector.as_u32 = collector.as_u32;
8026 frm->collector_port = collector_port;
8027 frm->src_address.as_u32 = src.as_u32;
8028 frm->fib_index = fib_index;
8029 frm->path_mtu = path_mtu;
8030 frm->template_interval = template_interval;
8031 frm->udp_checksum = udp_checksum;
8033 /* Turn on the flow reporting process */
8034 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
8037 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
8041 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
8043 flow_report_main_t *frm = &flow_report_main;
8044 unix_shared_memory_queue_t *q;
8045 vl_api_ipfix_exporter_details_t *rmp;
8046 ip4_main_t *im = &ip4_main;
8049 q = vl_api_client_index_to_input_queue (mp->client_index);
8053 rmp = vl_msg_api_alloc (sizeof (*rmp));
8054 memset (rmp, 0, sizeof (*rmp));
8055 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
8056 rmp->context = mp->context;
8057 memcpy (rmp->collector_address, frm->ipfix_collector.data,
8058 sizeof (frm->ipfix_collector.data));
8059 rmp->collector_port = htons (frm->collector_port);
8060 memcpy (rmp->src_address, frm->src_address.data,
8061 sizeof (frm->src_address.data));
8062 if (frm->fib_index == ~0)
8065 vrf_id = im->fibs[frm->fib_index].ft_table_id;
8066 rmp->vrf_id = htonl (vrf_id);
8067 rmp->path_mtu = htonl (frm->path_mtu);
8068 rmp->template_interval = htonl (frm->template_interval);
8069 rmp->udp_checksum = (frm->udp_checksum != 0);
8071 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8075 vl_api_set_ipfix_classify_stream_t_handler
8076 (vl_api_set_ipfix_classify_stream_t * mp)
8078 vl_api_set_ipfix_classify_stream_reply_t *rmp;
8079 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8080 flow_report_main_t *frm = &flow_report_main;
8082 u32 src_port = UDP_DST_PORT_ipfix;
8085 domain_id = ntohl (mp->domain_id);
8086 src_port = ntohs (mp->src_port);
8088 if (fcm->src_port != 0 &&
8089 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
8091 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
8092 domain_id, (u16) src_port);
8096 fcm->domain_id = domain_id;
8097 fcm->src_port = (u16) src_port;
8099 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8103 vl_api_ipfix_classify_stream_dump_t_handler
8104 (vl_api_ipfix_classify_stream_dump_t * mp)
8106 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8107 unix_shared_memory_queue_t *q;
8108 vl_api_ipfix_classify_stream_details_t *rmp;
8110 q = vl_api_client_index_to_input_queue (mp->client_index);
8114 rmp = vl_msg_api_alloc (sizeof (*rmp));
8115 memset (rmp, 0, sizeof (*rmp));
8116 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
8117 rmp->context = mp->context;
8118 rmp->domain_id = htonl (fcm->domain_id);
8119 rmp->src_port = htons (fcm->src_port);
8121 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8125 vl_api_ipfix_classify_table_add_del_t_handler
8126 (vl_api_ipfix_classify_table_add_del_t * mp)
8128 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
8129 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8130 flow_report_main_t *frm = &flow_report_main;
8131 vnet_flow_report_add_del_args_t args;
8132 ipfix_classify_table_t *table;
8134 u32 classify_table_index;
8136 u8 transport_protocol;
8139 classify_table_index = ntohl (mp->table_id);
8140 ip_version = mp->ip_version;
8141 transport_protocol = mp->transport_protocol;
8142 is_add = mp->is_add;
8144 if (fcm->src_port == 0)
8146 /* call set_ipfix_classify_stream first */
8147 rv = VNET_API_ERROR_UNSPECIFIED;
8151 memset (&args, 0, sizeof (args));
8155 for (i = 0; i < vec_len (fcm->tables); i++)
8156 if (ipfix_classify_table_index_valid (i))
8157 if (fcm->tables[i].classify_table_index == classify_table_index)
8159 table = &fcm->tables[i];
8167 rv = VNET_API_ERROR_VALUE_EXIST;
8170 table = ipfix_classify_add_table ();
8171 table->classify_table_index = classify_table_index;
8177 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
8182 table->ip_version = ip_version;
8183 table->transport_protocol = transport_protocol;
8185 args.opaque.as_uword = table - fcm->tables;
8186 args.rewrite_callback = ipfix_classify_template_rewrite;
8187 args.flow_data_callback = ipfix_classify_send_flows;
8188 args.is_add = is_add;
8189 args.domain_id = fcm->domain_id;
8190 args.src_port = fcm->src_port;
8192 rv = vnet_flow_report_add_del (frm, &args);
8194 /* If deleting, or add failed */
8195 if (is_add == 0 || (rv && is_add))
8196 ipfix_classify_delete_table (table - fcm->tables);
8199 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8203 send_ipfix_classify_table_details (u32 table_index,
8204 unix_shared_memory_queue_t * q,
8207 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8208 vl_api_ipfix_classify_table_details_t *mp;
8210 ipfix_classify_table_t *table = &fcm->tables[table_index];
8212 mp = vl_msg_api_alloc (sizeof (*mp));
8213 memset (mp, 0, sizeof (*mp));
8214 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
8215 mp->context = context;
8216 mp->table_id = htonl (table->classify_table_index);
8217 mp->ip_version = table->ip_version;
8218 mp->transport_protocol = table->transport_protocol;
8220 vl_msg_api_send_shmem (q, (u8 *) & mp);
8224 vl_api_ipfix_classify_table_dump_t_handler
8225 (vl_api_ipfix_classify_table_dump_t * mp)
8227 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8228 unix_shared_memory_queue_t *q;
8231 q = vl_api_client_index_to_input_queue (mp->client_index);
8235 for (i = 0; i < vec_len (fcm->tables); i++)
8236 if (ipfix_classify_table_index_valid (i))
8237 send_ipfix_classify_table_details (i, q, mp->context);
8241 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8243 vl_api_pg_create_interface_reply_t *rmp;
8246 pg_main_t *pg = &pg_main;
8247 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8248 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
8251 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8253 rmp->sw_if_index = ntohl(pi->sw_if_index);
8259 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8261 vl_api_pg_capture_reply_t *rmp;
8264 vnet_main_t *vnm = vnet_get_main ();
8265 vnet_interface_main_t *im = &vnm->interface_main;
8266 vnet_hw_interface_t *hi = 0;
8268 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8269 u32 hw_if_index = ~0;
8270 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8273 vec_free (intf_name);
8275 if (hw_if_index != ~0)
8277 pg_capture_args_t _a, *a = &_a;
8279 u32 len = ntohl (mp->pcap_name_length);
8280 u8 *pcap_file_name = vec_new (u8, len);
8281 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8283 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8284 a->hw_if_index = hw_if_index;
8285 a->dev_instance = hi->dev_instance;
8286 a->is_enabled = mp->is_enabled;
8287 a->pcap_file_name = pcap_file_name;
8288 a->count = ntohl (mp->count);
8290 clib_error_t *e = pg_capture (a);
8293 clib_error_report (e);
8294 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8297 vec_free (pcap_file_name);
8299 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8303 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8305 vl_api_pg_enable_disable_reply_t *rmp;
8308 pg_main_t *pg = &pg_main;
8309 u32 stream_index = ~0;
8311 int is_enable = mp->is_enabled != 0;
8312 u32 len = ntohl (mp->stream_name_length) - 1;
8316 u8 *stream_name = vec_new (u8, len);
8317 clib_memcpy (stream_name, mp->stream_name, len);
8318 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8321 vec_free (stream_name);
8324 pg_enable_disable (stream_index, is_enable);
8326 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8330 vl_api_ip_source_and_port_range_check_add_del_t_handler
8331 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8333 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8336 u8 is_ipv6 = mp->is_ipv6;
8337 u8 is_add = mp->is_add;
8338 u8 mask_length = mp->mask_length;
8339 ip4_address_t ip4_addr;
8340 ip6_address_t ip6_addr;
8342 u16 *high_ports = 0;
8344 u16 tmp_low, tmp_high;
8348 // Validate port range
8349 num_ranges = mp->number_of_ranges;
8350 if (num_ranges > 32)
8351 { // This is size of array in VPE.API
8352 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8356 vec_reset_length (low_ports);
8357 vec_reset_length (high_ports);
8359 for (i = 0; i < num_ranges; i++)
8361 tmp_low = mp->low_ports[i];
8362 tmp_high = mp->high_ports[i];
8363 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8364 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8365 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8367 rv = VNET_API_ERROR_INVALID_VALUE;
8370 vec_add1 (low_ports, tmp_low);
8371 vec_add1 (high_ports, tmp_high + 1);
8374 // Validate mask_length
8375 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8377 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8381 vrf_id = ntohl (mp->vrf_id);
8385 rv = VNET_API_ERROR_INVALID_VALUE;
8392 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8393 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8397 high_ports, is_add);
8401 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8402 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8406 high_ports, is_add);
8410 vec_free (low_ports);
8411 vec_free (high_ports);
8412 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8416 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8417 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8419 vlib_main_t *vm = vlib_get_main ();
8420 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8421 ip4_main_t *im = &ip4_main;
8424 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8425 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8429 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8430 ntohl (mp->tcp_out_vrf_id);
8431 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8432 ntohl (mp->udp_out_vrf_id);
8433 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8434 ntohl (mp->tcp_in_vrf_id);
8435 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8436 ntohl (mp->udp_in_vrf_id);
8439 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8441 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8443 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8447 rv = VNET_API_ERROR_INVALID_VALUE;
8451 fib_index[i] = p[0];
8456 sw_if_index = ntohl (mp->sw_if_index);
8458 VALIDATE_SW_IF_INDEX (mp);
8461 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8464 BAD_SW_IF_INDEX_LABEL;
8467 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8471 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8474 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8476 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8477 u32 sw_if_index = ~0;
8479 /* Check src & dst are different */
8480 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8482 rv = VNET_API_ERROR_SAME_SRC_DST;
8486 memset (a, 0, sizeof (*a));
8488 /* ip addresses sent in network byte order */
8489 clib_memcpy (&(a->src), mp->src_address, 4);
8490 clib_memcpy (&(a->dst), mp->dst_address, 4);
8491 a->is_add = mp->is_add;
8492 a->lsa = ntohl (mp->local_sa_id);
8493 a->rsa = ntohl (mp->remote_sa_id);
8495 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8499 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8501 rmp->sw_if_index = ntohl (sw_if_index);
8506 static void send_ipsec_gre_tunnel_details
8507 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8509 vl_api_ipsec_gre_tunnel_details_t *rmp;
8511 rmp = vl_msg_api_alloc (sizeof (*rmp));
8512 memset (rmp, 0, sizeof (*rmp));
8513 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8514 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8515 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8516 rmp->sw_if_index = htonl (t->sw_if_index);
8517 rmp->local_sa_id = htonl (t->local_sa_id);
8518 rmp->remote_sa_id = htonl (t->remote_sa_id);
8519 rmp->context = context;
8521 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8524 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8525 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8527 unix_shared_memory_queue_t *q;
8528 ipsec_gre_main_t *igm = &ipsec_gre_main;
8529 ipsec_gre_tunnel_t *t;
8532 q = vl_api_client_index_to_input_queue (mp->client_index);
8538 sw_if_index = ntohl (mp->sw_if_index);
8540 if (~0 == sw_if_index)
8543 pool_foreach (t, igm->tunnels,
8545 send_ipsec_gre_tunnel_details(t, q, mp->context);
8551 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8552 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8556 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8557 send_ipsec_gre_tunnel_details (t, q, mp->context);
8562 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8564 vl_api_delete_subif_reply_t *rmp;
8567 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8569 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8573 vl_api_l2_interface_pbb_tag_rewrite_t_handler
8574 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
8576 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
8577 vnet_main_t *vnm = vnet_get_main ();
8578 vlib_main_t *vm = vlib_get_main ();
8582 VALIDATE_SW_IF_INDEX (mp);
8584 vtr_op = ntohl (mp->vtr_op);
8588 case L2_VTR_DISABLED:
8591 case L2_VTR_TRANSLATE_2_1:
8595 rv = VNET_API_ERROR_INVALID_VALUE;
8596 goto bad_sw_if_index;
8599 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
8600 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
8601 ntohl (mp->i_sid), ntohs (mp->outer_tag));
8603 BAD_SW_IF_INDEX_LABEL;
8605 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
8609 vl_api_punt_t_handler (vl_api_punt_t * mp)
8611 vl_api_punt_reply_t *rmp;
8612 vlib_main_t *vm = vlib_get_main ();
8614 clib_error_t *error;
8616 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8617 ntohs (mp->l4_port), mp->is_add);
8621 clib_error_report (error);
8624 REPLY_MACRO (VL_API_PUNT_REPLY);
8628 vl_api_flow_classify_set_interface_t_handler
8629 (vl_api_flow_classify_set_interface_t * mp)
8631 vlib_main_t *vm = vlib_get_main ();
8632 vl_api_flow_classify_set_interface_reply_t *rmp;
8634 u32 sw_if_index, ip4_table_index, ip6_table_index;
8636 ip4_table_index = ntohl (mp->ip4_table_index);
8637 ip6_table_index = ntohl (mp->ip6_table_index);
8638 sw_if_index = ntohl (mp->sw_if_index);
8640 VALIDATE_SW_IF_INDEX (mp);
8642 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
8643 ip6_table_index, mp->is_add);
8645 BAD_SW_IF_INDEX_LABEL;
8647 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
8651 send_flow_classify_details (u32 sw_if_index,
8653 unix_shared_memory_queue_t * q, u32 context)
8655 vl_api_flow_classify_details_t *mp;
8657 mp = vl_msg_api_alloc (sizeof (*mp));
8658 memset (mp, 0, sizeof (*mp));
8659 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
8660 mp->context = context;
8661 mp->sw_if_index = htonl (sw_if_index);
8662 mp->table_index = htonl (table_index);
8664 vl_msg_api_send_shmem (q, (u8 *) & mp);
8668 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8670 unix_shared_memory_queue_t *q;
8671 flow_classify_main_t *pcm = &flow_classify_main;
8675 q = vl_api_client_index_to_input_queue (mp->client_index);
8679 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8681 if (vec_len (vec_tbl))
8683 for (i = 0; i < vec_len (vec_tbl); i++)
8685 if (vec_elt (vec_tbl, i) == ~0)
8688 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8695 send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
8698 vl_api_ipsec_spd_details_t *mp;
8700 mp = vl_msg_api_alloc (sizeof (*mp));
8701 memset (mp, 0, sizeof (*mp));
8702 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
8703 mp->context = context;
8705 mp->spd_id = htonl (p->id);
8706 mp->priority = htonl (p->priority);
8707 mp->is_outbound = p->is_outbound;
8708 mp->is_ipv6 = p->is_ipv6;
8711 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
8712 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
8713 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
8714 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
8718 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
8719 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
8720 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
8721 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
8723 mp->local_start_port = htons (p->lport.start);
8724 mp->local_stop_port = htons (p->lport.stop);
8725 mp->remote_start_port = htons (p->rport.start);
8726 mp->remote_stop_port = htons (p->rport.stop);
8727 mp->protocol = p->protocol;
8728 mp->policy = p->policy;
8729 mp->sa_id = htonl (p->sa_id);
8730 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
8731 mp->packets = clib_host_to_net_u64 (p->counter.packets);
8733 vl_msg_api_send_shmem (q, (u8 *) & mp);
8737 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
8739 unix_shared_memory_queue_t *q;
8740 ipsec_main_t *im = &ipsec_main;
8741 ipsec_policy_t *policy;
8746 q = vl_api_client_index_to_input_queue (mp->client_index);
8750 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
8755 spd = pool_elt_at_index (im->spds, spd_index);
8757 pool_foreach (policy, spd->policies, (
8759 if (mp->sa_id == ~(0)
8760 || ntohl (mp->sa_id) ==
8762 send_ipsec_spd_details (policy, q,
8766 clib_warning ("unimplemented");
8770 #define BOUNCE_HANDLER(nn) \
8771 static void vl_api_##nn##_t_handler ( \
8772 vl_api_##nn##_t *mp) \
8774 vpe_client_registration_t *reg; \
8775 vpe_api_main_t * vam = &vpe_api_main; \
8776 unix_shared_memory_queue_t * q; \
8778 /* One registration only... */ \
8779 pool_foreach(reg, vam->nn##_registrations, \
8781 q = vl_api_client_index_to_input_queue (reg->client_index); \
8784 * If the queue is stuffed, turf the msg and complain \
8785 * It's unlikely that the intended recipient is \
8786 * alive; avoid deadlock at all costs. \
8788 if (q->cursize == q->maxsize) { \
8789 clib_warning ("ERROR: receiver queue full, drop msg"); \
8790 vl_msg_api_free (mp); \
8793 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8797 vl_msg_api_free (mp); \
8802 * Add vpe's API message handlers to the table.
8803 * vlib has alread mapped shared memory and
8804 * added the client registration handlers.
8805 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8808 static clib_error_t *
8809 vpe_api_hookup (vlib_main_t * vm)
8811 api_main_t *am = &api_main;
8814 vl_msg_api_set_handlers(VL_API_##N, #n, \
8815 vl_api_##n##_t_handler, \
8817 vl_api_##n##_t_endian, \
8818 vl_api_##n##_t_print, \
8819 sizeof(vl_api_##n##_t), 1);
8820 foreach_vpe_api_msg;
8824 * Manually register the sr tunnel add del msg, so we trace
8825 * enough bytes to capture a typical segment list
8827 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8828 "sr_tunnel_add_del",
8829 vl_api_sr_tunnel_add_del_t_handler,
8831 vl_api_sr_tunnel_add_del_t_endian,
8832 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8836 * Manually register the sr policy add del msg, so we trace
8837 * enough bytes to capture a typical tunnel name list
8839 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8840 "sr_policy_add_del",
8841 vl_api_sr_policy_add_del_t_handler,
8843 vl_api_sr_policy_add_del_t_endian,
8844 vl_api_sr_policy_add_del_t_print, 256, 1);
8847 * Trace space for 8 MPLS encap labels, classifier mask+match
8849 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8850 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8851 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8852 += 5 * sizeof (u32x4);
8853 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8856 * Thread-safe API messages
8858 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8859 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8864 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8866 static clib_error_t *
8867 vpe_api_init (vlib_main_t * vm)
8869 vpe_api_main_t *am = &vpe_api_main;
8872 am->vnet_main = vnet_get_main ();
8873 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8874 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8875 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8876 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8877 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8878 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8881 vl_set_memory_region_name ("/vpe-api");
8882 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8887 VLIB_INIT_FUNCTION (vpe_api_init);
8890 static clib_error_t *
8891 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8894 u64 baseva, size, pvt_heap_size;
8896 const int max_buf_size = 4096;
8898 struct passwd _pw, *pw;
8899 struct group _grp, *grp;
8901 buf = vec_new (char, 128);
8902 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8904 if (unformat (input, "prefix %s", &chroot_path))
8906 vec_add1 (chroot_path, 0);
8907 vl_set_memory_root_path ((char *) chroot_path);
8909 else if (unformat (input, "uid %d", &uid))
8910 vl_set_memory_uid (uid);
8911 else if (unformat (input, "gid %d", &gid))
8912 vl_set_memory_gid (gid);
8913 else if (unformat (input, "baseva %llx", &baseva))
8914 vl_set_global_memory_baseva (baseva);
8915 else if (unformat (input, "global-size %lldM", &size))
8916 vl_set_global_memory_size (size * (1ULL << 20));
8917 else if (unformat (input, "global-size %lldG", &size))
8918 vl_set_global_memory_size (size * (1ULL << 30));
8919 else if (unformat (input, "global-size %lld", &size))
8920 vl_set_global_memory_size (size);
8921 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8922 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8923 else if (unformat (input, "global-pvt-heap-size size %lld",
8925 vl_set_global_pvt_heap_size (pvt_heap_size);
8926 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8927 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8928 else if (unformat (input, "api-pvt-heap-size size %lld",
8930 vl_set_api_pvt_heap_size (pvt_heap_size);
8931 else if (unformat (input, "api-size %lldM", &size))
8932 vl_set_api_memory_size (size * (1ULL << 20));
8933 else if (unformat (input, "api-size %lldG", &size))
8934 vl_set_api_memory_size (size * (1ULL << 30));
8935 else if (unformat (input, "api-size %lld", &size))
8936 vl_set_api_memory_size (size);
8937 else if (unformat (input, "uid %s", &s))
8939 /* lookup the username */
8942 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8943 && (vec_len (buf) <= max_buf_size))
8945 vec_resize (buf, vec_len (buf) * 2);
8949 e = clib_error_return_code (0, rv,
8950 CLIB_ERROR_ERRNO_VALID |
8952 "cannot fetch username %s", s);
8960 clib_error_return_fatal (0, "username %s does not exist", s);
8966 vl_set_memory_uid (pw->pw_uid);
8968 else if (unformat (input, "gid %s", &s))
8970 /* lookup the group name */
8973 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8974 && (vec_len (buf) <= max_buf_size))
8976 vec_resize (buf, vec_len (buf) * 2);
8980 e = clib_error_return_code (0, rv,
8981 CLIB_ERROR_ERRNO_VALID |
8983 "cannot fetch group %s", s);
8990 e = clib_error_return_fatal (0, "group %s does not exist", s);
8997 vl_set_memory_gid (grp->gr_gid);
9000 return clib_error_return (0, "unknown input `%U'",
9001 format_unformat_error, input);
9006 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
9009 get_unformat_vnet_sw_interface (void)
9011 return (void *) &unformat_vnet_sw_interface;
9014 #undef vl_api_version
9015 #define vl_api_version(n,v) static u32 vpe_api_version = v;
9016 #include <vpp-api/vpe.api.h>
9017 #undef vl_api_version
9020 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
9022 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
9024 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
9025 clib_host_to_net_u32 (mp->api_versions[0]),
9033 format_arp_event (u8 * s, va_list * args)
9035 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
9037 s = format (s, "pid %d: ", event->pid);
9039 s = format (s, "bd mac/ip4 binding events");
9041 s = format (s, "resolution for %U", format_ip4_address, &event->address);
9046 format_nd_event (u8 * s, va_list * args)
9048 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
9050 s = format (s, "pid %d: ", event->pid);
9052 s = format (s, "bd mac/ip6 binding events");
9054 s = format (s, "resolution for %U", format_ip6_address, event->address);
9058 static clib_error_t *
9059 show_ip_arp_nd_events_fn (vlib_main_t * vm,
9060 unformat_input_t * input, vlib_cli_command_t * cmd)
9062 vpe_api_main_t *am = &vpe_api_main;
9063 vl_api_ip4_arp_event_t *arp_event;
9064 vl_api_ip6_nd_event_t *nd_event;
9066 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
9068 vlib_cli_output (vm, "No active arp or nd event registrations");
9073 pool_foreach (arp_event, am->arp_events,
9075 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
9078 pool_foreach (nd_event, am->nd_events,
9080 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
9088 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
9089 .path = "show arp-nd-event registrations",
9090 .function = show_ip_arp_nd_events_fn,
9091 .short_help = "Show ip4 arp and ip6 nd event registrations",
9096 * fd.io coding-style-patch-verification: ON
9099 * eval: (c-set-style "gnu")