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>
121 #define f64_endian(a)
122 #define f64_print(a,b)
124 #define vl_typedefs /* define message structures */
125 #include <vpp-api/vpe_all_api_h.h>
128 #define vl_endianfun /* define message structures */
129 #include <vpp-api/vpe_all_api_h.h>
132 /* instantiate all the print functions we know about */
133 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
135 #include <vpp-api/vpe_all_api_h.h>
138 #define REPLY_MACRO(t) \
140 unix_shared_memory_queue_t * q; \
141 rv = vl_msg_api_pd_handler (mp, rv); \
142 q = vl_api_client_index_to_input_queue (mp->client_index); \
146 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
147 rmp->_vl_msg_id = ntohs((t)); \
148 rmp->context = mp->context; \
149 rmp->retval = ntohl(rv); \
151 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
154 #define REPLY_MACRO2(t, body) \
156 unix_shared_memory_queue_t * q; \
157 rv = vl_msg_api_pd_handler (mp, rv); \
158 q = vl_api_client_index_to_input_queue (mp->client_index); \
162 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
163 rmp->_vl_msg_id = ntohs((t)); \
164 rmp->context = mp->context; \
165 rmp->retval = ntohl(rv); \
166 do {body;} while (0); \
167 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
170 #define REPLY_MACRO3(t, n, body) \
172 unix_shared_memory_queue_t * q; \
173 rv = vl_msg_api_pd_handler (mp, rv); \
174 q = vl_api_client_index_to_input_queue (mp->client_index); \
178 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
179 rmp->_vl_msg_id = ntohs((t)); \
180 rmp->context = mp->context; \
181 rmp->retval = ntohl(rv); \
182 do {body;} while (0); \
183 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
186 #define REPLY_MACRO4(t, n, body) \
188 unix_shared_memory_queue_t * q; \
190 rv = vl_msg_api_pd_handler (mp, rv); \
191 q = vl_api_client_index_to_input_queue (mp->client_index); \
195 rmp = vl_msg_api_alloc_or_null (sizeof (*rmp) + n); \
198 /* if there isn't enough memory, try to allocate */ \
199 /* some at least for returning an error */ \
200 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
204 memset (rmp, 0, sizeof (*rmp)); \
205 rv = VNET_API_ERROR_TABLE_TOO_BIG; \
208 rmp->_vl_msg_id = ntohs((t)); \
209 rmp->context = mp->context; \
210 rmp->retval = ntohl(rv); \
212 do {body;} while (0); \
213 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
216 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
218 #define VALIDATE_SW_IF_INDEX(mp) \
219 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
220 vnet_main_t *__vnm = vnet_get_main(); \
221 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
223 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
224 goto bad_sw_if_index; \
228 #define BAD_SW_IF_INDEX_LABEL \
234 #define VALIDATE_RX_SW_IF_INDEX(mp) \
235 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
236 vnet_main_t *__vnm = vnet_get_main(); \
237 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
238 __rx_sw_if_index)) { \
239 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
240 goto bad_rx_sw_if_index; \
244 #define BAD_RX_SW_IF_INDEX_LABEL \
246 bad_rx_sw_if_index: \
250 #define VALIDATE_TX_SW_IF_INDEX(mp) \
251 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
252 vnet_main_t *__vnm = vnet_get_main(); \
253 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
254 __tx_sw_if_index)) { \
255 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
256 goto bad_tx_sw_if_index; \
260 #define BAD_TX_SW_IF_INDEX_LABEL \
262 bad_tx_sw_if_index: \
268 #define VALIDATE_SW_IF_INDEX(mp)
269 #define BAD_SW_IF_INDEX_LABEL
270 #define VALIDATE_RX_SW_IF_INDEX(mp)
271 #define BAD_RX_SW_IF_INDEX_LABEL
272 #define VALIDATE_TX_SW_IF_INDEX(mp)
273 #define BAD_TX_SW_IF_INDEX_LABEL
275 #endif /* CLIB_DEBUG > 0 */
277 #define foreach_vpe_api_msg \
278 _(WANT_INTERFACE_EVENTS, want_interface_events) \
279 _(WANT_OAM_EVENTS, want_oam_events) \
280 _(OAM_ADD_DEL, oam_add_del) \
281 _(SW_INTERFACE_DUMP, sw_interface_dump) \
282 _(SW_INTERFACE_DETAILS, sw_interface_details) \
283 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
284 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
285 _(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \
286 _(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \
287 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
288 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
289 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
290 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
291 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
292 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
293 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
294 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
295 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
296 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
297 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
298 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
299 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
300 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
301 _(L2FIB_ADD_DEL, l2fib_add_del) \
302 _(L2_FLAGS, l2_flags) \
303 _(BRIDGE_FLAGS, bridge_flags) \
304 _(TAP_CONNECT, tap_connect) \
305 _(TAP_MODIFY, tap_modify) \
306 _(TAP_DELETE, tap_delete) \
307 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
308 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
309 _(CREATE_SUBIF, create_subif) \
310 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
311 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
312 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
313 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
314 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
315 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
316 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
317 _(RESET_FIB, reset_fib) \
318 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
319 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
320 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
321 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
322 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
323 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
324 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
325 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
326 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
327 sw_interface_ip6_set_link_local_address) \
328 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
329 _(CREATE_LOOPBACK, create_loopback) \
330 _(CONTROL_PING, control_ping) \
331 _(CLI_REQUEST, cli_request) \
332 _(CLI_INBAND, cli_inband) \
333 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
334 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
335 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
336 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
337 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
338 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
339 _(GET_NODE_INDEX, get_node_index) \
340 _(ADD_NODE_NEXT, add_node_next) \
341 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
342 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
343 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
344 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
345 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
346 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
347 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
348 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
349 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
350 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
351 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
352 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
353 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
354 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
355 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
356 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
357 _(IP_ADDRESS_DUMP, ip_address_dump) \
358 _(IP_DUMP, ip_dump) \
359 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
360 _(SHOW_VERSION, show_version) \
361 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
362 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
363 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
364 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
365 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
366 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
367 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
368 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
369 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
370 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
371 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
372 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
373 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
374 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
375 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
376 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
377 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
378 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
379 _(DELETE_LOOPBACK, delete_loopback) \
380 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
381 _(MAP_ADD_DOMAIN, map_add_domain) \
382 _(MAP_DEL_DOMAIN, map_del_domain) \
383 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
384 _(MAP_DOMAIN_DUMP, map_domain_dump) \
385 _(MAP_RULE_DUMP, map_rule_dump) \
386 _(MAP_SUMMARY_STATS, map_summary_stats) \
387 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
388 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
389 _(GET_NODE_GRAPH, get_node_graph) \
390 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
391 _(IOAM_ENABLE, ioam_enable) \
392 _(IOAM_DISABLE, ioam_disable) \
393 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
394 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
395 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
396 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
397 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
398 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
399 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
400 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
401 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
402 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
403 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
404 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
405 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
406 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
407 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
408 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
409 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
410 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
411 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
412 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
413 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
414 _(SHOW_LISP_STATUS, show_lisp_status) \
415 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
416 lisp_add_del_map_request_itr_rlocs) \
417 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
418 _(SHOW_LISP_PITR, show_lisp_pitr) \
419 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
420 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
421 _(AF_PACKET_CREATE, af_packet_create) \
422 _(AF_PACKET_DELETE, af_packet_delete) \
423 _(POLICER_ADD_DEL, policer_add_del) \
424 _(POLICER_DUMP, policer_dump) \
425 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
426 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
427 _(NETMAP_CREATE, netmap_create) \
428 _(NETMAP_DELETE, netmap_delete) \
429 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
430 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
431 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
432 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
433 _(MPLS_FIB_DUMP, mpls_fib_dump) \
434 _(MPLS_FIB_DETAILS, mpls_fib_details) \
435 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
436 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
437 _(CLASSIFY_TABLE_INFO,classify_table_info) \
438 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
439 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
440 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
441 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
442 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
443 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
444 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
445 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
446 _(GET_NEXT_INDEX, get_next_index) \
447 _(PG_CREATE_INTERFACE, pg_create_interface) \
448 _(PG_CAPTURE, pg_capture) \
449 _(PG_ENABLE_DISABLE, pg_enable_disable) \
450 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
451 ip_source_and_port_range_check_add_del) \
452 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
453 ip_source_and_port_range_check_interface_add_del) \
454 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
455 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
456 _(DELETE_SUBIF, delete_subif) \
457 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
459 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
460 _(FLOW_CLASSIFY_DUMP, flow_classify_dump)
463 #define QUOTE(x) QUOTE_(x)
465 #define foreach_registration_hash \
466 _(interface_events) \
467 _(to_netconf_server) \
468 _(from_netconf_server) \
469 _(to_netconf_client) \
470 _(from_netconf_client) \
475 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
476 RESOLVE_IP6_ADD_DEL_ROUTE,
477 RESOLVE_MPLS_ETHERNET_ADD_DEL,
485 vl_api_ip_add_del_route_t r;
486 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
493 #define _(a) uword *a##_registration_hash; \
494 vpe_client_registration_t * a##_registrations;
495 foreach_registration_hash
497 /* notifications happen really early in the game */
498 u8 link_state_process_up;
500 /* ip4 and ip6 pending route adds */
501 pending_route_t *pending_routes;
503 /* ip4 arp event registration pool */
504 vl_api_ip4_arp_event_t *arp_events;
506 /* ip6 nd event registration pool */
507 vl_api_ip6_nd_event_t *nd_events;
510 vlib_main_t *vlib_main;
511 vnet_main_t *vnet_main;
514 static vlib_node_registration_t vpe_resolver_process_node;
515 static vpe_api_main_t vpe_api_main;
517 static void send_sw_interface_flags (vpe_api_main_t * am,
518 unix_shared_memory_queue_t * q,
519 vnet_sw_interface_t * swif);
520 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
521 unix_shared_memory_queue_t * q,
524 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
525 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
528 /* Clean up all registrations belonging to the indicated client */
530 vl_api_memclnt_delete_callback (u32 client_index)
532 vpe_api_main_t *vam = &vpe_api_main;
533 vpe_client_registration_t *rp;
535 int stats_memclnt_delete_callback (u32 client_index);
537 stats_memclnt_delete_callback (client_index);
540 p = hash_get (vam->a##_registration_hash, client_index); \
542 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
543 pool_put (vam->a##_registrations, rp); \
544 hash_unset (vam->a##_registration_hash, client_index); \
546 foreach_registration_hash;
551 #define API_LINK_STATE_EVENT 1
552 #define API_ADMIN_UP_DOWN_EVENT 2
555 event_data_cmp (void *a1, void *a2)
560 return (word) e1[0] - (word) e2[0];
564 link_state_process (vlib_main_t * vm,
565 vlib_node_runtime_t * rt, vlib_frame_t * f)
567 vpe_api_main_t *vam = &vpe_api_main;
568 vnet_main_t *vnm = vam->vnet_main;
569 vnet_sw_interface_t *swif;
570 uword *event_data = 0;
571 vpe_client_registration_t *reg;
573 u32 prev_sw_if_index;
574 unix_shared_memory_queue_t *q;
576 vam->link_state_process_up = 1;
580 vlib_process_wait_for_event (vm);
582 /* Unified list of changed link or admin state sw_if_indices */
583 vlib_process_get_events_with_type
584 (vm, &event_data, API_LINK_STATE_EVENT);
585 vlib_process_get_events_with_type
586 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
588 /* Sort, so we can eliminate duplicates */
589 vec_sort_with_function (event_data, event_data_cmp);
591 prev_sw_if_index = ~0;
593 for (i = 0; i < vec_len (event_data); i++)
595 /* Only one message per swif */
596 if (prev_sw_if_index == event_data[i])
598 prev_sw_if_index = event_data[i];
601 pool_foreach(reg, vam->interface_events_registrations,
603 q = vl_api_client_index_to_input_queue (reg->client_index);
606 /* sw_interface may be deleted already */
607 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
610 swif = vnet_get_sw_interface (vnm, event_data[i]);
611 send_sw_interface_flags (vam, q, swif);
617 vec_reset_length (event_data);
623 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
625 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
626 u32 hw_if_index, u32 flags);
629 VLIB_REGISTER_NODE (link_state_process_node,static) = {
630 .function = link_state_process,
631 .type = VLIB_NODE_TYPE_PROCESS,
632 .name = "vpe-link-state-process",
636 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
637 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
639 static clib_error_t *
640 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
642 vpe_api_main_t *vam = &vpe_api_main;
643 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
645 if (vam->link_state_process_up)
646 vlib_process_signal_event (vam->vlib_main,
647 link_state_process_node.index,
648 API_LINK_STATE_EVENT, hi->sw_if_index);
652 static clib_error_t *
653 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
655 vpe_api_main_t *vam = &vpe_api_main;
658 * Note: it's perfectly fair to set a subif admin up / admin down.
659 * Note the subtle distinction between this routine and the previous
662 if (vam->link_state_process_up)
663 vlib_process_signal_event (vam->vlib_main,
664 link_state_process_node.index,
665 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
669 #define pub_sub_handler(lca,UCA) \
670 static void vl_api_want_##lca##_t_handler ( \
671 vl_api_want_##lca##_t *mp) \
673 vpe_api_main_t *vam = &vpe_api_main; \
674 vpe_client_registration_t *rp; \
675 vl_api_want_##lca##_reply_t *rmp; \
679 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
681 if (mp->enable_disable) { \
682 clib_warning ("pid %d: already enabled...", mp->pid); \
683 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
686 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
687 pool_put (vam->lca##_registrations, rp); \
688 hash_unset (vam->lca##_registration_hash, \
693 if (mp->enable_disable == 0) { \
694 clib_warning ("pid %d: already disabled...", mp->pid); \
695 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
698 pool_get (vam->lca##_registrations, rp); \
699 rp->client_index = mp->client_index; \
700 rp->client_pid = mp->pid; \
701 hash_set (vam->lca##_registration_hash, rp->client_index, \
702 rp - vam->lca##_registrations); \
705 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
709 pub_sub_handler (interface_events, INTERFACE_EVENTS)
710 pub_sub_handler (oam_events, OAM_EVENTS)
713 #define RESOLUTION_EVENT 1
714 #define RESOLUTION_PENDING_EVENT 2
715 #define IP4_ARP_EVENT 3
716 #define IP6_ND_EVENT 4
718 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
720 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
722 static int mpls_ethernet_add_del_tunnel_2_t_handler
723 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
726 handle_ip4_arp_event (u32 pool_index)
728 vpe_api_main_t *vam = &vpe_api_main;
729 vnet_main_t *vnm = vam->vnet_main;
730 vlib_main_t *vm = vam->vlib_main;
731 vl_api_ip4_arp_event_t *event;
732 vl_api_ip4_arp_event_t *mp;
733 unix_shared_memory_queue_t *q;
735 /* Client can cancel, die, etc. */
736 if (pool_is_free_index (vam->arp_events, pool_index))
739 event = pool_elt_at_index (vam->arp_events, pool_index);
741 q = vl_api_client_index_to_input_queue (event->client_index);
744 (void) vnet_add_del_ip4_arp_change_event
745 (vnm, arp_change_delete_callback,
746 event->pid, &event->address,
747 vpe_resolver_process_node.index, IP4_ARP_EVENT,
748 ~0 /* pool index, notused */ , 0 /* is_add */ );
752 if (q->cursize < q->maxsize)
754 mp = vl_msg_api_alloc (sizeof (*mp));
755 clib_memcpy (mp, event, sizeof (*mp));
756 vl_msg_api_send_shmem (q, (u8 *) & mp);
760 static f64 last_time;
762 * Throttle syslog msgs.
763 * It's pretty tempting to just revoke the registration...
765 if (vlib_time_now (vm) > last_time + 10.0)
767 clib_warning ("arp event for %U to pid %d: queue stuffed!",
768 format_ip4_address, &event->address, event->pid);
769 last_time = vlib_time_now (vm);
775 handle_ip6_nd_event (u32 pool_index)
777 vpe_api_main_t *vam = &vpe_api_main;
778 vnet_main_t *vnm = vam->vnet_main;
779 vlib_main_t *vm = vam->vlib_main;
780 vl_api_ip6_nd_event_t *event;
781 vl_api_ip6_nd_event_t *mp;
782 unix_shared_memory_queue_t *q;
784 /* Client can cancel, die, etc. */
785 if (pool_is_free_index (vam->nd_events, pool_index))
788 event = pool_elt_at_index (vam->nd_events, pool_index);
790 q = vl_api_client_index_to_input_queue (event->client_index);
793 (void) vnet_add_del_ip6_nd_change_event
794 (vnm, nd_change_delete_callback,
795 event->pid, &event->address,
796 vpe_resolver_process_node.index, IP6_ND_EVENT,
797 ~0 /* pool index, notused */ , 0 /* is_add */ );
801 if (q->cursize < q->maxsize)
803 mp = vl_msg_api_alloc (sizeof (*mp));
804 clib_memcpy (mp, event, sizeof (*mp));
805 vl_msg_api_send_shmem (q, (u8 *) & mp);
809 static f64 last_time;
811 * Throttle syslog msgs.
812 * It's pretty tempting to just revoke the registration...
814 if (vlib_time_now (vm) > last_time + 10.0)
816 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
817 format_ip6_address, &event->address, event->pid);
818 last_time = vlib_time_now (vm);
824 resolver_process (vlib_main_t * vm,
825 vlib_node_runtime_t * rt, vlib_frame_t * f)
828 uword *event_data = 0;
830 vpe_api_main_t *vam = &vpe_api_main;
832 vl_api_ip_add_del_route_t *adr;
833 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
834 u32 *resolution_failures = 0;
840 vlib_process_wait_for_event_or_clock (vm, timeout);
842 event_type = vlib_process_get_events (vm, &event_data);
846 case RESOLUTION_PENDING_EVENT:
850 case RESOLUTION_EVENT:
851 for (i = 0; i < vec_len (event_data); i++)
854 * Resolution events can occur long after the
855 * original request has timed out. $$$ add a cancel
858 if (pool_is_free_index (vam->pending_routes, event_data[i]))
861 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
865 switch (pr->resolve_type)
867 case RESOLVE_IP4_ADD_DEL_ROUTE:
868 rv = ip4_add_del_route_t_handler (adr);
869 clib_warning ("resolver: add %U/%d via %U %s",
871 (ip4_address_t *) & (adr->dst_address),
872 adr->dst_address_length,
874 (ip4_address_t *) & (adr->next_hop_address),
875 (rv >= 0) ? "succeeded" : "failed");
878 case RESOLVE_IP6_ADD_DEL_ROUTE:
879 rv = ip6_add_del_route_t_handler (adr);
880 clib_warning ("resolver: add %U/%d via %U %s",
882 (ip6_address_t *) & (adr->dst_address),
883 adr->dst_address_length,
885 (ip6_address_t *) & (adr->next_hop_address),
886 (rv >= 0) ? "succeeded" : "failed");
889 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
890 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
891 clib_warning ("resolver: add mpls-o-e via %U %s",
894 (pme->next_hop_ip4_address_in_outer_vrf),
895 (rv >= 0) ? "succeeded" : "failed");
899 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
901 pool_put (vam->pending_routes, pr);
906 for (i = 0; i < vec_len (event_data); i++)
907 handle_ip4_arp_event (event_data[i]);
911 for (i = 0; i < vec_len (event_data); i++)
912 handle_ip6_nd_event (event_data[i]);
915 case ~0: /* timeout, retry pending resolutions */
917 pool_foreach (pr, vam->pending_routes,
923 /* May fail, e.g. due to interface down */
924 switch (pr->resolve_type)
926 case RESOLVE_IP4_ADD_DEL_ROUTE:
927 e = ip4_probe_neighbor
928 (vm, (ip4_address_t *)&(adr->next_hop_address),
929 ntohl(adr->next_hop_sw_if_index));
932 case RESOLVE_IP6_ADD_DEL_ROUTE:
933 e = ip6_probe_neighbor
934 (vm, (ip6_address_t *)&(adr->next_hop_address),
935 ntohl(adr->next_hop_sw_if_index));
938 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
940 e = ip4_probe_neighbor
942 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
943 pme->resolve_opaque);
947 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
952 clib_error_report (e);
954 adr->resolve_attempts = 1;
956 pme->resolve_attempts = 1;
960 adr->resolve_attempts -= 1;
961 if (adr->resolve_attempts == 0)
962 vec_add1 (resolution_failures,
963 pr - vam->pending_routes);
967 pme->resolve_attempts -= 1;
968 if (pme->resolve_attempts == 0)
969 vec_add1 (resolution_failures,
970 pr - vam->pending_routes);
974 for (i = 0; i < vec_len (resolution_failures); i++)
976 pr = pool_elt_at_index (vam->pending_routes,
977 resolution_failures[i]);
981 switch (pr->resolve_type)
983 case RESOLVE_IP4_ADD_DEL_ROUTE:
984 clib_warning ("resolver: add %U/%d via %U retry failure",
986 (ip4_address_t *) & (adr->dst_address),
987 adr->dst_address_length,
989 (ip4_address_t *) & (adr->next_hop_address));
992 case RESOLVE_IP6_ADD_DEL_ROUTE:
993 clib_warning ("resolver: add %U/%d via %U retry failure",
995 (ip6_address_t *) & (adr->dst_address),
996 adr->dst_address_length,
998 (ip6_address_t *) & (adr->next_hop_address));
1001 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
1002 clib_warning ("resolver: add mpls-o-e via %U retry failure",
1005 (pme->next_hop_ip4_address_in_outer_vrf));
1009 clib_warning ("BUG");
1011 pool_put (vam->pending_routes, pr);
1013 vec_reset_length (resolution_failures);
1016 if (pool_elts (vam->pending_routes) == 0)
1018 vec_reset_length (event_data);
1020 return 0; /* or not */
1024 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
1025 .function = resolver_process,
1026 .type = VLIB_NODE_TYPE_PROCESS,
1027 .name = "vpe-route-resolver-process",
1032 add_del_route_t_handler (u8 is_multipath,
1037 u32 classify_table_index,
1039 u8 is_resolve_attached,
1041 const fib_prefix_t * prefix,
1042 u8 next_hop_proto_is_ip4,
1043 const ip46_address_t * next_hop,
1044 u32 next_hop_sw_if_index,
1045 u8 next_hop_fib_index,
1046 u32 next_hop_weight, u32 next_hop_out_label)
1048 vnet_classify_main_t *cm = &vnet_classify_main;
1049 fib_protocol_t proto = prefix->fp_proto;
1050 stats_main_t *sm = &stats_main;
1054 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1056 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1058 if (is_resolve_host)
1059 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1060 if (is_resolve_attached)
1061 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1064 fib_table_entry_path_add (fib_index,
1067 FIB_ENTRY_FLAG_NONE,
1068 (next_hop_proto_is_ip4 ?
1072 next_hop_sw_if_index,
1075 next_hop_out_label, path_flags);
1077 fib_table_entry_path_remove (fib_index,
1080 (next_hop_proto_is_ip4 ?
1084 next_hop_sw_if_index,
1086 next_hop_weight, path_flags);
1092 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1094 if (is_drop || is_local || is_classify)
1097 * special route types that link directly to the adj
1101 dpo_id_t dpo = DPO_NULL;
1104 dproto = fib_proto_to_dpo (prefix->fp_proto);
1107 dpo_copy (&dpo, drop_dpo_get (dproto));
1109 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
1110 else if (is_classify)
1112 if (pool_is_free_index (cm->tables,
1113 ntohl (classify_table_index)))
1116 return VNET_API_ERROR_NO_SUCH_TABLE;
1119 dpo_set (&dpo, DPO_CLASSIFY, proto,
1120 classify_dpo_create (prefix->fp_proto,
1121 ntohl (classify_table_index)));
1126 return VNET_API_ERROR_NO_SUCH_TABLE;
1129 fib_table_entry_special_dpo_add (fib_index,
1132 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
1137 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
1144 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1146 if (is_resolve_host)
1147 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1148 if (is_resolve_attached)
1149 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1151 fib_table_entry_update_one_path (fib_index,
1154 FIB_ENTRY_FLAG_NONE,
1155 (next_hop_proto_is_ip4 ?
1159 next_hop_sw_if_index,
1162 next_hop_out_label, path_flags);
1166 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
1175 add_del_route_check (fib_protocol_t table_proto,
1177 u32 next_hop_sw_if_index,
1178 fib_protocol_t next_hop_table_proto,
1179 u32 next_hop_table_id,
1180 u8 create_missing_tables,
1181 u32 * fib_index, u32 * next_hop_fib_index)
1183 vnet_main_t *vnm = vnet_get_main ();
1185 *fib_index = fib_table_find (table_proto, ntohl (table_id));
1186 if (~0 == *fib_index)
1188 if (create_missing_tables)
1190 *fib_index = fib_table_find_or_create_and_lock (table_proto,
1195 /* No such VRF, and we weren't asked to create one */
1196 return VNET_API_ERROR_NO_SUCH_FIB;
1200 if (~0 != ntohl (next_hop_sw_if_index))
1202 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1203 ntohl (next_hop_sw_if_index)))
1205 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1210 *next_hop_fib_index = fib_table_find (next_hop_table_proto,
1211 ntohl (next_hop_table_id));
1213 if (~0 == *next_hop_fib_index)
1215 if (create_missing_tables)
1217 *next_hop_fib_index =
1218 fib_table_find_or_create_and_lock (next_hop_table_proto,
1219 ntohl (next_hop_table_id));
1223 /* No such VRF, and we weren't asked to create one */
1224 return VNET_API_ERROR_NO_SUCH_FIB;
1233 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1235 u32 fib_index, next_hop_fib_index;
1238 rv = add_del_route_check (FIB_PROTOCOL_IP4,
1240 mp->next_hop_sw_if_index,
1242 mp->next_hop_table_id,
1243 mp->create_vrf_if_needed,
1244 &fib_index, &next_hop_fib_index);
1249 fib_prefix_t pfx = {
1250 .fp_len = mp->dst_address_length,
1251 .fp_proto = FIB_PROTOCOL_IP4,
1253 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
1256 memset (&nh, 0, sizeof (nh));
1257 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
1259 return (add_del_route_t_handler (mp->is_multipath, mp->is_add, mp->is_drop, mp->is_local, mp->is_classify, mp->classify_table_index, mp->is_resolve_host, mp->is_resolve_attached, fib_index, &pfx, 1, // is_ip4
1261 ntohl (mp->next_hop_sw_if_index),
1263 mp->next_hop_weight,
1264 ntohl (mp->next_hop_out_label)));
1268 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1270 u32 fib_index, next_hop_fib_index;
1273 rv = add_del_route_check (FIB_PROTOCOL_IP6,
1275 mp->next_hop_sw_if_index,
1277 mp->next_hop_table_id,
1278 mp->create_vrf_if_needed,
1279 &fib_index, &next_hop_fib_index);
1284 fib_prefix_t pfx = {
1285 .fp_len = mp->dst_address_length,
1286 .fp_proto = FIB_PROTOCOL_IP6,
1288 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
1291 memset (&nh, 0, sizeof (nh));
1292 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
1294 return (add_del_route_t_handler (mp->is_multipath, mp->is_add, mp->is_drop, mp->is_local, mp->is_classify, mp->classify_table_index, mp->is_resolve_host, mp->is_resolve_attached, fib_index, &pfx, 0, // is_ip4
1295 &nh, ntohl (mp->next_hop_sw_if_index),
1297 mp->next_hop_weight,
1298 ntohl (mp->next_hop_out_label)));
1302 mpls_route_add_del_t_handler (vnet_main_t * vnm,
1303 vl_api_mpls_route_add_del_t * mp)
1305 u32 fib_index, next_hop_fib_index;
1309 fib_prefix_t pfx = {
1311 .fp_proto = FIB_PROTOCOL_MPLS,
1312 .fp_eos = mp->mr_eos,
1313 .fp_label = ntohl (mp->mr_label),
1317 if (mp->mr_next_hop_proto_is_ip4)
1319 pfx.fp_payload_proto = DPO_PROTO_IP4;
1323 pfx.fp_payload_proto = DPO_PROTO_IP6;
1328 pfx.fp_payload_proto = DPO_PROTO_MPLS;
1331 rv = add_del_route_check (FIB_PROTOCOL_MPLS,
1333 mp->mr_next_hop_sw_if_index,
1334 dpo_proto_to_fib (pfx.fp_payload_proto),
1335 mp->mr_next_hop_table_id,
1336 mp->mr_create_table_if_needed,
1337 &fib_index, &next_hop_fib_index);
1343 memset (&nh, 0, sizeof (nh));
1345 if (mp->mr_next_hop_proto_is_ip4)
1346 memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
1348 memcpy (&nh.ip6, mp->mr_next_hop, sizeof (nh.ip6));
1350 return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop,
1353 mp->mr_classify_table_index,
1354 mp->mr_is_resolve_host,
1355 mp->mr_is_resolve_attached,
1357 mp->mr_next_hop_proto_is_ip4,
1358 &nh, ntohl (mp->mr_next_hop_sw_if_index),
1360 mp->mr_next_hop_weight,
1361 ntohl (mp->mr_next_hop_out_label)));
1365 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1367 vl_api_ip_add_del_route_reply_t *rmp;
1369 vnet_main_t *vnm = vnet_get_main ();
1374 rv = ip6_add_del_route_t_handler (mp);
1376 rv = ip4_add_del_route_t_handler (mp);
1378 rv = (rv == 0) ? vnm->api_errno : rv;
1380 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1384 vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
1386 vl_api_mpls_route_add_del_reply_t *rmp;
1390 vnm = vnet_get_main ();
1393 rv = mpls_route_add_del_t_handler (vnm, mp);
1395 rv = (rv == 0) ? vnm->api_errno : rv;
1397 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1401 mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
1402 vl_api_mpls_ip_bind_unbind_t * mp)
1404 u32 mpls_fib_index, ip_fib_index;
1407 fib_table_find (FIB_PROTOCOL_MPLS, ntohl (mp->mb_mpls_table_id));
1409 if (~0 == mpls_fib_index)
1411 if (mp->mb_create_table_if_needed)
1414 fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
1415 ntohl (mp->mb_mpls_table_id));
1418 return VNET_API_ERROR_NO_SUCH_FIB;
1421 ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
1424 ntohl (mp->mb_ip_table_id));
1425 if (~0 == ip_fib_index)
1426 return VNET_API_ERROR_NO_SUCH_FIB;
1428 fib_prefix_t pfx = {
1429 .fp_len = mp->mb_address_length,
1434 pfx.fp_proto = FIB_PROTOCOL_IP4;
1435 clib_memcpy (&pfx.fp_addr.ip4, mp->mb_address,
1436 sizeof (pfx.fp_addr.ip4));
1440 pfx.fp_proto = FIB_PROTOCOL_IP6;
1441 clib_memcpy (&pfx.fp_addr.ip6, mp->mb_address,
1442 sizeof (pfx.fp_addr.ip6));
1446 fib_table_entry_local_label_add (ip_fib_index, &pfx,
1447 ntohl (mp->mb_label));
1449 fib_table_entry_local_label_remove (ip_fib_index, &pfx,
1450 ntohl (mp->mb_label));
1456 vl_api_mpls_ip_bind_unbind_t_handler (vl_api_mpls_ip_bind_unbind_t * mp)
1458 vl_api_mpls_route_add_del_reply_t *rmp;
1462 vnm = vnet_get_main ();
1465 rv = mpls_ip_bind_unbind_handler (vnm, mp);
1467 rv = (rv == 0) ? vnm->api_errno : rv;
1469 REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
1473 vl_api_sw_interface_add_del_address_t_handler
1474 (vl_api_sw_interface_add_del_address_t * mp)
1476 vlib_main_t *vm = vlib_get_main ();
1477 vl_api_sw_interface_add_del_address_reply_t *rmp;
1481 VALIDATE_SW_IF_INDEX (mp);
1483 is_del = mp->is_add == 0;
1486 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1487 else if (mp->is_ipv6)
1488 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1489 (void *) mp->address,
1490 mp->address_length, is_del);
1492 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1493 (void *) mp->address,
1494 mp->address_length, is_del);
1496 BAD_SW_IF_INDEX_LABEL;
1498 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1502 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1505 u32 table_id = ntohl (mp->vrf_id);
1506 u32 sw_if_index = ntohl (mp->sw_if_index);
1507 vl_api_sw_interface_set_table_reply_t *rmp;
1508 stats_main_t *sm = &stats_main;
1511 VALIDATE_SW_IF_INDEX (mp);
1513 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1517 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1520 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
1521 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1526 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1529 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
1530 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1534 BAD_SW_IF_INDEX_LABEL;
1536 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1540 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1542 vlib_main_t *vm = vlib_get_main ();
1543 ip4_main_t *im4 = &ip4_main;
1544 ip6_main_t *im6 = &ip6_main;
1545 vl_api_sw_interface_set_vpath_reply_t *rmp;
1548 u32 sw_if_index = ntohl (mp->sw_if_index);
1549 ip4_main_t *ip4m = &ip4_main;
1550 ip6_main_t *ip6m = &ip6_main;
1551 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1552 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1553 ip_config_main_t *rx_cm4u =
1554 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1555 ip_config_main_t *rx_cm4m =
1556 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1557 ip_config_main_t *rx_cm6u =
1558 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1559 ip_config_main_t *rx_cm6m =
1560 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1562 VALIDATE_SW_IF_INDEX (mp);
1564 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1567 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1568 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1570 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1571 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1572 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1573 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1575 im4->ip4_multicast_rx_feature_vpath,
1577 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1578 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1579 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1581 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1582 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1583 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1584 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1586 im6->ip6_multicast_rx_feature_vpath,
1588 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1592 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1593 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1595 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1596 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1597 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1598 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1600 im4->ip4_multicast_rx_feature_vpath,
1602 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1603 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1604 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1606 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1607 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1608 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1609 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1611 im6->ip6_multicast_rx_feature_vpath,
1613 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1616 BAD_SW_IF_INDEX_LABEL;
1618 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1622 vl_api_sw_interface_set_l2_xconnect_t_handler
1623 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1625 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1627 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1628 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1629 vlib_main_t *vm = vlib_get_main ();
1630 vnet_main_t *vnm = vnet_get_main ();
1632 VALIDATE_RX_SW_IF_INDEX (mp);
1636 VALIDATE_TX_SW_IF_INDEX (mp);
1637 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1638 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1642 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1645 BAD_RX_SW_IF_INDEX_LABEL;
1646 BAD_TX_SW_IF_INDEX_LABEL;
1648 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1652 vl_api_sw_interface_set_l2_bridge_t_handler
1653 (vl_api_sw_interface_set_l2_bridge_t * mp)
1655 bd_main_t *bdm = &bd_main;
1656 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1658 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1659 u32 bd_id = ntohl (mp->bd_id);
1663 vlib_main_t *vm = vlib_get_main ();
1664 vnet_main_t *vnm = vnet_get_main ();
1666 VALIDATE_RX_SW_IF_INDEX (mp);
1668 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1672 //VALIDATE_TX_SW_IF_INDEX(mp);
1673 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1674 rx_sw_if_index, bd_index, bvi, shg, 0);
1678 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1681 BAD_RX_SW_IF_INDEX_LABEL;
1683 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1687 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1688 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1690 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1694 dpdk_main_t *dm = &dpdk_main;
1697 u32 sw_if_index = ntohl (mp->sw_if_index);
1698 u32 subport = ntohl (mp->subport);
1699 u32 pipe = ntohl (mp->pipe);
1700 u32 profile = ntohl (mp->profile);
1701 vnet_hw_interface_t *hw;
1703 VALIDATE_SW_IF_INDEX (mp);
1705 /* hw_if & dpdk device */
1706 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1708 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1710 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1712 BAD_SW_IF_INDEX_LABEL;
1714 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1715 rv = VNET_API_ERROR_UNIMPLEMENTED;
1718 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1722 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1723 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1725 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1729 dpdk_main_t *dm = &dpdk_main;
1731 struct rte_sched_subport_params p;
1733 u32 sw_if_index = ntohl (mp->sw_if_index);
1734 u32 subport = ntohl (mp->subport);
1735 p.tb_rate = ntohl (mp->tb_rate);
1736 p.tb_size = ntohl (mp->tb_size);
1737 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1738 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1739 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1740 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1741 p.tc_period = ntohl (mp->tc_period);
1743 vnet_hw_interface_t *hw;
1745 VALIDATE_SW_IF_INDEX (mp);
1747 /* hw_if & dpdk device */
1748 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1750 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1752 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1754 BAD_SW_IF_INDEX_LABEL;
1757 ("setting HQoS subport parameters without DPDK not implemented");
1758 rv = VNET_API_ERROR_UNIMPLEMENTED;
1761 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1765 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1766 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1768 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1772 dpdk_main_t *dm = &dpdk_main;
1773 vlib_thread_main_t *tm = vlib_get_thread_main ();
1776 u32 sw_if_index = ntohl (mp->sw_if_index);
1777 u32 entry = ntohl (mp->entry);
1778 u32 tc = ntohl (mp->tc);
1779 u32 queue = ntohl (mp->queue);
1782 vnet_hw_interface_t *hw;
1784 VALIDATE_SW_IF_INDEX (mp);
1786 /* hw_if & dpdk device */
1787 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1789 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1791 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1793 clib_warning ("invalid traffic class !!");
1794 rv = VNET_API_ERROR_INVALID_VALUE;
1797 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1799 clib_warning ("invalid queue !!");
1800 rv = VNET_API_ERROR_INVALID_VALUE;
1804 /* Detect the set of worker threads */
1805 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1809 clib_warning ("worker thread registration AWOL !!");
1810 rv = VNET_API_ERROR_INVALID_VALUE_2;
1814 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1815 int worker_thread_first = tr->first_index;
1816 int worker_thread_count = tr->count;
1818 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1819 for (i = 0; i < worker_thread_count; i++)
1820 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1822 BAD_SW_IF_INDEX_LABEL;
1825 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1826 rv = VNET_API_ERROR_UNIMPLEMENTED;
1829 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1833 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1835 vlib_main_t *vm = vlib_get_main ();
1836 bd_main_t *bdm = &bd_main;
1837 vl_api_bridge_domain_add_del_reply_t *rmp;
1839 u32 enable_flags = 0, disable_flags = 0;
1840 u32 bd_id = ntohl (mp->bd_id);
1845 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1848 enable_flags |= L2_FLOOD;
1850 disable_flags |= L2_FLOOD;
1853 enable_flags |= L2_UU_FLOOD;
1855 disable_flags |= L2_UU_FLOOD;
1858 enable_flags |= L2_FWD;
1860 disable_flags |= L2_FWD;
1863 enable_flags |= L2_ARP_TERM;
1865 disable_flags |= L2_ARP_TERM;
1868 enable_flags |= L2_LEARN;
1870 disable_flags |= L2_LEARN;
1873 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1876 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1880 rv = bd_delete_bd_index (bdm, bd_id);
1882 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1886 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1888 clib_warning ("BUG");
1892 vl_api_bridge_domain_sw_if_details_t_handler
1893 (vl_api_bridge_domain_sw_if_details_t * mp)
1895 clib_warning ("BUG");
1899 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1900 l2_bridge_domain_t * bd_config,
1901 u32 n_sw_ifs, u32 context)
1903 vl_api_bridge_domain_details_t *mp;
1905 mp = vl_msg_api_alloc (sizeof (*mp));
1906 memset (mp, 0, sizeof (*mp));
1907 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1908 mp->bd_id = ntohl (bd_config->bd_id);
1909 mp->flood = bd_feature_flood (bd_config);
1910 mp->uu_flood = bd_feature_uu_flood (bd_config);
1911 mp->forward = bd_feature_forward (bd_config);
1912 mp->learn = bd_feature_learn (bd_config);
1913 mp->arp_term = bd_feature_arp_term (bd_config);
1914 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1915 mp->n_sw_ifs = ntohl (n_sw_ifs);
1916 mp->context = context;
1918 vl_msg_api_send_shmem (q, (u8 *) & mp);
1922 send_bd_sw_if_details (l2input_main_t * l2im,
1923 unix_shared_memory_queue_t * q,
1924 l2_flood_member_t * member, u32 bd_id, u32 context)
1926 vl_api_bridge_domain_sw_if_details_t *mp;
1927 l2_input_config_t *input_cfg;
1929 mp = vl_msg_api_alloc (sizeof (*mp));
1930 memset (mp, 0, sizeof (*mp));
1931 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1932 mp->bd_id = ntohl (bd_id);
1933 mp->sw_if_index = ntohl (member->sw_if_index);
1934 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1935 mp->shg = input_cfg->shg;
1936 mp->context = context;
1938 vl_msg_api_send_shmem (q, (u8 *) & mp);
1942 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1944 bd_main_t *bdm = &bd_main;
1945 l2input_main_t *l2im = &l2input_main;
1946 unix_shared_memory_queue_t *q;
1947 l2_bridge_domain_t *bd_config;
1948 u32 bd_id, bd_index;
1951 q = vl_api_client_index_to_input_queue (mp->client_index);
1956 bd_id = ntohl (mp->bd_id);
1958 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1959 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1960 for (; bd_index < end; bd_index++)
1962 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1963 /* skip dummy bd_id 0 */
1964 if (bd_config && (bd_config->bd_id > 0))
1967 l2_flood_member_t *m;
1969 n_sw_ifs = vec_len (bd_config->members);
1970 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1972 vec_foreach (m, bd_config->members)
1974 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1981 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1983 bd_main_t *bdm = &bd_main;
1984 l2input_main_t *l2im = &l2input_main;
1985 vl_api_l2fib_add_del_reply_t *rmp;
1988 u32 sw_if_index = ntohl (mp->sw_if_index);
1989 u32 bd_id = ntohl (mp->bd_id);
1998 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2001 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2002 goto bad_sw_if_index;
2008 VALIDATE_SW_IF_INDEX (mp);
2009 if (vec_len (l2im->configs) <= sw_if_index)
2011 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2012 goto bad_sw_if_index;
2016 l2_input_config_t *config;
2017 config = vec_elt_at_index (l2im->configs, sw_if_index);
2018 if (config->bridge == 0)
2020 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2021 goto bad_sw_if_index;
2024 static_mac = mp->static_mac ? 1 : 0;
2025 filter_mac = mp->filter_mac ? 1 : 0;
2026 bvi_mac = mp->bvi_mac ? 1 : 0;
2027 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
2032 l2fib_del_entry (mac, bd_index);
2035 BAD_SW_IF_INDEX_LABEL;
2037 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
2041 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
2043 vl_api_l2_flags_reply_t *rmp;
2045 u32 sw_if_index = ntohl (mp->sw_if_index);
2046 u32 flags = ntohl (mp->feature_bitmap);
2049 VALIDATE_SW_IF_INDEX (mp);
2052 if (flags & L2INPUT_FEAT_ ## a) \
2053 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
2054 foreach_l2input_feat;
2057 BAD_SW_IF_INDEX_LABEL;
2060 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
2062 rmp->resulting_feature_bitmap = ntohl(rbm);
2068 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
2070 vlib_main_t *vm = vlib_get_main ();
2071 bd_main_t *bdm = &bd_main;
2072 vl_api_bridge_flags_reply_t *rmp;
2074 u32 bd_id = ntohl (mp->bd_id);
2076 u32 flags = ntohl (mp->feature_bitmap);
2079 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2082 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2088 bd_set_flags (vm, bd_index, flags, mp->is_set);
2092 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
2094 rmp->resulting_feature_bitmap = ntohl(flags);
2100 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
2102 bd_main_t *bdm = &bd_main;
2103 vl_api_bd_ip_mac_add_del_reply_t *rmp;
2105 u32 bd_id = ntohl (mp->bd_id);
2109 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
2112 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2117 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
2118 mp->mac_address, mp->is_ipv6, mp->is_add))
2119 rv = VNET_API_ERROR_UNSPECIFIED;
2122 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
2126 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
2129 vl_api_tap_connect_reply_t *rmp;
2130 unix_shared_memory_queue_t *q;
2131 u32 sw_if_index = (u32) ~ 0;
2133 rv = vnet_tap_connect_renumber (vm, 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_CONNECT_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_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
2155 vl_api_tap_modify_reply_t *rmp;
2156 unix_shared_memory_queue_t *q;
2157 u32 sw_if_index = (u32) ~ 0;
2159 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
2160 mp->use_random_mac ? 0 : mp->mac_address,
2161 &sw_if_index, mp->renumber,
2162 ntohl (mp->custom_dev_instance));
2164 q = vl_api_client_index_to_input_queue (mp->client_index);
2168 rmp = vl_msg_api_alloc (sizeof (*rmp));
2169 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
2170 rmp->context = mp->context;
2171 rmp->retval = ntohl (rv);
2172 rmp->sw_if_index = ntohl (sw_if_index);
2174 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2178 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
2181 vpe_api_main_t *vam = &vpe_api_main;
2182 vl_api_tap_delete_reply_t *rmp;
2183 unix_shared_memory_queue_t *q;
2184 u32 sw_if_index = ntohl (mp->sw_if_index);
2186 rv = vnet_tap_delete (vm, sw_if_index);
2188 q = vl_api_client_index_to_input_queue (mp->client_index);
2192 rmp = vl_msg_api_alloc (sizeof (*rmp));
2193 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
2194 rmp->context = mp->context;
2195 rmp->retval = ntohl (rv);
2197 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2200 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2204 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
2206 vl_api_create_vlan_subif_reply_t *rmp;
2207 vnet_main_t *vnm = vnet_get_main ();
2208 u32 hw_if_index, sw_if_index = (u32) ~ 0;
2209 vnet_hw_interface_t *hi;
2212 vnet_sw_interface_t template;
2214 vnet_interface_main_t *im = &vnm->interface_main;
2215 u64 sup_and_sub_key;
2217 unix_shared_memory_queue_t *q;
2218 clib_error_t *error;
2220 VALIDATE_SW_IF_INDEX (mp);
2222 hw_if_index = ntohl (mp->sw_if_index);
2223 hi = vnet_get_hw_interface (vnm, hw_if_index);
2225 id = ntohl (mp->vlan_id);
2226 if (id == 0 || id > 4095)
2228 rv = VNET_API_ERROR_INVALID_VLAN;
2232 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2234 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2237 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2241 kp = clib_mem_alloc (sizeof (*kp));
2242 *kp = sup_and_sub_key;
2244 memset (&template, 0, sizeof (template));
2245 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2246 template.sup_sw_if_index = hi->sw_if_index;
2247 template.sub.id = id;
2248 template.sub.eth.raw_flags = 0;
2249 template.sub.eth.flags.one_tag = 1;
2250 template.sub.eth.outer_vlan_id = id;
2251 template.sub.eth.flags.exact_match = 1;
2253 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2256 clib_error_report (error);
2257 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2260 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2261 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2263 BAD_SW_IF_INDEX_LABEL;
2266 q = vl_api_client_index_to_input_queue (mp->client_index);
2270 rmp = vl_msg_api_alloc (sizeof (*rmp));
2271 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2272 rmp->context = mp->context;
2273 rmp->retval = ntohl (rv);
2274 rmp->sw_if_index = ntohl (sw_if_index);
2275 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2279 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2281 vl_api_create_subif_reply_t *rmp;
2282 vnet_main_t *vnm = vnet_get_main ();
2283 u32 sw_if_index = ~0;
2286 vnet_sw_interface_t *si;
2287 vnet_hw_interface_t *hi;
2288 vnet_sw_interface_t template;
2290 vnet_interface_main_t *im = &vnm->interface_main;
2291 u64 sup_and_sub_key;
2293 clib_error_t *error;
2295 VALIDATE_SW_IF_INDEX (mp);
2297 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2298 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2300 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2302 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2306 sw_if_index = si->sw_if_index;
2307 sub_id = ntohl (mp->sub_id);
2309 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2311 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2315 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2316 sw_if_index, sub_id);
2317 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2321 kp = clib_mem_alloc (sizeof (*kp));
2322 *kp = sup_and_sub_key;
2324 memset (&template, 0, sizeof (template));
2325 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2326 template.sup_sw_if_index = sw_if_index;
2327 template.sub.id = sub_id;
2328 template.sub.eth.flags.no_tags = mp->no_tags;
2329 template.sub.eth.flags.one_tag = mp->one_tag;
2330 template.sub.eth.flags.two_tags = mp->two_tags;
2331 template.sub.eth.flags.dot1ad = mp->dot1ad;
2332 template.sub.eth.flags.exact_match = mp->exact_match;
2333 template.sub.eth.flags.default_sub = mp->default_sub;
2334 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2335 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2336 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2337 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2339 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2342 clib_error_report (error);
2343 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2347 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2348 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2350 BAD_SW_IF_INDEX_LABEL;
2355 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2357 rmp->sw_if_index = ntohl(sw_if_index);
2363 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2364 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2366 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2368 stats_main_t *sm = &stats_main;
2369 u32 tunnel_sw_if_index;
2371 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2373 rv = vnet_mpls_ethernet_add_del_tunnel
2374 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2375 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2376 ntohl (mp->tx_sw_if_index),
2377 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2382 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2384 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2390 * This piece of misery brought to you because the control-plane
2391 * can't figure out the tx interface + dst-mac address all by itself
2393 static int mpls_ethernet_add_del_tunnel_2_t_handler
2394 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2396 pending_route_t *pr;
2397 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2398 vnet_main_t *vnm = vnet_get_main ();
2399 vlib_main_t *vm = vlib_get_main ();
2400 stats_main_t *sm = &stats_main;
2401 vpe_api_main_t *vam = &vpe_api_main;
2402 u32 inner_fib_index, outer_fib_index;
2403 ip4_main_t *im = &ip4_main;
2404 ip_lookup_main_t *lm = &im->lookup_main;
2405 ip_adjacency_t *adj = 0;
2408 u8 *dst_mac_address;
2412 u32 tunnel_sw_if_index;
2414 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2416 return VNET_API_ERROR_NO_SUCH_FIB;
2418 outer_fib_index = p[0];
2421 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2423 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2425 inner_fib_index = p[0];
2427 if (inner_fib_index == outer_fib_index)
2428 return VNET_API_ERROR_INVALID_VALUE;
2431 lookup_result = ip4_fib_table_lookup_lb (ip4_fib_get (outer_fib_index),
2433 mp->next_hop_ip4_address_in_outer_vrf);
2435 adj = ip_get_adjacency (lm, lookup_result);
2436 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2438 if (mp->is_add && mp->resolve_if_needed)
2440 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2442 pool_get (vam->pending_routes, pr);
2443 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2445 clib_memcpy (pme, mp, sizeof (*pme));
2446 /* recursion block, "just in case" */
2447 pme->resolve_if_needed = 0;
2448 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2449 pme->resolve_opaque = tx_sw_if_index;
2450 vnet_register_ip4_arp_resolution_event
2452 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2453 vpe_resolver_process_node.index,
2454 RESOLUTION_EVENT, pr - vam->pending_routes);
2456 vlib_process_signal_event
2457 (vm, vpe_resolver_process_node.index,
2458 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2460 /* The interface may be down, etc. */
2461 e = ip4_probe_neighbor
2462 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2466 clib_error_report (e);
2468 return VNET_API_ERROR_IN_PROGRESS;
2472 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2473 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2476 vnet_rewrite_get_data_internal
2477 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2479 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2481 rv = vnet_mpls_ethernet_add_del_tunnel
2482 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2483 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2484 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2492 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2493 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2495 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2498 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2500 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2505 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2507 vl_api_mpls_add_del_encap_reply_t *rmp;
2512 vec_reset_length (labels);
2514 for (i = 0; i < mp->nlabels; i++)
2515 vec_add1 (labels, ntohl (mp->labels[i]));
2518 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2519 ntohl (mp->vrf_id), labels,
2520 ~0 /* policy_tunnel_index */ ,
2521 0 /* no_dst_hash */ ,
2525 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2529 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2531 vl_api_proxy_arp_add_del_reply_t *rmp;
2534 ip4_main_t *im = &ip4_main;
2535 stats_main_t *sm = &stats_main;
2536 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2537 ip4_address_t * hi_addr,
2538 u32 fib_index, int is_del);
2541 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2543 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2547 rv = VNET_API_ERROR_NO_SUCH_FIB;
2553 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2554 (ip4_address_t *) mp->hi_address,
2555 fib_index, mp->is_add == 0);
2559 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2563 vl_api_proxy_arp_intfc_enable_disable_t_handler
2564 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2567 vnet_main_t *vnm = vnet_get_main ();
2568 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2569 vnet_sw_interface_t *si;
2572 VALIDATE_SW_IF_INDEX (mp);
2574 sw_if_index = ntohl (mp->sw_if_index);
2576 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2578 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2582 si = vnet_get_sw_interface (vnm, sw_if_index);
2586 if (mp->enable_disable)
2587 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2589 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2591 BAD_SW_IF_INDEX_LABEL;
2594 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2598 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2601 vl_api_ip_neighbor_add_del_reply_t *rmp;
2602 vnet_main_t *vnm = vnet_get_main ();
2603 stats_main_t *sm = &stats_main;
2606 VALIDATE_SW_IF_INDEX (mp);
2608 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2611 * there's no validation here of the ND/ARP entry being added.
2612 * The expectation is that the FIB will ensure that nothing bad
2613 * will come of adding bogus entries.
2618 rv = vnet_set_ip6_ethernet_neighbor
2619 (vm, ntohl (mp->sw_if_index),
2620 (ip6_address_t *) (mp->dst_address),
2621 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2623 rv = vnet_unset_ip6_ethernet_neighbor
2624 (vm, ntohl (mp->sw_if_index),
2625 (ip6_address_t *) (mp->dst_address),
2626 mp->mac_address, sizeof (mp->mac_address));
2630 ethernet_arp_ip4_over_ethernet_address_t a;
2632 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2633 clib_memcpy (&a.ip4, mp->dst_address, 4);
2636 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2640 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2643 BAD_SW_IF_INDEX_LABEL;
2646 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2650 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2653 vpe_main_t *rm = &vpe_main;
2654 ip4_main_t *im4 = &ip4_main;
2655 ip6_main_t *im6 = &ip6_main;
2656 ip_lookup_main_t *lm;
2662 u32 adj_index, sw_if_index;
2663 vl_api_is_address_reachable_t *rmp;
2664 ip_adjacency_t *adj;
2665 unix_shared_memory_queue_t *q;
2667 q = vl_api_client_index_to_input_queue (mp->client_index);
2670 increment_missing_api_client_counter (rm->vlib_main);
2674 rmp = vl_msg_api_alloc (sizeof (*rmp));
2675 clib_memcpy (rmp, mp, sizeof (*rmp));
2677 sw_if_index = mp->next_hop_sw_if_index;
2678 clib_memcpy (&addr, mp->address, sizeof (addr));
2681 lm = &im6->lookup_main;
2682 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2686 lm = &im4->lookup_main;
2688 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2690 if (adj_index == ~0)
2695 adj = ip_get_adjacency (lm, adj_index);
2697 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2698 && adj->rewrite_header.sw_if_index == sw_if_index)
2704 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2705 && adj->rewrite_header.sw_if_index == sw_if_index)
2708 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2710 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2712 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2721 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2726 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2728 clib_warning ("BUG");
2732 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2734 vl_api_sw_interface_set_flags_reply_t *rmp;
2735 vnet_main_t *vnm = vnet_get_main ();
2737 clib_error_t *error;
2740 VALIDATE_SW_IF_INDEX (mp);
2742 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2744 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2748 clib_error_report (error);
2751 BAD_SW_IF_INDEX_LABEL;
2752 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2756 vl_api_sw_interface_set_mpls_enable_t_handler
2757 (vl_api_sw_interface_set_mpls_enable_t * mp)
2759 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2762 VALIDATE_SW_IF_INDEX (mp);
2764 mpls_sw_interface_enable_disable (&mpls_main,
2765 ntohl (mp->sw_if_index), mp->enable);
2767 BAD_SW_IF_INDEX_LABEL;
2768 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2772 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2775 vl_api_sw_interface_clear_stats_reply_t *rmp;
2777 vnet_main_t *vnm = vnet_get_main ();
2778 vnet_interface_main_t *im = &vnm->interface_main;
2779 vlib_simple_counter_main_t *sm;
2780 vlib_combined_counter_main_t *cm;
2781 static vnet_main_t **my_vnet_mains;
2782 int i, j, n_counters;
2785 if (mp->sw_if_index != ~0)
2786 VALIDATE_SW_IF_INDEX (mp);
2788 vec_reset_length (my_vnet_mains);
2790 for (i = 0; i < vec_len (vnet_mains); i++)
2793 vec_add1 (my_vnet_mains, vnet_mains[i]);
2796 if (vec_len (vnet_mains) == 0)
2797 vec_add1 (my_vnet_mains, vnm);
2799 n_counters = vec_len (im->combined_sw_if_counters);
2801 for (j = 0; j < n_counters; j++)
2803 for (i = 0; i < vec_len (my_vnet_mains); i++)
2805 im = &my_vnet_mains[i]->interface_main;
2806 cm = im->combined_sw_if_counters + j;
2807 if (mp->sw_if_index == (u32) ~ 0)
2808 vlib_clear_combined_counters (cm);
2810 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2814 n_counters = vec_len (im->sw_if_counters);
2816 for (j = 0; j < n_counters; j++)
2818 for (i = 0; i < vec_len (my_vnet_mains); i++)
2820 im = &my_vnet_mains[i]->interface_main;
2821 sm = im->sw_if_counters + j;
2822 if (mp->sw_if_index == (u32) ~ 0)
2823 vlib_clear_simple_counters (sm);
2825 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2829 BAD_SW_IF_INDEX_LABEL;
2831 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2835 send_sw_interface_details (vpe_api_main_t * am,
2836 unix_shared_memory_queue_t * q,
2837 vnet_sw_interface_t * swif,
2838 u8 * interface_name, u32 context)
2840 vl_api_sw_interface_details_t *mp;
2841 vnet_hw_interface_t *hi;
2843 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2845 mp = vl_msg_api_alloc (sizeof (*mp));
2846 memset (mp, 0, sizeof (*mp));
2847 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2848 mp->sw_if_index = ntohl (swif->sw_if_index);
2849 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2850 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2851 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2852 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2853 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2854 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2855 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2856 mp->link_mtu = ntohs (hi->max_packet_bytes);
2857 mp->context = context;
2859 strncpy ((char *) mp->interface_name,
2860 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2862 /* Send the L2 address for ethernet physical intfcs */
2863 if (swif->sup_sw_if_index == swif->sw_if_index
2864 && hi->hw_class_index == ethernet_hw_interface_class.index)
2866 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2867 ethernet_interface_t *ei;
2869 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2870 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2871 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2872 mp->l2_address_length = ntohl (sizeof (ei->address));
2874 else if (swif->sup_sw_if_index != swif->sw_if_index)
2876 vnet_sub_interface_t *sub = &swif->sub;
2877 mp->sub_id = ntohl (sub->id);
2878 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2879 mp->sub_number_of_tags =
2880 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2881 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2882 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2883 mp->sub_exact_match = sub->eth.flags.exact_match;
2884 mp->sub_default = sub->eth.flags.default_sub;
2885 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2886 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2888 /* vlan tag rewrite data */
2889 u32 vtr_op = L2_VTR_DISABLED;
2890 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2892 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2893 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2895 // error - default to disabled
2896 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2897 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2902 mp->vtr_op = ntohl (vtr_op);
2903 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2904 mp->vtr_tag1 = ntohl (vtr_tag1);
2905 mp->vtr_tag2 = ntohl (vtr_tag2);
2909 vl_msg_api_send_shmem (q, (u8 *) & mp);
2913 send_sw_interface_flags (vpe_api_main_t * am,
2914 unix_shared_memory_queue_t * q,
2915 vnet_sw_interface_t * swif)
2917 vl_api_sw_interface_set_flags_t *mp;
2918 vnet_main_t *vnm = am->vnet_main;
2920 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2922 mp = vl_msg_api_alloc (sizeof (*mp));
2923 memset (mp, 0, sizeof (*mp));
2924 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2925 mp->sw_if_index = ntohl (swif->sw_if_index);
2927 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2928 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2929 vl_msg_api_send_shmem (q, (u8 *) & mp);
2932 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2933 unix_shared_memory_queue_t * q,
2935 __attribute__ ((unused));
2938 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2939 unix_shared_memory_queue_t * q,
2942 vl_api_sw_interface_set_flags_t *mp;
2944 mp = vl_msg_api_alloc (sizeof (*mp));
2945 memset (mp, 0, sizeof (*mp));
2946 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2947 mp->sw_if_index = ntohl (sw_if_index);
2949 mp->admin_up_down = 0;
2950 mp->link_up_down = 0;
2952 vl_msg_api_send_shmem (q, (u8 *) & mp);
2956 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2958 vpe_api_main_t *am = &vpe_api_main;
2959 vnet_sw_interface_t *swif;
2960 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2961 u8 *filter_string = 0, *name_string = 0;
2962 unix_shared_memory_queue_t *q;
2963 char *strcasestr (char *, char *); /* lnx hdr file botch */
2965 q = vl_api_client_index_to_input_queue (mp->client_index);
2970 if (mp->name_filter_valid)
2972 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2973 filter_string = format (0, "%s%c", mp->name_filter, 0);
2977 pool_foreach (swif, im->sw_interfaces,
2979 name_string = format (name_string, "%U%c",
2980 format_vnet_sw_interface_name,
2981 am->vnet_main, swif, 0);
2983 if (mp->name_filter_valid == 0 ||
2984 strcasestr((char *) name_string, (char *) filter_string)) {
2986 send_sw_interface_details (am, q, swif, name_string, mp->context);
2988 _vec_len (name_string) = 0;
2992 vec_free (name_string);
2993 vec_free (filter_string);
2997 send_oam_event (oam_target_t * t)
2999 vpe_api_main_t *vam = &vpe_api_main;
3000 unix_shared_memory_queue_t *q;
3001 vpe_client_registration_t *reg;
3002 vl_api_oam_event_t *mp;
3005 pool_foreach(reg, vam->oam_events_registrations,
3007 q = vl_api_client_index_to_input_queue (reg->client_index);
3010 mp = vl_msg_api_alloc (sizeof (*mp));
3011 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
3012 clib_memcpy (mp->dst_address, &t->dst_address,
3013 sizeof (mp->dst_address));
3014 mp->state = t->state;
3015 vl_msg_api_send_shmem (q, (u8 *)&mp);
3022 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
3024 vl_api_oam_add_del_reply_t *rmp;
3027 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
3028 (ip4_address_t *) mp->dst_address,
3029 ntohl (mp->vrf_id), (int) (mp->is_add));
3031 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
3035 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
3037 stats_main_t *sm = &stats_main;
3038 vnet_interface_main_t *im = sm->interface_main;
3039 vl_api_vnet_summary_stats_reply_t *rmp;
3040 vlib_combined_counter_main_t *cm;
3043 u64 total_pkts[VLIB_N_RX_TX];
3044 u64 total_bytes[VLIB_N_RX_TX];
3046 unix_shared_memory_queue_t *q =
3047 vl_api_client_index_to_input_queue (mp->client_index);
3052 rmp = vl_msg_api_alloc (sizeof (*rmp));
3053 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
3054 rmp->context = mp->context;
3057 memset (total_pkts, 0, sizeof (total_pkts));
3058 memset (total_bytes, 0, sizeof (total_bytes));
3060 vnet_interface_counter_lock (im);
3062 vec_foreach (cm, im->combined_sw_if_counters)
3064 which = cm - im->combined_sw_if_counters;
3066 for (i = 0; i < vec_len (cm->maxi); i++)
3068 vlib_get_combined_counter (cm, i, &v);
3069 total_pkts[which] += v.packets;
3070 total_bytes[which] += v.bytes;
3073 vnet_interface_counter_unlock (im);
3075 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
3076 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
3077 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
3078 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
3080 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
3082 vl_msg_api_send_shmem (q, (u8 *) & rmp);
3086 typedef CLIB_PACKED (struct {
3087 ip4_address_t address;
3088 u32 address_length: 6;
3094 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3096 vnet_main_t *vnm = vnet_get_main ();
3097 vnet_interface_main_t *im = &vnm->interface_main;
3098 ip4_main_t *im4 = &ip4_main;
3099 static u32 *sw_if_indices_to_shut;
3100 stats_main_t *sm = &stats_main;
3101 fib_table_t *fib_table;
3105 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3106 u32 target_fib_id = ntohl (mp->vrf_id);
3108 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
3111 pool_foreach (fib_table, im4->fibs,
3113 fib = &fib_table->v4;
3114 vnet_sw_interface_t * si;
3116 if (fib->table_id != target_fib_id)
3119 /* remove any mpls encap/decap labels */
3120 mpls_fib_reset_labels (fib->table_id);
3122 /* remove any proxy arps in this fib */
3123 vnet_proxy_arp_fib_reset (fib->table_id);
3125 /* Set the flow hash for this fib to the default */
3126 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3128 vec_reset_length (sw_if_indices_to_shut);
3130 /* Shut down interfaces in this FIB / clean out intfc routes */
3131 pool_foreach (si, im->sw_interfaces,
3133 u32 sw_if_index = si->sw_if_index;
3135 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
3136 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
3138 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3141 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3142 sw_if_index = sw_if_indices_to_shut[i];
3143 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3145 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3146 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3147 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3150 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
3151 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
3155 })); /* pool_foreach (fib) */
3163 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3165 vnet_main_t *vnm = vnet_get_main ();
3166 vnet_interface_main_t *im = &vnm->interface_main;
3167 ip6_main_t *im6 = &ip6_main;
3168 stats_main_t *sm = &stats_main;
3169 static u32 *sw_if_indices_to_shut;
3170 fib_table_t *fib_table;
3174 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3175 u32 target_fib_id = ntohl (mp->vrf_id);
3177 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3180 pool_foreach (fib_table, im6->fibs,
3182 vnet_sw_interface_t * si;
3183 fib = &(fib_table->v6);
3185 if (fib->table_id != target_fib_id)
3188 vec_reset_length (sw_if_indices_to_shut);
3190 /* Shut down interfaces in this FIB / clean out intfc routes */
3191 pool_foreach (si, im->sw_interfaces,
3193 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3195 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3198 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3199 sw_if_index = sw_if_indices_to_shut[i];
3200 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3202 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3203 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3204 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3207 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
3208 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
3212 })); /* pool_foreach (fib) */
3220 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3223 vl_api_reset_fib_reply_t *rmp;
3226 rv = ip6_reset_fib_t_handler (mp);
3228 rv = ip4_reset_fib_t_handler (mp);
3230 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3235 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3237 vl_api_dhcp_proxy_config_reply_t *rmp;
3240 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3241 (ip4_address_t *) (&mp->dhcp_src_address),
3242 (u32) ntohl (mp->vrf_id),
3243 (int) mp->insert_circuit_id,
3244 (int) (mp->is_add == 0));
3246 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3251 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3253 vl_api_dhcp_proxy_config_reply_t *rmp;
3256 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3257 (ip6_address_t *) (&mp->dhcp_src_address),
3258 (u32) ntohl (mp->vrf_id),
3259 (int) mp->insert_circuit_id,
3260 (int) (mp->is_add == 0));
3262 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3266 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3268 vl_api_dhcp_proxy_config_reply_t *rmp;
3271 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3272 (ip4_address_t *) (&mp->dhcp_src_address),
3273 (u32) ntohl (mp->rx_vrf_id),
3274 (u32) ntohl (mp->server_vrf_id),
3275 (int) mp->insert_circuit_id,
3276 (int) (mp->is_add == 0));
3278 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3283 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3285 vl_api_dhcp_proxy_config_reply_t *rmp;
3289 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3290 (ip6_address_t *) (&mp->dhcp_src_address),
3291 (u32) ntohl (mp->rx_vrf_id),
3292 (u32) ntohl (mp->server_vrf_id),
3293 (int) mp->insert_circuit_id,
3294 (int) (mp->is_add == 0));
3296 rv = VNET_API_ERROR_UNIMPLEMENTED;
3299 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3304 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3306 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3309 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3312 (int) mp->is_add == 0);
3314 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3316 ntohl (mp->fib_id), (int) mp->is_add == 0);
3318 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3322 static void vl_api_dhcp_proxy_config_t_handler
3323 (vl_api_dhcp_proxy_config_t * mp)
3325 if (mp->is_ipv6 == 0)
3326 dhcpv4_proxy_config (mp);
3328 dhcpv6_proxy_config (mp);
3331 static void vl_api_dhcp_proxy_config_2_t_handler
3332 (vl_api_dhcp_proxy_config_2_t * mp)
3334 if (mp->is_ipv6 == 0)
3335 dhcpv4_proxy_config_2 (mp);
3337 dhcpv6_proxy_config_2 (mp);
3341 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3342 u8 is_ipv6, u8 * host_address, u8 * router_address,
3345 unix_shared_memory_queue_t *q;
3346 vl_api_dhcp_compl_event_t *mp;
3348 q = vl_api_client_index_to_input_queue (client_index);
3352 mp = vl_msg_api_alloc (sizeof (*mp));
3353 mp->client_index = client_index;
3355 mp->is_ipv6 = is_ipv6;
3356 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3357 mp->hostname[vec_len (hostname) + 1] = '\n';
3358 clib_memcpy (&mp->host_address[0], host_address, 16);
3359 clib_memcpy (&mp->router_address[0], router_address, 16);
3361 if (NULL != host_mac)
3362 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3364 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3366 vl_msg_api_send_shmem (q, (u8 *) & mp);
3369 static void vl_api_dhcp_client_config_t_handler
3370 (vl_api_dhcp_client_config_t * mp)
3372 vlib_main_t *vm = vlib_get_main ();
3373 vl_api_dhcp_client_config_reply_t *rmp;
3376 VALIDATE_SW_IF_INDEX (mp);
3378 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3379 mp->hostname, mp->is_add, mp->client_index,
3380 mp->want_dhcp_event ? dhcp_compl_event_callback :
3383 BAD_SW_IF_INDEX_LABEL;
3385 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3389 vl_api_sw_interface_ip6nd_ra_config_t_handler
3390 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3392 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3394 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3397 is_no = mp->is_no == 1;
3398 suppress = mp->suppress == 1;
3399 managed = mp->managed == 1;
3400 other = mp->other == 1;
3401 ll_option = mp->ll_option == 1;
3402 send_unicast = mp->send_unicast == 1;
3403 cease = mp->cease == 1;
3404 default_router = mp->default_router == 1;
3406 VALIDATE_SW_IF_INDEX (mp);
3408 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3409 suppress, managed, other,
3410 ll_option, send_unicast, cease,
3411 default_router, ntohl (mp->lifetime),
3412 ntohl (mp->initial_count),
3413 ntohl (mp->initial_interval),
3414 ntohl (mp->max_interval),
3415 ntohl (mp->min_interval), is_no);
3417 BAD_SW_IF_INDEX_LABEL;
3419 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3423 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3424 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3426 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3428 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3430 VALIDATE_SW_IF_INDEX (mp);
3432 is_no = mp->is_no == 1;
3433 use_default = mp->use_default == 1;
3434 no_advertise = mp->no_advertise == 1;
3435 off_link = mp->off_link == 1;
3436 no_autoconfig = mp->no_autoconfig == 1;
3437 no_onlink = mp->no_onlink == 1;
3439 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3440 (ip6_address_t *) mp->address,
3441 mp->address_length, use_default,
3442 ntohl (mp->val_lifetime),
3443 ntohl (mp->pref_lifetime), no_advertise,
3444 off_link, no_autoconfig, no_onlink, is_no);
3446 BAD_SW_IF_INDEX_LABEL;
3447 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3451 vl_api_sw_interface_ip6_enable_disable_t_handler
3452 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3454 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3455 vnet_main_t *vnm = vnet_get_main ();
3457 clib_error_t *error;
3461 VALIDATE_SW_IF_INDEX (mp);
3464 (mp->enable == 1) ? enable_ip6_interface (vm,
3465 ntohl (mp->sw_if_index)) :
3466 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3470 clib_error_report (error);
3471 rv = VNET_API_ERROR_UNSPECIFIED;
3475 rv = vnm->api_errno;
3478 BAD_SW_IF_INDEX_LABEL;
3480 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3484 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3485 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3487 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3489 clib_error_t *error;
3490 vnet_main_t *vnm = vnet_get_main ();
3494 VALIDATE_SW_IF_INDEX (mp);
3496 error = set_ip6_link_local_address (vm,
3497 ntohl (mp->sw_if_index),
3498 (ip6_address_t *) mp->address,
3499 mp->address_length);
3502 clib_error_report (error);
3503 rv = VNET_API_ERROR_UNSPECIFIED;
3507 rv = vnm->api_errno;
3510 BAD_SW_IF_INDEX_LABEL;
3512 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3516 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3518 vl_api_set_ip_flow_hash_reply_t *rmp;
3519 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3521 clib_warning ("unimplemented...");
3523 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3527 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3529 vl_api_set_ip_flow_hash_reply_t *rmp;
3532 flow_hash_config_t flow_hash_config = 0;
3534 table_id = ntohl (mp->vrf_id);
3536 #define _(a,b) if (mp->a) flow_hash_config |= b;
3537 foreach_flow_hash_bit;
3540 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3542 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3547 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3549 if (mp->is_ipv6 == 0)
3550 set_ip4_flow_hash (mp);
3552 set_ip6_flow_hash (mp);
3555 static void vl_api_sw_interface_set_unnumbered_t_handler
3556 (vl_api_sw_interface_set_unnumbered_t * mp)
3558 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3560 vnet_sw_interface_t *si;
3561 vnet_main_t *vnm = vnet_get_main ();
3562 u32 sw_if_index, unnumbered_sw_if_index;
3564 sw_if_index = ntohl (mp->sw_if_index);
3565 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3568 * The API message field names are backwards from
3569 * the underlying data structure names.
3570 * It's not worth changing them now.
3572 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3573 unnumbered_sw_if_index))
3575 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3579 /* Only check the "use loop0" field when setting the binding */
3581 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3583 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3587 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3591 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3592 si->unnumbered_sw_if_index = sw_if_index;
3593 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3594 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3598 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3599 si->unnumbered_sw_if_index = (u32) ~ 0;
3600 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3601 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3605 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3609 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3611 vl_api_create_loopback_reply_t *rmp;
3615 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3618 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3620 rmp->sw_if_index = ntohl (sw_if_index);
3626 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3628 vl_api_delete_loopback_reply_t *rmp;
3632 sw_if_index = ntohl (mp->sw_if_index);
3633 rv = vnet_delete_loopback_interface (sw_if_index);
3635 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3639 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3641 vl_api_control_ping_reply_t *rmp;
3645 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3647 rmp->vpe_pid = ntohl (getpid());
3653 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3655 u8 **shmem_vecp = (u8 **) arg;
3658 api_main_t *am = &api_main;
3661 shmem_vec = *shmem_vecp;
3663 offset = vec_len (shmem_vec);
3665 pthread_mutex_lock (&am->vlib_rp->mutex);
3666 oldheap = svm_push_data_heap (am->vlib_rp);
3668 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3670 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3672 svm_pop_heap (oldheap);
3673 pthread_mutex_unlock (&am->vlib_rp->mutex);
3675 *shmem_vecp = shmem_vec;
3680 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3682 vl_api_cli_reply_t *rp;
3683 unix_shared_memory_queue_t *q;
3684 vlib_main_t *vm = vlib_get_main ();
3685 api_main_t *am = &api_main;
3686 unformat_input_t input;
3690 q = vl_api_client_index_to_input_queue (mp->client_index);
3694 rp = vl_msg_api_alloc (sizeof (*rp));
3695 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3696 rp->context = mp->context;
3698 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3700 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3702 pthread_mutex_lock (&am->vlib_rp->mutex);
3703 oldheap = svm_push_data_heap (am->vlib_rp);
3705 vec_add1 (shmem_vec, 0);
3707 svm_pop_heap (oldheap);
3708 pthread_mutex_unlock (&am->vlib_rp->mutex);
3710 rp->reply_in_shmem = (uword) shmem_vec;
3712 vl_msg_api_send_shmem (q, (u8 *) & rp);
3716 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3718 u8 **mem_vecp = (u8 **) arg;
3719 u8 *mem_vec = *mem_vecp;
3720 u32 offset = vec_len (mem_vec);
3722 vec_validate (mem_vec, offset + buffer_bytes - 1);
3723 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3724 *mem_vecp = mem_vec;
3728 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3730 vl_api_cli_inband_reply_t *rmp;
3732 unix_shared_memory_queue_t *q;
3733 vlib_main_t *vm = vlib_get_main ();
3734 unformat_input_t input;
3737 q = vl_api_client_index_to_input_queue (mp->client_index);
3741 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3742 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3744 u32 len = vec_len (out_vec);
3746 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3748 rmp->length = htonl (len);
3749 clib_memcpy (rmp->reply, out_vec, len);
3756 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3759 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3760 vnet_main_t *vnm = vnet_get_main ();
3761 clib_error_t *error;
3766 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3768 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3772 clib_error_report (error);
3773 rv = VNET_API_ERROR_UNSPECIFIED;
3777 rv = vnm->api_errno;
3780 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3783 static void vl_api_sr_tunnel_add_del_t_handler
3784 (vl_api_sr_tunnel_add_del_t * mp)
3787 clib_warning ("unimplemented");
3789 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3791 vl_api_sr_tunnel_add_del_reply_t *rmp;
3792 ip6_address_t *segments = 0, *seg;
3793 ip6_address_t *tags = 0, *tag;
3794 ip6_address_t *this_address;
3797 if (mp->n_segments == 0)
3803 memset (a, 0, sizeof (*a));
3804 a->src_address = (ip6_address_t *) & mp->src_address;
3805 a->dst_address = (ip6_address_t *) & mp->dst_address;
3806 a->dst_mask_width = mp->dst_mask_width;
3807 a->flags_net_byte_order = mp->flags_net_byte_order;
3808 a->is_del = (mp->is_add == 0);
3809 a->rx_table_id = ntohl (mp->outer_vrf_id);
3810 a->tx_table_id = ntohl (mp->inner_vrf_id);
3812 a->name = format (0, "%s", mp->name);
3813 if (!(vec_len (a->name)))
3816 a->policy_name = format (0, "%s", mp->policy_name);
3817 if (!(vec_len (a->policy_name)))
3820 /* Yank segments and tags out of the API message */
3821 this_address = (ip6_address_t *) mp->segs_and_tags;
3822 for (i = 0; i < mp->n_segments; i++)
3824 vec_add2 (segments, seg, 1);
3825 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3828 for (i = 0; i < mp->n_tags; i++)
3830 vec_add2 (tags, tag, 1);
3831 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3835 a->segments = segments;
3838 rv = ip6_sr_add_del_tunnel (a);
3842 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3846 static void vl_api_sr_policy_add_del_t_handler
3847 (vl_api_sr_policy_add_del_t * mp)
3850 clib_warning ("unimplemented");
3852 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3854 vl_api_sr_policy_add_del_reply_t *rmp;
3857 memset (a, 0, sizeof (*a));
3858 a->is_del = (mp->is_add == 0);
3860 a->name = format (0, "%s", mp->name);
3861 if (!(vec_len (a->name)))
3863 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3867 if (!(mp->tunnel_names[0]))
3869 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3873 // start deserializing tunnel_names
3874 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3875 u8 *deser_tun_names = mp->tunnel_names;
3876 deser_tun_names += 1; //moving along
3879 int tun_name_len = 0;
3881 for (i = 0; i < num_tunnels; i++)
3883 tun_name_len = *deser_tun_names;
3884 deser_tun_names += 1;
3885 vec_resize (tun_name, tun_name_len);
3886 memcpy (tun_name, deser_tun_names, tun_name_len);
3887 vec_add1 (a->tunnel_names, tun_name);
3888 deser_tun_names += tun_name_len;
3892 rv = ip6_sr_add_del_policy (a);
3896 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3900 static void vl_api_sr_multicast_map_add_del_t_handler
3901 (vl_api_sr_multicast_map_add_del_t * mp)
3904 clib_warning ("unimplemented");
3906 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3908 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3910 memset (a, 0, sizeof (*a));
3911 a->is_del = (mp->is_add == 0);
3913 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3914 a->policy_name = format (0, "%s", mp->policy_name);
3916 if (a->multicast_address == 0)
3922 if (!(a->policy_name))
3928 #if DPDK > 0 /* Cannot call replicate without DPDK */
3929 rv = ip6_sr_add_del_multicastmap (a);
3931 clib_warning ("multicast replication without DPDK not implemented");
3932 rv = VNET_API_ERROR_UNIMPLEMENTED;
3937 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3941 #define foreach_classify_add_del_table_field \
3946 _(match_n_vectors) \
3947 _(next_table_index) \
3950 static void vl_api_classify_add_del_table_t_handler
3951 (vl_api_classify_add_del_table_t * mp)
3953 vl_api_classify_add_del_table_reply_t *rmp;
3954 vnet_classify_main_t *cm = &vnet_classify_main;
3955 vnet_classify_table_t *t;
3959 foreach_classify_add_del_table_field;
3962 #define _(a) a = ntohl(mp->a);
3963 foreach_classify_add_del_table_field;
3966 /* The underlying API fails silently, on purpose, so check here */
3967 if (mp->is_add == 0)
3968 if (pool_is_free_index (cm->tables, table_index))
3970 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3974 rv = vnet_classify_add_del_table
3975 (cm, mp->mask, nbuckets, memory_size,
3976 skip_n_vectors, match_n_vectors,
3977 next_table_index, miss_next_index, &table_index, mp->is_add);
3981 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3983 if (rv == 0 && mp->is_add)
3985 t = pool_elt_at_index (cm->tables, table_index);
3986 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3987 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3988 rmp->new_table_index = ntohl(table_index);
3992 rmp->skip_n_vectors = ~0;
3993 rmp->match_n_vectors = ~0;
3994 rmp->new_table_index = ~0;
4000 static void vl_api_classify_add_del_session_t_handler
4001 (vl_api_classify_add_del_session_t * mp)
4003 vnet_classify_main_t *cm = &vnet_classify_main;
4004 vl_api_classify_add_del_session_reply_t *rmp;
4006 u32 table_index, hit_next_index, opaque_index;
4009 table_index = ntohl (mp->table_index);
4010 hit_next_index = ntohl (mp->hit_next_index);
4011 opaque_index = ntohl (mp->opaque_index);
4012 advance = ntohl (mp->advance);
4014 rv = vnet_classify_add_del_session
4015 (cm, table_index, mp->match, hit_next_index, opaque_index,
4016 advance, mp->is_add);
4018 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
4021 static void vl_api_classify_set_interface_ip_table_t_handler
4022 (vl_api_classify_set_interface_ip_table_t * mp)
4024 vlib_main_t *vm = vlib_get_main ();
4025 vl_api_classify_set_interface_ip_table_reply_t *rmp;
4027 u32 table_index, sw_if_index;
4029 table_index = ntohl (mp->table_index);
4030 sw_if_index = ntohl (mp->sw_if_index);
4032 VALIDATE_SW_IF_INDEX (mp);
4035 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
4037 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
4039 BAD_SW_IF_INDEX_LABEL;
4041 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
4044 static void vl_api_classify_set_interface_l2_tables_t_handler
4045 (vl_api_classify_set_interface_l2_tables_t * mp)
4047 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
4049 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
4052 ip4_table_index = ntohl (mp->ip4_table_index);
4053 ip6_table_index = ntohl (mp->ip6_table_index);
4054 other_table_index = ntohl (mp->other_table_index);
4055 sw_if_index = ntohl (mp->sw_if_index);
4057 VALIDATE_SW_IF_INDEX (mp);
4060 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
4064 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
4070 if (ip4_table_index != ~0 || ip6_table_index != ~0
4071 || other_table_index != ~0)
4077 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
4079 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
4082 BAD_SW_IF_INDEX_LABEL;
4084 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
4088 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
4091 vl_api_l2_fib_clear_table_reply_t *rmp;
4093 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
4094 * that is not currently implemented. When that TODO is fixed
4095 * this call should be changed to pass 1 instead of 0.
4097 l2fib_clear_table (0);
4099 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
4102 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
4103 u32 sw_if_index, u32 enable);
4106 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
4110 vl_api_l2_interface_efp_filter_reply_t *rmp;
4111 vnet_main_t *vnm = vnet_get_main ();
4113 // enable/disable the feature
4114 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
4115 rv = vnm->api_errno;
4117 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
4121 vl_api_l2_interface_vlan_tag_rewrite_t_handler
4122 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
4125 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
4126 vnet_main_t *vnm = vnet_get_main ();
4127 vlib_main_t *vm = vlib_get_main ();
4130 VALIDATE_SW_IF_INDEX (mp);
4132 vtr_op = ntohl (mp->vtr_op);
4134 /* The L2 code is unsuspicious */
4137 case L2_VTR_DISABLED:
4142 case L2_VTR_TRANSLATE_1_1:
4143 case L2_VTR_TRANSLATE_1_2:
4144 case L2_VTR_TRANSLATE_2_1:
4145 case L2_VTR_TRANSLATE_2_2:
4149 rv = VNET_API_ERROR_INVALID_VALUE;
4150 goto bad_sw_if_index;
4153 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4154 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4157 BAD_SW_IF_INDEX_LABEL;
4159 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4163 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4166 vl_api_create_vhost_user_if_reply_t *rmp;
4167 u32 sw_if_index = (u32) ~ 0;
4169 vnet_main_t *vnm = vnet_get_main ();
4170 vlib_main_t *vm = vlib_get_main ();
4172 #if DPDK > 0 && DPDK_VHOST_USER
4173 rv = dpdk_vhost_user_create_if (
4175 rv = vhost_user_create_if (
4177 vnm, vm, (char *) mp->sock_filename,
4178 mp->is_server, &sw_if_index, (u64) ~ 0,
4179 mp->renumber, ntohl (mp->custom_dev_instance),
4180 (mp->use_custom_mac) ? mp->mac_address : NULL);
4183 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4185 rmp->sw_if_index = ntohl (sw_if_index);
4191 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4194 vl_api_modify_vhost_user_if_reply_t *rmp;
4195 u32 sw_if_index = ntohl (mp->sw_if_index);
4197 vnet_main_t *vnm = vnet_get_main ();
4198 vlib_main_t *vm = vlib_get_main ();
4200 #if DPDK > 0 && DPDK_VHOST_USER
4201 rv = dpdk_vhost_user_modify_if (
4203 rv = vhost_user_modify_if (
4205 vnm, vm, (char *) mp->sock_filename,
4206 mp->is_server, sw_if_index, (u64) ~ 0,
4207 mp->renumber, ntohl (mp->custom_dev_instance));
4208 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4212 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4215 vl_api_delete_vhost_user_if_reply_t *rmp;
4216 vpe_api_main_t *vam = &vpe_api_main;
4217 u32 sw_if_index = ntohl (mp->sw_if_index);
4219 vnet_main_t *vnm = vnet_get_main ();
4220 vlib_main_t *vm = vlib_get_main ();
4222 #if DPDK > 0 && DPDK_VHOST_USER
4223 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4225 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4228 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4231 unix_shared_memory_queue_t *q =
4232 vl_api_client_index_to_input_queue (mp->client_index);
4236 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4241 vl_api_sw_interface_vhost_user_details_t_handler
4242 (vl_api_sw_interface_vhost_user_details_t * mp)
4244 clib_warning ("BUG");
4248 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4249 unix_shared_memory_queue_t * q,
4250 vhost_user_intf_details_t * vui,
4253 vl_api_sw_interface_vhost_user_details_t *mp;
4255 mp = vl_msg_api_alloc (sizeof (*mp));
4256 memset (mp, 0, sizeof (*mp));
4257 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4258 mp->sw_if_index = ntohl (vui->sw_if_index);
4259 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4260 mp->features = clib_net_to_host_u64 (vui->features);
4261 mp->is_server = vui->is_server;
4262 mp->num_regions = ntohl (vui->num_regions);
4263 mp->sock_errno = ntohl (vui->sock_errno);
4264 mp->context = context;
4266 strncpy ((char *) mp->sock_filename,
4267 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4268 strncpy ((char *) mp->interface_name,
4269 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4271 vl_msg_api_send_shmem (q, (u8 *) & mp);
4275 vl_api_sw_interface_vhost_user_dump_t_handler
4276 (vl_api_sw_interface_vhost_user_dump_t * mp)
4279 vpe_api_main_t *am = &vpe_api_main;
4280 vnet_main_t *vnm = vnet_get_main ();
4281 vlib_main_t *vm = vlib_get_main ();
4282 vhost_user_intf_details_t *ifaces = NULL;
4283 vhost_user_intf_details_t *vuid = NULL;
4284 unix_shared_memory_queue_t *q;
4286 q = vl_api_client_index_to_input_queue (mp->client_index);
4290 #if DPDK > 0 && DPDK_VHOST_USER
4291 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4293 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4298 vec_foreach (vuid, ifaces)
4300 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4306 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4307 unix_shared_memory_queue_t * q,
4309 l2t_main_t * lm, u32 context)
4311 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4313 vnet_sw_interface_t *si = NULL;
4315 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4317 if_name = format (if_name, "%U",
4318 format_vnet_sw_interface_name, lm->vnet_main, si);
4320 mp = vl_msg_api_alloc (sizeof (*mp));
4321 memset (mp, 0, sizeof (*mp));
4322 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4323 strncpy ((char *) mp->interface_name,
4324 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4325 mp->sw_if_index = ntohl (si->sw_if_index);
4326 mp->local_session_id = s->local_session_id;
4327 mp->remote_session_id = s->remote_session_id;
4328 mp->local_cookie[0] = s->local_cookie[0];
4329 mp->local_cookie[1] = s->local_cookie[1];
4330 mp->remote_cookie = s->remote_cookie;
4331 clib_memcpy (mp->client_address, &s->client_address,
4332 sizeof (s->client_address));
4333 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4334 mp->l2_sublayer_present = s->l2_sublayer_present;
4335 mp->context = context;
4337 vl_msg_api_send_shmem (q, (u8 *) & mp);
4341 send_ip_address_details (vpe_api_main_t * am,
4342 unix_shared_memory_queue_t * q,
4343 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4345 vl_api_ip_address_details_t *mp;
4347 mp = vl_msg_api_alloc (sizeof (*mp));
4348 memset (mp, 0, sizeof (*mp));
4349 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4353 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4357 u32 *tp = (u32 *) mp->ip;
4358 *tp = ntohl (*(u32 *) ip);
4360 mp->prefix_length = prefix_length;
4361 mp->context = context;
4363 vl_msg_api_send_shmem (q, (u8 *) & mp);
4367 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4369 vpe_api_main_t *am = &vpe_api_main;
4370 unix_shared_memory_queue_t *q;
4373 ip6_main_t *im6 = &ip6_main;
4374 ip4_main_t *im4 = &ip4_main;
4375 ip_lookup_main_t *lm6 = &im6->lookup_main;
4376 ip_lookup_main_t *lm4 = &im4->lookup_main;
4377 ip_interface_address_t *ia = 0;
4378 u32 sw_if_index = ~0;
4379 int rv __attribute__ ((unused)) = 0;
4381 VALIDATE_SW_IF_INDEX (mp);
4383 sw_if_index = ntohl (mp->sw_if_index);
4385 q = vl_api_client_index_to_input_queue (mp->client_index);
4394 foreach_ip_interface_address (lm6, ia, sw_if_index,
4395 1 /* honor unnumbered */,
4397 r6 = ip_interface_address_get_address (lm6, ia);
4398 u16 prefix_length = ia->address_length;
4399 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4406 foreach_ip_interface_address (lm4, ia, sw_if_index,
4407 1 /* honor unnumbered */,
4409 r4 = ip_interface_address_get_address (lm4, ia);
4410 u16 prefix_length = ia->address_length;
4411 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4415 BAD_SW_IF_INDEX_LABEL;
4419 send_ip_details (vpe_api_main_t * am,
4420 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4422 vl_api_ip_details_t *mp;
4424 mp = vl_msg_api_alloc (sizeof (*mp));
4425 memset (mp, 0, sizeof (*mp));
4426 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4428 mp->sw_if_index = ntohl (sw_if_index);
4429 mp->context = context;
4431 vl_msg_api_send_shmem (q, (u8 *) & mp);
4435 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4438 vpe_api_main_t *am = &vpe_api_main;
4439 l2t_main_t *lm = &l2t_main;
4440 unix_shared_memory_queue_t *q;
4441 l2t_session_t *session;
4443 q = vl_api_client_index_to_input_queue (mp->client_index);
4448 pool_foreach (session, lm->sessions,
4450 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4457 send_sw_interface_tap_details (vpe_api_main_t * am,
4458 unix_shared_memory_queue_t * q,
4459 tapcli_interface_details_t * tap_if,
4462 vl_api_sw_interface_tap_details_t *mp;
4463 mp = vl_msg_api_alloc (sizeof (*mp));
4464 memset (mp, 0, sizeof (*mp));
4465 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4466 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4467 strncpy ((char *) mp->dev_name,
4468 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4469 mp->context = context;
4471 vl_msg_api_send_shmem (q, (u8 *) & mp);
4475 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4478 vpe_api_main_t *am = &vpe_api_main;
4479 unix_shared_memory_queue_t *q;
4480 tapcli_interface_details_t *tapifs = NULL;
4481 tapcli_interface_details_t *tap_if = NULL;
4483 q = vl_api_client_index_to_input_queue (mp->client_index);
4487 rv = vnet_tap_dump_ifs (&tapifs);
4491 vec_foreach (tap_if, tapifs)
4493 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4500 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4502 vpe_api_main_t *am = &vpe_api_main;
4503 vnet_main_t *vnm = vnet_get_main ();
4504 vlib_main_t *vm = vlib_get_main ();
4505 vnet_interface_main_t *im = &vnm->interface_main;
4506 unix_shared_memory_queue_t *q;
4507 vnet_sw_interface_t *si, *sorted_sis;
4508 u32 sw_if_index = ~0;
4510 q = vl_api_client_index_to_input_queue (mp->client_index);
4516 /* Gather interfaces. */
4517 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4518 _vec_len (sorted_sis) = 0;
4520 pool_foreach (si, im->sw_interfaces,
4522 vec_add1 (sorted_sis, si[0]);
4526 vec_foreach (si, sorted_sis)
4528 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4530 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4534 sw_if_index = si->sw_if_index;
4535 send_ip_details (am, q, sw_if_index, mp->context);
4541 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4543 clib_warning ("BUG");
4547 send_l2fib_table_entry (vpe_api_main_t * am,
4548 unix_shared_memory_queue_t * q,
4549 l2fib_entry_key_t * l2fe_key,
4550 l2fib_entry_result_t * l2fe_res, u32 context)
4552 vl_api_l2_fib_table_entry_t *mp;
4554 mp = vl_msg_api_alloc (sizeof (*mp));
4555 memset (mp, 0, sizeof (*mp));
4556 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4559 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4561 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4562 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4563 mp->static_mac = l2fe_res->fields.static_mac;
4564 mp->filter_mac = l2fe_res->fields.filter;
4565 mp->bvi_mac = l2fe_res->fields.bvi;
4566 mp->context = context;
4568 vl_msg_api_send_shmem (q, (u8 *) & mp);
4572 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4574 vpe_api_main_t *am = &vpe_api_main;
4575 bd_main_t *bdm = &bd_main;
4576 l2fib_entry_key_t *l2fe_key = NULL;
4577 l2fib_entry_result_t *l2fe_res = NULL;
4578 u32 ni, bd_id = ntohl (mp->bd_id);
4580 unix_shared_memory_queue_t *q;
4583 q = vl_api_client_index_to_input_queue (mp->client_index);
4587 /* see l2fib_table_dump: ~0 means "any" */
4592 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4599 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4601 vec_foreach_index (ni, l2fe_key)
4603 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4604 vec_elt_at_index (l2fe_res, ni), mp->context);
4606 vec_free (l2fe_key);
4607 vec_free (l2fe_res);
4611 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4613 vl_api_show_version_reply_t *rmp;
4615 char *vpe_api_get_build_directory (void);
4616 char *vpe_api_get_version (void);
4617 char *vpe_api_get_build_date (void);
4619 unix_shared_memory_queue_t *q =
4620 vl_api_client_index_to_input_queue (mp->client_index);
4626 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4628 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4629 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4630 ARRAY_LEN(rmp->build_directory)-1);
4631 strncpy ((char *) rmp->version, vpe_api_get_version(),
4632 ARRAY_LEN(rmp->version)-1);
4633 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4634 ARRAY_LEN(rmp->build_date)-1);
4640 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4642 vlib_main_t *vm = vlib_get_main ();
4643 vl_api_get_node_index_reply_t *rmp;
4646 u32 node_index = ~0;
4648 n = vlib_get_node_by_name (vm, mp->node_name);
4651 rv = VNET_API_ERROR_NO_SUCH_NODE;
4653 node_index = n->index;
4656 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4658 rmp->node_index = ntohl(node_index);
4664 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4666 vlib_main_t *vm = vlib_get_main ();
4667 vl_api_get_next_index_reply_t *rmp;
4668 vlib_node_t *node, *next_node;
4670 u32 next_node_index = ~0, next_index = ~0;
4673 node = vlib_get_node_by_name (vm, mp->node_name);
4677 rv = VNET_API_ERROR_NO_SUCH_NODE;
4681 next_node = vlib_get_node_by_name (vm, mp->next_name);
4685 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4689 next_node_index = next_node->index;
4691 p = hash_get (node->next_slot_by_node, next_node_index);
4695 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4703 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4705 rmp->next_index = ntohl(next_index);
4711 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4713 vlib_main_t *vm = vlib_get_main ();
4714 vl_api_add_node_next_reply_t *rmp;
4715 vlib_node_t *n, *next;
4717 u32 next_index = ~0;
4719 n = vlib_get_node_by_name (vm, mp->node_name);
4723 rv = VNET_API_ERROR_NO_SUCH_NODE;
4727 next = vlib_get_node_by_name (vm, mp->next_name);
4730 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4732 next_index = vlib_node_add_next (vm, n->index, next->index);
4736 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4738 rmp->next_index = ntohl(next_index);
4743 static void vl_api_l2tpv3_create_tunnel_t_handler
4744 (vl_api_l2tpv3_create_tunnel_t * mp)
4746 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4747 l2t_main_t *lm = &l2t_main;
4748 u32 sw_if_index = (u32) ~ 0;
4751 if (mp->is_ipv6 != 1)
4753 rv = VNET_API_ERROR_UNIMPLEMENTED;
4757 u32 encap_fib_index;
4759 if (mp->encap_vrf_id != ~0)
4762 ip6_main_t *im = &ip6_main;
4765 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4767 rv = VNET_API_ERROR_NO_SUCH_FIB;
4770 encap_fib_index = p[0];
4774 encap_fib_index = ~0;
4777 rv = create_l2tpv3_ipv6_tunnel (lm,
4778 (ip6_address_t *) mp->client_address,
4779 (ip6_address_t *) mp->our_address,
4780 ntohl (mp->local_session_id),
4781 ntohl (mp->remote_session_id),
4782 clib_net_to_host_u64 (mp->local_cookie),
4783 clib_net_to_host_u64 (mp->remote_cookie),
4784 mp->l2_sublayer_present,
4785 encap_fib_index, &sw_if_index);
4789 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4791 rmp->sw_if_index = ntohl (sw_if_index);
4796 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4797 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4799 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4800 l2t_main_t *lm = &l2t_main;
4803 VALIDATE_SW_IF_INDEX (mp);
4805 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4806 clib_net_to_host_u64 (mp->new_local_cookie),
4807 clib_net_to_host_u64
4808 (mp->new_remote_cookie));
4810 BAD_SW_IF_INDEX_LABEL;
4812 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4815 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4816 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4819 vnet_main_t *vnm = vnet_get_main ();
4820 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4822 VALIDATE_SW_IF_INDEX (mp);
4824 rv = l2tpv3_interface_enable_disable
4825 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4827 BAD_SW_IF_INDEX_LABEL;
4829 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4832 static void vl_api_l2tpv3_set_lookup_key_t_handler
4833 (vl_api_l2tpv3_set_lookup_key_t * mp)
4836 l2t_main_t *lm = &l2t_main;
4837 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4839 if (mp->key > L2T_LOOKUP_SESSION_ID)
4841 rv = VNET_API_ERROR_INVALID_VALUE;
4845 lm->lookup_type = mp->key;
4848 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4851 static void vl_api_vxlan_add_del_tunnel_t_handler
4852 (vl_api_vxlan_add_del_tunnel_t * mp)
4854 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4856 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4857 u32 encap_fib_index;
4859 ip4_main_t *im = &ip4_main;
4860 u32 sw_if_index = ~0;
4862 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4865 rv = VNET_API_ERROR_NO_SUCH_FIB;
4868 encap_fib_index = p[0];
4870 /* Check src & dst are different */
4871 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4872 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4874 rv = VNET_API_ERROR_SAME_SRC_DST;
4877 memset (a, 0, sizeof (*a));
4879 a->is_add = mp->is_add;
4880 a->is_ip6 = mp->is_ipv6;
4882 /* ip addresses sent in network byte order */
4885 memcpy (&(a->src.ip6), mp->src_address, 16);
4886 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4890 memcpy (&(a->src.ip4), mp->src_address, 4);
4891 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4894 a->encap_fib_index = encap_fib_index;
4895 a->decap_next_index = ntohl (mp->decap_next_index);
4896 a->vni = ntohl (mp->vni);
4897 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4901 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4903 rmp->sw_if_index = ntohl (sw_if_index);
4908 static void send_vxlan_tunnel_details
4909 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4911 vl_api_vxlan_tunnel_details_t *rmp;
4912 ip4_main_t *im4 = &ip4_main;
4913 ip6_main_t *im6 = &ip6_main;
4914 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4916 rmp = vl_msg_api_alloc (sizeof (*rmp));
4917 memset (rmp, 0, sizeof (*rmp));
4918 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4921 memcpy (rmp->src_address, &(t->src.ip6), 16);
4922 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4923 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4927 memcpy (rmp->src_address, &(t->src.ip4), 4);
4928 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4929 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4931 rmp->vni = htonl (t->vni);
4932 rmp->decap_next_index = htonl (t->decap_next_index);
4933 rmp->sw_if_index = htonl (t->sw_if_index);
4934 rmp->is_ipv6 = is_ipv6;
4935 rmp->context = context;
4937 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4940 static void vl_api_vxlan_tunnel_dump_t_handler
4941 (vl_api_vxlan_tunnel_dump_t * mp)
4943 unix_shared_memory_queue_t *q;
4944 vxlan_main_t *vxm = &vxlan_main;
4948 q = vl_api_client_index_to_input_queue (mp->client_index);
4954 sw_if_index = ntohl (mp->sw_if_index);
4956 if (~0 == sw_if_index)
4959 pool_foreach (t, vxm->tunnels,
4961 send_vxlan_tunnel_details(t, q, mp->context);
4967 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4968 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4972 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4973 send_vxlan_tunnel_details (t, q, mp->context);
4977 static void vl_api_gre_add_del_tunnel_t_handler
4978 (vl_api_gre_add_del_tunnel_t * mp)
4980 vl_api_gre_add_del_tunnel_reply_t *rmp;
4982 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4985 ip4_main_t *im = &ip4_main;
4986 u32 sw_if_index = ~0;
4988 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4991 rv = VNET_API_ERROR_NO_SUCH_FIB;
4994 outer_fib_id = p[0];
4996 /* Check src & dst are different */
4997 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4998 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
5000 rv = VNET_API_ERROR_SAME_SRC_DST;
5003 memset (a, 0, sizeof (*a));
5005 a->is_add = mp->is_add;
5008 /* ip addresses sent in network byte order */
5009 clib_memcpy (&(a->src), mp->src_address, 4);
5010 clib_memcpy (&(a->dst), mp->dst_address, 4);
5012 a->outer_fib_id = outer_fib_id;
5013 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
5017 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
5019 rmp->sw_if_index = ntohl (sw_if_index);
5024 static void send_gre_tunnel_details
5025 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5027 vl_api_gre_tunnel_details_t *rmp;
5028 ip4_main_t *im = &ip4_main;
5030 rmp = vl_msg_api_alloc (sizeof (*rmp));
5031 memset (rmp, 0, sizeof (*rmp));
5032 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
5033 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
5034 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
5035 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
5037 rmp->sw_if_index = htonl (t->sw_if_index);
5038 rmp->context = context;
5040 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5044 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
5046 unix_shared_memory_queue_t *q;
5047 gre_main_t *gm = &gre_main;
5051 q = vl_api_client_index_to_input_queue (mp->client_index);
5057 sw_if_index = ntohl (mp->sw_if_index);
5059 if (~0 == sw_if_index)
5062 pool_foreach (t, gm->tunnels,
5064 send_gre_tunnel_details(t, q, mp->context);
5070 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
5071 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
5075 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
5076 send_gre_tunnel_details (t, q, mp->context);
5081 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
5083 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5085 vl_api_l2_patch_add_del_reply_t *rmp;
5086 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5090 VALIDATE_RX_SW_IF_INDEX (mp);
5091 VALIDATE_TX_SW_IF_INDEX (mp);
5093 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
5094 ntohl (mp->tx_sw_if_index),
5095 (int) (mp->is_add != 0));
5097 BAD_RX_SW_IF_INDEX_LABEL;
5098 BAD_TX_SW_IF_INDEX_LABEL;
5100 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
5104 vl_api_vxlan_gpe_add_del_tunnel_t_handler
5105 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
5107 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
5109 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
5110 u32 encap_fib_index, decap_fib_index;
5113 ip4_main_t *im = &ip4_main;
5114 u32 sw_if_index = ~0;
5117 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
5120 rv = VNET_API_ERROR_NO_SUCH_FIB;
5123 encap_fib_index = p[0];
5125 protocol = mp->protocol;
5127 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
5128 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
5130 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
5133 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
5136 decap_fib_index = p[0];
5140 decap_fib_index = ntohl (mp->decap_vrf_id);
5143 /* Check src & dst are different */
5144 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5145 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5147 rv = VNET_API_ERROR_SAME_SRC_DST;
5150 memset (a, 0, sizeof (*a));
5152 a->is_add = mp->is_add;
5153 a->is_ip6 = mp->is_ipv6;
5154 /* ip addresses sent in network byte order */
5157 clib_memcpy (&(a->local.ip6), mp->local, 16);
5158 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5162 clib_memcpy (&(a->local.ip4), mp->local, 4);
5163 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5165 a->encap_fib_index = encap_fib_index;
5166 a->decap_fib_index = decap_fib_index;
5167 a->protocol = protocol;
5168 a->vni = ntohl (mp->vni);
5169 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5173 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5175 rmp->sw_if_index = ntohl (sw_if_index);
5180 static void send_vxlan_gpe_tunnel_details
5181 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5183 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5184 ip4_main_t *im4 = &ip4_main;
5185 ip6_main_t *im6 = &ip6_main;
5186 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5188 rmp = vl_msg_api_alloc (sizeof (*rmp));
5189 memset (rmp, 0, sizeof (*rmp));
5190 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5193 memcpy (rmp->local, &(t->local.ip6), 16);
5194 memcpy (rmp->remote, &(t->remote.ip6), 16);
5195 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
5196 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
5200 memcpy (rmp->local, &(t->local.ip4), 4);
5201 memcpy (rmp->remote, &(t->remote.ip4), 4);
5202 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
5203 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
5205 rmp->vni = htonl (t->vni);
5206 rmp->protocol = t->protocol;
5207 rmp->sw_if_index = htonl (t->sw_if_index);
5208 rmp->is_ipv6 = is_ipv6;
5209 rmp->context = context;
5211 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5214 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5215 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5217 unix_shared_memory_queue_t *q;
5218 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5219 vxlan_gpe_tunnel_t *t;
5222 q = vl_api_client_index_to_input_queue (mp->client_index);
5228 sw_if_index = ntohl (mp->sw_if_index);
5230 if (~0 == sw_if_index)
5233 pool_foreach (t, vgm->tunnels,
5235 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5241 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5242 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5246 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5247 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5251 /** Used for transferring locators via VPP API */
5253 typedef CLIB_PACKED (struct {
5254 u32 sw_if_index; /**< locator sw_if_index */
5255 u8 priority; /**< locator priority */
5256 u8 weight; /**< locator weight */
5261 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5264 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5266 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5268 ls_locator_t *ls_loc;
5269 u32 ls_index = ~0, locator_num;
5270 u8 *locator_name = NULL;
5273 memset (a, 0, sizeof (a[0]));
5275 locator_name = format (0, "%s", mp->locator_set_name);
5277 a->name = locator_name;
5278 a->is_add = mp->is_add;
5280 locator_num = clib_net_to_host_u32 (mp->locator_num);
5282 memset (&locator, 0, sizeof (locator));
5283 for (i = 0; i < locator_num; i++)
5285 ls_loc = &((ls_locator_t *) mp->locators)[i];
5286 VALIDATE_SW_IF_INDEX (ls_loc);
5288 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5289 locator.priority = ls_loc->priority;
5290 locator.weight = ls_loc->weight;
5292 vec_add1 (a->locators, locator);
5295 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5297 BAD_SW_IF_INDEX_LABEL;
5299 vec_free (locator_name);
5300 vec_free (a->locators);
5303 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5305 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5311 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5313 vl_api_lisp_add_del_locator_reply_t *rmp;
5315 locator_t locator, *locators = NULL;
5316 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5318 u8 *locator_name = NULL;
5320 memset (&locator, 0, sizeof (locator));
5321 memset (a, 0, sizeof (a[0]));
5323 locator.sw_if_index = ntohl (mp->sw_if_index);
5324 locator.priority = mp->priority;
5325 locator.weight = mp->weight;
5327 vec_add1 (locators, locator);
5329 locator_name = format (0, "%s", mp->locator_set_name);
5331 a->name = locator_name;
5332 a->locators = locators;
5333 a->is_add = mp->is_add;
5336 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5338 vec_free (locators);
5339 vec_free (locator_name);
5341 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5345 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5351 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5352 gid_address_ip_set (dst, src, IP4);
5353 gid_address_ippref_len (dst) = len;
5354 ip_prefix_normalize (&gid_address_ippref (dst));
5357 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5358 gid_address_ip_set (dst, src, IP6);
5359 gid_address_ippref_len (dst) = len;
5360 ip_prefix_normalize (&gid_address_ippref (dst));
5362 case 2: /* l2 mac */
5363 gid_address_type (dst) = GID_ADDR_MAC;
5364 clib_memcpy (&gid_address_mac (dst), src, 6);
5368 return VNET_API_ERROR_INVALID_VALUE;
5371 gid_address_vni (dst) = vni;
5377 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5379 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5380 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5382 gid_address_t _eid, *eid = &_eid;
5384 u32 locator_set_index = ~0, map_index = ~0;
5385 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5387 memset (a, 0, sizeof (a[0]));
5388 memset (eid, 0, sizeof (eid[0]));
5390 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5391 mp->eid_type, mp->eid, mp->prefix_len);
5395 name = format (0, "%s", mp->locator_set_name);
5396 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5399 rv = VNET_API_ERROR_INVALID_VALUE;
5402 locator_set_index = p[0];
5404 /* XXX treat batch configuration */
5405 a->is_add = mp->is_add;
5406 gid_address_copy (&a->eid, eid);
5407 a->locator_set_index = locator_set_index;
5409 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5413 gid_address_free (&a->eid);
5415 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5419 vl_api_lisp_eid_table_add_del_map_t_handler
5420 (vl_api_lisp_eid_table_add_del_map_t * mp)
5422 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5424 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5425 clib_net_to_host_u32 (mp->dp_table),
5426 mp->is_l2, mp->is_add);
5427 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5429 /** Used for transferring locators via VPP API */
5431 typedef CLIB_PACKED (struct {
5432 u8 is_ip4; /**< is locator an IPv4 address */
5433 u8 priority; /**< locator priority */
5434 u8 weight; /**< locator weight */
5435 u8 addr[16]; /**< IPv4/IPv6 address */
5439 static locator_pair_t *
5440 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5443 locator_pair_t *pairs = 0, pair;
5446 for (i = 0; i < rloc_num; i++)
5449 r = &((rloc_t *) lcl_locs)[i];
5450 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5451 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5453 /* remote locators */
5454 r = &((rloc_t *) rmt_locs)[i];
5455 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5456 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5458 pair.priority = r->priority;
5459 pair.weight = r->weight;
5461 vec_add1 (pairs, pair);
5467 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5470 locator_t *locs = 0, loc;
5473 for (i = 0; i < rloc_num; i++)
5475 /* remote locators */
5476 r = &((rloc_t *) rmt_locs)[i];
5477 memset (&loc, 0, sizeof (loc));
5478 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5480 loc.priority = r->priority;
5481 loc.weight = r->weight;
5483 vec_add1 (locs, loc);
5489 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5490 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5492 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5493 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5494 locator_pair_t *pairs = 0;
5497 memset (a, 0, sizeof (a[0]));
5499 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5500 mp->rmt_eid, mp->rmt_len);
5501 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5502 mp->lcl_eid, mp->lcl_len);
5504 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5506 if (rv || 0 == pairs)
5509 a->is_add = mp->is_add;
5510 a->locator_pairs = pairs;
5511 a->dp_table = mp->dp_table;
5513 a->action = mp->action;
5515 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5518 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5522 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5525 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5527 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5529 memset (a, 0, sizeof (a[0]));
5531 a->is_add = mp->is_add;
5532 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5534 rv = vnet_lisp_add_del_map_resolver (a);
5536 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5540 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5543 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5545 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5547 a->is_en = mp->is_en;
5548 vnet_lisp_gpe_enable_disable (a);
5550 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5554 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5556 vl_api_lisp_enable_disable_reply_t *rmp;
5559 vnet_lisp_enable_disable (mp->is_en);
5560 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5564 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5566 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5574 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
5578 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
5585 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
5589 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
5592 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5596 vl_api_show_lisp_map_request_mode_t_handler
5597 (vl_api_show_lisp_map_request_mode_t * mp)
5600 vl_api_show_lisp_map_request_mode_reply_t *rmp;
5603 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
5605 rmp->mode = vnet_lisp_get_map_request_mode ();
5611 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
5613 vl_api_lisp_map_request_mode_reply_t *rmp;
5616 rv = vnet_lisp_set_map_request_mode (mp->mode);
5618 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
5622 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5625 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5629 ls_name = format (0, "%s", mp->ls_name);
5630 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5633 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5637 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5638 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5640 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5642 u8 *locator_set_name = NULL;
5643 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5645 locator_set_name = format (0, "%s", mp->locator_set_name);
5647 a->is_add = mp->is_add;
5648 a->locator_set_name = locator_set_name;
5650 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5652 vec_free (locator_set_name);
5654 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5658 vl_api_lisp_add_del_remote_mapping_t_handler
5659 (vl_api_lisp_add_del_remote_mapping_t * mp)
5661 locator_t *rlocs = 0;
5662 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5664 gid_address_t _eid, *eid = &_eid;
5665 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5667 memset (eid, 0, sizeof (eid[0]));
5669 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5670 mp->eid_type, mp->eid, mp->eid_len);
5674 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5678 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5679 gid_address_copy (&a->reid, eid);
5681 rv = vnet_lisp_add_del_adjacency (a);
5688 /* NOTE: for now this works as a static remote mapping, i.e.,
5689 * not authoritative and ttl infinite. */
5690 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5691 mp->is_add, 1 /* is_static */ , 0);
5694 vnet_lisp_clear_all_remote_adjacencies ();
5699 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5703 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5705 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5706 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5709 memset (a, 0, sizeof (a[0]));
5711 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
5712 mp->eid_type, mp->leid, mp->leid_len);
5713 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
5714 mp->eid_type, mp->reid, mp->reid_len);
5719 a->is_add = mp->is_add;
5720 rv = vnet_lisp_add_del_adjacency (a);
5723 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5727 send_lisp_locator_details (lisp_cp_main_t * lcm,
5729 unix_shared_memory_queue_t * q, u32 context)
5731 vl_api_lisp_locator_details_t *rmp;
5733 rmp = vl_msg_api_alloc (sizeof (*rmp));
5734 memset (rmp, 0, sizeof (*rmp));
5735 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5736 rmp->context = context;
5738 rmp->local = loc->local;
5741 rmp->sw_if_index = ntohl (loc->sw_if_index);
5745 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5746 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5748 rmp->priority = loc->priority;
5749 rmp->weight = loc->weight;
5751 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5755 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5758 unix_shared_memory_queue_t *q = 0;
5759 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5760 locator_set_t *lsit = 0;
5762 u32 ls_index = ~0, *locit = 0;
5765 q = vl_api_client_index_to_input_queue (mp->client_index);
5771 if (mp->is_index_set)
5772 ls_index = htonl (mp->ls_index);
5775 /* make sure we get a proper C-string */
5776 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
5777 ls_name = format (0, "%s", mp->ls_name);
5778 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
5784 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
5787 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5789 vec_foreach (locit, lsit->locator_indices)
5791 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5792 send_lisp_locator_details (lcm, loc, q, mp->context);
5799 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5800 locator_set_t * lsit,
5801 unix_shared_memory_queue_t * q,
5802 u32 context, u32 ls_index)
5804 vl_api_lisp_locator_set_details_t *rmp;
5807 rmp = vl_msg_api_alloc (sizeof (*rmp));
5808 memset (rmp, 0, sizeof (*rmp));
5809 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5810 rmp->context = context;
5812 rmp->ls_index = htonl (ls_index);
5815 ASSERT (lsit->name != NULL);
5816 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
5817 vec_len (lsit->name));
5821 str = format (0, "<remote-%d>", ls_index);
5822 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
5826 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5830 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5832 unix_shared_memory_queue_t *q = NULL;
5833 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5834 locator_set_t *lsit = NULL;
5837 q = vl_api_client_index_to_input_queue (mp->client_index);
5843 filter = mp->filter;
5845 pool_foreach (lsit, lcm->locator_set_pool,
5847 if (filter && !((1 == filter && lsit->local) ||
5848 (2 == filter && !lsit->local)))
5852 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
5853 lsit - lcm->locator_set_pool);
5859 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5861 ASSERT (prefix_length);
5862 ip_prefix_t *ippref = &fid_addr_ippref (src);
5864 switch (fid_addr_type (src))
5866 case FID_ADDR_IP_PREF:
5867 if (ip_prefix_version (ippref) == IP4)
5868 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5870 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5871 prefix_length[0] = ip_prefix_len (ippref);
5875 prefix_length[0] = 0;
5876 clib_memcpy (dst, fid_addr_mac (src), 6);
5880 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5886 fid_type_to_api_type (fid_address_t * fid)
5888 ip_prefix_t *ippref;
5890 switch (fid_addr_type (fid))
5892 case FID_ADDR_IP_PREF:
5893 ippref = &fid_addr_ippref (fid);
5894 if (ip_prefix_version (ippref) == IP4)
5896 else if (ip_prefix_version (ippref) == IP6)
5909 send_lisp_eid_table_details (mapping_t * mapit,
5910 unix_shared_memory_queue_t * q,
5911 u32 context, u8 filter)
5914 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5915 locator_set_t *ls = 0;
5916 vl_api_lisp_eid_table_details_t *rmp = NULL;
5917 gid_address_t *gid = NULL;
5919 ip_prefix_t *ip_prefix = NULL;
5923 case 0: /* all mappings */
5926 case 1: /* local only */
5930 case 2: /* remote only */
5935 clib_warning ("Filter error, unknown filter: %d", filter);
5940 ip_prefix = &gid_address_ippref (gid);
5941 mac = gid_address_mac (gid);
5943 rmp = vl_msg_api_alloc (sizeof (*rmp));
5944 memset (rmp, 0, sizeof (*rmp));
5945 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5947 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5948 if (vec_len (ls->locator_indices) == 0)
5949 rmp->locator_set_index = ~0;
5951 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5953 rmp->is_local = mapit->local;
5954 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5955 rmp->action = mapit->action;
5956 rmp->authoritative = mapit->authoritative;
5958 switch (gid_address_type (gid))
5960 case GID_ADDR_SRC_DST:
5961 rmp->is_src_dst = 1;
5962 fid = &gid_address_sd_src (gid);
5963 rmp->eid_type = fid_type_to_api_type (fid);
5964 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5965 &rmp->seid_prefix_len);
5966 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5967 &rmp->eid_prefix_len);
5969 case GID_ADDR_IP_PREFIX:
5970 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5971 if (ip_prefix_version (ip_prefix) == IP4)
5973 rmp->eid_type = 0; /* ipv4 type */
5974 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5975 sizeof (ip_prefix_v4 (ip_prefix)));
5979 rmp->eid_type = 1; /* ipv6 type */
5980 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5981 sizeof (ip_prefix_v6 (ip_prefix)));
5985 rmp->eid_type = 2; /* l2 mac type */
5986 clib_memcpy (rmp->eid, mac, 6);
5991 rmp->context = context;
5992 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5993 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5997 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
6000 unix_shared_memory_queue_t *q = NULL;
6001 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6002 mapping_t *mapit = NULL;
6003 gid_address_t _eid, *eid = &_eid;
6005 q = vl_api_client_index_to_input_queue (mp->client_index);
6013 memset (eid, 0, sizeof (*eid));
6015 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
6016 mp->eid_type, mp->eid, mp->prefix_length);
6018 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
6019 if ((u32) ~ 0 == mi)
6022 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
6023 send_lisp_eid_table_details (mapit, q, mp->context,
6024 0 /* ignore filter */ );
6029 pool_foreach (mapit, lcm->mapping_pool,
6031 send_lisp_eid_table_details(mapit, q, mp->context,
6039 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
6040 unix_shared_memory_queue_t * q, u32 context)
6042 vl_api_lisp_gpe_tunnel_details_t *rmp;
6043 lisp_gpe_main_t *lgm = &lisp_gpe_main;
6045 rmp = vl_msg_api_alloc (sizeof (*rmp));
6046 memset (rmp, 0, sizeof (*rmp));
6047 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
6049 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
6051 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
6052 ip_address_copy_addr (rmp->source_ip,
6053 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
6054 ip_address_copy_addr (rmp->destination_ip,
6055 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
6057 rmp->encap_fib_id = htonl (0);
6058 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
6059 rmp->iid = htonl (lfe->key->vni);
6060 rmp->context = context;
6062 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6066 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
6068 unix_shared_memory_queue_t *q = NULL;
6069 lisp_gpe_main_t *lgm = &lisp_gpe_main;
6070 lisp_gpe_fwd_entry_t *lfe = NULL;
6072 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
6077 q = vl_api_client_index_to_input_queue (mp->client_index);
6084 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
6086 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
6092 send_lisp_map_resolver_details (ip_address_t * ip,
6093 unix_shared_memory_queue_t * q, u32 context)
6095 vl_api_lisp_map_resolver_details_t *rmp = NULL;
6097 rmp = vl_msg_api_alloc (sizeof (*rmp));
6098 memset (rmp, 0, sizeof (*rmp));
6099 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
6101 switch (ip_addr_version (ip))
6105 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
6106 sizeof (ip_addr_v4 (ip)));
6111 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
6112 sizeof (ip_addr_v6 (ip)));
6118 rmp->context = context;
6120 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6124 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
6126 unix_shared_memory_queue_t *q = NULL;
6127 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6130 q = vl_api_client_index_to_input_queue (mp->client_index);
6136 vec_foreach (mr, lcm->map_resolvers)
6138 send_lisp_map_resolver_details (&mr->address, q, mp->context);
6143 send_eid_table_map_pair (hash_pair_t * p,
6144 unix_shared_memory_queue_t * q, u32 context)
6146 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
6148 rmp = vl_msg_api_alloc (sizeof (*rmp));
6149 memset (rmp, 0, sizeof (*rmp));
6150 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
6152 rmp->vni = clib_host_to_net_u32 (p->key);
6153 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
6154 rmp->context = context;
6155 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6159 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
6162 unix_shared_memory_queue_t *q = NULL;
6163 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6165 uword *vni_table = 0;
6167 q = vl_api_client_index_to_input_queue (mp->client_index);
6175 vni_table = lcm->bd_id_by_vni;
6179 vni_table = lcm->table_id_by_vni;
6183 hash_foreach_pair (p, vni_table,
6185 send_eid_table_map_pair (p, q, mp->context);
6191 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6193 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6195 rmp = vl_msg_api_alloc (sizeof (*rmp));
6196 memset (rmp, 0, sizeof (*rmp));
6197 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6198 rmp->context = context;
6199 rmp->vni = clib_host_to_net_u32 (vni);
6200 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6204 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
6206 lisp_adjacency_t *adj;
6207 vl_api_lisp_adjacency_t a;
6208 u32 i, n = vec_len (adjs);
6210 for (i = 0; i < n; i++)
6212 adj = vec_elt_at_index (adjs, i);
6213 memset (&a, 0, sizeof (a));
6215 switch (gid_address_type (&adj->reid))
6217 case GID_ADDR_IP_PREFIX:
6218 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
6219 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
6220 if (gid_address_ip_version (&adj->reid) == IP4)
6222 a.eid_type = 0; /* ipv4 type */
6223 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
6224 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
6228 a.eid_type = 1; /* ipv6 type */
6229 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
6230 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
6234 a.eid_type = 2; /* l2 mac type */
6235 mac_copy (a.reid, gid_address_mac (&adj->reid));
6236 mac_copy (a.leid, gid_address_mac (&adj->leid));
6246 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
6248 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
6249 lisp_adjacency_t *adjs = 0;
6251 vl_api_lisp_adjacency_t a;
6253 u32 vni = clib_net_to_host_u32 (mp->vni);
6255 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
6256 size = vec_len (adjs) * sizeof (a);
6259 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
6261 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
6262 lisp_adjacency_copy (rmp->adjacencies, adjs);
6270 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6275 unix_shared_memory_queue_t *q = 0;
6276 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6278 q = vl_api_client_index_to_input_queue (mp->client_index);
6285 hash_foreach_pair (p, lcm->table_id_by_vni,
6287 hash_set (vnis, p->key, 0);
6290 hash_foreach_pair (p, lcm->bd_id_by_vni,
6292 hash_set (vnis, p->key, 0);
6295 hash_foreach_pair (p, vnis,
6297 send_eid_table_vni (p->key, q, mp->context);
6305 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6307 unix_shared_memory_queue_t *q = NULL;
6308 vl_api_show_lisp_status_reply_t *rmp = NULL;
6311 q = vl_api_client_index_to_input_queue (mp->client_index);
6318 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6320 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6321 rmp->feature_status = vnet_lisp_enable_disable_status ();
6327 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6328 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6330 unix_shared_memory_queue_t *q = NULL;
6331 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6332 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6333 locator_set_t *loc_set = 0;
6337 q = vl_api_client_index_to_input_queue (mp->client_index);
6343 if (~0 == lcm->mreq_itr_rlocs)
6345 tmp_str = format (0, " ");
6350 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6351 tmp_str = format (0, "%s", loc_set->name);
6355 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6357 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6358 ARRAY_LEN(rmp->locator_set_name) - 1);
6366 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6368 unix_shared_memory_queue_t *q = NULL;
6369 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6370 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6372 locator_set_t *ls = 0;
6376 q = vl_api_client_index_to_input_queue (mp->client_index);
6382 if (!lcm->lisp_pitr)
6384 tmp_str = format (0, "N/A");
6388 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6389 if (~0 != m->locator_set_index)
6392 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6393 tmp_str = format (0, "%s", ls->name);
6397 tmp_str = format (0, "N/A");
6400 vec_add1 (tmp_str, 0);
6403 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6405 rmp->status = lcm->lisp_pitr;
6406 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6407 ARRAY_LEN(rmp->locator_set_name) - 1);
6413 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6416 vl_api_interface_name_renumber_reply_t *rmp;
6419 VALIDATE_SW_IF_INDEX (mp);
6421 rv = vnet_interface_name_renumber
6422 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6424 BAD_SW_IF_INDEX_LABEL;
6426 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6430 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6431 u32 sw_if_index, u32 address)
6433 vpe_api_main_t *am = &vpe_api_main;
6434 vlib_main_t *vm = am->vlib_main;
6435 vl_api_ip4_arp_event_t *event;
6436 static f64 arp_event_last_time;
6437 f64 now = vlib_time_now (vm);
6439 if (pool_is_free_index (am->arp_events, pool_index))
6442 event = pool_elt_at_index (am->arp_events, pool_index);
6444 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6446 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6450 if (sw_if_index == event->sw_if_index &&
6452 /* for BD case, also check IP address with 10 sec timeout */
6453 (address == event->address &&
6454 (now - arp_event_last_time) < 10.0)))
6459 arp_event_last_time = now;
6460 event->sw_if_index = sw_if_index;
6462 event->address = address;
6467 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6468 u32 sw_if_index, ip6_address_t * address)
6470 vpe_api_main_t *am = &vpe_api_main;
6471 vlib_main_t *vm = am->vlib_main;
6472 vl_api_ip6_nd_event_t *event;
6473 static f64 nd_event_last_time;
6474 f64 now = vlib_time_now (vm);
6476 if (pool_is_free_index (am->nd_events, pool_index))
6479 event = pool_elt_at_index (am->nd_events, pool_index);
6482 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6484 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6488 if (sw_if_index == event->sw_if_index &&
6490 /* for BD case, also check IP address with 10 sec timeout */
6491 (ip6_address_is_equal (address,
6492 (ip6_address_t *) event->address) &&
6493 (now - nd_event_last_time) < 10.0)))
6498 nd_event_last_time = now;
6499 event->sw_if_index = sw_if_index;
6501 clib_memcpy (event->address, address, sizeof (event->address));
6506 arp_change_delete_callback (u32 pool_index, u8 * notused)
6508 vpe_api_main_t *am = &vpe_api_main;
6510 if (pool_is_free_index (am->arp_events, pool_index))
6513 pool_put_index (am->arp_events, pool_index);
6518 nd_change_delete_callback (u32 pool_index, u8 * notused)
6520 vpe_api_main_t *am = &vpe_api_main;
6522 if (pool_is_free_index (am->nd_events, pool_index))
6525 pool_put_index (am->nd_events, pool_index);
6530 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6532 vpe_api_main_t *am = &vpe_api_main;
6533 vnet_main_t *vnm = vnet_get_main ();
6534 vl_api_want_ip4_arp_events_reply_t *rmp;
6535 vl_api_ip4_arp_event_t *event;
6538 if (mp->enable_disable)
6540 pool_get (am->arp_events, event);
6541 memset (event, 0, sizeof (*event));
6543 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6544 event->client_index = mp->client_index;
6545 event->context = mp->context;
6546 event->address = mp->address;
6547 event->pid = mp->pid;
6548 if (mp->address == 0)
6551 rv = vnet_add_del_ip4_arp_change_event
6552 (vnm, arp_change_data_callback,
6553 mp->pid, &mp->address /* addr, in net byte order */ ,
6554 vpe_resolver_process_node.index,
6555 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6559 rv = vnet_add_del_ip4_arp_change_event
6560 (vnm, arp_change_delete_callback,
6561 mp->pid, &mp->address /* addr, in net byte order */ ,
6562 vpe_resolver_process_node.index,
6563 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6565 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6569 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6571 vpe_api_main_t *am = &vpe_api_main;
6572 vnet_main_t *vnm = vnet_get_main ();
6573 vl_api_want_ip6_nd_events_reply_t *rmp;
6574 vl_api_ip6_nd_event_t *event;
6577 if (mp->enable_disable)
6579 pool_get (am->nd_events, event);
6580 memset (event, 0, sizeof (*event));
6582 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6583 event->client_index = mp->client_index;
6584 event->context = mp->context;
6585 clib_memcpy (event->address, mp->address, 16);
6586 event->pid = mp->pid;
6587 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6590 rv = vnet_add_del_ip6_nd_change_event
6591 (vnm, nd_change_data_callback,
6592 mp->pid, mp->address /* addr, in net byte order */ ,
6593 vpe_resolver_process_node.index,
6594 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6598 rv = vnet_add_del_ip6_nd_change_event
6599 (vnm, nd_change_delete_callback,
6600 mp->pid, mp->address /* addr, in net byte order */ ,
6601 vpe_resolver_process_node.index,
6602 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6604 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6607 static void vl_api_input_acl_set_interface_t_handler
6608 (vl_api_input_acl_set_interface_t * mp)
6610 vlib_main_t *vm = vlib_get_main ();
6611 vl_api_input_acl_set_interface_reply_t *rmp;
6613 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6615 ip4_table_index = ntohl (mp->ip4_table_index);
6616 ip6_table_index = ntohl (mp->ip6_table_index);
6617 l2_table_index = ntohl (mp->l2_table_index);
6618 sw_if_index = ntohl (mp->sw_if_index);
6620 VALIDATE_SW_IF_INDEX (mp);
6622 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6623 ip6_table_index, l2_table_index, mp->is_add);
6625 BAD_SW_IF_INDEX_LABEL;
6627 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6630 static void vl_api_ipsec_spd_add_del_t_handler
6631 (vl_api_ipsec_spd_add_del_t * mp)
6634 clib_warning ("unimplemented");
6637 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6638 vl_api_ipsec_spd_add_del_reply_t *rmp;
6642 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6644 rv = VNET_API_ERROR_UNIMPLEMENTED;
6647 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6651 static void vl_api_ipsec_interface_add_del_spd_t_handler
6652 (vl_api_ipsec_interface_add_del_spd_t * mp)
6654 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6655 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6657 u32 sw_if_index __attribute__ ((unused));
6658 u32 spd_id __attribute__ ((unused));
6660 sw_if_index = ntohl (mp->sw_if_index);
6661 spd_id = ntohl (mp->spd_id);
6663 VALIDATE_SW_IF_INDEX (mp);
6666 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6668 rv = VNET_API_ERROR_UNIMPLEMENTED;
6671 BAD_SW_IF_INDEX_LABEL;
6673 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6676 static void vl_api_ipsec_spd_add_del_entry_t_handler
6677 (vl_api_ipsec_spd_add_del_entry_t * mp)
6679 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6680 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6686 memset (&p, 0, sizeof (p));
6688 p.id = ntohl (mp->spd_id);
6689 p.priority = ntohl (mp->priority);
6690 p.is_outbound = mp->is_outbound;
6691 p.is_ipv6 = mp->is_ipv6;
6693 if (mp->is_ipv6 || mp->is_ip_any)
6695 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6696 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6697 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6698 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6702 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6703 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6704 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6705 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6707 p.protocol = mp->protocol;
6708 p.rport.start = ntohs (mp->remote_port_start);
6709 p.rport.stop = ntohs (mp->remote_port_stop);
6710 p.lport.start = ntohs (mp->local_port_start);
6711 p.lport.stop = ntohs (mp->local_port_stop);
6712 /* policy action resolve unsupported */
6713 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6715 clib_warning ("unsupported action: 'resolve'");
6716 rv = VNET_API_ERROR_UNIMPLEMENTED;
6719 p.policy = mp->policy;
6720 p.sa_id = ntohl (mp->sa_id);
6722 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6729 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6732 rv = VNET_API_ERROR_UNIMPLEMENTED;
6737 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6740 static void vl_api_ipsec_sad_add_del_entry_t_handler
6741 (vl_api_ipsec_sad_add_del_entry_t * mp)
6743 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6744 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6749 memset (&sa, 0, sizeof (sa));
6751 sa.id = ntohl (mp->sad_id);
6752 sa.spi = ntohl (mp->spi);
6753 /* security protocol AH unsupported */
6754 if (mp->protocol == IPSEC_PROTOCOL_AH)
6756 clib_warning ("unsupported security protocol 'AH'");
6757 rv = VNET_API_ERROR_UNIMPLEMENTED;
6760 sa.protocol = mp->protocol;
6761 /* check for unsupported crypto-alg */
6762 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6763 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6765 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6766 mp->crypto_algorithm);
6767 rv = VNET_API_ERROR_UNIMPLEMENTED;
6770 sa.crypto_alg = mp->crypto_algorithm;
6771 sa.crypto_key_len = mp->crypto_key_length;
6772 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6773 /* check for unsupported integ-alg */
6774 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6775 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6777 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6778 mp->integrity_algorithm);
6779 rv = VNET_API_ERROR_UNIMPLEMENTED;
6782 sa.integ_alg = mp->integrity_algorithm;
6783 sa.integ_key_len = mp->integrity_key_length;
6784 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6785 sa.use_esn = mp->use_extended_sequence_number;
6786 sa.is_tunnel = mp->is_tunnel;
6787 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6788 if (sa.is_tunnel_ip6)
6790 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6791 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6795 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6796 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6799 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6801 rv = VNET_API_ERROR_UNIMPLEMENTED;
6806 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6810 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6812 vl_api_ikev2_profile_add_del_reply_t *rmp;
6816 vlib_main_t *vm = vlib_get_main ();
6817 clib_error_t *error;
6818 u8 *tmp = format (0, "%s", mp->name);
6819 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6822 rv = VNET_API_ERROR_UNSPECIFIED;
6824 rv = VNET_API_ERROR_UNIMPLEMENTED;
6827 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6831 vl_api_ikev2_profile_set_auth_t_handler
6832 (vl_api_ikev2_profile_set_auth_t * mp)
6834 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6838 vlib_main_t *vm = vlib_get_main ();
6839 clib_error_t *error;
6840 u8 *tmp = format (0, "%s", mp->name);
6841 u8 *data = vec_new (u8, mp->data_len);
6842 clib_memcpy (data, mp->data, mp->data_len);
6843 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6847 rv = VNET_API_ERROR_UNSPECIFIED;
6849 rv = VNET_API_ERROR_UNIMPLEMENTED;
6852 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6856 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6858 vl_api_ikev2_profile_add_del_reply_t *rmp;
6862 vlib_main_t *vm = vlib_get_main ();
6863 clib_error_t *error;
6864 u8 *tmp = format (0, "%s", mp->name);
6865 u8 *data = vec_new (u8, mp->data_len);
6866 clib_memcpy (data, mp->data, mp->data_len);
6867 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6871 rv = VNET_API_ERROR_UNSPECIFIED;
6873 rv = VNET_API_ERROR_UNIMPLEMENTED;
6876 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6880 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6882 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6886 vlib_main_t *vm = vlib_get_main ();
6887 clib_error_t *error;
6888 u8 *tmp = format (0, "%s", mp->name);
6889 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6890 mp->end_port, (ip4_address_t) mp->start_addr,
6891 (ip4_address_t) mp->end_addr, mp->is_local);
6894 rv = VNET_API_ERROR_UNSPECIFIED;
6896 rv = VNET_API_ERROR_UNIMPLEMENTED;
6899 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6903 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6905 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6909 vlib_main_t *vm = vlib_get_main ();
6910 clib_error_t *error;
6912 error = ikev2_set_local_key (vm, mp->key_file);
6914 rv = VNET_API_ERROR_UNSPECIFIED;
6916 rv = VNET_API_ERROR_UNIMPLEMENTED;
6919 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6923 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6925 vl_api_map_add_domain_reply_t *rmp;
6928 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6930 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6931 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6932 (ip6_address_t *) & mp->ip6_src,
6933 mp->ip6_src_prefix_len, mp->ea_bits_len,
6934 mp->psid_offset, mp->psid_length, &index,
6935 ntohs (mp->mtu), flags);
6938 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6940 rmp->index = ntohl(index);
6946 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6948 vl_api_map_del_domain_reply_t *rmp;
6951 rv = map_delete_domain (ntohl (mp->index));
6953 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6957 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6959 vl_api_map_del_domain_reply_t *rmp;
6963 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6964 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6966 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6970 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6972 vl_api_map_domain_details_t *rmp;
6973 map_main_t *mm = &map_main;
6975 unix_shared_memory_queue_t *q;
6977 if (pool_elts (mm->domains) == 0)
6980 q = vl_api_client_index_to_input_queue (mp->client_index);
6987 pool_foreach(d, mm->domains,
6989 /* Make sure every field is initiated (or don't skip the memset()) */
6990 rmp = vl_msg_api_alloc (sizeof (*rmp));
6991 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6992 rmp->domain_index = htonl(d - mm->domains);
6993 rmp->ea_bits_len = d->ea_bits_len;
6994 rmp->psid_offset = d->psid_offset;
6995 rmp->psid_length = d->psid_length;
6996 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6997 rmp->ip4_prefix_len = d->ip4_prefix_len;
6998 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6999 rmp->ip6_prefix_len = d->ip6_prefix_len;
7000 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
7001 rmp->ip6_src_len = d->ip6_src_len;
7002 rmp->mtu = htons(d->mtu);
7003 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
7004 rmp->context = mp->context;
7006 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7012 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
7014 unix_shared_memory_queue_t *q;
7017 vl_api_map_rule_details_t *rmp;
7018 map_main_t *mm = &map_main;
7019 u32 domain_index = ntohl (mp->domain_index);
7022 if (pool_elts (mm->domains) == 0)
7025 d = pool_elt_at_index (mm->domains, domain_index);
7026 if (!d || !d->rules)
7031 q = vl_api_client_index_to_input_queue (mp->client_index);
7037 for (i = 0; i < (0x1 << d->psid_length); i++)
7040 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
7044 rmp = vl_msg_api_alloc (sizeof (*rmp));
7045 memset (rmp, 0, sizeof (*rmp));
7046 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
7047 rmp->psid = htons (i);
7048 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
7049 rmp->context = mp->context;
7050 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7055 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
7057 vl_api_map_summary_stats_reply_t *rmp;
7058 vlib_combined_counter_main_t *cm;
7061 u64 total_pkts[VLIB_N_RX_TX];
7062 u64 total_bytes[VLIB_N_RX_TX];
7063 map_main_t *mm = &map_main;
7064 unix_shared_memory_queue_t *q =
7065 vl_api_client_index_to_input_queue (mp->client_index);
7070 rmp = vl_msg_api_alloc (sizeof (*rmp));
7071 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
7072 rmp->context = mp->context;
7075 memset (total_pkts, 0, sizeof (total_pkts));
7076 memset (total_bytes, 0, sizeof (total_bytes));
7078 map_domain_counter_lock (mm);
7079 vec_foreach (cm, mm->domain_counters)
7081 which = cm - mm->domain_counters;
7083 for (i = 0; i < vec_len (cm->maxi); i++)
7085 vlib_get_combined_counter (cm, i, &v);
7086 total_pkts[which] += v.packets;
7087 total_bytes[which] += v.bytes;
7091 map_domain_counter_unlock (mm);
7093 /* Note: in network byte order! */
7094 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
7095 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
7096 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
7097 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
7098 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
7099 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
7100 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
7101 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
7102 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
7103 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
7104 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
7105 clib_host_to_net_u64 (map_error_counter_get
7106 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
7107 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
7108 clib_host_to_net_u64 (map_error_counter_get
7109 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
7111 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7115 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
7117 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
7118 vl_api_ipsec_sa_set_key_reply_t *rmp;
7122 sa.id = ntohl (mp->sa_id);
7123 sa.crypto_key_len = mp->crypto_key_length;
7124 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
7125 sa.integ_key_len = mp->integrity_key_length;
7126 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
7128 rv = ipsec_set_sa_key (vm, &sa);
7130 rv = VNET_API_ERROR_UNIMPLEMENTED;
7133 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
7136 static void vl_api_cop_interface_enable_disable_t_handler
7137 (vl_api_cop_interface_enable_disable_t * mp)
7139 vl_api_cop_interface_enable_disable_reply_t *rmp;
7141 u32 sw_if_index = ntohl (mp->sw_if_index);
7144 VALIDATE_SW_IF_INDEX (mp);
7146 enable_disable = (int) mp->enable_disable;
7148 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
7150 BAD_SW_IF_INDEX_LABEL;
7152 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
7155 static void vl_api_cop_whitelist_enable_disable_t_handler
7156 (vl_api_cop_whitelist_enable_disable_t * mp)
7158 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
7159 cop_whitelist_enable_disable_args_t _a, *a = &_a;
7160 u32 sw_if_index = ntohl (mp->sw_if_index);
7163 VALIDATE_SW_IF_INDEX (mp);
7165 a->sw_if_index = sw_if_index;
7168 a->default_cop = mp->default_cop;
7169 a->fib_id = ntohl (mp->fib_id);
7171 rv = cop_whitelist_enable_disable (a);
7173 BAD_SW_IF_INDEX_LABEL;
7175 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
7179 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
7183 api_main_t *am = &api_main;
7184 vlib_main_t *vm = vlib_get_main ();
7186 vl_api_get_node_graph_reply_t *rmp;
7188 pthread_mutex_lock (&am->vlib_rp->mutex);
7189 oldheap = svm_push_data_heap (am->vlib_rp);
7192 * Keep the number of memcpy ops to a minimum (e.g. 1).
7194 vec_validate (vector, 16384);
7195 vec_reset_length (vector);
7198 vector = vlib_node_serialize (&vm->node_main, vector,
7199 (u32) ~ 0 /* all threads */ ,
7200 1 /* include nexts */ ,
7201 1 /* include stats */ );
7203 svm_pop_heap (oldheap);
7204 pthread_mutex_unlock (&am->vlib_rp->mutex);
7207 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
7209 rmp->reply_in_shmem = (uword) vector;
7215 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
7218 vl_api_ioam_enable_reply_t *rmp;
7219 clib_error_t *error;
7221 /* Ignoring the profile id as currently a single profile
7223 error = ip6_ioam_enable (mp->trace_enable, mp->pow_enable, mp->trace_ppc);
7226 clib_error_report (error);
7227 rv = clib_error_get_code (error);
7230 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
7234 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
7237 vl_api_ioam_disable_reply_t *rmp;
7238 clib_error_t *error;
7240 error = clear_ioam_rewrite_fn ();
7243 clib_error_report (error);
7244 rv = clib_error_get_code (error);
7247 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
7251 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7253 vlib_main_t *vm = vlib_get_main ();
7254 vl_api_af_packet_create_reply_t *rmp;
7256 u8 *host_if_name = NULL;
7259 host_if_name = format (0, "%s", mp->host_if_name);
7260 vec_add1 (host_if_name, 0);
7262 rv = af_packet_create_if (vm, host_if_name,
7263 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7266 vec_free (host_if_name);
7269 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7271 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7277 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7279 vlib_main_t *vm = vlib_get_main ();
7280 vl_api_af_packet_delete_reply_t *rmp;
7282 u8 *host_if_name = NULL;
7284 host_if_name = format (0, "%s", mp->host_if_name);
7285 vec_add1 (host_if_name, 0);
7287 rv = af_packet_delete_if (vm, host_if_name);
7289 vec_free (host_if_name);
7291 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7295 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7297 vlib_main_t *vm = vlib_get_main ();
7298 vl_api_policer_add_del_reply_t *rmp;
7301 sse2_qos_pol_cfg_params_st cfg;
7302 clib_error_t *error;
7305 name = format (0, "%s", mp->name);
7307 memset (&cfg, 0, sizeof (cfg));
7309 cfg.rnd_type = mp->round_type;
7310 cfg.rate_type = mp->rate_type;
7311 cfg.rb.kbps.cir_kbps = mp->cir;
7312 cfg.rb.kbps.eir_kbps = mp->eir;
7313 cfg.rb.kbps.cb_bytes = mp->cb;
7314 cfg.rb.kbps.eb_bytes = mp->eb;
7315 cfg.conform_action.action_type = mp->conform_action_type;
7316 cfg.conform_action.dscp = mp->conform_dscp;
7317 cfg.exceed_action.action_type = mp->exceed_action_type;
7318 cfg.exceed_action.dscp = mp->exceed_dscp;
7319 cfg.violate_action.action_type = mp->violate_action_type;
7320 cfg.violate_action.dscp = mp->violate_dscp;
7321 cfg.color_aware = mp->color_aware;
7323 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7326 rv = VNET_API_ERROR_UNSPECIFIED;
7329 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7331 if (rv == 0 && mp->is_add)
7332 rmp->policer_index = ntohl(policer_index);
7334 rmp->policer_index = ~0;
7340 send_policer_details (u8 * name,
7341 sse2_qos_pol_cfg_params_st * config,
7342 policer_read_response_type_st * templ,
7343 unix_shared_memory_queue_t * q, u32 context)
7345 vl_api_policer_details_t *mp;
7347 mp = vl_msg_api_alloc (sizeof (*mp));
7348 memset (mp, 0, sizeof (*mp));
7349 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7350 mp->context = context;
7351 mp->cir = htonl (config->rb.kbps.cir_kbps);
7352 mp->eir = htonl (config->rb.kbps.eir_kbps);
7353 mp->cb = htonl (config->rb.kbps.cb_bytes);
7354 mp->eb = htonl (config->rb.kbps.eb_bytes);
7355 mp->rate_type = config->rate_type;
7356 mp->round_type = config->rnd_type;
7357 mp->type = config->rfc;
7358 mp->conform_action_type = config->conform_action.action_type;
7359 mp->conform_dscp = config->conform_action.dscp;
7360 mp->exceed_action_type = config->exceed_action.action_type;
7361 mp->exceed_dscp = config->exceed_action.dscp;
7362 mp->violate_action_type = config->violate_action.action_type;
7363 mp->violate_dscp = config->violate_action.dscp;
7364 mp->single_rate = templ->single_rate ? 1 : 0;
7365 mp->color_aware = templ->color_aware ? 1 : 0;
7366 mp->scale = htonl (templ->scale);
7367 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7368 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7369 mp->current_limit = htonl (templ->current_limit);
7370 mp->current_bucket = htonl (templ->current_bucket);
7371 mp->extended_limit = htonl (templ->extended_limit);
7372 mp->extended_bucket = htonl (templ->extended_bucket);
7373 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7375 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7377 vl_msg_api_send_shmem (q, (u8 *) & mp);
7381 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7383 unix_shared_memory_queue_t *q;
7384 vnet_policer_main_t *pm = &vnet_policer_main;
7390 sse2_qos_pol_cfg_params_st *config;
7391 policer_read_response_type_st *templ;
7393 q = vl_api_client_index_to_input_queue (mp->client_index);
7397 if (mp->match_name_valid)
7399 match_name = format (0, "%s%c", mp->match_name, 0);
7402 if (mp->match_name_valid)
7404 p = hash_get_mem (pm->policer_config_by_name, match_name);
7408 config = pool_elt_at_index (pm->configs, pool_index);
7409 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7410 send_policer_details (match_name, config, templ, q, mp->context);
7416 hash_foreach_pair (hp, pm->policer_config_by_name,
7418 name = (u8 *) hp->key;
7419 pool_index = hp->value[0];
7420 config = pool_elt_at_index (pm->configs, pool_index);
7421 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7422 send_policer_details(name, config, templ, q, mp->context);
7429 vl_api_policer_classify_set_interface_t_handler
7430 (vl_api_policer_classify_set_interface_t * mp)
7432 vlib_main_t *vm = vlib_get_main ();
7433 vl_api_policer_classify_set_interface_reply_t *rmp;
7435 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7437 ip4_table_index = ntohl (mp->ip4_table_index);
7438 ip6_table_index = ntohl (mp->ip6_table_index);
7439 l2_table_index = ntohl (mp->l2_table_index);
7440 sw_if_index = ntohl (mp->sw_if_index);
7442 VALIDATE_SW_IF_INDEX (mp);
7444 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7445 ip6_table_index, l2_table_index,
7448 BAD_SW_IF_INDEX_LABEL;
7450 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7454 send_policer_classify_details (u32 sw_if_index,
7456 unix_shared_memory_queue_t * q, u32 context)
7458 vl_api_policer_classify_details_t *mp;
7460 mp = vl_msg_api_alloc (sizeof (*mp));
7461 memset (mp, 0, sizeof (*mp));
7462 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7463 mp->context = context;
7464 mp->sw_if_index = htonl (sw_if_index);
7465 mp->table_index = htonl (table_index);
7467 vl_msg_api_send_shmem (q, (u8 *) & mp);
7471 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7473 unix_shared_memory_queue_t *q;
7474 policer_classify_main_t *pcm = &policer_classify_main;
7478 q = vl_api_client_index_to_input_queue (mp->client_index);
7482 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7484 if (vec_len (vec_tbl))
7486 for (i = 0; i < vec_len (vec_tbl); i++)
7488 if (vec_elt (vec_tbl, i) == ~0)
7491 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7498 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7500 vlib_main_t *vm = vlib_get_main ();
7501 vl_api_netmap_create_reply_t *rmp;
7505 if_name = format (0, "%s", mp->netmap_if_name);
7506 vec_add1 (if_name, 0);
7509 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7510 mp->is_pipe, mp->is_master, 0);
7514 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7518 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7520 vlib_main_t *vm = vlib_get_main ();
7521 vl_api_netmap_delete_reply_t *rmp;
7525 if_name = format (0, "%s", mp->netmap_if_name);
7526 vec_add1 (if_name, 0);
7528 rv = netmap_delete_if (vm, if_name);
7532 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7536 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7539 clib_warning ("BUG");
7543 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7544 unix_shared_memory_queue_t * q,
7545 mpls_eth_tunnel_t * et, u32 index, u32 context)
7547 mpls_main_t *mm = &mpls_main;
7551 vl_api_mpls_eth_tunnel_details_t *mp;
7553 e = pool_elt_at_index (mm->encaps, et->encap_index);
7554 nlabels = vec_len (e->labels);
7556 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7557 memset (mp, 0, sizeof (*mp));
7558 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7559 mp->context = context;
7561 mp->tunnel_index = htonl (index);
7562 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7563 mp->intfc_address = et->intfc_address.as_u32;
7564 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7565 mp->inner_fib_index = htonl (et->inner_fib_index);
7566 mp->mask_width = htonl (et->mask_width);
7567 mp->encap_index = htonl (et->encap_index);
7568 mp->hw_if_index = htonl (et->hw_if_index);
7569 mp->l2_only = htonl (et->l2_only);
7570 mp->nlabels = htonl (nlabels);
7572 for (i = 0; i < nlabels; i++)
7575 htonl (vnet_mpls_uc_get_label
7576 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7579 vl_msg_api_send_shmem (q, (u8 *) & mp);
7583 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7585 vpe_api_main_t *am = &vpe_api_main;
7586 unix_shared_memory_queue_t *q;
7587 mpls_main_t *mm = &mpls_main;
7588 mpls_eth_tunnel_t *et;
7589 u32 index = ntohl (mp->tunnel_index);
7591 q = vl_api_client_index_to_input_queue (mp->client_index);
7597 if (!pool_is_free_index (mm->eth_tunnels, index))
7599 et = pool_elt_at_index (mm->eth_tunnels, index);
7600 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7607 pool_foreach (et, mm->eth_tunnels,
7609 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7617 vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
7619 clib_warning ("BUG");
7623 send_mpls_fib_details (vpe_api_main_t * am,
7624 unix_shared_memory_queue_t * q,
7625 u32 table_id, u32 label, u32 eos, u32 context)
7627 vl_api_mpls_fib_details_t *mp;
7629 mp = vl_msg_api_alloc (sizeof (*mp));
7630 memset (mp, 0, sizeof (*mp));
7631 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
7632 mp->context = context;
7634 mp->table_id = htonl (table_id);
7636 mp->label = htonl (label);
7638 vl_msg_api_send_shmem (q, (u8 *) & mp);
7642 vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp)
7644 vpe_api_main_t *am = &vpe_api_main;
7645 unix_shared_memory_queue_t *q;
7646 mpls_main_t *mm = &mpls_main;
7647 fib_table_t *fib_table;
7648 fib_node_index_t lfei, *lfeip, *lfeis = NULL;
7653 q = vl_api_client_index_to_input_queue (mp->client_index);
7658 pool_foreach (fib_table, mm->fibs,
7660 hash_foreach(key, lfei, fib_table->mpls.mf_entries,
7662 vec_add1(lfeis, lfei);
7665 vec_sort_with_function(lfeis, fib_entry_cmp_for_sort);
7667 vec_foreach(lfeip, lfeis)
7669 fib_entry_get_prefix(*lfeip, &pfx);
7670 fib_index = fib_entry_get_fib_index(*lfeip);
7672 fib_table = fib_table_get(fib_index, pfx.fp_proto);
7674 send_mpls_fib_details (am, q,
7675 fib_table->ft_table_id,
7685 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7687 clib_warning ("BUG");
7691 send_mpls_fib_encap_details (vpe_api_main_t * am,
7692 unix_shared_memory_queue_t * q,
7693 show_mpls_fib_t * s, u32 context)
7695 vl_api_mpls_fib_encap_details_t *mp;
7696 mpls_main_t *mm = &mpls_main;
7701 e = pool_elt_at_index (mm->encaps, s->entry_index);
7702 nlabels = vec_len (e->labels);
7704 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7705 memset (mp, 0, sizeof (*mp));
7706 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7707 mp->context = context;
7709 mp->fib_index = htonl (s->fib_index);
7710 mp->entry_index = htonl (s->entry_index);
7712 mp->s_bit = htonl (s->s_bit);
7714 mp->nlabels = htonl (nlabels);
7716 for (i = 0; i < nlabels; i++)
7719 htonl (vnet_mpls_uc_get_label
7720 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7723 vl_msg_api_send_shmem (q, (u8 *) & mp);
7727 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7729 vpe_api_main_t *am = &vpe_api_main;
7730 unix_shared_memory_queue_t *q;
7731 vlib_main_t *vm = &vlib_global_main;
7734 show_mpls_fib_t *records = 0;
7736 mpls_main_t *mm = &mpls_main;
7739 q = vl_api_client_index_to_input_queue (mp->client_index);
7744 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7746 vec_add2 (records, s, 1);
7747 s->fib_index = (u32)(key>>32);
7748 s->dest = (u32)(key & 0xFFFFFFFF);
7749 s->entry_index = (u32) value;
7753 if (0 == vec_len (records))
7755 vlib_cli_output (vm, "MPLS encap table empty");
7759 /* sort output by dst address within fib */
7760 vec_sort_with_function (records, mpls_dest_cmp);
7761 vec_sort_with_function (records, mpls_fib_index_cmp);
7762 vlib_cli_output (vm, "MPLS encap table");
7763 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7764 vec_foreach (s, records)
7766 rx_fib = ip4_fib_get (s->fib_index);
7767 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7768 format_ip4_address, &s->dest, format_mpls_encap_index,
7769 mm, s->entry_index);
7770 send_mpls_fib_encap_details (am, q, s, mp->context);
7778 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7780 unix_shared_memory_queue_t *q;
7782 q = vl_api_client_index_to_input_queue (mp->client_index);
7786 vnet_classify_main_t *cm = &vnet_classify_main;
7787 vnet_classify_table_t *t;
7792 pool_foreach (t, cm->tables,
7794 vec_add1 (table_ids, ntohl(t - cm->tables));
7797 count = vec_len (table_ids);
7799 vl_api_classify_table_ids_reply_t *rmp;
7800 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7801 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7802 rmp->context = mp->context;
7803 rmp->count = ntohl (count);
7804 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7807 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7809 vec_free (table_ids);
7813 vl_api_classify_table_by_interface_t_handler
7814 (vl_api_classify_table_by_interface_t * mp)
7816 vl_api_classify_table_by_interface_reply_t *rmp;
7819 u32 sw_if_index = ntohl (mp->sw_if_index);
7822 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7825 VALIDATE_SW_IF_INDEX (mp);
7827 input_acl_main_t *am = &input_acl_main;
7832 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7834 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7835 if (vec_len (vec_tbl))
7837 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7839 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7843 acl[type] = vec_elt (vec_tbl, if_idx);
7848 BAD_SW_IF_INDEX_LABEL;
7851 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7853 rmp->sw_if_index = ntohl(sw_if_index);
7854 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7855 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7856 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7863 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7865 unix_shared_memory_queue_t *q;
7867 q = vl_api_client_index_to_input_queue (mp->client_index);
7871 vl_api_classify_table_info_reply_t *rmp = 0;
7873 vnet_classify_main_t *cm = &vnet_classify_main;
7874 u32 table_id = ntohl (mp->table_id);
7875 vnet_classify_table_t *t;
7878 pool_foreach (t, cm->tables,
7880 if (table_id == t - cm->tables)
7882 rmp = vl_msg_api_alloc_as_if_client
7883 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7884 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7885 rmp->context = mp->context;
7886 rmp->table_id = ntohl(table_id);
7887 rmp->nbuckets = ntohl(t->nbuckets);
7888 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7889 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7890 rmp->active_sessions = ntohl(t->active_elements);
7891 rmp->next_table_index = ntohl(t->next_table_index);
7892 rmp->miss_next_index = ntohl(t->miss_next_index);
7893 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7894 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7903 rmp = vl_msg_api_alloc (sizeof (*rmp));
7904 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7905 rmp->context = mp->context;
7906 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7909 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7913 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7916 clib_warning ("BUG");
7920 send_classify_session_details (unix_shared_memory_queue_t * q,
7923 vnet_classify_entry_t * e, u32 context)
7925 vl_api_classify_session_details_t *rmp;
7927 rmp = vl_msg_api_alloc (sizeof (*rmp));
7928 memset (rmp, 0, sizeof (*rmp));
7929 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7930 rmp->context = context;
7931 rmp->table_id = ntohl (table_id);
7932 rmp->hit_next_index = ntohl (e->next_index);
7933 rmp->advance = ntohl (e->advance);
7934 rmp->opaque_index = ntohl (e->opaque_index);
7935 rmp->match_length = ntohl (match_length);
7936 clib_memcpy (rmp->match, e->key, match_length);
7938 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7942 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7944 vnet_classify_main_t *cm = &vnet_classify_main;
7945 unix_shared_memory_queue_t *q;
7947 u32 table_id = ntohl (mp->table_id);
7948 vnet_classify_table_t *t;
7950 q = vl_api_client_index_to_input_queue (mp->client_index);
7955 pool_foreach (t, cm->tables,
7957 if (table_id == t - cm->tables)
7959 vnet_classify_bucket_t * b;
7960 vnet_classify_entry_t * v, * save_v;
7963 for (i = 0; i < t->nbuckets; i++)
7965 b = &t->buckets [i];
7969 save_v = vnet_classify_get_entry (t, b->offset);
7970 for (j = 0; j < (1<<b->log2_pages); j++)
7972 for (k = 0; k < t->entries_per_page; k++)
7974 v = vnet_classify_entry_at_index
7975 (t, save_v, j*t->entries_per_page + k);
7976 if (vnet_classify_entry_is_free (v))
7979 send_classify_session_details
7980 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7992 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7994 vlib_main_t *vm = vlib_get_main ();
7995 flow_report_main_t *frm = &flow_report_main;
7996 vl_api_set_ipfix_exporter_reply_t *rmp;
7997 ip4_address_t collector, src;
7998 u16 collector_port = UDP_DST_PORT_ipfix;
8000 u32 template_interval;
8006 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
8007 collector_port = ntohs (mp->collector_port);
8008 if (collector_port == (u16) ~ 0)
8009 collector_port = UDP_DST_PORT_ipfix;
8010 memcpy (src.data, mp->src_address, sizeof (src.data));
8011 fib_id = ntohl (mp->vrf_id);
8013 ip4_main_t *im = &ip4_main;
8020 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
8023 rv = VNET_API_ERROR_NO_SUCH_FIB;
8029 path_mtu = ntohl (mp->path_mtu);
8031 path_mtu = 512; // RFC 7011 section 10.3.3.
8032 template_interval = ntohl (mp->template_interval);
8033 if (template_interval == ~0)
8034 template_interval = 20;
8035 udp_checksum = mp->udp_checksum;
8037 if (collector.as_u32 == 0)
8039 rv = VNET_API_ERROR_INVALID_VALUE;
8043 if (src.as_u32 == 0)
8045 rv = VNET_API_ERROR_INVALID_VALUE;
8049 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
8051 rv = VNET_API_ERROR_INVALID_VALUE;
8057 rv = VNET_API_ERROR_INVALID_VALUE;
8061 /* Reset report streams if we are reconfiguring IP addresses */
8062 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
8063 frm->src_address.as_u32 != src.as_u32 ||
8064 frm->collector_port != collector_port)
8065 vnet_flow_reports_reset (frm);
8067 frm->ipfix_collector.as_u32 = collector.as_u32;
8068 frm->collector_port = collector_port;
8069 frm->src_address.as_u32 = src.as_u32;
8070 frm->fib_index = fib_index;
8071 frm->path_mtu = path_mtu;
8072 frm->template_interval = template_interval;
8073 frm->udp_checksum = udp_checksum;
8075 /* Turn on the flow reporting process */
8076 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
8079 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
8083 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
8085 flow_report_main_t *frm = &flow_report_main;
8086 unix_shared_memory_queue_t *q;
8087 vl_api_ipfix_exporter_details_t *rmp;
8088 ip4_main_t *im = &ip4_main;
8091 q = vl_api_client_index_to_input_queue (mp->client_index);
8095 rmp = vl_msg_api_alloc (sizeof (*rmp));
8096 memset (rmp, 0, sizeof (*rmp));
8097 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
8098 rmp->context = mp->context;
8099 memcpy (rmp->collector_address, frm->ipfix_collector.data,
8100 sizeof (frm->ipfix_collector.data));
8101 rmp->collector_port = htons (frm->collector_port);
8102 memcpy (rmp->src_address, frm->src_address.data,
8103 sizeof (frm->src_address.data));
8104 if (frm->fib_index == ~0)
8107 vrf_id = im->fibs[frm->fib_index].ft_table_id;
8108 rmp->vrf_id = htonl (vrf_id);
8109 rmp->path_mtu = htonl (frm->path_mtu);
8110 rmp->template_interval = htonl (frm->template_interval);
8111 rmp->udp_checksum = (frm->udp_checksum != 0);
8113 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8117 vl_api_set_ipfix_classify_stream_t_handler
8118 (vl_api_set_ipfix_classify_stream_t * mp)
8120 vl_api_set_ipfix_classify_stream_reply_t *rmp;
8121 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8122 flow_report_main_t *frm = &flow_report_main;
8124 u32 src_port = UDP_DST_PORT_ipfix;
8127 domain_id = ntohl (mp->domain_id);
8128 src_port = ntohs (mp->src_port);
8130 if (fcm->src_port != 0 &&
8131 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
8133 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
8134 domain_id, (u16) src_port);
8138 fcm->domain_id = domain_id;
8139 fcm->src_port = (u16) src_port;
8141 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8145 vl_api_ipfix_classify_stream_dump_t_handler
8146 (vl_api_ipfix_classify_stream_dump_t * mp)
8148 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8149 unix_shared_memory_queue_t *q;
8150 vl_api_ipfix_classify_stream_details_t *rmp;
8152 q = vl_api_client_index_to_input_queue (mp->client_index);
8156 rmp = vl_msg_api_alloc (sizeof (*rmp));
8157 memset (rmp, 0, sizeof (*rmp));
8158 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
8159 rmp->context = mp->context;
8160 rmp->domain_id = htonl (fcm->domain_id);
8161 rmp->src_port = htons (fcm->src_port);
8163 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8167 vl_api_ipfix_classify_table_add_del_t_handler
8168 (vl_api_ipfix_classify_table_add_del_t * mp)
8170 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
8171 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8172 flow_report_main_t *frm = &flow_report_main;
8173 vnet_flow_report_add_del_args_t args;
8174 ipfix_classify_table_t *table;
8176 u32 classify_table_index;
8178 u8 transport_protocol;
8181 classify_table_index = ntohl (mp->table_id);
8182 ip_version = mp->ip_version;
8183 transport_protocol = mp->transport_protocol;
8184 is_add = mp->is_add;
8186 if (fcm->src_port == 0)
8188 /* call set_ipfix_classify_stream first */
8189 rv = VNET_API_ERROR_UNSPECIFIED;
8193 memset (&args, 0, sizeof (args));
8197 for (i = 0; i < vec_len (fcm->tables); i++)
8198 if (ipfix_classify_table_index_valid (i))
8199 if (fcm->tables[i].classify_table_index == classify_table_index)
8201 table = &fcm->tables[i];
8209 rv = VNET_API_ERROR_VALUE_EXIST;
8212 table = ipfix_classify_add_table ();
8213 table->classify_table_index = classify_table_index;
8219 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
8224 table->ip_version = ip_version;
8225 table->transport_protocol = transport_protocol;
8227 args.opaque.as_uword = table - fcm->tables;
8228 args.rewrite_callback = ipfix_classify_template_rewrite;
8229 args.flow_data_callback = ipfix_classify_send_flows;
8230 args.is_add = is_add;
8231 args.domain_id = fcm->domain_id;
8232 args.src_port = fcm->src_port;
8234 rv = vnet_flow_report_add_del (frm, &args);
8236 /* If deleting, or add failed */
8237 if (is_add == 0 || (rv && is_add))
8238 ipfix_classify_delete_table (table - fcm->tables);
8241 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8245 send_ipfix_classify_table_details (u32 table_index,
8246 unix_shared_memory_queue_t * q,
8249 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8250 vl_api_ipfix_classify_table_details_t *mp;
8252 ipfix_classify_table_t *table = &fcm->tables[table_index];
8254 mp = vl_msg_api_alloc (sizeof (*mp));
8255 memset (mp, 0, sizeof (*mp));
8256 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
8257 mp->context = context;
8258 mp->table_id = htonl (table->classify_table_index);
8259 mp->ip_version = table->ip_version;
8260 mp->transport_protocol = table->transport_protocol;
8262 vl_msg_api_send_shmem (q, (u8 *) & mp);
8266 vl_api_ipfix_classify_table_dump_t_handler
8267 (vl_api_ipfix_classify_table_dump_t * mp)
8269 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8270 unix_shared_memory_queue_t *q;
8273 q = vl_api_client_index_to_input_queue (mp->client_index);
8277 for (i = 0; i < vec_len (fcm->tables); i++)
8278 if (ipfix_classify_table_index_valid (i))
8279 send_ipfix_classify_table_details (i, q, mp->context);
8283 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8285 vl_api_pg_create_interface_reply_t *rmp;
8288 pg_main_t *pg = &pg_main;
8289 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8290 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
8293 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8295 rmp->sw_if_index = ntohl(pi->sw_if_index);
8301 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8303 vl_api_pg_capture_reply_t *rmp;
8306 vnet_main_t *vnm = vnet_get_main ();
8307 vnet_interface_main_t *im = &vnm->interface_main;
8308 vnet_hw_interface_t *hi = 0;
8310 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8311 u32 hw_if_index = ~0;
8312 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8315 vec_free (intf_name);
8317 if (hw_if_index != ~0)
8319 pg_capture_args_t _a, *a = &_a;
8321 u32 len = ntohl (mp->pcap_name_length);
8322 u8 *pcap_file_name = vec_new (u8, len);
8323 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8325 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8326 a->hw_if_index = hw_if_index;
8327 a->dev_instance = hi->dev_instance;
8328 a->is_enabled = mp->is_enabled;
8329 a->pcap_file_name = pcap_file_name;
8330 a->count = ntohl (mp->count);
8332 clib_error_t *e = pg_capture (a);
8335 clib_error_report (e);
8336 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8339 vec_free (pcap_file_name);
8341 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8345 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8347 vl_api_pg_enable_disable_reply_t *rmp;
8350 pg_main_t *pg = &pg_main;
8351 u32 stream_index = ~0;
8353 int is_enable = mp->is_enabled != 0;
8354 u32 len = ntohl (mp->stream_name_length) - 1;
8358 u8 *stream_name = vec_new (u8, len);
8359 clib_memcpy (stream_name, mp->stream_name, len);
8360 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8363 vec_free (stream_name);
8366 pg_enable_disable (stream_index, is_enable);
8368 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8372 vl_api_ip_source_and_port_range_check_add_del_t_handler
8373 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8375 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8378 u8 is_ipv6 = mp->is_ipv6;
8379 u8 is_add = mp->is_add;
8380 u8 mask_length = mp->mask_length;
8381 ip4_address_t ip4_addr;
8382 ip6_address_t ip6_addr;
8384 u16 *high_ports = 0;
8386 u16 tmp_low, tmp_high;
8390 // Validate port range
8391 num_ranges = mp->number_of_ranges;
8392 if (num_ranges > 32)
8393 { // This is size of array in VPE.API
8394 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8398 vec_reset_length (low_ports);
8399 vec_reset_length (high_ports);
8401 for (i = 0; i < num_ranges; i++)
8403 tmp_low = mp->low_ports[i];
8404 tmp_high = mp->high_ports[i];
8405 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8406 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8407 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8409 rv = VNET_API_ERROR_INVALID_VALUE;
8412 vec_add1 (low_ports, tmp_low);
8413 vec_add1 (high_ports, tmp_high + 1);
8416 // Validate mask_length
8417 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8419 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8423 vrf_id = ntohl (mp->vrf_id);
8427 rv = VNET_API_ERROR_INVALID_VALUE;
8434 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8435 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8439 high_ports, is_add);
8443 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8444 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8448 high_ports, is_add);
8452 vec_free (low_ports);
8453 vec_free (high_ports);
8454 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8458 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8459 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8461 vlib_main_t *vm = vlib_get_main ();
8462 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8463 ip4_main_t *im = &ip4_main;
8466 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8467 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8471 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8472 ntohl (mp->tcp_out_vrf_id);
8473 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8474 ntohl (mp->udp_out_vrf_id);
8475 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8476 ntohl (mp->tcp_in_vrf_id);
8477 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8478 ntohl (mp->udp_in_vrf_id);
8481 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8483 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8485 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8489 rv = VNET_API_ERROR_INVALID_VALUE;
8493 fib_index[i] = p[0];
8498 sw_if_index = ntohl (mp->sw_if_index);
8500 VALIDATE_SW_IF_INDEX (mp);
8503 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8506 BAD_SW_IF_INDEX_LABEL;
8509 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8513 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8516 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8518 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8519 u32 sw_if_index = ~0;
8521 /* Check src & dst are different */
8522 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8524 rv = VNET_API_ERROR_SAME_SRC_DST;
8528 memset (a, 0, sizeof (*a));
8530 /* ip addresses sent in network byte order */
8531 clib_memcpy (&(a->src), mp->src_address, 4);
8532 clib_memcpy (&(a->dst), mp->dst_address, 4);
8533 a->is_add = mp->is_add;
8534 a->lsa = ntohl (mp->local_sa_id);
8535 a->rsa = ntohl (mp->remote_sa_id);
8537 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8541 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8543 rmp->sw_if_index = ntohl (sw_if_index);
8548 static void send_ipsec_gre_tunnel_details
8549 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8551 vl_api_ipsec_gre_tunnel_details_t *rmp;
8553 rmp = vl_msg_api_alloc (sizeof (*rmp));
8554 memset (rmp, 0, sizeof (*rmp));
8555 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8556 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8557 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8558 rmp->sw_if_index = htonl (t->sw_if_index);
8559 rmp->local_sa_id = htonl (t->local_sa_id);
8560 rmp->remote_sa_id = htonl (t->remote_sa_id);
8561 rmp->context = context;
8563 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8566 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8567 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8569 unix_shared_memory_queue_t *q;
8570 ipsec_gre_main_t *igm = &ipsec_gre_main;
8571 ipsec_gre_tunnel_t *t;
8574 q = vl_api_client_index_to_input_queue (mp->client_index);
8580 sw_if_index = ntohl (mp->sw_if_index);
8582 if (~0 == sw_if_index)
8585 pool_foreach (t, igm->tunnels,
8587 send_ipsec_gre_tunnel_details(t, q, mp->context);
8593 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8594 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8598 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8599 send_ipsec_gre_tunnel_details (t, q, mp->context);
8604 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8606 vl_api_delete_subif_reply_t *rmp;
8609 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8611 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8615 vl_api_l2_interface_pbb_tag_rewrite_t_handler
8616 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
8618 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
8619 vnet_main_t *vnm = vnet_get_main ();
8620 vlib_main_t *vm = vlib_get_main ();
8624 VALIDATE_SW_IF_INDEX (mp);
8626 vtr_op = ntohl (mp->vtr_op);
8630 case L2_VTR_DISABLED:
8633 case L2_VTR_TRANSLATE_2_1:
8637 rv = VNET_API_ERROR_INVALID_VALUE;
8638 goto bad_sw_if_index;
8641 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
8642 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
8643 ntohl (mp->i_sid), ntohs (mp->outer_tag));
8645 BAD_SW_IF_INDEX_LABEL;
8647 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
8651 vl_api_punt_t_handler (vl_api_punt_t * mp)
8653 vl_api_punt_reply_t *rmp;
8654 vlib_main_t *vm = vlib_get_main ();
8656 clib_error_t *error;
8658 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8659 ntohs (mp->l4_port), mp->is_add);
8663 clib_error_report (error);
8666 REPLY_MACRO (VL_API_PUNT_REPLY);
8670 vl_api_flow_classify_set_interface_t_handler
8671 (vl_api_flow_classify_set_interface_t * mp)
8673 vlib_main_t *vm = vlib_get_main ();
8674 vl_api_flow_classify_set_interface_reply_t *rmp;
8676 u32 sw_if_index, ip4_table_index, ip6_table_index;
8678 ip4_table_index = ntohl (mp->ip4_table_index);
8679 ip6_table_index = ntohl (mp->ip6_table_index);
8680 sw_if_index = ntohl (mp->sw_if_index);
8682 VALIDATE_SW_IF_INDEX (mp);
8684 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
8685 ip6_table_index, mp->is_add);
8687 BAD_SW_IF_INDEX_LABEL;
8689 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
8693 send_flow_classify_details (u32 sw_if_index,
8695 unix_shared_memory_queue_t * q, u32 context)
8697 vl_api_flow_classify_details_t *mp;
8699 mp = vl_msg_api_alloc (sizeof (*mp));
8700 memset (mp, 0, sizeof (*mp));
8701 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
8702 mp->context = context;
8703 mp->sw_if_index = htonl (sw_if_index);
8704 mp->table_index = htonl (table_index);
8706 vl_msg_api_send_shmem (q, (u8 *) & mp);
8710 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8712 unix_shared_memory_queue_t *q;
8713 flow_classify_main_t *pcm = &flow_classify_main;
8717 q = vl_api_client_index_to_input_queue (mp->client_index);
8721 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8723 if (vec_len (vec_tbl))
8725 for (i = 0; i < vec_len (vec_tbl); i++)
8727 if (vec_elt (vec_tbl, i) == ~0)
8730 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8736 #define BOUNCE_HANDLER(nn) \
8737 static void vl_api_##nn##_t_handler ( \
8738 vl_api_##nn##_t *mp) \
8740 vpe_client_registration_t *reg; \
8741 vpe_api_main_t * vam = &vpe_api_main; \
8742 unix_shared_memory_queue_t * q; \
8744 /* One registration only... */ \
8745 pool_foreach(reg, vam->nn##_registrations, \
8747 q = vl_api_client_index_to_input_queue (reg->client_index); \
8750 * If the queue is stuffed, turf the msg and complain \
8751 * It's unlikely that the intended recipient is \
8752 * alive; avoid deadlock at all costs. \
8754 if (q->cursize == q->maxsize) { \
8755 clib_warning ("ERROR: receiver queue full, drop msg"); \
8756 vl_msg_api_free (mp); \
8759 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8763 vl_msg_api_free (mp); \
8768 * Add vpe's API message handlers to the table.
8769 * vlib has alread mapped shared memory and
8770 * added the client registration handlers.
8771 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8774 static clib_error_t *
8775 vpe_api_hookup (vlib_main_t * vm)
8777 api_main_t *am = &api_main;
8780 vl_msg_api_set_handlers(VL_API_##N, #n, \
8781 vl_api_##n##_t_handler, \
8783 vl_api_##n##_t_endian, \
8784 vl_api_##n##_t_print, \
8785 sizeof(vl_api_##n##_t), 1);
8786 foreach_vpe_api_msg;
8790 * Manually register the sr tunnel add del msg, so we trace
8791 * enough bytes to capture a typical segment list
8793 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8794 "sr_tunnel_add_del",
8795 vl_api_sr_tunnel_add_del_t_handler,
8797 vl_api_sr_tunnel_add_del_t_endian,
8798 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8802 * Manually register the sr policy add del msg, so we trace
8803 * enough bytes to capture a typical tunnel name list
8805 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8806 "sr_policy_add_del",
8807 vl_api_sr_policy_add_del_t_handler,
8809 vl_api_sr_policy_add_del_t_endian,
8810 vl_api_sr_policy_add_del_t_print, 256, 1);
8813 * Trace space for 8 MPLS encap labels, classifier mask+match
8815 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8816 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8817 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8818 += 5 * sizeof (u32x4);
8819 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8822 * Thread-safe API messages
8824 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8825 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8830 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8832 static clib_error_t *
8833 vpe_api_init (vlib_main_t * vm)
8835 vpe_api_main_t *am = &vpe_api_main;
8838 am->vnet_main = vnet_get_main ();
8839 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8840 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8841 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8842 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8843 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8844 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8847 vl_set_memory_region_name ("/vpe-api");
8848 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8853 VLIB_INIT_FUNCTION (vpe_api_init);
8856 static clib_error_t *
8857 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8860 u64 baseva, size, pvt_heap_size;
8862 const int max_buf_size = 4096;
8864 struct passwd _pw, *pw;
8865 struct group _grp, *grp;
8867 buf = vec_new (char, 128);
8868 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8870 if (unformat (input, "prefix %s", &chroot_path))
8872 vec_add1 (chroot_path, 0);
8873 vl_set_memory_root_path ((char *) chroot_path);
8875 else if (unformat (input, "uid %d", &uid))
8876 vl_set_memory_uid (uid);
8877 else if (unformat (input, "gid %d", &gid))
8878 vl_set_memory_gid (gid);
8879 else if (unformat (input, "baseva %llx", &baseva))
8880 vl_set_global_memory_baseva (baseva);
8881 else if (unformat (input, "global-size %lldM", &size))
8882 vl_set_global_memory_size (size * (1ULL << 20));
8883 else if (unformat (input, "global-size %lldG", &size))
8884 vl_set_global_memory_size (size * (1ULL << 30));
8885 else if (unformat (input, "global-size %lld", &size))
8886 vl_set_global_memory_size (size);
8887 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8888 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8889 else if (unformat (input, "global-pvt-heap-size size %lld",
8891 vl_set_global_pvt_heap_size (pvt_heap_size);
8892 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8893 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8894 else if (unformat (input, "api-pvt-heap-size size %lld",
8896 vl_set_api_pvt_heap_size (pvt_heap_size);
8897 else if (unformat (input, "api-size %lldM", &size))
8898 vl_set_api_memory_size (size * (1ULL << 20));
8899 else if (unformat (input, "api-size %lldG", &size))
8900 vl_set_api_memory_size (size * (1ULL << 30));
8901 else if (unformat (input, "api-size %lld", &size))
8902 vl_set_api_memory_size (size);
8903 else if (unformat (input, "uid %s", &s))
8905 /* lookup the username */
8908 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8909 && (vec_len (buf) <= max_buf_size))
8911 vec_resize (buf, vec_len (buf) * 2);
8915 e = clib_error_return_code (0, rv,
8916 CLIB_ERROR_ERRNO_VALID |
8918 "cannot fetch username %s", s);
8926 clib_error_return_fatal (0, "username %s does not exist", s);
8932 vl_set_memory_uid (pw->pw_uid);
8934 else if (unformat (input, "gid %s", &s))
8936 /* lookup the group name */
8939 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8940 && (vec_len (buf) <= max_buf_size))
8942 vec_resize (buf, vec_len (buf) * 2);
8946 e = clib_error_return_code (0, rv,
8947 CLIB_ERROR_ERRNO_VALID |
8949 "cannot fetch group %s", s);
8956 e = clib_error_return_fatal (0, "group %s does not exist", s);
8963 vl_set_memory_gid (grp->gr_gid);
8966 return clib_error_return (0, "unknown input `%U'",
8967 format_unformat_error, input);
8972 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8975 get_unformat_vnet_sw_interface (void)
8977 return (void *) &unformat_vnet_sw_interface;
8980 #undef vl_api_version
8981 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8982 #include <vpp-api/vpe.api.h>
8983 #undef vl_api_version
8986 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8988 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8990 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8991 clib_host_to_net_u32 (mp->api_versions[0]),
8999 format_arp_event (u8 * s, va_list * args)
9001 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
9003 s = format (s, "pid %d: ", event->pid);
9005 s = format (s, "bd mac/ip4 binding events");
9007 s = format (s, "resolution for %U", format_ip4_address, &event->address);
9012 format_nd_event (u8 * s, va_list * args)
9014 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
9016 s = format (s, "pid %d: ", event->pid);
9018 s = format (s, "bd mac/ip6 binding events");
9020 s = format (s, "resolution for %U", format_ip6_address, event->address);
9024 static clib_error_t *
9025 show_ip_arp_nd_events_fn (vlib_main_t * vm,
9026 unformat_input_t * input, vlib_cli_command_t * cmd)
9028 vpe_api_main_t *am = &vpe_api_main;
9029 vl_api_ip4_arp_event_t *arp_event;
9030 vl_api_ip6_nd_event_t *nd_event;
9032 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
9034 vlib_cli_output (vm, "No active arp or nd event registrations");
9039 pool_foreach (arp_event, am->arp_events,
9041 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
9044 pool_foreach (nd_event, am->nd_events,
9046 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
9054 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
9055 .path = "show arp-nd-event registrations",
9056 .function = show_ip_arp_nd_events_fn,
9057 .short_help = "Show ip4 arp and ip6 nd event registrations",
9062 * fd.io coding-style-patch-verification: ON
9065 * eval: (c-set-style "gnu")