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; \
174 rv = vl_msg_api_pd_handler (mp, rv); \
175 q = vl_api_client_index_to_input_queue (mp->client_index); \
179 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
182 /* if there isn't enough memory, try to allocate */ \
183 /* some at least for returning an error */ \
184 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
188 memset (rmp, 0, sizeof (*rmp)); \
189 rv = VNET_API_ERROR_TABLE_TOO_BIG; \
193 rmp->_vl_msg_id = ntohs((t)); \
194 rmp->context = mp->context; \
195 rmp->retval = ntohl(rv); \
197 do {body;} while (0); \
198 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
201 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
203 #define VALIDATE_SW_IF_INDEX(mp) \
204 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
205 vnet_main_t *__vnm = vnet_get_main(); \
206 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
208 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
209 goto bad_sw_if_index; \
213 #define BAD_SW_IF_INDEX_LABEL \
219 #define VALIDATE_RX_SW_IF_INDEX(mp) \
220 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
221 vnet_main_t *__vnm = vnet_get_main(); \
222 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
223 __rx_sw_if_index)) { \
224 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
225 goto bad_rx_sw_if_index; \
229 #define BAD_RX_SW_IF_INDEX_LABEL \
231 bad_rx_sw_if_index: \
235 #define VALIDATE_TX_SW_IF_INDEX(mp) \
236 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
237 vnet_main_t *__vnm = vnet_get_main(); \
238 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
239 __tx_sw_if_index)) { \
240 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
241 goto bad_tx_sw_if_index; \
245 #define BAD_TX_SW_IF_INDEX_LABEL \
247 bad_tx_sw_if_index: \
253 #define VALIDATE_SW_IF_INDEX(mp)
254 #define BAD_SW_IF_INDEX_LABEL
255 #define VALIDATE_RX_SW_IF_INDEX(mp)
256 #define BAD_RX_SW_IF_INDEX_LABEL
257 #define VALIDATE_TX_SW_IF_INDEX(mp)
258 #define BAD_TX_SW_IF_INDEX_LABEL
260 #endif /* CLIB_DEBUG > 0 */
262 #define foreach_vpe_api_msg \
263 _(WANT_INTERFACE_EVENTS, want_interface_events) \
264 _(WANT_OAM_EVENTS, want_oam_events) \
265 _(OAM_ADD_DEL, oam_add_del) \
266 _(SW_INTERFACE_DUMP, sw_interface_dump) \
267 _(SW_INTERFACE_DETAILS, sw_interface_details) \
268 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
269 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
270 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
271 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
272 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
273 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
274 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
275 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
276 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
277 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
278 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
279 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl) \
280 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
281 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
282 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
283 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
284 _(L2FIB_ADD_DEL, l2fib_add_del) \
285 _(L2_FLAGS, l2_flags) \
286 _(BRIDGE_FLAGS, bridge_flags) \
287 _(TAP_CONNECT, tap_connect) \
288 _(TAP_MODIFY, tap_modify) \
289 _(TAP_DELETE, tap_delete) \
290 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
291 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
292 _(CREATE_SUBIF, create_subif) \
293 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
294 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
295 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
296 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
297 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
298 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
299 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
300 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
301 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
302 _(RESET_FIB, reset_fib) \
303 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
304 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
305 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
306 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
307 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
308 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
309 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
310 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
311 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
312 sw_interface_ip6_set_link_local_address) \
313 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
314 _(CREATE_LOOPBACK, create_loopback) \
315 _(CONTROL_PING, control_ping) \
316 _(CLI_REQUEST, cli_request) \
317 _(CLI_INBAND, cli_inband) \
318 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
319 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
320 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
321 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
322 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
323 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
324 _(GET_NODE_INDEX, get_node_index) \
325 _(ADD_NODE_NEXT, add_node_next) \
326 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
327 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
328 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
329 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
330 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
331 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
332 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
333 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
334 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
335 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
336 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
337 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
338 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
339 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
340 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
341 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
342 _(IP_ADDRESS_DUMP, ip_address_dump) \
343 _(IP_DUMP, ip_dump) \
344 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
345 _(SHOW_VERSION, show_version) \
346 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
347 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
348 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
349 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
350 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
351 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
352 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
353 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
354 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
355 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
356 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
357 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
358 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
359 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
360 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
361 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
362 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
363 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
364 _(DELETE_LOOPBACK, delete_loopback) \
365 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
366 _(MAP_ADD_DOMAIN, map_add_domain) \
367 _(MAP_DEL_DOMAIN, map_del_domain) \
368 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
369 _(MAP_DOMAIN_DUMP, map_domain_dump) \
370 _(MAP_RULE_DUMP, map_rule_dump) \
371 _(MAP_SUMMARY_STATS, map_summary_stats) \
372 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
373 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
374 _(GET_NODE_GRAPH, get_node_graph) \
375 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
376 _(IOAM_ENABLE, ioam_enable) \
377 _(IOAM_DISABLE, ioam_disable) \
378 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
379 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
380 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
381 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
382 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
383 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
384 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
385 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
386 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
387 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
388 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
389 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
390 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
391 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
392 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
393 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
394 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
395 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
396 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
397 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
398 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
399 _(SHOW_LISP_STATUS, show_lisp_status) \
400 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
401 lisp_add_del_map_request_itr_rlocs) \
402 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
403 _(SHOW_LISP_PITR, show_lisp_pitr) \
404 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
405 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
406 _(AF_PACKET_CREATE, af_packet_create) \
407 _(AF_PACKET_DELETE, af_packet_delete) \
408 _(POLICER_ADD_DEL, policer_add_del) \
409 _(POLICER_DUMP, policer_dump) \
410 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
411 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
412 _(NETMAP_CREATE, netmap_create) \
413 _(NETMAP_DELETE, netmap_delete) \
414 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
415 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
416 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
417 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
418 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
419 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
420 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
421 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
422 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
423 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
424 _(CLASSIFY_TABLE_INFO,classify_table_info) \
425 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
426 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
427 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
428 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
429 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
430 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
431 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
432 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
433 _(GET_NEXT_INDEX, get_next_index) \
434 _(PG_CREATE_INTERFACE, pg_create_interface) \
435 _(PG_CAPTURE, pg_capture) \
436 _(PG_ENABLE_DISABLE, pg_enable_disable) \
437 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
438 ip_source_and_port_range_check_add_del) \
439 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
440 ip_source_and_port_range_check_interface_add_del) \
441 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
442 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
443 _(DELETE_SUBIF, delete_subif) \
444 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
446 _(FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface) \
447 _(FLOW_CLASSIFY_DUMP, flow_classify_dump)
450 #define QUOTE(x) QUOTE_(x)
452 #define foreach_registration_hash \
453 _(interface_events) \
454 _(to_netconf_server) \
455 _(from_netconf_server) \
456 _(to_netconf_client) \
457 _(from_netconf_client) \
462 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
463 RESOLVE_IP6_ADD_DEL_ROUTE,
464 RESOLVE_MPLS_ETHERNET_ADD_DEL,
472 vl_api_ip_add_del_route_t r;
473 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
480 #define _(a) uword *a##_registration_hash; \
481 vpe_client_registration_t * a##_registrations;
482 foreach_registration_hash
484 /* notifications happen really early in the game */
485 u8 link_state_process_up;
487 /* ip4 and ip6 pending route adds */
488 pending_route_t *pending_routes;
490 /* ip4 arp event registration pool */
491 vl_api_ip4_arp_event_t *arp_events;
493 /* ip6 nd event registration pool */
494 vl_api_ip6_nd_event_t *nd_events;
497 vlib_main_t *vlib_main;
498 vnet_main_t *vnet_main;
501 static vlib_node_registration_t vpe_resolver_process_node;
502 static vpe_api_main_t vpe_api_main;
504 static void send_sw_interface_flags (vpe_api_main_t * am,
505 unix_shared_memory_queue_t * q,
506 vnet_sw_interface_t * swif);
507 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
508 unix_shared_memory_queue_t * q,
511 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
512 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
515 /* Clean up all registrations belonging to the indicated client */
517 vl_api_memclnt_delete_callback (u32 client_index)
519 vpe_api_main_t *vam = &vpe_api_main;
520 vpe_client_registration_t *rp;
522 int stats_memclnt_delete_callback (u32 client_index);
524 stats_memclnt_delete_callback (client_index);
527 p = hash_get (vam->a##_registration_hash, client_index); \
529 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
530 pool_put (vam->a##_registrations, rp); \
531 hash_unset (vam->a##_registration_hash, client_index); \
533 foreach_registration_hash;
538 #define API_LINK_STATE_EVENT 1
539 #define API_ADMIN_UP_DOWN_EVENT 2
542 event_data_cmp (void *a1, void *a2)
547 return (word) e1[0] - (word) e2[0];
551 link_state_process (vlib_main_t * vm,
552 vlib_node_runtime_t * rt, vlib_frame_t * f)
554 vpe_api_main_t *vam = &vpe_api_main;
555 vnet_main_t *vnm = vam->vnet_main;
556 vnet_sw_interface_t *swif;
557 uword *event_data = 0;
558 vpe_client_registration_t *reg;
560 u32 prev_sw_if_index;
561 unix_shared_memory_queue_t *q;
563 vam->link_state_process_up = 1;
567 vlib_process_wait_for_event (vm);
569 /* Unified list of changed link or admin state sw_if_indices */
570 vlib_process_get_events_with_type
571 (vm, &event_data, API_LINK_STATE_EVENT);
572 vlib_process_get_events_with_type
573 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
575 /* Sort, so we can eliminate duplicates */
576 vec_sort_with_function (event_data, event_data_cmp);
578 prev_sw_if_index = ~0;
580 for (i = 0; i < vec_len (event_data); i++)
582 /* Only one message per swif */
583 if (prev_sw_if_index == event_data[i])
585 prev_sw_if_index = event_data[i];
588 pool_foreach(reg, vam->interface_events_registrations,
590 q = vl_api_client_index_to_input_queue (reg->client_index);
593 /* sw_interface may be deleted already */
594 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
597 swif = vnet_get_sw_interface (vnm, event_data[i]);
598 send_sw_interface_flags (vam, q, swif);
604 vec_reset_length (event_data);
610 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
612 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
613 u32 hw_if_index, u32 flags);
616 VLIB_REGISTER_NODE (link_state_process_node,static) = {
617 .function = link_state_process,
618 .type = VLIB_NODE_TYPE_PROCESS,
619 .name = "vpe-link-state-process",
623 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
624 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
626 static clib_error_t *
627 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
629 vpe_api_main_t *vam = &vpe_api_main;
630 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
632 if (vam->link_state_process_up)
633 vlib_process_signal_event (vam->vlib_main,
634 link_state_process_node.index,
635 API_LINK_STATE_EVENT, hi->sw_if_index);
639 static clib_error_t *
640 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
642 vpe_api_main_t *vam = &vpe_api_main;
645 * Note: it's perfectly fair to set a subif admin up / admin down.
646 * Note the subtle distinction between this routine and the previous
649 if (vam->link_state_process_up)
650 vlib_process_signal_event (vam->vlib_main,
651 link_state_process_node.index,
652 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
656 #define pub_sub_handler(lca,UCA) \
657 static void vl_api_want_##lca##_t_handler ( \
658 vl_api_want_##lca##_t *mp) \
660 vpe_api_main_t *vam = &vpe_api_main; \
661 vpe_client_registration_t *rp; \
662 vl_api_want_##lca##_reply_t *rmp; \
666 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
668 if (mp->enable_disable) { \
669 clib_warning ("pid %d: already enabled...", mp->pid); \
670 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
673 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
674 pool_put (vam->lca##_registrations, rp); \
675 hash_unset (vam->lca##_registration_hash, \
680 if (mp->enable_disable == 0) { \
681 clib_warning ("pid %d: already disabled...", mp->pid); \
682 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
685 pool_get (vam->lca##_registrations, rp); \
686 rp->client_index = mp->client_index; \
687 rp->client_pid = mp->pid; \
688 hash_set (vam->lca##_registration_hash, rp->client_index, \
689 rp - vam->lca##_registrations); \
692 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
696 pub_sub_handler (interface_events, INTERFACE_EVENTS)
697 pub_sub_handler (oam_events, OAM_EVENTS)
700 #define RESOLUTION_EVENT 1
701 #define RESOLUTION_PENDING_EVENT 2
702 #define IP4_ARP_EVENT 3
703 #define IP6_ND_EVENT 4
705 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
707 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
709 static int mpls_ethernet_add_del_tunnel_2_t_handler
710 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
713 handle_ip4_arp_event (u32 pool_index)
715 vpe_api_main_t *vam = &vpe_api_main;
716 vnet_main_t *vnm = vam->vnet_main;
717 vlib_main_t *vm = vam->vlib_main;
718 vl_api_ip4_arp_event_t *event;
719 vl_api_ip4_arp_event_t *mp;
720 unix_shared_memory_queue_t *q;
722 /* Client can cancel, die, etc. */
723 if (pool_is_free_index (vam->arp_events, pool_index))
726 event = pool_elt_at_index (vam->arp_events, pool_index);
728 q = vl_api_client_index_to_input_queue (event->client_index);
731 (void) vnet_add_del_ip4_arp_change_event
732 (vnm, arp_change_delete_callback,
733 event->pid, &event->address,
734 vpe_resolver_process_node.index, IP4_ARP_EVENT,
735 ~0 /* pool index, notused */ , 0 /* is_add */ );
739 if (q->cursize < q->maxsize)
741 mp = vl_msg_api_alloc (sizeof (*mp));
742 clib_memcpy (mp, event, sizeof (*mp));
743 vl_msg_api_send_shmem (q, (u8 *) & mp);
747 static f64 last_time;
749 * Throttle syslog msgs.
750 * It's pretty tempting to just revoke the registration...
752 if (vlib_time_now (vm) > last_time + 10.0)
754 clib_warning ("arp event for %U to pid %d: queue stuffed!",
755 format_ip4_address, &event->address, event->pid);
756 last_time = vlib_time_now (vm);
762 handle_ip6_nd_event (u32 pool_index)
764 vpe_api_main_t *vam = &vpe_api_main;
765 vnet_main_t *vnm = vam->vnet_main;
766 vlib_main_t *vm = vam->vlib_main;
767 vl_api_ip6_nd_event_t *event;
768 vl_api_ip6_nd_event_t *mp;
769 unix_shared_memory_queue_t *q;
771 /* Client can cancel, die, etc. */
772 if (pool_is_free_index (vam->nd_events, pool_index))
775 event = pool_elt_at_index (vam->nd_events, pool_index);
777 q = vl_api_client_index_to_input_queue (event->client_index);
780 (void) vnet_add_del_ip6_nd_change_event
781 (vnm, nd_change_delete_callback,
782 event->pid, &event->address,
783 vpe_resolver_process_node.index, IP6_ND_EVENT,
784 ~0 /* pool index, notused */ , 0 /* is_add */ );
788 if (q->cursize < q->maxsize)
790 mp = vl_msg_api_alloc (sizeof (*mp));
791 clib_memcpy (mp, event, sizeof (*mp));
792 vl_msg_api_send_shmem (q, (u8 *) & mp);
796 static f64 last_time;
798 * Throttle syslog msgs.
799 * It's pretty tempting to just revoke the registration...
801 if (vlib_time_now (vm) > last_time + 10.0)
803 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
804 format_ip6_address, &event->address, event->pid);
805 last_time = vlib_time_now (vm);
811 resolver_process (vlib_main_t * vm,
812 vlib_node_runtime_t * rt, vlib_frame_t * f)
815 uword *event_data = 0;
817 vpe_api_main_t *vam = &vpe_api_main;
819 vl_api_ip_add_del_route_t *adr;
820 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
821 u32 *resolution_failures = 0;
827 vlib_process_wait_for_event_or_clock (vm, timeout);
829 event_type = vlib_process_get_events (vm, &event_data);
833 case RESOLUTION_PENDING_EVENT:
837 case RESOLUTION_EVENT:
838 for (i = 0; i < vec_len (event_data); i++)
841 * Resolution events can occur long after the
842 * original request has timed out. $$$ add a cancel
845 if (pool_is_free_index (vam->pending_routes, event_data[i]))
848 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
852 switch (pr->resolve_type)
854 case RESOLVE_IP4_ADD_DEL_ROUTE:
855 rv = ip4_add_del_route_t_handler (adr);
856 clib_warning ("resolver: add %U/%d via %U %s",
858 (ip4_address_t *) & (adr->dst_address),
859 adr->dst_address_length,
861 (ip4_address_t *) & (adr->next_hop_address),
862 (rv >= 0) ? "succeeded" : "failed");
865 case RESOLVE_IP6_ADD_DEL_ROUTE:
866 rv = ip6_add_del_route_t_handler (adr);
867 clib_warning ("resolver: add %U/%d via %U %s",
869 (ip6_address_t *) & (adr->dst_address),
870 adr->dst_address_length,
872 (ip6_address_t *) & (adr->next_hop_address),
873 (rv >= 0) ? "succeeded" : "failed");
876 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
877 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
878 clib_warning ("resolver: add mpls-o-e via %U %s",
881 (pme->next_hop_ip4_address_in_outer_vrf),
882 (rv >= 0) ? "succeeded" : "failed");
886 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
888 pool_put (vam->pending_routes, pr);
893 for (i = 0; i < vec_len (event_data); i++)
894 handle_ip4_arp_event (event_data[i]);
898 for (i = 0; i < vec_len (event_data); i++)
899 handle_ip6_nd_event (event_data[i]);
902 case ~0: /* timeout, retry pending resolutions */
904 pool_foreach (pr, vam->pending_routes,
910 /* May fail, e.g. due to interface down */
911 switch (pr->resolve_type)
913 case RESOLVE_IP4_ADD_DEL_ROUTE:
914 e = ip4_probe_neighbor
915 (vm, (ip4_address_t *)&(adr->next_hop_address),
916 ntohl(adr->next_hop_sw_if_index));
919 case RESOLVE_IP6_ADD_DEL_ROUTE:
920 e = ip6_probe_neighbor
921 (vm, (ip6_address_t *)&(adr->next_hop_address),
922 ntohl(adr->next_hop_sw_if_index));
925 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
927 e = ip4_probe_neighbor
929 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
930 pme->resolve_opaque);
934 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
939 clib_error_report (e);
941 adr->resolve_attempts = 1;
943 pme->resolve_attempts = 1;
947 adr->resolve_attempts -= 1;
948 if (adr->resolve_attempts == 0)
949 vec_add1 (resolution_failures,
950 pr - vam->pending_routes);
954 pme->resolve_attempts -= 1;
955 if (pme->resolve_attempts == 0)
956 vec_add1 (resolution_failures,
957 pr - vam->pending_routes);
961 for (i = 0; i < vec_len (resolution_failures); i++)
963 pr = pool_elt_at_index (vam->pending_routes,
964 resolution_failures[i]);
968 switch (pr->resolve_type)
970 case RESOLVE_IP4_ADD_DEL_ROUTE:
971 clib_warning ("resolver: add %U/%d via %U retry failure",
973 (ip4_address_t *) & (adr->dst_address),
974 adr->dst_address_length,
976 (ip4_address_t *) & (adr->next_hop_address));
979 case RESOLVE_IP6_ADD_DEL_ROUTE:
980 clib_warning ("resolver: add %U/%d via %U retry failure",
982 (ip6_address_t *) & (adr->dst_address),
983 adr->dst_address_length,
985 (ip6_address_t *) & (adr->next_hop_address));
988 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
989 clib_warning ("resolver: add mpls-o-e via %U retry failure",
992 (pme->next_hop_ip4_address_in_outer_vrf));
996 clib_warning ("BUG");
998 pool_put (vam->pending_routes, pr);
1000 vec_reset_length (resolution_failures);
1003 if (pool_elts (vam->pending_routes) == 0)
1005 vec_reset_length (event_data);
1007 return 0; /* or not */
1011 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
1012 .function = resolver_process,
1013 .type = VLIB_NODE_TYPE_PROCESS,
1014 .name = "vpe-route-resolver-process",
1019 ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp,
1021 const fib_prefix_t * prefix,
1022 const ip46_address_t * next_hop,
1023 u32 next_hop_sw_if_index,
1024 u32 next_hop_fib_index, u32 next_hop_weight)
1026 vnet_classify_main_t *cm = &vnet_classify_main;
1027 fib_protocol_t proto = prefix->fp_proto;
1028 stats_main_t *sm = &stats_main;
1030 if (mp->is_multipath)
1032 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1034 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1036 if (mp->is_resolve_host)
1037 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1038 if (mp->is_resolve_attached)
1039 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1042 fib_table_entry_path_add (fib_index,
1045 FIB_ENTRY_FLAG_NONE,
1048 next_hop_sw_if_index,
1051 MPLS_LABEL_INVALID, path_flags);
1053 fib_table_entry_path_remove (fib_index,
1058 next_hop_sw_if_index,
1060 next_hop_weight, path_flags);
1066 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1068 if (mp->is_drop || mp->is_local || mp->is_classify || mp->lookup_in_vrf)
1071 * special route types that link directly to the adj
1075 dpo_id_t dpo = DPO_NULL;
1078 dproto = fib_proto_to_dpo (prefix->fp_proto);
1081 dpo_copy (&dpo, drop_dpo_get (dproto));
1082 else if (mp->is_local)
1083 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
1084 else if (mp->is_classify)
1086 if (pool_is_free_index (cm->tables,
1087 ntohl (mp->classify_table_index)))
1090 return VNET_API_ERROR_NO_SUCH_TABLE;
1093 dpo_set (&dpo, DPO_CLASSIFY, proto,
1094 classify_dpo_create (prefix->fp_proto,
1096 (mp->classify_table_index)));
1098 else if (mp->lookup_in_vrf)
1100 next_hop_fib_index =
1101 fib_table_id_find_fib_index (dproto,
1102 ntohl (mp->lookup_in_vrf));
1103 if (~0 == next_hop_fib_index)
1106 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1109 lookup_dpo_add_or_lock_w_fib_index (next_hop_fib_index,
1111 LOOKUP_INPUT_DST_ADDR,
1112 LOOKUP_TABLE_FROM_CONFIG,
1118 return VNET_API_ERROR_NO_SUCH_TABLE;
1121 fib_table_entry_special_dpo_add (fib_index,
1124 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
1129 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
1136 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1138 if (mp->is_resolve_host)
1139 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1140 if (mp->is_resolve_attached)
1141 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1143 fib_table_entry_update_one_path (fib_index,
1146 FIB_ENTRY_FLAG_NONE,
1149 next_hop_sw_if_index,
1152 MPLS_LABEL_INVALID, path_flags);
1156 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
1165 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1167 vpe_api_main_t *vam = &vpe_api_main;
1168 vnet_main_t *vnm = vam->vnet_main;
1171 fib_index = ip4_fib_index_from_table_id (ntohl (mp->vrf_id));
1172 if (~0 == fib_index)
1174 if (mp->create_vrf_if_needed)
1176 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1177 ntohl (mp->vrf_id));
1181 /* No such VRF, and we weren't asked to create one */
1182 return VNET_API_ERROR_NO_SUCH_FIB;
1186 if (~0 != ntohl (mp->next_hop_sw_if_index) &&
1187 pool_is_free_index (vnm->interface_main.sw_interfaces,
1188 ntohl (mp->next_hop_sw_if_index)))
1189 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1191 fib_prefix_t pfx = {
1192 .fp_len = mp->dst_address_length,
1193 .fp_proto = FIB_PROTOCOL_IP4,
1195 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
1198 memset (&nh, 0, sizeof (nh));
1199 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
1201 return (ip_add_del_route_t_handler (mp, fib_index, &pfx, &nh,
1202 ntohl (mp->next_hop_sw_if_index),
1203 fib_index, (u32) mp->next_hop_weight));
1207 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1209 vnet_main_t *vnm = vnet_get_main ();
1212 fib_index = ip6_fib_index_from_table_id (ntohl (mp->vrf_id));
1213 if (~0 == fib_index)
1215 if (mp->create_vrf_if_needed)
1217 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1218 ntohl (mp->vrf_id));
1222 /* No such VRF, and we weren't asked to create one */
1223 return VNET_API_ERROR_NO_SUCH_FIB;
1227 if (~0 != ntohl (mp->next_hop_sw_if_index) &&
1228 pool_is_free_index (vnm->interface_main.sw_interfaces,
1229 ntohl (mp->next_hop_sw_if_index)))
1230 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1232 fib_prefix_t pfx = {
1233 .fp_len = mp->dst_address_length,
1234 .fp_proto = FIB_PROTOCOL_IP6,
1236 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
1239 memset (&nh, 0, sizeof (nh));
1240 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
1242 return (ip_add_del_route_t_handler (mp, fib_index, &pfx,
1243 &nh, ntohl (mp->next_hop_sw_if_index),
1244 fib_index, (u32) mp->next_hop_weight));
1248 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1250 vl_api_ip_add_del_route_reply_t *rmp;
1252 vnet_main_t *vnm = vnet_get_main ();
1257 rv = ip6_add_del_route_t_handler (mp);
1259 rv = ip4_add_del_route_t_handler (mp);
1261 rv = (rv == 0) ? vnm->api_errno : rv;
1263 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1267 vl_api_sw_interface_add_del_address_t_handler
1268 (vl_api_sw_interface_add_del_address_t * mp)
1270 vlib_main_t *vm = vlib_get_main ();
1271 vl_api_sw_interface_add_del_address_reply_t *rmp;
1275 VALIDATE_SW_IF_INDEX (mp);
1277 is_del = mp->is_add == 0;
1280 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1281 else if (mp->is_ipv6)
1282 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1283 (void *) mp->address,
1284 mp->address_length, is_del);
1286 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1287 (void *) mp->address,
1288 mp->address_length, is_del);
1290 BAD_SW_IF_INDEX_LABEL;
1292 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1296 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1299 u32 table_id = ntohl (mp->vrf_id);
1300 u32 sw_if_index = ntohl (mp->sw_if_index);
1301 vl_api_sw_interface_set_table_reply_t *rmp;
1302 stats_main_t *sm = &stats_main;
1305 VALIDATE_SW_IF_INDEX (mp);
1307 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1311 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1314 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
1315 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1320 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1323 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
1324 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1328 BAD_SW_IF_INDEX_LABEL;
1330 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1334 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1336 vlib_main_t *vm = vlib_get_main ();
1337 ip4_main_t *im4 = &ip4_main;
1338 ip6_main_t *im6 = &ip6_main;
1339 vl_api_sw_interface_set_vpath_reply_t *rmp;
1342 u32 sw_if_index = ntohl (mp->sw_if_index);
1343 ip4_main_t *ip4m = &ip4_main;
1344 ip6_main_t *ip6m = &ip6_main;
1345 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1346 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1347 ip_config_main_t *rx_cm4u =
1348 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1349 ip_config_main_t *rx_cm4m =
1350 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1351 ip_config_main_t *rx_cm6u =
1352 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1353 ip_config_main_t *rx_cm6m =
1354 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1356 VALIDATE_SW_IF_INDEX (mp);
1358 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1361 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1362 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1364 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1365 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1366 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1367 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1369 im4->ip4_multicast_rx_feature_vpath,
1371 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1372 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1373 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1375 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1376 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1377 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1378 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1380 im6->ip6_multicast_rx_feature_vpath,
1382 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1386 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1387 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1389 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1390 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1391 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1392 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1394 im4->ip4_multicast_rx_feature_vpath,
1396 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1397 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1398 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1400 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1401 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1402 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1403 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1405 im6->ip6_multicast_rx_feature_vpath,
1407 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1410 BAD_SW_IF_INDEX_LABEL;
1412 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1416 vl_api_sw_interface_set_l2_xconnect_t_handler
1417 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1419 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1421 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1422 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1423 vlib_main_t *vm = vlib_get_main ();
1424 vnet_main_t *vnm = vnet_get_main ();
1426 VALIDATE_RX_SW_IF_INDEX (mp);
1430 VALIDATE_TX_SW_IF_INDEX (mp);
1431 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1432 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1436 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1439 BAD_RX_SW_IF_INDEX_LABEL;
1440 BAD_TX_SW_IF_INDEX_LABEL;
1442 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1446 vl_api_sw_interface_set_l2_bridge_t_handler
1447 (vl_api_sw_interface_set_l2_bridge_t * mp)
1449 bd_main_t *bdm = &bd_main;
1450 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1452 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1453 u32 bd_id = ntohl (mp->bd_id);
1457 vlib_main_t *vm = vlib_get_main ();
1458 vnet_main_t *vnm = vnet_get_main ();
1460 VALIDATE_RX_SW_IF_INDEX (mp);
1462 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1466 //VALIDATE_TX_SW_IF_INDEX(mp);
1467 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1468 rx_sw_if_index, bd_index, bvi, shg, 0);
1472 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1475 BAD_RX_SW_IF_INDEX_LABEL;
1477 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1481 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
1482 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
1484 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
1488 dpdk_main_t *dm = &dpdk_main;
1491 u32 sw_if_index = ntohl (mp->sw_if_index);
1492 u32 subport = ntohl (mp->subport);
1493 u32 pipe = ntohl (mp->pipe);
1494 u32 profile = ntohl (mp->profile);
1495 vnet_hw_interface_t *hw;
1497 VALIDATE_SW_IF_INDEX (mp);
1499 /* hw_if & dpdk device */
1500 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1502 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1504 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
1506 BAD_SW_IF_INDEX_LABEL;
1508 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
1509 rv = VNET_API_ERROR_UNIMPLEMENTED;
1512 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
1516 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
1517 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
1519 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
1523 dpdk_main_t *dm = &dpdk_main;
1525 struct rte_sched_subport_params p;
1527 u32 sw_if_index = ntohl (mp->sw_if_index);
1528 u32 subport = ntohl (mp->subport);
1529 p.tb_rate = ntohl (mp->tb_rate);
1530 p.tb_size = ntohl (mp->tb_size);
1531 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
1532 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
1533 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
1534 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
1535 p.tc_period = ntohl (mp->tc_period);
1537 vnet_hw_interface_t *hw;
1539 VALIDATE_SW_IF_INDEX (mp);
1541 /* hw_if & dpdk device */
1542 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1544 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1546 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
1548 BAD_SW_IF_INDEX_LABEL;
1551 ("setting HQoS subport parameters without DPDK not implemented");
1552 rv = VNET_API_ERROR_UNIMPLEMENTED;
1555 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
1559 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
1560 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
1562 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
1566 dpdk_main_t *dm = &dpdk_main;
1567 vlib_thread_main_t *tm = vlib_get_thread_main ();
1570 u32 sw_if_index = ntohl (mp->sw_if_index);
1571 u32 entry = ntohl (mp->entry);
1572 u32 tc = ntohl (mp->tc);
1573 u32 queue = ntohl (mp->queue);
1576 vnet_hw_interface_t *hw;
1578 VALIDATE_SW_IF_INDEX (mp);
1580 /* hw_if & dpdk device */
1581 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
1583 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1585 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1587 clib_warning ("invalid traffic class !!");
1588 rv = VNET_API_ERROR_INVALID_VALUE;
1591 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1593 clib_warning ("invalid queue !!");
1594 rv = VNET_API_ERROR_INVALID_VALUE;
1598 /* Detect the set of worker threads */
1599 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1600 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1601 int worker_thread_first = tr->first_index;
1602 int worker_thread_count = tr->count;
1604 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1605 for (i = 0; i < worker_thread_count; i++)
1606 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1608 BAD_SW_IF_INDEX_LABEL;
1611 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
1612 rv = VNET_API_ERROR_UNIMPLEMENTED;
1615 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
1619 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1621 vlib_main_t *vm = vlib_get_main ();
1622 bd_main_t *bdm = &bd_main;
1623 vl_api_bridge_domain_add_del_reply_t *rmp;
1625 u32 enable_flags = 0, disable_flags = 0;
1626 u32 bd_id = ntohl (mp->bd_id);
1631 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1634 enable_flags |= L2_FLOOD;
1636 disable_flags |= L2_FLOOD;
1639 enable_flags |= L2_UU_FLOOD;
1641 disable_flags |= L2_UU_FLOOD;
1644 enable_flags |= L2_FWD;
1646 disable_flags |= L2_FWD;
1649 enable_flags |= L2_ARP_TERM;
1651 disable_flags |= L2_ARP_TERM;
1654 enable_flags |= L2_LEARN;
1656 disable_flags |= L2_LEARN;
1659 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1662 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1666 rv = bd_delete_bd_index (bdm, bd_id);
1668 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1672 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1674 clib_warning ("BUG");
1678 vl_api_bridge_domain_sw_if_details_t_handler
1679 (vl_api_bridge_domain_sw_if_details_t * mp)
1681 clib_warning ("BUG");
1685 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1686 l2_bridge_domain_t * bd_config,
1687 u32 n_sw_ifs, u32 context)
1689 vl_api_bridge_domain_details_t *mp;
1691 mp = vl_msg_api_alloc (sizeof (*mp));
1692 memset (mp, 0, sizeof (*mp));
1693 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1694 mp->bd_id = ntohl (bd_config->bd_id);
1695 mp->flood = bd_feature_flood (bd_config);
1696 mp->uu_flood = bd_feature_uu_flood (bd_config);
1697 mp->forward = bd_feature_forward (bd_config);
1698 mp->learn = bd_feature_learn (bd_config);
1699 mp->arp_term = bd_feature_arp_term (bd_config);
1700 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1701 mp->n_sw_ifs = ntohl (n_sw_ifs);
1702 mp->context = context;
1704 vl_msg_api_send_shmem (q, (u8 *) & mp);
1708 send_bd_sw_if_details (l2input_main_t * l2im,
1709 unix_shared_memory_queue_t * q,
1710 l2_flood_member_t * member, u32 bd_id, u32 context)
1712 vl_api_bridge_domain_sw_if_details_t *mp;
1713 l2_input_config_t *input_cfg;
1715 mp = vl_msg_api_alloc (sizeof (*mp));
1716 memset (mp, 0, sizeof (*mp));
1717 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1718 mp->bd_id = ntohl (bd_id);
1719 mp->sw_if_index = ntohl (member->sw_if_index);
1720 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1721 mp->shg = input_cfg->shg;
1722 mp->context = context;
1724 vl_msg_api_send_shmem (q, (u8 *) & mp);
1728 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1730 bd_main_t *bdm = &bd_main;
1731 l2input_main_t *l2im = &l2input_main;
1732 unix_shared_memory_queue_t *q;
1733 l2_bridge_domain_t *bd_config;
1734 u32 bd_id, bd_index;
1737 q = vl_api_client_index_to_input_queue (mp->client_index);
1742 bd_id = ntohl (mp->bd_id);
1744 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1745 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1746 for (; bd_index < end; bd_index++)
1748 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1749 /* skip dummy bd_id 0 */
1750 if (bd_config && (bd_config->bd_id > 0))
1753 l2_flood_member_t *m;
1755 n_sw_ifs = vec_len (bd_config->members);
1756 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1758 vec_foreach (m, bd_config->members)
1760 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1767 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1769 bd_main_t *bdm = &bd_main;
1770 l2input_main_t *l2im = &l2input_main;
1771 vl_api_l2fib_add_del_reply_t *rmp;
1774 u32 sw_if_index = ntohl (mp->sw_if_index);
1775 u32 bd_id = ntohl (mp->bd_id);
1784 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1787 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1788 goto bad_sw_if_index;
1794 VALIDATE_SW_IF_INDEX (mp);
1795 if (vec_len (l2im->configs) <= sw_if_index)
1797 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1798 goto bad_sw_if_index;
1802 l2_input_config_t *config;
1803 config = vec_elt_at_index (l2im->configs, sw_if_index);
1804 if (config->bridge == 0)
1806 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1807 goto bad_sw_if_index;
1810 static_mac = mp->static_mac ? 1 : 0;
1811 filter_mac = mp->filter_mac ? 1 : 0;
1812 bvi_mac = mp->bvi_mac ? 1 : 0;
1813 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1818 l2fib_del_entry (mac, bd_index);
1821 BAD_SW_IF_INDEX_LABEL;
1823 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1827 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1829 vl_api_l2_flags_reply_t *rmp;
1831 u32 sw_if_index = ntohl (mp->sw_if_index);
1832 u32 flags = ntohl (mp->feature_bitmap);
1835 VALIDATE_SW_IF_INDEX (mp);
1838 if (flags & L2INPUT_FEAT_ ## a) \
1839 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1840 foreach_l2input_feat;
1843 BAD_SW_IF_INDEX_LABEL;
1846 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1848 rmp->resulting_feature_bitmap = ntohl(rbm);
1854 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1856 vlib_main_t *vm = vlib_get_main ();
1857 bd_main_t *bdm = &bd_main;
1858 vl_api_bridge_flags_reply_t *rmp;
1860 u32 bd_id = ntohl (mp->bd_id);
1862 u32 flags = ntohl (mp->feature_bitmap);
1865 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1868 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1874 bd_set_flags (vm, bd_index, flags, mp->is_set);
1878 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1880 rmp->resulting_feature_bitmap = ntohl(flags);
1886 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1888 bd_main_t *bdm = &bd_main;
1889 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1891 u32 bd_id = ntohl (mp->bd_id);
1895 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1898 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1903 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1904 mp->mac_address, mp->is_ipv6, mp->is_add))
1905 rv = VNET_API_ERROR_UNSPECIFIED;
1908 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1912 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1915 vl_api_tap_connect_reply_t *rmp;
1916 unix_shared_memory_queue_t *q;
1917 u32 sw_if_index = (u32) ~ 0;
1919 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1920 mp->use_random_mac ? 0 : mp->mac_address,
1921 &sw_if_index, mp->renumber,
1922 ntohl (mp->custom_dev_instance));
1924 q = vl_api_client_index_to_input_queue (mp->client_index);
1928 rmp = vl_msg_api_alloc (sizeof (*rmp));
1929 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1930 rmp->context = mp->context;
1931 rmp->retval = ntohl (rv);
1932 rmp->sw_if_index = ntohl (sw_if_index);
1934 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1938 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
1941 vl_api_tap_modify_reply_t *rmp;
1942 unix_shared_memory_queue_t *q;
1943 u32 sw_if_index = (u32) ~ 0;
1945 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1946 mp->use_random_mac ? 0 : mp->mac_address,
1947 &sw_if_index, mp->renumber,
1948 ntohl (mp->custom_dev_instance));
1950 q = vl_api_client_index_to_input_queue (mp->client_index);
1954 rmp = vl_msg_api_alloc (sizeof (*rmp));
1955 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1956 rmp->context = mp->context;
1957 rmp->retval = ntohl (rv);
1958 rmp->sw_if_index = ntohl (sw_if_index);
1960 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1964 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
1967 vpe_api_main_t *vam = &vpe_api_main;
1968 vl_api_tap_delete_reply_t *rmp;
1969 unix_shared_memory_queue_t *q;
1970 u32 sw_if_index = ntohl (mp->sw_if_index);
1972 rv = vnet_tap_delete (vm, sw_if_index);
1974 q = vl_api_client_index_to_input_queue (mp->client_index);
1978 rmp = vl_msg_api_alloc (sizeof (*rmp));
1979 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1980 rmp->context = mp->context;
1981 rmp->retval = ntohl (rv);
1983 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1986 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1990 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1992 vl_api_create_vlan_subif_reply_t *rmp;
1993 vnet_main_t *vnm = vnet_get_main ();
1994 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1995 vnet_hw_interface_t *hi;
1998 vnet_sw_interface_t template;
2000 vnet_interface_main_t *im = &vnm->interface_main;
2001 u64 sup_and_sub_key;
2003 unix_shared_memory_queue_t *q;
2004 clib_error_t *error;
2006 VALIDATE_SW_IF_INDEX (mp);
2008 hw_if_index = ntohl (mp->sw_if_index);
2009 hi = vnet_get_hw_interface (vnm, hw_if_index);
2011 id = ntohl (mp->vlan_id);
2012 if (id == 0 || id > 4095)
2014 rv = VNET_API_ERROR_INVALID_VLAN;
2018 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2020 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2023 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2027 kp = clib_mem_alloc (sizeof (*kp));
2028 *kp = sup_and_sub_key;
2030 memset (&template, 0, sizeof (template));
2031 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2032 template.sup_sw_if_index = hi->sw_if_index;
2033 template.sub.id = id;
2034 template.sub.eth.raw_flags = 0;
2035 template.sub.eth.flags.one_tag = 1;
2036 template.sub.eth.outer_vlan_id = id;
2037 template.sub.eth.flags.exact_match = 1;
2039 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2042 clib_error_report (error);
2043 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2046 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2047 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2049 BAD_SW_IF_INDEX_LABEL;
2052 q = vl_api_client_index_to_input_queue (mp->client_index);
2056 rmp = vl_msg_api_alloc (sizeof (*rmp));
2057 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2058 rmp->context = mp->context;
2059 rmp->retval = ntohl (rv);
2060 rmp->sw_if_index = ntohl (sw_if_index);
2061 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2065 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2067 vl_api_create_subif_reply_t *rmp;
2068 vnet_main_t *vnm = vnet_get_main ();
2069 u32 sw_if_index = ~0;
2072 vnet_sw_interface_t *si;
2073 vnet_hw_interface_t *hi;
2074 vnet_sw_interface_t template;
2076 vnet_interface_main_t *im = &vnm->interface_main;
2077 u64 sup_and_sub_key;
2079 clib_error_t *error;
2081 VALIDATE_SW_IF_INDEX (mp);
2083 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2084 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2086 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2088 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2092 sw_if_index = si->sw_if_index;
2093 sub_id = ntohl (mp->sub_id);
2095 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2097 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2101 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2102 sw_if_index, sub_id);
2103 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2107 kp = clib_mem_alloc (sizeof (*kp));
2108 *kp = sup_and_sub_key;
2110 memset (&template, 0, sizeof (template));
2111 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2112 template.sup_sw_if_index = sw_if_index;
2113 template.sub.id = sub_id;
2114 template.sub.eth.flags.no_tags = mp->no_tags;
2115 template.sub.eth.flags.one_tag = mp->one_tag;
2116 template.sub.eth.flags.two_tags = mp->two_tags;
2117 template.sub.eth.flags.dot1ad = mp->dot1ad;
2118 template.sub.eth.flags.exact_match = mp->exact_match;
2119 template.sub.eth.flags.default_sub = mp->default_sub;
2120 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2121 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2122 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2123 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2125 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2128 clib_error_report (error);
2129 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2133 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2134 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2136 BAD_SW_IF_INDEX_LABEL;
2141 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2143 rmp->sw_if_index = ntohl(sw_if_index);
2149 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2152 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2154 stats_main_t *sm = &stats_main;
2155 u32 tunnel_sw_if_index = ~0;
2157 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2159 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2160 (ip4_address_t *) (mp->dst_address),
2161 (ip4_address_t *) (mp->intfc_address),
2162 (u32) (mp->intfc_address_length),
2163 ntohl (mp->inner_vrf_id),
2164 ntohl (mp->outer_vrf_id),
2165 &tunnel_sw_if_index,
2166 mp->l2_only, mp->is_add);
2170 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2172 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2178 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2179 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2181 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2183 stats_main_t *sm = &stats_main;
2184 u32 tunnel_sw_if_index;
2186 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2188 rv = vnet_mpls_ethernet_add_del_tunnel
2189 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2190 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2191 ntohl (mp->tx_sw_if_index),
2192 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2197 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2199 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2205 * This piece of misery brought to you because the control-plane
2206 * can't figure out the tx interface + dst-mac address all by itself
2208 static int mpls_ethernet_add_del_tunnel_2_t_handler
2209 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2211 pending_route_t *pr;
2212 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2213 vnet_main_t *vnm = vnet_get_main ();
2214 vlib_main_t *vm = vlib_get_main ();
2215 stats_main_t *sm = &stats_main;
2216 vpe_api_main_t *vam = &vpe_api_main;
2217 u32 inner_fib_index, outer_fib_index;
2218 ip4_main_t *im = &ip4_main;
2219 ip_lookup_main_t *lm = &im->lookup_main;
2220 ip_adjacency_t *adj = 0;
2223 u8 *dst_mac_address;
2227 u32 tunnel_sw_if_index;
2229 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2231 return VNET_API_ERROR_NO_SUCH_FIB;
2233 outer_fib_index = p[0];
2236 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2238 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2240 inner_fib_index = p[0];
2242 if (inner_fib_index == outer_fib_index)
2243 return VNET_API_ERROR_INVALID_VALUE;
2246 lookup_result = ip4_fib_table_lookup_lb (ip4_fib_get (outer_fib_index),
2248 mp->next_hop_ip4_address_in_outer_vrf);
2250 adj = ip_get_adjacency (lm, lookup_result);
2251 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2253 if (mp->is_add && mp->resolve_if_needed)
2255 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2257 pool_get (vam->pending_routes, pr);
2258 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2260 clib_memcpy (pme, mp, sizeof (*pme));
2261 /* recursion block, "just in case" */
2262 pme->resolve_if_needed = 0;
2263 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2264 pme->resolve_opaque = tx_sw_if_index;
2265 vnet_register_ip4_arp_resolution_event
2267 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2268 vpe_resolver_process_node.index,
2269 RESOLUTION_EVENT, pr - vam->pending_routes);
2271 vlib_process_signal_event
2272 (vm, vpe_resolver_process_node.index,
2273 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2275 /* The interface may be down, etc. */
2276 e = ip4_probe_neighbor
2277 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2281 clib_error_report (e);
2283 return VNET_API_ERROR_IN_PROGRESS;
2287 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2288 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2291 vnet_rewrite_get_data_internal
2292 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2294 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2296 rv = vnet_mpls_ethernet_add_del_tunnel
2297 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2298 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2299 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2307 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2308 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2310 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2313 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2315 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2320 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2322 vl_api_mpls_add_del_encap_reply_t *rmp;
2327 vec_reset_length (labels);
2329 for (i = 0; i < mp->nlabels; i++)
2330 vec_add1 (labels, ntohl (mp->labels[i]));
2333 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2334 ntohl (mp->vrf_id), labels,
2335 ~0 /* policy_tunnel_index */ ,
2336 0 /* no_dst_hash */ ,
2340 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2344 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2346 vl_api_mpls_add_del_decap_reply_t *rmp;
2349 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2350 ntohl (mp->label), ntohl (mp->next_index),
2351 mp->s_bit, mp->is_add);
2353 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2357 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2359 vl_api_proxy_arp_add_del_reply_t *rmp;
2362 ip4_main_t *im = &ip4_main;
2363 stats_main_t *sm = &stats_main;
2364 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2365 ip4_address_t * hi_addr,
2366 u32 fib_index, int is_del);
2369 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2371 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2375 rv = VNET_API_ERROR_NO_SUCH_FIB;
2381 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2382 (ip4_address_t *) mp->hi_address,
2383 fib_index, mp->is_add == 0);
2387 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2391 vl_api_proxy_arp_intfc_enable_disable_t_handler
2392 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2395 vnet_main_t *vnm = vnet_get_main ();
2396 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2397 vnet_sw_interface_t *si;
2400 VALIDATE_SW_IF_INDEX (mp);
2402 sw_if_index = ntohl (mp->sw_if_index);
2404 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2406 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2410 si = vnet_get_sw_interface (vnm, sw_if_index);
2414 if (mp->enable_disable)
2415 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2417 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2419 BAD_SW_IF_INDEX_LABEL;
2422 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2426 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2429 vl_api_ip_neighbor_add_del_reply_t *rmp;
2430 vnet_main_t *vnm = vnet_get_main ();
2431 stats_main_t *sm = &stats_main;
2434 VALIDATE_SW_IF_INDEX (mp);
2436 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2439 * there's no validation here of the ND/ARP entry being added.
2440 * The expectation is that the FIB will ensure that nothing bad
2441 * will come of adding bogus entries.
2446 rv = vnet_set_ip6_ethernet_neighbor
2447 (vm, ntohl (mp->sw_if_index),
2448 (ip6_address_t *) (mp->dst_address),
2449 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2451 rv = vnet_unset_ip6_ethernet_neighbor
2452 (vm, ntohl (mp->sw_if_index),
2453 (ip6_address_t *) (mp->dst_address),
2454 mp->mac_address, sizeof (mp->mac_address));
2458 ethernet_arp_ip4_over_ethernet_address_t a;
2460 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2461 clib_memcpy (&a.ip4, mp->dst_address, 4);
2464 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2468 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2471 BAD_SW_IF_INDEX_LABEL;
2474 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2478 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2481 vpe_main_t *rm = &vpe_main;
2482 ip4_main_t *im4 = &ip4_main;
2483 ip6_main_t *im6 = &ip6_main;
2484 ip_lookup_main_t *lm;
2490 u32 adj_index, sw_if_index;
2491 vl_api_is_address_reachable_t *rmp;
2492 ip_adjacency_t *adj;
2493 unix_shared_memory_queue_t *q;
2495 q = vl_api_client_index_to_input_queue (mp->client_index);
2498 increment_missing_api_client_counter (rm->vlib_main);
2502 rmp = vl_msg_api_alloc (sizeof (*rmp));
2503 clib_memcpy (rmp, mp, sizeof (*rmp));
2505 sw_if_index = mp->next_hop_sw_if_index;
2506 clib_memcpy (&addr, mp->address, sizeof (addr));
2509 lm = &im6->lookup_main;
2510 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2514 lm = &im4->lookup_main;
2516 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2518 if (adj_index == ~0)
2523 adj = ip_get_adjacency (lm, adj_index);
2525 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2526 && adj->rewrite_header.sw_if_index == sw_if_index)
2532 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2533 && adj->rewrite_header.sw_if_index == sw_if_index)
2536 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2538 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2540 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2549 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2554 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2556 clib_warning ("BUG");
2560 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2562 vl_api_sw_interface_set_flags_reply_t *rmp;
2563 vnet_main_t *vnm = vnet_get_main ();
2565 clib_error_t *error;
2568 VALIDATE_SW_IF_INDEX (mp);
2570 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2572 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2576 clib_error_report (error);
2579 BAD_SW_IF_INDEX_LABEL;
2580 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2584 vl_api_sw_interface_set_mpls_enable_t_handler
2585 (vl_api_sw_interface_set_mpls_enable_t * mp)
2587 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2590 VALIDATE_SW_IF_INDEX (mp);
2592 mpls_sw_interface_enable_disable (&mpls_main,
2593 ntohl (mp->sw_if_index), mp->enable);
2595 BAD_SW_IF_INDEX_LABEL;
2596 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2600 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2603 vl_api_sw_interface_clear_stats_reply_t *rmp;
2605 vnet_main_t *vnm = vnet_get_main ();
2606 vnet_interface_main_t *im = &vnm->interface_main;
2607 vlib_simple_counter_main_t *sm;
2608 vlib_combined_counter_main_t *cm;
2609 static vnet_main_t **my_vnet_mains;
2610 int i, j, n_counters;
2613 if (mp->sw_if_index != ~0)
2614 VALIDATE_SW_IF_INDEX (mp);
2616 vec_reset_length (my_vnet_mains);
2618 for (i = 0; i < vec_len (vnet_mains); i++)
2621 vec_add1 (my_vnet_mains, vnet_mains[i]);
2624 if (vec_len (vnet_mains) == 0)
2625 vec_add1 (my_vnet_mains, vnm);
2627 n_counters = vec_len (im->combined_sw_if_counters);
2629 for (j = 0; j < n_counters; j++)
2631 for (i = 0; i < vec_len (my_vnet_mains); i++)
2633 im = &my_vnet_mains[i]->interface_main;
2634 cm = im->combined_sw_if_counters + j;
2635 if (mp->sw_if_index == (u32) ~ 0)
2636 vlib_clear_combined_counters (cm);
2638 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2642 n_counters = vec_len (im->sw_if_counters);
2644 for (j = 0; j < n_counters; j++)
2646 for (i = 0; i < vec_len (my_vnet_mains); i++)
2648 im = &my_vnet_mains[i]->interface_main;
2649 sm = im->sw_if_counters + j;
2650 if (mp->sw_if_index == (u32) ~ 0)
2651 vlib_clear_simple_counters (sm);
2653 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2657 BAD_SW_IF_INDEX_LABEL;
2659 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2663 send_sw_interface_details (vpe_api_main_t * am,
2664 unix_shared_memory_queue_t * q,
2665 vnet_sw_interface_t * swif,
2666 u8 * interface_name, u32 context)
2668 vl_api_sw_interface_details_t *mp;
2669 vnet_hw_interface_t *hi;
2671 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2673 mp = vl_msg_api_alloc (sizeof (*mp));
2674 memset (mp, 0, sizeof (*mp));
2675 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2676 mp->sw_if_index = ntohl (swif->sw_if_index);
2677 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2678 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2679 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2680 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2681 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2682 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2683 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2684 mp->link_mtu = ntohs (hi->max_packet_bytes);
2685 mp->context = context;
2687 strncpy ((char *) mp->interface_name,
2688 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2690 /* Send the L2 address for ethernet physical intfcs */
2691 if (swif->sup_sw_if_index == swif->sw_if_index
2692 && hi->hw_class_index == ethernet_hw_interface_class.index)
2694 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2695 ethernet_interface_t *ei;
2697 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2698 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2699 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2700 mp->l2_address_length = ntohl (sizeof (ei->address));
2702 else if (swif->sup_sw_if_index != swif->sw_if_index)
2704 vnet_sub_interface_t *sub = &swif->sub;
2705 mp->sub_id = ntohl (sub->id);
2706 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2707 mp->sub_number_of_tags =
2708 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2709 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2710 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2711 mp->sub_exact_match = sub->eth.flags.exact_match;
2712 mp->sub_default = sub->eth.flags.default_sub;
2713 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2714 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2716 /* vlan tag rewrite data */
2717 u32 vtr_op = L2_VTR_DISABLED;
2718 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2720 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2721 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2723 // error - default to disabled
2724 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2725 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2730 mp->vtr_op = ntohl (vtr_op);
2731 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2732 mp->vtr_tag1 = ntohl (vtr_tag1);
2733 mp->vtr_tag2 = ntohl (vtr_tag2);
2737 vl_msg_api_send_shmem (q, (u8 *) & mp);
2741 send_sw_interface_flags (vpe_api_main_t * am,
2742 unix_shared_memory_queue_t * q,
2743 vnet_sw_interface_t * swif)
2745 vl_api_sw_interface_set_flags_t *mp;
2746 vnet_main_t *vnm = am->vnet_main;
2748 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2750 mp = vl_msg_api_alloc (sizeof (*mp));
2751 memset (mp, 0, sizeof (*mp));
2752 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2753 mp->sw_if_index = ntohl (swif->sw_if_index);
2755 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2756 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2757 vl_msg_api_send_shmem (q, (u8 *) & mp);
2760 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2761 unix_shared_memory_queue_t * q,
2763 __attribute__ ((unused));
2766 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2767 unix_shared_memory_queue_t * q,
2770 vl_api_sw_interface_set_flags_t *mp;
2772 mp = vl_msg_api_alloc (sizeof (*mp));
2773 memset (mp, 0, sizeof (*mp));
2774 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2775 mp->sw_if_index = ntohl (sw_if_index);
2777 mp->admin_up_down = 0;
2778 mp->link_up_down = 0;
2780 vl_msg_api_send_shmem (q, (u8 *) & mp);
2784 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2786 vpe_api_main_t *am = &vpe_api_main;
2787 vnet_sw_interface_t *swif;
2788 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2789 u8 *filter_string = 0, *name_string = 0;
2790 unix_shared_memory_queue_t *q;
2791 char *strcasestr (char *, char *); /* lnx hdr file botch */
2793 q = vl_api_client_index_to_input_queue (mp->client_index);
2798 if (mp->name_filter_valid)
2800 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2801 filter_string = format (0, "%s%c", mp->name_filter, 0);
2805 pool_foreach (swif, im->sw_interfaces,
2807 name_string = format (name_string, "%U%c",
2808 format_vnet_sw_interface_name,
2809 am->vnet_main, swif, 0);
2811 if (mp->name_filter_valid == 0 ||
2812 strcasestr((char *) name_string, (char *) filter_string)) {
2814 send_sw_interface_details (am, q, swif, name_string, mp->context);
2816 _vec_len (name_string) = 0;
2820 vec_free (name_string);
2821 vec_free (filter_string);
2825 send_oam_event (oam_target_t * t)
2827 vpe_api_main_t *vam = &vpe_api_main;
2828 unix_shared_memory_queue_t *q;
2829 vpe_client_registration_t *reg;
2830 vl_api_oam_event_t *mp;
2833 pool_foreach(reg, vam->oam_events_registrations,
2835 q = vl_api_client_index_to_input_queue (reg->client_index);
2838 mp = vl_msg_api_alloc (sizeof (*mp));
2839 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2840 clib_memcpy (mp->dst_address, &t->dst_address,
2841 sizeof (mp->dst_address));
2842 mp->state = t->state;
2843 vl_msg_api_send_shmem (q, (u8 *)&mp);
2850 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2852 vl_api_oam_add_del_reply_t *rmp;
2855 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2856 (ip4_address_t *) mp->dst_address,
2857 ntohl (mp->vrf_id), (int) (mp->is_add));
2859 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2863 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2865 stats_main_t *sm = &stats_main;
2866 vnet_interface_main_t *im = sm->interface_main;
2867 vl_api_vnet_summary_stats_reply_t *rmp;
2868 vlib_combined_counter_main_t *cm;
2871 u64 total_pkts[VLIB_N_RX_TX];
2872 u64 total_bytes[VLIB_N_RX_TX];
2874 unix_shared_memory_queue_t *q =
2875 vl_api_client_index_to_input_queue (mp->client_index);
2880 rmp = vl_msg_api_alloc (sizeof (*rmp));
2881 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2882 rmp->context = mp->context;
2885 memset (total_pkts, 0, sizeof (total_pkts));
2886 memset (total_bytes, 0, sizeof (total_bytes));
2888 vnet_interface_counter_lock (im);
2890 vec_foreach (cm, im->combined_sw_if_counters)
2892 which = cm - im->combined_sw_if_counters;
2894 for (i = 0; i < vec_len (cm->maxi); i++)
2896 vlib_get_combined_counter (cm, i, &v);
2897 total_pkts[which] += v.packets;
2898 total_bytes[which] += v.bytes;
2901 vnet_interface_counter_unlock (im);
2903 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2904 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2905 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2906 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2908 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2910 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2914 typedef CLIB_PACKED (struct {
2915 ip4_address_t address;
2916 u32 address_length: 6;
2922 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2924 vnet_main_t *vnm = vnet_get_main ();
2925 vnet_interface_main_t *im = &vnm->interface_main;
2926 ip4_main_t *im4 = &ip4_main;
2927 static u32 *sw_if_indices_to_shut;
2928 stats_main_t *sm = &stats_main;
2929 fib_table_t *fib_table;
2933 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2934 u32 target_fib_id = ntohl (mp->vrf_id);
2936 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2939 pool_foreach (fib_table, im4->fibs,
2941 fib = &fib_table->v4;
2942 vnet_sw_interface_t * si;
2944 if (fib->table_id != target_fib_id)
2947 /* remove any mpls/gre tunnels in this fib */
2948 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2950 /* remove any mpls encap/decap labels */
2951 mpls_fib_reset_labels (fib->table_id);
2953 /* remove any proxy arps in this fib */
2954 vnet_proxy_arp_fib_reset (fib->table_id);
2956 /* Set the flow hash for this fib to the default */
2957 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2959 vec_reset_length (sw_if_indices_to_shut);
2961 /* Shut down interfaces in this FIB / clean out intfc routes */
2962 pool_foreach (si, im->sw_interfaces,
2964 u32 sw_if_index = si->sw_if_index;
2966 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2967 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2969 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2972 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2973 sw_if_index = sw_if_indices_to_shut[i];
2974 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2976 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2977 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2978 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2981 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
2982 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
2986 })); /* pool_foreach (fib) */
2994 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2996 vnet_main_t *vnm = vnet_get_main ();
2997 vnet_interface_main_t *im = &vnm->interface_main;
2998 ip6_main_t *im6 = &ip6_main;
2999 stats_main_t *sm = &stats_main;
3000 static u32 *sw_if_indices_to_shut;
3001 fib_table_t *fib_table;
3005 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3006 u32 target_fib_id = ntohl (mp->vrf_id);
3008 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3011 pool_foreach (fib_table, im6->fibs,
3013 vnet_sw_interface_t * si;
3014 fib = &(fib_table->v6);
3016 if (fib->table_id != target_fib_id)
3019 vec_reset_length (sw_if_indices_to_shut);
3021 /* Shut down interfaces in this FIB / clean out intfc routes */
3022 pool_foreach (si, im->sw_interfaces,
3024 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3026 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3029 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
3030 sw_if_index = sw_if_indices_to_shut[i];
3031 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3033 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3034 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3035 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3038 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
3039 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
3043 })); /* pool_foreach (fib) */
3051 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3054 vl_api_reset_fib_reply_t *rmp;
3057 rv = ip6_reset_fib_t_handler (mp);
3059 rv = ip4_reset_fib_t_handler (mp);
3061 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3066 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3068 vl_api_dhcp_proxy_config_reply_t *rmp;
3071 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3072 (ip4_address_t *) (&mp->dhcp_src_address),
3073 (u32) ntohl (mp->vrf_id),
3074 (int) mp->insert_circuit_id,
3075 (int) (mp->is_add == 0));
3077 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3082 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3084 vl_api_dhcp_proxy_config_reply_t *rmp;
3087 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3088 (ip6_address_t *) (&mp->dhcp_src_address),
3089 (u32) ntohl (mp->vrf_id),
3090 (int) mp->insert_circuit_id,
3091 (int) (mp->is_add == 0));
3093 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3097 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3099 vl_api_dhcp_proxy_config_reply_t *rmp;
3102 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3103 (ip4_address_t *) (&mp->dhcp_src_address),
3104 (u32) ntohl (mp->rx_vrf_id),
3105 (u32) ntohl (mp->server_vrf_id),
3106 (int) mp->insert_circuit_id,
3107 (int) (mp->is_add == 0));
3109 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3114 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3116 vl_api_dhcp_proxy_config_reply_t *rmp;
3120 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3121 (ip6_address_t *) (&mp->dhcp_src_address),
3122 (u32) ntohl (mp->rx_vrf_id),
3123 (u32) ntohl (mp->server_vrf_id),
3124 (int) mp->insert_circuit_id,
3125 (int) (mp->is_add == 0));
3127 rv = VNET_API_ERROR_UNIMPLEMENTED;
3130 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3135 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3137 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3140 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3143 (int) mp->is_add == 0);
3145 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3147 ntohl (mp->fib_id), (int) mp->is_add == 0);
3149 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3153 static void vl_api_dhcp_proxy_config_t_handler
3154 (vl_api_dhcp_proxy_config_t * mp)
3156 if (mp->is_ipv6 == 0)
3157 dhcpv4_proxy_config (mp);
3159 dhcpv6_proxy_config (mp);
3162 static void vl_api_dhcp_proxy_config_2_t_handler
3163 (vl_api_dhcp_proxy_config_2_t * mp)
3165 if (mp->is_ipv6 == 0)
3166 dhcpv4_proxy_config_2 (mp);
3168 dhcpv6_proxy_config_2 (mp);
3172 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3173 u8 is_ipv6, u8 * host_address, u8 * router_address,
3176 unix_shared_memory_queue_t *q;
3177 vl_api_dhcp_compl_event_t *mp;
3179 q = vl_api_client_index_to_input_queue (client_index);
3183 mp = vl_msg_api_alloc (sizeof (*mp));
3184 mp->client_index = client_index;
3186 mp->is_ipv6 = is_ipv6;
3187 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3188 mp->hostname[vec_len (hostname) + 1] = '\n';
3189 clib_memcpy (&mp->host_address[0], host_address, 16);
3190 clib_memcpy (&mp->router_address[0], router_address, 16);
3191 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3193 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3195 vl_msg_api_send_shmem (q, (u8 *) & mp);
3198 static void vl_api_dhcp_client_config_t_handler
3199 (vl_api_dhcp_client_config_t * mp)
3201 vlib_main_t *vm = vlib_get_main ();
3202 vl_api_dhcp_client_config_reply_t *rmp;
3205 VALIDATE_SW_IF_INDEX (mp);
3207 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3208 mp->hostname, mp->is_add, mp->client_index,
3209 mp->want_dhcp_event ? dhcp_compl_event_callback :
3212 BAD_SW_IF_INDEX_LABEL;
3214 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3218 vl_api_sw_interface_ip6nd_ra_config_t_handler
3219 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3221 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3223 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3226 is_no = mp->is_no == 1;
3227 suppress = mp->suppress == 1;
3228 managed = mp->managed == 1;
3229 other = mp->other == 1;
3230 ll_option = mp->ll_option == 1;
3231 send_unicast = mp->send_unicast == 1;
3232 cease = mp->cease == 1;
3233 default_router = mp->default_router == 1;
3235 VALIDATE_SW_IF_INDEX (mp);
3237 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3238 suppress, managed, other,
3239 ll_option, send_unicast, cease,
3240 default_router, ntohl (mp->lifetime),
3241 ntohl (mp->initial_count),
3242 ntohl (mp->initial_interval),
3243 ntohl (mp->max_interval),
3244 ntohl (mp->min_interval), is_no);
3246 BAD_SW_IF_INDEX_LABEL;
3248 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3252 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3253 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3255 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3257 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3259 VALIDATE_SW_IF_INDEX (mp);
3261 is_no = mp->is_no == 1;
3262 use_default = mp->use_default == 1;
3263 no_advertise = mp->no_advertise == 1;
3264 off_link = mp->off_link == 1;
3265 no_autoconfig = mp->no_autoconfig == 1;
3266 no_onlink = mp->no_onlink == 1;
3268 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3269 (ip6_address_t *) mp->address,
3270 mp->address_length, use_default,
3271 ntohl (mp->val_lifetime),
3272 ntohl (mp->pref_lifetime), no_advertise,
3273 off_link, no_autoconfig, no_onlink, is_no);
3275 BAD_SW_IF_INDEX_LABEL;
3276 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3280 vl_api_sw_interface_ip6_enable_disable_t_handler
3281 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3283 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3284 vnet_main_t *vnm = vnet_get_main ();
3286 clib_error_t *error;
3290 VALIDATE_SW_IF_INDEX (mp);
3293 (mp->enable == 1) ? enable_ip6_interface (vm,
3294 ntohl (mp->sw_if_index)) :
3295 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3299 clib_error_report (error);
3300 rv = VNET_API_ERROR_UNSPECIFIED;
3304 rv = vnm->api_errno;
3307 BAD_SW_IF_INDEX_LABEL;
3309 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3313 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3314 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3316 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3318 clib_error_t *error;
3319 vnet_main_t *vnm = vnet_get_main ();
3323 VALIDATE_SW_IF_INDEX (mp);
3325 error = set_ip6_link_local_address (vm,
3326 ntohl (mp->sw_if_index),
3327 (ip6_address_t *) mp->address,
3328 mp->address_length);
3331 clib_error_report (error);
3332 rv = VNET_API_ERROR_UNSPECIFIED;
3336 rv = vnm->api_errno;
3339 BAD_SW_IF_INDEX_LABEL;
3341 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3345 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3347 vl_api_set_ip_flow_hash_reply_t *rmp;
3348 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3350 clib_warning ("unimplemented...");
3352 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3356 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3358 vl_api_set_ip_flow_hash_reply_t *rmp;
3361 flow_hash_config_t flow_hash_config = 0;
3363 table_id = ntohl (mp->vrf_id);
3365 #define _(a,b) if (mp->a) flow_hash_config |= b;
3366 foreach_flow_hash_bit;
3369 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3371 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3376 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3378 if (mp->is_ipv6 == 0)
3379 set_ip4_flow_hash (mp);
3381 set_ip6_flow_hash (mp);
3384 static void vl_api_sw_interface_set_unnumbered_t_handler
3385 (vl_api_sw_interface_set_unnumbered_t * mp)
3387 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3389 vnet_sw_interface_t *si;
3390 vnet_main_t *vnm = vnet_get_main ();
3391 u32 sw_if_index, unnumbered_sw_if_index;
3393 sw_if_index = ntohl (mp->sw_if_index);
3394 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3397 * The API message field names are backwards from
3398 * the underlying data structure names.
3399 * It's not worth changing them now.
3401 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3402 unnumbered_sw_if_index))
3404 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3408 /* Only check the "use loop0" field when setting the binding */
3410 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3412 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3416 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3420 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3421 si->unnumbered_sw_if_index = sw_if_index;
3422 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3423 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
3427 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3428 si->unnumbered_sw_if_index = (u32) ~ 0;
3429 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3430 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
3434 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3438 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3440 vl_api_create_loopback_reply_t *rmp;
3444 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3447 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3449 rmp->sw_if_index = ntohl (sw_if_index);
3455 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3457 vl_api_delete_loopback_reply_t *rmp;
3461 sw_if_index = ntohl (mp->sw_if_index);
3462 rv = vnet_delete_loopback_interface (sw_if_index);
3464 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3468 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3470 vl_api_control_ping_reply_t *rmp;
3474 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3476 rmp->vpe_pid = ntohl (getpid());
3482 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3484 u8 **shmem_vecp = (u8 **) arg;
3487 api_main_t *am = &api_main;
3490 shmem_vec = *shmem_vecp;
3492 offset = vec_len (shmem_vec);
3494 pthread_mutex_lock (&am->vlib_rp->mutex);
3495 oldheap = svm_push_data_heap (am->vlib_rp);
3497 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3499 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3501 svm_pop_heap (oldheap);
3502 pthread_mutex_unlock (&am->vlib_rp->mutex);
3504 *shmem_vecp = shmem_vec;
3509 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3511 vl_api_cli_reply_t *rp;
3512 unix_shared_memory_queue_t *q;
3513 vlib_main_t *vm = vlib_get_main ();
3514 api_main_t *am = &api_main;
3515 unformat_input_t input;
3519 q = vl_api_client_index_to_input_queue (mp->client_index);
3523 rp = vl_msg_api_alloc (sizeof (*rp));
3524 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3525 rp->context = mp->context;
3527 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3529 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3531 pthread_mutex_lock (&am->vlib_rp->mutex);
3532 oldheap = svm_push_data_heap (am->vlib_rp);
3534 vec_add1 (shmem_vec, 0);
3536 svm_pop_heap (oldheap);
3537 pthread_mutex_unlock (&am->vlib_rp->mutex);
3539 rp->reply_in_shmem = (uword) shmem_vec;
3541 vl_msg_api_send_shmem (q, (u8 *) & rp);
3545 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3547 u8 **mem_vecp = (u8 **) arg;
3548 u8 *mem_vec = *mem_vecp;
3549 u32 offset = vec_len (mem_vec);
3551 vec_validate (mem_vec, offset + buffer_bytes - 1);
3552 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3553 *mem_vecp = mem_vec;
3557 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3559 vl_api_cli_inband_reply_t *rmp;
3561 unix_shared_memory_queue_t *q;
3562 vlib_main_t *vm = vlib_get_main ();
3563 unformat_input_t input;
3566 q = vl_api_client_index_to_input_queue (mp->client_index);
3570 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3571 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3573 u32 len = vec_len (out_vec);
3575 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3577 rmp->length = htonl (len);
3578 clib_memcpy (rmp->reply, out_vec, len);
3585 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3588 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3589 vnet_main_t *vnm = vnet_get_main ();
3590 clib_error_t *error;
3595 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3597 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3601 clib_error_report (error);
3602 rv = VNET_API_ERROR_UNSPECIFIED;
3606 rv = vnm->api_errno;
3609 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3612 static void vl_api_sr_tunnel_add_del_t_handler
3613 (vl_api_sr_tunnel_add_del_t * mp)
3616 clib_warning ("unimplemented");
3618 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3620 vl_api_sr_tunnel_add_del_reply_t *rmp;
3621 ip6_address_t *segments = 0, *seg;
3622 ip6_address_t *tags = 0, *tag;
3623 ip6_address_t *this_address;
3626 if (mp->n_segments == 0)
3632 memset (a, 0, sizeof (*a));
3633 a->src_address = (ip6_address_t *) & mp->src_address;
3634 a->dst_address = (ip6_address_t *) & mp->dst_address;
3635 a->dst_mask_width = mp->dst_mask_width;
3636 a->flags_net_byte_order = mp->flags_net_byte_order;
3637 a->is_del = (mp->is_add == 0);
3638 a->rx_table_id = ntohl (mp->outer_vrf_id);
3639 a->tx_table_id = ntohl (mp->inner_vrf_id);
3641 a->name = format (0, "%s", mp->name);
3642 if (!(vec_len (a->name)))
3645 a->policy_name = format (0, "%s", mp->policy_name);
3646 if (!(vec_len (a->policy_name)))
3649 /* Yank segments and tags out of the API message */
3650 this_address = (ip6_address_t *) mp->segs_and_tags;
3651 for (i = 0; i < mp->n_segments; i++)
3653 vec_add2 (segments, seg, 1);
3654 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3657 for (i = 0; i < mp->n_tags; i++)
3659 vec_add2 (tags, tag, 1);
3660 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3664 a->segments = segments;
3667 rv = ip6_sr_add_del_tunnel (a);
3671 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3675 static void vl_api_sr_policy_add_del_t_handler
3676 (vl_api_sr_policy_add_del_t * mp)
3679 clib_warning ("unimplemented");
3681 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3683 vl_api_sr_policy_add_del_reply_t *rmp;
3686 memset (a, 0, sizeof (*a));
3687 a->is_del = (mp->is_add == 0);
3689 a->name = format (0, "%s", mp->name);
3690 if (!(vec_len (a->name)))
3692 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3696 if (!(mp->tunnel_names[0]))
3698 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3702 // start deserializing tunnel_names
3703 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3704 u8 *deser_tun_names = mp->tunnel_names;
3705 deser_tun_names += 1; //moving along
3708 int tun_name_len = 0;
3710 for (i = 0; i < num_tunnels; i++)
3712 tun_name_len = *deser_tun_names;
3713 deser_tun_names += 1;
3714 vec_resize (tun_name, tun_name_len);
3715 memcpy (tun_name, deser_tun_names, tun_name_len);
3716 vec_add1 (a->tunnel_names, tun_name);
3717 deser_tun_names += tun_name_len;
3721 rv = ip6_sr_add_del_policy (a);
3725 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3729 static void vl_api_sr_multicast_map_add_del_t_handler
3730 (vl_api_sr_multicast_map_add_del_t * mp)
3733 clib_warning ("unimplemented");
3735 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3737 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3739 memset (a, 0, sizeof (*a));
3740 a->is_del = (mp->is_add == 0);
3742 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3743 a->policy_name = format (0, "%s", mp->policy_name);
3745 if (a->multicast_address == 0)
3751 if (!(a->policy_name))
3757 #if DPDK > 0 /* Cannot call replicate without DPDK */
3758 rv = ip6_sr_add_del_multicastmap (a);
3760 clib_warning ("multicast replication without DPDK not implemented");
3761 rv = VNET_API_ERROR_UNIMPLEMENTED;
3766 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3770 #define foreach_classify_add_del_table_field \
3775 _(match_n_vectors) \
3776 _(next_table_index) \
3779 static void vl_api_classify_add_del_table_t_handler
3780 (vl_api_classify_add_del_table_t * mp)
3782 vl_api_classify_add_del_table_reply_t *rmp;
3783 vnet_classify_main_t *cm = &vnet_classify_main;
3784 vnet_classify_table_t *t;
3788 foreach_classify_add_del_table_field;
3791 #define _(a) a = ntohl(mp->a);
3792 foreach_classify_add_del_table_field;
3795 /* The underlying API fails silently, on purpose, so check here */
3796 if (mp->is_add == 0)
3797 if (pool_is_free_index (cm->tables, table_index))
3799 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3803 rv = vnet_classify_add_del_table
3804 (cm, mp->mask, nbuckets, memory_size,
3805 skip_n_vectors, match_n_vectors,
3806 next_table_index, miss_next_index, &table_index, mp->is_add);
3810 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3812 if (rv == 0 && mp->is_add)
3814 t = pool_elt_at_index (cm->tables, table_index);
3815 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3816 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3817 rmp->new_table_index = ntohl(table_index);
3821 rmp->skip_n_vectors = ~0;
3822 rmp->match_n_vectors = ~0;
3823 rmp->new_table_index = ~0;
3829 static void vl_api_classify_add_del_session_t_handler
3830 (vl_api_classify_add_del_session_t * mp)
3832 vnet_classify_main_t *cm = &vnet_classify_main;
3833 vl_api_classify_add_del_session_reply_t *rmp;
3835 u32 table_index, hit_next_index, opaque_index;
3838 table_index = ntohl (mp->table_index);
3839 hit_next_index = ntohl (mp->hit_next_index);
3840 opaque_index = ntohl (mp->opaque_index);
3841 advance = ntohl (mp->advance);
3843 rv = vnet_classify_add_del_session
3844 (cm, table_index, mp->match, hit_next_index, opaque_index,
3845 advance, mp->is_add);
3847 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3850 static void vl_api_classify_set_interface_ip_table_t_handler
3851 (vl_api_classify_set_interface_ip_table_t * mp)
3853 vlib_main_t *vm = vlib_get_main ();
3854 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3856 u32 table_index, sw_if_index;
3858 table_index = ntohl (mp->table_index);
3859 sw_if_index = ntohl (mp->sw_if_index);
3861 VALIDATE_SW_IF_INDEX (mp);
3864 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3866 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3868 BAD_SW_IF_INDEX_LABEL;
3870 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3873 static void vl_api_classify_set_interface_l2_tables_t_handler
3874 (vl_api_classify_set_interface_l2_tables_t * mp)
3876 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3878 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3881 ip4_table_index = ntohl (mp->ip4_table_index);
3882 ip6_table_index = ntohl (mp->ip6_table_index);
3883 other_table_index = ntohl (mp->other_table_index);
3884 sw_if_index = ntohl (mp->sw_if_index);
3886 VALIDATE_SW_IF_INDEX (mp);
3889 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
3893 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
3899 if (ip4_table_index != ~0 || ip6_table_index != ~0
3900 || other_table_index != ~0)
3906 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
3908 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
3911 BAD_SW_IF_INDEX_LABEL;
3913 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3917 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3920 vl_api_l2_fib_clear_table_reply_t *rmp;
3922 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3923 * that is not currently implemented. When that TODO is fixed
3924 * this call should be changed to pass 1 instead of 0.
3926 l2fib_clear_table (0);
3928 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3931 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3932 u32 sw_if_index, u32 enable);
3935 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3939 vl_api_l2_interface_efp_filter_reply_t *rmp;
3940 vnet_main_t *vnm = vnet_get_main ();
3942 // enable/disable the feature
3943 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3944 rv = vnm->api_errno;
3946 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3950 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3951 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3954 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3955 vnet_main_t *vnm = vnet_get_main ();
3956 vlib_main_t *vm = vlib_get_main ();
3959 VALIDATE_SW_IF_INDEX (mp);
3961 vtr_op = ntohl (mp->vtr_op);
3963 /* The L2 code is unsuspicious */
3966 case L2_VTR_DISABLED:
3971 case L2_VTR_TRANSLATE_1_1:
3972 case L2_VTR_TRANSLATE_1_2:
3973 case L2_VTR_TRANSLATE_2_1:
3974 case L2_VTR_TRANSLATE_2_2:
3978 rv = VNET_API_ERROR_INVALID_VALUE;
3979 goto bad_sw_if_index;
3982 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
3983 ntohl (mp->push_dot1q), ntohl (mp->tag1),
3986 BAD_SW_IF_INDEX_LABEL;
3988 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3992 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
3995 vl_api_create_vhost_user_if_reply_t *rmp;
3996 u32 sw_if_index = (u32) ~ 0;
3998 vnet_main_t *vnm = vnet_get_main ();
3999 vlib_main_t *vm = vlib_get_main ();
4001 #if DPDK > 0 && DPDK_VHOST_USER
4002 rv = dpdk_vhost_user_create_if (
4004 rv = vhost_user_create_if (
4006 vnm, vm, (char *) mp->sock_filename,
4007 mp->is_server, &sw_if_index, (u64) ~ 0,
4008 mp->renumber, ntohl (mp->custom_dev_instance),
4009 (mp->use_custom_mac) ? mp->mac_address : NULL);
4012 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4014 rmp->sw_if_index = ntohl (sw_if_index);
4020 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4023 vl_api_modify_vhost_user_if_reply_t *rmp;
4024 u32 sw_if_index = ntohl (mp->sw_if_index);
4026 vnet_main_t *vnm = vnet_get_main ();
4027 vlib_main_t *vm = vlib_get_main ();
4029 #if DPDK > 0 && DPDK_VHOST_USER
4030 rv = dpdk_vhost_user_modify_if (
4032 rv = vhost_user_modify_if (
4034 vnm, vm, (char *) mp->sock_filename,
4035 mp->is_server, sw_if_index, (u64) ~ 0,
4036 mp->renumber, ntohl (mp->custom_dev_instance));
4037 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4041 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4044 vl_api_delete_vhost_user_if_reply_t *rmp;
4045 vpe_api_main_t *vam = &vpe_api_main;
4046 u32 sw_if_index = ntohl (mp->sw_if_index);
4048 vnet_main_t *vnm = vnet_get_main ();
4049 vlib_main_t *vm = vlib_get_main ();
4051 #if DPDK > 0 && DPDK_VHOST_USER
4052 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4054 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4057 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4060 unix_shared_memory_queue_t *q =
4061 vl_api_client_index_to_input_queue (mp->client_index);
4065 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4070 vl_api_sw_interface_vhost_user_details_t_handler
4071 (vl_api_sw_interface_vhost_user_details_t * mp)
4073 clib_warning ("BUG");
4077 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4078 unix_shared_memory_queue_t * q,
4079 vhost_user_intf_details_t * vui,
4082 vl_api_sw_interface_vhost_user_details_t *mp;
4084 mp = vl_msg_api_alloc (sizeof (*mp));
4085 memset (mp, 0, sizeof (*mp));
4086 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4087 mp->sw_if_index = ntohl (vui->sw_if_index);
4088 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4089 mp->features = clib_net_to_host_u64 (vui->features);
4090 mp->is_server = vui->is_server;
4091 mp->num_regions = ntohl (vui->num_regions);
4092 mp->sock_errno = ntohl (vui->sock_errno);
4093 mp->context = context;
4095 strncpy ((char *) mp->sock_filename,
4096 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4097 strncpy ((char *) mp->interface_name,
4098 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4100 vl_msg_api_send_shmem (q, (u8 *) & mp);
4104 vl_api_sw_interface_vhost_user_dump_t_handler
4105 (vl_api_sw_interface_vhost_user_dump_t * mp)
4108 vpe_api_main_t *am = &vpe_api_main;
4109 vnet_main_t *vnm = vnet_get_main ();
4110 vlib_main_t *vm = vlib_get_main ();
4111 vhost_user_intf_details_t *ifaces = NULL;
4112 vhost_user_intf_details_t *vuid = NULL;
4113 unix_shared_memory_queue_t *q;
4115 q = vl_api_client_index_to_input_queue (mp->client_index);
4119 #if DPDK > 0 && DPDK_VHOST_USER
4120 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4122 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4127 vec_foreach (vuid, ifaces)
4129 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4135 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4136 unix_shared_memory_queue_t * q,
4138 l2t_main_t * lm, u32 context)
4140 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4142 vnet_sw_interface_t *si = NULL;
4144 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4146 if_name = format (if_name, "%U",
4147 format_vnet_sw_interface_name, lm->vnet_main, si);
4149 mp = vl_msg_api_alloc (sizeof (*mp));
4150 memset (mp, 0, sizeof (*mp));
4151 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4152 strncpy ((char *) mp->interface_name,
4153 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4154 mp->sw_if_index = ntohl (si->sw_if_index);
4155 mp->local_session_id = s->local_session_id;
4156 mp->remote_session_id = s->remote_session_id;
4157 mp->local_cookie[0] = s->local_cookie[0];
4158 mp->local_cookie[1] = s->local_cookie[1];
4159 mp->remote_cookie = s->remote_cookie;
4160 clib_memcpy (mp->client_address, &s->client_address,
4161 sizeof (s->client_address));
4162 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4163 mp->l2_sublayer_present = s->l2_sublayer_present;
4164 mp->context = context;
4166 vl_msg_api_send_shmem (q, (u8 *) & mp);
4170 send_ip_address_details (vpe_api_main_t * am,
4171 unix_shared_memory_queue_t * q,
4172 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4174 vl_api_ip_address_details_t *mp;
4176 mp = vl_msg_api_alloc (sizeof (*mp));
4177 memset (mp, 0, sizeof (*mp));
4178 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4182 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4186 u32 *tp = (u32 *) mp->ip;
4187 *tp = ntohl (*(u32 *) ip);
4189 mp->prefix_length = prefix_length;
4190 mp->context = context;
4192 vl_msg_api_send_shmem (q, (u8 *) & mp);
4196 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4198 vpe_api_main_t *am = &vpe_api_main;
4199 unix_shared_memory_queue_t *q;
4202 ip6_main_t *im6 = &ip6_main;
4203 ip4_main_t *im4 = &ip4_main;
4204 ip_lookup_main_t *lm6 = &im6->lookup_main;
4205 ip_lookup_main_t *lm4 = &im4->lookup_main;
4206 ip_interface_address_t *ia = 0;
4207 u32 sw_if_index = ~0;
4208 int rv __attribute__ ((unused)) = 0;
4210 VALIDATE_SW_IF_INDEX (mp);
4212 sw_if_index = ntohl (mp->sw_if_index);
4214 q = vl_api_client_index_to_input_queue (mp->client_index);
4223 foreach_ip_interface_address (lm6, ia, sw_if_index,
4224 1 /* honor unnumbered */,
4226 r6 = ip_interface_address_get_address (lm6, ia);
4227 u16 prefix_length = ia->address_length;
4228 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4235 foreach_ip_interface_address (lm4, ia, sw_if_index,
4236 1 /* honor unnumbered */,
4238 r4 = ip_interface_address_get_address (lm4, ia);
4239 u16 prefix_length = ia->address_length;
4240 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4244 BAD_SW_IF_INDEX_LABEL;
4248 send_ip_details (vpe_api_main_t * am,
4249 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4251 vl_api_ip_details_t *mp;
4253 mp = vl_msg_api_alloc (sizeof (*mp));
4254 memset (mp, 0, sizeof (*mp));
4255 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4257 mp->sw_if_index = ntohl (sw_if_index);
4258 mp->context = context;
4260 vl_msg_api_send_shmem (q, (u8 *) & mp);
4264 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4267 vpe_api_main_t *am = &vpe_api_main;
4268 l2t_main_t *lm = &l2t_main;
4269 unix_shared_memory_queue_t *q;
4270 l2t_session_t *session;
4272 q = vl_api_client_index_to_input_queue (mp->client_index);
4277 pool_foreach (session, lm->sessions,
4279 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4286 send_sw_interface_tap_details (vpe_api_main_t * am,
4287 unix_shared_memory_queue_t * q,
4288 tapcli_interface_details_t * tap_if,
4291 vl_api_sw_interface_tap_details_t *mp;
4292 mp = vl_msg_api_alloc (sizeof (*mp));
4293 memset (mp, 0, sizeof (*mp));
4294 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4295 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4296 strncpy ((char *) mp->dev_name,
4297 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4298 mp->context = context;
4300 vl_msg_api_send_shmem (q, (u8 *) & mp);
4304 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4307 vpe_api_main_t *am = &vpe_api_main;
4308 unix_shared_memory_queue_t *q;
4309 tapcli_interface_details_t *tapifs = NULL;
4310 tapcli_interface_details_t *tap_if = NULL;
4312 q = vl_api_client_index_to_input_queue (mp->client_index);
4316 rv = vnet_tap_dump_ifs (&tapifs);
4320 vec_foreach (tap_if, tapifs)
4322 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4329 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4331 vpe_api_main_t *am = &vpe_api_main;
4332 vnet_main_t *vnm = vnet_get_main ();
4333 vlib_main_t *vm = vlib_get_main ();
4334 vnet_interface_main_t *im = &vnm->interface_main;
4335 unix_shared_memory_queue_t *q;
4336 vnet_sw_interface_t *si, *sorted_sis;
4337 u32 sw_if_index = ~0;
4339 q = vl_api_client_index_to_input_queue (mp->client_index);
4345 /* Gather interfaces. */
4346 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4347 _vec_len (sorted_sis) = 0;
4349 pool_foreach (si, im->sw_interfaces,
4351 vec_add1 (sorted_sis, si[0]);
4355 vec_foreach (si, sorted_sis)
4357 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4359 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4363 sw_if_index = si->sw_if_index;
4364 send_ip_details (am, q, sw_if_index, mp->context);
4370 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4372 clib_warning ("BUG");
4376 send_l2fib_table_entry (vpe_api_main_t * am,
4377 unix_shared_memory_queue_t * q,
4378 l2fib_entry_key_t * l2fe_key,
4379 l2fib_entry_result_t * l2fe_res, u32 context)
4381 vl_api_l2_fib_table_entry_t *mp;
4383 mp = vl_msg_api_alloc (sizeof (*mp));
4384 memset (mp, 0, sizeof (*mp));
4385 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4388 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4390 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4391 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4392 mp->static_mac = l2fe_res->fields.static_mac;
4393 mp->filter_mac = l2fe_res->fields.filter;
4394 mp->bvi_mac = l2fe_res->fields.bvi;
4395 mp->context = context;
4397 vl_msg_api_send_shmem (q, (u8 *) & mp);
4401 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4403 vpe_api_main_t *am = &vpe_api_main;
4404 bd_main_t *bdm = &bd_main;
4405 l2fib_entry_key_t *l2fe_key = NULL;
4406 l2fib_entry_result_t *l2fe_res = NULL;
4407 u32 ni, bd_id = ntohl (mp->bd_id);
4409 unix_shared_memory_queue_t *q;
4412 q = vl_api_client_index_to_input_queue (mp->client_index);
4416 /* see l2fib_table_dump: ~0 means "any" */
4421 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4428 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4430 vec_foreach_index (ni, l2fe_key)
4432 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4433 vec_elt_at_index (l2fe_res, ni), mp->context);
4435 vec_free (l2fe_key);
4436 vec_free (l2fe_res);
4440 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4442 vl_api_show_version_reply_t *rmp;
4444 char *vpe_api_get_build_directory (void);
4445 char *vpe_api_get_version (void);
4446 char *vpe_api_get_build_date (void);
4448 unix_shared_memory_queue_t *q =
4449 vl_api_client_index_to_input_queue (mp->client_index);
4455 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4457 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4458 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4459 ARRAY_LEN(rmp->build_directory)-1);
4460 strncpy ((char *) rmp->version, vpe_api_get_version(),
4461 ARRAY_LEN(rmp->version)-1);
4462 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4463 ARRAY_LEN(rmp->build_date)-1);
4469 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4471 vlib_main_t *vm = vlib_get_main ();
4472 vl_api_get_node_index_reply_t *rmp;
4475 u32 node_index = ~0;
4477 n = vlib_get_node_by_name (vm, mp->node_name);
4480 rv = VNET_API_ERROR_NO_SUCH_NODE;
4482 node_index = n->index;
4485 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4487 rmp->node_index = ntohl(node_index);
4493 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4495 vlib_main_t *vm = vlib_get_main ();
4496 vl_api_get_next_index_reply_t *rmp;
4497 vlib_node_t *node, *next_node;
4499 u32 next_node_index = ~0, next_index = ~0;
4502 node = vlib_get_node_by_name (vm, mp->node_name);
4506 rv = VNET_API_ERROR_NO_SUCH_NODE;
4510 next_node = vlib_get_node_by_name (vm, mp->next_name);
4514 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4518 next_node_index = next_node->index;
4520 p = hash_get (node->next_slot_by_node, next_node_index);
4524 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4532 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4534 rmp->next_index = ntohl(next_index);
4540 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4542 vlib_main_t *vm = vlib_get_main ();
4543 vl_api_add_node_next_reply_t *rmp;
4544 vlib_node_t *n, *next;
4546 u32 next_index = ~0;
4548 n = vlib_get_node_by_name (vm, mp->node_name);
4552 rv = VNET_API_ERROR_NO_SUCH_NODE;
4556 next = vlib_get_node_by_name (vm, mp->next_name);
4559 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4561 next_index = vlib_node_add_next (vm, n->index, next->index);
4565 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4567 rmp->next_index = ntohl(next_index);
4572 static void vl_api_l2tpv3_create_tunnel_t_handler
4573 (vl_api_l2tpv3_create_tunnel_t * mp)
4575 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4576 l2t_main_t *lm = &l2t_main;
4577 u32 sw_if_index = (u32) ~ 0;
4580 if (mp->is_ipv6 != 1)
4582 rv = VNET_API_ERROR_UNIMPLEMENTED;
4586 u32 encap_fib_index;
4588 if (mp->encap_vrf_id != ~0)
4591 ip6_main_t *im = &ip6_main;
4594 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4596 rv = VNET_API_ERROR_NO_SUCH_FIB;
4599 encap_fib_index = p[0];
4603 encap_fib_index = ~0;
4606 rv = create_l2tpv3_ipv6_tunnel (lm,
4607 (ip6_address_t *) mp->client_address,
4608 (ip6_address_t *) mp->our_address,
4609 ntohl (mp->local_session_id),
4610 ntohl (mp->remote_session_id),
4611 clib_net_to_host_u64 (mp->local_cookie),
4612 clib_net_to_host_u64 (mp->remote_cookie),
4613 mp->l2_sublayer_present,
4614 encap_fib_index, &sw_if_index);
4618 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4620 rmp->sw_if_index = ntohl (sw_if_index);
4625 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4626 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4628 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4629 l2t_main_t *lm = &l2t_main;
4632 VALIDATE_SW_IF_INDEX (mp);
4634 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4635 clib_net_to_host_u64 (mp->new_local_cookie),
4636 clib_net_to_host_u64
4637 (mp->new_remote_cookie));
4639 BAD_SW_IF_INDEX_LABEL;
4641 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4644 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4645 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4648 vnet_main_t *vnm = vnet_get_main ();
4649 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4651 VALIDATE_SW_IF_INDEX (mp);
4653 rv = l2tpv3_interface_enable_disable
4654 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4656 BAD_SW_IF_INDEX_LABEL;
4658 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4661 static void vl_api_l2tpv3_set_lookup_key_t_handler
4662 (vl_api_l2tpv3_set_lookup_key_t * mp)
4665 l2t_main_t *lm = &l2t_main;
4666 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4668 if (mp->key > L2T_LOOKUP_SESSION_ID)
4670 rv = VNET_API_ERROR_INVALID_VALUE;
4674 lm->lookup_type = mp->key;
4677 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4680 static void vl_api_vxlan_add_del_tunnel_t_handler
4681 (vl_api_vxlan_add_del_tunnel_t * mp)
4683 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4685 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4686 u32 encap_fib_index;
4688 ip4_main_t *im = &ip4_main;
4689 u32 sw_if_index = ~0;
4691 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4694 rv = VNET_API_ERROR_NO_SUCH_FIB;
4697 encap_fib_index = p[0];
4699 /* Check src & dst are different */
4700 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4701 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4703 rv = VNET_API_ERROR_SAME_SRC_DST;
4706 memset (a, 0, sizeof (*a));
4708 a->is_add = mp->is_add;
4709 a->is_ip6 = mp->is_ipv6;
4711 /* ip addresses sent in network byte order */
4714 memcpy (&(a->src.ip6), mp->src_address, 16);
4715 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4719 memcpy (&(a->src.ip4), mp->src_address, 4);
4720 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4723 a->encap_fib_index = encap_fib_index;
4724 a->decap_next_index = ntohl (mp->decap_next_index);
4725 a->vni = ntohl (mp->vni);
4726 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4730 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4732 rmp->sw_if_index = ntohl (sw_if_index);
4737 static void send_vxlan_tunnel_details
4738 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4740 vl_api_vxlan_tunnel_details_t *rmp;
4741 ip4_main_t *im4 = &ip4_main;
4742 ip6_main_t *im6 = &ip6_main;
4743 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4745 rmp = vl_msg_api_alloc (sizeof (*rmp));
4746 memset (rmp, 0, sizeof (*rmp));
4747 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4750 memcpy (rmp->src_address, &(t->src.ip6), 16);
4751 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4752 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4756 memcpy (rmp->src_address, &(t->src.ip4), 4);
4757 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4758 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4760 rmp->vni = htonl (t->vni);
4761 rmp->decap_next_index = htonl (t->decap_next_index);
4762 rmp->sw_if_index = htonl (t->sw_if_index);
4763 rmp->is_ipv6 = is_ipv6;
4764 rmp->context = context;
4766 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4769 static void vl_api_vxlan_tunnel_dump_t_handler
4770 (vl_api_vxlan_tunnel_dump_t * mp)
4772 unix_shared_memory_queue_t *q;
4773 vxlan_main_t *vxm = &vxlan_main;
4777 q = vl_api_client_index_to_input_queue (mp->client_index);
4783 sw_if_index = ntohl (mp->sw_if_index);
4785 if (~0 == sw_if_index)
4788 pool_foreach (t, vxm->tunnels,
4790 send_vxlan_tunnel_details(t, q, mp->context);
4796 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4797 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4801 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4802 send_vxlan_tunnel_details (t, q, mp->context);
4806 static void vl_api_gre_add_del_tunnel_t_handler
4807 (vl_api_gre_add_del_tunnel_t * mp)
4809 vl_api_gre_add_del_tunnel_reply_t *rmp;
4811 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4814 ip4_main_t *im = &ip4_main;
4815 u32 sw_if_index = ~0;
4817 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4820 rv = VNET_API_ERROR_NO_SUCH_FIB;
4823 outer_fib_id = p[0];
4825 /* Check src & dst are different */
4826 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4827 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4829 rv = VNET_API_ERROR_SAME_SRC_DST;
4832 memset (a, 0, sizeof (*a));
4834 a->is_add = mp->is_add;
4837 /* ip addresses sent in network byte order */
4838 clib_memcpy (&(a->src), mp->src_address, 4);
4839 clib_memcpy (&(a->dst), mp->dst_address, 4);
4841 a->outer_fib_id = outer_fib_id;
4842 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4846 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4848 rmp->sw_if_index = ntohl (sw_if_index);
4853 static void send_gre_tunnel_details
4854 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4856 vl_api_gre_tunnel_details_t *rmp;
4857 ip4_main_t *im = &ip4_main;
4859 rmp = vl_msg_api_alloc (sizeof (*rmp));
4860 memset (rmp, 0, sizeof (*rmp));
4861 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4862 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4863 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4864 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4866 rmp->sw_if_index = htonl (t->sw_if_index);
4867 rmp->context = context;
4869 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4873 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4875 unix_shared_memory_queue_t *q;
4876 gre_main_t *gm = &gre_main;
4880 q = vl_api_client_index_to_input_queue (mp->client_index);
4886 sw_if_index = ntohl (mp->sw_if_index);
4888 if (~0 == sw_if_index)
4891 pool_foreach (t, gm->tunnels,
4893 send_gre_tunnel_details(t, q, mp->context);
4899 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4900 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4904 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4905 send_gre_tunnel_details (t, q, mp->context);
4910 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4912 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4914 vl_api_l2_patch_add_del_reply_t *rmp;
4915 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4919 VALIDATE_RX_SW_IF_INDEX (mp);
4920 VALIDATE_TX_SW_IF_INDEX (mp);
4922 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4923 ntohl (mp->tx_sw_if_index),
4924 (int) (mp->is_add != 0));
4926 BAD_RX_SW_IF_INDEX_LABEL;
4927 BAD_TX_SW_IF_INDEX_LABEL;
4929 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4933 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4934 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4936 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4938 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4939 u32 encap_fib_index, decap_fib_index;
4942 ip4_main_t *im = &ip4_main;
4943 u32 sw_if_index = ~0;
4946 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4949 rv = VNET_API_ERROR_NO_SUCH_FIB;
4952 encap_fib_index = p[0];
4954 protocol = mp->protocol;
4956 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4957 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4959 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4962 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4965 decap_fib_index = p[0];
4969 decap_fib_index = ntohl (mp->decap_vrf_id);
4972 /* Check src & dst are different */
4973 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4974 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
4976 rv = VNET_API_ERROR_SAME_SRC_DST;
4979 memset (a, 0, sizeof (*a));
4981 a->is_add = mp->is_add;
4982 a->is_ip6 = mp->is_ipv6;
4983 /* ip addresses sent in network byte order */
4986 clib_memcpy (&(a->local.ip6), mp->local, 16);
4987 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
4991 clib_memcpy (&(a->local.ip4), mp->local, 4);
4992 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
4994 a->encap_fib_index = encap_fib_index;
4995 a->decap_fib_index = decap_fib_index;
4996 a->protocol = protocol;
4997 a->vni = ntohl (mp->vni);
4998 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5002 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5004 rmp->sw_if_index = ntohl (sw_if_index);
5009 static void send_vxlan_gpe_tunnel_details
5010 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5012 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5013 ip4_main_t *im4 = &ip4_main;
5014 ip6_main_t *im6 = &ip6_main;
5015 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5017 rmp = vl_msg_api_alloc (sizeof (*rmp));
5018 memset (rmp, 0, sizeof (*rmp));
5019 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5022 memcpy (rmp->local, &(t->local.ip6), 16);
5023 memcpy (rmp->remote, &(t->remote.ip6), 16);
5024 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
5025 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
5029 memcpy (rmp->local, &(t->local.ip4), 4);
5030 memcpy (rmp->remote, &(t->remote.ip4), 4);
5031 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
5032 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
5034 rmp->vni = htonl (t->vni);
5035 rmp->protocol = t->protocol;
5036 rmp->sw_if_index = htonl (t->sw_if_index);
5037 rmp->is_ipv6 = is_ipv6;
5038 rmp->context = context;
5040 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5043 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5044 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5046 unix_shared_memory_queue_t *q;
5047 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5048 vxlan_gpe_tunnel_t *t;
5051 q = vl_api_client_index_to_input_queue (mp->client_index);
5057 sw_if_index = ntohl (mp->sw_if_index);
5059 if (~0 == sw_if_index)
5062 pool_foreach (t, vgm->tunnels,
5064 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5070 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5071 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5075 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5076 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5080 /** Used for transferring locators via VPP API */
5082 typedef CLIB_PACKED (struct {
5083 u32 sw_if_index; /**< locator sw_if_index */
5084 u8 priority; /**< locator priority */
5085 u8 weight; /**< locator weight */
5090 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5093 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5095 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5097 ls_locator_t *ls_loc;
5098 u32 ls_index = ~0, locator_num;
5099 u8 *locator_name = NULL;
5102 memset (a, 0, sizeof (a[0]));
5104 locator_name = format (0, "%s", mp->locator_set_name);
5106 a->name = locator_name;
5107 a->is_add = mp->is_add;
5109 locator_num = clib_net_to_host_u32 (mp->locator_num);
5111 memset (&locator, 0, sizeof (locator));
5112 for (i = 0; i < locator_num; i++)
5114 ls_loc = &((ls_locator_t *) mp->locators)[i];
5115 VALIDATE_SW_IF_INDEX (ls_loc);
5117 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5118 locator.priority = ls_loc->priority;
5119 locator.weight = ls_loc->weight;
5121 vec_add1 (a->locators, locator);
5124 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5126 BAD_SW_IF_INDEX_LABEL;
5128 vec_free (locator_name);
5129 vec_free (a->locators);
5132 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5134 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5140 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5142 vl_api_lisp_add_del_locator_reply_t *rmp;
5144 locator_t locator, *locators = NULL;
5145 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5147 u8 *locator_name = NULL;
5149 memset (&locator, 0, sizeof (locator));
5150 memset (a, 0, sizeof (a[0]));
5152 locator.sw_if_index = ntohl (mp->sw_if_index);
5153 locator.priority = mp->priority;
5154 locator.weight = mp->weight;
5156 vec_add1 (locators, locator);
5158 locator_name = format (0, "%s", mp->locator_set_name);
5160 a->name = locator_name;
5161 a->locators = locators;
5162 a->is_add = mp->is_add;
5165 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5167 vec_free (locators);
5168 vec_free (locator_name);
5170 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5174 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5180 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5181 gid_address_ip_set (dst, src, IP4);
5182 gid_address_ippref_len (dst) = len;
5183 ip_prefix_normalize (&gid_address_ippref (dst));
5186 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5187 gid_address_ip_set (dst, src, IP6);
5188 gid_address_ippref_len (dst) = len;
5189 ip_prefix_normalize (&gid_address_ippref (dst));
5191 case 2: /* l2 mac */
5192 gid_address_type (dst) = GID_ADDR_MAC;
5193 clib_memcpy (&gid_address_mac (dst), src, 6);
5197 return VNET_API_ERROR_INVALID_VALUE;
5200 gid_address_vni (dst) = vni;
5206 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5208 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5209 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5211 gid_address_t _eid, *eid = &_eid;
5213 u32 locator_set_index = ~0, map_index = ~0;
5214 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5216 memset (a, 0, sizeof (a[0]));
5217 memset (eid, 0, sizeof (eid[0]));
5219 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5220 mp->eid_type, mp->eid, mp->prefix_len);
5224 name = format (0, "%s", mp->locator_set_name);
5225 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5228 rv = VNET_API_ERROR_INVALID_VALUE;
5231 locator_set_index = p[0];
5233 /* XXX treat batch configuration */
5234 a->is_add = mp->is_add;
5235 gid_address_copy (&a->eid, eid);
5236 a->locator_set_index = locator_set_index;
5238 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5242 gid_address_free (&a->eid);
5244 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5248 vl_api_lisp_eid_table_add_del_map_t_handler
5249 (vl_api_lisp_eid_table_add_del_map_t * mp)
5251 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5253 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5254 clib_net_to_host_u32 (mp->dp_table),
5255 mp->is_l2, mp->is_add);
5256 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5258 /** Used for transferring locators via VPP API */
5260 typedef CLIB_PACKED (struct {
5261 u8 is_ip4; /**< is locator an IPv4 address */
5262 u8 priority; /**< locator priority */
5263 u8 weight; /**< locator weight */
5264 u8 addr[16]; /**< IPv4/IPv6 address */
5268 static locator_pair_t *
5269 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5272 locator_pair_t *pairs = 0, pair;
5275 for (i = 0; i < rloc_num; i++)
5278 r = &((rloc_t *) lcl_locs)[i];
5279 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5280 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5282 /* remote locators */
5283 r = &((rloc_t *) rmt_locs)[i];
5284 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5285 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5287 pair.priority = r->priority;
5288 pair.weight = r->weight;
5290 vec_add1 (pairs, pair);
5296 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5299 locator_t *locs = 0, loc;
5302 for (i = 0; i < rloc_num; i++)
5304 /* remote locators */
5305 r = &((rloc_t *) rmt_locs)[i];
5306 memset (&loc, 0, sizeof (loc));
5307 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5309 loc.priority = r->priority;
5310 loc.weight = r->weight;
5312 vec_add1 (locs, loc);
5318 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5319 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5321 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5322 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5323 locator_pair_t *pairs = 0;
5326 memset (a, 0, sizeof (a[0]));
5328 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5329 mp->rmt_eid, mp->rmt_len);
5330 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5331 mp->lcl_eid, mp->lcl_len);
5333 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5335 if (rv || 0 == pairs)
5338 a->is_add = mp->is_add;
5339 a->locator_pairs = pairs;
5340 a->dp_table = mp->dp_table;
5342 a->action = mp->action;
5344 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5347 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5351 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5354 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5356 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5358 memset (a, 0, sizeof (a[0]));
5360 a->is_add = mp->is_add;
5361 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5363 rv = vnet_lisp_add_del_map_resolver (a);
5365 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5369 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5372 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5374 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5376 a->is_en = mp->is_en;
5377 vnet_lisp_gpe_enable_disable (a);
5379 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5383 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5385 vl_api_lisp_enable_disable_reply_t *rmp;
5388 vnet_lisp_enable_disable (mp->is_en);
5389 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5393 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5395 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5403 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
5407 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
5414 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
5418 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
5421 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5425 vl_api_show_lisp_map_request_mode_t_handler
5426 (vl_api_show_lisp_map_request_mode_t * mp)
5429 vl_api_show_lisp_map_request_mode_reply_t *rmp;
5432 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
5434 rmp->mode = vnet_lisp_get_map_request_mode ();
5440 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
5442 vl_api_lisp_map_request_mode_reply_t *rmp;
5445 rv = vnet_lisp_set_map_request_mode (mp->mode);
5447 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
5451 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5454 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5458 ls_name = format (0, "%s", mp->ls_name);
5459 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5462 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5466 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5467 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5469 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5471 u8 *locator_set_name = NULL;
5472 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5474 locator_set_name = format (0, "%s", mp->locator_set_name);
5476 a->is_add = mp->is_add;
5477 a->locator_set_name = locator_set_name;
5479 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5481 vec_free (locator_set_name);
5483 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5487 vl_api_lisp_add_del_remote_mapping_t_handler
5488 (vl_api_lisp_add_del_remote_mapping_t * mp)
5490 locator_t *rlocs = 0;
5491 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5493 gid_address_t _eid, *eid = &_eid;
5494 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5496 memset (eid, 0, sizeof (eid[0]));
5498 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5499 mp->eid_type, mp->eid, mp->eid_len);
5503 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5507 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5508 gid_address_copy (&a->reid, eid);
5510 rv = vnet_lisp_add_del_adjacency (a);
5517 /* NOTE: for now this works as a static remote mapping, i.e.,
5518 * not authoritative and ttl infinite. */
5519 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5520 mp->is_add, 1 /* is_static */ , 0);
5523 vnet_lisp_clear_all_remote_adjacencies ();
5528 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5532 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5534 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5535 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5538 memset (a, 0, sizeof (a[0]));
5540 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
5541 mp->eid_type, mp->leid, mp->leid_len);
5542 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
5543 mp->eid_type, mp->reid, mp->reid_len);
5548 a->is_add = mp->is_add;
5549 rv = vnet_lisp_add_del_adjacency (a);
5552 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5556 send_lisp_locator_details (lisp_cp_main_t * lcm,
5558 unix_shared_memory_queue_t * q, u32 context)
5560 vl_api_lisp_locator_details_t *rmp;
5562 rmp = vl_msg_api_alloc (sizeof (*rmp));
5563 memset (rmp, 0, sizeof (*rmp));
5564 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5565 rmp->context = context;
5567 rmp->local = loc->local;
5570 rmp->sw_if_index = ntohl (loc->sw_if_index);
5574 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5575 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5577 rmp->priority = loc->priority;
5578 rmp->weight = loc->weight;
5580 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5584 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5587 unix_shared_memory_queue_t *q = 0;
5588 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5589 locator_set_t *lsit = 0;
5591 u32 ls_index = ~0, *locit = 0;
5594 q = vl_api_client_index_to_input_queue (mp->client_index);
5600 if (mp->is_index_set)
5601 ls_index = htonl (mp->ls_index);
5604 /* make sure we get a proper C-string */
5605 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
5606 ls_name = format (0, "%s", mp->ls_name);
5607 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
5613 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
5616 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5618 vec_foreach (locit, lsit->locator_indices)
5620 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5621 send_lisp_locator_details (lcm, loc, q, mp->context);
5628 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5629 locator_set_t * lsit,
5630 unix_shared_memory_queue_t * q,
5631 u32 context, u32 ls_index)
5633 vl_api_lisp_locator_set_details_t *rmp;
5636 rmp = vl_msg_api_alloc (sizeof (*rmp));
5637 memset (rmp, 0, sizeof (*rmp));
5638 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5639 rmp->context = context;
5641 rmp->ls_index = htonl (ls_index);
5644 ASSERT (lsit->name != NULL);
5645 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
5646 vec_len (lsit->name));
5650 str = format (0, "<remote-%d>", ls_index);
5651 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
5655 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5659 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5661 unix_shared_memory_queue_t *q = NULL;
5662 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5663 locator_set_t *lsit = NULL;
5666 q = vl_api_client_index_to_input_queue (mp->client_index);
5672 filter = mp->filter;
5674 pool_foreach (lsit, lcm->locator_set_pool,
5676 if (filter && !((1 == filter && lsit->local) ||
5677 (2 == filter && !lsit->local)))
5681 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
5682 lsit - lcm->locator_set_pool);
5688 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5690 ASSERT (prefix_length);
5691 ip_prefix_t *ippref = &fid_addr_ippref (src);
5693 switch (fid_addr_type (src))
5695 case FID_ADDR_IP_PREF:
5696 if (ip_prefix_version (ippref) == IP4)
5697 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5699 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5700 prefix_length[0] = ip_prefix_len (ippref);
5704 prefix_length[0] = 0;
5705 clib_memcpy (dst, fid_addr_mac (src), 6);
5709 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5715 fid_type_to_api_type (fid_address_t * fid)
5717 ip_prefix_t *ippref;
5719 switch (fid_addr_type (fid))
5721 case FID_ADDR_IP_PREF:
5722 ippref = &fid_addr_ippref (fid);
5723 if (ip_prefix_version (ippref) == IP4)
5725 else if (ip_prefix_version (ippref) == IP6)
5738 send_lisp_eid_table_details (mapping_t * mapit,
5739 unix_shared_memory_queue_t * q,
5740 u32 context, u8 filter)
5743 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5744 locator_set_t *ls = 0;
5745 vl_api_lisp_eid_table_details_t *rmp = NULL;
5746 gid_address_t *gid = NULL;
5748 ip_prefix_t *ip_prefix = NULL;
5752 case 0: /* all mappings */
5755 case 1: /* local only */
5759 case 2: /* remote only */
5764 clib_warning ("Filter error, unknown filter: %d", filter);
5769 ip_prefix = &gid_address_ippref (gid);
5770 mac = gid_address_mac (gid);
5772 rmp = vl_msg_api_alloc (sizeof (*rmp));
5773 memset (rmp, 0, sizeof (*rmp));
5774 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5776 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5777 if (vec_len (ls->locator_indices) == 0)
5778 rmp->locator_set_index = ~0;
5780 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5782 rmp->is_local = mapit->local;
5783 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5784 rmp->action = mapit->action;
5785 rmp->authoritative = mapit->authoritative;
5787 switch (gid_address_type (gid))
5789 case GID_ADDR_SRC_DST:
5790 rmp->is_src_dst = 1;
5791 fid = &gid_address_sd_src (gid);
5792 rmp->eid_type = fid_type_to_api_type (fid);
5793 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5794 &rmp->seid_prefix_len);
5795 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5796 &rmp->eid_prefix_len);
5798 case GID_ADDR_IP_PREFIX:
5799 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5800 if (ip_prefix_version (ip_prefix) == IP4)
5802 rmp->eid_type = 0; /* ipv4 type */
5803 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5804 sizeof (ip_prefix_v4 (ip_prefix)));
5808 rmp->eid_type = 1; /* ipv6 type */
5809 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5810 sizeof (ip_prefix_v6 (ip_prefix)));
5814 rmp->eid_type = 2; /* l2 mac type */
5815 clib_memcpy (rmp->eid, mac, 6);
5820 rmp->context = context;
5821 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5822 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5826 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5829 unix_shared_memory_queue_t *q = NULL;
5830 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5831 mapping_t *mapit = NULL;
5832 gid_address_t _eid, *eid = &_eid;
5834 q = vl_api_client_index_to_input_queue (mp->client_index);
5842 memset (eid, 0, sizeof (*eid));
5844 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5845 mp->eid_type, mp->eid, mp->prefix_length);
5847 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5848 if ((u32) ~ 0 == mi)
5851 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5852 send_lisp_eid_table_details (mapit, q, mp->context,
5853 0 /* ignore filter */ );
5858 pool_foreach (mapit, lcm->mapping_pool,
5860 send_lisp_eid_table_details(mapit, q, mp->context,
5868 send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
5869 unix_shared_memory_queue_t * q, u32 context)
5871 vl_api_lisp_gpe_tunnel_details_t *rmp;
5872 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5874 rmp = vl_msg_api_alloc (sizeof (*rmp));
5875 memset (rmp, 0, sizeof (*rmp));
5876 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5878 rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
5880 rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
5881 ip_address_copy_addr (rmp->source_ip,
5882 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5883 ip_address_copy_addr (rmp->destination_ip,
5884 &ip_prefix_addr (&(lfe->key->rmt.ippref)));
5886 rmp->encap_fib_id = htonl (0);
5887 rmp->decap_fib_id = htonl (lfe->eid_fib_index);
5888 rmp->iid = htonl (lfe->key->vni);
5889 rmp->context = context;
5891 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5895 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5897 unix_shared_memory_queue_t *q = NULL;
5898 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5899 lisp_gpe_fwd_entry_t *lfe = NULL;
5901 if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
5906 q = vl_api_client_index_to_input_queue (mp->client_index);
5913 pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
5915 send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
5921 send_lisp_map_resolver_details (ip_address_t * ip,
5922 unix_shared_memory_queue_t * q, u32 context)
5924 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5926 rmp = vl_msg_api_alloc (sizeof (*rmp));
5927 memset (rmp, 0, sizeof (*rmp));
5928 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5930 switch (ip_addr_version (ip))
5934 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5935 sizeof (ip_addr_v4 (ip)));
5940 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5941 sizeof (ip_addr_v6 (ip)));
5947 rmp->context = context;
5949 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5953 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5955 unix_shared_memory_queue_t *q = NULL;
5956 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5959 q = vl_api_client_index_to_input_queue (mp->client_index);
5965 vec_foreach (mr, lcm->map_resolvers)
5967 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5972 send_eid_table_map_pair (hash_pair_t * p,
5973 unix_shared_memory_queue_t * q, u32 context)
5975 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5977 rmp = vl_msg_api_alloc (sizeof (*rmp));
5978 memset (rmp, 0, sizeof (*rmp));
5979 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5981 rmp->vni = clib_host_to_net_u32 (p->key);
5982 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5983 rmp->context = context;
5984 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5988 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5991 unix_shared_memory_queue_t *q = NULL;
5992 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5994 uword *vni_table = 0;
5996 q = vl_api_client_index_to_input_queue (mp->client_index);
6004 vni_table = lcm->bd_id_by_vni;
6008 vni_table = lcm->table_id_by_vni;
6012 hash_foreach_pair (p, vni_table,
6014 send_eid_table_map_pair (p, q, mp->context);
6020 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6022 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6024 rmp = vl_msg_api_alloc (sizeof (*rmp));
6025 memset (rmp, 0, sizeof (*rmp));
6026 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6027 rmp->context = context;
6028 rmp->vni = clib_host_to_net_u32 (vni);
6029 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6033 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
6035 lisp_adjacency_t *adj;
6036 vl_api_lisp_adjacency_t a;
6037 u32 i, n = vec_len (adjs);
6039 for (i = 0; i < n; i++)
6041 adj = vec_elt_at_index (adjs, i);
6042 memset (&a, 0, sizeof (a));
6044 switch (gid_address_type (&adj->reid))
6046 case GID_ADDR_IP_PREFIX:
6047 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
6048 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
6049 if (gid_address_ip_version (&adj->reid) == IP4)
6051 a.eid_type = 0; /* ipv4 type */
6052 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
6053 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
6057 a.eid_type = 1; /* ipv6 type */
6058 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
6059 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
6063 a.eid_type = 2; /* l2 mac type */
6064 mac_copy (a.reid, gid_address_mac (&adj->reid));
6065 mac_copy (a.leid, gid_address_mac (&adj->leid));
6075 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
6077 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
6078 lisp_adjacency_t *adjs = 0;
6080 vl_api_lisp_adjacency_t a;
6082 u32 vni = clib_net_to_host_u32 (mp->vni);
6084 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
6085 size = vec_len (adjs) * sizeof (a);
6088 REPLY_MACRO3 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
6090 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
6091 lisp_adjacency_copy (rmp->adjacencies, adjs);
6099 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6104 unix_shared_memory_queue_t *q = 0;
6105 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6107 q = vl_api_client_index_to_input_queue (mp->client_index);
6114 hash_foreach_pair (p, lcm->table_id_by_vni,
6116 hash_set (vnis, p->key, 0);
6119 hash_foreach_pair (p, lcm->bd_id_by_vni,
6121 hash_set (vnis, p->key, 0);
6124 hash_foreach_pair (p, vnis,
6126 send_eid_table_vni (p->key, q, mp->context);
6134 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6136 unix_shared_memory_queue_t *q = NULL;
6137 vl_api_show_lisp_status_reply_t *rmp = NULL;
6140 q = vl_api_client_index_to_input_queue (mp->client_index);
6147 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6149 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6150 rmp->feature_status = vnet_lisp_enable_disable_status ();
6156 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6157 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6159 unix_shared_memory_queue_t *q = NULL;
6160 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6161 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6162 locator_set_t *loc_set = 0;
6166 q = vl_api_client_index_to_input_queue (mp->client_index);
6172 if (~0 == lcm->mreq_itr_rlocs)
6174 tmp_str = format (0, " ");
6179 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6180 tmp_str = format (0, "%s", loc_set->name);
6184 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6186 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6187 ARRAY_LEN(rmp->locator_set_name) - 1);
6195 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6197 unix_shared_memory_queue_t *q = NULL;
6198 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6199 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6201 locator_set_t *ls = 0;
6205 q = vl_api_client_index_to_input_queue (mp->client_index);
6211 if (!lcm->lisp_pitr)
6213 tmp_str = format (0, "N/A");
6217 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6218 if (~0 != m->locator_set_index)
6221 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6222 tmp_str = format (0, "%s", ls->name);
6226 tmp_str = format (0, "N/A");
6229 vec_add1 (tmp_str, 0);
6232 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6234 rmp->status = lcm->lisp_pitr;
6235 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6236 ARRAY_LEN(rmp->locator_set_name) - 1);
6242 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6245 vl_api_interface_name_renumber_reply_t *rmp;
6248 VALIDATE_SW_IF_INDEX (mp);
6250 rv = vnet_interface_name_renumber
6251 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6253 BAD_SW_IF_INDEX_LABEL;
6255 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6259 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6260 u32 sw_if_index, u32 address)
6262 vpe_api_main_t *am = &vpe_api_main;
6263 vlib_main_t *vm = am->vlib_main;
6264 vl_api_ip4_arp_event_t *event;
6265 static f64 arp_event_last_time;
6266 f64 now = vlib_time_now (vm);
6268 if (pool_is_free_index (am->arp_events, pool_index))
6271 event = pool_elt_at_index (am->arp_events, pool_index);
6273 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6275 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6279 if (sw_if_index == event->sw_if_index &&
6281 /* for BD case, also check IP address with 10 sec timeout */
6282 (address == event->address &&
6283 (now - arp_event_last_time) < 10.0)))
6288 arp_event_last_time = now;
6289 event->sw_if_index = sw_if_index;
6291 event->address = address;
6296 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6297 u32 sw_if_index, ip6_address_t * address)
6299 vpe_api_main_t *am = &vpe_api_main;
6300 vlib_main_t *vm = am->vlib_main;
6301 vl_api_ip6_nd_event_t *event;
6302 static f64 nd_event_last_time;
6303 f64 now = vlib_time_now (vm);
6305 if (pool_is_free_index (am->nd_events, pool_index))
6308 event = pool_elt_at_index (am->nd_events, pool_index);
6311 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6313 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6317 if (sw_if_index == event->sw_if_index &&
6319 /* for BD case, also check IP address with 10 sec timeout */
6320 (ip6_address_is_equal (address,
6321 (ip6_address_t *) event->address) &&
6322 (now - nd_event_last_time) < 10.0)))
6327 nd_event_last_time = now;
6328 event->sw_if_index = sw_if_index;
6330 clib_memcpy (event->address, address, sizeof (event->address));
6335 arp_change_delete_callback (u32 pool_index, u8 * notused)
6337 vpe_api_main_t *am = &vpe_api_main;
6339 if (pool_is_free_index (am->arp_events, pool_index))
6342 pool_put_index (am->arp_events, pool_index);
6347 nd_change_delete_callback (u32 pool_index, u8 * notused)
6349 vpe_api_main_t *am = &vpe_api_main;
6351 if (pool_is_free_index (am->nd_events, pool_index))
6354 pool_put_index (am->nd_events, pool_index);
6359 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6361 vpe_api_main_t *am = &vpe_api_main;
6362 vnet_main_t *vnm = vnet_get_main ();
6363 vl_api_want_ip4_arp_events_reply_t *rmp;
6364 vl_api_ip4_arp_event_t *event;
6367 if (mp->enable_disable)
6369 pool_get (am->arp_events, event);
6370 memset (event, 0, sizeof (*event));
6372 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6373 event->client_index = mp->client_index;
6374 event->context = mp->context;
6375 event->address = mp->address;
6376 event->pid = mp->pid;
6377 if (mp->address == 0)
6380 rv = vnet_add_del_ip4_arp_change_event
6381 (vnm, arp_change_data_callback,
6382 mp->pid, &mp->address /* addr, in net byte order */ ,
6383 vpe_resolver_process_node.index,
6384 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6388 rv = vnet_add_del_ip4_arp_change_event
6389 (vnm, arp_change_delete_callback,
6390 mp->pid, &mp->address /* addr, in net byte order */ ,
6391 vpe_resolver_process_node.index,
6392 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6394 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6398 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6400 vpe_api_main_t *am = &vpe_api_main;
6401 vnet_main_t *vnm = vnet_get_main ();
6402 vl_api_want_ip6_nd_events_reply_t *rmp;
6403 vl_api_ip6_nd_event_t *event;
6406 if (mp->enable_disable)
6408 pool_get (am->nd_events, event);
6409 memset (event, 0, sizeof (*event));
6411 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6412 event->client_index = mp->client_index;
6413 event->context = mp->context;
6414 clib_memcpy (event->address, mp->address, 16);
6415 event->pid = mp->pid;
6416 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6419 rv = vnet_add_del_ip6_nd_change_event
6420 (vnm, nd_change_data_callback,
6421 mp->pid, mp->address /* addr, in net byte order */ ,
6422 vpe_resolver_process_node.index,
6423 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6427 rv = vnet_add_del_ip6_nd_change_event
6428 (vnm, nd_change_delete_callback,
6429 mp->pid, mp->address /* addr, in net byte order */ ,
6430 vpe_resolver_process_node.index,
6431 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6433 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6436 static void vl_api_input_acl_set_interface_t_handler
6437 (vl_api_input_acl_set_interface_t * mp)
6439 vlib_main_t *vm = vlib_get_main ();
6440 vl_api_input_acl_set_interface_reply_t *rmp;
6442 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6444 ip4_table_index = ntohl (mp->ip4_table_index);
6445 ip6_table_index = ntohl (mp->ip6_table_index);
6446 l2_table_index = ntohl (mp->l2_table_index);
6447 sw_if_index = ntohl (mp->sw_if_index);
6449 VALIDATE_SW_IF_INDEX (mp);
6451 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6452 ip6_table_index, l2_table_index, mp->is_add);
6454 BAD_SW_IF_INDEX_LABEL;
6456 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6459 static void vl_api_ipsec_spd_add_del_t_handler
6460 (vl_api_ipsec_spd_add_del_t * mp)
6463 clib_warning ("unimplemented");
6466 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6467 vl_api_ipsec_spd_add_del_reply_t *rmp;
6471 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6473 rv = VNET_API_ERROR_UNIMPLEMENTED;
6476 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6480 static void vl_api_ipsec_interface_add_del_spd_t_handler
6481 (vl_api_ipsec_interface_add_del_spd_t * mp)
6483 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6484 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6486 u32 sw_if_index __attribute__ ((unused));
6487 u32 spd_id __attribute__ ((unused));
6489 sw_if_index = ntohl (mp->sw_if_index);
6490 spd_id = ntohl (mp->spd_id);
6492 VALIDATE_SW_IF_INDEX (mp);
6495 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6497 rv = VNET_API_ERROR_UNIMPLEMENTED;
6500 BAD_SW_IF_INDEX_LABEL;
6502 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6505 static void vl_api_ipsec_spd_add_del_entry_t_handler
6506 (vl_api_ipsec_spd_add_del_entry_t * mp)
6508 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6509 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6515 memset (&p, 0, sizeof (p));
6517 p.id = ntohl (mp->spd_id);
6518 p.priority = ntohl (mp->priority);
6519 p.is_outbound = mp->is_outbound;
6520 p.is_ipv6 = mp->is_ipv6;
6522 if (mp->is_ipv6 || mp->is_ip_any)
6524 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6525 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6526 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6527 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6531 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6532 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6533 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6534 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6536 p.protocol = mp->protocol;
6537 p.rport.start = ntohs (mp->remote_port_start);
6538 p.rport.stop = ntohs (mp->remote_port_stop);
6539 p.lport.start = ntohs (mp->local_port_start);
6540 p.lport.stop = ntohs (mp->local_port_stop);
6541 /* policy action resolve unsupported */
6542 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6544 clib_warning ("unsupported action: 'resolve'");
6545 rv = VNET_API_ERROR_UNIMPLEMENTED;
6548 p.policy = mp->policy;
6549 p.sa_id = ntohl (mp->sa_id);
6551 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6558 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6561 rv = VNET_API_ERROR_UNIMPLEMENTED;
6566 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6569 static void vl_api_ipsec_sad_add_del_entry_t_handler
6570 (vl_api_ipsec_sad_add_del_entry_t * mp)
6572 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6573 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6578 memset (&sa, 0, sizeof (sa));
6580 sa.id = ntohl (mp->sad_id);
6581 sa.spi = ntohl (mp->spi);
6582 /* security protocol AH unsupported */
6583 if (mp->protocol == IPSEC_PROTOCOL_AH)
6585 clib_warning ("unsupported security protocol 'AH'");
6586 rv = VNET_API_ERROR_UNIMPLEMENTED;
6589 sa.protocol = mp->protocol;
6590 /* check for unsupported crypto-alg */
6591 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6592 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6594 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6595 mp->crypto_algorithm);
6596 rv = VNET_API_ERROR_UNIMPLEMENTED;
6599 sa.crypto_alg = mp->crypto_algorithm;
6600 sa.crypto_key_len = mp->crypto_key_length;
6601 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6602 /* check for unsupported integ-alg */
6603 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6604 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6606 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6607 mp->integrity_algorithm);
6608 rv = VNET_API_ERROR_UNIMPLEMENTED;
6611 sa.integ_alg = mp->integrity_algorithm;
6612 sa.integ_key_len = mp->integrity_key_length;
6613 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6614 sa.use_esn = mp->use_extended_sequence_number;
6615 sa.is_tunnel = mp->is_tunnel;
6616 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6617 if (sa.is_tunnel_ip6)
6619 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6620 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6624 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6625 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6628 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6630 rv = VNET_API_ERROR_UNIMPLEMENTED;
6635 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6639 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6641 vl_api_ikev2_profile_add_del_reply_t *rmp;
6645 vlib_main_t *vm = vlib_get_main ();
6646 clib_error_t *error;
6647 u8 *tmp = format (0, "%s", mp->name);
6648 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6651 rv = VNET_API_ERROR_UNSPECIFIED;
6653 rv = VNET_API_ERROR_UNIMPLEMENTED;
6656 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6660 vl_api_ikev2_profile_set_auth_t_handler
6661 (vl_api_ikev2_profile_set_auth_t * mp)
6663 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6667 vlib_main_t *vm = vlib_get_main ();
6668 clib_error_t *error;
6669 u8 *tmp = format (0, "%s", mp->name);
6670 u8 *data = vec_new (u8, mp->data_len);
6671 clib_memcpy (data, mp->data, mp->data_len);
6672 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6676 rv = VNET_API_ERROR_UNSPECIFIED;
6678 rv = VNET_API_ERROR_UNIMPLEMENTED;
6681 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6685 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6687 vl_api_ikev2_profile_add_del_reply_t *rmp;
6691 vlib_main_t *vm = vlib_get_main ();
6692 clib_error_t *error;
6693 u8 *tmp = format (0, "%s", mp->name);
6694 u8 *data = vec_new (u8, mp->data_len);
6695 clib_memcpy (data, mp->data, mp->data_len);
6696 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6700 rv = VNET_API_ERROR_UNSPECIFIED;
6702 rv = VNET_API_ERROR_UNIMPLEMENTED;
6705 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6709 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6711 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6715 vlib_main_t *vm = vlib_get_main ();
6716 clib_error_t *error;
6717 u8 *tmp = format (0, "%s", mp->name);
6718 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6719 mp->end_port, (ip4_address_t) mp->start_addr,
6720 (ip4_address_t) mp->end_addr, mp->is_local);
6723 rv = VNET_API_ERROR_UNSPECIFIED;
6725 rv = VNET_API_ERROR_UNIMPLEMENTED;
6728 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6732 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6734 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6738 vlib_main_t *vm = vlib_get_main ();
6739 clib_error_t *error;
6741 error = ikev2_set_local_key (vm, mp->key_file);
6743 rv = VNET_API_ERROR_UNSPECIFIED;
6745 rv = VNET_API_ERROR_UNIMPLEMENTED;
6748 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6752 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6754 vl_api_map_add_domain_reply_t *rmp;
6757 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6759 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6760 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6761 (ip6_address_t *) & mp->ip6_src,
6762 mp->ip6_src_prefix_len, mp->ea_bits_len,
6763 mp->psid_offset, mp->psid_length, &index,
6764 ntohs (mp->mtu), flags);
6767 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6769 rmp->index = ntohl(index);
6775 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6777 vl_api_map_del_domain_reply_t *rmp;
6780 rv = map_delete_domain (ntohl (mp->index));
6782 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6786 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6788 vl_api_map_del_domain_reply_t *rmp;
6792 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6793 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6795 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6799 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6801 vl_api_map_domain_details_t *rmp;
6802 map_main_t *mm = &map_main;
6804 unix_shared_memory_queue_t *q;
6806 if (pool_elts (mm->domains) == 0)
6809 q = vl_api_client_index_to_input_queue (mp->client_index);
6816 pool_foreach(d, mm->domains,
6818 /* Make sure every field is initiated (or don't skip the memset()) */
6819 rmp = vl_msg_api_alloc (sizeof (*rmp));
6820 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6821 rmp->domain_index = htonl(d - mm->domains);
6822 rmp->ea_bits_len = d->ea_bits_len;
6823 rmp->psid_offset = d->psid_offset;
6824 rmp->psid_length = d->psid_length;
6825 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6826 rmp->ip4_prefix_len = d->ip4_prefix_len;
6827 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6828 rmp->ip6_prefix_len = d->ip6_prefix_len;
6829 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6830 rmp->ip6_src_len = d->ip6_src_len;
6831 rmp->mtu = htons(d->mtu);
6832 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6833 rmp->context = mp->context;
6835 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6841 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6843 unix_shared_memory_queue_t *q;
6846 vl_api_map_rule_details_t *rmp;
6847 map_main_t *mm = &map_main;
6848 u32 domain_index = ntohl (mp->domain_index);
6851 if (pool_elts (mm->domains) == 0)
6854 d = pool_elt_at_index (mm->domains, domain_index);
6855 if (!d || !d->rules)
6860 q = vl_api_client_index_to_input_queue (mp->client_index);
6866 for (i = 0; i < (0x1 << d->psid_length); i++)
6869 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6873 rmp = vl_msg_api_alloc (sizeof (*rmp));
6874 memset (rmp, 0, sizeof (*rmp));
6875 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6876 rmp->psid = htons (i);
6877 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6878 rmp->context = mp->context;
6879 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6884 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6886 vl_api_map_summary_stats_reply_t *rmp;
6887 vlib_combined_counter_main_t *cm;
6890 u64 total_pkts[VLIB_N_RX_TX];
6891 u64 total_bytes[VLIB_N_RX_TX];
6892 map_main_t *mm = &map_main;
6893 unix_shared_memory_queue_t *q =
6894 vl_api_client_index_to_input_queue (mp->client_index);
6899 rmp = vl_msg_api_alloc (sizeof (*rmp));
6900 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6901 rmp->context = mp->context;
6904 memset (total_pkts, 0, sizeof (total_pkts));
6905 memset (total_bytes, 0, sizeof (total_bytes));
6907 map_domain_counter_lock (mm);
6908 vec_foreach (cm, mm->domain_counters)
6910 which = cm - mm->domain_counters;
6912 for (i = 0; i < vec_len (cm->maxi); i++)
6914 vlib_get_combined_counter (cm, i, &v);
6915 total_pkts[which] += v.packets;
6916 total_bytes[which] += v.bytes;
6920 map_domain_counter_unlock (mm);
6922 /* Note: in network byte order! */
6923 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6924 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6925 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6926 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6927 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6928 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6929 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6930 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6931 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6932 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6933 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6934 clib_host_to_net_u64 (map_error_counter_get
6935 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6936 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6937 clib_host_to_net_u64 (map_error_counter_get
6938 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6940 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6944 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6946 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6947 vl_api_ipsec_sa_set_key_reply_t *rmp;
6951 sa.id = ntohl (mp->sa_id);
6952 sa.crypto_key_len = mp->crypto_key_length;
6953 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6954 sa.integ_key_len = mp->integrity_key_length;
6955 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6957 rv = ipsec_set_sa_key (vm, &sa);
6959 rv = VNET_API_ERROR_UNIMPLEMENTED;
6962 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6965 static void vl_api_cop_interface_enable_disable_t_handler
6966 (vl_api_cop_interface_enable_disable_t * mp)
6968 vl_api_cop_interface_enable_disable_reply_t *rmp;
6970 u32 sw_if_index = ntohl (mp->sw_if_index);
6973 VALIDATE_SW_IF_INDEX (mp);
6975 enable_disable = (int) mp->enable_disable;
6977 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6979 BAD_SW_IF_INDEX_LABEL;
6981 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6984 static void vl_api_cop_whitelist_enable_disable_t_handler
6985 (vl_api_cop_whitelist_enable_disable_t * mp)
6987 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6988 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6989 u32 sw_if_index = ntohl (mp->sw_if_index);
6992 VALIDATE_SW_IF_INDEX (mp);
6994 a->sw_if_index = sw_if_index;
6997 a->default_cop = mp->default_cop;
6998 a->fib_id = ntohl (mp->fib_id);
7000 rv = cop_whitelist_enable_disable (a);
7002 BAD_SW_IF_INDEX_LABEL;
7004 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
7008 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
7012 api_main_t *am = &api_main;
7013 vlib_main_t *vm = vlib_get_main ();
7015 vl_api_get_node_graph_reply_t *rmp;
7017 pthread_mutex_lock (&am->vlib_rp->mutex);
7018 oldheap = svm_push_data_heap (am->vlib_rp);
7021 * Keep the number of memcpy ops to a minimum (e.g. 1).
7023 vec_validate (vector, 16384);
7024 vec_reset_length (vector);
7027 vector = vlib_node_serialize (&vm->node_main, vector,
7028 (u32) ~ 0 /* all threads */ ,
7029 1 /* include nexts */ ,
7030 1 /* include stats */ );
7032 svm_pop_heap (oldheap);
7033 pthread_mutex_unlock (&am->vlib_rp->mutex);
7036 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
7038 rmp->reply_in_shmem = (uword) vector;
7044 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
7047 vl_api_ioam_enable_reply_t *rmp;
7048 clib_error_t *error;
7050 /* Ignoring the profile id as currently a single profile
7052 error = ip6_ioam_enable (mp->trace_enable, mp->pow_enable, mp->trace_ppc);
7055 clib_error_report (error);
7056 rv = clib_error_get_code (error);
7059 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
7063 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
7066 vl_api_ioam_disable_reply_t *rmp;
7067 clib_error_t *error;
7069 error = clear_ioam_rewrite_fn ();
7072 clib_error_report (error);
7073 rv = clib_error_get_code (error);
7076 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
7080 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7082 vlib_main_t *vm = vlib_get_main ();
7083 vl_api_af_packet_create_reply_t *rmp;
7085 u8 *host_if_name = NULL;
7088 host_if_name = format (0, "%s", mp->host_if_name);
7089 vec_add1 (host_if_name, 0);
7091 rv = af_packet_create_if (vm, host_if_name,
7092 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7095 vec_free (host_if_name);
7098 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7100 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7106 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7108 vlib_main_t *vm = vlib_get_main ();
7109 vl_api_af_packet_delete_reply_t *rmp;
7111 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_delete_if (vm, host_if_name);
7118 vec_free (host_if_name);
7120 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7124 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7126 vlib_main_t *vm = vlib_get_main ();
7127 vl_api_policer_add_del_reply_t *rmp;
7130 sse2_qos_pol_cfg_params_st cfg;
7131 clib_error_t *error;
7134 name = format (0, "%s", mp->name);
7136 memset (&cfg, 0, sizeof (cfg));
7138 cfg.rnd_type = mp->round_type;
7139 cfg.rate_type = mp->rate_type;
7140 cfg.rb.kbps.cir_kbps = mp->cir;
7141 cfg.rb.kbps.eir_kbps = mp->eir;
7142 cfg.rb.kbps.cb_bytes = mp->cb;
7143 cfg.rb.kbps.eb_bytes = mp->eb;
7144 cfg.conform_action.action_type = mp->conform_action_type;
7145 cfg.conform_action.dscp = mp->conform_dscp;
7146 cfg.exceed_action.action_type = mp->exceed_action_type;
7147 cfg.exceed_action.dscp = mp->exceed_dscp;
7148 cfg.violate_action.action_type = mp->violate_action_type;
7149 cfg.violate_action.dscp = mp->violate_dscp;
7150 cfg.color_aware = mp->color_aware;
7152 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7155 rv = VNET_API_ERROR_UNSPECIFIED;
7158 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7160 if (rv == 0 && mp->is_add)
7161 rmp->policer_index = ntohl(policer_index);
7163 rmp->policer_index = ~0;
7169 send_policer_details (u8 * name,
7170 sse2_qos_pol_cfg_params_st * config,
7171 policer_read_response_type_st * templ,
7172 unix_shared_memory_queue_t * q, u32 context)
7174 vl_api_policer_details_t *mp;
7176 mp = vl_msg_api_alloc (sizeof (*mp));
7177 memset (mp, 0, sizeof (*mp));
7178 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7179 mp->context = context;
7180 mp->cir = htonl (config->rb.kbps.cir_kbps);
7181 mp->eir = htonl (config->rb.kbps.eir_kbps);
7182 mp->cb = htonl (config->rb.kbps.cb_bytes);
7183 mp->eb = htonl (config->rb.kbps.eb_bytes);
7184 mp->rate_type = config->rate_type;
7185 mp->round_type = config->rnd_type;
7186 mp->type = config->rfc;
7187 mp->conform_action_type = config->conform_action.action_type;
7188 mp->conform_dscp = config->conform_action.dscp;
7189 mp->exceed_action_type = config->exceed_action.action_type;
7190 mp->exceed_dscp = config->exceed_action.dscp;
7191 mp->violate_action_type = config->violate_action.action_type;
7192 mp->violate_dscp = config->violate_action.dscp;
7193 mp->single_rate = templ->single_rate ? 1 : 0;
7194 mp->color_aware = templ->color_aware ? 1 : 0;
7195 mp->scale = htonl (templ->scale);
7196 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7197 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7198 mp->current_limit = htonl (templ->current_limit);
7199 mp->current_bucket = htonl (templ->current_bucket);
7200 mp->extended_limit = htonl (templ->extended_limit);
7201 mp->extended_bucket = htonl (templ->extended_bucket);
7202 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7204 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7206 vl_msg_api_send_shmem (q, (u8 *) & mp);
7210 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7212 unix_shared_memory_queue_t *q;
7213 vnet_policer_main_t *pm = &vnet_policer_main;
7219 sse2_qos_pol_cfg_params_st *config;
7220 policer_read_response_type_st *templ;
7222 q = vl_api_client_index_to_input_queue (mp->client_index);
7226 if (mp->match_name_valid)
7228 match_name = format (0, "%s%c", mp->match_name, 0);
7231 if (mp->match_name_valid)
7233 p = hash_get_mem (pm->policer_config_by_name, match_name);
7237 config = pool_elt_at_index (pm->configs, pool_index);
7238 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7239 send_policer_details (match_name, config, templ, q, mp->context);
7245 hash_foreach_pair (hp, pm->policer_config_by_name,
7247 name = (u8 *) hp->key;
7248 pool_index = hp->value[0];
7249 config = pool_elt_at_index (pm->configs, pool_index);
7250 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7251 send_policer_details(name, config, templ, q, mp->context);
7258 vl_api_policer_classify_set_interface_t_handler
7259 (vl_api_policer_classify_set_interface_t * mp)
7261 vlib_main_t *vm = vlib_get_main ();
7262 vl_api_policer_classify_set_interface_reply_t *rmp;
7264 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7266 ip4_table_index = ntohl (mp->ip4_table_index);
7267 ip6_table_index = ntohl (mp->ip6_table_index);
7268 l2_table_index = ntohl (mp->l2_table_index);
7269 sw_if_index = ntohl (mp->sw_if_index);
7271 VALIDATE_SW_IF_INDEX (mp);
7273 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7274 ip6_table_index, l2_table_index,
7277 BAD_SW_IF_INDEX_LABEL;
7279 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7283 send_policer_classify_details (u32 sw_if_index,
7285 unix_shared_memory_queue_t * q, u32 context)
7287 vl_api_policer_classify_details_t *mp;
7289 mp = vl_msg_api_alloc (sizeof (*mp));
7290 memset (mp, 0, sizeof (*mp));
7291 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7292 mp->context = context;
7293 mp->sw_if_index = htonl (sw_if_index);
7294 mp->table_index = htonl (table_index);
7296 vl_msg_api_send_shmem (q, (u8 *) & mp);
7300 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7302 unix_shared_memory_queue_t *q;
7303 policer_classify_main_t *pcm = &policer_classify_main;
7307 q = vl_api_client_index_to_input_queue (mp->client_index);
7311 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7313 if (vec_len (vec_tbl))
7315 for (i = 0; i < vec_len (vec_tbl); i++)
7317 if (vec_elt (vec_tbl, i) == ~0)
7320 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7327 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7329 vlib_main_t *vm = vlib_get_main ();
7330 vl_api_netmap_create_reply_t *rmp;
7334 if_name = format (0, "%s", mp->netmap_if_name);
7335 vec_add1 (if_name, 0);
7338 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7339 mp->is_pipe, mp->is_master, 0);
7343 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7347 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7349 vlib_main_t *vm = vlib_get_main ();
7350 vl_api_netmap_delete_reply_t *rmp;
7354 if_name = format (0, "%s", mp->netmap_if_name);
7355 vec_add1 (if_name, 0);
7357 rv = netmap_delete_if (vm, if_name);
7361 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7365 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7368 clib_warning ("BUG");
7372 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7373 unix_shared_memory_queue_t * q,
7374 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7376 vl_api_mpls_gre_tunnel_details_t *mp;
7377 mpls_main_t *mm = &mpls_main;
7382 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7383 nlabels = vec_len (e->labels);
7385 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7386 memset (mp, 0, sizeof (*mp));
7387 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7388 mp->context = context;
7390 mp->tunnel_index = htonl (index);
7391 mp->tunnel_src = gt->tunnel_src.as_u32;
7392 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7393 mp->intfc_address = gt->intfc_address.as_u32;
7394 mp->mask_width = htonl (gt->mask_width);
7395 mp->inner_fib_index = htonl (gt->inner_fib_index);
7396 mp->outer_fib_index = htonl (gt->outer_fib_index);
7397 mp->encap_index = htonl (gt->encap_index);
7398 mp->hw_if_index = htonl (gt->hw_if_index);
7399 mp->l2_only = htonl (gt->l2_only);
7400 mp->nlabels = htonl (nlabels);
7402 for (i = 0; i < nlabels; i++)
7405 htonl (vnet_mpls_uc_get_label
7406 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7409 vl_msg_api_send_shmem (q, (u8 *) & mp);
7413 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7415 vpe_api_main_t *am = &vpe_api_main;
7416 unix_shared_memory_queue_t *q;
7417 mpls_main_t *mm = &mpls_main;
7418 mpls_gre_tunnel_t *gt;
7419 u32 index = ntohl (mp->tunnel_index);
7421 q = vl_api_client_index_to_input_queue (mp->client_index);
7427 if (!pool_is_free_index (mm->gre_tunnels, index))
7429 gt = pool_elt_at_index (mm->gre_tunnels, index);
7430 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7437 pool_foreach (gt, mm->gre_tunnels,
7439 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7447 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7450 clib_warning ("BUG");
7454 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7455 unix_shared_memory_queue_t * q,
7456 mpls_eth_tunnel_t * et, u32 index, u32 context)
7458 mpls_main_t *mm = &mpls_main;
7462 vl_api_mpls_eth_tunnel_details_t *mp;
7464 e = pool_elt_at_index (mm->encaps, et->encap_index);
7465 nlabels = vec_len (e->labels);
7467 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7468 memset (mp, 0, sizeof (*mp));
7469 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7470 mp->context = context;
7472 mp->tunnel_index = htonl (index);
7473 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7474 mp->intfc_address = et->intfc_address.as_u32;
7475 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7476 mp->inner_fib_index = htonl (et->inner_fib_index);
7477 mp->mask_width = htonl (et->mask_width);
7478 mp->encap_index = htonl (et->encap_index);
7479 mp->hw_if_index = htonl (et->hw_if_index);
7480 mp->l2_only = htonl (et->l2_only);
7481 mp->nlabels = htonl (nlabels);
7483 for (i = 0; i < nlabels; i++)
7486 htonl (vnet_mpls_uc_get_label
7487 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7490 vl_msg_api_send_shmem (q, (u8 *) & mp);
7494 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7496 vpe_api_main_t *am = &vpe_api_main;
7497 unix_shared_memory_queue_t *q;
7498 mpls_main_t *mm = &mpls_main;
7499 mpls_eth_tunnel_t *et;
7500 u32 index = ntohl (mp->tunnel_index);
7502 q = vl_api_client_index_to_input_queue (mp->client_index);
7508 if (!pool_is_free_index (mm->eth_tunnels, index))
7510 et = pool_elt_at_index (mm->eth_tunnels, index);
7511 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7518 pool_foreach (et, mm->eth_tunnels,
7520 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7528 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7530 clib_warning ("BUG");
7534 send_mpls_fib_encap_details (vpe_api_main_t * am,
7535 unix_shared_memory_queue_t * q,
7536 show_mpls_fib_t * s, u32 context)
7538 vl_api_mpls_fib_encap_details_t *mp;
7539 mpls_main_t *mm = &mpls_main;
7544 e = pool_elt_at_index (mm->encaps, s->entry_index);
7545 nlabels = vec_len (e->labels);
7547 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7548 memset (mp, 0, sizeof (*mp));
7549 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7550 mp->context = context;
7552 mp->fib_index = htonl (s->fib_index);
7553 mp->entry_index = htonl (s->entry_index);
7555 mp->s_bit = htonl (s->s_bit);
7557 mp->nlabels = htonl (nlabels);
7559 for (i = 0; i < nlabels; i++)
7562 htonl (vnet_mpls_uc_get_label
7563 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7566 vl_msg_api_send_shmem (q, (u8 *) & mp);
7570 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7572 vpe_api_main_t *am = &vpe_api_main;
7573 unix_shared_memory_queue_t *q;
7574 vlib_main_t *vm = &vlib_global_main;
7577 show_mpls_fib_t *records = 0;
7579 mpls_main_t *mm = &mpls_main;
7582 q = vl_api_client_index_to_input_queue (mp->client_index);
7587 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7589 vec_add2 (records, s, 1);
7590 s->fib_index = (u32)(key>>32);
7591 s->dest = (u32)(key & 0xFFFFFFFF);
7592 s->entry_index = (u32) value;
7596 if (0 == vec_len (records))
7598 vlib_cli_output (vm, "MPLS encap table empty");
7602 /* sort output by dst address within fib */
7603 vec_sort_with_function (records, mpls_dest_cmp);
7604 vec_sort_with_function (records, mpls_fib_index_cmp);
7605 vlib_cli_output (vm, "MPLS encap table");
7606 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7607 vec_foreach (s, records)
7609 rx_fib = ip4_fib_get (s->fib_index);
7610 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7611 format_ip4_address, &s->dest, format_mpls_encap_index,
7612 mm, s->entry_index);
7613 send_mpls_fib_encap_details (am, q, s, mp->context);
7621 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7623 clib_warning ("BUG");
7627 send_mpls_fib_decap_details (vpe_api_main_t * am,
7628 unix_shared_memory_queue_t * q,
7629 show_mpls_fib_t * s,
7631 u32 tx_table_id, char *swif_tag, u32 context)
7633 vl_api_mpls_fib_decap_details_t *mp;
7635 mp = vl_msg_api_alloc (sizeof (*mp));
7636 memset (mp, 0, sizeof (*mp));
7637 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7638 mp->context = context;
7640 mp->fib_index = htonl (s->fib_index);
7641 mp->entry_index = htonl (s->entry_index);
7643 mp->s_bit = htonl (s->s_bit);
7644 mp->label = htonl (s->label);
7645 mp->rx_table_id = htonl (rx_table_id);
7646 mp->tx_table_id = htonl (tx_table_id);
7647 strncpy ((char *) mp->swif_tag,
7648 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7650 vl_msg_api_send_shmem (q, (u8 *) & mp);
7654 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7656 vpe_api_main_t *am = &vpe_api_main;
7657 unix_shared_memory_queue_t *q;
7658 vlib_main_t *vm = &vlib_global_main;
7661 show_mpls_fib_t *records = 0;
7663 mpls_main_t *mm = &mpls_main;
7669 q = vl_api_client_index_to_input_queue (mp->client_index);
7674 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7676 vec_add2 (records, s, 1);
7677 s->fib_index = (u32)(key>>32);
7678 s->entry_index = (u32) value;
7679 s->label = ((u32) key)>>12;
7680 s->s_bit = (key & (1<<8)) != 0;
7684 if (!vec_len (records))
7686 vlib_cli_output (vm, "MPLS decap table empty");
7690 vec_sort_with_function (records, mpls_label_cmp);
7691 vlib_cli_output (vm, "MPLS decap table");
7692 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7694 vec_foreach (s, records)
7697 d = pool_elt_at_index (mm->decaps, s->entry_index);
7698 if (d->next_index == MPLS_LOOKUP_NEXT_IP4_INPUT)
7700 tx_fib = ip4_fib_get (d->tx_fib_index);
7701 tx_table_id = tx_fib->table_id;
7706 tx_table_id = d->tx_fib_index;
7709 rx_fib = ip4_fib_get (s->fib_index);
7711 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7712 tx_table_id, swif_tag, s->label, s->s_bit);
7714 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7715 tx_table_id, swif_tag, mp->context);
7723 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7725 unix_shared_memory_queue_t *q;
7727 q = vl_api_client_index_to_input_queue (mp->client_index);
7731 vnet_classify_main_t *cm = &vnet_classify_main;
7732 vnet_classify_table_t *t;
7737 pool_foreach (t, cm->tables,
7739 vec_add1 (table_ids, ntohl(t - cm->tables));
7742 count = vec_len (table_ids);
7744 vl_api_classify_table_ids_reply_t *rmp;
7745 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7746 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7747 rmp->context = mp->context;
7748 rmp->count = ntohl (count);
7749 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7752 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7754 vec_free (table_ids);
7758 vl_api_classify_table_by_interface_t_handler
7759 (vl_api_classify_table_by_interface_t * mp)
7761 vl_api_classify_table_by_interface_reply_t *rmp;
7764 u32 sw_if_index = ntohl (mp->sw_if_index);
7767 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7770 VALIDATE_SW_IF_INDEX (mp);
7772 input_acl_main_t *am = &input_acl_main;
7777 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7779 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7780 if (vec_len (vec_tbl))
7782 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7784 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7788 acl[type] = vec_elt (vec_tbl, if_idx);
7793 BAD_SW_IF_INDEX_LABEL;
7796 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7798 rmp->sw_if_index = ntohl(sw_if_index);
7799 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7800 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7801 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7808 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7810 unix_shared_memory_queue_t *q;
7812 q = vl_api_client_index_to_input_queue (mp->client_index);
7816 vl_api_classify_table_info_reply_t *rmp = 0;
7818 vnet_classify_main_t *cm = &vnet_classify_main;
7819 u32 table_id = ntohl (mp->table_id);
7820 vnet_classify_table_t *t;
7823 pool_foreach (t, cm->tables,
7825 if (table_id == t - cm->tables)
7827 rmp = vl_msg_api_alloc_as_if_client
7828 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7829 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7830 rmp->context = mp->context;
7831 rmp->table_id = ntohl(table_id);
7832 rmp->nbuckets = ntohl(t->nbuckets);
7833 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7834 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7835 rmp->active_sessions = ntohl(t->active_elements);
7836 rmp->next_table_index = ntohl(t->next_table_index);
7837 rmp->miss_next_index = ntohl(t->miss_next_index);
7838 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7839 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7848 rmp = vl_msg_api_alloc (sizeof (*rmp));
7849 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7850 rmp->context = mp->context;
7851 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7854 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7858 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7861 clib_warning ("BUG");
7865 send_classify_session_details (unix_shared_memory_queue_t * q,
7868 vnet_classify_entry_t * e, u32 context)
7870 vl_api_classify_session_details_t *rmp;
7872 rmp = vl_msg_api_alloc (sizeof (*rmp));
7873 memset (rmp, 0, sizeof (*rmp));
7874 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7875 rmp->context = context;
7876 rmp->table_id = ntohl (table_id);
7877 rmp->hit_next_index = ntohl (e->next_index);
7878 rmp->advance = ntohl (e->advance);
7879 rmp->opaque_index = ntohl (e->opaque_index);
7880 rmp->match_length = ntohl (match_length);
7881 clib_memcpy (rmp->match, e->key, match_length);
7883 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7887 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7889 vnet_classify_main_t *cm = &vnet_classify_main;
7890 unix_shared_memory_queue_t *q;
7892 u32 table_id = ntohl (mp->table_id);
7893 vnet_classify_table_t *t;
7895 q = vl_api_client_index_to_input_queue (mp->client_index);
7900 pool_foreach (t, cm->tables,
7902 if (table_id == t - cm->tables)
7904 vnet_classify_bucket_t * b;
7905 vnet_classify_entry_t * v, * save_v;
7908 for (i = 0; i < t->nbuckets; i++)
7910 b = &t->buckets [i];
7914 save_v = vnet_classify_get_entry (t, b->offset);
7915 for (j = 0; j < (1<<b->log2_pages); j++)
7917 for (k = 0; k < t->entries_per_page; k++)
7919 v = vnet_classify_entry_at_index
7920 (t, save_v, j*t->entries_per_page + k);
7921 if (vnet_classify_entry_is_free (v))
7924 send_classify_session_details
7925 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7937 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7939 vlib_main_t *vm = vlib_get_main ();
7940 flow_report_main_t *frm = &flow_report_main;
7941 vl_api_set_ipfix_exporter_reply_t *rmp;
7942 ip4_address_t collector, src;
7943 u16 collector_port = UDP_DST_PORT_ipfix;
7945 u32 template_interval;
7951 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7952 collector_port = ntohs (mp->collector_port);
7953 if (collector_port == (u16) ~ 0)
7954 collector_port = UDP_DST_PORT_ipfix;
7955 memcpy (src.data, mp->src_address, sizeof (src.data));
7956 fib_id = ntohl (mp->vrf_id);
7958 ip4_main_t *im = &ip4_main;
7965 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7968 rv = VNET_API_ERROR_NO_SUCH_FIB;
7974 path_mtu = ntohl (mp->path_mtu);
7976 path_mtu = 512; // RFC 7011 section 10.3.3.
7977 template_interval = ntohl (mp->template_interval);
7978 if (template_interval == ~0)
7979 template_interval = 20;
7980 udp_checksum = mp->udp_checksum;
7982 if (collector.as_u32 == 0)
7984 rv = VNET_API_ERROR_INVALID_VALUE;
7988 if (src.as_u32 == 0)
7990 rv = VNET_API_ERROR_INVALID_VALUE;
7994 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7996 rv = VNET_API_ERROR_INVALID_VALUE;
8002 rv = VNET_API_ERROR_INVALID_VALUE;
8006 /* Reset report streams if we are reconfiguring IP addresses */
8007 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
8008 frm->src_address.as_u32 != src.as_u32 ||
8009 frm->collector_port != collector_port)
8010 vnet_flow_reports_reset (frm);
8012 frm->ipfix_collector.as_u32 = collector.as_u32;
8013 frm->collector_port = collector_port;
8014 frm->src_address.as_u32 = src.as_u32;
8015 frm->fib_index = fib_index;
8016 frm->path_mtu = path_mtu;
8017 frm->template_interval = template_interval;
8018 frm->udp_checksum = udp_checksum;
8020 /* Turn on the flow reporting process */
8021 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
8024 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
8028 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
8030 flow_report_main_t *frm = &flow_report_main;
8031 unix_shared_memory_queue_t *q;
8032 vl_api_ipfix_exporter_details_t *rmp;
8033 ip4_main_t *im = &ip4_main;
8036 q = vl_api_client_index_to_input_queue (mp->client_index);
8040 rmp = vl_msg_api_alloc (sizeof (*rmp));
8041 memset (rmp, 0, sizeof (*rmp));
8042 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
8043 rmp->context = mp->context;
8044 memcpy (rmp->collector_address, frm->ipfix_collector.data,
8045 sizeof (frm->ipfix_collector.data));
8046 rmp->collector_port = htons (frm->collector_port);
8047 memcpy (rmp->src_address, frm->src_address.data,
8048 sizeof (frm->src_address.data));
8049 if (frm->fib_index == ~0)
8052 vrf_id = im->fibs[frm->fib_index].ft_table_id;
8053 rmp->vrf_id = htonl (vrf_id);
8054 rmp->path_mtu = htonl (frm->path_mtu);
8055 rmp->template_interval = htonl (frm->template_interval);
8056 rmp->udp_checksum = (frm->udp_checksum != 0);
8058 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8062 vl_api_set_ipfix_classify_stream_t_handler
8063 (vl_api_set_ipfix_classify_stream_t * mp)
8065 vl_api_set_ipfix_classify_stream_reply_t *rmp;
8066 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8067 flow_report_main_t *frm = &flow_report_main;
8069 u32 src_port = UDP_DST_PORT_ipfix;
8072 domain_id = ntohl (mp->domain_id);
8073 src_port = ntohs (mp->src_port);
8075 if (fcm->src_port != 0 &&
8076 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
8078 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
8079 domain_id, (u16) src_port);
8083 fcm->domain_id = domain_id;
8084 fcm->src_port = (u16) src_port;
8086 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8090 vl_api_ipfix_classify_stream_dump_t_handler
8091 (vl_api_ipfix_classify_stream_dump_t * mp)
8093 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8094 unix_shared_memory_queue_t *q;
8095 vl_api_ipfix_classify_stream_details_t *rmp;
8097 q = vl_api_client_index_to_input_queue (mp->client_index);
8101 rmp = vl_msg_api_alloc (sizeof (*rmp));
8102 memset (rmp, 0, sizeof (*rmp));
8103 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
8104 rmp->context = mp->context;
8105 rmp->domain_id = htonl (fcm->domain_id);
8106 rmp->src_port = htons (fcm->src_port);
8108 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8112 vl_api_ipfix_classify_table_add_del_t_handler
8113 (vl_api_ipfix_classify_table_add_del_t * mp)
8115 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
8116 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8117 flow_report_main_t *frm = &flow_report_main;
8118 vnet_flow_report_add_del_args_t args;
8119 ipfix_classify_table_t *table;
8121 u32 classify_table_index;
8123 u8 transport_protocol;
8126 classify_table_index = ntohl (mp->table_id);
8127 ip_version = mp->ip_version;
8128 transport_protocol = mp->transport_protocol;
8129 is_add = mp->is_add;
8131 if (fcm->src_port == 0)
8133 /* call set_ipfix_classify_stream first */
8134 rv = VNET_API_ERROR_UNSPECIFIED;
8138 memset (&args, 0, sizeof (args));
8142 for (i = 0; i < vec_len (fcm->tables); i++)
8143 if (ipfix_classify_table_index_valid (i))
8144 if (fcm->tables[i].classify_table_index == classify_table_index)
8146 table = &fcm->tables[i];
8154 rv = VNET_API_ERROR_VALUE_EXIST;
8157 table = ipfix_classify_add_table ();
8158 table->classify_table_index = classify_table_index;
8164 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
8169 table->ip_version = ip_version;
8170 table->transport_protocol = transport_protocol;
8172 args.opaque.as_uword = table - fcm->tables;
8173 args.rewrite_callback = ipfix_classify_template_rewrite;
8174 args.flow_data_callback = ipfix_classify_send_flows;
8175 args.is_add = is_add;
8176 args.domain_id = fcm->domain_id;
8177 args.src_port = fcm->src_port;
8179 rv = vnet_flow_report_add_del (frm, &args);
8181 /* If deleting, or add failed */
8182 if (is_add == 0 || (rv && is_add))
8183 ipfix_classify_delete_table (table - fcm->tables);
8186 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8190 send_ipfix_classify_table_details (u32 table_index,
8191 unix_shared_memory_queue_t * q,
8194 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8195 vl_api_ipfix_classify_table_details_t *mp;
8197 ipfix_classify_table_t *table = &fcm->tables[table_index];
8199 mp = vl_msg_api_alloc (sizeof (*mp));
8200 memset (mp, 0, sizeof (*mp));
8201 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
8202 mp->context = context;
8203 mp->table_id = htonl (table->classify_table_index);
8204 mp->ip_version = table->ip_version;
8205 mp->transport_protocol = table->transport_protocol;
8207 vl_msg_api_send_shmem (q, (u8 *) & mp);
8211 vl_api_ipfix_classify_table_dump_t_handler
8212 (vl_api_ipfix_classify_table_dump_t * mp)
8214 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8215 unix_shared_memory_queue_t *q;
8218 q = vl_api_client_index_to_input_queue (mp->client_index);
8222 for (i = 0; i < vec_len (fcm->tables); i++)
8223 if (ipfix_classify_table_index_valid (i))
8224 send_ipfix_classify_table_details (i, q, mp->context);
8228 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8230 vl_api_pg_create_interface_reply_t *rmp;
8233 pg_main_t *pg = &pg_main;
8234 u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8235 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
8238 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8240 rmp->sw_if_index = ntohl(pi->sw_if_index);
8246 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8248 vl_api_pg_capture_reply_t *rmp;
8251 vnet_main_t *vnm = vnet_get_main ();
8252 vnet_interface_main_t *im = &vnm->interface_main;
8253 vnet_hw_interface_t *hi = 0;
8255 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8256 u32 hw_if_index = ~0;
8257 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8260 vec_free (intf_name);
8262 if (hw_if_index != ~0)
8264 pg_capture_args_t _a, *a = &_a;
8266 u32 len = ntohl (mp->pcap_name_length);
8267 u8 *pcap_file_name = vec_new (u8, len);
8268 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8270 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8271 a->hw_if_index = hw_if_index;
8272 a->dev_instance = hi->dev_instance;
8273 a->is_enabled = mp->is_enabled;
8274 a->pcap_file_name = pcap_file_name;
8275 a->count = ntohl (mp->count);
8277 clib_error_t *e = pg_capture (a);
8280 clib_error_report (e);
8281 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8284 vec_free (pcap_file_name);
8286 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8290 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8292 vl_api_pg_enable_disable_reply_t *rmp;
8295 pg_main_t *pg = &pg_main;
8296 u32 stream_index = ~0;
8298 int is_enable = mp->is_enabled != 0;
8299 u32 len = ntohl (mp->stream_name_length) - 1;
8303 u8 *stream_name = vec_new (u8, len);
8304 clib_memcpy (stream_name, mp->stream_name, len);
8305 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8308 vec_free (stream_name);
8311 pg_enable_disable (stream_index, is_enable);
8313 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8317 vl_api_ip_source_and_port_range_check_add_del_t_handler
8318 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8320 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8323 u8 is_ipv6 = mp->is_ipv6;
8324 u8 is_add = mp->is_add;
8325 u8 mask_length = mp->mask_length;
8326 ip4_address_t ip4_addr;
8327 ip6_address_t ip6_addr;
8329 u16 *high_ports = 0;
8331 u16 tmp_low, tmp_high;
8335 // Validate port range
8336 num_ranges = mp->number_of_ranges;
8337 if (num_ranges > 32)
8338 { // This is size of array in VPE.API
8339 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8343 vec_reset_length (low_ports);
8344 vec_reset_length (high_ports);
8346 for (i = 0; i < num_ranges; i++)
8348 tmp_low = mp->low_ports[i];
8349 tmp_high = mp->high_ports[i];
8350 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8351 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8352 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8354 rv = VNET_API_ERROR_INVALID_VALUE;
8357 vec_add1 (low_ports, tmp_low);
8358 vec_add1 (high_ports, tmp_high + 1);
8361 // Validate mask_length
8362 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8364 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8368 vrf_id = ntohl (mp->vrf_id);
8372 rv = VNET_API_ERROR_INVALID_VALUE;
8379 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8380 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8384 high_ports, is_add);
8388 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8389 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8393 high_ports, is_add);
8397 vec_free (low_ports);
8398 vec_free (high_ports);
8399 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8403 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8404 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8406 vlib_main_t *vm = vlib_get_main ();
8407 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8408 ip4_main_t *im = &ip4_main;
8411 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8412 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8416 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8417 ntohl (mp->tcp_out_vrf_id);
8418 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8419 ntohl (mp->udp_out_vrf_id);
8420 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8421 ntohl (mp->tcp_in_vrf_id);
8422 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8423 ntohl (mp->udp_in_vrf_id);
8426 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8428 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8430 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8434 rv = VNET_API_ERROR_INVALID_VALUE;
8438 fib_index[i] = p[0];
8443 sw_if_index = ntohl (mp->sw_if_index);
8445 VALIDATE_SW_IF_INDEX (mp);
8448 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8451 BAD_SW_IF_INDEX_LABEL;
8454 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8458 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8461 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8463 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8464 u32 sw_if_index = ~0;
8466 /* Check src & dst are different */
8467 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8469 rv = VNET_API_ERROR_SAME_SRC_DST;
8473 memset (a, 0, sizeof (*a));
8475 /* ip addresses sent in network byte order */
8476 clib_memcpy (&(a->src), mp->src_address, 4);
8477 clib_memcpy (&(a->dst), mp->dst_address, 4);
8478 a->is_add = mp->is_add;
8479 a->lsa = ntohl (mp->local_sa_id);
8480 a->rsa = ntohl (mp->remote_sa_id);
8482 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8486 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8488 rmp->sw_if_index = ntohl (sw_if_index);
8493 static void send_ipsec_gre_tunnel_details
8494 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8496 vl_api_ipsec_gre_tunnel_details_t *rmp;
8498 rmp = vl_msg_api_alloc (sizeof (*rmp));
8499 memset (rmp, 0, sizeof (*rmp));
8500 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8501 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8502 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8503 rmp->sw_if_index = htonl (t->sw_if_index);
8504 rmp->local_sa_id = htonl (t->local_sa_id);
8505 rmp->remote_sa_id = htonl (t->remote_sa_id);
8506 rmp->context = context;
8508 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8511 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8512 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8514 unix_shared_memory_queue_t *q;
8515 ipsec_gre_main_t *igm = &ipsec_gre_main;
8516 ipsec_gre_tunnel_t *t;
8519 q = vl_api_client_index_to_input_queue (mp->client_index);
8525 sw_if_index = ntohl (mp->sw_if_index);
8527 if (~0 == sw_if_index)
8530 pool_foreach (t, igm->tunnels,
8532 send_ipsec_gre_tunnel_details(t, q, mp->context);
8538 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8539 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8543 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8544 send_ipsec_gre_tunnel_details (t, q, mp->context);
8549 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8551 vl_api_delete_subif_reply_t *rmp;
8554 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8556 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8560 vl_api_l2_interface_pbb_tag_rewrite_t_handler
8561 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
8563 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
8564 vnet_main_t *vnm = vnet_get_main ();
8565 vlib_main_t *vm = vlib_get_main ();
8569 VALIDATE_SW_IF_INDEX (mp);
8571 vtr_op = ntohl (mp->vtr_op);
8575 case L2_VTR_DISABLED:
8578 case L2_VTR_TRANSLATE_2_1:
8582 rv = VNET_API_ERROR_INVALID_VALUE;
8583 goto bad_sw_if_index;
8586 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
8587 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
8588 ntohl (mp->i_sid), ntohs (mp->outer_tag));
8590 BAD_SW_IF_INDEX_LABEL;
8592 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
8596 vl_api_punt_t_handler (vl_api_punt_t * mp)
8598 vl_api_punt_reply_t *rmp;
8599 vlib_main_t *vm = vlib_get_main ();
8601 clib_error_t *error;
8603 error = vnet_punt_add_del (vm, mp->ipv, mp->l4_protocol,
8604 ntohs (mp->l4_port), mp->is_add);
8608 clib_error_report (error);
8611 REPLY_MACRO (VL_API_PUNT_REPLY);
8615 vl_api_flow_classify_set_interface_t_handler
8616 (vl_api_flow_classify_set_interface_t * mp)
8618 vlib_main_t *vm = vlib_get_main ();
8619 vl_api_flow_classify_set_interface_reply_t *rmp;
8621 u32 sw_if_index, ip4_table_index, ip6_table_index;
8623 ip4_table_index = ntohl (mp->ip4_table_index);
8624 ip6_table_index = ntohl (mp->ip6_table_index);
8625 sw_if_index = ntohl (mp->sw_if_index);
8627 VALIDATE_SW_IF_INDEX (mp);
8629 rv = vnet_set_flow_classify_intfc (vm, sw_if_index, ip4_table_index,
8630 ip6_table_index, mp->is_add);
8632 BAD_SW_IF_INDEX_LABEL;
8634 REPLY_MACRO (VL_API_FLOW_CLASSIFY_SET_INTERFACE_REPLY);
8638 send_flow_classify_details (u32 sw_if_index,
8640 unix_shared_memory_queue_t * q, u32 context)
8642 vl_api_flow_classify_details_t *mp;
8644 mp = vl_msg_api_alloc (sizeof (*mp));
8645 memset (mp, 0, sizeof (*mp));
8646 mp->_vl_msg_id = ntohs (VL_API_FLOW_CLASSIFY_DETAILS);
8647 mp->context = context;
8648 mp->sw_if_index = htonl (sw_if_index);
8649 mp->table_index = htonl (table_index);
8651 vl_msg_api_send_shmem (q, (u8 *) & mp);
8655 vl_api_flow_classify_dump_t_handler (vl_api_flow_classify_dump_t * mp)
8657 unix_shared_memory_queue_t *q;
8658 flow_classify_main_t *pcm = &flow_classify_main;
8662 q = vl_api_client_index_to_input_queue (mp->client_index);
8666 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
8668 if (vec_len (vec_tbl))
8670 for (i = 0; i < vec_len (vec_tbl); i++)
8672 if (vec_elt (vec_tbl, i) == ~0)
8675 send_flow_classify_details (i, vec_elt (vec_tbl, i), q,
8681 #define BOUNCE_HANDLER(nn) \
8682 static void vl_api_##nn##_t_handler ( \
8683 vl_api_##nn##_t *mp) \
8685 vpe_client_registration_t *reg; \
8686 vpe_api_main_t * vam = &vpe_api_main; \
8687 unix_shared_memory_queue_t * q; \
8689 /* One registration only... */ \
8690 pool_foreach(reg, vam->nn##_registrations, \
8692 q = vl_api_client_index_to_input_queue (reg->client_index); \
8695 * If the queue is stuffed, turf the msg and complain \
8696 * It's unlikely that the intended recipient is \
8697 * alive; avoid deadlock at all costs. \
8699 if (q->cursize == q->maxsize) { \
8700 clib_warning ("ERROR: receiver queue full, drop msg"); \
8701 vl_msg_api_free (mp); \
8704 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8708 vl_msg_api_free (mp); \
8713 * Add vpe's API message handlers to the table.
8714 * vlib has alread mapped shared memory and
8715 * added the client registration handlers.
8716 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8719 static clib_error_t *
8720 vpe_api_hookup (vlib_main_t * vm)
8722 api_main_t *am = &api_main;
8725 vl_msg_api_set_handlers(VL_API_##N, #n, \
8726 vl_api_##n##_t_handler, \
8728 vl_api_##n##_t_endian, \
8729 vl_api_##n##_t_print, \
8730 sizeof(vl_api_##n##_t), 1);
8731 foreach_vpe_api_msg;
8735 * Manually register the sr tunnel add del msg, so we trace
8736 * enough bytes to capture a typical segment list
8738 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8739 "sr_tunnel_add_del",
8740 vl_api_sr_tunnel_add_del_t_handler,
8742 vl_api_sr_tunnel_add_del_t_endian,
8743 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8747 * Manually register the sr policy add del msg, so we trace
8748 * enough bytes to capture a typical tunnel name list
8750 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8751 "sr_policy_add_del",
8752 vl_api_sr_policy_add_del_t_handler,
8754 vl_api_sr_policy_add_del_t_endian,
8755 vl_api_sr_policy_add_del_t_print, 256, 1);
8758 * Trace space for 8 MPLS encap labels, classifier mask+match
8760 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8761 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8762 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8763 += 5 * sizeof (u32x4);
8764 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8767 * Thread-safe API messages
8769 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8770 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8775 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8777 static clib_error_t *
8778 vpe_api_init (vlib_main_t * vm)
8780 vpe_api_main_t *am = &vpe_api_main;
8783 am->vnet_main = vnet_get_main ();
8784 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8785 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8786 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8787 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8788 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8789 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8792 vl_set_memory_region_name ("/vpe-api");
8793 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8798 VLIB_INIT_FUNCTION (vpe_api_init);
8801 static clib_error_t *
8802 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8805 u64 baseva, size, pvt_heap_size;
8807 const int max_buf_size = 4096;
8809 struct passwd _pw, *pw;
8810 struct group _grp, *grp;
8812 buf = vec_new (char, 128);
8813 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8815 if (unformat (input, "prefix %s", &chroot_path))
8817 vec_add1 (chroot_path, 0);
8818 vl_set_memory_root_path ((char *) chroot_path);
8820 else if (unformat (input, "uid %d", &uid))
8821 vl_set_memory_uid (uid);
8822 else if (unformat (input, "gid %d", &gid))
8823 vl_set_memory_gid (gid);
8824 else if (unformat (input, "baseva %llx", &baseva))
8825 vl_set_global_memory_baseva (baseva);
8826 else if (unformat (input, "global-size %lldM", &size))
8827 vl_set_global_memory_size (size * (1ULL << 20));
8828 else if (unformat (input, "global-size %lldG", &size))
8829 vl_set_global_memory_size (size * (1ULL << 30));
8830 else if (unformat (input, "global-size %lld", &size))
8831 vl_set_global_memory_size (size);
8832 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8833 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8834 else if (unformat (input, "global-pvt-heap-size size %lld",
8836 vl_set_global_pvt_heap_size (pvt_heap_size);
8837 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8838 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8839 else if (unformat (input, "api-pvt-heap-size size %lld",
8841 vl_set_api_pvt_heap_size (pvt_heap_size);
8842 else if (unformat (input, "api-size %lldM", &size))
8843 vl_set_api_memory_size (size * (1ULL << 20));
8844 else if (unformat (input, "api-size %lldG", &size))
8845 vl_set_api_memory_size (size * (1ULL << 30));
8846 else if (unformat (input, "api-size %lld", &size))
8847 vl_set_api_memory_size (size);
8848 else if (unformat (input, "uid %s", &s))
8850 /* lookup the username */
8853 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8854 && (vec_len (buf) <= max_buf_size))
8856 vec_resize (buf, vec_len (buf) * 2);
8860 e = clib_error_return_code (0, rv,
8861 CLIB_ERROR_ERRNO_VALID |
8863 "cannot fetch username %s", s);
8871 clib_error_return_fatal (0, "username %s does not exist", s);
8877 vl_set_memory_uid (pw->pw_uid);
8879 else if (unformat (input, "gid %s", &s))
8881 /* lookup the group name */
8884 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8885 && (vec_len (buf) <= max_buf_size))
8887 vec_resize (buf, vec_len (buf) * 2);
8891 e = clib_error_return_code (0, rv,
8892 CLIB_ERROR_ERRNO_VALID |
8894 "cannot fetch group %s", s);
8901 e = clib_error_return_fatal (0, "group %s does not exist", s);
8908 vl_set_memory_gid (grp->gr_gid);
8911 return clib_error_return (0, "unknown input `%U'",
8912 format_unformat_error, input);
8917 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8920 get_unformat_vnet_sw_interface (void)
8922 return (void *) &unformat_vnet_sw_interface;
8925 #undef vl_api_version
8926 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8927 #include <vpp-api/vpe.api.h>
8928 #undef vl_api_version
8931 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8933 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8935 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8936 clib_host_to_net_u32 (mp->api_versions[0]),
8944 format_arp_event (u8 * s, va_list * args)
8946 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8948 s = format (s, "pid %d: ", event->pid);
8950 s = format (s, "bd mac/ip4 binding events");
8952 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8957 format_nd_event (u8 * s, va_list * args)
8959 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8961 s = format (s, "pid %d: ", event->pid);
8963 s = format (s, "bd mac/ip6 binding events");
8965 s = format (s, "resolution for %U", format_ip6_address, event->address);
8969 static clib_error_t *
8970 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8971 unformat_input_t * input, vlib_cli_command_t * cmd)
8973 vpe_api_main_t *am = &vpe_api_main;
8974 vl_api_ip4_arp_event_t *arp_event;
8975 vl_api_ip6_nd_event_t *nd_event;
8977 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8979 vlib_cli_output (vm, "No active arp or nd event registrations");
8984 pool_foreach (arp_event, am->arp_events,
8986 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8989 pool_foreach (nd_event, am->nd_events,
8991 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8999 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
9000 .path = "show arp-nd-event registrations",
9001 .function = show_ip_arp_nd_events_fn,
9002 .short_help = "Show ip4 arp and ip6 nd event registrations",
9007 * fd.io coding-style-patch-verification: ON
9010 * eval: (c-set-style "gnu")