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 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
286 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
287 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
288 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
289 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
290 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
291 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
292 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
293 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
294 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
295 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
296 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
297 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
298 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
299 _(L2FIB_ADD_DEL, l2fib_add_del) \
300 _(L2_FLAGS, l2_flags) \
301 _(BRIDGE_FLAGS, bridge_flags) \
302 _(TAP_CONNECT, tap_connect) \
303 _(TAP_MODIFY, tap_modify) \
304 _(TAP_DELETE, tap_delete) \
305 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
306 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
307 _(CREATE_SUBIF, create_subif) \
308 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
309 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
310 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
311 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
312 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
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_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
430 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
431 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
432 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
433 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
434 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
435 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
436 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
437 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
438 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
439 _(CLASSIFY_TABLE_INFO,classify_table_info) \
440 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
441 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
442 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
443 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
444 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
445 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
446 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
447 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
448 _(GET_NEXT_INDEX, get_next_index) \
449 _(PG_CREATE_INTERFACE, pg_create_interface) \
450 _(PG_CAPTURE, pg_capture) \
451 _(PG_ENABLE_DISABLE, pg_enable_disable) \
452 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
453 ip_source_and_port_range_check_add_del) \
454 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
455 ip_source_and_port_range_check_interface_add_del) \
456 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
457 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
458 _(DELETE_SUBIF, delete_subif) \
459 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
461 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
462 _(FLOW_CLASSIFY_DUMP, flow_classify_dump)
465 #define QUOTE(x) QUOTE_(x)
467 #define foreach_registration_hash \
468 _(interface_events) \
469 _(to_netconf_server) \
470 _(from_netconf_server) \
471 _(to_netconf_client) \
472 _(from_netconf_client) \
477 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
478 RESOLVE_IP6_ADD_DEL_ROUTE,
479 RESOLVE_MPLS_ETHERNET_ADD_DEL,
487 vl_api_ip_add_del_route_t r;
488 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
495 #define _(a) uword *a##_registration_hash; \
496 vpe_client_registration_t * a##_registrations;
497 foreach_registration_hash
499 /* notifications happen really early in the game */
500 u8 link_state_process_up;
502 /* ip4 and ip6 pending route adds */
503 pending_route_t *pending_routes;
505 /* ip4 arp event registration pool */
506 vl_api_ip4_arp_event_t *arp_events;
508 /* ip6 nd event registration pool */
509 vl_api_ip6_nd_event_t *nd_events;
512 vlib_main_t *vlib_main;
513 vnet_main_t *vnet_main;
516 static vlib_node_registration_t vpe_resolver_process_node;
517 static vpe_api_main_t vpe_api_main;
519 static void send_sw_interface_flags (vpe_api_main_t * am,
520 unix_shared_memory_queue_t * q,
521 vnet_sw_interface_t * swif);
522 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
523 unix_shared_memory_queue_t * q,
526 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
527 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
530 /* Clean up all registrations belonging to the indicated client */
532 vl_api_memclnt_delete_callback (u32 client_index)
534 vpe_api_main_t *vam = &vpe_api_main;
535 vpe_client_registration_t *rp;
537 int stats_memclnt_delete_callback (u32 client_index);
539 stats_memclnt_delete_callback (client_index);
542 p = hash_get (vam->a##_registration_hash, client_index); \
544 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
545 pool_put (vam->a##_registrations, rp); \
546 hash_unset (vam->a##_registration_hash, client_index); \
548 foreach_registration_hash;
553 #define API_LINK_STATE_EVENT 1
554 #define API_ADMIN_UP_DOWN_EVENT 2
557 event_data_cmp (void *a1, void *a2)
562 return (word) e1[0] - (word) e2[0];
566 link_state_process (vlib_main_t * vm,
567 vlib_node_runtime_t * rt, vlib_frame_t * f)
569 vpe_api_main_t *vam = &vpe_api_main;
570 vnet_main_t *vnm = vam->vnet_main;
571 vnet_sw_interface_t *swif;
572 uword *event_data = 0;
573 vpe_client_registration_t *reg;
575 u32 prev_sw_if_index;
576 unix_shared_memory_queue_t *q;
578 vam->link_state_process_up = 1;
582 vlib_process_wait_for_event (vm);
584 /* Unified list of changed link or admin state sw_if_indices */
585 vlib_process_get_events_with_type
586 (vm, &event_data, API_LINK_STATE_EVENT);
587 vlib_process_get_events_with_type
588 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
590 /* Sort, so we can eliminate duplicates */
591 vec_sort_with_function (event_data, event_data_cmp);
593 prev_sw_if_index = ~0;
595 for (i = 0; i < vec_len (event_data); i++)
597 /* Only one message per swif */
598 if (prev_sw_if_index == event_data[i])
600 prev_sw_if_index = event_data[i];
603 pool_foreach(reg, vam->interface_events_registrations,
605 q = vl_api_client_index_to_input_queue (reg->client_index);
608 /* sw_interface may be deleted already */
609 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
612 swif = vnet_get_sw_interface (vnm, event_data[i]);
613 send_sw_interface_flags (vam, q, swif);
619 vec_reset_length (event_data);
625 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
627 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
628 u32 hw_if_index, u32 flags);
631 VLIB_REGISTER_NODE (link_state_process_node,static) = {
632 .function = link_state_process,
633 .type = VLIB_NODE_TYPE_PROCESS,
634 .name = "vpe-link-state-process",
638 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
639 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
641 static clib_error_t *
642 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
644 vpe_api_main_t *vam = &vpe_api_main;
645 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
647 if (vam->link_state_process_up)
648 vlib_process_signal_event (vam->vlib_main,
649 link_state_process_node.index,
650 API_LINK_STATE_EVENT, hi->sw_if_index);
654 static clib_error_t *
655 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
657 vpe_api_main_t *vam = &vpe_api_main;
660 * Note: it's perfectly fair to set a subif admin up / admin down.
661 * Note the subtle distinction between this routine and the previous
664 if (vam->link_state_process_up)
665 vlib_process_signal_event (vam->vlib_main,
666 link_state_process_node.index,
667 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
671 #define pub_sub_handler(lca,UCA) \
672 static void vl_api_want_##lca##_t_handler ( \
673 vl_api_want_##lca##_t *mp) \
675 vpe_api_main_t *vam = &vpe_api_main; \
676 vpe_client_registration_t *rp; \
677 vl_api_want_##lca##_reply_t *rmp; \
681 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
683 if (mp->enable_disable) { \
684 clib_warning ("pid %d: already enabled...", mp->pid); \
685 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
688 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
689 pool_put (vam->lca##_registrations, rp); \
690 hash_unset (vam->lca##_registration_hash, \
695 if (mp->enable_disable == 0) { \
696 clib_warning ("pid %d: already disabled...", mp->pid); \
697 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
700 pool_get (vam->lca##_registrations, rp); \
701 rp->client_index = mp->client_index; \
702 rp->client_pid = mp->pid; \
703 hash_set (vam->lca##_registration_hash, rp->client_index, \
704 rp - vam->lca##_registrations); \
707 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
711 pub_sub_handler (interface_events, INTERFACE_EVENTS)
712 pub_sub_handler (oam_events, OAM_EVENTS)
715 #define RESOLUTION_EVENT 1
716 #define RESOLUTION_PENDING_EVENT 2
717 #define IP4_ARP_EVENT 3
718 #define IP6_ND_EVENT 4
720 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
722 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
724 static int mpls_ethernet_add_del_tunnel_2_t_handler
725 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
728 handle_ip4_arp_event (u32 pool_index)
730 vpe_api_main_t *vam = &vpe_api_main;
731 vnet_main_t *vnm = vam->vnet_main;
732 vlib_main_t *vm = vam->vlib_main;
733 vl_api_ip4_arp_event_t *event;
734 vl_api_ip4_arp_event_t *mp;
735 unix_shared_memory_queue_t *q;
737 /* Client can cancel, die, etc. */
738 if (pool_is_free_index (vam->arp_events, pool_index))
741 event = pool_elt_at_index (vam->arp_events, pool_index);
743 q = vl_api_client_index_to_input_queue (event->client_index);
746 (void) vnet_add_del_ip4_arp_change_event
747 (vnm, arp_change_delete_callback,
748 event->pid, &event->address,
749 vpe_resolver_process_node.index, IP4_ARP_EVENT,
750 ~0 /* pool index, notused */ , 0 /* is_add */ );
754 if (q->cursize < q->maxsize)
756 mp = vl_msg_api_alloc (sizeof (*mp));
757 clib_memcpy (mp, event, sizeof (*mp));
758 vl_msg_api_send_shmem (q, (u8 *) & mp);
762 static f64 last_time;
764 * Throttle syslog msgs.
765 * It's pretty tempting to just revoke the registration...
767 if (vlib_time_now (vm) > last_time + 10.0)
769 clib_warning ("arp event for %U to pid %d: queue stuffed!",
770 format_ip4_address, &event->address, event->pid);
771 last_time = vlib_time_now (vm);
777 handle_ip6_nd_event (u32 pool_index)
779 vpe_api_main_t *vam = &vpe_api_main;
780 vnet_main_t *vnm = vam->vnet_main;
781 vlib_main_t *vm = vam->vlib_main;
782 vl_api_ip6_nd_event_t *event;
783 vl_api_ip6_nd_event_t *mp;
784 unix_shared_memory_queue_t *q;
786 /* Client can cancel, die, etc. */
787 if (pool_is_free_index (vam->nd_events, pool_index))
790 event = pool_elt_at_index (vam->nd_events, pool_index);
792 q = vl_api_client_index_to_input_queue (event->client_index);
795 (void) vnet_add_del_ip6_nd_change_event
796 (vnm, nd_change_delete_callback,
797 event->pid, &event->address,
798 vpe_resolver_process_node.index, IP6_ND_EVENT,
799 ~0 /* pool index, notused */ , 0 /* is_add */ );
803 if (q->cursize < q->maxsize)
805 mp = vl_msg_api_alloc (sizeof (*mp));
806 clib_memcpy (mp, event, sizeof (*mp));
807 vl_msg_api_send_shmem (q, (u8 *) & mp);
811 static f64 last_time;
813 * Throttle syslog msgs.
814 * It's pretty tempting to just revoke the registration...
816 if (vlib_time_now (vm) > last_time + 10.0)
818 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
819 format_ip6_address, &event->address, event->pid);
820 last_time = vlib_time_now (vm);
826 resolver_process (vlib_main_t * vm,
827 vlib_node_runtime_t * rt, vlib_frame_t * f)
830 uword *event_data = 0;
832 vpe_api_main_t *vam = &vpe_api_main;
834 vl_api_ip_add_del_route_t *adr;
835 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
836 u32 *resolution_failures = 0;
842 vlib_process_wait_for_event_or_clock (vm, timeout);
844 event_type = vlib_process_get_events (vm, &event_data);
848 case RESOLUTION_PENDING_EVENT:
852 case RESOLUTION_EVENT:
853 for (i = 0; i < vec_len (event_data); i++)
856 * Resolution events can occur long after the
857 * original request has timed out. $$$ add a cancel
860 if (pool_is_free_index (vam->pending_routes, event_data[i]))
863 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
867 switch (pr->resolve_type)
869 case RESOLVE_IP4_ADD_DEL_ROUTE:
870 rv = ip4_add_del_route_t_handler (adr);
871 clib_warning ("resolver: add %U/%d via %U %s",
873 (ip4_address_t *) & (adr->dst_address),
874 adr->dst_address_length,
876 (ip4_address_t *) & (adr->next_hop_address),
877 (rv >= 0) ? "succeeded" : "failed");
880 case RESOLVE_IP6_ADD_DEL_ROUTE:
881 rv = ip6_add_del_route_t_handler (adr);
882 clib_warning ("resolver: add %U/%d via %U %s",
884 (ip6_address_t *) & (adr->dst_address),
885 adr->dst_address_length,
887 (ip6_address_t *) & (adr->next_hop_address),
888 (rv >= 0) ? "succeeded" : "failed");
891 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
892 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
893 clib_warning ("resolver: add mpls-o-e via %U %s",
896 (pme->next_hop_ip4_address_in_outer_vrf),
897 (rv >= 0) ? "succeeded" : "failed");
901 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
903 pool_put (vam->pending_routes, pr);
908 for (i = 0; i < vec_len (event_data); i++)
909 handle_ip4_arp_event (event_data[i]);
913 for (i = 0; i < vec_len (event_data); i++)
914 handle_ip6_nd_event (event_data[i]);
917 case ~0: /* timeout, retry pending resolutions */
919 pool_foreach (pr, vam->pending_routes,
925 /* May fail, e.g. due to interface down */
926 switch (pr->resolve_type)
928 case RESOLVE_IP4_ADD_DEL_ROUTE:
929 e = ip4_probe_neighbor
930 (vm, (ip4_address_t *)&(adr->next_hop_address),
931 ntohl(adr->next_hop_sw_if_index));
934 case RESOLVE_IP6_ADD_DEL_ROUTE:
935 e = ip6_probe_neighbor
936 (vm, (ip6_address_t *)&(adr->next_hop_address),
937 ntohl(adr->next_hop_sw_if_index));
940 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
942 e = ip4_probe_neighbor
944 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
945 pme->resolve_opaque);
949 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
954 clib_error_report (e);
956 adr->resolve_attempts = 1;
958 pme->resolve_attempts = 1;
962 adr->resolve_attempts -= 1;
963 if (adr->resolve_attempts == 0)
964 vec_add1 (resolution_failures,
965 pr - vam->pending_routes);
969 pme->resolve_attempts -= 1;
970 if (pme->resolve_attempts == 0)
971 vec_add1 (resolution_failures,
972 pr - vam->pending_routes);
976 for (i = 0; i < vec_len (resolution_failures); i++)
978 pr = pool_elt_at_index (vam->pending_routes,
979 resolution_failures[i]);
983 switch (pr->resolve_type)
985 case RESOLVE_IP4_ADD_DEL_ROUTE:
986 clib_warning ("resolver: add %U/%d via %U retry failure",
988 (ip4_address_t *) & (adr->dst_address),
989 adr->dst_address_length,
991 (ip4_address_t *) & (adr->next_hop_address));
994 case RESOLVE_IP6_ADD_DEL_ROUTE:
995 clib_warning ("resolver: add %U/%d via %U retry failure",
997 (ip6_address_t *) & (adr->dst_address),
998 adr->dst_address_length,
1000 (ip6_address_t *) & (adr->next_hop_address));
1003 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
1004 clib_warning ("resolver: add mpls-o-e via %U retry failure",
1007 (pme->next_hop_ip4_address_in_outer_vrf));
1011 clib_warning ("BUG");
1013 pool_put (vam->pending_routes, pr);
1015 vec_reset_length (resolution_failures);
1018 if (pool_elts (vam->pending_routes) == 0)
1020 vec_reset_length (event_data);
1022 return 0; /* or not */
1026 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
1027 .function = resolver_process,
1028 .type = VLIB_NODE_TYPE_PROCESS,
1029 .name = "vpe-route-resolver-process",
1034 ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp,
1036 const fib_prefix_t * prefix,
1037 const ip46_address_t * next_hop,
1038 u32 next_hop_sw_if_index,
1039 u32 next_hop_fib_index, u32 next_hop_weight)
1041 vnet_classify_main_t *cm = &vnet_classify_main;
1042 fib_protocol_t proto = prefix->fp_proto;
1043 stats_main_t *sm = &stats_main;
1045 if (mp->is_multipath)
1047 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1049 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1051 if (mp->is_resolve_host)
1052 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1053 if (mp->is_resolve_attached)
1054 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1057 fib_table_entry_path_add (fib_index,
1060 FIB_ENTRY_FLAG_NONE,
1063 next_hop_sw_if_index,
1066 MPLS_LABEL_INVALID, path_flags);
1068 fib_table_entry_path_remove (fib_index,
1073 next_hop_sw_if_index,
1075 next_hop_weight, path_flags);
1081 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1083 if (mp->is_drop || mp->is_local || mp->is_classify || mp->lookup_in_vrf)
1086 * special route types that link directly to the adj
1090 dpo_id_t dpo = DPO_NULL;
1093 dproto = fib_proto_to_dpo (prefix->fp_proto);
1096 dpo_copy (&dpo, drop_dpo_get (dproto));
1097 else if (mp->is_local)
1098 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
1099 else if (mp->is_classify)
1101 if (pool_is_free_index (cm->tables,
1102 ntohl (mp->classify_table_index)))
1105 return VNET_API_ERROR_NO_SUCH_TABLE;
1108 dpo_set (&dpo, DPO_CLASSIFY, proto,
1109 classify_dpo_create (prefix->fp_proto,
1111 (mp->classify_table_index)));
1113 else if (mp->lookup_in_vrf)
1115 next_hop_fib_index =
1116 fib_table_id_find_fib_index (dproto,
1117 ntohl (mp->lookup_in_vrf));
1118 if (~0 == next_hop_fib_index)
1121 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1124 lookup_dpo_add_or_lock_w_fib_index (next_hop_fib_index,
1126 LOOKUP_INPUT_DST_ADDR,
1127 LOOKUP_TABLE_FROM_CONFIG,
1133 return VNET_API_ERROR_NO_SUCH_TABLE;
1136 fib_table_entry_special_dpo_add (fib_index,
1139 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
1144 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
1151 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1153 if (mp->is_resolve_host)
1154 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1155 if (mp->is_resolve_attached)
1156 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1158 fib_table_entry_update_one_path (fib_index,
1161 FIB_ENTRY_FLAG_NONE,
1164 next_hop_sw_if_index,
1167 MPLS_LABEL_INVALID, path_flags);
1171 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
1180 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1182 vpe_api_main_t *vam = &vpe_api_main;
1183 vnet_main_t *vnm = vam->vnet_main;
1186 fib_index = ip4_fib_index_from_table_id (ntohl (mp->vrf_id));
1187 if (~0 == fib_index)
1189 if (mp->create_vrf_if_needed)
1191 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1192 ntohl (mp->vrf_id));
1196 /* No such VRF, and we weren't asked to create one */
1197 return VNET_API_ERROR_NO_SUCH_FIB;
1201 if (~0 != ntohl (mp->next_hop_sw_if_index) &&
1202 pool_is_free_index (vnm->interface_main.sw_interfaces,
1203 ntohl (mp->next_hop_sw_if_index)))
1204 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1206 fib_prefix_t pfx = {
1207 .fp_len = mp->dst_address_length,
1208 .fp_proto = FIB_PROTOCOL_IP4,
1210 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
1213 memset (&nh, 0, sizeof (nh));
1214 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
1216 return (ip_add_del_route_t_handler (mp, fib_index, &pfx, &nh,
1217 ntohl (mp->next_hop_sw_if_index),
1218 fib_index, (u32) mp->next_hop_weight));
1222 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1224 vnet_main_t *vnm = vnet_get_main ();
1227 fib_index = ip6_fib_index_from_table_id (ntohl (mp->vrf_id));
1228 if (~0 == fib_index)
1230 if (mp->create_vrf_if_needed)
1232 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1233 ntohl (mp->vrf_id));
1237 /* No such VRF, and we weren't asked to create one */
1238 return VNET_API_ERROR_NO_SUCH_FIB;
1242 if (~0 != ntohl (mp->next_hop_sw_if_index) &&
1243 pool_is_free_index (vnm->interface_main.sw_interfaces,
1244 ntohl (mp->next_hop_sw_if_index)))
1245 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1247 fib_prefix_t pfx = {
1248 .fp_len = mp->dst_address_length,
1249 .fp_proto = FIB_PROTOCOL_IP6,
1251 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
1254 memset (&nh, 0, sizeof (nh));
1255 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
1257 return (ip_add_del_route_t_handler (mp, fib_index, &pfx,
1258 &nh, ntohl (mp->next_hop_sw_if_index),
1259 fib_index, (u32) mp->next_hop_weight));
1263 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1265 vl_api_ip_add_del_route_reply_t *rmp;
1267 vnet_main_t *vnm = vnet_get_main ();
1272 rv = ip6_add_del_route_t_handler (mp);
1274 rv = ip4_add_del_route_t_handler (mp);
1276 rv = (rv == 0) ? vnm->api_errno : rv;
1278 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1282 vl_api_sw_interface_add_del_address_t_handler
1283 (vl_api_sw_interface_add_del_address_t * mp)
1285 vlib_main_t *vm = vlib_get_main ();
1286 vl_api_sw_interface_add_del_address_reply_t *rmp;
1290 VALIDATE_SW_IF_INDEX (mp);
1292 is_del = mp->is_add == 0;
1295 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1296 else if (mp->is_ipv6)
1297 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1298 (void *) mp->address,
1299 mp->address_length, is_del);
1301 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1302 (void *) mp->address,
1303 mp->address_length, is_del);
1305 BAD_SW_IF_INDEX_LABEL;
1307 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1311 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1314 u32 table_id = ntohl (mp->vrf_id);
1315 u32 sw_if_index = ntohl (mp->sw_if_index);
1316 vl_api_sw_interface_set_table_reply_t *rmp;
1317 stats_main_t *sm = &stats_main;
1320 VALIDATE_SW_IF_INDEX (mp);
1322 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1326 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1329 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
1330 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1335 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1338 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
1339 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1343 BAD_SW_IF_INDEX_LABEL;
1345 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1349 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1351 vlib_main_t *vm = vlib_get_main ();
1352 ip4_main_t *im4 = &ip4_main;
1353 ip6_main_t *im6 = &ip6_main;
1354 vl_api_sw_interface_set_vpath_reply_t *rmp;
1357 u32 sw_if_index = ntohl (mp->sw_if_index);
1358 ip4_main_t *ip4m = &ip4_main;
1359 ip6_main_t *ip6m = &ip6_main;
1360 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1361 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1362 ip_config_main_t *rx_cm4u =
1363 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1364 ip_config_main_t *rx_cm4m =
1365 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1366 ip_config_main_t *rx_cm6u =
1367 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1368 ip_config_main_t *rx_cm6m =
1369 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1371 VALIDATE_SW_IF_INDEX (mp);
1373 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1376 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1377 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1379 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1380 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1381 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1382 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1384 im4->ip4_multicast_rx_feature_vpath,
1386 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1387 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1388 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1390 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1391 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1392 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1393 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1395 im6->ip6_multicast_rx_feature_vpath,
1397 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1401 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1402 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1404 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1405 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1406 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1407 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1409 im4->ip4_multicast_rx_feature_vpath,
1411 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1412 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1413 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1415 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1416 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1417 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1418 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1420 im6->ip6_multicast_rx_feature_vpath,
1422 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1425 BAD_SW_IF_INDEX_LABEL;
1427 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1431 vl_api_sw_interface_set_l2_xconnect_t_handler
1432 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1434 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1436 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1437 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1438 vlib_main_t *vm = vlib_get_main ();
1439 vnet_main_t *vnm = vnet_get_main ();
1441 VALIDATE_RX_SW_IF_INDEX (mp);
1445 VALIDATE_TX_SW_IF_INDEX (mp);
1446 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1447 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1451 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1454 BAD_RX_SW_IF_INDEX_LABEL;
1455 BAD_TX_SW_IF_INDEX_LABEL;
1457 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1461 vl_api_sw_interface_set_l2_bridge_t_handler
1462 (vl_api_sw_interface_set_l2_bridge_t * mp)
1464 bd_main_t *bdm = &bd_main;
1465 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1467 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1468 u32 bd_id = ntohl (mp->bd_id);
1472 vlib_main_t *vm = vlib_get_main ();
1473 vnet_main_t *vnm = vnet_get_main ();
1475 VALIDATE_RX_SW_IF_INDEX (mp);
1477 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1481 //VALIDATE_TX_SW_IF_INDEX(mp);
1482 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1483 rx_sw_if_index, bd_index, bvi, shg, 0);
1487 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1490 BAD_RX_SW_IF_INDEX_LABEL;
1492 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1496 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1497 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1499 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1503 dpdk_main_t *dm = &dpdk_main;
1506 u32 sw_if_index = ntohl (mp->sw_if_index);
1507 u32 subport = ntohl (mp->subport);
1508 u32 pipe = ntohl (mp->pipe);
1509 u32 profile = ntohl (mp->profile);
1510 vnet_hw_interface_t *hw;
1512 VALIDATE_SW_IF_INDEX (mp);
1514 /* hw_if & dpdk device */
1515 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1517 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1519 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1521 BAD_SW_IF_INDEX_LABEL;
1523 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1524 rv = VNET_API_ERROR_UNIMPLEMENTED;
1527 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1531 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1532 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1534 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1538 dpdk_main_t *dm = &dpdk_main;
1540 struct rte_sched_subport_params p;
1542 u32 sw_if_index = ntohl (mp->sw_if_index);
1543 u32 subport = ntohl (mp->subport);
1544 p.tb_rate = ntohl (mp->tb_rate);
1545 p.tb_size = ntohl (mp->tb_size);
1546 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1547 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1548 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1549 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1550 p.tc_period = ntohl (mp->tc_period);
1552 vnet_hw_interface_t *hw;
1554 VALIDATE_SW_IF_INDEX (mp);
1556 /* hw_if & dpdk device */
1557 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1559 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1561 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1563 BAD_SW_IF_INDEX_LABEL;
1566 ("setting HQoS subport parameters without DPDK not implemented");
1567 rv = VNET_API_ERROR_UNIMPLEMENTED;
1570 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1574 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1575 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1577 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1581 dpdk_main_t *dm = &dpdk_main;
1582 vlib_thread_main_t *tm = vlib_get_thread_main ();
1585 u32 sw_if_index = ntohl (mp->sw_if_index);
1586 u32 entry = ntohl (mp->entry);
1587 u32 tc = ntohl (mp->tc);
1588 u32 queue = ntohl (mp->queue);
1591 vnet_hw_interface_t *hw;
1593 VALIDATE_SW_IF_INDEX (mp);
1595 /* hw_if & dpdk device */
1596 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1598 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1600 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1602 clib_warning ("invalid traffic class !!");
1603 rv = VNET_API_ERROR_INVALID_VALUE;
1606 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1608 clib_warning ("invalid queue !!");
1609 rv = VNET_API_ERROR_INVALID_VALUE;
1613 /* Detect the set of worker threads */
1614 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1618 clib_warning ("worker thread registration AWOL !!");
1619 rv = VNET_API_ERROR_INVALID_VALUE_2;
1623 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1624 int worker_thread_first = tr->first_index;
1625 int worker_thread_count = tr->count;
1627 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1628 for (i = 0; i < worker_thread_count; i++)
1629 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1631 BAD_SW_IF_INDEX_LABEL;
1634 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1635 rv = VNET_API_ERROR_UNIMPLEMENTED;
1638 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1642 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1644 vlib_main_t *vm = vlib_get_main ();
1645 bd_main_t *bdm = &bd_main;
1646 vl_api_bridge_domain_add_del_reply_t *rmp;
1648 u32 enable_flags = 0, disable_flags = 0;
1649 u32 bd_id = ntohl (mp->bd_id);
1654 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1657 enable_flags |= L2_FLOOD;
1659 disable_flags |= L2_FLOOD;
1662 enable_flags |= L2_UU_FLOOD;
1664 disable_flags |= L2_UU_FLOOD;
1667 enable_flags |= L2_FWD;
1669 disable_flags |= L2_FWD;
1672 enable_flags |= L2_ARP_TERM;
1674 disable_flags |= L2_ARP_TERM;
1677 enable_flags |= L2_LEARN;
1679 disable_flags |= L2_LEARN;
1682 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1685 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1689 rv = bd_delete_bd_index (bdm, bd_id);
1691 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1695 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1697 clib_warning ("BUG");
1701 vl_api_bridge_domain_sw_if_details_t_handler
1702 (vl_api_bridge_domain_sw_if_details_t * mp)
1704 clib_warning ("BUG");
1708 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1709 l2_bridge_domain_t * bd_config,
1710 u32 n_sw_ifs, u32 context)
1712 vl_api_bridge_domain_details_t *mp;
1714 mp = vl_msg_api_alloc (sizeof (*mp));
1715 memset (mp, 0, sizeof (*mp));
1716 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1717 mp->bd_id = ntohl (bd_config->bd_id);
1718 mp->flood = bd_feature_flood (bd_config);
1719 mp->uu_flood = bd_feature_uu_flood (bd_config);
1720 mp->forward = bd_feature_forward (bd_config);
1721 mp->learn = bd_feature_learn (bd_config);
1722 mp->arp_term = bd_feature_arp_term (bd_config);
1723 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1724 mp->n_sw_ifs = ntohl (n_sw_ifs);
1725 mp->context = context;
1727 vl_msg_api_send_shmem (q, (u8 *) & mp);
1731 send_bd_sw_if_details (l2input_main_t * l2im,
1732 unix_shared_memory_queue_t * q,
1733 l2_flood_member_t * member, u32 bd_id, u32 context)
1735 vl_api_bridge_domain_sw_if_details_t *mp;
1736 l2_input_config_t *input_cfg;
1738 mp = vl_msg_api_alloc (sizeof (*mp));
1739 memset (mp, 0, sizeof (*mp));
1740 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1741 mp->bd_id = ntohl (bd_id);
1742 mp->sw_if_index = ntohl (member->sw_if_index);
1743 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1744 mp->shg = input_cfg->shg;
1745 mp->context = context;
1747 vl_msg_api_send_shmem (q, (u8 *) & mp);
1751 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1753 bd_main_t *bdm = &bd_main;
1754 l2input_main_t *l2im = &l2input_main;
1755 unix_shared_memory_queue_t *q;
1756 l2_bridge_domain_t *bd_config;
1757 u32 bd_id, bd_index;
1760 q = vl_api_client_index_to_input_queue (mp->client_index);
1765 bd_id = ntohl (mp->bd_id);
1767 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1768 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1769 for (; bd_index < end; bd_index++)
1771 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1772 /* skip dummy bd_id 0 */
1773 if (bd_config && (bd_config->bd_id > 0))
1776 l2_flood_member_t *m;
1778 n_sw_ifs = vec_len (bd_config->members);
1779 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1781 vec_foreach (m, bd_config->members)
1783 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1790 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1792 bd_main_t *bdm = &bd_main;
1793 l2input_main_t *l2im = &l2input_main;
1794 vl_api_l2fib_add_del_reply_t *rmp;
1797 u32 sw_if_index = ntohl (mp->sw_if_index);
1798 u32 bd_id = ntohl (mp->bd_id);
1807 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1810 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1811 goto bad_sw_if_index;
1817 VALIDATE_SW_IF_INDEX (mp);
1818 if (vec_len (l2im->configs) <= sw_if_index)
1820 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1821 goto bad_sw_if_index;
1825 l2_input_config_t *config;
1826 config = vec_elt_at_index (l2im->configs, sw_if_index);
1827 if (config->bridge == 0)
1829 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1830 goto bad_sw_if_index;
1833 static_mac = mp->static_mac ? 1 : 0;
1834 filter_mac = mp->filter_mac ? 1 : 0;
1835 bvi_mac = mp->bvi_mac ? 1 : 0;
1836 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1841 l2fib_del_entry (mac, bd_index);
1844 BAD_SW_IF_INDEX_LABEL;
1846 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1850 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1852 vl_api_l2_flags_reply_t *rmp;
1854 u32 sw_if_index = ntohl (mp->sw_if_index);
1855 u32 flags = ntohl (mp->feature_bitmap);
1858 VALIDATE_SW_IF_INDEX (mp);
1861 if (flags & L2INPUT_FEAT_ ## a) \
1862 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1863 foreach_l2input_feat;
1866 BAD_SW_IF_INDEX_LABEL;
1869 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1871 rmp->resulting_feature_bitmap = ntohl(rbm);
1877 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1879 vlib_main_t *vm = vlib_get_main ();
1880 bd_main_t *bdm = &bd_main;
1881 vl_api_bridge_flags_reply_t *rmp;
1883 u32 bd_id = ntohl (mp->bd_id);
1885 u32 flags = ntohl (mp->feature_bitmap);
1888 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1891 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1897 bd_set_flags (vm, bd_index, flags, mp->is_set);
1901 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1903 rmp->resulting_feature_bitmap = ntohl(flags);
1909 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1911 bd_main_t *bdm = &bd_main;
1912 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1914 u32 bd_id = ntohl (mp->bd_id);
1918 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1921 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1926 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1927 mp->mac_address, mp->is_ipv6, mp->is_add))
1928 rv = VNET_API_ERROR_UNSPECIFIED;
1931 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1935 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1938 vl_api_tap_connect_reply_t *rmp;
1939 unix_shared_memory_queue_t *q;
1940 u32 sw_if_index = (u32) ~ 0;
1942 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1943 mp->use_random_mac ? 0 : mp->mac_address,
1944 &sw_if_index, mp->renumber,
1945 ntohl (mp->custom_dev_instance));
1947 q = vl_api_client_index_to_input_queue (mp->client_index);
1951 rmp = vl_msg_api_alloc (sizeof (*rmp));
1952 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1953 rmp->context = mp->context;
1954 rmp->retval = ntohl (rv);
1955 rmp->sw_if_index = ntohl (sw_if_index);
1957 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1961 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
1964 vl_api_tap_modify_reply_t *rmp;
1965 unix_shared_memory_queue_t *q;
1966 u32 sw_if_index = (u32) ~ 0;
1968 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1969 mp->use_random_mac ? 0 : mp->mac_address,
1970 &sw_if_index, mp->renumber,
1971 ntohl (mp->custom_dev_instance));
1973 q = vl_api_client_index_to_input_queue (mp->client_index);
1977 rmp = vl_msg_api_alloc (sizeof (*rmp));
1978 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1979 rmp->context = mp->context;
1980 rmp->retval = ntohl (rv);
1981 rmp->sw_if_index = ntohl (sw_if_index);
1983 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1987 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
1990 vpe_api_main_t *vam = &vpe_api_main;
1991 vl_api_tap_delete_reply_t *rmp;
1992 unix_shared_memory_queue_t *q;
1993 u32 sw_if_index = ntohl (mp->sw_if_index);
1995 rv = vnet_tap_delete (vm, sw_if_index);
1997 q = vl_api_client_index_to_input_queue (mp->client_index);
2001 rmp = vl_msg_api_alloc (sizeof (*rmp));
2002 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
2003 rmp->context = mp->context;
2004 rmp->retval = ntohl (rv);
2006 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2009 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2013 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
2015 vl_api_create_vlan_subif_reply_t *rmp;
2016 vnet_main_t *vnm = vnet_get_main ();
2017 u32 hw_if_index, sw_if_index = (u32) ~ 0;
2018 vnet_hw_interface_t *hi;
2021 vnet_sw_interface_t template;
2023 vnet_interface_main_t *im = &vnm->interface_main;
2024 u64 sup_and_sub_key;
2026 unix_shared_memory_queue_t *q;
2027 clib_error_t *error;
2029 VALIDATE_SW_IF_INDEX (mp);
2031 hw_if_index = ntohl (mp->sw_if_index);
2032 hi = vnet_get_hw_interface (vnm, hw_if_index);
2034 id = ntohl (mp->vlan_id);
2035 if (id == 0 || id > 4095)
2037 rv = VNET_API_ERROR_INVALID_VLAN;
2041 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2043 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2046 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2050 kp = clib_mem_alloc (sizeof (*kp));
2051 *kp = sup_and_sub_key;
2053 memset (&template, 0, sizeof (template));
2054 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2055 template.sup_sw_if_index = hi->sw_if_index;
2056 template.sub.id = id;
2057 template.sub.eth.raw_flags = 0;
2058 template.sub.eth.flags.one_tag = 1;
2059 template.sub.eth.outer_vlan_id = id;
2060 template.sub.eth.flags.exact_match = 1;
2062 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2065 clib_error_report (error);
2066 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2069 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2070 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2072 BAD_SW_IF_INDEX_LABEL;
2075 q = vl_api_client_index_to_input_queue (mp->client_index);
2079 rmp = vl_msg_api_alloc (sizeof (*rmp));
2080 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2081 rmp->context = mp->context;
2082 rmp->retval = ntohl (rv);
2083 rmp->sw_if_index = ntohl (sw_if_index);
2084 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2088 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2090 vl_api_create_subif_reply_t *rmp;
2091 vnet_main_t *vnm = vnet_get_main ();
2092 u32 sw_if_index = ~0;
2095 vnet_sw_interface_t *si;
2096 vnet_hw_interface_t *hi;
2097 vnet_sw_interface_t template;
2099 vnet_interface_main_t *im = &vnm->interface_main;
2100 u64 sup_and_sub_key;
2102 clib_error_t *error;
2104 VALIDATE_SW_IF_INDEX (mp);
2106 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2107 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2109 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2111 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2115 sw_if_index = si->sw_if_index;
2116 sub_id = ntohl (mp->sub_id);
2118 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2120 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2124 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2125 sw_if_index, sub_id);
2126 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2130 kp = clib_mem_alloc (sizeof (*kp));
2131 *kp = sup_and_sub_key;
2133 memset (&template, 0, sizeof (template));
2134 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2135 template.sup_sw_if_index = sw_if_index;
2136 template.sub.id = sub_id;
2137 template.sub.eth.flags.no_tags = mp->no_tags;
2138 template.sub.eth.flags.one_tag = mp->one_tag;
2139 template.sub.eth.flags.two_tags = mp->two_tags;
2140 template.sub.eth.flags.dot1ad = mp->dot1ad;
2141 template.sub.eth.flags.exact_match = mp->exact_match;
2142 template.sub.eth.flags.default_sub = mp->default_sub;
2143 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2144 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2145 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2146 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2148 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2151 clib_error_report (error);
2152 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2156 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2157 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2159 BAD_SW_IF_INDEX_LABEL;
2164 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2166 rmp->sw_if_index = ntohl(sw_if_index);
2172 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2175 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2177 stats_main_t *sm = &stats_main;
2178 u32 tunnel_sw_if_index = ~0;
2180 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2182 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2183 (ip4_address_t *) (mp->dst_address),
2184 (ip4_address_t *) (mp->intfc_address),
2185 (u32) (mp->intfc_address_length),
2186 ntohl (mp->inner_vrf_id),
2187 ntohl (mp->outer_vrf_id),
2188 &tunnel_sw_if_index,
2189 mp->l2_only, mp->is_add);
2193 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2195 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2201 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2202 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2204 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2206 stats_main_t *sm = &stats_main;
2207 u32 tunnel_sw_if_index;
2209 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2211 rv = vnet_mpls_ethernet_add_del_tunnel
2212 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2213 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2214 ntohl (mp->tx_sw_if_index),
2215 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2220 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2222 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2228 * This piece of misery brought to you because the control-plane
2229 * can't figure out the tx interface + dst-mac address all by itself
2231 static int mpls_ethernet_add_del_tunnel_2_t_handler
2232 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2234 pending_route_t *pr;
2235 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2236 vnet_main_t *vnm = vnet_get_main ();
2237 vlib_main_t *vm = vlib_get_main ();
2238 stats_main_t *sm = &stats_main;
2239 vpe_api_main_t *vam = &vpe_api_main;
2240 u32 inner_fib_index, outer_fib_index;
2241 ip4_main_t *im = &ip4_main;
2242 ip_lookup_main_t *lm = &im->lookup_main;
2243 ip_adjacency_t *adj = 0;
2246 u8 *dst_mac_address;
2250 u32 tunnel_sw_if_index;
2252 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2254 return VNET_API_ERROR_NO_SUCH_FIB;
2256 outer_fib_index = p[0];
2259 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2261 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2263 inner_fib_index = p[0];
2265 if (inner_fib_index == outer_fib_index)
2266 return VNET_API_ERROR_INVALID_VALUE;
2269 lookup_result = ip4_fib_table_lookup_lb (ip4_fib_get (outer_fib_index),
2271 mp->next_hop_ip4_address_in_outer_vrf);
2273 adj = ip_get_adjacency (lm, lookup_result);
2274 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2276 if (mp->is_add && mp->resolve_if_needed)
2278 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2280 pool_get (vam->pending_routes, pr);
2281 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2283 clib_memcpy (pme, mp, sizeof (*pme));
2284 /* recursion block, "just in case" */
2285 pme->resolve_if_needed = 0;
2286 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2287 pme->resolve_opaque = tx_sw_if_index;
2288 vnet_register_ip4_arp_resolution_event
2290 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2291 vpe_resolver_process_node.index,
2292 RESOLUTION_EVENT, pr - vam->pending_routes);
2294 vlib_process_signal_event
2295 (vm, vpe_resolver_process_node.index,
2296 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2298 /* The interface may be down, etc. */
2299 e = ip4_probe_neighbor
2300 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2304 clib_error_report (e);
2306 return VNET_API_ERROR_IN_PROGRESS;
2310 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2311 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2314 vnet_rewrite_get_data_internal
2315 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2317 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2319 rv = vnet_mpls_ethernet_add_del_tunnel
2320 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2321 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2322 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2330 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2331 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2333 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2336 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2338 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2343 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2345 vl_api_mpls_add_del_encap_reply_t *rmp;
2350 vec_reset_length (labels);
2352 for (i = 0; i < mp->nlabels; i++)
2353 vec_add1 (labels, ntohl (mp->labels[i]));
2356 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2357 ntohl (mp->vrf_id), labels,
2358 ~0 /* policy_tunnel_index */ ,
2359 0 /* no_dst_hash */ ,
2363 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2367 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2369 vl_api_mpls_add_del_decap_reply_t *rmp;
2372 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2373 ntohl (mp->label), ntohl (mp->next_index),
2374 mp->s_bit, mp->is_add);
2376 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2380 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2382 vl_api_proxy_arp_add_del_reply_t *rmp;
2385 ip4_main_t *im = &ip4_main;
2386 stats_main_t *sm = &stats_main;
2387 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2388 ip4_address_t * hi_addr,
2389 u32 fib_index, int is_del);
2392 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2394 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2398 rv = VNET_API_ERROR_NO_SUCH_FIB;
2404 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2405 (ip4_address_t *) mp->hi_address,
2406 fib_index, mp->is_add == 0);
2410 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2414 vl_api_proxy_arp_intfc_enable_disable_t_handler
2415 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2418 vnet_main_t *vnm = vnet_get_main ();
2419 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2420 vnet_sw_interface_t *si;
2423 VALIDATE_SW_IF_INDEX (mp);
2425 sw_if_index = ntohl (mp->sw_if_index);
2427 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2429 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2433 si = vnet_get_sw_interface (vnm, sw_if_index);
2437 if (mp->enable_disable)
2438 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2440 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2442 BAD_SW_IF_INDEX_LABEL;
2445 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2449 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2452 vl_api_ip_neighbor_add_del_reply_t *rmp;
2453 vnet_main_t *vnm = vnet_get_main ();
2454 stats_main_t *sm = &stats_main;
2457 VALIDATE_SW_IF_INDEX (mp);
2459 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2462 * there's no validation here of the ND/ARP entry being added.
2463 * The expectation is that the FIB will ensure that nothing bad
2464 * will come of adding bogus entries.
2469 rv = vnet_set_ip6_ethernet_neighbor
2470 (vm, ntohl (mp->sw_if_index),
2471 (ip6_address_t *) (mp->dst_address),
2472 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2474 rv = vnet_unset_ip6_ethernet_neighbor
2475 (vm, ntohl (mp->sw_if_index),
2476 (ip6_address_t *) (mp->dst_address),
2477 mp->mac_address, sizeof (mp->mac_address));
2481 ethernet_arp_ip4_over_ethernet_address_t a;
2483 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2484 clib_memcpy (&a.ip4, mp->dst_address, 4);
2487 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2491 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2494 BAD_SW_IF_INDEX_LABEL;
2497 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2501 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2504 vpe_main_t *rm = &vpe_main;
2505 ip4_main_t *im4 = &ip4_main;
2506 ip6_main_t *im6 = &ip6_main;
2507 ip_lookup_main_t *lm;
2513 u32 adj_index, sw_if_index;
2514 vl_api_is_address_reachable_t *rmp;
2515 ip_adjacency_t *adj;
2516 unix_shared_memory_queue_t *q;
2518 q = vl_api_client_index_to_input_queue (mp->client_index);
2521 increment_missing_api_client_counter (rm->vlib_main);
2525 rmp = vl_msg_api_alloc (sizeof (*rmp));
2526 clib_memcpy (rmp, mp, sizeof (*rmp));
2528 sw_if_index = mp->next_hop_sw_if_index;
2529 clib_memcpy (&addr, mp->address, sizeof (addr));
2532 lm = &im6->lookup_main;
2533 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2537 lm = &im4->lookup_main;
2539 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2541 if (adj_index == ~0)
2546 adj = ip_get_adjacency (lm, adj_index);
2548 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2549 && adj->rewrite_header.sw_if_index == sw_if_index)
2555 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2556 && adj->rewrite_header.sw_if_index == sw_if_index)
2559 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2561 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2563 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2572 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2577 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2579 clib_warning ("BUG");
2583 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2585 vl_api_sw_interface_set_flags_reply_t *rmp;
2586 vnet_main_t *vnm = vnet_get_main ();
2588 clib_error_t *error;
2591 VALIDATE_SW_IF_INDEX (mp);
2593 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2595 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2599 clib_error_report (error);
2602 BAD_SW_IF_INDEX_LABEL;
2603 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2607 vl_api_sw_interface_set_mpls_enable_t_handler
2608 (vl_api_sw_interface_set_mpls_enable_t * mp)
2610 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2613 VALIDATE_SW_IF_INDEX (mp);
2615 mpls_sw_interface_enable_disable (&mpls_main,
2616 ntohl (mp->sw_if_index), mp->enable);
2618 BAD_SW_IF_INDEX_LABEL;
2619 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2623 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2626 vl_api_sw_interface_clear_stats_reply_t *rmp;
2628 vnet_main_t *vnm = vnet_get_main ();
2629 vnet_interface_main_t *im = &vnm->interface_main;
2630 vlib_simple_counter_main_t *sm;
2631 vlib_combined_counter_main_t *cm;
2632 static vnet_main_t **my_vnet_mains;
2633 int i, j, n_counters;
2636 if (mp->sw_if_index != ~0)
2637 VALIDATE_SW_IF_INDEX (mp);
2639 vec_reset_length (my_vnet_mains);
2641 for (i = 0; i < vec_len (vnet_mains); i++)
2644 vec_add1 (my_vnet_mains, vnet_mains[i]);
2647 if (vec_len (vnet_mains) == 0)
2648 vec_add1 (my_vnet_mains, vnm);
2650 n_counters = vec_len (im->combined_sw_if_counters);
2652 for (j = 0; j < n_counters; j++)
2654 for (i = 0; i < vec_len (my_vnet_mains); i++)
2656 im = &my_vnet_mains[i]->interface_main;
2657 cm = im->combined_sw_if_counters + j;
2658 if (mp->sw_if_index == (u32) ~ 0)
2659 vlib_clear_combined_counters (cm);
2661 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2665 n_counters = vec_len (im->sw_if_counters);
2667 for (j = 0; j < n_counters; j++)
2669 for (i = 0; i < vec_len (my_vnet_mains); i++)
2671 im = &my_vnet_mains[i]->interface_main;
2672 sm = im->sw_if_counters + j;
2673 if (mp->sw_if_index == (u32) ~ 0)
2674 vlib_clear_simple_counters (sm);
2676 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2680 BAD_SW_IF_INDEX_LABEL;
2682 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2686 send_sw_interface_details (vpe_api_main_t * am,
2687 unix_shared_memory_queue_t * q,
2688 vnet_sw_interface_t * swif,
2689 u8 * interface_name, u32 context)
2691 vl_api_sw_interface_details_t *mp;
2692 vnet_hw_interface_t *hi;
2694 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2696 mp = vl_msg_api_alloc (sizeof (*mp));
2697 memset (mp, 0, sizeof (*mp));
2698 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2699 mp->sw_if_index = ntohl (swif->sw_if_index);
2700 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2701 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2702 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2703 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2704 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2705 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2706 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2707 mp->link_mtu = ntohs (hi->max_packet_bytes);
2708 mp->context = context;
2710 strncpy ((char *) mp->interface_name,
2711 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2713 /* Send the L2 address for ethernet physical intfcs */
2714 if (swif->sup_sw_if_index == swif->sw_if_index
2715 && hi->hw_class_index == ethernet_hw_interface_class.index)
2717 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2718 ethernet_interface_t *ei;
2720 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2721 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2722 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2723 mp->l2_address_length = ntohl (sizeof (ei->address));
2725 else if (swif->sup_sw_if_index != swif->sw_if_index)
2727 vnet_sub_interface_t *sub = &swif->sub;
2728 mp->sub_id = ntohl (sub->id);
2729 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2730 mp->sub_number_of_tags =
2731 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2732 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2733 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2734 mp->sub_exact_match = sub->eth.flags.exact_match;
2735 mp->sub_default = sub->eth.flags.default_sub;
2736 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2737 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2739 /* vlan tag rewrite data */
2740 u32 vtr_op = L2_VTR_DISABLED;
2741 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2743 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2744 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2746 // error - default to disabled
2747 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2748 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2753 mp->vtr_op = ntohl (vtr_op);
2754 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2755 mp->vtr_tag1 = ntohl (vtr_tag1);
2756 mp->vtr_tag2 = ntohl (vtr_tag2);
2760 vl_msg_api_send_shmem (q, (u8 *) & mp);
2764 send_sw_interface_flags (vpe_api_main_t * am,
2765 unix_shared_memory_queue_t * q,
2766 vnet_sw_interface_t * swif)
2768 vl_api_sw_interface_set_flags_t *mp;
2769 vnet_main_t *vnm = am->vnet_main;
2771 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2773 mp = vl_msg_api_alloc (sizeof (*mp));
2774 memset (mp, 0, sizeof (*mp));
2775 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2776 mp->sw_if_index = ntohl (swif->sw_if_index);
2778 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2779 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2780 vl_msg_api_send_shmem (q, (u8 *) & mp);
2783 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2784 unix_shared_memory_queue_t * q,
2786 __attribute__ ((unused));
2789 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2790 unix_shared_memory_queue_t * q,
2793 vl_api_sw_interface_set_flags_t *mp;
2795 mp = vl_msg_api_alloc (sizeof (*mp));
2796 memset (mp, 0, sizeof (*mp));
2797 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2798 mp->sw_if_index = ntohl (sw_if_index);
2800 mp->admin_up_down = 0;
2801 mp->link_up_down = 0;
2803 vl_msg_api_send_shmem (q, (u8 *) & mp);
2807 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2809 vpe_api_main_t *am = &vpe_api_main;
2810 vnet_sw_interface_t *swif;
2811 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2812 u8 *filter_string = 0, *name_string = 0;
2813 unix_shared_memory_queue_t *q;
2814 char *strcasestr (char *, char *); /* lnx hdr file botch */
2816 q = vl_api_client_index_to_input_queue (mp->client_index);
2821 if (mp->name_filter_valid)
2823 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2824 filter_string = format (0, "%s%c", mp->name_filter, 0);
2828 pool_foreach (swif, im->sw_interfaces,
2830 name_string = format (name_string, "%U%c",
2831 format_vnet_sw_interface_name,
2832 am->vnet_main, swif, 0);
2834 if (mp->name_filter_valid == 0 ||
2835 strcasestr((char *) name_string, (char *) filter_string)) {
2837 send_sw_interface_details (am, q, swif, name_string, mp->context);
2839 _vec_len (name_string) = 0;
2843 vec_free (name_string);
2844 vec_free (filter_string);
2848 send_oam_event (oam_target_t * t)
2850 vpe_api_main_t *vam = &vpe_api_main;
2851 unix_shared_memory_queue_t *q;
2852 vpe_client_registration_t *reg;
2853 vl_api_oam_event_t *mp;
2856 pool_foreach(reg, vam->oam_events_registrations,
2858 q = vl_api_client_index_to_input_queue (reg->client_index);
2861 mp = vl_msg_api_alloc (sizeof (*mp));
2862 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2863 clib_memcpy (mp->dst_address, &t->dst_address,
2864 sizeof (mp->dst_address));
2865 mp->state = t->state;
2866 vl_msg_api_send_shmem (q, (u8 *)&mp);
2873 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2875 vl_api_oam_add_del_reply_t *rmp;
2878 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2879 (ip4_address_t *) mp->dst_address,
2880 ntohl (mp->vrf_id), (int) (mp->is_add));
2882 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2886 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2888 stats_main_t *sm = &stats_main;
2889 vnet_interface_main_t *im = sm->interface_main;
2890 vl_api_vnet_summary_stats_reply_t *rmp;
2891 vlib_combined_counter_main_t *cm;
2894 u64 total_pkts[VLIB_N_RX_TX];
2895 u64 total_bytes[VLIB_N_RX_TX];
2897 unix_shared_memory_queue_t *q =
2898 vl_api_client_index_to_input_queue (mp->client_index);
2903 rmp = vl_msg_api_alloc (sizeof (*rmp));
2904 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2905 rmp->context = mp->context;
2908 memset (total_pkts, 0, sizeof (total_pkts));
2909 memset (total_bytes, 0, sizeof (total_bytes));
2911 vnet_interface_counter_lock (im);
2913 vec_foreach (cm, im->combined_sw_if_counters)
2915 which = cm - im->combined_sw_if_counters;
2917 for (i = 0; i < vec_len (cm->maxi); i++)
2919 vlib_get_combined_counter (cm, i, &v);
2920 total_pkts[which] += v.packets;
2921 total_bytes[which] += v.bytes;
2924 vnet_interface_counter_unlock (im);
2926 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2927 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2928 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2929 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2931 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2933 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2937 typedef CLIB_PACKED (struct {
2938 ip4_address_t address;
2939 u32 address_length: 6;
2945 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2947 vnet_main_t *vnm = vnet_get_main ();
2948 vnet_interface_main_t *im = &vnm->interface_main;
2949 ip4_main_t *im4 = &ip4_main;
2950 static u32 *sw_if_indices_to_shut;
2951 stats_main_t *sm = &stats_main;
2952 fib_table_t *fib_table;
2956 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2957 u32 target_fib_id = ntohl (mp->vrf_id);
2959 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2962 pool_foreach (fib_table, im4->fibs,
2964 fib = &fib_table->v4;
2965 vnet_sw_interface_t * si;
2967 if (fib->table_id != target_fib_id)
2970 /* remove any mpls/gre tunnels in this fib */
2971 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2973 /* remove any mpls encap/decap labels */
2974 mpls_fib_reset_labels (fib->table_id);
2976 /* remove any proxy arps in this fib */
2977 vnet_proxy_arp_fib_reset (fib->table_id);
2979 /* Set the flow hash for this fib to the default */
2980 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2982 vec_reset_length (sw_if_indices_to_shut);
2984 /* Shut down interfaces in this FIB / clean out intfc routes */
2985 pool_foreach (si, im->sw_interfaces,
2987 u32 sw_if_index = si->sw_if_index;
2989 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2990 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2992 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2995 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2996 sw_if_index = sw_if_indices_to_shut[i];
2997 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2999 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3000 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3001 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3004 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
3005 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
3009 })); /* pool_foreach (fib) */
3017 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3019 vnet_main_t *vnm = vnet_get_main ();
3020 vnet_interface_main_t *im = &vnm->interface_main;
3021 ip6_main_t *im6 = &ip6_main;
3022 stats_main_t *sm = &stats_main;
3023 static u32 *sw_if_indices_to_shut;
3024 fib_table_t *fib_table;
3028 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3029 u32 target_fib_id = ntohl (mp->vrf_id);
3031 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3034 pool_foreach (fib_table, im6->fibs,
3036 vnet_sw_interface_t * si;
3037 fib = &(fib_table->v6);
3039 if (fib->table_id != target_fib_id)
3042 vec_reset_length (sw_if_indices_to_shut);
3044 /* Shut down interfaces in this FIB / clean out intfc routes */
3045 pool_foreach (si, im->sw_interfaces,
3047 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3049 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3052 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3053 sw_if_index = sw_if_indices_to_shut[i];
3054 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3056 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3057 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3058 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3061 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
3062 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
3066 })); /* pool_foreach (fib) */
3074 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3077 vl_api_reset_fib_reply_t *rmp;
3080 rv = ip6_reset_fib_t_handler (mp);
3082 rv = ip4_reset_fib_t_handler (mp);
3084 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3089 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3091 vl_api_dhcp_proxy_config_reply_t *rmp;
3094 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3095 (ip4_address_t *) (&mp->dhcp_src_address),
3096 (u32) ntohl (mp->vrf_id),
3097 (int) mp->insert_circuit_id,
3098 (int) (mp->is_add == 0));
3100 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3105 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3107 vl_api_dhcp_proxy_config_reply_t *rmp;
3110 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3111 (ip6_address_t *) (&mp->dhcp_src_address),
3112 (u32) ntohl (mp->vrf_id),
3113 (int) mp->insert_circuit_id,
3114 (int) (mp->is_add == 0));
3116 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3120 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3122 vl_api_dhcp_proxy_config_reply_t *rmp;
3125 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3126 (ip4_address_t *) (&mp->dhcp_src_address),
3127 (u32) ntohl (mp->rx_vrf_id),
3128 (u32) ntohl (mp->server_vrf_id),
3129 (int) mp->insert_circuit_id,
3130 (int) (mp->is_add == 0));
3132 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3137 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3139 vl_api_dhcp_proxy_config_reply_t *rmp;
3143 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3144 (ip6_address_t *) (&mp->dhcp_src_address),
3145 (u32) ntohl (mp->rx_vrf_id),
3146 (u32) ntohl (mp->server_vrf_id),
3147 (int) mp->insert_circuit_id,
3148 (int) (mp->is_add == 0));
3150 rv = VNET_API_ERROR_UNIMPLEMENTED;
3153 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3158 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3160 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3163 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3166 (int) mp->is_add == 0);
3168 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3170 ntohl (mp->fib_id), (int) mp->is_add == 0);
3172 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3176 static void vl_api_dhcp_proxy_config_t_handler
3177 (vl_api_dhcp_proxy_config_t * mp)
3179 if (mp->is_ipv6 == 0)
3180 dhcpv4_proxy_config (mp);
3182 dhcpv6_proxy_config (mp);
3185 static void vl_api_dhcp_proxy_config_2_t_handler
3186 (vl_api_dhcp_proxy_config_2_t * mp)
3188 if (mp->is_ipv6 == 0)
3189 dhcpv4_proxy_config_2 (mp);
3191 dhcpv6_proxy_config_2 (mp);
3195 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3196 u8 is_ipv6, u8 * host_address, u8 * router_address,
3199 unix_shared_memory_queue_t *q;
3200 vl_api_dhcp_compl_event_t *mp;
3202 q = vl_api_client_index_to_input_queue (client_index);
3206 mp = vl_msg_api_alloc (sizeof (*mp));
3207 mp->client_index = client_index;
3209 mp->is_ipv6 = is_ipv6;
3210 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3211 mp->hostname[vec_len (hostname) + 1] = '\n';
3212 clib_memcpy (&mp->host_address[0], host_address, 16);
3213 clib_memcpy (&mp->router_address[0], router_address, 16);
3215 if (NULL != host_mac)
3216 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3218 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3220 vl_msg_api_send_shmem (q, (u8 *) & mp);
3223 static void vl_api_dhcp_client_config_t_handler
3224 (vl_api_dhcp_client_config_t * mp)
3226 vlib_main_t *vm = vlib_get_main ();
3227 vl_api_dhcp_client_config_reply_t *rmp;
3230 VALIDATE_SW_IF_INDEX (mp);
3232 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3233 mp->hostname, mp->is_add, mp->client_index,
3234 mp->want_dhcp_event ? dhcp_compl_event_callback :
3237 BAD_SW_IF_INDEX_LABEL;
3239 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3243 vl_api_sw_interface_ip6nd_ra_config_t_handler
3244 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3246 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3248 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3251 is_no = mp->is_no == 1;
3252 suppress = mp->suppress == 1;
3253 managed = mp->managed == 1;
3254 other = mp->other == 1;
3255 ll_option = mp->ll_option == 1;
3256 send_unicast = mp->send_unicast == 1;
3257 cease = mp->cease == 1;
3258 default_router = mp->default_router == 1;
3260 VALIDATE_SW_IF_INDEX (mp);
3262 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3263 suppress, managed, other,
3264 ll_option, send_unicast, cease,
3265 default_router, ntohl (mp->lifetime),
3266 ntohl (mp->initial_count),
3267 ntohl (mp->initial_interval),
3268 ntohl (mp->max_interval),
3269 ntohl (mp->min_interval), is_no);
3271 BAD_SW_IF_INDEX_LABEL;
3273 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3277 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3278 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3280 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3282 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3284 VALIDATE_SW_IF_INDEX (mp);
3286 is_no = mp->is_no == 1;
3287 use_default = mp->use_default == 1;
3288 no_advertise = mp->no_advertise == 1;
3289 off_link = mp->off_link == 1;
3290 no_autoconfig = mp->no_autoconfig == 1;
3291 no_onlink = mp->no_onlink == 1;
3293 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3294 (ip6_address_t *) mp->address,
3295 mp->address_length, use_default,
3296 ntohl (mp->val_lifetime),
3297 ntohl (mp->pref_lifetime), no_advertise,
3298 off_link, no_autoconfig, no_onlink, is_no);
3300 BAD_SW_IF_INDEX_LABEL;
3301 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3305 vl_api_sw_interface_ip6_enable_disable_t_handler
3306 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3308 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3309 vnet_main_t *vnm = vnet_get_main ();
3311 clib_error_t *error;
3315 VALIDATE_SW_IF_INDEX (mp);
3318 (mp->enable == 1) ? enable_ip6_interface (vm,
3319 ntohl (mp->sw_if_index)) :
3320 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3324 clib_error_report (error);
3325 rv = VNET_API_ERROR_UNSPECIFIED;
3329 rv = vnm->api_errno;
3332 BAD_SW_IF_INDEX_LABEL;
3334 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3338 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3339 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3341 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3343 clib_error_t *error;
3344 vnet_main_t *vnm = vnet_get_main ();
3348 VALIDATE_SW_IF_INDEX (mp);
3350 error = set_ip6_link_local_address (vm,
3351 ntohl (mp->sw_if_index),
3352 (ip6_address_t *) mp->address,
3353 mp->address_length);
3356 clib_error_report (error);
3357 rv = VNET_API_ERROR_UNSPECIFIED;
3361 rv = vnm->api_errno;
3364 BAD_SW_IF_INDEX_LABEL;
3366 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3370 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3372 vl_api_set_ip_flow_hash_reply_t *rmp;
3373 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3375 clib_warning ("unimplemented...");
3377 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3381 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3383 vl_api_set_ip_flow_hash_reply_t *rmp;
3386 flow_hash_config_t flow_hash_config = 0;
3388 table_id = ntohl (mp->vrf_id);
3390 #define _(a,b) if (mp->a) flow_hash_config |= b;
3391 foreach_flow_hash_bit;
3394 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3396 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3401 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3403 if (mp->is_ipv6 == 0)
3404 set_ip4_flow_hash (mp);
3406 set_ip6_flow_hash (mp);
3409 static void vl_api_sw_interface_set_unnumbered_t_handler
3410 (vl_api_sw_interface_set_unnumbered_t * mp)
3412 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3414 vnet_sw_interface_t *si;
3415 vnet_main_t *vnm = vnet_get_main ();
3416 u32 sw_if_index, unnumbered_sw_if_index;
3418 sw_if_index = ntohl (mp->sw_if_index);
3419 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3422 * The API message field names are backwards from
3423 * the underlying data structure names.
3424 * It's not worth changing them now.
3426 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3427 unnumbered_sw_if_index))
3429 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3433 /* Only check the "use loop0" field when setting the binding */
3435 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3437 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3441 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3445 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3446 si->unnumbered_sw_if_index = sw_if_index;
3447 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3448 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3452 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3453 si->unnumbered_sw_if_index = (u32) ~ 0;
3454 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3455 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3459 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3463 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3465 vl_api_create_loopback_reply_t *rmp;
3469 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3472 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3474 rmp->sw_if_index = ntohl (sw_if_index);
3480 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3482 vl_api_delete_loopback_reply_t *rmp;
3486 sw_if_index = ntohl (mp->sw_if_index);
3487 rv = vnet_delete_loopback_interface (sw_if_index);
3489 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3493 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3495 vl_api_control_ping_reply_t *rmp;
3499 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3501 rmp->vpe_pid = ntohl (getpid());
3507 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3509 u8 **shmem_vecp = (u8 **) arg;
3512 api_main_t *am = &api_main;
3515 shmem_vec = *shmem_vecp;
3517 offset = vec_len (shmem_vec);
3519 pthread_mutex_lock (&am->vlib_rp->mutex);
3520 oldheap = svm_push_data_heap (am->vlib_rp);
3522 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3524 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3526 svm_pop_heap (oldheap);
3527 pthread_mutex_unlock (&am->vlib_rp->mutex);
3529 *shmem_vecp = shmem_vec;
3534 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3536 vl_api_cli_reply_t *rp;
3537 unix_shared_memory_queue_t *q;
3538 vlib_main_t *vm = vlib_get_main ();
3539 api_main_t *am = &api_main;
3540 unformat_input_t input;
3544 q = vl_api_client_index_to_input_queue (mp->client_index);
3548 rp = vl_msg_api_alloc (sizeof (*rp));
3549 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3550 rp->context = mp->context;
3552 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3554 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3556 pthread_mutex_lock (&am->vlib_rp->mutex);
3557 oldheap = svm_push_data_heap (am->vlib_rp);
3559 vec_add1 (shmem_vec, 0);
3561 svm_pop_heap (oldheap);
3562 pthread_mutex_unlock (&am->vlib_rp->mutex);
3564 rp->reply_in_shmem = (uword) shmem_vec;
3566 vl_msg_api_send_shmem (q, (u8 *) & rp);
3570 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3572 u8 **mem_vecp = (u8 **) arg;
3573 u8 *mem_vec = *mem_vecp;
3574 u32 offset = vec_len (mem_vec);
3576 vec_validate (mem_vec, offset + buffer_bytes - 1);
3577 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3578 *mem_vecp = mem_vec;
3582 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3584 vl_api_cli_inband_reply_t *rmp;
3586 unix_shared_memory_queue_t *q;
3587 vlib_main_t *vm = vlib_get_main ();
3588 unformat_input_t input;
3591 q = vl_api_client_index_to_input_queue (mp->client_index);
3595 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3596 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3598 u32 len = vec_len (out_vec);
3600 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3602 rmp->length = htonl (len);
3603 clib_memcpy (rmp->reply, out_vec, len);
3610 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3613 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3614 vnet_main_t *vnm = vnet_get_main ();
3615 clib_error_t *error;
3620 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3622 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3626 clib_error_report (error);
3627 rv = VNET_API_ERROR_UNSPECIFIED;
3631 rv = vnm->api_errno;
3634 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3637 static void vl_api_sr_tunnel_add_del_t_handler
3638 (vl_api_sr_tunnel_add_del_t * mp)
3641 clib_warning ("unimplemented");
3643 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3645 vl_api_sr_tunnel_add_del_reply_t *rmp;
3646 ip6_address_t *segments = 0, *seg;
3647 ip6_address_t *tags = 0, *tag;
3648 ip6_address_t *this_address;
3651 if (mp->n_segments == 0)
3657 memset (a, 0, sizeof (*a));
3658 a->src_address = (ip6_address_t *) & mp->src_address;
3659 a->dst_address = (ip6_address_t *) & mp->dst_address;
3660 a->dst_mask_width = mp->dst_mask_width;
3661 a->flags_net_byte_order = mp->flags_net_byte_order;
3662 a->is_del = (mp->is_add == 0);
3663 a->rx_table_id = ntohl (mp->outer_vrf_id);
3664 a->tx_table_id = ntohl (mp->inner_vrf_id);
3666 a->name = format (0, "%s", mp->name);
3667 if (!(vec_len (a->name)))
3670 a->policy_name = format (0, "%s", mp->policy_name);
3671 if (!(vec_len (a->policy_name)))
3674 /* Yank segments and tags out of the API message */
3675 this_address = (ip6_address_t *) mp->segs_and_tags;
3676 for (i = 0; i < mp->n_segments; i++)
3678 vec_add2 (segments, seg, 1);
3679 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3682 for (i = 0; i < mp->n_tags; i++)
3684 vec_add2 (tags, tag, 1);
3685 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3689 a->segments = segments;
3692 rv = ip6_sr_add_del_tunnel (a);
3696 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3700 static void vl_api_sr_policy_add_del_t_handler
3701 (vl_api_sr_policy_add_del_t * mp)
3704 clib_warning ("unimplemented");
3706 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3708 vl_api_sr_policy_add_del_reply_t *rmp;
3711 memset (a, 0, sizeof (*a));
3712 a->is_del = (mp->is_add == 0);
3714 a->name = format (0, "%s", mp->name);
3715 if (!(vec_len (a->name)))
3717 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3721 if (!(mp->tunnel_names[0]))
3723 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3727 // start deserializing tunnel_names
3728 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3729 u8 *deser_tun_names = mp->tunnel_names;
3730 deser_tun_names += 1; //moving along
3733 int tun_name_len = 0;
3735 for (i = 0; i < num_tunnels; i++)
3737 tun_name_len = *deser_tun_names;
3738 deser_tun_names += 1;
3739 vec_resize (tun_name, tun_name_len);
3740 memcpy (tun_name, deser_tun_names, tun_name_len);
3741 vec_add1 (a->tunnel_names, tun_name);
3742 deser_tun_names += tun_name_len;
3746 rv = ip6_sr_add_del_policy (a);
3750 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3754 static void vl_api_sr_multicast_map_add_del_t_handler
3755 (vl_api_sr_multicast_map_add_del_t * mp)
3758 clib_warning ("unimplemented");
3760 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3762 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3764 memset (a, 0, sizeof (*a));
3765 a->is_del = (mp->is_add == 0);
3767 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3768 a->policy_name = format (0, "%s", mp->policy_name);
3770 if (a->multicast_address == 0)
3776 if (!(a->policy_name))
3782 #if DPDK > 0 /* Cannot call replicate without DPDK */
3783 rv = ip6_sr_add_del_multicastmap (a);
3785 clib_warning ("multicast replication without DPDK not implemented");
3786 rv = VNET_API_ERROR_UNIMPLEMENTED;
3791 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3795 #define foreach_classify_add_del_table_field \
3800 _(match_n_vectors) \
3801 _(next_table_index) \
3804 static void vl_api_classify_add_del_table_t_handler
3805 (vl_api_classify_add_del_table_t * mp)
3807 vl_api_classify_add_del_table_reply_t *rmp;
3808 vnet_classify_main_t *cm = &vnet_classify_main;
3809 vnet_classify_table_t *t;
3813 foreach_classify_add_del_table_field;
3816 #define _(a) a = ntohl(mp->a);
3817 foreach_classify_add_del_table_field;
3820 /* The underlying API fails silently, on purpose, so check here */
3821 if (mp->is_add == 0)
3822 if (pool_is_free_index (cm->tables, table_index))
3824 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3828 rv = vnet_classify_add_del_table
3829 (cm, mp->mask, nbuckets, memory_size,
3830 skip_n_vectors, match_n_vectors,
3831 next_table_index, miss_next_index, &table_index, mp->is_add);
3835 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3837 if (rv == 0 && mp->is_add)
3839 t = pool_elt_at_index (cm->tables, table_index);
3840 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3841 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3842 rmp->new_table_index = ntohl(table_index);
3846 rmp->skip_n_vectors = ~0;
3847 rmp->match_n_vectors = ~0;
3848 rmp->new_table_index = ~0;
3854 static void vl_api_classify_add_del_session_t_handler
3855 (vl_api_classify_add_del_session_t * mp)
3857 vnet_classify_main_t *cm = &vnet_classify_main;
3858 vl_api_classify_add_del_session_reply_t *rmp;
3860 u32 table_index, hit_next_index, opaque_index;
3863 table_index = ntohl (mp->table_index);
3864 hit_next_index = ntohl (mp->hit_next_index);
3865 opaque_index = ntohl (mp->opaque_index);
3866 advance = ntohl (mp->advance);
3868 rv = vnet_classify_add_del_session
3869 (cm, table_index, mp->match, hit_next_index, opaque_index,
3870 advance, mp->is_add);
3872 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3875 static void vl_api_classify_set_interface_ip_table_t_handler
3876 (vl_api_classify_set_interface_ip_table_t * mp)
3878 vlib_main_t *vm = vlib_get_main ();
3879 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3881 u32 table_index, sw_if_index;
3883 table_index = ntohl (mp->table_index);
3884 sw_if_index = ntohl (mp->sw_if_index);
3886 VALIDATE_SW_IF_INDEX (mp);
3889 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3891 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3893 BAD_SW_IF_INDEX_LABEL;
3895 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3898 static void vl_api_classify_set_interface_l2_tables_t_handler
3899 (vl_api_classify_set_interface_l2_tables_t * mp)
3901 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3903 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3906 ip4_table_index = ntohl (mp->ip4_table_index);
3907 ip6_table_index = ntohl (mp->ip6_table_index);
3908 other_table_index = ntohl (mp->other_table_index);
3909 sw_if_index = ntohl (mp->sw_if_index);
3911 VALIDATE_SW_IF_INDEX (mp);
3914 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
3918 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
3924 if (ip4_table_index != ~0 || ip6_table_index != ~0
3925 || other_table_index != ~0)
3931 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
3933 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
3936 BAD_SW_IF_INDEX_LABEL;
3938 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3942 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3945 vl_api_l2_fib_clear_table_reply_t *rmp;
3947 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3948 * that is not currently implemented. When that TODO is fixed
3949 * this call should be changed to pass 1 instead of 0.
3951 l2fib_clear_table (0);
3953 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3956 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3957 u32 sw_if_index, u32 enable);
3960 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3964 vl_api_l2_interface_efp_filter_reply_t *rmp;
3965 vnet_main_t *vnm = vnet_get_main ();
3967 // enable/disable the feature
3968 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3969 rv = vnm->api_errno;
3971 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3975 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3976 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3979 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3980 vnet_main_t *vnm = vnet_get_main ();
3981 vlib_main_t *vm = vlib_get_main ();
3984 VALIDATE_SW_IF_INDEX (mp);
3986 vtr_op = ntohl (mp->vtr_op);
3988 /* The L2 code is unsuspicious */
3991 case L2_VTR_DISABLED:
3996 case L2_VTR_TRANSLATE_1_1:
3997 case L2_VTR_TRANSLATE_1_2:
3998 case L2_VTR_TRANSLATE_2_1:
3999 case L2_VTR_TRANSLATE_2_2:
4003 rv = VNET_API_ERROR_INVALID_VALUE;
4004 goto bad_sw_if_index;
4007 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4008 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4011 BAD_SW_IF_INDEX_LABEL;
4013 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4017 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4020 vl_api_create_vhost_user_if_reply_t *rmp;
4021 u32 sw_if_index = (u32) ~ 0;
4023 vnet_main_t *vnm = vnet_get_main ();
4024 vlib_main_t *vm = vlib_get_main ();
4026 #if DPDK > 0 && DPDK_VHOST_USER
4027 rv = dpdk_vhost_user_create_if (
4029 rv = vhost_user_create_if (
4031 vnm, vm, (char *) mp->sock_filename,
4032 mp->is_server, &sw_if_index, (u64) ~ 0,
4033 mp->renumber, ntohl (mp->custom_dev_instance),
4034 (mp->use_custom_mac) ? mp->mac_address : NULL);
4037 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4039 rmp->sw_if_index = ntohl (sw_if_index);
4045 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4048 vl_api_modify_vhost_user_if_reply_t *rmp;
4049 u32 sw_if_index = ntohl (mp->sw_if_index);
4051 vnet_main_t *vnm = vnet_get_main ();
4052 vlib_main_t *vm = vlib_get_main ();
4054 #if DPDK > 0 && DPDK_VHOST_USER
4055 rv = dpdk_vhost_user_modify_if (
4057 rv = vhost_user_modify_if (
4059 vnm, vm, (char *) mp->sock_filename,
4060 mp->is_server, sw_if_index, (u64) ~ 0,
4061 mp->renumber, ntohl (mp->custom_dev_instance));
4062 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4066 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4069 vl_api_delete_vhost_user_if_reply_t *rmp;
4070 vpe_api_main_t *vam = &vpe_api_main;
4071 u32 sw_if_index = ntohl (mp->sw_if_index);
4073 vnet_main_t *vnm = vnet_get_main ();
4074 vlib_main_t *vm = vlib_get_main ();
4076 #if DPDK > 0 && DPDK_VHOST_USER
4077 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4079 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4082 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4085 unix_shared_memory_queue_t *q =
4086 vl_api_client_index_to_input_queue (mp->client_index);
4090 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4095 vl_api_sw_interface_vhost_user_details_t_handler
4096 (vl_api_sw_interface_vhost_user_details_t * mp)
4098 clib_warning ("BUG");
4102 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4103 unix_shared_memory_queue_t * q,
4104 vhost_user_intf_details_t * vui,
4107 vl_api_sw_interface_vhost_user_details_t *mp;
4109 mp = vl_msg_api_alloc (sizeof (*mp));
4110 memset (mp, 0, sizeof (*mp));
4111 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4112 mp->sw_if_index = ntohl (vui->sw_if_index);
4113 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4114 mp->features = clib_net_to_host_u64 (vui->features);
4115 mp->is_server = vui->is_server;
4116 mp->num_regions = ntohl (vui->num_regions);
4117 mp->sock_errno = ntohl (vui->sock_errno);
4118 mp->context = context;
4120 strncpy ((char *) mp->sock_filename,
4121 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4122 strncpy ((char *) mp->interface_name,
4123 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4125 vl_msg_api_send_shmem (q, (u8 *) & mp);
4129 vl_api_sw_interface_vhost_user_dump_t_handler
4130 (vl_api_sw_interface_vhost_user_dump_t * mp)
4133 vpe_api_main_t *am = &vpe_api_main;
4134 vnet_main_t *vnm = vnet_get_main ();
4135 vlib_main_t *vm = vlib_get_main ();
4136 vhost_user_intf_details_t *ifaces = NULL;
4137 vhost_user_intf_details_t *vuid = NULL;
4138 unix_shared_memory_queue_t *q;
4140 q = vl_api_client_index_to_input_queue (mp->client_index);
4144 #if DPDK > 0 && DPDK_VHOST_USER
4145 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4147 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4152 vec_foreach (vuid, ifaces)
4154 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4160 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4161 unix_shared_memory_queue_t * q,
4163 l2t_main_t * lm, u32 context)
4165 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4167 vnet_sw_interface_t *si = NULL;
4169 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4171 if_name = format (if_name, "%U",
4172 format_vnet_sw_interface_name, lm->vnet_main, si);
4174 mp = vl_msg_api_alloc (sizeof (*mp));
4175 memset (mp, 0, sizeof (*mp));
4176 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4177 strncpy ((char *) mp->interface_name,
4178 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4179 mp->sw_if_index = ntohl (si->sw_if_index);
4180 mp->local_session_id = s->local_session_id;
4181 mp->remote_session_id = s->remote_session_id;
4182 mp->local_cookie[0] = s->local_cookie[0];
4183 mp->local_cookie[1] = s->local_cookie[1];
4184 mp->remote_cookie = s->remote_cookie;
4185 clib_memcpy (mp->client_address, &s->client_address,
4186 sizeof (s->client_address));
4187 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4188 mp->l2_sublayer_present = s->l2_sublayer_present;
4189 mp->context = context;
4191 vl_msg_api_send_shmem (q, (u8 *) & mp);
4195 send_ip_address_details (vpe_api_main_t * am,
4196 unix_shared_memory_queue_t * q,
4197 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4199 vl_api_ip_address_details_t *mp;
4201 mp = vl_msg_api_alloc (sizeof (*mp));
4202 memset (mp, 0, sizeof (*mp));
4203 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4207 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4211 u32 *tp = (u32 *) mp->ip;
4212 *tp = ntohl (*(u32 *) ip);
4214 mp->prefix_length = prefix_length;
4215 mp->context = context;
4217 vl_msg_api_send_shmem (q, (u8 *) & mp);
4221 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4223 vpe_api_main_t *am = &vpe_api_main;
4224 unix_shared_memory_queue_t *q;
4227 ip6_main_t *im6 = &ip6_main;
4228 ip4_main_t *im4 = &ip4_main;
4229 ip_lookup_main_t *lm6 = &im6->lookup_main;
4230 ip_lookup_main_t *lm4 = &im4->lookup_main;
4231 ip_interface_address_t *ia = 0;
4232 u32 sw_if_index = ~0;
4233 int rv __attribute__ ((unused)) = 0;
4235 VALIDATE_SW_IF_INDEX (mp);
4237 sw_if_index = ntohl (mp->sw_if_index);
4239 q = vl_api_client_index_to_input_queue (mp->client_index);
4248 foreach_ip_interface_address (lm6, ia, sw_if_index,
4249 1 /* honor unnumbered */,
4251 r6 = ip_interface_address_get_address (lm6, ia);
4252 u16 prefix_length = ia->address_length;
4253 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4260 foreach_ip_interface_address (lm4, ia, sw_if_index,
4261 1 /* honor unnumbered */,
4263 r4 = ip_interface_address_get_address (lm4, ia);
4264 u16 prefix_length = ia->address_length;
4265 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4269 BAD_SW_IF_INDEX_LABEL;
4273 send_ip_details (vpe_api_main_t * am,
4274 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4276 vl_api_ip_details_t *mp;
4278 mp = vl_msg_api_alloc (sizeof (*mp));
4279 memset (mp, 0, sizeof (*mp));
4280 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4282 mp->sw_if_index = ntohl (sw_if_index);
4283 mp->context = context;
4285 vl_msg_api_send_shmem (q, (u8 *) & mp);
4289 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4292 vpe_api_main_t *am = &vpe_api_main;
4293 l2t_main_t *lm = &l2t_main;
4294 unix_shared_memory_queue_t *q;
4295 l2t_session_t *session;
4297 q = vl_api_client_index_to_input_queue (mp->client_index);
4302 pool_foreach (session, lm->sessions,
4304 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4311 send_sw_interface_tap_details (vpe_api_main_t * am,
4312 unix_shared_memory_queue_t * q,
4313 tapcli_interface_details_t * tap_if,
4316 vl_api_sw_interface_tap_details_t *mp;
4317 mp = vl_msg_api_alloc (sizeof (*mp));
4318 memset (mp, 0, sizeof (*mp));
4319 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4320 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4321 strncpy ((char *) mp->dev_name,
4322 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4323 mp->context = context;
4325 vl_msg_api_send_shmem (q, (u8 *) & mp);
4329 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4332 vpe_api_main_t *am = &vpe_api_main;
4333 unix_shared_memory_queue_t *q;
4334 tapcli_interface_details_t *tapifs = NULL;
4335 tapcli_interface_details_t *tap_if = NULL;
4337 q = vl_api_client_index_to_input_queue (mp->client_index);
4341 rv = vnet_tap_dump_ifs (&tapifs);
4345 vec_foreach (tap_if, tapifs)
4347 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4354 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4356 vpe_api_main_t *am = &vpe_api_main;
4357 vnet_main_t *vnm = vnet_get_main ();
4358 vlib_main_t *vm = vlib_get_main ();
4359 vnet_interface_main_t *im = &vnm->interface_main;
4360 unix_shared_memory_queue_t *q;
4361 vnet_sw_interface_t *si, *sorted_sis;
4362 u32 sw_if_index = ~0;
4364 q = vl_api_client_index_to_input_queue (mp->client_index);
4370 /* Gather interfaces. */
4371 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4372 _vec_len (sorted_sis) = 0;
4374 pool_foreach (si, im->sw_interfaces,
4376 vec_add1 (sorted_sis, si[0]);
4380 vec_foreach (si, sorted_sis)
4382 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4384 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4388 sw_if_index = si->sw_if_index;
4389 send_ip_details (am, q, sw_if_index, mp->context);
4395 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4397 clib_warning ("BUG");
4401 send_l2fib_table_entry (vpe_api_main_t * am,
4402 unix_shared_memory_queue_t * q,
4403 l2fib_entry_key_t * l2fe_key,
4404 l2fib_entry_result_t * l2fe_res, u32 context)
4406 vl_api_l2_fib_table_entry_t *mp;
4408 mp = vl_msg_api_alloc (sizeof (*mp));
4409 memset (mp, 0, sizeof (*mp));
4410 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4413 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4415 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4416 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4417 mp->static_mac = l2fe_res->fields.static_mac;
4418 mp->filter_mac = l2fe_res->fields.filter;
4419 mp->bvi_mac = l2fe_res->fields.bvi;
4420 mp->context = context;
4422 vl_msg_api_send_shmem (q, (u8 *) & mp);
4426 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4428 vpe_api_main_t *am = &vpe_api_main;
4429 bd_main_t *bdm = &bd_main;
4430 l2fib_entry_key_t *l2fe_key = NULL;
4431 l2fib_entry_result_t *l2fe_res = NULL;
4432 u32 ni, bd_id = ntohl (mp->bd_id);
4434 unix_shared_memory_queue_t *q;
4437 q = vl_api_client_index_to_input_queue (mp->client_index);
4441 /* see l2fib_table_dump: ~0 means "any" */
4446 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4453 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4455 vec_foreach_index (ni, l2fe_key)
4457 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4458 vec_elt_at_index (l2fe_res, ni), mp->context);
4460 vec_free (l2fe_key);
4461 vec_free (l2fe_res);
4465 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4467 vl_api_show_version_reply_t *rmp;
4469 char *vpe_api_get_build_directory (void);
4470 char *vpe_api_get_version (void);
4471 char *vpe_api_get_build_date (void);
4473 unix_shared_memory_queue_t *q =
4474 vl_api_client_index_to_input_queue (mp->client_index);
4480 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4482 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4483 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4484 ARRAY_LEN(rmp->build_directory)-1);
4485 strncpy ((char *) rmp->version, vpe_api_get_version(),
4486 ARRAY_LEN(rmp->version)-1);
4487 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4488 ARRAY_LEN(rmp->build_date)-1);
4494 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4496 vlib_main_t *vm = vlib_get_main ();
4497 vl_api_get_node_index_reply_t *rmp;
4500 u32 node_index = ~0;
4502 n = vlib_get_node_by_name (vm, mp->node_name);
4505 rv = VNET_API_ERROR_NO_SUCH_NODE;
4507 node_index = n->index;
4510 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4512 rmp->node_index = ntohl(node_index);
4518 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4520 vlib_main_t *vm = vlib_get_main ();
4521 vl_api_get_next_index_reply_t *rmp;
4522 vlib_node_t *node, *next_node;
4524 u32 next_node_index = ~0, next_index = ~0;
4527 node = vlib_get_node_by_name (vm, mp->node_name);
4531 rv = VNET_API_ERROR_NO_SUCH_NODE;
4535 next_node = vlib_get_node_by_name (vm, mp->next_name);
4539 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4543 next_node_index = next_node->index;
4545 p = hash_get (node->next_slot_by_node, next_node_index);
4549 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4557 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4559 rmp->next_index = ntohl(next_index);
4565 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4567 vlib_main_t *vm = vlib_get_main ();
4568 vl_api_add_node_next_reply_t *rmp;
4569 vlib_node_t *n, *next;
4571 u32 next_index = ~0;
4573 n = vlib_get_node_by_name (vm, mp->node_name);
4577 rv = VNET_API_ERROR_NO_SUCH_NODE;
4581 next = vlib_get_node_by_name (vm, mp->next_name);
4584 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4586 next_index = vlib_node_add_next (vm, n->index, next->index);
4590 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4592 rmp->next_index = ntohl(next_index);
4597 static void vl_api_l2tpv3_create_tunnel_t_handler
4598 (vl_api_l2tpv3_create_tunnel_t * mp)
4600 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4601 l2t_main_t *lm = &l2t_main;
4602 u32 sw_if_index = (u32) ~ 0;
4605 if (mp->is_ipv6 != 1)
4607 rv = VNET_API_ERROR_UNIMPLEMENTED;
4611 u32 encap_fib_index;
4613 if (mp->encap_vrf_id != ~0)
4616 ip6_main_t *im = &ip6_main;
4619 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4621 rv = VNET_API_ERROR_NO_SUCH_FIB;
4624 encap_fib_index = p[0];
4628 encap_fib_index = ~0;
4631 rv = create_l2tpv3_ipv6_tunnel (lm,
4632 (ip6_address_t *) mp->client_address,
4633 (ip6_address_t *) mp->our_address,
4634 ntohl (mp->local_session_id),
4635 ntohl (mp->remote_session_id),
4636 clib_net_to_host_u64 (mp->local_cookie),
4637 clib_net_to_host_u64 (mp->remote_cookie),
4638 mp->l2_sublayer_present,
4639 encap_fib_index, &sw_if_index);
4643 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4645 rmp->sw_if_index = ntohl (sw_if_index);
4650 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4651 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4653 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4654 l2t_main_t *lm = &l2t_main;
4657 VALIDATE_SW_IF_INDEX (mp);
4659 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4660 clib_net_to_host_u64 (mp->new_local_cookie),
4661 clib_net_to_host_u64
4662 (mp->new_remote_cookie));
4664 BAD_SW_IF_INDEX_LABEL;
4666 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4669 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4670 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4673 vnet_main_t *vnm = vnet_get_main ();
4674 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4676 VALIDATE_SW_IF_INDEX (mp);
4678 rv = l2tpv3_interface_enable_disable
4679 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4681 BAD_SW_IF_INDEX_LABEL;
4683 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4686 static void vl_api_l2tpv3_set_lookup_key_t_handler
4687 (vl_api_l2tpv3_set_lookup_key_t * mp)
4690 l2t_main_t *lm = &l2t_main;
4691 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4693 if (mp->key > L2T_LOOKUP_SESSION_ID)
4695 rv = VNET_API_ERROR_INVALID_VALUE;
4699 lm->lookup_type = mp->key;
4702 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4705 static void vl_api_vxlan_add_del_tunnel_t_handler
4706 (vl_api_vxlan_add_del_tunnel_t * mp)
4708 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4710 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4711 u32 encap_fib_index;
4713 ip4_main_t *im = &ip4_main;
4714 u32 sw_if_index = ~0;
4716 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4719 rv = VNET_API_ERROR_NO_SUCH_FIB;
4722 encap_fib_index = p[0];
4724 /* Check src & dst are different */
4725 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4726 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4728 rv = VNET_API_ERROR_SAME_SRC_DST;
4731 memset (a, 0, sizeof (*a));
4733 a->is_add = mp->is_add;
4734 a->is_ip6 = mp->is_ipv6;
4736 /* ip addresses sent in network byte order */
4739 memcpy (&(a->src.ip6), mp->src_address, 16);
4740 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4744 memcpy (&(a->src.ip4), mp->src_address, 4);
4745 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4748 a->encap_fib_index = encap_fib_index;
4749 a->decap_next_index = ntohl (mp->decap_next_index);
4750 a->vni = ntohl (mp->vni);
4751 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4755 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4757 rmp->sw_if_index = ntohl (sw_if_index);
4762 static void send_vxlan_tunnel_details
4763 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4765 vl_api_vxlan_tunnel_details_t *rmp;
4766 ip4_main_t *im4 = &ip4_main;
4767 ip6_main_t *im6 = &ip6_main;
4768 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4770 rmp = vl_msg_api_alloc (sizeof (*rmp));
4771 memset (rmp, 0, sizeof (*rmp));
4772 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4775 memcpy (rmp->src_address, &(t->src.ip6), 16);
4776 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4777 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4781 memcpy (rmp->src_address, &(t->src.ip4), 4);
4782 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4783 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4785 rmp->vni = htonl (t->vni);
4786 rmp->decap_next_index = htonl (t->decap_next_index);
4787 rmp->sw_if_index = htonl (t->sw_if_index);
4788 rmp->is_ipv6 = is_ipv6;
4789 rmp->context = context;
4791 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4794 static void vl_api_vxlan_tunnel_dump_t_handler
4795 (vl_api_vxlan_tunnel_dump_t * mp)
4797 unix_shared_memory_queue_t *q;
4798 vxlan_main_t *vxm = &vxlan_main;
4802 q = vl_api_client_index_to_input_queue (mp->client_index);
4808 sw_if_index = ntohl (mp->sw_if_index);
4810 if (~0 == sw_if_index)
4813 pool_foreach (t, vxm->tunnels,
4815 send_vxlan_tunnel_details(t, q, mp->context);
4821 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4822 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4826 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4827 send_vxlan_tunnel_details (t, q, mp->context);
4831 static void vl_api_gre_add_del_tunnel_t_handler
4832 (vl_api_gre_add_del_tunnel_t * mp)
4834 vl_api_gre_add_del_tunnel_reply_t *rmp;
4836 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4839 ip4_main_t *im = &ip4_main;
4840 u32 sw_if_index = ~0;
4842 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4845 rv = VNET_API_ERROR_NO_SUCH_FIB;
4848 outer_fib_id = p[0];
4850 /* Check src & dst are different */
4851 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4852 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4854 rv = VNET_API_ERROR_SAME_SRC_DST;
4857 memset (a, 0, sizeof (*a));
4859 a->is_add = mp->is_add;
4862 /* ip addresses sent in network byte order */
4863 clib_memcpy (&(a->src), mp->src_address, 4);
4864 clib_memcpy (&(a->dst), mp->dst_address, 4);
4866 a->outer_fib_id = outer_fib_id;
4867 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4871 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4873 rmp->sw_if_index = ntohl (sw_if_index);
4878 static void send_gre_tunnel_details
4879 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4881 vl_api_gre_tunnel_details_t *rmp;
4882 ip4_main_t *im = &ip4_main;
4884 rmp = vl_msg_api_alloc (sizeof (*rmp));
4885 memset (rmp, 0, sizeof (*rmp));
4886 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4887 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4888 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4889 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4891 rmp->sw_if_index = htonl (t->sw_if_index);
4892 rmp->context = context;
4894 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4898 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4900 unix_shared_memory_queue_t *q;
4901 gre_main_t *gm = &gre_main;
4905 q = vl_api_client_index_to_input_queue (mp->client_index);
4911 sw_if_index = ntohl (mp->sw_if_index);
4913 if (~0 == sw_if_index)
4916 pool_foreach (t, gm->tunnels,
4918 send_gre_tunnel_details(t, q, mp->context);
4924 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4925 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4929 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4930 send_gre_tunnel_details (t, q, mp->context);
4935 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4937 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4939 vl_api_l2_patch_add_del_reply_t *rmp;
4940 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4944 VALIDATE_RX_SW_IF_INDEX (mp);
4945 VALIDATE_TX_SW_IF_INDEX (mp);
4947 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4948 ntohl (mp->tx_sw_if_index),
4949 (int) (mp->is_add != 0));
4951 BAD_RX_SW_IF_INDEX_LABEL;
4952 BAD_TX_SW_IF_INDEX_LABEL;
4954 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4958 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4959 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4961 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4963 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4964 u32 encap_fib_index, decap_fib_index;
4967 ip4_main_t *im = &ip4_main;
4968 u32 sw_if_index = ~0;
4971 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4974 rv = VNET_API_ERROR_NO_SUCH_FIB;
4977 encap_fib_index = p[0];
4979 protocol = mp->protocol;
4981 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4982 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4984 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4987 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4990 decap_fib_index = p[0];
4994 decap_fib_index = ntohl (mp->decap_vrf_id);
4997 /* Check src & dst are different */
4998 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4999 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5001 rv = VNET_API_ERROR_SAME_SRC_DST;
5004 memset (a, 0, sizeof (*a));
5006 a->is_add = mp->is_add;
5007 a->is_ip6 = mp->is_ipv6;
5008 /* ip addresses sent in network byte order */
5011 clib_memcpy (&(a->local.ip6), mp->local, 16);
5012 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5016 clib_memcpy (&(a->local.ip4), mp->local, 4);
5017 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5019 a->encap_fib_index = encap_fib_index;
5020 a->decap_fib_index = decap_fib_index;
5021 a->protocol = protocol;
5022 a->vni = ntohl (mp->vni);
5023 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5027 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5029 rmp->sw_if_index = ntohl (sw_if_index);
5034 static void send_vxlan_gpe_tunnel_details
5035 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5037 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5038 ip4_main_t *im4 = &ip4_main;
5039 ip6_main_t *im6 = &ip6_main;
5040 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5042 rmp = vl_msg_api_alloc (sizeof (*rmp));
5043 memset (rmp, 0, sizeof (*rmp));
5044 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5047 memcpy (rmp->local, &(t->local.ip6), 16);
5048 memcpy (rmp->remote, &(t->remote.ip6), 16);
5049 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
5050 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
5054 memcpy (rmp->local, &(t->local.ip4), 4);
5055 memcpy (rmp->remote, &(t->remote.ip4), 4);
5056 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
5057 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
5059 rmp->vni = htonl (t->vni);
5060 rmp->protocol = t->protocol;
5061 rmp->sw_if_index = htonl (t->sw_if_index);
5062 rmp->is_ipv6 = is_ipv6;
5063 rmp->context = context;
5065 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5068 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5069 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5071 unix_shared_memory_queue_t *q;
5072 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5073 vxlan_gpe_tunnel_t *t;
5076 q = vl_api_client_index_to_input_queue (mp->client_index);
5082 sw_if_index = ntohl (mp->sw_if_index);
5084 if (~0 == sw_if_index)
5087 pool_foreach (t, vgm->tunnels,
5089 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5095 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5096 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5100 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5101 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5105 /** Used for transferring locators via VPP API */
5107 typedef CLIB_PACKED (struct {
5108 u32 sw_if_index; /**< locator sw_if_index */
5109 u8 priority; /**< locator priority */
5110 u8 weight; /**< locator weight */
5115 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5118 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5120 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5122 ls_locator_t *ls_loc;
5123 u32 ls_index = ~0, locator_num;
5124 u8 *locator_name = NULL;
5127 memset (a, 0, sizeof (a[0]));
5129 locator_name = format (0, "%s", mp->locator_set_name);
5131 a->name = locator_name;
5132 a->is_add = mp->is_add;
5134 locator_num = clib_net_to_host_u32 (mp->locator_num);
5136 memset (&locator, 0, sizeof (locator));
5137 for (i = 0; i < locator_num; i++)
5139 ls_loc = &((ls_locator_t *) mp->locators)[i];
5140 VALIDATE_SW_IF_INDEX (ls_loc);
5142 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5143 locator.priority = ls_loc->priority;
5144 locator.weight = ls_loc->weight;
5146 vec_add1 (a->locators, locator);
5149 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5151 BAD_SW_IF_INDEX_LABEL;
5153 vec_free (locator_name);
5154 vec_free (a->locators);
5157 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5159 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5165 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5167 vl_api_lisp_add_del_locator_reply_t *rmp;
5169 locator_t locator, *locators = NULL;
5170 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5172 u8 *locator_name = NULL;
5174 memset (&locator, 0, sizeof (locator));
5175 memset (a, 0, sizeof (a[0]));
5177 locator.sw_if_index = ntohl (mp->sw_if_index);
5178 locator.priority = mp->priority;
5179 locator.weight = mp->weight;
5181 vec_add1 (locators, locator);
5183 locator_name = format (0, "%s", mp->locator_set_name);
5185 a->name = locator_name;
5186 a->locators = locators;
5187 a->is_add = mp->is_add;
5190 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5192 vec_free (locators);
5193 vec_free (locator_name);
5195 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5199 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5205 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5206 gid_address_ip_set (dst, src, IP4);
5207 gid_address_ippref_len (dst) = len;
5208 ip_prefix_normalize (&gid_address_ippref (dst));
5211 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5212 gid_address_ip_set (dst, src, IP6);
5213 gid_address_ippref_len (dst) = len;
5214 ip_prefix_normalize (&gid_address_ippref (dst));
5216 case 2: /* l2 mac */
5217 gid_address_type (dst) = GID_ADDR_MAC;
5218 clib_memcpy (&gid_address_mac (dst), src, 6);
5222 return VNET_API_ERROR_INVALID_VALUE;
5225 gid_address_vni (dst) = vni;
5231 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5233 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5234 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5236 gid_address_t _eid, *eid = &_eid;
5238 u32 locator_set_index = ~0, map_index = ~0;
5239 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5241 memset (a, 0, sizeof (a[0]));
5242 memset (eid, 0, sizeof (eid[0]));
5244 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5245 mp->eid_type, mp->eid, mp->prefix_len);
5249 name = format (0, "%s", mp->locator_set_name);
5250 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5253 rv = VNET_API_ERROR_INVALID_VALUE;
5256 locator_set_index = p[0];
5258 /* XXX treat batch configuration */
5259 a->is_add = mp->is_add;
5260 gid_address_copy (&a->eid, eid);
5261 a->locator_set_index = locator_set_index;
5263 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5267 gid_address_free (&a->eid);
5269 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5273 vl_api_lisp_eid_table_add_del_map_t_handler
5274 (vl_api_lisp_eid_table_add_del_map_t * mp)
5276 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5278 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5279 clib_net_to_host_u32 (mp->dp_table),
5280 mp->is_l2, mp->is_add);
5281 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5283 /** Used for transferring locators via VPP API */
5285 typedef CLIB_PACKED (struct {
5286 u8 is_ip4; /**< is locator an IPv4 address */
5287 u8 priority; /**< locator priority */
5288 u8 weight; /**< locator weight */
5289 u8 addr[16]; /**< IPv4/IPv6 address */
5293 static locator_pair_t *
5294 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5297 locator_pair_t *pairs = 0, pair;
5300 for (i = 0; i < rloc_num; i++)
5303 r = &((rloc_t *) lcl_locs)[i];
5304 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5305 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5307 /* remote locators */
5308 r = &((rloc_t *) rmt_locs)[i];
5309 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5310 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5312 pair.priority = r->priority;
5313 pair.weight = r->weight;
5315 vec_add1 (pairs, pair);
5321 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5324 locator_t *locs = 0, loc;
5327 for (i = 0; i < rloc_num; i++)
5329 /* remote locators */
5330 r = &((rloc_t *) rmt_locs)[i];
5331 memset (&loc, 0, sizeof (loc));
5332 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5334 loc.priority = r->priority;
5335 loc.weight = r->weight;
5337 vec_add1 (locs, loc);
5343 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5344 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5346 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5347 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5348 locator_pair_t *pairs = 0;
5351 memset (a, 0, sizeof (a[0]));
5353 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5354 mp->rmt_eid, mp->rmt_len);
5355 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5356 mp->lcl_eid, mp->lcl_len);
5358 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5360 if (rv || 0 == pairs)
5363 a->is_add = mp->is_add;
5364 a->locator_pairs = pairs;
5365 a->dp_table = mp->dp_table;
5367 a->action = mp->action;
5369 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5372 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5376 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5379 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5381 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5383 memset (a, 0, sizeof (a[0]));
5385 a->is_add = mp->is_add;
5386 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5388 rv = vnet_lisp_add_del_map_resolver (a);
5390 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5394 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5397 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5399 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5401 a->is_en = mp->is_en;
5402 vnet_lisp_gpe_enable_disable (a);
5404 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5408 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5410 vl_api_lisp_enable_disable_reply_t *rmp;
5413 vnet_lisp_enable_disable (mp->is_en);
5414 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5418 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5420 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5428 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
5432 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
5439 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
5443 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
5446 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5450 vl_api_show_lisp_map_request_mode_t_handler
5451 (vl_api_show_lisp_map_request_mode_t * mp)
5454 vl_api_show_lisp_map_request_mode_reply_t *rmp;
5457 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
5459 rmp->mode = vnet_lisp_get_map_request_mode ();
5465 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
5467 vl_api_lisp_map_request_mode_reply_t *rmp;
5470 rv = vnet_lisp_set_map_request_mode (mp->mode);
5472 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
5476 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5479 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5483 ls_name = format (0, "%s", mp->ls_name);
5484 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5487 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5491 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5492 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5494 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5496 u8 *locator_set_name = NULL;
5497 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5499 locator_set_name = format (0, "%s", mp->locator_set_name);
5501 a->is_add = mp->is_add;
5502 a->locator_set_name = locator_set_name;
5504 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5506 vec_free (locator_set_name);
5508 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5512 vl_api_lisp_add_del_remote_mapping_t_handler
5513 (vl_api_lisp_add_del_remote_mapping_t * mp)
5515 locator_t *rlocs = 0;
5516 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5518 gid_address_t _eid, *eid = &_eid;
5519 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5521 memset (eid, 0, sizeof (eid[0]));
5523 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5524 mp->eid_type, mp->eid, mp->eid_len);
5528 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5532 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5533 gid_address_copy (&a->reid, eid);
5535 rv = vnet_lisp_add_del_adjacency (a);
5542 /* NOTE: for now this works as a static remote mapping, i.e.,
5543 * not authoritative and ttl infinite. */
5544 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5545 mp->is_add, 1 /* is_static */ , 0);
5548 vnet_lisp_clear_all_remote_adjacencies ();
5553 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5557 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5559 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5560 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5563 memset (a, 0, sizeof (a[0]));
5565 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
5566 mp->eid_type, mp->leid, mp->leid_len);
5567 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
5568 mp->eid_type, mp->reid, mp->reid_len);
5573 a->is_add = mp->is_add;
5574 rv = vnet_lisp_add_del_adjacency (a);
5577 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5581 send_lisp_locator_details (lisp_cp_main_t * lcm,
5583 unix_shared_memory_queue_t * q, u32 context)
5585 vl_api_lisp_locator_details_t *rmp;
5587 rmp = vl_msg_api_alloc (sizeof (*rmp));
5588 memset (rmp, 0, sizeof (*rmp));
5589 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5590 rmp->context = context;
5592 rmp->local = loc->local;
5595 rmp->sw_if_index = ntohl (loc->sw_if_index);
5599 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5600 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5602 rmp->priority = loc->priority;
5603 rmp->weight = loc->weight;
5605 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5609 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5612 unix_shared_memory_queue_t *q = 0;
5613 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5614 locator_set_t *lsit = 0;
5616 u32 ls_index = ~0, *locit = 0;
5619 q = vl_api_client_index_to_input_queue (mp->client_index);
5625 if (mp->is_index_set)
5626 ls_index = htonl (mp->ls_index);
5629 /* make sure we get a proper C-string */
5630 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
5631 ls_name = format (0, "%s", mp->ls_name);
5632 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
5638 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
5641 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5643 vec_foreach (locit, lsit->locator_indices)
5645 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5646 send_lisp_locator_details (lcm, loc, q, mp->context);
5653 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5654 locator_set_t * lsit,
5655 unix_shared_memory_queue_t * q,
5656 u32 context, u32 ls_index)
5658 vl_api_lisp_locator_set_details_t *rmp;
5661 rmp = vl_msg_api_alloc (sizeof (*rmp));
5662 memset (rmp, 0, sizeof (*rmp));
5663 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5664 rmp->context = context;
5666 rmp->ls_index = htonl (ls_index);
5669 ASSERT (lsit->name != NULL);
5670 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
5671 vec_len (lsit->name));
5675 str = format (0, "<remote-%d>", ls_index);
5676 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
5680 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5684 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5686 unix_shared_memory_queue_t *q = NULL;
5687 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5688 locator_set_t *lsit = NULL;
5691 q = vl_api_client_index_to_input_queue (mp->client_index);
5697 filter = mp->filter;
5699 pool_foreach (lsit, lcm->locator_set_pool,
5701 if (filter && !((1 == filter && lsit->local) ||
5702 (2 == filter && !lsit->local)))
5706 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
5707 lsit - lcm->locator_set_pool);
5713 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5715 ASSERT (prefix_length);
5716 ip_prefix_t *ippref = &fid_addr_ippref (src);
5718 switch (fid_addr_type (src))
5720 case FID_ADDR_IP_PREF:
5721 if (ip_prefix_version (ippref) == IP4)
5722 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5724 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5725 prefix_length[0] = ip_prefix_len (ippref);
5729 prefix_length[0] = 0;
5730 clib_memcpy (dst, fid_addr_mac (src), 6);
5734 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5740 fid_type_to_api_type (fid_address_t * fid)
5742 ip_prefix_t *ippref;
5744 switch (fid_addr_type (fid))
5746 case FID_ADDR_IP_PREF:
5747 ippref = &fid_addr_ippref (fid);
5748 if (ip_prefix_version (ippref) == IP4)
5750 else if (ip_prefix_version (ippref) == IP6)
5763 send_lisp_eid_table_details (mapping_t * mapit,
5764 unix_shared_memory_queue_t * q,
5765 u32 context, u8 filter)
5768 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5769 locator_set_t *ls = 0;
5770 vl_api_lisp_eid_table_details_t *rmp = NULL;
5771 gid_address_t *gid = NULL;
5773 ip_prefix_t *ip_prefix = NULL;
5777 case 0: /* all mappings */
5780 case 1: /* local only */
5784 case 2: /* remote only */
5789 clib_warning ("Filter error, unknown filter: %d", filter);
5794 ip_prefix = &gid_address_ippref (gid);
5795 mac = gid_address_mac (gid);
5797 rmp = vl_msg_api_alloc (sizeof (*rmp));
5798 memset (rmp, 0, sizeof (*rmp));
5799 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5801 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5802 if (vec_len (ls->locator_indices) == 0)
5803 rmp->locator_set_index = ~0;
5805 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5807 rmp->is_local = mapit->local;
5808 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5809 rmp->action = mapit->action;
5810 rmp->authoritative = mapit->authoritative;
5812 switch (gid_address_type (gid))
5814 case GID_ADDR_SRC_DST:
5815 rmp->is_src_dst = 1;
5816 fid = &gid_address_sd_src (gid);
5817 rmp->eid_type = fid_type_to_api_type (fid);
5818 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5819 &rmp->seid_prefix_len);
5820 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5821 &rmp->eid_prefix_len);
5823 case GID_ADDR_IP_PREFIX:
5824 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5825 if (ip_prefix_version (ip_prefix) == IP4)
5827 rmp->eid_type = 0; /* ipv4 type */
5828 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5829 sizeof (ip_prefix_v4 (ip_prefix)));
5833 rmp->eid_type = 1; /* ipv6 type */
5834 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5835 sizeof (ip_prefix_v6 (ip_prefix)));
5839 rmp->eid_type = 2; /* l2 mac type */
5840 clib_memcpy (rmp->eid, mac, 6);
5845 rmp->context = context;
5846 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5847 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5851 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5854 unix_shared_memory_queue_t *q = NULL;
5855 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5856 mapping_t *mapit = NULL;
5857 gid_address_t _eid, *eid = &_eid;
5859 q = vl_api_client_index_to_input_queue (mp->client_index);
5867 memset (eid, 0, sizeof (*eid));
5869 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5870 mp->eid_type, mp->eid, mp->prefix_length);
5872 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5873 if ((u32) ~ 0 == mi)
5876 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5877 send_lisp_eid_table_details (mapit, q, mp->context,
5878 0 /* ignore filter */ );
5883 pool_foreach (mapit, lcm->mapping_pool,
5885 send_lisp_eid_table_details(mapit, q, mp->context,
5893 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
5894 unix_shared_memory_queue_t * q, u32 context)
5896 vl_api_lisp_gpe_tunnel_details_t *rmp;
5897 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5899 rmp = vl_msg_api_alloc (sizeof (*rmp));
5900 memset (rmp, 0, sizeof (*rmp));
5901 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5903 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
5905 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
5906 ip_address_copy_addr (rmp->source_ip,
5907 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5908 ip_address_copy_addr (rmp->destination_ip,
5909 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5911 rmp->encap_fib_id = htonl (0);
5912 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
5913 rmp->iid = htonl (lfe->key->vni);
5914 rmp->context = context;
5916 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5920 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5922 unix_shared_memory_queue_t *q = NULL;
5923 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5924 lisp_gpe_fwd_entry_t *lfe = NULL;
5926 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
5931 q = vl_api_client_index_to_input_queue (mp->client_index);
5938 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
5940 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
5946 send_lisp_map_resolver_details (ip_address_t * ip,
5947 unix_shared_memory_queue_t * q, u32 context)
5949 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5951 rmp = vl_msg_api_alloc (sizeof (*rmp));
5952 memset (rmp, 0, sizeof (*rmp));
5953 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5955 switch (ip_addr_version (ip))
5959 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5960 sizeof (ip_addr_v4 (ip)));
5965 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5966 sizeof (ip_addr_v6 (ip)));
5972 rmp->context = context;
5974 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5978 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5980 unix_shared_memory_queue_t *q = NULL;
5981 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5984 q = vl_api_client_index_to_input_queue (mp->client_index);
5990 vec_foreach (mr, lcm->map_resolvers)
5992 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5997 send_eid_table_map_pair (hash_pair_t * p,
5998 unix_shared_memory_queue_t * q, u32 context)
6000 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
6002 rmp = vl_msg_api_alloc (sizeof (*rmp));
6003 memset (rmp, 0, sizeof (*rmp));
6004 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
6006 rmp->vni = clib_host_to_net_u32 (p->key);
6007 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
6008 rmp->context = context;
6009 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6013 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
6016 unix_shared_memory_queue_t *q = NULL;
6017 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6019 uword *vni_table = 0;
6021 q = vl_api_client_index_to_input_queue (mp->client_index);
6029 vni_table = lcm->bd_id_by_vni;
6033 vni_table = lcm->table_id_by_vni;
6037 hash_foreach_pair (p, vni_table,
6039 send_eid_table_map_pair (p, q, mp->context);
6045 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6047 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6049 rmp = vl_msg_api_alloc (sizeof (*rmp));
6050 memset (rmp, 0, sizeof (*rmp));
6051 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6052 rmp->context = context;
6053 rmp->vni = clib_host_to_net_u32 (vni);
6054 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6058 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
6060 lisp_adjacency_t *adj;
6061 vl_api_lisp_adjacency_t a;
6062 u32 i, n = vec_len (adjs);
6064 for (i = 0; i < n; i++)
6066 adj = vec_elt_at_index (adjs, i);
6067 memset (&a, 0, sizeof (a));
6069 switch (gid_address_type (&adj->reid))
6071 case GID_ADDR_IP_PREFIX:
6072 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
6073 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
6074 if (gid_address_ip_version (&adj->reid) == IP4)
6076 a.eid_type = 0; /* ipv4 type */
6077 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
6078 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
6082 a.eid_type = 1; /* ipv6 type */
6083 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
6084 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
6088 a.eid_type = 2; /* l2 mac type */
6089 mac_copy (a.reid, gid_address_mac (&adj->reid));
6090 mac_copy (a.leid, gid_address_mac (&adj->leid));
6100 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
6102 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
6103 lisp_adjacency_t *adjs = 0;
6105 vl_api_lisp_adjacency_t a;
6107 u32 vni = clib_net_to_host_u32 (mp->vni);
6109 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
6110 size = vec_len (adjs) * sizeof (a);
6113 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
6115 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
6116 lisp_adjacency_copy (rmp->adjacencies, adjs);
6124 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6129 unix_shared_memory_queue_t *q = 0;
6130 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6132 q = vl_api_client_index_to_input_queue (mp->client_index);
6139 hash_foreach_pair (p, lcm->table_id_by_vni,
6141 hash_set (vnis, p->key, 0);
6144 hash_foreach_pair (p, lcm->bd_id_by_vni,
6146 hash_set (vnis, p->key, 0);
6149 hash_foreach_pair (p, vnis,
6151 send_eid_table_vni (p->key, q, mp->context);
6159 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6161 unix_shared_memory_queue_t *q = NULL;
6162 vl_api_show_lisp_status_reply_t *rmp = NULL;
6165 q = vl_api_client_index_to_input_queue (mp->client_index);
6172 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6174 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6175 rmp->feature_status = vnet_lisp_enable_disable_status ();
6181 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6182 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6184 unix_shared_memory_queue_t *q = NULL;
6185 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6186 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6187 locator_set_t *loc_set = 0;
6191 q = vl_api_client_index_to_input_queue (mp->client_index);
6197 if (~0 == lcm->mreq_itr_rlocs)
6199 tmp_str = format (0, " ");
6204 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6205 tmp_str = format (0, "%s", loc_set->name);
6209 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6211 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6212 ARRAY_LEN(rmp->locator_set_name) - 1);
6220 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6222 unix_shared_memory_queue_t *q = NULL;
6223 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6224 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6226 locator_set_t *ls = 0;
6230 q = vl_api_client_index_to_input_queue (mp->client_index);
6236 if (!lcm->lisp_pitr)
6238 tmp_str = format (0, "N/A");
6242 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6243 if (~0 != m->locator_set_index)
6246 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6247 tmp_str = format (0, "%s", ls->name);
6251 tmp_str = format (0, "N/A");
6254 vec_add1 (tmp_str, 0);
6257 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6259 rmp->status = lcm->lisp_pitr;
6260 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6261 ARRAY_LEN(rmp->locator_set_name) - 1);
6267 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6270 vl_api_interface_name_renumber_reply_t *rmp;
6273 VALIDATE_SW_IF_INDEX (mp);
6275 rv = vnet_interface_name_renumber
6276 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6278 BAD_SW_IF_INDEX_LABEL;
6280 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6284 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6285 u32 sw_if_index, u32 address)
6287 vpe_api_main_t *am = &vpe_api_main;
6288 vlib_main_t *vm = am->vlib_main;
6289 vl_api_ip4_arp_event_t *event;
6290 static f64 arp_event_last_time;
6291 f64 now = vlib_time_now (vm);
6293 if (pool_is_free_index (am->arp_events, pool_index))
6296 event = pool_elt_at_index (am->arp_events, pool_index);
6298 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6300 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6304 if (sw_if_index == event->sw_if_index &&
6306 /* for BD case, also check IP address with 10 sec timeout */
6307 (address == event->address &&
6308 (now - arp_event_last_time) < 10.0)))
6313 arp_event_last_time = now;
6314 event->sw_if_index = sw_if_index;
6316 event->address = address;
6321 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6322 u32 sw_if_index, ip6_address_t * address)
6324 vpe_api_main_t *am = &vpe_api_main;
6325 vlib_main_t *vm = am->vlib_main;
6326 vl_api_ip6_nd_event_t *event;
6327 static f64 nd_event_last_time;
6328 f64 now = vlib_time_now (vm);
6330 if (pool_is_free_index (am->nd_events, pool_index))
6333 event = pool_elt_at_index (am->nd_events, pool_index);
6336 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6338 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6342 if (sw_if_index == event->sw_if_index &&
6344 /* for BD case, also check IP address with 10 sec timeout */
6345 (ip6_address_is_equal (address,
6346 (ip6_address_t *) event->address) &&
6347 (now - nd_event_last_time) < 10.0)))
6352 nd_event_last_time = now;
6353 event->sw_if_index = sw_if_index;
6355 clib_memcpy (event->address, address, sizeof (event->address));
6360 arp_change_delete_callback (u32 pool_index, u8 * notused)
6362 vpe_api_main_t *am = &vpe_api_main;
6364 if (pool_is_free_index (am->arp_events, pool_index))
6367 pool_put_index (am->arp_events, pool_index);
6372 nd_change_delete_callback (u32 pool_index, u8 * notused)
6374 vpe_api_main_t *am = &vpe_api_main;
6376 if (pool_is_free_index (am->nd_events, pool_index))
6379 pool_put_index (am->nd_events, pool_index);
6384 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6386 vpe_api_main_t *am = &vpe_api_main;
6387 vnet_main_t *vnm = vnet_get_main ();
6388 vl_api_want_ip4_arp_events_reply_t *rmp;
6389 vl_api_ip4_arp_event_t *event;
6392 if (mp->enable_disable)
6394 pool_get (am->arp_events, event);
6395 memset (event, 0, sizeof (*event));
6397 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6398 event->client_index = mp->client_index;
6399 event->context = mp->context;
6400 event->address = mp->address;
6401 event->pid = mp->pid;
6402 if (mp->address == 0)
6405 rv = vnet_add_del_ip4_arp_change_event
6406 (vnm, arp_change_data_callback,
6407 mp->pid, &mp->address /* addr, in net byte order */ ,
6408 vpe_resolver_process_node.index,
6409 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6413 rv = vnet_add_del_ip4_arp_change_event
6414 (vnm, arp_change_delete_callback,
6415 mp->pid, &mp->address /* addr, in net byte order */ ,
6416 vpe_resolver_process_node.index,
6417 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6419 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6423 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6425 vpe_api_main_t *am = &vpe_api_main;
6426 vnet_main_t *vnm = vnet_get_main ();
6427 vl_api_want_ip6_nd_events_reply_t *rmp;
6428 vl_api_ip6_nd_event_t *event;
6431 if (mp->enable_disable)
6433 pool_get (am->nd_events, event);
6434 memset (event, 0, sizeof (*event));
6436 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6437 event->client_index = mp->client_index;
6438 event->context = mp->context;
6439 clib_memcpy (event->address, mp->address, 16);
6440 event->pid = mp->pid;
6441 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6444 rv = vnet_add_del_ip6_nd_change_event
6445 (vnm, nd_change_data_callback,
6446 mp->pid, mp->address /* addr, in net byte order */ ,
6447 vpe_resolver_process_node.index,
6448 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6452 rv = vnet_add_del_ip6_nd_change_event
6453 (vnm, nd_change_delete_callback,
6454 mp->pid, mp->address /* addr, in net byte order */ ,
6455 vpe_resolver_process_node.index,
6456 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6458 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6461 static void vl_api_input_acl_set_interface_t_handler
6462 (vl_api_input_acl_set_interface_t * mp)
6464 vlib_main_t *vm = vlib_get_main ();
6465 vl_api_input_acl_set_interface_reply_t *rmp;
6467 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6469 ip4_table_index = ntohl (mp->ip4_table_index);
6470 ip6_table_index = ntohl (mp->ip6_table_index);
6471 l2_table_index = ntohl (mp->l2_table_index);
6472 sw_if_index = ntohl (mp->sw_if_index);
6474 VALIDATE_SW_IF_INDEX (mp);
6476 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6477 ip6_table_index, l2_table_index, mp->is_add);
6479 BAD_SW_IF_INDEX_LABEL;
6481 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6484 static void vl_api_ipsec_spd_add_del_t_handler
6485 (vl_api_ipsec_spd_add_del_t * mp)
6488 clib_warning ("unimplemented");
6491 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6492 vl_api_ipsec_spd_add_del_reply_t *rmp;
6496 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6498 rv = VNET_API_ERROR_UNIMPLEMENTED;
6501 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6505 static void vl_api_ipsec_interface_add_del_spd_t_handler
6506 (vl_api_ipsec_interface_add_del_spd_t * mp)
6508 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6509 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6511 u32 sw_if_index __attribute__ ((unused));
6512 u32 spd_id __attribute__ ((unused));
6514 sw_if_index = ntohl (mp->sw_if_index);
6515 spd_id = ntohl (mp->spd_id);
6517 VALIDATE_SW_IF_INDEX (mp);
6520 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6522 rv = VNET_API_ERROR_UNIMPLEMENTED;
6525 BAD_SW_IF_INDEX_LABEL;
6527 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6530 static void vl_api_ipsec_spd_add_del_entry_t_handler
6531 (vl_api_ipsec_spd_add_del_entry_t * mp)
6533 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6534 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6540 memset (&p, 0, sizeof (p));
6542 p.id = ntohl (mp->spd_id);
6543 p.priority = ntohl (mp->priority);
6544 p.is_outbound = mp->is_outbound;
6545 p.is_ipv6 = mp->is_ipv6;
6547 if (mp->is_ipv6 || mp->is_ip_any)
6549 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6550 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6551 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6552 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6556 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6557 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6558 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6559 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6561 p.protocol = mp->protocol;
6562 p.rport.start = ntohs (mp->remote_port_start);
6563 p.rport.stop = ntohs (mp->remote_port_stop);
6564 p.lport.start = ntohs (mp->local_port_start);
6565 p.lport.stop = ntohs (mp->local_port_stop);
6566 /* policy action resolve unsupported */
6567 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6569 clib_warning ("unsupported action: 'resolve'");
6570 rv = VNET_API_ERROR_UNIMPLEMENTED;
6573 p.policy = mp->policy;
6574 p.sa_id = ntohl (mp->sa_id);
6576 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6583 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6586 rv = VNET_API_ERROR_UNIMPLEMENTED;
6591 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6594 static void vl_api_ipsec_sad_add_del_entry_t_handler
6595 (vl_api_ipsec_sad_add_del_entry_t * mp)
6597 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6598 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6603 memset (&sa, 0, sizeof (sa));
6605 sa.id = ntohl (mp->sad_id);
6606 sa.spi = ntohl (mp->spi);
6607 /* security protocol AH unsupported */
6608 if (mp->protocol == IPSEC_PROTOCOL_AH)
6610 clib_warning ("unsupported security protocol 'AH'");
6611 rv = VNET_API_ERROR_UNIMPLEMENTED;
6614 sa.protocol = mp->protocol;
6615 /* check for unsupported crypto-alg */
6616 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6617 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6619 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6620 mp->crypto_algorithm);
6621 rv = VNET_API_ERROR_UNIMPLEMENTED;
6624 sa.crypto_alg = mp->crypto_algorithm;
6625 sa.crypto_key_len = mp->crypto_key_length;
6626 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6627 /* check for unsupported integ-alg */
6628 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6629 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6631 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6632 mp->integrity_algorithm);
6633 rv = VNET_API_ERROR_UNIMPLEMENTED;
6636 sa.integ_alg = mp->integrity_algorithm;
6637 sa.integ_key_len = mp->integrity_key_length;
6638 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6639 sa.use_esn = mp->use_extended_sequence_number;
6640 sa.is_tunnel = mp->is_tunnel;
6641 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6642 if (sa.is_tunnel_ip6)
6644 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6645 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6649 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6650 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6653 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6655 rv = VNET_API_ERROR_UNIMPLEMENTED;
6660 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6664 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6666 vl_api_ikev2_profile_add_del_reply_t *rmp;
6670 vlib_main_t *vm = vlib_get_main ();
6671 clib_error_t *error;
6672 u8 *tmp = format (0, "%s", mp->name);
6673 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6676 rv = VNET_API_ERROR_UNSPECIFIED;
6678 rv = VNET_API_ERROR_UNIMPLEMENTED;
6681 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6685 vl_api_ikev2_profile_set_auth_t_handler
6686 (vl_api_ikev2_profile_set_auth_t * mp)
6688 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6692 vlib_main_t *vm = vlib_get_main ();
6693 clib_error_t *error;
6694 u8 *tmp = format (0, "%s", mp->name);
6695 u8 *data = vec_new (u8, mp->data_len);
6696 clib_memcpy (data, mp->data, mp->data_len);
6697 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6701 rv = VNET_API_ERROR_UNSPECIFIED;
6703 rv = VNET_API_ERROR_UNIMPLEMENTED;
6706 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6710 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6712 vl_api_ikev2_profile_add_del_reply_t *rmp;
6716 vlib_main_t *vm = vlib_get_main ();
6717 clib_error_t *error;
6718 u8 *tmp = format (0, "%s", mp->name);
6719 u8 *data = vec_new (u8, mp->data_len);
6720 clib_memcpy (data, mp->data, mp->data_len);
6721 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6725 rv = VNET_API_ERROR_UNSPECIFIED;
6727 rv = VNET_API_ERROR_UNIMPLEMENTED;
6730 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6734 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6736 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6740 vlib_main_t *vm = vlib_get_main ();
6741 clib_error_t *error;
6742 u8 *tmp = format (0, "%s", mp->name);
6743 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6744 mp->end_port, (ip4_address_t) mp->start_addr,
6745 (ip4_address_t) mp->end_addr, mp->is_local);
6748 rv = VNET_API_ERROR_UNSPECIFIED;
6750 rv = VNET_API_ERROR_UNIMPLEMENTED;
6753 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6757 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6759 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6763 vlib_main_t *vm = vlib_get_main ();
6764 clib_error_t *error;
6766 error = ikev2_set_local_key (vm, mp->key_file);
6768 rv = VNET_API_ERROR_UNSPECIFIED;
6770 rv = VNET_API_ERROR_UNIMPLEMENTED;
6773 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6777 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6779 vl_api_map_add_domain_reply_t *rmp;
6782 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6784 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6785 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6786 (ip6_address_t *) & mp->ip6_src,
6787 mp->ip6_src_prefix_len, mp->ea_bits_len,
6788 mp->psid_offset, mp->psid_length, &index,
6789 ntohs (mp->mtu), flags);
6792 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6794 rmp->index = ntohl(index);
6800 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6802 vl_api_map_del_domain_reply_t *rmp;
6805 rv = map_delete_domain (ntohl (mp->index));
6807 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6811 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6813 vl_api_map_del_domain_reply_t *rmp;
6817 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6818 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6820 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6824 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6826 vl_api_map_domain_details_t *rmp;
6827 map_main_t *mm = &map_main;
6829 unix_shared_memory_queue_t *q;
6831 if (pool_elts (mm->domains) == 0)
6834 q = vl_api_client_index_to_input_queue (mp->client_index);
6841 pool_foreach(d, mm->domains,
6843 /* Make sure every field is initiated (or don't skip the memset()) */
6844 rmp = vl_msg_api_alloc (sizeof (*rmp));
6845 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6846 rmp->domain_index = htonl(d - mm->domains);
6847 rmp->ea_bits_len = d->ea_bits_len;
6848 rmp->psid_offset = d->psid_offset;
6849 rmp->psid_length = d->psid_length;
6850 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6851 rmp->ip4_prefix_len = d->ip4_prefix_len;
6852 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6853 rmp->ip6_prefix_len = d->ip6_prefix_len;
6854 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6855 rmp->ip6_src_len = d->ip6_src_len;
6856 rmp->mtu = htons(d->mtu);
6857 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6858 rmp->context = mp->context;
6860 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6866 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6868 unix_shared_memory_queue_t *q;
6871 vl_api_map_rule_details_t *rmp;
6872 map_main_t *mm = &map_main;
6873 u32 domain_index = ntohl (mp->domain_index);
6876 if (pool_elts (mm->domains) == 0)
6879 d = pool_elt_at_index (mm->domains, domain_index);
6880 if (!d || !d->rules)
6885 q = vl_api_client_index_to_input_queue (mp->client_index);
6891 for (i = 0; i < (0x1 << d->psid_length); i++)
6894 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6898 rmp = vl_msg_api_alloc (sizeof (*rmp));
6899 memset (rmp, 0, sizeof (*rmp));
6900 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6901 rmp->psid = htons (i);
6902 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6903 rmp->context = mp->context;
6904 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6909 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6911 vl_api_map_summary_stats_reply_t *rmp;
6912 vlib_combined_counter_main_t *cm;
6915 u64 total_pkts[VLIB_N_RX_TX];
6916 u64 total_bytes[VLIB_N_RX_TX];
6917 map_main_t *mm = &map_main;
6918 unix_shared_memory_queue_t *q =
6919 vl_api_client_index_to_input_queue (mp->client_index);
6924 rmp = vl_msg_api_alloc (sizeof (*rmp));
6925 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6926 rmp->context = mp->context;
6929 memset (total_pkts, 0, sizeof (total_pkts));
6930 memset (total_bytes, 0, sizeof (total_bytes));
6932 map_domain_counter_lock (mm);
6933 vec_foreach (cm, mm->domain_counters)
6935 which = cm - mm->domain_counters;
6937 for (i = 0; i < vec_len (cm->maxi); i++)
6939 vlib_get_combined_counter (cm, i, &v);
6940 total_pkts[which] += v.packets;
6941 total_bytes[which] += v.bytes;
6945 map_domain_counter_unlock (mm);
6947 /* Note: in network byte order! */
6948 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6949 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6950 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6951 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6952 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6953 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6954 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6955 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6956 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6957 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6958 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6959 clib_host_to_net_u64 (map_error_counter_get
6960 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6961 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6962 clib_host_to_net_u64 (map_error_counter_get
6963 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6965 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6969 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6971 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6972 vl_api_ipsec_sa_set_key_reply_t *rmp;
6976 sa.id = ntohl (mp->sa_id);
6977 sa.crypto_key_len = mp->crypto_key_length;
6978 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6979 sa.integ_key_len = mp->integrity_key_length;
6980 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6982 rv = ipsec_set_sa_key (vm, &sa);
6984 rv = VNET_API_ERROR_UNIMPLEMENTED;
6987 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6990 static void vl_api_cop_interface_enable_disable_t_handler
6991 (vl_api_cop_interface_enable_disable_t * mp)
6993 vl_api_cop_interface_enable_disable_reply_t *rmp;
6995 u32 sw_if_index = ntohl (mp->sw_if_index);
6998 VALIDATE_SW_IF_INDEX (mp);
7000 enable_disable = (int) mp->enable_disable;
7002 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
7004 BAD_SW_IF_INDEX_LABEL;
7006 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
7009 static void vl_api_cop_whitelist_enable_disable_t_handler
7010 (vl_api_cop_whitelist_enable_disable_t * mp)
7012 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
7013 cop_whitelist_enable_disable_args_t _a, *a = &_a;
7014 u32 sw_if_index = ntohl (mp->sw_if_index);
7017 VALIDATE_SW_IF_INDEX (mp);
7019 a->sw_if_index = sw_if_index;
7022 a->default_cop = mp->default_cop;
7023 a->fib_id = ntohl (mp->fib_id);
7025 rv = cop_whitelist_enable_disable (a);
7027 BAD_SW_IF_INDEX_LABEL;
7029 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
7033 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
7037 api_main_t *am = &api_main;
7038 vlib_main_t *vm = vlib_get_main ();
7040 vl_api_get_node_graph_reply_t *rmp;
7042 pthread_mutex_lock (&am->vlib_rp->mutex);
7043 oldheap = svm_push_data_heap (am->vlib_rp);
7046 * Keep the number of memcpy ops to a minimum (e.g. 1).
7048 vec_validate (vector, 16384);
7049 vec_reset_length (vector);
7052 vector = vlib_node_serialize (&vm->node_main, vector,
7053 (u32) ~ 0 /* all threads */ ,
7054 1 /* include nexts */ ,
7055 1 /* include stats */ );
7057 svm_pop_heap (oldheap);
7058 pthread_mutex_unlock (&am->vlib_rp->mutex);
7061 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
7063 rmp->reply_in_shmem = (uword) vector;
7069 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
7072 vl_api_ioam_enable_reply_t *rmp;
7073 clib_error_t *error;
7075 /* Ignoring the profile id as currently a single profile
7077 error = ip6_ioam_enable (mp->trace_enable, mp->pow_enable, mp->trace_ppc);
7080 clib_error_report (error);
7081 rv = clib_error_get_code (error);
7084 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
7088 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
7091 vl_api_ioam_disable_reply_t *rmp;
7092 clib_error_t *error;
7094 error = clear_ioam_rewrite_fn ();
7097 clib_error_report (error);
7098 rv = clib_error_get_code (error);
7101 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
7105 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7107 vlib_main_t *vm = vlib_get_main ();
7108 vl_api_af_packet_create_reply_t *rmp;
7110 u8 *host_if_name = NULL;
7113 host_if_name = format (0, "%s", mp->host_if_name);
7114 vec_add1 (host_if_name, 0);
7116 rv = af_packet_create_if (vm, host_if_name,
7117 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7120 vec_free (host_if_name);
7123 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7125 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7131 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7133 vlib_main_t *vm = vlib_get_main ();
7134 vl_api_af_packet_delete_reply_t *rmp;
7136 u8 *host_if_name = NULL;
7138 host_if_name = format (0, "%s", mp->host_if_name);
7139 vec_add1 (host_if_name, 0);
7141 rv = af_packet_delete_if (vm, host_if_name);
7143 vec_free (host_if_name);
7145 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7149 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7151 vlib_main_t *vm = vlib_get_main ();
7152 vl_api_policer_add_del_reply_t *rmp;
7155 sse2_qos_pol_cfg_params_st cfg;
7156 clib_error_t *error;
7159 name = format (0, "%s", mp->name);
7161 memset (&cfg, 0, sizeof (cfg));
7163 cfg.rnd_type = mp->round_type;
7164 cfg.rate_type = mp->rate_type;
7165 cfg.rb.kbps.cir_kbps = mp->cir;
7166 cfg.rb.kbps.eir_kbps = mp->eir;
7167 cfg.rb.kbps.cb_bytes = mp->cb;
7168 cfg.rb.kbps.eb_bytes = mp->eb;
7169 cfg.conform_action.action_type = mp->conform_action_type;
7170 cfg.conform_action.dscp = mp->conform_dscp;
7171 cfg.exceed_action.action_type = mp->exceed_action_type;
7172 cfg.exceed_action.dscp = mp->exceed_dscp;
7173 cfg.violate_action.action_type = mp->violate_action_type;
7174 cfg.violate_action.dscp = mp->violate_dscp;
7175 cfg.color_aware = mp->color_aware;
7177 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7180 rv = VNET_API_ERROR_UNSPECIFIED;
7183 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7185 if (rv == 0 && mp->is_add)
7186 rmp->policer_index = ntohl(policer_index);
7188 rmp->policer_index = ~0;
7194 send_policer_details (u8 * name,
7195 sse2_qos_pol_cfg_params_st * config,
7196 policer_read_response_type_st * templ,
7197 unix_shared_memory_queue_t * q, u32 context)
7199 vl_api_policer_details_t *mp;
7201 mp = vl_msg_api_alloc (sizeof (*mp));
7202 memset (mp, 0, sizeof (*mp));
7203 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7204 mp->context = context;
7205 mp->cir = htonl (config->rb.kbps.cir_kbps);
7206 mp->eir = htonl (config->rb.kbps.eir_kbps);
7207 mp->cb = htonl (config->rb.kbps.cb_bytes);
7208 mp->eb = htonl (config->rb.kbps.eb_bytes);
7209 mp->rate_type = config->rate_type;
7210 mp->round_type = config->rnd_type;
7211 mp->type = config->rfc;
7212 mp->conform_action_type = config->conform_action.action_type;
7213 mp->conform_dscp = config->conform_action.dscp;
7214 mp->exceed_action_type = config->exceed_action.action_type;
7215 mp->exceed_dscp = config->exceed_action.dscp;
7216 mp->violate_action_type = config->violate_action.action_type;
7217 mp->violate_dscp = config->violate_action.dscp;
7218 mp->single_rate = templ->single_rate ? 1 : 0;
7219 mp->color_aware = templ->color_aware ? 1 : 0;
7220 mp->scale = htonl (templ->scale);
7221 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7222 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7223 mp->current_limit = htonl (templ->current_limit);
7224 mp->current_bucket = htonl (templ->current_bucket);
7225 mp->extended_limit = htonl (templ->extended_limit);
7226 mp->extended_bucket = htonl (templ->extended_bucket);
7227 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7229 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7231 vl_msg_api_send_shmem (q, (u8 *) & mp);
7235 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7237 unix_shared_memory_queue_t *q;
7238 vnet_policer_main_t *pm = &vnet_policer_main;
7244 sse2_qos_pol_cfg_params_st *config;
7245 policer_read_response_type_st *templ;
7247 q = vl_api_client_index_to_input_queue (mp->client_index);
7251 if (mp->match_name_valid)
7253 match_name = format (0, "%s%c", mp->match_name, 0);
7256 if (mp->match_name_valid)
7258 p = hash_get_mem (pm->policer_config_by_name, match_name);
7262 config = pool_elt_at_index (pm->configs, pool_index);
7263 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7264 send_policer_details (match_name, config, templ, q, mp->context);
7270 hash_foreach_pair (hp, pm->policer_config_by_name,
7272 name = (u8 *) hp->key;
7273 pool_index = hp->value[0];
7274 config = pool_elt_at_index (pm->configs, pool_index);
7275 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7276 send_policer_details(name, config, templ, q, mp->context);
7283 vl_api_policer_classify_set_interface_t_handler
7284 (vl_api_policer_classify_set_interface_t * mp)
7286 vlib_main_t *vm = vlib_get_main ();
7287 vl_api_policer_classify_set_interface_reply_t *rmp;
7289 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7291 ip4_table_index = ntohl (mp->ip4_table_index);
7292 ip6_table_index = ntohl (mp->ip6_table_index);
7293 l2_table_index = ntohl (mp->l2_table_index);
7294 sw_if_index = ntohl (mp->sw_if_index);
7296 VALIDATE_SW_IF_INDEX (mp);
7298 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7299 ip6_table_index, l2_table_index,
7302 BAD_SW_IF_INDEX_LABEL;
7304 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7308 send_policer_classify_details (u32 sw_if_index,
7310 unix_shared_memory_queue_t * q, u32 context)
7312 vl_api_policer_classify_details_t *mp;
7314 mp = vl_msg_api_alloc (sizeof (*mp));
7315 memset (mp, 0, sizeof (*mp));
7316 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7317 mp->context = context;
7318 mp->sw_if_index = htonl (sw_if_index);
7319 mp->table_index = htonl (table_index);
7321 vl_msg_api_send_shmem (q, (u8 *) & mp);
7325 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7327 unix_shared_memory_queue_t *q;
7328 policer_classify_main_t *pcm = &policer_classify_main;
7332 q = vl_api_client_index_to_input_queue (mp->client_index);
7336 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7338 if (vec_len (vec_tbl))
7340 for (i = 0; i < vec_len (vec_tbl); i++)
7342 if (vec_elt (vec_tbl, i) == ~0)
7345 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7352 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7354 vlib_main_t *vm = vlib_get_main ();
7355 vl_api_netmap_create_reply_t *rmp;
7359 if_name = format (0, "%s", mp->netmap_if_name);
7360 vec_add1 (if_name, 0);
7363 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7364 mp->is_pipe, mp->is_master, 0);
7368 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7372 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7374 vlib_main_t *vm = vlib_get_main ();
7375 vl_api_netmap_delete_reply_t *rmp;
7379 if_name = format (0, "%s", mp->netmap_if_name);
7380 vec_add1 (if_name, 0);
7382 rv = netmap_delete_if (vm, if_name);
7386 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7390 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7393 clib_warning ("BUG");
7397 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7398 unix_shared_memory_queue_t * q,
7399 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7401 vl_api_mpls_gre_tunnel_details_t *mp;
7402 mpls_main_t *mm = &mpls_main;
7407 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7408 nlabels = vec_len (e->labels);
7410 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7411 memset (mp, 0, sizeof (*mp));
7412 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7413 mp->context = context;
7415 mp->tunnel_index = htonl (index);
7416 mp->tunnel_src = gt->tunnel_src.as_u32;
7417 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7418 mp->intfc_address = gt->intfc_address.as_u32;
7419 mp->mask_width = htonl (gt->mask_width);
7420 mp->inner_fib_index = htonl (gt->inner_fib_index);
7421 mp->outer_fib_index = htonl (gt->outer_fib_index);
7422 mp->encap_index = htonl (gt->encap_index);
7423 mp->hw_if_index = htonl (gt->hw_if_index);
7424 mp->l2_only = htonl (gt->l2_only);
7425 mp->nlabels = htonl (nlabels);
7427 for (i = 0; i < nlabels; i++)
7430 htonl (vnet_mpls_uc_get_label
7431 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7434 vl_msg_api_send_shmem (q, (u8 *) & mp);
7438 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7440 vpe_api_main_t *am = &vpe_api_main;
7441 unix_shared_memory_queue_t *q;
7442 mpls_main_t *mm = &mpls_main;
7443 mpls_gre_tunnel_t *gt;
7444 u32 index = ntohl (mp->tunnel_index);
7446 q = vl_api_client_index_to_input_queue (mp->client_index);
7452 if (!pool_is_free_index (mm->gre_tunnels, index))
7454 gt = pool_elt_at_index (mm->gre_tunnels, index);
7455 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7462 pool_foreach (gt, mm->gre_tunnels,
7464 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7472 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7475 clib_warning ("BUG");
7479 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7480 unix_shared_memory_queue_t * q,
7481 mpls_eth_tunnel_t * et, u32 index, u32 context)
7483 mpls_main_t *mm = &mpls_main;
7487 vl_api_mpls_eth_tunnel_details_t *mp;
7489 e = pool_elt_at_index (mm->encaps, et->encap_index);
7490 nlabels = vec_len (e->labels);
7492 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7493 memset (mp, 0, sizeof (*mp));
7494 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7495 mp->context = context;
7497 mp->tunnel_index = htonl (index);
7498 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7499 mp->intfc_address = et->intfc_address.as_u32;
7500 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7501 mp->inner_fib_index = htonl (et->inner_fib_index);
7502 mp->mask_width = htonl (et->mask_width);
7503 mp->encap_index = htonl (et->encap_index);
7504 mp->hw_if_index = htonl (et->hw_if_index);
7505 mp->l2_only = htonl (et->l2_only);
7506 mp->nlabels = htonl (nlabels);
7508 for (i = 0; i < nlabels; i++)
7511 htonl (vnet_mpls_uc_get_label
7512 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7515 vl_msg_api_send_shmem (q, (u8 *) & mp);
7519 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7521 vpe_api_main_t *am = &vpe_api_main;
7522 unix_shared_memory_queue_t *q;
7523 mpls_main_t *mm = &mpls_main;
7524 mpls_eth_tunnel_t *et;
7525 u32 index = ntohl (mp->tunnel_index);
7527 q = vl_api_client_index_to_input_queue (mp->client_index);
7533 if (!pool_is_free_index (mm->eth_tunnels, index))
7535 et = pool_elt_at_index (mm->eth_tunnels, index);
7536 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7543 pool_foreach (et, mm->eth_tunnels,
7545 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7553 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7555 clib_warning ("BUG");
7559 send_mpls_fib_encap_details (vpe_api_main_t * am,
7560 unix_shared_memory_queue_t * q,
7561 show_mpls_fib_t * s, u32 context)
7563 vl_api_mpls_fib_encap_details_t *mp;
7564 mpls_main_t *mm = &mpls_main;
7569 e = pool_elt_at_index (mm->encaps, s->entry_index);
7570 nlabels = vec_len (e->labels);
7572 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7573 memset (mp, 0, sizeof (*mp));
7574 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7575 mp->context = context;
7577 mp->fib_index = htonl (s->fib_index);
7578 mp->entry_index = htonl (s->entry_index);
7580 mp->s_bit = htonl (s->s_bit);
7582 mp->nlabels = htonl (nlabels);
7584 for (i = 0; i < nlabels; i++)
7587 htonl (vnet_mpls_uc_get_label
7588 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7591 vl_msg_api_send_shmem (q, (u8 *) & mp);
7595 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7597 vpe_api_main_t *am = &vpe_api_main;
7598 unix_shared_memory_queue_t *q;
7599 vlib_main_t *vm = &vlib_global_main;
7602 show_mpls_fib_t *records = 0;
7604 mpls_main_t *mm = &mpls_main;
7607 q = vl_api_client_index_to_input_queue (mp->client_index);
7612 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7614 vec_add2 (records, s, 1);
7615 s->fib_index = (u32)(key>>32);
7616 s->dest = (u32)(key & 0xFFFFFFFF);
7617 s->entry_index = (u32) value;
7621 if (0 == vec_len (records))
7623 vlib_cli_output (vm, "MPLS encap table empty");
7627 /* sort output by dst address within fib */
7628 vec_sort_with_function (records, mpls_dest_cmp);
7629 vec_sort_with_function (records, mpls_fib_index_cmp);
7630 vlib_cli_output (vm, "MPLS encap table");
7631 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7632 vec_foreach (s, records)
7634 rx_fib = ip4_fib_get (s->fib_index);
7635 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7636 format_ip4_address, &s->dest, format_mpls_encap_index,
7637 mm, s->entry_index);
7638 send_mpls_fib_encap_details (am, q, s, mp->context);
7646 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7648 clib_warning ("BUG");
7652 send_mpls_fib_decap_details (vpe_api_main_t * am,
7653 unix_shared_memory_queue_t * q,
7654 show_mpls_fib_t * s,
7656 u32 tx_table_id, char *swif_tag, u32 context)
7658 vl_api_mpls_fib_decap_details_t *mp;
7660 mp = vl_msg_api_alloc (sizeof (*mp));
7661 memset (mp, 0, sizeof (*mp));
7662 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7663 mp->context = context;
7665 mp->fib_index = htonl (s->fib_index);
7666 mp->entry_index = htonl (s->entry_index);
7668 mp->s_bit = htonl (s->s_bit);
7669 mp->label = htonl (s->label);
7670 mp->rx_table_id = htonl (rx_table_id);
7671 mp->tx_table_id = htonl (tx_table_id);
7672 strncpy ((char *) mp->swif_tag,
7673 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7675 vl_msg_api_send_shmem (q, (u8 *) & mp);
7679 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7681 vpe_api_main_t *am = &vpe_api_main;
7682 unix_shared_memory_queue_t *q;
7683 vlib_main_t *vm = &vlib_global_main;
7686 show_mpls_fib_t *records = 0;
7688 mpls_main_t *mm = &mpls_main;
7694 q = vl_api_client_index_to_input_queue (mp->client_index);
7699 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7701 vec_add2 (records, s, 1);
7702 s->fib_index = (u32)(key>>32);
7703 s->entry_index = (u32) value;
7704 s->label = ((u32) key)>>12;
7705 s->s_bit = (key & (1<<8)) != 0;
7709 if (!vec_len (records))
7711 vlib_cli_output (vm, "MPLS decap table empty");
7715 vec_sort_with_function (records, mpls_label_cmp);
7716 vlib_cli_output (vm, "MPLS decap table");
7717 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7719 vec_foreach (s, records)
7722 d = pool_elt_at_index (mm->decaps, s->entry_index);
7723 if (d->next_index == MPLS_LOOKUP_NEXT_IP4_INPUT)
7725 tx_fib = ip4_fib_get (d->tx_fib_index);
7726 tx_table_id = tx_fib->table_id;
7731 tx_table_id = d->tx_fib_index;
7734 rx_fib = ip4_fib_get (s->fib_index);
7736 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7737 tx_table_id, swif_tag, s->label, s->s_bit);
7739 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7740 tx_table_id, swif_tag, mp->context);
7748 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7750 unix_shared_memory_queue_t *q;
7752 q = vl_api_client_index_to_input_queue (mp->client_index);
7756 vnet_classify_main_t *cm = &vnet_classify_main;
7757 vnet_classify_table_t *t;
7762 pool_foreach (t, cm->tables,
7764 vec_add1 (table_ids, ntohl(t - cm->tables));
7767 count = vec_len (table_ids);
7769 vl_api_classify_table_ids_reply_t *rmp;
7770 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7771 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7772 rmp->context = mp->context;
7773 rmp->count = ntohl (count);
7774 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7777 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7779 vec_free (table_ids);
7783 vl_api_classify_table_by_interface_t_handler
7784 (vl_api_classify_table_by_interface_t * mp)
7786 vl_api_classify_table_by_interface_reply_t *rmp;
7789 u32 sw_if_index = ntohl (mp->sw_if_index);
7792 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7795 VALIDATE_SW_IF_INDEX (mp);
7797 input_acl_main_t *am = &input_acl_main;
7802 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7804 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7805 if (vec_len (vec_tbl))
7807 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7809 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7813 acl[type] = vec_elt (vec_tbl, if_idx);
7818 BAD_SW_IF_INDEX_LABEL;
7821 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7823 rmp->sw_if_index = ntohl(sw_if_index);
7824 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7825 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7826 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7833 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7835 unix_shared_memory_queue_t *q;
7837 q = vl_api_client_index_to_input_queue (mp->client_index);
7841 vl_api_classify_table_info_reply_t *rmp = 0;
7843 vnet_classify_main_t *cm = &vnet_classify_main;
7844 u32 table_id = ntohl (mp->table_id);
7845 vnet_classify_table_t *t;
7848 pool_foreach (t, cm->tables,
7850 if (table_id == t - cm->tables)
7852 rmp = vl_msg_api_alloc_as_if_client
7853 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7854 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7855 rmp->context = mp->context;
7856 rmp->table_id = ntohl(table_id);
7857 rmp->nbuckets = ntohl(t->nbuckets);
7858 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7859 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7860 rmp->active_sessions = ntohl(t->active_elements);
7861 rmp->next_table_index = ntohl(t->next_table_index);
7862 rmp->miss_next_index = ntohl(t->miss_next_index);
7863 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7864 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7873 rmp = vl_msg_api_alloc (sizeof (*rmp));
7874 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7875 rmp->context = mp->context;
7876 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7879 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7883 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7886 clib_warning ("BUG");
7890 send_classify_session_details (unix_shared_memory_queue_t * q,
7893 vnet_classify_entry_t * e, u32 context)
7895 vl_api_classify_session_details_t *rmp;
7897 rmp = vl_msg_api_alloc (sizeof (*rmp));
7898 memset (rmp, 0, sizeof (*rmp));
7899 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7900 rmp->context = context;
7901 rmp->table_id = ntohl (table_id);
7902 rmp->hit_next_index = ntohl (e->next_index);
7903 rmp->advance = ntohl (e->advance);
7904 rmp->opaque_index = ntohl (e->opaque_index);
7905 rmp->match_length = ntohl (match_length);
7906 clib_memcpy (rmp->match, e->key, match_length);
7908 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7912 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7914 vnet_classify_main_t *cm = &vnet_classify_main;
7915 unix_shared_memory_queue_t *q;
7917 u32 table_id = ntohl (mp->table_id);
7918 vnet_classify_table_t *t;
7920 q = vl_api_client_index_to_input_queue (mp->client_index);
7925 pool_foreach (t, cm->tables,
7927 if (table_id == t - cm->tables)
7929 vnet_classify_bucket_t * b;
7930 vnet_classify_entry_t * v, * save_v;
7933 for (i = 0; i < t->nbuckets; i++)
7935 b = &t->buckets [i];
7939 save_v = vnet_classify_get_entry (t, b->offset);
7940 for (j = 0; j < (1<<b->log2_pages); j++)
7942 for (k = 0; k < t->entries_per_page; k++)
7944 v = vnet_classify_entry_at_index
7945 (t, save_v, j*t->entries_per_page + k);
7946 if (vnet_classify_entry_is_free (v))
7949 send_classify_session_details
7950 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7962 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7964 vlib_main_t *vm = vlib_get_main ();
7965 flow_report_main_t *frm = &flow_report_main;
7966 vl_api_set_ipfix_exporter_reply_t *rmp;
7967 ip4_address_t collector, src;
7968 u16 collector_port = UDP_DST_PORT_ipfix;
7970 u32 template_interval;
7976 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7977 collector_port = ntohs (mp->collector_port);
7978 if (collector_port == (u16) ~ 0)
7979 collector_port = UDP_DST_PORT_ipfix;
7980 memcpy (src.data, mp->src_address, sizeof (src.data));
7981 fib_id = ntohl (mp->vrf_id);
7983 ip4_main_t *im = &ip4_main;
7990 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7993 rv = VNET_API_ERROR_NO_SUCH_FIB;
7999 path_mtu = ntohl (mp->path_mtu);
8001 path_mtu = 512; // RFC 7011 section 10.3.3.
8002 template_interval = ntohl (mp->template_interval);
8003 if (template_interval == ~0)
8004 template_interval = 20;
8005 udp_checksum = mp->udp_checksum;
8007 if (collector.as_u32 == 0)
8009 rv = VNET_API_ERROR_INVALID_VALUE;
8013 if (src.as_u32 == 0)
8015 rv = VNET_API_ERROR_INVALID_VALUE;
8019 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
8021 rv = VNET_API_ERROR_INVALID_VALUE;
8027 rv = VNET_API_ERROR_INVALID_VALUE;
8031 /* Reset report streams if we are reconfiguring IP addresses */
8032 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
8033 frm->src_address.as_u32 != src.as_u32 ||
8034 frm->collector_port != collector_port)
8035 vnet_flow_reports_reset (frm);
8037 frm->ipfix_collector.as_u32 = collector.as_u32;
8038 frm->collector_port = collector_port;
8039 frm->src_address.as_u32 = src.as_u32;
8040 frm->fib_index = fib_index;
8041 frm->path_mtu = path_mtu;
8042 frm->template_interval = template_interval;
8043 frm->udp_checksum = udp_checksum;
8045 /* Turn on the flow reporting process */
8046 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
8049 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
8053 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
8055 flow_report_main_t *frm = &flow_report_main;
8056 unix_shared_memory_queue_t *q;
8057 vl_api_ipfix_exporter_details_t *rmp;
8058 ip4_main_t *im = &ip4_main;
8061 q = vl_api_client_index_to_input_queue (mp->client_index);
8065 rmp = vl_msg_api_alloc (sizeof (*rmp));
8066 memset (rmp, 0, sizeof (*rmp));
8067 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
8068 rmp->context = mp->context;
8069 memcpy (rmp->collector_address, frm->ipfix_collector.data,
8070 sizeof (frm->ipfix_collector.data));
8071 rmp->collector_port = htons (frm->collector_port);
8072 memcpy (rmp->src_address, frm->src_address.data,
8073 sizeof (frm->src_address.data));
8074 if (frm->fib_index == ~0)
8077 vrf_id = im->fibs[frm->fib_index].ft_table_id;
8078 rmp->vrf_id = htonl (vrf_id);
8079 rmp->path_mtu = htonl (frm->path_mtu);
8080 rmp->template_interval = htonl (frm->template_interval);
8081 rmp->udp_checksum = (frm->udp_checksum != 0);
8083 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8087 vl_api_set_ipfix_classify_stream_t_handler
8088 (vl_api_set_ipfix_classify_stream_t * mp)
8090 vl_api_set_ipfix_classify_stream_reply_t *rmp;
8091 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8092 flow_report_main_t *frm = &flow_report_main;
8094 u32 src_port = UDP_DST_PORT_ipfix;
8097 domain_id = ntohl (mp->domain_id);
8098 src_port = ntohs (mp->src_port);
8100 if (fcm->src_port != 0 &&
8101 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
8103 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
8104 domain_id, (u16) src_port);
8108 fcm->domain_id = domain_id;
8109 fcm->src_port = (u16) src_port;
8111 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8115 vl_api_ipfix_classify_stream_dump_t_handler
8116 (vl_api_ipfix_classify_stream_dump_t * mp)
8118 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8119 unix_shared_memory_queue_t *q;
8120 vl_api_ipfix_classify_stream_details_t *rmp;
8122 q = vl_api_client_index_to_input_queue (mp->client_index);
8126 rmp = vl_msg_api_alloc (sizeof (*rmp));
8127 memset (rmp, 0, sizeof (*rmp));
8128 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
8129 rmp->context = mp->context;
8130 rmp->domain_id = htonl (fcm->domain_id);
8131 rmp->src_port = htons (fcm->src_port);
8133 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8137 vl_api_ipfix_classify_table_add_del_t_handler
8138 (vl_api_ipfix_classify_table_add_del_t * mp)
8140 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
8141 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8142 flow_report_main_t *frm = &flow_report_main;
8143 vnet_flow_report_add_del_args_t args;
8144 ipfix_classify_table_t *table;
8146 u32 classify_table_index;
8148 u8 transport_protocol;
8151 classify_table_index = ntohl (mp->table_id);
8152 ip_version = mp->ip_version;
8153 transport_protocol = mp->transport_protocol;
8154 is_add = mp->is_add;
8156 if (fcm->src_port == 0)
8158 /* call set_ipfix_classify_stream first */
8159 rv = VNET_API_ERROR_UNSPECIFIED;
8163 memset (&args, 0, sizeof (args));
8167 for (i = 0; i < vec_len (fcm->tables); i++)
8168 if (ipfix_classify_table_index_valid (i))
8169 if (fcm->tables[i].classify_table_index == classify_table_index)
8171 table = &fcm->tables[i];
8179 rv = VNET_API_ERROR_VALUE_EXIST;
8182 table = ipfix_classify_add_table ();
8183 table->classify_table_index = classify_table_index;
8189 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
8194 table->ip_version = ip_version;
8195 table->transport_protocol = transport_protocol;
8197 args.opaque.as_uword = table - fcm->tables;
8198 args.rewrite_callback = ipfix_classify_template_rewrite;
8199 args.flow_data_callback = ipfix_classify_send_flows;
8200 args.is_add = is_add;
8201 args.domain_id = fcm->domain_id;
8202 args.src_port = fcm->src_port;
8204 rv = vnet_flow_report_add_del (frm, &args);
8206 /* If deleting, or add failed */
8207 if (is_add == 0 || (rv && is_add))
8208 ipfix_classify_delete_table (table - fcm->tables);
8211 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8215 send_ipfix_classify_table_details (u32 table_index,
8216 unix_shared_memory_queue_t * q,
8219 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8220 vl_api_ipfix_classify_table_details_t *mp;
8222 ipfix_classify_table_t *table = &fcm->tables[table_index];
8224 mp = vl_msg_api_alloc (sizeof (*mp));
8225 memset (mp, 0, sizeof (*mp));
8226 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
8227 mp->context = context;
8228 mp->table_id = htonl (table->classify_table_index);
8229 mp->ip_version = table->ip_version;
8230 mp->transport_protocol = table->transport_protocol;
8232 vl_msg_api_send_shmem (q, (u8 *) & mp);
8236 vl_api_ipfix_classify_table_dump_t_handler
8237 (vl_api_ipfix_classify_table_dump_t * mp)
8239 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8240 unix_shared_memory_queue_t *q;
8243 q = vl_api_client_index_to_input_queue (mp->client_index);
8247 for (i = 0; i < vec_len (fcm->tables); i++)
8248 if (ipfix_classify_table_index_valid (i))
8249 send_ipfix_classify_table_details (i, q, mp->context);
8253 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8255 vl_api_pg_create_interface_reply_t *rmp;
8258 pg_main_t *pg = &pg_main;
8259 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8260 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
8263 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8265 rmp->sw_if_index = ntohl(pi->sw_if_index);
8271 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8273 vl_api_pg_capture_reply_t *rmp;
8276 vnet_main_t *vnm = vnet_get_main ();
8277 vnet_interface_main_t *im = &vnm->interface_main;
8278 vnet_hw_interface_t *hi = 0;
8280 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8281 u32 hw_if_index = ~0;
8282 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8285 vec_free (intf_name);
8287 if (hw_if_index != ~0)
8289 pg_capture_args_t _a, *a = &_a;
8291 u32 len = ntohl (mp->pcap_name_length);
8292 u8 *pcap_file_name = vec_new (u8, len);
8293 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8295 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8296 a->hw_if_index = hw_if_index;
8297 a->dev_instance = hi->dev_instance;
8298 a->is_enabled = mp->is_enabled;
8299 a->pcap_file_name = pcap_file_name;
8300 a->count = ntohl (mp->count);
8302 clib_error_t *e = pg_capture (a);
8305 clib_error_report (e);
8306 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8309 vec_free (pcap_file_name);
8311 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8315 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8317 vl_api_pg_enable_disable_reply_t *rmp;
8320 pg_main_t *pg = &pg_main;
8321 u32 stream_index = ~0;
8323 int is_enable = mp->is_enabled != 0;
8324 u32 len = ntohl (mp->stream_name_length) - 1;
8328 u8 *stream_name = vec_new (u8, len);
8329 clib_memcpy (stream_name, mp->stream_name, len);
8330 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8333 vec_free (stream_name);
8336 pg_enable_disable (stream_index, is_enable);
8338 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8342 vl_api_ip_source_and_port_range_check_add_del_t_handler
8343 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8345 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8348 u8 is_ipv6 = mp->is_ipv6;
8349 u8 is_add = mp->is_add;
8350 u8 mask_length = mp->mask_length;
8351 ip4_address_t ip4_addr;
8352 ip6_address_t ip6_addr;
8354 u16 *high_ports = 0;
8356 u16 tmp_low, tmp_high;
8360 // Validate port range
8361 num_ranges = mp->number_of_ranges;
8362 if (num_ranges > 32)
8363 { // This is size of array in VPE.API
8364 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8368 vec_reset_length (low_ports);
8369 vec_reset_length (high_ports);
8371 for (i = 0; i < num_ranges; i++)
8373 tmp_low = mp->low_ports[i];
8374 tmp_high = mp->high_ports[i];
8375 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8376 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8377 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8379 rv = VNET_API_ERROR_INVALID_VALUE;
8382 vec_add1 (low_ports, tmp_low);
8383 vec_add1 (high_ports, tmp_high + 1);
8386 // Validate mask_length
8387 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8389 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8393 vrf_id = ntohl (mp->vrf_id);
8397 rv = VNET_API_ERROR_INVALID_VALUE;
8404 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8405 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8409 high_ports, is_add);
8413 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8414 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8418 high_ports, is_add);
8422 vec_free (low_ports);
8423 vec_free (high_ports);
8424 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8428 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8429 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8431 vlib_main_t *vm = vlib_get_main ();
8432 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8433 ip4_main_t *im = &ip4_main;
8436 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8437 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8441 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8442 ntohl (mp->tcp_out_vrf_id);
8443 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8444 ntohl (mp->udp_out_vrf_id);
8445 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8446 ntohl (mp->tcp_in_vrf_id);
8447 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8448 ntohl (mp->udp_in_vrf_id);
8451 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8453 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8455 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8459 rv = VNET_API_ERROR_INVALID_VALUE;
8463 fib_index[i] = p[0];
8468 sw_if_index = ntohl (mp->sw_if_index);
8470 VALIDATE_SW_IF_INDEX (mp);
8473 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8476 BAD_SW_IF_INDEX_LABEL;
8479 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8483 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8486 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8488 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8489 u32 sw_if_index = ~0;
8491 /* Check src & dst are different */
8492 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8494 rv = VNET_API_ERROR_SAME_SRC_DST;
8498 memset (a, 0, sizeof (*a));
8500 /* ip addresses sent in network byte order */
8501 clib_memcpy (&(a->src), mp->src_address, 4);
8502 clib_memcpy (&(a->dst), mp->dst_address, 4);
8503 a->is_add = mp->is_add;
8504 a->lsa = ntohl (mp->local_sa_id);
8505 a->rsa = ntohl (mp->remote_sa_id);
8507 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8511 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8513 rmp->sw_if_index = ntohl (sw_if_index);
8518 static void send_ipsec_gre_tunnel_details
8519 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8521 vl_api_ipsec_gre_tunnel_details_t *rmp;
8523 rmp = vl_msg_api_alloc (sizeof (*rmp));
8524 memset (rmp, 0, sizeof (*rmp));
8525 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8526 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8527 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8528 rmp->sw_if_index = htonl (t->sw_if_index);
8529 rmp->local_sa_id = htonl (t->local_sa_id);
8530 rmp->remote_sa_id = htonl (t->remote_sa_id);
8531 rmp->context = context;
8533 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8536 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8537 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8539 unix_shared_memory_queue_t *q;
8540 ipsec_gre_main_t *igm = &ipsec_gre_main;
8541 ipsec_gre_tunnel_t *t;
8544 q = vl_api_client_index_to_input_queue (mp->client_index);
8550 sw_if_index = ntohl (mp->sw_if_index);
8552 if (~0 == sw_if_index)
8555 pool_foreach (t, igm->tunnels,
8557 send_ipsec_gre_tunnel_details(t, q, mp->context);
8563 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8564 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8568 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8569 send_ipsec_gre_tunnel_details (t, q, mp->context);
8574 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8576 vl_api_delete_subif_reply_t *rmp;
8579 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8581 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8585 vl_api_l2_interface_pbb_tag_rewrite_t_handler
8586 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
8588 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
8589 vnet_main_t *vnm = vnet_get_main ();
8590 vlib_main_t *vm = vlib_get_main ();
8594 VALIDATE_SW_IF_INDEX (mp);
8596 vtr_op = ntohl (mp->vtr_op);
8600 case L2_VTR_DISABLED:
8603 case L2_VTR_TRANSLATE_2_1:
8607 rv = VNET_API_ERROR_INVALID_VALUE;
8608 goto bad_sw_if_index;
8611 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
8612 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
8613 ntohl (mp->i_sid), ntohs (mp->outer_tag));
8615 BAD_SW_IF_INDEX_LABEL;
8617 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
8621 vl_api_punt_t_handler (vl_api_punt_t * mp)
8623 vl_api_punt_reply_t *rmp;
8624 vlib_main_t *vm = vlib_get_main ();
8626 clib_error_t *error;
8628 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8629 ntohs (mp->l4_port), mp->is_add);
8633 clib_error_report (error);
8636 REPLY_MACRO (VL_API_PUNT_REPLY);
8640 vl_api_flow_classify_set_interface_t_handler
8641 (vl_api_flow_classify_set_interface_t * mp)
8643 vlib_main_t *vm = vlib_get_main ();
8644 vl_api_flow_classify_set_interface_reply_t *rmp;
8646 u32 sw_if_index, ip4_table_index, ip6_table_index;
8648 ip4_table_index = ntohl (mp->ip4_table_index);
8649 ip6_table_index = ntohl (mp->ip6_table_index);
8650 sw_if_index = ntohl (mp->sw_if_index);
8652 VALIDATE_SW_IF_INDEX (mp);
8654 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
8655 ip6_table_index, mp->is_add);
8657 BAD_SW_IF_INDEX_LABEL;
8659 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
8663 send_flow_classify_details (u32 sw_if_index,
8665 unix_shared_memory_queue_t * q, u32 context)
8667 vl_api_flow_classify_details_t *mp;
8669 mp = vl_msg_api_alloc (sizeof (*mp));
8670 memset (mp, 0, sizeof (*mp));
8671 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
8672 mp->context = context;
8673 mp->sw_if_index = htonl (sw_if_index);
8674 mp->table_index = htonl (table_index);
8676 vl_msg_api_send_shmem (q, (u8 *) & mp);
8680 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8682 unix_shared_memory_queue_t *q;
8683 flow_classify_main_t *pcm = &flow_classify_main;
8687 q = vl_api_client_index_to_input_queue (mp->client_index);
8691 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8693 if (vec_len (vec_tbl))
8695 for (i = 0; i < vec_len (vec_tbl); i++)
8697 if (vec_elt (vec_tbl, i) == ~0)
8700 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8706 #define BOUNCE_HANDLER(nn) \
8707 static void vl_api_##nn##_t_handler ( \
8708 vl_api_##nn##_t *mp) \
8710 vpe_client_registration_t *reg; \
8711 vpe_api_main_t * vam = &vpe_api_main; \
8712 unix_shared_memory_queue_t * q; \
8714 /* One registration only... */ \
8715 pool_foreach(reg, vam->nn##_registrations, \
8717 q = vl_api_client_index_to_input_queue (reg->client_index); \
8720 * If the queue is stuffed, turf the msg and complain \
8721 * It's unlikely that the intended recipient is \
8722 * alive; avoid deadlock at all costs. \
8724 if (q->cursize == q->maxsize) { \
8725 clib_warning ("ERROR: receiver queue full, drop msg"); \
8726 vl_msg_api_free (mp); \
8729 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8733 vl_msg_api_free (mp); \
8738 * Add vpe's API message handlers to the table.
8739 * vlib has alread mapped shared memory and
8740 * added the client registration handlers.
8741 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8744 static clib_error_t *
8745 vpe_api_hookup (vlib_main_t * vm)
8747 api_main_t *am = &api_main;
8750 vl_msg_api_set_handlers(VL_API_##N, #n, \
8751 vl_api_##n##_t_handler, \
8753 vl_api_##n##_t_endian, \
8754 vl_api_##n##_t_print, \
8755 sizeof(vl_api_##n##_t), 1);
8756 foreach_vpe_api_msg;
8760 * Manually register the sr tunnel add del msg, so we trace
8761 * enough bytes to capture a typical segment list
8763 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8764 "sr_tunnel_add_del",
8765 vl_api_sr_tunnel_add_del_t_handler,
8767 vl_api_sr_tunnel_add_del_t_endian,
8768 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8772 * Manually register the sr policy add del msg, so we trace
8773 * enough bytes to capture a typical tunnel name list
8775 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8776 "sr_policy_add_del",
8777 vl_api_sr_policy_add_del_t_handler,
8779 vl_api_sr_policy_add_del_t_endian,
8780 vl_api_sr_policy_add_del_t_print, 256, 1);
8783 * Trace space for 8 MPLS encap labels, classifier mask+match
8785 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8786 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8787 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8788 += 5 * sizeof (u32x4);
8789 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8792 * Thread-safe API messages
8794 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8795 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8800 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8802 static clib_error_t *
8803 vpe_api_init (vlib_main_t * vm)
8805 vpe_api_main_t *am = &vpe_api_main;
8808 am->vnet_main = vnet_get_main ();
8809 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8810 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8811 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8812 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8813 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8814 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8817 vl_set_memory_region_name ("/vpe-api");
8818 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8823 VLIB_INIT_FUNCTION (vpe_api_init);
8826 static clib_error_t *
8827 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8830 u64 baseva, size, pvt_heap_size;
8832 const int max_buf_size = 4096;
8834 struct passwd _pw, *pw;
8835 struct group _grp, *grp;
8837 buf = vec_new (char, 128);
8838 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8840 if (unformat (input, "prefix %s", &chroot_path))
8842 vec_add1 (chroot_path, 0);
8843 vl_set_memory_root_path ((char *) chroot_path);
8845 else if (unformat (input, "uid %d", &uid))
8846 vl_set_memory_uid (uid);
8847 else if (unformat (input, "gid %d", &gid))
8848 vl_set_memory_gid (gid);
8849 else if (unformat (input, "baseva %llx", &baseva))
8850 vl_set_global_memory_baseva (baseva);
8851 else if (unformat (input, "global-size %lldM", &size))
8852 vl_set_global_memory_size (size * (1ULL << 20));
8853 else if (unformat (input, "global-size %lldG", &size))
8854 vl_set_global_memory_size (size * (1ULL << 30));
8855 else if (unformat (input, "global-size %lld", &size))
8856 vl_set_global_memory_size (size);
8857 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8858 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8859 else if (unformat (input, "global-pvt-heap-size size %lld",
8861 vl_set_global_pvt_heap_size (pvt_heap_size);
8862 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8863 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8864 else if (unformat (input, "api-pvt-heap-size size %lld",
8866 vl_set_api_pvt_heap_size (pvt_heap_size);
8867 else if (unformat (input, "api-size %lldM", &size))
8868 vl_set_api_memory_size (size * (1ULL << 20));
8869 else if (unformat (input, "api-size %lldG", &size))
8870 vl_set_api_memory_size (size * (1ULL << 30));
8871 else if (unformat (input, "api-size %lld", &size))
8872 vl_set_api_memory_size (size);
8873 else if (unformat (input, "uid %s", &s))
8875 /* lookup the username */
8878 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8879 && (vec_len (buf) <= max_buf_size))
8881 vec_resize (buf, vec_len (buf) * 2);
8885 e = clib_error_return_code (0, rv,
8886 CLIB_ERROR_ERRNO_VALID |
8888 "cannot fetch username %s", s);
8896 clib_error_return_fatal (0, "username %s does not exist", s);
8902 vl_set_memory_uid (pw->pw_uid);
8904 else if (unformat (input, "gid %s", &s))
8906 /* lookup the group name */
8909 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8910 && (vec_len (buf) <= max_buf_size))
8912 vec_resize (buf, vec_len (buf) * 2);
8916 e = clib_error_return_code (0, rv,
8917 CLIB_ERROR_ERRNO_VALID |
8919 "cannot fetch group %s", s);
8926 e = clib_error_return_fatal (0, "group %s does not exist", s);
8933 vl_set_memory_gid (grp->gr_gid);
8936 return clib_error_return (0, "unknown input `%U'",
8937 format_unformat_error, input);
8942 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8945 get_unformat_vnet_sw_interface (void)
8947 return (void *) &unformat_vnet_sw_interface;
8950 #undef vl_api_version
8951 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8952 #include <vpp-api/vpe.api.h>
8953 #undef vl_api_version
8956 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8958 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8960 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8961 clib_host_to_net_u32 (mp->api_versions[0]),
8969 format_arp_event (u8 * s, va_list * args)
8971 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8973 s = format (s, "pid %d: ", event->pid);
8975 s = format (s, "bd mac/ip4 binding events");
8977 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8982 format_nd_event (u8 * s, va_list * args)
8984 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8986 s = format (s, "pid %d: ", event->pid);
8988 s = format (s, "bd mac/ip6 binding events");
8990 s = format (s, "resolution for %U", format_ip6_address, event->address);
8994 static clib_error_t *
8995 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8996 unformat_input_t * input, vlib_cli_command_t * cmd)
8998 vpe_api_main_t *am = &vpe_api_main;
8999 vl_api_ip4_arp_event_t *arp_event;
9000 vl_api_ip6_nd_event_t *nd_event;
9002 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
9004 vlib_cli_output (vm, "No active arp or nd event registrations");
9009 pool_foreach (arp_event, am->arp_events,
9011 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
9014 pool_foreach (nd_event, am->nd_events,
9016 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
9024 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
9025 .path = "show arp-nd-event registrations",
9026 .function = show_ip_arp_nd_events_fn,
9027 .short_help = "Show ip4 arp and ip6 nd event registrations",
9032 * fd.io coding-style-patch-verification: ON
9035 * eval: (c-set-style "gnu")