2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010 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/l2/l2_classify.h>
72 #include <vnet/vxlan/vxlan.h>
73 #include <vnet/gre/gre.h>
74 #include <vnet/l2/l2_vtr.h>
75 #include <vnet/vxlan-gpe/vxlan_gpe.h>
76 #include <vnet/lisp-gpe/lisp_gpe.h>
77 #include <vnet/lisp-cp/control.h>
78 #include <vnet/map/map.h>
79 #include <vnet/cop/cop.h>
80 #include <vnet/ip/ip6_hop_by_hop.h>
81 #include <vnet/ip/ip_source_and_port_range_check.h>
82 #include <vnet/devices/af_packet/af_packet.h>
83 #include <vnet/policer/policer.h>
84 #include <vnet/devices/netmap/netmap.h>
85 #include <vnet/flow/flow_report.h>
86 #include <vnet/ipsec-gre/ipsec_gre.h>
87 #include <vnet/flow/flow_report_classify.h>
90 #undef __included_bihash_template_h__
91 #include <vnet/l2/l2_fib.h>
94 #include <vnet/ipsec/ipsec.h>
95 #include <vnet/ipsec/ikev2.h>
97 #include <vnet/devices/virtio/vhost-user.h>
99 #include <stats/stats.h>
102 #include <vnet/ethernet/ethernet.h>
103 #include <vnet/ethernet/arp_packet.h>
104 #include <vnet/interface.h>
106 #include <vnet/l2/l2_fib.h>
107 #include <vnet/l2/l2_bd.h>
108 #include <vpp-api/vpe_msg_enum.h>
110 #include <vnet/fib/ip6_fib.h>
111 #include <vnet/fib/ip4_fib.h>
112 #include <vnet/dpo/drop_dpo.h>
113 #include <vnet/dpo/receive_dpo.h>
114 #include <vnet/dpo/lookup_dpo.h>
115 #include <vnet/dpo/classify_dpo.h>
117 #define f64_endian(a)
118 #define f64_print(a,b)
120 #define vl_typedefs /* define message structures */
121 #include <vpp-api/vpe_all_api_h.h>
124 #define vl_endianfun /* define message structures */
125 #include <vpp-api/vpe_all_api_h.h>
128 /* instantiate all the print functions we know about */
129 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
131 #include <vpp-api/vpe_all_api_h.h>
134 #define REPLY_MACRO(t) \
136 unix_shared_memory_queue_t * q; \
137 rv = vl_msg_api_pd_handler (mp, rv); \
138 q = vl_api_client_index_to_input_queue (mp->client_index); \
142 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
143 rmp->_vl_msg_id = ntohs((t)); \
144 rmp->context = mp->context; \
145 rmp->retval = ntohl(rv); \
147 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
150 #define REPLY_MACRO2(t, body) \
152 unix_shared_memory_queue_t * q; \
153 rv = vl_msg_api_pd_handler (mp, rv); \
154 q = vl_api_client_index_to_input_queue (mp->client_index); \
158 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
159 rmp->_vl_msg_id = ntohs((t)); \
160 rmp->context = mp->context; \
161 rmp->retval = ntohl(rv); \
162 do {body;} while (0); \
163 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
166 #define REPLY_MACRO3(t, n, body) \
168 unix_shared_memory_queue_t * q; \
169 rv = vl_msg_api_pd_handler (mp, rv); \
170 q = vl_api_client_index_to_input_queue (mp->client_index); \
174 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
175 rmp->_vl_msg_id = ntohs((t)); \
176 rmp->context = mp->context; \
177 rmp->retval = ntohl(rv); \
178 do {body;} while (0); \
179 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
182 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
184 #define VALIDATE_SW_IF_INDEX(mp) \
185 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
186 vnet_main_t *__vnm = vnet_get_main(); \
187 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
189 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
190 goto bad_sw_if_index; \
194 #define BAD_SW_IF_INDEX_LABEL \
200 #define VALIDATE_RX_SW_IF_INDEX(mp) \
201 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
202 vnet_main_t *__vnm = vnet_get_main(); \
203 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
204 __rx_sw_if_index)) { \
205 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
206 goto bad_rx_sw_if_index; \
210 #define BAD_RX_SW_IF_INDEX_LABEL \
212 bad_rx_sw_if_index: \
216 #define VALIDATE_TX_SW_IF_INDEX(mp) \
217 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
218 vnet_main_t *__vnm = vnet_get_main(); \
219 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
220 __tx_sw_if_index)) { \
221 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
222 goto bad_tx_sw_if_index; \
226 #define BAD_TX_SW_IF_INDEX_LABEL \
228 bad_tx_sw_if_index: \
234 #define VALIDATE_SW_IF_INDEX(mp)
235 #define BAD_SW_IF_INDEX_LABEL
236 #define VALIDATE_RX_SW_IF_INDEX(mp)
237 #define BAD_RX_SW_IF_INDEX_LABEL
238 #define VALIDATE_TX_SW_IF_INDEX(mp)
239 #define BAD_TX_SW_IF_INDEX_LABEL
241 #endif /* CLIB_DEBUG > 0 */
243 #define foreach_vpe_api_msg \
244 _(WANT_INTERFACE_EVENTS, want_interface_events) \
245 _(WANT_OAM_EVENTS, want_oam_events) \
246 _(OAM_ADD_DEL, oam_add_del) \
247 _(SW_INTERFACE_DUMP, sw_interface_dump) \
248 _(SW_INTERFACE_DETAILS, sw_interface_details) \
249 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
250 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
251 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
252 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
253 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
254 _(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \
255 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
256 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
257 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
258 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
259 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
260 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
261 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
262 _(L2FIB_ADD_DEL, l2fib_add_del) \
263 _(L2_FLAGS, l2_flags) \
264 _(BRIDGE_FLAGS, bridge_flags) \
265 _(TAP_CONNECT, tap_connect) \
266 _(TAP_MODIFY, tap_modify) \
267 _(TAP_DELETE, tap_delete) \
268 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
269 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
270 _(CREATE_SUBIF, create_subif) \
271 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
272 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
273 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
274 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
275 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
276 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
277 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
278 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
279 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
280 _(RESET_FIB, reset_fib) \
281 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
282 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
283 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
284 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
285 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
286 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
287 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
288 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
289 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
290 sw_interface_ip6_set_link_local_address) \
291 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
292 _(CREATE_LOOPBACK, create_loopback) \
293 _(CONTROL_PING, control_ping) \
294 _(CLI_REQUEST, cli_request) \
295 _(CLI_INBAND, cli_inband) \
296 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
297 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
298 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
299 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
300 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
301 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
302 _(GET_NODE_INDEX, get_node_index) \
303 _(ADD_NODE_NEXT, add_node_next) \
304 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
305 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
306 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
307 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
308 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
309 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
310 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
311 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
312 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
313 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
314 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
315 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
316 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
317 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
318 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
319 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
320 _(IP_ADDRESS_DUMP, ip_address_dump) \
321 _(IP_DUMP, ip_dump) \
322 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
323 _(SHOW_VERSION, show_version) \
324 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
325 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
326 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
327 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
328 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
329 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
330 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
331 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
332 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
333 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
334 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
335 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
336 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
337 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
338 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
339 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
340 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
341 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
342 _(DELETE_LOOPBACK, delete_loopback) \
343 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
344 _(MAP_ADD_DOMAIN, map_add_domain) \
345 _(MAP_DEL_DOMAIN, map_del_domain) \
346 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
347 _(MAP_DOMAIN_DUMP, map_domain_dump) \
348 _(MAP_RULE_DUMP, map_rule_dump) \
349 _(MAP_SUMMARY_STATS, map_summary_stats) \
350 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
351 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
352 _(GET_NODE_GRAPH, get_node_graph) \
353 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
354 _(IOAM_ENABLE, ioam_enable) \
355 _(IOAM_DISABLE, ioam_disable) \
356 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
357 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
358 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
359 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
360 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
361 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
362 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
363 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
364 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
365 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
366 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
367 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
368 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
369 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
370 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
371 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
372 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
373 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
374 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
375 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
376 _(SHOW_LISP_STATUS, show_lisp_status) \
377 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
378 lisp_add_del_map_request_itr_rlocs) \
379 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
380 _(SHOW_LISP_PITR, show_lisp_pitr) \
381 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
382 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
383 _(AF_PACKET_CREATE, af_packet_create) \
384 _(AF_PACKET_DELETE, af_packet_delete) \
385 _(POLICER_ADD_DEL, policer_add_del) \
386 _(POLICER_DUMP, policer_dump) \
387 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
388 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
389 _(NETMAP_CREATE, netmap_create) \
390 _(NETMAP_DELETE, netmap_delete) \
391 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
392 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
393 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
394 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
395 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
396 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
397 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
398 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
399 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
400 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
401 _(CLASSIFY_TABLE_INFO,classify_table_info) \
402 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
403 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
404 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
405 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
406 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
407 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
408 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
409 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
410 _(GET_NEXT_INDEX, get_next_index) \
411 _(PG_CREATE_INTERFACE, pg_create_interface) \
412 _(PG_CAPTURE, pg_capture) \
413 _(PG_ENABLE_DISABLE, pg_enable_disable) \
414 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
415 ip_source_and_port_range_check_add_del) \
416 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
417 ip_source_and_port_range_check_interface_add_del) \
418 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
419 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
420 _(DELETE_SUBIF, delete_subif)
423 #define QUOTE(x) QUOTE_(x)
425 #define foreach_registration_hash \
426 _(interface_events) \
427 _(to_netconf_server) \
428 _(from_netconf_server) \
429 _(to_netconf_client) \
430 _(from_netconf_client) \
435 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
436 RESOLVE_IP6_ADD_DEL_ROUTE,
437 RESOLVE_MPLS_ETHERNET_ADD_DEL,
445 vl_api_ip_add_del_route_t r;
446 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
453 #define _(a) uword *a##_registration_hash; \
454 vpe_client_registration_t * a##_registrations;
455 foreach_registration_hash
457 /* notifications happen really early in the game */
458 u8 link_state_process_up;
460 /* ip4 and ip6 pending route adds */
461 pending_route_t *pending_routes;
463 /* ip4 arp event registration pool */
464 vl_api_ip4_arp_event_t *arp_events;
466 /* ip6 nd event registration pool */
467 vl_api_ip6_nd_event_t *nd_events;
470 vlib_main_t *vlib_main;
471 vnet_main_t *vnet_main;
474 static vlib_node_registration_t vpe_resolver_process_node;
475 static vpe_api_main_t vpe_api_main;
477 static void send_sw_interface_flags (vpe_api_main_t * am,
478 unix_shared_memory_queue_t * q,
479 vnet_sw_interface_t * swif);
480 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
481 unix_shared_memory_queue_t * q,
484 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
485 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
488 /* Clean up all registrations belonging to the indicated client */
490 vl_api_memclnt_delete_callback (u32 client_index)
492 vpe_api_main_t *vam = &vpe_api_main;
493 vpe_client_registration_t *rp;
495 int stats_memclnt_delete_callback (u32 client_index);
497 stats_memclnt_delete_callback (client_index);
500 p = hash_get (vam->a##_registration_hash, client_index); \
502 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
503 pool_put (vam->a##_registrations, rp); \
504 hash_unset (vam->a##_registration_hash, client_index); \
506 foreach_registration_hash;
511 #define API_LINK_STATE_EVENT 1
512 #define API_ADMIN_UP_DOWN_EVENT 2
515 event_data_cmp (void *a1, void *a2)
520 return (word) e1[0] - (word) e2[0];
524 link_state_process (vlib_main_t * vm,
525 vlib_node_runtime_t * rt, vlib_frame_t * f)
527 vpe_api_main_t *vam = &vpe_api_main;
528 vnet_main_t *vnm = vam->vnet_main;
529 vnet_sw_interface_t *swif;
530 uword *event_data = 0;
531 vpe_client_registration_t *reg;
533 u32 prev_sw_if_index;
534 unix_shared_memory_queue_t *q;
536 vam->link_state_process_up = 1;
540 vlib_process_wait_for_event (vm);
542 /* Unified list of changed link or admin state sw_if_indices */
543 vlib_process_get_events_with_type
544 (vm, &event_data, API_LINK_STATE_EVENT);
545 vlib_process_get_events_with_type
546 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
548 /* Sort, so we can eliminate duplicates */
549 vec_sort_with_function (event_data, event_data_cmp);
551 prev_sw_if_index = ~0;
553 for (i = 0; i < vec_len (event_data); i++)
555 /* Only one message per swif */
556 if (prev_sw_if_index == event_data[i])
558 prev_sw_if_index = event_data[i];
561 pool_foreach(reg, vam->interface_events_registrations,
563 q = vl_api_client_index_to_input_queue (reg->client_index);
566 /* sw_interface may be deleted already */
567 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
570 swif = vnet_get_sw_interface (vnm, event_data[i]);
571 send_sw_interface_flags (vam, q, swif);
577 vec_reset_length (event_data);
583 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
585 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
586 u32 hw_if_index, u32 flags);
589 VLIB_REGISTER_NODE (link_state_process_node,static) = {
590 .function = link_state_process,
591 .type = VLIB_NODE_TYPE_PROCESS,
592 .name = "vpe-link-state-process",
596 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
597 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
599 static clib_error_t *
600 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
602 vpe_api_main_t *vam = &vpe_api_main;
603 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
605 if (vam->link_state_process_up)
606 vlib_process_signal_event (vam->vlib_main,
607 link_state_process_node.index,
608 API_LINK_STATE_EVENT, hi->sw_if_index);
612 static clib_error_t *
613 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
615 vpe_api_main_t *vam = &vpe_api_main;
618 * Note: it's perfectly fair to set a subif admin up / admin down.
619 * Note the subtle distinction between this routine and the previous
622 if (vam->link_state_process_up)
623 vlib_process_signal_event (vam->vlib_main,
624 link_state_process_node.index,
625 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
629 #define pub_sub_handler(lca,UCA) \
630 static void vl_api_want_##lca##_t_handler ( \
631 vl_api_want_##lca##_t *mp) \
633 vpe_api_main_t *vam = &vpe_api_main; \
634 vpe_client_registration_t *rp; \
635 vl_api_want_##lca##_reply_t *rmp; \
639 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
641 if (mp->enable_disable) { \
642 clib_warning ("pid %d: already enabled...", mp->pid); \
643 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
646 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
647 pool_put (vam->lca##_registrations, rp); \
648 hash_unset (vam->lca##_registration_hash, \
653 if (mp->enable_disable == 0) { \
654 clib_warning ("pid %d: already disabled...", mp->pid); \
655 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
658 pool_get (vam->lca##_registrations, rp); \
659 rp->client_index = mp->client_index; \
660 rp->client_pid = mp->pid; \
661 hash_set (vam->lca##_registration_hash, rp->client_index, \
662 rp - vam->lca##_registrations); \
665 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
669 pub_sub_handler (interface_events, INTERFACE_EVENTS)
670 pub_sub_handler (oam_events, OAM_EVENTS)
673 #define RESOLUTION_EVENT 1
674 #define RESOLUTION_PENDING_EVENT 2
675 #define IP4_ARP_EVENT 3
676 #define IP6_ND_EVENT 4
678 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
680 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
682 static int mpls_ethernet_add_del_tunnel_2_t_handler
683 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
686 handle_ip4_arp_event (u32 pool_index)
688 vpe_api_main_t *vam = &vpe_api_main;
689 vnet_main_t *vnm = vam->vnet_main;
690 vlib_main_t *vm = vam->vlib_main;
691 vl_api_ip4_arp_event_t *event;
692 vl_api_ip4_arp_event_t *mp;
693 unix_shared_memory_queue_t *q;
695 /* Client can cancel, die, etc. */
696 if (pool_is_free_index (vam->arp_events, pool_index))
699 event = pool_elt_at_index (vam->arp_events, pool_index);
701 q = vl_api_client_index_to_input_queue (event->client_index);
704 (void) vnet_add_del_ip4_arp_change_event
705 (vnm, arp_change_delete_callback,
706 event->pid, &event->address,
707 vpe_resolver_process_node.index, IP4_ARP_EVENT,
708 ~0 /* pool index, notused */ , 0 /* is_add */ );
712 if (q->cursize < q->maxsize)
714 mp = vl_msg_api_alloc (sizeof (*mp));
715 clib_memcpy (mp, event, sizeof (*mp));
716 vl_msg_api_send_shmem (q, (u8 *) & mp);
720 static f64 last_time;
722 * Throttle syslog msgs.
723 * It's pretty tempting to just revoke the registration...
725 if (vlib_time_now (vm) > last_time + 10.0)
727 clib_warning ("arp event for %U to pid %d: queue stuffed!",
728 format_ip4_address, &event->address, event->pid);
729 last_time = vlib_time_now (vm);
735 handle_ip6_nd_event (u32 pool_index)
737 vpe_api_main_t *vam = &vpe_api_main;
738 vnet_main_t *vnm = vam->vnet_main;
739 vlib_main_t *vm = vam->vlib_main;
740 vl_api_ip6_nd_event_t *event;
741 vl_api_ip6_nd_event_t *mp;
742 unix_shared_memory_queue_t *q;
744 /* Client can cancel, die, etc. */
745 if (pool_is_free_index (vam->nd_events, pool_index))
748 event = pool_elt_at_index (vam->nd_events, pool_index);
750 q = vl_api_client_index_to_input_queue (event->client_index);
753 (void) vnet_add_del_ip6_nd_change_event
754 (vnm, nd_change_delete_callback,
755 event->pid, &event->address,
756 vpe_resolver_process_node.index, IP6_ND_EVENT,
757 ~0 /* pool index, notused */ , 0 /* is_add */ );
761 if (q->cursize < q->maxsize)
763 mp = vl_msg_api_alloc (sizeof (*mp));
764 clib_memcpy (mp, event, sizeof (*mp));
765 vl_msg_api_send_shmem (q, (u8 *) & mp);
769 static f64 last_time;
771 * Throttle syslog msgs.
772 * It's pretty tempting to just revoke the registration...
774 if (vlib_time_now (vm) > last_time + 10.0)
776 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
777 format_ip6_address, &event->address, event->pid);
778 last_time = vlib_time_now (vm);
784 resolver_process (vlib_main_t * vm,
785 vlib_node_runtime_t * rt, vlib_frame_t * f)
788 uword *event_data = 0;
790 vpe_api_main_t *vam = &vpe_api_main;
792 vl_api_ip_add_del_route_t *adr;
793 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
794 u32 *resolution_failures = 0;
800 vlib_process_wait_for_event_or_clock (vm, timeout);
802 event_type = vlib_process_get_events (vm, &event_data);
806 case RESOLUTION_PENDING_EVENT:
810 case RESOLUTION_EVENT:
811 for (i = 0; i < vec_len (event_data); i++)
814 * Resolution events can occur long after the
815 * original request has timed out. $$$ add a cancel
818 if (pool_is_free_index (vam->pending_routes, event_data[i]))
821 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
825 switch (pr->resolve_type)
827 case RESOLVE_IP4_ADD_DEL_ROUTE:
828 rv = ip4_add_del_route_t_handler (adr);
829 clib_warning ("resolver: add %U/%d via %U %s",
831 (ip4_address_t *) & (adr->dst_address),
832 adr->dst_address_length,
834 (ip4_address_t *) & (adr->next_hop_address),
835 (rv >= 0) ? "succeeded" : "failed");
838 case RESOLVE_IP6_ADD_DEL_ROUTE:
839 rv = ip6_add_del_route_t_handler (adr);
840 clib_warning ("resolver: add %U/%d via %U %s",
842 (ip6_address_t *) & (adr->dst_address),
843 adr->dst_address_length,
845 (ip6_address_t *) & (adr->next_hop_address),
846 (rv >= 0) ? "succeeded" : "failed");
849 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
850 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
851 clib_warning ("resolver: add mpls-o-e via %U %s",
854 (pme->next_hop_ip4_address_in_outer_vrf),
855 (rv >= 0) ? "succeeded" : "failed");
859 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
861 pool_put (vam->pending_routes, pr);
866 for (i = 0; i < vec_len (event_data); i++)
867 handle_ip4_arp_event (event_data[i]);
871 for (i = 0; i < vec_len (event_data); i++)
872 handle_ip6_nd_event (event_data[i]);
875 case ~0: /* timeout, retry pending resolutions */
877 pool_foreach (pr, vam->pending_routes,
883 /* May fail, e.g. due to interface down */
884 switch (pr->resolve_type)
886 case RESOLVE_IP4_ADD_DEL_ROUTE:
887 e = ip4_probe_neighbor
888 (vm, (ip4_address_t *)&(adr->next_hop_address),
889 ntohl(adr->next_hop_sw_if_index));
892 case RESOLVE_IP6_ADD_DEL_ROUTE:
893 e = ip6_probe_neighbor
894 (vm, (ip6_address_t *)&(adr->next_hop_address),
895 ntohl(adr->next_hop_sw_if_index));
898 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
900 e = ip4_probe_neighbor
902 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
903 pme->resolve_opaque);
907 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
912 clib_error_report (e);
914 adr->resolve_attempts = 1;
916 pme->resolve_attempts = 1;
920 adr->resolve_attempts -= 1;
921 if (adr->resolve_attempts == 0)
922 vec_add1 (resolution_failures,
923 pr - vam->pending_routes);
927 pme->resolve_attempts -= 1;
928 if (pme->resolve_attempts == 0)
929 vec_add1 (resolution_failures,
930 pr - vam->pending_routes);
934 for (i = 0; i < vec_len (resolution_failures); i++)
936 pr = pool_elt_at_index (vam->pending_routes,
937 resolution_failures[i]);
941 switch (pr->resolve_type)
943 case RESOLVE_IP4_ADD_DEL_ROUTE:
944 clib_warning ("resolver: add %U/%d via %U retry failure",
946 (ip4_address_t *) & (adr->dst_address),
947 adr->dst_address_length,
949 (ip4_address_t *) & (adr->next_hop_address));
952 case RESOLVE_IP6_ADD_DEL_ROUTE:
953 clib_warning ("resolver: add %U/%d via %U retry failure",
955 (ip6_address_t *) & (adr->dst_address),
956 adr->dst_address_length,
958 (ip6_address_t *) & (adr->next_hop_address));
961 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
962 clib_warning ("resolver: add mpls-o-e via %U retry failure",
965 (pme->next_hop_ip4_address_in_outer_vrf));
969 clib_warning ("BUG");
971 pool_put (vam->pending_routes, pr);
973 vec_reset_length (resolution_failures);
976 if (pool_elts (vam->pending_routes) == 0)
978 vec_reset_length (event_data);
980 return 0; /* or not */
984 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
985 .function = resolver_process,
986 .type = VLIB_NODE_TYPE_PROCESS,
987 .name = "vpe-route-resolver-process",
992 ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp,
994 const fib_prefix_t * prefix,
995 const ip46_address_t * next_hop,
996 u32 next_hop_sw_if_index,
997 u32 next_hop_fib_index, u32 next_hop_weight)
999 vnet_classify_main_t *cm = &vnet_classify_main;
1000 fib_protocol_t proto = prefix->fp_proto;
1001 stats_main_t *sm = &stats_main;
1003 if (mp->is_multipath)
1005 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1007 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1009 if (mp->is_resolve_host)
1010 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1011 if (mp->is_resolve_attached)
1012 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1015 fib_table_entry_path_add (fib_index,
1018 FIB_ENTRY_FLAG_NONE,
1021 next_hop_sw_if_index,
1024 MPLS_LABEL_INVALID, path_flags);
1026 fib_table_entry_path_remove (fib_index,
1031 next_hop_sw_if_index,
1033 next_hop_weight, path_flags);
1039 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1041 if (mp->is_drop || mp->is_local || mp->is_classify || mp->lookup_in_vrf)
1044 * special route types that link directly to the adj
1048 dpo_id_t dpo = DPO_NULL;
1051 dproto = fib_proto_to_dpo (prefix->fp_proto);
1054 dpo_copy (&dpo, drop_dpo_get (dproto));
1055 else if (mp->is_local)
1056 receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo);
1057 else if (mp->is_classify)
1059 if (pool_is_free_index (cm->tables,
1060 ntohl (mp->classify_table_index)))
1063 return VNET_API_ERROR_NO_SUCH_TABLE;
1066 dpo_set (&dpo, DPO_CLASSIFY, proto,
1067 classify_dpo_create (prefix->fp_proto,
1069 (mp->classify_table_index)));
1071 else if (mp->lookup_in_vrf)
1073 next_hop_fib_index =
1074 fib_table_id_find_fib_index (dproto,
1075 ntohl (mp->lookup_in_vrf));
1076 if (~0 == next_hop_fib_index)
1079 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1082 lookup_dpo_add_or_lock_w_fib_index (next_hop_fib_index,
1084 LOOKUP_INPUT_DST_ADDR,
1085 LOOKUP_TABLE_FROM_CONFIG,
1091 return VNET_API_ERROR_NO_SUCH_TABLE;
1094 fib_table_entry_special_dpo_add (fib_index,
1097 FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
1102 fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API);
1109 fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE;
1111 if (mp->is_resolve_host)
1112 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
1113 if (mp->is_resolve_attached)
1114 path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
1116 fib_table_entry_update_one_path (fib_index,
1119 FIB_ENTRY_FLAG_NONE,
1122 next_hop_sw_if_index,
1125 MPLS_LABEL_INVALID, path_flags);
1129 fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API);
1138 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1140 vpe_api_main_t *vam = &vpe_api_main;
1141 vnet_main_t *vnm = vam->vnet_main;
1144 fib_index = ip4_fib_index_from_table_id (ntohl (mp->vrf_id));
1145 if (~0 == fib_index)
1147 if (mp->create_vrf_if_needed)
1149 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1150 ntohl (mp->vrf_id));
1154 /* No such VRF, and we weren't asked to create one */
1155 return VNET_API_ERROR_NO_SUCH_FIB;
1159 if (~0 != ntohl (mp->next_hop_sw_if_index) &&
1160 pool_is_free_index (vnm->interface_main.sw_interfaces,
1161 ntohl (mp->next_hop_sw_if_index)))
1162 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1164 fib_prefix_t pfx = {
1165 .fp_len = mp->dst_address_length,
1166 .fp_proto = FIB_PROTOCOL_IP4,
1168 clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4));
1171 memset (&nh, 0, sizeof (nh));
1172 memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4));
1174 return (ip_add_del_route_t_handler (mp, fib_index, &pfx, &nh,
1175 ntohl (mp->next_hop_sw_if_index),
1176 fib_index, (u32) mp->next_hop_weight));
1180 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1182 vnet_main_t *vnm = vnet_get_main ();
1185 fib_index = ip6_fib_index_from_table_id (ntohl (mp->vrf_id));
1186 if (~0 == fib_index)
1188 if (mp->create_vrf_if_needed)
1190 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1191 ntohl (mp->vrf_id));
1195 /* No such VRF, and we weren't asked to create one */
1196 return VNET_API_ERROR_NO_SUCH_FIB;
1200 if (~0 != ntohl (mp->next_hop_sw_if_index) &&
1201 pool_is_free_index (vnm->interface_main.sw_interfaces,
1202 ntohl (mp->next_hop_sw_if_index)))
1203 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1205 fib_prefix_t pfx = {
1206 .fp_len = mp->dst_address_length,
1207 .fp_proto = FIB_PROTOCOL_IP6,
1209 clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6));
1212 memset (&nh, 0, sizeof (nh));
1213 memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6));
1215 return (ip_add_del_route_t_handler (mp, fib_index, &pfx,
1216 &nh, ntohl (mp->next_hop_sw_if_index),
1217 fib_index, (u32) mp->next_hop_weight));
1221 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1223 vl_api_ip_add_del_route_reply_t *rmp;
1225 vnet_main_t *vnm = vnet_get_main ();
1230 rv = ip6_add_del_route_t_handler (mp);
1232 rv = ip4_add_del_route_t_handler (mp);
1234 rv = (rv == 0) ? vnm->api_errno : rv;
1236 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1240 vl_api_sw_interface_add_del_address_t_handler
1241 (vl_api_sw_interface_add_del_address_t * mp)
1243 vlib_main_t *vm = vlib_get_main ();
1244 vl_api_sw_interface_add_del_address_reply_t *rmp;
1248 VALIDATE_SW_IF_INDEX (mp);
1250 is_del = mp->is_add == 0;
1253 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1254 else if (mp->is_ipv6)
1255 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1256 (void *) mp->address,
1257 mp->address_length, is_del);
1259 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1260 (void *) mp->address,
1261 mp->address_length, is_del);
1263 BAD_SW_IF_INDEX_LABEL;
1265 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1269 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1272 u32 table_id = ntohl (mp->vrf_id);
1273 u32 sw_if_index = ntohl (mp->sw_if_index);
1274 vl_api_sw_interface_set_table_reply_t *rmp;
1275 stats_main_t *sm = &stats_main;
1278 VALIDATE_SW_IF_INDEX (mp);
1280 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1284 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
1287 vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index);
1288 ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1293 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
1296 vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index);
1297 ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index;
1301 BAD_SW_IF_INDEX_LABEL;
1303 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1307 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1309 vlib_main_t *vm = vlib_get_main ();
1310 ip4_main_t *im4 = &ip4_main;
1311 ip6_main_t *im6 = &ip6_main;
1312 vl_api_sw_interface_set_vpath_reply_t *rmp;
1315 u32 sw_if_index = ntohl (mp->sw_if_index);
1316 ip4_main_t *ip4m = &ip4_main;
1317 ip6_main_t *ip6m = &ip6_main;
1318 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1319 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1320 ip_config_main_t *rx_cm4u =
1321 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1322 ip_config_main_t *rx_cm4m =
1323 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1324 ip_config_main_t *rx_cm6u =
1325 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1326 ip_config_main_t *rx_cm6m =
1327 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1329 VALIDATE_SW_IF_INDEX (mp);
1331 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1334 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1335 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1337 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1338 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1339 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1340 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1342 im4->ip4_multicast_rx_feature_vpath,
1344 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1345 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1346 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1348 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1349 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1350 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1351 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1353 im6->ip6_multicast_rx_feature_vpath,
1355 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1359 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1360 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1362 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1363 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1364 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1365 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1367 im4->ip4_multicast_rx_feature_vpath,
1369 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1370 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1371 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1373 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1374 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1375 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1376 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1378 im6->ip6_multicast_rx_feature_vpath,
1380 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1383 BAD_SW_IF_INDEX_LABEL;
1385 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1389 vl_api_sw_interface_set_l2_xconnect_t_handler
1390 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1392 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1394 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1395 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1396 vlib_main_t *vm = vlib_get_main ();
1397 vnet_main_t *vnm = vnet_get_main ();
1399 VALIDATE_RX_SW_IF_INDEX (mp);
1403 VALIDATE_TX_SW_IF_INDEX (mp);
1404 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1405 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1409 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1412 BAD_RX_SW_IF_INDEX_LABEL;
1413 BAD_TX_SW_IF_INDEX_LABEL;
1415 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1419 vl_api_sw_interface_set_l2_bridge_t_handler
1420 (vl_api_sw_interface_set_l2_bridge_t * mp)
1422 bd_main_t *bdm = &bd_main;
1423 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1425 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1426 u32 bd_id = ntohl (mp->bd_id);
1430 vlib_main_t *vm = vlib_get_main ();
1431 vnet_main_t *vnm = vnet_get_main ();
1433 VALIDATE_RX_SW_IF_INDEX (mp);
1435 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1439 //VALIDATE_TX_SW_IF_INDEX(mp);
1440 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1441 rx_sw_if_index, bd_index, bvi, shg, 0);
1445 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1448 BAD_RX_SW_IF_INDEX_LABEL;
1450 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1454 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1456 vlib_main_t *vm = vlib_get_main ();
1457 bd_main_t *bdm = &bd_main;
1458 vl_api_bridge_domain_add_del_reply_t *rmp;
1460 u32 enable_flags = 0, disable_flags = 0;
1461 u32 bd_id = ntohl (mp->bd_id);
1466 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1469 enable_flags |= L2_FLOOD;
1471 disable_flags |= L2_FLOOD;
1474 enable_flags |= L2_UU_FLOOD;
1476 disable_flags |= L2_UU_FLOOD;
1479 enable_flags |= L2_FWD;
1481 disable_flags |= L2_FWD;
1484 enable_flags |= L2_ARP_TERM;
1486 disable_flags |= L2_ARP_TERM;
1489 enable_flags |= L2_LEARN;
1491 disable_flags |= L2_LEARN;
1494 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1497 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1501 rv = bd_delete_bd_index (bdm, bd_id);
1503 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1507 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1509 clib_warning ("BUG");
1513 vl_api_bridge_domain_sw_if_details_t_handler
1514 (vl_api_bridge_domain_sw_if_details_t * mp)
1516 clib_warning ("BUG");
1520 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1521 l2_bridge_domain_t * bd_config,
1522 u32 n_sw_ifs, u32 context)
1524 vl_api_bridge_domain_details_t *mp;
1526 mp = vl_msg_api_alloc (sizeof (*mp));
1527 memset (mp, 0, sizeof (*mp));
1528 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1529 mp->bd_id = ntohl (bd_config->bd_id);
1530 mp->flood = bd_feature_flood (bd_config);
1531 mp->uu_flood = bd_feature_uu_flood (bd_config);
1532 mp->forward = bd_feature_forward (bd_config);
1533 mp->learn = bd_feature_learn (bd_config);
1534 mp->arp_term = bd_feature_arp_term (bd_config);
1535 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1536 mp->n_sw_ifs = ntohl (n_sw_ifs);
1537 mp->context = context;
1539 vl_msg_api_send_shmem (q, (u8 *) & mp);
1543 send_bd_sw_if_details (l2input_main_t * l2im,
1544 unix_shared_memory_queue_t * q,
1545 l2_flood_member_t * member, u32 bd_id, u32 context)
1547 vl_api_bridge_domain_sw_if_details_t *mp;
1548 l2_input_config_t *input_cfg;
1550 mp = vl_msg_api_alloc (sizeof (*mp));
1551 memset (mp, 0, sizeof (*mp));
1552 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1553 mp->bd_id = ntohl (bd_id);
1554 mp->sw_if_index = ntohl (member->sw_if_index);
1555 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1556 mp->shg = input_cfg->shg;
1557 mp->context = context;
1559 vl_msg_api_send_shmem (q, (u8 *) & mp);
1563 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1565 bd_main_t *bdm = &bd_main;
1566 l2input_main_t *l2im = &l2input_main;
1567 unix_shared_memory_queue_t *q;
1568 l2_bridge_domain_t *bd_config;
1569 u32 bd_id, bd_index;
1572 q = vl_api_client_index_to_input_queue (mp->client_index);
1577 bd_id = ntohl (mp->bd_id);
1579 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1580 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1581 for (; bd_index < end; bd_index++)
1583 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1584 /* skip dummy bd_id 0 */
1585 if (bd_config && (bd_config->bd_id > 0))
1588 l2_flood_member_t *m;
1590 n_sw_ifs = vec_len (bd_config->members);
1591 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1593 vec_foreach (m, bd_config->members)
1595 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1602 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1604 bd_main_t *bdm = &bd_main;
1605 l2input_main_t *l2im = &l2input_main;
1606 vl_api_l2fib_add_del_reply_t *rmp;
1609 u32 sw_if_index = ntohl (mp->sw_if_index);
1610 u32 bd_id = ntohl (mp->bd_id);
1619 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1622 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1623 goto bad_sw_if_index;
1629 VALIDATE_SW_IF_INDEX (mp);
1630 if (vec_len (l2im->configs) <= sw_if_index)
1632 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1633 goto bad_sw_if_index;
1637 l2_input_config_t *config;
1638 config = vec_elt_at_index (l2im->configs, sw_if_index);
1639 if (config->bridge == 0)
1641 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1642 goto bad_sw_if_index;
1645 static_mac = mp->static_mac ? 1 : 0;
1646 filter_mac = mp->filter_mac ? 1 : 0;
1647 bvi_mac = mp->bvi_mac ? 1 : 0;
1648 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1653 l2fib_del_entry (mac, bd_index);
1656 BAD_SW_IF_INDEX_LABEL;
1658 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1662 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1664 vl_api_l2_flags_reply_t *rmp;
1666 u32 sw_if_index = ntohl (mp->sw_if_index);
1667 u32 flags = ntohl (mp->feature_bitmap);
1670 VALIDATE_SW_IF_INDEX (mp);
1673 if (flags & L2INPUT_FEAT_ ## a) \
1674 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1675 foreach_l2input_feat;
1678 BAD_SW_IF_INDEX_LABEL;
1681 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1683 rmp->resulting_feature_bitmap = ntohl(rbm);
1689 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1691 vlib_main_t *vm = vlib_get_main ();
1692 bd_main_t *bdm = &bd_main;
1693 vl_api_bridge_flags_reply_t *rmp;
1695 u32 bd_id = ntohl (mp->bd_id);
1697 u32 flags = ntohl (mp->feature_bitmap);
1700 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1703 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1709 bd_set_flags (vm, bd_index, flags, mp->is_set);
1713 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1715 rmp->resulting_feature_bitmap = ntohl(flags);
1721 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1723 bd_main_t *bdm = &bd_main;
1724 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1726 u32 bd_id = ntohl (mp->bd_id);
1730 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1733 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1738 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1739 mp->mac_address, mp->is_ipv6, mp->is_add))
1740 rv = VNET_API_ERROR_UNSPECIFIED;
1743 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1747 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1750 vl_api_tap_connect_reply_t *rmp;
1751 unix_shared_memory_queue_t *q;
1752 u32 sw_if_index = (u32) ~ 0;
1754 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1755 mp->use_random_mac ? 0 : mp->mac_address,
1756 &sw_if_index, mp->renumber,
1757 ntohl (mp->custom_dev_instance));
1759 q = vl_api_client_index_to_input_queue (mp->client_index);
1763 rmp = vl_msg_api_alloc (sizeof (*rmp));
1764 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1765 rmp->context = mp->context;
1766 rmp->retval = ntohl (rv);
1767 rmp->sw_if_index = ntohl (sw_if_index);
1769 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1773 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
1776 vl_api_tap_modify_reply_t *rmp;
1777 unix_shared_memory_queue_t *q;
1778 u32 sw_if_index = (u32) ~ 0;
1780 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1781 mp->use_random_mac ? 0 : mp->mac_address,
1782 &sw_if_index, mp->renumber,
1783 ntohl (mp->custom_dev_instance));
1785 q = vl_api_client_index_to_input_queue (mp->client_index);
1789 rmp = vl_msg_api_alloc (sizeof (*rmp));
1790 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1791 rmp->context = mp->context;
1792 rmp->retval = ntohl (rv);
1793 rmp->sw_if_index = ntohl (sw_if_index);
1795 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1799 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
1802 vpe_api_main_t *vam = &vpe_api_main;
1803 vl_api_tap_delete_reply_t *rmp;
1804 unix_shared_memory_queue_t *q;
1805 u32 sw_if_index = ntohl (mp->sw_if_index);
1807 rv = vnet_tap_delete (vm, sw_if_index);
1809 q = vl_api_client_index_to_input_queue (mp->client_index);
1813 rmp = vl_msg_api_alloc (sizeof (*rmp));
1814 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1815 rmp->context = mp->context;
1816 rmp->retval = ntohl (rv);
1818 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1821 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1825 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1827 vl_api_create_vlan_subif_reply_t *rmp;
1828 vnet_main_t *vnm = vnet_get_main ();
1829 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1830 vnet_hw_interface_t *hi;
1833 vnet_sw_interface_t template;
1835 vnet_interface_main_t *im = &vnm->interface_main;
1836 u64 sup_and_sub_key;
1838 unix_shared_memory_queue_t *q;
1839 clib_error_t *error;
1841 VALIDATE_SW_IF_INDEX (mp);
1843 hw_if_index = ntohl (mp->sw_if_index);
1844 hi = vnet_get_hw_interface (vnm, hw_if_index);
1846 id = ntohl (mp->vlan_id);
1847 if (id == 0 || id > 4095)
1849 rv = VNET_API_ERROR_INVALID_VLAN;
1853 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1855 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1858 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1862 kp = clib_mem_alloc (sizeof (*kp));
1863 *kp = sup_and_sub_key;
1865 memset (&template, 0, sizeof (template));
1866 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1867 template.sup_sw_if_index = hi->sw_if_index;
1868 template.sub.id = id;
1869 template.sub.eth.raw_flags = 0;
1870 template.sub.eth.flags.one_tag = 1;
1871 template.sub.eth.outer_vlan_id = id;
1872 template.sub.eth.flags.exact_match = 1;
1874 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1877 clib_error_report (error);
1878 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1881 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1882 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1884 BAD_SW_IF_INDEX_LABEL;
1887 q = vl_api_client_index_to_input_queue (mp->client_index);
1891 rmp = vl_msg_api_alloc (sizeof (*rmp));
1892 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
1893 rmp->context = mp->context;
1894 rmp->retval = ntohl (rv);
1895 rmp->sw_if_index = ntohl (sw_if_index);
1896 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1900 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1902 vl_api_create_subif_reply_t *rmp;
1903 vnet_main_t *vnm = vnet_get_main ();
1904 u32 sw_if_index = ~0;
1907 vnet_sw_interface_t *si;
1908 vnet_hw_interface_t *hi;
1909 vnet_sw_interface_t template;
1911 vnet_interface_main_t *im = &vnm->interface_main;
1912 u64 sup_and_sub_key;
1914 clib_error_t *error;
1916 VALIDATE_SW_IF_INDEX (mp);
1918 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
1919 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1921 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
1923 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1927 sw_if_index = si->sw_if_index;
1928 sub_id = ntohl (mp->sub_id);
1930 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
1932 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1936 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1937 sw_if_index, sub_id);
1938 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1942 kp = clib_mem_alloc (sizeof (*kp));
1943 *kp = sup_and_sub_key;
1945 memset (&template, 0, sizeof (template));
1946 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1947 template.sup_sw_if_index = sw_if_index;
1948 template.sub.id = sub_id;
1949 template.sub.eth.flags.no_tags = mp->no_tags;
1950 template.sub.eth.flags.one_tag = mp->one_tag;
1951 template.sub.eth.flags.two_tags = mp->two_tags;
1952 template.sub.eth.flags.dot1ad = mp->dot1ad;
1953 template.sub.eth.flags.exact_match = mp->exact_match;
1954 template.sub.eth.flags.default_sub = mp->default_sub;
1955 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1956 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1957 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
1958 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
1960 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1963 clib_error_report (error);
1964 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1968 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1969 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1971 BAD_SW_IF_INDEX_LABEL;
1976 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1978 rmp->sw_if_index = ntohl(sw_if_index);
1984 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
1987 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
1989 stats_main_t *sm = &stats_main;
1990 u32 tunnel_sw_if_index = ~0;
1992 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
1994 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
1995 (ip4_address_t *) (mp->dst_address),
1996 (ip4_address_t *) (mp->intfc_address),
1997 (u32) (mp->intfc_address_length),
1998 ntohl (mp->inner_vrf_id),
1999 ntohl (mp->outer_vrf_id),
2000 &tunnel_sw_if_index,
2001 mp->l2_only, mp->is_add);
2005 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2007 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2013 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2014 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2016 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2018 stats_main_t *sm = &stats_main;
2019 u32 tunnel_sw_if_index;
2021 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2023 rv = vnet_mpls_ethernet_add_del_tunnel
2024 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2025 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2026 ntohl (mp->tx_sw_if_index),
2027 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2032 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2034 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2040 * This piece of misery brought to you because the control-plane
2041 * can't figure out the tx interface + dst-mac address all by itself
2043 static int mpls_ethernet_add_del_tunnel_2_t_handler
2044 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2046 pending_route_t *pr;
2047 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2048 vnet_main_t *vnm = vnet_get_main ();
2049 vlib_main_t *vm = vlib_get_main ();
2050 stats_main_t *sm = &stats_main;
2051 vpe_api_main_t *vam = &vpe_api_main;
2052 u32 inner_fib_index, outer_fib_index;
2053 ip4_main_t *im = &ip4_main;
2054 ip_lookup_main_t *lm = &im->lookup_main;
2055 ip_adjacency_t *adj = 0;
2058 u8 *dst_mac_address;
2062 u32 tunnel_sw_if_index;
2064 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2066 return VNET_API_ERROR_NO_SUCH_FIB;
2068 outer_fib_index = p[0];
2071 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2073 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2075 inner_fib_index = p[0];
2077 if (inner_fib_index == outer_fib_index)
2078 return VNET_API_ERROR_INVALID_VALUE;
2081 lookup_result = ip4_fib_table_lookup_lb (ip4_fib_get (outer_fib_index),
2084 next_hop_ip4_address_in_outer_vrf);
2086 adj = ip_get_adjacency (lm, lookup_result);
2087 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2089 if (mp->is_add && mp->resolve_if_needed)
2091 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2093 pool_get (vam->pending_routes, pr);
2094 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2096 clib_memcpy (pme, mp, sizeof (*pme));
2097 /* recursion block, "just in case" */
2098 pme->resolve_if_needed = 0;
2099 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2100 pme->resolve_opaque = tx_sw_if_index;
2101 vnet_register_ip4_arp_resolution_event
2103 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2104 vpe_resolver_process_node.index,
2105 RESOLUTION_EVENT, pr - vam->pending_routes);
2107 vlib_process_signal_event
2108 (vm, vpe_resolver_process_node.index,
2109 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2111 /* The interface may be down, etc. */
2112 e = ip4_probe_neighbor
2113 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2117 clib_error_report (e);
2119 return VNET_API_ERROR_IN_PROGRESS;
2123 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2124 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2127 vnet_rewrite_get_data_internal
2128 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2130 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2132 rv = vnet_mpls_ethernet_add_del_tunnel
2133 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2134 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2135 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2143 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2144 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2146 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2149 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2151 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2156 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2158 vl_api_mpls_add_del_encap_reply_t *rmp;
2163 vec_reset_length (labels);
2165 for (i = 0; i < mp->nlabels; i++)
2166 vec_add1 (labels, ntohl (mp->labels[i]));
2169 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2170 ntohl (mp->vrf_id), labels,
2171 ~0 /* policy_tunnel_index */ ,
2172 0 /* no_dst_hash */ ,
2176 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2180 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2182 vl_api_mpls_add_del_decap_reply_t *rmp;
2185 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2186 ntohl (mp->label), ntohl (mp->next_index),
2187 mp->s_bit, mp->is_add);
2189 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2193 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2195 vl_api_proxy_arp_add_del_reply_t *rmp;
2198 ip4_main_t *im = &ip4_main;
2199 stats_main_t *sm = &stats_main;
2200 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2201 ip4_address_t * hi_addr,
2202 u32 fib_index, int is_del);
2205 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2207 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2211 rv = VNET_API_ERROR_NO_SUCH_FIB;
2217 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2218 (ip4_address_t *) mp->hi_address,
2219 fib_index, mp->is_add == 0);
2223 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2227 vl_api_proxy_arp_intfc_enable_disable_t_handler
2228 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2231 vnet_main_t *vnm = vnet_get_main ();
2232 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2233 vnet_sw_interface_t *si;
2236 VALIDATE_SW_IF_INDEX (mp);
2238 sw_if_index = ntohl (mp->sw_if_index);
2240 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2242 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2246 si = vnet_get_sw_interface (vnm, sw_if_index);
2250 if (mp->enable_disable)
2251 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2253 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2255 BAD_SW_IF_INDEX_LABEL;
2258 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2262 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2265 vl_api_ip_neighbor_add_del_reply_t *rmp;
2266 vnet_main_t *vnm = vnet_get_main ();
2267 stats_main_t *sm = &stats_main;
2270 VALIDATE_SW_IF_INDEX (mp);
2272 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2275 * there's no validation here of the ND/ARP entry being added.
2276 * The expectation is that the FIB will ensure that nothing bad
2277 * will come of adding bogus entries.
2282 rv = vnet_set_ip6_ethernet_neighbor
2283 (vm, ntohl (mp->sw_if_index),
2284 (ip6_address_t *) (mp->dst_address),
2285 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2287 rv = vnet_unset_ip6_ethernet_neighbor
2288 (vm, ntohl (mp->sw_if_index),
2289 (ip6_address_t *) (mp->dst_address),
2290 mp->mac_address, sizeof (mp->mac_address));
2294 ethernet_arp_ip4_over_ethernet_address_t a;
2296 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2297 clib_memcpy (&a.ip4, mp->dst_address, 4);
2300 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2304 vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a);
2307 BAD_SW_IF_INDEX_LABEL;
2310 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2314 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2317 vpe_main_t *rm = &vpe_main;
2318 ip4_main_t *im4 = &ip4_main;
2319 ip6_main_t *im6 = &ip6_main;
2320 ip_lookup_main_t *lm;
2326 u32 adj_index, sw_if_index;
2327 vl_api_is_address_reachable_t *rmp;
2328 ip_adjacency_t *adj;
2329 unix_shared_memory_queue_t *q;
2331 q = vl_api_client_index_to_input_queue (mp->client_index);
2334 increment_missing_api_client_counter (rm->vlib_main);
2338 rmp = vl_msg_api_alloc (sizeof (*rmp));
2339 clib_memcpy (rmp, mp, sizeof (*rmp));
2341 sw_if_index = mp->next_hop_sw_if_index;
2342 clib_memcpy (&addr, mp->address, sizeof (addr));
2345 lm = &im6->lookup_main;
2346 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2350 lm = &im4->lookup_main;
2352 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2354 if (adj_index == ~0)
2359 adj = ip_get_adjacency (lm, adj_index);
2361 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2362 && adj->rewrite_header.sw_if_index == sw_if_index)
2368 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2369 && adj->rewrite_header.sw_if_index == sw_if_index)
2372 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2374 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2376 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2385 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2390 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2392 clib_warning ("BUG");
2396 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2398 vl_api_sw_interface_set_flags_reply_t *rmp;
2399 vnet_main_t *vnm = vnet_get_main ();
2401 clib_error_t *error;
2404 VALIDATE_SW_IF_INDEX (mp);
2406 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2408 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2412 clib_error_report (error);
2415 BAD_SW_IF_INDEX_LABEL;
2416 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2420 vl_api_sw_interface_set_mpls_enable_t_handler
2421 (vl_api_sw_interface_set_mpls_enable_t * mp)
2423 vl_api_sw_interface_set_mpls_enable_reply_t *rmp;
2426 VALIDATE_SW_IF_INDEX (mp);
2428 mpls_sw_interface_enable_disable (&mpls_main,
2429 ntohl (mp->sw_if_index), mp->enable);
2431 BAD_SW_IF_INDEX_LABEL;
2432 REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY);
2436 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2439 vl_api_sw_interface_clear_stats_reply_t *rmp;
2441 vnet_main_t *vnm = vnet_get_main ();
2442 vnet_interface_main_t *im = &vnm->interface_main;
2443 vlib_simple_counter_main_t *sm;
2444 vlib_combined_counter_main_t *cm;
2445 static vnet_main_t **my_vnet_mains;
2446 int i, j, n_counters;
2449 if (mp->sw_if_index != ~0)
2450 VALIDATE_SW_IF_INDEX (mp);
2452 vec_reset_length (my_vnet_mains);
2454 for (i = 0; i < vec_len (vnet_mains); i++)
2457 vec_add1 (my_vnet_mains, vnet_mains[i]);
2460 if (vec_len (vnet_mains) == 0)
2461 vec_add1 (my_vnet_mains, vnm);
2463 n_counters = vec_len (im->combined_sw_if_counters);
2465 for (j = 0; j < n_counters; j++)
2467 for (i = 0; i < vec_len (my_vnet_mains); i++)
2469 im = &my_vnet_mains[i]->interface_main;
2470 cm = im->combined_sw_if_counters + j;
2471 if (mp->sw_if_index == (u32) ~ 0)
2472 vlib_clear_combined_counters (cm);
2474 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2478 n_counters = vec_len (im->sw_if_counters);
2480 for (j = 0; j < n_counters; j++)
2482 for (i = 0; i < vec_len (my_vnet_mains); i++)
2484 im = &my_vnet_mains[i]->interface_main;
2485 sm = im->sw_if_counters + j;
2486 if (mp->sw_if_index == (u32) ~ 0)
2487 vlib_clear_simple_counters (sm);
2489 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2493 BAD_SW_IF_INDEX_LABEL;
2495 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2499 send_sw_interface_details (vpe_api_main_t * am,
2500 unix_shared_memory_queue_t * q,
2501 vnet_sw_interface_t * swif,
2502 u8 * interface_name, u32 context)
2504 vl_api_sw_interface_details_t *mp;
2505 vnet_hw_interface_t *hi;
2507 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2509 mp = vl_msg_api_alloc (sizeof (*mp));
2510 memset (mp, 0, sizeof (*mp));
2511 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2512 mp->sw_if_index = ntohl (swif->sw_if_index);
2513 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2514 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2515 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2516 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2517 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2518 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2519 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2520 mp->link_mtu = ntohs (hi->max_packet_bytes);
2521 mp->context = context;
2523 strncpy ((char *) mp->interface_name,
2524 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2526 /* Send the L2 address for ethernet physical intfcs */
2527 if (swif->sup_sw_if_index == swif->sw_if_index
2528 && hi->hw_class_index == ethernet_hw_interface_class.index)
2530 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2531 ethernet_interface_t *ei;
2533 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2534 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2535 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2536 mp->l2_address_length = ntohl (sizeof (ei->address));
2538 else if (swif->sup_sw_if_index != swif->sw_if_index)
2540 vnet_sub_interface_t *sub = &swif->sub;
2541 mp->sub_id = ntohl (sub->id);
2542 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2543 mp->sub_number_of_tags =
2544 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2545 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2546 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2547 mp->sub_exact_match = sub->eth.flags.exact_match;
2548 mp->sub_default = sub->eth.flags.default_sub;
2549 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2550 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2552 /* vlan tag rewrite data */
2553 u32 vtr_op = L2_VTR_DISABLED;
2554 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2556 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2557 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2559 // error - default to disabled
2560 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2561 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2566 mp->vtr_op = ntohl (vtr_op);
2567 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2568 mp->vtr_tag1 = ntohl (vtr_tag1);
2569 mp->vtr_tag2 = ntohl (vtr_tag2);
2573 vl_msg_api_send_shmem (q, (u8 *) & mp);
2577 send_sw_interface_flags (vpe_api_main_t * am,
2578 unix_shared_memory_queue_t * q,
2579 vnet_sw_interface_t * swif)
2581 vl_api_sw_interface_set_flags_t *mp;
2582 vnet_main_t *vnm = am->vnet_main;
2584 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2586 mp = vl_msg_api_alloc (sizeof (*mp));
2587 memset (mp, 0, sizeof (*mp));
2588 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2589 mp->sw_if_index = ntohl (swif->sw_if_index);
2591 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2592 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2593 vl_msg_api_send_shmem (q, (u8 *) & mp);
2596 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2597 unix_shared_memory_queue_t * q,
2599 __attribute__ ((unused));
2602 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2603 unix_shared_memory_queue_t * q,
2606 vl_api_sw_interface_set_flags_t *mp;
2608 mp = vl_msg_api_alloc (sizeof (*mp));
2609 memset (mp, 0, sizeof (*mp));
2610 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2611 mp->sw_if_index = ntohl (sw_if_index);
2613 mp->admin_up_down = 0;
2614 mp->link_up_down = 0;
2616 vl_msg_api_send_shmem (q, (u8 *) & mp);
2620 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2622 vpe_api_main_t *am = &vpe_api_main;
2623 vnet_sw_interface_t *swif;
2624 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2625 u8 *filter_string = 0, *name_string = 0;
2626 unix_shared_memory_queue_t *q;
2627 char *strcasestr (char *, char *); /* lnx hdr file botch */
2629 q = vl_api_client_index_to_input_queue (mp->client_index);
2634 if (mp->name_filter_valid)
2636 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2637 filter_string = format (0, "%s%c", mp->name_filter, 0);
2641 pool_foreach (swif, im->sw_interfaces,
2643 name_string = format (name_string, "%U%c",
2644 format_vnet_sw_interface_name,
2645 am->vnet_main, swif, 0);
2647 if (mp->name_filter_valid == 0 ||
2648 strcasestr((char *) name_string, (char *) filter_string)) {
2650 send_sw_interface_details (am, q, swif, name_string, mp->context);
2652 _vec_len (name_string) = 0;
2656 vec_free (name_string);
2657 vec_free (filter_string);
2661 send_oam_event (oam_target_t * t)
2663 vpe_api_main_t *vam = &vpe_api_main;
2664 unix_shared_memory_queue_t *q;
2665 vpe_client_registration_t *reg;
2666 vl_api_oam_event_t *mp;
2669 pool_foreach(reg, vam->oam_events_registrations,
2671 q = vl_api_client_index_to_input_queue (reg->client_index);
2674 mp = vl_msg_api_alloc (sizeof (*mp));
2675 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2676 clib_memcpy (mp->dst_address, &t->dst_address,
2677 sizeof (mp->dst_address));
2678 mp->state = t->state;
2679 vl_msg_api_send_shmem (q, (u8 *)&mp);
2686 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2688 vl_api_oam_add_del_reply_t *rmp;
2691 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2692 (ip4_address_t *) mp->dst_address,
2693 ntohl (mp->vrf_id), (int) (mp->is_add));
2695 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2699 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2701 stats_main_t *sm = &stats_main;
2702 vnet_interface_main_t *im = sm->interface_main;
2703 vl_api_vnet_summary_stats_reply_t *rmp;
2704 vlib_combined_counter_main_t *cm;
2707 u64 total_pkts[VLIB_N_RX_TX];
2708 u64 total_bytes[VLIB_N_RX_TX];
2710 unix_shared_memory_queue_t *q =
2711 vl_api_client_index_to_input_queue (mp->client_index);
2716 rmp = vl_msg_api_alloc (sizeof (*rmp));
2717 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2718 rmp->context = mp->context;
2721 memset (total_pkts, 0, sizeof (total_pkts));
2722 memset (total_bytes, 0, sizeof (total_bytes));
2724 vnet_interface_counter_lock (im);
2726 vec_foreach (cm, im->combined_sw_if_counters)
2728 which = cm - im->combined_sw_if_counters;
2730 for (i = 0; i < vec_len (cm->maxi); i++)
2732 vlib_get_combined_counter (cm, i, &v);
2733 total_pkts[which] += v.packets;
2734 total_bytes[which] += v.bytes;
2737 vnet_interface_counter_unlock (im);
2739 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2740 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2741 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2742 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2744 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2746 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2750 typedef CLIB_PACKED (struct {
2751 ip4_address_t address;
2752 u32 address_length: 6;
2758 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2760 vnet_main_t *vnm = vnet_get_main ();
2761 vnet_interface_main_t *im = &vnm->interface_main;
2762 ip4_main_t *im4 = &ip4_main;
2763 static u32 *sw_if_indices_to_shut;
2764 stats_main_t *sm = &stats_main;
2765 fib_table_t *fib_table;
2769 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2770 u32 target_fib_id = ntohl (mp->vrf_id);
2772 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2775 pool_foreach (fib_table, im4->fibs,
2777 fib = &fib_table->v4;
2778 vnet_sw_interface_t * si;
2780 if (fib->table_id != target_fib_id)
2783 /* remove any mpls/gre tunnels in this fib */
2784 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2786 /* remove any mpls encap/decap labels */
2787 mpls_fib_reset_labels (fib->table_id);
2789 /* remove any proxy arps in this fib */
2790 vnet_proxy_arp_fib_reset (fib->table_id);
2792 /* Set the flow hash for this fib to the default */
2793 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2795 vec_reset_length (sw_if_indices_to_shut);
2797 /* Shut down interfaces in this FIB / clean out intfc routes */
2798 pool_foreach (si, im->sw_interfaces,
2800 u32 sw_if_index = si->sw_if_index;
2802 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2803 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2805 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2808 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2809 sw_if_index = sw_if_indices_to_shut[i];
2810 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2812 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2813 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2814 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2817 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API);
2818 fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE);
2822 })); /* pool_foreach (fib) */
2830 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2832 vnet_main_t *vnm = vnet_get_main ();
2833 vnet_interface_main_t *im = &vnm->interface_main;
2834 ip6_main_t *im6 = &ip6_main;
2835 stats_main_t *sm = &stats_main;
2836 static u32 *sw_if_indices_to_shut;
2837 fib_table_t *fib_table;
2841 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2842 u32 target_fib_id = ntohl (mp->vrf_id);
2844 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
2847 pool_foreach (fib_table, im6->fibs,
2849 vnet_sw_interface_t * si;
2850 fib = &(fib_table->v6);
2852 if (fib->table_id != target_fib_id)
2855 vec_reset_length (sw_if_indices_to_shut);
2857 /* Shut down interfaces in this FIB / clean out intfc routes */
2858 pool_foreach (si, im->sw_interfaces,
2860 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2862 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2865 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2866 sw_if_index = sw_if_indices_to_shut[i];
2867 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2869 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2870 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2871 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2874 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API);
2875 fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE);
2879 })); /* pool_foreach (fib) */
2887 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2890 vl_api_reset_fib_reply_t *rmp;
2893 rv = ip6_reset_fib_t_handler (mp);
2895 rv = ip4_reset_fib_t_handler (mp);
2897 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
2902 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2904 vl_api_dhcp_proxy_config_reply_t *rmp;
2907 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
2908 (ip4_address_t *) (&mp->dhcp_src_address),
2909 (u32) ntohl (mp->vrf_id),
2910 (int) mp->insert_circuit_id,
2911 (int) (mp->is_add == 0));
2913 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2918 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
2920 vl_api_dhcp_proxy_config_reply_t *rmp;
2923 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
2924 (ip6_address_t *) (&mp->dhcp_src_address),
2925 (u32) ntohl (mp->vrf_id),
2926 (int) mp->insert_circuit_id,
2927 (int) (mp->is_add == 0));
2929 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
2933 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2935 vl_api_dhcp_proxy_config_reply_t *rmp;
2938 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
2939 (ip4_address_t *) (&mp->dhcp_src_address),
2940 (u32) ntohl (mp->rx_vrf_id),
2941 (u32) ntohl (mp->server_vrf_id),
2942 (int) mp->insert_circuit_id,
2943 (int) (mp->is_add == 0));
2945 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2950 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
2952 vl_api_dhcp_proxy_config_reply_t *rmp;
2956 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
2957 (ip6_address_t *) (&mp->dhcp_src_address),
2958 (u32) ntohl (mp->rx_vrf_id),
2959 (u32) ntohl (mp->server_vrf_id),
2960 (int) mp->insert_circuit_id,
2961 (int) (mp->is_add == 0));
2963 rv = VNET_API_ERROR_UNIMPLEMENTED;
2966 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2971 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
2973 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2976 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
2979 (int) mp->is_add == 0);
2981 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
2983 ntohl (mp->fib_id), (int) mp->is_add == 0);
2985 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
2989 static void vl_api_dhcp_proxy_config_t_handler
2990 (vl_api_dhcp_proxy_config_t * mp)
2992 if (mp->is_ipv6 == 0)
2993 dhcpv4_proxy_config (mp);
2995 dhcpv6_proxy_config (mp);
2998 static void vl_api_dhcp_proxy_config_2_t_handler
2999 (vl_api_dhcp_proxy_config_2_t * mp)
3001 if (mp->is_ipv6 == 0)
3002 dhcpv4_proxy_config_2 (mp);
3004 dhcpv6_proxy_config_2 (mp);
3008 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3009 u8 is_ipv6, u8 * host_address, u8 * router_address,
3012 unix_shared_memory_queue_t *q;
3013 vl_api_dhcp_compl_event_t *mp;
3015 q = vl_api_client_index_to_input_queue (client_index);
3019 mp = vl_msg_api_alloc (sizeof (*mp));
3020 mp->client_index = client_index;
3022 mp->is_ipv6 = is_ipv6;
3023 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3024 mp->hostname[vec_len (hostname) + 1] = '\n';
3025 clib_memcpy (&mp->host_address[0], host_address, 16);
3026 clib_memcpy (&mp->router_address[0], router_address, 16);
3027 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3029 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3031 vl_msg_api_send_shmem (q, (u8 *) & mp);
3034 static void vl_api_dhcp_client_config_t_handler
3035 (vl_api_dhcp_client_config_t * mp)
3037 vlib_main_t *vm = vlib_get_main ();
3038 vl_api_dhcp_client_config_reply_t *rmp;
3041 VALIDATE_SW_IF_INDEX (mp);
3043 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3044 mp->hostname, mp->is_add, mp->client_index,
3045 mp->want_dhcp_event ? dhcp_compl_event_callback :
3048 BAD_SW_IF_INDEX_LABEL;
3050 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3054 vl_api_sw_interface_ip6nd_ra_config_t_handler
3055 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3057 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3059 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3062 is_no = mp->is_no == 1;
3063 suppress = mp->suppress == 1;
3064 managed = mp->managed == 1;
3065 other = mp->other == 1;
3066 ll_option = mp->ll_option == 1;
3067 send_unicast = mp->send_unicast == 1;
3068 cease = mp->cease == 1;
3069 default_router = mp->default_router == 1;
3071 VALIDATE_SW_IF_INDEX (mp);
3073 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3074 suppress, managed, other,
3075 ll_option, send_unicast, cease,
3076 default_router, ntohl (mp->lifetime),
3077 ntohl (mp->initial_count),
3078 ntohl (mp->initial_interval),
3079 ntohl (mp->max_interval),
3080 ntohl (mp->min_interval), is_no);
3082 BAD_SW_IF_INDEX_LABEL;
3084 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3088 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3089 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3091 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3093 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3095 VALIDATE_SW_IF_INDEX (mp);
3097 is_no = mp->is_no == 1;
3098 use_default = mp->use_default == 1;
3099 no_advertise = mp->no_advertise == 1;
3100 off_link = mp->off_link == 1;
3101 no_autoconfig = mp->no_autoconfig == 1;
3102 no_onlink = mp->no_onlink == 1;
3104 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3105 (ip6_address_t *) mp->address,
3106 mp->address_length, use_default,
3107 ntohl (mp->val_lifetime),
3108 ntohl (mp->pref_lifetime), no_advertise,
3109 off_link, no_autoconfig, no_onlink, is_no);
3111 BAD_SW_IF_INDEX_LABEL;
3112 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3116 vl_api_sw_interface_ip6_enable_disable_t_handler
3117 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3119 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3120 vnet_main_t *vnm = vnet_get_main ();
3122 clib_error_t *error;
3126 VALIDATE_SW_IF_INDEX (mp);
3129 (mp->enable == 1) ? enable_ip6_interface (vm,
3130 ntohl (mp->sw_if_index)) :
3131 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3135 clib_error_report (error);
3136 rv = VNET_API_ERROR_UNSPECIFIED;
3140 rv = vnm->api_errno;
3143 BAD_SW_IF_INDEX_LABEL;
3145 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3149 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3150 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3152 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3154 clib_error_t *error;
3155 vnet_main_t *vnm = vnet_get_main ();
3159 VALIDATE_SW_IF_INDEX (mp);
3161 error = set_ip6_link_local_address (vm,
3162 ntohl (mp->sw_if_index),
3163 (ip6_address_t *) mp->address,
3164 mp->address_length);
3167 clib_error_report (error);
3168 rv = VNET_API_ERROR_UNSPECIFIED;
3172 rv = vnm->api_errno;
3175 BAD_SW_IF_INDEX_LABEL;
3177 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3181 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3183 vl_api_set_ip_flow_hash_reply_t *rmp;
3184 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3186 clib_warning ("unimplemented...");
3188 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3192 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3194 vl_api_set_ip_flow_hash_reply_t *rmp;
3197 flow_hash_config_t flow_hash_config = 0;
3199 table_id = ntohl (mp->vrf_id);
3201 #define _(a,b) if (mp->a) flow_hash_config |= b;
3202 foreach_flow_hash_bit;
3205 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3207 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3212 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3214 if (mp->is_ipv6 == 0)
3215 set_ip4_flow_hash (mp);
3217 set_ip6_flow_hash (mp);
3220 static void vl_api_sw_interface_set_unnumbered_t_handler
3221 (vl_api_sw_interface_set_unnumbered_t * mp)
3223 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3225 vnet_sw_interface_t *si;
3226 vnet_main_t *vnm = vnet_get_main ();
3227 u32 sw_if_index, unnumbered_sw_if_index;
3229 sw_if_index = ntohl (mp->sw_if_index);
3230 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3233 * The API message field names are backwards from
3234 * the underlying data structure names.
3235 * It's not worth changing them now.
3237 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3238 unnumbered_sw_if_index))
3240 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3244 /* Only check the "use loop0" field when setting the binding */
3246 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3248 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3252 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3256 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3257 si->unnumbered_sw_if_index = sw_if_index;
3258 ip4_sw_interface_enable_disable (sw_if_index, 1);
3259 ip6_sw_interface_enable_disable (sw_if_index, 1);
3263 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3264 si->unnumbered_sw_if_index = (u32) ~ 0;
3265 ip4_sw_interface_enable_disable (sw_if_index, 0);
3266 ip6_sw_interface_enable_disable (sw_if_index, 0);
3270 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3274 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3276 vl_api_create_loopback_reply_t *rmp;
3280 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3283 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3285 rmp->sw_if_index = ntohl (sw_if_index);
3291 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3293 vl_api_delete_loopback_reply_t *rmp;
3297 sw_if_index = ntohl (mp->sw_if_index);
3298 rv = vnet_delete_loopback_interface (sw_if_index);
3300 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3304 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3306 vl_api_control_ping_reply_t *rmp;
3310 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3312 rmp->vpe_pid = ntohl (getpid());
3318 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3320 u8 **shmem_vecp = (u8 **) arg;
3323 api_main_t *am = &api_main;
3326 shmem_vec = *shmem_vecp;
3328 offset = vec_len (shmem_vec);
3330 pthread_mutex_lock (&am->vlib_rp->mutex);
3331 oldheap = svm_push_data_heap (am->vlib_rp);
3333 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3335 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3337 svm_pop_heap (oldheap);
3338 pthread_mutex_unlock (&am->vlib_rp->mutex);
3340 *shmem_vecp = shmem_vec;
3345 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3347 vl_api_cli_reply_t *rp;
3348 unix_shared_memory_queue_t *q;
3349 vlib_main_t *vm = vlib_get_main ();
3350 api_main_t *am = &api_main;
3351 unformat_input_t input;
3355 q = vl_api_client_index_to_input_queue (mp->client_index);
3359 rp = vl_msg_api_alloc (sizeof (*rp));
3360 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3361 rp->context = mp->context;
3363 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3365 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3367 pthread_mutex_lock (&am->vlib_rp->mutex);
3368 oldheap = svm_push_data_heap (am->vlib_rp);
3370 vec_add1 (shmem_vec, 0);
3372 svm_pop_heap (oldheap);
3373 pthread_mutex_unlock (&am->vlib_rp->mutex);
3375 rp->reply_in_shmem = (uword) shmem_vec;
3377 vl_msg_api_send_shmem (q, (u8 *) & rp);
3381 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3383 u8 **mem_vecp = (u8 **) arg;
3384 u8 *mem_vec = *mem_vecp;
3385 u32 offset = vec_len (mem_vec);
3387 vec_validate (mem_vec, offset + buffer_bytes - 1);
3388 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3389 *mem_vecp = mem_vec;
3393 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3395 vl_api_cli_inband_reply_t *rmp;
3397 unix_shared_memory_queue_t *q;
3398 vlib_main_t *vm = vlib_get_main ();
3399 unformat_input_t input;
3402 q = vl_api_client_index_to_input_queue (mp->client_index);
3406 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3407 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3409 u32 len = vec_len (out_vec);
3411 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3413 rmp->length = htonl (len);
3414 clib_memcpy (rmp->reply, out_vec, len);
3421 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3424 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3425 vnet_main_t *vnm = vnet_get_main ();
3426 clib_error_t *error;
3431 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3433 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3437 clib_error_report (error);
3438 rv = VNET_API_ERROR_UNSPECIFIED;
3442 rv = vnm->api_errno;
3445 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3448 static void vl_api_sr_tunnel_add_del_t_handler
3449 (vl_api_sr_tunnel_add_del_t * mp)
3452 clib_warning ("unimplemented");
3454 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3456 vl_api_sr_tunnel_add_del_reply_t *rmp;
3457 ip6_address_t *segments = 0, *seg;
3458 ip6_address_t *tags = 0, *tag;
3459 ip6_address_t *this_address;
3462 if (mp->n_segments == 0)
3468 memset (a, 0, sizeof (*a));
3469 a->src_address = (ip6_address_t *) & mp->src_address;
3470 a->dst_address = (ip6_address_t *) & mp->dst_address;
3471 a->dst_mask_width = mp->dst_mask_width;
3472 a->flags_net_byte_order = mp->flags_net_byte_order;
3473 a->is_del = (mp->is_add == 0);
3474 a->rx_table_id = ntohl (mp->outer_vrf_id);
3475 a->tx_table_id = ntohl (mp->inner_vrf_id);
3477 a->name = format (0, "%s", mp->name);
3478 if (!(vec_len (a->name)))
3481 a->policy_name = format (0, "%s", mp->policy_name);
3482 if (!(vec_len (a->policy_name)))
3485 /* Yank segments and tags out of the API message */
3486 this_address = (ip6_address_t *) mp->segs_and_tags;
3487 for (i = 0; i < mp->n_segments; i++)
3489 vec_add2 (segments, seg, 1);
3490 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3493 for (i = 0; i < mp->n_tags; i++)
3495 vec_add2 (tags, tag, 1);
3496 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3500 a->segments = segments;
3503 rv = ip6_sr_add_del_tunnel (a);
3507 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3511 static void vl_api_sr_policy_add_del_t_handler
3512 (vl_api_sr_policy_add_del_t * mp)
3515 clib_warning ("unimplemented");
3517 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3519 vl_api_sr_policy_add_del_reply_t *rmp;
3522 memset (a, 0, sizeof (*a));
3523 a->is_del = (mp->is_add == 0);
3525 a->name = format (0, "%s", mp->name);
3526 if (!(vec_len (a->name)))
3528 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3532 if (!(mp->tunnel_names[0]))
3534 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3538 // start deserializing tunnel_names
3539 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3540 u8 *deser_tun_names = mp->tunnel_names;
3541 deser_tun_names += 1; //moving along
3544 int tun_name_len = 0;
3546 for (i = 0; i < num_tunnels; i++)
3548 tun_name_len = *deser_tun_names;
3549 deser_tun_names += 1;
3550 vec_resize (tun_name, tun_name_len);
3551 memcpy (tun_name, deser_tun_names, tun_name_len);
3552 vec_add1 (a->tunnel_names, tun_name);
3553 deser_tun_names += tun_name_len;
3557 rv = ip6_sr_add_del_policy (a);
3561 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3565 static void vl_api_sr_multicast_map_add_del_t_handler
3566 (vl_api_sr_multicast_map_add_del_t * mp)
3569 clib_warning ("unimplemented");
3571 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3573 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3575 memset (a, 0, sizeof (*a));
3576 a->is_del = (mp->is_add == 0);
3578 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3579 a->policy_name = format (0, "%s", mp->policy_name);
3581 if (a->multicast_address == 0)
3587 if (!(a->policy_name))
3593 #if DPDK > 0 /* Cannot call replicate without DPDK */
3594 rv = ip6_sr_add_del_multicastmap (a);
3596 clib_warning ("multicast replication without DPDK not implemented");
3597 rv = VNET_API_ERROR_UNIMPLEMENTED;
3602 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3606 #define foreach_classify_add_del_table_field \
3611 _(match_n_vectors) \
3612 _(next_table_index) \
3615 static void vl_api_classify_add_del_table_t_handler
3616 (vl_api_classify_add_del_table_t * mp)
3618 vl_api_classify_add_del_table_reply_t *rmp;
3619 vnet_classify_main_t *cm = &vnet_classify_main;
3620 vnet_classify_table_t *t;
3624 foreach_classify_add_del_table_field;
3627 #define _(a) a = ntohl(mp->a);
3628 foreach_classify_add_del_table_field;
3631 /* The underlying API fails silently, on purpose, so check here */
3632 if (mp->is_add == 0)
3633 if (pool_is_free_index (cm->tables, table_index))
3635 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3639 rv = vnet_classify_add_del_table
3640 (cm, mp->mask, nbuckets, memory_size,
3641 skip_n_vectors, match_n_vectors,
3642 next_table_index, miss_next_index, &table_index, mp->is_add);
3646 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3648 if (rv == 0 && mp->is_add)
3650 t = pool_elt_at_index (cm->tables, table_index);
3651 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3652 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3653 rmp->new_table_index = ntohl(table_index);
3657 rmp->skip_n_vectors = ~0;
3658 rmp->match_n_vectors = ~0;
3659 rmp->new_table_index = ~0;
3665 static void vl_api_classify_add_del_session_t_handler
3666 (vl_api_classify_add_del_session_t * mp)
3668 vnet_classify_main_t *cm = &vnet_classify_main;
3669 vl_api_classify_add_del_session_reply_t *rmp;
3671 u32 table_index, hit_next_index, opaque_index;
3674 table_index = ntohl (mp->table_index);
3675 hit_next_index = ntohl (mp->hit_next_index);
3676 opaque_index = ntohl (mp->opaque_index);
3677 advance = ntohl (mp->advance);
3679 rv = vnet_classify_add_del_session
3680 (cm, table_index, mp->match, hit_next_index, opaque_index,
3681 advance, mp->is_add);
3683 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3686 static void vl_api_classify_set_interface_ip_table_t_handler
3687 (vl_api_classify_set_interface_ip_table_t * mp)
3689 vlib_main_t *vm = vlib_get_main ();
3690 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3692 u32 table_index, sw_if_index;
3694 table_index = ntohl (mp->table_index);
3695 sw_if_index = ntohl (mp->sw_if_index);
3697 VALIDATE_SW_IF_INDEX (mp);
3700 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3702 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3704 BAD_SW_IF_INDEX_LABEL;
3706 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3709 static void vl_api_classify_set_interface_l2_tables_t_handler
3710 (vl_api_classify_set_interface_l2_tables_t * mp)
3712 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3714 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3717 ip4_table_index = ntohl (mp->ip4_table_index);
3718 ip6_table_index = ntohl (mp->ip6_table_index);
3719 other_table_index = ntohl (mp->other_table_index);
3720 sw_if_index = ntohl (mp->sw_if_index);
3722 VALIDATE_SW_IF_INDEX (mp);
3725 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
3729 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
3735 if (ip4_table_index != ~0 || ip6_table_index != ~0
3736 || other_table_index != ~0)
3742 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
3744 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
3747 BAD_SW_IF_INDEX_LABEL;
3749 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3753 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3756 vl_api_l2_fib_clear_table_reply_t *rmp;
3758 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3759 * that is not currently implemented. When that TODO is fixed
3760 * this call should be changed to pass 1 instead of 0.
3762 l2fib_clear_table (0);
3764 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3767 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3768 u32 sw_if_index, u32 enable);
3771 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3775 vl_api_l2_interface_efp_filter_reply_t *rmp;
3776 vnet_main_t *vnm = vnet_get_main ();
3778 // enable/disable the feature
3779 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3780 rv = vnm->api_errno;
3782 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3786 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3787 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3790 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3791 vnet_main_t *vnm = vnet_get_main ();
3792 vlib_main_t *vm = vlib_get_main ();
3795 VALIDATE_SW_IF_INDEX (mp);
3797 vtr_op = ntohl (mp->vtr_op);
3799 /* The L2 code is unsuspicious */
3802 case L2_VTR_DISABLED:
3807 case L2_VTR_TRANSLATE_1_1:
3808 case L2_VTR_TRANSLATE_1_2:
3809 case L2_VTR_TRANSLATE_2_1:
3810 case L2_VTR_TRANSLATE_2_2:
3814 rv = VNET_API_ERROR_INVALID_VALUE;
3815 goto bad_sw_if_index;
3818 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
3819 ntohl (mp->push_dot1q), ntohl (mp->tag1),
3822 BAD_SW_IF_INDEX_LABEL;
3824 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3828 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
3831 vl_api_create_vhost_user_if_reply_t *rmp;
3832 u32 sw_if_index = (u32) ~ 0;
3834 vnet_main_t *vnm = vnet_get_main ();
3835 vlib_main_t *vm = vlib_get_main ();
3837 #if DPDK > 0 && DPDK_VHOST_USER
3838 rv = dpdk_vhost_user_create_if (
3840 rv = vhost_user_create_if (
3842 vnm, vm, (char *) mp->sock_filename,
3843 mp->is_server, &sw_if_index, (u64) ~ 0,
3844 mp->renumber, ntohl (mp->custom_dev_instance),
3845 (mp->use_custom_mac) ? mp->mac_address : NULL);
3848 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3850 rmp->sw_if_index = ntohl (sw_if_index);
3856 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
3859 vl_api_modify_vhost_user_if_reply_t *rmp;
3860 u32 sw_if_index = ntohl (mp->sw_if_index);
3862 vnet_main_t *vnm = vnet_get_main ();
3863 vlib_main_t *vm = vlib_get_main ();
3865 #if DPDK > 0 && DPDK_VHOST_USER
3866 rv = dpdk_vhost_user_modify_if (
3868 rv = vhost_user_modify_if (
3870 vnm, vm, (char *) mp->sock_filename,
3871 mp->is_server, sw_if_index, (u64) ~ 0,
3872 mp->renumber, ntohl (mp->custom_dev_instance));
3873 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
3877 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
3880 vl_api_delete_vhost_user_if_reply_t *rmp;
3881 vpe_api_main_t *vam = &vpe_api_main;
3882 u32 sw_if_index = ntohl (mp->sw_if_index);
3884 vnet_main_t *vnm = vnet_get_main ();
3885 vlib_main_t *vm = vlib_get_main ();
3887 #if DPDK > 0 && DPDK_VHOST_USER
3888 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
3890 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
3893 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
3896 unix_shared_memory_queue_t *q =
3897 vl_api_client_index_to_input_queue (mp->client_index);
3901 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3906 vl_api_sw_interface_vhost_user_details_t_handler
3907 (vl_api_sw_interface_vhost_user_details_t * mp)
3909 clib_warning ("BUG");
3913 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3914 unix_shared_memory_queue_t * q,
3915 vhost_user_intf_details_t * vui,
3918 vl_api_sw_interface_vhost_user_details_t *mp;
3920 mp = vl_msg_api_alloc (sizeof (*mp));
3921 memset (mp, 0, sizeof (*mp));
3922 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3923 mp->sw_if_index = ntohl (vui->sw_if_index);
3924 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3925 mp->features = clib_net_to_host_u64 (vui->features);
3926 mp->is_server = vui->is_server;
3927 mp->num_regions = ntohl (vui->num_regions);
3928 mp->sock_errno = ntohl (vui->sock_errno);
3929 mp->context = context;
3931 strncpy ((char *) mp->sock_filename,
3932 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
3933 strncpy ((char *) mp->interface_name,
3934 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
3936 vl_msg_api_send_shmem (q, (u8 *) & mp);
3940 vl_api_sw_interface_vhost_user_dump_t_handler
3941 (vl_api_sw_interface_vhost_user_dump_t * mp)
3944 vpe_api_main_t *am = &vpe_api_main;
3945 vnet_main_t *vnm = vnet_get_main ();
3946 vlib_main_t *vm = vlib_get_main ();
3947 vhost_user_intf_details_t *ifaces = NULL;
3948 vhost_user_intf_details_t *vuid = NULL;
3949 unix_shared_memory_queue_t *q;
3951 q = vl_api_client_index_to_input_queue (mp->client_index);
3955 #if DPDK > 0 && DPDK_VHOST_USER
3956 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
3958 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
3963 vec_foreach (vuid, ifaces)
3965 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3971 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3972 unix_shared_memory_queue_t * q,
3974 l2t_main_t * lm, u32 context)
3976 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
3978 vnet_sw_interface_t *si = NULL;
3980 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3982 if_name = format (if_name, "%U",
3983 format_vnet_sw_interface_name, lm->vnet_main, si);
3985 mp = vl_msg_api_alloc (sizeof (*mp));
3986 memset (mp, 0, sizeof (*mp));
3987 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3988 strncpy ((char *) mp->interface_name,
3989 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
3990 mp->sw_if_index = ntohl (si->sw_if_index);
3991 mp->local_session_id = s->local_session_id;
3992 mp->remote_session_id = s->remote_session_id;
3993 mp->local_cookie[0] = s->local_cookie[0];
3994 mp->local_cookie[1] = s->local_cookie[1];
3995 mp->remote_cookie = s->remote_cookie;
3996 clib_memcpy (mp->client_address, &s->client_address,
3997 sizeof (s->client_address));
3998 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
3999 mp->l2_sublayer_present = s->l2_sublayer_present;
4000 mp->context = context;
4002 vl_msg_api_send_shmem (q, (u8 *) & mp);
4006 send_ip_address_details (vpe_api_main_t * am,
4007 unix_shared_memory_queue_t * q,
4008 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4010 vl_api_ip_address_details_t *mp;
4012 mp = vl_msg_api_alloc (sizeof (*mp));
4013 memset (mp, 0, sizeof (*mp));
4014 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4018 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4022 u32 *tp = (u32 *) mp->ip;
4023 *tp = ntohl (*(u32 *) ip);
4025 mp->prefix_length = prefix_length;
4026 mp->context = context;
4028 vl_msg_api_send_shmem (q, (u8 *) & mp);
4032 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4034 vpe_api_main_t *am = &vpe_api_main;
4035 unix_shared_memory_queue_t *q;
4038 ip6_main_t *im6 = &ip6_main;
4039 ip4_main_t *im4 = &ip4_main;
4040 ip_lookup_main_t *lm6 = &im6->lookup_main;
4041 ip_lookup_main_t *lm4 = &im4->lookup_main;
4042 ip_interface_address_t *ia = 0;
4043 u32 sw_if_index = ~0;
4044 int rv __attribute__ ((unused)) = 0;
4046 VALIDATE_SW_IF_INDEX (mp);
4048 sw_if_index = ntohl (mp->sw_if_index);
4050 q = vl_api_client_index_to_input_queue (mp->client_index);
4059 foreach_ip_interface_address (lm6, ia, sw_if_index,
4060 1 /* honor unnumbered */,
4062 r6 = ip_interface_address_get_address (lm6, ia);
4063 u16 prefix_length = ia->address_length;
4064 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4071 foreach_ip_interface_address (lm4, ia, sw_if_index,
4072 1 /* honor unnumbered */,
4074 r4 = ip_interface_address_get_address (lm4, ia);
4075 u16 prefix_length = ia->address_length;
4076 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4080 BAD_SW_IF_INDEX_LABEL;
4084 send_ip_details (vpe_api_main_t * am,
4085 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4087 vl_api_ip_details_t *mp;
4089 mp = vl_msg_api_alloc (sizeof (*mp));
4090 memset (mp, 0, sizeof (*mp));
4091 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4093 mp->sw_if_index = ntohl (sw_if_index);
4094 mp->context = context;
4096 vl_msg_api_send_shmem (q, (u8 *) & mp);
4100 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4103 vpe_api_main_t *am = &vpe_api_main;
4104 l2t_main_t *lm = &l2t_main;
4105 unix_shared_memory_queue_t *q;
4106 l2t_session_t *session;
4108 q = vl_api_client_index_to_input_queue (mp->client_index);
4113 pool_foreach (session, lm->sessions,
4115 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4122 send_sw_interface_tap_details (vpe_api_main_t * am,
4123 unix_shared_memory_queue_t * q,
4124 tapcli_interface_details_t * tap_if,
4127 vl_api_sw_interface_tap_details_t *mp;
4128 mp = vl_msg_api_alloc (sizeof (*mp));
4129 memset (mp, 0, sizeof (*mp));
4130 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4131 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4132 strncpy ((char *) mp->dev_name,
4133 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4134 mp->context = context;
4136 vl_msg_api_send_shmem (q, (u8 *) & mp);
4140 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4143 vpe_api_main_t *am = &vpe_api_main;
4144 unix_shared_memory_queue_t *q;
4145 tapcli_interface_details_t *tapifs = NULL;
4146 tapcli_interface_details_t *tap_if = NULL;
4148 q = vl_api_client_index_to_input_queue (mp->client_index);
4152 rv = vnet_tap_dump_ifs (&tapifs);
4156 vec_foreach (tap_if, tapifs)
4158 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4165 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4167 vpe_api_main_t *am = &vpe_api_main;
4168 vnet_main_t *vnm = vnet_get_main ();
4169 vlib_main_t *vm = vlib_get_main ();
4170 vnet_interface_main_t *im = &vnm->interface_main;
4171 unix_shared_memory_queue_t *q;
4172 vnet_sw_interface_t *si, *sorted_sis;
4173 u32 sw_if_index = ~0;
4175 q = vl_api_client_index_to_input_queue (mp->client_index);
4181 /* Gather interfaces. */
4182 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4183 _vec_len (sorted_sis) = 0;
4185 pool_foreach (si, im->sw_interfaces,
4187 vec_add1 (sorted_sis, si[0]);
4191 vec_foreach (si, sorted_sis)
4193 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4195 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4199 sw_if_index = si->sw_if_index;
4200 send_ip_details (am, q, sw_if_index, mp->context);
4206 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4208 clib_warning ("BUG");
4212 send_l2fib_table_entry (vpe_api_main_t * am,
4213 unix_shared_memory_queue_t * q,
4214 l2fib_entry_key_t * l2fe_key,
4215 l2fib_entry_result_t * l2fe_res, u32 context)
4217 vl_api_l2_fib_table_entry_t *mp;
4219 mp = vl_msg_api_alloc (sizeof (*mp));
4220 memset (mp, 0, sizeof (*mp));
4221 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4224 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4226 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4227 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4228 mp->static_mac = l2fe_res->fields.static_mac;
4229 mp->filter_mac = l2fe_res->fields.filter;
4230 mp->bvi_mac = l2fe_res->fields.bvi;
4231 mp->context = context;
4233 vl_msg_api_send_shmem (q, (u8 *) & mp);
4237 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4239 vpe_api_main_t *am = &vpe_api_main;
4240 bd_main_t *bdm = &bd_main;
4241 l2fib_entry_key_t *l2fe_key = NULL;
4242 l2fib_entry_result_t *l2fe_res = NULL;
4243 u32 ni, bd_id = ntohl (mp->bd_id);
4245 unix_shared_memory_queue_t *q;
4248 q = vl_api_client_index_to_input_queue (mp->client_index);
4252 /* see l2fib_table_dump: ~0 means "any" */
4257 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4264 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4266 vec_foreach_index (ni, l2fe_key)
4268 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4269 vec_elt_at_index (l2fe_res, ni), mp->context);
4271 vec_free (l2fe_key);
4272 vec_free (l2fe_res);
4276 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4278 vl_api_show_version_reply_t *rmp;
4280 char *vpe_api_get_build_directory (void);
4281 char *vpe_api_get_version (void);
4282 char *vpe_api_get_build_date (void);
4284 unix_shared_memory_queue_t *q =
4285 vl_api_client_index_to_input_queue (mp->client_index);
4291 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4293 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4294 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4295 ARRAY_LEN(rmp->build_directory)-1);
4296 strncpy ((char *) rmp->version, vpe_api_get_version(),
4297 ARRAY_LEN(rmp->version)-1);
4298 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4299 ARRAY_LEN(rmp->build_date)-1);
4305 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4307 vlib_main_t *vm = vlib_get_main ();
4308 vl_api_get_node_index_reply_t *rmp;
4311 u32 node_index = ~0;
4313 n = vlib_get_node_by_name (vm, mp->node_name);
4316 rv = VNET_API_ERROR_NO_SUCH_NODE;
4318 node_index = n->index;
4321 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4323 rmp->node_index = ntohl(node_index);
4329 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4331 vlib_main_t *vm = vlib_get_main ();
4332 vl_api_get_next_index_reply_t *rmp;
4333 vlib_node_t *node, *next_node;
4335 u32 next_node_index = ~0, next_index = ~0;
4338 node = vlib_get_node_by_name (vm, mp->node_name);
4342 rv = VNET_API_ERROR_NO_SUCH_NODE;
4346 next_node = vlib_get_node_by_name (vm, mp->next_name);
4350 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4354 next_node_index = next_node->index;
4356 p = hash_get (node->next_slot_by_node, next_node_index);
4360 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4368 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4370 rmp->next_index = ntohl(next_index);
4376 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4378 vlib_main_t *vm = vlib_get_main ();
4379 vl_api_add_node_next_reply_t *rmp;
4380 vlib_node_t *n, *next;
4382 u32 next_index = ~0;
4384 n = vlib_get_node_by_name (vm, mp->node_name);
4388 rv = VNET_API_ERROR_NO_SUCH_NODE;
4392 next = vlib_get_node_by_name (vm, mp->next_name);
4395 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4397 next_index = vlib_node_add_next (vm, n->index, next->index);
4401 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4403 rmp->next_index = ntohl(next_index);
4408 static void vl_api_l2tpv3_create_tunnel_t_handler
4409 (vl_api_l2tpv3_create_tunnel_t * mp)
4411 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4412 l2t_main_t *lm = &l2t_main;
4413 u32 sw_if_index = (u32) ~ 0;
4416 if (mp->is_ipv6 != 1)
4418 rv = VNET_API_ERROR_UNIMPLEMENTED;
4422 u32 encap_fib_index;
4424 if (mp->encap_vrf_id != ~0)
4427 ip6_main_t *im = &ip6_main;
4430 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4432 rv = VNET_API_ERROR_NO_SUCH_FIB;
4435 encap_fib_index = p[0];
4439 encap_fib_index = ~0;
4442 rv = create_l2tpv3_ipv6_tunnel (lm,
4443 (ip6_address_t *) mp->client_address,
4444 (ip6_address_t *) mp->our_address,
4445 ntohl (mp->local_session_id),
4446 ntohl (mp->remote_session_id),
4447 clib_net_to_host_u64 (mp->local_cookie),
4448 clib_net_to_host_u64 (mp->remote_cookie),
4449 mp->l2_sublayer_present,
4450 encap_fib_index, &sw_if_index);
4454 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4456 rmp->sw_if_index = ntohl (sw_if_index);
4461 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4462 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4464 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4465 l2t_main_t *lm = &l2t_main;
4468 VALIDATE_SW_IF_INDEX (mp);
4470 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4471 clib_net_to_host_u64 (mp->new_local_cookie),
4472 clib_net_to_host_u64
4473 (mp->new_remote_cookie));
4475 BAD_SW_IF_INDEX_LABEL;
4477 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4480 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4481 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4484 vnet_main_t *vnm = vnet_get_main ();
4485 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4487 VALIDATE_SW_IF_INDEX (mp);
4489 rv = l2tpv3_interface_enable_disable
4490 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4492 BAD_SW_IF_INDEX_LABEL;
4494 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4497 static void vl_api_l2tpv3_set_lookup_key_t_handler
4498 (vl_api_l2tpv3_set_lookup_key_t * mp)
4501 l2t_main_t *lm = &l2t_main;
4502 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4504 if (mp->key > L2T_LOOKUP_SESSION_ID)
4506 rv = VNET_API_ERROR_INVALID_VALUE;
4510 lm->lookup_type = mp->key;
4513 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4516 static void vl_api_vxlan_add_del_tunnel_t_handler
4517 (vl_api_vxlan_add_del_tunnel_t * mp)
4519 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4521 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4522 u32 encap_fib_index;
4524 ip4_main_t *im = &ip4_main;
4525 u32 sw_if_index = ~0;
4527 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4530 rv = VNET_API_ERROR_NO_SUCH_FIB;
4533 encap_fib_index = p[0];
4535 /* Check src & dst are different */
4536 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4537 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4539 rv = VNET_API_ERROR_SAME_SRC_DST;
4542 memset (a, 0, sizeof (*a));
4544 a->is_add = mp->is_add;
4545 a->is_ip6 = mp->is_ipv6;
4547 /* ip addresses sent in network byte order */
4550 memcpy (&(a->src.ip6), mp->src_address, 16);
4551 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4555 memcpy (&(a->src.ip4), mp->src_address, 4);
4556 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4559 a->encap_fib_index = encap_fib_index;
4560 a->decap_next_index = ntohl (mp->decap_next_index);
4561 a->vni = ntohl (mp->vni);
4562 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4566 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4568 rmp->sw_if_index = ntohl (sw_if_index);
4573 static void send_vxlan_tunnel_details
4574 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4576 vl_api_vxlan_tunnel_details_t *rmp;
4577 ip4_main_t *im4 = &ip4_main;
4578 ip6_main_t *im6 = &ip6_main;
4579 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4581 rmp = vl_msg_api_alloc (sizeof (*rmp));
4582 memset (rmp, 0, sizeof (*rmp));
4583 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4586 memcpy (rmp->src_address, &(t->src.ip6), 16);
4587 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4588 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4592 memcpy (rmp->src_address, &(t->src.ip4), 4);
4593 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4594 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4596 rmp->vni = htonl (t->vni);
4597 rmp->decap_next_index = htonl (t->decap_next_index);
4598 rmp->sw_if_index = htonl (t->sw_if_index);
4599 rmp->is_ipv6 = is_ipv6;
4600 rmp->context = context;
4602 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4605 static void vl_api_vxlan_tunnel_dump_t_handler
4606 (vl_api_vxlan_tunnel_dump_t * mp)
4608 unix_shared_memory_queue_t *q;
4609 vxlan_main_t *vxm = &vxlan_main;
4613 q = vl_api_client_index_to_input_queue (mp->client_index);
4619 sw_if_index = ntohl (mp->sw_if_index);
4621 if (~0 == sw_if_index)
4624 pool_foreach (t, vxm->tunnels,
4626 send_vxlan_tunnel_details(t, q, mp->context);
4632 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4633 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4637 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4638 send_vxlan_tunnel_details (t, q, mp->context);
4642 static void vl_api_gre_add_del_tunnel_t_handler
4643 (vl_api_gre_add_del_tunnel_t * mp)
4645 vl_api_gre_add_del_tunnel_reply_t *rmp;
4647 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4650 ip4_main_t *im = &ip4_main;
4651 u32 sw_if_index = ~0;
4653 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4656 rv = VNET_API_ERROR_NO_SUCH_FIB;
4659 outer_fib_id = p[0];
4661 /* Check src & dst are different */
4662 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4663 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4665 rv = VNET_API_ERROR_SAME_SRC_DST;
4668 memset (a, 0, sizeof (*a));
4670 a->is_add = mp->is_add;
4673 /* ip addresses sent in network byte order */
4674 clib_memcpy (&(a->src), mp->src_address, 4);
4675 clib_memcpy (&(a->dst), mp->dst_address, 4);
4677 a->outer_fib_id = outer_fib_id;
4678 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4682 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4684 rmp->sw_if_index = ntohl (sw_if_index);
4689 static void send_gre_tunnel_details
4690 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4692 vl_api_gre_tunnel_details_t *rmp;
4693 ip4_main_t *im = &ip4_main;
4695 rmp = vl_msg_api_alloc (sizeof (*rmp));
4696 memset (rmp, 0, sizeof (*rmp));
4697 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4698 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4699 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4700 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
4702 rmp->sw_if_index = htonl (t->sw_if_index);
4703 rmp->context = context;
4705 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4709 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4711 unix_shared_memory_queue_t *q;
4712 gre_main_t *gm = &gre_main;
4716 q = vl_api_client_index_to_input_queue (mp->client_index);
4722 sw_if_index = ntohl (mp->sw_if_index);
4724 if (~0 == sw_if_index)
4727 pool_foreach (t, gm->tunnels,
4729 send_gre_tunnel_details(t, q, mp->context);
4735 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4736 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4740 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4741 send_gre_tunnel_details (t, q, mp->context);
4746 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4748 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4750 vl_api_l2_patch_add_del_reply_t *rmp;
4751 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4755 VALIDATE_RX_SW_IF_INDEX (mp);
4756 VALIDATE_TX_SW_IF_INDEX (mp);
4758 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4759 ntohl (mp->tx_sw_if_index),
4760 (int) (mp->is_add != 0));
4762 BAD_RX_SW_IF_INDEX_LABEL;
4763 BAD_TX_SW_IF_INDEX_LABEL;
4765 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4769 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4770 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4772 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4774 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4775 u32 encap_fib_index, decap_fib_index;
4778 ip4_main_t *im = &ip4_main;
4779 u32 sw_if_index = ~0;
4782 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4785 rv = VNET_API_ERROR_NO_SUCH_FIB;
4788 encap_fib_index = p[0];
4790 protocol = mp->protocol;
4792 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4793 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4795 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4798 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4801 decap_fib_index = p[0];
4805 decap_fib_index = ntohl (mp->decap_vrf_id);
4808 /* Check src & dst are different */
4809 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4810 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
4812 rv = VNET_API_ERROR_SAME_SRC_DST;
4815 memset (a, 0, sizeof (*a));
4817 a->is_add = mp->is_add;
4818 a->is_ip6 = mp->is_ipv6;
4819 /* ip addresses sent in network byte order */
4822 clib_memcpy (&(a->local.ip6), mp->local, 16);
4823 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
4827 clib_memcpy (&(a->local.ip4), mp->local, 4);
4828 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
4830 a->encap_fib_index = encap_fib_index;
4831 a->decap_fib_index = decap_fib_index;
4832 a->protocol = protocol;
4833 a->vni = ntohl (mp->vni);
4834 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4838 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4840 rmp->sw_if_index = ntohl (sw_if_index);
4845 static void send_vxlan_gpe_tunnel_details
4846 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4848 vl_api_vxlan_gpe_tunnel_details_t *rmp;
4849 ip4_main_t *im4 = &ip4_main;
4850 ip6_main_t *im6 = &ip6_main;
4851 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4853 rmp = vl_msg_api_alloc (sizeof (*rmp));
4854 memset (rmp, 0, sizeof (*rmp));
4855 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4858 memcpy (rmp->local, &(t->local.ip6), 16);
4859 memcpy (rmp->remote, &(t->remote.ip6), 16);
4860 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id);
4861 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].ft_table_id);
4865 memcpy (rmp->local, &(t->local.ip4), 4);
4866 memcpy (rmp->remote, &(t->remote.ip4), 4);
4867 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id);
4868 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].ft_table_id);
4870 rmp->vni = htonl (t->vni);
4871 rmp->protocol = t->protocol;
4872 rmp->sw_if_index = htonl (t->sw_if_index);
4873 rmp->is_ipv6 = is_ipv6;
4874 rmp->context = context;
4876 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4879 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4880 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4882 unix_shared_memory_queue_t *q;
4883 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
4884 vxlan_gpe_tunnel_t *t;
4887 q = vl_api_client_index_to_input_queue (mp->client_index);
4893 sw_if_index = ntohl (mp->sw_if_index);
4895 if (~0 == sw_if_index)
4898 pool_foreach (t, vgm->tunnels,
4900 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4906 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
4907 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
4911 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4912 send_vxlan_gpe_tunnel_details (t, q, mp->context);
4916 /** Used for transferring locators via VPP API */
4918 typedef CLIB_PACKED (struct {
4919 u32 sw_if_index; /**< locator sw_if_index */
4920 u8 priority; /**< locator priority */
4921 u8 weight; /**< locator weight */
4926 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
4929 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4931 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4933 ls_locator_t *ls_loc;
4934 u32 ls_index = ~0, locator_num;
4935 u8 *locator_name = NULL;
4938 memset (a, 0, sizeof (a[0]));
4940 locator_name = format (0, "%s", mp->locator_set_name);
4942 a->name = locator_name;
4943 a->is_add = mp->is_add;
4945 locator_num = clib_net_to_host_u32 (mp->locator_num);
4947 memset (&locator, 0, sizeof (locator));
4948 for (i = 0; i < locator_num; i++)
4950 ls_loc = &((ls_locator_t *) mp->locators)[i];
4951 VALIDATE_SW_IF_INDEX (ls_loc);
4953 locator.sw_if_index = htonl (ls_loc->sw_if_index);
4954 locator.priority = ls_loc->priority;
4955 locator.weight = ls_loc->weight;
4957 vec_add1 (a->locators, locator);
4960 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
4962 BAD_SW_IF_INDEX_LABEL;
4964 vec_free (locator_name);
4965 vec_free (a->locators);
4968 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
4970 rmp->ls_index = clib_host_to_net_u32 (ls_index);
4976 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
4978 vl_api_lisp_add_del_locator_reply_t *rmp;
4980 locator_t locator, *locators = NULL;
4981 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4983 u8 *locator_name = NULL;
4985 memset (&locator, 0, sizeof (locator));
4986 memset (a, 0, sizeof (a[0]));
4988 locator.sw_if_index = ntohl (mp->sw_if_index);
4989 locator.priority = mp->priority;
4990 locator.weight = mp->weight;
4992 vec_add1 (locators, locator);
4994 locator_name = format (0, "%s", mp->locator_set_name);
4996 a->name = locator_name;
4997 a->locators = locators;
4998 a->is_add = mp->is_add;
5001 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5003 vec_free (locators);
5004 vec_free (locator_name);
5006 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5010 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5016 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5017 gid_address_ip_set (dst, src, IP4);
5018 gid_address_ippref_len (dst) = len;
5019 ip_prefix_normalize (&gid_address_ippref (dst));
5022 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5023 gid_address_ip_set (dst, src, IP6);
5024 gid_address_ippref_len (dst) = len;
5025 ip_prefix_normalize (&gid_address_ippref (dst));
5027 case 2: /* l2 mac */
5028 gid_address_type (dst) = GID_ADDR_MAC;
5029 clib_memcpy (&gid_address_mac (dst), src, 6);
5033 return VNET_API_ERROR_INVALID_VALUE;
5036 gid_address_vni (dst) = vni;
5042 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5044 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5045 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5047 gid_address_t _eid, *eid = &_eid;
5049 u32 locator_set_index = ~0, map_index = ~0;
5050 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5052 memset (a, 0, sizeof (a[0]));
5053 memset (eid, 0, sizeof (eid[0]));
5055 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5056 mp->eid_type, mp->eid, mp->prefix_len);
5060 name = format (0, "%s", mp->locator_set_name);
5061 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5064 rv = VNET_API_ERROR_INVALID_VALUE;
5067 locator_set_index = p[0];
5069 /* XXX treat batch configuration */
5070 a->is_add = mp->is_add;
5071 gid_address_copy (&a->eid, eid);
5072 a->locator_set_index = locator_set_index;
5074 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5078 gid_address_free (&a->eid);
5080 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5084 vl_api_lisp_eid_table_add_del_map_t_handler
5085 (vl_api_lisp_eid_table_add_del_map_t * mp)
5087 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5089 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5090 clib_net_to_host_u32 (mp->dp_table),
5091 mp->is_l2, mp->is_add);
5092 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5094 /** Used for transferring locators via VPP API */
5096 typedef CLIB_PACKED (struct {
5097 u8 is_ip4; /**< is locator an IPv4 address */
5098 u8 priority; /**< locator priority */
5099 u8 weight; /**< locator weight */
5100 u8 addr[16]; /**< IPv4/IPv6 address */
5104 static locator_pair_t *
5105 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5108 locator_pair_t *pairs = 0, pair;
5111 for (i = 0; i < rloc_num; i++)
5114 r = &((rloc_t *) lcl_locs)[i];
5115 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5116 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5118 /* remote locators */
5119 r = &((rloc_t *) rmt_locs)[i];
5120 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5121 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5123 pair.priority = r->priority;
5124 pair.weight = r->weight;
5126 vec_add1 (pairs, pair);
5132 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5135 locator_t *locs = 0, loc;
5138 for (i = 0; i < rloc_num; i++)
5140 /* remote locators */
5141 r = &((rloc_t *) rmt_locs)[i];
5142 memset (&loc, 0, sizeof (loc));
5143 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5145 loc.priority = r->priority;
5146 loc.weight = r->weight;
5148 vec_add1 (locs, loc);
5154 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5155 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5157 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5158 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5159 locator_pair_t *pairs = 0;
5162 memset (a, 0, sizeof (a[0]));
5164 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5165 mp->rmt_eid, mp->rmt_len);
5166 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5167 mp->lcl_eid, mp->lcl_len);
5169 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5171 if (rv || 0 == pairs)
5174 a->is_add = mp->is_add;
5175 a->locator_pairs = pairs;
5176 a->dp_table = mp->dp_table;
5178 a->action = mp->action;
5180 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5183 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5187 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5190 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5192 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5194 memset (a, 0, sizeof (a[0]));
5196 a->is_add = mp->is_add;
5197 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5199 rv = vnet_lisp_add_del_map_resolver (a);
5201 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5205 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5208 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5210 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5212 a->is_en = mp->is_en;
5213 vnet_lisp_gpe_enable_disable (a);
5215 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5219 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5221 vl_api_lisp_enable_disable_reply_t *rmp;
5224 vnet_lisp_enable_disable (mp->is_en);
5225 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5229 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5231 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5233 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5235 a->is_add = mp->is_add;
5236 a->dp_table = mp->dp_table;
5238 a->is_l2 = mp->is_l2;
5239 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5241 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5245 vl_api_show_lisp_map_request_mode_t_handler
5246 (vl_api_show_lisp_map_request_mode_t * mp)
5249 vl_api_show_lisp_map_request_mode_reply_t *rmp;
5252 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
5254 rmp->mode = vnet_lisp_get_map_request_mode ();
5260 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
5262 vl_api_lisp_map_request_mode_reply_t *rmp;
5265 rv = vnet_lisp_set_map_request_mode (mp->mode);
5267 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
5271 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5274 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5278 ls_name = format (0, "%s", mp->ls_name);
5279 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5282 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5286 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5287 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5289 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5291 u8 *locator_set_name = NULL;
5292 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5294 locator_set_name = format (0, "%s", mp->locator_set_name);
5296 a->is_add = mp->is_add;
5297 a->locator_set_name = locator_set_name;
5299 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5301 vec_free (locator_set_name);
5303 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5307 vl_api_lisp_add_del_remote_mapping_t_handler
5308 (vl_api_lisp_add_del_remote_mapping_t * mp)
5310 locator_t *rlocs = 0;
5311 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5313 gid_address_t _eid, *eid = &_eid;
5314 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5316 memset (eid, 0, sizeof (eid[0]));
5318 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5319 mp->eid_type, mp->eid, mp->eid_len);
5323 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5327 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5328 gid_address_copy (&a->deid, eid);
5330 rv = vnet_lisp_add_del_adjacency (a);
5337 /* NOTE: for now this works as a static remote mapping, i.e.,
5338 * not authoritative and ttl infinite. */
5339 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5340 mp->is_add, 1 /* is_static */ , 0);
5343 vnet_lisp_clear_all_remote_adjacencies ();
5348 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5352 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5354 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5355 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5358 memset (a, 0, sizeof (a[0]));
5360 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5361 mp->eid_type, mp->seid, mp->seid_len);
5362 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5363 mp->eid_type, mp->deid, mp->deid_len);
5368 a->is_add = mp->is_add;
5369 rv = vnet_lisp_add_del_adjacency (a);
5372 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5376 send_lisp_locator_details (lisp_cp_main_t * lcm,
5378 unix_shared_memory_queue_t * q, u32 context)
5380 vl_api_lisp_locator_details_t *rmp;
5382 rmp = vl_msg_api_alloc (sizeof (*rmp));
5383 memset (rmp, 0, sizeof (*rmp));
5384 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5385 rmp->context = context;
5387 rmp->local = loc->local;
5390 rmp->sw_if_index = ntohl (loc->sw_if_index);
5394 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5395 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5397 rmp->priority = loc->priority;
5398 rmp->weight = loc->weight;
5400 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5404 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5407 unix_shared_memory_queue_t *q = 0;
5408 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5409 locator_set_t *lsit = 0;
5411 u32 ls_index = ~0, *locit = 0;
5414 q = vl_api_client_index_to_input_queue (mp->client_index);
5420 if (mp->is_index_set)
5421 ls_index = htonl (mp->ls_index);
5424 /* make sure we get a proper C-string */
5425 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
5426 ls_name = format (0, "%s", mp->ls_name);
5427 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
5433 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
5436 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5438 vec_foreach (locit, lsit->locator_indices)
5440 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5441 send_lisp_locator_details (lcm, loc, q, mp->context);
5448 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5449 locator_set_t * lsit,
5450 unix_shared_memory_queue_t * q,
5451 u32 context, u32 ls_index)
5453 vl_api_lisp_locator_set_details_t *rmp;
5456 rmp = vl_msg_api_alloc (sizeof (*rmp));
5457 memset (rmp, 0, sizeof (*rmp));
5458 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5459 rmp->context = context;
5461 rmp->ls_index = htonl (ls_index);
5464 ASSERT (lsit->name != NULL);
5465 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
5466 vec_len (lsit->name));
5470 str = format (0, "<remote-%d>", ls_index);
5471 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
5475 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5479 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5481 unix_shared_memory_queue_t *q = NULL;
5482 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5483 locator_set_t *lsit = NULL;
5486 q = vl_api_client_index_to_input_queue (mp->client_index);
5492 filter = mp->filter;
5494 pool_foreach (lsit, lcm->locator_set_pool,
5496 if (filter && !((1 == filter && lsit->local) ||
5497 (2 == filter && !lsit->local)))
5501 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
5502 lsit - lcm->locator_set_pool);
5508 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
5510 ASSERT (prefix_length);
5511 ip_prefix_t *ippref = &fid_addr_ippref (src);
5513 switch (fid_addr_type (src))
5515 case FID_ADDR_IP_PREF:
5516 if (ip_prefix_version (ippref) == IP4)
5517 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
5519 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
5520 prefix_length[0] = ip_prefix_len (ippref);
5524 prefix_length[0] = 0;
5525 clib_memcpy (dst, fid_addr_mac (src), 6);
5529 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
5535 fid_type_to_api_type (fid_address_t * fid)
5537 ip_prefix_t *ippref;
5539 switch (fid_addr_type (fid))
5541 case FID_ADDR_IP_PREF:
5542 ippref = &fid_addr_ippref (fid);
5543 if (ip_prefix_version (ippref) == IP4)
5545 else if (ip_prefix_version (ippref) == IP6)
5558 send_lisp_eid_table_details (mapping_t * mapit,
5559 unix_shared_memory_queue_t * q,
5560 u32 context, u8 filter)
5563 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5564 locator_set_t *ls = 0;
5565 vl_api_lisp_eid_table_details_t *rmp = NULL;
5566 gid_address_t *gid = NULL;
5568 ip_prefix_t *ip_prefix = NULL;
5572 case 0: /* all mappings */
5575 case 1: /* local only */
5579 case 2: /* remote only */
5584 clib_warning ("Filter error, unknown filter: %d", filter);
5589 ip_prefix = &gid_address_ippref (gid);
5590 mac = gid_address_mac (gid);
5592 rmp = vl_msg_api_alloc (sizeof (*rmp));
5593 memset (rmp, 0, sizeof (*rmp));
5594 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5596 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5597 if (vec_len (ls->locator_indices) == 0)
5598 rmp->locator_set_index = ~0;
5600 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5602 rmp->is_local = mapit->local;
5603 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5604 rmp->action = mapit->action;
5605 rmp->authoritative = mapit->authoritative;
5607 switch (gid_address_type (gid))
5609 case GID_ADDR_SRC_DST:
5610 rmp->is_src_dst = 1;
5611 fid = &gid_address_sd_src (gid);
5612 rmp->eid_type = fid_type_to_api_type (fid);
5613 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
5614 &rmp->seid_prefix_len);
5615 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
5616 &rmp->eid_prefix_len);
5618 case GID_ADDR_IP_PREFIX:
5619 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5620 if (ip_prefix_version (ip_prefix) == IP4)
5622 rmp->eid_type = 0; /* ipv4 type */
5623 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5624 sizeof (ip_prefix_v4 (ip_prefix)));
5628 rmp->eid_type = 1; /* ipv6 type */
5629 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5630 sizeof (ip_prefix_v6 (ip_prefix)));
5634 rmp->eid_type = 2; /* l2 mac type */
5635 clib_memcpy (rmp->eid, mac, 6);
5640 rmp->context = context;
5641 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5642 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5646 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5649 unix_shared_memory_queue_t *q = NULL;
5650 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5651 mapping_t *mapit = NULL;
5652 gid_address_t _eid, *eid = &_eid;
5654 q = vl_api_client_index_to_input_queue (mp->client_index);
5662 memset (eid, 0, sizeof (*eid));
5664 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5665 mp->eid_type, mp->eid, mp->prefix_length);
5667 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5668 if ((u32) ~ 0 == mi)
5671 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5672 send_lisp_eid_table_details (mapit, q, mp->context,
5673 0 /* ignore filter */ );
5678 pool_foreach (mapit, lcm->mapping_pool,
5680 send_lisp_eid_table_details(mapit, q, mp->context,
5688 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5689 unix_shared_memory_queue_t * q, u32 context)
5691 vl_api_lisp_gpe_tunnel_details_t *rmp;
5692 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5694 rmp = vl_msg_api_alloc (sizeof (*rmp));
5695 memset (rmp, 0, sizeof (*rmp));
5696 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5698 rmp->tunnels = tunnel - lgm->tunnels;
5700 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5701 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5702 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5704 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5705 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5706 rmp->dcap_next = htonl (tunnel->decap_next_index);
5707 rmp->lisp_ver = tunnel->ver_res;
5708 rmp->next_protocol = tunnel->next_protocol;
5709 rmp->flags = tunnel->flags;
5710 rmp->ver_res = tunnel->ver_res;
5711 rmp->res = tunnel->res;
5712 rmp->iid = htonl (tunnel->vni);
5713 rmp->context = context;
5715 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5719 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5721 unix_shared_memory_queue_t *q = NULL;
5722 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5723 lisp_gpe_tunnel_t *tunnel = NULL;
5725 if (pool_elts (lgm->tunnels) == 0)
5730 q = vl_api_client_index_to_input_queue (mp->client_index);
5737 pool_foreach(tunnel, lgm->tunnels,
5739 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5745 send_lisp_map_resolver_details (ip_address_t * ip,
5746 unix_shared_memory_queue_t * q, u32 context)
5748 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5750 rmp = vl_msg_api_alloc (sizeof (*rmp));
5751 memset (rmp, 0, sizeof (*rmp));
5752 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5754 switch (ip_addr_version (ip))
5758 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5759 sizeof (ip_addr_v4 (ip)));
5764 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5765 sizeof (ip_addr_v6 (ip)));
5771 rmp->context = context;
5773 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5777 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5779 unix_shared_memory_queue_t *q = NULL;
5780 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5783 q = vl_api_client_index_to_input_queue (mp->client_index);
5789 vec_foreach (mr, lcm->map_resolvers)
5791 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5796 send_eid_table_map_pair (hash_pair_t * p,
5797 unix_shared_memory_queue_t * q, u32 context)
5799 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5801 rmp = vl_msg_api_alloc (sizeof (*rmp));
5802 memset (rmp, 0, sizeof (*rmp));
5803 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5805 rmp->vni = clib_host_to_net_u32 (p->key);
5806 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5807 rmp->context = context;
5808 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5812 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5815 unix_shared_memory_queue_t *q = NULL;
5816 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5818 uword *vni_table = 0;
5820 q = vl_api_client_index_to_input_queue (mp->client_index);
5828 vni_table = lcm->bd_id_by_vni;
5832 vni_table = lcm->table_id_by_vni;
5836 hash_foreach_pair (p, vni_table,
5838 send_eid_table_map_pair (p, q, mp->context);
5844 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
5846 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
5848 rmp = vl_msg_api_alloc (sizeof (*rmp));
5849 memset (rmp, 0, sizeof (*rmp));
5850 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
5851 rmp->context = context;
5852 rmp->vni = clib_host_to_net_u32 (vni);
5853 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5857 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
5862 unix_shared_memory_queue_t *q = 0;
5863 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5865 q = vl_api_client_index_to_input_queue (mp->client_index);
5872 hash_foreach_pair (p, lcm->table_id_by_vni,
5874 hash_set (vnis, p->key, 0);
5877 hash_foreach_pair (p, lcm->bd_id_by_vni,
5879 hash_set (vnis, p->key, 0);
5882 hash_foreach_pair (p, vnis,
5884 send_eid_table_vni (p->key, q, mp->context);
5892 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
5894 unix_shared_memory_queue_t *q = NULL;
5895 vl_api_show_lisp_status_reply_t *rmp = NULL;
5898 q = vl_api_client_index_to_input_queue (mp->client_index);
5905 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5907 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5908 rmp->feature_status = vnet_lisp_enable_disable_status ();
5914 vl_api_lisp_get_map_request_itr_rlocs_t_handler
5915 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
5917 unix_shared_memory_queue_t *q = NULL;
5918 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5919 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5920 locator_set_t *loc_set = 0;
5924 q = vl_api_client_index_to_input_queue (mp->client_index);
5930 if (~0 == lcm->mreq_itr_rlocs)
5932 tmp_str = format (0, " ");
5937 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5938 tmp_str = format (0, "%s", loc_set->name);
5942 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5944 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5945 ARRAY_LEN(rmp->locator_set_name) - 1);
5953 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5955 unix_shared_memory_queue_t *q = NULL;
5956 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
5957 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5959 locator_set_t *ls = 0;
5963 q = vl_api_client_index_to_input_queue (mp->client_index);
5969 if (!lcm->lisp_pitr)
5971 tmp_str = format (0, "N/A");
5975 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5976 if (~0 != m->locator_set_index)
5979 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5980 tmp_str = format (0, "%s", ls->name);
5984 tmp_str = format (0, "N/A");
5987 vec_add1 (tmp_str, 0);
5990 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5992 rmp->status = lcm->lisp_pitr;
5993 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5994 ARRAY_LEN(rmp->locator_set_name) - 1);
6000 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6003 vl_api_interface_name_renumber_reply_t *rmp;
6006 VALIDATE_SW_IF_INDEX (mp);
6008 rv = vnet_interface_name_renumber
6009 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6011 BAD_SW_IF_INDEX_LABEL;
6013 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6017 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6018 u32 sw_if_index, u32 address)
6020 vpe_api_main_t *am = &vpe_api_main;
6021 vlib_main_t *vm = am->vlib_main;
6022 vl_api_ip4_arp_event_t *event;
6023 static f64 arp_event_last_time;
6024 f64 now = vlib_time_now (vm);
6026 if (pool_is_free_index (am->arp_events, pool_index))
6029 event = pool_elt_at_index (am->arp_events, pool_index);
6031 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6033 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6037 if (sw_if_index == event->sw_if_index &&
6039 /* for BD case, also check IP address with 10 sec timeout */
6040 (address == event->address &&
6041 (now - arp_event_last_time) < 10.0)))
6046 arp_event_last_time = now;
6047 event->sw_if_index = sw_if_index;
6049 event->address = address;
6054 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6055 u32 sw_if_index, ip6_address_t * address)
6057 vpe_api_main_t *am = &vpe_api_main;
6058 vlib_main_t *vm = am->vlib_main;
6059 vl_api_ip6_nd_event_t *event;
6060 static f64 nd_event_last_time;
6061 f64 now = vlib_time_now (vm);
6063 if (pool_is_free_index (am->nd_events, pool_index))
6066 event = pool_elt_at_index (am->nd_events, pool_index);
6069 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6071 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6075 if (sw_if_index == event->sw_if_index &&
6077 /* for BD case, also check IP address with 10 sec timeout */
6078 (ip6_address_is_equal (address,
6079 (ip6_address_t *) event->address) &&
6080 (now - nd_event_last_time) < 10.0)))
6085 nd_event_last_time = now;
6086 event->sw_if_index = sw_if_index;
6088 clib_memcpy (event->address, address, sizeof (event->address));
6093 arp_change_delete_callback (u32 pool_index, u8 * notused)
6095 vpe_api_main_t *am = &vpe_api_main;
6097 if (pool_is_free_index (am->arp_events, pool_index))
6100 pool_put_index (am->arp_events, pool_index);
6105 nd_change_delete_callback (u32 pool_index, u8 * notused)
6107 vpe_api_main_t *am = &vpe_api_main;
6109 if (pool_is_free_index (am->nd_events, pool_index))
6112 pool_put_index (am->nd_events, pool_index);
6117 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6119 vpe_api_main_t *am = &vpe_api_main;
6120 vnet_main_t *vnm = vnet_get_main ();
6121 vl_api_want_ip4_arp_events_reply_t *rmp;
6122 vl_api_ip4_arp_event_t *event;
6125 if (mp->enable_disable)
6127 pool_get (am->arp_events, event);
6128 memset (event, 0, sizeof (*event));
6130 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6131 event->client_index = mp->client_index;
6132 event->context = mp->context;
6133 event->address = mp->address;
6134 event->pid = mp->pid;
6135 if (mp->address == 0)
6138 rv = vnet_add_del_ip4_arp_change_event
6139 (vnm, arp_change_data_callback,
6140 mp->pid, &mp->address /* addr, in net byte order */ ,
6141 vpe_resolver_process_node.index,
6142 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6146 rv = vnet_add_del_ip4_arp_change_event
6147 (vnm, arp_change_delete_callback,
6148 mp->pid, &mp->address /* addr, in net byte order */ ,
6149 vpe_resolver_process_node.index,
6150 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6152 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6156 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6158 vpe_api_main_t *am = &vpe_api_main;
6159 vnet_main_t *vnm = vnet_get_main ();
6160 vl_api_want_ip6_nd_events_reply_t *rmp;
6161 vl_api_ip6_nd_event_t *event;
6164 if (mp->enable_disable)
6166 pool_get (am->nd_events, event);
6167 memset (event, 0, sizeof (*event));
6169 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6170 event->client_index = mp->client_index;
6171 event->context = mp->context;
6172 clib_memcpy (event->address, mp->address, 16);
6173 event->pid = mp->pid;
6174 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6177 rv = vnet_add_del_ip6_nd_change_event
6178 (vnm, nd_change_data_callback,
6179 mp->pid, mp->address /* addr, in net byte order */ ,
6180 vpe_resolver_process_node.index,
6181 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6185 rv = vnet_add_del_ip6_nd_change_event
6186 (vnm, nd_change_delete_callback,
6187 mp->pid, mp->address /* addr, in net byte order */ ,
6188 vpe_resolver_process_node.index,
6189 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6191 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6194 static void vl_api_input_acl_set_interface_t_handler
6195 (vl_api_input_acl_set_interface_t * mp)
6197 vlib_main_t *vm = vlib_get_main ();
6198 vl_api_input_acl_set_interface_reply_t *rmp;
6200 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6202 ip4_table_index = ntohl (mp->ip4_table_index);
6203 ip6_table_index = ntohl (mp->ip6_table_index);
6204 l2_table_index = ntohl (mp->l2_table_index);
6205 sw_if_index = ntohl (mp->sw_if_index);
6207 VALIDATE_SW_IF_INDEX (mp);
6209 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6210 ip6_table_index, l2_table_index, mp->is_add);
6212 BAD_SW_IF_INDEX_LABEL;
6214 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6217 static void vl_api_ipsec_spd_add_del_t_handler
6218 (vl_api_ipsec_spd_add_del_t * mp)
6221 clib_warning ("unimplemented");
6224 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6225 vl_api_ipsec_spd_add_del_reply_t *rmp;
6229 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6231 rv = VNET_API_ERROR_UNIMPLEMENTED;
6234 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6238 static void vl_api_ipsec_interface_add_del_spd_t_handler
6239 (vl_api_ipsec_interface_add_del_spd_t * mp)
6241 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6242 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6244 u32 sw_if_index __attribute__ ((unused));
6245 u32 spd_id __attribute__ ((unused));
6247 sw_if_index = ntohl (mp->sw_if_index);
6248 spd_id = ntohl (mp->spd_id);
6250 VALIDATE_SW_IF_INDEX (mp);
6253 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6255 rv = VNET_API_ERROR_UNIMPLEMENTED;
6258 BAD_SW_IF_INDEX_LABEL;
6260 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6263 static void vl_api_ipsec_spd_add_del_entry_t_handler
6264 (vl_api_ipsec_spd_add_del_entry_t * mp)
6266 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6267 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6273 memset (&p, 0, sizeof (p));
6275 p.id = ntohl (mp->spd_id);
6276 p.priority = ntohl (mp->priority);
6277 p.is_outbound = mp->is_outbound;
6278 p.is_ipv6 = mp->is_ipv6;
6280 if (mp->is_ipv6 || mp->is_ip_any)
6282 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6283 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6284 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6285 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6289 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6290 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6291 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6292 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6294 p.protocol = mp->protocol;
6295 p.rport.start = ntohs (mp->remote_port_start);
6296 p.rport.stop = ntohs (mp->remote_port_stop);
6297 p.lport.start = ntohs (mp->local_port_start);
6298 p.lport.stop = ntohs (mp->local_port_stop);
6299 /* policy action resolve unsupported */
6300 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6302 clib_warning ("unsupported action: 'resolve'");
6303 rv = VNET_API_ERROR_UNIMPLEMENTED;
6306 p.policy = mp->policy;
6307 p.sa_id = ntohl (mp->sa_id);
6309 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6316 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6319 rv = VNET_API_ERROR_UNIMPLEMENTED;
6324 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6327 static void vl_api_ipsec_sad_add_del_entry_t_handler
6328 (vl_api_ipsec_sad_add_del_entry_t * mp)
6330 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6331 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6336 memset (&sa, 0, sizeof (sa));
6338 sa.id = ntohl (mp->sad_id);
6339 sa.spi = ntohl (mp->spi);
6340 /* security protocol AH unsupported */
6341 if (mp->protocol == IPSEC_PROTOCOL_AH)
6343 clib_warning ("unsupported security protocol 'AH'");
6344 rv = VNET_API_ERROR_UNIMPLEMENTED;
6347 sa.protocol = mp->protocol;
6348 /* check for unsupported crypto-alg */
6349 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6350 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6352 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6353 mp->crypto_algorithm);
6354 rv = VNET_API_ERROR_UNIMPLEMENTED;
6357 sa.crypto_alg = mp->crypto_algorithm;
6358 sa.crypto_key_len = mp->crypto_key_length;
6359 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6360 /* check for unsupported integ-alg */
6361 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6362 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6364 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6365 mp->integrity_algorithm);
6366 rv = VNET_API_ERROR_UNIMPLEMENTED;
6369 sa.integ_alg = mp->integrity_algorithm;
6370 sa.integ_key_len = mp->integrity_key_length;
6371 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6372 sa.use_esn = mp->use_extended_sequence_number;
6373 sa.is_tunnel = mp->is_tunnel;
6374 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6375 if (sa.is_tunnel_ip6)
6377 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6378 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6382 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6383 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6386 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6388 rv = VNET_API_ERROR_UNIMPLEMENTED;
6393 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6397 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6399 vl_api_ikev2_profile_add_del_reply_t *rmp;
6403 vlib_main_t *vm = vlib_get_main ();
6404 clib_error_t *error;
6405 u8 *tmp = format (0, "%s", mp->name);
6406 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6409 rv = VNET_API_ERROR_UNSPECIFIED;
6411 rv = VNET_API_ERROR_UNIMPLEMENTED;
6414 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6418 vl_api_ikev2_profile_set_auth_t_handler
6419 (vl_api_ikev2_profile_set_auth_t * mp)
6421 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6425 vlib_main_t *vm = vlib_get_main ();
6426 clib_error_t *error;
6427 u8 *tmp = format (0, "%s", mp->name);
6428 u8 *data = vec_new (u8, mp->data_len);
6429 clib_memcpy (data, mp->data, mp->data_len);
6430 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6434 rv = VNET_API_ERROR_UNSPECIFIED;
6436 rv = VNET_API_ERROR_UNIMPLEMENTED;
6439 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6443 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6445 vl_api_ikev2_profile_add_del_reply_t *rmp;
6449 vlib_main_t *vm = vlib_get_main ();
6450 clib_error_t *error;
6451 u8 *tmp = format (0, "%s", mp->name);
6452 u8 *data = vec_new (u8, mp->data_len);
6453 clib_memcpy (data, mp->data, mp->data_len);
6454 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6458 rv = VNET_API_ERROR_UNSPECIFIED;
6460 rv = VNET_API_ERROR_UNIMPLEMENTED;
6463 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6467 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6469 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6473 vlib_main_t *vm = vlib_get_main ();
6474 clib_error_t *error;
6475 u8 *tmp = format (0, "%s", mp->name);
6476 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6477 mp->end_port, (ip4_address_t) mp->start_addr,
6478 (ip4_address_t) mp->end_addr, mp->is_local);
6481 rv = VNET_API_ERROR_UNSPECIFIED;
6483 rv = VNET_API_ERROR_UNIMPLEMENTED;
6486 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6490 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6492 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6496 vlib_main_t *vm = vlib_get_main ();
6497 clib_error_t *error;
6499 error = ikev2_set_local_key (vm, mp->key_file);
6501 rv = VNET_API_ERROR_UNSPECIFIED;
6503 rv = VNET_API_ERROR_UNIMPLEMENTED;
6506 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6510 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6512 vl_api_map_add_domain_reply_t *rmp;
6515 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6517 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6518 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6519 (ip6_address_t *) & mp->ip6_src,
6520 mp->ip6_src_prefix_len, mp->ea_bits_len,
6521 mp->psid_offset, mp->psid_length, &index,
6522 ntohs (mp->mtu), flags);
6525 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6527 rmp->index = ntohl(index);
6533 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6535 vl_api_map_del_domain_reply_t *rmp;
6538 rv = map_delete_domain (ntohl (mp->index));
6540 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6544 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6546 vl_api_map_del_domain_reply_t *rmp;
6550 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6551 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6553 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6557 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6559 vl_api_map_domain_details_t *rmp;
6560 map_main_t *mm = &map_main;
6562 unix_shared_memory_queue_t *q;
6564 if (pool_elts (mm->domains) == 0)
6567 q = vl_api_client_index_to_input_queue (mp->client_index);
6574 pool_foreach(d, mm->domains,
6576 /* Make sure every field is initiated (or don't skip the memset()) */
6577 rmp = vl_msg_api_alloc (sizeof (*rmp));
6578 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6579 rmp->domain_index = htonl(d - mm->domains);
6580 rmp->ea_bits_len = d->ea_bits_len;
6581 rmp->psid_offset = d->psid_offset;
6582 rmp->psid_length = d->psid_length;
6583 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6584 rmp->ip4_prefix_len = d->ip4_prefix_len;
6585 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6586 rmp->ip6_prefix_len = d->ip6_prefix_len;
6587 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6588 rmp->ip6_src_len = d->ip6_src_len;
6589 rmp->mtu = htons(d->mtu);
6590 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6591 rmp->context = mp->context;
6593 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6599 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6601 unix_shared_memory_queue_t *q;
6604 vl_api_map_rule_details_t *rmp;
6605 map_main_t *mm = &map_main;
6606 u32 domain_index = ntohl (mp->domain_index);
6609 if (pool_elts (mm->domains) == 0)
6612 d = pool_elt_at_index (mm->domains, domain_index);
6613 if (!d || !d->rules)
6618 q = vl_api_client_index_to_input_queue (mp->client_index);
6624 for (i = 0; i < (0x1 << d->psid_length); i++)
6627 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6631 rmp = vl_msg_api_alloc (sizeof (*rmp));
6632 memset (rmp, 0, sizeof (*rmp));
6633 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6634 rmp->psid = htons (i);
6635 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6636 rmp->context = mp->context;
6637 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6642 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6644 vl_api_map_summary_stats_reply_t *rmp;
6645 vlib_combined_counter_main_t *cm;
6648 u64 total_pkts[VLIB_N_RX_TX];
6649 u64 total_bytes[VLIB_N_RX_TX];
6650 map_main_t *mm = &map_main;
6651 unix_shared_memory_queue_t *q =
6652 vl_api_client_index_to_input_queue (mp->client_index);
6657 rmp = vl_msg_api_alloc (sizeof (*rmp));
6658 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6659 rmp->context = mp->context;
6662 memset (total_pkts, 0, sizeof (total_pkts));
6663 memset (total_bytes, 0, sizeof (total_bytes));
6665 map_domain_counter_lock (mm);
6666 vec_foreach (cm, mm->domain_counters)
6668 which = cm - mm->domain_counters;
6670 for (i = 0; i < vec_len (cm->maxi); i++)
6672 vlib_get_combined_counter (cm, i, &v);
6673 total_pkts[which] += v.packets;
6674 total_bytes[which] += v.bytes;
6678 map_domain_counter_unlock (mm);
6680 /* Note: in network byte order! */
6681 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6682 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6683 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6684 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6685 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6686 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6687 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6688 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6689 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6690 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6691 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6692 clib_host_to_net_u64 (map_error_counter_get
6693 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6694 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6695 clib_host_to_net_u64 (map_error_counter_get
6696 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6698 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6702 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6704 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6705 vl_api_ipsec_sa_set_key_reply_t *rmp;
6709 sa.id = ntohl (mp->sa_id);
6710 sa.crypto_key_len = mp->crypto_key_length;
6711 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6712 sa.integ_key_len = mp->integrity_key_length;
6713 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6715 rv = ipsec_set_sa_key (vm, &sa);
6717 rv = VNET_API_ERROR_UNIMPLEMENTED;
6720 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6723 static void vl_api_cop_interface_enable_disable_t_handler
6724 (vl_api_cop_interface_enable_disable_t * mp)
6726 vl_api_cop_interface_enable_disable_reply_t *rmp;
6728 u32 sw_if_index = ntohl (mp->sw_if_index);
6731 VALIDATE_SW_IF_INDEX (mp);
6733 enable_disable = (int) mp->enable_disable;
6735 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6737 BAD_SW_IF_INDEX_LABEL;
6739 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6742 static void vl_api_cop_whitelist_enable_disable_t_handler
6743 (vl_api_cop_whitelist_enable_disable_t * mp)
6745 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6746 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6747 u32 sw_if_index = ntohl (mp->sw_if_index);
6750 VALIDATE_SW_IF_INDEX (mp);
6752 a->sw_if_index = sw_if_index;
6755 a->default_cop = mp->default_cop;
6756 a->fib_id = ntohl (mp->fib_id);
6758 rv = cop_whitelist_enable_disable (a);
6760 BAD_SW_IF_INDEX_LABEL;
6762 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6766 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6770 api_main_t *am = &api_main;
6771 vlib_main_t *vm = vlib_get_main ();
6773 vl_api_get_node_graph_reply_t *rmp;
6775 pthread_mutex_lock (&am->vlib_rp->mutex);
6776 oldheap = svm_push_data_heap (am->vlib_rp);
6779 * Keep the number of memcpy ops to a minimum (e.g. 1).
6781 vec_validate (vector, 16384);
6782 vec_reset_length (vector);
6785 vector = vlib_node_serialize (&vm->node_main, vector,
6786 (u32) ~ 0 /* all threads */ ,
6787 1 /* include nexts */ ,
6788 1 /* include stats */ );
6790 svm_pop_heap (oldheap);
6791 pthread_mutex_unlock (&am->vlib_rp->mutex);
6794 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6796 rmp->reply_in_shmem = (uword) vector;
6802 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
6805 vl_api_ioam_enable_reply_t *rmp;
6806 clib_error_t *error;
6808 /* Ignoring the profile id as currently a single profile
6810 error = ip6_ioam_enable (mp->trace_enable, mp->pow_enable, mp->trace_ppc);
6813 clib_error_report (error);
6814 rv = clib_error_get_code (error);
6817 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
6821 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
6824 vl_api_ioam_disable_reply_t *rmp;
6825 clib_error_t *error;
6827 error = clear_ioam_rewrite_fn ();
6830 clib_error_report (error);
6831 rv = clib_error_get_code (error);
6834 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
6838 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6840 vlib_main_t *vm = vlib_get_main ();
6841 vl_api_af_packet_create_reply_t *rmp;
6843 u8 *host_if_name = NULL;
6846 host_if_name = format (0, "%s", mp->host_if_name);
6847 vec_add1 (host_if_name, 0);
6849 rv = af_packet_create_if (vm, host_if_name,
6850 mp->use_random_hw_addr ? 0 : mp->hw_addr,
6853 vec_free (host_if_name);
6856 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6858 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
6864 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
6866 vlib_main_t *vm = vlib_get_main ();
6867 vl_api_af_packet_delete_reply_t *rmp;
6869 u8 *host_if_name = NULL;
6871 host_if_name = format (0, "%s", mp->host_if_name);
6872 vec_add1 (host_if_name, 0);
6874 rv = af_packet_delete_if (vm, host_if_name);
6876 vec_free (host_if_name);
6878 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
6882 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
6884 vlib_main_t *vm = vlib_get_main ();
6885 vl_api_policer_add_del_reply_t *rmp;
6888 sse2_qos_pol_cfg_params_st cfg;
6889 clib_error_t *error;
6892 name = format (0, "%s", mp->name);
6894 memset (&cfg, 0, sizeof (cfg));
6896 cfg.rnd_type = mp->round_type;
6897 cfg.rate_type = mp->rate_type;
6898 cfg.rb.kbps.cir_kbps = mp->cir;
6899 cfg.rb.kbps.eir_kbps = mp->eir;
6900 cfg.rb.kbps.cb_bytes = mp->cb;
6901 cfg.rb.kbps.eb_bytes = mp->eb;
6902 cfg.conform_action.action_type = mp->conform_action_type;
6903 cfg.conform_action.dscp = mp->conform_dscp;
6904 cfg.exceed_action.action_type = mp->exceed_action_type;
6905 cfg.exceed_action.dscp = mp->exceed_dscp;
6906 cfg.violate_action.action_type = mp->violate_action_type;
6907 cfg.violate_action.dscp = mp->violate_dscp;
6908 cfg.color_aware = mp->color_aware;
6910 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
6913 rv = VNET_API_ERROR_UNSPECIFIED;
6916 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6918 if (rv == 0 && mp->is_add)
6919 rmp->policer_index = ntohl(policer_index);
6921 rmp->policer_index = ~0;
6927 send_policer_details (u8 * name,
6928 sse2_qos_pol_cfg_params_st * config,
6929 policer_read_response_type_st * templ,
6930 unix_shared_memory_queue_t * q, u32 context)
6932 vl_api_policer_details_t *mp;
6934 mp = vl_msg_api_alloc (sizeof (*mp));
6935 memset (mp, 0, sizeof (*mp));
6936 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6937 mp->context = context;
6938 mp->cir = htonl (config->rb.kbps.cir_kbps);
6939 mp->eir = htonl (config->rb.kbps.eir_kbps);
6940 mp->cb = htonl (config->rb.kbps.cb_bytes);
6941 mp->eb = htonl (config->rb.kbps.eb_bytes);
6942 mp->rate_type = config->rate_type;
6943 mp->round_type = config->rnd_type;
6944 mp->type = config->rfc;
6945 mp->conform_action_type = config->conform_action.action_type;
6946 mp->conform_dscp = config->conform_action.dscp;
6947 mp->exceed_action_type = config->exceed_action.action_type;
6948 mp->exceed_dscp = config->exceed_action.dscp;
6949 mp->violate_action_type = config->violate_action.action_type;
6950 mp->violate_dscp = config->violate_action.dscp;
6951 mp->single_rate = templ->single_rate ? 1 : 0;
6952 mp->color_aware = templ->color_aware ? 1 : 0;
6953 mp->scale = htonl (templ->scale);
6954 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
6955 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
6956 mp->current_limit = htonl (templ->current_limit);
6957 mp->current_bucket = htonl (templ->current_bucket);
6958 mp->extended_limit = htonl (templ->extended_limit);
6959 mp->extended_bucket = htonl (templ->extended_bucket);
6960 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
6962 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
6964 vl_msg_api_send_shmem (q, (u8 *) & mp);
6968 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
6970 unix_shared_memory_queue_t *q;
6971 vnet_policer_main_t *pm = &vnet_policer_main;
6977 sse2_qos_pol_cfg_params_st *config;
6978 policer_read_response_type_st *templ;
6980 q = vl_api_client_index_to_input_queue (mp->client_index);
6984 if (mp->match_name_valid)
6986 match_name = format (0, "%s%c", mp->match_name, 0);
6989 if (mp->match_name_valid)
6991 p = hash_get_mem (pm->policer_config_by_name, match_name);
6995 config = pool_elt_at_index (pm->configs, pool_index);
6996 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6997 send_policer_details (match_name, config, templ, q, mp->context);
7003 hash_foreach_pair (hp, pm->policer_config_by_name,
7005 name = (u8 *) hp->key;
7006 pool_index = hp->value[0];
7007 config = pool_elt_at_index (pm->configs, pool_index);
7008 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7009 send_policer_details(name, config, templ, q, mp->context);
7016 vl_api_policer_classify_set_interface_t_handler
7017 (vl_api_policer_classify_set_interface_t * mp)
7019 vlib_main_t *vm = vlib_get_main ();
7020 vl_api_policer_classify_set_interface_reply_t *rmp;
7022 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7024 ip4_table_index = ntohl (mp->ip4_table_index);
7025 ip6_table_index = ntohl (mp->ip6_table_index);
7026 l2_table_index = ntohl (mp->l2_table_index);
7027 sw_if_index = ntohl (mp->sw_if_index);
7029 VALIDATE_SW_IF_INDEX (mp);
7031 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7032 ip6_table_index, l2_table_index,
7035 BAD_SW_IF_INDEX_LABEL;
7037 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7041 send_policer_classify_details (u32 sw_if_index,
7043 unix_shared_memory_queue_t * q, u32 context)
7045 vl_api_policer_classify_details_t *mp;
7047 mp = vl_msg_api_alloc (sizeof (*mp));
7048 memset (mp, 0, sizeof (*mp));
7049 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7050 mp->context = context;
7051 mp->sw_if_index = htonl (sw_if_index);
7052 mp->table_index = htonl (table_index);
7054 vl_msg_api_send_shmem (q, (u8 *) & mp);
7058 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7060 unix_shared_memory_queue_t *q;
7061 policer_classify_main_t *pcm = &policer_classify_main;
7065 q = vl_api_client_index_to_input_queue (mp->client_index);
7069 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7071 if (vec_len (vec_tbl))
7073 for (i = 0; i < vec_len (vec_tbl); i++)
7075 if (vec_elt (vec_tbl, i) == ~0)
7078 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7085 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7087 vlib_main_t *vm = vlib_get_main ();
7088 vl_api_netmap_create_reply_t *rmp;
7092 if_name = format (0, "%s", mp->netmap_if_name);
7093 vec_add1 (if_name, 0);
7096 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7097 mp->is_pipe, mp->is_master, 0);
7101 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7105 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7107 vlib_main_t *vm = vlib_get_main ();
7108 vl_api_netmap_delete_reply_t *rmp;
7112 if_name = format (0, "%s", mp->netmap_if_name);
7113 vec_add1 (if_name, 0);
7115 rv = netmap_delete_if (vm, if_name);
7119 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7123 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7126 clib_warning ("BUG");
7130 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7131 unix_shared_memory_queue_t * q,
7132 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7134 vl_api_mpls_gre_tunnel_details_t *mp;
7135 mpls_main_t *mm = &mpls_main;
7140 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7141 nlabels = vec_len (e->labels);
7143 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7144 memset (mp, 0, sizeof (*mp));
7145 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7146 mp->context = context;
7148 mp->tunnel_index = htonl (index);
7149 mp->tunnel_src = gt->tunnel_src.as_u32;
7150 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7151 mp->intfc_address = gt->intfc_address.as_u32;
7152 mp->mask_width = htonl (gt->mask_width);
7153 mp->inner_fib_index = htonl (gt->inner_fib_index);
7154 mp->outer_fib_index = htonl (gt->outer_fib_index);
7155 mp->encap_index = htonl (gt->encap_index);
7156 mp->hw_if_index = htonl (gt->hw_if_index);
7157 mp->l2_only = htonl (gt->l2_only);
7158 mp->nlabels = htonl (nlabels);
7160 for (i = 0; i < nlabels; i++)
7163 htonl (vnet_mpls_uc_get_label
7164 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7167 vl_msg_api_send_shmem (q, (u8 *) & mp);
7171 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7173 vpe_api_main_t *am = &vpe_api_main;
7174 unix_shared_memory_queue_t *q;
7175 mpls_main_t *mm = &mpls_main;
7176 mpls_gre_tunnel_t *gt;
7177 u32 index = ntohl (mp->tunnel_index);
7179 q = vl_api_client_index_to_input_queue (mp->client_index);
7185 if (!pool_is_free_index (mm->gre_tunnels, index))
7187 gt = pool_elt_at_index (mm->gre_tunnels, index);
7188 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7195 pool_foreach (gt, mm->gre_tunnels,
7197 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7205 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7208 clib_warning ("BUG");
7212 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7213 unix_shared_memory_queue_t * q,
7214 mpls_eth_tunnel_t * et, u32 index, u32 context)
7216 mpls_main_t *mm = &mpls_main;
7220 vl_api_mpls_eth_tunnel_details_t *mp;
7222 e = pool_elt_at_index (mm->encaps, et->encap_index);
7223 nlabels = vec_len (e->labels);
7225 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7226 memset (mp, 0, sizeof (*mp));
7227 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7228 mp->context = context;
7230 mp->tunnel_index = htonl (index);
7231 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7232 mp->intfc_address = et->intfc_address.as_u32;
7233 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7234 mp->inner_fib_index = htonl (et->inner_fib_index);
7235 mp->mask_width = htonl (et->mask_width);
7236 mp->encap_index = htonl (et->encap_index);
7237 mp->hw_if_index = htonl (et->hw_if_index);
7238 mp->l2_only = htonl (et->l2_only);
7239 mp->nlabels = htonl (nlabels);
7241 for (i = 0; i < nlabels; i++)
7244 htonl (vnet_mpls_uc_get_label
7245 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7248 vl_msg_api_send_shmem (q, (u8 *) & mp);
7252 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7254 vpe_api_main_t *am = &vpe_api_main;
7255 unix_shared_memory_queue_t *q;
7256 mpls_main_t *mm = &mpls_main;
7257 mpls_eth_tunnel_t *et;
7258 u32 index = ntohl (mp->tunnel_index);
7260 q = vl_api_client_index_to_input_queue (mp->client_index);
7266 if (!pool_is_free_index (mm->eth_tunnels, index))
7268 et = pool_elt_at_index (mm->eth_tunnels, index);
7269 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7276 pool_foreach (et, mm->eth_tunnels,
7278 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7286 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7288 clib_warning ("BUG");
7292 send_mpls_fib_encap_details (vpe_api_main_t * am,
7293 unix_shared_memory_queue_t * q,
7294 show_mpls_fib_t * s, u32 context)
7296 vl_api_mpls_fib_encap_details_t *mp;
7297 mpls_main_t *mm = &mpls_main;
7302 e = pool_elt_at_index (mm->encaps, s->entry_index);
7303 nlabels = vec_len (e->labels);
7305 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7306 memset (mp, 0, sizeof (*mp));
7307 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7308 mp->context = context;
7310 mp->fib_index = htonl (s->fib_index);
7311 mp->entry_index = htonl (s->entry_index);
7313 mp->s_bit = htonl (s->s_bit);
7315 mp->nlabels = htonl (nlabels);
7317 for (i = 0; i < nlabels; i++)
7320 htonl (vnet_mpls_uc_get_label
7321 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7324 vl_msg_api_send_shmem (q, (u8 *) & mp);
7328 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7330 vpe_api_main_t *am = &vpe_api_main;
7331 unix_shared_memory_queue_t *q;
7332 vlib_main_t *vm = &vlib_global_main;
7335 show_mpls_fib_t *records = 0;
7337 mpls_main_t *mm = &mpls_main;
7340 q = vl_api_client_index_to_input_queue (mp->client_index);
7345 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7347 vec_add2 (records, s, 1);
7348 s->fib_index = (u32)(key>>32);
7349 s->dest = (u32)(key & 0xFFFFFFFF);
7350 s->entry_index = (u32) value;
7354 if (0 == vec_len (records))
7356 vlib_cli_output (vm, "MPLS encap table empty");
7360 /* sort output by dst address within fib */
7361 vec_sort_with_function (records, mpls_dest_cmp);
7362 vec_sort_with_function (records, mpls_fib_index_cmp);
7363 vlib_cli_output (vm, "MPLS encap table");
7364 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7365 vec_foreach (s, records)
7367 rx_fib = ip4_fib_get (s->fib_index);
7368 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7369 format_ip4_address, &s->dest, format_mpls_encap_index,
7370 mm, s->entry_index);
7371 send_mpls_fib_encap_details (am, q, s, mp->context);
7379 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7381 clib_warning ("BUG");
7385 send_mpls_fib_decap_details (vpe_api_main_t * am,
7386 unix_shared_memory_queue_t * q,
7387 show_mpls_fib_t * s,
7389 u32 tx_table_id, char *swif_tag, u32 context)
7391 vl_api_mpls_fib_decap_details_t *mp;
7393 mp = vl_msg_api_alloc (sizeof (*mp));
7394 memset (mp, 0, sizeof (*mp));
7395 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7396 mp->context = context;
7398 mp->fib_index = htonl (s->fib_index);
7399 mp->entry_index = htonl (s->entry_index);
7401 mp->s_bit = htonl (s->s_bit);
7402 mp->label = htonl (s->label);
7403 mp->rx_table_id = htonl (rx_table_id);
7404 mp->tx_table_id = htonl (tx_table_id);
7405 strncpy ((char *) mp->swif_tag,
7406 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7408 vl_msg_api_send_shmem (q, (u8 *) & mp);
7412 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7414 vpe_api_main_t *am = &vpe_api_main;
7415 unix_shared_memory_queue_t *q;
7416 vlib_main_t *vm = &vlib_global_main;
7419 show_mpls_fib_t *records = 0;
7421 mpls_main_t *mm = &mpls_main;
7427 q = vl_api_client_index_to_input_queue (mp->client_index);
7432 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7434 vec_add2 (records, s, 1);
7435 s->fib_index = (u32)(key>>32);
7436 s->entry_index = (u32) value;
7437 s->label = ((u32) key)>>12;
7438 s->s_bit = (key & (1<<8)) != 0;
7442 if (!vec_len (records))
7444 vlib_cli_output (vm, "MPLS decap table empty");
7448 vec_sort_with_function (records, mpls_label_cmp);
7449 vlib_cli_output (vm, "MPLS decap table");
7450 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7452 vec_foreach (s, records)
7455 d = pool_elt_at_index (mm->decaps, s->entry_index);
7456 if (d->next_index == MPLS_LOOKUP_NEXT_IP4_INPUT)
7458 tx_fib = ip4_fib_get (d->tx_fib_index);
7459 tx_table_id = tx_fib->table_id;
7464 tx_table_id = d->tx_fib_index;
7467 rx_fib = ip4_fib_get (s->fib_index);
7469 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7470 tx_table_id, swif_tag, s->label, s->s_bit);
7472 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7473 tx_table_id, swif_tag, mp->context);
7481 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7483 unix_shared_memory_queue_t *q;
7485 q = vl_api_client_index_to_input_queue (mp->client_index);
7489 vnet_classify_main_t *cm = &vnet_classify_main;
7490 vnet_classify_table_t *t;
7495 pool_foreach (t, cm->tables,
7497 vec_add1 (table_ids, ntohl(t - cm->tables));
7500 count = vec_len (table_ids);
7502 vl_api_classify_table_ids_reply_t *rmp;
7503 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7504 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7505 rmp->context = mp->context;
7506 rmp->count = ntohl (count);
7507 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7510 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7512 vec_free (table_ids);
7516 vl_api_classify_table_by_interface_t_handler
7517 (vl_api_classify_table_by_interface_t * mp)
7519 vl_api_classify_table_by_interface_reply_t *rmp;
7522 u32 sw_if_index = ntohl (mp->sw_if_index);
7525 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7528 VALIDATE_SW_IF_INDEX (mp);
7530 input_acl_main_t *am = &input_acl_main;
7535 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7537 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7538 if (vec_len (vec_tbl))
7540 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7542 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7546 acl[type] = vec_elt (vec_tbl, if_idx);
7551 BAD_SW_IF_INDEX_LABEL;
7554 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7556 rmp->sw_if_index = ntohl(sw_if_index);
7557 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7558 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7559 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7566 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7568 unix_shared_memory_queue_t *q;
7570 q = vl_api_client_index_to_input_queue (mp->client_index);
7574 vl_api_classify_table_info_reply_t *rmp = 0;
7576 vnet_classify_main_t *cm = &vnet_classify_main;
7577 u32 table_id = ntohl (mp->table_id);
7578 vnet_classify_table_t *t;
7581 pool_foreach (t, cm->tables,
7583 if (table_id == t - cm->tables)
7585 rmp = vl_msg_api_alloc_as_if_client
7586 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7587 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7588 rmp->context = mp->context;
7589 rmp->table_id = ntohl(table_id);
7590 rmp->nbuckets = ntohl(t->nbuckets);
7591 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7592 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7593 rmp->active_sessions = ntohl(t->active_elements);
7594 rmp->next_table_index = ntohl(t->next_table_index);
7595 rmp->miss_next_index = ntohl(t->miss_next_index);
7596 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7597 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7606 rmp = vl_msg_api_alloc (sizeof (*rmp));
7607 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7608 rmp->context = mp->context;
7609 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7612 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7616 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7619 clib_warning ("BUG");
7623 send_classify_session_details (unix_shared_memory_queue_t * q,
7626 vnet_classify_entry_t * e, u32 context)
7628 vl_api_classify_session_details_t *rmp;
7630 rmp = vl_msg_api_alloc (sizeof (*rmp));
7631 memset (rmp, 0, sizeof (*rmp));
7632 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7633 rmp->context = context;
7634 rmp->table_id = ntohl (table_id);
7635 rmp->hit_next_index = ntohl (e->next_index);
7636 rmp->advance = ntohl (e->advance);
7637 rmp->opaque_index = ntohl (e->opaque_index);
7638 rmp->match_length = ntohl (match_length);
7639 clib_memcpy (rmp->match, e->key, match_length);
7641 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7645 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7647 vnet_classify_main_t *cm = &vnet_classify_main;
7648 unix_shared_memory_queue_t *q;
7650 u32 table_id = ntohl (mp->table_id);
7651 vnet_classify_table_t *t;
7653 q = vl_api_client_index_to_input_queue (mp->client_index);
7658 pool_foreach (t, cm->tables,
7660 if (table_id == t - cm->tables)
7662 vnet_classify_bucket_t * b;
7663 vnet_classify_entry_t * v, * save_v;
7666 for (i = 0; i < t->nbuckets; i++)
7668 b = &t->buckets [i];
7672 save_v = vnet_classify_get_entry (t, b->offset);
7673 for (j = 0; j < (1<<b->log2_pages); j++)
7675 for (k = 0; k < t->entries_per_page; k++)
7677 v = vnet_classify_entry_at_index
7678 (t, save_v, j*t->entries_per_page + k);
7679 if (vnet_classify_entry_is_free (v))
7682 send_classify_session_details
7683 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7695 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7697 vlib_main_t *vm = vlib_get_main ();
7698 flow_report_main_t *frm = &flow_report_main;
7699 vl_api_set_ipfix_exporter_reply_t *rmp;
7700 ip4_address_t collector, src;
7701 u16 collector_port = UDP_DST_PORT_ipfix;
7703 u32 template_interval;
7709 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7710 collector_port = ntohs (mp->collector_port);
7711 if (collector_port == (u16) ~ 0)
7712 collector_port = UDP_DST_PORT_ipfix;
7713 memcpy (src.data, mp->src_address, sizeof (src.data));
7714 fib_id = ntohl (mp->vrf_id);
7716 ip4_main_t *im = &ip4_main;
7723 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7726 rv = VNET_API_ERROR_NO_SUCH_FIB;
7732 path_mtu = ntohl (mp->path_mtu);
7734 path_mtu = 512; // RFC 7011 section 10.3.3.
7735 template_interval = ntohl (mp->template_interval);
7736 if (template_interval == ~0)
7737 template_interval = 20;
7738 udp_checksum = mp->udp_checksum;
7740 if (collector.as_u32 == 0)
7742 rv = VNET_API_ERROR_INVALID_VALUE;
7746 if (src.as_u32 == 0)
7748 rv = VNET_API_ERROR_INVALID_VALUE;
7752 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7754 rv = VNET_API_ERROR_INVALID_VALUE;
7760 rv = VNET_API_ERROR_INVALID_VALUE;
7764 /* Reset report streams if we are reconfiguring IP addresses */
7765 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7766 frm->src_address.as_u32 != src.as_u32 ||
7767 frm->collector_port != collector_port)
7768 vnet_flow_reports_reset (frm);
7770 frm->ipfix_collector.as_u32 = collector.as_u32;
7771 frm->collector_port = collector_port;
7772 frm->src_address.as_u32 = src.as_u32;
7773 frm->fib_index = fib_index;
7774 frm->path_mtu = path_mtu;
7775 frm->template_interval = template_interval;
7776 frm->udp_checksum = udp_checksum;
7778 /* Turn on the flow reporting process */
7779 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7782 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
7786 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
7788 flow_report_main_t *frm = &flow_report_main;
7789 unix_shared_memory_queue_t *q;
7790 vl_api_ipfix_exporter_details_t *rmp;
7791 ip4_main_t *im = &ip4_main;
7794 q = vl_api_client_index_to_input_queue (mp->client_index);
7798 rmp = vl_msg_api_alloc (sizeof (*rmp));
7799 memset (rmp, 0, sizeof (*rmp));
7800 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
7801 rmp->context = mp->context;
7802 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7803 sizeof (frm->ipfix_collector.data));
7804 rmp->collector_port = htons (frm->collector_port);
7805 memcpy (rmp->src_address, frm->src_address.data,
7806 sizeof (frm->src_address.data));
7807 if (frm->fib_index == ~0)
7810 vrf_id = im->fibs[frm->fib_index].ft_table_id;
7811 rmp->vrf_id = htonl (vrf_id);
7812 rmp->path_mtu = htonl (frm->path_mtu);
7813 rmp->template_interval = htonl (frm->template_interval);
7814 rmp->udp_checksum = (frm->udp_checksum != 0);
7816 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7820 vl_api_set_ipfix_classify_stream_t_handler
7821 (vl_api_set_ipfix_classify_stream_t * mp)
7823 vl_api_set_ipfix_classify_stream_reply_t *rmp;
7824 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7825 flow_report_main_t *frm = &flow_report_main;
7827 u32 src_port = UDP_DST_PORT_ipfix;
7830 domain_id = ntohl (mp->domain_id);
7831 src_port = ntohs (mp->src_port);
7833 if (fcm->src_port != 0 &&
7834 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
7836 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
7837 domain_id, (u16) src_port);
7841 fcm->domain_id = domain_id;
7842 fcm->src_port = (u16) src_port;
7844 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7848 vl_api_ipfix_classify_stream_dump_t_handler
7849 (vl_api_ipfix_classify_stream_dump_t * mp)
7851 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7852 unix_shared_memory_queue_t *q;
7853 vl_api_ipfix_classify_stream_details_t *rmp;
7855 q = vl_api_client_index_to_input_queue (mp->client_index);
7859 rmp = vl_msg_api_alloc (sizeof (*rmp));
7860 memset (rmp, 0, sizeof (*rmp));
7861 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
7862 rmp->context = mp->context;
7863 rmp->domain_id = htonl (fcm->domain_id);
7864 rmp->src_port = htons (fcm->src_port);
7866 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7870 vl_api_ipfix_classify_table_add_del_t_handler
7871 (vl_api_ipfix_classify_table_add_del_t * mp)
7873 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
7874 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7875 flow_report_main_t *frm = &flow_report_main;
7876 vnet_flow_report_add_del_args_t args;
7877 ipfix_classify_table_t *table;
7879 u32 classify_table_index;
7881 u8 transport_protocol;
7884 classify_table_index = ntohl (mp->table_id);
7885 ip_version = mp->ip_version;
7886 transport_protocol = mp->transport_protocol;
7887 is_add = mp->is_add;
7889 if (fcm->src_port == 0)
7891 /* call set_ipfix_classify_stream first */
7892 rv = VNET_API_ERROR_UNSPECIFIED;
7896 memset (&args, 0, sizeof (args));
7900 for (i = 0; i < vec_len (fcm->tables); i++)
7901 if (ipfix_classify_table_index_valid (i))
7902 if (fcm->tables[i].classify_table_index == classify_table_index)
7904 table = &fcm->tables[i];
7912 rv = VNET_API_ERROR_VALUE_EXIST;
7915 table = ipfix_classify_add_table ();
7916 table->classify_table_index = classify_table_index;
7922 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
7927 table->ip_version = ip_version;
7928 table->transport_protocol = transport_protocol;
7930 args.opaque.as_uword = table - fcm->tables;
7931 args.rewrite_callback = ipfix_classify_template_rewrite;
7932 args.flow_data_callback = ipfix_classify_send_flows;
7933 args.is_add = is_add;
7934 args.domain_id = fcm->domain_id;
7935 args.src_port = fcm->src_port;
7937 rv = vnet_flow_report_add_del (frm, &args);
7939 /* If deleting, or add failed */
7940 if (is_add == 0 || (rv && is_add))
7941 ipfix_classify_delete_table (table - fcm->tables);
7944 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
7948 send_ipfix_classify_table_details (u32 table_index,
7949 unix_shared_memory_queue_t * q,
7952 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7953 vl_api_ipfix_classify_table_details_t *mp;
7955 ipfix_classify_table_t *table = &fcm->tables[table_index];
7957 mp = vl_msg_api_alloc (sizeof (*mp));
7958 memset (mp, 0, sizeof (*mp));
7959 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
7960 mp->context = context;
7961 mp->table_id = htonl (table->classify_table_index);
7962 mp->ip_version = table->ip_version;
7963 mp->transport_protocol = table->transport_protocol;
7965 vl_msg_api_send_shmem (q, (u8 *) & mp);
7969 vl_api_ipfix_classify_table_dump_t_handler
7970 (vl_api_ipfix_classify_table_dump_t * mp)
7972 flow_report_classify_main_t *fcm = &flow_report_classify_main;
7973 unix_shared_memory_queue_t *q;
7976 q = vl_api_client_index_to_input_queue (mp->client_index);
7980 for (i = 0; i < vec_len (fcm->tables); i++)
7981 if (ipfix_classify_table_index_valid (i))
7982 send_ipfix_classify_table_details (i, q, mp->context);
7986 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
7988 vl_api_pg_create_interface_reply_t *rmp;
7991 pg_main_t *pg = &pg_main;
7992 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
7995 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7997 rmp->sw_if_index = ntohl(sw_if_index);
8003 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8005 vl_api_pg_capture_reply_t *rmp;
8008 vnet_main_t *vnm = vnet_get_main ();
8009 vnet_interface_main_t *im = &vnm->interface_main;
8010 vnet_hw_interface_t *hi = 0;
8012 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8013 u32 hw_if_index = ~0;
8014 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8017 vec_free (intf_name);
8019 if (hw_if_index != ~0)
8021 pg_capture_args_t _a, *a = &_a;
8023 u32 len = ntohl (mp->pcap_name_length);
8024 u8 *pcap_file_name = vec_new (u8, len);
8025 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8027 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8028 a->hw_if_index = hw_if_index;
8029 a->dev_instance = hi->dev_instance;
8030 a->is_enabled = mp->is_enabled;
8031 a->pcap_file_name = pcap_file_name;
8032 a->count = ntohl (mp->count);
8034 clib_error_t *e = pg_capture (a);
8037 clib_error_report (e);
8038 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8041 vec_free (pcap_file_name);
8043 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8047 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8049 vl_api_pg_enable_disable_reply_t *rmp;
8052 pg_main_t *pg = &pg_main;
8053 u32 stream_index = ~0;
8055 int is_enable = mp->is_enabled != 0;
8056 u32 len = ntohl (mp->stream_name_length) - 1;
8060 u8 *stream_name = vec_new (u8, len);
8061 clib_memcpy (stream_name, mp->stream_name, len);
8062 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8065 vec_free (stream_name);
8068 pg_enable_disable (stream_index, is_enable);
8070 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8074 vl_api_ip_source_and_port_range_check_add_del_t_handler
8075 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8077 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8080 u8 is_ipv6 = mp->is_ipv6;
8081 u8 is_add = mp->is_add;
8082 u8 mask_length = mp->mask_length;
8083 ip4_address_t ip4_addr;
8084 ip6_address_t ip6_addr;
8086 u16 *high_ports = 0;
8088 u16 tmp_low, tmp_high;
8092 // Validate port range
8093 num_ranges = mp->number_of_ranges;
8094 if (num_ranges > 32)
8095 { // This is size of array in VPE.API
8096 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8100 vec_reset_length (low_ports);
8101 vec_reset_length (high_ports);
8103 for (i = 0; i < num_ranges; i++)
8105 tmp_low = mp->low_ports[i];
8106 tmp_high = mp->high_ports[i];
8107 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8108 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8109 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8111 rv = VNET_API_ERROR_INVALID_VALUE;
8114 vec_add1 (low_ports, tmp_low);
8115 vec_add1 (high_ports, tmp_high + 1);
8118 // Validate mask_length
8119 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8121 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8125 vrf_id = ntohl (mp->vrf_id);
8129 rv = VNET_API_ERROR_INVALID_VALUE;
8136 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8137 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8141 high_ports, is_add);
8145 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8146 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8150 high_ports, is_add);
8154 vec_free (low_ports);
8155 vec_free (high_ports);
8156 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8160 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8161 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8163 vlib_main_t *vm = vlib_get_main ();
8164 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8165 ip4_main_t *im = &ip4_main;
8168 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8169 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8173 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8174 ntohl (mp->tcp_out_vrf_id);
8175 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8176 ntohl (mp->udp_out_vrf_id);
8177 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8178 ntohl (mp->tcp_in_vrf_id);
8179 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8180 ntohl (mp->udp_in_vrf_id);
8183 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8185 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8187 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8191 rv = VNET_API_ERROR_INVALID_VALUE;
8195 fib_index[i] = p[0];
8200 sw_if_index = ntohl (mp->sw_if_index);
8202 VALIDATE_SW_IF_INDEX (mp);
8205 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8208 BAD_SW_IF_INDEX_LABEL;
8211 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8215 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8218 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8220 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8221 u32 sw_if_index = ~0;
8223 /* Check src & dst are different */
8224 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8226 rv = VNET_API_ERROR_SAME_SRC_DST;
8230 memset (a, 0, sizeof (*a));
8232 /* ip addresses sent in network byte order */
8233 clib_memcpy (&(a->src), mp->src_address, 4);
8234 clib_memcpy (&(a->dst), mp->dst_address, 4);
8235 a->is_add = mp->is_add;
8236 a->lsa = ntohl (mp->local_sa_id);
8237 a->rsa = ntohl (mp->remote_sa_id);
8239 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8243 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8245 rmp->sw_if_index = ntohl (sw_if_index);
8250 static void send_ipsec_gre_tunnel_details
8251 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8253 vl_api_ipsec_gre_tunnel_details_t *rmp;
8255 rmp = vl_msg_api_alloc (sizeof (*rmp));
8256 memset (rmp, 0, sizeof (*rmp));
8257 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8258 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8259 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8260 rmp->sw_if_index = htonl (t->sw_if_index);
8261 rmp->local_sa_id = htonl (t->local_sa_id);
8262 rmp->remote_sa_id = htonl (t->remote_sa_id);
8263 rmp->context = context;
8265 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8268 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8269 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8271 unix_shared_memory_queue_t *q;
8272 ipsec_gre_main_t *igm = &ipsec_gre_main;
8273 ipsec_gre_tunnel_t *t;
8276 q = vl_api_client_index_to_input_queue (mp->client_index);
8282 sw_if_index = ntohl (mp->sw_if_index);
8284 if (~0 == sw_if_index)
8287 pool_foreach (t, igm->tunnels,
8289 send_ipsec_gre_tunnel_details(t, q, mp->context);
8295 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8296 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8300 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8301 send_ipsec_gre_tunnel_details (t, q, mp->context);
8306 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8308 vl_api_delete_subif_reply_t *rmp;
8311 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8313 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8316 #define BOUNCE_HANDLER(nn) \
8317 static void vl_api_##nn##_t_handler ( \
8318 vl_api_##nn##_t *mp) \
8320 vpe_client_registration_t *reg; \
8321 vpe_api_main_t * vam = &vpe_api_main; \
8322 unix_shared_memory_queue_t * q; \
8324 /* One registration only... */ \
8325 pool_foreach(reg, vam->nn##_registrations, \
8327 q = vl_api_client_index_to_input_queue (reg->client_index); \
8330 * If the queue is stuffed, turf the msg and complain \
8331 * It's unlikely that the intended recipient is \
8332 * alive; avoid deadlock at all costs. \
8334 if (q->cursize == q->maxsize) { \
8335 clib_warning ("ERROR: receiver queue full, drop msg"); \
8336 vl_msg_api_free (mp); \
8339 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8343 vl_msg_api_free (mp); \
8348 * Add vpe's API message handlers to the table.
8349 * vlib has alread mapped shared memory and
8350 * added the client registration handlers.
8351 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8354 static clib_error_t *
8355 vpe_api_hookup (vlib_main_t * vm)
8357 api_main_t *am = &api_main;
8360 vl_msg_api_set_handlers(VL_API_##N, #n, \
8361 vl_api_##n##_t_handler, \
8363 vl_api_##n##_t_endian, \
8364 vl_api_##n##_t_print, \
8365 sizeof(vl_api_##n##_t), 1);
8366 foreach_vpe_api_msg;
8370 * Manually register the sr tunnel add del msg, so we trace
8371 * enough bytes to capture a typical segment list
8373 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8374 "sr_tunnel_add_del",
8375 vl_api_sr_tunnel_add_del_t_handler,
8377 vl_api_sr_tunnel_add_del_t_endian,
8378 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8382 * Manually register the sr policy add del msg, so we trace
8383 * enough bytes to capture a typical tunnel name list
8385 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8386 "sr_policy_add_del",
8387 vl_api_sr_policy_add_del_t_handler,
8389 vl_api_sr_policy_add_del_t_endian,
8390 vl_api_sr_policy_add_del_t_print, 256, 1);
8393 * Trace space for 8 MPLS encap labels, classifier mask+match
8395 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8396 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8397 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8398 += 5 * sizeof (u32x4);
8399 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8402 * Thread-safe API messages
8404 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8405 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8410 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8412 static clib_error_t *
8413 vpe_api_init (vlib_main_t * vm)
8415 vpe_api_main_t *am = &vpe_api_main;
8418 am->vnet_main = vnet_get_main ();
8419 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8420 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8421 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8422 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8423 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8424 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8427 vl_set_memory_region_name ("/vpe-api");
8428 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8433 VLIB_INIT_FUNCTION (vpe_api_init);
8436 static clib_error_t *
8437 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8440 u64 baseva, size, pvt_heap_size;
8442 const int max_buf_size = 4096;
8444 struct passwd _pw, *pw;
8445 struct group _grp, *grp;
8447 buf = vec_new (char, 128);
8448 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8450 if (unformat (input, "prefix %s", &chroot_path))
8452 vec_add1 (chroot_path, 0);
8453 vl_set_memory_root_path ((char *) chroot_path);
8455 else if (unformat (input, "uid %d", &uid))
8456 vl_set_memory_uid (uid);
8457 else if (unformat (input, "gid %d", &gid))
8458 vl_set_memory_gid (gid);
8459 else if (unformat (input, "baseva %llx", &baseva))
8460 vl_set_global_memory_baseva (baseva);
8461 else if (unformat (input, "global-size %lldM", &size))
8462 vl_set_global_memory_size (size * (1ULL << 20));
8463 else if (unformat (input, "global-size %lldG", &size))
8464 vl_set_global_memory_size (size * (1ULL << 30));
8465 else if (unformat (input, "global-size %lld", &size))
8466 vl_set_global_memory_size (size);
8467 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8468 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8469 else if (unformat (input, "global-pvt-heap-size size %lld",
8471 vl_set_global_pvt_heap_size (pvt_heap_size);
8472 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8473 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8474 else if (unformat (input, "api-pvt-heap-size size %lld",
8476 vl_set_api_pvt_heap_size (pvt_heap_size);
8477 else if (unformat (input, "api-size %lldM", &size))
8478 vl_set_api_memory_size (size * (1ULL << 20));
8479 else if (unformat (input, "api-size %lldG", &size))
8480 vl_set_api_memory_size (size * (1ULL << 30));
8481 else if (unformat (input, "api-size %lld", &size))
8482 vl_set_api_memory_size (size);
8483 else if (unformat (input, "uid %s", &s))
8485 /* lookup the username */
8488 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8489 && (vec_len (buf) <= max_buf_size))
8491 vec_resize (buf, vec_len (buf) * 2);
8495 e = clib_error_return_code (0, rv,
8496 CLIB_ERROR_ERRNO_VALID |
8498 "cannot fetch username %s", s);
8506 clib_error_return_fatal (0, "username %s does not exist", s);
8512 vl_set_memory_uid (pw->pw_uid);
8514 else if (unformat (input, "gid %s", &s))
8516 /* lookup the group name */
8519 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8520 && (vec_len (buf) <= max_buf_size))
8522 vec_resize (buf, vec_len (buf) * 2);
8526 e = clib_error_return_code (0, rv,
8527 CLIB_ERROR_ERRNO_VALID |
8529 "cannot fetch group %s", s);
8536 e = clib_error_return_fatal (0, "group %s does not exist", s);
8543 vl_set_memory_gid (grp->gr_gid);
8546 return clib_error_return (0, "unknown input `%U'",
8547 format_unformat_error, input);
8552 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8555 get_unformat_vnet_sw_interface (void)
8557 return (void *) &unformat_vnet_sw_interface;
8560 #undef vl_api_version
8561 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8562 #include <vpp-api/vpe.api.h>
8563 #undef vl_api_version
8566 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8568 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8570 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8571 clib_host_to_net_u32 (mp->api_versions[0]),
8579 format_arp_event (u8 * s, va_list * args)
8581 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8583 s = format (s, "pid %d: ", event->pid);
8585 s = format (s, "bd mac/ip4 binding events");
8587 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8592 format_nd_event (u8 * s, va_list * args)
8594 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8596 s = format (s, "pid %d: ", event->pid);
8598 s = format (s, "bd mac/ip6 binding events");
8600 s = format (s, "resolution for %U", format_ip6_address, event->address);
8604 static clib_error_t *
8605 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8606 unformat_input_t * input, vlib_cli_command_t * cmd)
8608 vpe_api_main_t *am = &vpe_api_main;
8609 vl_api_ip4_arp_event_t *arp_event;
8610 vl_api_ip6_nd_event_t *nd_event;
8612 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8614 vlib_cli_output (vm, "No active arp or nd event registrations");
8619 pool_foreach (arp_event, am->arp_events,
8621 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8624 pool_foreach (nd_event, am->nd_events,
8626 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8634 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8635 .path = "show arp-nd-event registrations",
8636 .function = show_ip_arp_nd_events_fn,
8637 .short_help = "Show ip4 arp and ip6 nd event registrations",
8642 * fd.io coding-style-patch-verification: ON
8645 * eval: (c-set-style "gnu")