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_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
333 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
334 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
335 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
336 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
337 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
338 lisp_enable_disable_status_dump) \
339 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
340 _(AF_PACKET_CREATE, af_packet_create) \
341 _(AF_PACKET_DELETE, af_packet_delete) \
342 _(POLICER_ADD_DEL, policer_add_del) \
343 _(POLICER_DUMP, policer_dump) \
344 _(NETMAP_CREATE, netmap_create) \
345 _(NETMAP_DELETE, netmap_delete)
348 #define QUOTE(x) QUOTE_(x)
350 #define foreach_registration_hash \
351 _(interface_events) \
352 _(to_netconf_server) \
353 _(from_netconf_server) \
354 _(to_netconf_client) \
355 _(from_netconf_client) \
359 RESOLVE_IP4_ADD_DEL_ROUTE=1,
360 RESOLVE_IP6_ADD_DEL_ROUTE,
361 RESOLVE_MPLS_ETHERNET_ADD_DEL,
367 vl_api_ip_add_del_route_t r;
368 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
374 #define _(a) uword *a##_registration_hash; \
375 vpe_client_registration_t * a##_registrations;
376 foreach_registration_hash
379 /* notifications happen really early in the game */
380 u8 link_state_process_up;
382 /* ip4 pending route adds */
383 pending_route_t * pending_routes;
385 /* ip4 arp event registration pool */
386 vl_api_ip4_arp_event_t * arp_events;
389 vlib_main_t * vlib_main;
390 vnet_main_t * vnet_main;
393 static vlib_node_registration_t vpe_resolver_process_node;
394 static vpe_api_main_t vpe_api_main;
396 static void send_sw_interface_flags (vpe_api_main_t * am,
397 unix_shared_memory_queue_t *q,
398 vnet_sw_interface_t * swif);
399 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
400 unix_shared_memory_queue_t *q,
403 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
406 /* Clean up all registrations belonging to the indicated client */
407 int vl_api_memclnt_delete_callback (u32 client_index)
409 vpe_api_main_t * vam = &vpe_api_main;
410 vpe_client_registration_t *rp;
412 int stats_memclnt_delete_callback (u32 client_index);
414 stats_memclnt_delete_callback (client_index);
417 p = hash_get (vam->a##_registration_hash, client_index); \
419 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
420 pool_put (vam->a##_registrations, rp); \
421 hash_unset (vam->a##_registration_hash, client_index); \
423 foreach_registration_hash;
428 #define API_LINK_STATE_EVENT 1
429 #define API_ADMIN_UP_DOWN_EVENT 2
432 event_data_cmp (void * a1, void * a2)
437 return (word) e1[0] - (word) e2[0];
441 link_state_process (vlib_main_t * vm,
442 vlib_node_runtime_t * rt,
445 vpe_api_main_t * vam = &vpe_api_main;
446 vnet_main_t * vnm = vam->vnet_main;
447 vnet_sw_interface_t * swif;
448 uword * event_data = 0;
449 vpe_client_registration_t *reg;
451 u32 prev_sw_if_index;
452 unix_shared_memory_queue_t * q;
454 vam->link_state_process_up = 1;
457 vlib_process_wait_for_event (vm);
459 /* Unified list of changed link or admin state sw_if_indices */
460 vlib_process_get_events_with_type
461 (vm, &event_data, API_LINK_STATE_EVENT);
462 vlib_process_get_events_with_type
463 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
465 /* Sort, so we can eliminate duplicates */
466 vec_sort_with_function (event_data, event_data_cmp);
468 prev_sw_if_index = ~0;
470 for (i = 0; i < vec_len(event_data); i++) {
471 /* Only one message per swif */
472 if (prev_sw_if_index == event_data[i])
474 prev_sw_if_index = event_data[i];
476 pool_foreach(reg, vam->interface_events_registrations,
478 q = vl_api_client_index_to_input_queue (reg->client_index);
480 // sw_interface may be deleted already
481 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
484 swif = vnet_get_sw_interface (vnm, event_data[i]);
485 send_sw_interface_flags (vam, q, swif);
490 vec_reset_length (event_data);
496 static clib_error_t *
497 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
498 static clib_error_t *
499 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
501 VLIB_REGISTER_NODE (link_state_process_node,static) = {
502 .function = link_state_process,
503 .type = VLIB_NODE_TYPE_PROCESS,
504 .name = "vpe-link-state-process",
507 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
508 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
510 static clib_error_t *
511 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
513 vpe_api_main_t * vam = &vpe_api_main;
514 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
516 if (vam->link_state_process_up)
517 vlib_process_signal_event (vam->vlib_main,
518 link_state_process_node.index,
519 API_LINK_STATE_EVENT,
524 static clib_error_t *
525 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
527 vpe_api_main_t * vam = &vpe_api_main;
530 * Note: it's perfectly fair to set a subif admin up / admin down.
531 * Note the subtle distinction between this routine and the previous
534 if (vam->link_state_process_up)
535 vlib_process_signal_event (vam->vlib_main,
536 link_state_process_node.index,
537 API_ADMIN_UP_DOWN_EVENT,
542 #define pub_sub_handler(lca,UCA) \
543 static void vl_api_want_##lca##_t_handler ( \
544 vl_api_want_##lca##_t *mp) \
546 vpe_api_main_t *vam = &vpe_api_main; \
547 vpe_client_registration_t *rp; \
548 vl_api_want_##lca##_reply_t *rmp; \
552 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
554 if (mp->enable_disable) { \
555 clib_warning ("pid %d: already enabled...", mp->pid); \
556 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
559 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
560 pool_put (vam->lca##_registrations, rp); \
561 hash_unset (vam->lca##_registration_hash, \
566 if (mp->enable_disable == 0) { \
567 clib_warning ("pid %d: already disabled...", mp->pid); \
568 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
571 pool_get (vam->lca##_registrations, rp); \
572 rp->client_index = mp->client_index; \
573 rp->client_pid = mp->pid; \
574 hash_set (vam->lca##_registration_hash, rp->client_index, \
575 rp - vam->lca##_registrations); \
578 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
581 pub_sub_handler (interface_events,INTERFACE_EVENTS)
582 pub_sub_handler (oam_events,OAM_EVENTS)
584 #define RESOLUTION_EVENT 1
585 #define RESOLUTION_PENDING_EVENT 2
586 #define IP4_ARP_EVENT 3
588 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
589 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
590 static int mpls_ethernet_add_del_tunnel_2_t_handler
591 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
593 void handle_ip4_arp_event (u32 pool_index)
595 vpe_api_main_t * vam = &vpe_api_main;
596 vnet_main_t * vnm = vam->vnet_main;
597 vlib_main_t * vm = vam->vlib_main;
598 vl_api_ip4_arp_event_t * event;
599 vl_api_ip4_arp_event_t * mp;
600 unix_shared_memory_queue_t * q;
602 /* Client can cancel, die, etc. */
603 if (pool_is_free_index (vam->arp_events, pool_index))
606 event = pool_elt_at_index (vam->arp_events, pool_index);
608 q = vl_api_client_index_to_input_queue (event->client_index);
610 (void) vnet_add_del_ip4_arp_change_event
611 (vnm, arp_change_delete_callback,
612 event->pid, &event->address,
613 vpe_resolver_process_node.index, IP4_ARP_EVENT,
614 ~0 /* pool index, notused */, 0 /* is_add */);
618 if (q->cursize < q->maxsize) {
619 mp = vl_msg_api_alloc (sizeof (*mp));
620 clib_memcpy (mp, event, sizeof (*mp));
621 vl_msg_api_send_shmem (q, (u8 *)&mp);
623 static f64 last_time;
625 * Throttle syslog msgs.
626 * It's pretty tempting to just revoke the registration...
628 if (vlib_time_now (vm) > last_time + 10.0) {
629 clib_warning ("arp event for %U to pid %d: queue stuffed!",
630 format_ip4_address, &event->address, event->pid);
631 last_time = vlib_time_now(vm);
637 resolver_process (vlib_main_t * vm,
638 vlib_node_runtime_t * rt,
642 uword *event_data = 0;
644 vpe_api_main_t * vam = &vpe_api_main;
645 pending_route_t * pr;
646 vl_api_ip_add_del_route_t * adr;
647 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
648 u32 * resolution_failures = 0;
653 vlib_process_wait_for_event_or_clock (vm, timeout);
655 event_type = vlib_process_get_events (vm, &event_data);
657 switch (event_type) {
658 case RESOLUTION_PENDING_EVENT:
662 case RESOLUTION_EVENT:
663 for (i = 0; i < vec_len(event_data); i++) {
665 * Resolution events can occur long after the
666 * original request has timed out. $$$ add a cancel
669 if (pool_is_free_index (vam->pending_routes, event_data[i]))
672 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
676 switch (pr->resolve_type) {
677 case RESOLVE_IP4_ADD_DEL_ROUTE:
678 rv = ip4_add_del_route_t_handler (adr);
679 clib_warning ("resolver: add %U/%d via %U %s",
681 (ip4_address_t *)&(adr->dst_address),
682 adr->dst_address_length,
684 (ip4_address_t *)&(adr->next_hop_address),
685 (rv >= 0) ? "succeeded" : "failed");
688 case RESOLVE_IP6_ADD_DEL_ROUTE:
689 rv = ip6_add_del_route_t_handler (adr);
690 clib_warning ("resolver: add %U/%d via %U %s",
692 (ip6_address_t *)&(adr->dst_address),
693 adr->dst_address_length,
695 (ip6_address_t *)&(adr->next_hop_address),
696 (rv >= 0) ? "succeeded" : "failed");
699 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
700 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
701 clib_warning ("resolver: add mpls-o-e via %U %s",
703 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
704 (rv >= 0) ? "succeeded" : "failed");
708 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
710 pool_put (vam->pending_routes, pr);
715 for (i = 0; i < vec_len(event_data); i++)
716 handle_ip4_arp_event (event_data[i]);
719 case ~0: /* timeout, retry pending resolutions */
720 pool_foreach (pr, vam->pending_routes,
726 /* May fail, e.g. due to interface down */
727 switch (pr->resolve_type) {
728 case RESOLVE_IP4_ADD_DEL_ROUTE:
729 e = ip4_probe_neighbor
730 (vm, (ip4_address_t *)&(adr->next_hop_address),
731 ntohl(adr->next_hop_sw_if_index));
734 case RESOLVE_IP6_ADD_DEL_ROUTE:
735 e = ip6_probe_neighbor
736 (vm, (ip6_address_t *)&(adr->next_hop_address),
737 ntohl(adr->next_hop_sw_if_index));
740 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
742 e = ip4_probe_neighbor
744 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
745 pme->resolve_opaque);
749 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
753 clib_error_report (e);
755 adr->resolve_attempts = 1;
757 pme->resolve_attempts = 1;
761 adr->resolve_attempts -= 1;
762 if (adr->resolve_attempts == 0)
763 vec_add1 (resolution_failures,
764 pr - vam->pending_routes);
766 pme->resolve_attempts -= 1;
767 if (pme->resolve_attempts == 0)
768 vec_add1 (resolution_failures,
769 pr - vam->pending_routes);
773 for (i = 0; i < vec_len (resolution_failures); i++) {
774 pr = pool_elt_at_index (vam->pending_routes,
775 resolution_failures[i]);
779 switch (pr->resolve_type) {
780 case RESOLVE_IP4_ADD_DEL_ROUTE:
781 clib_warning ("resolver: add %U/%d via %U retry failure",
783 (ip4_address_t *)&(adr->dst_address),
784 adr->dst_address_length,
786 (ip4_address_t *)&(adr->next_hop_address));
789 case RESOLVE_IP6_ADD_DEL_ROUTE:
790 clib_warning ("resolver: add %U/%d via %U retry failure",
792 (ip6_address_t *)&(adr->dst_address),
793 adr->dst_address_length,
795 (ip6_address_t *)&(adr->next_hop_address));
798 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
799 clib_warning ("resolver: add mpls-o-e via %U retry failure",
801 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
805 clib_warning ("BUG");
807 pool_put(vam->pending_routes, pr);
809 vec_reset_length (resolution_failures);
812 if (pool_elts (vam->pending_routes) == 0)
814 vec_reset_length (event_data);
816 return 0; /* or not */
819 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
820 .function = resolver_process,
821 .type = VLIB_NODE_TYPE_PROCESS,
822 .name = "vpe-route-resolver-process",
825 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
827 ip4_main_t * im = &ip4_main;
828 ip_lookup_main_t * lm = &im->lookup_main;
829 vnet_classify_main_t * cm = &vnet_classify_main;
830 stats_main_t * sm = &stats_main;
831 ip4_add_del_route_args_t a;
832 ip4_address_t next_hop_address;
834 vpe_api_main_t * vam = &vpe_api_main;
835 vnet_main_t * vnm = vam->vnet_main;
836 vlib_main_t * vm = vlib_get_main();
837 pending_route_t * pr;
838 vl_api_ip_add_del_route_t * adr;
842 ip_adjacency_t *nh_adj, *add_adj = 0;
844 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
846 if (mp->create_vrf_if_needed) {
848 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
850 fib_index = f->index;
852 /* No such VRF, and we weren't asked to create one */
853 return VNET_API_ERROR_NO_SUCH_FIB;
859 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
860 ntohl(mp->next_hop_sw_if_index)))
861 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
863 clib_memcpy (next_hop_address.data, mp->next_hop_address,
864 sizeof (next_hop_address.data));
866 /* Arp for the next_hop if necessary */
867 if (mp->is_add && mp->resolve_if_needed) {
869 ip_adjacency_t * adj;
871 lookup_result = ip4_fib_lookup_with_table
872 (im, fib_index, &next_hop_address, 1 /* disable default route */);
874 adj = ip_get_adjacency (lm, lookup_result);
876 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
877 pool_get (vam->pending_routes, pr);
878 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
880 clib_memcpy (adr, mp, sizeof (*adr));
881 /* recursion block, "just in case" */
882 adr->resolve_if_needed = 0;
883 adr->resolve_attempts = ntohl(mp->resolve_attempts);
884 vnet_register_ip4_arp_resolution_event
885 (vnm, &next_hop_address, vpe_resolver_process_node.index,
886 RESOLUTION_EVENT, pr - vam->pending_routes);
888 vlib_process_signal_event
889 (vm, vpe_resolver_process_node.index,
890 RESOLUTION_PENDING_EVENT, 0 /* data */);
892 /* The interface may be down, etc. */
893 e = ip4_probe_neighbor
894 (vm, (ip4_address_t *)&(mp->next_hop_address),
895 ntohl(mp->next_hop_sw_if_index));
898 clib_error_report(e);
900 return VNET_API_ERROR_IN_PROGRESS;
904 if (mp->is_multipath) {
907 dslock (sm, 1 /* release hint */, 10 /* tag */);
910 flags = IP4_ROUTE_FLAG_ADD;
912 flags = IP4_ROUTE_FLAG_DEL;
915 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
917 ip4_add_del_route_next_hop (im, flags,
918 (ip4_address_t *) mp->dst_address,
919 (u32) mp->dst_address_length,
920 (ip4_address_t *) mp->next_hop_address,
921 ntohl(mp->next_hop_sw_if_index),
922 (u32) mp->next_hop_weight,
929 memset (&a, 0, sizeof (a));
930 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
932 a.dst_address_length = mp->dst_address_length;
934 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
935 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
936 a.table_index_or_table_id = fib_index;
941 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
943 dslock (sm, 1 /* release hint */, 2 /* tag */);
947 ai = lm->drop_adj_index;
948 else if (mp->is_local)
949 ai = lm->local_adj_index;
950 else if (mp->is_classify) {
952 memset(&cadj, 0, sizeof(cadj));
953 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
954 cadj.classify.table_index = ntohl(mp->classify_table_index);
955 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
957 return VNET_API_ERROR_NO_SUCH_TABLE;
959 vec_add1 (add_adj, cadj);
963 ai = ip4_fib_lookup_with_table
964 (im, fib_index, &next_hop_address,
965 1 /* disable default route */);
966 if (ai == lm->miss_adj_index) {
968 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
972 nh_adj = ip_get_adjacency (lm, ai);
973 vec_add1 (add_adj, nh_adj[0]);
974 if (mp->lookup_in_vrf) {
975 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
977 add_adj[0].explicit_fib_index = p[0];
981 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
985 ip_adjacency_t * adj;
986 int disable_default_route = 1;
988 /* Trying to delete the default route? */
989 if (a.dst_address.as_u32 == 0 &&
990 a.dst_address_length == 0)
991 disable_default_route = 0;
993 ai = ip4_fib_lookup_with_table
994 (im, fib_index, &a.dst_address, disable_default_route);
995 if (ai == lm->miss_adj_index) {
997 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1000 adj = ip_get_adjacency (lm, ai);
1001 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1003 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1009 a.add_adj = add_adj;
1010 a.n_add_adj = vec_len(add_adj);
1011 ip4_add_del_route (im, &a);
1019 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1021 ip6_main_t * im = &ip6_main;
1022 ip_lookup_main_t * lm = &im->lookup_main;
1023 vnet_main_t * vnm = vnet_get_main();
1024 vlib_main_t * vm = vlib_get_main();
1025 vpe_api_main_t * vam = &vpe_api_main;
1026 stats_main_t * sm = &stats_main;
1027 ip6_add_del_route_args_t a;
1028 ip6_address_t next_hop_address;
1029 pending_route_t * pr;
1030 vl_api_ip_add_del_route_t * adr;
1035 ip_adjacency_t * nh_adj, * add_adj = 0;
1038 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1041 if (mp->create_vrf_if_needed) {
1043 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1045 fib_index = f->index;
1047 /* No such VRF, and we weren't asked to create one */
1048 return VNET_API_ERROR_NO_SUCH_FIB;
1054 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1055 ntohl(mp->next_hop_sw_if_index)))
1056 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1058 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1059 sizeof (next_hop_address.as_u8));
1061 /* Arp for the next_hop if necessary */
1062 if (mp->is_add && mp->resolve_if_needed) {
1064 ip_adjacency_t * adj;
1066 lookup_result = ip6_fib_lookup_with_table
1067 (im, fib_index, &next_hop_address);
1069 adj = ip_get_adjacency (lm, lookup_result);
1071 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1072 pool_get (vam->pending_routes, pr);
1074 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1075 clib_memcpy (adr, mp, sizeof (*adr));
1076 /* recursion block, "just in case" */
1077 adr->resolve_if_needed = 0;
1078 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1079 vnet_register_ip6_neighbor_resolution_event
1080 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1081 RESOLUTION_EVENT, pr - vam->pending_routes);
1083 vlib_process_signal_event
1084 (vm, vpe_resolver_process_node.index,
1085 RESOLUTION_PENDING_EVENT, 0 /* data */);
1087 /* The interface may be down, etc. */
1088 e = ip6_probe_neighbor
1089 (vm, (ip6_address_t *)&(mp->next_hop_address),
1090 ntohl(mp->next_hop_sw_if_index));
1093 clib_error_report(e);
1095 return VNET_API_ERROR_IN_PROGRESS;
1099 if (mp->is_multipath) {
1102 dslock (sm, 1 /* release hint */, 11 /* tag */);
1105 flags = IP6_ROUTE_FLAG_ADD;
1107 flags = IP6_ROUTE_FLAG_DEL;
1110 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1112 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1113 (u32) mp->dst_address_length,
1114 (ip6_address_t *)mp->next_hop_address,
1115 ntohl(mp->next_hop_sw_if_index),
1116 (u32) mp->next_hop_weight,
1123 memset (&a, 0, sizeof (a));
1124 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1126 a.dst_address_length = mp->dst_address_length;
1128 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1129 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1130 a.table_index_or_table_id = fib_index;
1135 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1137 dslock (sm, 1 /* release hint */, 3 /* tag */);
1141 ai = lm->drop_adj_index;
1142 else if (mp->is_local)
1143 ai = lm->local_adj_index;
1145 ai = ip6_fib_lookup_with_table
1146 (im, fib_index, &next_hop_address);
1147 if (ai == lm->miss_adj_index) {
1149 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1153 nh_adj = ip_get_adjacency (lm, ai);
1154 vec_add1 (add_adj, nh_adj[0]);
1155 if (mp->lookup_in_vrf) {
1156 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1158 add_adj[0].explicit_fib_index = p[0];
1162 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1166 ip_adjacency_t * adj;
1168 ai = ip6_fib_lookup_with_table
1169 (im, fib_index, &a.dst_address);
1170 if (ai == lm->miss_adj_index) {
1172 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1174 adj = ip_get_adjacency (lm, ai);
1175 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1177 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1182 a.add_adj = add_adj;
1183 a.n_add_adj = vec_len(add_adj);
1184 ip6_add_del_route (im, &a);
1192 void vl_api_ip_add_del_route_t_handler (
1193 vl_api_ip_add_del_route_t *mp)
1195 vl_api_ip_add_del_route_reply_t * rmp;
1197 vnet_main_t * vnm = vnet_get_main();
1202 rv = ip6_add_del_route_t_handler (mp);
1204 rv = ip4_add_del_route_t_handler (mp);
1206 rv = (rv == 0) ? vnm->api_errno : rv;
1208 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1211 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1212 u32 sw_if_index, u8 *next_hop_addr)
1214 vl_api_ip_add_del_route_t mp;
1217 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1220 * Configure default IP route:
1221 * - ip route add 0.0.0.0/1 via <GW IP>
1222 * - ip route add 128.0.0.0/1 via <GW IP>
1224 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1226 mp.resolve_attempts = ~0;
1227 mp.resolve_if_needed = 1;
1229 mp.is_ipv6 = is_ipv6;
1230 mp.next_hop_weight = 1;
1232 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1235 rv = ip6_add_del_route_t_handler (&mp);
1238 mp.dst_address_length = 1;
1240 mp.dst_address[0] = 0;
1241 rv = ip4_add_del_route_t_handler (&mp);
1243 mp.dst_address[0] = 128;
1244 rv |= ip4_add_del_route_t_handler (&mp);
1248 clib_error_return (0, "failed to config default IP route");
1253 vl_api_sw_interface_add_del_address_t_handler
1254 (vl_api_sw_interface_add_del_address_t *mp)
1256 vlib_main_t *vm = vlib_get_main();
1257 vl_api_sw_interface_add_del_address_reply_t * rmp;
1261 VALIDATE_SW_IF_INDEX(mp);
1263 is_del = mp->is_add == 0;
1266 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1267 else if (mp->is_ipv6)
1268 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1269 (void *)mp->address,
1270 mp->address_length, is_del);
1272 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1273 (void *) mp->address,
1274 mp->address_length, is_del);
1276 BAD_SW_IF_INDEX_LABEL;
1278 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1282 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1285 u32 table_id = ntohl(mp->vrf_id);
1286 u32 sw_if_index = ntohl(mp->sw_if_index);
1287 vl_api_sw_interface_set_table_reply_t * rmp;
1288 stats_main_t * sm = &stats_main;
1290 VALIDATE_SW_IF_INDEX(mp);
1292 dslock (sm, 1 /* release hint */, 4 /* tag */);
1295 ip6_main_t * im = &ip6_main;
1297 find_ip6_fib_by_table_index_or_id (im, table_id,
1298 IP6_ROUTE_FLAG_TABLE_ID);
1300 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1301 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1303 rv = VNET_API_ERROR_NO_SUCH_FIB;
1306 ip4_main_t * im = &ip4_main;
1307 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1308 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1310 /* Truthfully this can't fail */
1312 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1313 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1315 rv = VNET_API_ERROR_NO_SUCH_FIB;
1320 BAD_SW_IF_INDEX_LABEL;
1322 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1326 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1328 vlib_main_t *vm = vlib_get_main();
1329 vl_api_sw_interface_set_vpath_reply_t * rmp;
1332 u32 sw_if_index = ntohl(mp->sw_if_index);
1333 ip4_main_t *ip4m = &ip4_main;
1334 ip6_main_t *ip6m = &ip6_main;
1335 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1336 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1337 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1338 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1339 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1340 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1342 VALIDATE_SW_IF_INDEX(mp);
1344 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1346 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1347 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1348 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1349 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1350 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1351 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1352 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1353 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1354 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1355 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1356 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1357 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1358 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1359 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1360 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1361 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1363 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1364 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1365 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1366 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1367 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1368 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1369 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1370 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1371 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1372 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1373 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1374 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1375 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1376 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1377 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1378 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1381 BAD_SW_IF_INDEX_LABEL;
1383 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1387 vl_api_sw_interface_set_l2_xconnect_t_handler (
1388 vl_api_sw_interface_set_l2_xconnect_t *mp)
1390 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1392 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1393 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1394 vlib_main_t *vm = vlib_get_main();
1395 vnet_main_t *vnm = vnet_get_main();
1397 VALIDATE_RX_SW_IF_INDEX(mp);
1400 VALIDATE_TX_SW_IF_INDEX(mp);
1401 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1402 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1404 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1407 BAD_RX_SW_IF_INDEX_LABEL;
1408 BAD_TX_SW_IF_INDEX_LABEL;
1410 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1414 vl_api_sw_interface_set_l2_bridge_t_handler (
1415 vl_api_sw_interface_set_l2_bridge_t *mp)
1417 bd_main_t * bdm = &bd_main;
1418 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1420 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1421 u32 bd_id = ntohl(mp->bd_id);
1425 vlib_main_t *vm = vlib_get_main();
1426 vnet_main_t *vnm = vnet_get_main();
1428 VALIDATE_RX_SW_IF_INDEX(mp);
1430 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1433 //VALIDATE_TX_SW_IF_INDEX(mp);
1434 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1435 rx_sw_if_index, bd_index, bvi, shg, 0);
1437 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1440 BAD_RX_SW_IF_INDEX_LABEL;
1442 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1446 vl_api_bridge_domain_add_del_t_handler (
1447 vl_api_bridge_domain_add_del_t *mp)
1449 vlib_main_t * vm = vlib_get_main ();
1450 bd_main_t * bdm = &bd_main;
1451 vl_api_bridge_domain_add_del_reply_t * rmp;
1453 u32 enable_flags = 0, disable_flags = 0;
1454 u32 bd_id = ntohl(mp->bd_id);
1458 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1461 enable_flags |= L2_FLOOD;
1463 disable_flags |= L2_FLOOD;
1466 enable_flags |= L2_UU_FLOOD;
1468 disable_flags |= L2_UU_FLOOD;
1471 enable_flags |= L2_FWD;
1473 disable_flags |= L2_FWD;
1476 enable_flags |= L2_ARP_TERM;
1478 disable_flags |= L2_ARP_TERM;
1481 enable_flags |= L2_LEARN;
1483 disable_flags |= L2_LEARN;
1486 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1489 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1492 rv = bd_delete_bd_index(bdm, bd_id);
1494 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1497 static void vl_api_bridge_domain_details_t_handler (
1498 vl_api_bridge_domain_details_t * mp)
1500 clib_warning ("BUG");
1503 static void vl_api_bridge_domain_sw_if_details_t_handler (
1504 vl_api_bridge_domain_sw_if_details_t * mp)
1506 clib_warning ("BUG");
1509 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1510 l2_bridge_domain_t * bd_config,
1514 vl_api_bridge_domain_details_t * mp;
1516 mp = vl_msg_api_alloc (sizeof (*mp));
1517 memset (mp, 0, sizeof (*mp));
1518 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1519 mp->bd_id = ntohl (bd_config->bd_id);
1520 mp->flood = bd_feature_flood (bd_config);
1521 mp->uu_flood = bd_feature_uu_flood (bd_config);
1522 mp->forward = bd_feature_forward (bd_config);
1523 mp->learn = bd_feature_learn (bd_config);
1524 mp->arp_term = bd_feature_arp_term (bd_config);
1525 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1526 mp->n_sw_ifs = ntohl (n_sw_ifs);
1527 mp->context = context;
1529 vl_msg_api_send_shmem (q, (u8 *)&mp);
1532 static void send_bd_sw_if_details (l2input_main_t * l2im,
1533 unix_shared_memory_queue_t *q,
1534 l2_flood_member_t * member, u32 bd_id,
1537 vl_api_bridge_domain_sw_if_details_t * mp;
1538 l2_input_config_t * input_cfg;
1540 mp = vl_msg_api_alloc (sizeof (*mp));
1541 memset (mp, 0, sizeof (*mp));
1542 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1543 mp->bd_id = ntohl (bd_id);
1544 mp->sw_if_index = ntohl (member->sw_if_index);
1545 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1546 mp->shg = input_cfg->shg;
1547 mp->context = context;
1549 vl_msg_api_send_shmem (q, (u8 *)&mp);
1552 static void vl_api_bridge_domain_dump_t_handler (
1553 vl_api_bridge_domain_dump_t *mp)
1555 bd_main_t * bdm = &bd_main;
1556 l2input_main_t * l2im = &l2input_main;
1557 unix_shared_memory_queue_t * q;
1558 l2_bridge_domain_t * bd_config;
1559 u32 bd_id, bd_index;
1562 q = vl_api_client_index_to_input_queue (mp->client_index);
1567 bd_id = ntohl(mp->bd_id);
1569 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1570 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1571 for (; bd_index < end; bd_index++) {
1572 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1573 /* skip dummy bd_id 0 */
1574 if (bd_config && (bd_config->bd_id > 0)) {
1576 l2_flood_member_t * m;
1578 n_sw_ifs = vec_len (bd_config->members);
1579 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1581 vec_foreach (m, bd_config->members) {
1582 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1589 vl_api_l2fib_add_del_t_handler (
1590 vl_api_l2fib_add_del_t *mp)
1592 bd_main_t * bdm = &bd_main;
1593 l2input_main_t * l2im = &l2input_main;
1594 vl_api_l2fib_add_del_reply_t * rmp;
1597 u32 sw_if_index = ntohl(mp->sw_if_index);
1598 u32 bd_id = ntohl(mp->bd_id);
1606 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1608 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1609 goto bad_sw_if_index;
1614 VALIDATE_SW_IF_INDEX(mp);
1615 if (vec_len(l2im->configs) <= sw_if_index) {
1616 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1617 goto bad_sw_if_index;
1619 l2_input_config_t * config;
1620 config = vec_elt_at_index(l2im->configs, sw_if_index);
1621 if (config->bridge == 0) {
1622 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1623 goto bad_sw_if_index;
1626 static_mac = mp->static_mac ? 1 : 0;
1627 filter_mac = mp->filter_mac ? 1 : 0;
1628 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1631 l2fib_del_entry(mac, bd_index);
1634 BAD_SW_IF_INDEX_LABEL;
1636 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1640 vl_api_l2_flags_t_handler (
1641 vl_api_l2_flags_t *mp)
1643 vl_api_l2_flags_reply_t * rmp;
1645 u32 sw_if_index = ntohl(mp->sw_if_index);
1646 u32 flags = ntohl(mp->feature_bitmap);
1649 VALIDATE_SW_IF_INDEX(mp);
1652 if (flags & L2INPUT_FEAT_ ## a) \
1653 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1654 foreach_l2input_feat;
1657 BAD_SW_IF_INDEX_LABEL;
1659 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1663 vl_api_bridge_flags_t_handler (
1664 vl_api_bridge_flags_t *mp)
1666 vlib_main_t *vm = vlib_get_main();
1667 bd_main_t * bdm = &bd_main;
1668 vl_api_bridge_flags_reply_t * rmp;
1670 u32 bd_id = ntohl(mp->bd_id);
1672 u32 flags = ntohl(mp->feature_bitmap);
1675 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1677 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1683 bd_set_flags(vm, bd_index, flags, mp->is_set);
1686 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1687 rmp->resulting_feature_bitmap = ntohl(flags));
1691 vl_api_bd_ip_mac_add_del_t_handler (
1692 vl_api_bd_ip_mac_add_del_t *mp)
1694 bd_main_t * bdm = &bd_main;
1695 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1697 u32 bd_id = ntohl(mp->bd_id);
1701 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1703 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1708 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1709 mp->mac_address, mp->is_ipv6, mp->is_add))
1710 rv = VNET_API_ERROR_UNSPECIFIED;
1713 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1717 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1720 vl_api_tap_connect_reply_t * rmp;
1721 unix_shared_memory_queue_t * q;
1722 u32 sw_if_index = (u32)~0;
1724 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1725 mp->use_random_mac ? 0 : mp->mac_address,
1726 &sw_if_index, mp->renumber,
1727 ntohl(mp->custom_dev_instance));
1729 q = vl_api_client_index_to_input_queue (mp->client_index);
1733 rmp = vl_msg_api_alloc (sizeof (*rmp));
1734 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1735 rmp->context = mp->context;
1736 rmp->retval = ntohl(rv);
1737 rmp->sw_if_index = ntohl(sw_if_index);
1739 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1743 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1746 vl_api_tap_modify_reply_t * rmp;
1747 unix_shared_memory_queue_t * q;
1748 u32 sw_if_index = (u32)~0;
1750 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1751 mp->use_random_mac ? 0 : mp->mac_address,
1752 &sw_if_index, mp->renumber,
1753 ntohl(mp->custom_dev_instance));
1755 q = vl_api_client_index_to_input_queue (mp->client_index);
1759 rmp = vl_msg_api_alloc (sizeof (*rmp));
1760 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1761 rmp->context = mp->context;
1762 rmp->retval = ntohl(rv);
1763 rmp->sw_if_index = ntohl(sw_if_index);
1765 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1769 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1772 vpe_api_main_t * vam = &vpe_api_main;
1773 vl_api_tap_delete_reply_t * rmp;
1774 unix_shared_memory_queue_t * q;
1775 u32 sw_if_index = ntohl(mp->sw_if_index);
1777 rv = vnet_tap_delete (vm, sw_if_index);
1779 q = vl_api_client_index_to_input_queue (mp->client_index);
1783 rmp = vl_msg_api_alloc (sizeof (*rmp));
1784 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1785 rmp->context = mp->context;
1786 rmp->retval = ntohl(rv);
1788 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1791 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1795 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1797 vl_api_create_vlan_subif_reply_t * rmp;
1798 vnet_main_t * vnm = vnet_get_main();
1799 u32 hw_if_index, sw_if_index = (u32)~0;
1800 vnet_hw_interface_t * hi;
1803 vnet_sw_interface_t template;
1805 vnet_interface_main_t * im = &vnm->interface_main;
1806 u64 sup_and_sub_key;
1808 unix_shared_memory_queue_t * q;
1809 clib_error_t * error;
1811 VALIDATE_SW_IF_INDEX(mp);
1813 hw_if_index = ntohl(mp->sw_if_index);
1814 hi = vnet_get_hw_interface (vnm, hw_if_index);
1816 id = ntohl(mp->vlan_id);
1817 if (id == 0 || id > 4095) {
1818 rv = VNET_API_ERROR_INVALID_VLAN;
1822 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1824 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1826 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1830 kp = clib_mem_alloc (sizeof (*kp));
1831 *kp = sup_and_sub_key;
1833 memset (&template, 0, sizeof (template));
1834 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1835 template.sup_sw_if_index = hi->sw_if_index;
1836 template.sub.id = id;
1837 template.sub.eth.raw_flags = 0;
1838 template.sub.eth.flags.one_tag = 1;
1839 template.sub.eth.outer_vlan_id = id;
1840 template.sub.eth.flags.exact_match = 1;
1842 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1844 clib_error_report(error);
1845 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1848 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1849 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1851 BAD_SW_IF_INDEX_LABEL;
1854 q = vl_api_client_index_to_input_queue (mp->client_index);
1858 rmp = vl_msg_api_alloc (sizeof (*rmp));
1859 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1860 rmp->context = mp->context;
1861 rmp->retval = ntohl(rv);
1862 rmp->sw_if_index = ntohl(sw_if_index);
1863 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1867 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1869 vl_api_create_subif_reply_t * rmp;
1870 vnet_main_t * vnm = vnet_get_main();
1871 u32 sw_if_index = ~0;
1874 vnet_sw_interface_t *si;
1875 vnet_hw_interface_t *hi;
1876 vnet_sw_interface_t template;
1878 vnet_interface_main_t * im = &vnm->interface_main;
1879 u64 sup_and_sub_key;
1881 clib_error_t * error;
1883 VALIDATE_SW_IF_INDEX(mp);
1885 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1886 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1888 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1889 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1893 sw_if_index = si->sw_if_index;
1894 sub_id = ntohl(mp->sub_id);
1896 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1898 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1901 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1902 sw_if_index, sub_id);
1903 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1907 kp = clib_mem_alloc (sizeof (*kp));
1908 *kp = sup_and_sub_key;
1910 memset (&template, 0, sizeof (template));
1911 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1912 template.sup_sw_if_index = sw_if_index;
1913 template.sub.id = sub_id;
1914 template.sub.eth.flags.no_tags = mp->no_tags;
1915 template.sub.eth.flags.one_tag = mp->one_tag;
1916 template.sub.eth.flags.two_tags = mp->two_tags;
1917 template.sub.eth.flags.dot1ad = mp->dot1ad;
1918 template.sub.eth.flags.exact_match = mp->exact_match;
1919 template.sub.eth.flags.default_sub = mp->default_sub;
1920 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1921 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1922 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1923 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1925 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1927 clib_error_report (error);
1928 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1932 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1933 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1935 BAD_SW_IF_INDEX_LABEL;
1939 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1941 rmp->sw_if_index = ntohl(sw_if_index);
1946 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1948 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1950 stats_main_t * sm = &stats_main;
1951 u32 tunnel_sw_if_index = ~0;
1953 dslock (sm, 1 /* release hint */, 5 /* tag */);
1955 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1956 (ip4_address_t *)(mp->dst_address),
1957 (ip4_address_t *)(mp->intfc_address),
1958 (u32)(mp->intfc_address_length),
1959 ntohl(mp->inner_vrf_id),
1960 ntohl(mp->outer_vrf_id),
1961 &tunnel_sw_if_index,
1966 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1968 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1973 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1974 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1976 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1978 stats_main_t * sm = &stats_main;
1979 u32 tunnel_sw_if_index;
1981 dslock (sm, 1 /* release hint */, 5 /* tag */);
1983 rv = vnet_mpls_ethernet_add_del_tunnel
1984 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1985 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1986 ntohl(mp->tx_sw_if_index),
1987 &tunnel_sw_if_index,
1993 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1995 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2000 * This piece of misery brought to you because the control-plane
2001 * can't figure out the tx interface + dst-mac address all by itself
2003 static int mpls_ethernet_add_del_tunnel_2_t_handler
2004 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2006 pending_route_t * pr;
2007 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2008 vnet_main_t * vnm = vnet_get_main();
2009 vlib_main_t * vm = vlib_get_main();
2010 stats_main_t * sm = &stats_main;
2011 vpe_api_main_t * vam = &vpe_api_main;
2012 u32 inner_fib_index, outer_fib_index;
2013 ip4_main_t * im = &ip4_main;
2014 ip_lookup_main_t * lm = &im->lookup_main;
2015 ip_adjacency_t * adj = 0;
2018 u8 * dst_mac_address;
2022 u32 tunnel_sw_if_index;
2024 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2026 return VNET_API_ERROR_NO_SUCH_FIB;
2028 outer_fib_index = p[0];
2031 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2033 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2035 inner_fib_index = p[0];
2037 if (inner_fib_index == outer_fib_index)
2038 return VNET_API_ERROR_INVALID_VALUE;
2040 lookup_result = ip4_fib_lookup_with_table
2041 (im, outer_fib_index,
2042 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2043 1 /* disable default route */);
2045 adj = ip_get_adjacency (lm, lookup_result);
2046 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2048 if (mp->is_add && mp->resolve_if_needed) {
2049 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2050 pool_get (vam->pending_routes, pr);
2051 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2053 clib_memcpy (pme, mp, sizeof (*pme));
2054 /* recursion block, "just in case" */
2055 pme->resolve_if_needed = 0;
2056 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2057 pme->resolve_opaque = tx_sw_if_index;
2058 vnet_register_ip4_arp_resolution_event
2060 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2061 vpe_resolver_process_node.index,
2062 RESOLUTION_EVENT, pr - vam->pending_routes);
2064 vlib_process_signal_event
2065 (vm, vpe_resolver_process_node.index,
2066 RESOLUTION_PENDING_EVENT, 0 /* data */);
2068 /* The interface may be down, etc. */
2069 e = ip4_probe_neighbor
2070 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2074 clib_error_report(e);
2076 return VNET_API_ERROR_IN_PROGRESS;
2080 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2081 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2084 vnet_rewrite_get_data_internal
2085 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2087 dslock (sm, 1 /* release hint */, 10 /* tag */);
2089 rv = vnet_mpls_ethernet_add_del_tunnel
2090 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2091 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2092 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2100 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2101 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2103 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2106 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2108 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2113 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2115 vl_api_mpls_add_del_encap_reply_t * rmp;
2117 static u32 * labels;
2120 vec_reset_length (labels);
2122 for (i = 0; i < mp->nlabels; i++)
2123 vec_add1 (labels, ntohl(mp->labels[i]));
2126 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2127 ntohl(mp->vrf_id), labels,
2128 ~0 /* policy_tunnel_index */,
2129 0 /* no_dst_hash */,
2133 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2137 vl_api_mpls_add_del_decap_t_handler
2138 (vl_api_mpls_add_del_decap_t *mp)
2140 vl_api_mpls_add_del_decap_reply_t * rmp;
2143 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2144 ntohl(mp->label), ntohl(mp->next_index),
2145 mp->s_bit, mp->is_add);
2147 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2151 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2153 vl_api_proxy_arp_add_del_reply_t * rmp;
2156 ip4_main_t * im = &ip4_main;
2157 stats_main_t * sm = &stats_main;
2158 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2159 ip4_address_t *hi_addr,
2160 u32 fib_index, int is_del);
2163 dslock (sm, 1 /* release hint */, 6 /* tag */);
2165 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2168 rv = VNET_API_ERROR_NO_SUCH_FIB;
2174 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2175 (ip4_address_t *)mp->hi_address,
2176 fib_index, mp->is_add == 0);
2180 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2184 vl_api_proxy_arp_intfc_enable_disable_t_handler
2185 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2188 vnet_main_t * vnm = vnet_get_main();
2189 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2190 vnet_sw_interface_t * si;
2193 VALIDATE_SW_IF_INDEX(mp);
2195 sw_if_index = ntohl(mp->sw_if_index);
2197 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2199 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2203 si = vnet_get_sw_interface (vnm, sw_if_index);
2207 if (mp->enable_disable)
2208 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2210 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2212 BAD_SW_IF_INDEX_LABEL;
2215 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2219 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2221 vl_api_ip_neighbor_add_del_reply_t * rmp;
2222 vnet_main_t * vnm = vnet_get_main();
2225 stats_main_t * sm = &stats_main;
2227 VALIDATE_SW_IF_INDEX(mp);
2229 dslock (sm, 1 /* release hint */, 7 /* tag */);
2233 rv = vnet_set_ip6_ethernet_neighbor
2234 (vm, ntohl(mp->sw_if_index),
2235 (ip6_address_t *)(mp->dst_address),
2236 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2238 rv = vnet_unset_ip6_ethernet_neighbor
2239 (vm, ntohl(mp->sw_if_index),
2240 (ip6_address_t *)(mp->dst_address),
2241 mp->mac_address, sizeof(mp->mac_address));
2243 ip4_main_t * im = &ip4_main;
2244 ip_lookup_main_t * lm = &im->lookup_main;
2245 ethernet_arp_ip4_over_ethernet_address_t a;
2247 ip_adjacency_t *nh_adj;
2249 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2251 rv = VNET_API_ERROR_NO_SUCH_FIB;
2257 * Unfortunately, folks have a penchant for
2258 * adding interface addresses to the ARP cache, and
2259 * wondering why the forwarder eventually ASSERTs...
2261 ai = ip4_fib_lookup_with_table
2262 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2263 1 /* disable default route */);
2266 nh_adj = ip_get_adjacency (lm, ai);
2267 /* Never allow manipulation of a local adj! */
2268 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2269 clib_warning("%U matches local adj",
2271 (ip4_address_t *)(mp->dst_address));
2272 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2277 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2278 clib_memcpy (&a.ip4, mp->dst_address, 4);
2281 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2282 fib_index, &a, mp->is_static);
2284 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2288 BAD_SW_IF_INDEX_LABEL;
2291 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2295 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2298 vpe_main_t *rm = &vpe_main;
2299 ip4_main_t *im4 = &ip4_main;
2300 ip6_main_t *im6 = &ip6_main;
2301 ip_lookup_main_t * lm;
2306 u32 adj_index, sw_if_index;
2307 vl_api_is_address_reachable_t *rmp;
2308 ip_adjacency_t * adj;
2309 unix_shared_memory_queue_t *q;
2311 q = vl_api_client_index_to_input_queue (mp->client_index);
2313 increment_missing_api_client_counter (rm->vlib_main);
2317 rmp = vl_msg_api_alloc (sizeof (*rmp));
2318 clib_memcpy (rmp, mp, sizeof (*rmp));
2320 sw_if_index = mp->next_hop_sw_if_index;
2321 clib_memcpy (&addr, mp->address, sizeof (addr));
2323 lm = &im6->lookup_main;
2325 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2327 lm = &im4->lookup_main;
2329 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2331 if (adj_index == ~0) {
2335 adj = ip_get_adjacency (lm, adj_index);
2337 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2338 && adj->rewrite_header.sw_if_index == sw_if_index) {
2341 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2342 && adj->rewrite_header.sw_if_index == sw_if_index) {
2344 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2346 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2347 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2355 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2359 static void vl_api_sw_interface_details_t_handler (
2360 vl_api_sw_interface_details_t * mp)
2362 clib_warning ("BUG");
2365 static void vl_api_sw_interface_set_flags_t_handler (
2366 vl_api_sw_interface_set_flags_t * mp)
2368 vl_api_sw_interface_set_flags_reply_t *rmp;
2369 vnet_main_t * vnm = vnet_get_main();
2371 clib_error_t * error;
2374 VALIDATE_SW_IF_INDEX(mp);
2376 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2378 error = vnet_sw_interface_set_flags (vnm,
2379 ntohl(mp->sw_if_index),
2383 clib_error_report (error);
2386 BAD_SW_IF_INDEX_LABEL;
2387 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2390 static void vl_api_sw_interface_clear_stats_t_handler (
2391 vl_api_sw_interface_clear_stats_t * mp)
2393 vl_api_sw_interface_clear_stats_reply_t *rmp;
2395 vnet_main_t * vnm = vnet_get_main();
2396 vnet_interface_main_t * im = &vnm->interface_main;
2397 vlib_simple_counter_main_t * sm;
2398 vlib_combined_counter_main_t * cm;
2399 static vnet_main_t ** my_vnet_mains;
2400 int i, j, n_counters;
2404 vec_reset_length (my_vnet_mains);
2406 for (i = 0; i < vec_len (vnet_mains); i++)
2409 vec_add1 (my_vnet_mains, vnet_mains[i]);
2412 if (vec_len (vnet_mains) == 0)
2413 vec_add1 (my_vnet_mains, vnm);
2415 n_counters = vec_len (im->combined_sw_if_counters);
2417 for (j = 0; j < n_counters; j++)
2419 for (i = 0; i < vec_len(my_vnet_mains); i++)
2421 im = &my_vnet_mains[i]->interface_main;
2422 cm = im->combined_sw_if_counters + j;
2423 if (mp->sw_if_index == (u32)~0)
2424 vlib_clear_combined_counters (cm);
2426 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2430 n_counters = vec_len (im->sw_if_counters);
2432 for (j = 0; j < n_counters; j++)
2434 for (i = 0; i < vec_len(my_vnet_mains); i++)
2436 im = &my_vnet_mains[i]->interface_main;
2437 sm = im->sw_if_counters + j;
2438 if (mp->sw_if_index == (u32)~0)
2439 vlib_clear_simple_counters (sm);
2441 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2445 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2448 static void send_sw_interface_details (vpe_api_main_t * am,
2449 unix_shared_memory_queue_t *q,
2450 vnet_sw_interface_t * swif,
2451 u8 * interface_name,
2454 vl_api_sw_interface_details_t * mp;
2455 vnet_hw_interface_t * hi;
2457 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2459 mp = vl_msg_api_alloc (sizeof (*mp));
2460 memset (mp, 0, sizeof (*mp));
2461 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2462 mp->sw_if_index = ntohl(swif->sw_if_index);
2463 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2464 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2466 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2468 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2469 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2470 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2471 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2472 mp->link_mtu = ntohs(hi->max_packet_bytes);
2473 mp->context = context;
2475 strncpy ((char *) mp->interface_name,
2476 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2478 /* Send the L2 address for ethernet physical intfcs */
2479 if (swif->sup_sw_if_index == swif->sw_if_index
2480 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2481 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2482 ethernet_interface_t *ei;
2484 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2485 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2486 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2487 mp->l2_address_length = ntohl(sizeof (ei->address));
2488 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2489 vnet_sub_interface_t *sub = &swif->sub;
2490 mp->sub_id = ntohl(sub->id);
2491 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2492 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2493 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2494 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2495 mp->sub_exact_match = sub->eth.flags.exact_match;
2496 mp->sub_default = sub->eth.flags.default_sub;
2497 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2498 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2500 /* vlan tag rewrite data */
2501 u32 vtr_op = L2_VTR_DISABLED;
2502 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2504 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2505 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2506 // error - default to disabled
2507 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2508 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2511 mp->vtr_op = ntohl(vtr_op);
2512 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2513 mp->vtr_tag1 = ntohl(vtr_tag1);
2514 mp->vtr_tag2 = ntohl(vtr_tag2);
2518 vl_msg_api_send_shmem (q, (u8 *)&mp);
2521 static void send_sw_interface_flags (vpe_api_main_t * am,
2522 unix_shared_memory_queue_t *q,
2523 vnet_sw_interface_t * swif)
2525 vl_api_sw_interface_set_flags_t *mp;
2526 vnet_main_t * vnm = am->vnet_main;
2528 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2530 mp = vl_msg_api_alloc (sizeof (*mp));
2531 memset (mp, 0, sizeof (*mp));
2532 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2533 mp->sw_if_index = ntohl(swif->sw_if_index);
2535 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2537 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2539 vl_msg_api_send_shmem (q, (u8 *)&mp);
2542 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2543 unix_shared_memory_queue_t *q,
2545 __attribute__((unused));
2547 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2548 unix_shared_memory_queue_t *q,
2551 vl_api_sw_interface_set_flags_t *mp;
2553 mp = vl_msg_api_alloc (sizeof (*mp));
2554 memset (mp, 0, sizeof (*mp));
2555 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2556 mp->sw_if_index = ntohl(sw_if_index);
2558 mp->admin_up_down = 0;
2559 mp->link_up_down = 0;
2561 vl_msg_api_send_shmem (q, (u8 *)&mp);
2564 static void vl_api_sw_interface_dump_t_handler (
2565 vl_api_sw_interface_dump_t *mp)
2567 vpe_api_main_t * am = &vpe_api_main;
2568 vnet_sw_interface_t * swif;
2569 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2570 u8 * filter_string = 0, * name_string = 0;
2571 unix_shared_memory_queue_t * q;
2572 char * strcasestr (char *, char *); /* lnx hdr file botch */
2574 q = vl_api_client_index_to_input_queue (mp->client_index);
2579 if (mp->name_filter_valid) {
2580 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2581 filter_string = format (0, "%s%c", mp->name_filter, 0);
2584 pool_foreach (swif, im->sw_interfaces,
2586 name_string = format (name_string, "%U%c",
2587 format_vnet_sw_interface_name,
2588 am->vnet_main, swif, 0);
2590 if (mp->name_filter_valid == 0 ||
2591 strcasestr((char *) name_string, (char *) filter_string)) {
2593 send_sw_interface_details (am, q, swif, name_string, mp->context);
2594 send_sw_interface_flags (am, q, swif);
2596 _vec_len (name_string) = 0;
2599 vec_free (name_string);
2600 vec_free (filter_string);
2603 void send_oam_event (oam_target_t * t)
2605 vpe_api_main_t * vam = &vpe_api_main;
2606 unix_shared_memory_queue_t * q;
2607 vpe_client_registration_t *reg;
2608 vl_api_oam_event_t * mp;
2610 pool_foreach(reg, vam->oam_events_registrations,
2612 q = vl_api_client_index_to_input_queue (reg->client_index);
2614 mp = vl_msg_api_alloc (sizeof (*mp));
2615 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2616 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2617 mp->state = t->state;
2618 vl_msg_api_send_shmem (q, (u8 *)&mp);
2624 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2626 vl_api_oam_add_del_reply_t * rmp;
2629 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2630 (ip4_address_t *)mp->dst_address,
2634 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2638 vl_api_vnet_get_summary_stats_t_handler (
2639 vl_api_vnet_get_summary_stats_t *mp)
2641 stats_main_t * sm = &stats_main;
2642 vnet_interface_main_t * im = sm->interface_main;
2643 vl_api_vnet_summary_stats_reply_t *rmp;
2644 vlib_combined_counter_main_t * cm;
2647 u64 total_pkts[VLIB_N_RX_TX];
2648 u64 total_bytes[VLIB_N_RX_TX];
2650 unix_shared_memory_queue_t * q =
2651 vl_api_client_index_to_input_queue (mp->client_index);
2656 rmp = vl_msg_api_alloc (sizeof (*rmp));
2657 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2658 rmp->context = mp->context;
2661 memset (total_pkts, 0, sizeof (total_pkts));
2662 memset (total_bytes, 0, sizeof (total_bytes));
2664 vnet_interface_counter_lock (im);
2666 vec_foreach (cm, im->combined_sw_if_counters) {
2667 which = cm - im->combined_sw_if_counters;
2669 for (i = 0; i < vec_len (cm->maxi); i++) {
2670 vlib_get_combined_counter (cm, i, &v);
2671 total_pkts[which] += v.packets;
2672 total_bytes[which] += v.bytes;
2675 vnet_interface_counter_unlock (im);
2677 /* Note: in HOST byte order! */
2678 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2679 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2680 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2681 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2682 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2684 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2687 typedef CLIB_PACKED (struct {
2688 ip4_address_t address;
2690 u32 address_length : 6;
2695 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2697 vnet_main_t * vnm = vnet_get_main();
2698 vnet_interface_main_t * im = &vnm->interface_main;
2699 ip4_main_t * im4 = &ip4_main;
2700 static ip4_route_t * routes;
2701 static u32 * sw_if_indices_to_shut;
2702 stats_main_t * sm = &stats_main;
2707 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2708 u32 target_fib_id = ntohl(mp->vrf_id);
2710 dslock (sm, 1 /* release hint */, 8 /* tag */);
2712 vec_foreach (fib, im4->fibs) {
2713 vnet_sw_interface_t * si;
2715 if (fib->table_id != target_fib_id)
2718 /* remove any mpls/gre tunnels in this fib */
2719 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2721 /* remove any mpls encap/decap labels */
2722 mpls_fib_reset_labels (fib->table_id);
2724 /* remove any proxy arps in this fib */
2725 vnet_proxy_arp_fib_reset (fib->table_id);
2727 /* Set the flow hash for this fib to the default */
2728 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2730 vec_reset_length (sw_if_indices_to_shut);
2732 /* Shut down interfaces in this FIB / clean out intfc routes */
2733 pool_foreach (si, im->sw_interfaces,
2735 u32 sw_if_index = si->sw_if_index;
2737 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2738 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2740 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2743 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2744 sw_if_index = sw_if_indices_to_shut[i];
2745 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2747 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2748 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2749 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2752 vec_reset_length (routes);
2754 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2755 uword * hash = fib->adj_index_by_dst_address[i];
2759 x.address_length = i;
2761 hash_foreach_pair (p, hash,
2763 x.address.data_u32 = p->key;
2764 vec_add1 (routes, x);
2768 vec_foreach (r, routes) {
2769 ip4_add_del_route_args_t a;
2771 memset (&a, 0, sizeof (a));
2772 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2773 a.table_index_or_table_id = fib - im4->fibs;
2774 a.dst_address = r->address;
2775 a.dst_address_length = r->address_length;
2778 ip4_add_del_route (im4, &a);
2779 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2780 IP4_ROUTE_FLAG_FIB_INDEX);
2784 } /* vec_foreach (fib) */
2791 ip6_address_t address;
2798 ip6_route_t ** routep;
2799 } add_routes_in_fib_arg_t;
2801 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2803 add_routes_in_fib_arg_t * ap = arg;
2805 if (kvp->key[2]>>32 == ap->fib_index)
2807 ip6_address_t *addr;
2809 addr = (ip6_address_t *) kvp;
2810 vec_add2 (*ap->routep, r, 1);
2811 r->address = addr[0];
2812 r->address_length = kvp->key[2] & 0xFF;
2813 r->index = kvp->value;
2817 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2819 vnet_main_t * vnm = vnet_get_main();
2820 vnet_interface_main_t * im = &vnm->interface_main;
2821 ip6_main_t * im6 = &ip6_main;
2822 stats_main_t * sm = &stats_main;
2823 static ip6_route_t * routes;
2824 static u32 * sw_if_indices_to_shut;
2829 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2830 u32 target_fib_id = ntohl(mp->vrf_id);
2831 add_routes_in_fib_arg_t _a, *a=&_a;
2832 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2834 dslock (sm, 1 /* release hint */, 9 /* tag */);
2836 vec_foreach (fib, im6->fibs) {
2837 vnet_sw_interface_t * si;
2839 if (fib->table_id != target_fib_id)
2842 vec_reset_length (sw_if_indices_to_shut);
2844 /* Shut down interfaces in this FIB / clean out intfc routes */
2845 pool_foreach (si, im->sw_interfaces,
2847 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2849 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2852 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2853 sw_if_index = sw_if_indices_to_shut[i];
2854 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2856 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2857 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2858 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2861 vec_reset_length (routes);
2863 a->fib_index = fib - im6->fibs;
2864 a->routep = &routes;
2866 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2868 vec_foreach (r, routes) {
2869 ip6_add_del_route_args_t a;
2871 memset (&a, 0, sizeof (a));
2872 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2873 a.table_index_or_table_id = fib - im6->fibs;
2874 a.dst_address = r->address;
2875 a.dst_address_length = r->address_length;
2878 ip6_add_del_route (im6, &a);
2879 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2880 IP6_ROUTE_FLAG_FIB_INDEX);
2883 /* Reinstall the neighbor / router discovery routes */
2884 vnet_ip6_fib_init (im6, fib - im6->fibs);
2886 } /* vec_foreach (fib) */
2892 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2895 vl_api_reset_fib_reply_t * rmp;
2898 rv = ip6_reset_fib_t_handler (mp);
2900 rv = ip4_reset_fib_t_handler (mp);
2902 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2907 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2909 vl_api_dhcp_proxy_config_reply_t * rmp;
2912 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2913 (ip4_address_t *)(&mp->dhcp_src_address),
2914 (u32) ntohl(mp->vrf_id),
2915 (int) mp->insert_circuit_id,
2916 (int) (mp->is_add == 0));
2918 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2923 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2925 vl_api_dhcp_proxy_config_reply_t * rmp;
2928 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2929 (ip6_address_t *)(&mp->dhcp_src_address),
2930 (u32) ntohl(mp->vrf_id),
2931 (int) mp->insert_circuit_id,
2932 (int) (mp->is_add == 0));
2934 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2938 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2940 vl_api_dhcp_proxy_config_reply_t * rmp;
2943 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2944 (ip4_address_t *)(&mp->dhcp_src_address),
2945 (u32) ntohl(mp->rx_vrf_id),
2946 (u32) ntohl(mp->server_vrf_id),
2947 (int) mp->insert_circuit_id,
2948 (int) (mp->is_add == 0));
2950 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2955 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2957 vl_api_dhcp_proxy_config_reply_t * rmp;
2961 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2962 (ip6_address_t *)(&mp->dhcp_src_address),
2963 (u32) ntohl(mp->rx_vrf_id),
2964 (u32) ntohl(mp->server_vrf_id),
2965 (int) mp->insert_circuit_id,
2966 (int) (mp->is_add == 0));
2968 rv = VNET_API_ERROR_UNIMPLEMENTED;
2971 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2976 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2978 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2981 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2984 (int)mp->is_add == 0);
2986 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2989 (int)mp->is_add == 0);
2991 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2995 static void vl_api_dhcp_proxy_config_t_handler
2996 (vl_api_dhcp_proxy_config_t *mp)
2998 if (mp->is_ipv6 == 0)
2999 dhcpv4_proxy_config (mp);
3001 dhcpv6_proxy_config (mp);
3004 static void vl_api_dhcp_proxy_config_2_t_handler
3005 (vl_api_dhcp_proxy_config_2_t *mp)
3007 if (mp->is_ipv6 == 0)
3008 dhcpv4_proxy_config_2 (mp);
3010 dhcpv6_proxy_config_2 (mp);
3013 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3014 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3016 unix_shared_memory_queue_t * q;
3017 vl_api_dhcp_compl_event_t * mp;
3019 q = vl_api_client_index_to_input_queue (client_index);
3023 mp = vl_msg_api_alloc (sizeof (*mp));
3024 mp->client_index = client_index;
3026 mp->is_ipv6 = is_ipv6;
3027 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3028 mp->hostname[vec_len(hostname) + 1] = '\n';
3029 clib_memcpy (&mp->host_address[0], host_address, 16);
3030 clib_memcpy (&mp->router_address[0], router_address, 16);
3031 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3033 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3035 vl_msg_api_send_shmem (q, (u8 *)&mp);
3038 static void vl_api_dhcp_client_config_t_handler
3039 (vl_api_dhcp_client_config_t *mp)
3041 vlib_main_t *vm = vlib_get_main();
3042 vl_api_dhcp_client_config_reply_t * rmp;
3045 VALIDATE_SW_IF_INDEX(mp);
3047 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3048 mp->hostname, mp->is_add, mp->client_index,
3049 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3052 BAD_SW_IF_INDEX_LABEL;
3054 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3058 vl_api_sw_interface_ip6nd_ra_config_t_handler
3059 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3061 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3063 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3065 is_no = mp->is_no == 1;
3066 surpress = mp->surpress == 1;
3067 managed = mp->managed == 1;
3068 other = mp->other == 1;
3069 ll_option = mp->ll_option == 1;
3070 send_unicast = mp->send_unicast == 1;
3071 cease = mp->cease == 1;
3072 default_router = mp->default_router == 1;
3074 VALIDATE_SW_IF_INDEX(mp);
3076 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3077 surpress, managed, other,
3078 ll_option, send_unicast, cease,
3079 default_router, ntohl (mp->lifetime),
3080 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3081 ntohl(mp->max_interval), ntohl( mp->min_interval),
3084 BAD_SW_IF_INDEX_LABEL;
3086 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3090 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3091 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3093 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3095 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3097 VALIDATE_SW_IF_INDEX(mp);
3099 is_no = mp->is_no == 1;
3100 use_default = mp->use_default == 1;
3101 no_advertise = mp->no_advertise == 1;
3102 off_link = mp->off_link == 1;
3103 no_autoconfig = mp->no_autoconfig == 1;
3104 no_onlink = mp->no_onlink == 1;
3106 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3107 (ip6_address_t *)mp->address, mp->address_length,
3108 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3109 no_advertise, off_link, no_autoconfig, no_onlink,
3112 BAD_SW_IF_INDEX_LABEL;
3113 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3117 vl_api_sw_interface_ip6_enable_disable_t_handler
3118 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3120 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3121 vnet_main_t * vnm = vnet_get_main();
3123 clib_error_t * error;
3127 VALIDATE_SW_IF_INDEX(mp);
3129 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3130 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3133 clib_error_report(error);
3134 rv = VNET_API_ERROR_UNSPECIFIED;
3136 rv = vnm->api_errno;
3139 BAD_SW_IF_INDEX_LABEL;
3141 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3145 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3146 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3148 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3150 clib_error_t * error;
3151 vnet_main_t * vnm = vnet_get_main();
3155 VALIDATE_SW_IF_INDEX(mp);
3157 error = set_ip6_link_local_address(vm,
3158 ntohl(mp->sw_if_index),
3159 (ip6_address_t *)mp->address,
3160 mp->address_length);
3162 clib_error_report(error);
3163 rv = VNET_API_ERROR_UNSPECIFIED;
3165 rv = vnm->api_errno;
3168 BAD_SW_IF_INDEX_LABEL;
3170 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3173 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3175 vl_api_set_ip_flow_hash_reply_t *rmp;
3176 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3178 clib_warning ("unimplemented...");
3180 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3183 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3185 vl_api_set_ip_flow_hash_reply_t *rmp;
3188 u32 flow_hash_config = 0;
3190 table_id = ntohl(mp->vrf_id);
3192 #define _(a,b) if (mp->a) flow_hash_config |= b;
3193 foreach_flow_hash_bit;
3196 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3198 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3202 static void vl_api_set_ip_flow_hash_t_handler
3203 (vl_api_set_ip_flow_hash_t *mp)
3205 if (mp->is_ipv6 == 0)
3206 set_ip4_flow_hash (mp);
3208 set_ip6_flow_hash (mp);
3211 static void vl_api_sw_interface_set_unnumbered_t_handler
3212 (vl_api_sw_interface_set_unnumbered_t *mp)
3214 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3216 vnet_sw_interface_t * si;
3217 vnet_main_t *vnm = vnet_get_main();
3218 u32 sw_if_index, unnumbered_sw_if_index;
3220 sw_if_index = ntohl(mp->sw_if_index);
3221 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3224 * The API message field names are backwards from
3225 * the underlying data structure names.
3226 * It's not worth changing them now.
3228 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3229 unnumbered_sw_if_index)) {
3230 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3234 /* Only check the "use loop0" field when setting the binding */
3236 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3237 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3241 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3244 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3245 si->unnumbered_sw_if_index = sw_if_index;
3247 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3248 si->unnumbered_sw_if_index = (u32)~0;
3252 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3255 static void vl_api_create_loopback_t_handler
3256 (vl_api_create_loopback_t *mp)
3258 vl_api_create_loopback_reply_t * rmp;
3262 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3264 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3266 rmp->sw_if_index = ntohl (sw_if_index);
3270 static void vl_api_delete_loopback_t_handler
3271 (vl_api_delete_loopback_t *mp)
3273 vl_api_delete_loopback_reply_t * rmp;
3277 sw_if_index = ntohl (mp->sw_if_index);
3278 rv = vnet_delete_loopback_interface (sw_if_index);
3280 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3283 static void vl_api_control_ping_t_handler
3284 (vl_api_control_ping_t *mp)
3286 vl_api_control_ping_reply_t * rmp;
3289 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3291 rmp->vpe_pid = ntohl (getpid());
3295 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3297 u8 **shmem_vecp = (u8 **)arg;
3300 api_main_t * am = &api_main;
3303 shmem_vec = *shmem_vecp;
3305 offset = vec_len (shmem_vec);
3307 pthread_mutex_lock (&am->vlib_rp->mutex);
3308 oldheap = svm_push_data_heap (am->vlib_rp);
3310 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3312 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3314 svm_pop_heap (oldheap);
3315 pthread_mutex_unlock (&am->vlib_rp->mutex);
3317 *shmem_vecp = shmem_vec;
3321 static void vl_api_cli_request_t_handler
3322 (vl_api_cli_request_t *mp)
3324 vl_api_cli_reply_t *rp;
3325 unix_shared_memory_queue_t *q;
3326 vlib_main_t * vm = vlib_get_main();
3327 api_main_t * am = &api_main;
3328 unformat_input_t input;
3332 q = vl_api_client_index_to_input_queue (mp->client_index);
3336 rp = vl_msg_api_alloc (sizeof (*rp));
3337 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3338 rp->context = mp->context;
3340 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3342 vlib_cli_input (vm, &input, shmem_cli_output,
3345 pthread_mutex_lock (&am->vlib_rp->mutex);
3346 oldheap = svm_push_data_heap (am->vlib_rp);
3348 vec_add1(shmem_vec, 0);
3350 svm_pop_heap (oldheap);
3351 pthread_mutex_unlock (&am->vlib_rp->mutex);
3353 rp->reply_in_shmem = (uword)shmem_vec;
3355 vl_msg_api_send_shmem (q, (u8 *)&rp);
3358 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3361 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3362 vnet_main_t *vnm = vnet_get_main();
3363 clib_error_t * error;
3368 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3370 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3373 clib_error_report(error);
3374 rv = VNET_API_ERROR_UNSPECIFIED;
3376 rv = vnm->api_errno;
3379 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3382 static void vl_api_sr_tunnel_add_del_t_handler
3383 (vl_api_sr_tunnel_add_del_t *mp)
3386 clib_warning ("unimplemented");
3388 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3390 vl_api_sr_tunnel_add_del_reply_t * rmp;
3391 ip6_address_t * segments = 0, * seg;
3392 ip6_address_t * tags = 0, *tag;
3393 ip6_address_t * this_address;
3396 if (mp->n_segments == 0) {
3401 memset (a, 0, sizeof (*a));
3402 a->src_address = (ip6_address_t *)&mp->src_address;
3403 a->dst_address = (ip6_address_t *)&mp->dst_address;
3404 a->dst_mask_width = mp->dst_mask_width;
3405 a->flags_net_byte_order = mp->flags_net_byte_order;
3406 a->is_del = (mp->is_add == 0);
3407 a->rx_table_id = ntohl(mp->outer_vrf_id);
3408 a->tx_table_id = ntohl(mp->inner_vrf_id);
3410 a->name = format(0, "%s", mp->name);
3411 if (!(vec_len(a->name)))
3414 a->policy_name = format(0, "%s", mp->policy_name);
3415 if (!(vec_len(a->policy_name)))
3418 /* Yank segments and tags out of the API message */
3419 this_address = (ip6_address_t *)mp->segs_and_tags;
3420 for (i = 0; i < mp->n_segments; i++) {
3421 vec_add2 (segments, seg, 1);
3422 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3425 for (i = 0; i < mp->n_tags; i++) {
3426 vec_add2 (tags, tag, 1);
3427 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3431 a->segments = segments;
3434 rv = ip6_sr_add_del_tunnel (a);
3438 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3442 static void vl_api_sr_policy_add_del_t_handler
3443 (vl_api_sr_policy_add_del_t *mp)
3446 clib_warning ("unimplemented");
3448 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3450 vl_api_sr_policy_add_del_reply_t * rmp;
3453 memset (a, 0, sizeof (*a));
3454 a->is_del = (mp->is_add == 0);
3456 a->name = format(0, "%s", mp->name);
3457 if (!(vec_len(a->name)))
3459 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3463 if (!(mp->tunnel_names[0]))
3465 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3469 // start deserializing tunnel_names
3470 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3471 u8 * deser_tun_names = mp->tunnel_names;
3472 deser_tun_names += 1; //moving along
3475 int tun_name_len = 0;
3477 for (i=0; i < num_tunnels; i++)
3479 tun_name_len= *deser_tun_names;
3480 deser_tun_names += 1;
3481 vec_resize (tun_name, tun_name_len);
3482 memcpy(tun_name, deser_tun_names, tun_name_len);
3483 vec_add1 (a->tunnel_names, tun_name);
3484 deser_tun_names += tun_name_len;
3488 rv = ip6_sr_add_del_policy (a);
3492 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3496 static void vl_api_sr_multicast_map_add_del_t_handler
3497 (vl_api_sr_multicast_map_add_del_t *mp)
3500 clib_warning ("unimplemented");
3502 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3504 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3506 memset (a, 0, sizeof (*a));
3507 a->is_del = (mp->is_add == 0);
3509 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3510 a->policy_name = format(0, "%s", mp->policy_name);
3512 if (a->multicast_address == 0)
3518 if (!(a->policy_name))
3524 #if DPDK > 0 /* Cannot call replicate without DPDK */
3525 rv = ip6_sr_add_del_multicastmap (a);
3527 clib_warning ("multicast replication without DPDK not implemented");
3528 rv = VNET_API_ERROR_UNIMPLEMENTED;
3533 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3537 #define foreach_classify_add_del_table_field \
3542 _(match_n_vectors) \
3543 _(next_table_index) \
3546 static void vl_api_classify_add_del_table_t_handler
3547 (vl_api_classify_add_del_table_t * mp)
3549 vl_api_classify_add_del_table_reply_t * rmp;
3550 vnet_classify_main_t * cm = &vnet_classify_main;
3551 vnet_classify_table_t * t;
3555 foreach_classify_add_del_table_field;
3558 #define _(a) a = ntohl(mp->a);
3559 foreach_classify_add_del_table_field;
3562 /* The underlying API fails silently, on purpose, so check here */
3563 if (mp->is_add == 0)
3564 if (pool_is_free_index (cm->tables, table_index)) {
3565 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3569 rv = vnet_classify_add_del_table
3570 (cm, mp->mask, nbuckets, memory_size,
3571 skip_n_vectors, match_n_vectors,
3572 next_table_index, miss_next_index,
3573 &table_index, mp->is_add);
3576 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3578 if (rv == 0 && mp->is_add) {
3579 t = pool_elt_at_index (cm->tables, table_index);
3580 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3581 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3582 rmp->new_table_index = ntohl(table_index);
3584 rmp->skip_n_vectors = ~0;
3585 rmp->match_n_vectors = ~0;
3586 rmp->new_table_index = ~0;
3591 static void vl_api_classify_add_del_session_t_handler
3592 (vl_api_classify_add_del_session_t * mp)
3594 vnet_classify_main_t * cm = &vnet_classify_main;
3595 vl_api_classify_add_del_session_reply_t * rmp;
3597 u32 table_index, hit_next_index, opaque_index;
3600 table_index = ntohl (mp->table_index);
3601 hit_next_index = ntohl (mp->hit_next_index);
3602 opaque_index = ntohl (mp->opaque_index);
3603 advance = ntohl (mp->advance);
3605 rv = vnet_classify_add_del_session
3606 (cm, table_index, mp->match, hit_next_index, opaque_index,
3607 advance, mp->is_add);
3609 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3612 static void vl_api_classify_set_interface_ip_table_t_handler
3613 (vl_api_classify_set_interface_ip_table_t * mp)
3615 vlib_main_t * vm = vlib_get_main();
3616 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3618 u32 table_index, sw_if_index;
3620 table_index = ntohl (mp->table_index);
3621 sw_if_index = ntohl (mp->sw_if_index);
3623 VALIDATE_SW_IF_INDEX(mp);
3626 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3628 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3630 BAD_SW_IF_INDEX_LABEL;
3632 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3635 static void vl_api_classify_set_interface_l2_tables_t_handler
3636 (vl_api_classify_set_interface_l2_tables_t * mp)
3638 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3640 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3643 ip4_table_index = ntohl(mp->ip4_table_index);
3644 ip6_table_index = ntohl(mp->ip6_table_index);
3645 other_table_index = ntohl(mp->other_table_index);
3646 sw_if_index = ntohl(mp->sw_if_index);
3648 VALIDATE_SW_IF_INDEX(mp);
3650 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3651 ip6_table_index, other_table_index);
3654 if (ip4_table_index != ~0 || ip6_table_index != ~0
3655 || other_table_index != ~0)
3660 vnet_l2_classify_enable_disable (sw_if_index, enable);
3663 BAD_SW_IF_INDEX_LABEL;
3665 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3669 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3672 vl_api_l2_fib_clear_table_reply_t * rmp;
3674 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3675 * that is not currently implemented. When that TODO is fixed
3676 * this call should be changed to pass 1 instead of 0.
3678 l2fib_clear_table (0);
3680 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3683 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3688 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3691 vl_api_l2_interface_efp_filter_reply_t * rmp;
3692 vnet_main_t *vnm = vnet_get_main();
3694 // enable/disable the feature
3695 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3696 rv = vnm->api_errno;
3698 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3702 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3705 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3706 vnet_main_t * vnm = vnet_get_main();
3707 vlib_main_t * vm = vlib_get_main();
3710 VALIDATE_SW_IF_INDEX(mp);
3712 vtr_op = ntohl(mp->vtr_op);
3714 /* The L2 code is unsuspicious */
3716 case L2_VTR_DISABLED:
3721 case L2_VTR_TRANSLATE_1_1:
3722 case L2_VTR_TRANSLATE_1_2:
3723 case L2_VTR_TRANSLATE_2_1:
3724 case L2_VTR_TRANSLATE_2_2:
3728 rv = VNET_API_ERROR_INVALID_VALUE;
3729 goto bad_sw_if_index;
3732 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3733 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3736 BAD_SW_IF_INDEX_LABEL;
3738 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3742 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3746 vl_api_create_vhost_user_if_reply_t * rmp;
3747 u32 sw_if_index = (u32)~0;
3749 vnet_main_t * vnm = vnet_get_main();
3750 vlib_main_t * vm = vlib_get_main();
3752 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3753 mp->is_server, &sw_if_index, (u64)~0,
3754 mp->renumber, ntohl(mp->custom_dev_instance),
3755 (mp->use_custom_mac)?mp->mac_address:NULL);
3757 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3759 rmp->sw_if_index = ntohl (sw_if_index);
3765 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3769 vl_api_modify_vhost_user_if_reply_t * rmp;
3770 u32 sw_if_index = ntohl(mp->sw_if_index);
3772 vnet_main_t * vnm = vnet_get_main();
3773 vlib_main_t * vm = vlib_get_main();
3775 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3776 mp->is_server, sw_if_index, (u64)~0,
3777 mp->renumber, ntohl(mp->custom_dev_instance));
3779 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3784 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3788 vpe_api_main_t * vam = &vpe_api_main;
3789 vl_api_delete_vhost_user_if_reply_t * rmp;
3790 u32 sw_if_index = ntohl(mp->sw_if_index);
3792 vnet_main_t * vnm = vnet_get_main();
3793 vlib_main_t * vm = vlib_get_main();
3795 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3797 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3799 unix_shared_memory_queue_t * q =
3800 vl_api_client_index_to_input_queue (mp->client_index);
3804 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3809 static void vl_api_sw_interface_vhost_user_details_t_handler (
3810 vl_api_sw_interface_vhost_user_details_t * mp)
3812 clib_warning ("BUG");
3816 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3817 unix_shared_memory_queue_t *q,
3818 vhost_user_intf_details_t * vui,
3821 vl_api_sw_interface_vhost_user_details_t * mp;
3823 mp = vl_msg_api_alloc (sizeof (*mp));
3824 memset (mp, 0, sizeof (*mp));
3825 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3826 mp->sw_if_index = ntohl(vui->sw_if_index);
3827 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3828 mp->features = clib_net_to_host_u64 (vui->features);
3829 mp->is_server = vui->is_server;
3830 mp->num_regions = ntohl(vui->num_regions);
3831 mp->sock_errno = ntohl(vui->sock_errno);
3832 mp->context = context;
3834 strncpy ((char *) mp->sock_filename,
3835 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3836 strncpy ((char *) mp->interface_name,
3837 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3839 vl_msg_api_send_shmem (q, (u8 *)&mp);
3844 vl_api_sw_interface_vhost_user_dump_t_handler (
3845 vl_api_sw_interface_vhost_user_dump_t *mp)
3849 vpe_api_main_t * am = &vpe_api_main;
3850 vnet_main_t * vnm = vnet_get_main();
3851 vlib_main_t * vm = vlib_get_main();
3852 vhost_user_intf_details_t *ifaces = NULL;
3853 vhost_user_intf_details_t *vuid = NULL;
3854 unix_shared_memory_queue_t * q;
3856 q = vl_api_client_index_to_input_queue (mp->client_index);
3860 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3864 vec_foreach (vuid, ifaces) {
3865 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3871 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3872 unix_shared_memory_queue_t *q,
3877 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3878 u8 * if_name = NULL;
3879 vnet_sw_interface_t * si = NULL;
3881 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3883 if_name = format(if_name, "%U",
3884 format_vnet_sw_interface_name, lm->vnet_main, si);
3886 mp = vl_msg_api_alloc (sizeof (*mp));
3887 memset (mp, 0, sizeof (*mp));
3888 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3889 strncpy((char *)mp->interface_name,
3890 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3891 mp->sw_if_index = ntohl(si->sw_if_index);
3892 mp->local_session_id = s->local_session_id;
3893 mp->remote_session_id = s->remote_session_id;
3894 mp->local_cookie[0] = s->local_cookie[0];
3895 mp->local_cookie[1] = s->local_cookie[1];
3896 mp->remote_cookie = s->remote_cookie;
3897 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3898 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3899 mp->l2_sublayer_present = s->l2_sublayer_present;
3900 mp->context = context;
3902 vl_msg_api_send_shmem (q, (u8 *)&mp);
3905 static void send_ip_address_details (vpe_api_main_t * am,
3906 unix_shared_memory_queue_t * q,
3912 vl_api_ip_address_details_t * mp;
3914 mp = vl_msg_api_alloc (sizeof (*mp));
3915 memset (mp, 0, sizeof (*mp));
3916 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3919 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3921 u32 * tp = (u32 *)mp->ip;
3922 *tp = ntohl(*(u32*)ip);
3924 mp->prefix_length = prefix_length;
3925 mp->context = context;
3927 vl_msg_api_send_shmem (q, (u8 *)&mp);
3931 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3933 vpe_api_main_t * am = &vpe_api_main;
3934 unix_shared_memory_queue_t * q;
3937 ip6_main_t * im6 = &ip6_main;
3938 ip4_main_t * im4 = &ip4_main;
3939 ip_lookup_main_t * lm6 = &im6->lookup_main;
3940 ip_lookup_main_t * lm4 = &im4->lookup_main;
3941 ip_interface_address_t * ia = 0;
3942 u32 sw_if_index = ~0;
3943 int rv __attribute__ ((unused)) = 0;
3945 VALIDATE_SW_IF_INDEX(mp);
3947 sw_if_index = ntohl(mp->sw_if_index);
3949 q = vl_api_client_index_to_input_queue (mp->client_index);
3955 foreach_ip_interface_address (lm6, ia, sw_if_index,
3956 1 /* honor unnumbered */,
3958 r6 = ip_interface_address_get_address (lm6, ia);
3959 u16 prefix_length = ia->address_length;
3960 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3963 foreach_ip_interface_address (lm4, ia, sw_if_index,
3964 1 /* honor unnumbered */,
3966 r4 = ip_interface_address_get_address (lm4, ia);
3967 u16 prefix_length = ia->address_length;
3968 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3971 BAD_SW_IF_INDEX_LABEL;
3974 static void send_ip_details (vpe_api_main_t * am,
3975 unix_shared_memory_queue_t *q,
3979 vl_api_ip_details_t * mp;
3981 mp = vl_msg_api_alloc (sizeof (*mp));
3982 memset (mp, 0, sizeof (*mp));
3983 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3985 mp->sw_if_index = ntohl(sw_if_index);
3986 mp->context = context;
3988 vl_msg_api_send_shmem (q, (u8 *)&mp);
3992 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3993 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3995 vpe_api_main_t * am = &vpe_api_main;
3996 l2t_main_t * lm = &l2t_main;
3997 unix_shared_memory_queue_t * q;
3998 l2t_session_t *session;
4000 q = vl_api_client_index_to_input_queue (mp->client_index);
4004 pool_foreach (session, lm->sessions,
4006 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4011 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4012 unix_shared_memory_queue_t *q,
4013 tapcli_interface_details_t *tap_if,
4016 vl_api_sw_interface_tap_details_t * mp;
4017 mp = vl_msg_api_alloc (sizeof (*mp));
4018 memset (mp, 0, sizeof (*mp));
4019 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4020 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4021 strncpy((char *)mp->dev_name,
4022 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4023 mp->context = context;
4025 vl_msg_api_send_shmem (q, (u8 *)&mp);
4029 vl_api_sw_interface_tap_dump_t_handler (
4030 vl_api_sw_interface_tap_dump_t *mp)
4033 vpe_api_main_t * am = &vpe_api_main;
4034 unix_shared_memory_queue_t * q;
4035 tapcli_interface_details_t *tapifs = NULL;
4036 tapcli_interface_details_t *tap_if = NULL;
4038 q = vl_api_client_index_to_input_queue (mp->client_index);
4042 rv = vnet_tap_dump_ifs(&tapifs);
4046 vec_foreach(tap_if, tapifs) {
4047 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4054 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4056 vpe_api_main_t * am = &vpe_api_main;
4057 vnet_main_t * vnm = vnet_get_main();
4058 vlib_main_t * vm = vlib_get_main();
4059 vnet_interface_main_t * im = &vnm->interface_main;
4060 unix_shared_memory_queue_t * q;
4061 vnet_sw_interface_t * si, * sorted_sis;
4062 u32 sw_if_index = ~0;
4064 q = vl_api_client_index_to_input_queue (mp->client_index);
4069 /* Gather interfaces. */
4070 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4071 _vec_len (sorted_sis) = 0;
4072 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4074 vec_foreach (si, sorted_sis) {
4075 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4076 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4079 sw_if_index = si->sw_if_index;
4080 send_ip_details(am, q, sw_if_index, mp->context);
4085 static void vl_api_l2_fib_table_entry_t_handler (
4086 vl_api_l2_fib_table_entry_t * mp)
4088 clib_warning ("BUG");
4091 static void send_l2fib_table_entry (vpe_api_main_t * am,
4092 unix_shared_memory_queue_t *q,
4093 l2fib_entry_key_t * l2fe_key,
4094 l2fib_entry_result_t * l2fe_res,
4097 vl_api_l2_fib_table_entry_t * mp;
4099 mp = vl_msg_api_alloc (sizeof (*mp));
4100 memset (mp, 0, sizeof (*mp));
4101 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4103 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4105 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4106 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4107 mp->static_mac = l2fe_res->fields.static_mac;
4108 mp->filter_mac = l2fe_res->fields.filter;
4109 mp->bvi_mac = l2fe_res->fields.bvi;
4110 mp->context = context;
4112 vl_msg_api_send_shmem (q, (u8 *)&mp);
4116 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4118 vpe_api_main_t * am = &vpe_api_main;
4119 bd_main_t * bdm = &bd_main;
4120 l2fib_entry_key_t *l2fe_key = NULL;
4121 l2fib_entry_result_t *l2fe_res = NULL;
4122 u32 ni, bd_id = ntohl (mp->bd_id);
4124 unix_shared_memory_queue_t * q;
4127 q = vl_api_client_index_to_input_queue (mp->client_index);
4131 /* see l2fib_table_dump: ~0 means "any" */
4135 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4142 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4144 vec_foreach_index (ni, l2fe_key) {
4145 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4146 vec_elt_at_index(l2fe_res, ni), mp->context);
4153 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4155 vl_api_show_version_reply_t *rmp;
4157 char * vpe_api_get_build_directory(void);
4158 char * vpe_api_get_version(void);
4159 char * vpe_api_get_build_date(void);
4161 unix_shared_memory_queue_t * q =
4162 vl_api_client_index_to_input_queue (mp->client_index);
4167 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4169 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4170 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4171 ARRAY_LEN(rmp->build_directory)-1);
4172 strncpy ((char *) rmp->version, vpe_api_get_version(),
4173 ARRAY_LEN(rmp->version)-1);
4174 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4175 ARRAY_LEN(rmp->build_date)-1);
4179 static void vl_api_get_node_index_t_handler
4180 (vl_api_get_node_index_t * mp)
4182 vlib_main_t * vm = vlib_get_main();
4183 vl_api_get_node_index_reply_t * rmp;
4186 u32 node_index = ~0;
4188 n = vlib_get_node_by_name (vm, mp->node_name);
4191 rv = VNET_API_ERROR_NO_SUCH_NODE;
4193 node_index = n->index;
4195 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4197 rmp->node_index = ntohl(node_index);
4201 static void vl_api_add_node_next_t_handler
4202 (vl_api_add_node_next_t * mp)
4204 vlib_main_t * vm = vlib_get_main();
4205 vl_api_add_node_next_reply_t * rmp;
4206 vlib_node_t * n, * next;
4208 u32 next_index = ~0;
4210 n = vlib_get_node_by_name (vm, mp->node_name);
4213 rv = VNET_API_ERROR_NO_SUCH_NODE;
4217 next = vlib_get_node_by_name (vm, mp->next_name);
4220 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4222 next_index = vlib_node_add_next (vm, n->index, next->index);
4225 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4227 rmp->next_index = ntohl(next_index);
4231 static void vl_api_l2tpv3_create_tunnel_t_handler
4232 (vl_api_l2tpv3_create_tunnel_t *mp)
4234 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4235 l2t_main_t *lm = &l2t_main;
4236 u32 sw_if_index = (u32)~0;
4239 if (mp->is_ipv6 != 1) {
4240 rv = VNET_API_ERROR_UNIMPLEMENTED;
4244 rv = create_l2tpv3_ipv6_tunnel (lm,
4245 (ip6_address_t *) mp->client_address,
4246 (ip6_address_t *) mp->our_address,
4247 ntohl(mp->local_session_id),
4248 ntohl(mp->remote_session_id),
4249 clib_net_to_host_u64(mp->local_cookie),
4250 clib_net_to_host_u64(mp->remote_cookie),
4251 mp->l2_sublayer_present,
4255 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4257 rmp->sw_if_index = ntohl (sw_if_index);
4261 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4262 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4264 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4265 l2t_main_t *lm = &l2t_main;
4268 VALIDATE_SW_IF_INDEX(mp);
4270 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4271 clib_net_to_host_u64(mp->new_local_cookie),
4272 clib_net_to_host_u64(mp->new_remote_cookie));
4274 BAD_SW_IF_INDEX_LABEL;
4276 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4279 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4280 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4283 vnet_main_t * vnm = vnet_get_main();
4284 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4286 VALIDATE_SW_IF_INDEX(mp);
4288 rv = l2tpv3_interface_enable_disable
4289 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4291 BAD_SW_IF_INDEX_LABEL;
4293 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4296 static void vl_api_l2tpv3_set_lookup_key_t_handler
4297 (vl_api_l2tpv3_set_lookup_key_t * mp)
4300 l2t_main_t *lm = &l2t_main;
4301 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4303 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4304 rv = VNET_API_ERROR_INVALID_VALUE;
4308 lm->lookup_type = mp->key;
4311 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4314 static void vl_api_vxlan_add_del_tunnel_t_handler
4315 (vl_api_vxlan_add_del_tunnel_t * mp)
4317 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4319 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4320 u32 encap_fib_index;
4322 ip4_main_t * im = &ip4_main;
4323 u32 sw_if_index = ~0;
4325 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4327 rv = VNET_API_ERROR_NO_SUCH_FIB;
4330 encap_fib_index = p[0];
4332 /* Check src & dst are different */
4333 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4334 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4335 rv = VNET_API_ERROR_SAME_SRC_DST;
4338 memset (a, 0, sizeof (*a));
4340 a->is_add = mp->is_add;
4341 a->is_ip6 = mp->is_ipv6;
4343 /* ip addresses sent in network byte order */
4345 memcpy(&(a->src.ip6), mp->src_address, 16);
4346 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4348 memcpy(&(a->src.ip4), mp->src_address, 4);
4349 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4352 a->encap_fib_index = encap_fib_index;
4353 a->decap_next_index = ntohl(mp->decap_next_index);
4354 a->vni = ntohl(mp->vni);
4355 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4358 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4360 rmp->sw_if_index = ntohl (sw_if_index);
4364 static void send_vxlan_tunnel_details
4365 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4367 vl_api_vxlan_tunnel_details_t * rmp;
4368 ip4_main_t * im4 = &ip4_main;
4369 ip6_main_t * im6 = &ip6_main;
4370 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4372 rmp = vl_msg_api_alloc (sizeof (*rmp));
4373 memset (rmp, 0, sizeof (*rmp));
4374 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4376 memcpy(rmp->src_address, &(t->src.ip6), 16);
4377 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4378 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4380 memcpy(rmp->src_address, &(t->src.ip4), 4);
4381 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4382 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4384 rmp->vni = htonl(t->vni);
4385 rmp->decap_next_index = htonl(t->decap_next_index);
4386 rmp->sw_if_index = htonl(t->sw_if_index);
4387 rmp->is_ipv6 = is_ipv6;
4388 rmp->context = context;
4390 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4393 static void vl_api_vxlan_tunnel_dump_t_handler
4394 (vl_api_vxlan_tunnel_dump_t * mp)
4396 unix_shared_memory_queue_t * q;
4397 vxlan_main_t * vxm = &vxlan_main;
4401 q = vl_api_client_index_to_input_queue (mp->client_index);
4406 sw_if_index = ntohl(mp->sw_if_index);
4408 if (~0 == sw_if_index) {
4409 pool_foreach (t, vxm->tunnels,
4411 send_vxlan_tunnel_details(t, q, mp->context);
4414 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4415 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4418 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4419 send_vxlan_tunnel_details(t, q, mp->context);
4423 static void vl_api_gre_add_del_tunnel_t_handler
4424 (vl_api_gre_add_del_tunnel_t * mp)
4426 vl_api_gre_add_del_tunnel_reply_t * rmp;
4428 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4431 ip4_main_t * im = &ip4_main;
4432 u32 sw_if_index = ~0;
4434 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4436 rv = VNET_API_ERROR_NO_SUCH_FIB;
4439 outer_table_id = p[0];
4441 /* Check src & dst are different */
4442 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4443 rv = VNET_API_ERROR_SAME_SRC_DST;
4447 memset (a, 0, sizeof (*a));
4449 a->is_add = mp->is_add;
4451 /* ip addresses sent in network byte order */
4452 a->src.as_u32 = mp->src_address;
4453 a->dst.as_u32 = mp->dst_address;
4455 a->outer_table_id = outer_table_id;
4456 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4459 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4461 rmp->sw_if_index = ntohl (sw_if_index);
4465 static void send_gre_tunnel_details
4466 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4468 vl_api_gre_tunnel_details_t * rmp;
4469 ip4_main_t * im = &ip4_main;
4471 rmp = vl_msg_api_alloc (sizeof (*rmp));
4472 memset (rmp, 0, sizeof (*rmp));
4473 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4474 rmp->src_address = t->tunnel_src.data_u32;
4475 rmp->dst_address = t->tunnel_dst.data_u32;
4476 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4477 rmp->sw_if_index = htonl(t->sw_if_index);
4478 rmp->context = context;
4480 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4483 static void vl_api_gre_tunnel_dump_t_handler
4484 (vl_api_gre_tunnel_dump_t * mp)
4486 unix_shared_memory_queue_t * q;
4487 gre_main_t * gm = &gre_main;
4491 q = vl_api_client_index_to_input_queue (mp->client_index);
4496 sw_if_index = ntohl(mp->sw_if_index);
4498 if (~0 == sw_if_index) {
4499 pool_foreach (t, gm->tunnels,
4501 send_gre_tunnel_details(t, q, mp->context);
4504 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4505 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4508 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4509 send_gre_tunnel_details(t, q, mp->context);
4514 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4516 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4518 vl_api_l2_patch_add_del_reply_t * rmp;
4519 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4523 VALIDATE_RX_SW_IF_INDEX(mp);
4524 VALIDATE_TX_SW_IF_INDEX(mp);
4526 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4527 ntohl(mp->tx_sw_if_index),
4528 (int)(mp->is_add != 0));
4530 BAD_RX_SW_IF_INDEX_LABEL;
4531 BAD_TX_SW_IF_INDEX_LABEL;
4533 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4537 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4538 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4540 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4542 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4543 u32 encap_fib_index, decap_fib_index;
4546 ip4_main_t * im = &ip4_main;
4547 u32 sw_if_index = ~0;
4550 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4552 rv = VNET_API_ERROR_NO_SUCH_FIB;
4555 encap_fib_index = p[0];
4557 protocol = ntohl(mp->protocol);
4559 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4560 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4561 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4563 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4566 decap_fib_index = p[0];
4568 decap_fib_index = ntohl(mp->decap_vrf_id);
4571 /* Check src & dst are different */
4572 if ((a->is_ip6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4573 (!a->is_ip6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4574 rv = VNET_API_ERROR_SAME_SRC_DST;
4577 memset (a, 0, sizeof (*a));
4579 a->is_add = mp->is_add;
4580 a->is_ip6 = mp->is_ipv6;
4581 /* ip addresses sent in network byte order */
4583 clib_memcpy(&(a->local.ip6), mp->local, 16);
4584 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4586 clib_memcpy(&(a->local.ip4), mp->local, 4);
4587 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4589 a->encap_fib_index = encap_fib_index;
4590 a->decap_fib_index = decap_fib_index;
4591 a->protocol = protocol;
4592 a->vni = ntohl(mp->vni);
4593 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4596 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4598 rmp->sw_if_index = ntohl (sw_if_index);
4603 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4605 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4607 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4609 u8 *locator_name = NULL;
4611 memset(a, 0, sizeof(a[0]));
4613 locator_name = format(0, "%s", mp->locator_set_name);
4615 a->name = locator_name;
4617 a->is_add = mp->is_add;
4620 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4622 vec_free(locator_name);
4624 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4628 vl_api_lisp_add_del_locator_t_handler(
4629 vl_api_lisp_add_del_locator_t *mp)
4631 vl_api_lisp_add_del_locator_reply_t *rmp;
4633 locator_t locator, *locators = NULL;
4634 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4636 u8 *locator_name = NULL;
4638 memset(&locator, 0, sizeof(locator));
4639 memset(a, 0, sizeof(a[0]));
4641 locator.sw_if_index = ntohl(mp->sw_if_index);
4642 locator.priority = mp->priority;
4643 locator.weight = mp->weight;
4645 vec_add1(locators, locator);
4647 locator_name = format(0, "%s", mp->locator_set_name);
4649 a->name = locator_name;
4650 a->locators = locators;
4651 a->is_add = mp->is_add;
4654 rv = vnet_lisp_add_del_locator(a, &ls_index);
4657 vec_free(locator_name);
4659 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4663 vl_api_lisp_add_del_local_eid_t_handler(
4664 vl_api_lisp_add_del_local_eid_t *mp)
4666 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4667 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4669 ip_prefix_t *prefp = NULL;
4670 ip_address_t *ip_eid = NULL;
4673 u32 locator_set_index = ~0, map_index = ~0;
4674 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4677 prefp = &gid_address_ippref(&eid);
4678 ip_eid = &ip_prefix_addr(prefp);
4679 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4682 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4683 sizeof(ip_addr_v6(ip_eid)));
4684 ip_addr_version(ip_eid) = IP6;
4686 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4687 sizeof(ip_addr_v4(ip_eid)));
4688 ip_addr_version(ip_eid) = IP4;
4690 ip_prefix_len(prefp) = mp->prefix_len;
4692 name = format(0, "%s", mp->locator_set_name);
4693 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4695 rv = VNET_API_ERROR_INVALID_VALUE;
4698 locator_set_index = p[0];
4700 /* XXX treat batch configuration */
4701 a->is_add = mp->is_add;
4703 a->locator_set_index = locator_set_index;
4706 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4711 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4715 lisp_gpe_add_del_fwd_entry_set_address(
4716 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4717 ip_address_t *slocator,
4718 ip_address_t *dlocator,
4721 ip_address_t *ip_eid = NULL;
4722 ip_prefix_t *prefp = NULL;
4724 prefp = &gid_address_ippref(eid);
4725 ip_eid = &ip_prefix_addr(prefp);
4727 if (mp->eid_is_ipv6) {
4728 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4729 sizeof(ip_addr_v6(ip_eid)));
4730 ip_addr_version(ip_eid) = IP6;
4732 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4733 sizeof(ip_addr_v4(ip_eid)));
4734 ip_addr_version(ip_eid) = IP4;
4736 ip_prefix_len(prefp) = mp->eid_prefix_len;
4738 if (mp->address_is_ipv6) {
4739 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4740 sizeof(ip_addr_v6(slocator)));
4741 ip_addr_version(slocator) = IP6;
4742 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4743 sizeof(ip_addr_v6(dlocator)));
4744 ip_addr_version(dlocator) = IP6;
4746 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4747 sizeof(ip_addr_v4(slocator)));
4748 ip_addr_version(slocator) = IP4;
4749 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4750 sizeof(ip_addr_v4(dlocator)));
4751 ip_addr_version(dlocator) = IP4;
4756 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4757 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4759 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4761 ip_address_t slocator, dlocator;
4763 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4765 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4767 memset (&a, 0, sizeof(a));
4769 a.is_add = mp->is_add;
4771 a.slocator = slocator;
4772 a.dlocator = dlocator;
4773 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4775 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4779 vl_api_lisp_add_del_map_resolver_t_handler(
4780 vl_api_lisp_add_del_map_resolver_t *mp)
4782 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4784 ip_address_t *ip_addr = NULL;
4785 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4787 a->is_add = mp->is_add;
4788 ip_addr = &a->address;
4791 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4792 sizeof(ip_addr_v6(ip_addr)));
4793 ip_addr_version(ip_addr) = IP6;
4795 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4796 sizeof(ip_addr_v4(ip_addr)));
4797 ip_addr_version(ip_addr) = IP4;
4800 rv = vnet_lisp_add_del_map_resolver (a);
4802 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4806 vl_api_lisp_gpe_enable_disable_t_handler(
4807 vl_api_lisp_gpe_enable_disable_t *mp)
4809 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4811 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4813 a->is_en = mp->is_en;
4814 vnet_lisp_gpe_enable_disable (a);
4816 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4820 vl_api_lisp_enable_disable_t_handler(
4821 vl_api_lisp_enable_disable_t *mp)
4823 vl_api_lisp_enable_disable_reply_t *rmp;
4826 vnet_lisp_enable_disable (mp->is_en);
4827 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4831 vl_api_lisp_gpe_add_del_iface_t_handler(
4832 vl_api_lisp_gpe_add_del_iface_t *mp)
4834 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4836 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4838 a->is_add = mp->is_add;
4839 a->table_id = mp->table_id;
4841 vnet_lisp_gpe_add_del_iface (a, 0);
4843 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4847 vl_api_lisp_pitr_set_locator_set_t_handler(
4848 vl_api_lisp_pitr_set_locator_set_t *mp)
4850 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4854 ls_name = format (0, "%s", mp->ls_name);
4855 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4858 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4861 /** Used for transferring locators via VPP API */
4862 typedef CLIB_PACKED(struct
4864 u8 is_ip4; /**< is locator an IPv4 address */
4865 u8 addr[16]; /**< IPv4/IPv6 address */
4869 send_lisp_locator_set_details_set_address
4870 (vl_api_lisp_locator_set_details_t *rmp,
4871 gid_address_t *gid_address)
4873 ip_prefix_t *ip_addr;
4875 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4879 ip_addr = &gid_address_ippref(gid_address);
4880 rmp->prefix_len = ip_prefix_len(ip_addr);
4881 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4882 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4886 vl_api_lisp_add_del_remote_mapping_t_handler (
4887 vl_api_lisp_add_del_remote_mapping_t *mp)
4890 ip_address_t rloc, * rlocs = 0;
4891 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
4893 gid_address_t _seid, * seid = &_seid;
4894 gid_address_t _deid, * deid = &_deid;
4895 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
4896 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
4898 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
4899 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
4900 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
4901 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
4902 ip_prefix_len(seid_pref) = mp->seid_len;
4903 ip_prefix_len(deid_pref) = mp->deid_len;
4904 gid_address_set_vni (seid, ntohl (mp->vni));
4905 gid_address_set_vni (deid, ntohl (mp->vni));
4907 if (mp->eid_is_ip4) {
4908 ip_prefix_version(seid_pref) = IP4;
4909 ip_prefix_version(deid_pref) = IP4;
4910 clib_memcpy (&ip_addr_v4(seid_addr),
4911 mp->seid, sizeof (ip_addr_v4(seid_addr)));
4912 clib_memcpy (&ip_addr_v4(deid_addr),
4913 mp->deid, sizeof (ip_addr_v4(deid_addr)));
4915 ip_prefix_version(seid_pref) = IP6;
4916 ip_prefix_version(deid_pref) = IP6;
4917 clib_memcpy (&ip_addr_v6(seid_addr),
4918 mp->seid, sizeof (ip_addr_v6(seid_addr)));
4919 clib_memcpy (&ip_addr_v6(deid_addr),
4920 mp->deid, sizeof (ip_addr_v6(deid_addr)));
4923 for (i = 0; i < mp->rloc_num; i++) {
4924 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
4926 clib_memcpy (&ip_addr_v4(&rloc), &r->addr, sizeof (rloc_t));
4927 ip_addr_version (&rloc) = IP4;
4929 clib_memcpy (&ip_addr_v6(&rloc), &r->addr, sizeof (rloc_t));
4930 ip_addr_version (&rloc) = IP6;
4932 vec_add1 (rlocs, rloc);
4935 rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs,
4936 mp->action, mp->is_add);
4938 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4942 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4943 locator_set_t *lsit,
4944 unix_shared_memory_queue_t *q,
4948 vl_api_lisp_locator_set_details_t *rmp;
4949 locator_t *loc = NULL;
4953 vec_foreach (locit, lsit->locator_indices) {
4954 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4955 rmp = vl_msg_api_alloc (sizeof (*rmp));
4956 memset (rmp, 0, sizeof (*rmp));
4957 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4958 rmp->local = lsit->local;
4960 ASSERT(lsit->name != NULL);
4961 strncpy((char *) rmp->locator_set_name,
4962 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4963 rmp->sw_if_index = htonl(loc->sw_if_index);
4965 str = format(0, "remote-%d", index);
4966 strncpy((char *) rmp->locator_set_name, (char *) str,
4967 ARRAY_LEN(rmp->locator_set_name) - 1);
4968 send_lisp_locator_set_details_set_address(rmp, &loc->address);
4972 rmp->priority = loc->priority;
4973 rmp->weight = loc->weight;
4974 rmp->context = context;
4976 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4981 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4983 unix_shared_memory_queue_t * q = NULL;
4984 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4985 locator_set_t * lsit = NULL;
4988 q = vl_api_client_index_to_input_queue (mp->client_index);
4994 pool_foreach (lsit, lcm->locator_set_pool,
4996 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5001 send_lisp_local_eid_table_details (mapping_t *mapit,
5002 unix_shared_memory_queue_t *q,
5005 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5006 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5007 locator_set_t *ls = NULL;
5008 gid_address_t *gid = NULL;
5009 ip_prefix_t *ip_prefix = NULL;
5013 ls = pool_elt_at_index (lcm->locator_set_pool,
5014 mapit->locator_set_index);
5017 type = gid_address_type(gid);
5019 if (type != GID_ADDR_IP_PREFIX) {
5023 ip_prefix = &gid_address_ippref(gid);
5025 rmp = vl_msg_api_alloc (sizeof (*rmp));
5026 memset (rmp, 0, sizeof (*rmp));
5027 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5029 ASSERT(ls->name != NULL);
5030 strncpy((char *) rmp->locator_set_name,
5031 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5033 str = format(0, "remote-%d", mapit->locator_set_index);
5034 strncpy((char *) rmp->locator_set_name, (char *) str,
5035 ARRAY_LEN(rmp->locator_set_name) - 1);
5039 switch (ip_prefix_version(ip_prefix)) {
5041 rmp->eid_is_ipv6 = 0;
5042 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5043 sizeof(ip_prefix_v4(ip_prefix)));
5047 rmp->eid_is_ipv6 = 1;
5048 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5049 sizeof(ip_prefix_v6(ip_prefix)));
5055 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5056 rmp->context = context;
5058 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5062 vl_api_lisp_local_eid_table_dump_t_handler (
5063 vl_api_lisp_local_eid_table_dump_t *mp)
5065 unix_shared_memory_queue_t * q = NULL;
5066 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5067 mapping_t * mapit = NULL;
5069 q = vl_api_client_index_to_input_queue (mp->client_index);
5074 pool_foreach (mapit, lcm->mapping_pool,
5076 send_lisp_local_eid_table_details(mapit, q, mp->context);
5081 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5082 unix_shared_memory_queue_t *q,
5085 vl_api_lisp_gpe_tunnel_details_t *rmp;
5086 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5088 rmp = vl_msg_api_alloc (sizeof (*rmp));
5089 memset (rmp, 0, sizeof (*rmp));
5090 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5092 rmp->tunnels = tunnel - lgm->tunnels;
5094 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5095 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5096 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5098 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5099 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5100 rmp->dcap_next = htonl(tunnel->decap_next_index);
5101 rmp->lisp_ver = tunnel->ver_res;
5102 rmp->next_protocol = tunnel->next_protocol;
5103 rmp->flags = tunnel->flags;
5104 rmp->ver_res = tunnel->ver_res;
5105 rmp->res = tunnel->res;
5106 rmp->iid = htonl(tunnel->vni);
5107 rmp->context = context;
5109 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5113 vl_api_lisp_gpe_tunnel_dump_t_handler (
5114 vl_api_lisp_local_eid_table_dump_t *mp)
5116 unix_shared_memory_queue_t * q = NULL;
5117 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5118 lisp_gpe_tunnel_t * tunnel = NULL;
5120 if (pool_elts(lgm->tunnels) == 0) {
5124 q = vl_api_client_index_to_input_queue (mp->client_index);
5129 pool_foreach(tunnel, lgm->tunnels,
5131 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5136 send_lisp_map_resolver_details (ip_address_t *ip,
5137 unix_shared_memory_queue_t *q,
5140 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5142 rmp = vl_msg_api_alloc (sizeof (*rmp));
5143 memset (rmp, 0, sizeof (*rmp));
5144 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5146 switch (ip_addr_version(ip)) {
5149 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5154 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5160 rmp->context = context;
5162 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5166 vl_api_lisp_map_resolver_dump_t_handler (
5167 vl_api_lisp_local_eid_table_dump_t *mp)
5169 unix_shared_memory_queue_t * q = NULL;
5170 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5171 ip_address_t *ip = NULL;
5173 q = vl_api_client_index_to_input_queue (mp->client_index);
5178 vec_foreach(ip, lcm->map_resolvers) {
5179 send_lisp_map_resolver_details(ip, q, mp->context);
5185 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5188 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5190 rmp = vl_msg_api_alloc (sizeof (*rmp));
5191 memset (rmp, 0, sizeof (*rmp));
5192 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5194 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5195 rmp->feature_status = vnet_lisp_enable_disable_status ();
5196 rmp->context = context;
5198 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5202 vl_api_lisp_enable_disable_status_dump_t_handler
5203 (vl_api_lisp_enable_disable_status_dump_t *mp)
5205 unix_shared_memory_queue_t * q = NULL;
5207 q = vl_api_client_index_to_input_queue (mp->client_index);
5212 send_lisp_enable_disable_details(q, mp->context);
5216 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5218 vl_api_interface_name_renumber_reply_t * rmp;
5221 VALIDATE_SW_IF_INDEX(mp);
5223 rv = vnet_interface_name_renumber
5224 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5226 BAD_SW_IF_INDEX_LABEL;
5228 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5231 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5232 u32 sw_if_index, u32 address)
5234 vpe_api_main_t * am = &vpe_api_main;
5235 vlib_main_t * vm = am->vlib_main;
5236 vl_api_ip4_arp_event_t * event;
5237 static f64 arp_event_last_time;
5238 f64 now = vlib_time_now (vm);
5240 if (pool_is_free_index (am->arp_events, pool_index))
5243 event = pool_elt_at_index (am->arp_events, pool_index);
5244 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5245 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5246 } else { /* same mac */
5247 if ((sw_if_index == event->sw_if_index) &&
5249 /* for BD case, also check IP address with 10 sec timeout */
5250 ((address == event->address) &&
5251 ((now - arp_event_last_time) < 10.0))))
5255 arp_event_last_time = now;
5256 event->sw_if_index = sw_if_index;
5257 if (address) event->address = address;
5261 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5263 vpe_api_main_t * am = &vpe_api_main;
5265 if (pool_is_free_index (am->arp_events, pool_index))
5268 pool_put_index (am->arp_events, pool_index);
5273 vl_api_want_ip4_arp_events_t_handler
5274 (vl_api_want_ip4_arp_events_t * mp)
5276 vpe_api_main_t * am = &vpe_api_main;
5277 vnet_main_t * vnm = vnet_get_main();
5278 vl_api_want_ip4_arp_events_reply_t *rmp;
5279 vl_api_ip4_arp_event_t * event;
5282 if (mp->enable_disable) {
5283 pool_get (am->arp_events, event);
5284 memset (event, 0, sizeof (*event));
5286 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5287 event->client_index = mp->client_index;
5288 event->context = mp->context;
5289 event->address = mp->address;
5290 event->pid = mp->pid;
5292 rv = vnet_add_del_ip4_arp_change_event
5293 (vnm, arp_change_data_callback,
5295 &mp->address /* addr, in net byte order */,
5296 vpe_resolver_process_node.index,
5297 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5299 rv = vnet_add_del_ip4_arp_change_event
5300 (vnm, arp_change_delete_callback,
5302 &mp->address /* addr, in net byte order */,
5303 vpe_resolver_process_node.index,
5304 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5306 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5309 static void vl_api_input_acl_set_interface_t_handler
5310 (vl_api_input_acl_set_interface_t * mp)
5312 vlib_main_t *vm = vlib_get_main();
5313 vl_api_input_acl_set_interface_reply_t * rmp;
5315 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5317 ip4_table_index = ntohl(mp->ip4_table_index);
5318 ip6_table_index = ntohl(mp->ip6_table_index);
5319 l2_table_index = ntohl(mp->l2_table_index);
5320 sw_if_index = ntohl(mp->sw_if_index);
5322 VALIDATE_SW_IF_INDEX(mp);
5324 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5325 ip6_table_index, l2_table_index,
5328 BAD_SW_IF_INDEX_LABEL;
5330 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5333 static void vl_api_ipsec_spd_add_del_t_handler
5334 (vl_api_ipsec_spd_add_del_t * mp)
5337 clib_warning ("unimplemented");
5340 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5341 vl_api_ipsec_spd_add_del_reply_t * rmp;
5345 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5347 rv = VNET_API_ERROR_UNIMPLEMENTED;
5350 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5354 static void vl_api_ipsec_interface_add_del_spd_t_handler
5355 (vl_api_ipsec_interface_add_del_spd_t * mp)
5357 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5358 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5360 u32 sw_if_index __attribute__((unused));
5361 u32 spd_id __attribute__((unused));
5363 sw_if_index = ntohl(mp->sw_if_index);
5364 spd_id = ntohl(mp->spd_id);
5366 VALIDATE_SW_IF_INDEX(mp);
5369 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5371 rv = VNET_API_ERROR_UNIMPLEMENTED;
5374 BAD_SW_IF_INDEX_LABEL;
5376 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5379 static void vl_api_ipsec_spd_add_del_entry_t_handler
5380 (vl_api_ipsec_spd_add_del_entry_t * mp)
5382 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5383 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5389 memset(&p, 0, sizeof(p));
5391 p.id = ntohl(mp->spd_id);
5392 p.priority = ntohl(mp->priority);
5393 p.is_outbound = mp->is_outbound;
5394 p.is_ipv6 = mp->is_ipv6;
5396 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5397 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5398 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5399 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5401 p.protocol = mp->protocol;
5402 p.rport.start = ntohs(mp->remote_port_start);
5403 p.rport.stop = ntohs(mp->remote_port_stop);
5404 p.lport.start = ntohs(mp->local_port_start);
5405 p.lport.stop = ntohs(mp->local_port_stop);
5406 /* policy action resolve unsupported */
5407 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5408 clib_warning("unsupported action: 'resolve'");
5409 rv = VNET_API_ERROR_UNIMPLEMENTED;
5412 p.policy = mp->policy;
5413 p.sa_id = ntohl(mp->sa_id);
5415 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5419 if (mp->is_ip_any) {
5421 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5424 rv = VNET_API_ERROR_UNIMPLEMENTED;
5429 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5432 static void vl_api_ipsec_sad_add_del_entry_t_handler
5433 (vl_api_ipsec_sad_add_del_entry_t * mp)
5435 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5436 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5441 memset(&sa, 0, sizeof(sa));
5443 sa.id = ntohl(mp->sad_id);
5444 sa.spi = ntohl(mp->spi);
5445 /* security protocol AH unsupported */
5446 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5447 clib_warning("unsupported security protocol 'AH'");
5448 rv = VNET_API_ERROR_UNIMPLEMENTED;
5451 sa.protocol = mp->protocol;
5452 /* check for unsupported crypto-alg */
5453 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5454 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5455 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5456 mp->crypto_algorithm);
5457 rv = VNET_API_ERROR_UNIMPLEMENTED;
5460 sa.crypto_alg = mp->crypto_algorithm;
5461 sa.crypto_key_len = mp->crypto_key_length;
5462 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5463 /* check for unsupported integ-alg */
5464 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5465 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5466 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5467 mp->integrity_algorithm);
5468 rv = VNET_API_ERROR_UNIMPLEMENTED;
5471 sa.integ_alg = mp->integrity_algorithm;
5472 sa.integ_key_len = mp->integrity_key_length;
5473 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5474 sa.use_esn = mp->use_extended_sequence_number;
5475 sa.is_tunnel = mp->is_tunnel;
5476 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5477 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5478 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5480 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5482 rv = VNET_API_ERROR_UNIMPLEMENTED;
5487 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5491 vl_api_ikev2_profile_add_del_t_handler
5492 (vl_api_ikev2_profile_add_del_t * mp)
5494 vl_api_ikev2_profile_add_del_reply_t * rmp;
5498 vlib_main_t * vm = vlib_get_main();
5499 clib_error_t * error;
5500 u8 * tmp = format(0, "%s", mp->name);
5501 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5504 rv = VNET_API_ERROR_UNSPECIFIED;
5506 rv = VNET_API_ERROR_UNIMPLEMENTED;
5509 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5513 vl_api_ikev2_profile_set_auth_t_handler
5514 (vl_api_ikev2_profile_set_auth_t * mp)
5516 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5520 vlib_main_t * vm = vlib_get_main();
5521 clib_error_t * error;
5522 u8 * tmp = format(0, "%s", mp->name);
5523 u8 * data = vec_new (u8, mp->data_len);
5524 clib_memcpy(data, mp->data, mp->data_len);
5525 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5529 rv = VNET_API_ERROR_UNSPECIFIED;
5531 rv = VNET_API_ERROR_UNIMPLEMENTED;
5534 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5538 vl_api_ikev2_profile_set_id_t_handler
5539 (vl_api_ikev2_profile_set_id_t * mp)
5541 vl_api_ikev2_profile_add_del_reply_t * rmp;
5545 vlib_main_t * vm = vlib_get_main();
5546 clib_error_t * error;
5547 u8 * tmp = format(0, "%s", mp->name);
5548 u8 * data = vec_new (u8, mp->data_len);
5549 clib_memcpy(data, mp->data, mp->data_len);
5550 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5554 rv = VNET_API_ERROR_UNSPECIFIED;
5556 rv = VNET_API_ERROR_UNIMPLEMENTED;
5559 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5563 vl_api_ikev2_profile_set_ts_t_handler
5564 (vl_api_ikev2_profile_set_ts_t * mp)
5566 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5570 vlib_main_t * vm = vlib_get_main();
5571 clib_error_t * error;
5572 u8 * tmp = format(0, "%s", mp->name);
5573 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5574 mp->end_port, (ip4_address_t) mp->start_addr,
5575 (ip4_address_t) mp->end_addr, mp->is_local);
5578 rv = VNET_API_ERROR_UNSPECIFIED;
5580 rv = VNET_API_ERROR_UNIMPLEMENTED;
5583 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5587 vl_api_ikev2_set_local_key_t_handler
5588 (vl_api_ikev2_set_local_key_t * mp)
5590 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5594 vlib_main_t * vm = vlib_get_main();
5595 clib_error_t * error;
5597 error = ikev2_set_local_key(vm, mp->key_file);
5599 rv = VNET_API_ERROR_UNSPECIFIED;
5601 rv = VNET_API_ERROR_UNIMPLEMENTED;
5604 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5608 vl_api_map_add_domain_t_handler
5609 (vl_api_map_add_domain_t * mp)
5611 vl_api_map_add_domain_reply_t * rmp;
5614 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5615 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5616 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5617 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5618 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5620 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5622 rmp->index = ntohl(index);
5627 vl_api_map_del_domain_t_handler
5628 (vl_api_map_del_domain_t * mp)
5630 vl_api_map_del_domain_reply_t * rmp;
5633 rv = map_delete_domain(ntohl(mp->index));
5635 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5639 vl_api_map_add_del_rule_t_handler
5640 (vl_api_map_add_del_rule_t * mp)
5642 vl_api_map_del_domain_reply_t * rmp;
5645 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5647 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5651 vl_api_map_domain_dump_t_handler
5652 (vl_api_map_domain_dump_t * mp)
5654 vl_api_map_domain_details_t * rmp;
5655 map_main_t *mm = &map_main;
5657 unix_shared_memory_queue_t * q;
5659 if (pool_elts (mm->domains) == 0)
5662 q = vl_api_client_index_to_input_queue (mp->client_index);
5667 pool_foreach(d, mm->domains, ({
5668 /* Make sure every field is initiated (or don't skip the memset()) */
5669 rmp = vl_msg_api_alloc (sizeof (*rmp));
5670 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5671 rmp->domain_index = htonl(d - mm->domains);
5672 rmp->ea_bits_len = d->ea_bits_len;
5673 rmp->psid_offset = d->psid_offset;
5674 rmp->psid_length = d->psid_length;
5675 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5676 rmp->ip4_prefix_len = d->ip4_prefix_len;
5677 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5678 rmp->ip6_prefix_len = d->ip6_prefix_len;
5679 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5680 rmp->ip6_src_len = d->ip6_src_len;
5681 rmp->mtu = htons(d->mtu);
5682 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5683 rmp->context = mp->context;
5685 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5690 vl_api_map_rule_dump_t_handler
5691 (vl_api_map_rule_dump_t * mp)
5693 unix_shared_memory_queue_t * q;
5696 vl_api_map_rule_details_t * rmp;
5697 map_main_t *mm = &map_main;
5698 u32 domain_index = ntohl(mp->domain_index);
5701 if (pool_elts (mm->domains) == 0)
5704 d = pool_elt_at_index(mm->domains, domain_index);
5705 if (!d || !d->rules) {
5709 q = vl_api_client_index_to_input_queue (mp->client_index);
5714 for (i = 0; i < (0x1 << d->psid_length); i++) {
5716 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5719 rmp = vl_msg_api_alloc(sizeof(*rmp));
5720 memset(rmp, 0, sizeof(*rmp));
5721 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5722 rmp->psid = htons(i);
5723 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5724 rmp->context = mp->context;
5725 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5730 vl_api_map_summary_stats_t_handler (
5731 vl_api_map_summary_stats_t *mp)
5733 vl_api_map_summary_stats_reply_t *rmp;
5734 vlib_combined_counter_main_t *cm;
5737 u64 total_pkts[VLIB_N_RX_TX];
5738 u64 total_bytes[VLIB_N_RX_TX];
5739 map_main_t *mm = &map_main;
5740 unix_shared_memory_queue_t *q =
5741 vl_api_client_index_to_input_queue(mp->client_index);
5746 rmp = vl_msg_api_alloc (sizeof (*rmp));
5747 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5748 rmp->context = mp->context;
5751 memset (total_pkts, 0, sizeof (total_pkts));
5752 memset (total_bytes, 0, sizeof (total_bytes));
5754 map_domain_counter_lock (mm);
5755 vec_foreach(cm, mm->domain_counters) {
5756 which = cm - mm->domain_counters;
5758 for (i = 0; i < vec_len(cm->maxi); i++) {
5759 vlib_get_combined_counter (cm, i, &v);
5760 total_pkts[which] += v.packets;
5761 total_bytes[which] += v.bytes;
5765 map_domain_counter_unlock (mm);
5767 /* Note: in network byte order! */
5768 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5769 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5770 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5771 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5772 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5773 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5774 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));
5775 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));
5777 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5780 static void vl_api_ipsec_sa_set_key_t_handler
5781 (vl_api_ipsec_sa_set_key_t * mp)
5783 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5784 vl_api_ipsec_sa_set_key_reply_t *rmp;
5788 sa.id = ntohl(mp->sa_id);
5789 sa.crypto_key_len = mp->crypto_key_length;
5790 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5791 sa.integ_key_len = mp->integrity_key_length;
5792 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5794 rv = ipsec_set_sa_key(vm, &sa);
5796 rv = VNET_API_ERROR_UNIMPLEMENTED;
5799 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5802 static void vl_api_cop_interface_enable_disable_t_handler
5803 (vl_api_cop_interface_enable_disable_t * mp)
5805 vl_api_cop_interface_enable_disable_reply_t * rmp;
5807 u32 sw_if_index = ntohl(mp->sw_if_index);
5810 VALIDATE_SW_IF_INDEX(mp);
5812 enable_disable = (int) mp->enable_disable;
5814 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5816 BAD_SW_IF_INDEX_LABEL;
5818 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5821 static void vl_api_cop_whitelist_enable_disable_t_handler
5822 (vl_api_cop_whitelist_enable_disable_t * mp)
5824 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5825 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5826 u32 sw_if_index = ntohl(mp->sw_if_index);
5829 VALIDATE_SW_IF_INDEX(mp);
5831 a->sw_if_index = sw_if_index;
5834 a->default_cop = mp->default_cop;
5835 a->fib_id = ntohl(mp->fib_id);
5837 rv = cop_whitelist_enable_disable (a);
5839 BAD_SW_IF_INDEX_LABEL;
5841 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5844 static void vl_api_get_node_graph_t_handler
5845 (vl_api_get_node_graph_t * mp)
5849 api_main_t * am = &api_main;
5850 vlib_main_t * vm = vlib_get_main();
5852 vl_api_get_node_graph_reply_t * rmp;
5854 pthread_mutex_lock (&am->vlib_rp->mutex);
5855 oldheap = svm_push_data_heap (am->vlib_rp);
5858 * Keep the number of memcpy ops to a minimum (e.g. 1).
5860 vec_validate (vector, 16384);
5861 vec_reset_length (vector);
5864 vector = vlib_node_serialize (&vm->node_main, vector,
5865 (u32)~0 /* all threads */,
5866 1 /* include nexts */,
5867 1 /* include stats */);
5869 svm_pop_heap (oldheap);
5870 pthread_mutex_unlock (&am->vlib_rp->mutex);
5872 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5873 rmp->reply_in_shmem = (uword) vector);
5876 static void vl_api_trace_profile_add_t_handler
5877 (vl_api_trace_profile_add_t *mp)
5880 vl_api_trace_profile_add_reply_t * rmp;
5881 clib_error_t *error;
5883 /* Ignoring the profile id as currently a single profile
5885 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5886 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5887 mp->pow_enable, mp->trace_tsp,
5890 clib_error_report(error);
5891 rv = clib_error_get_code(error);
5894 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5897 static void vl_api_trace_profile_apply_t_handler
5898 (vl_api_trace_profile_apply_t *mp)
5901 vl_api_trace_profile_apply_reply_t * rmp;
5903 if (mp->enable != 0) {
5904 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5905 ntohl(mp->prefix_length),
5907 mp->trace_op == IOAM_HBYH_ADD,
5908 mp->trace_op == IOAM_HBYH_POP,
5909 mp->trace_op == IOAM_HBYH_MOD);
5911 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5913 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5916 static void vl_api_trace_profile_del_t_handler
5917 (vl_api_trace_profile_del_t *mp)
5920 vl_api_trace_profile_del_reply_t * rmp;
5921 clib_error_t *error;
5923 error = clear_ioam_rewrite_fn();
5925 clib_error_report(error);
5926 rv = clib_error_get_code(error);
5929 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5933 vl_api_af_packet_create_t_handler
5934 (vl_api_af_packet_create_t *mp)
5936 vlib_main_t *vm = vlib_get_main();
5937 vl_api_af_packet_create_reply_t *rmp;
5939 u8 *host_if_name = NULL;
5941 host_if_name = format(0, "%s", mp->host_if_name);
5942 vec_add1 (host_if_name, 0);
5944 rv = af_packet_create_if(vm, host_if_name,
5945 mp->use_random_hw_addr ? 0 : mp->hw_addr, 0);
5947 vec_free(host_if_name);
5949 REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
5953 vl_api_af_packet_delete_t_handler
5954 (vl_api_af_packet_delete_t *mp)
5956 vlib_main_t * vm = vlib_get_main();
5957 vl_api_af_packet_delete_reply_t *rmp;
5959 u8 *host_if_name = NULL;
5961 host_if_name = format(0, "%s", mp->host_if_name);
5962 vec_add1 (host_if_name, 0);
5964 rv = af_packet_delete_if(vm, host_if_name);
5966 vec_free(host_if_name);
5968 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
5972 vl_api_policer_add_del_t_handler
5973 (vl_api_policer_add_del_t *mp)
5975 vlib_main_t * vm = vlib_get_main();
5976 vl_api_policer_add_del_reply_t *rmp;
5979 sse2_qos_pol_cfg_params_st cfg;
5980 clib_error_t * error;
5982 name = format(0, "%s", mp->name);
5984 memset (&cfg, 0, sizeof (cfg));
5986 cfg.rnd_type = mp->round_type;
5987 cfg.rate_type = mp->rate_type;
5988 cfg.rb.kbps.cir_kbps = mp->cir;
5989 cfg.rb.kbps.eir_kbps = mp->eir;
5990 cfg.rb.kbps.cb_bytes = mp->cb;
5991 cfg.rb.kbps.eb_bytes = mp->eb;
5993 error = policer_add_del(vm, name, &cfg, mp->is_add);
5996 rv = VNET_API_ERROR_UNSPECIFIED;
5998 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
6002 send_policer_details (u8 *name,
6003 sse2_qos_pol_cfg_params_st *config,
6004 policer_read_response_type_st *templ,
6005 unix_shared_memory_queue_t *q,
6008 vl_api_policer_details_t * mp;
6010 mp = vl_msg_api_alloc (sizeof (*mp));
6011 memset (mp, 0, sizeof (*mp));
6012 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6013 mp->context = context;
6014 mp->cir = htonl(config->rb.kbps.cir_kbps);
6015 mp->eir = htonl(config->rb.kbps.eir_kbps);
6016 mp->cb = htonl(config->rb.kbps.cb_bytes);
6017 mp->eb = htonl(config->rb.kbps.eb_bytes);
6018 mp->rate_type = config->rate_type;
6019 mp->round_type = config->rnd_type;
6020 mp->type = config->rfc;
6021 mp->single_rate = templ->single_rate ? 1 : 0;
6022 mp->color_aware = templ->color_aware ? 1 : 0;
6023 mp->scale = htonl(templ->scale);
6024 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6025 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6026 mp->current_limit = htonl(templ->current_limit);
6027 mp->current_bucket = htonl(templ->current_bucket);
6028 mp->extended_limit = htonl(templ->extended_limit);
6029 mp->extended_bucket = htonl(templ->extended_bucket);
6030 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6032 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6034 vl_msg_api_send_shmem (q, (u8 *)&mp);
6038 vl_api_policer_dump_t_handler
6039 (vl_api_policer_dump_t *mp)
6041 unix_shared_memory_queue_t * q;
6042 vnet_policer_main_t * pm = &vnet_policer_main;
6046 u8 * match_name = 0;
6048 sse2_qos_pol_cfg_params_st *config;
6049 policer_read_response_type_st *templ;
6051 q = vl_api_client_index_to_input_queue (mp->client_index);
6055 if (mp->match_name_valid) {
6056 match_name = format(0, "%s%c", mp->match_name, 0);
6059 if (mp->match_name_valid) {
6060 p = hash_get_mem (pm->policer_config_by_name, match_name);
6063 config = pool_elt_at_index (pm->configs, pool_index);
6064 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6065 send_policer_details(match_name, config, templ, q, mp->context);
6068 hash_foreach_pair (hp, pm->policer_config_by_name,
6070 name = (u8 *) hp->key;
6071 pool_index = hp->value[0];
6072 config = pool_elt_at_index (pm->configs, pool_index);
6073 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6074 send_policer_details(name, config, templ, q, mp->context);
6080 vl_api_netmap_create_t_handler
6081 (vl_api_netmap_create_t *mp)
6083 vlib_main_t *vm = vlib_get_main();
6084 vl_api_netmap_create_reply_t *rmp;
6088 if_name = format(0, "%s", mp->netmap_if_name);
6089 vec_add1 (if_name, 0);
6091 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6092 mp->is_pipe, mp->is_master, 0);
6096 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6100 vl_api_netmap_delete_t_handler
6101 (vl_api_netmap_delete_t *mp)
6103 vlib_main_t * vm = vlib_get_main();
6104 vl_api_netmap_delete_reply_t *rmp;
6108 if_name = format(0, "%s", mp->netmap_if_name);
6109 vec_add1 (if_name, 0);
6111 rv = netmap_delete_if(vm, if_name);
6115 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6118 #define BOUNCE_HANDLER(nn) \
6119 static void vl_api_##nn##_t_handler ( \
6120 vl_api_##nn##_t *mp) \
6122 vpe_client_registration_t *reg; \
6123 vpe_api_main_t * vam = &vpe_api_main; \
6124 unix_shared_memory_queue_t * q; \
6126 /* One registration only... */ \
6127 pool_foreach(reg, vam->nn##_registrations, \
6129 q = vl_api_client_index_to_input_queue (reg->client_index); \
6132 * If the queue is stuffed, turf the msg and complain \
6133 * It's unlikely that the intended recipient is \
6134 * alive; avoid deadlock at all costs. \
6136 if (q->cursize == q->maxsize) { \
6137 clib_warning ("ERROR: receiver queue full, drop msg"); \
6138 vl_msg_api_free (mp); \
6141 vl_msg_api_send_shmem (q, (u8 *)&mp); \
6145 vl_msg_api_free (mp); \
6150 * Add vpe's API message handlers to the table.
6151 * vlib has alread mapped shared memory and
6152 * added the client registration handlers.
6153 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
6156 static clib_error_t *
6157 vpe_api_hookup (vlib_main_t *vm)
6159 api_main_t * am = &api_main;
6162 vl_msg_api_set_handlers(VL_API_##N, #n, \
6163 vl_api_##n##_t_handler, \
6165 vl_api_##n##_t_endian, \
6166 vl_api_##n##_t_print, \
6167 sizeof(vl_api_##n##_t), 1);
6168 foreach_vpe_api_msg;
6172 * Manually register the sr tunnel add del msg, so we trace
6173 * enough bytes to capture a typical segment list
6175 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6176 "sr_tunnel_add_del",
6177 vl_api_sr_tunnel_add_del_t_handler,
6179 vl_api_sr_tunnel_add_del_t_endian,
6180 vl_api_sr_tunnel_add_del_t_print,
6185 * Manually register the sr policy add del msg, so we trace
6186 * enough bytes to capture a typical tunnel name list
6188 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6189 "sr_policy_add_del",
6190 vl_api_sr_policy_add_del_t_handler,
6192 vl_api_sr_policy_add_del_t_endian,
6193 vl_api_sr_policy_add_del_t_print,
6197 * Trace space for 8 MPLS encap labels, classifier mask+match
6199 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6200 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6201 += 5 * sizeof (u32x4);
6202 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6203 += 5 * sizeof (u32x4);
6204 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6205 += 16 * sizeof (u32);
6208 * Thread-safe API messages
6210 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6211 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
6216 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6218 static clib_error_t *
6219 vpe_api_init (vlib_main_t *vm)
6221 vpe_api_main_t *am = &vpe_api_main;
6224 am->vnet_main = vnet_get_main();
6225 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6226 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6227 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6228 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6229 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6230 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6233 vl_set_memory_region_name ("/vpe-api");
6234 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6239 VLIB_INIT_FUNCTION(vpe_api_init);
6241 static clib_error_t *
6242 chroot_config (vlib_main_t * vm, unformat_input_t * input)
6246 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6248 if (unformat (input, "prefix %s", &chroot_path))
6250 vec_add1 (chroot_path, 0);
6251 vl_set_memory_root_path ((char *)chroot_path);
6254 return clib_error_return (0, "unknown input `%U'",
6255 format_unformat_error, input);
6259 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6261 void * get_unformat_vnet_sw_interface (void)
6263 return (void *) &unformat_vnet_sw_interface;
6266 #undef vl_api_version
6267 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6268 #include <api/vpe.api.h>
6269 #undef vl_api_version
6271 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6273 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6274 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6275 clib_host_to_net_u32 (mp->api_versions[0]),
6282 static u8 * format_arp_event (u8 * s, va_list * args)
6284 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6286 s = format (s, "pid %d: %U", event->pid,
6287 format_ip4_address, &event->address);
6291 static clib_error_t *
6292 show_ip4_arp_events_fn (vlib_main_t * vm,
6293 unformat_input_t * input,
6294 vlib_cli_command_t * cmd)
6296 vpe_api_main_t * am = &vpe_api_main;
6297 vl_api_ip4_arp_event_t * event;
6299 if (pool_elts (am->arp_events) == 0) {
6300 vlib_cli_output (vm, "No active arp event registrations");
6304 pool_foreach (event, am->arp_events,
6306 vlib_cli_output (vm, "%U", format_arp_event, event);
6312 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6313 .path = "show arp event registrations",
6314 .function = show_ip4_arp_events_fn,
6315 .short_help = "Show arp event registrations",