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/unix/tuntap.h>
55 #include <vnet/unix/tapcli.h>
56 #include <vnet/mpls-gre/mpls.h>
57 #include <vnet/dhcp/proxy.h>
58 #include <vnet/dhcp/client.h>
60 #include <vnet/sr/sr.h>
62 #include <vnet/dhcpv6/proxy.h>
63 #include <vlib/vlib.h>
64 #include <vlib/unix/unix.h>
65 #include <vlibapi/api.h>
66 #include <vlibmemory/api.h>
67 #include <vnet/classify/vnet_classify.h>
68 #include <vnet/classify/input_acl.h>
69 #include <vnet/classify/policer_classify.h>
70 #include <vnet/l2/l2_classify.h>
71 #include <vnet/vxlan/vxlan.h>
72 #include <vnet/gre/gre.h>
73 #include <vnet/l2/l2_vtr.h>
74 #include <vnet/vxlan-gpe/vxlan_gpe.h>
75 #include <vnet/lisp-gpe/lisp_gpe.h>
76 #include <vnet/lisp-cp/control.h>
77 #include <vnet/map/map.h>
78 #include <vnet/cop/cop.h>
79 #include <vnet/ip/ip6_hop_by_hop.h>
80 #include <vnet/ip/ip_source_and_port_range_check.h>
81 #include <vnet/devices/af_packet/af_packet.h>
82 #include <vnet/policer/policer.h>
83 #include <vnet/devices/netmap/netmap.h>
84 #include <vnet/flow/flow_report.h>
87 #undef __included_bihash_template_h__
88 #include <vnet/l2/l2_fib.h>
91 #include <vnet/ipsec/ipsec.h>
92 #include <vnet/ipsec/ikev2.h>
95 #include <vnet/devices/virtio/vhost-user.h>
98 #include <stats/stats.h>
101 #include <vnet/ethernet/ethernet.h>
102 #include <vnet/ethernet/arp_packet.h>
103 #include <vnet/interface.h>
105 #include <vnet/l2/l2_fib.h>
106 #include <vnet/l2/l2_bd.h>
107 #include <vpp-api/vpe_msg_enum.h>
109 #define f64_endian(a)
110 #define f64_print(a,b)
112 #define vl_typedefs /* define message structures */
113 #include <vpp-api/vpe_all_api_h.h>
116 #define vl_endianfun /* define message structures */
117 #include <vpp-api/vpe_all_api_h.h>
120 /* instantiate all the print functions we know about */
121 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
123 #include <vpp-api/vpe_all_api_h.h>
126 #define REPLY_MACRO(t) \
128 unix_shared_memory_queue_t * q; \
129 rv = vl_msg_api_pd_handler (mp, rv); \
130 q = vl_api_client_index_to_input_queue (mp->client_index); \
134 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
135 rmp->_vl_msg_id = ntohs((t)); \
136 rmp->context = mp->context; \
137 rmp->retval = ntohl(rv); \
139 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
142 #define REPLY_MACRO2(t, body) \
144 unix_shared_memory_queue_t * q; \
145 rv = vl_msg_api_pd_handler (mp, rv); \
146 q = vl_api_client_index_to_input_queue (mp->client_index); \
150 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
151 rmp->_vl_msg_id = ntohs((t)); \
152 rmp->context = mp->context; \
153 rmp->retval = ntohl(rv); \
154 do {body;} while (0); \
155 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
158 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
160 #define VALIDATE_SW_IF_INDEX(mp) \
161 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
162 vnet_main_t *__vnm = vnet_get_main(); \
163 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
165 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
166 goto bad_sw_if_index; \
170 #define BAD_SW_IF_INDEX_LABEL \
176 #define VALIDATE_RX_SW_IF_INDEX(mp) \
177 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
178 vnet_main_t *__vnm = vnet_get_main(); \
179 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
180 __rx_sw_if_index)) { \
181 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
182 goto bad_rx_sw_if_index; \
186 #define BAD_RX_SW_IF_INDEX_LABEL \
188 bad_rx_sw_if_index: \
192 #define VALIDATE_TX_SW_IF_INDEX(mp) \
193 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
194 vnet_main_t *__vnm = vnet_get_main(); \
195 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
196 __tx_sw_if_index)) { \
197 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
198 goto bad_tx_sw_if_index; \
202 #define BAD_TX_SW_IF_INDEX_LABEL \
204 bad_tx_sw_if_index: \
210 #define VALIDATE_SW_IF_INDEX(mp)
211 #define BAD_SW_IF_INDEX_LABEL
212 #define VALIDATE_RX_SW_IF_INDEX(mp)
213 #define BAD_RX_SW_IF_INDEX_LABEL
214 #define VALIDATE_TX_SW_IF_INDEX(mp)
215 #define BAD_TX_SW_IF_INDEX_LABEL
217 #endif /* CLIB_DEBUG > 0 */
219 #define foreach_vpe_api_msg \
220 _(WANT_INTERFACE_EVENTS, want_interface_events) \
221 _(WANT_OAM_EVENTS, want_oam_events) \
222 _(OAM_ADD_DEL, oam_add_del) \
223 _(SW_INTERFACE_DUMP, sw_interface_dump) \
224 _(SW_INTERFACE_DETAILS, sw_interface_details) \
225 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
226 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
227 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
228 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
229 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
230 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
231 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
232 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
233 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
234 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
235 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
236 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
237 _(L2FIB_ADD_DEL, l2fib_add_del) \
238 _(L2_FLAGS, l2_flags) \
239 _(BRIDGE_FLAGS, bridge_flags) \
240 _(TAP_CONNECT, tap_connect) \
241 _(TAP_MODIFY, tap_modify) \
242 _(TAP_DELETE, tap_delete) \
243 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
244 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
245 _(CREATE_SUBIF, create_subif) \
246 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
247 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
248 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
249 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
250 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
251 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
252 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
253 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
254 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
255 _(RESET_FIB, reset_fib) \
256 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
257 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
258 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
259 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
260 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
261 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
262 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
263 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
264 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
265 sw_interface_ip6_set_link_local_address) \
266 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
267 _(CREATE_LOOPBACK, create_loopback) \
268 _(CONTROL_PING, control_ping) \
269 _(NOPRINT_CONTROL_PING, noprint_control_ping) \
270 _(CLI_REQUEST, cli_request) \
271 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
272 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
273 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
274 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
275 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
276 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
277 _(GET_NODE_INDEX, get_node_index) \
278 _(ADD_NODE_NEXT, add_node_next) \
279 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
280 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
281 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
282 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
283 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
284 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
285 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
286 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
287 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
288 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
289 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
290 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
291 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
292 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
293 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
294 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
295 _(IP_ADDRESS_DUMP, ip_address_dump) \
296 _(IP_DUMP, ip_dump) \
297 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
298 _(SHOW_VERSION, show_version) \
299 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
300 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
301 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
302 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
303 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
304 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
305 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
306 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
307 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
308 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
309 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
310 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
311 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
312 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
313 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
314 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
315 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
316 _(DELETE_LOOPBACK, delete_loopback) \
317 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
318 _(MAP_ADD_DOMAIN, map_add_domain) \
319 _(MAP_DEL_DOMAIN, map_del_domain) \
320 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
321 _(MAP_DOMAIN_DUMP, map_domain_dump) \
322 _(MAP_RULE_DUMP, map_rule_dump) \
323 _(MAP_SUMMARY_STATS, map_summary_stats) \
324 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
325 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
326 _(GET_NODE_GRAPH, get_node_graph) \
327 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
328 _(TRACE_PROFILE_ADD, trace_profile_add) \
329 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
330 _(TRACE_PROFILE_DEL, trace_profile_del) \
331 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
332 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
333 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
334 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
335 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
336 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
337 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
338 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
339 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
340 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
341 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
342 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
343 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
344 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
345 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
346 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
347 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
348 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
349 _(SHOW_LISP_STATUS, show_lisp_status) \
350 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
351 lisp_add_del_map_request_itr_rlocs) \
352 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
353 _(SHOW_LISP_PITR, show_lisp_pitr) \
354 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
355 _(AF_PACKET_CREATE, af_packet_create) \
356 _(AF_PACKET_DELETE, af_packet_delete) \
357 _(POLICER_ADD_DEL, policer_add_del) \
358 _(POLICER_DUMP, policer_dump) \
359 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
360 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
361 _(NETMAP_CREATE, netmap_create) \
362 _(NETMAP_DELETE, netmap_delete) \
363 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
364 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
365 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
366 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
367 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
368 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
369 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
370 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
371 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
372 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
373 _(CLASSIFY_TABLE_INFO,classify_table_info) \
374 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
375 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
376 _(IPFIX_ENABLE,ipfix_enable) \
377 _(IPFIX_DUMP,ipfix_dump) \
378 _(GET_NEXT_INDEX, get_next_index) \
379 _(PG_CREATE_INTERFACE, pg_create_interface) \
380 _(PG_CAPTURE, pg_capture) \
381 _(PG_ENABLE_DISABLE, pg_enable_disable) \
382 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
383 ip_source_and_port_range_check_add_del) \
384 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
385 ip_source_and_port_range_check_interface_add_del)
388 #define QUOTE(x) QUOTE_(x)
390 #define foreach_registration_hash \
391 _(interface_events) \
392 _(to_netconf_server) \
393 _(from_netconf_server) \
394 _(to_netconf_client) \
395 _(from_netconf_client) \
400 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
401 RESOLVE_IP6_ADD_DEL_ROUTE,
402 RESOLVE_MPLS_ETHERNET_ADD_DEL,
410 vl_api_ip_add_del_route_t r;
411 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
418 #define _(a) uword *a##_registration_hash; \
419 vpe_client_registration_t * a##_registrations;
420 foreach_registration_hash
422 /* notifications happen really early in the game */
423 u8 link_state_process_up;
425 /* ip4 pending route adds */
426 pending_route_t *pending_routes;
428 /* ip4 arp event registration pool */
429 vl_api_ip4_arp_event_t *arp_events;
432 vlib_main_t *vlib_main;
433 vnet_main_t *vnet_main;
436 static vlib_node_registration_t vpe_resolver_process_node;
437 static vpe_api_main_t vpe_api_main;
439 static void send_sw_interface_flags (vpe_api_main_t * am,
440 unix_shared_memory_queue_t * q,
441 vnet_sw_interface_t * swif);
442 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
443 unix_shared_memory_queue_t * q,
446 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
449 /* Clean up all registrations belonging to the indicated client */
451 vl_api_memclnt_delete_callback (u32 client_index)
453 vpe_api_main_t *vam = &vpe_api_main;
454 vpe_client_registration_t *rp;
456 int stats_memclnt_delete_callback (u32 client_index);
458 stats_memclnt_delete_callback (client_index);
461 p = hash_get (vam->a##_registration_hash, client_index); \
463 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
464 pool_put (vam->a##_registrations, rp); \
465 hash_unset (vam->a##_registration_hash, client_index); \
467 foreach_registration_hash;
472 #define API_LINK_STATE_EVENT 1
473 #define API_ADMIN_UP_DOWN_EVENT 2
476 event_data_cmp (void *a1, void *a2)
481 return (word) e1[0] - (word) e2[0];
485 link_state_process (vlib_main_t * vm,
486 vlib_node_runtime_t * rt, vlib_frame_t * f)
488 vpe_api_main_t *vam = &vpe_api_main;
489 vnet_main_t *vnm = vam->vnet_main;
490 vnet_sw_interface_t *swif;
491 uword *event_data = 0;
492 vpe_client_registration_t *reg;
494 u32 prev_sw_if_index;
495 unix_shared_memory_queue_t *q;
497 vam->link_state_process_up = 1;
501 vlib_process_wait_for_event (vm);
503 /* Unified list of changed link or admin state sw_if_indices */
504 vlib_process_get_events_with_type
505 (vm, &event_data, API_LINK_STATE_EVENT);
506 vlib_process_get_events_with_type
507 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
509 /* Sort, so we can eliminate duplicates */
510 vec_sort_with_function (event_data, event_data_cmp);
512 prev_sw_if_index = ~0;
514 for (i = 0; i < vec_len (event_data); i++)
516 /* Only one message per swif */
517 if (prev_sw_if_index == event_data[i])
519 prev_sw_if_index = event_data[i];
522 pool_foreach(reg, vam->interface_events_registrations,
524 q = vl_api_client_index_to_input_queue (reg->client_index);
527 /* sw_interface may be deleted already */
528 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
531 swif = vnet_get_sw_interface (vnm, event_data[i]);
532 send_sw_interface_flags (vam, q, swif);
538 vec_reset_length (event_data);
544 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
546 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
547 u32 hw_if_index, u32 flags);
550 VLIB_REGISTER_NODE (link_state_process_node,static) = {
551 .function = link_state_process,
552 .type = VLIB_NODE_TYPE_PROCESS,
553 .name = "vpe-link-state-process",
557 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
558 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
560 static clib_error_t *
561 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
563 vpe_api_main_t *vam = &vpe_api_main;
564 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
566 if (vam->link_state_process_up)
567 vlib_process_signal_event (vam->vlib_main,
568 link_state_process_node.index,
569 API_LINK_STATE_EVENT, hi->sw_if_index);
573 static clib_error_t *
574 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
576 vpe_api_main_t *vam = &vpe_api_main;
579 * Note: it's perfectly fair to set a subif admin up / admin down.
580 * Note the subtle distinction between this routine and the previous
583 if (vam->link_state_process_up)
584 vlib_process_signal_event (vam->vlib_main,
585 link_state_process_node.index,
586 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
590 #define pub_sub_handler(lca,UCA) \
591 static void vl_api_want_##lca##_t_handler ( \
592 vl_api_want_##lca##_t *mp) \
594 vpe_api_main_t *vam = &vpe_api_main; \
595 vpe_client_registration_t *rp; \
596 vl_api_want_##lca##_reply_t *rmp; \
600 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
602 if (mp->enable_disable) { \
603 clib_warning ("pid %d: already enabled...", mp->pid); \
604 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
607 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
608 pool_put (vam->lca##_registrations, rp); \
609 hash_unset (vam->lca##_registration_hash, \
614 if (mp->enable_disable == 0) { \
615 clib_warning ("pid %d: already disabled...", mp->pid); \
616 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
619 pool_get (vam->lca##_registrations, rp); \
620 rp->client_index = mp->client_index; \
621 rp->client_pid = mp->pid; \
622 hash_set (vam->lca##_registration_hash, rp->client_index, \
623 rp - vam->lca##_registrations); \
626 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
629 pub_sub_handler (interface_events, INTERFACE_EVENTS)
630 pub_sub_handler (oam_events, OAM_EVENTS)
631 #define RESOLUTION_EVENT 1
632 #define RESOLUTION_PENDING_EVENT 2
633 #define IP4_ARP_EVENT 3
634 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
635 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
636 static int mpls_ethernet_add_del_tunnel_2_t_handler
637 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
639 void handle_ip4_arp_event (u32 pool_index)
641 vpe_api_main_t *vam = &vpe_api_main;
642 vnet_main_t *vnm = vam->vnet_main;
643 vlib_main_t *vm = vam->vlib_main;
644 vl_api_ip4_arp_event_t *event;
645 vl_api_ip4_arp_event_t *mp;
646 unix_shared_memory_queue_t *q;
648 /* Client can cancel, die, etc. */
649 if (pool_is_free_index (vam->arp_events, pool_index))
652 event = pool_elt_at_index (vam->arp_events, pool_index);
654 q = vl_api_client_index_to_input_queue (event->client_index);
657 (void) vnet_add_del_ip4_arp_change_event
658 (vnm, arp_change_delete_callback,
659 event->pid, &event->address,
660 vpe_resolver_process_node.index, IP4_ARP_EVENT,
661 ~0 /* pool index, notused */ , 0 /* is_add */ );
665 if (q->cursize < q->maxsize)
667 mp = vl_msg_api_alloc (sizeof (*mp));
668 clib_memcpy (mp, event, sizeof (*mp));
669 vl_msg_api_send_shmem (q, (u8 *) & mp);
673 static f64 last_time;
675 * Throttle syslog msgs.
676 * It's pretty tempting to just revoke the registration...
678 if (vlib_time_now (vm) > last_time + 10.0)
680 clib_warning ("arp event for %U to pid %d: queue stuffed!",
681 format_ip4_address, &event->address, event->pid);
682 last_time = vlib_time_now (vm);
688 resolver_process (vlib_main_t * vm,
689 vlib_node_runtime_t * rt, vlib_frame_t * f)
692 uword *event_data = 0;
694 vpe_api_main_t *vam = &vpe_api_main;
696 vl_api_ip_add_del_route_t *adr;
697 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
698 u32 *resolution_failures = 0;
704 vlib_process_wait_for_event_or_clock (vm, timeout);
706 event_type = vlib_process_get_events (vm, &event_data);
710 case RESOLUTION_PENDING_EVENT:
714 case RESOLUTION_EVENT:
715 for (i = 0; i < vec_len (event_data); i++)
718 * Resolution events can occur long after the
719 * original request has timed out. $$$ add a cancel
722 if (pool_is_free_index (vam->pending_routes, event_data[i]))
725 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
729 switch (pr->resolve_type)
731 case RESOLVE_IP4_ADD_DEL_ROUTE:
732 rv = ip4_add_del_route_t_handler (adr);
733 clib_warning ("resolver: add %U/%d via %U %s",
735 (ip4_address_t *) & (adr->dst_address),
736 adr->dst_address_length,
738 (ip4_address_t *) & (adr->next_hop_address),
739 (rv >= 0) ? "succeeded" : "failed");
742 case RESOLVE_IP6_ADD_DEL_ROUTE:
743 rv = ip6_add_del_route_t_handler (adr);
744 clib_warning ("resolver: add %U/%d via %U %s",
746 (ip6_address_t *) & (adr->dst_address),
747 adr->dst_address_length,
749 (ip6_address_t *) & (adr->next_hop_address),
750 (rv >= 0) ? "succeeded" : "failed");
753 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
754 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
755 clib_warning ("resolver: add mpls-o-e via %U %s",
758 (pme->next_hop_ip4_address_in_outer_vrf),
759 (rv >= 0) ? "succeeded" : "failed");
763 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
765 pool_put (vam->pending_routes, pr);
770 for (i = 0; i < vec_len (event_data); i++)
771 handle_ip4_arp_event (event_data[i]);
774 case ~0: /* timeout, retry pending resolutions */
776 pool_foreach (pr, vam->pending_routes,
782 /* May fail, e.g. due to interface down */
783 switch (pr->resolve_type)
785 case RESOLVE_IP4_ADD_DEL_ROUTE:
786 e = ip4_probe_neighbor
787 (vm, (ip4_address_t *)&(adr->next_hop_address),
788 ntohl(adr->next_hop_sw_if_index));
791 case RESOLVE_IP6_ADD_DEL_ROUTE:
792 e = ip6_probe_neighbor
793 (vm, (ip6_address_t *)&(adr->next_hop_address),
794 ntohl(adr->next_hop_sw_if_index));
797 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
799 e = ip4_probe_neighbor
801 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
802 pme->resolve_opaque);
806 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
811 clib_error_report (e);
813 adr->resolve_attempts = 1;
815 pme->resolve_attempts = 1;
819 adr->resolve_attempts -= 1;
820 if (adr->resolve_attempts == 0)
821 vec_add1 (resolution_failures,
822 pr - vam->pending_routes);
826 pme->resolve_attempts -= 1;
827 if (pme->resolve_attempts == 0)
828 vec_add1 (resolution_failures,
829 pr - vam->pending_routes);
833 for (i = 0; i < vec_len (resolution_failures); i++)
835 pr = pool_elt_at_index (vam->pending_routes,
836 resolution_failures[i]);
840 switch (pr->resolve_type)
842 case RESOLVE_IP4_ADD_DEL_ROUTE:
843 clib_warning ("resolver: add %U/%d via %U retry failure",
845 (ip4_address_t *) & (adr->dst_address),
846 adr->dst_address_length,
848 (ip4_address_t *) & (adr->next_hop_address));
851 case RESOLVE_IP6_ADD_DEL_ROUTE:
852 clib_warning ("resolver: add %U/%d via %U retry failure",
854 (ip6_address_t *) & (adr->dst_address),
855 adr->dst_address_length,
857 (ip6_address_t *) & (adr->next_hop_address));
860 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
861 clib_warning ("resolver: add mpls-o-e via %U retry failure",
864 (pme->next_hop_ip4_address_in_outer_vrf));
868 clib_warning ("BUG");
870 pool_put (vam->pending_routes, pr);
872 vec_reset_length (resolution_failures);
875 if (pool_elts (vam->pending_routes) == 0)
877 vec_reset_length (event_data);
879 return 0; /* or not */
883 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
884 .function = resolver_process,
885 .type = VLIB_NODE_TYPE_PROCESS,
886 .name = "vpe-route-resolver-process",
891 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
893 ip4_main_t *im = &ip4_main;
894 ip_lookup_main_t *lm = &im->lookup_main;
895 vnet_classify_main_t *cm = &vnet_classify_main;
896 stats_main_t *sm = &stats_main;
897 ip4_add_del_route_args_t a;
898 ip4_address_t next_hop_address;
900 vpe_api_main_t *vam = &vpe_api_main;
901 vnet_main_t *vnm = vam->vnet_main;
902 vlib_main_t *vm = vlib_get_main ();
904 vl_api_ip_add_del_route_t *adr;
910 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
913 if (mp->create_vrf_if_needed)
916 f = find_ip4_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
918 fib_index = f->index;
922 /* No such VRF, and we weren't asked to create one */
923 return VNET_API_ERROR_NO_SUCH_FIB;
931 if (~0 != mp->next_hop_sw_if_index &&
932 pool_is_free_index (vnm->interface_main.sw_interfaces,
933 ntohl (mp->next_hop_sw_if_index)))
934 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
936 clib_memcpy (next_hop_address.data, mp->next_hop_address,
937 sizeof (next_hop_address.data));
939 /* Arp for the next_hop if necessary */
940 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
945 lookup_result = ip4_fib_lookup_with_table
946 (im, fib_index, &next_hop_address, 1 /* disable default route */ );
948 adj = ip_get_adjacency (lm, lookup_result);
950 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
952 pool_get (vam->pending_routes, pr);
953 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
955 clib_memcpy (adr, mp, sizeof (*adr));
956 /* recursion block, "just in case" */
957 adr->resolve_if_needed = 0;
958 adr->resolve_attempts = ntohl (mp->resolve_attempts);
959 vnet_register_ip4_arp_resolution_event
960 (vnm, &next_hop_address, vpe_resolver_process_node.index,
961 RESOLUTION_EVENT, pr - vam->pending_routes);
963 vlib_process_signal_event
964 (vm, vpe_resolver_process_node.index,
965 RESOLUTION_PENDING_EVENT, 0 /* data */ );
967 /* The interface may be down, etc. */
968 e = ip4_probe_neighbor
969 (vm, (ip4_address_t *) & (mp->next_hop_address),
970 ntohl (mp->next_hop_sw_if_index));
973 clib_error_report (e);
975 return VNET_API_ERROR_IN_PROGRESS;
979 if (mp->is_multipath)
983 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
986 flags = IP4_ROUTE_FLAG_ADD;
988 flags = IP4_ROUTE_FLAG_DEL;
991 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
993 ip4_add_del_route_next_hop (im, flags,
994 (ip4_address_t *) mp->dst_address,
995 (u32) mp->dst_address_length,
996 (ip4_address_t *) mp->next_hop_address,
997 ntohl (mp->next_hop_sw_if_index),
998 (u32) mp->next_hop_weight,
1005 memset (&a, 0, sizeof (a));
1006 clib_memcpy (a.dst_address.data, mp->dst_address,
1007 sizeof (a.dst_address.data));
1009 a.dst_address_length = mp->dst_address_length;
1011 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
1012 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
1013 a.table_index_or_table_id = fib_index;
1018 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1020 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1025 ai = lm->drop_adj_index;
1026 else if (mp->is_local)
1027 ai = lm->local_adj_index;
1028 else if (mp->is_classify)
1030 if (pool_is_free_index
1031 (cm->tables, ntohl (mp->classify_table_index)))
1034 return VNET_API_ERROR_NO_SUCH_TABLE;
1036 adj = ip_add_adjacency (lm,
1041 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
1042 adj->classify.table_index = ntohl (mp->classify_table_index);
1044 else if (mp->lookup_in_vrf)
1046 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1049 adj = ip_add_adjacency (lm,
1053 adj->explicit_fib_index = p[0];
1058 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1062 ai = ip4_route_get_next_hop_adj (im,
1065 ntohl (mp->next_hop_sw_if_index),
1068 if (ai == lm->miss_adj_index)
1071 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1076 ip_adjacency_t *adj;
1077 int disable_default_route = 1;
1079 /* Trying to delete the default route? */
1080 if (a.dst_address.as_u32 == 0 && a.dst_address_length == 0)
1081 disable_default_route = 0;
1083 ai = ip4_fib_lookup_with_table
1084 (im, fib_index, &a.dst_address, disable_default_route);
1085 if (ai == lm->miss_adj_index)
1088 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1091 adj = ip_get_adjacency (lm, ai);
1092 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1095 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1100 ip4_add_del_route (im, &a);
1107 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1109 ip6_main_t *im = &ip6_main;
1110 ip_lookup_main_t *lm = &im->lookup_main;
1111 vnet_main_t *vnm = vnet_get_main ();
1112 vlib_main_t *vm = vlib_get_main ();
1113 vpe_api_main_t *vam = &vpe_api_main;
1114 stats_main_t *sm = &stats_main;
1115 ip6_add_del_route_args_t a;
1116 ip6_address_t next_hop_address;
1117 pending_route_t *pr;
1118 vl_api_ip_add_del_route_t *adr;
1123 ip_adjacency_t *adj = 0;
1126 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1130 if (mp->create_vrf_if_needed)
1133 f = find_ip6_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1135 fib_index = f->index;
1139 /* No such VRF, and we weren't asked to create one */
1140 return VNET_API_ERROR_NO_SUCH_FIB;
1148 if (~0 != mp->next_hop_sw_if_index &&
1149 pool_is_free_index (vnm->interface_main.sw_interfaces,
1150 ntohl (mp->next_hop_sw_if_index)))
1151 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1153 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1154 sizeof (next_hop_address.as_u8));
1156 /* Arp for the next_hop if necessary */
1157 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1160 ip_adjacency_t *adj;
1162 lookup_result = ip6_fib_lookup_with_table
1163 (im, fib_index, &next_hop_address);
1165 adj = ip_get_adjacency (lm, lookup_result);
1167 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1169 pool_get (vam->pending_routes, pr);
1171 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1172 clib_memcpy (adr, mp, sizeof (*adr));
1173 /* recursion block, "just in case" */
1174 adr->resolve_if_needed = 0;
1175 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1176 vnet_register_ip6_neighbor_resolution_event
1177 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1178 RESOLUTION_EVENT, pr - vam->pending_routes);
1180 vlib_process_signal_event
1181 (vm, vpe_resolver_process_node.index,
1182 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1184 /* The interface may be down, etc. */
1185 e = ip6_probe_neighbor
1186 (vm, (ip6_address_t *) & (mp->next_hop_address),
1187 ntohl (mp->next_hop_sw_if_index));
1190 clib_error_report (e);
1192 return VNET_API_ERROR_IN_PROGRESS;
1196 if (mp->is_multipath)
1200 dslock (sm, 1 /* release hint */ , 11 /* tag */ );
1203 flags = IP6_ROUTE_FLAG_ADD;
1205 flags = IP6_ROUTE_FLAG_DEL;
1208 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1210 ip6_add_del_route_next_hop (im, flags,
1211 (ip6_address_t *) mp->dst_address,
1212 (u32) mp->dst_address_length,
1213 (ip6_address_t *) mp->next_hop_address,
1214 ntohl (mp->next_hop_sw_if_index),
1215 (u32) mp->next_hop_weight,
1216 ~0 /* adj_index */ ,
1222 memset (&a, 0, sizeof (a));
1223 clib_memcpy (a.dst_address.as_u8, mp->dst_address,
1224 sizeof (a.dst_address.as_u8));
1226 a.dst_address_length = mp->dst_address_length;
1228 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1229 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1230 a.table_index_or_table_id = fib_index;
1235 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1237 dslock (sm, 1 /* release hint */ , 3 /* tag */ );
1242 ai = lm->drop_adj_index;
1243 else if (mp->is_local)
1244 ai = lm->local_adj_index;
1245 else if (mp->lookup_in_vrf)
1247 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1250 adj = ip_add_adjacency (lm,
1254 adj->explicit_fib_index = p[0];
1259 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1263 ai = ip6_route_get_next_hop_adj (im,
1266 ntohl (mp->next_hop_sw_if_index),
1268 if (ai == lm->miss_adj_index)
1271 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1276 ip_adjacency_t *adj;
1278 ai = ip6_fib_lookup_with_table (im, fib_index, &a.dst_address);
1279 if (ai == lm->miss_adj_index)
1282 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1284 adj = ip_get_adjacency (lm, ai);
1285 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1288 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1293 ip6_add_del_route (im, &a);
1300 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1302 vl_api_ip_add_del_route_reply_t *rmp;
1304 vnet_main_t *vnm = vnet_get_main ();
1309 rv = ip6_add_del_route_t_handler (mp);
1311 rv = ip4_add_del_route_t_handler (mp);
1313 rv = (rv == 0) ? vnm->api_errno : rv;
1315 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1319 api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1320 u32 sw_if_index, u8 * next_hop_addr)
1322 vl_api_ip_add_del_route_t mp;
1325 memset (&mp, 0, sizeof (vl_api_ip_add_del_route_t));
1328 * Configure default IP route:
1329 * - ip route add 0.0.0.0/1 via <GW IP>
1330 * - ip route add 128.0.0.0/1 via <GW IP>
1332 mp.next_hop_sw_if_index = ntohl (sw_if_index);
1334 mp.resolve_attempts = ~0;
1335 mp.resolve_if_needed = 1;
1337 mp.is_ipv6 = is_ipv6;
1338 mp.next_hop_weight = 1;
1340 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1343 rv = ip6_add_del_route_t_handler (&mp);
1346 mp.dst_address_length = 1;
1348 mp.dst_address[0] = 0;
1349 rv = ip4_add_del_route_t_handler (&mp);
1351 mp.dst_address[0] = 128;
1352 rv |= ip4_add_del_route_t_handler (&mp);
1356 clib_error_return (0, "failed to config default IP route");
1361 vl_api_sw_interface_add_del_address_t_handler
1362 (vl_api_sw_interface_add_del_address_t * mp)
1364 vlib_main_t *vm = vlib_get_main ();
1365 vl_api_sw_interface_add_del_address_reply_t *rmp;
1369 VALIDATE_SW_IF_INDEX (mp);
1371 is_del = mp->is_add == 0;
1374 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1375 else if (mp->is_ipv6)
1376 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1377 (void *) mp->address,
1378 mp->address_length, is_del);
1380 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1381 (void *) mp->address,
1382 mp->address_length, is_del);
1384 BAD_SW_IF_INDEX_LABEL;
1386 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1390 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1393 u32 table_id = ntohl (mp->vrf_id);
1394 u32 sw_if_index = ntohl (mp->sw_if_index);
1395 vl_api_sw_interface_set_table_reply_t *rmp;
1396 stats_main_t *sm = &stats_main;
1398 VALIDATE_SW_IF_INDEX (mp);
1400 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1404 ip6_main_t *im = &ip6_main;
1405 ip6_fib_t *fib = find_ip6_fib_by_table_index_or_id (im, table_id,
1406 IP6_ROUTE_FLAG_TABLE_ID);
1409 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1410 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1414 rv = VNET_API_ERROR_NO_SUCH_FIB;
1419 ip4_main_t *im = &ip4_main;
1420 ip4_fib_t *fib = find_ip4_fib_by_table_index_or_id
1421 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1423 /* Truthfully this can't fail */
1426 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1427 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1431 rv = VNET_API_ERROR_NO_SUCH_FIB;
1436 BAD_SW_IF_INDEX_LABEL;
1438 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1442 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1444 vlib_main_t *vm = vlib_get_main ();
1445 ip4_main_t *im4 = &ip4_main;
1446 ip6_main_t *im6 = &ip6_main;
1447 vl_api_sw_interface_set_vpath_reply_t *rmp;
1450 u32 sw_if_index = ntohl (mp->sw_if_index);
1451 ip4_main_t *ip4m = &ip4_main;
1452 ip6_main_t *ip6m = &ip6_main;
1453 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1454 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1455 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1456 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1457 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1458 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1460 VALIDATE_SW_IF_INDEX (mp);
1462 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1465 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1466 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1468 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1469 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1470 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1471 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1473 im4->ip4_multicast_rx_feature_vpath,
1475 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1476 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1477 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1479 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1480 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1481 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1482 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1484 im6->ip6_multicast_rx_feature_vpath,
1486 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1490 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1491 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1493 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1494 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1495 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1496 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1498 im4->ip4_multicast_rx_feature_vpath,
1500 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1501 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1502 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1504 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1505 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1506 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1507 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1509 im6->ip6_multicast_rx_feature_vpath,
1511 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1514 BAD_SW_IF_INDEX_LABEL;
1516 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1520 vl_api_sw_interface_set_l2_xconnect_t_handler
1521 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1523 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1525 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1526 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1527 vlib_main_t *vm = vlib_get_main ();
1528 vnet_main_t *vnm = vnet_get_main ();
1530 VALIDATE_RX_SW_IF_INDEX (mp);
1534 VALIDATE_TX_SW_IF_INDEX (mp);
1535 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1536 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1540 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1543 BAD_RX_SW_IF_INDEX_LABEL;
1544 BAD_TX_SW_IF_INDEX_LABEL;
1546 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1550 vl_api_sw_interface_set_l2_bridge_t_handler
1551 (vl_api_sw_interface_set_l2_bridge_t * mp)
1553 bd_main_t *bdm = &bd_main;
1554 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1556 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1557 u32 bd_id = ntohl (mp->bd_id);
1561 vlib_main_t *vm = vlib_get_main ();
1562 vnet_main_t *vnm = vnet_get_main ();
1564 VALIDATE_RX_SW_IF_INDEX (mp);
1566 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1570 //VALIDATE_TX_SW_IF_INDEX(mp);
1571 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1572 rx_sw_if_index, bd_index, bvi, shg, 0);
1576 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1579 BAD_RX_SW_IF_INDEX_LABEL;
1581 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1585 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1587 vlib_main_t *vm = vlib_get_main ();
1588 bd_main_t *bdm = &bd_main;
1589 vl_api_bridge_domain_add_del_reply_t *rmp;
1591 u32 enable_flags = 0, disable_flags = 0;
1592 u32 bd_id = ntohl (mp->bd_id);
1597 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1600 enable_flags |= L2_FLOOD;
1602 disable_flags |= L2_FLOOD;
1605 enable_flags |= L2_UU_FLOOD;
1607 disable_flags |= L2_UU_FLOOD;
1610 enable_flags |= L2_FWD;
1612 disable_flags |= L2_FWD;
1615 enable_flags |= L2_ARP_TERM;
1617 disable_flags |= L2_ARP_TERM;
1620 enable_flags |= L2_LEARN;
1622 disable_flags |= L2_LEARN;
1625 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1628 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1632 rv = bd_delete_bd_index (bdm, bd_id);
1634 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1638 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1640 clib_warning ("BUG");
1644 vl_api_bridge_domain_sw_if_details_t_handler
1645 (vl_api_bridge_domain_sw_if_details_t * mp)
1647 clib_warning ("BUG");
1651 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1652 l2_bridge_domain_t * bd_config,
1653 u32 n_sw_ifs, u32 context)
1655 vl_api_bridge_domain_details_t *mp;
1657 mp = vl_msg_api_alloc (sizeof (*mp));
1658 memset (mp, 0, sizeof (*mp));
1659 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1660 mp->bd_id = ntohl (bd_config->bd_id);
1661 mp->flood = bd_feature_flood (bd_config);
1662 mp->uu_flood = bd_feature_uu_flood (bd_config);
1663 mp->forward = bd_feature_forward (bd_config);
1664 mp->learn = bd_feature_learn (bd_config);
1665 mp->arp_term = bd_feature_arp_term (bd_config);
1666 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1667 mp->n_sw_ifs = ntohl (n_sw_ifs);
1668 mp->context = context;
1670 vl_msg_api_send_shmem (q, (u8 *) & mp);
1674 send_bd_sw_if_details (l2input_main_t * l2im,
1675 unix_shared_memory_queue_t * q,
1676 l2_flood_member_t * member, u32 bd_id, u32 context)
1678 vl_api_bridge_domain_sw_if_details_t *mp;
1679 l2_input_config_t *input_cfg;
1681 mp = vl_msg_api_alloc (sizeof (*mp));
1682 memset (mp, 0, sizeof (*mp));
1683 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1684 mp->bd_id = ntohl (bd_id);
1685 mp->sw_if_index = ntohl (member->sw_if_index);
1686 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1687 mp->shg = input_cfg->shg;
1688 mp->context = context;
1690 vl_msg_api_send_shmem (q, (u8 *) & mp);
1694 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1696 bd_main_t *bdm = &bd_main;
1697 l2input_main_t *l2im = &l2input_main;
1698 unix_shared_memory_queue_t *q;
1699 l2_bridge_domain_t *bd_config;
1700 u32 bd_id, bd_index;
1703 q = vl_api_client_index_to_input_queue (mp->client_index);
1708 bd_id = ntohl (mp->bd_id);
1710 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1711 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1712 for (; bd_index < end; bd_index++)
1714 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1715 /* skip dummy bd_id 0 */
1716 if (bd_config && (bd_config->bd_id > 0))
1719 l2_flood_member_t *m;
1721 n_sw_ifs = vec_len (bd_config->members);
1722 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1724 vec_foreach (m, bd_config->members)
1726 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1733 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1735 bd_main_t *bdm = &bd_main;
1736 l2input_main_t *l2im = &l2input_main;
1737 vl_api_l2fib_add_del_reply_t *rmp;
1740 u32 sw_if_index = ntohl (mp->sw_if_index);
1741 u32 bd_id = ntohl (mp->bd_id);
1750 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1753 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1754 goto bad_sw_if_index;
1760 VALIDATE_SW_IF_INDEX (mp);
1761 if (vec_len (l2im->configs) <= sw_if_index)
1763 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1764 goto bad_sw_if_index;
1768 l2_input_config_t *config;
1769 config = vec_elt_at_index (l2im->configs, sw_if_index);
1770 if (config->bridge == 0)
1772 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1773 goto bad_sw_if_index;
1776 static_mac = mp->static_mac ? 1 : 0;
1777 filter_mac = mp->filter_mac ? 1 : 0;
1778 bvi_mac = mp->bvi_mac ? 1 : 0;
1779 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1784 l2fib_del_entry (mac, bd_index);
1787 BAD_SW_IF_INDEX_LABEL;
1789 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1793 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1795 vl_api_l2_flags_reply_t *rmp;
1797 u32 sw_if_index = ntohl (mp->sw_if_index);
1798 u32 flags = ntohl (mp->feature_bitmap);
1801 VALIDATE_SW_IF_INDEX (mp);
1804 if (flags & L2INPUT_FEAT_ ## a) \
1805 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1806 foreach_l2input_feat;
1809 BAD_SW_IF_INDEX_LABEL;
1812 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1814 rmp->resulting_feature_bitmap = ntohl(rbm);
1820 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1822 vlib_main_t *vm = vlib_get_main ();
1823 bd_main_t *bdm = &bd_main;
1824 vl_api_bridge_flags_reply_t *rmp;
1826 u32 bd_id = ntohl (mp->bd_id);
1828 u32 flags = ntohl (mp->feature_bitmap);
1831 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1834 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1840 bd_set_flags (vm, bd_index, flags, mp->is_set);
1844 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1846 rmp->resulting_feature_bitmap = ntohl(flags);
1852 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1854 bd_main_t *bdm = &bd_main;
1855 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1857 u32 bd_id = ntohl (mp->bd_id);
1861 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1864 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1869 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1870 mp->mac_address, mp->is_ipv6, mp->is_add))
1871 rv = VNET_API_ERROR_UNSPECIFIED;
1874 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1878 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1881 vl_api_tap_connect_reply_t *rmp;
1882 unix_shared_memory_queue_t *q;
1883 u32 sw_if_index = (u32) ~ 0;
1885 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1886 mp->use_random_mac ? 0 : mp->mac_address,
1887 &sw_if_index, mp->renumber,
1888 ntohl (mp->custom_dev_instance));
1890 q = vl_api_client_index_to_input_queue (mp->client_index);
1894 rmp = vl_msg_api_alloc (sizeof (*rmp));
1895 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1896 rmp->context = mp->context;
1897 rmp->retval = ntohl (rv);
1898 rmp->sw_if_index = ntohl (sw_if_index);
1900 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1904 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
1907 vl_api_tap_modify_reply_t *rmp;
1908 unix_shared_memory_queue_t *q;
1909 u32 sw_if_index = (u32) ~ 0;
1911 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1912 mp->use_random_mac ? 0 : mp->mac_address,
1913 &sw_if_index, mp->renumber,
1914 ntohl (mp->custom_dev_instance));
1916 q = vl_api_client_index_to_input_queue (mp->client_index);
1920 rmp = vl_msg_api_alloc (sizeof (*rmp));
1921 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1922 rmp->context = mp->context;
1923 rmp->retval = ntohl (rv);
1924 rmp->sw_if_index = ntohl (sw_if_index);
1926 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1930 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
1933 vpe_api_main_t *vam = &vpe_api_main;
1934 vl_api_tap_delete_reply_t *rmp;
1935 unix_shared_memory_queue_t *q;
1936 u32 sw_if_index = ntohl (mp->sw_if_index);
1938 rv = vnet_tap_delete (vm, sw_if_index);
1940 q = vl_api_client_index_to_input_queue (mp->client_index);
1944 rmp = vl_msg_api_alloc (sizeof (*rmp));
1945 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1946 rmp->context = mp->context;
1947 rmp->retval = ntohl (rv);
1949 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1952 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1956 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1958 vl_api_create_vlan_subif_reply_t *rmp;
1959 vnet_main_t *vnm = vnet_get_main ();
1960 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1961 vnet_hw_interface_t *hi;
1964 vnet_sw_interface_t template;
1966 vnet_interface_main_t *im = &vnm->interface_main;
1967 u64 sup_and_sub_key;
1969 unix_shared_memory_queue_t *q;
1970 clib_error_t *error;
1972 VALIDATE_SW_IF_INDEX (mp);
1974 hw_if_index = ntohl (mp->sw_if_index);
1975 hi = vnet_get_hw_interface (vnm, hw_if_index);
1977 id = ntohl (mp->vlan_id);
1978 if (id == 0 || id > 4095)
1980 rv = VNET_API_ERROR_INVALID_VLAN;
1984 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1986 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1989 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1993 kp = clib_mem_alloc (sizeof (*kp));
1994 *kp = sup_and_sub_key;
1996 memset (&template, 0, sizeof (template));
1997 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1998 template.sup_sw_if_index = hi->sw_if_index;
1999 template.sub.id = id;
2000 template.sub.eth.raw_flags = 0;
2001 template.sub.eth.flags.one_tag = 1;
2002 template.sub.eth.outer_vlan_id = id;
2003 template.sub.eth.flags.exact_match = 1;
2005 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2008 clib_error_report (error);
2009 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2012 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2013 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2015 BAD_SW_IF_INDEX_LABEL;
2018 q = vl_api_client_index_to_input_queue (mp->client_index);
2022 rmp = vl_msg_api_alloc (sizeof (*rmp));
2023 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2024 rmp->context = mp->context;
2025 rmp->retval = ntohl (rv);
2026 rmp->sw_if_index = ntohl (sw_if_index);
2027 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2031 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2033 vl_api_create_subif_reply_t *rmp;
2034 vnet_main_t *vnm = vnet_get_main ();
2035 u32 sw_if_index = ~0;
2038 vnet_sw_interface_t *si;
2039 vnet_hw_interface_t *hi;
2040 vnet_sw_interface_t template;
2042 vnet_interface_main_t *im = &vnm->interface_main;
2043 u64 sup_and_sub_key;
2045 clib_error_t *error;
2047 VALIDATE_SW_IF_INDEX (mp);
2049 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2050 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2052 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2054 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2058 sw_if_index = si->sw_if_index;
2059 sub_id = ntohl (mp->sub_id);
2061 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2063 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2067 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2068 sw_if_index, sub_id);
2069 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2073 kp = clib_mem_alloc (sizeof (*kp));
2074 *kp = sup_and_sub_key;
2076 memset (&template, 0, sizeof (template));
2077 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2078 template.sup_sw_if_index = sw_if_index;
2079 template.sub.id = sub_id;
2080 template.sub.eth.flags.no_tags = mp->no_tags;
2081 template.sub.eth.flags.one_tag = mp->one_tag;
2082 template.sub.eth.flags.two_tags = mp->two_tags;
2083 template.sub.eth.flags.dot1ad = mp->dot1ad;
2084 template.sub.eth.flags.exact_match = mp->exact_match;
2085 template.sub.eth.flags.default_sub = mp->default_sub;
2086 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2087 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2088 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2089 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2091 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2094 clib_error_report (error);
2095 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2099 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2100 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2102 BAD_SW_IF_INDEX_LABEL;
2107 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2109 rmp->sw_if_index = ntohl(sw_if_index);
2115 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2118 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2120 stats_main_t *sm = &stats_main;
2121 u32 tunnel_sw_if_index = ~0;
2123 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2125 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2126 (ip4_address_t *) (mp->dst_address),
2127 (ip4_address_t *) (mp->intfc_address),
2128 (u32) (mp->intfc_address_length),
2129 ntohl (mp->inner_vrf_id),
2130 ntohl (mp->outer_vrf_id),
2131 &tunnel_sw_if_index,
2132 mp->l2_only, mp->is_add);
2136 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2138 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2144 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2145 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2147 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2149 stats_main_t *sm = &stats_main;
2150 u32 tunnel_sw_if_index;
2152 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2154 rv = vnet_mpls_ethernet_add_del_tunnel
2155 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2156 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2157 ntohl (mp->tx_sw_if_index),
2158 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2163 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2165 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2171 * This piece of misery brought to you because the control-plane
2172 * can't figure out the tx interface + dst-mac address all by itself
2174 static int mpls_ethernet_add_del_tunnel_2_t_handler
2175 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2177 pending_route_t *pr;
2178 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2179 vnet_main_t *vnm = vnet_get_main ();
2180 vlib_main_t *vm = vlib_get_main ();
2181 stats_main_t *sm = &stats_main;
2182 vpe_api_main_t *vam = &vpe_api_main;
2183 u32 inner_fib_index, outer_fib_index;
2184 ip4_main_t *im = &ip4_main;
2185 ip_lookup_main_t *lm = &im->lookup_main;
2186 ip_adjacency_t *adj = 0;
2189 u8 *dst_mac_address;
2193 u32 tunnel_sw_if_index;
2195 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2197 return VNET_API_ERROR_NO_SUCH_FIB;
2199 outer_fib_index = p[0];
2202 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2204 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2206 inner_fib_index = p[0];
2208 if (inner_fib_index == outer_fib_index)
2209 return VNET_API_ERROR_INVALID_VALUE;
2211 lookup_result = ip4_fib_lookup_with_table
2212 (im, outer_fib_index,
2213 (ip4_address_t *) mp->next_hop_ip4_address_in_outer_vrf,
2214 1 /* disable default route */ );
2216 adj = ip_get_adjacency (lm, lookup_result);
2217 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2219 if (mp->is_add && mp->resolve_if_needed)
2221 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2223 pool_get (vam->pending_routes, pr);
2224 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2226 clib_memcpy (pme, mp, sizeof (*pme));
2227 /* recursion block, "just in case" */
2228 pme->resolve_if_needed = 0;
2229 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2230 pme->resolve_opaque = tx_sw_if_index;
2231 vnet_register_ip4_arp_resolution_event
2233 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2234 vpe_resolver_process_node.index,
2235 RESOLUTION_EVENT, pr - vam->pending_routes);
2237 vlib_process_signal_event
2238 (vm, vpe_resolver_process_node.index,
2239 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2241 /* The interface may be down, etc. */
2242 e = ip4_probe_neighbor
2243 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2247 clib_error_report (e);
2249 return VNET_API_ERROR_IN_PROGRESS;
2253 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2254 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2257 vnet_rewrite_get_data_internal
2258 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2260 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2262 rv = vnet_mpls_ethernet_add_del_tunnel
2263 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2264 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2265 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2273 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2274 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2276 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2279 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2281 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2286 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2288 vl_api_mpls_add_del_encap_reply_t *rmp;
2293 vec_reset_length (labels);
2295 for (i = 0; i < mp->nlabels; i++)
2296 vec_add1 (labels, ntohl (mp->labels[i]));
2299 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2300 ntohl (mp->vrf_id), labels,
2301 ~0 /* policy_tunnel_index */ ,
2302 0 /* no_dst_hash */ ,
2306 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2310 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2312 vl_api_mpls_add_del_decap_reply_t *rmp;
2315 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2316 ntohl (mp->label), ntohl (mp->next_index),
2317 mp->s_bit, mp->is_add);
2319 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2323 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2325 vl_api_proxy_arp_add_del_reply_t *rmp;
2328 ip4_main_t *im = &ip4_main;
2329 stats_main_t *sm = &stats_main;
2330 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2331 ip4_address_t * hi_addr,
2332 u32 fib_index, int is_del);
2335 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2337 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2341 rv = VNET_API_ERROR_NO_SUCH_FIB;
2347 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2348 (ip4_address_t *) mp->hi_address,
2349 fib_index, mp->is_add == 0);
2353 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2357 vl_api_proxy_arp_intfc_enable_disable_t_handler
2358 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2361 vnet_main_t *vnm = vnet_get_main ();
2362 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2363 vnet_sw_interface_t *si;
2366 VALIDATE_SW_IF_INDEX (mp);
2368 sw_if_index = ntohl (mp->sw_if_index);
2370 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2372 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2376 si = vnet_get_sw_interface (vnm, sw_if_index);
2380 if (mp->enable_disable)
2381 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2383 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2385 BAD_SW_IF_INDEX_LABEL;
2388 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2392 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2395 vl_api_ip_neighbor_add_del_reply_t *rmp;
2396 vnet_main_t *vnm = vnet_get_main ();
2399 stats_main_t *sm = &stats_main;
2401 VALIDATE_SW_IF_INDEX (mp);
2403 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2408 rv = vnet_set_ip6_ethernet_neighbor
2409 (vm, ntohl (mp->sw_if_index),
2410 (ip6_address_t *) (mp->dst_address),
2411 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2413 rv = vnet_unset_ip6_ethernet_neighbor
2414 (vm, ntohl (mp->sw_if_index),
2415 (ip6_address_t *) (mp->dst_address),
2416 mp->mac_address, sizeof (mp->mac_address));
2420 ip4_main_t *im = &ip4_main;
2421 ip_lookup_main_t *lm = &im->lookup_main;
2422 ethernet_arp_ip4_over_ethernet_address_t a;
2424 ip_adjacency_t *nh_adj;
2426 uword *p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2429 rv = VNET_API_ERROR_NO_SUCH_FIB;
2435 * Unfortunately, folks have a penchant for
2436 * adding interface addresses to the ARP cache, and
2437 * wondering why the forwarder eventually ASSERTs...
2439 ai = ip4_fib_lookup_with_table
2440 (im, fib_index, (ip4_address_t *) (mp->dst_address),
2441 1 /* disable default route */ );
2445 nh_adj = ip_get_adjacency (lm, ai);
2446 /* Never allow manipulation of a local adj! */
2447 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL)
2449 clib_warning ("%U matches local adj",
2451 (ip4_address_t *) (mp->dst_address));
2452 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2457 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2458 clib_memcpy (&a.ip4, mp->dst_address, 4);
2461 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2462 fib_index, &a, mp->is_static);
2464 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2468 BAD_SW_IF_INDEX_LABEL;
2471 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2475 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2478 vpe_main_t *rm = &vpe_main;
2479 ip4_main_t *im4 = &ip4_main;
2480 ip6_main_t *im6 = &ip6_main;
2481 ip_lookup_main_t *lm;
2487 u32 adj_index, sw_if_index;
2488 vl_api_is_address_reachable_t *rmp;
2489 ip_adjacency_t *adj;
2490 unix_shared_memory_queue_t *q;
2492 q = vl_api_client_index_to_input_queue (mp->client_index);
2495 increment_missing_api_client_counter (rm->vlib_main);
2499 rmp = vl_msg_api_alloc (sizeof (*rmp));
2500 clib_memcpy (rmp, mp, sizeof (*rmp));
2502 sw_if_index = mp->next_hop_sw_if_index;
2503 clib_memcpy (&addr, mp->address, sizeof (addr));
2506 lm = &im6->lookup_main;
2507 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2511 lm = &im4->lookup_main;
2512 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2514 if (adj_index == ~0)
2519 adj = ip_get_adjacency (lm, adj_index);
2521 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2522 && adj->rewrite_header.sw_if_index == sw_if_index)
2528 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2529 && adj->rewrite_header.sw_if_index == sw_if_index)
2532 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2534 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2536 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2545 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2550 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2552 clib_warning ("BUG");
2556 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2558 vl_api_sw_interface_set_flags_reply_t *rmp;
2559 vnet_main_t *vnm = vnet_get_main ();
2561 clib_error_t *error;
2564 VALIDATE_SW_IF_INDEX (mp);
2566 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2568 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2572 clib_error_report (error);
2575 BAD_SW_IF_INDEX_LABEL;
2576 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2580 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2583 vl_api_sw_interface_clear_stats_reply_t *rmp;
2585 vnet_main_t *vnm = vnet_get_main ();
2586 vnet_interface_main_t *im = &vnm->interface_main;
2587 vlib_simple_counter_main_t *sm;
2588 vlib_combined_counter_main_t *cm;
2589 static vnet_main_t **my_vnet_mains;
2590 int i, j, n_counters;
2593 if (mp->sw_if_index != ~0)
2594 VALIDATE_SW_IF_INDEX (mp);
2596 vec_reset_length (my_vnet_mains);
2598 for (i = 0; i < vec_len (vnet_mains); i++)
2601 vec_add1 (my_vnet_mains, vnet_mains[i]);
2604 if (vec_len (vnet_mains) == 0)
2605 vec_add1 (my_vnet_mains, vnm);
2607 n_counters = vec_len (im->combined_sw_if_counters);
2609 for (j = 0; j < n_counters; j++)
2611 for (i = 0; i < vec_len (my_vnet_mains); i++)
2613 im = &my_vnet_mains[i]->interface_main;
2614 cm = im->combined_sw_if_counters + j;
2615 if (mp->sw_if_index == (u32) ~ 0)
2616 vlib_clear_combined_counters (cm);
2618 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2622 n_counters = vec_len (im->sw_if_counters);
2624 for (j = 0; j < n_counters; j++)
2626 for (i = 0; i < vec_len (my_vnet_mains); i++)
2628 im = &my_vnet_mains[i]->interface_main;
2629 sm = im->sw_if_counters + j;
2630 if (mp->sw_if_index == (u32) ~ 0)
2631 vlib_clear_simple_counters (sm);
2633 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2637 BAD_SW_IF_INDEX_LABEL;
2639 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2643 send_sw_interface_details (vpe_api_main_t * am,
2644 unix_shared_memory_queue_t * q,
2645 vnet_sw_interface_t * swif,
2646 u8 * interface_name, u32 context)
2648 vl_api_sw_interface_details_t *mp;
2649 vnet_hw_interface_t *hi;
2651 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2653 mp = vl_msg_api_alloc (sizeof (*mp));
2654 memset (mp, 0, sizeof (*mp));
2655 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2656 mp->sw_if_index = ntohl (swif->sw_if_index);
2657 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2658 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2659 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2660 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2661 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2662 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2663 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2664 mp->link_mtu = ntohs (hi->max_packet_bytes);
2665 mp->context = context;
2667 strncpy ((char *) mp->interface_name,
2668 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2670 /* Send the L2 address for ethernet physical intfcs */
2671 if (swif->sup_sw_if_index == swif->sw_if_index
2672 && hi->hw_class_index == ethernet_hw_interface_class.index)
2674 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2675 ethernet_interface_t *ei;
2677 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2678 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2679 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2680 mp->l2_address_length = ntohl (sizeof (ei->address));
2682 else if (swif->sup_sw_if_index != swif->sw_if_index)
2684 vnet_sub_interface_t *sub = &swif->sub;
2685 mp->sub_id = ntohl (sub->id);
2686 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2687 mp->sub_number_of_tags =
2688 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2689 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2690 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2691 mp->sub_exact_match = sub->eth.flags.exact_match;
2692 mp->sub_default = sub->eth.flags.default_sub;
2693 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2694 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2696 /* vlan tag rewrite data */
2697 u32 vtr_op = L2_VTR_DISABLED;
2698 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2700 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2701 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2703 // error - default to disabled
2704 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2705 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2710 mp->vtr_op = ntohl (vtr_op);
2711 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2712 mp->vtr_tag1 = ntohl (vtr_tag1);
2713 mp->vtr_tag2 = ntohl (vtr_tag2);
2717 vl_msg_api_send_shmem (q, (u8 *) & mp);
2721 send_sw_interface_flags (vpe_api_main_t * am,
2722 unix_shared_memory_queue_t * q,
2723 vnet_sw_interface_t * swif)
2725 vl_api_sw_interface_set_flags_t *mp;
2726 vnet_main_t *vnm = am->vnet_main;
2728 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2730 mp = vl_msg_api_alloc (sizeof (*mp));
2731 memset (mp, 0, sizeof (*mp));
2732 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2733 mp->sw_if_index = ntohl (swif->sw_if_index);
2735 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2736 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2737 vl_msg_api_send_shmem (q, (u8 *) & mp);
2740 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2741 unix_shared_memory_queue_t * q,
2743 __attribute__ ((unused));
2746 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2747 unix_shared_memory_queue_t * q,
2750 vl_api_sw_interface_set_flags_t *mp;
2752 mp = vl_msg_api_alloc (sizeof (*mp));
2753 memset (mp, 0, sizeof (*mp));
2754 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2755 mp->sw_if_index = ntohl (sw_if_index);
2757 mp->admin_up_down = 0;
2758 mp->link_up_down = 0;
2760 vl_msg_api_send_shmem (q, (u8 *) & mp);
2764 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2766 vpe_api_main_t *am = &vpe_api_main;
2767 vnet_sw_interface_t *swif;
2768 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2769 u8 *filter_string = 0, *name_string = 0;
2770 unix_shared_memory_queue_t *q;
2771 char *strcasestr (char *, char *); /* lnx hdr file botch */
2773 q = vl_api_client_index_to_input_queue (mp->client_index);
2778 if (mp->name_filter_valid)
2780 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2781 filter_string = format (0, "%s%c", mp->name_filter, 0);
2785 pool_foreach (swif, im->sw_interfaces,
2787 name_string = format (name_string, "%U%c",
2788 format_vnet_sw_interface_name,
2789 am->vnet_main, swif, 0);
2791 if (mp->name_filter_valid == 0 ||
2792 strcasestr((char *) name_string, (char *) filter_string)) {
2794 send_sw_interface_details (am, q, swif, name_string, mp->context);
2796 _vec_len (name_string) = 0;
2800 vec_free (name_string);
2801 vec_free (filter_string);
2805 send_oam_event (oam_target_t * t)
2807 vpe_api_main_t *vam = &vpe_api_main;
2808 unix_shared_memory_queue_t *q;
2809 vpe_client_registration_t *reg;
2810 vl_api_oam_event_t *mp;
2813 pool_foreach(reg, vam->oam_events_registrations,
2815 q = vl_api_client_index_to_input_queue (reg->client_index);
2818 mp = vl_msg_api_alloc (sizeof (*mp));
2819 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2820 clib_memcpy (mp->dst_address, &t->dst_address,
2821 sizeof (mp->dst_address));
2822 mp->state = t->state;
2823 vl_msg_api_send_shmem (q, (u8 *)&mp);
2830 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2832 vl_api_oam_add_del_reply_t *rmp;
2835 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2836 (ip4_address_t *) mp->dst_address,
2837 ntohl (mp->vrf_id), (int) (mp->is_add));
2839 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2843 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2845 stats_main_t *sm = &stats_main;
2846 vnet_interface_main_t *im = sm->interface_main;
2847 vl_api_vnet_summary_stats_reply_t *rmp;
2848 vlib_combined_counter_main_t *cm;
2851 u64 total_pkts[VLIB_N_RX_TX];
2852 u64 total_bytes[VLIB_N_RX_TX];
2854 unix_shared_memory_queue_t *q =
2855 vl_api_client_index_to_input_queue (mp->client_index);
2860 rmp = vl_msg_api_alloc (sizeof (*rmp));
2861 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2862 rmp->context = mp->context;
2865 memset (total_pkts, 0, sizeof (total_pkts));
2866 memset (total_bytes, 0, sizeof (total_bytes));
2868 vnet_interface_counter_lock (im);
2870 vec_foreach (cm, im->combined_sw_if_counters)
2872 which = cm - im->combined_sw_if_counters;
2874 for (i = 0; i < vec_len (cm->maxi); i++)
2876 vlib_get_combined_counter (cm, i, &v);
2877 total_pkts[which] += v.packets;
2878 total_bytes[which] += v.bytes;
2881 vnet_interface_counter_unlock (im);
2883 /* Note: in HOST byte order! */
2884 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2885 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2886 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2887 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2888 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2890 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2894 typedef CLIB_PACKED (struct {
2895 ip4_address_t address;
2896 u32 address_length: 6;
2902 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2904 vnet_main_t *vnm = vnet_get_main ();
2905 vnet_interface_main_t *im = &vnm->interface_main;
2906 ip4_main_t *im4 = &ip4_main;
2907 static ip4_route_t *routes;
2908 static u32 *sw_if_indices_to_shut;
2909 stats_main_t *sm = &stats_main;
2914 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2915 u32 target_fib_id = ntohl (mp->vrf_id);
2917 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2919 vec_foreach (fib, im4->fibs)
2921 vnet_sw_interface_t *si;
2923 if (fib->table_id != target_fib_id)
2926 /* remove any mpls/gre tunnels in this fib */
2927 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2929 /* remove any mpls encap/decap labels */
2930 mpls_fib_reset_labels (fib->table_id);
2932 /* remove any proxy arps in this fib */
2933 vnet_proxy_arp_fib_reset (fib->table_id);
2935 /* Set the flow hash for this fib to the default */
2936 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2938 vec_reset_length (sw_if_indices_to_shut);
2940 /* Shut down interfaces in this FIB / clean out intfc routes */
2942 pool_foreach (si, im->sw_interfaces,
2944 u32 sw_if_index = si->sw_if_index;
2946 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2947 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2949 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2953 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
2955 sw_if_index = sw_if_indices_to_shut[i];
2956 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2958 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2959 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2960 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2963 vec_reset_length (routes);
2965 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++)
2967 uword *hash = fib->adj_index_by_dst_address[i];
2971 x.address_length = i;
2974 hash_foreach_pair (p, hash,
2976 x.address.data_u32 = p->key;
2977 vec_add1 (routes, x);
2982 vec_foreach (r, routes)
2984 ip4_add_del_route_args_t a;
2986 memset (&a, 0, sizeof (a));
2987 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2988 a.table_index_or_table_id = fib - im4->fibs;
2989 a.dst_address = r->address;
2990 a.dst_address_length = r->address_length;
2993 ip4_add_del_route (im4, &a);
2994 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2995 IP4_ROUTE_FLAG_FIB_INDEX);
2999 } /* vec_foreach (fib) */
3007 ip6_address_t address;
3015 ip6_route_t **routep;
3016 } add_routes_in_fib_arg_t;
3019 add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
3021 add_routes_in_fib_arg_t *ap = arg;
3023 if (kvp->key[2] >> 32 == ap->fib_index)
3025 ip6_address_t *addr;
3027 addr = (ip6_address_t *) kvp;
3028 vec_add2 (*ap->routep, r, 1);
3029 r->address = addr[0];
3030 r->address_length = kvp->key[2] & 0xFF;
3031 r->index = kvp->value;
3036 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3038 vnet_main_t *vnm = vnet_get_main ();
3039 vnet_interface_main_t *im = &vnm->interface_main;
3040 ip6_main_t *im6 = &ip6_main;
3041 stats_main_t *sm = &stats_main;
3042 static ip6_route_t *routes;
3043 static u32 *sw_if_indices_to_shut;
3048 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3049 u32 target_fib_id = ntohl (mp->vrf_id);
3050 add_routes_in_fib_arg_t _a, *a = &_a;
3051 clib_bihash_24_8_t *h = &im6->ip6_lookup_table;
3053 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3055 vec_foreach (fib, im6->fibs)
3057 vnet_sw_interface_t *si;
3059 if (fib->table_id != target_fib_id)
3062 vec_reset_length (sw_if_indices_to_shut);
3064 /* Shut down interfaces in this FIB / clean out intfc routes */
3066 pool_foreach (si, im->sw_interfaces,
3068 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3070 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3074 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3076 sw_if_index = sw_if_indices_to_shut[i];
3077 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3079 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3080 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3081 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3084 vec_reset_length (routes);
3086 a->fib_index = fib - im6->fibs;
3087 a->routep = &routes;
3089 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
3091 vec_foreach (r, routes)
3093 ip6_add_del_route_args_t a;
3095 memset (&a, 0, sizeof (a));
3096 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
3097 a.table_index_or_table_id = fib - im6->fibs;
3098 a.dst_address = r->address;
3099 a.dst_address_length = r->address_length;
3102 ip6_add_del_route (im6, &a);
3103 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
3104 IP6_ROUTE_FLAG_FIB_INDEX);
3107 /* Reinstall the neighbor / router discovery routes */
3108 vnet_ip6_fib_init (im6, fib - im6->fibs);
3110 } /* vec_foreach (fib) */
3117 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3120 vl_api_reset_fib_reply_t *rmp;
3123 rv = ip6_reset_fib_t_handler (mp);
3125 rv = ip4_reset_fib_t_handler (mp);
3127 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3132 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3134 vl_api_dhcp_proxy_config_reply_t *rmp;
3137 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3138 (ip4_address_t *) (&mp->dhcp_src_address),
3139 (u32) ntohl (mp->vrf_id),
3140 (int) mp->insert_circuit_id,
3141 (int) (mp->is_add == 0));
3143 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3148 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3150 vl_api_dhcp_proxy_config_reply_t *rmp;
3153 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3154 (ip6_address_t *) (&mp->dhcp_src_address),
3155 (u32) ntohl (mp->vrf_id),
3156 (int) mp->insert_circuit_id,
3157 (int) (mp->is_add == 0));
3159 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3163 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3165 vl_api_dhcp_proxy_config_reply_t *rmp;
3168 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3169 (ip4_address_t *) (&mp->dhcp_src_address),
3170 (u32) ntohl (mp->rx_vrf_id),
3171 (u32) ntohl (mp->server_vrf_id),
3172 (int) mp->insert_circuit_id,
3173 (int) (mp->is_add == 0));
3175 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3180 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3182 vl_api_dhcp_proxy_config_reply_t *rmp;
3186 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3187 (ip6_address_t *) (&mp->dhcp_src_address),
3188 (u32) ntohl (mp->rx_vrf_id),
3189 (u32) ntohl (mp->server_vrf_id),
3190 (int) mp->insert_circuit_id,
3191 (int) (mp->is_add == 0));
3193 rv = VNET_API_ERROR_UNIMPLEMENTED;
3196 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3201 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3203 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3206 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3209 (int) mp->is_add == 0);
3211 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3213 ntohl (mp->fib_id), (int) mp->is_add == 0);
3215 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3219 static void vl_api_dhcp_proxy_config_t_handler
3220 (vl_api_dhcp_proxy_config_t * mp)
3222 if (mp->is_ipv6 == 0)
3223 dhcpv4_proxy_config (mp);
3225 dhcpv6_proxy_config (mp);
3228 static void vl_api_dhcp_proxy_config_2_t_handler
3229 (vl_api_dhcp_proxy_config_2_t * mp)
3231 if (mp->is_ipv6 == 0)
3232 dhcpv4_proxy_config_2 (mp);
3234 dhcpv6_proxy_config_2 (mp);
3238 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3239 u8 is_ipv6, u8 * host_address, u8 * router_address,
3242 unix_shared_memory_queue_t *q;
3243 vl_api_dhcp_compl_event_t *mp;
3245 q = vl_api_client_index_to_input_queue (client_index);
3249 mp = vl_msg_api_alloc (sizeof (*mp));
3250 mp->client_index = client_index;
3252 mp->is_ipv6 = is_ipv6;
3253 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3254 mp->hostname[vec_len (hostname) + 1] = '\n';
3255 clib_memcpy (&mp->host_address[0], host_address, 16);
3256 clib_memcpy (&mp->router_address[0], router_address, 16);
3257 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3259 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3261 vl_msg_api_send_shmem (q, (u8 *) & mp);
3264 static void vl_api_dhcp_client_config_t_handler
3265 (vl_api_dhcp_client_config_t * mp)
3267 vlib_main_t *vm = vlib_get_main ();
3268 vl_api_dhcp_client_config_reply_t *rmp;
3271 VALIDATE_SW_IF_INDEX (mp);
3273 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3274 mp->hostname, mp->is_add, mp->client_index,
3275 mp->want_dhcp_event ? dhcp_compl_event_callback :
3278 BAD_SW_IF_INDEX_LABEL;
3280 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3284 vl_api_sw_interface_ip6nd_ra_config_t_handler
3285 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3287 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3289 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3292 is_no = mp->is_no == 1;
3293 suppress = mp->suppress == 1;
3294 managed = mp->managed == 1;
3295 other = mp->other == 1;
3296 ll_option = mp->ll_option == 1;
3297 send_unicast = mp->send_unicast == 1;
3298 cease = mp->cease == 1;
3299 default_router = mp->default_router == 1;
3301 VALIDATE_SW_IF_INDEX (mp);
3303 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3304 suppress, managed, other,
3305 ll_option, send_unicast, cease,
3306 default_router, ntohl (mp->lifetime),
3307 ntohl (mp->initial_count),
3308 ntohl (mp->initial_interval),
3309 ntohl (mp->max_interval),
3310 ntohl (mp->min_interval), is_no);
3312 BAD_SW_IF_INDEX_LABEL;
3314 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3318 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3319 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3321 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3323 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3325 VALIDATE_SW_IF_INDEX (mp);
3327 is_no = mp->is_no == 1;
3328 use_default = mp->use_default == 1;
3329 no_advertise = mp->no_advertise == 1;
3330 off_link = mp->off_link == 1;
3331 no_autoconfig = mp->no_autoconfig == 1;
3332 no_onlink = mp->no_onlink == 1;
3334 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3335 (ip6_address_t *) mp->address,
3336 mp->address_length, use_default,
3337 ntohl (mp->val_lifetime),
3338 ntohl (mp->pref_lifetime), no_advertise,
3339 off_link, no_autoconfig, no_onlink, is_no);
3341 BAD_SW_IF_INDEX_LABEL;
3342 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3346 vl_api_sw_interface_ip6_enable_disable_t_handler
3347 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3349 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3350 vnet_main_t *vnm = vnet_get_main ();
3352 clib_error_t *error;
3356 VALIDATE_SW_IF_INDEX (mp);
3359 (mp->enable == 1) ? enable_ip6_interface (vm,
3360 ntohl (mp->sw_if_index)) :
3361 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3365 clib_error_report (error);
3366 rv = VNET_API_ERROR_UNSPECIFIED;
3370 rv = vnm->api_errno;
3373 BAD_SW_IF_INDEX_LABEL;
3375 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3379 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3380 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3382 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3384 clib_error_t *error;
3385 vnet_main_t *vnm = vnet_get_main ();
3389 VALIDATE_SW_IF_INDEX (mp);
3391 error = set_ip6_link_local_address (vm,
3392 ntohl (mp->sw_if_index),
3393 (ip6_address_t *) mp->address,
3394 mp->address_length);
3397 clib_error_report (error);
3398 rv = VNET_API_ERROR_UNSPECIFIED;
3402 rv = vnm->api_errno;
3405 BAD_SW_IF_INDEX_LABEL;
3407 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3411 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3413 vl_api_set_ip_flow_hash_reply_t *rmp;
3414 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3416 clib_warning ("unimplemented...");
3418 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3422 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3424 vl_api_set_ip_flow_hash_reply_t *rmp;
3427 u32 flow_hash_config = 0;
3429 table_id = ntohl (mp->vrf_id);
3431 #define _(a,b) if (mp->a) flow_hash_config |= b;
3432 foreach_flow_hash_bit;
3435 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3437 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3442 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3444 if (mp->is_ipv6 == 0)
3445 set_ip4_flow_hash (mp);
3447 set_ip6_flow_hash (mp);
3450 static void vl_api_sw_interface_set_unnumbered_t_handler
3451 (vl_api_sw_interface_set_unnumbered_t * mp)
3453 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3455 vnet_sw_interface_t *si;
3456 vnet_main_t *vnm = vnet_get_main ();
3457 u32 sw_if_index, unnumbered_sw_if_index;
3459 sw_if_index = ntohl (mp->sw_if_index);
3460 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3463 * The API message field names are backwards from
3464 * the underlying data structure names.
3465 * It's not worth changing them now.
3467 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3468 unnumbered_sw_if_index))
3470 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3474 /* Only check the "use loop0" field when setting the binding */
3476 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3478 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3482 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3486 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3487 si->unnumbered_sw_if_index = sw_if_index;
3491 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3492 si->unnumbered_sw_if_index = (u32) ~ 0;
3496 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3500 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3502 vl_api_create_loopback_reply_t *rmp;
3506 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3509 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3511 rmp->sw_if_index = ntohl (sw_if_index);
3517 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3519 vl_api_delete_loopback_reply_t *rmp;
3523 sw_if_index = ntohl (mp->sw_if_index);
3524 rv = vnet_delete_loopback_interface (sw_if_index);
3526 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3530 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3532 vl_api_control_ping_reply_t *rmp;
3536 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3538 rmp->vpe_pid = ntohl (getpid());
3543 static void vl_api_noprint_control_ping_t_handler
3544 (vl_api_noprint_control_ping_t * mp)
3546 vl_api_noprint_control_ping_reply_t *rmp;
3550 REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY,
3552 rmp->vpe_pid = ntohl (getpid());
3558 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3560 u8 **shmem_vecp = (u8 **) arg;
3563 api_main_t *am = &api_main;
3566 shmem_vec = *shmem_vecp;
3568 offset = vec_len (shmem_vec);
3570 pthread_mutex_lock (&am->vlib_rp->mutex);
3571 oldheap = svm_push_data_heap (am->vlib_rp);
3573 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3575 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3577 svm_pop_heap (oldheap);
3578 pthread_mutex_unlock (&am->vlib_rp->mutex);
3580 *shmem_vecp = shmem_vec;
3585 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3587 vl_api_cli_reply_t *rp;
3588 unix_shared_memory_queue_t *q;
3589 vlib_main_t *vm = vlib_get_main ();
3590 api_main_t *am = &api_main;
3591 unformat_input_t input;
3595 q = vl_api_client_index_to_input_queue (mp->client_index);
3599 rp = vl_msg_api_alloc (sizeof (*rp));
3600 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3601 rp->context = mp->context;
3603 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3605 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3607 pthread_mutex_lock (&am->vlib_rp->mutex);
3608 oldheap = svm_push_data_heap (am->vlib_rp);
3610 vec_add1 (shmem_vec, 0);
3612 svm_pop_heap (oldheap);
3613 pthread_mutex_unlock (&am->vlib_rp->mutex);
3615 rp->reply_in_shmem = (uword) shmem_vec;
3617 vl_msg_api_send_shmem (q, (u8 *) & rp);
3621 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3624 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3625 vnet_main_t *vnm = vnet_get_main ();
3626 clib_error_t *error;
3631 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3633 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3637 clib_error_report (error);
3638 rv = VNET_API_ERROR_UNSPECIFIED;
3642 rv = vnm->api_errno;
3645 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3648 static void vl_api_sr_tunnel_add_del_t_handler
3649 (vl_api_sr_tunnel_add_del_t * mp)
3652 clib_warning ("unimplemented");
3654 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3656 vl_api_sr_tunnel_add_del_reply_t *rmp;
3657 ip6_address_t *segments = 0, *seg;
3658 ip6_address_t *tags = 0, *tag;
3659 ip6_address_t *this_address;
3662 if (mp->n_segments == 0)
3668 memset (a, 0, sizeof (*a));
3669 a->src_address = (ip6_address_t *) & mp->src_address;
3670 a->dst_address = (ip6_address_t *) & mp->dst_address;
3671 a->dst_mask_width = mp->dst_mask_width;
3672 a->flags_net_byte_order = mp->flags_net_byte_order;
3673 a->is_del = (mp->is_add == 0);
3674 a->rx_table_id = ntohl (mp->outer_vrf_id);
3675 a->tx_table_id = ntohl (mp->inner_vrf_id);
3677 a->name = format (0, "%s", mp->name);
3678 if (!(vec_len (a->name)))
3681 a->policy_name = format (0, "%s", mp->policy_name);
3682 if (!(vec_len (a->policy_name)))
3685 /* Yank segments and tags out of the API message */
3686 this_address = (ip6_address_t *) mp->segs_and_tags;
3687 for (i = 0; i < mp->n_segments; i++)
3689 vec_add2 (segments, seg, 1);
3690 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3693 for (i = 0; i < mp->n_tags; i++)
3695 vec_add2 (tags, tag, 1);
3696 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3700 a->segments = segments;
3703 rv = ip6_sr_add_del_tunnel (a);
3707 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3711 static void vl_api_sr_policy_add_del_t_handler
3712 (vl_api_sr_policy_add_del_t * mp)
3715 clib_warning ("unimplemented");
3717 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3719 vl_api_sr_policy_add_del_reply_t *rmp;
3722 memset (a, 0, sizeof (*a));
3723 a->is_del = (mp->is_add == 0);
3725 a->name = format (0, "%s", mp->name);
3726 if (!(vec_len (a->name)))
3728 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3732 if (!(mp->tunnel_names[0]))
3734 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3738 // start deserializing tunnel_names
3739 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3740 u8 *deser_tun_names = mp->tunnel_names;
3741 deser_tun_names += 1; //moving along
3744 int tun_name_len = 0;
3746 for (i = 0; i < num_tunnels; i++)
3748 tun_name_len = *deser_tun_names;
3749 deser_tun_names += 1;
3750 vec_resize (tun_name, tun_name_len);
3751 memcpy (tun_name, deser_tun_names, tun_name_len);
3752 vec_add1 (a->tunnel_names, tun_name);
3753 deser_tun_names += tun_name_len;
3757 rv = ip6_sr_add_del_policy (a);
3761 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3765 static void vl_api_sr_multicast_map_add_del_t_handler
3766 (vl_api_sr_multicast_map_add_del_t * mp)
3769 clib_warning ("unimplemented");
3771 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3773 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3775 memset (a, 0, sizeof (*a));
3776 a->is_del = (mp->is_add == 0);
3778 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3779 a->policy_name = format (0, "%s", mp->policy_name);
3781 if (a->multicast_address == 0)
3787 if (!(a->policy_name))
3793 #if DPDK > 0 /* Cannot call replicate without DPDK */
3794 rv = ip6_sr_add_del_multicastmap (a);
3796 clib_warning ("multicast replication without DPDK not implemented");
3797 rv = VNET_API_ERROR_UNIMPLEMENTED;
3802 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3806 #define foreach_classify_add_del_table_field \
3811 _(match_n_vectors) \
3812 _(next_table_index) \
3815 static void vl_api_classify_add_del_table_t_handler
3816 (vl_api_classify_add_del_table_t * mp)
3818 vl_api_classify_add_del_table_reply_t *rmp;
3819 vnet_classify_main_t *cm = &vnet_classify_main;
3820 vnet_classify_table_t *t;
3824 foreach_classify_add_del_table_field;
3827 #define _(a) a = ntohl(mp->a);
3828 foreach_classify_add_del_table_field;
3831 /* The underlying API fails silently, on purpose, so check here */
3832 if (mp->is_add == 0)
3833 if (pool_is_free_index (cm->tables, table_index))
3835 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3839 rv = vnet_classify_add_del_table
3840 (cm, mp->mask, nbuckets, memory_size,
3841 skip_n_vectors, match_n_vectors,
3842 next_table_index, miss_next_index, &table_index, mp->is_add);
3846 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3848 if (rv == 0 && mp->is_add)
3850 t = pool_elt_at_index (cm->tables, table_index);
3851 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3852 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3853 rmp->new_table_index = ntohl(table_index);
3857 rmp->skip_n_vectors = ~0;
3858 rmp->match_n_vectors = ~0;
3859 rmp->new_table_index = ~0;
3865 static void vl_api_classify_add_del_session_t_handler
3866 (vl_api_classify_add_del_session_t * mp)
3868 vnet_classify_main_t *cm = &vnet_classify_main;
3869 vl_api_classify_add_del_session_reply_t *rmp;
3871 u32 table_index, hit_next_index, opaque_index;
3874 table_index = ntohl (mp->table_index);
3875 hit_next_index = ntohl (mp->hit_next_index);
3876 opaque_index = ntohl (mp->opaque_index);
3877 advance = ntohl (mp->advance);
3879 rv = vnet_classify_add_del_session
3880 (cm, table_index, mp->match, hit_next_index, opaque_index,
3881 advance, mp->is_add);
3883 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3886 static void vl_api_classify_set_interface_ip_table_t_handler
3887 (vl_api_classify_set_interface_ip_table_t * mp)
3889 vlib_main_t *vm = vlib_get_main ();
3890 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3892 u32 table_index, sw_if_index;
3894 table_index = ntohl (mp->table_index);
3895 sw_if_index = ntohl (mp->sw_if_index);
3897 VALIDATE_SW_IF_INDEX (mp);
3900 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3902 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3904 BAD_SW_IF_INDEX_LABEL;
3906 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3909 static void vl_api_classify_set_interface_l2_tables_t_handler
3910 (vl_api_classify_set_interface_l2_tables_t * mp)
3912 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3914 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3917 ip4_table_index = ntohl (mp->ip4_table_index);
3918 ip6_table_index = ntohl (mp->ip6_table_index);
3919 other_table_index = ntohl (mp->other_table_index);
3920 sw_if_index = ntohl (mp->sw_if_index);
3922 VALIDATE_SW_IF_INDEX (mp);
3924 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3925 ip6_table_index, other_table_index);
3929 if (ip4_table_index != ~0 || ip6_table_index != ~0
3930 || other_table_index != ~0)
3935 vnet_l2_classify_enable_disable (sw_if_index, enable);
3938 BAD_SW_IF_INDEX_LABEL;
3940 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3944 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3947 vl_api_l2_fib_clear_table_reply_t *rmp;
3949 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3950 * that is not currently implemented. When that TODO is fixed
3951 * this call should be changed to pass 1 instead of 0.
3953 l2fib_clear_table (0);
3955 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3958 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3959 u32 sw_if_index, u32 enable);
3962 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3966 vl_api_l2_interface_efp_filter_reply_t *rmp;
3967 vnet_main_t *vnm = vnet_get_main ();
3969 // enable/disable the feature
3970 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3971 rv = vnm->api_errno;
3973 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3977 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3978 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3981 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3982 vnet_main_t *vnm = vnet_get_main ();
3983 vlib_main_t *vm = vlib_get_main ();
3986 VALIDATE_SW_IF_INDEX (mp);
3988 vtr_op = ntohl (mp->vtr_op);
3990 /* The L2 code is unsuspicious */
3993 case L2_VTR_DISABLED:
3998 case L2_VTR_TRANSLATE_1_1:
3999 case L2_VTR_TRANSLATE_1_2:
4000 case L2_VTR_TRANSLATE_2_1:
4001 case L2_VTR_TRANSLATE_2_2:
4005 rv = VNET_API_ERROR_INVALID_VALUE;
4006 goto bad_sw_if_index;
4009 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4010 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4013 BAD_SW_IF_INDEX_LABEL;
4015 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4019 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4022 vl_api_create_vhost_user_if_reply_t *rmp;
4024 u32 sw_if_index = (u32) ~ 0;
4026 vnet_main_t *vnm = vnet_get_main ();
4027 vlib_main_t *vm = vlib_get_main ();
4029 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
4030 mp->is_server, &sw_if_index, (u64) ~ 0,
4031 mp->renumber, ntohl (mp->custom_dev_instance),
4032 (mp->use_custom_mac) ? mp->mac_address : NULL);
4035 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4037 rmp->sw_if_index = ntohl (sw_if_index);
4041 rv = VNET_API_ERROR_UNIMPLEMENTED;
4042 REPLY_MACRO (VL_API_CREATE_VHOST_USER_IF_REPLY);
4047 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4050 vl_api_modify_vhost_user_if_reply_t *rmp;
4051 #if DPDK > 0 && DPDK_VHOST_USER
4052 u32 sw_if_index = ntohl (mp->sw_if_index);
4054 vnet_main_t *vnm = vnet_get_main ();
4055 vlib_main_t *vm = vlib_get_main ();
4057 rv = dpdk_vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
4058 mp->is_server, sw_if_index, (u64) ~ 0,
4060 ntohl (mp->custom_dev_instance));
4062 rv = VNET_API_ERROR_UNIMPLEMENTED;
4064 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4068 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4071 vl_api_delete_vhost_user_if_reply_t *rmp;
4072 #if DPDK > 0 && DPDK_VHOST_USER
4073 vpe_api_main_t *vam = &vpe_api_main;
4074 u32 sw_if_index = ntohl (mp->sw_if_index);
4076 vnet_main_t *vnm = vnet_get_main ();
4077 vlib_main_t *vm = vlib_get_main ();
4079 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4081 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4084 unix_shared_memory_queue_t *q =
4085 vl_api_client_index_to_input_queue (mp->client_index);
4089 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4092 rv = VNET_API_ERROR_UNIMPLEMENTED;
4093 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4098 vl_api_sw_interface_vhost_user_details_t_handler
4099 (vl_api_sw_interface_vhost_user_details_t * mp)
4101 clib_warning ("BUG");
4104 #if DPDK > 0 && DPDK_VHOST_USER
4106 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4107 unix_shared_memory_queue_t * q,
4108 vhost_user_intf_details_t * vui,
4111 vl_api_sw_interface_vhost_user_details_t *mp;
4113 mp = vl_msg_api_alloc (sizeof (*mp));
4114 memset (mp, 0, sizeof (*mp));
4115 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4116 mp->sw_if_index = ntohl (vui->sw_if_index);
4117 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4118 mp->features = clib_net_to_host_u64 (vui->features);
4119 mp->is_server = vui->is_server;
4120 mp->num_regions = ntohl (vui->num_regions);
4121 mp->sock_errno = ntohl (vui->sock_errno);
4122 mp->context = context;
4124 strncpy ((char *) mp->sock_filename,
4125 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4126 strncpy ((char *) mp->interface_name,
4127 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4129 vl_msg_api_send_shmem (q, (u8 *) & mp);
4134 vl_api_sw_interface_vhost_user_dump_t_handler
4135 (vl_api_sw_interface_vhost_user_dump_t * mp)
4137 #if DPDK > 0 && DPDK_VHOST_USER
4139 vpe_api_main_t *am = &vpe_api_main;
4140 vnet_main_t *vnm = vnet_get_main ();
4141 vlib_main_t *vm = vlib_get_main ();
4142 vhost_user_intf_details_t *ifaces = NULL;
4143 vhost_user_intf_details_t *vuid = NULL;
4144 unix_shared_memory_queue_t *q;
4146 q = vl_api_client_index_to_input_queue (mp->client_index);
4150 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4154 vec_foreach (vuid, ifaces)
4156 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4163 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4164 unix_shared_memory_queue_t * q,
4166 l2t_main_t * lm, u32 context)
4168 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4170 vnet_sw_interface_t *si = NULL;
4172 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4174 if_name = format (if_name, "%U",
4175 format_vnet_sw_interface_name, lm->vnet_main, si);
4177 mp = vl_msg_api_alloc (sizeof (*mp));
4178 memset (mp, 0, sizeof (*mp));
4179 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4180 strncpy ((char *) mp->interface_name,
4181 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4182 mp->sw_if_index = ntohl (si->sw_if_index);
4183 mp->local_session_id = s->local_session_id;
4184 mp->remote_session_id = s->remote_session_id;
4185 mp->local_cookie[0] = s->local_cookie[0];
4186 mp->local_cookie[1] = s->local_cookie[1];
4187 mp->remote_cookie = s->remote_cookie;
4188 clib_memcpy (mp->client_address, &s->client_address,
4189 sizeof (s->client_address));
4190 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4191 mp->l2_sublayer_present = s->l2_sublayer_present;
4192 mp->context = context;
4194 vl_msg_api_send_shmem (q, (u8 *) & mp);
4198 send_ip_address_details (vpe_api_main_t * am,
4199 unix_shared_memory_queue_t * q,
4200 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4202 vl_api_ip_address_details_t *mp;
4204 mp = vl_msg_api_alloc (sizeof (*mp));
4205 memset (mp, 0, sizeof (*mp));
4206 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4210 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4214 u32 *tp = (u32 *) mp->ip;
4215 *tp = ntohl (*(u32 *) ip);
4217 mp->prefix_length = prefix_length;
4218 mp->context = context;
4220 vl_msg_api_send_shmem (q, (u8 *) & mp);
4224 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4226 vpe_api_main_t *am = &vpe_api_main;
4227 unix_shared_memory_queue_t *q;
4230 ip6_main_t *im6 = &ip6_main;
4231 ip4_main_t *im4 = &ip4_main;
4232 ip_lookup_main_t *lm6 = &im6->lookup_main;
4233 ip_lookup_main_t *lm4 = &im4->lookup_main;
4234 ip_interface_address_t *ia = 0;
4235 u32 sw_if_index = ~0;
4236 int rv __attribute__ ((unused)) = 0;
4238 VALIDATE_SW_IF_INDEX (mp);
4240 sw_if_index = ntohl (mp->sw_if_index);
4242 q = vl_api_client_index_to_input_queue (mp->client_index);
4251 foreach_ip_interface_address (lm6, ia, sw_if_index,
4252 1 /* honor unnumbered */,
4254 r6 = ip_interface_address_get_address (lm6, ia);
4255 u16 prefix_length = ia->address_length;
4256 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4263 foreach_ip_interface_address (lm4, ia, sw_if_index,
4264 1 /* honor unnumbered */,
4266 r4 = ip_interface_address_get_address (lm4, ia);
4267 u16 prefix_length = ia->address_length;
4268 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4272 BAD_SW_IF_INDEX_LABEL;
4276 send_ip_details (vpe_api_main_t * am,
4277 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4279 vl_api_ip_details_t *mp;
4281 mp = vl_msg_api_alloc (sizeof (*mp));
4282 memset (mp, 0, sizeof (*mp));
4283 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4285 mp->sw_if_index = ntohl (sw_if_index);
4286 mp->context = context;
4288 vl_msg_api_send_shmem (q, (u8 *) & mp);
4292 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4295 vpe_api_main_t *am = &vpe_api_main;
4296 l2t_main_t *lm = &l2t_main;
4297 unix_shared_memory_queue_t *q;
4298 l2t_session_t *session;
4300 q = vl_api_client_index_to_input_queue (mp->client_index);
4305 pool_foreach (session, lm->sessions,
4307 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4314 send_sw_interface_tap_details (vpe_api_main_t * am,
4315 unix_shared_memory_queue_t * q,
4316 tapcli_interface_details_t * tap_if,
4319 vl_api_sw_interface_tap_details_t *mp;
4320 mp = vl_msg_api_alloc (sizeof (*mp));
4321 memset (mp, 0, sizeof (*mp));
4322 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4323 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4324 strncpy ((char *) mp->dev_name,
4325 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4326 mp->context = context;
4328 vl_msg_api_send_shmem (q, (u8 *) & mp);
4332 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4335 vpe_api_main_t *am = &vpe_api_main;
4336 unix_shared_memory_queue_t *q;
4337 tapcli_interface_details_t *tapifs = NULL;
4338 tapcli_interface_details_t *tap_if = NULL;
4340 q = vl_api_client_index_to_input_queue (mp->client_index);
4344 rv = vnet_tap_dump_ifs (&tapifs);
4348 vec_foreach (tap_if, tapifs)
4350 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4357 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4359 vpe_api_main_t *am = &vpe_api_main;
4360 vnet_main_t *vnm = vnet_get_main ();
4361 vlib_main_t *vm = vlib_get_main ();
4362 vnet_interface_main_t *im = &vnm->interface_main;
4363 unix_shared_memory_queue_t *q;
4364 vnet_sw_interface_t *si, *sorted_sis;
4365 u32 sw_if_index = ~0;
4367 q = vl_api_client_index_to_input_queue (mp->client_index);
4373 /* Gather interfaces. */
4374 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4375 _vec_len (sorted_sis) = 0;
4377 pool_foreach (si, im->sw_interfaces,
4379 vec_add1 (sorted_sis, si[0]);
4383 vec_foreach (si, sorted_sis)
4385 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4387 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4391 sw_if_index = si->sw_if_index;
4392 send_ip_details (am, q, sw_if_index, mp->context);
4398 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4400 clib_warning ("BUG");
4404 send_l2fib_table_entry (vpe_api_main_t * am,
4405 unix_shared_memory_queue_t * q,
4406 l2fib_entry_key_t * l2fe_key,
4407 l2fib_entry_result_t * l2fe_res, u32 context)
4409 vl_api_l2_fib_table_entry_t *mp;
4411 mp = vl_msg_api_alloc (sizeof (*mp));
4412 memset (mp, 0, sizeof (*mp));
4413 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4416 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4418 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4419 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4420 mp->static_mac = l2fe_res->fields.static_mac;
4421 mp->filter_mac = l2fe_res->fields.filter;
4422 mp->bvi_mac = l2fe_res->fields.bvi;
4423 mp->context = context;
4425 vl_msg_api_send_shmem (q, (u8 *) & mp);
4429 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4431 vpe_api_main_t *am = &vpe_api_main;
4432 bd_main_t *bdm = &bd_main;
4433 l2fib_entry_key_t *l2fe_key = NULL;
4434 l2fib_entry_result_t *l2fe_res = NULL;
4435 u32 ni, bd_id = ntohl (mp->bd_id);
4437 unix_shared_memory_queue_t *q;
4440 q = vl_api_client_index_to_input_queue (mp->client_index);
4444 /* see l2fib_table_dump: ~0 means "any" */
4449 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4456 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4458 vec_foreach_index (ni, l2fe_key)
4460 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4461 vec_elt_at_index (l2fe_res, ni), mp->context);
4463 vec_free (l2fe_key);
4464 vec_free (l2fe_res);
4468 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4470 vl_api_show_version_reply_t *rmp;
4472 char *vpe_api_get_build_directory (void);
4473 char *vpe_api_get_version (void);
4474 char *vpe_api_get_build_date (void);
4476 unix_shared_memory_queue_t *q =
4477 vl_api_client_index_to_input_queue (mp->client_index);
4483 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4485 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4486 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4487 ARRAY_LEN(rmp->build_directory)-1);
4488 strncpy ((char *) rmp->version, vpe_api_get_version(),
4489 ARRAY_LEN(rmp->version)-1);
4490 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4491 ARRAY_LEN(rmp->build_date)-1);
4497 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4499 vlib_main_t *vm = vlib_get_main ();
4500 vl_api_get_node_index_reply_t *rmp;
4503 u32 node_index = ~0;
4505 n = vlib_get_node_by_name (vm, mp->node_name);
4508 rv = VNET_API_ERROR_NO_SUCH_NODE;
4510 node_index = n->index;
4513 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4515 rmp->node_index = ntohl(node_index);
4521 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4523 vlib_main_t *vm = vlib_get_main ();
4524 vl_api_get_next_index_reply_t *rmp;
4525 vlib_node_t *node, *next_node;
4527 u32 next_node_index = ~0, next_index = ~0;
4530 node = vlib_get_node_by_name (vm, mp->node_name);
4534 rv = VNET_API_ERROR_NO_SUCH_NODE;
4538 next_node = vlib_get_node_by_name (vm, mp->next_name);
4542 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4546 next_node_index = next_node->index;
4548 p = hash_get (node->next_slot_by_node, next_node_index);
4552 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4560 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4562 rmp->next_index = ntohl(next_index);
4568 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4570 vlib_main_t *vm = vlib_get_main ();
4571 vl_api_add_node_next_reply_t *rmp;
4572 vlib_node_t *n, *next;
4574 u32 next_index = ~0;
4576 n = vlib_get_node_by_name (vm, mp->node_name);
4580 rv = VNET_API_ERROR_NO_SUCH_NODE;
4584 next = vlib_get_node_by_name (vm, mp->next_name);
4587 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4589 next_index = vlib_node_add_next (vm, n->index, next->index);
4593 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4595 rmp->next_index = ntohl(next_index);
4600 static void vl_api_l2tpv3_create_tunnel_t_handler
4601 (vl_api_l2tpv3_create_tunnel_t * mp)
4603 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4604 l2t_main_t *lm = &l2t_main;
4605 u32 sw_if_index = (u32) ~ 0;
4608 if (mp->is_ipv6 != 1)
4610 rv = VNET_API_ERROR_UNIMPLEMENTED;
4614 u32 encap_fib_index;
4616 if (mp->encap_vrf_id != ~0)
4619 ip6_main_t *im = &ip6_main;
4622 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4624 rv = VNET_API_ERROR_NO_SUCH_FIB;
4627 encap_fib_index = p[0];
4631 encap_fib_index = ~0;
4634 rv = create_l2tpv3_ipv6_tunnel (lm,
4635 (ip6_address_t *) mp->client_address,
4636 (ip6_address_t *) mp->our_address,
4637 ntohl (mp->local_session_id),
4638 ntohl (mp->remote_session_id),
4639 clib_net_to_host_u64 (mp->local_cookie),
4640 clib_net_to_host_u64 (mp->remote_cookie),
4641 mp->l2_sublayer_present,
4642 encap_fib_index, &sw_if_index);
4646 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4648 rmp->sw_if_index = ntohl (sw_if_index);
4653 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4654 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4656 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4657 l2t_main_t *lm = &l2t_main;
4660 VALIDATE_SW_IF_INDEX (mp);
4662 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4663 clib_net_to_host_u64 (mp->new_local_cookie),
4664 clib_net_to_host_u64
4665 (mp->new_remote_cookie));
4667 BAD_SW_IF_INDEX_LABEL;
4669 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4672 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4673 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4676 vnet_main_t *vnm = vnet_get_main ();
4677 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4679 VALIDATE_SW_IF_INDEX (mp);
4681 rv = l2tpv3_interface_enable_disable
4682 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4684 BAD_SW_IF_INDEX_LABEL;
4686 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4689 static void vl_api_l2tpv3_set_lookup_key_t_handler
4690 (vl_api_l2tpv3_set_lookup_key_t * mp)
4693 l2t_main_t *lm = &l2t_main;
4694 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4696 if (mp->key > L2T_LOOKUP_SESSION_ID)
4698 rv = VNET_API_ERROR_INVALID_VALUE;
4702 lm->lookup_type = mp->key;
4705 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4708 static void vl_api_vxlan_add_del_tunnel_t_handler
4709 (vl_api_vxlan_add_del_tunnel_t * mp)
4711 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4713 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4714 u32 encap_fib_index;
4716 ip4_main_t *im = &ip4_main;
4717 u32 sw_if_index = ~0;
4719 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4722 rv = VNET_API_ERROR_NO_SUCH_FIB;
4725 encap_fib_index = p[0];
4727 /* Check src & dst are different */
4728 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4729 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4731 rv = VNET_API_ERROR_SAME_SRC_DST;
4734 memset (a, 0, sizeof (*a));
4736 a->is_add = mp->is_add;
4737 a->is_ip6 = mp->is_ipv6;
4739 /* ip addresses sent in network byte order */
4742 memcpy (&(a->src.ip6), mp->src_address, 16);
4743 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4747 memcpy (&(a->src.ip4), mp->src_address, 4);
4748 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4751 a->encap_fib_index = encap_fib_index;
4752 a->decap_next_index = ntohl (mp->decap_next_index);
4753 a->vni = ntohl (mp->vni);
4754 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4758 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4760 rmp->sw_if_index = ntohl (sw_if_index);
4765 static void send_vxlan_tunnel_details
4766 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4768 vl_api_vxlan_tunnel_details_t *rmp;
4769 ip4_main_t *im4 = &ip4_main;
4770 ip6_main_t *im6 = &ip6_main;
4771 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4773 rmp = vl_msg_api_alloc (sizeof (*rmp));
4774 memset (rmp, 0, sizeof (*rmp));
4775 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4778 memcpy (rmp->src_address, &(t->src.ip6), 16);
4779 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4780 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
4784 memcpy (rmp->src_address, &(t->src.ip4), 4);
4785 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4786 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
4788 rmp->vni = htonl (t->vni);
4789 rmp->decap_next_index = htonl (t->decap_next_index);
4790 rmp->sw_if_index = htonl (t->sw_if_index);
4791 rmp->is_ipv6 = is_ipv6;
4792 rmp->context = context;
4794 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4797 static void vl_api_vxlan_tunnel_dump_t_handler
4798 (vl_api_vxlan_tunnel_dump_t * mp)
4800 unix_shared_memory_queue_t *q;
4801 vxlan_main_t *vxm = &vxlan_main;
4805 q = vl_api_client_index_to_input_queue (mp->client_index);
4811 sw_if_index = ntohl (mp->sw_if_index);
4813 if (~0 == sw_if_index)
4816 pool_foreach (t, vxm->tunnels,
4818 send_vxlan_tunnel_details(t, q, mp->context);
4824 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4825 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4829 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4830 send_vxlan_tunnel_details (t, q, mp->context);
4834 static void vl_api_gre_add_del_tunnel_t_handler
4835 (vl_api_gre_add_del_tunnel_t * mp)
4837 vl_api_gre_add_del_tunnel_reply_t *rmp;
4839 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4842 ip4_main_t *im = &ip4_main;
4843 u32 sw_if_index = ~0;
4845 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4848 rv = VNET_API_ERROR_NO_SUCH_FIB;
4851 outer_fib_id = p[0];
4853 /* Check src & dst are different */
4854 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4855 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4857 rv = VNET_API_ERROR_SAME_SRC_DST;
4860 memset (a, 0, sizeof (*a));
4862 a->is_add = mp->is_add;
4864 /* ip addresses sent in network byte order */
4865 clib_memcpy (&(a->src), mp->src_address, 4);
4866 clib_memcpy (&(a->dst), mp->dst_address, 4);
4868 a->outer_fib_id = outer_fib_id;
4869 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4873 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4875 rmp->sw_if_index = ntohl (sw_if_index);
4880 static void send_gre_tunnel_details
4881 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4883 vl_api_gre_tunnel_details_t *rmp;
4884 ip4_main_t *im = &ip4_main;
4886 rmp = vl_msg_api_alloc (sizeof (*rmp));
4887 memset (rmp, 0, sizeof (*rmp));
4888 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4889 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4890 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4891 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
4892 rmp->sw_if_index = htonl (t->sw_if_index);
4893 rmp->context = context;
4895 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4899 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4901 unix_shared_memory_queue_t *q;
4902 gre_main_t *gm = &gre_main;
4906 q = vl_api_client_index_to_input_queue (mp->client_index);
4912 sw_if_index = ntohl (mp->sw_if_index);
4914 if (~0 == sw_if_index)
4917 pool_foreach (t, gm->tunnels,
4919 send_gre_tunnel_details(t, q, mp->context);
4925 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4926 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4930 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4931 send_gre_tunnel_details (t, q, mp->context);
4936 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4938 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4940 vl_api_l2_patch_add_del_reply_t *rmp;
4941 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4945 VALIDATE_RX_SW_IF_INDEX (mp);
4946 VALIDATE_TX_SW_IF_INDEX (mp);
4948 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4949 ntohl (mp->tx_sw_if_index),
4950 (int) (mp->is_add != 0));
4952 BAD_RX_SW_IF_INDEX_LABEL;
4953 BAD_TX_SW_IF_INDEX_LABEL;
4955 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4959 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4960 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4962 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4964 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4965 u32 encap_fib_index, decap_fib_index;
4968 ip4_main_t *im = &ip4_main;
4969 u32 sw_if_index = ~0;
4972 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4975 rv = VNET_API_ERROR_NO_SUCH_FIB;
4978 encap_fib_index = p[0];
4980 protocol = mp->protocol;
4982 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4983 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4985 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4988 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4991 decap_fib_index = p[0];
4995 decap_fib_index = ntohl (mp->decap_vrf_id);
4998 /* Check src & dst are different */
4999 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5000 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5002 rv = VNET_API_ERROR_SAME_SRC_DST;
5005 memset (a, 0, sizeof (*a));
5007 a->is_add = mp->is_add;
5008 a->is_ip6 = mp->is_ipv6;
5009 /* ip addresses sent in network byte order */
5012 clib_memcpy (&(a->local.ip6), mp->local, 16);
5013 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5017 clib_memcpy (&(a->local.ip4), mp->local, 4);
5018 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5020 a->encap_fib_index = encap_fib_index;
5021 a->decap_fib_index = decap_fib_index;
5022 a->protocol = protocol;
5023 a->vni = ntohl (mp->vni);
5024 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5028 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5030 rmp->sw_if_index = ntohl (sw_if_index);
5035 static void send_vxlan_gpe_tunnel_details
5036 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5038 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5039 ip4_main_t *im4 = &ip4_main;
5040 ip6_main_t *im6 = &ip6_main;
5041 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5043 rmp = vl_msg_api_alloc (sizeof (*rmp));
5044 memset (rmp, 0, sizeof (*rmp));
5045 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5048 memcpy (rmp->local, &(t->local.ip6), 16);
5049 memcpy (rmp->remote, &(t->remote.ip6), 16);
5050 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
5051 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].table_id);
5055 memcpy (rmp->local, &(t->local.ip4), 4);
5056 memcpy (rmp->remote, &(t->remote.ip4), 4);
5057 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
5058 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].table_id);
5060 rmp->vni = htonl (t->vni);
5061 rmp->protocol = t->protocol;
5062 rmp->sw_if_index = htonl (t->sw_if_index);
5063 rmp->is_ipv6 = is_ipv6;
5064 rmp->context = context;
5066 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5069 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5070 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5072 unix_shared_memory_queue_t *q;
5073 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5074 vxlan_gpe_tunnel_t *t;
5077 q = vl_api_client_index_to_input_queue (mp->client_index);
5083 sw_if_index = ntohl (mp->sw_if_index);
5085 if (~0 == sw_if_index)
5088 pool_foreach (t, vgm->tunnels,
5090 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5096 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5097 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5101 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5102 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5106 /** Used for transferring locators via VPP API */
5108 typedef CLIB_PACKED (struct {
5109 u32 sw_if_index; /**< locator sw_if_index */
5110 u8 priority; /**< locator priority */
5111 u8 weight; /**< locator weight */
5116 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5119 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5121 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5123 ls_locator_t *ls_loc;
5125 u8 *locator_name = NULL;
5128 memset (a, 0, sizeof (a[0]));
5130 locator_name = format (0, "%s", mp->locator_set_name);
5132 a->name = locator_name;
5133 a->is_add = mp->is_add;
5136 memset (&locator, 0, sizeof (locator));
5137 for (i = 0; i < mp->locator_num; i++)
5139 ls_loc = &((ls_locator_t *) mp->locators)[i];
5140 VALIDATE_SW_IF_INDEX (ls_loc);
5142 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5143 locator.priority = ls_loc->priority;
5144 locator.weight = ls_loc->weight;
5146 vec_add1 (a->locators, locator);
5149 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5151 BAD_SW_IF_INDEX_LABEL;
5153 vec_free (locator_name);
5154 vec_free (a->locators);
5156 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
5160 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5162 vl_api_lisp_add_del_locator_reply_t *rmp;
5164 locator_t locator, *locators = NULL;
5165 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5167 u8 *locator_name = NULL;
5169 memset (&locator, 0, sizeof (locator));
5170 memset (a, 0, sizeof (a[0]));
5172 locator.sw_if_index = ntohl (mp->sw_if_index);
5173 locator.priority = mp->priority;
5174 locator.weight = mp->weight;
5176 vec_add1 (locators, locator);
5178 locator_name = format (0, "%s", mp->locator_set_name);
5180 a->name = locator_name;
5181 a->locators = locators;
5182 a->is_add = mp->is_add;
5185 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5187 vec_free (locators);
5188 vec_free (locator_name);
5190 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5194 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5200 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5201 gid_address_ip_set (dst, src, IP4);
5202 gid_address_ippref_len (dst) = len;
5203 ip_prefix_normalize (&gid_address_ippref (dst));
5206 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5207 gid_address_ip_set (dst, src, IP6);
5208 gid_address_ippref_len (dst) = len;
5209 ip_prefix_normalize (&gid_address_ippref (dst));
5211 case 2: /* l2 mac */
5212 gid_address_type (dst) = GID_ADDR_MAC;
5213 clib_memcpy (&gid_address_mac (dst), src, 6);
5217 return VNET_API_ERROR_INVALID_VALUE;
5220 gid_address_vni (dst) = vni;
5226 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5228 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5229 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5231 gid_address_t _eid, *eid = &_eid;
5233 u32 locator_set_index = ~0, map_index = ~0;
5234 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5236 memset (a, 0, sizeof (a[0]));
5237 memset (eid, 0, sizeof (eid[0]));
5239 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5240 mp->eid_type, mp->eid, mp->prefix_len);
5244 name = format (0, "%s", mp->locator_set_name);
5245 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5248 rv = VNET_API_ERROR_INVALID_VALUE;
5251 locator_set_index = p[0];
5253 /* XXX treat batch configuration */
5254 a->is_add = mp->is_add;
5255 gid_address_copy (&a->eid, eid);
5256 a->locator_set_index = locator_set_index;
5258 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5262 gid_address_free (&a->eid);
5264 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5268 vl_api_lisp_eid_table_add_del_map_t_handler
5269 (vl_api_lisp_eid_table_add_del_map_t * mp)
5271 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5273 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5274 clib_net_to_host_u32 (mp->dp_table),
5275 mp->is_l2, mp->is_add);
5276 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5278 /** Used for transferring locators via VPP API */
5280 typedef CLIB_PACKED (struct {
5281 u8 is_ip4; /**< is locator an IPv4 address */
5282 u8 priority; /**< locator priority */
5283 u8 weight; /**< locator weight */
5284 u8 addr[16]; /**< IPv4/IPv6 address */
5288 static locator_pair_t *
5289 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5292 locator_pair_t *pairs = 0, pair;
5295 for (i = 0; i < rloc_num; i++)
5298 r = &((rloc_t *) lcl_locs)[i];
5299 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5300 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5302 /* remote locators */
5303 r = &((rloc_t *) rmt_locs)[i];
5304 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5305 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5307 pair.priority = r->priority;
5308 pair.weight = r->weight;
5310 vec_add1 (pairs, pair);
5316 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5319 locator_t *locs = 0, loc;
5322 for (i = 0; i < rloc_num; i++)
5324 /* remote locators */
5325 r = &((rloc_t *) rmt_locs)[i];
5326 memset (&loc, 0, sizeof (loc));
5327 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5329 loc.priority = r->priority;
5330 loc.weight = r->weight;
5332 vec_add1 (locs, loc);
5338 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5339 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5341 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5342 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5343 locator_pair_t *pairs = 0;
5346 memset (a, 0, sizeof (a[0]));
5348 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5349 mp->rmt_eid, mp->rmt_len);
5350 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5351 mp->lcl_eid, mp->lcl_len);
5353 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5355 if (rv || 0 == pairs)
5358 a->is_add = mp->is_add;
5359 a->locator_pairs = pairs;
5360 a->dp_table = mp->dp_table;
5362 a->action = mp->action;
5364 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5367 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5371 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5374 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5376 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5378 memset (a, 0, sizeof (a[0]));
5380 a->is_add = mp->is_add;
5381 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5383 rv = vnet_lisp_add_del_map_resolver (a);
5385 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5389 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5392 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5394 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5396 a->is_en = mp->is_en;
5397 vnet_lisp_gpe_enable_disable (a);
5399 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5403 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5405 vl_api_lisp_enable_disable_reply_t *rmp;
5408 vnet_lisp_enable_disable (mp->is_en);
5409 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5413 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5415 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5417 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5419 a->is_add = mp->is_add;
5420 a->dp_table = mp->dp_table;
5422 a->is_l2 = mp->is_l2;
5423 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5425 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5429 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5432 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5436 ls_name = format (0, "%s", mp->ls_name);
5437 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5440 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5444 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5445 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5447 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5449 u8 *locator_set_name = NULL;
5450 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5452 locator_set_name = format (0, "%s", mp->locator_set_name);
5454 a->is_add = mp->is_add;
5455 a->locator_set_name = locator_set_name;
5457 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5459 vec_free (locator_set_name);
5461 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5465 vl_api_lisp_add_del_remote_mapping_t_handler
5466 (vl_api_lisp_add_del_remote_mapping_t * mp)
5468 locator_t *rlocs = 0;
5469 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5471 gid_address_t _eid, *eid = &_eid;
5473 memset (eid, 0, sizeof (eid[0]));
5475 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5476 mp->eid_type, mp->eid, mp->eid_len);
5480 rlocs = unformat_lisp_locs (mp->rlocs, mp->rloc_num);
5486 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5487 gid_address_copy (&a->deid, eid);
5489 rv = vnet_lisp_add_del_adjacency (a);
5496 /* NOTE: for now this works as a static remote mapping, i.e.,
5497 * not authoritative and ttl infinite. */
5498 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5502 vnet_lisp_clear_all_remote_adjacencies ();
5507 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5511 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5513 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5514 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5517 memset (a, 0, sizeof (a[0]));
5519 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5520 mp->eid_type, mp->seid, mp->seid_len);
5521 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5522 mp->eid_type, mp->deid, mp->deid_len);
5527 a->is_add = mp->is_add;
5528 rv = vnet_lisp_add_del_adjacency (a);
5531 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5535 send_lisp_locator_details (lisp_cp_main_t * lcm,
5537 unix_shared_memory_queue_t * q, u32 context)
5539 vl_api_lisp_locator_details_t *rmp;
5541 rmp = vl_msg_api_alloc (sizeof (*rmp));
5542 memset (rmp, 0, sizeof (*rmp));
5543 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5544 rmp->context = context;
5546 rmp->local = loc->local;
5549 rmp->sw_if_index = ntohl (loc->sw_if_index);
5553 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5554 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5556 rmp->priority = loc->priority;
5557 rmp->weight = loc->weight;
5559 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5563 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5565 unix_shared_memory_queue_t *q = 0;
5566 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5567 locator_set_t *lsit = 0;
5569 u32 ls_index = ~0, *locit = 0;
5572 q = vl_api_client_index_to_input_queue (mp->client_index);
5578 ls_index = htonl (mp->locator_set_index);
5580 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5582 filter = mp->filter;
5583 if (filter && !((1 == filter && lsit->local) ||
5584 (2 == filter && !lsit->local)))
5589 vec_foreach (locit, lsit->locator_indices)
5591 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5592 send_lisp_locator_details (lcm, loc, q, mp->context);
5597 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5598 locator_set_t * lsit,
5599 unix_shared_memory_queue_t * q,
5600 u32 context, u32 ls_index)
5602 vl_api_lisp_locator_set_details_t *rmp;
5605 rmp = vl_msg_api_alloc (sizeof (*rmp));
5606 memset (rmp, 0, sizeof (*rmp));
5607 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5608 rmp->context = context;
5610 rmp->local = lsit->local;
5611 rmp->locator_set_index = htonl (ls_index);
5614 ASSERT (lsit->name != NULL);
5615 strncpy ((char *) rmp->locator_set_name,
5616 (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1);
5620 str = format (0, "remote-%d", ls_index);
5621 strncpy ((char *) rmp->locator_set_name, (char *) str,
5622 ARRAY_LEN (rmp->locator_set_name) - 1);
5626 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5630 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5632 unix_shared_memory_queue_t *q = NULL;
5633 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5634 locator_set_t *lsit = NULL;
5638 q = vl_api_client_index_to_input_queue (mp->client_index);
5644 filter = mp->filter;
5647 pool_foreach (lsit, lcm->locator_set_pool,
5649 if (filter && !((1 == filter && lsit->local) ||
5650 (2 == filter && !lsit->local))) {
5654 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5660 send_lisp_eid_table_details (mapping_t * mapit,
5661 unix_shared_memory_queue_t * q,
5662 u32 context, u8 filter)
5664 vl_api_lisp_eid_table_details_t *rmp = NULL;
5665 gid_address_t *gid = NULL;
5667 ip_prefix_t *ip_prefix = NULL;
5671 case 0: /* all mappings */
5674 case 1: /* local only */
5678 case 2: /* remote only */
5683 clib_warning ("Filter error, unknown filter: %d", filter);
5688 ip_prefix = &gid_address_ippref (gid);
5689 mac = gid_address_mac (gid);
5691 rmp = vl_msg_api_alloc (sizeof (*rmp));
5692 memset (rmp, 0, sizeof (*rmp));
5693 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5694 rmp->locator_set_index = mapit->locator_set_index;
5695 rmp->is_local = mapit->local;
5696 rmp->ttl = mapit->ttl;
5697 rmp->authoritative = mapit->authoritative;
5699 switch (gid_address_type (gid))
5701 case GID_ADDR_IP_PREFIX:
5702 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5703 if (ip_prefix_version (ip_prefix) == IP4)
5705 rmp->eid_type = 0; /* ipv4 type */
5706 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5707 sizeof (ip_prefix_v4 (ip_prefix)));
5711 rmp->eid_type = 1; /* ipv6 type */
5712 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5713 sizeof (ip_prefix_v6 (ip_prefix)));
5717 rmp->eid_type = 2; /* l2 mac type */
5718 clib_memcpy (rmp->eid, mac, 6);
5723 rmp->context = context;
5724 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5725 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5729 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5732 unix_shared_memory_queue_t *q = NULL;
5733 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5734 mapping_t *mapit = NULL;
5735 gid_address_t _eid, *eid = &_eid;
5737 q = vl_api_client_index_to_input_queue (mp->client_index);
5745 memset (eid, 0, sizeof (*eid));
5747 unformat_lisp_eid_api (eid, mp->eid_type,
5748 clib_net_to_host_u32 (mp->vni), mp->eid,
5751 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5752 if ((u32) ~ 0 == mi)
5755 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5756 send_lisp_eid_table_details (mapit, q, mp->context,
5757 0 /* ignore filter */ );
5762 pool_foreach (mapit, lcm->mapping_pool,
5764 send_lisp_eid_table_details(mapit, q, mp->context,
5772 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5773 unix_shared_memory_queue_t * q, u32 context)
5775 vl_api_lisp_gpe_tunnel_details_t *rmp;
5776 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5778 rmp = vl_msg_api_alloc (sizeof (*rmp));
5779 memset (rmp, 0, sizeof (*rmp));
5780 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5782 rmp->tunnels = tunnel - lgm->tunnels;
5784 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5785 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5786 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5788 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5789 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5790 rmp->dcap_next = htonl (tunnel->decap_next_index);
5791 rmp->lisp_ver = tunnel->ver_res;
5792 rmp->next_protocol = tunnel->next_protocol;
5793 rmp->flags = tunnel->flags;
5794 rmp->ver_res = tunnel->ver_res;
5795 rmp->res = tunnel->res;
5796 rmp->iid = htonl (tunnel->vni);
5797 rmp->context = context;
5799 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5803 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5805 unix_shared_memory_queue_t *q = NULL;
5806 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5807 lisp_gpe_tunnel_t *tunnel = NULL;
5809 if (pool_elts (lgm->tunnels) == 0)
5814 q = vl_api_client_index_to_input_queue (mp->client_index);
5821 pool_foreach(tunnel, lgm->tunnels,
5823 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5829 send_lisp_map_resolver_details (ip_address_t * ip,
5830 unix_shared_memory_queue_t * q, u32 context)
5832 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5834 rmp = vl_msg_api_alloc (sizeof (*rmp));
5835 memset (rmp, 0, sizeof (*rmp));
5836 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5838 switch (ip_addr_version (ip))
5842 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5843 sizeof (ip_addr_v4 (ip)));
5848 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5849 sizeof (ip_addr_v6 (ip)));
5855 rmp->context = context;
5857 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5861 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5863 unix_shared_memory_queue_t *q = NULL;
5864 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5865 ip_address_t *ip = NULL;
5867 q = vl_api_client_index_to_input_queue (mp->client_index);
5873 vec_foreach (ip, lcm->map_resolvers)
5875 send_lisp_map_resolver_details (ip, q, mp->context);
5881 send_eid_table_map_pair (hash_pair_t * p,
5882 unix_shared_memory_queue_t * q, u32 context)
5884 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5886 rmp = vl_msg_api_alloc (sizeof (*rmp));
5887 memset (rmp, 0, sizeof (*rmp));
5888 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5890 rmp->vni = clib_host_to_net_u32 (p->key);
5891 rmp->vrf = clib_host_to_net_u32 (p->value[0]);
5892 rmp->context = context;
5893 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5897 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5900 unix_shared_memory_queue_t *q = NULL;
5901 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5904 q = vl_api_client_index_to_input_queue (mp->client_index);
5910 hash_foreach_pair (p, lcm->table_id_by_vni,
5912 send_eid_table_map_pair (p, q, mp->context);
5918 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
5920 unix_shared_memory_queue_t *q = NULL;
5921 vl_api_show_lisp_status_reply_t *rmp = NULL;
5924 q = vl_api_client_index_to_input_queue (mp->client_index);
5931 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5933 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5934 rmp->feature_status = vnet_lisp_enable_disable_status ();
5940 vl_api_lisp_get_map_request_itr_rlocs_t_handler
5941 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
5943 unix_shared_memory_queue_t *q = NULL;
5944 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5945 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5946 locator_set_t *loc_set = 0;
5950 q = vl_api_client_index_to_input_queue (mp->client_index);
5956 if (~0 == lcm->mreq_itr_rlocs)
5958 tmp_str = format (0, " ");
5963 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5964 tmp_str = format (0, "%s", loc_set->name);
5968 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5970 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5971 ARRAY_LEN(rmp->locator_set_name) - 1);
5979 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5981 unix_shared_memory_queue_t *q = NULL;
5982 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
5983 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5985 locator_set_t *ls = 0;
5989 q = vl_api_client_index_to_input_queue (mp->client_index);
5995 if (!lcm->lisp_pitr)
5997 tmp_str = format (0, "N/A");
6001 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6002 if (~0 != m->locator_set_index)
6005 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6006 tmp_str = format (0, "%s", ls->name);
6010 tmp_str = format (0, "N/A");
6013 vec_add1 (tmp_str, 0);
6016 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6018 rmp->status = lcm->lisp_pitr;
6019 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6020 ARRAY_LEN(rmp->locator_set_name) - 1);
6026 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6029 vl_api_interface_name_renumber_reply_t *rmp;
6032 VALIDATE_SW_IF_INDEX (mp);
6034 rv = vnet_interface_name_renumber
6035 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6037 BAD_SW_IF_INDEX_LABEL;
6039 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6043 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6044 u32 sw_if_index, u32 address)
6046 vpe_api_main_t *am = &vpe_api_main;
6047 vlib_main_t *vm = am->vlib_main;
6048 vl_api_ip4_arp_event_t *event;
6049 static f64 arp_event_last_time;
6050 f64 now = vlib_time_now (vm);
6052 if (pool_is_free_index (am->arp_events, pool_index))
6055 event = pool_elt_at_index (am->arp_events, pool_index);
6056 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6058 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6062 if ((sw_if_index == event->sw_if_index) && ((address == 0) ||
6063 /* for BD case, also check IP address with 10 sec timeout */
6064 ((address == event->address)
6067 arp_event_last_time) <
6072 arp_event_last_time = now;
6073 event->sw_if_index = sw_if_index;
6075 event->address = address;
6080 arp_change_delete_callback (u32 pool_index, u8 * notused)
6082 vpe_api_main_t *am = &vpe_api_main;
6084 if (pool_is_free_index (am->arp_events, pool_index))
6087 pool_put_index (am->arp_events, pool_index);
6092 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6094 vpe_api_main_t *am = &vpe_api_main;
6095 vnet_main_t *vnm = vnet_get_main ();
6096 vl_api_want_ip4_arp_events_reply_t *rmp;
6097 vl_api_ip4_arp_event_t *event;
6100 if (mp->enable_disable)
6102 pool_get (am->arp_events, event);
6103 memset (event, 0, sizeof (*event));
6105 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6106 event->client_index = mp->client_index;
6107 event->context = mp->context;
6108 event->address = mp->address;
6109 event->pid = mp->pid;
6111 rv = vnet_add_del_ip4_arp_change_event
6112 (vnm, arp_change_data_callback,
6113 mp->pid, &mp->address /* addr, in net byte order */ ,
6114 vpe_resolver_process_node.index,
6115 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6119 rv = vnet_add_del_ip4_arp_change_event
6120 (vnm, arp_change_delete_callback,
6121 mp->pid, &mp->address /* addr, in net byte order */ ,
6122 vpe_resolver_process_node.index,
6123 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6125 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6128 static void vl_api_input_acl_set_interface_t_handler
6129 (vl_api_input_acl_set_interface_t * mp)
6131 vlib_main_t *vm = vlib_get_main ();
6132 vl_api_input_acl_set_interface_reply_t *rmp;
6134 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6136 ip4_table_index = ntohl (mp->ip4_table_index);
6137 ip6_table_index = ntohl (mp->ip6_table_index);
6138 l2_table_index = ntohl (mp->l2_table_index);
6139 sw_if_index = ntohl (mp->sw_if_index);
6141 VALIDATE_SW_IF_INDEX (mp);
6143 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6144 ip6_table_index, l2_table_index, mp->is_add);
6146 BAD_SW_IF_INDEX_LABEL;
6148 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6151 static void vl_api_ipsec_spd_add_del_t_handler
6152 (vl_api_ipsec_spd_add_del_t * mp)
6155 clib_warning ("unimplemented");
6158 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6159 vl_api_ipsec_spd_add_del_reply_t *rmp;
6163 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6165 rv = VNET_API_ERROR_UNIMPLEMENTED;
6168 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6172 static void vl_api_ipsec_interface_add_del_spd_t_handler
6173 (vl_api_ipsec_interface_add_del_spd_t * mp)
6175 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6176 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6178 u32 sw_if_index __attribute__ ((unused));
6179 u32 spd_id __attribute__ ((unused));
6181 sw_if_index = ntohl (mp->sw_if_index);
6182 spd_id = ntohl (mp->spd_id);
6184 VALIDATE_SW_IF_INDEX (mp);
6187 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6189 rv = VNET_API_ERROR_UNIMPLEMENTED;
6192 BAD_SW_IF_INDEX_LABEL;
6194 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6197 static void vl_api_ipsec_spd_add_del_entry_t_handler
6198 (vl_api_ipsec_spd_add_del_entry_t * mp)
6200 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6201 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6207 memset (&p, 0, sizeof (p));
6209 p.id = ntohl (mp->spd_id);
6210 p.priority = ntohl (mp->priority);
6211 p.is_outbound = mp->is_outbound;
6212 p.is_ipv6 = mp->is_ipv6;
6214 if (mp->is_ipv6 || mp->is_ip_any)
6216 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6217 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6218 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6219 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6223 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6224 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6225 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6226 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6228 p.protocol = mp->protocol;
6229 p.rport.start = ntohs (mp->remote_port_start);
6230 p.rport.stop = ntohs (mp->remote_port_stop);
6231 p.lport.start = ntohs (mp->local_port_start);
6232 p.lport.stop = ntohs (mp->local_port_stop);
6233 /* policy action resolve unsupported */
6234 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6236 clib_warning ("unsupported action: 'resolve'");
6237 rv = VNET_API_ERROR_UNIMPLEMENTED;
6240 p.policy = mp->policy;
6241 p.sa_id = ntohl (mp->sa_id);
6243 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6250 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6253 rv = VNET_API_ERROR_UNIMPLEMENTED;
6258 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6261 static void vl_api_ipsec_sad_add_del_entry_t_handler
6262 (vl_api_ipsec_sad_add_del_entry_t * mp)
6264 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6265 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6270 memset (&sa, 0, sizeof (sa));
6272 sa.id = ntohl (mp->sad_id);
6273 sa.spi = ntohl (mp->spi);
6274 /* security protocol AH unsupported */
6275 if (mp->protocol == IPSEC_PROTOCOL_AH)
6277 clib_warning ("unsupported security protocol 'AH'");
6278 rv = VNET_API_ERROR_UNIMPLEMENTED;
6281 sa.protocol = mp->protocol;
6282 /* check for unsupported crypto-alg */
6283 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6284 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6286 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6287 mp->crypto_algorithm);
6288 rv = VNET_API_ERROR_UNIMPLEMENTED;
6291 sa.crypto_alg = mp->crypto_algorithm;
6292 sa.crypto_key_len = mp->crypto_key_length;
6293 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6294 /* check for unsupported integ-alg */
6295 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6296 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6298 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6299 mp->integrity_algorithm);
6300 rv = VNET_API_ERROR_UNIMPLEMENTED;
6303 sa.integ_alg = mp->integrity_algorithm;
6304 sa.integ_key_len = mp->integrity_key_length;
6305 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6306 sa.use_esn = mp->use_extended_sequence_number;
6307 sa.is_tunnel = mp->is_tunnel;
6308 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6309 if (sa.is_tunnel_ip6)
6311 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6312 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6316 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6317 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6320 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6322 rv = VNET_API_ERROR_UNIMPLEMENTED;
6327 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6331 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6333 vl_api_ikev2_profile_add_del_reply_t *rmp;
6337 vlib_main_t *vm = vlib_get_main ();
6338 clib_error_t *error;
6339 u8 *tmp = format (0, "%s", mp->name);
6340 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6343 rv = VNET_API_ERROR_UNSPECIFIED;
6345 rv = VNET_API_ERROR_UNIMPLEMENTED;
6348 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6352 vl_api_ikev2_profile_set_auth_t_handler
6353 (vl_api_ikev2_profile_set_auth_t * mp)
6355 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6359 vlib_main_t *vm = vlib_get_main ();
6360 clib_error_t *error;
6361 u8 *tmp = format (0, "%s", mp->name);
6362 u8 *data = vec_new (u8, mp->data_len);
6363 clib_memcpy (data, mp->data, mp->data_len);
6364 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6368 rv = VNET_API_ERROR_UNSPECIFIED;
6370 rv = VNET_API_ERROR_UNIMPLEMENTED;
6373 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6377 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6379 vl_api_ikev2_profile_add_del_reply_t *rmp;
6383 vlib_main_t *vm = vlib_get_main ();
6384 clib_error_t *error;
6385 u8 *tmp = format (0, "%s", mp->name);
6386 u8 *data = vec_new (u8, mp->data_len);
6387 clib_memcpy (data, mp->data, mp->data_len);
6388 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6392 rv = VNET_API_ERROR_UNSPECIFIED;
6394 rv = VNET_API_ERROR_UNIMPLEMENTED;
6397 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6401 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6403 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6407 vlib_main_t *vm = vlib_get_main ();
6408 clib_error_t *error;
6409 u8 *tmp = format (0, "%s", mp->name);
6410 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6411 mp->end_port, (ip4_address_t) mp->start_addr,
6412 (ip4_address_t) mp->end_addr, mp->is_local);
6415 rv = VNET_API_ERROR_UNSPECIFIED;
6417 rv = VNET_API_ERROR_UNIMPLEMENTED;
6420 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6424 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6426 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6430 vlib_main_t *vm = vlib_get_main ();
6431 clib_error_t *error;
6433 error = ikev2_set_local_key (vm, mp->key_file);
6435 rv = VNET_API_ERROR_UNSPECIFIED;
6437 rv = VNET_API_ERROR_UNIMPLEMENTED;
6440 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6444 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6446 vl_api_map_add_domain_reply_t *rmp;
6449 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6451 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6452 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6453 (ip6_address_t *) & mp->ip6_src,
6454 mp->ip6_src_prefix_len, mp->ea_bits_len,
6455 mp->psid_offset, mp->psid_length, &index,
6456 ntohs (mp->mtu), flags);
6459 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6461 rmp->index = ntohl(index);
6467 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6469 vl_api_map_del_domain_reply_t *rmp;
6472 rv = map_delete_domain (ntohl (mp->index));
6474 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6478 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6480 vl_api_map_del_domain_reply_t *rmp;
6484 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6485 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6487 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6491 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6493 vl_api_map_domain_details_t *rmp;
6494 map_main_t *mm = &map_main;
6496 unix_shared_memory_queue_t *q;
6498 if (pool_elts (mm->domains) == 0)
6501 q = vl_api_client_index_to_input_queue (mp->client_index);
6508 pool_foreach(d, mm->domains,
6510 /* Make sure every field is initiated (or don't skip the memset()) */
6511 rmp = vl_msg_api_alloc (sizeof (*rmp));
6512 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6513 rmp->domain_index = htonl(d - mm->domains);
6514 rmp->ea_bits_len = d->ea_bits_len;
6515 rmp->psid_offset = d->psid_offset;
6516 rmp->psid_length = d->psid_length;
6517 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6518 rmp->ip4_prefix_len = d->ip4_prefix_len;
6519 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6520 rmp->ip6_prefix_len = d->ip6_prefix_len;
6521 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6522 rmp->ip6_src_len = d->ip6_src_len;
6523 rmp->mtu = htons(d->mtu);
6524 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6525 rmp->context = mp->context;
6527 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6533 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6535 unix_shared_memory_queue_t *q;
6538 vl_api_map_rule_details_t *rmp;
6539 map_main_t *mm = &map_main;
6540 u32 domain_index = ntohl (mp->domain_index);
6543 if (pool_elts (mm->domains) == 0)
6546 d = pool_elt_at_index (mm->domains, domain_index);
6547 if (!d || !d->rules)
6552 q = vl_api_client_index_to_input_queue (mp->client_index);
6558 for (i = 0; i < (0x1 << d->psid_length); i++)
6561 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6565 rmp = vl_msg_api_alloc (sizeof (*rmp));
6566 memset (rmp, 0, sizeof (*rmp));
6567 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6568 rmp->psid = htons (i);
6569 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6570 rmp->context = mp->context;
6571 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6576 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6578 vl_api_map_summary_stats_reply_t *rmp;
6579 vlib_combined_counter_main_t *cm;
6582 u64 total_pkts[VLIB_N_RX_TX];
6583 u64 total_bytes[VLIB_N_RX_TX];
6584 map_main_t *mm = &map_main;
6585 unix_shared_memory_queue_t *q =
6586 vl_api_client_index_to_input_queue (mp->client_index);
6591 rmp = vl_msg_api_alloc (sizeof (*rmp));
6592 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6593 rmp->context = mp->context;
6596 memset (total_pkts, 0, sizeof (total_pkts));
6597 memset (total_bytes, 0, sizeof (total_bytes));
6599 map_domain_counter_lock (mm);
6600 vec_foreach (cm, mm->domain_counters)
6602 which = cm - mm->domain_counters;
6604 for (i = 0; i < vec_len (cm->maxi); i++)
6606 vlib_get_combined_counter (cm, i, &v);
6607 total_pkts[which] += v.packets;
6608 total_bytes[which] += v.bytes;
6612 map_domain_counter_unlock (mm);
6614 /* Note: in network byte order! */
6615 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6616 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6617 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6618 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6619 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6620 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6621 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6622 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6623 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6624 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6625 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6626 clib_host_to_net_u64 (map_error_counter_get
6627 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6628 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6629 clib_host_to_net_u64 (map_error_counter_get
6630 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6632 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6636 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6638 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6639 vl_api_ipsec_sa_set_key_reply_t *rmp;
6643 sa.id = ntohl (mp->sa_id);
6644 sa.crypto_key_len = mp->crypto_key_length;
6645 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6646 sa.integ_key_len = mp->integrity_key_length;
6647 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6649 rv = ipsec_set_sa_key (vm, &sa);
6651 rv = VNET_API_ERROR_UNIMPLEMENTED;
6654 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6657 static void vl_api_cop_interface_enable_disable_t_handler
6658 (vl_api_cop_interface_enable_disable_t * mp)
6660 vl_api_cop_interface_enable_disable_reply_t *rmp;
6662 u32 sw_if_index = ntohl (mp->sw_if_index);
6665 VALIDATE_SW_IF_INDEX (mp);
6667 enable_disable = (int) mp->enable_disable;
6669 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6671 BAD_SW_IF_INDEX_LABEL;
6673 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6676 static void vl_api_cop_whitelist_enable_disable_t_handler
6677 (vl_api_cop_whitelist_enable_disable_t * mp)
6679 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6680 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6681 u32 sw_if_index = ntohl (mp->sw_if_index);
6684 VALIDATE_SW_IF_INDEX (mp);
6686 a->sw_if_index = sw_if_index;
6689 a->default_cop = mp->default_cop;
6690 a->fib_id = ntohl (mp->fib_id);
6692 rv = cop_whitelist_enable_disable (a);
6694 BAD_SW_IF_INDEX_LABEL;
6696 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6700 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6704 api_main_t *am = &api_main;
6705 vlib_main_t *vm = vlib_get_main ();
6707 vl_api_get_node_graph_reply_t *rmp;
6709 pthread_mutex_lock (&am->vlib_rp->mutex);
6710 oldheap = svm_push_data_heap (am->vlib_rp);
6713 * Keep the number of memcpy ops to a minimum (e.g. 1).
6715 vec_validate (vector, 16384);
6716 vec_reset_length (vector);
6719 vector = vlib_node_serialize (&vm->node_main, vector,
6720 (u32) ~ 0 /* all threads */ ,
6721 1 /* include nexts */ ,
6722 1 /* include stats */ );
6724 svm_pop_heap (oldheap);
6725 pthread_mutex_unlock (&am->vlib_rp->mutex);
6728 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6730 rmp->reply_in_shmem = (uword) vector;
6735 static void vl_api_trace_profile_add_t_handler
6736 (vl_api_trace_profile_add_t * mp)
6739 vl_api_trace_profile_add_reply_t *rmp;
6740 clib_error_t *error;
6742 /* Ignoring the profile id as currently a single profile
6744 error = ip6_ioam_trace_profile_set (mp->trace_num_elt, mp->trace_type,
6745 ntohl (mp->node_id),
6746 ntohl (mp->trace_app_data),
6747 mp->pow_enable, mp->trace_tsp,
6751 clib_error_report (error);
6752 rv = clib_error_get_code (error);
6755 REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
6758 static void vl_api_trace_profile_apply_t_handler
6759 (vl_api_trace_profile_apply_t * mp)
6762 vl_api_trace_profile_apply_reply_t *rmp;
6764 if (mp->enable != 0)
6766 rv = ip6_ioam_set_destination ((ip6_address_t *) (&mp->dest_ipv6),
6767 ntohl (mp->prefix_length),
6769 mp->trace_op == IOAM_HBYH_ADD,
6770 mp->trace_op == IOAM_HBYH_POP,
6771 mp->trace_op == IOAM_HBYH_MOD);
6775 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6777 REPLY_MACRO (VL_API_TRACE_PROFILE_APPLY_REPLY);
6780 static void vl_api_trace_profile_del_t_handler
6781 (vl_api_trace_profile_del_t * mp)
6784 vl_api_trace_profile_del_reply_t *rmp;
6785 clib_error_t *error;
6787 error = clear_ioam_rewrite_fn ();
6790 clib_error_report (error);
6791 rv = clib_error_get_code (error);
6794 REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
6798 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6800 vlib_main_t *vm = vlib_get_main ();
6801 vl_api_af_packet_create_reply_t *rmp;
6803 u8 *host_if_name = NULL;
6806 host_if_name = format (0, "%s", mp->host_if_name);
6807 vec_add1 (host_if_name, 0);
6809 rv = af_packet_create_if (vm, host_if_name,
6810 mp->use_random_hw_addr ? 0 : mp->hw_addr,
6813 vec_free (host_if_name);
6816 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6818 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
6824 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
6826 vlib_main_t *vm = vlib_get_main ();
6827 vl_api_af_packet_delete_reply_t *rmp;
6829 u8 *host_if_name = NULL;
6831 host_if_name = format (0, "%s", mp->host_if_name);
6832 vec_add1 (host_if_name, 0);
6834 rv = af_packet_delete_if (vm, host_if_name);
6836 vec_free (host_if_name);
6838 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
6842 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
6844 vlib_main_t *vm = vlib_get_main ();
6845 vl_api_policer_add_del_reply_t *rmp;
6848 sse2_qos_pol_cfg_params_st cfg;
6849 clib_error_t *error;
6852 name = format (0, "%s", mp->name);
6854 memset (&cfg, 0, sizeof (cfg));
6856 cfg.rnd_type = mp->round_type;
6857 cfg.rate_type = mp->rate_type;
6858 cfg.rb.kbps.cir_kbps = mp->cir;
6859 cfg.rb.kbps.eir_kbps = mp->eir;
6860 cfg.rb.kbps.cb_bytes = mp->cb;
6861 cfg.rb.kbps.eb_bytes = mp->eb;
6862 cfg.conform_action.action_type = mp->conform_action_type;
6863 cfg.conform_action.dscp = mp->conform_dscp;
6864 cfg.exceed_action.action_type = mp->exceed_action_type;
6865 cfg.exceed_action.dscp = mp->exceed_dscp;
6866 cfg.violate_action.action_type = mp->violate_action_type;
6867 cfg.violate_action.dscp = mp->violate_dscp;
6868 cfg.color_aware = mp->color_aware;
6870 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
6873 rv = VNET_API_ERROR_UNSPECIFIED;
6876 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6878 if (rv == 0 && mp->is_add)
6879 rmp->policer_index = ntohl(policer_index);
6881 rmp->policer_index = ~0;
6887 send_policer_details (u8 * name,
6888 sse2_qos_pol_cfg_params_st * config,
6889 policer_read_response_type_st * templ,
6890 unix_shared_memory_queue_t * q, u32 context)
6892 vl_api_policer_details_t *mp;
6894 mp = vl_msg_api_alloc (sizeof (*mp));
6895 memset (mp, 0, sizeof (*mp));
6896 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6897 mp->context = context;
6898 mp->cir = htonl (config->rb.kbps.cir_kbps);
6899 mp->eir = htonl (config->rb.kbps.eir_kbps);
6900 mp->cb = htonl (config->rb.kbps.cb_bytes);
6901 mp->eb = htonl (config->rb.kbps.eb_bytes);
6902 mp->rate_type = config->rate_type;
6903 mp->round_type = config->rnd_type;
6904 mp->type = config->rfc;
6905 mp->conform_action_type = config->conform_action.action_type;
6906 mp->conform_dscp = config->conform_action.dscp;
6907 mp->exceed_action_type = config->exceed_action.action_type;
6908 mp->exceed_dscp = config->exceed_action.dscp;
6909 mp->violate_action_type = config->violate_action.action_type;
6910 mp->violate_dscp = config->violate_action.dscp;
6911 mp->single_rate = templ->single_rate ? 1 : 0;
6912 mp->color_aware = templ->color_aware ? 1 : 0;
6913 mp->scale = htonl (templ->scale);
6914 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
6915 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
6916 mp->current_limit = htonl (templ->current_limit);
6917 mp->current_bucket = htonl (templ->current_bucket);
6918 mp->extended_limit = htonl (templ->extended_limit);
6919 mp->extended_bucket = htonl (templ->extended_bucket);
6920 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
6922 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
6924 vl_msg_api_send_shmem (q, (u8 *) & mp);
6928 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
6930 unix_shared_memory_queue_t *q;
6931 vnet_policer_main_t *pm = &vnet_policer_main;
6937 sse2_qos_pol_cfg_params_st *config;
6938 policer_read_response_type_st *templ;
6940 q = vl_api_client_index_to_input_queue (mp->client_index);
6944 if (mp->match_name_valid)
6946 match_name = format (0, "%s%c", mp->match_name, 0);
6949 if (mp->match_name_valid)
6951 p = hash_get_mem (pm->policer_config_by_name, match_name);
6955 config = pool_elt_at_index (pm->configs, pool_index);
6956 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6957 send_policer_details (match_name, config, templ, q, mp->context);
6963 hash_foreach_pair (hp, pm->policer_config_by_name,
6965 name = (u8 *) hp->key;
6966 pool_index = hp->value[0];
6967 config = pool_elt_at_index (pm->configs, pool_index);
6968 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6969 send_policer_details(name, config, templ, q, mp->context);
6976 vl_api_policer_classify_set_interface_t_handler
6977 (vl_api_policer_classify_set_interface_t * mp)
6979 vlib_main_t *vm = vlib_get_main ();
6980 vl_api_policer_classify_set_interface_reply_t *rmp;
6982 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6984 ip4_table_index = ntohl (mp->ip4_table_index);
6985 ip6_table_index = ntohl (mp->ip6_table_index);
6986 l2_table_index = ntohl (mp->l2_table_index);
6987 sw_if_index = ntohl (mp->sw_if_index);
6989 VALIDATE_SW_IF_INDEX (mp);
6991 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
6992 ip6_table_index, l2_table_index,
6995 BAD_SW_IF_INDEX_LABEL;
6997 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7001 send_policer_classify_details (u32 sw_if_index,
7003 unix_shared_memory_queue_t * q, u32 context)
7005 vl_api_policer_classify_details_t *mp;
7007 mp = vl_msg_api_alloc (sizeof (*mp));
7008 memset (mp, 0, sizeof (*mp));
7009 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7010 mp->context = context;
7011 mp->sw_if_index = htonl (sw_if_index);
7012 mp->table_index = htonl (table_index);
7014 vl_msg_api_send_shmem (q, (u8 *) & mp);
7018 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7020 unix_shared_memory_queue_t *q;
7021 policer_classify_main_t *pcm = &policer_classify_main;
7025 q = vl_api_client_index_to_input_queue (mp->client_index);
7029 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7031 if (vec_len (vec_tbl))
7033 for (i = 0; i < vec_len (vec_tbl); i++)
7035 if (vec_elt (vec_tbl, i) == ~0)
7038 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7045 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7047 vlib_main_t *vm = vlib_get_main ();
7048 vl_api_netmap_create_reply_t *rmp;
7052 if_name = format (0, "%s", mp->netmap_if_name);
7053 vec_add1 (if_name, 0);
7056 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7057 mp->is_pipe, mp->is_master, 0);
7061 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7065 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7067 vlib_main_t *vm = vlib_get_main ();
7068 vl_api_netmap_delete_reply_t *rmp;
7072 if_name = format (0, "%s", mp->netmap_if_name);
7073 vec_add1 (if_name, 0);
7075 rv = netmap_delete_if (vm, if_name);
7079 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7083 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7086 clib_warning ("BUG");
7090 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7091 unix_shared_memory_queue_t * q,
7092 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7094 vl_api_mpls_gre_tunnel_details_t *mp;
7095 mpls_main_t *mm = &mpls_main;
7100 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7101 nlabels = vec_len (e->labels);
7103 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7104 memset (mp, 0, sizeof (*mp));
7105 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7106 mp->context = context;
7108 mp->tunnel_index = htonl (index);
7109 mp->tunnel_src = gt->tunnel_src.as_u32;
7110 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7111 mp->intfc_address = gt->intfc_address.as_u32;
7112 mp->mask_width = htonl (gt->mask_width);
7113 mp->inner_fib_index = htonl (gt->inner_fib_index);
7114 mp->outer_fib_index = htonl (gt->outer_fib_index);
7115 mp->encap_index = htonl (gt->encap_index);
7116 mp->hw_if_index = htonl (gt->hw_if_index);
7117 mp->l2_only = htonl (gt->l2_only);
7118 mp->nlabels = htonl (nlabels);
7120 for (i = 0; i < nlabels; i++)
7123 htonl (vnet_mpls_uc_get_label
7124 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7127 vl_msg_api_send_shmem (q, (u8 *) & mp);
7131 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7133 vpe_api_main_t *am = &vpe_api_main;
7134 unix_shared_memory_queue_t *q;
7135 mpls_main_t *mm = &mpls_main;
7136 mpls_gre_tunnel_t *gt;
7137 u32 index = ntohl (mp->tunnel_index);
7139 q = vl_api_client_index_to_input_queue (mp->client_index);
7145 if (!pool_is_free_index (mm->gre_tunnels, index))
7147 gt = pool_elt_at_index (mm->gre_tunnels, index);
7148 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7155 pool_foreach (gt, mm->gre_tunnels,
7157 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7165 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7168 clib_warning ("BUG");
7172 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7173 unix_shared_memory_queue_t * q,
7174 mpls_eth_tunnel_t * et, u32 index, u32 context)
7176 mpls_main_t *mm = &mpls_main;
7180 vl_api_mpls_eth_tunnel_details_t *mp;
7182 e = pool_elt_at_index (mm->encaps, et->encap_index);
7183 nlabels = vec_len (e->labels);
7185 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7186 memset (mp, 0, sizeof (*mp));
7187 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7188 mp->context = context;
7190 mp->tunnel_index = htonl (index);
7191 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7192 mp->intfc_address = et->intfc_address.as_u32;
7193 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7194 mp->inner_fib_index = htonl (et->inner_fib_index);
7195 mp->mask_width = htonl (et->mask_width);
7196 mp->encap_index = htonl (et->encap_index);
7197 mp->hw_if_index = htonl (et->hw_if_index);
7198 mp->l2_only = htonl (et->l2_only);
7199 mp->nlabels = htonl (nlabels);
7201 for (i = 0; i < nlabels; i++)
7204 htonl (vnet_mpls_uc_get_label
7205 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7208 vl_msg_api_send_shmem (q, (u8 *) & mp);
7212 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7214 vpe_api_main_t *am = &vpe_api_main;
7215 unix_shared_memory_queue_t *q;
7216 mpls_main_t *mm = &mpls_main;
7217 mpls_eth_tunnel_t *et;
7218 u32 index = ntohl (mp->tunnel_index);
7220 q = vl_api_client_index_to_input_queue (mp->client_index);
7226 if (!pool_is_free_index (mm->eth_tunnels, index))
7228 et = pool_elt_at_index (mm->eth_tunnels, index);
7229 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7236 pool_foreach (et, mm->eth_tunnels,
7238 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7246 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7248 clib_warning ("BUG");
7252 send_mpls_fib_encap_details (vpe_api_main_t * am,
7253 unix_shared_memory_queue_t * q,
7254 show_mpls_fib_t * s, u32 context)
7256 vl_api_mpls_fib_encap_details_t *mp;
7257 mpls_main_t *mm = &mpls_main;
7262 e = pool_elt_at_index (mm->encaps, s->entry_index);
7263 nlabels = vec_len (e->labels);
7265 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7266 memset (mp, 0, sizeof (*mp));
7267 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7268 mp->context = context;
7270 mp->fib_index = htonl (s->fib_index);
7271 mp->entry_index = htonl (s->entry_index);
7273 mp->s_bit = htonl (s->s_bit);
7275 mp->nlabels = htonl (nlabels);
7277 for (i = 0; i < nlabels; i++)
7280 htonl (vnet_mpls_uc_get_label
7281 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7284 vl_msg_api_send_shmem (q, (u8 *) & mp);
7288 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7290 vpe_api_main_t *am = &vpe_api_main;
7291 unix_shared_memory_queue_t *q;
7292 vlib_main_t *vm = &vlib_global_main;
7295 show_mpls_fib_t *records = 0;
7297 mpls_main_t *mm = &mpls_main;
7298 ip4_main_t *im = &ip4_main;
7301 q = vl_api_client_index_to_input_queue (mp->client_index);
7306 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7308 vec_add2 (records, s, 1);
7309 s->fib_index = (u32)(key>>32);
7310 s->dest = (u32)(key & 0xFFFFFFFF);
7311 s->entry_index = (u32) value;
7315 if (0 == vec_len (records))
7317 vlib_cli_output (vm, "MPLS encap table empty");
7321 /* sort output by dst address within fib */
7322 vec_sort_with_function (records, mpls_dest_cmp);
7323 vec_sort_with_function (records, mpls_fib_index_cmp);
7324 vlib_cli_output (vm, "MPLS encap table");
7325 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7326 vec_foreach (s, records)
7328 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7329 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7330 format_ip4_address, &s->dest, format_mpls_encap_index,
7331 mm, s->entry_index);
7332 send_mpls_fib_encap_details (am, q, s, mp->context);
7340 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7342 clib_warning ("BUG");
7346 send_mpls_fib_decap_details (vpe_api_main_t * am,
7347 unix_shared_memory_queue_t * q,
7348 show_mpls_fib_t * s,
7350 u32 tx_table_id, char *swif_tag, u32 context)
7352 vl_api_mpls_fib_decap_details_t *mp;
7354 mp = vl_msg_api_alloc (sizeof (*mp));
7355 memset (mp, 0, sizeof (*mp));
7356 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7357 mp->context = context;
7359 mp->fib_index = htonl (s->fib_index);
7360 mp->entry_index = htonl (s->entry_index);
7362 mp->s_bit = htonl (s->s_bit);
7363 mp->label = htonl (s->label);
7364 mp->rx_table_id = htonl (rx_table_id);
7365 mp->tx_table_id = htonl (tx_table_id);
7366 strncpy ((char *) mp->swif_tag,
7367 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7369 vl_msg_api_send_shmem (q, (u8 *) & mp);
7373 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7375 vpe_api_main_t *am = &vpe_api_main;
7376 unix_shared_memory_queue_t *q;
7377 vlib_main_t *vm = &vlib_global_main;
7380 show_mpls_fib_t *records = 0;
7382 mpls_main_t *mm = &mpls_main;
7383 ip4_main_t *im = &ip4_main;
7389 q = vl_api_client_index_to_input_queue (mp->client_index);
7394 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7396 vec_add2 (records, s, 1);
7397 s->fib_index = (u32)(key>>32);
7398 s->entry_index = (u32) value;
7399 s->label = ((u32) key)>>12;
7400 s->s_bit = (key & (1<<8)) != 0;
7404 if (!vec_len (records))
7406 vlib_cli_output (vm, "MPLS decap table empty");
7410 vec_sort_with_function (records, mpls_label_cmp);
7411 vlib_cli_output (vm, "MPLS decap table");
7412 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7414 vec_foreach (s, records)
7417 d = pool_elt_at_index (mm->decaps, s->entry_index);
7418 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT)
7420 tx_fib = vec_elt_at_index (im->fibs, d->tx_fib_index);
7421 tx_table_id = tx_fib->table_id;
7426 tx_table_id = d->tx_fib_index;
7429 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7431 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7432 tx_table_id, swif_tag, s->label, s->s_bit);
7434 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7435 tx_table_id, swif_tag, mp->context);
7443 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7445 unix_shared_memory_queue_t *q;
7447 q = vl_api_client_index_to_input_queue (mp->client_index);
7451 vnet_classify_main_t *cm = &vnet_classify_main;
7452 vnet_classify_table_t *t;
7457 pool_foreach (t, cm->tables,
7459 vec_add1 (table_ids, ntohl(t - cm->tables));
7462 count = vec_len (table_ids);
7464 vl_api_classify_table_ids_reply_t *rmp;
7465 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7466 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7467 rmp->context = mp->context;
7468 rmp->count = ntohl (count);
7469 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7472 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7474 vec_free (table_ids);
7478 vl_api_classify_table_by_interface_t_handler
7479 (vl_api_classify_table_by_interface_t * mp)
7481 vl_api_classify_table_by_interface_reply_t *rmp;
7484 u32 sw_if_index = ntohl (mp->sw_if_index);
7487 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7490 VALIDATE_SW_IF_INDEX (mp);
7492 input_acl_main_t *am = &input_acl_main;
7497 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7499 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7500 if (vec_len (vec_tbl))
7502 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7504 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7508 acl[type] = vec_elt (vec_tbl, if_idx);
7513 BAD_SW_IF_INDEX_LABEL;
7516 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7518 rmp->sw_if_index = ntohl(sw_if_index);
7519 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7520 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7521 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7528 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7530 unix_shared_memory_queue_t *q;
7532 q = vl_api_client_index_to_input_queue (mp->client_index);
7536 vl_api_classify_table_info_reply_t *rmp = 0;
7538 vnet_classify_main_t *cm = &vnet_classify_main;
7539 u32 table_id = ntohl (mp->table_id);
7540 vnet_classify_table_t *t;
7543 pool_foreach (t, cm->tables,
7545 if (table_id == t - cm->tables)
7547 rmp = vl_msg_api_alloc_as_if_client
7548 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7549 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7550 rmp->context = mp->context;
7551 rmp->table_id = ntohl(table_id);
7552 rmp->nbuckets = ntohl(t->nbuckets);
7553 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7554 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7555 rmp->active_sessions = ntohl(t->active_elements);
7556 rmp->next_table_index = ntohl(t->next_table_index);
7557 rmp->miss_next_index = ntohl(t->miss_next_index);
7558 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7559 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7568 rmp = vl_msg_api_alloc (sizeof (*rmp));
7569 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7570 rmp->context = mp->context;
7571 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7574 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7578 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7581 clib_warning ("BUG");
7585 send_classify_session_details (unix_shared_memory_queue_t * q,
7588 vnet_classify_entry_t * e, u32 context)
7590 vl_api_classify_session_details_t *rmp;
7592 rmp = vl_msg_api_alloc (sizeof (*rmp));
7593 memset (rmp, 0, sizeof (*rmp));
7594 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7595 rmp->context = context;
7596 rmp->table_id = ntohl (table_id);
7597 rmp->hit_next_index = ntohl (e->next_index);
7598 rmp->advance = ntohl (e->advance);
7599 rmp->opaque_index = ntohl (e->opaque_index);
7600 rmp->match_length = ntohl (match_length);
7601 clib_memcpy (rmp->match, e->key, match_length);
7603 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7607 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7609 vnet_classify_main_t *cm = &vnet_classify_main;
7610 unix_shared_memory_queue_t *q;
7612 u32 table_id = ntohl (mp->table_id);
7613 vnet_classify_table_t *t;
7615 q = vl_api_client_index_to_input_queue (mp->client_index);
7618 pool_foreach (t, cm->tables,
7620 if (table_id == t - cm->tables)
7622 vnet_classify_bucket_t * b;
7623 vnet_classify_entry_t * v, * save_v;
7626 for (i = 0; i < t->nbuckets; i++)
7628 b = &t->buckets [i];
7632 save_v = vnet_classify_get_entry (t, b->offset);
7633 for (j = 0; j < (1<<b->log2_pages); j++)
7635 for (k = 0; k < t->entries_per_page; k++)
7637 v = vnet_classify_entry_at_index
7638 (t, save_v, j*t->entries_per_page + k);
7639 if (vnet_classify_entry_is_free (v))
7642 send_classify_session_details
7643 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7655 vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t * mp)
7657 vlib_main_t *vm = vlib_get_main ();
7658 flow_report_main_t *frm = &flow_report_main;
7659 vl_api_ipfix_enable_reply_t *rmp;
7660 ip4_address_t collector, src;
7661 u16 collector_port = UDP_DST_PORT_ipfix;
7663 u32 template_interval;
7668 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7669 collector_port = ntohs (mp->collector_port);
7670 if (collector_port == (u16) ~ 0)
7671 collector_port = UDP_DST_PORT_ipfix;
7672 memcpy (src.data, mp->src_address, sizeof (src.data));
7673 fib_id = ntohl (mp->vrf_id);
7675 ip4_main_t *im = &ip4_main;
7676 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7679 rv = VNET_API_ERROR_NO_SUCH_FIB;
7684 path_mtu = ntohl (mp->path_mtu);
7686 path_mtu = 512; // RFC 7011 section 10.3.3.
7687 template_interval = ntohl (mp->template_interval);
7688 if (template_interval == ~0)
7689 template_interval = 20;
7691 if (collector.as_u32 == 0)
7693 rv = VNET_API_ERROR_INVALID_VALUE;
7697 if (src.as_u32 == 0)
7699 rv = VNET_API_ERROR_INVALID_VALUE;
7703 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7705 rv = VNET_API_ERROR_INVALID_VALUE;
7711 rv = VNET_API_ERROR_INVALID_VALUE;
7715 /* Reset report streams if we are reconfiguring IP addresses */
7716 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7717 frm->src_address.as_u32 != src.as_u32 ||
7718 frm->collector_port != collector_port)
7719 vnet_flow_reports_reset (frm);
7721 frm->ipfix_collector.as_u32 = collector.as_u32;
7722 frm->collector_port = collector_port;
7723 frm->src_address.as_u32 = src.as_u32;
7724 frm->fib_index = fib_index;
7725 frm->path_mtu = path_mtu;
7726 frm->template_interval = template_interval;
7728 /* Turn on the flow reporting process */
7729 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7732 REPLY_MACRO (VL_API_IPFIX_ENABLE_REPLY);
7736 vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t * mp)
7738 flow_report_main_t *frm = &flow_report_main;
7739 unix_shared_memory_queue_t *q;
7740 vl_api_ipfix_details_t *rmp;
7742 q = vl_api_client_index_to_input_queue (mp->client_index);
7746 rmp = vl_msg_api_alloc (sizeof (*rmp));
7747 memset (rmp, 0, sizeof (*rmp));
7748 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_DETAILS);
7749 rmp->context = mp->context;
7750 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7751 sizeof (frm->ipfix_collector.data));
7752 rmp->collector_port = htons (frm->collector_port);
7753 memcpy (rmp->src_address, frm->src_address.data,
7754 sizeof (frm->src_address.data));
7755 rmp->fib_index = htonl (frm->fib_index);
7756 rmp->path_mtu = htonl (frm->path_mtu);
7757 rmp->template_interval = htonl (frm->template_interval);
7759 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7763 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
7765 vl_api_pg_create_interface_reply_t *rmp;
7768 pg_main_t *pg = &pg_main;
7769 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
7772 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7774 rmp->sw_if_index = ntohl(sw_if_index);
7780 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
7782 vl_api_pg_capture_reply_t *rmp;
7785 vnet_main_t *vnm = vnet_get_main ();
7786 vnet_interface_main_t *im = &vnm->interface_main;
7787 vnet_hw_interface_t *hi = 0;
7789 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
7790 u32 hw_if_index = ~0;
7791 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
7794 vec_free (intf_name);
7796 if (hw_if_index != ~0)
7798 pg_capture_args_t _a, *a = &_a;
7800 u32 len = ntohl (mp->pcap_name_length);
7801 u8 *pcap_file_name = vec_new (u8, len);
7802 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
7804 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7805 a->hw_if_index = hw_if_index;
7806 a->dev_instance = hi->dev_instance;
7807 a->is_enabled = mp->is_enabled;
7808 a->pcap_file_name = pcap_file_name;
7809 a->count = ntohl (mp->count);
7811 clib_error_t *e = pg_capture (a);
7814 clib_error_report (e);
7815 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7818 vec_free (pcap_file_name);
7820 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
7824 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
7826 vl_api_pg_enable_disable_reply_t *rmp;
7829 pg_main_t *pg = &pg_main;
7830 u32 stream_index = ~0;
7832 int is_enable = mp->is_enabled != 0;
7833 u32 len = ntohl (mp->stream_name_length) - 1;
7837 u8 *stream_name = vec_new (u8, len);
7838 clib_memcpy (stream_name, mp->stream_name, len);
7839 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
7842 vec_free (stream_name);
7845 pg_enable_disable (stream_index, is_enable);
7847 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
7851 vl_api_ip_source_and_port_range_check_add_del_t_handler
7852 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
7854 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
7857 u8 is_ipv6 = mp->is_ipv6;
7858 u8 is_add = mp->is_add;
7859 u8 mask_length = mp->mask_length;
7860 ip4_address_t ip4_addr;
7861 ip6_address_t ip6_addr;
7863 u16 *high_ports = 0;
7865 u16 tmp_low, tmp_high;
7869 // Validate port range
7870 num_ranges = mp->number_of_ranges;
7871 if (num_ranges > 32)
7872 { // This is size of array in VPE.API
7873 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
7877 vec_reset_length (low_ports);
7878 vec_reset_length (high_ports);
7880 for (i = 0; i < num_ranges; i++)
7882 tmp_low = mp->low_ports[i];
7883 tmp_high = mp->high_ports[i];
7884 // If tmp_low <= tmp_high then only need to check tmp_low = 0
7885 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
7886 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
7888 rv = VNET_API_ERROR_INVALID_VALUE;
7891 vec_add1 (low_ports, tmp_low);
7892 vec_add1 (high_ports, tmp_high + 1);
7895 // Validate mask_length
7896 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
7898 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
7902 vrf_id = ntohl (mp->vrf_id);
7906 rv = VNET_API_ERROR_INVALID_VALUE;
7913 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
7914 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
7918 high_ports, is_add);
7922 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
7923 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
7927 high_ports, is_add);
7931 vec_free (low_ports);
7932 vec_free (high_ports);
7933 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
7937 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
7938 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
7940 vlib_main_t *vm = vlib_get_main ();
7941 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
7942 ip4_main_t *im = &ip4_main;
7945 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7946 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7950 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
7951 ntohl (mp->tcp_out_vrf_id);
7952 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
7953 ntohl (mp->udp_out_vrf_id);
7954 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
7955 ntohl (mp->tcp_in_vrf_id);
7956 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
7957 ntohl (mp->udp_in_vrf_id);
7960 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
7962 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
7964 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
7968 rv = VNET_API_ERROR_INVALID_VALUE;
7972 fib_index[i] = p[0];
7977 sw_if_index = ntohl (mp->sw_if_index);
7979 VALIDATE_SW_IF_INDEX (mp);
7982 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
7985 BAD_SW_IF_INDEX_LABEL;
7988 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
7991 #define BOUNCE_HANDLER(nn) \
7992 static void vl_api_##nn##_t_handler ( \
7993 vl_api_##nn##_t *mp) \
7995 vpe_client_registration_t *reg; \
7996 vpe_api_main_t * vam = &vpe_api_main; \
7997 unix_shared_memory_queue_t * q; \
7999 /* One registration only... */ \
8000 pool_foreach(reg, vam->nn##_registrations, \
8002 q = vl_api_client_index_to_input_queue (reg->client_index); \
8005 * If the queue is stuffed, turf the msg and complain \
8006 * It's unlikely that the intended recipient is \
8007 * alive; avoid deadlock at all costs. \
8009 if (q->cursize == q->maxsize) { \
8010 clib_warning ("ERROR: receiver queue full, drop msg"); \
8011 vl_msg_api_free (mp); \
8014 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8018 vl_msg_api_free (mp); \
8023 * Add vpe's API message handlers to the table.
8024 * vlib has alread mapped shared memory and
8025 * added the client registration handlers.
8026 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8029 static clib_error_t *
8030 vpe_api_hookup (vlib_main_t * vm)
8032 api_main_t *am = &api_main;
8035 vl_msg_api_set_handlers(VL_API_##N, #n, \
8036 vl_api_##n##_t_handler, \
8038 vl_api_##n##_t_endian, \
8039 vl_api_##n##_t_print, \
8040 sizeof(vl_api_##n##_t), 1);
8041 foreach_vpe_api_msg;
8045 * Manually register the sr tunnel add del msg, so we trace
8046 * enough bytes to capture a typical segment list
8048 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8049 "sr_tunnel_add_del",
8050 vl_api_sr_tunnel_add_del_t_handler,
8052 vl_api_sr_tunnel_add_del_t_endian,
8053 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8057 * Manually register the sr policy add del msg, so we trace
8058 * enough bytes to capture a typical tunnel name list
8060 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8061 "sr_policy_add_del",
8062 vl_api_sr_policy_add_del_t_handler,
8064 vl_api_sr_policy_add_del_t_endian,
8065 vl_api_sr_policy_add_del_t_print, 256, 1);
8068 * Trace space for 8 MPLS encap labels, classifier mask+match
8070 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8071 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8072 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8073 += 5 * sizeof (u32x4);
8074 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8077 * Thread-safe API messages
8079 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8080 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8085 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8087 static clib_error_t *
8088 vpe_api_init (vlib_main_t * vm)
8090 vpe_api_main_t *am = &vpe_api_main;
8093 am->vnet_main = vnet_get_main ();
8094 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8095 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8096 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8097 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8098 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8099 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8102 vl_set_memory_region_name ("/vpe-api");
8103 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8108 VLIB_INIT_FUNCTION (vpe_api_init);
8111 static clib_error_t *
8112 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8115 u64 baseva, size, pvt_heap_size;
8117 const int max_buf_size = 4096;
8119 struct passwd _pw, *pw;
8120 struct group _grp, *grp;
8122 buf = vec_new (char, 128);
8123 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8125 if (unformat (input, "prefix %s", &chroot_path))
8127 vec_add1 (chroot_path, 0);
8128 vl_set_memory_root_path ((char *) chroot_path);
8130 else if (unformat (input, "uid %d", &uid))
8131 vl_set_memory_uid (uid);
8132 else if (unformat (input, "gid %d", &gid))
8133 vl_set_memory_gid (gid);
8134 else if (unformat (input, "baseva %llx", &baseva))
8135 vl_set_global_memory_baseva (baseva);
8136 else if (unformat (input, "global-size %lldM", &size))
8137 vl_set_global_memory_size (size * (1ULL<<20));
8138 else if (unformat (input, "global-size %lldG", &size))
8139 vl_set_global_memory_size (size * (1ULL<<30));
8140 else if (unformat (input, "global-size %lld", &size))
8141 vl_set_global_memory_size (size);
8142 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8143 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL<<20));
8144 else if (unformat (input, "global-pvt-heap-size size %lld",
8146 vl_set_global_pvt_heap_size (pvt_heap_size);
8147 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8148 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL<<20));
8149 else if (unformat (input, "api-pvt-heap-size size %lld",
8151 vl_set_api_pvt_heap_size (pvt_heap_size);
8152 else if (unformat (input, "api-size %lldM", &size))
8153 vl_set_api_memory_size (size * (1ULL<<20));
8154 else if (unformat (input, "api-size %lldG", &size))
8155 vl_set_api_memory_size (size * (1ULL<<30));
8156 else if (unformat (input, "api-size %lld", &size))
8157 vl_set_api_memory_size (size);
8158 else if (unformat (input, "uid %s", &s))
8160 /* lookup the username */
8163 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8164 && (vec_len (buf) <= max_buf_size))
8166 vec_resize (buf, vec_len (buf) * 2);
8170 e = clib_error_return_code (0, rv,
8171 CLIB_ERROR_ERRNO_VALID |
8173 "cannot fetch username %s", s);
8181 clib_error_return_fatal (0, "username %s does not exist", s);
8187 vl_set_memory_uid (pw->pw_uid);
8189 else if (unformat (input, "gid %s", &s))
8191 /* lookup the group name */
8194 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8195 && (vec_len (buf) <= max_buf_size))
8197 vec_resize (buf, vec_len (buf) * 2);
8201 e = clib_error_return_code (0, rv,
8202 CLIB_ERROR_ERRNO_VALID |
8204 "cannot fetch group %s", s);
8211 e = clib_error_return_fatal (0, "group %s does not exist", s);
8218 vl_set_memory_gid (grp->gr_gid);
8221 return clib_error_return (0, "unknown input `%U'",
8222 format_unformat_error, input);
8227 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8230 get_unformat_vnet_sw_interface (void)
8232 return (void *) &unformat_vnet_sw_interface;
8235 #undef vl_api_version
8236 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8237 #include <vpp-api/vpe.api.h>
8238 #undef vl_api_version
8241 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8243 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8245 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8246 clib_host_to_net_u32 (mp->api_versions[0]),
8254 format_arp_event (u8 * s, va_list * args)
8256 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8258 s = format (s, "pid %d: %U", event->pid,
8259 format_ip4_address, &event->address);
8263 static clib_error_t *
8264 show_ip4_arp_events_fn (vlib_main_t * vm,
8265 unformat_input_t * input, vlib_cli_command_t * cmd)
8267 vpe_api_main_t *am = &vpe_api_main;
8268 vl_api_ip4_arp_event_t *event;
8270 if (pool_elts (am->arp_events) == 0)
8272 vlib_cli_output (vm, "No active arp event registrations");
8277 pool_foreach (event, am->arp_events,
8279 vlib_cli_output (vm, "%U", format_arp_event, event);
8287 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
8288 .path = "show arp event registrations",
8289 .function = show_ip4_arp_events_fn,
8290 .short_help = "Show arp event registrations",
8295 * fd.io coding-style-patch-verification: ON
8298 * eval: (c-set-style "gnu")