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>
33 #include <vppinfra/clib.h>
34 #include <vppinfra/vec.h>
35 #include <vppinfra/hash.h>
36 #include <vppinfra/bitmap.h>
37 #include <vppinfra/fifo.h>
38 #include <vppinfra/time.h>
39 #include <vppinfra/mheap.h>
40 #include <vppinfra/heap.h>
41 #include <vppinfra/pool.h>
42 #include <vppinfra/format.h>
43 #include <vppinfra/error.h>
45 #include <vnet/api_errno.h> // alagalah TODO : committers please pay note, is this ok?
46 #include <vnet/vnet.h>
47 #include <vnet/l2/l2_input.h>
48 #include <vnet/l2/l2_bd.h>
49 #include <vnet/l2tp/l2tp.h>
50 #include <vnet/ip/ip.h>
51 #include <vnet/unix/tuntap.h>
52 #include <vnet/unix/tapcli.h>
53 #include <vnet/mpls-gre/mpls.h>
54 #include <vnet/dhcp/proxy.h>
55 #include <vnet/dhcp/client.h>
57 #include <vnet/sr/sr.h>
59 #include <vnet/dhcpv6/proxy.h>
60 #include <vlib/vlib.h>
61 #include <vlib/unix/unix.h>
62 #include <vlibapi/api.h>
63 #include <vlibmemory/api.h>
64 #include <vnet/classify/vnet_classify.h>
65 #include <vnet/classify/input_acl.h>
66 #include <vnet/l2/l2_classify.h>
67 #include <vnet/vxlan/vxlan.h>
68 #include <vnet/gre/gre.h>
69 #include <vnet/l2/l2_vtr.h>
70 #include <vnet/vxlan-gpe/vxlan_gpe.h>
71 #include <vnet/lisp-gpe/lisp_gpe.h>
72 #include <vnet/lisp-cp/control.h>
73 #include <vnet/map/map.h>
74 #include <vnet/cop/cop.h>
75 #include <vnet/ip/ip6_hop_by_hop.h>
76 #include <vnet/devices/af_packet/af_packet.h>
77 #include <vnet/policer/policer.h>
78 #include <vnet/devices/netmap/netmap.h>
81 #undef __included_bihash_template_h__
82 #include <vnet/l2/l2_fib.h>
85 #include <vnet/ipsec/ipsec.h>
86 #include <vnet/ipsec/ikev2.h>
89 #include <vnet/devices/virtio/vhost-user.h>
92 #include <stats/stats.h>
95 #include <vnet/ethernet/ethernet.h>
96 #include <vnet/ethernet/arp_packet.h>
97 #include <vnet/interface.h>
99 #include <vnet/l2/l2_fib.h>
100 #include <vnet/l2/l2_bd.h>
101 #include <api/vpe_msg_enum.h>
103 #define f64_endian(a)
104 #define f64_print(a,b)
106 #define vl_typedefs /* define message structures */
107 #include <api/vpe_all_api_h.h>
110 #define vl_endianfun /* define message structures */
111 #include <api/vpe_all_api_h.h>
114 /* instantiate all the print functions we know about */
115 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
117 #include <api/vpe_all_api_h.h>
120 #define REPLY_MACRO(t) \
122 unix_shared_memory_queue_t * q; \
123 rv = vl_msg_api_pd_handler (mp, rv); \
124 q = vl_api_client_index_to_input_queue (mp->client_index); \
128 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
129 rmp->_vl_msg_id = ntohs((t)); \
130 rmp->context = mp->context; \
131 rmp->retval = ntohl(rv); \
133 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
136 #define REPLY_MACRO2(t, body) \
138 unix_shared_memory_queue_t * q; \
139 rv = vl_msg_api_pd_handler (mp, rv); \
140 q = vl_api_client_index_to_input_queue (mp->client_index); \
144 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
145 rmp->_vl_msg_id = ntohs((t)); \
146 rmp->context = mp->context; \
147 rmp->retval = ntohl(rv); \
148 do {body;} while (0); \
149 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
152 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
154 #define VALIDATE_SW_IF_INDEX(mp) \
155 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
156 vnet_main_t *__vnm = vnet_get_main(); \
157 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
159 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
160 goto bad_sw_if_index; \
164 #define BAD_SW_IF_INDEX_LABEL \
170 #define VALIDATE_RX_SW_IF_INDEX(mp) \
171 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
172 vnet_main_t *__vnm = vnet_get_main(); \
173 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
174 __rx_sw_if_index)) { \
175 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
176 goto bad_rx_sw_if_index; \
180 #define BAD_RX_SW_IF_INDEX_LABEL \
182 bad_rx_sw_if_index: \
186 #define VALIDATE_TX_SW_IF_INDEX(mp) \
187 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
188 vnet_main_t *__vnm = vnet_get_main(); \
189 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
190 __tx_sw_if_index)) { \
191 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
192 goto bad_tx_sw_if_index; \
196 #define BAD_TX_SW_IF_INDEX_LABEL \
198 bad_tx_sw_if_index: \
204 #define VALIDATE_SW_IF_INDEX(mp)
205 #define BAD_SW_IF_INDEX_LABEL
206 #define VALIDATE_RX_SW_IF_INDEX(mp)
207 #define BAD_RX_SW_IF_INDEX_LABEL
208 #define VALIDATE_TX_SW_IF_INDEX(mp)
209 #define BAD_TX_SW_IF_INDEX_LABEL
211 #endif /* CLIB_DEBUG > 0 */
213 #define foreach_vpe_api_msg \
214 _(WANT_INTERFACE_EVENTS, want_interface_events) \
215 _(WANT_OAM_EVENTS, want_oam_events) \
216 _(OAM_ADD_DEL, oam_add_del) \
217 _(SW_INTERFACE_DUMP, sw_interface_dump) \
218 _(SW_INTERFACE_DETAILS, sw_interface_details) \
219 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
220 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
221 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
222 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
223 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
224 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
225 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
226 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
227 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
228 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
229 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
230 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
231 _(L2FIB_ADD_DEL, l2fib_add_del) \
232 _(L2_FLAGS, l2_flags) \
233 _(BRIDGE_FLAGS, bridge_flags) \
234 _(TAP_CONNECT, tap_connect) \
235 _(TAP_MODIFY, tap_modify) \
236 _(TAP_DELETE, tap_delete) \
237 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
238 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
239 _(CREATE_SUBIF, create_subif) \
240 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
241 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
242 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
243 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
244 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
245 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
246 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
247 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
248 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
249 _(RESET_FIB, reset_fib) \
250 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
251 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
252 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
253 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
254 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
255 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
256 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
257 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
258 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
259 sw_interface_ip6_set_link_local_address) \
260 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
261 _(CREATE_LOOPBACK, create_loopback) \
262 _(CONTROL_PING, control_ping) \
263 _(CLI_REQUEST, cli_request) \
264 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
265 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
266 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
267 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
268 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
269 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
270 _(GET_NODE_INDEX, get_node_index) \
271 _(ADD_NODE_NEXT, add_node_next) \
272 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
273 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
274 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
275 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
276 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
277 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
278 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
279 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
280 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
281 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
282 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
283 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
284 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
285 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
286 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
287 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
288 _(IP_ADDRESS_DUMP, ip_address_dump) \
289 _(IP_DUMP, ip_dump) \
290 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
291 _(SHOW_VERSION, show_version) \
292 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
293 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
294 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
295 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
296 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
297 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
298 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
299 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
300 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
301 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
302 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
303 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
304 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
305 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
306 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
307 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
308 _(DELETE_LOOPBACK, delete_loopback) \
309 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
310 _(MAP_ADD_DOMAIN, map_add_domain) \
311 _(MAP_DEL_DOMAIN, map_del_domain) \
312 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
313 _(MAP_DOMAIN_DUMP, map_domain_dump) \
314 _(MAP_RULE_DUMP, map_rule_dump) \
315 _(MAP_SUMMARY_STATS, map_summary_stats) \
316 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
317 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
318 _(GET_NODE_GRAPH, get_node_graph) \
319 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
320 _(TRACE_PROFILE_ADD, trace_profile_add) \
321 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
322 _(TRACE_PROFILE_DEL, trace_profile_del) \
323 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
324 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
325 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
326 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
327 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
328 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
329 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
330 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
331 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
332 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
333 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
334 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
335 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
336 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
337 lisp_enable_disable_status_dump) \
338 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
339 _(AF_PACKET_CREATE, af_packet_create) \
340 _(AF_PACKET_DELETE, af_packet_delete) \
341 _(POLICER_ADD_DEL, policer_add_del) \
342 _(POLICER_DUMP, policer_dump) \
343 _(NETMAP_CREATE, netmap_create) \
344 _(NETMAP_DELETE, netmap_delete)
347 #define QUOTE(x) QUOTE_(x)
349 #define foreach_registration_hash \
350 _(interface_events) \
351 _(to_netconf_server) \
352 _(from_netconf_server) \
353 _(to_netconf_client) \
354 _(from_netconf_client) \
358 RESOLVE_IP4_ADD_DEL_ROUTE=1,
359 RESOLVE_IP6_ADD_DEL_ROUTE,
360 RESOLVE_MPLS_ETHERNET_ADD_DEL,
366 vl_api_ip_add_del_route_t r;
367 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
373 #define _(a) uword *a##_registration_hash; \
374 vpe_client_registration_t * a##_registrations;
375 foreach_registration_hash
378 /* notifications happen really early in the game */
379 u8 link_state_process_up;
381 /* ip4 pending route adds */
382 pending_route_t * pending_routes;
384 /* ip4 arp event registration pool */
385 vl_api_ip4_arp_event_t * arp_events;
388 vlib_main_t * vlib_main;
389 vnet_main_t * vnet_main;
392 static vlib_node_registration_t vpe_resolver_process_node;
393 static vpe_api_main_t vpe_api_main;
395 static void send_sw_interface_flags (vpe_api_main_t * am,
396 unix_shared_memory_queue_t *q,
397 vnet_sw_interface_t * swif);
398 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
399 unix_shared_memory_queue_t *q,
402 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
405 /* Clean up all registrations belonging to the indicated client */
406 int vl_api_memclnt_delete_callback (u32 client_index)
408 vpe_api_main_t * vam = &vpe_api_main;
409 vpe_client_registration_t *rp;
411 int stats_memclnt_delete_callback (u32 client_index);
413 stats_memclnt_delete_callback (client_index);
416 p = hash_get (vam->a##_registration_hash, client_index); \
418 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
419 pool_put (vam->a##_registrations, rp); \
420 hash_unset (vam->a##_registration_hash, client_index); \
422 foreach_registration_hash;
427 #define API_LINK_STATE_EVENT 1
428 #define API_ADMIN_UP_DOWN_EVENT 2
431 event_data_cmp (void * a1, void * a2)
436 return (word) e1[0] - (word) e2[0];
440 link_state_process (vlib_main_t * vm,
441 vlib_node_runtime_t * rt,
444 vpe_api_main_t * vam = &vpe_api_main;
445 vnet_main_t * vnm = vam->vnet_main;
446 vnet_sw_interface_t * swif;
447 uword * event_data = 0;
448 vpe_client_registration_t *reg;
450 u32 prev_sw_if_index;
451 unix_shared_memory_queue_t * q;
453 vam->link_state_process_up = 1;
456 vlib_process_wait_for_event (vm);
458 /* Unified list of changed link or admin state sw_if_indices */
459 vlib_process_get_events_with_type
460 (vm, &event_data, API_LINK_STATE_EVENT);
461 vlib_process_get_events_with_type
462 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
464 /* Sort, so we can eliminate duplicates */
465 vec_sort_with_function (event_data, event_data_cmp);
467 prev_sw_if_index = ~0;
469 for (i = 0; i < vec_len(event_data); i++) {
470 /* Only one message per swif */
471 if (prev_sw_if_index == event_data[i])
473 prev_sw_if_index = event_data[i];
475 pool_foreach(reg, vam->interface_events_registrations,
477 q = vl_api_client_index_to_input_queue (reg->client_index);
479 // sw_interface may be deleted already
480 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
483 swif = vnet_get_sw_interface (vnm, event_data[i]);
484 send_sw_interface_flags (vam, q, swif);
489 vec_reset_length (event_data);
495 static clib_error_t *
496 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
497 static clib_error_t *
498 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
500 VLIB_REGISTER_NODE (link_state_process_node,static) = {
501 .function = link_state_process,
502 .type = VLIB_NODE_TYPE_PROCESS,
503 .name = "vpe-link-state-process",
506 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
507 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
509 static clib_error_t *
510 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
512 vpe_api_main_t * vam = &vpe_api_main;
513 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
515 if (vam->link_state_process_up)
516 vlib_process_signal_event (vam->vlib_main,
517 link_state_process_node.index,
518 API_LINK_STATE_EVENT,
523 static clib_error_t *
524 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
526 vpe_api_main_t * vam = &vpe_api_main;
529 * Note: it's perfectly fair to set a subif admin up / admin down.
530 * Note the subtle distinction between this routine and the previous
533 if (vam->link_state_process_up)
534 vlib_process_signal_event (vam->vlib_main,
535 link_state_process_node.index,
536 API_ADMIN_UP_DOWN_EVENT,
541 #define pub_sub_handler(lca,UCA) \
542 static void vl_api_want_##lca##_t_handler ( \
543 vl_api_want_##lca##_t *mp) \
545 vpe_api_main_t *vam = &vpe_api_main; \
546 vpe_client_registration_t *rp; \
547 vl_api_want_##lca##_reply_t *rmp; \
551 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
553 if (mp->enable_disable) { \
554 clib_warning ("pid %d: already enabled...", mp->pid); \
555 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
558 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
559 pool_put (vam->lca##_registrations, rp); \
560 hash_unset (vam->lca##_registration_hash, \
565 if (mp->enable_disable == 0) { \
566 clib_warning ("pid %d: already disabled...", mp->pid); \
567 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
570 pool_get (vam->lca##_registrations, rp); \
571 rp->client_index = mp->client_index; \
572 rp->client_pid = mp->pid; \
573 hash_set (vam->lca##_registration_hash, rp->client_index, \
574 rp - vam->lca##_registrations); \
577 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
580 pub_sub_handler (interface_events,INTERFACE_EVENTS)
581 pub_sub_handler (oam_events,OAM_EVENTS)
583 #define RESOLUTION_EVENT 1
584 #define RESOLUTION_PENDING_EVENT 2
585 #define IP4_ARP_EVENT 3
587 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
588 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
589 static int mpls_ethernet_add_del_tunnel_2_t_handler
590 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
592 void handle_ip4_arp_event (u32 pool_index)
594 vpe_api_main_t * vam = &vpe_api_main;
595 vnet_main_t * vnm = vam->vnet_main;
596 vlib_main_t * vm = vam->vlib_main;
597 vl_api_ip4_arp_event_t * event;
598 vl_api_ip4_arp_event_t * mp;
599 unix_shared_memory_queue_t * q;
601 /* Client can cancel, die, etc. */
602 if (pool_is_free_index (vam->arp_events, pool_index))
605 event = pool_elt_at_index (vam->arp_events, pool_index);
607 q = vl_api_client_index_to_input_queue (event->client_index);
609 (void) vnet_add_del_ip4_arp_change_event
610 (vnm, arp_change_delete_callback,
611 event->pid, &event->address,
612 vpe_resolver_process_node.index, IP4_ARP_EVENT,
613 ~0 /* pool index, notused */, 0 /* is_add */);
617 if (q->cursize < q->maxsize) {
618 mp = vl_msg_api_alloc (sizeof (*mp));
619 clib_memcpy (mp, event, sizeof (*mp));
620 vl_msg_api_send_shmem (q, (u8 *)&mp);
622 static f64 last_time;
624 * Throttle syslog msgs.
625 * It's pretty tempting to just revoke the registration...
627 if (vlib_time_now (vm) > last_time + 10.0) {
628 clib_warning ("arp event for %U to pid %d: queue stuffed!",
629 format_ip4_address, &event->address, event->pid);
630 last_time = vlib_time_now(vm);
636 resolver_process (vlib_main_t * vm,
637 vlib_node_runtime_t * rt,
641 uword *event_data = 0;
643 vpe_api_main_t * vam = &vpe_api_main;
644 pending_route_t * pr;
645 vl_api_ip_add_del_route_t * adr;
646 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
647 u32 * resolution_failures = 0;
652 vlib_process_wait_for_event_or_clock (vm, timeout);
654 event_type = vlib_process_get_events (vm, &event_data);
656 switch (event_type) {
657 case RESOLUTION_PENDING_EVENT:
661 case RESOLUTION_EVENT:
662 for (i = 0; i < vec_len(event_data); i++) {
664 * Resolution events can occur long after the
665 * original request has timed out. $$$ add a cancel
668 if (pool_is_free_index (vam->pending_routes, event_data[i]))
671 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
675 switch (pr->resolve_type) {
676 case RESOLVE_IP4_ADD_DEL_ROUTE:
677 rv = ip4_add_del_route_t_handler (adr);
678 clib_warning ("resolver: add %U/%d via %U %s",
680 (ip4_address_t *)&(adr->dst_address),
681 adr->dst_address_length,
683 (ip4_address_t *)&(adr->next_hop_address),
684 (rv >= 0) ? "succeeded" : "failed");
687 case RESOLVE_IP6_ADD_DEL_ROUTE:
688 rv = ip6_add_del_route_t_handler (adr);
689 clib_warning ("resolver: add %U/%d via %U %s",
691 (ip6_address_t *)&(adr->dst_address),
692 adr->dst_address_length,
694 (ip6_address_t *)&(adr->next_hop_address),
695 (rv >= 0) ? "succeeded" : "failed");
698 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
699 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
700 clib_warning ("resolver: add mpls-o-e via %U %s",
702 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
703 (rv >= 0) ? "succeeded" : "failed");
707 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
709 pool_put (vam->pending_routes, pr);
714 for (i = 0; i < vec_len(event_data); i++)
715 handle_ip4_arp_event (event_data[i]);
718 case ~0: /* timeout, retry pending resolutions */
719 pool_foreach (pr, vam->pending_routes,
725 /* May fail, e.g. due to interface down */
726 switch (pr->resolve_type) {
727 case RESOLVE_IP4_ADD_DEL_ROUTE:
728 e = ip4_probe_neighbor
729 (vm, (ip4_address_t *)&(adr->next_hop_address),
730 ntohl(adr->next_hop_sw_if_index));
733 case RESOLVE_IP6_ADD_DEL_ROUTE:
734 e = ip6_probe_neighbor
735 (vm, (ip6_address_t *)&(adr->next_hop_address),
736 ntohl(adr->next_hop_sw_if_index));
739 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
741 e = ip4_probe_neighbor
743 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
744 pme->resolve_opaque);
748 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
752 clib_error_report (e);
754 adr->resolve_attempts = 1;
756 pme->resolve_attempts = 1;
760 adr->resolve_attempts -= 1;
761 if (adr->resolve_attempts == 0)
762 vec_add1 (resolution_failures,
763 pr - vam->pending_routes);
765 pme->resolve_attempts -= 1;
766 if (pme->resolve_attempts == 0)
767 vec_add1 (resolution_failures,
768 pr - vam->pending_routes);
772 for (i = 0; i < vec_len (resolution_failures); i++) {
773 pr = pool_elt_at_index (vam->pending_routes,
774 resolution_failures[i]);
778 switch (pr->resolve_type) {
779 case RESOLVE_IP4_ADD_DEL_ROUTE:
780 clib_warning ("resolver: add %U/%d via %U retry failure",
782 (ip4_address_t *)&(adr->dst_address),
783 adr->dst_address_length,
785 (ip4_address_t *)&(adr->next_hop_address));
788 case RESOLVE_IP6_ADD_DEL_ROUTE:
789 clib_warning ("resolver: add %U/%d via %U retry failure",
791 (ip6_address_t *)&(adr->dst_address),
792 adr->dst_address_length,
794 (ip6_address_t *)&(adr->next_hop_address));
797 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
798 clib_warning ("resolver: add mpls-o-e via %U retry failure",
800 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
804 clib_warning ("BUG");
806 pool_put(vam->pending_routes, pr);
808 vec_reset_length (resolution_failures);
811 if (pool_elts (vam->pending_routes) == 0)
813 vec_reset_length (event_data);
815 return 0; /* or not */
818 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
819 .function = resolver_process,
820 .type = VLIB_NODE_TYPE_PROCESS,
821 .name = "vpe-route-resolver-process",
824 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
826 ip4_main_t * im = &ip4_main;
827 ip_lookup_main_t * lm = &im->lookup_main;
828 vnet_classify_main_t * cm = &vnet_classify_main;
829 stats_main_t * sm = &stats_main;
830 ip4_add_del_route_args_t a;
831 ip4_address_t next_hop_address;
833 vpe_api_main_t * vam = &vpe_api_main;
834 vnet_main_t * vnm = vam->vnet_main;
835 vlib_main_t * vm = vlib_get_main();
836 pending_route_t * pr;
837 vl_api_ip_add_del_route_t * adr;
841 ip_adjacency_t *nh_adj, *add_adj = 0;
843 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
845 if (mp->create_vrf_if_needed) {
847 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
849 fib_index = f->index;
851 /* No such VRF, and we weren't asked to create one */
852 return VNET_API_ERROR_NO_SUCH_FIB;
858 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
859 ntohl(mp->next_hop_sw_if_index)))
860 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
862 clib_memcpy (next_hop_address.data, mp->next_hop_address,
863 sizeof (next_hop_address.data));
865 /* Arp for the next_hop if necessary */
866 if (mp->is_add && mp->resolve_if_needed) {
868 ip_adjacency_t * adj;
870 lookup_result = ip4_fib_lookup_with_table
871 (im, fib_index, &next_hop_address, 1 /* disable default route */);
873 adj = ip_get_adjacency (lm, lookup_result);
875 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
876 pool_get (vam->pending_routes, pr);
877 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
879 clib_memcpy (adr, mp, sizeof (*adr));
880 /* recursion block, "just in case" */
881 adr->resolve_if_needed = 0;
882 adr->resolve_attempts = ntohl(mp->resolve_attempts);
883 vnet_register_ip4_arp_resolution_event
884 (vnm, &next_hop_address, vpe_resolver_process_node.index,
885 RESOLUTION_EVENT, pr - vam->pending_routes);
887 vlib_process_signal_event
888 (vm, vpe_resolver_process_node.index,
889 RESOLUTION_PENDING_EVENT, 0 /* data */);
891 /* The interface may be down, etc. */
892 e = ip4_probe_neighbor
893 (vm, (ip4_address_t *)&(mp->next_hop_address),
894 ntohl(mp->next_hop_sw_if_index));
897 clib_error_report(e);
899 return VNET_API_ERROR_IN_PROGRESS;
903 if (mp->is_multipath) {
906 dslock (sm, 1 /* release hint */, 10 /* tag */);
909 flags = IP4_ROUTE_FLAG_ADD;
911 flags = IP4_ROUTE_FLAG_DEL;
914 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
916 ip4_add_del_route_next_hop (im, flags,
917 (ip4_address_t *) mp->dst_address,
918 (u32) mp->dst_address_length,
919 (ip4_address_t *) mp->next_hop_address,
920 ntohl(mp->next_hop_sw_if_index),
921 (u32) mp->next_hop_weight,
928 memset (&a, 0, sizeof (a));
929 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
931 a.dst_address_length = mp->dst_address_length;
933 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
934 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
935 a.table_index_or_table_id = fib_index;
940 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
942 dslock (sm, 1 /* release hint */, 2 /* tag */);
946 ai = lm->drop_adj_index;
947 else if (mp->is_local)
948 ai = lm->local_adj_index;
949 else if (mp->is_classify) {
951 memset(&cadj, 0, sizeof(cadj));
952 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
953 cadj.classify.table_index = ntohl(mp->classify_table_index);
954 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
956 return VNET_API_ERROR_NO_SUCH_TABLE;
958 vec_add1 (add_adj, cadj);
962 ai = ip4_fib_lookup_with_table
963 (im, fib_index, &next_hop_address,
964 1 /* disable default route */);
965 if (ai == lm->miss_adj_index) {
967 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
971 nh_adj = ip_get_adjacency (lm, ai);
972 vec_add1 (add_adj, nh_adj[0]);
973 if (mp->lookup_in_vrf) {
974 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
976 add_adj[0].explicit_fib_index = p[0];
980 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
984 ip_adjacency_t * adj;
985 int disable_default_route = 1;
987 /* Trying to delete the default route? */
988 if (a.dst_address.as_u32 == 0 &&
989 a.dst_address_length == 0)
990 disable_default_route = 0;
992 ai = ip4_fib_lookup_with_table
993 (im, fib_index, &a.dst_address, disable_default_route);
994 if (ai == lm->miss_adj_index) {
996 return VNET_API_ERROR_UNKNOWN_DESTINATION;
999 adj = ip_get_adjacency (lm, ai);
1000 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1002 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1008 a.add_adj = add_adj;
1009 a.n_add_adj = vec_len(add_adj);
1010 ip4_add_del_route (im, &a);
1018 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1020 ip6_main_t * im = &ip6_main;
1021 ip_lookup_main_t * lm = &im->lookup_main;
1022 vnet_main_t * vnm = vnet_get_main();
1023 vlib_main_t * vm = vlib_get_main();
1024 vpe_api_main_t * vam = &vpe_api_main;
1025 stats_main_t * sm = &stats_main;
1026 ip6_add_del_route_args_t a;
1027 ip6_address_t next_hop_address;
1028 pending_route_t * pr;
1029 vl_api_ip_add_del_route_t * adr;
1034 ip_adjacency_t * nh_adj, * add_adj = 0;
1037 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1040 if (mp->create_vrf_if_needed) {
1042 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1044 fib_index = f->index;
1046 /* No such VRF, and we weren't asked to create one */
1047 return VNET_API_ERROR_NO_SUCH_FIB;
1053 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1054 ntohl(mp->next_hop_sw_if_index)))
1055 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1057 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1058 sizeof (next_hop_address.as_u8));
1060 /* Arp for the next_hop if necessary */
1061 if (mp->is_add && mp->resolve_if_needed) {
1063 ip_adjacency_t * adj;
1065 lookup_result = ip6_fib_lookup_with_table
1066 (im, fib_index, &next_hop_address);
1068 adj = ip_get_adjacency (lm, lookup_result);
1070 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1071 pool_get (vam->pending_routes, pr);
1073 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1074 clib_memcpy (adr, mp, sizeof (*adr));
1075 /* recursion block, "just in case" */
1076 adr->resolve_if_needed = 0;
1077 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1078 vnet_register_ip6_neighbor_resolution_event
1079 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1080 RESOLUTION_EVENT, pr - vam->pending_routes);
1082 vlib_process_signal_event
1083 (vm, vpe_resolver_process_node.index,
1084 RESOLUTION_PENDING_EVENT, 0 /* data */);
1086 /* The interface may be down, etc. */
1087 e = ip6_probe_neighbor
1088 (vm, (ip6_address_t *)&(mp->next_hop_address),
1089 ntohl(mp->next_hop_sw_if_index));
1092 clib_error_report(e);
1094 return VNET_API_ERROR_IN_PROGRESS;
1098 if (mp->is_multipath) {
1101 dslock (sm, 1 /* release hint */, 11 /* tag */);
1104 flags = IP6_ROUTE_FLAG_ADD;
1106 flags = IP6_ROUTE_FLAG_DEL;
1109 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1111 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1112 (u32) mp->dst_address_length,
1113 (ip6_address_t *)mp->next_hop_address,
1114 ntohl(mp->next_hop_sw_if_index),
1115 (u32) mp->next_hop_weight,
1122 memset (&a, 0, sizeof (a));
1123 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1125 a.dst_address_length = mp->dst_address_length;
1127 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1128 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1129 a.table_index_or_table_id = fib_index;
1134 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1136 dslock (sm, 1 /* release hint */, 3 /* tag */);
1140 ai = lm->drop_adj_index;
1141 else if (mp->is_local)
1142 ai = lm->local_adj_index;
1144 ai = ip6_fib_lookup_with_table
1145 (im, fib_index, &next_hop_address);
1146 if (ai == lm->miss_adj_index) {
1148 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1152 nh_adj = ip_get_adjacency (lm, ai);
1153 vec_add1 (add_adj, nh_adj[0]);
1154 if (mp->lookup_in_vrf) {
1155 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1157 add_adj[0].explicit_fib_index = p[0];
1161 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1165 ip_adjacency_t * adj;
1167 ai = ip6_fib_lookup_with_table
1168 (im, fib_index, &a.dst_address);
1169 if (ai == lm->miss_adj_index) {
1171 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1173 adj = ip_get_adjacency (lm, ai);
1174 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1176 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1181 a.add_adj = add_adj;
1182 a.n_add_adj = vec_len(add_adj);
1183 ip6_add_del_route (im, &a);
1191 void vl_api_ip_add_del_route_t_handler (
1192 vl_api_ip_add_del_route_t *mp)
1194 vl_api_ip_add_del_route_reply_t * rmp;
1196 vnet_main_t * vnm = vnet_get_main();
1201 rv = ip6_add_del_route_t_handler (mp);
1203 rv = ip4_add_del_route_t_handler (mp);
1205 rv = (rv == 0) ? vnm->api_errno : rv;
1207 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1210 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1211 u32 sw_if_index, u8 *next_hop_addr)
1213 vl_api_ip_add_del_route_t mp;
1216 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1219 * Configure default IP route:
1220 * - ip route add 0.0.0.0/1 via <GW IP>
1221 * - ip route add 128.0.0.0/1 via <GW IP>
1223 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1225 mp.resolve_attempts = ~0;
1226 mp.resolve_if_needed = 1;
1228 mp.is_ipv6 = is_ipv6;
1229 mp.next_hop_weight = 1;
1231 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1234 rv = ip6_add_del_route_t_handler (&mp);
1237 mp.dst_address_length = 1;
1239 mp.dst_address[0] = 0;
1240 rv = ip4_add_del_route_t_handler (&mp);
1242 mp.dst_address[0] = 128;
1243 rv |= ip4_add_del_route_t_handler (&mp);
1247 clib_error_return (0, "failed to config default IP route");
1252 vl_api_sw_interface_add_del_address_t_handler
1253 (vl_api_sw_interface_add_del_address_t *mp)
1255 vlib_main_t *vm = vlib_get_main();
1256 vl_api_sw_interface_add_del_address_reply_t * rmp;
1260 VALIDATE_SW_IF_INDEX(mp);
1262 is_del = mp->is_add == 0;
1265 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1266 else if (mp->is_ipv6)
1267 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1268 (void *)mp->address,
1269 mp->address_length, is_del);
1271 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1272 (void *) mp->address,
1273 mp->address_length, is_del);
1275 BAD_SW_IF_INDEX_LABEL;
1277 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1281 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1284 u32 table_id = ntohl(mp->vrf_id);
1285 u32 sw_if_index = ntohl(mp->sw_if_index);
1286 vl_api_sw_interface_set_table_reply_t * rmp;
1287 stats_main_t * sm = &stats_main;
1289 VALIDATE_SW_IF_INDEX(mp);
1291 dslock (sm, 1 /* release hint */, 4 /* tag */);
1294 ip6_main_t * im = &ip6_main;
1296 find_ip6_fib_by_table_index_or_id (im, table_id,
1297 IP6_ROUTE_FLAG_TABLE_ID);
1299 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1300 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1302 rv = VNET_API_ERROR_NO_SUCH_FIB;
1305 ip4_main_t * im = &ip4_main;
1306 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1307 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1309 /* Truthfully this can't fail */
1311 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1312 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1314 rv = VNET_API_ERROR_NO_SUCH_FIB;
1319 BAD_SW_IF_INDEX_LABEL;
1321 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1325 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1327 vlib_main_t *vm = vlib_get_main();
1328 vl_api_sw_interface_set_vpath_reply_t * rmp;
1331 u32 sw_if_index = ntohl(mp->sw_if_index);
1332 ip4_main_t *ip4m = &ip4_main;
1333 ip6_main_t *ip6m = &ip6_main;
1334 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1335 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1336 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1337 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1338 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1339 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1341 VALIDATE_SW_IF_INDEX(mp);
1343 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1345 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1346 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1347 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1348 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1349 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1350 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1351 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1352 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1353 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1354 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1355 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1356 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1357 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1358 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1359 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1360 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1362 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1363 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1364 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1365 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1366 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1367 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1368 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1369 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1370 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1371 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1372 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1373 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1374 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1375 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1376 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1377 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1380 BAD_SW_IF_INDEX_LABEL;
1382 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1386 vl_api_sw_interface_set_l2_xconnect_t_handler (
1387 vl_api_sw_interface_set_l2_xconnect_t *mp)
1389 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1391 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1392 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1393 vlib_main_t *vm = vlib_get_main();
1394 vnet_main_t *vnm = vnet_get_main();
1396 VALIDATE_RX_SW_IF_INDEX(mp);
1399 VALIDATE_TX_SW_IF_INDEX(mp);
1400 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1401 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1403 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1406 BAD_RX_SW_IF_INDEX_LABEL;
1407 BAD_TX_SW_IF_INDEX_LABEL;
1409 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1413 vl_api_sw_interface_set_l2_bridge_t_handler (
1414 vl_api_sw_interface_set_l2_bridge_t *mp)
1416 bd_main_t * bdm = &bd_main;
1417 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1419 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1420 u32 bd_id = ntohl(mp->bd_id);
1424 vlib_main_t *vm = vlib_get_main();
1425 vnet_main_t *vnm = vnet_get_main();
1427 VALIDATE_RX_SW_IF_INDEX(mp);
1429 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1432 //VALIDATE_TX_SW_IF_INDEX(mp);
1433 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1434 rx_sw_if_index, bd_index, bvi, shg, 0);
1436 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1439 BAD_RX_SW_IF_INDEX_LABEL;
1441 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1445 vl_api_bridge_domain_add_del_t_handler (
1446 vl_api_bridge_domain_add_del_t *mp)
1448 vlib_main_t * vm = vlib_get_main ();
1449 bd_main_t * bdm = &bd_main;
1450 vl_api_bridge_domain_add_del_reply_t * rmp;
1452 u32 enable_flags = 0, disable_flags = 0;
1453 u32 bd_id = ntohl(mp->bd_id);
1457 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1460 enable_flags |= L2_FLOOD;
1462 disable_flags |= L2_FLOOD;
1465 enable_flags |= L2_UU_FLOOD;
1467 disable_flags |= L2_UU_FLOOD;
1470 enable_flags |= L2_FWD;
1472 disable_flags |= L2_FWD;
1475 enable_flags |= L2_ARP_TERM;
1477 disable_flags |= L2_ARP_TERM;
1480 enable_flags |= L2_LEARN;
1482 disable_flags |= L2_LEARN;
1485 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1488 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1491 rv = bd_delete_bd_index(bdm, bd_id);
1493 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1496 static void vl_api_bridge_domain_details_t_handler (
1497 vl_api_bridge_domain_details_t * mp)
1499 clib_warning ("BUG");
1502 static void vl_api_bridge_domain_sw_if_details_t_handler (
1503 vl_api_bridge_domain_sw_if_details_t * mp)
1505 clib_warning ("BUG");
1508 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1509 l2_bridge_domain_t * bd_config,
1513 vl_api_bridge_domain_details_t * mp;
1515 mp = vl_msg_api_alloc (sizeof (*mp));
1516 memset (mp, 0, sizeof (*mp));
1517 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1518 mp->bd_id = ntohl (bd_config->bd_id);
1519 mp->flood = bd_feature_flood (bd_config);
1520 mp->uu_flood = bd_feature_uu_flood (bd_config);
1521 mp->forward = bd_feature_forward (bd_config);
1522 mp->learn = bd_feature_learn (bd_config);
1523 mp->arp_term = bd_feature_arp_term (bd_config);
1524 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1525 mp->n_sw_ifs = ntohl (n_sw_ifs);
1526 mp->context = context;
1528 vl_msg_api_send_shmem (q, (u8 *)&mp);
1531 static void send_bd_sw_if_details (l2input_main_t * l2im,
1532 unix_shared_memory_queue_t *q,
1533 l2_flood_member_t * member, u32 bd_id,
1536 vl_api_bridge_domain_sw_if_details_t * mp;
1537 l2_input_config_t * input_cfg;
1539 mp = vl_msg_api_alloc (sizeof (*mp));
1540 memset (mp, 0, sizeof (*mp));
1541 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1542 mp->bd_id = ntohl (bd_id);
1543 mp->sw_if_index = ntohl (member->sw_if_index);
1544 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1545 mp->shg = input_cfg->shg;
1546 mp->context = context;
1548 vl_msg_api_send_shmem (q, (u8 *)&mp);
1551 static void vl_api_bridge_domain_dump_t_handler (
1552 vl_api_bridge_domain_dump_t *mp)
1554 bd_main_t * bdm = &bd_main;
1555 l2input_main_t * l2im = &l2input_main;
1556 unix_shared_memory_queue_t * q;
1557 l2_bridge_domain_t * bd_config;
1558 u32 bd_id, bd_index;
1561 q = vl_api_client_index_to_input_queue (mp->client_index);
1566 bd_id = ntohl(mp->bd_id);
1568 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1569 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1570 for (; bd_index < end; bd_index++) {
1571 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1572 /* skip dummy bd_id 0 */
1573 if (bd_config && (bd_config->bd_id > 0)) {
1575 l2_flood_member_t * m;
1577 n_sw_ifs = vec_len (bd_config->members);
1578 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1580 vec_foreach (m, bd_config->members) {
1581 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1588 vl_api_l2fib_add_del_t_handler (
1589 vl_api_l2fib_add_del_t *mp)
1591 bd_main_t * bdm = &bd_main;
1592 l2input_main_t * l2im = &l2input_main;
1593 vl_api_l2fib_add_del_reply_t * rmp;
1596 u32 sw_if_index = ntohl(mp->sw_if_index);
1597 u32 bd_id = ntohl(mp->bd_id);
1605 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1607 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1608 goto bad_sw_if_index;
1613 VALIDATE_SW_IF_INDEX(mp);
1614 if (vec_len(l2im->configs) <= sw_if_index) {
1615 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1616 goto bad_sw_if_index;
1618 l2_input_config_t * config;
1619 config = vec_elt_at_index(l2im->configs, sw_if_index);
1620 if (config->bridge == 0) {
1621 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1622 goto bad_sw_if_index;
1625 static_mac = mp->static_mac ? 1 : 0;
1626 filter_mac = mp->filter_mac ? 1 : 0;
1627 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1630 l2fib_del_entry(mac, bd_index);
1633 BAD_SW_IF_INDEX_LABEL;
1635 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1639 vl_api_l2_flags_t_handler (
1640 vl_api_l2_flags_t *mp)
1642 vl_api_l2_flags_reply_t * rmp;
1644 u32 sw_if_index = ntohl(mp->sw_if_index);
1645 u32 flags = ntohl(mp->feature_bitmap);
1648 VALIDATE_SW_IF_INDEX(mp);
1651 if (flags & L2INPUT_FEAT_ ## a) \
1652 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1653 foreach_l2input_feat;
1656 BAD_SW_IF_INDEX_LABEL;
1658 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1662 vl_api_bridge_flags_t_handler (
1663 vl_api_bridge_flags_t *mp)
1665 vlib_main_t *vm = vlib_get_main();
1666 bd_main_t * bdm = &bd_main;
1667 vl_api_bridge_flags_reply_t * rmp;
1669 u32 bd_id = ntohl(mp->bd_id);
1671 u32 flags = ntohl(mp->feature_bitmap);
1674 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1676 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1682 bd_set_flags(vm, bd_index, flags, mp->is_set);
1685 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1686 rmp->resulting_feature_bitmap = ntohl(flags));
1690 vl_api_bd_ip_mac_add_del_t_handler (
1691 vl_api_bd_ip_mac_add_del_t *mp)
1693 bd_main_t * bdm = &bd_main;
1694 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1696 u32 bd_id = ntohl(mp->bd_id);
1700 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1702 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1707 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1708 mp->mac_address, mp->is_ipv6, mp->is_add))
1709 rv = VNET_API_ERROR_UNSPECIFIED;
1712 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1716 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1719 vl_api_tap_connect_reply_t * rmp;
1720 unix_shared_memory_queue_t * q;
1721 u32 sw_if_index = (u32)~0;
1723 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1724 mp->use_random_mac ? 0 : mp->mac_address,
1725 &sw_if_index, mp->renumber,
1726 ntohl(mp->custom_dev_instance));
1728 q = vl_api_client_index_to_input_queue (mp->client_index);
1732 rmp = vl_msg_api_alloc (sizeof (*rmp));
1733 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1734 rmp->context = mp->context;
1735 rmp->retval = ntohl(rv);
1736 rmp->sw_if_index = ntohl(sw_if_index);
1738 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1742 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1745 vl_api_tap_modify_reply_t * rmp;
1746 unix_shared_memory_queue_t * q;
1747 u32 sw_if_index = (u32)~0;
1749 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1750 mp->use_random_mac ? 0 : mp->mac_address,
1751 &sw_if_index, mp->renumber,
1752 ntohl(mp->custom_dev_instance));
1754 q = vl_api_client_index_to_input_queue (mp->client_index);
1758 rmp = vl_msg_api_alloc (sizeof (*rmp));
1759 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1760 rmp->context = mp->context;
1761 rmp->retval = ntohl(rv);
1762 rmp->sw_if_index = ntohl(sw_if_index);
1764 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1768 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1771 vpe_api_main_t * vam = &vpe_api_main;
1772 vl_api_tap_delete_reply_t * rmp;
1773 unix_shared_memory_queue_t * q;
1774 u32 sw_if_index = ntohl(mp->sw_if_index);
1776 rv = vnet_tap_delete (vm, sw_if_index);
1778 q = vl_api_client_index_to_input_queue (mp->client_index);
1782 rmp = vl_msg_api_alloc (sizeof (*rmp));
1783 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1784 rmp->context = mp->context;
1785 rmp->retval = ntohl(rv);
1787 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1790 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1794 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1796 vl_api_create_vlan_subif_reply_t * rmp;
1797 vnet_main_t * vnm = vnet_get_main();
1798 u32 hw_if_index, sw_if_index = (u32)~0;
1799 vnet_hw_interface_t * hi;
1802 vnet_sw_interface_t template;
1804 vnet_interface_main_t * im = &vnm->interface_main;
1805 u64 sup_and_sub_key;
1807 unix_shared_memory_queue_t * q;
1808 clib_error_t * error;
1810 VALIDATE_SW_IF_INDEX(mp);
1812 hw_if_index = ntohl(mp->sw_if_index);
1813 hi = vnet_get_hw_interface (vnm, hw_if_index);
1815 id = ntohl(mp->vlan_id);
1816 if (id == 0 || id > 4095) {
1817 rv = VNET_API_ERROR_INVALID_VLAN;
1821 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1823 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1825 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1829 kp = clib_mem_alloc (sizeof (*kp));
1830 *kp = sup_and_sub_key;
1832 memset (&template, 0, sizeof (template));
1833 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1834 template.sup_sw_if_index = hi->sw_if_index;
1835 template.sub.id = id;
1836 template.sub.eth.raw_flags = 0;
1837 template.sub.eth.flags.one_tag = 1;
1838 template.sub.eth.outer_vlan_id = id;
1839 template.sub.eth.flags.exact_match = 1;
1841 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1843 clib_error_report(error);
1844 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1847 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1848 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1850 BAD_SW_IF_INDEX_LABEL;
1853 q = vl_api_client_index_to_input_queue (mp->client_index);
1857 rmp = vl_msg_api_alloc (sizeof (*rmp));
1858 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1859 rmp->context = mp->context;
1860 rmp->retval = ntohl(rv);
1861 rmp->sw_if_index = ntohl(sw_if_index);
1862 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1866 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1868 vl_api_create_subif_reply_t * rmp;
1869 vnet_main_t * vnm = vnet_get_main();
1870 u32 sw_if_index = ~0;
1873 vnet_sw_interface_t *si;
1874 vnet_hw_interface_t *hi;
1875 vnet_sw_interface_t template;
1877 vnet_interface_main_t * im = &vnm->interface_main;
1878 u64 sup_and_sub_key;
1880 clib_error_t * error;
1882 VALIDATE_SW_IF_INDEX(mp);
1884 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1885 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1887 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1888 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1892 sw_if_index = si->sw_if_index;
1893 sub_id = ntohl(mp->sub_id);
1895 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1897 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1900 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1901 sw_if_index, sub_id);
1902 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1906 kp = clib_mem_alloc (sizeof (*kp));
1907 *kp = sup_and_sub_key;
1909 memset (&template, 0, sizeof (template));
1910 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1911 template.sup_sw_if_index = sw_if_index;
1912 template.sub.id = sub_id;
1913 template.sub.eth.flags.no_tags = mp->no_tags;
1914 template.sub.eth.flags.one_tag = mp->one_tag;
1915 template.sub.eth.flags.two_tags = mp->two_tags;
1916 template.sub.eth.flags.dot1ad = mp->dot1ad;
1917 template.sub.eth.flags.exact_match = mp->exact_match;
1918 template.sub.eth.flags.default_sub = mp->default_sub;
1919 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1920 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1921 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1922 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1924 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1926 clib_error_report (error);
1927 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1931 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1932 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1934 BAD_SW_IF_INDEX_LABEL;
1938 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1940 rmp->sw_if_index = ntohl(sw_if_index);
1945 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1947 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1949 stats_main_t * sm = &stats_main;
1950 u32 tunnel_sw_if_index = ~0;
1952 dslock (sm, 1 /* release hint */, 5 /* tag */);
1954 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1955 (ip4_address_t *)(mp->dst_address),
1956 (ip4_address_t *)(mp->intfc_address),
1957 (u32)(mp->intfc_address_length),
1958 ntohl(mp->inner_vrf_id),
1959 ntohl(mp->outer_vrf_id),
1960 &tunnel_sw_if_index,
1965 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1967 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1972 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1973 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1975 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1977 stats_main_t * sm = &stats_main;
1978 u32 tunnel_sw_if_index;
1980 dslock (sm, 1 /* release hint */, 5 /* tag */);
1982 rv = vnet_mpls_ethernet_add_del_tunnel
1983 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1984 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1985 ntohl(mp->tx_sw_if_index),
1986 &tunnel_sw_if_index,
1992 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1994 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1999 * This piece of misery brought to you because the control-plane
2000 * can't figure out the tx interface + dst-mac address all by itself
2002 static int mpls_ethernet_add_del_tunnel_2_t_handler
2003 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2005 pending_route_t * pr;
2006 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2007 vnet_main_t * vnm = vnet_get_main();
2008 vlib_main_t * vm = vlib_get_main();
2009 stats_main_t * sm = &stats_main;
2010 vpe_api_main_t * vam = &vpe_api_main;
2011 u32 inner_fib_index, outer_fib_index;
2012 ip4_main_t * im = &ip4_main;
2013 ip_lookup_main_t * lm = &im->lookup_main;
2014 ip_adjacency_t * adj = 0;
2017 u8 * dst_mac_address;
2021 u32 tunnel_sw_if_index;
2023 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2025 return VNET_API_ERROR_NO_SUCH_FIB;
2027 outer_fib_index = p[0];
2030 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2032 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2034 inner_fib_index = p[0];
2036 if (inner_fib_index == outer_fib_index)
2037 return VNET_API_ERROR_INVALID_VALUE;
2039 lookup_result = ip4_fib_lookup_with_table
2040 (im, outer_fib_index,
2041 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2042 1 /* disable default route */);
2044 adj = ip_get_adjacency (lm, lookup_result);
2045 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2047 if (mp->is_add && mp->resolve_if_needed) {
2048 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2049 pool_get (vam->pending_routes, pr);
2050 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2052 clib_memcpy (pme, mp, sizeof (*pme));
2053 /* recursion block, "just in case" */
2054 pme->resolve_if_needed = 0;
2055 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2056 pme->resolve_opaque = tx_sw_if_index;
2057 vnet_register_ip4_arp_resolution_event
2059 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2060 vpe_resolver_process_node.index,
2061 RESOLUTION_EVENT, pr - vam->pending_routes);
2063 vlib_process_signal_event
2064 (vm, vpe_resolver_process_node.index,
2065 RESOLUTION_PENDING_EVENT, 0 /* data */);
2067 /* The interface may be down, etc. */
2068 e = ip4_probe_neighbor
2069 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2073 clib_error_report(e);
2075 return VNET_API_ERROR_IN_PROGRESS;
2079 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2080 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2083 vnet_rewrite_get_data_internal
2084 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2086 dslock (sm, 1 /* release hint */, 10 /* tag */);
2088 rv = vnet_mpls_ethernet_add_del_tunnel
2089 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2090 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2091 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2099 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2100 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2102 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2105 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2107 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2112 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2114 vl_api_mpls_add_del_encap_reply_t * rmp;
2116 static u32 * labels;
2119 vec_reset_length (labels);
2121 for (i = 0; i < mp->nlabels; i++)
2122 vec_add1 (labels, ntohl(mp->labels[i]));
2125 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2126 ntohl(mp->vrf_id), labels,
2127 ~0 /* policy_tunnel_index */,
2128 0 /* no_dst_hash */,
2132 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2136 vl_api_mpls_add_del_decap_t_handler
2137 (vl_api_mpls_add_del_decap_t *mp)
2139 vl_api_mpls_add_del_decap_reply_t * rmp;
2142 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2143 ntohl(mp->label), ntohl(mp->next_index),
2144 mp->s_bit, mp->is_add);
2146 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2150 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2152 vl_api_proxy_arp_add_del_reply_t * rmp;
2155 ip4_main_t * im = &ip4_main;
2156 stats_main_t * sm = &stats_main;
2157 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2158 ip4_address_t *hi_addr,
2159 u32 fib_index, int is_del);
2162 dslock (sm, 1 /* release hint */, 6 /* tag */);
2164 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2167 rv = VNET_API_ERROR_NO_SUCH_FIB;
2173 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2174 (ip4_address_t *)mp->hi_address,
2175 fib_index, mp->is_add == 0);
2179 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2183 vl_api_proxy_arp_intfc_enable_disable_t_handler
2184 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2187 vnet_main_t * vnm = vnet_get_main();
2188 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2189 vnet_sw_interface_t * si;
2192 VALIDATE_SW_IF_INDEX(mp);
2194 sw_if_index = ntohl(mp->sw_if_index);
2196 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2198 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2202 si = vnet_get_sw_interface (vnm, sw_if_index);
2206 if (mp->enable_disable)
2207 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2209 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2211 BAD_SW_IF_INDEX_LABEL;
2214 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2218 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2220 vl_api_ip_neighbor_add_del_reply_t * rmp;
2221 vnet_main_t * vnm = vnet_get_main();
2224 stats_main_t * sm = &stats_main;
2226 VALIDATE_SW_IF_INDEX(mp);
2228 dslock (sm, 1 /* release hint */, 7 /* tag */);
2232 rv = vnet_set_ip6_ethernet_neighbor
2233 (vm, ntohl(mp->sw_if_index),
2234 (ip6_address_t *)(mp->dst_address),
2235 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2237 rv = vnet_unset_ip6_ethernet_neighbor
2238 (vm, ntohl(mp->sw_if_index),
2239 (ip6_address_t *)(mp->dst_address),
2240 mp->mac_address, sizeof(mp->mac_address));
2242 ip4_main_t * im = &ip4_main;
2243 ip_lookup_main_t * lm = &im->lookup_main;
2244 ethernet_arp_ip4_over_ethernet_address_t a;
2246 ip_adjacency_t *nh_adj;
2248 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2250 rv = VNET_API_ERROR_NO_SUCH_FIB;
2256 * Unfortunately, folks have a penchant for
2257 * adding interface addresses to the ARP cache, and
2258 * wondering why the forwarder eventually ASSERTs...
2260 ai = ip4_fib_lookup_with_table
2261 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2262 1 /* disable default route */);
2265 nh_adj = ip_get_adjacency (lm, ai);
2266 /* Never allow manipulation of a local adj! */
2267 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2268 clib_warning("%U matches local adj",
2270 (ip4_address_t *)(mp->dst_address));
2271 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2276 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2277 clib_memcpy (&a.ip4, mp->dst_address, 4);
2280 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2281 fib_index, &a, mp->is_static);
2283 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2287 BAD_SW_IF_INDEX_LABEL;
2290 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2294 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2297 vpe_main_t *rm = &vpe_main;
2298 ip4_main_t *im4 = &ip4_main;
2299 ip6_main_t *im6 = &ip6_main;
2300 ip_lookup_main_t * lm;
2305 u32 adj_index, sw_if_index;
2306 vl_api_is_address_reachable_t *rmp;
2307 ip_adjacency_t * adj;
2308 unix_shared_memory_queue_t *q;
2310 q = vl_api_client_index_to_input_queue (mp->client_index);
2312 increment_missing_api_client_counter (rm->vlib_main);
2316 rmp = vl_msg_api_alloc (sizeof (*rmp));
2317 clib_memcpy (rmp, mp, sizeof (*rmp));
2319 sw_if_index = mp->next_hop_sw_if_index;
2320 clib_memcpy (&addr, mp->address, sizeof (addr));
2322 lm = &im6->lookup_main;
2324 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2326 lm = &im4->lookup_main;
2328 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2330 if (adj_index == ~0) {
2334 adj = ip_get_adjacency (lm, adj_index);
2336 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2337 && adj->rewrite_header.sw_if_index == sw_if_index) {
2340 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2341 && adj->rewrite_header.sw_if_index == sw_if_index) {
2343 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2345 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2346 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2354 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2358 static void vl_api_sw_interface_details_t_handler (
2359 vl_api_sw_interface_details_t * mp)
2361 clib_warning ("BUG");
2364 static void vl_api_sw_interface_set_flags_t_handler (
2365 vl_api_sw_interface_set_flags_t * mp)
2367 vl_api_sw_interface_set_flags_reply_t *rmp;
2368 vnet_main_t * vnm = vnet_get_main();
2370 clib_error_t * error;
2373 VALIDATE_SW_IF_INDEX(mp);
2375 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2377 error = vnet_sw_interface_set_flags (vnm,
2378 ntohl(mp->sw_if_index),
2382 clib_error_report (error);
2385 BAD_SW_IF_INDEX_LABEL;
2386 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2389 static void vl_api_sw_interface_clear_stats_t_handler (
2390 vl_api_sw_interface_clear_stats_t * mp)
2392 vl_api_sw_interface_clear_stats_reply_t *rmp;
2394 vnet_main_t * vnm = vnet_get_main();
2395 vnet_interface_main_t * im = &vnm->interface_main;
2396 vlib_simple_counter_main_t * sm;
2397 vlib_combined_counter_main_t * cm;
2398 static vnet_main_t ** my_vnet_mains;
2399 int i, j, n_counters;
2403 vec_reset_length (my_vnet_mains);
2405 for (i = 0; i < vec_len (vnet_mains); i++)
2408 vec_add1 (my_vnet_mains, vnet_mains[i]);
2411 if (vec_len (vnet_mains) == 0)
2412 vec_add1 (my_vnet_mains, vnm);
2414 n_counters = vec_len (im->combined_sw_if_counters);
2416 for (j = 0; j < n_counters; j++)
2418 for (i = 0; i < vec_len(my_vnet_mains); i++)
2420 im = &my_vnet_mains[i]->interface_main;
2421 cm = im->combined_sw_if_counters + j;
2422 if (mp->sw_if_index == (u32)~0)
2423 vlib_clear_combined_counters (cm);
2425 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2429 n_counters = vec_len (im->sw_if_counters);
2431 for (j = 0; j < n_counters; j++)
2433 for (i = 0; i < vec_len(my_vnet_mains); i++)
2435 im = &my_vnet_mains[i]->interface_main;
2436 sm = im->sw_if_counters + j;
2437 if (mp->sw_if_index == (u32)~0)
2438 vlib_clear_simple_counters (sm);
2440 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2444 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2447 static void send_sw_interface_details (vpe_api_main_t * am,
2448 unix_shared_memory_queue_t *q,
2449 vnet_sw_interface_t * swif,
2450 u8 * interface_name,
2453 vl_api_sw_interface_details_t * mp;
2454 vnet_hw_interface_t * hi;
2456 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2458 mp = vl_msg_api_alloc (sizeof (*mp));
2459 memset (mp, 0, sizeof (*mp));
2460 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2461 mp->sw_if_index = ntohl(swif->sw_if_index);
2462 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2463 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2465 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2467 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2468 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2469 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2470 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2471 mp->link_mtu = ntohs(hi->max_packet_bytes);
2472 mp->context = context;
2474 strncpy ((char *) mp->interface_name,
2475 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2477 /* Send the L2 address for ethernet physical intfcs */
2478 if (swif->sup_sw_if_index == swif->sw_if_index
2479 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2480 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2481 ethernet_interface_t *ei;
2483 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2484 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2485 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2486 mp->l2_address_length = ntohl(sizeof (ei->address));
2487 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2488 vnet_sub_interface_t *sub = &swif->sub;
2489 mp->sub_id = ntohl(sub->id);
2490 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2491 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2492 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2493 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2494 mp->sub_exact_match = sub->eth.flags.exact_match;
2495 mp->sub_default = sub->eth.flags.default_sub;
2496 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2497 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2499 /* vlan tag rewrite data */
2500 u32 vtr_op = L2_VTR_DISABLED;
2501 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2503 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2504 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2505 // error - default to disabled
2506 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2507 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2510 mp->vtr_op = ntohl(vtr_op);
2511 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2512 mp->vtr_tag1 = ntohl(vtr_tag1);
2513 mp->vtr_tag2 = ntohl(vtr_tag2);
2517 vl_msg_api_send_shmem (q, (u8 *)&mp);
2520 static void send_sw_interface_flags (vpe_api_main_t * am,
2521 unix_shared_memory_queue_t *q,
2522 vnet_sw_interface_t * swif)
2524 vl_api_sw_interface_set_flags_t *mp;
2525 vnet_main_t * vnm = am->vnet_main;
2527 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2529 mp = vl_msg_api_alloc (sizeof (*mp));
2530 memset (mp, 0, sizeof (*mp));
2531 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2532 mp->sw_if_index = ntohl(swif->sw_if_index);
2534 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2536 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2538 vl_msg_api_send_shmem (q, (u8 *)&mp);
2541 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2542 unix_shared_memory_queue_t *q,
2544 __attribute__((unused));
2546 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2547 unix_shared_memory_queue_t *q,
2550 vl_api_sw_interface_set_flags_t *mp;
2552 mp = vl_msg_api_alloc (sizeof (*mp));
2553 memset (mp, 0, sizeof (*mp));
2554 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2555 mp->sw_if_index = ntohl(sw_if_index);
2557 mp->admin_up_down = 0;
2558 mp->link_up_down = 0;
2560 vl_msg_api_send_shmem (q, (u8 *)&mp);
2563 static void vl_api_sw_interface_dump_t_handler (
2564 vl_api_sw_interface_dump_t *mp)
2566 vpe_api_main_t * am = &vpe_api_main;
2567 vnet_sw_interface_t * swif;
2568 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2569 u8 * filter_string = 0, * name_string = 0;
2570 unix_shared_memory_queue_t * q;
2571 char * strcasestr (char *, char *); /* lnx hdr file botch */
2573 q = vl_api_client_index_to_input_queue (mp->client_index);
2578 if (mp->name_filter_valid) {
2579 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2580 filter_string = format (0, "%s%c", mp->name_filter, 0);
2583 pool_foreach (swif, im->sw_interfaces,
2585 name_string = format (name_string, "%U%c",
2586 format_vnet_sw_interface_name,
2587 am->vnet_main, swif, 0);
2589 if (mp->name_filter_valid == 0 ||
2590 strcasestr((char *) name_string, (char *) filter_string)) {
2592 send_sw_interface_details (am, q, swif, name_string, mp->context);
2593 send_sw_interface_flags (am, q, swif);
2595 _vec_len (name_string) = 0;
2598 vec_free (name_string);
2599 vec_free (filter_string);
2602 void send_oam_event (oam_target_t * t)
2604 vpe_api_main_t * vam = &vpe_api_main;
2605 unix_shared_memory_queue_t * q;
2606 vpe_client_registration_t *reg;
2607 vl_api_oam_event_t * mp;
2609 pool_foreach(reg, vam->oam_events_registrations,
2611 q = vl_api_client_index_to_input_queue (reg->client_index);
2613 mp = vl_msg_api_alloc (sizeof (*mp));
2614 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2615 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2616 mp->state = t->state;
2617 vl_msg_api_send_shmem (q, (u8 *)&mp);
2623 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2625 vl_api_oam_add_del_reply_t * rmp;
2628 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2629 (ip4_address_t *)mp->dst_address,
2633 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2637 vl_api_vnet_get_summary_stats_t_handler (
2638 vl_api_vnet_get_summary_stats_t *mp)
2640 stats_main_t * sm = &stats_main;
2641 vnet_interface_main_t * im = sm->interface_main;
2642 vl_api_vnet_summary_stats_reply_t *rmp;
2643 vlib_combined_counter_main_t * cm;
2646 u64 total_pkts[VLIB_N_RX_TX];
2647 u64 total_bytes[VLIB_N_RX_TX];
2649 unix_shared_memory_queue_t * q =
2650 vl_api_client_index_to_input_queue (mp->client_index);
2655 rmp = vl_msg_api_alloc (sizeof (*rmp));
2656 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2657 rmp->context = mp->context;
2660 memset (total_pkts, 0, sizeof (total_pkts));
2661 memset (total_bytes, 0, sizeof (total_bytes));
2663 vnet_interface_counter_lock (im);
2665 vec_foreach (cm, im->combined_sw_if_counters) {
2666 which = cm - im->combined_sw_if_counters;
2668 for (i = 0; i < vec_len (cm->maxi); i++) {
2669 vlib_get_combined_counter (cm, i, &v);
2670 total_pkts[which] += v.packets;
2671 total_bytes[which] += v.bytes;
2674 vnet_interface_counter_unlock (im);
2676 /* Note: in HOST byte order! */
2677 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2678 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2679 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2680 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2681 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2683 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2686 typedef CLIB_PACKED (struct {
2687 ip4_address_t address;
2689 u32 address_length : 6;
2694 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2696 vnet_main_t * vnm = vnet_get_main();
2697 vnet_interface_main_t * im = &vnm->interface_main;
2698 ip4_main_t * im4 = &ip4_main;
2699 static ip4_route_t * routes;
2700 static u32 * sw_if_indices_to_shut;
2701 stats_main_t * sm = &stats_main;
2706 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2707 u32 target_fib_id = ntohl(mp->vrf_id);
2709 dslock (sm, 1 /* release hint */, 8 /* tag */);
2711 vec_foreach (fib, im4->fibs) {
2712 vnet_sw_interface_t * si;
2714 if (fib->table_id != target_fib_id)
2717 /* remove any mpls/gre tunnels in this fib */
2718 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2720 /* remove any mpls encap/decap labels */
2721 mpls_fib_reset_labels (fib->table_id);
2723 /* remove any proxy arps in this fib */
2724 vnet_proxy_arp_fib_reset (fib->table_id);
2726 /* Set the flow hash for this fib to the default */
2727 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2729 vec_reset_length (sw_if_indices_to_shut);
2731 /* Shut down interfaces in this FIB / clean out intfc routes */
2732 pool_foreach (si, im->sw_interfaces,
2734 u32 sw_if_index = si->sw_if_index;
2736 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2737 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2739 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2742 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2743 sw_if_index = sw_if_indices_to_shut[i];
2744 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2746 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2747 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2748 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2751 vec_reset_length (routes);
2753 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2754 uword * hash = fib->adj_index_by_dst_address[i];
2758 x.address_length = i;
2760 hash_foreach_pair (p, hash,
2762 x.address.data_u32 = p->key;
2763 vec_add1 (routes, x);
2767 vec_foreach (r, routes) {
2768 ip4_add_del_route_args_t a;
2770 memset (&a, 0, sizeof (a));
2771 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2772 a.table_index_or_table_id = fib - im4->fibs;
2773 a.dst_address = r->address;
2774 a.dst_address_length = r->address_length;
2777 ip4_add_del_route (im4, &a);
2778 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2779 IP4_ROUTE_FLAG_FIB_INDEX);
2783 } /* vec_foreach (fib) */
2790 ip6_address_t address;
2797 ip6_route_t ** routep;
2798 } add_routes_in_fib_arg_t;
2800 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2802 add_routes_in_fib_arg_t * ap = arg;
2804 if (kvp->key[2]>>32 == ap->fib_index)
2806 ip6_address_t *addr;
2808 addr = (ip6_address_t *) kvp;
2809 vec_add2 (*ap->routep, r, 1);
2810 r->address = addr[0];
2811 r->address_length = kvp->key[2] & 0xFF;
2812 r->index = kvp->value;
2816 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2818 vnet_main_t * vnm = vnet_get_main();
2819 vnet_interface_main_t * im = &vnm->interface_main;
2820 ip6_main_t * im6 = &ip6_main;
2821 stats_main_t * sm = &stats_main;
2822 static ip6_route_t * routes;
2823 static u32 * sw_if_indices_to_shut;
2828 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2829 u32 target_fib_id = ntohl(mp->vrf_id);
2830 add_routes_in_fib_arg_t _a, *a=&_a;
2831 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2833 dslock (sm, 1 /* release hint */, 9 /* tag */);
2835 vec_foreach (fib, im6->fibs) {
2836 vnet_sw_interface_t * si;
2838 if (fib->table_id != target_fib_id)
2841 vec_reset_length (sw_if_indices_to_shut);
2843 /* Shut down interfaces in this FIB / clean out intfc routes */
2844 pool_foreach (si, im->sw_interfaces,
2846 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2848 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2851 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2852 sw_if_index = sw_if_indices_to_shut[i];
2853 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2855 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2856 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2857 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2860 vec_reset_length (routes);
2862 a->fib_index = fib - im6->fibs;
2863 a->routep = &routes;
2865 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2867 vec_foreach (r, routes) {
2868 ip6_add_del_route_args_t a;
2870 memset (&a, 0, sizeof (a));
2871 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2872 a.table_index_or_table_id = fib - im6->fibs;
2873 a.dst_address = r->address;
2874 a.dst_address_length = r->address_length;
2877 ip6_add_del_route (im6, &a);
2878 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2879 IP6_ROUTE_FLAG_FIB_INDEX);
2882 /* Reinstall the neighbor / router discovery routes */
2883 vnet_ip6_fib_init (im6, fib - im6->fibs);
2885 } /* vec_foreach (fib) */
2891 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2894 vl_api_reset_fib_reply_t * rmp;
2897 rv = ip6_reset_fib_t_handler (mp);
2899 rv = ip4_reset_fib_t_handler (mp);
2901 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2906 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2908 vl_api_dhcp_proxy_config_reply_t * rmp;
2911 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2912 (ip4_address_t *)(&mp->dhcp_src_address),
2913 (u32) ntohl(mp->vrf_id),
2914 (int) mp->insert_circuit_id,
2915 (int) (mp->is_add == 0));
2917 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2922 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2924 vl_api_dhcp_proxy_config_reply_t * rmp;
2927 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2928 (ip6_address_t *)(&mp->dhcp_src_address),
2929 (u32) ntohl(mp->vrf_id),
2930 (int) mp->insert_circuit_id,
2931 (int) (mp->is_add == 0));
2933 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2937 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2939 vl_api_dhcp_proxy_config_reply_t * rmp;
2942 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2943 (ip4_address_t *)(&mp->dhcp_src_address),
2944 (u32) ntohl(mp->rx_vrf_id),
2945 (u32) ntohl(mp->server_vrf_id),
2946 (int) mp->insert_circuit_id,
2947 (int) (mp->is_add == 0));
2949 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2954 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2956 vl_api_dhcp_proxy_config_reply_t * rmp;
2960 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2961 (ip6_address_t *)(&mp->dhcp_src_address),
2962 (u32) ntohl(mp->rx_vrf_id),
2963 (u32) ntohl(mp->server_vrf_id),
2964 (int) mp->insert_circuit_id,
2965 (int) (mp->is_add == 0));
2967 rv = VNET_API_ERROR_UNIMPLEMENTED;
2970 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2975 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2977 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2980 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2983 (int)mp->is_add == 0);
2985 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2988 (int)mp->is_add == 0);
2990 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2994 static void vl_api_dhcp_proxy_config_t_handler
2995 (vl_api_dhcp_proxy_config_t *mp)
2997 if (mp->is_ipv6 == 0)
2998 dhcpv4_proxy_config (mp);
3000 dhcpv6_proxy_config (mp);
3003 static void vl_api_dhcp_proxy_config_2_t_handler
3004 (vl_api_dhcp_proxy_config_2_t *mp)
3006 if (mp->is_ipv6 == 0)
3007 dhcpv4_proxy_config_2 (mp);
3009 dhcpv6_proxy_config_2 (mp);
3012 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3013 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3015 unix_shared_memory_queue_t * q;
3016 vl_api_dhcp_compl_event_t * mp;
3018 q = vl_api_client_index_to_input_queue (client_index);
3022 mp = vl_msg_api_alloc (sizeof (*mp));
3023 mp->client_index = client_index;
3025 mp->is_ipv6 = is_ipv6;
3026 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3027 mp->hostname[vec_len(hostname) + 1] = '\n';
3028 clib_memcpy (&mp->host_address[0], host_address, 16);
3029 clib_memcpy (&mp->router_address[0], router_address, 16);
3030 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3032 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3034 vl_msg_api_send_shmem (q, (u8 *)&mp);
3037 static void vl_api_dhcp_client_config_t_handler
3038 (vl_api_dhcp_client_config_t *mp)
3040 vlib_main_t *vm = vlib_get_main();
3041 vl_api_dhcp_client_config_reply_t * rmp;
3044 VALIDATE_SW_IF_INDEX(mp);
3046 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3047 mp->hostname, mp->is_add, mp->client_index,
3048 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3051 BAD_SW_IF_INDEX_LABEL;
3053 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3057 vl_api_sw_interface_ip6nd_ra_config_t_handler
3058 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3060 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3062 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3064 is_no = mp->is_no == 1;
3065 surpress = mp->surpress == 1;
3066 managed = mp->managed == 1;
3067 other = mp->other == 1;
3068 ll_option = mp->ll_option == 1;
3069 send_unicast = mp->send_unicast == 1;
3070 cease = mp->cease == 1;
3071 default_router = mp->default_router == 1;
3073 VALIDATE_SW_IF_INDEX(mp);
3075 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3076 surpress, managed, other,
3077 ll_option, send_unicast, cease,
3078 default_router, ntohl (mp->lifetime),
3079 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3080 ntohl(mp->max_interval), ntohl( mp->min_interval),
3083 BAD_SW_IF_INDEX_LABEL;
3085 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3089 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3090 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3092 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3094 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3096 VALIDATE_SW_IF_INDEX(mp);
3098 is_no = mp->is_no == 1;
3099 use_default = mp->use_default == 1;
3100 no_advertise = mp->no_advertise == 1;
3101 off_link = mp->off_link == 1;
3102 no_autoconfig = mp->no_autoconfig == 1;
3103 no_onlink = mp->no_onlink == 1;
3105 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3106 (ip6_address_t *)mp->address, mp->address_length,
3107 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3108 no_advertise, off_link, no_autoconfig, no_onlink,
3111 BAD_SW_IF_INDEX_LABEL;
3112 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3116 vl_api_sw_interface_ip6_enable_disable_t_handler
3117 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3119 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3120 vnet_main_t * vnm = vnet_get_main();
3122 clib_error_t * error;
3126 VALIDATE_SW_IF_INDEX(mp);
3128 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3129 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3132 clib_error_report(error);
3133 rv = VNET_API_ERROR_UNSPECIFIED;
3135 rv = vnm->api_errno;
3138 BAD_SW_IF_INDEX_LABEL;
3140 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3144 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3145 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3147 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3149 clib_error_t * error;
3150 vnet_main_t * vnm = vnet_get_main();
3154 VALIDATE_SW_IF_INDEX(mp);
3156 error = set_ip6_link_local_address(vm,
3157 ntohl(mp->sw_if_index),
3158 (ip6_address_t *)mp->address,
3159 mp->address_length);
3161 clib_error_report(error);
3162 rv = VNET_API_ERROR_UNSPECIFIED;
3164 rv = vnm->api_errno;
3167 BAD_SW_IF_INDEX_LABEL;
3169 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3172 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3174 vl_api_set_ip_flow_hash_reply_t *rmp;
3175 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3177 clib_warning ("unimplemented...");
3179 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3182 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3184 vl_api_set_ip_flow_hash_reply_t *rmp;
3187 u32 flow_hash_config = 0;
3189 table_id = ntohl(mp->vrf_id);
3191 #define _(a,b) if (mp->a) flow_hash_config |= b;
3192 foreach_flow_hash_bit;
3195 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3197 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3201 static void vl_api_set_ip_flow_hash_t_handler
3202 (vl_api_set_ip_flow_hash_t *mp)
3204 if (mp->is_ipv6 == 0)
3205 set_ip4_flow_hash (mp);
3207 set_ip6_flow_hash (mp);
3210 static void vl_api_sw_interface_set_unnumbered_t_handler
3211 (vl_api_sw_interface_set_unnumbered_t *mp)
3213 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3215 vnet_sw_interface_t * si;
3216 vnet_main_t *vnm = vnet_get_main();
3217 u32 sw_if_index, unnumbered_sw_if_index;
3219 sw_if_index = ntohl(mp->sw_if_index);
3220 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3223 * The API message field names are backwards from
3224 * the underlying data structure names.
3225 * It's not worth changing them now.
3227 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3228 unnumbered_sw_if_index)) {
3229 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3233 /* Only check the "use loop0" field when setting the binding */
3235 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3236 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3240 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3243 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3244 si->unnumbered_sw_if_index = sw_if_index;
3246 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3247 si->unnumbered_sw_if_index = (u32)~0;
3251 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3254 static void vl_api_create_loopback_t_handler
3255 (vl_api_create_loopback_t *mp)
3257 vl_api_create_loopback_reply_t * rmp;
3261 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3263 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3265 rmp->sw_if_index = ntohl (sw_if_index);
3269 static void vl_api_delete_loopback_t_handler
3270 (vl_api_delete_loopback_t *mp)
3272 vl_api_delete_loopback_reply_t * rmp;
3276 sw_if_index = ntohl (mp->sw_if_index);
3277 rv = vnet_delete_loopback_interface (sw_if_index);
3279 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3282 static void vl_api_control_ping_t_handler
3283 (vl_api_control_ping_t *mp)
3285 vl_api_control_ping_reply_t * rmp;
3288 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3290 rmp->vpe_pid = ntohl (getpid());
3294 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3296 u8 **shmem_vecp = (u8 **)arg;
3299 api_main_t * am = &api_main;
3302 shmem_vec = *shmem_vecp;
3304 offset = vec_len (shmem_vec);
3306 pthread_mutex_lock (&am->vlib_rp->mutex);
3307 oldheap = svm_push_data_heap (am->vlib_rp);
3309 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3311 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3313 svm_pop_heap (oldheap);
3314 pthread_mutex_unlock (&am->vlib_rp->mutex);
3316 *shmem_vecp = shmem_vec;
3320 static void vl_api_cli_request_t_handler
3321 (vl_api_cli_request_t *mp)
3323 vl_api_cli_reply_t *rp;
3324 unix_shared_memory_queue_t *q;
3325 vlib_main_t * vm = vlib_get_main();
3326 api_main_t * am = &api_main;
3327 unformat_input_t input;
3331 q = vl_api_client_index_to_input_queue (mp->client_index);
3335 rp = vl_msg_api_alloc (sizeof (*rp));
3336 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3337 rp->context = mp->context;
3339 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3341 vlib_cli_input (vm, &input, shmem_cli_output,
3344 pthread_mutex_lock (&am->vlib_rp->mutex);
3345 oldheap = svm_push_data_heap (am->vlib_rp);
3347 vec_add1(shmem_vec, 0);
3349 svm_pop_heap (oldheap);
3350 pthread_mutex_unlock (&am->vlib_rp->mutex);
3352 rp->reply_in_shmem = (uword)shmem_vec;
3354 vl_msg_api_send_shmem (q, (u8 *)&rp);
3357 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3360 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3361 vnet_main_t *vnm = vnet_get_main();
3362 clib_error_t * error;
3367 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3369 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3372 clib_error_report(error);
3373 rv = VNET_API_ERROR_UNSPECIFIED;
3375 rv = vnm->api_errno;
3378 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3381 static void vl_api_sr_tunnel_add_del_t_handler
3382 (vl_api_sr_tunnel_add_del_t *mp)
3385 clib_warning ("unimplemented");
3387 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3389 vl_api_sr_tunnel_add_del_reply_t * rmp;
3390 ip6_address_t * segments = 0, * seg;
3391 ip6_address_t * tags = 0, *tag;
3392 ip6_address_t * this_address;
3395 if (mp->n_segments == 0) {
3400 memset (a, 0, sizeof (*a));
3401 a->src_address = (ip6_address_t *)&mp->src_address;
3402 a->dst_address = (ip6_address_t *)&mp->dst_address;
3403 a->dst_mask_width = mp->dst_mask_width;
3404 a->flags_net_byte_order = mp->flags_net_byte_order;
3405 a->is_del = (mp->is_add == 0);
3406 a->rx_table_id = ntohl(mp->outer_vrf_id);
3407 a->tx_table_id = ntohl(mp->inner_vrf_id);
3409 a->name = format(0, "%s", mp->name);
3410 if (!(vec_len(a->name)))
3413 a->policy_name = format(0, "%s", mp->policy_name);
3414 if (!(vec_len(a->policy_name)))
3417 /* Yank segments and tags out of the API message */
3418 this_address = (ip6_address_t *)mp->segs_and_tags;
3419 for (i = 0; i < mp->n_segments; i++) {
3420 vec_add2 (segments, seg, 1);
3421 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3424 for (i = 0; i < mp->n_tags; i++) {
3425 vec_add2 (tags, tag, 1);
3426 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3430 a->segments = segments;
3433 rv = ip6_sr_add_del_tunnel (a);
3437 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3441 static void vl_api_sr_policy_add_del_t_handler
3442 (vl_api_sr_policy_add_del_t *mp)
3445 clib_warning ("unimplemented");
3447 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3449 vl_api_sr_policy_add_del_reply_t * rmp;
3452 memset (a, 0, sizeof (*a));
3453 a->is_del = (mp->is_add == 0);
3455 a->name = format(0, "%s", mp->name);
3456 if (!(vec_len(a->name)))
3458 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3462 if (!(mp->tunnel_names[0]))
3464 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3468 // start deserializing tunnel_names
3469 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3470 u8 * deser_tun_names = mp->tunnel_names;
3471 deser_tun_names += 1; //moving along
3474 int tun_name_len = 0;
3476 for (i=0; i < num_tunnels; i++)
3478 tun_name_len= *deser_tun_names;
3479 deser_tun_names += 1;
3480 vec_resize (tun_name, tun_name_len);
3481 memcpy(tun_name, deser_tun_names, tun_name_len);
3482 vec_add1 (a->tunnel_names, tun_name);
3483 deser_tun_names += tun_name_len;
3487 rv = ip6_sr_add_del_policy (a);
3491 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3495 static void vl_api_sr_multicast_map_add_del_t_handler
3496 (vl_api_sr_multicast_map_add_del_t *mp)
3499 clib_warning ("unimplemented");
3501 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3503 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3505 memset (a, 0, sizeof (*a));
3506 a->is_del = (mp->is_add == 0);
3508 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3509 a->policy_name = format(0, "%s", mp->policy_name);
3511 if (a->multicast_address == 0)
3517 if (!(a->policy_name))
3523 #if DPDK > 0 /* Cannot call replicate without DPDK */
3524 rv = ip6_sr_add_del_multicastmap (a);
3526 clib_warning ("multicast replication without DPDK not implemented");
3527 rv = VNET_API_ERROR_UNIMPLEMENTED;
3532 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3536 #define foreach_classify_add_del_table_field \
3541 _(match_n_vectors) \
3542 _(next_table_index) \
3545 static void vl_api_classify_add_del_table_t_handler
3546 (vl_api_classify_add_del_table_t * mp)
3548 vl_api_classify_add_del_table_reply_t * rmp;
3549 vnet_classify_main_t * cm = &vnet_classify_main;
3550 vnet_classify_table_t * t;
3554 foreach_classify_add_del_table_field;
3557 #define _(a) a = ntohl(mp->a);
3558 foreach_classify_add_del_table_field;
3561 /* The underlying API fails silently, on purpose, so check here */
3562 if (mp->is_add == 0)
3563 if (pool_is_free_index (cm->tables, table_index)) {
3564 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3568 rv = vnet_classify_add_del_table
3569 (cm, mp->mask, nbuckets, memory_size,
3570 skip_n_vectors, match_n_vectors,
3571 next_table_index, miss_next_index,
3572 &table_index, mp->is_add);
3575 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3577 if (rv == 0 && mp->is_add) {
3578 t = pool_elt_at_index (cm->tables, table_index);
3579 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3580 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3581 rmp->new_table_index = ntohl(table_index);
3583 rmp->skip_n_vectors = ~0;
3584 rmp->match_n_vectors = ~0;
3585 rmp->new_table_index = ~0;
3590 static void vl_api_classify_add_del_session_t_handler
3591 (vl_api_classify_add_del_session_t * mp)
3593 vnet_classify_main_t * cm = &vnet_classify_main;
3594 vl_api_classify_add_del_session_reply_t * rmp;
3596 u32 table_index, hit_next_index, opaque_index;
3599 table_index = ntohl (mp->table_index);
3600 hit_next_index = ntohl (mp->hit_next_index);
3601 opaque_index = ntohl (mp->opaque_index);
3602 advance = ntohl (mp->advance);
3604 rv = vnet_classify_add_del_session
3605 (cm, table_index, mp->match, hit_next_index, opaque_index,
3606 advance, mp->is_add);
3608 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3611 static void vl_api_classify_set_interface_ip_table_t_handler
3612 (vl_api_classify_set_interface_ip_table_t * mp)
3614 vlib_main_t * vm = vlib_get_main();
3615 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3617 u32 table_index, sw_if_index;
3619 table_index = ntohl (mp->table_index);
3620 sw_if_index = ntohl (mp->sw_if_index);
3622 VALIDATE_SW_IF_INDEX(mp);
3625 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3627 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3629 BAD_SW_IF_INDEX_LABEL;
3631 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3634 static void vl_api_classify_set_interface_l2_tables_t_handler
3635 (vl_api_classify_set_interface_l2_tables_t * mp)
3637 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3639 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3642 ip4_table_index = ntohl(mp->ip4_table_index);
3643 ip6_table_index = ntohl(mp->ip6_table_index);
3644 other_table_index = ntohl(mp->other_table_index);
3645 sw_if_index = ntohl(mp->sw_if_index);
3647 VALIDATE_SW_IF_INDEX(mp);
3649 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3650 ip6_table_index, other_table_index);
3653 if (ip4_table_index != ~0 || ip6_table_index != ~0
3654 || other_table_index != ~0)
3659 vnet_l2_classify_enable_disable (sw_if_index, enable);
3662 BAD_SW_IF_INDEX_LABEL;
3664 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3668 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3671 vl_api_l2_fib_clear_table_reply_t * rmp;
3673 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3674 * that is not currently implemented. When that TODO is fixed
3675 * this call should be changed to pass 1 instead of 0.
3677 l2fib_clear_table (0);
3679 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3682 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3687 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3690 vl_api_l2_interface_efp_filter_reply_t * rmp;
3691 vnet_main_t *vnm = vnet_get_main();
3693 // enable/disable the feature
3694 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3695 rv = vnm->api_errno;
3697 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3701 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3704 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3705 vnet_main_t * vnm = vnet_get_main();
3706 vlib_main_t * vm = vlib_get_main();
3709 VALIDATE_SW_IF_INDEX(mp);
3711 vtr_op = ntohl(mp->vtr_op);
3713 /* The L2 code is unsuspicious */
3715 case L2_VTR_DISABLED:
3720 case L2_VTR_TRANSLATE_1_1:
3721 case L2_VTR_TRANSLATE_1_2:
3722 case L2_VTR_TRANSLATE_2_1:
3723 case L2_VTR_TRANSLATE_2_2:
3727 rv = VNET_API_ERROR_INVALID_VALUE;
3728 goto bad_sw_if_index;
3731 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3732 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3735 BAD_SW_IF_INDEX_LABEL;
3737 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3741 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3745 vl_api_create_vhost_user_if_reply_t * rmp;
3746 u32 sw_if_index = (u32)~0;
3748 vnet_main_t * vnm = vnet_get_main();
3749 vlib_main_t * vm = vlib_get_main();
3751 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3752 mp->is_server, &sw_if_index, (u64)~0,
3753 mp->renumber, ntohl(mp->custom_dev_instance),
3754 (mp->use_custom_mac)?mp->mac_address:NULL);
3756 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3758 rmp->sw_if_index = ntohl (sw_if_index);
3764 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3768 vl_api_modify_vhost_user_if_reply_t * rmp;
3769 u32 sw_if_index = ntohl(mp->sw_if_index);
3771 vnet_main_t * vnm = vnet_get_main();
3772 vlib_main_t * vm = vlib_get_main();
3774 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3775 mp->is_server, sw_if_index, (u64)~0,
3776 mp->renumber, ntohl(mp->custom_dev_instance));
3778 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3783 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3787 vpe_api_main_t * vam = &vpe_api_main;
3788 vl_api_delete_vhost_user_if_reply_t * rmp;
3789 u32 sw_if_index = ntohl(mp->sw_if_index);
3791 vnet_main_t * vnm = vnet_get_main();
3792 vlib_main_t * vm = vlib_get_main();
3794 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3796 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3798 unix_shared_memory_queue_t * q =
3799 vl_api_client_index_to_input_queue (mp->client_index);
3803 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3808 static void vl_api_sw_interface_vhost_user_details_t_handler (
3809 vl_api_sw_interface_vhost_user_details_t * mp)
3811 clib_warning ("BUG");
3815 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3816 unix_shared_memory_queue_t *q,
3817 vhost_user_intf_details_t * vui,
3820 vl_api_sw_interface_vhost_user_details_t * mp;
3822 mp = vl_msg_api_alloc (sizeof (*mp));
3823 memset (mp, 0, sizeof (*mp));
3824 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3825 mp->sw_if_index = ntohl(vui->sw_if_index);
3826 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3827 mp->features = clib_net_to_host_u64 (vui->features);
3828 mp->is_server = vui->is_server;
3829 mp->num_regions = ntohl(vui->num_regions);
3830 mp->sock_errno = ntohl(vui->sock_errno);
3831 mp->context = context;
3833 strncpy ((char *) mp->sock_filename,
3834 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3835 strncpy ((char *) mp->interface_name,
3836 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3838 vl_msg_api_send_shmem (q, (u8 *)&mp);
3843 vl_api_sw_interface_vhost_user_dump_t_handler (
3844 vl_api_sw_interface_vhost_user_dump_t *mp)
3848 vpe_api_main_t * am = &vpe_api_main;
3849 vnet_main_t * vnm = vnet_get_main();
3850 vlib_main_t * vm = vlib_get_main();
3851 vhost_user_intf_details_t *ifaces = NULL;
3852 vhost_user_intf_details_t *vuid = NULL;
3853 unix_shared_memory_queue_t * q;
3855 q = vl_api_client_index_to_input_queue (mp->client_index);
3859 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3863 vec_foreach (vuid, ifaces) {
3864 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3870 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3871 unix_shared_memory_queue_t *q,
3876 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3877 u8 * if_name = NULL;
3878 vnet_sw_interface_t * si = NULL;
3880 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3882 if_name = format(if_name, "%U",
3883 format_vnet_sw_interface_name, lm->vnet_main, si);
3885 mp = vl_msg_api_alloc (sizeof (*mp));
3886 memset (mp, 0, sizeof (*mp));
3887 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3888 strncpy((char *)mp->interface_name,
3889 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3890 mp->sw_if_index = ntohl(si->sw_if_index);
3891 mp->local_session_id = s->local_session_id;
3892 mp->remote_session_id = s->remote_session_id;
3893 mp->local_cookie[0] = s->local_cookie[0];
3894 mp->local_cookie[1] = s->local_cookie[1];
3895 mp->remote_cookie = s->remote_cookie;
3896 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3897 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3898 mp->l2_sublayer_present = s->l2_sublayer_present;
3899 mp->context = context;
3901 vl_msg_api_send_shmem (q, (u8 *)&mp);
3904 static void send_ip_address_details (vpe_api_main_t * am,
3905 unix_shared_memory_queue_t * q,
3911 vl_api_ip_address_details_t * mp;
3913 mp = vl_msg_api_alloc (sizeof (*mp));
3914 memset (mp, 0, sizeof (*mp));
3915 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3918 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3920 u32 * tp = (u32 *)mp->ip;
3921 *tp = ntohl(*(u32*)ip);
3923 mp->prefix_length = prefix_length;
3924 mp->context = context;
3926 vl_msg_api_send_shmem (q, (u8 *)&mp);
3930 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3932 vpe_api_main_t * am = &vpe_api_main;
3933 unix_shared_memory_queue_t * q;
3936 ip6_main_t * im6 = &ip6_main;
3937 ip4_main_t * im4 = &ip4_main;
3938 ip_lookup_main_t * lm6 = &im6->lookup_main;
3939 ip_lookup_main_t * lm4 = &im4->lookup_main;
3940 ip_interface_address_t * ia = 0;
3941 u32 sw_if_index = ~0;
3942 int rv __attribute__ ((unused)) = 0;
3944 VALIDATE_SW_IF_INDEX(mp);
3946 sw_if_index = ntohl(mp->sw_if_index);
3948 q = vl_api_client_index_to_input_queue (mp->client_index);
3954 foreach_ip_interface_address (lm6, ia, sw_if_index,
3955 1 /* honor unnumbered */,
3957 r6 = ip_interface_address_get_address (lm6, ia);
3958 u16 prefix_length = ia->address_length;
3959 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3962 foreach_ip_interface_address (lm4, ia, sw_if_index,
3963 1 /* honor unnumbered */,
3965 r4 = ip_interface_address_get_address (lm4, ia);
3966 u16 prefix_length = ia->address_length;
3967 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3970 BAD_SW_IF_INDEX_LABEL;
3973 static void send_ip_details (vpe_api_main_t * am,
3974 unix_shared_memory_queue_t *q,
3978 vl_api_ip_details_t * mp;
3980 mp = vl_msg_api_alloc (sizeof (*mp));
3981 memset (mp, 0, sizeof (*mp));
3982 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3984 mp->sw_if_index = ntohl(sw_if_index);
3985 mp->context = context;
3987 vl_msg_api_send_shmem (q, (u8 *)&mp);
3991 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3992 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3994 vpe_api_main_t * am = &vpe_api_main;
3995 l2t_main_t * lm = &l2t_main;
3996 unix_shared_memory_queue_t * q;
3997 l2t_session_t *session;
3999 q = vl_api_client_index_to_input_queue (mp->client_index);
4003 pool_foreach (session, lm->sessions,
4005 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4010 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4011 unix_shared_memory_queue_t *q,
4012 tapcli_interface_details_t *tap_if,
4015 vl_api_sw_interface_tap_details_t * mp;
4016 mp = vl_msg_api_alloc (sizeof (*mp));
4017 memset (mp, 0, sizeof (*mp));
4018 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4019 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4020 strncpy((char *)mp->dev_name,
4021 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4022 mp->context = context;
4024 vl_msg_api_send_shmem (q, (u8 *)&mp);
4028 vl_api_sw_interface_tap_dump_t_handler (
4029 vl_api_sw_interface_tap_dump_t *mp)
4032 vpe_api_main_t * am = &vpe_api_main;
4033 unix_shared_memory_queue_t * q;
4034 tapcli_interface_details_t *tapifs = NULL;
4035 tapcli_interface_details_t *tap_if = NULL;
4037 q = vl_api_client_index_to_input_queue (mp->client_index);
4041 rv = vnet_tap_dump_ifs(&tapifs);
4045 vec_foreach(tap_if, tapifs) {
4046 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4053 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4055 vpe_api_main_t * am = &vpe_api_main;
4056 vnet_main_t * vnm = vnet_get_main();
4057 vlib_main_t * vm = vlib_get_main();
4058 vnet_interface_main_t * im = &vnm->interface_main;
4059 unix_shared_memory_queue_t * q;
4060 vnet_sw_interface_t * si, * sorted_sis;
4061 u32 sw_if_index = ~0;
4063 q = vl_api_client_index_to_input_queue (mp->client_index);
4068 /* Gather interfaces. */
4069 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4070 _vec_len (sorted_sis) = 0;
4071 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4073 vec_foreach (si, sorted_sis) {
4074 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4075 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4078 sw_if_index = si->sw_if_index;
4079 send_ip_details(am, q, sw_if_index, mp->context);
4084 static void vl_api_l2_fib_table_entry_t_handler (
4085 vl_api_l2_fib_table_entry_t * mp)
4087 clib_warning ("BUG");
4090 static void send_l2fib_table_entry (vpe_api_main_t * am,
4091 unix_shared_memory_queue_t *q,
4092 l2fib_entry_key_t * l2fe_key,
4093 l2fib_entry_result_t * l2fe_res,
4096 vl_api_l2_fib_table_entry_t * mp;
4098 mp = vl_msg_api_alloc (sizeof (*mp));
4099 memset (mp, 0, sizeof (*mp));
4100 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4102 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4104 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4105 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4106 mp->static_mac = l2fe_res->fields.static_mac;
4107 mp->filter_mac = l2fe_res->fields.filter;
4108 mp->bvi_mac = l2fe_res->fields.bvi;
4109 mp->context = context;
4111 vl_msg_api_send_shmem (q, (u8 *)&mp);
4115 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4117 vpe_api_main_t * am = &vpe_api_main;
4118 bd_main_t * bdm = &bd_main;
4119 l2fib_entry_key_t *l2fe_key = NULL;
4120 l2fib_entry_result_t *l2fe_res = NULL;
4121 u32 ni, bd_id = ntohl (mp->bd_id);
4123 unix_shared_memory_queue_t * q;
4126 q = vl_api_client_index_to_input_queue (mp->client_index);
4130 /* see l2fib_table_dump: ~0 means "any" */
4134 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4141 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4143 vec_foreach_index (ni, l2fe_key) {
4144 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4145 vec_elt_at_index(l2fe_res, ni), mp->context);
4152 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4154 vl_api_show_version_reply_t *rmp;
4156 char * vpe_api_get_build_directory(void);
4157 char * vpe_api_get_version(void);
4158 char * vpe_api_get_build_date(void);
4160 unix_shared_memory_queue_t * q =
4161 vl_api_client_index_to_input_queue (mp->client_index);
4166 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4168 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4169 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4170 ARRAY_LEN(rmp->build_directory)-1);
4171 strncpy ((char *) rmp->version, vpe_api_get_version(),
4172 ARRAY_LEN(rmp->version)-1);
4173 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4174 ARRAY_LEN(rmp->build_date)-1);
4178 static void vl_api_get_node_index_t_handler
4179 (vl_api_get_node_index_t * mp)
4181 vlib_main_t * vm = vlib_get_main();
4182 vl_api_get_node_index_reply_t * rmp;
4185 u32 node_index = ~0;
4187 n = vlib_get_node_by_name (vm, mp->node_name);
4190 rv = VNET_API_ERROR_NO_SUCH_NODE;
4192 node_index = n->index;
4194 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4196 rmp->node_index = ntohl(node_index);
4200 static void vl_api_add_node_next_t_handler
4201 (vl_api_add_node_next_t * mp)
4203 vlib_main_t * vm = vlib_get_main();
4204 vl_api_add_node_next_reply_t * rmp;
4205 vlib_node_t * n, * next;
4207 u32 next_index = ~0;
4209 n = vlib_get_node_by_name (vm, mp->node_name);
4212 rv = VNET_API_ERROR_NO_SUCH_NODE;
4216 next = vlib_get_node_by_name (vm, mp->next_name);
4219 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4221 next_index = vlib_node_add_next (vm, n->index, next->index);
4224 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4226 rmp->next_index = ntohl(next_index);
4230 static void vl_api_l2tpv3_create_tunnel_t_handler
4231 (vl_api_l2tpv3_create_tunnel_t *mp)
4233 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4234 l2t_main_t *lm = &l2t_main;
4235 u32 sw_if_index = (u32)~0;
4238 if (mp->is_ipv6 != 1) {
4239 rv = VNET_API_ERROR_UNIMPLEMENTED;
4243 rv = create_l2tpv3_ipv6_tunnel (lm,
4244 (ip6_address_t *) mp->client_address,
4245 (ip6_address_t *) mp->our_address,
4246 ntohl(mp->local_session_id),
4247 ntohl(mp->remote_session_id),
4248 clib_net_to_host_u64(mp->local_cookie),
4249 clib_net_to_host_u64(mp->remote_cookie),
4250 mp->l2_sublayer_present,
4254 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4256 rmp->sw_if_index = ntohl (sw_if_index);
4260 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4261 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4263 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4264 l2t_main_t *lm = &l2t_main;
4267 VALIDATE_SW_IF_INDEX(mp);
4269 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4270 clib_net_to_host_u64(mp->new_local_cookie),
4271 clib_net_to_host_u64(mp->new_remote_cookie));
4273 BAD_SW_IF_INDEX_LABEL;
4275 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4278 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4279 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4282 vnet_main_t * vnm = vnet_get_main();
4283 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4285 VALIDATE_SW_IF_INDEX(mp);
4287 rv = l2tpv3_interface_enable_disable
4288 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4290 BAD_SW_IF_INDEX_LABEL;
4292 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4295 static void vl_api_l2tpv3_set_lookup_key_t_handler
4296 (vl_api_l2tpv3_set_lookup_key_t * mp)
4299 l2t_main_t *lm = &l2t_main;
4300 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4302 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4303 rv = VNET_API_ERROR_INVALID_VALUE;
4307 lm->lookup_type = mp->key;
4310 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4313 static void vl_api_vxlan_add_del_tunnel_t_handler
4314 (vl_api_vxlan_add_del_tunnel_t * mp)
4316 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4318 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4319 u32 encap_fib_index;
4321 ip4_main_t * im = &ip4_main;
4322 u32 sw_if_index = ~0;
4324 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4326 rv = VNET_API_ERROR_NO_SUCH_FIB;
4329 encap_fib_index = p[0];
4331 /* Check src & dst are different */
4332 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4333 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4334 rv = VNET_API_ERROR_SAME_SRC_DST;
4337 memset (a, 0, sizeof (*a));
4339 a->is_add = mp->is_add;
4340 a->is_ip6 = mp->is_ipv6;
4342 /* ip addresses sent in network byte order */
4344 memcpy(&(a->src.ip6), mp->src_address, 16);
4345 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4347 memcpy(&(a->src.ip4), mp->src_address, 4);
4348 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4351 a->encap_fib_index = encap_fib_index;
4352 a->decap_next_index = ntohl(mp->decap_next_index);
4353 a->vni = ntohl(mp->vni);
4354 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4357 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4359 rmp->sw_if_index = ntohl (sw_if_index);
4363 static void send_vxlan_tunnel_details
4364 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4366 vl_api_vxlan_tunnel_details_t * rmp;
4367 ip4_main_t * im4 = &ip4_main;
4368 ip6_main_t * im6 = &ip6_main;
4369 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4371 rmp = vl_msg_api_alloc (sizeof (*rmp));
4372 memset (rmp, 0, sizeof (*rmp));
4373 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4375 memcpy(rmp->src_address, &(t->src.ip6), 16);
4376 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4377 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4379 memcpy(rmp->src_address, &(t->src.ip4), 4);
4380 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4381 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4383 rmp->vni = htonl(t->vni);
4384 rmp->decap_next_index = htonl(t->decap_next_index);
4385 rmp->sw_if_index = htonl(t->sw_if_index);
4386 rmp->is_ipv6 = is_ipv6;
4387 rmp->context = context;
4389 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4392 static void vl_api_vxlan_tunnel_dump_t_handler
4393 (vl_api_vxlan_tunnel_dump_t * mp)
4395 unix_shared_memory_queue_t * q;
4396 vxlan_main_t * vxm = &vxlan_main;
4400 q = vl_api_client_index_to_input_queue (mp->client_index);
4405 sw_if_index = ntohl(mp->sw_if_index);
4407 if (~0 == sw_if_index) {
4408 pool_foreach (t, vxm->tunnels,
4410 send_vxlan_tunnel_details(t, q, mp->context);
4413 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4414 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4417 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4418 send_vxlan_tunnel_details(t, q, mp->context);
4422 static void vl_api_gre_add_del_tunnel_t_handler
4423 (vl_api_gre_add_del_tunnel_t * mp)
4425 vl_api_gre_add_del_tunnel_reply_t * rmp;
4427 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4430 ip4_main_t * im = &ip4_main;
4431 u32 sw_if_index = ~0;
4433 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4435 rv = VNET_API_ERROR_NO_SUCH_FIB;
4438 outer_table_id = p[0];
4440 /* Check src & dst are different */
4441 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4442 rv = VNET_API_ERROR_SAME_SRC_DST;
4446 memset (a, 0, sizeof (*a));
4448 a->is_add = mp->is_add;
4450 /* ip addresses sent in network byte order */
4451 a->src.as_u32 = mp->src_address;
4452 a->dst.as_u32 = mp->dst_address;
4454 a->outer_table_id = outer_table_id;
4455 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4458 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4460 rmp->sw_if_index = ntohl (sw_if_index);
4464 static void send_gre_tunnel_details
4465 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4467 vl_api_gre_tunnel_details_t * rmp;
4468 ip4_main_t * im = &ip4_main;
4470 rmp = vl_msg_api_alloc (sizeof (*rmp));
4471 memset (rmp, 0, sizeof (*rmp));
4472 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4473 rmp->src_address = t->tunnel_src.data_u32;
4474 rmp->dst_address = t->tunnel_dst.data_u32;
4475 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4476 rmp->sw_if_index = htonl(t->sw_if_index);
4477 rmp->context = context;
4479 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4482 static void vl_api_gre_tunnel_dump_t_handler
4483 (vl_api_gre_tunnel_dump_t * mp)
4485 unix_shared_memory_queue_t * q;
4486 gre_main_t * gm = &gre_main;
4490 q = vl_api_client_index_to_input_queue (mp->client_index);
4495 sw_if_index = ntohl(mp->sw_if_index);
4497 if (~0 == sw_if_index) {
4498 pool_foreach (t, gm->tunnels,
4500 send_gre_tunnel_details(t, q, mp->context);
4503 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4504 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4507 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4508 send_gre_tunnel_details(t, q, mp->context);
4513 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4515 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4517 vl_api_l2_patch_add_del_reply_t * rmp;
4518 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4522 VALIDATE_RX_SW_IF_INDEX(mp);
4523 VALIDATE_TX_SW_IF_INDEX(mp);
4525 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4526 ntohl(mp->tx_sw_if_index),
4527 (int)(mp->is_add != 0));
4529 BAD_RX_SW_IF_INDEX_LABEL;
4530 BAD_TX_SW_IF_INDEX_LABEL;
4532 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4536 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4537 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4539 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4541 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4542 u32 encap_fib_index, decap_fib_index;
4545 ip4_main_t * im = &ip4_main;
4546 u32 sw_if_index = ~0;
4549 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4551 rv = VNET_API_ERROR_NO_SUCH_FIB;
4554 encap_fib_index = p[0];
4556 protocol = ntohl(mp->protocol);
4558 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4559 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4560 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4562 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4565 decap_fib_index = p[0];
4567 decap_fib_index = ntohl(mp->decap_vrf_id);
4570 memset (a, 0, sizeof (*a));
4572 a->is_add = mp->is_add;
4573 /* ip addresses sent in network byte order */
4574 a->local.as_u32 = ntohl(mp->local);
4575 a->remote.as_u32 = ntohl(mp->remote);
4576 a->encap_fib_index = encap_fib_index;
4577 a->decap_fib_index = decap_fib_index;
4578 a->protocol = protocol;
4579 a->vni = ntohl(mp->vni);
4580 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4583 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4585 rmp->sw_if_index = ntohl (sw_if_index);
4590 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4592 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4594 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4596 u8 *locator_name = NULL;
4598 memset(a, 0, sizeof(a[0]));
4600 locator_name = format(0, "%s", mp->locator_set_name);
4602 a->name = locator_name;
4604 a->is_add = mp->is_add;
4607 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4609 vec_free(locator_name);
4611 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4615 vl_api_lisp_add_del_locator_t_handler(
4616 vl_api_lisp_add_del_locator_t *mp)
4618 vl_api_lisp_add_del_locator_reply_t *rmp;
4620 locator_t locator, *locators = NULL;
4621 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4623 u8 *locator_name = NULL;
4625 memset(&locator, 0, sizeof(locator));
4626 memset(a, 0, sizeof(a[0]));
4628 locator.sw_if_index = ntohl(mp->sw_if_index);
4629 locator.priority = mp->priority;
4630 locator.weight = mp->weight;
4632 vec_add1(locators, locator);
4634 locator_name = format(0, "%s", mp->locator_set_name);
4636 a->name = locator_name;
4637 a->locators = locators;
4638 a->is_add = mp->is_add;
4641 rv = vnet_lisp_add_del_locator(a, &ls_index);
4644 vec_free(locator_name);
4646 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4650 vl_api_lisp_add_del_local_eid_t_handler(
4651 vl_api_lisp_add_del_local_eid_t *mp)
4653 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4654 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4656 ip_prefix_t *prefp = NULL;
4657 ip_address_t *ip_eid = NULL;
4660 u32 locator_set_index = ~0, map_index = ~0;
4661 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4664 prefp = &gid_address_ippref(&eid);
4665 ip_eid = &ip_prefix_addr(prefp);
4666 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4669 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4670 sizeof(ip_addr_v6(ip_eid)));
4671 ip_addr_version(ip_eid) = IP6;
4673 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4674 sizeof(ip_addr_v4(ip_eid)));
4675 ip_addr_version(ip_eid) = IP4;
4677 ip_prefix_len(prefp) = mp->prefix_len;
4679 name = format(0, "%s", mp->locator_set_name);
4680 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4682 rv = VNET_API_ERROR_INVALID_VALUE;
4685 locator_set_index = p[0];
4687 /* XXX treat batch configuration */
4688 a->is_add = mp->is_add;
4690 a->locator_set_index = locator_set_index;
4693 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4698 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4702 lisp_gpe_add_del_fwd_entry_set_address(
4703 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4704 ip_address_t *slocator,
4705 ip_address_t *dlocator,
4708 ip_address_t *ip_eid = NULL;
4709 ip_prefix_t *prefp = NULL;
4711 prefp = &gid_address_ippref(eid);
4712 ip_eid = &ip_prefix_addr(prefp);
4714 if (mp->eid_is_ipv6) {
4715 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4716 sizeof(ip_addr_v6(ip_eid)));
4717 ip_addr_version(ip_eid) = IP6;
4719 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4720 sizeof(ip_addr_v4(ip_eid)));
4721 ip_addr_version(ip_eid) = IP4;
4723 ip_prefix_len(prefp) = mp->eid_prefix_len;
4725 if (mp->address_is_ipv6) {
4726 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4727 sizeof(ip_addr_v6(slocator)));
4728 ip_addr_version(slocator) = IP6;
4729 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4730 sizeof(ip_addr_v6(dlocator)));
4731 ip_addr_version(dlocator) = IP6;
4733 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4734 sizeof(ip_addr_v4(slocator)));
4735 ip_addr_version(slocator) = IP4;
4736 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4737 sizeof(ip_addr_v4(dlocator)));
4738 ip_addr_version(dlocator) = IP4;
4743 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4744 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4746 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4748 ip_address_t slocator, dlocator;
4750 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4752 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4754 memset (&a, 0, sizeof(a));
4756 a.is_add = mp->is_add;
4758 a.slocator = slocator;
4759 a.dlocator = dlocator;
4760 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4762 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4766 vl_api_lisp_add_del_map_resolver_t_handler(
4767 vl_api_lisp_add_del_map_resolver_t *mp)
4769 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4771 ip_address_t *ip_addr = NULL;
4772 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4774 a->is_add = mp->is_add;
4775 ip_addr = &a->address;
4778 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4779 sizeof(ip_addr_v6(ip_addr)));
4780 ip_addr_version(ip_addr) = IP6;
4782 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4783 sizeof(ip_addr_v4(ip_addr)));
4784 ip_addr_version(ip_addr) = IP4;
4787 rv = vnet_lisp_add_del_map_resolver (a);
4789 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4793 vl_api_lisp_gpe_enable_disable_t_handler(
4794 vl_api_lisp_gpe_enable_disable_t *mp)
4796 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4798 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4800 a->is_en = mp->is_en;
4801 vnet_lisp_gpe_enable_disable (a);
4803 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4807 vl_api_lisp_enable_disable_t_handler(
4808 vl_api_lisp_enable_disable_t *mp)
4810 vl_api_lisp_enable_disable_reply_t *rmp;
4813 vnet_lisp_enable_disable (mp->is_en);
4814 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4818 vl_api_lisp_gpe_add_del_iface_t_handler(
4819 vl_api_lisp_gpe_add_del_iface_t *mp)
4821 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4823 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4825 a->is_add = mp->is_add;
4826 a->table_id = mp->table_id;
4828 vnet_lisp_gpe_add_del_iface (a, 0);
4830 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4833 /** Used for transferring locators via VPP API */
4834 typedef CLIB_PACKED(struct
4836 u8 is_ip4; /**< is locator an IPv4 address */
4837 u8 addr[16]; /**< IPv4/IPv6 address */
4841 send_lisp_locator_set_details_set_address
4842 (vl_api_lisp_locator_set_details_t *rmp,
4843 gid_address_t *gid_address)
4845 ip_prefix_t *ip_addr;
4847 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4851 ip_addr = &gid_address_ippref(gid_address);
4852 rmp->prefix_len = ip_prefix_len(ip_addr);
4853 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4854 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4858 vl_api_lisp_add_del_remote_mapping_t_handler (
4859 vl_api_lisp_add_del_remote_mapping_t *mp)
4862 ip_address_t rloc, * rlocs = 0;
4863 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
4865 gid_address_t _seid, * seid = &_seid;
4866 gid_address_t _deid, * deid = &_deid;
4867 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
4868 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
4870 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
4871 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
4872 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
4873 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
4874 ip_prefix_len(seid_pref) = mp->seid_len;
4875 ip_prefix_len(deid_pref) = mp->deid_len;
4876 gid_address_set_vni (seid, ntohl (mp->vni));
4877 gid_address_set_vni (deid, ntohl (mp->vni));
4879 if (mp->eid_is_ip4) {
4880 ip_prefix_version(seid_pref) = IP4;
4881 ip_prefix_version(deid_pref) = IP4;
4882 clib_memcpy (&ip_addr_v4(seid_addr),
4883 mp->seid, sizeof (ip_addr_v4(seid_addr)));
4884 clib_memcpy (&ip_addr_v4(deid_addr),
4885 mp->deid, sizeof (ip_addr_v4(deid_addr)));
4887 ip_prefix_version(seid_pref) = IP6;
4888 ip_prefix_version(deid_pref) = IP6;
4889 clib_memcpy (&ip_addr_v6(seid_addr),
4890 mp->seid, sizeof (ip_addr_v6(seid_addr)));
4891 clib_memcpy (&ip_addr_v6(deid_addr),
4892 mp->deid, sizeof (ip_addr_v6(deid_addr)));
4895 for (i = 0; i < mp->rloc_num; i++) {
4896 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
4898 clib_memcpy (&ip_addr_v4(&rloc), &r->addr, sizeof (rloc_t));
4899 ip_addr_version (&rloc) = IP4;
4901 clib_memcpy (&ip_addr_v6(&rloc), &r->addr, sizeof (rloc_t));
4902 ip_addr_version (&rloc) = IP6;
4904 vec_add1 (rlocs, rloc);
4907 rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs,
4908 mp->action, mp->is_add);
4910 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4914 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4915 locator_set_t *lsit,
4916 unix_shared_memory_queue_t *q,
4920 vl_api_lisp_locator_set_details_t *rmp;
4921 locator_t *loc = NULL;
4925 vec_foreach (locit, lsit->locator_indices) {
4926 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4927 rmp = vl_msg_api_alloc (sizeof (*rmp));
4928 memset (rmp, 0, sizeof (*rmp));
4929 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4930 rmp->local = lsit->local;
4932 ASSERT(lsit->name != NULL);
4933 strncpy((char *) rmp->locator_set_name,
4934 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4935 rmp->sw_if_index = htonl(loc->sw_if_index);
4937 str = format(0, "remote-%d", index);
4938 strncpy((char *) rmp->locator_set_name, (char *) str,
4939 ARRAY_LEN(rmp->locator_set_name) - 1);
4940 send_lisp_locator_set_details_set_address(rmp, &loc->address);
4944 rmp->priority = loc->priority;
4945 rmp->weight = loc->weight;
4946 rmp->context = context;
4948 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4953 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4955 unix_shared_memory_queue_t * q = NULL;
4956 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4957 locator_set_t * lsit = NULL;
4960 q = vl_api_client_index_to_input_queue (mp->client_index);
4966 pool_foreach (lsit, lcm->locator_set_pool,
4968 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
4973 send_lisp_local_eid_table_details (mapping_t *mapit,
4974 unix_shared_memory_queue_t *q,
4977 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4978 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4979 locator_set_t *ls = NULL;
4980 gid_address_t *gid = NULL;
4981 ip_prefix_t *ip_prefix = NULL;
4985 ls = pool_elt_at_index (lcm->locator_set_pool,
4986 mapit->locator_set_index);
4989 type = gid_address_type(gid);
4991 if (type != GID_ADDR_IP_PREFIX) {
4995 ip_prefix = &gid_address_ippref(gid);
4997 rmp = vl_msg_api_alloc (sizeof (*rmp));
4998 memset (rmp, 0, sizeof (*rmp));
4999 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5001 ASSERT(ls->name != NULL);
5002 strncpy((char *) rmp->locator_set_name,
5003 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5005 str = format(0, "remote-%d", mapit->locator_set_index);
5006 strncpy((char *) rmp->locator_set_name, (char *) str,
5007 ARRAY_LEN(rmp->locator_set_name) - 1);
5011 switch (ip_prefix_version(ip_prefix)) {
5013 rmp->eid_is_ipv6 = 0;
5014 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5015 sizeof(ip_prefix_v4(ip_prefix)));
5019 rmp->eid_is_ipv6 = 1;
5020 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5021 sizeof(ip_prefix_v6(ip_prefix)));
5027 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5028 rmp->context = context;
5030 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5034 vl_api_lisp_local_eid_table_dump_t_handler (
5035 vl_api_lisp_local_eid_table_dump_t *mp)
5037 unix_shared_memory_queue_t * q = NULL;
5038 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5039 mapping_t * mapit = NULL;
5041 q = vl_api_client_index_to_input_queue (mp->client_index);
5046 pool_foreach (mapit, lcm->mapping_pool,
5048 send_lisp_local_eid_table_details(mapit, q, mp->context);
5053 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5054 unix_shared_memory_queue_t *q,
5057 vl_api_lisp_gpe_tunnel_details_t *rmp;
5058 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5060 rmp = vl_msg_api_alloc (sizeof (*rmp));
5061 memset (rmp, 0, sizeof (*rmp));
5062 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5064 rmp->tunnels = tunnel - lgm->tunnels;
5066 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5067 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5068 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5070 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5071 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5072 rmp->dcap_next = htonl(tunnel->decap_next_index);
5073 rmp->lisp_ver = tunnel->ver_res;
5074 rmp->next_protocol = tunnel->next_protocol;
5075 rmp->flags = tunnel->flags;
5076 rmp->ver_res = tunnel->ver_res;
5077 rmp->res = tunnel->res;
5078 rmp->iid = htonl(tunnel->vni);
5079 rmp->context = context;
5081 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5085 vl_api_lisp_gpe_tunnel_dump_t_handler (
5086 vl_api_lisp_local_eid_table_dump_t *mp)
5088 unix_shared_memory_queue_t * q = NULL;
5089 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5090 lisp_gpe_tunnel_t * tunnel = NULL;
5092 if (pool_elts(lgm->tunnels) == 0) {
5096 q = vl_api_client_index_to_input_queue (mp->client_index);
5101 pool_foreach(tunnel, lgm->tunnels,
5103 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5108 send_lisp_map_resolver_details (ip_address_t *ip,
5109 unix_shared_memory_queue_t *q,
5112 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5114 rmp = vl_msg_api_alloc (sizeof (*rmp));
5115 memset (rmp, 0, sizeof (*rmp));
5116 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5118 switch (ip_addr_version(ip)) {
5121 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5126 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5132 rmp->context = context;
5134 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5138 vl_api_lisp_map_resolver_dump_t_handler (
5139 vl_api_lisp_local_eid_table_dump_t *mp)
5141 unix_shared_memory_queue_t * q = NULL;
5142 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5143 ip_address_t *ip = NULL;
5145 q = vl_api_client_index_to_input_queue (mp->client_index);
5150 vec_foreach(ip, lcm->map_resolvers) {
5151 send_lisp_map_resolver_details(ip, q, mp->context);
5157 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5160 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5162 rmp = vl_msg_api_alloc (sizeof (*rmp));
5163 memset (rmp, 0, sizeof (*rmp));
5164 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5166 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5167 rmp->feature_status = vnet_lisp_enable_disable_status ();
5168 rmp->context = context;
5170 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5174 vl_api_lisp_enable_disable_status_dump_t_handler
5175 (vl_api_lisp_enable_disable_status_dump_t *mp)
5177 unix_shared_memory_queue_t * q = NULL;
5179 q = vl_api_client_index_to_input_queue (mp->client_index);
5184 send_lisp_enable_disable_details(q, mp->context);
5188 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5190 vl_api_interface_name_renumber_reply_t * rmp;
5193 VALIDATE_SW_IF_INDEX(mp);
5195 rv = vnet_interface_name_renumber
5196 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5198 BAD_SW_IF_INDEX_LABEL;
5200 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5203 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5204 u32 sw_if_index, u32 address)
5206 vpe_api_main_t * am = &vpe_api_main;
5207 vlib_main_t * vm = am->vlib_main;
5208 vl_api_ip4_arp_event_t * event;
5209 static f64 arp_event_last_time;
5210 f64 now = vlib_time_now (vm);
5212 if (pool_is_free_index (am->arp_events, pool_index))
5215 event = pool_elt_at_index (am->arp_events, pool_index);
5216 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5217 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5218 } else { /* same mac */
5219 if ((sw_if_index == event->sw_if_index) &&
5221 /* for BD case, also check IP address with 10 sec timeout */
5222 ((address == event->address) &&
5223 ((now - arp_event_last_time) < 10.0))))
5227 arp_event_last_time = now;
5228 event->sw_if_index = sw_if_index;
5229 if (address) event->address = address;
5233 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5235 vpe_api_main_t * am = &vpe_api_main;
5237 if (pool_is_free_index (am->arp_events, pool_index))
5240 pool_put_index (am->arp_events, pool_index);
5245 vl_api_want_ip4_arp_events_t_handler
5246 (vl_api_want_ip4_arp_events_t * mp)
5248 vpe_api_main_t * am = &vpe_api_main;
5249 vnet_main_t * vnm = vnet_get_main();
5250 vl_api_want_ip4_arp_events_reply_t *rmp;
5251 vl_api_ip4_arp_event_t * event;
5254 if (mp->enable_disable) {
5255 pool_get (am->arp_events, event);
5256 memset (event, 0, sizeof (*event));
5258 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5259 event->client_index = mp->client_index;
5260 event->context = mp->context;
5261 event->address = mp->address;
5262 event->pid = mp->pid;
5264 rv = vnet_add_del_ip4_arp_change_event
5265 (vnm, arp_change_data_callback,
5267 &mp->address /* addr, in net byte order */,
5268 vpe_resolver_process_node.index,
5269 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5271 rv = vnet_add_del_ip4_arp_change_event
5272 (vnm, arp_change_delete_callback,
5274 &mp->address /* addr, in net byte order */,
5275 vpe_resolver_process_node.index,
5276 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5278 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5281 static void vl_api_input_acl_set_interface_t_handler
5282 (vl_api_input_acl_set_interface_t * mp)
5284 vlib_main_t *vm = vlib_get_main();
5285 vl_api_input_acl_set_interface_reply_t * rmp;
5287 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5289 ip4_table_index = ntohl(mp->ip4_table_index);
5290 ip6_table_index = ntohl(mp->ip6_table_index);
5291 l2_table_index = ntohl(mp->l2_table_index);
5292 sw_if_index = ntohl(mp->sw_if_index);
5294 VALIDATE_SW_IF_INDEX(mp);
5296 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5297 ip6_table_index, l2_table_index,
5300 BAD_SW_IF_INDEX_LABEL;
5302 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5305 static void vl_api_ipsec_spd_add_del_t_handler
5306 (vl_api_ipsec_spd_add_del_t * mp)
5309 clib_warning ("unimplemented");
5312 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5313 vl_api_ipsec_spd_add_del_reply_t * rmp;
5317 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5319 rv = VNET_API_ERROR_UNIMPLEMENTED;
5322 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5326 static void vl_api_ipsec_interface_add_del_spd_t_handler
5327 (vl_api_ipsec_interface_add_del_spd_t * mp)
5329 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5330 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5332 u32 sw_if_index __attribute__((unused));
5333 u32 spd_id __attribute__((unused));
5335 sw_if_index = ntohl(mp->sw_if_index);
5336 spd_id = ntohl(mp->spd_id);
5338 VALIDATE_SW_IF_INDEX(mp);
5341 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5343 rv = VNET_API_ERROR_UNIMPLEMENTED;
5346 BAD_SW_IF_INDEX_LABEL;
5348 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5351 static void vl_api_ipsec_spd_add_del_entry_t_handler
5352 (vl_api_ipsec_spd_add_del_entry_t * mp)
5354 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5355 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5361 memset(&p, 0, sizeof(p));
5363 p.id = ntohl(mp->spd_id);
5364 p.priority = ntohl(mp->priority);
5365 p.is_outbound = mp->is_outbound;
5366 p.is_ipv6 = mp->is_ipv6;
5368 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5369 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5370 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5371 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5373 p.protocol = mp->protocol;
5374 p.rport.start = ntohs(mp->remote_port_start);
5375 p.rport.stop = ntohs(mp->remote_port_stop);
5376 p.lport.start = ntohs(mp->local_port_start);
5377 p.lport.stop = ntohs(mp->local_port_stop);
5378 /* policy action resolve unsupported */
5379 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5380 clib_warning("unsupported action: 'resolve'");
5381 rv = VNET_API_ERROR_UNIMPLEMENTED;
5384 p.policy = mp->policy;
5385 p.sa_id = ntohl(mp->sa_id);
5387 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5391 if (mp->is_ip_any) {
5393 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5396 rv = VNET_API_ERROR_UNIMPLEMENTED;
5401 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5404 static void vl_api_ipsec_sad_add_del_entry_t_handler
5405 (vl_api_ipsec_sad_add_del_entry_t * mp)
5407 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5408 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5413 memset(&sa, 0, sizeof(sa));
5415 sa.id = ntohl(mp->sad_id);
5416 sa.spi = ntohl(mp->spi);
5417 /* security protocol AH unsupported */
5418 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5419 clib_warning("unsupported security protocol 'AH'");
5420 rv = VNET_API_ERROR_UNIMPLEMENTED;
5423 sa.protocol = mp->protocol;
5424 /* check for unsupported crypto-alg */
5425 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5426 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5427 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5428 mp->crypto_algorithm);
5429 rv = VNET_API_ERROR_UNIMPLEMENTED;
5432 sa.crypto_alg = mp->crypto_algorithm;
5433 sa.crypto_key_len = mp->crypto_key_length;
5434 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5435 /* check for unsupported integ-alg */
5436 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5437 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5438 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5439 mp->integrity_algorithm);
5440 rv = VNET_API_ERROR_UNIMPLEMENTED;
5443 sa.integ_alg = mp->integrity_algorithm;
5444 sa.integ_key_len = mp->integrity_key_length;
5445 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5446 sa.use_esn = mp->use_extended_sequence_number;
5447 sa.is_tunnel = mp->is_tunnel;
5448 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5449 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5450 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5452 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5454 rv = VNET_API_ERROR_UNIMPLEMENTED;
5459 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5463 vl_api_ikev2_profile_add_del_t_handler
5464 (vl_api_ikev2_profile_add_del_t * mp)
5466 vl_api_ikev2_profile_add_del_reply_t * rmp;
5470 vlib_main_t * vm = vlib_get_main();
5471 clib_error_t * error;
5472 u8 * tmp = format(0, "%s", mp->name);
5473 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5476 rv = VNET_API_ERROR_UNSPECIFIED;
5478 rv = VNET_API_ERROR_UNIMPLEMENTED;
5481 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5485 vl_api_ikev2_profile_set_auth_t_handler
5486 (vl_api_ikev2_profile_set_auth_t * mp)
5488 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5492 vlib_main_t * vm = vlib_get_main();
5493 clib_error_t * error;
5494 u8 * tmp = format(0, "%s", mp->name);
5495 u8 * data = vec_new (u8, mp->data_len);
5496 clib_memcpy(data, mp->data, mp->data_len);
5497 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5501 rv = VNET_API_ERROR_UNSPECIFIED;
5503 rv = VNET_API_ERROR_UNIMPLEMENTED;
5506 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5510 vl_api_ikev2_profile_set_id_t_handler
5511 (vl_api_ikev2_profile_set_id_t * mp)
5513 vl_api_ikev2_profile_add_del_reply_t * rmp;
5517 vlib_main_t * vm = vlib_get_main();
5518 clib_error_t * error;
5519 u8 * tmp = format(0, "%s", mp->name);
5520 u8 * data = vec_new (u8, mp->data_len);
5521 clib_memcpy(data, mp->data, mp->data_len);
5522 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5526 rv = VNET_API_ERROR_UNSPECIFIED;
5528 rv = VNET_API_ERROR_UNIMPLEMENTED;
5531 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5535 vl_api_ikev2_profile_set_ts_t_handler
5536 (vl_api_ikev2_profile_set_ts_t * mp)
5538 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5542 vlib_main_t * vm = vlib_get_main();
5543 clib_error_t * error;
5544 u8 * tmp = format(0, "%s", mp->name);
5545 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5546 mp->end_port, (ip4_address_t) mp->start_addr,
5547 (ip4_address_t) mp->end_addr, mp->is_local);
5550 rv = VNET_API_ERROR_UNSPECIFIED;
5552 rv = VNET_API_ERROR_UNIMPLEMENTED;
5555 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5559 vl_api_ikev2_set_local_key_t_handler
5560 (vl_api_ikev2_set_local_key_t * mp)
5562 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5566 vlib_main_t * vm = vlib_get_main();
5567 clib_error_t * error;
5569 error = ikev2_set_local_key(vm, mp->key_file);
5571 rv = VNET_API_ERROR_UNSPECIFIED;
5573 rv = VNET_API_ERROR_UNIMPLEMENTED;
5576 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5580 vl_api_map_add_domain_t_handler
5581 (vl_api_map_add_domain_t * mp)
5583 vl_api_map_add_domain_reply_t * rmp;
5586 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5587 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5588 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5589 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5590 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5592 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5594 rmp->index = ntohl(index);
5599 vl_api_map_del_domain_t_handler
5600 (vl_api_map_del_domain_t * mp)
5602 vl_api_map_del_domain_reply_t * rmp;
5605 rv = map_delete_domain(ntohl(mp->index));
5607 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5611 vl_api_map_add_del_rule_t_handler
5612 (vl_api_map_add_del_rule_t * mp)
5614 vl_api_map_del_domain_reply_t * rmp;
5617 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5619 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5623 vl_api_map_domain_dump_t_handler
5624 (vl_api_map_domain_dump_t * mp)
5626 vl_api_map_domain_details_t * rmp;
5627 map_main_t *mm = &map_main;
5629 unix_shared_memory_queue_t * q;
5631 if (pool_elts (mm->domains) == 0)
5634 q = vl_api_client_index_to_input_queue (mp->client_index);
5639 pool_foreach(d, mm->domains, ({
5640 /* Make sure every field is initiated (or don't skip the memset()) */
5641 rmp = vl_msg_api_alloc (sizeof (*rmp));
5642 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5643 rmp->domain_index = htonl(d - mm->domains);
5644 rmp->ea_bits_len = d->ea_bits_len;
5645 rmp->psid_offset = d->psid_offset;
5646 rmp->psid_length = d->psid_length;
5647 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5648 rmp->ip4_prefix_len = d->ip4_prefix_len;
5649 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5650 rmp->ip6_prefix_len = d->ip6_prefix_len;
5651 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5652 rmp->ip6_src_len = d->ip6_src_len;
5653 rmp->mtu = htons(d->mtu);
5654 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5655 rmp->context = mp->context;
5657 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5662 vl_api_map_rule_dump_t_handler
5663 (vl_api_map_rule_dump_t * mp)
5665 unix_shared_memory_queue_t * q;
5668 vl_api_map_rule_details_t * rmp;
5669 map_main_t *mm = &map_main;
5670 u32 domain_index = ntohl(mp->domain_index);
5673 if (pool_elts (mm->domains) == 0)
5676 d = pool_elt_at_index(mm->domains, domain_index);
5677 if (!d || !d->rules) {
5681 q = vl_api_client_index_to_input_queue (mp->client_index);
5686 for (i = 0; i < (0x1 << d->psid_length); i++) {
5688 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5691 rmp = vl_msg_api_alloc(sizeof(*rmp));
5692 memset(rmp, 0, sizeof(*rmp));
5693 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5694 rmp->psid = htons(i);
5695 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5696 rmp->context = mp->context;
5697 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5702 vl_api_map_summary_stats_t_handler (
5703 vl_api_map_summary_stats_t *mp)
5705 vl_api_map_summary_stats_reply_t *rmp;
5706 vlib_combined_counter_main_t *cm;
5709 u64 total_pkts[VLIB_N_RX_TX];
5710 u64 total_bytes[VLIB_N_RX_TX];
5711 map_main_t *mm = &map_main;
5712 unix_shared_memory_queue_t *q =
5713 vl_api_client_index_to_input_queue(mp->client_index);
5718 rmp = vl_msg_api_alloc (sizeof (*rmp));
5719 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5720 rmp->context = mp->context;
5723 memset (total_pkts, 0, sizeof (total_pkts));
5724 memset (total_bytes, 0, sizeof (total_bytes));
5726 map_domain_counter_lock (mm);
5727 vec_foreach(cm, mm->domain_counters) {
5728 which = cm - mm->domain_counters;
5730 for (i = 0; i < vec_len(cm->maxi); i++) {
5731 vlib_get_combined_counter (cm, i, &v);
5732 total_pkts[which] += v.packets;
5733 total_bytes[which] += v.bytes;
5737 map_domain_counter_unlock (mm);
5739 /* Note: in network byte order! */
5740 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5741 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5742 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5743 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5744 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5745 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5746 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
5747 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
5749 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5752 static void vl_api_ipsec_sa_set_key_t_handler
5753 (vl_api_ipsec_sa_set_key_t * mp)
5755 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5756 vl_api_ipsec_sa_set_key_reply_t *rmp;
5760 sa.id = ntohl(mp->sa_id);
5761 sa.crypto_key_len = mp->crypto_key_length;
5762 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5763 sa.integ_key_len = mp->integrity_key_length;
5764 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5766 rv = ipsec_set_sa_key(vm, &sa);
5768 rv = VNET_API_ERROR_UNIMPLEMENTED;
5771 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5774 static void vl_api_cop_interface_enable_disable_t_handler
5775 (vl_api_cop_interface_enable_disable_t * mp)
5777 vl_api_cop_interface_enable_disable_reply_t * rmp;
5779 u32 sw_if_index = ntohl(mp->sw_if_index);
5782 VALIDATE_SW_IF_INDEX(mp);
5784 enable_disable = (int) mp->enable_disable;
5786 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5788 BAD_SW_IF_INDEX_LABEL;
5790 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5793 static void vl_api_cop_whitelist_enable_disable_t_handler
5794 (vl_api_cop_whitelist_enable_disable_t * mp)
5796 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5797 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5798 u32 sw_if_index = ntohl(mp->sw_if_index);
5801 VALIDATE_SW_IF_INDEX(mp);
5803 a->sw_if_index = sw_if_index;
5806 a->default_cop = mp->default_cop;
5807 a->fib_id = ntohl(mp->fib_id);
5809 rv = cop_whitelist_enable_disable (a);
5811 BAD_SW_IF_INDEX_LABEL;
5813 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5816 static void vl_api_get_node_graph_t_handler
5817 (vl_api_get_node_graph_t * mp)
5821 api_main_t * am = &api_main;
5822 vlib_main_t * vm = vlib_get_main();
5824 vl_api_get_node_graph_reply_t * rmp;
5826 pthread_mutex_lock (&am->vlib_rp->mutex);
5827 oldheap = svm_push_data_heap (am->vlib_rp);
5830 * Keep the number of memcpy ops to a minimum (e.g. 1).
5831 * The current size of the serialized vector is
5832 * slightly under 4K.
5834 vec_validate (vector, 4095);
5835 vec_reset_length (vector);
5837 vector = vlib_node_serialize (&vm->node_main, vector);
5839 svm_pop_heap (oldheap);
5840 pthread_mutex_unlock (&am->vlib_rp->mutex);
5842 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5843 rmp->reply_in_shmem = (uword) vector);
5846 static void vl_api_trace_profile_add_t_handler
5847 (vl_api_trace_profile_add_t *mp)
5850 vl_api_trace_profile_add_reply_t * rmp;
5851 clib_error_t *error;
5853 /* Ignoring the profile id as currently a single profile
5855 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5856 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5857 mp->pow_enable, mp->trace_tsp,
5860 clib_error_report(error);
5861 rv = clib_error_get_code(error);
5864 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5867 static void vl_api_trace_profile_apply_t_handler
5868 (vl_api_trace_profile_apply_t *mp)
5871 vl_api_trace_profile_apply_reply_t * rmp;
5873 if (mp->enable != 0) {
5874 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5875 ntohl(mp->prefix_length),
5877 mp->trace_op == IOAM_HBYH_ADD,
5878 mp->trace_op == IOAM_HBYH_POP,
5879 mp->trace_op == IOAM_HBYH_MOD);
5881 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5883 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5886 static void vl_api_trace_profile_del_t_handler
5887 (vl_api_trace_profile_del_t *mp)
5890 vl_api_trace_profile_del_reply_t * rmp;
5891 clib_error_t *error;
5893 error = clear_ioam_rewrite_fn();
5895 clib_error_report(error);
5896 rv = clib_error_get_code(error);
5899 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5903 vl_api_af_packet_create_t_handler
5904 (vl_api_af_packet_create_t *mp)
5906 vlib_main_t *vm = vlib_get_main();
5907 vl_api_af_packet_create_reply_t *rmp;
5909 u8 *host_if_name = NULL;
5911 host_if_name = format(0, "%s", mp->host_if_name);
5912 vec_add1 (host_if_name, 0);
5914 rv = af_packet_create_if(vm, host_if_name,
5915 mp->use_random_hw_addr ? 0 : mp->hw_addr);
5917 vec_free(host_if_name);
5919 REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
5923 vl_api_af_packet_delete_t_handler
5924 (vl_api_af_packet_delete_t *mp)
5926 vlib_main_t * vm = vlib_get_main();
5927 vl_api_af_packet_delete_reply_t *rmp;
5929 u8 *host_if_name = NULL;
5931 host_if_name = format(0, "%s", mp->host_if_name);
5932 vec_add1 (host_if_name, 0);
5934 rv = af_packet_delete_if(vm, host_if_name);
5936 vec_free(host_if_name);
5938 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
5942 vl_api_policer_add_del_t_handler
5943 (vl_api_policer_add_del_t *mp)
5945 vlib_main_t * vm = vlib_get_main();
5946 vl_api_policer_add_del_reply_t *rmp;
5949 sse2_qos_pol_cfg_params_st cfg;
5950 clib_error_t * error;
5952 name = format(0, "%s", mp->name);
5954 memset (&cfg, 0, sizeof (cfg));
5956 cfg.rnd_type = mp->round_type;
5957 cfg.rate_type = mp->rate_type;
5958 cfg.rb.kbps.cir_kbps = mp->cir;
5959 cfg.rb.kbps.eir_kbps = mp->eir;
5960 cfg.rb.kbps.cb_bytes = mp->cb;
5961 cfg.rb.kbps.eb_bytes = mp->eb;
5963 error = policer_add_del(vm, name, &cfg, mp->is_add);
5966 rv = VNET_API_ERROR_UNSPECIFIED;
5968 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
5972 send_policer_details (u8 *name,
5973 sse2_qos_pol_cfg_params_st *config,
5974 policer_read_response_type_st *templ,
5975 unix_shared_memory_queue_t *q,
5978 vl_api_policer_details_t * mp;
5980 mp = vl_msg_api_alloc (sizeof (*mp));
5981 memset (mp, 0, sizeof (*mp));
5982 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
5983 mp->context = context;
5984 mp->cir = htonl(config->rb.kbps.cir_kbps);
5985 mp->eir = htonl(config->rb.kbps.eir_kbps);
5986 mp->cb = htonl(config->rb.kbps.cb_bytes);
5987 mp->eb = htonl(config->rb.kbps.eb_bytes);
5988 mp->rate_type = config->rate_type;
5989 mp->round_type = config->rnd_type;
5990 mp->type = config->rfc;
5991 mp->single_rate = templ->single_rate ? 1 : 0;
5992 mp->color_aware = templ->color_aware ? 1 : 0;
5993 mp->scale = htonl(templ->scale);
5994 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
5995 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
5996 mp->current_limit = htonl(templ->current_limit);
5997 mp->current_bucket = htonl(templ->current_bucket);
5998 mp->extended_limit = htonl(templ->extended_limit);
5999 mp->extended_bucket = htonl(templ->extended_bucket);
6000 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6002 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6004 vl_msg_api_send_shmem (q, (u8 *)&mp);
6008 vl_api_policer_dump_t_handler
6009 (vl_api_policer_dump_t *mp)
6011 unix_shared_memory_queue_t * q;
6012 vnet_policer_main_t * pm = &vnet_policer_main;
6016 u8 * match_name = 0;
6018 sse2_qos_pol_cfg_params_st *config;
6019 policer_read_response_type_st *templ;
6021 q = vl_api_client_index_to_input_queue (mp->client_index);
6025 if (mp->match_name_valid) {
6026 match_name = format(0, "%s%c", mp->match_name, 0);
6029 if (mp->match_name_valid) {
6030 p = hash_get_mem (pm->policer_config_by_name, match_name);
6033 config = pool_elt_at_index (pm->configs, pool_index);
6034 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6035 send_policer_details(match_name, config, templ, q, mp->context);
6038 hash_foreach_pair (hp, pm->policer_config_by_name,
6040 name = (u8 *) hp->key;
6041 pool_index = hp->value[0];
6042 config = pool_elt_at_index (pm->configs, pool_index);
6043 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6044 send_policer_details(name, config, templ, q, mp->context);
6050 vl_api_netmap_create_t_handler
6051 (vl_api_netmap_create_t *mp)
6053 vlib_main_t *vm = vlib_get_main();
6054 vl_api_netmap_create_reply_t *rmp;
6058 if_name = format(0, "%s", mp->netmap_if_name);
6059 vec_add1 (if_name, 0);
6061 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6062 mp->is_pipe, mp->is_master);
6066 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6070 vl_api_netmap_delete_t_handler
6071 (vl_api_netmap_delete_t *mp)
6073 vlib_main_t * vm = vlib_get_main();
6074 vl_api_netmap_delete_reply_t *rmp;
6078 if_name = format(0, "%s", mp->netmap_if_name);
6079 vec_add1 (if_name, 0);
6081 rv = netmap_delete_if(vm, if_name);
6085 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6088 #define BOUNCE_HANDLER(nn) \
6089 static void vl_api_##nn##_t_handler ( \
6090 vl_api_##nn##_t *mp) \
6092 vpe_client_registration_t *reg; \
6093 vpe_api_main_t * vam = &vpe_api_main; \
6094 unix_shared_memory_queue_t * q; \
6096 /* One registration only... */ \
6097 pool_foreach(reg, vam->nn##_registrations, \
6099 q = vl_api_client_index_to_input_queue (reg->client_index); \
6102 * If the queue is stuffed, turf the msg and complain \
6103 * It's unlikely that the intended recipient is \
6104 * alive; avoid deadlock at all costs. \
6106 if (q->cursize == q->maxsize) { \
6107 clib_warning ("ERROR: receiver queue full, drop msg"); \
6108 vl_msg_api_free (mp); \
6111 vl_msg_api_send_shmem (q, (u8 *)&mp); \
6115 vl_msg_api_free (mp); \
6120 * Add vpe's API message handlers to the table.
6121 * vlib has alread mapped shared memory and
6122 * added the client registration handlers.
6123 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
6126 static clib_error_t *
6127 vpe_api_hookup (vlib_main_t *vm)
6129 api_main_t * am = &api_main;
6132 vl_msg_api_set_handlers(VL_API_##N, #n, \
6133 vl_api_##n##_t_handler, \
6135 vl_api_##n##_t_endian, \
6136 vl_api_##n##_t_print, \
6137 sizeof(vl_api_##n##_t), 1);
6138 foreach_vpe_api_msg;
6142 * Manually register the sr tunnel add del msg, so we trace
6143 * enough bytes to capture a typical segment list
6145 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6146 "sr_tunnel_add_del",
6147 vl_api_sr_tunnel_add_del_t_handler,
6149 vl_api_sr_tunnel_add_del_t_endian,
6150 vl_api_sr_tunnel_add_del_t_print,
6155 * Manually register the sr policy add del msg, so we trace
6156 * enough bytes to capture a typical tunnel name list
6158 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6159 "sr_policy_add_del",
6160 vl_api_sr_policy_add_del_t_handler,
6162 vl_api_sr_policy_add_del_t_endian,
6163 vl_api_sr_policy_add_del_t_print,
6167 * Trace space for 8 MPLS encap labels, classifier mask+match
6169 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6170 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6171 += 5 * sizeof (u32x4);
6172 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6173 += 5 * sizeof (u32x4);
6174 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6175 += 16 * sizeof (u32);
6178 * Thread-safe API messages
6180 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6185 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6187 static clib_error_t *
6188 vpe_api_init (vlib_main_t *vm)
6190 vpe_api_main_t *am = &vpe_api_main;
6193 am->vnet_main = vnet_get_main();
6194 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6195 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6196 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6197 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6198 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6199 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6202 vl_set_memory_region_name ("/vpe-api");
6203 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6208 VLIB_INIT_FUNCTION(vpe_api_init);
6210 static clib_error_t *
6211 chroot_config (vlib_main_t * vm, unformat_input_t * input)
6215 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6217 if (unformat (input, "prefix %s", &chroot_path))
6219 vec_add1 (chroot_path, 0);
6220 vl_set_memory_root_path ((char *)chroot_path);
6223 return clib_error_return (0, "unknown input `%U'",
6224 format_unformat_error, input);
6228 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6230 void * get_unformat_vnet_sw_interface (void)
6232 return (void *) &unformat_vnet_sw_interface;
6235 #undef vl_api_version
6236 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6237 #include <api/vpe.api.h>
6238 #undef vl_api_version
6240 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6242 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6243 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6244 clib_host_to_net_u32 (mp->api_versions[0]),
6251 static u8 * format_arp_event (u8 * s, va_list * args)
6253 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6255 s = format (s, "pid %d: %U", event->pid,
6256 format_ip4_address, &event->address);
6260 static clib_error_t *
6261 show_ip4_arp_events_fn (vlib_main_t * vm,
6262 unformat_input_t * input,
6263 vlib_cli_command_t * cmd)
6265 vpe_api_main_t * am = &vpe_api_main;
6266 vl_api_ip4_arp_event_t * event;
6268 if (pool_elts (am->arp_events) == 0) {
6269 vlib_cli_output (vm, "No active arp event registrations");
6273 pool_foreach (event, am->arp_events,
6275 vlib_cli_output (vm, "%U", format_arp_event, event);
6281 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6282 .path = "show arp event registrations",
6283 .function = show_ip4_arp_events_fn,
6284 .short_help = "Show arp event registrations",