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;
2594 vec_reset_length (my_vnet_mains);
2596 for (i = 0; i < vec_len (vnet_mains); i++)
2599 vec_add1 (my_vnet_mains, vnet_mains[i]);
2602 if (vec_len (vnet_mains) == 0)
2603 vec_add1 (my_vnet_mains, vnm);
2605 n_counters = vec_len (im->combined_sw_if_counters);
2607 for (j = 0; j < n_counters; j++)
2609 for (i = 0; i < vec_len (my_vnet_mains); i++)
2611 im = &my_vnet_mains[i]->interface_main;
2612 cm = im->combined_sw_if_counters + j;
2613 if (mp->sw_if_index == (u32) ~ 0)
2614 vlib_clear_combined_counters (cm);
2616 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2620 n_counters = vec_len (im->sw_if_counters);
2622 for (j = 0; j < n_counters; j++)
2624 for (i = 0; i < vec_len (my_vnet_mains); i++)
2626 im = &my_vnet_mains[i]->interface_main;
2627 sm = im->sw_if_counters + j;
2628 if (mp->sw_if_index == (u32) ~ 0)
2629 vlib_clear_simple_counters (sm);
2631 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2635 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2639 send_sw_interface_details (vpe_api_main_t * am,
2640 unix_shared_memory_queue_t * q,
2641 vnet_sw_interface_t * swif,
2642 u8 * interface_name, u32 context)
2644 vl_api_sw_interface_details_t *mp;
2645 vnet_hw_interface_t *hi;
2647 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2649 mp = vl_msg_api_alloc (sizeof (*mp));
2650 memset (mp, 0, sizeof (*mp));
2651 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2652 mp->sw_if_index = ntohl (swif->sw_if_index);
2653 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2654 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2655 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2656 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2657 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2658 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2659 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2660 mp->link_mtu = ntohs (hi->max_packet_bytes);
2661 mp->context = context;
2663 strncpy ((char *) mp->interface_name,
2664 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2666 /* Send the L2 address for ethernet physical intfcs */
2667 if (swif->sup_sw_if_index == swif->sw_if_index
2668 && hi->hw_class_index == ethernet_hw_interface_class.index)
2670 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2671 ethernet_interface_t *ei;
2673 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2674 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2675 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2676 mp->l2_address_length = ntohl (sizeof (ei->address));
2678 else if (swif->sup_sw_if_index != swif->sw_if_index)
2680 vnet_sub_interface_t *sub = &swif->sub;
2681 mp->sub_id = ntohl (sub->id);
2682 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2683 mp->sub_number_of_tags =
2684 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2685 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2686 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2687 mp->sub_exact_match = sub->eth.flags.exact_match;
2688 mp->sub_default = sub->eth.flags.default_sub;
2689 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2690 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2692 /* vlan tag rewrite data */
2693 u32 vtr_op = L2_VTR_DISABLED;
2694 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2696 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2697 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2699 // error - default to disabled
2700 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2701 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2706 mp->vtr_op = ntohl (vtr_op);
2707 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2708 mp->vtr_tag1 = ntohl (vtr_tag1);
2709 mp->vtr_tag2 = ntohl (vtr_tag2);
2713 vl_msg_api_send_shmem (q, (u8 *) & mp);
2717 send_sw_interface_flags (vpe_api_main_t * am,
2718 unix_shared_memory_queue_t * q,
2719 vnet_sw_interface_t * swif)
2721 vl_api_sw_interface_set_flags_t *mp;
2722 vnet_main_t *vnm = am->vnet_main;
2724 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2726 mp = vl_msg_api_alloc (sizeof (*mp));
2727 memset (mp, 0, sizeof (*mp));
2728 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2729 mp->sw_if_index = ntohl (swif->sw_if_index);
2731 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2732 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2733 vl_msg_api_send_shmem (q, (u8 *) & mp);
2736 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2737 unix_shared_memory_queue_t * q,
2739 __attribute__ ((unused));
2742 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2743 unix_shared_memory_queue_t * q,
2746 vl_api_sw_interface_set_flags_t *mp;
2748 mp = vl_msg_api_alloc (sizeof (*mp));
2749 memset (mp, 0, sizeof (*mp));
2750 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2751 mp->sw_if_index = ntohl (sw_if_index);
2753 mp->admin_up_down = 0;
2754 mp->link_up_down = 0;
2756 vl_msg_api_send_shmem (q, (u8 *) & mp);
2760 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2762 vpe_api_main_t *am = &vpe_api_main;
2763 vnet_sw_interface_t *swif;
2764 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2765 u8 *filter_string = 0, *name_string = 0;
2766 unix_shared_memory_queue_t *q;
2767 char *strcasestr (char *, char *); /* lnx hdr file botch */
2769 q = vl_api_client_index_to_input_queue (mp->client_index);
2774 if (mp->name_filter_valid)
2776 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2777 filter_string = format (0, "%s%c", mp->name_filter, 0);
2781 pool_foreach (swif, im->sw_interfaces,
2783 name_string = format (name_string, "%U%c",
2784 format_vnet_sw_interface_name,
2785 am->vnet_main, swif, 0);
2787 if (mp->name_filter_valid == 0 ||
2788 strcasestr((char *) name_string, (char *) filter_string)) {
2790 send_sw_interface_details (am, q, swif, name_string, mp->context);
2792 _vec_len (name_string) = 0;
2796 vec_free (name_string);
2797 vec_free (filter_string);
2801 send_oam_event (oam_target_t * t)
2803 vpe_api_main_t *vam = &vpe_api_main;
2804 unix_shared_memory_queue_t *q;
2805 vpe_client_registration_t *reg;
2806 vl_api_oam_event_t *mp;
2809 pool_foreach(reg, vam->oam_events_registrations,
2811 q = vl_api_client_index_to_input_queue (reg->client_index);
2814 mp = vl_msg_api_alloc (sizeof (*mp));
2815 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2816 clib_memcpy (mp->dst_address, &t->dst_address,
2817 sizeof (mp->dst_address));
2818 mp->state = t->state;
2819 vl_msg_api_send_shmem (q, (u8 *)&mp);
2826 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2828 vl_api_oam_add_del_reply_t *rmp;
2831 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2832 (ip4_address_t *) mp->dst_address,
2833 ntohl (mp->vrf_id), (int) (mp->is_add));
2835 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2839 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2841 stats_main_t *sm = &stats_main;
2842 vnet_interface_main_t *im = sm->interface_main;
2843 vl_api_vnet_summary_stats_reply_t *rmp;
2844 vlib_combined_counter_main_t *cm;
2847 u64 total_pkts[VLIB_N_RX_TX];
2848 u64 total_bytes[VLIB_N_RX_TX];
2850 unix_shared_memory_queue_t *q =
2851 vl_api_client_index_to_input_queue (mp->client_index);
2856 rmp = vl_msg_api_alloc (sizeof (*rmp));
2857 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2858 rmp->context = mp->context;
2861 memset (total_pkts, 0, sizeof (total_pkts));
2862 memset (total_bytes, 0, sizeof (total_bytes));
2864 vnet_interface_counter_lock (im);
2866 vec_foreach (cm, im->combined_sw_if_counters)
2868 which = cm - im->combined_sw_if_counters;
2870 for (i = 0; i < vec_len (cm->maxi); i++)
2872 vlib_get_combined_counter (cm, i, &v);
2873 total_pkts[which] += v.packets;
2874 total_bytes[which] += v.bytes;
2877 vnet_interface_counter_unlock (im);
2879 /* Note: in HOST byte order! */
2880 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2881 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2882 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2883 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2884 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2886 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2890 typedef CLIB_PACKED (struct {
2891 ip4_address_t address;
2892 u32 address_length: 6;
2898 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2900 vnet_main_t *vnm = vnet_get_main ();
2901 vnet_interface_main_t *im = &vnm->interface_main;
2902 ip4_main_t *im4 = &ip4_main;
2903 static ip4_route_t *routes;
2904 static u32 *sw_if_indices_to_shut;
2905 stats_main_t *sm = &stats_main;
2910 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2911 u32 target_fib_id = ntohl (mp->vrf_id);
2913 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2915 vec_foreach (fib, im4->fibs)
2917 vnet_sw_interface_t *si;
2919 if (fib->table_id != target_fib_id)
2922 /* remove any mpls/gre tunnels in this fib */
2923 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2925 /* remove any mpls encap/decap labels */
2926 mpls_fib_reset_labels (fib->table_id);
2928 /* remove any proxy arps in this fib */
2929 vnet_proxy_arp_fib_reset (fib->table_id);
2931 /* Set the flow hash for this fib to the default */
2932 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2934 vec_reset_length (sw_if_indices_to_shut);
2936 /* Shut down interfaces in this FIB / clean out intfc routes */
2938 pool_foreach (si, im->sw_interfaces,
2940 u32 sw_if_index = si->sw_if_index;
2942 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2943 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2945 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2949 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
2951 sw_if_index = sw_if_indices_to_shut[i];
2952 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2954 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2955 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2956 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2959 vec_reset_length (routes);
2961 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++)
2963 uword *hash = fib->adj_index_by_dst_address[i];
2967 x.address_length = i;
2970 hash_foreach_pair (p, hash,
2972 x.address.data_u32 = p->key;
2973 vec_add1 (routes, x);
2978 vec_foreach (r, routes)
2980 ip4_add_del_route_args_t a;
2982 memset (&a, 0, sizeof (a));
2983 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2984 a.table_index_or_table_id = fib - im4->fibs;
2985 a.dst_address = r->address;
2986 a.dst_address_length = r->address_length;
2989 ip4_add_del_route (im4, &a);
2990 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2991 IP4_ROUTE_FLAG_FIB_INDEX);
2995 } /* vec_foreach (fib) */
3003 ip6_address_t address;
3011 ip6_route_t **routep;
3012 } add_routes_in_fib_arg_t;
3015 add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
3017 add_routes_in_fib_arg_t *ap = arg;
3019 if (kvp->key[2] >> 32 == ap->fib_index)
3021 ip6_address_t *addr;
3023 addr = (ip6_address_t *) kvp;
3024 vec_add2 (*ap->routep, r, 1);
3025 r->address = addr[0];
3026 r->address_length = kvp->key[2] & 0xFF;
3027 r->index = kvp->value;
3032 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3034 vnet_main_t *vnm = vnet_get_main ();
3035 vnet_interface_main_t *im = &vnm->interface_main;
3036 ip6_main_t *im6 = &ip6_main;
3037 stats_main_t *sm = &stats_main;
3038 static ip6_route_t *routes;
3039 static u32 *sw_if_indices_to_shut;
3044 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3045 u32 target_fib_id = ntohl (mp->vrf_id);
3046 add_routes_in_fib_arg_t _a, *a = &_a;
3047 clib_bihash_24_8_t *h = &im6->ip6_lookup_table;
3049 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3051 vec_foreach (fib, im6->fibs)
3053 vnet_sw_interface_t *si;
3055 if (fib->table_id != target_fib_id)
3058 vec_reset_length (sw_if_indices_to_shut);
3060 /* Shut down interfaces in this FIB / clean out intfc routes */
3062 pool_foreach (si, im->sw_interfaces,
3064 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3066 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3070 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3072 sw_if_index = sw_if_indices_to_shut[i];
3073 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3075 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3076 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3077 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3080 vec_reset_length (routes);
3082 a->fib_index = fib - im6->fibs;
3083 a->routep = &routes;
3085 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
3087 vec_foreach (r, routes)
3089 ip6_add_del_route_args_t a;
3091 memset (&a, 0, sizeof (a));
3092 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
3093 a.table_index_or_table_id = fib - im6->fibs;
3094 a.dst_address = r->address;
3095 a.dst_address_length = r->address_length;
3098 ip6_add_del_route (im6, &a);
3099 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
3100 IP6_ROUTE_FLAG_FIB_INDEX);
3103 /* Reinstall the neighbor / router discovery routes */
3104 vnet_ip6_fib_init (im6, fib - im6->fibs);
3106 } /* vec_foreach (fib) */
3113 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3116 vl_api_reset_fib_reply_t *rmp;
3119 rv = ip6_reset_fib_t_handler (mp);
3121 rv = ip4_reset_fib_t_handler (mp);
3123 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3128 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3130 vl_api_dhcp_proxy_config_reply_t *rmp;
3133 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3134 (ip4_address_t *) (&mp->dhcp_src_address),
3135 (u32) ntohl (mp->vrf_id),
3136 (int) mp->insert_circuit_id,
3137 (int) (mp->is_add == 0));
3139 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3144 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3146 vl_api_dhcp_proxy_config_reply_t *rmp;
3149 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3150 (ip6_address_t *) (&mp->dhcp_src_address),
3151 (u32) ntohl (mp->vrf_id),
3152 (int) mp->insert_circuit_id,
3153 (int) (mp->is_add == 0));
3155 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3159 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3161 vl_api_dhcp_proxy_config_reply_t *rmp;
3164 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3165 (ip4_address_t *) (&mp->dhcp_src_address),
3166 (u32) ntohl (mp->rx_vrf_id),
3167 (u32) ntohl (mp->server_vrf_id),
3168 (int) mp->insert_circuit_id,
3169 (int) (mp->is_add == 0));
3171 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3176 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3178 vl_api_dhcp_proxy_config_reply_t *rmp;
3182 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3183 (ip6_address_t *) (&mp->dhcp_src_address),
3184 (u32) ntohl (mp->rx_vrf_id),
3185 (u32) ntohl (mp->server_vrf_id),
3186 (int) mp->insert_circuit_id,
3187 (int) (mp->is_add == 0));
3189 rv = VNET_API_ERROR_UNIMPLEMENTED;
3192 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3197 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3199 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3202 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3205 (int) mp->is_add == 0);
3207 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3209 ntohl (mp->fib_id), (int) mp->is_add == 0);
3211 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3215 static void vl_api_dhcp_proxy_config_t_handler
3216 (vl_api_dhcp_proxy_config_t * mp)
3218 if (mp->is_ipv6 == 0)
3219 dhcpv4_proxy_config (mp);
3221 dhcpv6_proxy_config (mp);
3224 static void vl_api_dhcp_proxy_config_2_t_handler
3225 (vl_api_dhcp_proxy_config_2_t * mp)
3227 if (mp->is_ipv6 == 0)
3228 dhcpv4_proxy_config_2 (mp);
3230 dhcpv6_proxy_config_2 (mp);
3234 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3235 u8 is_ipv6, u8 * host_address, u8 * router_address,
3238 unix_shared_memory_queue_t *q;
3239 vl_api_dhcp_compl_event_t *mp;
3241 q = vl_api_client_index_to_input_queue (client_index);
3245 mp = vl_msg_api_alloc (sizeof (*mp));
3246 mp->client_index = client_index;
3248 mp->is_ipv6 = is_ipv6;
3249 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3250 mp->hostname[vec_len (hostname) + 1] = '\n';
3251 clib_memcpy (&mp->host_address[0], host_address, 16);
3252 clib_memcpy (&mp->router_address[0], router_address, 16);
3253 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3255 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3257 vl_msg_api_send_shmem (q, (u8 *) & mp);
3260 static void vl_api_dhcp_client_config_t_handler
3261 (vl_api_dhcp_client_config_t * mp)
3263 vlib_main_t *vm = vlib_get_main ();
3264 vl_api_dhcp_client_config_reply_t *rmp;
3267 VALIDATE_SW_IF_INDEX (mp);
3269 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3270 mp->hostname, mp->is_add, mp->client_index,
3271 mp->want_dhcp_event ? dhcp_compl_event_callback :
3274 BAD_SW_IF_INDEX_LABEL;
3276 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3280 vl_api_sw_interface_ip6nd_ra_config_t_handler
3281 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3283 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3285 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3288 is_no = mp->is_no == 1;
3289 suppress = mp->suppress == 1;
3290 managed = mp->managed == 1;
3291 other = mp->other == 1;
3292 ll_option = mp->ll_option == 1;
3293 send_unicast = mp->send_unicast == 1;
3294 cease = mp->cease == 1;
3295 default_router = mp->default_router == 1;
3297 VALIDATE_SW_IF_INDEX (mp);
3299 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3300 suppress, managed, other,
3301 ll_option, send_unicast, cease,
3302 default_router, ntohl (mp->lifetime),
3303 ntohl (mp->initial_count),
3304 ntohl (mp->initial_interval),
3305 ntohl (mp->max_interval),
3306 ntohl (mp->min_interval), is_no);
3308 BAD_SW_IF_INDEX_LABEL;
3310 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3314 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3315 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3317 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3319 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3321 VALIDATE_SW_IF_INDEX (mp);
3323 is_no = mp->is_no == 1;
3324 use_default = mp->use_default == 1;
3325 no_advertise = mp->no_advertise == 1;
3326 off_link = mp->off_link == 1;
3327 no_autoconfig = mp->no_autoconfig == 1;
3328 no_onlink = mp->no_onlink == 1;
3330 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3331 (ip6_address_t *) mp->address,
3332 mp->address_length, use_default,
3333 ntohl (mp->val_lifetime),
3334 ntohl (mp->pref_lifetime), no_advertise,
3335 off_link, no_autoconfig, no_onlink, is_no);
3337 BAD_SW_IF_INDEX_LABEL;
3338 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3342 vl_api_sw_interface_ip6_enable_disable_t_handler
3343 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3345 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3346 vnet_main_t *vnm = vnet_get_main ();
3348 clib_error_t *error;
3352 VALIDATE_SW_IF_INDEX (mp);
3355 (mp->enable == 1) ? enable_ip6_interface (vm,
3356 ntohl (mp->sw_if_index)) :
3357 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3361 clib_error_report (error);
3362 rv = VNET_API_ERROR_UNSPECIFIED;
3366 rv = vnm->api_errno;
3369 BAD_SW_IF_INDEX_LABEL;
3371 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3375 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3376 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3378 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3380 clib_error_t *error;
3381 vnet_main_t *vnm = vnet_get_main ();
3385 VALIDATE_SW_IF_INDEX (mp);
3387 error = set_ip6_link_local_address (vm,
3388 ntohl (mp->sw_if_index),
3389 (ip6_address_t *) mp->address,
3390 mp->address_length);
3393 clib_error_report (error);
3394 rv = VNET_API_ERROR_UNSPECIFIED;
3398 rv = vnm->api_errno;
3401 BAD_SW_IF_INDEX_LABEL;
3403 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3407 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3409 vl_api_set_ip_flow_hash_reply_t *rmp;
3410 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3412 clib_warning ("unimplemented...");
3414 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3418 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3420 vl_api_set_ip_flow_hash_reply_t *rmp;
3423 u32 flow_hash_config = 0;
3425 table_id = ntohl (mp->vrf_id);
3427 #define _(a,b) if (mp->a) flow_hash_config |= b;
3428 foreach_flow_hash_bit;
3431 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3433 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3438 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3440 if (mp->is_ipv6 == 0)
3441 set_ip4_flow_hash (mp);
3443 set_ip6_flow_hash (mp);
3446 static void vl_api_sw_interface_set_unnumbered_t_handler
3447 (vl_api_sw_interface_set_unnumbered_t * mp)
3449 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3451 vnet_sw_interface_t *si;
3452 vnet_main_t *vnm = vnet_get_main ();
3453 u32 sw_if_index, unnumbered_sw_if_index;
3455 sw_if_index = ntohl (mp->sw_if_index);
3456 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3459 * The API message field names are backwards from
3460 * the underlying data structure names.
3461 * It's not worth changing them now.
3463 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3464 unnumbered_sw_if_index))
3466 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3470 /* Only check the "use loop0" field when setting the binding */
3472 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3474 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3478 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3482 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3483 si->unnumbered_sw_if_index = sw_if_index;
3487 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3488 si->unnumbered_sw_if_index = (u32) ~ 0;
3492 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3496 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3498 vl_api_create_loopback_reply_t *rmp;
3502 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3505 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3507 rmp->sw_if_index = ntohl (sw_if_index);
3513 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3515 vl_api_delete_loopback_reply_t *rmp;
3519 sw_if_index = ntohl (mp->sw_if_index);
3520 rv = vnet_delete_loopback_interface (sw_if_index);
3522 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3526 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3528 vl_api_control_ping_reply_t *rmp;
3532 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3534 rmp->vpe_pid = ntohl (getpid());
3539 static void vl_api_noprint_control_ping_t_handler
3540 (vl_api_noprint_control_ping_t * mp)
3542 vl_api_noprint_control_ping_reply_t *rmp;
3546 REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY,
3548 rmp->vpe_pid = ntohl (getpid());
3554 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3556 u8 **shmem_vecp = (u8 **) arg;
3559 api_main_t *am = &api_main;
3562 shmem_vec = *shmem_vecp;
3564 offset = vec_len (shmem_vec);
3566 pthread_mutex_lock (&am->vlib_rp->mutex);
3567 oldheap = svm_push_data_heap (am->vlib_rp);
3569 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3571 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3573 svm_pop_heap (oldheap);
3574 pthread_mutex_unlock (&am->vlib_rp->mutex);
3576 *shmem_vecp = shmem_vec;
3581 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3583 vl_api_cli_reply_t *rp;
3584 unix_shared_memory_queue_t *q;
3585 vlib_main_t *vm = vlib_get_main ();
3586 api_main_t *am = &api_main;
3587 unformat_input_t input;
3591 q = vl_api_client_index_to_input_queue (mp->client_index);
3595 rp = vl_msg_api_alloc (sizeof (*rp));
3596 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3597 rp->context = mp->context;
3599 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3601 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3603 pthread_mutex_lock (&am->vlib_rp->mutex);
3604 oldheap = svm_push_data_heap (am->vlib_rp);
3606 vec_add1 (shmem_vec, 0);
3608 svm_pop_heap (oldheap);
3609 pthread_mutex_unlock (&am->vlib_rp->mutex);
3611 rp->reply_in_shmem = (uword) shmem_vec;
3613 vl_msg_api_send_shmem (q, (u8 *) & rp);
3617 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3620 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3621 vnet_main_t *vnm = vnet_get_main ();
3622 clib_error_t *error;
3627 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3629 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3633 clib_error_report (error);
3634 rv = VNET_API_ERROR_UNSPECIFIED;
3638 rv = vnm->api_errno;
3641 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3644 static void vl_api_sr_tunnel_add_del_t_handler
3645 (vl_api_sr_tunnel_add_del_t * mp)
3648 clib_warning ("unimplemented");
3650 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3652 vl_api_sr_tunnel_add_del_reply_t *rmp;
3653 ip6_address_t *segments = 0, *seg;
3654 ip6_address_t *tags = 0, *tag;
3655 ip6_address_t *this_address;
3658 if (mp->n_segments == 0)
3664 memset (a, 0, sizeof (*a));
3665 a->src_address = (ip6_address_t *) & mp->src_address;
3666 a->dst_address = (ip6_address_t *) & mp->dst_address;
3667 a->dst_mask_width = mp->dst_mask_width;
3668 a->flags_net_byte_order = mp->flags_net_byte_order;
3669 a->is_del = (mp->is_add == 0);
3670 a->rx_table_id = ntohl (mp->outer_vrf_id);
3671 a->tx_table_id = ntohl (mp->inner_vrf_id);
3673 a->name = format (0, "%s", mp->name);
3674 if (!(vec_len (a->name)))
3677 a->policy_name = format (0, "%s", mp->policy_name);
3678 if (!(vec_len (a->policy_name)))
3681 /* Yank segments and tags out of the API message */
3682 this_address = (ip6_address_t *) mp->segs_and_tags;
3683 for (i = 0; i < mp->n_segments; i++)
3685 vec_add2 (segments, seg, 1);
3686 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3689 for (i = 0; i < mp->n_tags; i++)
3691 vec_add2 (tags, tag, 1);
3692 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3696 a->segments = segments;
3699 rv = ip6_sr_add_del_tunnel (a);
3703 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3707 static void vl_api_sr_policy_add_del_t_handler
3708 (vl_api_sr_policy_add_del_t * mp)
3711 clib_warning ("unimplemented");
3713 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3715 vl_api_sr_policy_add_del_reply_t *rmp;
3718 memset (a, 0, sizeof (*a));
3719 a->is_del = (mp->is_add == 0);
3721 a->name = format (0, "%s", mp->name);
3722 if (!(vec_len (a->name)))
3724 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3728 if (!(mp->tunnel_names[0]))
3730 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3734 // start deserializing tunnel_names
3735 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3736 u8 *deser_tun_names = mp->tunnel_names;
3737 deser_tun_names += 1; //moving along
3740 int tun_name_len = 0;
3742 for (i = 0; i < num_tunnels; i++)
3744 tun_name_len = *deser_tun_names;
3745 deser_tun_names += 1;
3746 vec_resize (tun_name, tun_name_len);
3747 memcpy (tun_name, deser_tun_names, tun_name_len);
3748 vec_add1 (a->tunnel_names, tun_name);
3749 deser_tun_names += tun_name_len;
3753 rv = ip6_sr_add_del_policy (a);
3757 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3761 static void vl_api_sr_multicast_map_add_del_t_handler
3762 (vl_api_sr_multicast_map_add_del_t * mp)
3765 clib_warning ("unimplemented");
3767 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3769 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3771 memset (a, 0, sizeof (*a));
3772 a->is_del = (mp->is_add == 0);
3774 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3775 a->policy_name = format (0, "%s", mp->policy_name);
3777 if (a->multicast_address == 0)
3783 if (!(a->policy_name))
3789 #if DPDK > 0 /* Cannot call replicate without DPDK */
3790 rv = ip6_sr_add_del_multicastmap (a);
3792 clib_warning ("multicast replication without DPDK not implemented");
3793 rv = VNET_API_ERROR_UNIMPLEMENTED;
3798 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3802 #define foreach_classify_add_del_table_field \
3807 _(match_n_vectors) \
3808 _(next_table_index) \
3811 static void vl_api_classify_add_del_table_t_handler
3812 (vl_api_classify_add_del_table_t * mp)
3814 vl_api_classify_add_del_table_reply_t *rmp;
3815 vnet_classify_main_t *cm = &vnet_classify_main;
3816 vnet_classify_table_t *t;
3820 foreach_classify_add_del_table_field;
3823 #define _(a) a = ntohl(mp->a);
3824 foreach_classify_add_del_table_field;
3827 /* The underlying API fails silently, on purpose, so check here */
3828 if (mp->is_add == 0)
3829 if (pool_is_free_index (cm->tables, table_index))
3831 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3835 rv = vnet_classify_add_del_table
3836 (cm, mp->mask, nbuckets, memory_size,
3837 skip_n_vectors, match_n_vectors,
3838 next_table_index, miss_next_index, &table_index, mp->is_add);
3842 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3844 if (rv == 0 && mp->is_add)
3846 t = pool_elt_at_index (cm->tables, table_index);
3847 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3848 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3849 rmp->new_table_index = ntohl(table_index);
3853 rmp->skip_n_vectors = ~0;
3854 rmp->match_n_vectors = ~0;
3855 rmp->new_table_index = ~0;
3861 static void vl_api_classify_add_del_session_t_handler
3862 (vl_api_classify_add_del_session_t * mp)
3864 vnet_classify_main_t *cm = &vnet_classify_main;
3865 vl_api_classify_add_del_session_reply_t *rmp;
3867 u32 table_index, hit_next_index, opaque_index;
3870 table_index = ntohl (mp->table_index);
3871 hit_next_index = ntohl (mp->hit_next_index);
3872 opaque_index = ntohl (mp->opaque_index);
3873 advance = ntohl (mp->advance);
3875 rv = vnet_classify_add_del_session
3876 (cm, table_index, mp->match, hit_next_index, opaque_index,
3877 advance, mp->is_add);
3879 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3882 static void vl_api_classify_set_interface_ip_table_t_handler
3883 (vl_api_classify_set_interface_ip_table_t * mp)
3885 vlib_main_t *vm = vlib_get_main ();
3886 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3888 u32 table_index, sw_if_index;
3890 table_index = ntohl (mp->table_index);
3891 sw_if_index = ntohl (mp->sw_if_index);
3893 VALIDATE_SW_IF_INDEX (mp);
3896 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3898 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3900 BAD_SW_IF_INDEX_LABEL;
3902 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3905 static void vl_api_classify_set_interface_l2_tables_t_handler
3906 (vl_api_classify_set_interface_l2_tables_t * mp)
3908 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3910 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3913 ip4_table_index = ntohl (mp->ip4_table_index);
3914 ip6_table_index = ntohl (mp->ip6_table_index);
3915 other_table_index = ntohl (mp->other_table_index);
3916 sw_if_index = ntohl (mp->sw_if_index);
3918 VALIDATE_SW_IF_INDEX (mp);
3920 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3921 ip6_table_index, other_table_index);
3925 if (ip4_table_index != ~0 || ip6_table_index != ~0
3926 || other_table_index != ~0)
3931 vnet_l2_classify_enable_disable (sw_if_index, enable);
3934 BAD_SW_IF_INDEX_LABEL;
3936 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3940 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3943 vl_api_l2_fib_clear_table_reply_t *rmp;
3945 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3946 * that is not currently implemented. When that TODO is fixed
3947 * this call should be changed to pass 1 instead of 0.
3949 l2fib_clear_table (0);
3951 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3954 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3955 u32 sw_if_index, u32 enable);
3958 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3962 vl_api_l2_interface_efp_filter_reply_t *rmp;
3963 vnet_main_t *vnm = vnet_get_main ();
3965 // enable/disable the feature
3966 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3967 rv = vnm->api_errno;
3969 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3973 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3974 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3977 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3978 vnet_main_t *vnm = vnet_get_main ();
3979 vlib_main_t *vm = vlib_get_main ();
3982 VALIDATE_SW_IF_INDEX (mp);
3984 vtr_op = ntohl (mp->vtr_op);
3986 /* The L2 code is unsuspicious */
3989 case L2_VTR_DISABLED:
3994 case L2_VTR_TRANSLATE_1_1:
3995 case L2_VTR_TRANSLATE_1_2:
3996 case L2_VTR_TRANSLATE_2_1:
3997 case L2_VTR_TRANSLATE_2_2:
4001 rv = VNET_API_ERROR_INVALID_VALUE;
4002 goto bad_sw_if_index;
4005 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4006 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4009 BAD_SW_IF_INDEX_LABEL;
4011 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4015 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4018 vl_api_create_vhost_user_if_reply_t *rmp;
4020 u32 sw_if_index = (u32) ~ 0;
4022 vnet_main_t *vnm = vnet_get_main ();
4023 vlib_main_t *vm = vlib_get_main ();
4025 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
4026 mp->is_server, &sw_if_index, (u64) ~ 0,
4027 mp->renumber, ntohl (mp->custom_dev_instance),
4028 (mp->use_custom_mac) ? mp->mac_address : NULL);
4031 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4033 rmp->sw_if_index = ntohl (sw_if_index);
4037 rv = VNET_API_ERROR_UNIMPLEMENTED;
4038 REPLY_MACRO (VL_API_CREATE_VHOST_USER_IF_REPLY);
4043 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4046 vl_api_modify_vhost_user_if_reply_t *rmp;
4047 #if DPDK > 0 && DPDK_VHOST_USER
4048 u32 sw_if_index = ntohl (mp->sw_if_index);
4050 vnet_main_t *vnm = vnet_get_main ();
4051 vlib_main_t *vm = vlib_get_main ();
4053 rv = dpdk_vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
4054 mp->is_server, sw_if_index, (u64) ~ 0,
4056 ntohl (mp->custom_dev_instance));
4058 rv = VNET_API_ERROR_UNIMPLEMENTED;
4060 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4064 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4067 vl_api_delete_vhost_user_if_reply_t *rmp;
4068 #if DPDK > 0 && DPDK_VHOST_USER
4069 vpe_api_main_t *vam = &vpe_api_main;
4070 u32 sw_if_index = ntohl (mp->sw_if_index);
4072 vnet_main_t *vnm = vnet_get_main ();
4073 vlib_main_t *vm = vlib_get_main ();
4075 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4077 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4080 unix_shared_memory_queue_t *q =
4081 vl_api_client_index_to_input_queue (mp->client_index);
4085 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4088 rv = VNET_API_ERROR_UNIMPLEMENTED;
4089 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4094 vl_api_sw_interface_vhost_user_details_t_handler
4095 (vl_api_sw_interface_vhost_user_details_t * mp)
4097 clib_warning ("BUG");
4100 #if DPDK > 0 && DPDK_VHOST_USER
4102 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4103 unix_shared_memory_queue_t * q,
4104 vhost_user_intf_details_t * vui,
4107 vl_api_sw_interface_vhost_user_details_t *mp;
4109 mp = vl_msg_api_alloc (sizeof (*mp));
4110 memset (mp, 0, sizeof (*mp));
4111 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4112 mp->sw_if_index = ntohl (vui->sw_if_index);
4113 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4114 mp->features = clib_net_to_host_u64 (vui->features);
4115 mp->is_server = vui->is_server;
4116 mp->num_regions = ntohl (vui->num_regions);
4117 mp->sock_errno = ntohl (vui->sock_errno);
4118 mp->context = context;
4120 strncpy ((char *) mp->sock_filename,
4121 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4122 strncpy ((char *) mp->interface_name,
4123 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4125 vl_msg_api_send_shmem (q, (u8 *) & mp);
4130 vl_api_sw_interface_vhost_user_dump_t_handler
4131 (vl_api_sw_interface_vhost_user_dump_t * mp)
4133 #if DPDK > 0 && DPDK_VHOST_USER
4135 vpe_api_main_t *am = &vpe_api_main;
4136 vnet_main_t *vnm = vnet_get_main ();
4137 vlib_main_t *vm = vlib_get_main ();
4138 vhost_user_intf_details_t *ifaces = NULL;
4139 vhost_user_intf_details_t *vuid = NULL;
4140 unix_shared_memory_queue_t *q;
4142 q = vl_api_client_index_to_input_queue (mp->client_index);
4146 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4150 vec_foreach (vuid, ifaces)
4152 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4159 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4160 unix_shared_memory_queue_t * q,
4162 l2t_main_t * lm, u32 context)
4164 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4166 vnet_sw_interface_t *si = NULL;
4168 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4170 if_name = format (if_name, "%U",
4171 format_vnet_sw_interface_name, lm->vnet_main, si);
4173 mp = vl_msg_api_alloc (sizeof (*mp));
4174 memset (mp, 0, sizeof (*mp));
4175 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4176 strncpy ((char *) mp->interface_name,
4177 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4178 mp->sw_if_index = ntohl (si->sw_if_index);
4179 mp->local_session_id = s->local_session_id;
4180 mp->remote_session_id = s->remote_session_id;
4181 mp->local_cookie[0] = s->local_cookie[0];
4182 mp->local_cookie[1] = s->local_cookie[1];
4183 mp->remote_cookie = s->remote_cookie;
4184 clib_memcpy (mp->client_address, &s->client_address,
4185 sizeof (s->client_address));
4186 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4187 mp->l2_sublayer_present = s->l2_sublayer_present;
4188 mp->context = context;
4190 vl_msg_api_send_shmem (q, (u8 *) & mp);
4194 send_ip_address_details (vpe_api_main_t * am,
4195 unix_shared_memory_queue_t * q,
4196 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4198 vl_api_ip_address_details_t *mp;
4200 mp = vl_msg_api_alloc (sizeof (*mp));
4201 memset (mp, 0, sizeof (*mp));
4202 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4206 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4210 u32 *tp = (u32 *) mp->ip;
4211 *tp = ntohl (*(u32 *) ip);
4213 mp->prefix_length = prefix_length;
4214 mp->context = context;
4216 vl_msg_api_send_shmem (q, (u8 *) & mp);
4220 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4222 vpe_api_main_t *am = &vpe_api_main;
4223 unix_shared_memory_queue_t *q;
4226 ip6_main_t *im6 = &ip6_main;
4227 ip4_main_t *im4 = &ip4_main;
4228 ip_lookup_main_t *lm6 = &im6->lookup_main;
4229 ip_lookup_main_t *lm4 = &im4->lookup_main;
4230 ip_interface_address_t *ia = 0;
4231 u32 sw_if_index = ~0;
4232 int rv __attribute__ ((unused)) = 0;
4234 VALIDATE_SW_IF_INDEX (mp);
4236 sw_if_index = ntohl (mp->sw_if_index);
4238 q = vl_api_client_index_to_input_queue (mp->client_index);
4247 foreach_ip_interface_address (lm6, ia, sw_if_index,
4248 1 /* honor unnumbered */,
4250 r6 = ip_interface_address_get_address (lm6, ia);
4251 u16 prefix_length = ia->address_length;
4252 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4259 foreach_ip_interface_address (lm4, ia, sw_if_index,
4260 1 /* honor unnumbered */,
4262 r4 = ip_interface_address_get_address (lm4, ia);
4263 u16 prefix_length = ia->address_length;
4264 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4268 BAD_SW_IF_INDEX_LABEL;
4272 send_ip_details (vpe_api_main_t * am,
4273 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4275 vl_api_ip_details_t *mp;
4277 mp = vl_msg_api_alloc (sizeof (*mp));
4278 memset (mp, 0, sizeof (*mp));
4279 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4281 mp->sw_if_index = ntohl (sw_if_index);
4282 mp->context = context;
4284 vl_msg_api_send_shmem (q, (u8 *) & mp);
4288 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4291 vpe_api_main_t *am = &vpe_api_main;
4292 l2t_main_t *lm = &l2t_main;
4293 unix_shared_memory_queue_t *q;
4294 l2t_session_t *session;
4296 q = vl_api_client_index_to_input_queue (mp->client_index);
4301 pool_foreach (session, lm->sessions,
4303 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4310 send_sw_interface_tap_details (vpe_api_main_t * am,
4311 unix_shared_memory_queue_t * q,
4312 tapcli_interface_details_t * tap_if,
4315 vl_api_sw_interface_tap_details_t *mp;
4316 mp = vl_msg_api_alloc (sizeof (*mp));
4317 memset (mp, 0, sizeof (*mp));
4318 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4319 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4320 strncpy ((char *) mp->dev_name,
4321 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4322 mp->context = context;
4324 vl_msg_api_send_shmem (q, (u8 *) & mp);
4328 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4331 vpe_api_main_t *am = &vpe_api_main;
4332 unix_shared_memory_queue_t *q;
4333 tapcli_interface_details_t *tapifs = NULL;
4334 tapcli_interface_details_t *tap_if = NULL;
4336 q = vl_api_client_index_to_input_queue (mp->client_index);
4340 rv = vnet_tap_dump_ifs (&tapifs);
4344 vec_foreach (tap_if, tapifs)
4346 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4353 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4355 vpe_api_main_t *am = &vpe_api_main;
4356 vnet_main_t *vnm = vnet_get_main ();
4357 vlib_main_t *vm = vlib_get_main ();
4358 vnet_interface_main_t *im = &vnm->interface_main;
4359 unix_shared_memory_queue_t *q;
4360 vnet_sw_interface_t *si, *sorted_sis;
4361 u32 sw_if_index = ~0;
4363 q = vl_api_client_index_to_input_queue (mp->client_index);
4369 /* Gather interfaces. */
4370 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4371 _vec_len (sorted_sis) = 0;
4373 pool_foreach (si, im->sw_interfaces,
4375 vec_add1 (sorted_sis, si[0]);
4379 vec_foreach (si, sorted_sis)
4381 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4383 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4387 sw_if_index = si->sw_if_index;
4388 send_ip_details (am, q, sw_if_index, mp->context);
4394 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4396 clib_warning ("BUG");
4400 send_l2fib_table_entry (vpe_api_main_t * am,
4401 unix_shared_memory_queue_t * q,
4402 l2fib_entry_key_t * l2fe_key,
4403 l2fib_entry_result_t * l2fe_res, u32 context)
4405 vl_api_l2_fib_table_entry_t *mp;
4407 mp = vl_msg_api_alloc (sizeof (*mp));
4408 memset (mp, 0, sizeof (*mp));
4409 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4412 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4414 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4415 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4416 mp->static_mac = l2fe_res->fields.static_mac;
4417 mp->filter_mac = l2fe_res->fields.filter;
4418 mp->bvi_mac = l2fe_res->fields.bvi;
4419 mp->context = context;
4421 vl_msg_api_send_shmem (q, (u8 *) & mp);
4425 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4427 vpe_api_main_t *am = &vpe_api_main;
4428 bd_main_t *bdm = &bd_main;
4429 l2fib_entry_key_t *l2fe_key = NULL;
4430 l2fib_entry_result_t *l2fe_res = NULL;
4431 u32 ni, bd_id = ntohl (mp->bd_id);
4433 unix_shared_memory_queue_t *q;
4436 q = vl_api_client_index_to_input_queue (mp->client_index);
4440 /* see l2fib_table_dump: ~0 means "any" */
4445 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4452 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4454 vec_foreach_index (ni, l2fe_key)
4456 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4457 vec_elt_at_index (l2fe_res, ni), mp->context);
4459 vec_free (l2fe_key);
4460 vec_free (l2fe_res);
4464 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4466 vl_api_show_version_reply_t *rmp;
4468 char *vpe_api_get_build_directory (void);
4469 char *vpe_api_get_version (void);
4470 char *vpe_api_get_build_date (void);
4472 unix_shared_memory_queue_t *q =
4473 vl_api_client_index_to_input_queue (mp->client_index);
4479 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4481 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4482 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4483 ARRAY_LEN(rmp->build_directory)-1);
4484 strncpy ((char *) rmp->version, vpe_api_get_version(),
4485 ARRAY_LEN(rmp->version)-1);
4486 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4487 ARRAY_LEN(rmp->build_date)-1);
4493 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4495 vlib_main_t *vm = vlib_get_main ();
4496 vl_api_get_node_index_reply_t *rmp;
4499 u32 node_index = ~0;
4501 n = vlib_get_node_by_name (vm, mp->node_name);
4504 rv = VNET_API_ERROR_NO_SUCH_NODE;
4506 node_index = n->index;
4509 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4511 rmp->node_index = ntohl(node_index);
4517 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4519 vlib_main_t *vm = vlib_get_main ();
4520 vl_api_get_next_index_reply_t *rmp;
4521 vlib_node_t *node, *next_node;
4523 u32 next_node_index = ~0, next_index = ~0;
4526 node = vlib_get_node_by_name (vm, mp->node_name);
4530 rv = VNET_API_ERROR_NO_SUCH_NODE;
4534 next_node = vlib_get_node_by_name (vm, mp->next_name);
4538 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4542 next_node_index = next_node->index;
4544 p = hash_get (node->next_slot_by_node, next_node_index);
4548 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4556 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4558 rmp->next_index = ntohl(next_index);
4564 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4566 vlib_main_t *vm = vlib_get_main ();
4567 vl_api_add_node_next_reply_t *rmp;
4568 vlib_node_t *n, *next;
4570 u32 next_index = ~0;
4572 n = vlib_get_node_by_name (vm, mp->node_name);
4576 rv = VNET_API_ERROR_NO_SUCH_NODE;
4580 next = vlib_get_node_by_name (vm, mp->next_name);
4583 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4585 next_index = vlib_node_add_next (vm, n->index, next->index);
4589 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4591 rmp->next_index = ntohl(next_index);
4596 static void vl_api_l2tpv3_create_tunnel_t_handler
4597 (vl_api_l2tpv3_create_tunnel_t * mp)
4599 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4600 l2t_main_t *lm = &l2t_main;
4601 u32 sw_if_index = (u32) ~ 0;
4604 if (mp->is_ipv6 != 1)
4606 rv = VNET_API_ERROR_UNIMPLEMENTED;
4610 u32 encap_fib_index;
4612 if (mp->encap_vrf_id != ~0)
4615 ip6_main_t *im = &ip6_main;
4618 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4620 rv = VNET_API_ERROR_NO_SUCH_FIB;
4623 encap_fib_index = p[0];
4627 encap_fib_index = ~0;
4630 rv = create_l2tpv3_ipv6_tunnel (lm,
4631 (ip6_address_t *) mp->client_address,
4632 (ip6_address_t *) mp->our_address,
4633 ntohl (mp->local_session_id),
4634 ntohl (mp->remote_session_id),
4635 clib_net_to_host_u64 (mp->local_cookie),
4636 clib_net_to_host_u64 (mp->remote_cookie),
4637 mp->l2_sublayer_present,
4638 encap_fib_index, &sw_if_index);
4642 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4644 rmp->sw_if_index = ntohl (sw_if_index);
4649 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4650 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4652 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4653 l2t_main_t *lm = &l2t_main;
4656 VALIDATE_SW_IF_INDEX (mp);
4658 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4659 clib_net_to_host_u64 (mp->new_local_cookie),
4660 clib_net_to_host_u64
4661 (mp->new_remote_cookie));
4663 BAD_SW_IF_INDEX_LABEL;
4665 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4668 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4669 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4672 vnet_main_t *vnm = vnet_get_main ();
4673 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4675 VALIDATE_SW_IF_INDEX (mp);
4677 rv = l2tpv3_interface_enable_disable
4678 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4680 BAD_SW_IF_INDEX_LABEL;
4682 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4685 static void vl_api_l2tpv3_set_lookup_key_t_handler
4686 (vl_api_l2tpv3_set_lookup_key_t * mp)
4689 l2t_main_t *lm = &l2t_main;
4690 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4692 if (mp->key > L2T_LOOKUP_SESSION_ID)
4694 rv = VNET_API_ERROR_INVALID_VALUE;
4698 lm->lookup_type = mp->key;
4701 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4704 static void vl_api_vxlan_add_del_tunnel_t_handler
4705 (vl_api_vxlan_add_del_tunnel_t * mp)
4707 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4709 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4710 u32 encap_fib_index;
4712 ip4_main_t *im = &ip4_main;
4713 u32 sw_if_index = ~0;
4715 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4718 rv = VNET_API_ERROR_NO_SUCH_FIB;
4721 encap_fib_index = p[0];
4723 /* Check src & dst are different */
4724 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4725 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4727 rv = VNET_API_ERROR_SAME_SRC_DST;
4730 memset (a, 0, sizeof (*a));
4732 a->is_add = mp->is_add;
4733 a->is_ip6 = mp->is_ipv6;
4735 /* ip addresses sent in network byte order */
4738 memcpy (&(a->src.ip6), mp->src_address, 16);
4739 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4743 memcpy (&(a->src.ip4), mp->src_address, 4);
4744 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4747 a->encap_fib_index = encap_fib_index;
4748 a->decap_next_index = ntohl (mp->decap_next_index);
4749 a->vni = ntohl (mp->vni);
4750 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4754 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4756 rmp->sw_if_index = ntohl (sw_if_index);
4761 static void send_vxlan_tunnel_details
4762 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4764 vl_api_vxlan_tunnel_details_t *rmp;
4765 ip4_main_t *im4 = &ip4_main;
4766 ip6_main_t *im6 = &ip6_main;
4767 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4769 rmp = vl_msg_api_alloc (sizeof (*rmp));
4770 memset (rmp, 0, sizeof (*rmp));
4771 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4774 memcpy (rmp->src_address, &(t->src.ip6), 16);
4775 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4776 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
4780 memcpy (rmp->src_address, &(t->src.ip4), 4);
4781 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4782 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
4784 rmp->vni = htonl (t->vni);
4785 rmp->decap_next_index = htonl (t->decap_next_index);
4786 rmp->sw_if_index = htonl (t->sw_if_index);
4787 rmp->is_ipv6 = is_ipv6;
4788 rmp->context = context;
4790 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4793 static void vl_api_vxlan_tunnel_dump_t_handler
4794 (vl_api_vxlan_tunnel_dump_t * mp)
4796 unix_shared_memory_queue_t *q;
4797 vxlan_main_t *vxm = &vxlan_main;
4801 q = vl_api_client_index_to_input_queue (mp->client_index);
4807 sw_if_index = ntohl (mp->sw_if_index);
4809 if (~0 == sw_if_index)
4812 pool_foreach (t, vxm->tunnels,
4814 send_vxlan_tunnel_details(t, q, mp->context);
4820 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4821 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4825 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4826 send_vxlan_tunnel_details (t, q, mp->context);
4830 static void vl_api_gre_add_del_tunnel_t_handler
4831 (vl_api_gre_add_del_tunnel_t * mp)
4833 vl_api_gre_add_del_tunnel_reply_t *rmp;
4835 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4838 ip4_main_t *im = &ip4_main;
4839 u32 sw_if_index = ~0;
4841 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4844 rv = VNET_API_ERROR_NO_SUCH_FIB;
4847 outer_fib_id = p[0];
4849 /* Check src & dst are different */
4850 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4851 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4853 rv = VNET_API_ERROR_SAME_SRC_DST;
4856 memset (a, 0, sizeof (*a));
4858 a->is_add = mp->is_add;
4860 /* ip addresses sent in network byte order */
4861 clib_memcpy (&(a->src), mp->src_address, 4);
4862 clib_memcpy (&(a->dst), mp->dst_address, 4);
4864 a->outer_fib_id = outer_fib_id;
4865 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4869 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4871 rmp->sw_if_index = ntohl (sw_if_index);
4876 static void send_gre_tunnel_details
4877 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4879 vl_api_gre_tunnel_details_t *rmp;
4880 ip4_main_t *im = &ip4_main;
4882 rmp = vl_msg_api_alloc (sizeof (*rmp));
4883 memset (rmp, 0, sizeof (*rmp));
4884 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4885 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4886 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4887 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
4888 rmp->sw_if_index = htonl (t->sw_if_index);
4889 rmp->context = context;
4891 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4895 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4897 unix_shared_memory_queue_t *q;
4898 gre_main_t *gm = &gre_main;
4902 q = vl_api_client_index_to_input_queue (mp->client_index);
4908 sw_if_index = ntohl (mp->sw_if_index);
4910 if (~0 == sw_if_index)
4913 pool_foreach (t, gm->tunnels,
4915 send_gre_tunnel_details(t, q, mp->context);
4921 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4922 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4926 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4927 send_gre_tunnel_details (t, q, mp->context);
4932 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4934 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4936 vl_api_l2_patch_add_del_reply_t *rmp;
4937 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4941 VALIDATE_RX_SW_IF_INDEX (mp);
4942 VALIDATE_TX_SW_IF_INDEX (mp);
4944 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4945 ntohl (mp->tx_sw_if_index),
4946 (int) (mp->is_add != 0));
4948 BAD_RX_SW_IF_INDEX_LABEL;
4949 BAD_TX_SW_IF_INDEX_LABEL;
4951 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4955 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4956 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4958 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4960 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4961 u32 encap_fib_index, decap_fib_index;
4964 ip4_main_t *im = &ip4_main;
4965 u32 sw_if_index = ~0;
4968 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4971 rv = VNET_API_ERROR_NO_SUCH_FIB;
4974 encap_fib_index = p[0];
4976 protocol = mp->protocol;
4978 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4979 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4981 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4984 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4987 decap_fib_index = p[0];
4991 decap_fib_index = ntohl (mp->decap_vrf_id);
4994 /* Check src & dst are different */
4995 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
4996 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
4998 rv = VNET_API_ERROR_SAME_SRC_DST;
5001 memset (a, 0, sizeof (*a));
5003 a->is_add = mp->is_add;
5004 a->is_ip6 = mp->is_ipv6;
5005 /* ip addresses sent in network byte order */
5008 clib_memcpy (&(a->local.ip6), mp->local, 16);
5009 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5013 clib_memcpy (&(a->local.ip4), mp->local, 4);
5014 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5016 a->encap_fib_index = encap_fib_index;
5017 a->decap_fib_index = decap_fib_index;
5018 a->protocol = protocol;
5019 a->vni = ntohl (mp->vni);
5020 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5024 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5026 rmp->sw_if_index = ntohl (sw_if_index);
5031 static void send_vxlan_gpe_tunnel_details
5032 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5034 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5035 ip4_main_t *im4 = &ip4_main;
5036 ip6_main_t *im6 = &ip6_main;
5037 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5039 rmp = vl_msg_api_alloc (sizeof (*rmp));
5040 memset (rmp, 0, sizeof (*rmp));
5041 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5044 memcpy (rmp->local, &(t->local.ip6), 16);
5045 memcpy (rmp->remote, &(t->remote.ip6), 16);
5046 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
5047 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].table_id);
5051 memcpy (rmp->local, &(t->local.ip4), 4);
5052 memcpy (rmp->remote, &(t->remote.ip4), 4);
5053 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
5054 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].table_id);
5056 rmp->vni = htonl (t->vni);
5057 rmp->protocol = t->protocol;
5058 rmp->sw_if_index = htonl (t->sw_if_index);
5059 rmp->is_ipv6 = is_ipv6;
5060 rmp->context = context;
5062 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5065 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5066 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5068 unix_shared_memory_queue_t *q;
5069 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5070 vxlan_gpe_tunnel_t *t;
5073 q = vl_api_client_index_to_input_queue (mp->client_index);
5079 sw_if_index = ntohl (mp->sw_if_index);
5081 if (~0 == sw_if_index)
5084 pool_foreach (t, vgm->tunnels,
5086 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5092 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5093 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5097 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5098 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5102 /** Used for transferring locators via VPP API */
5104 typedef CLIB_PACKED (struct {
5105 u32 sw_if_index; /**< locator sw_if_index */
5106 u8 priority; /**< locator priority */
5107 u8 weight; /**< locator weight */
5112 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5115 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5117 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5119 ls_locator_t *ls_loc;
5121 u8 *locator_name = NULL;
5124 memset (a, 0, sizeof (a[0]));
5126 locator_name = format (0, "%s", mp->locator_set_name);
5128 a->name = locator_name;
5129 a->is_add = mp->is_add;
5132 memset (&locator, 0, sizeof (locator));
5133 for (i = 0; i < mp->locator_num; i++)
5135 ls_loc = &((ls_locator_t *) mp->locators)[i];
5136 VALIDATE_SW_IF_INDEX (ls_loc);
5138 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5139 locator.priority = ls_loc->priority;
5140 locator.weight = ls_loc->weight;
5142 vec_add1 (a->locators, locator);
5145 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5147 BAD_SW_IF_INDEX_LABEL;
5149 vec_free (locator_name);
5150 vec_free (a->locators);
5152 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
5156 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5158 vl_api_lisp_add_del_locator_reply_t *rmp;
5160 locator_t locator, *locators = NULL;
5161 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5163 u8 *locator_name = NULL;
5165 memset (&locator, 0, sizeof (locator));
5166 memset (a, 0, sizeof (a[0]));
5168 locator.sw_if_index = ntohl (mp->sw_if_index);
5169 locator.priority = mp->priority;
5170 locator.weight = mp->weight;
5172 vec_add1 (locators, locator);
5174 locator_name = format (0, "%s", mp->locator_set_name);
5176 a->name = locator_name;
5177 a->locators = locators;
5178 a->is_add = mp->is_add;
5181 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5183 vec_free (locators);
5184 vec_free (locator_name);
5186 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5190 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5196 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5197 gid_address_ip_set (dst, src, IP4);
5198 gid_address_ippref_len (dst) = len;
5199 ip_prefix_normalize (&gid_address_ippref (dst));
5202 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5203 gid_address_ip_set (dst, src, IP6);
5204 gid_address_ippref_len (dst) = len;
5205 ip_prefix_normalize (&gid_address_ippref (dst));
5207 case 2: /* l2 mac */
5208 gid_address_type (dst) = GID_ADDR_MAC;
5209 clib_memcpy (&gid_address_mac (dst), src, 6);
5213 return VNET_API_ERROR_INVALID_VALUE;
5216 gid_address_vni (dst) = vni;
5222 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5224 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5225 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5227 gid_address_t _eid, *eid = &_eid;
5229 u32 locator_set_index = ~0, map_index = ~0;
5230 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5232 memset (a, 0, sizeof (a[0]));
5233 memset (eid, 0, sizeof (eid[0]));
5235 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5236 mp->eid_type, mp->eid, mp->prefix_len);
5240 name = format (0, "%s", mp->locator_set_name);
5241 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5244 rv = VNET_API_ERROR_INVALID_VALUE;
5247 locator_set_index = p[0];
5249 /* XXX treat batch configuration */
5250 a->is_add = mp->is_add;
5251 gid_address_copy (&a->eid, eid);
5252 a->locator_set_index = locator_set_index;
5254 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5258 gid_address_free (&a->eid);
5260 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5264 vl_api_lisp_eid_table_add_del_map_t_handler
5265 (vl_api_lisp_eid_table_add_del_map_t * mp)
5267 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5269 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5270 clib_net_to_host_u32 (mp->dp_table),
5271 mp->is_l2, mp->is_add);
5272 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5274 /** Used for transferring locators via VPP API */
5276 typedef CLIB_PACKED (struct {
5277 u8 is_ip4; /**< is locator an IPv4 address */
5278 u8 priority; /**< locator priority */
5279 u8 weight; /**< locator weight */
5280 u8 addr[16]; /**< IPv4/IPv6 address */
5284 static locator_pair_t *
5285 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5288 locator_pair_t *pairs = 0, pair;
5291 for (i = 0; i < rloc_num; i++)
5294 r = &((rloc_t *) lcl_locs)[i];
5295 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5296 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5298 /* remote locators */
5299 r = &((rloc_t *) rmt_locs)[i];
5300 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5301 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5303 pair.priority = r->priority;
5304 pair.weight = r->weight;
5306 vec_add1 (pairs, pair);
5312 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5315 locator_t *locs = 0, loc;
5318 for (i = 0; i < rloc_num; i++)
5320 /* remote locators */
5321 r = &((rloc_t *) rmt_locs)[i];
5322 memset (&loc, 0, sizeof (loc));
5323 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5325 loc.priority = r->priority;
5326 loc.weight = r->weight;
5328 vec_add1 (locs, loc);
5334 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5335 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5337 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5338 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5339 locator_pair_t *pairs = 0;
5342 memset (a, 0, sizeof (a[0]));
5344 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5345 mp->rmt_eid, mp->rmt_len);
5346 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5347 mp->lcl_eid, mp->lcl_len);
5349 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5351 if (rv || 0 == pairs)
5354 a->is_add = mp->is_add;
5355 a->locator_pairs = pairs;
5356 a->dp_table = mp->dp_table;
5358 a->action = mp->action;
5360 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5363 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5367 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5370 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5372 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5374 memset (a, 0, sizeof (a[0]));
5376 a->is_add = mp->is_add;
5377 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5379 rv = vnet_lisp_add_del_map_resolver (a);
5381 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5385 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5388 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5390 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5392 a->is_en = mp->is_en;
5393 vnet_lisp_gpe_enable_disable (a);
5395 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5399 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5401 vl_api_lisp_enable_disable_reply_t *rmp;
5404 vnet_lisp_enable_disable (mp->is_en);
5405 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5409 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5411 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5413 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5415 a->is_add = mp->is_add;
5416 a->dp_table = mp->dp_table;
5418 a->is_l2 = mp->is_l2;
5419 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5421 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5425 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5428 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5432 ls_name = format (0, "%s", mp->ls_name);
5433 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5436 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5440 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5441 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5443 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5445 u8 *locator_set_name = NULL;
5446 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5448 locator_set_name = format (0, "%s", mp->locator_set_name);
5450 a->is_add = mp->is_add;
5451 a->locator_set_name = locator_set_name;
5453 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5455 vec_free (locator_set_name);
5457 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5461 vl_api_lisp_add_del_remote_mapping_t_handler
5462 (vl_api_lisp_add_del_remote_mapping_t * mp)
5464 locator_t *rlocs = 0;
5465 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5467 gid_address_t _eid, *eid = &_eid;
5469 memset (eid, 0, sizeof (eid[0]));
5471 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5472 mp->eid_type, mp->eid, mp->eid_len);
5476 rlocs = unformat_lisp_locs (mp->rlocs, mp->rloc_num);
5482 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5483 gid_address_copy (&a->deid, eid);
5485 rv = vnet_lisp_add_del_adjacency (a);
5492 /* NOTE: for now this works as a static remote mapping, i.e.,
5493 * not authoritative and ttl infinite. */
5494 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5498 vnet_lisp_clear_all_remote_adjacencies ();
5503 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5507 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5509 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5510 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5513 memset (a, 0, sizeof (a[0]));
5515 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5516 mp->eid_type, mp->seid, mp->seid_len);
5517 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5518 mp->eid_type, mp->deid, mp->deid_len);
5523 a->is_add = mp->is_add;
5524 rv = vnet_lisp_add_del_adjacency (a);
5527 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5531 send_lisp_locator_details (lisp_cp_main_t * lcm,
5533 unix_shared_memory_queue_t * q, u32 context)
5535 vl_api_lisp_locator_details_t *rmp;
5537 rmp = vl_msg_api_alloc (sizeof (*rmp));
5538 memset (rmp, 0, sizeof (*rmp));
5539 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5540 rmp->context = context;
5542 rmp->local = loc->local;
5545 rmp->sw_if_index = ntohl (loc->sw_if_index);
5549 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5550 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5552 rmp->priority = loc->priority;
5553 rmp->weight = loc->weight;
5555 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5559 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5561 unix_shared_memory_queue_t *q = 0;
5562 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5563 locator_set_t *lsit = 0;
5565 u32 ls_index = ~0, *locit = 0;
5568 q = vl_api_client_index_to_input_queue (mp->client_index);
5574 ls_index = htonl (mp->locator_set_index);
5576 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5578 filter = mp->filter;
5579 if (filter && !((1 == filter && lsit->local) ||
5580 (2 == filter && !lsit->local)))
5585 vec_foreach (locit, lsit->locator_indices)
5587 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5588 send_lisp_locator_details (lcm, loc, q, mp->context);
5593 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5594 locator_set_t * lsit,
5595 unix_shared_memory_queue_t * q,
5596 u32 context, u32 ls_index)
5598 vl_api_lisp_locator_set_details_t *rmp;
5601 rmp = vl_msg_api_alloc (sizeof (*rmp));
5602 memset (rmp, 0, sizeof (*rmp));
5603 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5604 rmp->context = context;
5606 rmp->local = lsit->local;
5607 rmp->locator_set_index = htonl (ls_index);
5610 ASSERT (lsit->name != NULL);
5611 strncpy ((char *) rmp->locator_set_name,
5612 (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1);
5616 str = format (0, "remote-%d", ls_index);
5617 strncpy ((char *) rmp->locator_set_name, (char *) str,
5618 ARRAY_LEN (rmp->locator_set_name) - 1);
5622 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5626 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5628 unix_shared_memory_queue_t *q = NULL;
5629 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5630 locator_set_t *lsit = NULL;
5634 q = vl_api_client_index_to_input_queue (mp->client_index);
5640 filter = mp->filter;
5643 pool_foreach (lsit, lcm->locator_set_pool,
5645 if (filter && !((1 == filter && lsit->local) ||
5646 (2 == filter && !lsit->local))) {
5650 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5656 send_lisp_eid_table_details (mapping_t * mapit,
5657 unix_shared_memory_queue_t * q,
5658 u32 context, u8 filter)
5660 vl_api_lisp_eid_table_details_t *rmp = NULL;
5661 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5662 locator_set_t *ls = NULL;
5663 gid_address_t *gid = NULL;
5665 ip_prefix_t *ip_prefix = NULL;
5667 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5686 clib_warning ("Filter error, unknown filter: %d\n", filter);
5691 ip_prefix = &gid_address_ippref (gid);
5692 mac = gid_address_mac (gid);
5694 rmp = vl_msg_api_alloc (sizeof (*rmp));
5695 memset (rmp, 0, sizeof (*rmp));
5696 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5697 rmp->locator_set_index = mapit->locator_set_index;
5698 rmp->is_local = ls->local;
5699 rmp->ttl = mapit->ttl;
5700 rmp->authoritative = mapit->authoritative;
5702 switch (gid_address_type (gid))
5704 case GID_ADDR_IP_PREFIX:
5705 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5706 if (ip_prefix_version (ip_prefix) == IP4)
5708 rmp->eid_type = 0; /* ipv4 type */
5709 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5710 sizeof (ip_prefix_v4 (ip_prefix)));
5714 rmp->eid_type = 1; /* ipv6 type */
5715 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5716 sizeof (ip_prefix_v6 (ip_prefix)));
5720 rmp->eid_type = 2; /* l2 mac type */
5721 clib_memcpy (rmp->eid, mac, 6);
5726 rmp->context = context;
5727 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5728 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5732 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5735 unix_shared_memory_queue_t *q = NULL;
5736 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5737 mapping_t *mapit = NULL;
5738 gid_address_t _eid, *eid = &_eid;
5740 q = vl_api_client_index_to_input_queue (mp->client_index);
5748 memset (eid, 0, sizeof (*eid));
5750 unformat_lisp_eid_api (eid, mp->eid_type,
5751 clib_net_to_host_u32 (mp->vni), mp->eid,
5754 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5755 if ((u32) ~ 0 == mi)
5758 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5759 send_lisp_eid_table_details (mapit, q, mp->context, mp->filter);
5764 pool_foreach (mapit, lcm->mapping_pool,
5766 send_lisp_eid_table_details(mapit, q, mp->context,
5774 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5775 unix_shared_memory_queue_t * q, u32 context)
5777 vl_api_lisp_gpe_tunnel_details_t *rmp;
5778 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5780 rmp = vl_msg_api_alloc (sizeof (*rmp));
5781 memset (rmp, 0, sizeof (*rmp));
5782 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5784 rmp->tunnels = tunnel - lgm->tunnels;
5786 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5787 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5788 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5790 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5791 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5792 rmp->dcap_next = htonl (tunnel->decap_next_index);
5793 rmp->lisp_ver = tunnel->ver_res;
5794 rmp->next_protocol = tunnel->next_protocol;
5795 rmp->flags = tunnel->flags;
5796 rmp->ver_res = tunnel->ver_res;
5797 rmp->res = tunnel->res;
5798 rmp->iid = htonl (tunnel->vni);
5799 rmp->context = context;
5801 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5805 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5807 unix_shared_memory_queue_t *q = NULL;
5808 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5809 lisp_gpe_tunnel_t *tunnel = NULL;
5811 if (pool_elts (lgm->tunnels) == 0)
5816 q = vl_api_client_index_to_input_queue (mp->client_index);
5823 pool_foreach(tunnel, lgm->tunnels,
5825 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5831 send_lisp_map_resolver_details (ip_address_t * ip,
5832 unix_shared_memory_queue_t * q, u32 context)
5834 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5836 rmp = vl_msg_api_alloc (sizeof (*rmp));
5837 memset (rmp, 0, sizeof (*rmp));
5838 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5840 switch (ip_addr_version (ip))
5844 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5845 sizeof (ip_addr_v4 (ip)));
5850 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5851 sizeof (ip_addr_v6 (ip)));
5857 rmp->context = context;
5859 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5863 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5865 unix_shared_memory_queue_t *q = NULL;
5866 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5867 ip_address_t *ip = NULL;
5869 q = vl_api_client_index_to_input_queue (mp->client_index);
5875 vec_foreach (ip, lcm->map_resolvers)
5877 send_lisp_map_resolver_details (ip, q, mp->context);
5883 send_eid_table_map_pair (hash_pair_t * p,
5884 unix_shared_memory_queue_t * q, u32 context)
5886 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5888 rmp = vl_msg_api_alloc (sizeof (*rmp));
5889 memset (rmp, 0, sizeof (*rmp));
5890 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5892 rmp->vni = clib_host_to_net_u32 (p->key);
5893 rmp->vrf = clib_host_to_net_u32 (p->value[0]);
5894 rmp->context = context;
5895 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5899 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5902 unix_shared_memory_queue_t *q = NULL;
5903 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5906 q = vl_api_client_index_to_input_queue (mp->client_index);
5912 hash_foreach_pair (p, lcm->table_id_by_vni,
5914 send_eid_table_map_pair (p, q, mp->context);
5920 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
5922 unix_shared_memory_queue_t *q = NULL;
5923 vl_api_show_lisp_status_reply_t *rmp = NULL;
5926 q = vl_api_client_index_to_input_queue (mp->client_index);
5933 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5935 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5936 rmp->feature_status = vnet_lisp_enable_disable_status ();
5942 vl_api_lisp_get_map_request_itr_rlocs_t_handler
5943 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
5945 unix_shared_memory_queue_t *q = NULL;
5946 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5947 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5948 locator_set_t *loc_set = 0;
5952 q = vl_api_client_index_to_input_queue (mp->client_index);
5958 if (~0 == lcm->mreq_itr_rlocs)
5960 tmp_str = format (0, " ");
5965 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5966 tmp_str = format (0, "%s", loc_set->name);
5970 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5972 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5973 ARRAY_LEN(rmp->locator_set_name) - 1);
5981 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5983 unix_shared_memory_queue_t *q = NULL;
5984 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
5985 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5987 locator_set_t *ls = 0;
5991 q = vl_api_client_index_to_input_queue (mp->client_index);
5997 if (!lcm->lisp_pitr)
5999 tmp_str = format (0, "N/A");
6003 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6004 if (~0 != m->locator_set_index)
6007 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6008 tmp_str = format (0, "%s", ls->name);
6012 tmp_str = format (0, "N/A");
6015 vec_add1 (tmp_str, 0);
6018 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6020 rmp->status = lcm->lisp_pitr;
6021 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6022 ARRAY_LEN(rmp->locator_set_name) - 1);
6028 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6031 vl_api_interface_name_renumber_reply_t *rmp;
6034 VALIDATE_SW_IF_INDEX (mp);
6036 rv = vnet_interface_name_renumber
6037 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6039 BAD_SW_IF_INDEX_LABEL;
6041 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6045 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6046 u32 sw_if_index, u32 address)
6048 vpe_api_main_t *am = &vpe_api_main;
6049 vlib_main_t *vm = am->vlib_main;
6050 vl_api_ip4_arp_event_t *event;
6051 static f64 arp_event_last_time;
6052 f64 now = vlib_time_now (vm);
6054 if (pool_is_free_index (am->arp_events, pool_index))
6057 event = pool_elt_at_index (am->arp_events, pool_index);
6058 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6060 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6064 if ((sw_if_index == event->sw_if_index) && ((address == 0) ||
6065 /* for BD case, also check IP address with 10 sec timeout */
6066 ((address == event->address)
6069 arp_event_last_time) <
6074 arp_event_last_time = now;
6075 event->sw_if_index = sw_if_index;
6077 event->address = address;
6082 arp_change_delete_callback (u32 pool_index, u8 * notused)
6084 vpe_api_main_t *am = &vpe_api_main;
6086 if (pool_is_free_index (am->arp_events, pool_index))
6089 pool_put_index (am->arp_events, pool_index);
6094 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6096 vpe_api_main_t *am = &vpe_api_main;
6097 vnet_main_t *vnm = vnet_get_main ();
6098 vl_api_want_ip4_arp_events_reply_t *rmp;
6099 vl_api_ip4_arp_event_t *event;
6102 if (mp->enable_disable)
6104 pool_get (am->arp_events, event);
6105 memset (event, 0, sizeof (*event));
6107 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6108 event->client_index = mp->client_index;
6109 event->context = mp->context;
6110 event->address = mp->address;
6111 event->pid = mp->pid;
6113 rv = vnet_add_del_ip4_arp_change_event
6114 (vnm, arp_change_data_callback,
6115 mp->pid, &mp->address /* addr, in net byte order */ ,
6116 vpe_resolver_process_node.index,
6117 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6121 rv = vnet_add_del_ip4_arp_change_event
6122 (vnm, arp_change_delete_callback,
6123 mp->pid, &mp->address /* addr, in net byte order */ ,
6124 vpe_resolver_process_node.index,
6125 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6127 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6130 static void vl_api_input_acl_set_interface_t_handler
6131 (vl_api_input_acl_set_interface_t * mp)
6133 vlib_main_t *vm = vlib_get_main ();
6134 vl_api_input_acl_set_interface_reply_t *rmp;
6136 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6138 ip4_table_index = ntohl (mp->ip4_table_index);
6139 ip6_table_index = ntohl (mp->ip6_table_index);
6140 l2_table_index = ntohl (mp->l2_table_index);
6141 sw_if_index = ntohl (mp->sw_if_index);
6143 VALIDATE_SW_IF_INDEX (mp);
6145 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6146 ip6_table_index, l2_table_index, mp->is_add);
6148 BAD_SW_IF_INDEX_LABEL;
6150 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6153 static void vl_api_ipsec_spd_add_del_t_handler
6154 (vl_api_ipsec_spd_add_del_t * mp)
6157 clib_warning ("unimplemented");
6160 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6161 vl_api_ipsec_spd_add_del_reply_t *rmp;
6165 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6167 rv = VNET_API_ERROR_UNIMPLEMENTED;
6170 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6174 static void vl_api_ipsec_interface_add_del_spd_t_handler
6175 (vl_api_ipsec_interface_add_del_spd_t * mp)
6177 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6178 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6180 u32 sw_if_index __attribute__ ((unused));
6181 u32 spd_id __attribute__ ((unused));
6183 sw_if_index = ntohl (mp->sw_if_index);
6184 spd_id = ntohl (mp->spd_id);
6186 VALIDATE_SW_IF_INDEX (mp);
6189 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6191 rv = VNET_API_ERROR_UNIMPLEMENTED;
6194 BAD_SW_IF_INDEX_LABEL;
6196 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6199 static void vl_api_ipsec_spd_add_del_entry_t_handler
6200 (vl_api_ipsec_spd_add_del_entry_t * mp)
6202 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6203 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6209 memset (&p, 0, sizeof (p));
6211 p.id = ntohl (mp->spd_id);
6212 p.priority = ntohl (mp->priority);
6213 p.is_outbound = mp->is_outbound;
6214 p.is_ipv6 = mp->is_ipv6;
6216 if (mp->is_ipv6 || mp->is_ip_any)
6218 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6219 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6220 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6221 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6225 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6226 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6227 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6228 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6230 p.protocol = mp->protocol;
6231 p.rport.start = ntohs (mp->remote_port_start);
6232 p.rport.stop = ntohs (mp->remote_port_stop);
6233 p.lport.start = ntohs (mp->local_port_start);
6234 p.lport.stop = ntohs (mp->local_port_stop);
6235 /* policy action resolve unsupported */
6236 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6238 clib_warning ("unsupported action: 'resolve'");
6239 rv = VNET_API_ERROR_UNIMPLEMENTED;
6242 p.policy = mp->policy;
6243 p.sa_id = ntohl (mp->sa_id);
6245 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6252 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6255 rv = VNET_API_ERROR_UNIMPLEMENTED;
6260 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6263 static void vl_api_ipsec_sad_add_del_entry_t_handler
6264 (vl_api_ipsec_sad_add_del_entry_t * mp)
6266 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6267 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6272 memset (&sa, 0, sizeof (sa));
6274 sa.id = ntohl (mp->sad_id);
6275 sa.spi = ntohl (mp->spi);
6276 /* security protocol AH unsupported */
6277 if (mp->protocol == IPSEC_PROTOCOL_AH)
6279 clib_warning ("unsupported security protocol 'AH'");
6280 rv = VNET_API_ERROR_UNIMPLEMENTED;
6283 sa.protocol = mp->protocol;
6284 /* check for unsupported crypto-alg */
6285 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6286 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6288 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6289 mp->crypto_algorithm);
6290 rv = VNET_API_ERROR_UNIMPLEMENTED;
6293 sa.crypto_alg = mp->crypto_algorithm;
6294 sa.crypto_key_len = mp->crypto_key_length;
6295 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6296 /* check for unsupported integ-alg */
6297 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6298 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6300 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6301 mp->integrity_algorithm);
6302 rv = VNET_API_ERROR_UNIMPLEMENTED;
6305 sa.integ_alg = mp->integrity_algorithm;
6306 sa.integ_key_len = mp->integrity_key_length;
6307 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6308 sa.use_esn = mp->use_extended_sequence_number;
6309 sa.is_tunnel = mp->is_tunnel;
6310 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6311 if (sa.is_tunnel_ip6)
6313 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6314 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6318 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6319 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6322 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6324 rv = VNET_API_ERROR_UNIMPLEMENTED;
6329 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6333 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6335 vl_api_ikev2_profile_add_del_reply_t *rmp;
6339 vlib_main_t *vm = vlib_get_main ();
6340 clib_error_t *error;
6341 u8 *tmp = format (0, "%s", mp->name);
6342 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6345 rv = VNET_API_ERROR_UNSPECIFIED;
6347 rv = VNET_API_ERROR_UNIMPLEMENTED;
6350 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6354 vl_api_ikev2_profile_set_auth_t_handler
6355 (vl_api_ikev2_profile_set_auth_t * mp)
6357 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6361 vlib_main_t *vm = vlib_get_main ();
6362 clib_error_t *error;
6363 u8 *tmp = format (0, "%s", mp->name);
6364 u8 *data = vec_new (u8, mp->data_len);
6365 clib_memcpy (data, mp->data, mp->data_len);
6366 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6370 rv = VNET_API_ERROR_UNSPECIFIED;
6372 rv = VNET_API_ERROR_UNIMPLEMENTED;
6375 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6379 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6381 vl_api_ikev2_profile_add_del_reply_t *rmp;
6385 vlib_main_t *vm = vlib_get_main ();
6386 clib_error_t *error;
6387 u8 *tmp = format (0, "%s", mp->name);
6388 u8 *data = vec_new (u8, mp->data_len);
6389 clib_memcpy (data, mp->data, mp->data_len);
6390 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6394 rv = VNET_API_ERROR_UNSPECIFIED;
6396 rv = VNET_API_ERROR_UNIMPLEMENTED;
6399 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6403 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6405 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6409 vlib_main_t *vm = vlib_get_main ();
6410 clib_error_t *error;
6411 u8 *tmp = format (0, "%s", mp->name);
6412 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6413 mp->end_port, (ip4_address_t) mp->start_addr,
6414 (ip4_address_t) mp->end_addr, mp->is_local);
6417 rv = VNET_API_ERROR_UNSPECIFIED;
6419 rv = VNET_API_ERROR_UNIMPLEMENTED;
6422 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6426 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6428 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6432 vlib_main_t *vm = vlib_get_main ();
6433 clib_error_t *error;
6435 error = ikev2_set_local_key (vm, mp->key_file);
6437 rv = VNET_API_ERROR_UNSPECIFIED;
6439 rv = VNET_API_ERROR_UNIMPLEMENTED;
6442 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6446 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6448 vl_api_map_add_domain_reply_t *rmp;
6451 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6453 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6454 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6455 (ip6_address_t *) & mp->ip6_src,
6456 mp->ip6_src_prefix_len, mp->ea_bits_len,
6457 mp->psid_offset, mp->psid_length, &index,
6458 ntohs (mp->mtu), flags);
6461 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6463 rmp->index = ntohl(index);
6469 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6471 vl_api_map_del_domain_reply_t *rmp;
6474 rv = map_delete_domain (ntohl (mp->index));
6476 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6480 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6482 vl_api_map_del_domain_reply_t *rmp;
6486 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6487 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6489 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6493 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6495 vl_api_map_domain_details_t *rmp;
6496 map_main_t *mm = &map_main;
6498 unix_shared_memory_queue_t *q;
6500 if (pool_elts (mm->domains) == 0)
6503 q = vl_api_client_index_to_input_queue (mp->client_index);
6510 pool_foreach(d, mm->domains,
6512 /* Make sure every field is initiated (or don't skip the memset()) */
6513 rmp = vl_msg_api_alloc (sizeof (*rmp));
6514 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6515 rmp->domain_index = htonl(d - mm->domains);
6516 rmp->ea_bits_len = d->ea_bits_len;
6517 rmp->psid_offset = d->psid_offset;
6518 rmp->psid_length = d->psid_length;
6519 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6520 rmp->ip4_prefix_len = d->ip4_prefix_len;
6521 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6522 rmp->ip6_prefix_len = d->ip6_prefix_len;
6523 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6524 rmp->ip6_src_len = d->ip6_src_len;
6525 rmp->mtu = htons(d->mtu);
6526 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6527 rmp->context = mp->context;
6529 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6535 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6537 unix_shared_memory_queue_t *q;
6540 vl_api_map_rule_details_t *rmp;
6541 map_main_t *mm = &map_main;
6542 u32 domain_index = ntohl (mp->domain_index);
6545 if (pool_elts (mm->domains) == 0)
6548 d = pool_elt_at_index (mm->domains, domain_index);
6549 if (!d || !d->rules)
6554 q = vl_api_client_index_to_input_queue (mp->client_index);
6560 for (i = 0; i < (0x1 << d->psid_length); i++)
6563 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6567 rmp = vl_msg_api_alloc (sizeof (*rmp));
6568 memset (rmp, 0, sizeof (*rmp));
6569 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6570 rmp->psid = htons (i);
6571 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6572 rmp->context = mp->context;
6573 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6578 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6580 vl_api_map_summary_stats_reply_t *rmp;
6581 vlib_combined_counter_main_t *cm;
6584 u64 total_pkts[VLIB_N_RX_TX];
6585 u64 total_bytes[VLIB_N_RX_TX];
6586 map_main_t *mm = &map_main;
6587 unix_shared_memory_queue_t *q =
6588 vl_api_client_index_to_input_queue (mp->client_index);
6593 rmp = vl_msg_api_alloc (sizeof (*rmp));
6594 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6595 rmp->context = mp->context;
6598 memset (total_pkts, 0, sizeof (total_pkts));
6599 memset (total_bytes, 0, sizeof (total_bytes));
6601 map_domain_counter_lock (mm);
6602 vec_foreach (cm, mm->domain_counters)
6604 which = cm - mm->domain_counters;
6606 for (i = 0; i < vec_len (cm->maxi); i++)
6608 vlib_get_combined_counter (cm, i, &v);
6609 total_pkts[which] += v.packets;
6610 total_bytes[which] += v.bytes;
6614 map_domain_counter_unlock (mm);
6616 /* Note: in network byte order! */
6617 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6618 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6619 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6620 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6621 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6622 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6623 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6624 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6625 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6626 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6627 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6628 clib_host_to_net_u64 (map_error_counter_get
6629 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6630 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6631 clib_host_to_net_u64 (map_error_counter_get
6632 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6634 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6638 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6640 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6641 vl_api_ipsec_sa_set_key_reply_t *rmp;
6645 sa.id = ntohl (mp->sa_id);
6646 sa.crypto_key_len = mp->crypto_key_length;
6647 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6648 sa.integ_key_len = mp->integrity_key_length;
6649 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6651 rv = ipsec_set_sa_key (vm, &sa);
6653 rv = VNET_API_ERROR_UNIMPLEMENTED;
6656 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6659 static void vl_api_cop_interface_enable_disable_t_handler
6660 (vl_api_cop_interface_enable_disable_t * mp)
6662 vl_api_cop_interface_enable_disable_reply_t *rmp;
6664 u32 sw_if_index = ntohl (mp->sw_if_index);
6667 VALIDATE_SW_IF_INDEX (mp);
6669 enable_disable = (int) mp->enable_disable;
6671 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6673 BAD_SW_IF_INDEX_LABEL;
6675 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6678 static void vl_api_cop_whitelist_enable_disable_t_handler
6679 (vl_api_cop_whitelist_enable_disable_t * mp)
6681 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6682 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6683 u32 sw_if_index = ntohl (mp->sw_if_index);
6686 VALIDATE_SW_IF_INDEX (mp);
6688 a->sw_if_index = sw_if_index;
6691 a->default_cop = mp->default_cop;
6692 a->fib_id = ntohl (mp->fib_id);
6694 rv = cop_whitelist_enable_disable (a);
6696 BAD_SW_IF_INDEX_LABEL;
6698 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6702 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6706 api_main_t *am = &api_main;
6707 vlib_main_t *vm = vlib_get_main ();
6709 vl_api_get_node_graph_reply_t *rmp;
6711 pthread_mutex_lock (&am->vlib_rp->mutex);
6712 oldheap = svm_push_data_heap (am->vlib_rp);
6715 * Keep the number of memcpy ops to a minimum (e.g. 1).
6717 vec_validate (vector, 16384);
6718 vec_reset_length (vector);
6721 vector = vlib_node_serialize (&vm->node_main, vector,
6722 (u32) ~ 0 /* all threads */ ,
6723 1 /* include nexts */ ,
6724 1 /* include stats */ );
6726 svm_pop_heap (oldheap);
6727 pthread_mutex_unlock (&am->vlib_rp->mutex);
6730 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6732 rmp->reply_in_shmem = (uword) vector;
6737 static void vl_api_trace_profile_add_t_handler
6738 (vl_api_trace_profile_add_t * mp)
6741 vl_api_trace_profile_add_reply_t *rmp;
6742 clib_error_t *error;
6744 /* Ignoring the profile id as currently a single profile
6746 error = ip6_ioam_trace_profile_set (mp->trace_num_elt, mp->trace_type,
6747 ntohl (mp->node_id),
6748 ntohl (mp->trace_app_data),
6749 mp->pow_enable, mp->trace_tsp,
6753 clib_error_report (error);
6754 rv = clib_error_get_code (error);
6757 REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
6760 static void vl_api_trace_profile_apply_t_handler
6761 (vl_api_trace_profile_apply_t * mp)
6764 vl_api_trace_profile_apply_reply_t *rmp;
6766 if (mp->enable != 0)
6768 rv = ip6_ioam_set_destination ((ip6_address_t *) (&mp->dest_ipv6),
6769 ntohl (mp->prefix_length),
6771 mp->trace_op == IOAM_HBYH_ADD,
6772 mp->trace_op == IOAM_HBYH_POP,
6773 mp->trace_op == IOAM_HBYH_MOD);
6777 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6779 REPLY_MACRO (VL_API_TRACE_PROFILE_APPLY_REPLY);
6782 static void vl_api_trace_profile_del_t_handler
6783 (vl_api_trace_profile_del_t * mp)
6786 vl_api_trace_profile_del_reply_t *rmp;
6787 clib_error_t *error;
6789 error = clear_ioam_rewrite_fn ();
6792 clib_error_report (error);
6793 rv = clib_error_get_code (error);
6796 REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
6800 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6802 vlib_main_t *vm = vlib_get_main ();
6803 vl_api_af_packet_create_reply_t *rmp;
6805 u8 *host_if_name = NULL;
6808 host_if_name = format (0, "%s", mp->host_if_name);
6809 vec_add1 (host_if_name, 0);
6811 rv = af_packet_create_if (vm, host_if_name,
6812 mp->use_random_hw_addr ? 0 : mp->hw_addr,
6815 vec_free (host_if_name);
6818 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6820 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
6826 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
6828 vlib_main_t *vm = vlib_get_main ();
6829 vl_api_af_packet_delete_reply_t *rmp;
6831 u8 *host_if_name = NULL;
6833 host_if_name = format (0, "%s", mp->host_if_name);
6834 vec_add1 (host_if_name, 0);
6836 rv = af_packet_delete_if (vm, host_if_name);
6838 vec_free (host_if_name);
6840 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
6844 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
6846 vlib_main_t *vm = vlib_get_main ();
6847 vl_api_policer_add_del_reply_t *rmp;
6850 sse2_qos_pol_cfg_params_st cfg;
6851 clib_error_t *error;
6854 name = format (0, "%s", mp->name);
6856 memset (&cfg, 0, sizeof (cfg));
6858 cfg.rnd_type = mp->round_type;
6859 cfg.rate_type = mp->rate_type;
6860 cfg.rb.kbps.cir_kbps = mp->cir;
6861 cfg.rb.kbps.eir_kbps = mp->eir;
6862 cfg.rb.kbps.cb_bytes = mp->cb;
6863 cfg.rb.kbps.eb_bytes = mp->eb;
6864 cfg.conform_action.action_type = mp->conform_action_type;
6865 cfg.conform_action.dscp = mp->conform_dscp;
6866 cfg.exceed_action.action_type = mp->exceed_action_type;
6867 cfg.exceed_action.dscp = mp->exceed_dscp;
6868 cfg.violate_action.action_type = mp->violate_action_type;
6869 cfg.violate_action.dscp = mp->violate_dscp;
6870 cfg.color_aware = mp->color_aware;
6872 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
6875 rv = VNET_API_ERROR_UNSPECIFIED;
6878 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6880 if (rv == 0 && mp->is_add)
6881 rmp->policer_index = ntohl(policer_index);
6883 rmp->policer_index = ~0;
6889 send_policer_details (u8 * name,
6890 sse2_qos_pol_cfg_params_st * config,
6891 policer_read_response_type_st * templ,
6892 unix_shared_memory_queue_t * q, u32 context)
6894 vl_api_policer_details_t *mp;
6896 mp = vl_msg_api_alloc (sizeof (*mp));
6897 memset (mp, 0, sizeof (*mp));
6898 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6899 mp->context = context;
6900 mp->cir = htonl (config->rb.kbps.cir_kbps);
6901 mp->eir = htonl (config->rb.kbps.eir_kbps);
6902 mp->cb = htonl (config->rb.kbps.cb_bytes);
6903 mp->eb = htonl (config->rb.kbps.eb_bytes);
6904 mp->rate_type = config->rate_type;
6905 mp->round_type = config->rnd_type;
6906 mp->type = config->rfc;
6907 mp->conform_action_type = config->conform_action.action_type;
6908 mp->conform_dscp = config->conform_action.dscp;
6909 mp->exceed_action_type = config->exceed_action.action_type;
6910 mp->exceed_dscp = config->exceed_action.dscp;
6911 mp->violate_action_type = config->violate_action.action_type;
6912 mp->violate_dscp = config->violate_action.dscp;
6913 mp->single_rate = templ->single_rate ? 1 : 0;
6914 mp->color_aware = templ->color_aware ? 1 : 0;
6915 mp->scale = htonl (templ->scale);
6916 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
6917 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
6918 mp->current_limit = htonl (templ->current_limit);
6919 mp->current_bucket = htonl (templ->current_bucket);
6920 mp->extended_limit = htonl (templ->extended_limit);
6921 mp->extended_bucket = htonl (templ->extended_bucket);
6922 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
6924 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
6926 vl_msg_api_send_shmem (q, (u8 *) & mp);
6930 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
6932 unix_shared_memory_queue_t *q;
6933 vnet_policer_main_t *pm = &vnet_policer_main;
6939 sse2_qos_pol_cfg_params_st *config;
6940 policer_read_response_type_st *templ;
6942 q = vl_api_client_index_to_input_queue (mp->client_index);
6946 if (mp->match_name_valid)
6948 match_name = format (0, "%s%c", mp->match_name, 0);
6951 if (mp->match_name_valid)
6953 p = hash_get_mem (pm->policer_config_by_name, match_name);
6957 config = pool_elt_at_index (pm->configs, pool_index);
6958 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6959 send_policer_details (match_name, config, templ, q, mp->context);
6965 hash_foreach_pair (hp, pm->policer_config_by_name,
6967 name = (u8 *) hp->key;
6968 pool_index = hp->value[0];
6969 config = pool_elt_at_index (pm->configs, pool_index);
6970 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6971 send_policer_details(name, config, templ, q, mp->context);
6978 vl_api_policer_classify_set_interface_t_handler
6979 (vl_api_policer_classify_set_interface_t * mp)
6981 vlib_main_t *vm = vlib_get_main ();
6982 vl_api_policer_classify_set_interface_reply_t *rmp;
6984 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6986 ip4_table_index = ntohl (mp->ip4_table_index);
6987 ip6_table_index = ntohl (mp->ip6_table_index);
6988 l2_table_index = ntohl (mp->l2_table_index);
6989 sw_if_index = ntohl (mp->sw_if_index);
6991 VALIDATE_SW_IF_INDEX (mp);
6993 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
6994 ip6_table_index, l2_table_index,
6997 BAD_SW_IF_INDEX_LABEL;
6999 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7003 send_policer_classify_details (u32 sw_if_index,
7005 unix_shared_memory_queue_t * q, u32 context)
7007 vl_api_policer_classify_details_t *mp;
7009 mp = vl_msg_api_alloc (sizeof (*mp));
7010 memset (mp, 0, sizeof (*mp));
7011 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7012 mp->context = context;
7013 mp->sw_if_index = htonl (sw_if_index);
7014 mp->table_index = htonl (table_index);
7016 vl_msg_api_send_shmem (q, (u8 *) & mp);
7020 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7022 unix_shared_memory_queue_t *q;
7023 policer_classify_main_t *pcm = &policer_classify_main;
7027 q = vl_api_client_index_to_input_queue (mp->client_index);
7031 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7033 if (vec_len (vec_tbl))
7035 for (i = 0; i < vec_len (vec_tbl); i++)
7037 if (vec_elt (vec_tbl, i) == ~0)
7040 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7047 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7049 vlib_main_t *vm = vlib_get_main ();
7050 vl_api_netmap_create_reply_t *rmp;
7054 if_name = format (0, "%s", mp->netmap_if_name);
7055 vec_add1 (if_name, 0);
7058 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7059 mp->is_pipe, mp->is_master, 0);
7063 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7067 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7069 vlib_main_t *vm = vlib_get_main ();
7070 vl_api_netmap_delete_reply_t *rmp;
7074 if_name = format (0, "%s", mp->netmap_if_name);
7075 vec_add1 (if_name, 0);
7077 rv = netmap_delete_if (vm, if_name);
7081 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7085 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7088 clib_warning ("BUG");
7092 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7093 unix_shared_memory_queue_t * q,
7094 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7096 vl_api_mpls_gre_tunnel_details_t *mp;
7098 mp = vl_msg_api_alloc (sizeof (*mp));
7099 memset (mp, 0, sizeof (*mp));
7100 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7101 mp->context = context;
7105 mp->tunnel_index = htonl (index);
7106 mp->tunnel_src = gt->tunnel_src.as_u32;
7107 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7108 mp->intfc_address = gt->intfc_address.as_u32;
7109 mp->mask_width = htonl (gt->mask_width);
7110 mp->inner_fib_index = htonl (gt->inner_fib_index);
7111 mp->outer_fib_index = htonl (gt->outer_fib_index);
7112 mp->encap_index = htonl (gt->encap_index);
7113 mp->hw_if_index = htonl (gt->hw_if_index);
7114 mp->l2_only = htonl (gt->l2_only);
7117 mpls_main_t *mm = &mpls_main;
7122 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7123 len = vec_len (e->labels);
7124 mp->nlabels = htonl (len);
7126 for (i = 0; i < len; i++)
7129 htonl (vnet_mpls_uc_get_label
7130 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7133 vl_msg_api_send_shmem (q, (u8 *) & mp);
7137 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7139 vpe_api_main_t *am = &vpe_api_main;
7140 unix_shared_memory_queue_t *q;
7141 vlib_main_t *vm = &vlib_global_main;
7142 mpls_main_t *mm = &mpls_main;
7143 mpls_gre_tunnel_t *gt;
7144 u32 index = ntohl (mp->tunnel_index);
7146 q = vl_api_client_index_to_input_queue (mp->client_index);
7150 if (pool_elts (mm->gre_tunnels))
7152 if (mp->tunnel_index >= 0)
7154 vlib_cli_output (vm, "MPLS-GRE tunnel %u", index);
7155 gt = pool_elt_at_index (mm->gre_tunnels, index);
7156 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7161 vlib_cli_output (vm, "MPLS-GRE tunnels");
7163 pool_foreach (gt, mm->gre_tunnels,
7165 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7173 vlib_cli_output (vm, "No MPLS-GRE tunnels");
7178 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7181 clib_warning ("BUG");
7185 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7186 unix_shared_memory_queue_t * q,
7187 mpls_eth_tunnel_t * et, u32 index, u32 context)
7189 vl_api_mpls_eth_tunnel_details_t *mp;
7191 mp = vl_msg_api_alloc (sizeof (*mp));
7192 memset (mp, 0, sizeof (*mp));
7193 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7194 mp->context = context;
7198 mp->tunnel_index = htonl (index);
7199 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7200 mp->intfc_address = et->intfc_address.as_u32;
7201 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7202 mp->inner_fib_index = htonl (et->inner_fib_index);
7203 mp->mask_width = htonl (et->mask_width);
7204 mp->encap_index = htonl (et->encap_index);
7205 mp->hw_if_index = htonl (et->hw_if_index);
7206 mp->l2_only = htonl (et->l2_only);
7209 mpls_main_t *mm = &mpls_main;
7214 e = pool_elt_at_index (mm->encaps, et->encap_index);
7215 len = vec_len (e->labels);
7216 mp->nlabels = htonl (len);
7218 for (i = 0; i < len; i++)
7221 htonl (vnet_mpls_uc_get_label
7222 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7225 vl_msg_api_send_shmem (q, (u8 *) & mp);
7229 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7231 vpe_api_main_t *am = &vpe_api_main;
7232 unix_shared_memory_queue_t *q;
7233 vlib_main_t *vm = &vlib_global_main;
7234 mpls_main_t *mm = &mpls_main;
7235 mpls_eth_tunnel_t *et;
7236 u32 index = ntohl (mp->tunnel_index);
7238 q = vl_api_client_index_to_input_queue (mp->client_index);
7242 clib_warning ("Received mpls_eth_tunnel_dump");
7243 clib_warning ("Received tunnel index: %u from client %u", index,
7246 if (pool_elts (mm->eth_tunnels))
7248 if (mp->tunnel_index >= 0)
7250 vlib_cli_output (vm, "MPLS-Ethernet tunnel %u", index);
7251 et = pool_elt_at_index (mm->eth_tunnels, index);
7252 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7257 clib_warning ("MPLS-Ethernet tunnels");
7259 pool_foreach (et, mm->eth_tunnels,
7261 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7269 clib_warning ("No MPLS-Ethernet tunnels");
7274 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7276 clib_warning ("BUG");
7280 send_mpls_fib_encap_details (vpe_api_main_t * am,
7281 unix_shared_memory_queue_t * q,
7282 show_mpls_fib_t * s, u32 context)
7284 vl_api_mpls_fib_encap_details_t *mp;
7286 mp = vl_msg_api_alloc (sizeof (*mp));
7287 memset (mp, 0, sizeof (*mp));
7288 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7289 mp->context = context;
7291 mp->fib_index = htonl (s->fib_index);
7292 mp->entry_index = htonl (s->entry_index);
7294 mp->s_bit = htonl (s->s_bit);
7296 mpls_main_t *mm = &mpls_main;
7301 e = pool_elt_at_index (mm->encaps, s->entry_index);
7302 len = vec_len (e->labels);
7303 mp->nlabels = htonl (len);
7305 for (i = 0; i < len; i++)
7308 htonl (vnet_mpls_uc_get_label
7309 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7312 vl_msg_api_send_shmem (q, (u8 *) & mp);
7316 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7318 vpe_api_main_t *am = &vpe_api_main;
7319 unix_shared_memory_queue_t *q;
7320 vlib_main_t *vm = &vlib_global_main;
7323 show_mpls_fib_t *records = 0;
7325 mpls_main_t *mm = &mpls_main;
7326 ip4_main_t *im = &ip4_main;
7329 q = vl_api_client_index_to_input_queue (mp->client_index);
7334 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7336 vec_add2 (records, s, 1);
7337 s->fib_index = (u32)(key>>32);
7338 s->dest = (u32)(key & 0xFFFFFFFF);
7339 s->entry_index = (u32) value;
7343 if (0 == vec_len (records))
7345 vlib_cli_output (vm, "MPLS encap table empty");
7349 /* sort output by dst address within fib */
7350 vec_sort_with_function (records, mpls_dest_cmp);
7351 vec_sort_with_function (records, mpls_fib_index_cmp);
7352 vlib_cli_output (vm, "MPLS encap table");
7353 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7354 vec_foreach (s, records)
7356 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7357 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7358 format_ip4_address, &s->dest, format_mpls_encap_index,
7359 mm, s->entry_index);
7360 send_mpls_fib_encap_details (am, q, s, mp->context);
7368 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7370 clib_warning ("BUG");
7374 send_mpls_fib_decap_details (vpe_api_main_t * am,
7375 unix_shared_memory_queue_t * q,
7376 show_mpls_fib_t * s,
7378 u32 tx_table_id, char *swif_tag, u32 context)
7380 vl_api_mpls_fib_decap_details_t *mp;
7382 mp = vl_msg_api_alloc (sizeof (*mp));
7383 memset (mp, 0, sizeof (*mp));
7384 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7385 mp->context = context;
7387 mp->fib_index = htonl (s->fib_index);
7388 mp->entry_index = htonl (s->entry_index);
7390 mp->s_bit = htonl (s->s_bit);
7391 mp->label = htonl (s->label);
7392 mp->rx_table_id = htonl (rx_table_id);
7393 mp->tx_table_id = htonl (tx_table_id);
7394 strncpy ((char *) mp->swif_tag,
7395 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7397 vl_msg_api_send_shmem (q, (u8 *) & mp);
7401 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7403 vpe_api_main_t *am = &vpe_api_main;
7404 unix_shared_memory_queue_t *q;
7405 vlib_main_t *vm = &vlib_global_main;
7408 show_mpls_fib_t *records = 0;
7410 mpls_main_t *mm = &mpls_main;
7411 ip4_main_t *im = &ip4_main;
7417 q = vl_api_client_index_to_input_queue (mp->client_index);
7422 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7424 vec_add2 (records, s, 1);
7425 s->fib_index = (u32)(key>>32);
7426 s->entry_index = (u32) value;
7427 s->label = ((u32) key)>>12;
7428 s->s_bit = (key & (1<<8)) != 0;
7432 if (!vec_len (records))
7434 vlib_cli_output (vm, "MPLS decap table empty");
7438 vec_sort_with_function (records, mpls_label_cmp);
7439 vlib_cli_output (vm, "MPLS decap table");
7440 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7442 vec_foreach (s, records)
7445 d = pool_elt_at_index (mm->decaps, s->entry_index);
7446 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT)
7448 tx_fib = vec_elt_at_index (im->fibs, d->tx_fib_index);
7449 tx_table_id = tx_fib->table_id;
7454 tx_table_id = d->tx_fib_index;
7457 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7459 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7460 tx_table_id, swif_tag, s->label, s->s_bit);
7462 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7463 tx_table_id, swif_tag, mp->context);
7471 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7473 unix_shared_memory_queue_t *q;
7475 q = vl_api_client_index_to_input_queue (mp->client_index);
7479 vnet_classify_main_t *cm = &vnet_classify_main;
7480 vnet_classify_table_t *t;
7485 pool_foreach (t, cm->tables,
7487 vec_add1 (table_ids, ntohl(t - cm->tables));
7490 count = vec_len (table_ids);
7492 vl_api_classify_table_ids_reply_t *rmp;
7493 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7494 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7495 rmp->context = mp->context;
7496 rmp->count = ntohl (count);
7497 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7500 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7502 vec_free (table_ids);
7506 vl_api_classify_table_by_interface_t_handler
7507 (vl_api_classify_table_by_interface_t * mp)
7509 vl_api_classify_table_by_interface_reply_t *rmp;
7512 u32 sw_if_index = ntohl (mp->sw_if_index);
7515 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7518 VALIDATE_SW_IF_INDEX (mp);
7520 input_acl_main_t *am = &input_acl_main;
7525 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7527 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7528 if (vec_len (vec_tbl))
7530 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7532 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7536 acl[type] = vec_elt (vec_tbl, if_idx);
7541 BAD_SW_IF_INDEX_LABEL;
7544 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7546 rmp->sw_if_index = ntohl(sw_if_index);
7547 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7548 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7549 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7556 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7558 unix_shared_memory_queue_t *q;
7560 q = vl_api_client_index_to_input_queue (mp->client_index);
7564 vl_api_classify_table_info_reply_t *rmp = 0;
7566 vnet_classify_main_t *cm = &vnet_classify_main;
7567 u32 table_id = ntohl (mp->table_id);
7568 vnet_classify_table_t *t;
7571 pool_foreach (t, cm->tables,
7573 if (table_id == t - cm->tables)
7575 rmp = vl_msg_api_alloc_as_if_client
7576 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7577 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7578 rmp->context = mp->context;
7579 rmp->table_id = ntohl(table_id);
7580 rmp->nbuckets = ntohl(t->nbuckets);
7581 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7582 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7583 rmp->active_sessions = ntohl(t->active_elements);
7584 rmp->next_table_index = ntohl(t->next_table_index);
7585 rmp->miss_next_index = ntohl(t->miss_next_index);
7586 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7587 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7596 rmp = vl_msg_api_alloc (sizeof (*rmp));
7597 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7598 rmp->context = mp->context;
7599 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7602 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7606 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7609 clib_warning ("BUG");
7613 send_classify_session_details (unix_shared_memory_queue_t * q,
7616 vnet_classify_entry_t * e, u32 context)
7618 vl_api_classify_session_details_t *rmp;
7620 rmp = vl_msg_api_alloc (sizeof (*rmp));
7621 memset (rmp, 0, sizeof (*rmp));
7622 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7623 rmp->context = context;
7624 rmp->table_id = ntohl (table_id);
7625 rmp->hit_next_index = ntohl (e->next_index);
7626 rmp->advance = ntohl (e->advance);
7627 rmp->opaque_index = ntohl (e->opaque_index);
7628 rmp->match_length = ntohl (match_length);
7629 clib_memcpy (rmp->match, e->key, match_length);
7631 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7635 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7637 vnet_classify_main_t *cm = &vnet_classify_main;
7638 unix_shared_memory_queue_t *q;
7640 u32 table_id = ntohl (mp->table_id);
7641 vnet_classify_table_t *t;
7643 q = vl_api_client_index_to_input_queue (mp->client_index);
7646 pool_foreach (t, cm->tables,
7648 if (table_id == t - cm->tables)
7650 vnet_classify_bucket_t * b;
7651 vnet_classify_entry_t * v, * save_v;
7654 for (i = 0; i < t->nbuckets; i++)
7656 b = &t->buckets [i];
7660 save_v = vnet_classify_get_entry (t, b->offset);
7661 for (j = 0; j < (1<<b->log2_pages); j++)
7663 for (k = 0; k < t->entries_per_page; k++)
7665 v = vnet_classify_entry_at_index
7666 (t, save_v, j*t->entries_per_page + k);
7667 if (vnet_classify_entry_is_free (v))
7670 send_classify_session_details
7671 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7683 vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t * mp)
7685 vlib_main_t *vm = vlib_get_main ();
7686 flow_report_main_t *frm = &flow_report_main;
7687 vl_api_ipfix_enable_reply_t *rmp;
7688 ip4_address_t collector, src;
7689 u16 collector_port = UDP_DST_PORT_ipfix;
7691 u32 template_interval;
7696 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7697 collector_port = ntohs (mp->collector_port);
7698 if (collector_port == (u16) ~ 0)
7699 collector_port = UDP_DST_PORT_ipfix;
7700 memcpy (src.data, mp->src_address, sizeof (src.data));
7701 fib_id = ntohl (mp->vrf_id);
7703 ip4_main_t *im = &ip4_main;
7704 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7707 rv = VNET_API_ERROR_NO_SUCH_FIB;
7712 path_mtu = ntohl (mp->path_mtu);
7714 path_mtu = 512; // RFC 7011 section 10.3.3.
7715 template_interval = ntohl (mp->template_interval);
7716 if (template_interval == ~0)
7717 template_interval = 20;
7719 if (collector.as_u32 == 0)
7721 rv = VNET_API_ERROR_INVALID_VALUE;
7725 if (src.as_u32 == 0)
7727 rv = VNET_API_ERROR_INVALID_VALUE;
7731 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7733 rv = VNET_API_ERROR_INVALID_VALUE;
7739 rv = VNET_API_ERROR_INVALID_VALUE;
7743 /* Reset report streams if we are reconfiguring IP addresses */
7744 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7745 frm->src_address.as_u32 != src.as_u32 ||
7746 frm->collector_port != collector_port)
7747 vnet_flow_reports_reset (frm);
7749 frm->ipfix_collector.as_u32 = collector.as_u32;
7750 frm->collector_port = collector_port;
7751 frm->src_address.as_u32 = src.as_u32;
7752 frm->fib_index = fib_index;
7753 frm->path_mtu = path_mtu;
7754 frm->template_interval = template_interval;
7756 /* Turn on the flow reporting process */
7757 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7760 REPLY_MACRO (VL_API_IPFIX_ENABLE_REPLY);
7764 vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t * mp)
7766 flow_report_main_t *frm = &flow_report_main;
7767 unix_shared_memory_queue_t *q;
7768 vl_api_ipfix_details_t *rmp;
7770 q = vl_api_client_index_to_input_queue (mp->client_index);
7772 rmp = vl_msg_api_alloc (sizeof (*rmp));
7773 memset (rmp, 0, sizeof (*rmp));
7774 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_DETAILS);
7775 rmp->context = mp->context;
7776 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7777 sizeof (frm->ipfix_collector.data));
7778 rmp->collector_port = htons (frm->collector_port);
7779 memcpy (rmp->src_address, frm->src_address.data,
7780 sizeof (frm->src_address.data));
7781 rmp->fib_index = htonl (frm->fib_index);
7782 rmp->path_mtu = htonl (frm->path_mtu);
7783 rmp->template_interval = htonl (frm->template_interval);
7785 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7789 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
7791 vl_api_pg_create_interface_reply_t *rmp;
7794 pg_main_t *pg = &pg_main;
7795 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
7798 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7800 rmp->sw_if_index = ntohl(sw_if_index);
7806 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
7808 vl_api_pg_capture_reply_t *rmp;
7811 vnet_main_t *vnm = vnet_get_main ();
7812 vnet_interface_main_t *im = &vnm->interface_main;
7813 vnet_hw_interface_t *hi = 0;
7815 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
7816 u32 hw_if_index = ~0;
7817 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
7820 vec_free (intf_name);
7822 if (hw_if_index != ~0)
7824 pg_capture_args_t _a, *a = &_a;
7826 u32 len = ntohl (mp->pcap_name_length);
7827 u8 *pcap_file_name = vec_new (u8, len);
7828 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
7830 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7831 a->hw_if_index = hw_if_index;
7832 a->dev_instance = hi->dev_instance;
7833 a->is_enabled = mp->is_enabled;
7834 a->pcap_file_name = pcap_file_name;
7835 a->count = ntohl (mp->count);
7837 clib_error_t *e = pg_capture (a);
7840 clib_error_report (e);
7841 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7844 vec_free (pcap_file_name);
7846 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
7850 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
7852 vl_api_pg_enable_disable_reply_t *rmp;
7855 pg_main_t *pg = &pg_main;
7856 u32 stream_index = ~0;
7858 int is_enable = mp->is_enabled != 0;
7859 u32 len = ntohl (mp->stream_name_length) - 1;
7863 u8 *stream_name = vec_new (u8, len);
7864 clib_memcpy (stream_name, mp->stream_name, len);
7865 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
7868 vec_free (stream_name);
7871 pg_enable_disable (stream_index, is_enable);
7873 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
7877 vl_api_ip_source_and_port_range_check_add_del_t_handler
7878 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
7880 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
7883 u8 is_ipv6 = mp->is_ipv6;
7884 u8 is_add = mp->is_add;
7885 u8 mask_length = mp->mask_length;
7886 ip4_address_t ip4_addr;
7887 ip6_address_t ip6_addr;
7889 u16 *high_ports = 0;
7891 u16 tmp_low, tmp_high;
7895 // Validate port range
7896 num_ranges = mp->number_of_ranges;
7897 if (num_ranges > 32)
7898 { // This is size of array in VPE.API
7899 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
7903 vec_reset_length (low_ports);
7904 vec_reset_length (high_ports);
7906 for (i = 0; i < num_ranges; i++)
7908 tmp_low = mp->low_ports[i];
7909 tmp_high = mp->high_ports[i];
7910 // If tmp_low <= tmp_high then only need to check tmp_low = 0
7911 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
7912 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
7914 rv = VNET_API_ERROR_INVALID_VALUE;
7917 vec_add1 (low_ports, tmp_low);
7918 vec_add1 (high_ports, tmp_high + 1);
7921 // Validate mask_length
7922 if (mask_length < 0 ||
7923 (is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
7925 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
7929 vrf_id = ntohl (mp->vrf_id);
7933 rv = VNET_API_ERROR_INVALID_VALUE;
7940 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
7941 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
7945 high_ports, is_add);
7949 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
7950 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
7954 high_ports, is_add);
7958 vec_free (low_ports);
7959 vec_free (high_ports);
7960 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
7964 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
7965 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
7967 vlib_main_t *vm = vlib_get_main ();
7968 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
7969 ip4_main_t *im = &ip4_main;
7972 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7973 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7977 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
7978 ntohl (mp->tcp_out_vrf_id);
7979 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
7980 ntohl (mp->udp_out_vrf_id);
7981 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
7982 ntohl (mp->tcp_in_vrf_id);
7983 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
7984 ntohl (mp->udp_in_vrf_id);
7987 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
7989 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
7991 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
7995 rv = VNET_API_ERROR_INVALID_VALUE;
7999 fib_index[i] = p[0];
8004 sw_if_index = ntohl (mp->sw_if_index);
8006 VALIDATE_SW_IF_INDEX (mp);
8009 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8012 BAD_SW_IF_INDEX_LABEL;
8015 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8018 #define BOUNCE_HANDLER(nn) \
8019 static void vl_api_##nn##_t_handler ( \
8020 vl_api_##nn##_t *mp) \
8022 vpe_client_registration_t *reg; \
8023 vpe_api_main_t * vam = &vpe_api_main; \
8024 unix_shared_memory_queue_t * q; \
8026 /* One registration only... */ \
8027 pool_foreach(reg, vam->nn##_registrations, \
8029 q = vl_api_client_index_to_input_queue (reg->client_index); \
8032 * If the queue is stuffed, turf the msg and complain \
8033 * It's unlikely that the intended recipient is \
8034 * alive; avoid deadlock at all costs. \
8036 if (q->cursize == q->maxsize) { \
8037 clib_warning ("ERROR: receiver queue full, drop msg"); \
8038 vl_msg_api_free (mp); \
8041 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8045 vl_msg_api_free (mp); \
8050 * Add vpe's API message handlers to the table.
8051 * vlib has alread mapped shared memory and
8052 * added the client registration handlers.
8053 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8056 static clib_error_t *
8057 vpe_api_hookup (vlib_main_t * vm)
8059 api_main_t *am = &api_main;
8062 vl_msg_api_set_handlers(VL_API_##N, #n, \
8063 vl_api_##n##_t_handler, \
8065 vl_api_##n##_t_endian, \
8066 vl_api_##n##_t_print, \
8067 sizeof(vl_api_##n##_t), 1);
8068 foreach_vpe_api_msg;
8072 * Manually register the sr tunnel add del msg, so we trace
8073 * enough bytes to capture a typical segment list
8075 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8076 "sr_tunnel_add_del",
8077 vl_api_sr_tunnel_add_del_t_handler,
8079 vl_api_sr_tunnel_add_del_t_endian,
8080 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8084 * Manually register the sr policy add del msg, so we trace
8085 * enough bytes to capture a typical tunnel name list
8087 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8088 "sr_policy_add_del",
8089 vl_api_sr_policy_add_del_t_handler,
8091 vl_api_sr_policy_add_del_t_endian,
8092 vl_api_sr_policy_add_del_t_print, 256, 1);
8095 * Trace space for 8 MPLS encap labels, classifier mask+match
8097 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8098 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8099 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8100 += 5 * sizeof (u32x4);
8101 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8104 * Thread-safe API messages
8106 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8107 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8112 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8114 static clib_error_t *
8115 vpe_api_init (vlib_main_t * vm)
8117 vpe_api_main_t *am = &vpe_api_main;
8120 am->vnet_main = vnet_get_main ();
8121 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8122 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8123 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8124 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8125 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8126 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8129 vl_set_memory_region_name ("/vpe-api");
8130 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8135 VLIB_INIT_FUNCTION (vpe_api_init);
8138 static clib_error_t *
8139 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8144 struct passwd _pw, *pw;
8145 struct group _grp, *grp;
8148 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8150 if (unformat (input, "prefix %s", &chroot_path))
8152 vec_add1 (chroot_path, 0);
8153 vl_set_memory_root_path ((char *) chroot_path);
8155 else if (unformat (input, "uid %d", &uid))
8156 vl_set_memory_uid (uid);
8157 else if (unformat (input, "gid %d", &gid))
8158 vl_set_memory_gid (gid);
8159 else if (unformat (input, "uid %s", &s))
8161 /* lookup the username */
8163 rv = getpwnam_r (s, &_pw, buf, sizeof (buf), &pw);
8166 e = clib_error_return_code (0, rv,
8167 CLIB_ERROR_ERRNO_VALID |
8169 "cannot fetch username %s", s);
8176 clib_error_return_fatal (0, "username %s does not exist", s);
8181 vl_set_memory_uid (pw->pw_uid);
8183 else if (unformat (input, "gid %s", &s))
8185 /* lookup the group name */
8187 rv = getgrnam_r (s, &_grp, buf, sizeof (buf), &grp);
8190 e = clib_error_return_code (0, rv,
8191 CLIB_ERROR_ERRNO_VALID |
8193 "cannot fetch group %s", s);
8199 e = clib_error_return_fatal (0, "group %s does not exist", s);
8204 vl_set_memory_gid (grp->gr_gid);
8207 return clib_error_return (0, "unknown input `%U'",
8208 format_unformat_error, input);
8213 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8216 get_unformat_vnet_sw_interface (void)
8218 return (void *) &unformat_vnet_sw_interface;
8221 #undef vl_api_version
8222 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8223 #include <vpp-api/vpe.api.h>
8224 #undef vl_api_version
8227 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8229 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8231 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8232 clib_host_to_net_u32 (mp->api_versions[0]),
8240 format_arp_event (u8 * s, va_list * args)
8242 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8244 s = format (s, "pid %d: %U", event->pid,
8245 format_ip4_address, &event->address);
8249 static clib_error_t *
8250 show_ip4_arp_events_fn (vlib_main_t * vm,
8251 unformat_input_t * input, vlib_cli_command_t * cmd)
8253 vpe_api_main_t *am = &vpe_api_main;
8254 vl_api_ip4_arp_event_t *event;
8256 if (pool_elts (am->arp_events) == 0)
8258 vlib_cli_output (vm, "No active arp event registrations");
8263 pool_foreach (event, am->arp_events,
8265 vlib_cli_output (vm, "%U", format_arp_event, event);
8273 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
8274 .path = "show arp event registrations",
8275 .function = show_ip4_arp_events_fn,
8276 .short_help = "Show arp event registrations",
8281 * fd.io coding-style-patch-verification: ON
8284 * eval: (c-set-style "gnu")