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/vnet.h>
46 #include <vnet/l2/l2_input.h>
47 #include <vnet/l2/l2_bd.h>
48 #include <vnet/l2tp/l2tp.h>
49 #include <vnet/ip/ip.h>
50 #include <vnet/unix/tuntap.h>
51 #include <vnet/unix/tapcli.h>
52 #include <vnet/mpls-gre/mpls.h>
53 #include <vnet/dhcp/proxy.h>
54 #include <vnet/dhcp/client.h>
55 #include <vnet/sr/sr.h>
56 #include <vnet/dhcpv6/proxy.h>
57 #include <vlib/vlib.h>
58 #include <vlib/unix/unix.h>
59 #include <vlibapi/api.h>
60 #include <vlibmemory/api.h>
61 #include <vnet/classify/vnet_classify.h>
62 #include <vnet/classify/input_acl.h>
63 #include <vnet/l2/l2_classify.h>
64 #include <vnet/vxlan/vxlan.h>
65 #include <vnet/l2/l2_vtr.h>
66 #include <vnet/nsh-gre/nsh_gre.h>
67 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
68 #include <vnet/lisp-gpe/lisp_gpe.h>
69 #include <vnet/map/map.h>
72 #undef __included_bihash_template_h__
73 #include <vnet/l2/l2_fib.h>
76 #include <vnet/ipsec/ipsec.h>
77 #include <vnet/devices/virtio/vhost-user.h>
80 #include <stats/stats.h>
83 #include <vnet/ethernet/ethernet.h>
84 #include <vnet/ethernet/arp_packet.h>
85 #include <vnet/interface.h>
87 #include <vnet/l2/l2_fib.h>
88 #include <vnet/l2/l2_bd.h>
89 #include <api/vpe_msg_enum.h>
92 #define f64_print(a,b)
94 #define vl_typedefs /* define message structures */
95 #include <api/vpe_all_api_h.h>
98 #define vl_endianfun /* define message structures */
99 #include <api/vpe_all_api_h.h>
102 /* instantiate all the print functions we know about */
103 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
105 #include <api/vpe_all_api_h.h>
108 #define REPLY_MACRO(t) \
110 unix_shared_memory_queue_t * q; \
111 rv = vl_msg_api_pd_handler (mp, rv); \
112 q = vl_api_client_index_to_input_queue (mp->client_index); \
116 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
117 rmp->_vl_msg_id = ntohs((t)); \
118 rmp->context = mp->context; \
119 rmp->retval = ntohl(rv); \
121 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
124 #define REPLY_MACRO2(t, body) \
126 unix_shared_memory_queue_t * q; \
127 rv = vl_msg_api_pd_handler (mp, rv); \
128 q = vl_api_client_index_to_input_queue (mp->client_index); \
132 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
133 rmp->_vl_msg_id = ntohs((t)); \
134 rmp->context = mp->context; \
135 rmp->retval = ntohl(rv); \
136 do {body;} while (0); \
137 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
140 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
142 #define VALIDATE_SW_IF_INDEX(mp) \
143 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
144 vnet_main_t *__vnm = vnet_get_main(); \
145 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
147 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
148 goto bad_sw_if_index; \
152 #define BAD_SW_IF_INDEX_LABEL \
158 #define VALIDATE_RX_SW_IF_INDEX(mp) \
159 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
160 vnet_main_t *__vnm = vnet_get_main(); \
161 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
162 __rx_sw_if_index)) { \
163 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
164 goto bad_rx_sw_if_index; \
168 #define BAD_RX_SW_IF_INDEX_LABEL \
170 bad_rx_sw_if_index: \
174 #define VALIDATE_TX_SW_IF_INDEX(mp) \
175 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
176 vnet_main_t *__vnm = vnet_get_main(); \
177 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
178 __tx_sw_if_index)) { \
179 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
180 goto bad_tx_sw_if_index; \
184 #define BAD_TX_SW_IF_INDEX_LABEL \
186 bad_tx_sw_if_index: \
192 #define VALIDATE_SW_IF_INDEX(mp)
193 #define BAD_SW_IF_INDEX_LABEL
194 #define VALIDATE_RX_SW_IF_INDEX(mp)
195 #define BAD_RX_SW_IF_INDEX_LABEL
196 #define VALIDATE_TX_SW_IF_INDEX(mp)
197 #define BAD_TX_SW_IF_INDEX_LABEL
199 #endif /* CLIB_DEBUG > 0 */
201 #define foreach_vpe_api_msg \
202 _(WANT_INTERFACE_EVENTS, want_interface_events) \
203 _(WANT_FROM_NETCONF_SERVER, want_from_netconf_server) \
204 _(WANT_TO_NETCONF_SERVER, want_to_netconf_server) \
205 _(WANT_FROM_NETCONF_CLIENT, want_from_netconf_client) \
206 _(WANT_TO_NETCONF_CLIENT, want_to_netconf_client) \
207 _(FROM_NETCONF_SERVER, from_netconf_server) \
208 _(TO_NETCONF_SERVER, to_netconf_server) \
209 _(FROM_NETCONF_CLIENT, from_netconf_client) \
210 _(TO_NETCONF_CLIENT, to_netconf_client) \
211 _(WANT_OAM_EVENTS, want_oam_events) \
212 _(OAM_ADD_DEL, oam_add_del) \
213 _(SW_INTERFACE_DUMP, sw_interface_dump) \
214 _(SW_INTERFACE_DETAILS, sw_interface_details) \
215 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
216 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
217 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
218 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
219 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
220 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
221 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
222 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
223 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
224 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
225 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
226 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
227 _(L2FIB_ADD_DEL, l2fib_add_del) \
228 _(L2_FLAGS, l2_flags) \
229 _(BRIDGE_FLAGS, bridge_flags) \
230 _(TAP_CONNECT, tap_connect) \
231 _(TAP_MODIFY, tap_modify) \
232 _(TAP_DELETE, tap_delete) \
233 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
234 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
235 _(CREATE_SUBIF, create_subif) \
236 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
237 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
238 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
239 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
240 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
241 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
242 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
243 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
244 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
245 _(RESET_FIB, reset_fib) \
246 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
247 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
248 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
249 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
250 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
251 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
252 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
253 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
254 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
255 sw_interface_ip6_set_link_local_address) \
256 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
257 _(CREATE_LOOPBACK, create_loopback) \
258 _(CONTROL_PING, control_ping) \
259 _(CLI_REQUEST, cli_request) \
260 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
261 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
262 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
263 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
264 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
265 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
266 _(GET_NODE_INDEX, get_node_index) \
267 _(ADD_NODE_NEXT, add_node_next) \
268 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
269 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
270 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
271 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
272 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
273 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
274 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
275 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
276 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
277 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
278 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
279 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
280 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
281 _(IP_ADDRESS_DUMP, ip_address_dump) \
282 _(IP_DUMP, ip_dump) \
283 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
284 _(SHOW_VERSION, show_version) \
285 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
286 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
287 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
288 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
289 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel) \
290 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
291 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
292 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
293 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
294 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
295 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
296 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
297 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
298 _(DELETE_LOOPBACK, delete_loopback) \
299 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
300 _(MAP_ADD_DOMAIN, map_add_domain) \
301 _(MAP_DEL_DOMAIN, map_del_domain) \
302 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
303 _(MAP_DOMAIN_DUMP, map_domain_dump) \
304 _(MAP_RULE_DUMP, map_rule_dump) \
305 _(MAP_SUMMARY_STATS, map_summary_stats)
308 #define QUOTE(x) QUOTE_(x)
310 #define foreach_registration_hash \
311 _(interface_events) \
312 _(to_netconf_server) \
313 _(from_netconf_server) \
314 _(to_netconf_client) \
315 _(from_netconf_client) \
319 RESOLVE_IP4_ADD_DEL_ROUTE=1,
320 RESOLVE_IP6_ADD_DEL_ROUTE,
321 RESOLVE_MPLS_ETHERNET_ADD_DEL,
327 vl_api_ip_add_del_route_t r;
328 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
334 #define _(a) uword *a##_registration_hash; \
335 vpe_client_registration_t * a##_registrations;
336 foreach_registration_hash
339 /* notifications happen really early in the game */
340 u8 link_state_process_up;
342 /* ip4 pending route adds */
343 pending_route_t * pending_routes;
345 /* ip4 arp event registration pool */
346 vl_api_ip4_arp_event_t * arp_events;
349 vlib_main_t * vlib_main;
350 vnet_main_t * vnet_main;
353 static vlib_node_registration_t vpe_resolver_process_node;
354 static vpe_api_main_t vpe_api_main;
356 static void send_sw_interface_flags (vpe_api_main_t * am,
357 unix_shared_memory_queue_t *q,
358 vnet_sw_interface_t * swif);
359 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
360 unix_shared_memory_queue_t *q,
363 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
366 /* Clean up all registrations belonging to the indicated client */
367 int vl_api_memclnt_delete_callback (u32 client_index)
369 vpe_api_main_t * vam = &vpe_api_main;
370 vpe_client_registration_t *rp;
372 int stats_memclnt_delete_callback (u32 client_index);
374 stats_memclnt_delete_callback (client_index);
377 p = hash_get (vam->a##_registration_hash, client_index); \
379 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
380 pool_put (vam->a##_registrations, rp); \
381 hash_unset (vam->a##_registration_hash, client_index); \
383 foreach_registration_hash;
388 #define API_LINK_STATE_EVENT 1
389 #define API_ADMIN_UP_DOWN_EVENT 2
392 link_state_process (vlib_main_t * vm,
393 vlib_node_runtime_t * rt,
396 vpe_api_main_t * vam = &vpe_api_main;
397 vnet_main_t * vnm = vam->vnet_main;
398 vnet_sw_interface_t * swif;
399 uword * event_data = 0;
400 vpe_client_registration_t *reg;
402 u32 prev_sw_if_index;
403 unix_shared_memory_queue_t * q;
405 vam->link_state_process_up = 1;
408 vlib_process_wait_for_event (vm);
410 /* Unified list of changed link or admin state sw_if_indices */
411 vlib_process_get_events_with_type
412 (vm, &event_data, API_LINK_STATE_EVENT);
413 vlib_process_get_events_with_type
414 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
416 /* Sort, so we can eliminate duplicates */
417 vec_sort (event_data, e1, e2, (word) e1[0] - (word) e2[0]);
419 prev_sw_if_index = ~0;
421 for (i = 0; i < vec_len(event_data); i++) {
422 /* Only one message per swif */
423 if (prev_sw_if_index == event_data[i])
425 prev_sw_if_index = event_data[i];
427 pool_foreach(reg, vam->interface_events_registrations,
429 q = vl_api_client_index_to_input_queue (reg->client_index);
431 // sw_interface may be deleted already
432 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
435 swif = vnet_get_sw_interface (vnm, event_data[i]);
436 send_sw_interface_flags (vam, q, swif);
441 vec_reset_length (event_data);
447 static clib_error_t *
448 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
449 static clib_error_t *
450 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
452 VLIB_REGISTER_NODE (link_state_process_node,static) = {
453 .function = link_state_process,
454 .type = VLIB_NODE_TYPE_PROCESS,
455 .name = "vpe-link-state-process",
458 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
459 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
461 static clib_error_t *
462 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
464 vpe_api_main_t * vam = &vpe_api_main;
465 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
467 if (vam->link_state_process_up)
468 vlib_process_signal_event (vam->vlib_main,
469 link_state_process_node.index,
470 API_LINK_STATE_EVENT,
475 static clib_error_t *
476 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
478 vpe_api_main_t * vam = &vpe_api_main;
481 * Note: it's perfectly fair to set a subif admin up / admin down.
482 * Note the subtle distinction between this routine and the previous
485 if (vam->link_state_process_up)
486 vlib_process_signal_event (vam->vlib_main,
487 link_state_process_node.index,
488 API_ADMIN_UP_DOWN_EVENT,
493 #define pub_sub_handler(lca,UCA) \
494 static void vl_api_want_##lca##_t_handler ( \
495 vl_api_want_##lca##_t *mp) \
497 vpe_api_main_t *vam = &vpe_api_main; \
498 vpe_client_registration_t *rp; \
499 vl_api_want_##lca##_reply_t *rmp; \
503 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
505 if (mp->enable_disable) { \
506 clib_warning ("pid %d: already enabled...", mp->pid); \
507 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
510 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
511 pool_put (vam->lca##_registrations, rp); \
512 hash_unset (vam->lca##_registration_hash, \
517 if (mp->enable_disable == 0) { \
518 clib_warning ("pid %d: already disabled...", mp->pid); \
519 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
522 pool_get (vam->lca##_registrations, rp); \
523 rp->client_index = mp->client_index; \
524 rp->client_pid = mp->pid; \
525 hash_set (vam->lca##_registration_hash, rp->client_index, \
526 rp - vam->lca##_registrations); \
529 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
532 pub_sub_handler (interface_events,INTERFACE_EVENTS)
533 pub_sub_handler (from_netconf_server,FROM_NETCONF_SERVER)
534 pub_sub_handler (to_netconf_server,TO_NETCONF_SERVER)
535 pub_sub_handler (from_netconf_client,FROM_NETCONF_CLIENT)
536 pub_sub_handler (to_netconf_client,TO_NETCONF_CLIENT)
537 pub_sub_handler (oam_events,OAM_EVENTS)
539 #define RESOLUTION_EVENT 1
540 #define RESOLUTION_PENDING_EVENT 2
541 #define IP4_ARP_EVENT 3
543 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
544 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
545 static int mpls_ethernet_add_del_tunnel_2_t_handler
546 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
548 void handle_ip4_arp_event (u32 pool_index)
550 vpe_api_main_t * vam = &vpe_api_main;
551 vnet_main_t * vnm = vam->vnet_main;
552 vlib_main_t * vm = vam->vlib_main;
553 vl_api_ip4_arp_event_t * event;
554 vl_api_ip4_arp_event_t * mp;
555 unix_shared_memory_queue_t * q;
557 /* Client can cancel, die, etc. */
558 if (pool_is_free_index (vam->arp_events, pool_index))
561 event = pool_elt_at_index (vam->arp_events, pool_index);
563 q = vl_api_client_index_to_input_queue (event->client_index);
565 (void) vnet_add_del_ip4_arp_change_event
566 (vnm, arp_change_delete_callback,
567 event->pid, &event->address,
568 vpe_resolver_process_node.index, IP4_ARP_EVENT,
569 ~0 /* pool index, notused */, 0 /* is_add */);
573 if (q->cursize < q->maxsize) {
574 mp = vl_msg_api_alloc (sizeof (*mp));
575 memcpy (mp, event, sizeof (*mp));
576 vl_msg_api_send_shmem (q, (u8 *)&mp);
578 static f64 last_time;
580 * Throttle syslog msgs.
581 * It's pretty tempting to just revoke the registration...
583 if (vlib_time_now (vm) > last_time + 10.0) {
584 clib_warning ("arp event for %U to pid %d: queue stuffed!",
585 format_ip4_address, &event->address, event->pid);
586 last_time = vlib_time_now(vm);
592 resolver_process (vlib_main_t * vm,
593 vlib_node_runtime_t * rt,
597 uword *event_data = 0;
599 vpe_api_main_t * vam = &vpe_api_main;
600 pending_route_t * pr;
601 vl_api_ip_add_del_route_t * adr;
602 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
603 u32 * resolution_failures = 0;
608 vlib_process_wait_for_event_or_clock (vm, timeout);
610 event_type = vlib_process_get_events (vm, &event_data);
612 switch (event_type) {
613 case RESOLUTION_PENDING_EVENT:
617 case RESOLUTION_EVENT:
618 for (i = 0; i < vec_len(event_data); i++) {
620 * Resolution events can occur long after the
621 * original request has timed out. $$$ add a cancel
624 if (pool_is_free_index (vam->pending_routes, event_data[i]))
627 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
631 switch (pr->resolve_type) {
632 case RESOLVE_IP4_ADD_DEL_ROUTE:
633 rv = ip4_add_del_route_t_handler (adr);
634 clib_warning ("resolver: add %U/%d via %U %s",
636 (ip4_address_t *)&(adr->dst_address),
637 adr->dst_address_length,
639 (ip4_address_t *)&(adr->next_hop_address),
640 (rv >= 0) ? "succeeded" : "failed");
643 case RESOLVE_IP6_ADD_DEL_ROUTE:
644 rv = ip6_add_del_route_t_handler (adr);
645 clib_warning ("resolver: add %U/%d via %U %s",
647 (ip6_address_t *)&(adr->dst_address),
648 adr->dst_address_length,
650 (ip6_address_t *)&(adr->next_hop_address),
651 (rv >= 0) ? "succeeded" : "failed");
654 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
655 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
656 clib_warning ("resolver: add mpls-o-e via %U %s",
658 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
659 (rv >= 0) ? "succeeded" : "failed");
663 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
665 pool_put (vam->pending_routes, pr);
670 for (i = 0; i < vec_len(event_data); i++)
671 handle_ip4_arp_event (event_data[i]);
674 case ~0: /* timeout, retry pending resolutions */
675 pool_foreach (pr, vam->pending_routes,
681 /* May fail, e.g. due to interface down */
682 switch (pr->resolve_type) {
683 case RESOLVE_IP4_ADD_DEL_ROUTE:
684 e = ip4_probe_neighbor
685 (vm, (ip4_address_t *)&(adr->next_hop_address),
686 ntohl(adr->next_hop_sw_if_index));
689 case RESOLVE_IP6_ADD_DEL_ROUTE:
690 e = ip6_probe_neighbor
691 (vm, (ip6_address_t *)&(adr->next_hop_address),
692 ntohl(adr->next_hop_sw_if_index));
695 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
697 e = ip4_probe_neighbor
699 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
700 pme->resolve_opaque);
704 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
708 clib_error_report (e);
710 adr->resolve_attempts = 1;
712 pme->resolve_attempts = 1;
716 adr->resolve_attempts -= 1;
717 if (adr->resolve_attempts == 0)
718 vec_add1 (resolution_failures,
719 pr - vam->pending_routes);
721 pme->resolve_attempts -= 1;
722 if (pme->resolve_attempts == 0)
723 vec_add1 (resolution_failures,
724 pr - vam->pending_routes);
728 for (i = 0; i < vec_len (resolution_failures); i++) {
729 pr = pool_elt_at_index (vam->pending_routes,
730 resolution_failures[i]);
734 switch (pr->resolve_type) {
735 case RESOLVE_IP4_ADD_DEL_ROUTE:
736 clib_warning ("resolver: add %U/%d via %U retry failure",
738 (ip4_address_t *)&(adr->dst_address),
739 adr->dst_address_length,
741 (ip4_address_t *)&(adr->next_hop_address));
744 case RESOLVE_IP6_ADD_DEL_ROUTE:
745 clib_warning ("resolver: add %U/%d via %U retry failure",
747 (ip6_address_t *)&(adr->dst_address),
748 adr->dst_address_length,
750 (ip6_address_t *)&(adr->next_hop_address));
753 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
754 clib_warning ("resolver: add mpls-o-e via %U retry failure",
756 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
760 clib_warning ("BUG");
762 pool_put(vam->pending_routes, pr);
764 vec_reset_length (resolution_failures);
767 if (pool_elts (vam->pending_routes) == 0)
769 vec_reset_length (event_data);
771 return 0; /* or not */
774 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
775 .function = resolver_process,
776 .type = VLIB_NODE_TYPE_PROCESS,
777 .name = "vpe-route-resolver-process",
780 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
782 ip4_main_t * im = &ip4_main;
783 ip_lookup_main_t * lm = &im->lookup_main;
784 vnet_classify_main_t * cm = &vnet_classify_main;
785 stats_main_t * sm = &stats_main;
786 ip4_add_del_route_args_t a;
787 ip4_address_t next_hop_address;
789 vpe_api_main_t * vam = &vpe_api_main;
790 vnet_main_t * vnm = vam->vnet_main;
791 vlib_main_t * vm = vlib_get_main();
792 pending_route_t * pr;
793 vl_api_ip_add_del_route_t * adr;
797 ip_adjacency_t *nh_adj, *add_adj = 0;
799 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
801 if (mp->create_vrf_if_needed) {
803 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
805 fib_index = f->index;
807 /* No such VRF, and we weren't asked to create one */
808 return VNET_API_ERROR_NO_SUCH_FIB;
814 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
815 ntohl(mp->next_hop_sw_if_index)))
816 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
818 memcpy (next_hop_address.data, mp->next_hop_address,
819 sizeof (next_hop_address.data));
821 /* Arp for the next_hop if necessary */
822 if (mp->is_add && mp->resolve_if_needed) {
824 ip_adjacency_t * adj;
826 lookup_result = ip4_fib_lookup_with_table
827 (im, fib_index, &next_hop_address, 1 /* disable default route */);
829 adj = ip_get_adjacency (lm, lookup_result);
831 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
832 pool_get (vam->pending_routes, pr);
833 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
835 memcpy (adr, mp, sizeof (*adr));
836 /* recursion block, "just in case" */
837 adr->resolve_if_needed = 0;
838 adr->resolve_attempts = ntohl(mp->resolve_attempts);
839 vnet_register_ip4_arp_resolution_event
840 (vnm, &next_hop_address, vpe_resolver_process_node.index,
841 RESOLUTION_EVENT, pr - vam->pending_routes);
843 vlib_process_signal_event
844 (vm, vpe_resolver_process_node.index,
845 RESOLUTION_PENDING_EVENT, 0 /* data */);
847 /* The interface may be down, etc. */
848 e = ip4_probe_neighbor
849 (vm, (ip4_address_t *)&(mp->next_hop_address),
850 ntohl(mp->next_hop_sw_if_index));
853 clib_error_report(e);
855 return VNET_API_ERROR_IN_PROGRESS;
859 if (mp->is_multipath) {
862 dslock (sm, 1 /* release hint */, 10 /* tag */);
865 flags = IP4_ROUTE_FLAG_ADD;
867 flags = IP4_ROUTE_FLAG_DEL;
870 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
872 ip4_add_del_route_next_hop (im, flags,
873 (ip4_address_t *) mp->dst_address,
874 (u32) mp->dst_address_length,
875 (ip4_address_t *) mp->next_hop_address,
876 ntohl(mp->next_hop_sw_if_index),
877 (u32) mp->next_hop_weight,
884 memset (&a, 0, sizeof (a));
885 memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
887 a.dst_address_length = mp->dst_address_length;
889 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
890 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
891 a.table_index_or_table_id = fib_index;
896 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
898 dslock (sm, 1 /* release hint */, 2 /* tag */);
902 ai = lm->drop_adj_index;
903 else if (mp->is_local)
904 ai = lm->local_adj_index;
905 else if (mp->is_classify) {
907 memset(&cadj, 0, sizeof(cadj));
908 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
909 cadj.classify_table_index = ntohl(mp->classify_table_index);
910 if (pool_is_free_index (cm->tables, cadj.classify_table_index)) {
912 return VNET_API_ERROR_NO_SUCH_TABLE;
914 vec_add1 (add_adj, cadj);
918 ai = ip4_fib_lookup_with_table
919 (im, fib_index, &next_hop_address,
920 1 /* disable default route */);
921 if (ai == lm->miss_adj_index) {
923 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
927 nh_adj = ip_get_adjacency (lm, ai);
928 vec_add1 (add_adj, nh_adj[0]);
929 if (mp->lookup_in_vrf) {
930 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
932 add_adj[0].explicit_fib_index = p[0];
936 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
940 ip_adjacency_t * adj;
941 int disable_default_route = 1;
943 /* Trying to delete the default route? */
944 if (a.dst_address.as_u32 == 0 &&
945 a.dst_address_length == 0)
946 disable_default_route = 0;
948 ai = ip4_fib_lookup_with_table
949 (im, fib_index, &a.dst_address, disable_default_route);
950 if (ai == lm->miss_adj_index) {
952 return VNET_API_ERROR_UNKNOWN_DESTINATION;
955 adj = ip_get_adjacency (lm, ai);
956 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
958 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
965 a.n_add_adj = vec_len(add_adj);
966 ip4_add_del_route (im, &a);
974 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
976 ip6_main_t * im = &ip6_main;
977 ip_lookup_main_t * lm = &im->lookup_main;
978 vnet_main_t * vnm = vnet_get_main();
979 vlib_main_t * vm = vlib_get_main();
980 vpe_api_main_t * vam = &vpe_api_main;
981 stats_main_t * sm = &stats_main;
982 ip6_add_del_route_args_t a;
983 ip6_address_t next_hop_address;
984 pending_route_t * pr;
985 vl_api_ip_add_del_route_t * adr;
990 ip_adjacency_t * nh_adj, * add_adj = 0;
993 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
996 if (mp->create_vrf_if_needed) {
998 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1000 fib_index = f->index;
1002 /* No such VRF, and we weren't asked to create one */
1003 return VNET_API_ERROR_NO_SUCH_FIB;
1009 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1010 ntohl(mp->next_hop_sw_if_index)))
1011 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1013 memcpy (next_hop_address.as_u8, mp->next_hop_address,
1014 sizeof (next_hop_address.as_u8));
1016 /* Arp for the next_hop if necessary */
1017 if (mp->is_add && mp->resolve_if_needed) {
1019 ip_adjacency_t * adj;
1021 lookup_result = ip6_fib_lookup_with_table
1022 (im, fib_index, &next_hop_address);
1024 adj = ip_get_adjacency (lm, lookup_result);
1026 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1027 pool_get (vam->pending_routes, pr);
1029 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1030 memcpy (adr, mp, sizeof (*adr));
1031 /* recursion block, "just in case" */
1032 adr->resolve_if_needed = 0;
1033 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1034 vnet_register_ip6_neighbor_resolution_event
1035 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1036 RESOLUTION_EVENT, pr - vam->pending_routes);
1038 vlib_process_signal_event
1039 (vm, vpe_resolver_process_node.index,
1040 RESOLUTION_PENDING_EVENT, 0 /* data */);
1042 /* The interface may be down, etc. */
1043 e = ip6_probe_neighbor
1044 (vm, (ip6_address_t *)&(mp->next_hop_address),
1045 ntohl(mp->next_hop_sw_if_index));
1048 clib_error_report(e);
1050 return VNET_API_ERROR_IN_PROGRESS;
1054 if (mp->is_multipath) {
1057 dslock (sm, 1 /* release hint */, 11 /* tag */);
1060 flags = IP6_ROUTE_FLAG_ADD;
1062 flags = IP6_ROUTE_FLAG_DEL;
1065 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1067 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1068 (u32) mp->dst_address_length,
1069 (ip6_address_t *)mp->next_hop_address,
1070 ntohl(mp->next_hop_sw_if_index),
1071 (u32) mp->next_hop_weight,
1078 memset (&a, 0, sizeof (a));
1079 memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1081 a.dst_address_length = mp->dst_address_length;
1083 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1084 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1085 a.table_index_or_table_id = fib_index;
1090 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1092 dslock (sm, 1 /* release hint */, 3 /* tag */);
1096 ai = lm->drop_adj_index;
1097 else if (mp->is_local)
1098 ai = lm->local_adj_index;
1100 ai = ip6_fib_lookup_with_table
1101 (im, fib_index, &next_hop_address);
1102 if (ai == lm->miss_adj_index) {
1104 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1108 nh_adj = ip_get_adjacency (lm, ai);
1109 vec_add1 (add_adj, nh_adj[0]);
1110 if (mp->lookup_in_vrf) {
1111 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1113 add_adj[0].explicit_fib_index = p[0];
1117 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1121 ip_adjacency_t * adj;
1123 ai = ip6_fib_lookup_with_table
1124 (im, fib_index, &a.dst_address);
1125 if (ai == lm->miss_adj_index) {
1127 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1129 adj = ip_get_adjacency (lm, ai);
1130 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1132 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1137 a.add_adj = add_adj;
1138 a.n_add_adj = vec_len(add_adj);
1139 ip6_add_del_route (im, &a);
1147 void vl_api_ip_add_del_route_t_handler (
1148 vl_api_ip_add_del_route_t *mp)
1150 vl_api_ip_add_del_route_reply_t * rmp;
1152 vnet_main_t * vnm = vnet_get_main();
1157 rv = ip6_add_del_route_t_handler (mp);
1159 rv = ip4_add_del_route_t_handler (mp);
1161 rv = (rv == 0) ? vnm->api_errno : rv;
1163 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1166 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1167 u32 sw_if_index, u8 *next_hop_addr)
1169 vl_api_ip_add_del_route_t mp;
1172 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1175 * Configure default IP route:
1176 * - ip route add 0.0.0.0/1 via <GW IP>
1177 * - ip route add 128.0.0.0/1 via <GW IP>
1179 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1181 mp.resolve_attempts = ~0;
1182 mp.resolve_if_needed = 1;
1184 mp.is_ipv6 = is_ipv6;
1185 mp.next_hop_weight = 1;
1187 memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1190 rv = ip6_add_del_route_t_handler (&mp);
1193 mp.dst_address_length = 1;
1195 mp.dst_address[0] = 0;
1196 rv = ip4_add_del_route_t_handler (&mp);
1198 mp.dst_address[0] = 128;
1199 rv |= ip4_add_del_route_t_handler (&mp);
1203 clib_error_return (0, "failed to config default IP route");
1208 vl_api_sw_interface_add_del_address_t_handler
1209 (vl_api_sw_interface_add_del_address_t *mp)
1211 vlib_main_t *vm = vlib_get_main();
1212 vl_api_sw_interface_add_del_address_reply_t * rmp;
1216 VALIDATE_SW_IF_INDEX(mp);
1218 is_del = mp->is_add == 0;
1221 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1222 else if (mp->is_ipv6)
1223 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1224 (void *)mp->address,
1225 mp->address_length, is_del);
1227 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1228 (void *) mp->address,
1229 mp->address_length, is_del);
1231 BAD_SW_IF_INDEX_LABEL;
1233 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1237 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1240 u32 table_id = ntohl(mp->vrf_id);
1241 u32 sw_if_index = ntohl(mp->sw_if_index);
1242 vl_api_sw_interface_set_table_reply_t * rmp;
1243 stats_main_t * sm = &stats_main;
1245 VALIDATE_SW_IF_INDEX(mp);
1247 dslock (sm, 1 /* release hint */, 4 /* tag */);
1250 ip6_main_t * im = &ip6_main;
1252 find_ip6_fib_by_table_index_or_id (im, table_id,
1253 IP6_ROUTE_FLAG_TABLE_ID);
1255 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1256 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1258 rv = VNET_API_ERROR_NO_SUCH_FIB;
1261 ip4_main_t * im = &ip4_main;
1262 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1263 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1265 /* Truthfully this can't fail */
1267 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1268 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1270 rv = VNET_API_ERROR_NO_SUCH_FIB;
1275 BAD_SW_IF_INDEX_LABEL;
1277 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1281 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1283 vlib_main_t *vm = vlib_get_main();
1284 vl_api_sw_interface_set_vpath_reply_t * rmp;
1287 u32 sw_if_index = ntohl(mp->sw_if_index);
1288 ip4_main_t *ip4m = &ip4_main;
1289 ip6_main_t *ip6m = &ip6_main;
1290 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1291 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1292 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1293 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1294 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1295 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1297 VALIDATE_SW_IF_INDEX(mp);
1299 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1301 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1302 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1303 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1304 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1305 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1306 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1307 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1308 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1309 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1310 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1311 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1312 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1313 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1314 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1315 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1316 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1318 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1319 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1320 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1321 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1322 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1323 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1324 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1325 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1326 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1327 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1328 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1329 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1330 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1331 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1332 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1333 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1336 BAD_SW_IF_INDEX_LABEL;
1338 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1342 vl_api_sw_interface_set_l2_xconnect_t_handler (
1343 vl_api_sw_interface_set_l2_xconnect_t *mp)
1345 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1347 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1348 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1349 vlib_main_t *vm = vlib_get_main();
1350 vnet_main_t *vnm = vnet_get_main();
1352 VALIDATE_RX_SW_IF_INDEX(mp);
1355 VALIDATE_TX_SW_IF_INDEX(mp);
1356 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1357 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1359 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1362 BAD_RX_SW_IF_INDEX_LABEL;
1363 BAD_TX_SW_IF_INDEX_LABEL;
1365 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1369 vl_api_sw_interface_set_l2_bridge_t_handler (
1370 vl_api_sw_interface_set_l2_bridge_t *mp)
1372 bd_main_t * bdm = &bd_main;
1373 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1375 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1376 u32 bd_id = ntohl(mp->bd_id);
1380 vlib_main_t *vm = vlib_get_main();
1381 vnet_main_t *vnm = vnet_get_main();
1383 VALIDATE_RX_SW_IF_INDEX(mp);
1385 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1388 //VALIDATE_TX_SW_IF_INDEX(mp);
1389 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1390 rx_sw_if_index, bd_index, bvi, shg, 0);
1392 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1395 BAD_RX_SW_IF_INDEX_LABEL;
1397 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1401 vl_api_bridge_domain_add_del_t_handler (
1402 vl_api_bridge_domain_add_del_t *mp)
1404 vlib_main_t * vm = vlib_get_main ();
1405 bd_main_t * bdm = &bd_main;
1406 vl_api_bridge_domain_add_del_reply_t * rmp;
1408 u32 enable_flags = 0, disable_flags = 0;
1409 u32 bd_id = ntohl(mp->bd_id);
1413 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1416 enable_flags |= L2_FLOOD;
1418 disable_flags |= L2_FLOOD;
1421 enable_flags |= L2_UU_FLOOD;
1423 disable_flags |= L2_UU_FLOOD;
1426 enable_flags |= L2_FWD;
1428 disable_flags |= L2_FWD;
1431 enable_flags |= L2_ARP_TERM;
1433 disable_flags |= L2_ARP_TERM;
1436 enable_flags |= L2_LEARN;
1438 disable_flags |= L2_LEARN;
1441 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1444 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1447 rv = bd_delete_bd_index(bdm, bd_id);
1449 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1452 static void vl_api_bridge_domain_details_t_handler (
1453 vl_api_bridge_domain_details_t * mp)
1455 clib_warning ("BUG");
1458 static void vl_api_bridge_domain_sw_if_details_t_handler (
1459 vl_api_bridge_domain_sw_if_details_t * mp)
1461 clib_warning ("BUG");
1464 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1465 l2_bridge_domain_t * bd_config,
1468 vl_api_bridge_domain_details_t * mp;
1470 mp = vl_msg_api_alloc (sizeof (*mp));
1471 memset (mp, 0, sizeof (*mp));
1472 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1473 mp->bd_id = ntohl (bd_config->bd_id);
1474 mp->flood = bd_feature_flood (bd_config);
1475 mp->uu_flood = bd_feature_uu_flood (bd_config);
1476 mp->forward = bd_feature_forward (bd_config);
1477 mp->learn = bd_feature_learn (bd_config);
1478 mp->arp_term = bd_feature_arp_term (bd_config);
1479 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1480 mp->n_sw_ifs = ntohl (n_sw_ifs);
1482 vl_msg_api_send_shmem (q, (u8 *)&mp);
1485 static void send_bd_sw_if_details (l2input_main_t * l2im,
1486 unix_shared_memory_queue_t *q,
1487 l2_flood_member_t * member, u32 bd_id)
1489 vl_api_bridge_domain_sw_if_details_t * mp;
1490 l2_input_config_t * input_cfg;
1492 mp = vl_msg_api_alloc (sizeof (*mp));
1493 memset (mp, 0, sizeof (*mp));
1494 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1495 mp->bd_id = ntohl (bd_id);
1496 mp->sw_if_index = ntohl (member->sw_if_index);
1497 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1498 mp->shg = input_cfg->shg;
1500 vl_msg_api_send_shmem (q, (u8 *)&mp);
1503 static void vl_api_bridge_domain_dump_t_handler (
1504 vl_api_bridge_domain_dump_t *mp)
1506 bd_main_t * bdm = &bd_main;
1507 l2input_main_t * l2im = &l2input_main;
1508 unix_shared_memory_queue_t * q;
1509 l2_bridge_domain_t * bd_config;
1510 u32 bd_id, bd_index;
1513 q = vl_api_client_index_to_input_queue (mp->client_index);
1518 bd_id = ntohl(mp->bd_id);
1520 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1521 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1522 for (; bd_index < end; bd_index++) {
1523 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1524 /* skip dummy bd_id 0 */
1525 if (bd_config && (bd_config->bd_id > 0)) {
1527 l2_flood_member_t * m;
1529 n_sw_ifs = vec_len (bd_config->members);
1530 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1532 vec_foreach (m, bd_config->members) {
1533 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1540 vl_api_l2fib_add_del_t_handler (
1541 vl_api_l2fib_add_del_t *mp)
1543 bd_main_t * bdm = &bd_main;
1544 l2input_main_t * l2im = &l2input_main;
1545 vl_api_l2fib_add_del_reply_t * rmp;
1548 u32 sw_if_index = ntohl(mp->sw_if_index);
1549 u32 bd_id = ntohl(mp->bd_id);
1557 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1559 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1560 goto bad_sw_if_index;
1565 VALIDATE_SW_IF_INDEX(mp);
1566 if (vec_len(l2im->configs) <= sw_if_index) {
1567 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1568 goto bad_sw_if_index;
1570 l2_input_config_t * config;
1571 config = vec_elt_at_index(l2im->configs, sw_if_index);
1572 if (config->bridge == 0) {
1573 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1574 goto bad_sw_if_index;
1577 static_mac = mp->static_mac ? 1 : 0;
1578 filter_mac = mp->filter_mac ? 1 : 0;
1579 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1582 l2fib_del_entry(mac, bd_index);
1585 BAD_SW_IF_INDEX_LABEL;
1587 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1591 vl_api_l2_flags_t_handler (
1592 vl_api_l2_flags_t *mp)
1594 vl_api_l2_flags_reply_t * rmp;
1596 u32 sw_if_index = ntohl(mp->sw_if_index);
1597 u32 flags = ntohl(mp->feature_bitmap);
1600 VALIDATE_SW_IF_INDEX(mp);
1603 if (flags & L2INPUT_FEAT_ ## a) \
1604 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1605 foreach_l2input_feat;
1608 BAD_SW_IF_INDEX_LABEL;
1610 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1614 vl_api_bridge_flags_t_handler (
1615 vl_api_bridge_flags_t *mp)
1617 vlib_main_t *vm = vlib_get_main();
1618 bd_main_t * bdm = &bd_main;
1619 vl_api_bridge_flags_reply_t * rmp;
1621 u32 bd_id = ntohl(mp->bd_id);
1623 u32 flags = ntohl(mp->feature_bitmap);
1626 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1628 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1634 bd_set_flags(vm, bd_index, flags, mp->is_set);
1637 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1638 rmp->resulting_feature_bitmap = ntohl(flags));
1642 vl_api_bd_ip_mac_add_del_t_handler (
1643 vl_api_bd_ip_mac_add_del_t *mp)
1645 bd_main_t * bdm = &bd_main;
1646 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1648 u32 bd_id = ntohl(mp->bd_id);
1652 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1654 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1659 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1660 mp->mac_address, mp->is_ipv6, mp->is_add))
1661 rv = VNET_API_ERROR_UNSPECIFIED;
1664 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1668 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1671 vl_api_tap_connect_reply_t * rmp;
1672 unix_shared_memory_queue_t * q;
1673 u32 sw_if_index = (u32)~0;
1675 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1676 mp->use_random_mac ? 0 : mp->mac_address,
1677 &sw_if_index, mp->renumber,
1678 ntohl(mp->custom_dev_instance));
1680 q = vl_api_client_index_to_input_queue (mp->client_index);
1684 rmp = vl_msg_api_alloc (sizeof (*rmp));
1685 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1686 rmp->context = mp->context;
1687 rmp->retval = ntohl(rv);
1688 rmp->sw_if_index = ntohl(sw_if_index);
1690 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1694 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1697 vl_api_tap_modify_reply_t * rmp;
1698 unix_shared_memory_queue_t * q;
1699 u32 sw_if_index = (u32)~0;
1701 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1702 mp->use_random_mac ? 0 : mp->mac_address,
1703 &sw_if_index, mp->renumber,
1704 ntohl(mp->custom_dev_instance));
1706 q = vl_api_client_index_to_input_queue (mp->client_index);
1710 rmp = vl_msg_api_alloc (sizeof (*rmp));
1711 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1712 rmp->context = mp->context;
1713 rmp->retval = ntohl(rv);
1714 rmp->sw_if_index = ntohl(sw_if_index);
1716 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1720 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1723 vpe_api_main_t * vam = &vpe_api_main;
1724 vl_api_tap_delete_reply_t * rmp;
1725 unix_shared_memory_queue_t * q;
1726 u32 sw_if_index = ntohl(mp->sw_if_index);
1728 rv = vnet_tap_delete (vm, sw_if_index);
1730 q = vl_api_client_index_to_input_queue (mp->client_index);
1734 rmp = vl_msg_api_alloc (sizeof (*rmp));
1735 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1736 rmp->context = mp->context;
1737 rmp->retval = ntohl(rv);
1739 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1742 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1746 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1748 vl_api_create_vlan_subif_reply_t * rmp;
1749 vnet_main_t * vnm = vnet_get_main();
1750 u32 hw_if_index, sw_if_index = (u32)~0;
1751 vnet_hw_interface_t * hi;
1754 vnet_sw_interface_t template;
1756 vnet_interface_main_t * im = &vnm->interface_main;
1757 u64 sup_and_sub_key;
1759 unix_shared_memory_queue_t * q;
1760 clib_error_t * error;
1762 VALIDATE_SW_IF_INDEX(mp);
1764 hw_if_index = ntohl(mp->sw_if_index);
1765 hi = vnet_get_hw_interface (vnm, hw_if_index);
1767 id = ntohl(mp->vlan_id);
1768 if (id == 0 || id > 4095) {
1769 rv = VNET_API_ERROR_INVALID_VLAN;
1773 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1775 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1777 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1781 kp = clib_mem_alloc (sizeof (*kp));
1782 *kp = sup_and_sub_key;
1784 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1785 template.sup_sw_if_index = hi->sw_if_index;
1786 template.sub.id = id;
1787 template.sub.eth.raw_flags = 0;
1788 template.sub.eth.flags.one_tag = 1;
1789 template.sub.eth.outer_vlan_id = id;
1790 template.sub.eth.flags.exact_match = 1;
1792 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1794 clib_error_report(error);
1795 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1798 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1799 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1801 BAD_SW_IF_INDEX_LABEL;
1804 q = vl_api_client_index_to_input_queue (mp->client_index);
1808 rmp = vl_msg_api_alloc (sizeof (*rmp));
1809 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1810 rmp->context = mp->context;
1811 rmp->retval = ntohl(rv);
1812 rmp->sw_if_index = ntohl(sw_if_index);
1813 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1817 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1819 vl_api_create_subif_reply_t * rmp;
1820 vnet_main_t * vnm = vnet_get_main();
1821 u32 sw_if_index = ~0;
1824 vnet_sw_interface_t *si;
1825 vnet_hw_interface_t *hi;
1826 vnet_sw_interface_t template;
1828 vnet_interface_main_t * im = &vnm->interface_main;
1829 u64 sup_and_sub_key;
1831 clib_error_t * error;
1833 VALIDATE_SW_IF_INDEX(mp);
1835 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1836 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1838 sw_if_index = si->sw_if_index;
1839 sub_id = ntohl(mp->sub_id);
1841 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1843 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1846 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1847 sw_if_index, sub_id);
1848 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1852 kp = clib_mem_alloc (sizeof (*kp));
1853 *kp = sup_and_sub_key;
1855 memset (&template, 0, sizeof (template));
1856 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1857 template.sup_sw_if_index = sw_if_index;
1858 template.sub.id = sub_id;
1859 template.sub.eth.flags.no_tags = mp->no_tags;
1860 template.sub.eth.flags.one_tag = mp->one_tag;
1861 template.sub.eth.flags.two_tags = mp->two_tags;
1862 template.sub.eth.flags.dot1ad = mp->dot1ad;
1863 template.sub.eth.flags.exact_match = mp->exact_match;
1864 template.sub.eth.flags.default_sub = mp->default_sub;
1865 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1866 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1867 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1868 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1870 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1872 clib_error_report (error);
1873 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1877 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1878 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1880 BAD_SW_IF_INDEX_LABEL;
1884 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1886 rmp->sw_if_index = ntohl(sw_if_index);
1891 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1893 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1895 stats_main_t * sm = &stats_main;
1896 u32 tunnel_sw_if_index = ~0;
1898 dslock (sm, 1 /* release hint */, 5 /* tag */);
1900 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1901 (ip4_address_t *)(mp->dst_address),
1902 (ip4_address_t *)(mp->intfc_address),
1903 (u32)(mp->intfc_address_length),
1904 ntohl(mp->inner_vrf_id),
1905 ntohl(mp->outer_vrf_id),
1906 &tunnel_sw_if_index,
1911 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1913 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1918 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1919 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1921 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1923 stats_main_t * sm = &stats_main;
1924 u32 tunnel_sw_if_index;
1926 dslock (sm, 1 /* release hint */, 5 /* tag */);
1928 rv = vnet_mpls_ethernet_add_del_tunnel
1929 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1930 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1931 ntohl(mp->tx_sw_if_index),
1932 &tunnel_sw_if_index,
1938 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1940 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1945 * This piece of misery brought to you because the control-plane
1946 * can't figure out the tx interface + dst-mac address all by itself
1948 static int mpls_ethernet_add_del_tunnel_2_t_handler
1949 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1951 pending_route_t * pr;
1952 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1953 vnet_main_t * vnm = vnet_get_main();
1954 vlib_main_t * vm = vlib_get_main();
1955 stats_main_t * sm = &stats_main;
1956 vpe_api_main_t * vam = &vpe_api_main;
1957 u32 inner_fib_index, outer_fib_index;
1958 ip4_main_t * im = &ip4_main;
1959 ip_lookup_main_t * lm = &im->lookup_main;
1960 ip_adjacency_t * adj = 0;
1963 u8 * dst_mac_address;
1967 u32 tunnel_sw_if_index;
1969 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
1971 return VNET_API_ERROR_NO_SUCH_FIB;
1973 outer_fib_index = p[0];
1976 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
1978 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1980 inner_fib_index = p[0];
1982 if (inner_fib_index == outer_fib_index)
1983 return VNET_API_ERROR_INVALID_VALUE;
1985 lookup_result = ip4_fib_lookup_with_table
1986 (im, outer_fib_index,
1987 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
1988 1 /* disable default route */);
1990 adj = ip_get_adjacency (lm, lookup_result);
1991 tx_sw_if_index = adj->rewrite_header.sw_if_index;
1993 if (mp->is_add && mp->resolve_if_needed) {
1994 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1995 pool_get (vam->pending_routes, pr);
1996 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
1998 memcpy (pme, mp, sizeof (*pme));
1999 /* recursion block, "just in case" */
2000 pme->resolve_if_needed = 0;
2001 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2002 pme->resolve_opaque = tx_sw_if_index;
2003 vnet_register_ip4_arp_resolution_event
2005 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2006 vpe_resolver_process_node.index,
2007 RESOLUTION_EVENT, pr - vam->pending_routes);
2009 vlib_process_signal_event
2010 (vm, vpe_resolver_process_node.index,
2011 RESOLUTION_PENDING_EVENT, 0 /* data */);
2013 /* The interface may be down, etc. */
2014 e = ip4_probe_neighbor
2015 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2019 clib_error_report(e);
2021 return VNET_API_ERROR_IN_PROGRESS;
2025 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2026 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2029 vnet_rewrite_get_data_internal
2030 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2032 dslock (sm, 1 /* release hint */, 10 /* tag */);
2034 rv = vnet_mpls_ethernet_add_del_tunnel
2035 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2036 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2037 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2045 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2046 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2048 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2051 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2053 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2058 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2060 vl_api_mpls_add_del_encap_reply_t * rmp;
2062 static u32 * labels;
2065 vec_reset_length (labels);
2067 for (i = 0; i < mp->nlabels; i++)
2068 vec_add1 (labels, ntohl(mp->labels[i]));
2071 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2072 ntohl(mp->vrf_id), labels,
2073 ~0 /* policy_tunnel_index */,
2074 0 /* no_dst_hash */,
2078 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2082 vl_api_mpls_add_del_decap_t_handler
2083 (vl_api_mpls_add_del_decap_t *mp)
2085 vl_api_mpls_add_del_decap_reply_t * rmp;
2088 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2089 ntohl(mp->label), ntohl(mp->next_index),
2090 mp->s_bit, mp->is_add);
2092 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2096 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2098 vl_api_proxy_arp_add_del_reply_t * rmp;
2101 ip4_main_t * im = &ip4_main;
2102 stats_main_t * sm = &stats_main;
2103 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2104 ip4_address_t *hi_addr,
2105 u32 fib_index, int is_del);
2108 dslock (sm, 1 /* release hint */, 6 /* tag */);
2110 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2113 rv = VNET_API_ERROR_NO_SUCH_FIB;
2119 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2120 (ip4_address_t *)mp->hi_address,
2121 fib_index, mp->is_add == 0);
2125 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2129 vl_api_proxy_arp_intfc_enable_disable_t_handler
2130 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2133 vnet_main_t * vnm = vnet_get_main();
2134 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2135 vnet_sw_interface_t * si;
2138 VALIDATE_SW_IF_INDEX(mp);
2140 sw_if_index = ntohl(mp->sw_if_index);
2142 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2144 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2148 si = vnet_get_sw_interface (vnm, sw_if_index);
2152 if (mp->enable_disable)
2153 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2155 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2157 BAD_SW_IF_INDEX_LABEL;
2160 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2164 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2166 vl_api_ip_neighbor_add_del_reply_t * rmp;
2167 vnet_main_t * vnm = vnet_get_main();
2170 stats_main_t * sm = &stats_main;
2172 VALIDATE_SW_IF_INDEX(mp);
2174 dslock (sm, 1 /* release hint */, 7 /* tag */);
2178 rv = vnet_set_ip6_ethernet_neighbor
2179 (vm, ntohl(mp->sw_if_index),
2180 (ip6_address_t *)(mp->dst_address),
2181 mp->mac_address, sizeof (mp->mac_address));
2183 rv = vnet_unset_ip6_ethernet_neighbor
2184 (vm, ntohl(mp->sw_if_index),
2185 (ip6_address_t *)(mp->dst_address),
2186 mp->mac_address, sizeof(mp->mac_address));
2188 ip4_main_t * im = &ip4_main;
2189 ip_lookup_main_t * lm = &im->lookup_main;
2190 ethernet_arp_ip4_over_ethernet_address_t a;
2192 ip_adjacency_t *nh_adj;
2194 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2196 rv = VNET_API_ERROR_NO_SUCH_FIB;
2202 * Unfortunately, folks have a penchant for
2203 * adding interface addresses to the ARP cache, and
2204 * wondering why the forwarder eventually ASSERTs...
2206 ai = ip4_fib_lookup_with_table
2207 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2208 1 /* disable default route */);
2211 nh_adj = ip_get_adjacency (lm, ai);
2212 /* Never allow manipulation of a local adj! */
2213 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2214 clib_warning("%U matches local adj",
2216 (ip4_address_t *)(mp->dst_address));
2217 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2222 memcpy (&a.ethernet, mp->mac_address, 6);
2223 memcpy (&a.ip4, mp->dst_address, 4);
2226 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2227 fib_index, &a, mp->is_static);
2229 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2233 BAD_SW_IF_INDEX_LABEL;
2236 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2240 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2243 vpe_main_t *rm = &vpe_main;
2244 ip4_main_t *im4 = &ip4_main;
2245 ip6_main_t *im6 = &ip6_main;
2246 ip_lookup_main_t * lm;
2251 u32 adj_index, sw_if_index;
2252 vl_api_is_address_reachable_t *rmp;
2253 ip_adjacency_t * adj;
2254 unix_shared_memory_queue_t *q;
2256 q = vl_api_client_index_to_input_queue (mp->client_index);
2258 increment_missing_api_client_counter (rm->vlib_main);
2262 rmp = vl_msg_api_alloc (sizeof (*rmp));
2263 memcpy (rmp, mp, sizeof (*rmp));
2265 sw_if_index = mp->next_hop_sw_if_index;
2266 memcpy (&addr, mp->address, sizeof (addr));
2268 lm = &im6->lookup_main;
2270 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2272 lm = &im4->lookup_main;
2274 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2276 if (adj_index == ~0) {
2280 adj = ip_get_adjacency (lm, adj_index);
2282 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2283 && adj->rewrite_header.sw_if_index == sw_if_index) {
2286 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2287 && adj->rewrite_header.sw_if_index == sw_if_index) {
2289 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2291 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2292 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2300 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2304 static void vl_api_sw_interface_details_t_handler (
2305 vl_api_sw_interface_details_t * mp)
2307 clib_warning ("BUG");
2310 static void vl_api_sw_interface_set_flags_t_handler (
2311 vl_api_sw_interface_set_flags_t * mp)
2313 vl_api_sw_interface_set_flags_reply_t *rmp;
2314 vnet_main_t * vnm = vnet_get_main();
2316 clib_error_t * error;
2319 VALIDATE_SW_IF_INDEX(mp);
2321 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2323 error = vnet_sw_interface_set_flags (vnm,
2324 ntohl(mp->sw_if_index),
2328 clib_error_report (error);
2331 BAD_SW_IF_INDEX_LABEL;
2332 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2335 static void send_sw_interface_details (vpe_api_main_t * am,
2336 unix_shared_memory_queue_t *q,
2337 vnet_sw_interface_t * swif,
2338 u8 * interface_name)
2340 vl_api_sw_interface_details_t * mp;
2341 vnet_hw_interface_t * hi;
2343 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2345 mp = vl_msg_api_alloc (sizeof (*mp));
2346 memset (mp, 0, sizeof (*mp));
2347 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2348 mp->sw_if_index = ntohl(swif->sw_if_index);
2349 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2350 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2352 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2354 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2355 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2356 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2357 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2359 strncpy ((char *) mp->interface_name,
2360 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2362 /* Send the L2 address for ethernet physical intfcs */
2363 if (swif->sup_sw_if_index == swif->sw_if_index
2364 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2365 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2366 ethernet_interface_t *ei;
2368 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2369 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2370 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2371 mp->l2_address_length = ntohl(sizeof (ei->address));
2372 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2373 vnet_sub_interface_t *sub = &swif->sub;
2374 mp->sub_id = ntohl(sub->id);
2375 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2376 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2377 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2378 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2379 mp->sub_exact_match = sub->eth.flags.exact_match;
2380 mp->sub_default = sub->eth.flags.default_sub;
2381 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2382 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2384 /* vlan tag rewrite data */
2385 u32 vtr_op = L2_VTR_DISABLED;
2386 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2388 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2389 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2390 // error - default to disabled
2391 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2392 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2395 mp->vtr_op = ntohl(vtr_op);
2396 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2397 mp->vtr_tag1 = ntohl(vtr_tag1);
2398 mp->vtr_tag2 = ntohl(vtr_tag2);
2402 vl_msg_api_send_shmem (q, (u8 *)&mp);
2405 static void send_sw_interface_flags (vpe_api_main_t * am,
2406 unix_shared_memory_queue_t *q,
2407 vnet_sw_interface_t * swif)
2409 vl_api_sw_interface_set_flags_t *mp;
2410 vnet_main_t * vnm = am->vnet_main;
2412 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2414 mp = vl_msg_api_alloc (sizeof (*mp));
2415 memset (mp, 0, sizeof (*mp));
2416 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2417 mp->sw_if_index = ntohl(swif->sw_if_index);
2419 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2421 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2423 vl_msg_api_send_shmem (q, (u8 *)&mp);
2426 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2427 unix_shared_memory_queue_t *q,
2429 __attribute__((unused));
2431 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2432 unix_shared_memory_queue_t *q,
2435 vl_api_sw_interface_set_flags_t *mp;
2437 mp = vl_msg_api_alloc (sizeof (*mp));
2438 memset (mp, 0, sizeof (*mp));
2439 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2440 mp->sw_if_index = ntohl(sw_if_index);
2442 mp->admin_up_down = 0;
2443 mp->link_up_down = 0;
2445 vl_msg_api_send_shmem (q, (u8 *)&mp);
2448 static void vl_api_sw_interface_dump_t_handler (
2449 vl_api_sw_interface_dump_t *mp)
2451 vpe_api_main_t * am = &vpe_api_main;
2452 vnet_sw_interface_t * swif;
2453 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2454 u8 * filter_string = 0, * name_string = 0;
2455 unix_shared_memory_queue_t * q;
2456 char * strcasestr (char *, char *); /* lnx hdr file botch */
2458 q = vl_api_client_index_to_input_queue (mp->client_index);
2463 if (mp->name_filter_valid) {
2464 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2465 filter_string = format (0, "%s%c", mp->name_filter, 0);
2468 pool_foreach (swif, im->sw_interfaces,
2470 name_string = format (name_string, "%U%c",
2471 format_vnet_sw_interface_name,
2472 am->vnet_main, swif, 0);
2474 if (mp->name_filter_valid == 0 ||
2475 strcasestr((char *) name_string, (char *) filter_string)) {
2477 send_sw_interface_details (am, q, swif, name_string);
2478 send_sw_interface_flags (am, q, swif);
2480 _vec_len (name_string) = 0;
2483 vec_free (name_string);
2484 vec_free (filter_string);
2487 void send_oam_event (oam_target_t * t)
2489 vpe_api_main_t * vam = &vpe_api_main;
2490 unix_shared_memory_queue_t * q;
2491 vpe_client_registration_t *reg;
2492 vl_api_oam_event_t * mp;
2494 pool_foreach(reg, vam->oam_events_registrations,
2496 q = vl_api_client_index_to_input_queue (reg->client_index);
2498 mp = vl_msg_api_alloc (sizeof (*mp));
2499 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2500 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2501 mp->state = t->state;
2502 vl_msg_api_send_shmem (q, (u8 *)&mp);
2508 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2510 vl_api_oam_add_del_reply_t * rmp;
2513 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2514 (ip4_address_t *)mp->dst_address,
2518 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2522 vl_api_vnet_get_summary_stats_t_handler (
2523 vl_api_vnet_get_summary_stats_t *mp)
2525 stats_main_t * sm = &stats_main;
2526 vnet_interface_main_t * im = sm->interface_main;
2527 vl_api_vnet_summary_stats_reply_t *rmp;
2528 vlib_combined_counter_main_t * cm;
2531 u64 total_pkts[VLIB_N_RX_TX];
2532 u64 total_bytes[VLIB_N_RX_TX];
2534 unix_shared_memory_queue_t * q =
2535 vl_api_client_index_to_input_queue (mp->client_index);
2540 rmp = vl_msg_api_alloc (sizeof (*rmp));
2541 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2542 rmp->context = mp->context;
2545 memset (total_pkts, 0, sizeof (total_pkts));
2546 memset (total_bytes, 0, sizeof (total_bytes));
2548 vnet_interface_counter_lock (im);
2550 vec_foreach (cm, im->combined_sw_if_counters) {
2551 which = cm - im->combined_sw_if_counters;
2553 for (i = 0; i < vec_len (cm->maxi); i++) {
2554 vlib_get_combined_counter (cm, i, &v);
2555 total_pkts[which] += v.packets;
2556 total_bytes[which] += v.bytes;
2559 vnet_interface_counter_unlock (im);
2561 /* Note: in HOST byte order! */
2562 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2563 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2564 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2565 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2566 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2568 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2571 typedef CLIB_PACKED (struct {
2572 ip4_address_t address;
2574 u32 address_length : 6;
2579 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2581 vnet_main_t * vnm = vnet_get_main();
2582 vnet_interface_main_t * im = &vnm->interface_main;
2583 ip4_main_t * im4 = &ip4_main;
2584 static ip4_route_t * routes;
2585 static u32 * sw_if_indices_to_shut;
2586 stats_main_t * sm = &stats_main;
2591 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2592 u32 target_fib_id = ntohl(mp->vrf_id);
2594 dslock (sm, 1 /* release hint */, 8 /* tag */);
2596 vec_foreach (fib, im4->fibs) {
2597 vnet_sw_interface_t * si;
2599 if (fib->table_id != target_fib_id)
2602 /* remove any mpls/gre tunnels in this fib */
2603 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2605 /* remove any mpls encap/decap labels */
2606 mpls_fib_reset_labels (fib->table_id);
2608 /* remove any proxy arps in this fib */
2609 vnet_proxy_arp_fib_reset (fib->table_id);
2611 /* Set the flow hash for this fib to the default */
2612 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2614 vec_reset_length (sw_if_indices_to_shut);
2616 /* Shut down interfaces in this FIB / clean out intfc routes */
2617 pool_foreach (si, im->sw_interfaces,
2619 u32 sw_if_index = si->sw_if_index;
2621 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2622 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2624 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2627 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2628 sw_if_index = sw_if_indices_to_shut[i];
2629 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2631 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2632 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2633 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2636 vec_reset_length (routes);
2638 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2639 uword * hash = fib->adj_index_by_dst_address[i];
2643 x.address_length = i;
2645 hash_foreach_pair (p, hash,
2647 x.address.data_u32 = p->key;
2648 vec_add1 (routes, x);
2652 vec_foreach (r, routes) {
2653 ip4_add_del_route_args_t a;
2655 memset (&a, 0, sizeof (a));
2656 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2657 a.table_index_or_table_id = fib - im4->fibs;
2658 a.dst_address = r->address;
2659 a.dst_address_length = r->address_length;
2662 ip4_add_del_route (im4, &a);
2663 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2664 IP4_ROUTE_FLAG_FIB_INDEX);
2668 } /* vec_foreach (fib) */
2675 ip6_address_t address;
2682 ip6_route_t ** routep;
2683 } add_routes_in_fib_arg_t;
2685 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2687 add_routes_in_fib_arg_t * ap = arg;
2689 if (kvp->key[2]>>32 == ap->fib_index)
2691 ip6_address_t *addr;
2693 addr = (ip6_address_t *) kvp;
2694 vec_add2 (*ap->routep, r, 1);
2695 r->address = addr[0];
2696 r->address_length = kvp->key[2] & 0xFF;
2697 r->index = kvp->value;
2701 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2703 vnet_main_t * vnm = vnet_get_main();
2704 vnet_interface_main_t * im = &vnm->interface_main;
2705 ip6_main_t * im6 = &ip6_main;
2706 stats_main_t * sm = &stats_main;
2707 static ip6_route_t * routes;
2708 static u32 * sw_if_indices_to_shut;
2713 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2714 u32 target_fib_id = ntohl(mp->vrf_id);
2715 add_routes_in_fib_arg_t _a, *a=&_a;
2716 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2718 dslock (sm, 1 /* release hint */, 9 /* tag */);
2720 vec_foreach (fib, im6->fibs) {
2721 vnet_sw_interface_t * si;
2723 if (fib->table_id != target_fib_id)
2726 vec_reset_length (sw_if_indices_to_shut);
2728 /* Shut down interfaces in this FIB / clean out intfc routes */
2729 pool_foreach (si, im->sw_interfaces,
2731 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2733 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2736 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2737 sw_if_index = sw_if_indices_to_shut[i];
2738 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2740 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2741 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2742 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2745 vec_reset_length (routes);
2747 a->fib_index = fib - im6->fibs;
2748 a->routep = &routes;
2750 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2752 vec_foreach (r, routes) {
2753 ip6_add_del_route_args_t a;
2755 memset (&a, 0, sizeof (a));
2756 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2757 a.table_index_or_table_id = fib - im6->fibs;
2758 a.dst_address = r->address;
2759 a.dst_address_length = r->address_length;
2762 ip6_add_del_route (im6, &a);
2763 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2764 IP6_ROUTE_FLAG_FIB_INDEX);
2767 /* Reinstall the neighbor / router discovery routes */
2768 vnet_ip6_fib_init (im6, fib - im6->fibs);
2770 } /* vec_foreach (fib) */
2776 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2779 vl_api_reset_fib_reply_t * rmp;
2782 rv = ip6_reset_fib_t_handler (mp);
2784 rv = ip4_reset_fib_t_handler (mp);
2786 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2791 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2793 vl_api_dhcp_proxy_config_reply_t * rmp;
2796 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2797 (ip4_address_t *)(&mp->dhcp_src_address),
2798 (u32) ntohl(mp->vrf_id),
2799 (int) mp->insert_circuit_id,
2800 (int) (mp->is_add == 0));
2802 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2807 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2809 vl_api_dhcp_proxy_config_reply_t * rmp;
2812 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2813 (ip6_address_t *)(&mp->dhcp_src_address),
2814 (u32) ntohl(mp->vrf_id),
2815 (int) mp->insert_circuit_id,
2816 (int) (mp->is_add == 0));
2818 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2822 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2824 vl_api_dhcp_proxy_config_reply_t * rmp;
2827 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2828 (ip4_address_t *)(&mp->dhcp_src_address),
2829 (u32) ntohl(mp->rx_vrf_id),
2830 (u32) ntohl(mp->server_vrf_id),
2831 (int) mp->insert_circuit_id,
2832 (int) (mp->is_add == 0));
2834 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2839 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2841 vl_api_dhcp_proxy_config_reply_t * rmp;
2845 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2846 (ip6_address_t *)(&mp->dhcp_src_address),
2847 (u32) ntohl(mp->rx_vrf_id),
2848 (u32) ntohl(mp->server_vrf_id),
2849 (int) mp->insert_circuit_id,
2850 (int) (mp->is_add == 0));
2852 rv = VNET_API_ERROR_UNIMPLEMENTED;
2855 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2860 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2862 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2865 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2868 (int)mp->is_add == 0);
2870 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2873 (int)mp->is_add == 0);
2875 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2879 static void vl_api_dhcp_proxy_config_t_handler
2880 (vl_api_dhcp_proxy_config_t *mp)
2882 if (mp->is_ipv6 == 0)
2883 dhcpv4_proxy_config (mp);
2885 dhcpv6_proxy_config (mp);
2888 static void vl_api_dhcp_proxy_config_2_t_handler
2889 (vl_api_dhcp_proxy_config_2_t *mp)
2891 if (mp->is_ipv6 == 0)
2892 dhcpv4_proxy_config_2 (mp);
2894 dhcpv6_proxy_config_2 (mp);
2897 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2898 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2900 unix_shared_memory_queue_t * q;
2901 vl_api_dhcp_compl_event_t * mp;
2903 q = vl_api_client_index_to_input_queue (client_index);
2907 mp = vl_msg_api_alloc (sizeof (*mp));
2908 mp->client_index = client_index;
2910 mp->is_ipv6 = is_ipv6;
2911 memcpy (&mp->hostname, hostname, vec_len(hostname));
2912 mp->hostname[vec_len(hostname) + 1] = '\n';
2913 memcpy (&mp->host_address[0], host_address, 16);
2914 memcpy (&mp->router_address[0], router_address, 16);
2915 memcpy (&mp->host_mac[0], host_mac, 6);
2917 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2919 vl_msg_api_send_shmem (q, (u8 *)&mp);
2922 static void vl_api_dhcp_client_config_t_handler
2923 (vl_api_dhcp_client_config_t *mp)
2925 vlib_main_t *vm = vlib_get_main();
2926 vl_api_dhcp_client_config_reply_t * rmp;
2929 VALIDATE_SW_IF_INDEX(mp);
2931 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
2932 mp->hostname, mp->is_add, mp->client_index,
2933 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
2936 BAD_SW_IF_INDEX_LABEL;
2938 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
2942 vl_api_sw_interface_ip6nd_ra_config_t_handler
2943 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
2945 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
2947 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
2949 is_no = mp->is_no == 1;
2950 surpress = mp->surpress == 1;
2951 managed = mp->managed == 1;
2952 other = mp->other == 1;
2953 ll_option = mp->ll_option == 1;
2954 send_unicast = mp->send_unicast == 1;
2955 cease = mp->cease == 1;
2956 default_router = mp->default_router == 1;
2958 VALIDATE_SW_IF_INDEX(mp);
2960 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
2961 surpress, managed, other,
2962 ll_option, send_unicast, cease,
2963 default_router, ntohl (mp->lifetime),
2964 ntohl(mp->initial_count), ntohl(mp->initial_interval),
2965 ntohl(mp->max_interval), ntohl( mp->min_interval),
2968 BAD_SW_IF_INDEX_LABEL;
2970 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2974 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2975 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
2977 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
2979 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
2981 VALIDATE_SW_IF_INDEX(mp);
2983 is_no = mp->is_no == 1;
2984 use_default = mp->use_default == 1;
2985 no_advertise = mp->no_advertise == 1;
2986 off_link = mp->off_link == 1;
2987 no_autoconfig = mp->no_autoconfig == 1;
2988 no_onlink = mp->no_onlink == 1;
2990 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
2991 (ip6_address_t *)mp->address, mp->address_length,
2992 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
2993 no_advertise, off_link, no_autoconfig, no_onlink,
2996 BAD_SW_IF_INDEX_LABEL;
2997 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3001 vl_api_sw_interface_ip6_enable_disable_t_handler
3002 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3004 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3005 vnet_main_t * vnm = vnet_get_main();
3007 clib_error_t * error;
3011 VALIDATE_SW_IF_INDEX(mp);
3013 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3014 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3017 clib_error_report(error);
3018 rv = VNET_API_ERROR_UNSPECIFIED;
3020 rv = vnm->api_errno;
3023 BAD_SW_IF_INDEX_LABEL;
3025 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3029 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3030 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3032 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3034 clib_error_t * error;
3035 vnet_main_t * vnm = vnet_get_main();
3039 VALIDATE_SW_IF_INDEX(mp);
3041 error = set_ip6_link_local_address(vm,
3042 ntohl(mp->sw_if_index),
3043 (ip6_address_t *)mp->address,
3044 mp->address_length);
3046 clib_error_report(error);
3047 rv = VNET_API_ERROR_UNSPECIFIED;
3049 rv = vnm->api_errno;
3052 BAD_SW_IF_INDEX_LABEL;
3054 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3057 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3059 vl_api_set_ip_flow_hash_reply_t *rmp;
3060 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3062 clib_warning ("unimplemented...");
3064 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3067 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3069 vl_api_set_ip_flow_hash_reply_t *rmp;
3072 u32 flow_hash_config = 0;
3074 table_id = ntohl(mp->vrf_id);
3076 #define _(a,b) if (mp->a) flow_hash_config |= b;
3077 foreach_flow_hash_bit;
3080 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3082 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3086 static void vl_api_set_ip_flow_hash_t_handler
3087 (vl_api_set_ip_flow_hash_t *mp)
3089 if (mp->is_ipv6 == 0)
3090 set_ip4_flow_hash (mp);
3092 set_ip6_flow_hash (mp);
3095 static void vl_api_sw_interface_set_unnumbered_t_handler
3096 (vl_api_sw_interface_set_unnumbered_t *mp)
3098 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3100 vnet_sw_interface_t * si;
3101 vnet_main_t *vnm = vnet_get_main();
3102 u32 sw_if_index, unnumbered_sw_if_index;
3104 sw_if_index = ntohl(mp->sw_if_index);
3105 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3108 * The API message field names are backwards from
3109 * the underlying data structure names.
3110 * It's not worth changing them now.
3112 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3113 unnumbered_sw_if_index)) {
3114 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3118 /* Only check the "use loop0" field when setting the binding */
3120 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3121 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3125 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3128 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3129 si->unnumbered_sw_if_index = sw_if_index;
3131 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3132 si->unnumbered_sw_if_index = (u32)~0;
3136 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3139 static void vl_api_create_loopback_t_handler
3140 (vl_api_create_loopback_t *mp)
3142 vl_api_create_loopback_reply_t * rmp;
3146 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3148 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3150 rmp->sw_if_index = ntohl (sw_if_index);
3154 static void vl_api_delete_loopback_t_handler
3155 (vl_api_delete_loopback_t *mp)
3157 vl_api_delete_loopback_reply_t * rmp;
3161 sw_if_index = ntohl (mp->sw_if_index);
3162 rv = vnet_delete_loopback_interface (sw_if_index);
3164 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3167 static void vl_api_control_ping_t_handler
3168 (vl_api_control_ping_t *mp)
3170 vl_api_control_ping_reply_t * rmp;
3173 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3175 rmp->vpe_pid = ntohl (getpid());
3179 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3181 u8 **shmem_vecp = (u8 **)arg;
3184 api_main_t * am = &api_main;
3187 shmem_vec = *shmem_vecp;
3189 offset = vec_len (shmem_vec);
3191 pthread_mutex_lock (&am->vlib_rp->mutex);
3192 oldheap = svm_push_data_heap (am->vlib_rp);
3194 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3196 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3198 svm_pop_heap (oldheap);
3199 pthread_mutex_unlock (&am->vlib_rp->mutex);
3201 *shmem_vecp = shmem_vec;
3205 static void vl_api_cli_request_t_handler
3206 (vl_api_cli_request_t *mp)
3208 vl_api_cli_reply_t *rp;
3209 unix_shared_memory_queue_t *q;
3210 vlib_main_t * vm = vlib_get_main();
3211 api_main_t * am = &api_main;
3212 unformat_input_t input;
3216 q = vl_api_client_index_to_input_queue (mp->client_index);
3220 rp = vl_msg_api_alloc (sizeof (*rp));
3221 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3222 rp->context = mp->context;
3224 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3226 vlib_cli_input (vm, &input, shmem_cli_output,
3229 pthread_mutex_lock (&am->vlib_rp->mutex);
3230 oldheap = svm_push_data_heap (am->vlib_rp);
3232 vec_add1(shmem_vec, 0);
3234 svm_pop_heap (oldheap);
3235 pthread_mutex_unlock (&am->vlib_rp->mutex);
3237 rp->reply_in_shmem = (uword)shmem_vec;
3239 vl_msg_api_send_shmem (q, (u8 *)&rp);
3242 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3245 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3246 vnet_main_t *vnm = vnet_get_main();
3247 clib_error_t * error;
3252 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3254 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3257 clib_error_report(error);
3258 rv = VNET_API_ERROR_UNSPECIFIED;
3260 rv = vnm->api_errno;
3263 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3266 static void vl_api_sr_tunnel_add_del_t_handler
3267 (vl_api_sr_tunnel_add_del_t *mp)
3269 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3271 vl_api_sr_tunnel_add_del_reply_t * rmp;
3272 ip6_address_t * segments = 0, * seg;
3273 ip6_address_t * tags = 0, *tag;
3274 ip6_address_t * this_address;
3277 if (mp->n_segments == 0) {
3282 memset (a, 0, sizeof (*a));
3283 a->src_address = (ip6_address_t *)&mp->src_address;
3284 a->dst_address = (ip6_address_t *)&mp->dst_address;
3285 a->dst_mask_width = mp->dst_mask_width;
3286 a->flags_net_byte_order = mp->flags_net_byte_order;
3287 a->is_del = (mp->is_add == 0);
3288 a->rx_table_id = ntohl(mp->outer_vrf_id);
3289 a->tx_table_id = ntohl(mp->inner_vrf_id);
3291 /* Yank segments and tags out of the API message */
3292 this_address = (ip6_address_t *)mp->segs_and_tags;
3293 for (i = 0; i < mp->n_segments; i++) {
3294 vec_add2 (segments, seg, 1);
3295 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3298 for (i = 0; i < mp->n_tags; i++) {
3299 vec_add2 (tags, tag, 1);
3300 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3304 a->segments = segments;
3307 rv = ip6_sr_add_del_tunnel (a);
3311 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3314 #define foreach_classify_add_del_table_field \
3319 _(match_n_vectors) \
3320 _(next_table_index) \
3323 static void vl_api_classify_add_del_table_t_handler
3324 (vl_api_classify_add_del_table_t * mp)
3326 vl_api_classify_add_del_table_reply_t * rmp;
3327 vnet_classify_main_t * cm = &vnet_classify_main;
3328 vnet_classify_table_t * t;
3332 foreach_classify_add_del_table_field;
3335 #define _(a) a = ntohl(mp->a);
3336 foreach_classify_add_del_table_field;
3339 /* The underlying API fails silently, on purpose, so check here */
3340 if (mp->is_add == 0)
3341 if (pool_is_free_index (cm->tables, table_index)) {
3342 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3346 rv = vnet_classify_add_del_table
3347 (cm, mp->mask, nbuckets, memory_size,
3348 skip_n_vectors, match_n_vectors,
3349 next_table_index, miss_next_index,
3350 &table_index, mp->is_add);
3353 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3355 if (rv == 0 && mp->is_add) {
3356 t = pool_elt_at_index (cm->tables, table_index);
3357 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3358 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3359 rmp->new_table_index = ntohl(table_index);
3361 rmp->skip_n_vectors = ~0;
3362 rmp->match_n_vectors = ~0;
3363 rmp->new_table_index = ~0;
3368 static void vl_api_classify_add_del_session_t_handler
3369 (vl_api_classify_add_del_session_t * mp)
3371 vnet_classify_main_t * cm = &vnet_classify_main;
3372 vl_api_classify_add_del_session_reply_t * rmp;
3374 u32 table_index, hit_next_index, opaque_index;
3377 table_index = ntohl (mp->table_index);
3378 hit_next_index = ntohl (mp->hit_next_index);
3379 opaque_index = ntohl (mp->opaque_index);
3380 advance = ntohl (mp->advance);
3382 rv = vnet_classify_add_del_session
3383 (cm, table_index, mp->match, hit_next_index, opaque_index,
3384 advance, mp->is_add);
3386 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3389 static void vl_api_classify_set_interface_ip_table_t_handler
3390 (vl_api_classify_set_interface_ip_table_t * mp)
3392 vlib_main_t * vm = vlib_get_main();
3393 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3395 u32 table_index, sw_if_index;
3397 table_index = ntohl (mp->table_index);
3398 sw_if_index = ntohl (mp->sw_if_index);
3400 VALIDATE_SW_IF_INDEX(mp);
3403 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3405 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3407 BAD_SW_IF_INDEX_LABEL;
3409 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3412 static void vl_api_classify_set_interface_l2_tables_t_handler
3413 (vl_api_classify_set_interface_l2_tables_t * mp)
3415 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3417 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3420 ip4_table_index = ntohl(mp->ip4_table_index);
3421 ip6_table_index = ntohl(mp->ip6_table_index);
3422 other_table_index = ntohl(mp->other_table_index);
3423 sw_if_index = ntohl(mp->sw_if_index);
3425 VALIDATE_SW_IF_INDEX(mp);
3427 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3428 ip6_table_index, other_table_index);
3431 if (ip4_table_index != ~0 || ip6_table_index != ~0
3432 || other_table_index != ~0)
3437 vnet_l2_classify_enable_disable (sw_if_index, enable);
3440 BAD_SW_IF_INDEX_LABEL;
3442 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3446 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3449 vl_api_l2_fib_clear_table_reply_t * rmp;
3451 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3452 * that is not currently implemented. When that TODO is fixed
3453 * this call should be changed to pass 1 instead of 0.
3455 l2fib_clear_table (0);
3457 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3460 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3465 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3468 vl_api_l2_interface_efp_filter_reply_t * rmp;
3469 vnet_main_t *vnm = vnet_get_main();
3471 // enable/disable the feature
3472 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3473 rv = vnm->api_errno;
3475 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3479 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3482 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3483 vnet_main_t * vnm = vnet_get_main();
3484 vlib_main_t * vm = vlib_get_main();
3487 VALIDATE_SW_IF_INDEX(mp);
3489 vtr_op = ntohl(mp->vtr_op);
3491 /* The L2 code is unsuspicious */
3493 case L2_VTR_DISABLED:
3498 case L2_VTR_TRANSLATE_1_1:
3499 case L2_VTR_TRANSLATE_1_2:
3500 case L2_VTR_TRANSLATE_2_1:
3501 case L2_VTR_TRANSLATE_2_2:
3505 rv = VNET_API_ERROR_INVALID_VALUE;
3506 goto bad_sw_if_index;
3509 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3510 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3513 BAD_SW_IF_INDEX_LABEL;
3515 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3519 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3523 vl_api_create_vhost_user_if_reply_t * rmp;
3524 u32 sw_if_index = (u32)~0;
3526 vnet_main_t * vnm = vnet_get_main();
3527 vlib_main_t * vm = vlib_get_main();
3529 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3530 mp->is_server, &sw_if_index, (u64)~0,
3531 mp->renumber, ntohl(mp->custom_dev_instance));
3533 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3535 rmp->sw_if_index = ntohl (sw_if_index);
3541 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3545 vl_api_modify_vhost_user_if_reply_t * rmp;
3546 u32 sw_if_index = ntohl(mp->sw_if_index);
3548 vnet_main_t * vnm = vnet_get_main();
3549 vlib_main_t * vm = vlib_get_main();
3551 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3552 mp->is_server, sw_if_index, (u64)~0,
3553 mp->renumber, ntohl(mp->custom_dev_instance));
3555 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3560 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3564 vpe_api_main_t * vam = &vpe_api_main;
3565 vl_api_delete_vhost_user_if_reply_t * rmp;
3566 u32 sw_if_index = ntohl(mp->sw_if_index);
3568 vnet_main_t * vnm = vnet_get_main();
3569 vlib_main_t * vm = vlib_get_main();
3571 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3573 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3575 unix_shared_memory_queue_t * q =
3576 vl_api_client_index_to_input_queue (mp->client_index);
3580 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3585 static void vl_api_sw_interface_vhost_user_details_t_handler (
3586 vl_api_sw_interface_vhost_user_details_t * mp)
3588 clib_warning ("BUG");
3592 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3593 unix_shared_memory_queue_t *q,
3594 vhost_user_intf_details_t * vui)
3596 vl_api_sw_interface_vhost_user_details_t * mp;
3598 mp = vl_msg_api_alloc (sizeof (*mp));
3599 memset (mp, 0, sizeof (*mp));
3600 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3601 mp->sw_if_index = ntohl(vui->sw_if_index);
3602 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3603 mp->features = clib_net_to_host_u64 (vui->features);
3604 mp->is_server = vui->is_server;
3605 mp->num_regions = ntohl(vui->num_regions);
3606 mp->sock_errno = ntohl(vui->sock_errno);
3608 strncpy ((char *) mp->sock_filename,
3609 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3610 strncpy ((char *) mp->interface_name,
3611 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3613 vl_msg_api_send_shmem (q, (u8 *)&mp);
3618 vl_api_sw_interface_vhost_user_dump_t_handler (
3619 vl_api_sw_interface_vhost_user_dump_t *mp)
3623 vpe_api_main_t * am = &vpe_api_main;
3624 vnet_main_t * vnm = vnet_get_main();
3625 vlib_main_t * vm = vlib_get_main();
3626 vhost_user_intf_details_t *ifaces = NULL;
3627 vhost_user_intf_details_t *vuid = NULL;
3628 unix_shared_memory_queue_t * q;
3630 q = vl_api_client_index_to_input_queue (mp->client_index);
3634 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3638 vec_foreach (vuid, ifaces) {
3639 send_sw_interface_vhost_user_details (am, q, vuid);
3645 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3646 unix_shared_memory_queue_t *q,
3650 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3651 u8 * if_name = NULL;
3652 vnet_sw_interface_t * si = NULL;
3654 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3656 if_name = format(if_name, "%U",
3657 format_vnet_sw_interface_name, lm->vnet_main, si);
3659 mp = vl_msg_api_alloc (sizeof (*mp));
3660 memset (mp, 0, sizeof (*mp));
3661 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3662 strncpy((char *)mp->interface_name,
3663 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3664 mp->sw_if_index = ntohl(si->sw_if_index);
3665 mp->local_session_id = s->local_session_id;
3666 mp->remote_session_id = s->remote_session_id;
3667 mp->local_cookie[0] = s->local_cookie[0];
3668 mp->local_cookie[1] = s->local_cookie[1];
3669 mp->remote_cookie = s->remote_cookie;
3670 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3671 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3672 mp->l2_sublayer_present = s->l2_sublayer_present;
3674 vl_msg_api_send_shmem (q, (u8 *)&mp);
3677 static void send_ip_address_details (vpe_api_main_t * am,
3678 unix_shared_memory_queue_t * q,
3683 vl_api_ip_address_details_t * mp;
3685 mp = vl_msg_api_alloc (sizeof (*mp));
3686 memset (mp, 0, sizeof (*mp));
3687 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3690 memcpy(&mp->ip, ip, sizeof(mp->ip));
3692 u32 * tp = (u32 *)mp->ip;
3693 *tp = ntohl(*(u32*)ip);
3695 mp->prefix_length = prefix_length;
3697 vl_msg_api_send_shmem (q, (u8 *)&mp);
3701 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3703 vpe_api_main_t * am = &vpe_api_main;
3704 unix_shared_memory_queue_t * q;
3707 ip6_main_t * im6 = &ip6_main;
3708 ip4_main_t * im4 = &ip4_main;
3709 ip_lookup_main_t * lm6 = &im6->lookup_main;
3710 ip_lookup_main_t * lm4 = &im4->lookup_main;
3711 ip_interface_address_t * ia = 0;
3712 u32 sw_if_index = ~0;
3714 sw_if_index = ntohl(mp->sw_if_index);
3716 q = vl_api_client_index_to_input_queue (mp->client_index);
3722 foreach_ip_interface_address (lm6, ia, sw_if_index,
3723 1 /* honor unnumbered */,
3725 r6 = ip_interface_address_get_address (lm6, ia);
3726 u16 prefix_length = ia->address_length;
3727 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3730 foreach_ip_interface_address (lm4, ia, sw_if_index,
3731 1 /* honor unnumbered */,
3733 r4 = ip_interface_address_get_address (lm4, ia);
3734 u16 prefix_length = ia->address_length;
3735 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3740 static void send_ip_details (vpe_api_main_t * am,
3741 unix_shared_memory_queue_t *q,
3744 vl_api_ip_details_t * mp;
3746 mp = vl_msg_api_alloc (sizeof (*mp));
3747 memset (mp, 0, sizeof (*mp));
3748 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3750 mp->sw_if_index = ntohl(sw_if_index);
3752 vl_msg_api_send_shmem (q, (u8 *)&mp);
3756 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3757 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3759 vpe_api_main_t * am = &vpe_api_main;
3760 l2t_main_t * lm = &l2t_main;
3761 unix_shared_memory_queue_t * q;
3762 l2t_session_t *session;
3764 q = vl_api_client_index_to_input_queue (mp->client_index);
3768 pool_foreach (session, lm->sessions,
3770 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3775 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3776 unix_shared_memory_queue_t *q,
3777 tapcli_interface_details_t *tap_if)
3779 vl_api_sw_interface_tap_details_t * mp;
3780 mp = vl_msg_api_alloc (sizeof (*mp));
3781 memset (mp, 0, sizeof (*mp));
3782 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3783 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3784 strncpy((char *)mp->dev_name,
3785 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3787 vl_msg_api_send_shmem (q, (u8 *)&mp);
3791 vl_api_sw_interface_tap_dump_t_handler (
3792 vl_api_sw_interface_tap_dump_t *mp)
3795 vpe_api_main_t * am = &vpe_api_main;
3796 unix_shared_memory_queue_t * q;
3797 tapcli_interface_details_t *tapifs = NULL;
3798 tapcli_interface_details_t *tap_if = NULL;
3800 q = vl_api_client_index_to_input_queue (mp->client_index);
3804 rv = vnet_tap_dump_ifs(&tapifs);
3808 vec_foreach(tap_if, tapifs) {
3809 send_sw_interface_tap_details(am, q, tap_if);
3816 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3818 vpe_api_main_t * am = &vpe_api_main;
3819 vnet_main_t * vnm = vnet_get_main();
3820 vlib_main_t * vm = vlib_get_main();
3821 vnet_interface_main_t * im = &vnm->interface_main;
3822 unix_shared_memory_queue_t * q;
3823 vnet_sw_interface_t * si, * sorted_sis;
3824 u32 sw_if_index = ~0;
3826 q = vl_api_client_index_to_input_queue (mp->client_index);
3831 /* Gather interfaces. */
3832 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3833 _vec_len (sorted_sis) = 0;
3834 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3836 vec_foreach (si, sorted_sis) {
3837 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3838 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3841 sw_if_index = si->sw_if_index;
3842 send_ip_details(am, q, sw_if_index);
3847 static void vl_api_l2_fib_table_entry_t_handler (
3848 vl_api_l2_fib_table_entry_t * mp)
3850 clib_warning ("BUG");
3853 static void send_l2fib_table_entry (vpe_api_main_t * am,
3854 unix_shared_memory_queue_t *q,
3855 l2fib_entry_key_t * l2fe_key,
3856 l2fib_entry_result_t * l2fe_res)
3858 vl_api_l2_fib_table_entry_t * mp;
3860 mp = vl_msg_api_alloc (sizeof (*mp));
3861 memset (mp, 0, sizeof (*mp));
3862 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3864 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3866 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3867 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3868 mp->static_mac = l2fe_res->fields.static_mac;
3869 mp->filter_mac = l2fe_res->fields.filter;
3870 mp->bvi_mac = l2fe_res->fields.bvi;
3872 vl_msg_api_send_shmem (q, (u8 *)&mp);
3876 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3878 vpe_api_main_t * am = &vpe_api_main;
3879 bd_main_t * bdm = &bd_main;
3880 l2fib_entry_key_t *l2fe_key = NULL;
3881 l2fib_entry_result_t *l2fe_res = NULL;
3882 u32 ni, bd_id = ntohl (mp->bd_id);
3884 unix_shared_memory_queue_t * q;
3887 q = vl_api_client_index_to_input_queue (mp->client_index);
3891 /* see l2fib_table_dump: ~0 means "any" */
3895 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3902 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3904 vec_foreach_index (ni, l2fe_key) {
3905 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
3906 vec_elt_at_index(l2fe_res, ni));
3913 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
3915 vl_api_show_version_reply_t *rmp;
3917 char * vpe_api_get_build_directory(void);
3918 char * vpe_api_get_branch(void);
3919 char * vpe_api_get_build_date(void);
3921 unix_shared_memory_queue_t * q =
3922 vl_api_client_index_to_input_queue (mp->client_index);
3927 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3929 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3930 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3931 ARRAY_LEN(rmp->build_directory)-1);
3932 strncpy ((char *) rmp->git_branch, vpe_api_get_branch(),
3933 ARRAY_LEN(rmp->git_branch)-1);
3934 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3935 ARRAY_LEN(rmp->build_date)-1);
3939 static void vl_api_get_node_index_t_handler
3940 (vl_api_get_node_index_t * mp)
3942 vlib_main_t * vm = vlib_get_main();
3943 vl_api_get_node_index_reply_t * rmp;
3946 u32 node_index = ~0;
3948 n = vlib_get_node_by_name (vm, mp->node_name);
3951 rv = VNET_API_ERROR_NO_SUCH_NODE;
3953 node_index = n->index;
3955 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3957 rmp->node_index = ntohl(node_index);
3961 static void vl_api_add_node_next_t_handler
3962 (vl_api_add_node_next_t * mp)
3964 vlib_main_t * vm = vlib_get_main();
3965 vl_api_add_node_next_reply_t * rmp;
3966 vlib_node_t * n, * next;
3968 u32 next_index = ~0;
3970 n = vlib_get_node_by_name (vm, mp->node_name);
3973 rv = VNET_API_ERROR_NO_SUCH_NODE;
3977 next = vlib_get_node_by_name (vm, mp->next_name);
3980 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3982 next_index = vlib_node_add_next (vm, n->index, next->index);
3985 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3987 rmp->next_index = ntohl(next_index);
3991 static void vl_api_l2tpv3_create_tunnel_t_handler
3992 (vl_api_l2tpv3_create_tunnel_t *mp)
3994 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
3995 l2t_main_t *lm = &l2t_main;
3996 u32 sw_if_index = (u32)~0;
3999 if (mp->is_ipv6 != 1) {
4000 rv = VNET_API_ERROR_UNIMPLEMENTED;
4004 rv = create_l2tpv3_ipv6_tunnel (lm,
4005 (ip6_address_t *) mp->client_address,
4006 (ip6_address_t *) mp->our_address,
4007 ntohl(mp->local_session_id),
4008 ntohl(mp->remote_session_id),
4009 clib_net_to_host_u64(mp->local_cookie),
4010 clib_net_to_host_u64(mp->remote_cookie),
4011 mp->l2_sublayer_present,
4015 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4017 rmp->sw_if_index = ntohl (sw_if_index);
4021 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4022 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4024 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4025 l2t_main_t *lm = &l2t_main;
4028 VALIDATE_SW_IF_INDEX(mp);
4030 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4031 clib_net_to_host_u64(mp->new_local_cookie),
4032 clib_net_to_host_u64(mp->new_remote_cookie));
4034 BAD_SW_IF_INDEX_LABEL;
4036 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4039 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4040 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4043 vnet_main_t * vnm = vnet_get_main();
4044 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4046 VALIDATE_SW_IF_INDEX(mp);
4048 rv = l2tpv3_interface_enable_disable
4049 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4051 BAD_SW_IF_INDEX_LABEL;
4053 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4056 static void vl_api_l2tpv3_set_lookup_key_t_handler
4057 (vl_api_l2tpv3_set_lookup_key_t * mp)
4060 l2t_main_t *lm = &l2t_main;
4061 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4063 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4064 rv = VNET_API_ERROR_INVALID_VALUE;
4068 lm->lookup_type = mp->key;
4071 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4074 static void vl_api_vxlan_add_del_tunnel_t_handler
4075 (vl_api_vxlan_add_del_tunnel_t * mp)
4077 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4079 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4080 u32 encap_fib_index;
4082 ip4_main_t * im = &ip4_main;
4083 u32 sw_if_index = ~0;
4085 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4087 rv = VNET_API_ERROR_NO_SUCH_FIB;
4090 encap_fib_index = p[0];
4092 memset (a, 0, sizeof (*a));
4094 a->is_add = mp->is_add;
4096 /* ip addresses sent in network byte order */
4097 a->src.as_u32 = mp->src_address;
4098 a->dst.as_u32 = mp->dst_address;
4100 a->encap_fib_index = encap_fib_index;
4101 a->decap_next_index = ntohl(mp->decap_next_index);
4102 a->vni = ntohl(mp->vni);
4103 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4106 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4108 rmp->sw_if_index = ntohl (sw_if_index);
4113 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4115 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4117 vl_api_l2_patch_add_del_reply_t * rmp;
4118 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4122 VALIDATE_RX_SW_IF_INDEX(mp);
4123 VALIDATE_TX_SW_IF_INDEX(mp);
4125 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4126 ntohl(mp->tx_sw_if_index),
4127 (int)(mp->is_add != 0));
4129 BAD_RX_SW_IF_INDEX_LABEL;
4130 BAD_TX_SW_IF_INDEX_LABEL;
4132 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4136 vl_api_nsh_gre_add_del_tunnel_t_handler
4137 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4139 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4141 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4142 u32 encap_fib_index, decap_fib_index;
4143 u32 decap_next_index;
4145 ip4_main_t * im = &ip4_main;
4147 u32 sw_if_index = ~0;
4150 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4152 rv = VNET_API_ERROR_NO_SUCH_FIB;
4155 encap_fib_index = p[0];
4157 decap_next_index = ntohl(mp->decap_next_index);
4159 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4160 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4161 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4163 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4166 decap_fib_index = p[0];
4168 decap_fib_index = ntohl(mp->decap_vrf_id);
4171 memset (a, 0, sizeof (*a));
4173 a->is_add = mp->is_add;
4174 /* ip addresses sent in network byte order */
4175 a->src.as_u32 = ntohl(mp->src);
4176 a->dst.as_u32 = ntohl(mp->dst);
4177 a->encap_fib_index = encap_fib_index;
4178 a->decap_fib_index = decap_fib_index;
4179 a->decap_next_index = decap_next_index;
4180 a->ver_o_c = mp->ver_o_c;
4181 a->length = mp->length;
4182 a->md_type = mp->md_type;
4183 a->next_protocol = mp->next_protocol;
4184 a->spi_si = ntohl(mp->spi_si);
4185 a->c1 = ntohl(mp->c1);
4186 a->c2 = ntohl(mp->c2);
4187 a->c3 = ntohl(mp->c3);
4188 a->c4 = ntohl(mp->c4);
4190 for (i = 0; i < mp->tlv_len_in_words; i++)
4191 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4195 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4198 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4200 rmp->sw_if_index = ntohl (sw_if_index);
4205 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4206 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4208 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4210 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4211 u32 encap_fib_index, decap_fib_index;
4212 u32 decap_next_index;
4214 ip4_main_t * im = &ip4_main;
4216 u32 sw_if_index = ~0;
4219 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4221 rv = VNET_API_ERROR_NO_SUCH_FIB;
4224 encap_fib_index = p[0];
4226 decap_next_index = ntohl(mp->decap_next_index);
4228 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4229 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4230 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4232 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4235 decap_fib_index = p[0];
4237 decap_fib_index = ntohl(mp->decap_vrf_id);
4240 memset (a, 0, sizeof (*a));
4242 a->is_add = mp->is_add;
4243 /* ip addresses sent in network byte order */
4244 a->src.as_u32 = ntohl(mp->src);
4245 a->dst.as_u32 = ntohl(mp->dst);
4246 a->encap_fib_index = encap_fib_index;
4247 a->decap_fib_index = decap_fib_index;
4248 a->decap_next_index = decap_next_index;
4249 a->vni = ntohl(mp->vni);
4250 a->ver_o_c = mp->ver_o_c;
4251 a->length = mp->length;
4252 a->md_type = mp->md_type;
4253 a->next_protocol = mp->next_protocol;
4254 a->spi_si = ntohl(mp->spi_si);
4255 a->c1 = ntohl(mp->c1);
4256 a->c2 = ntohl(mp->c2);
4257 a->c3 = ntohl(mp->c3);
4258 a->c4 = ntohl(mp->c4);
4260 for (i = 0; i < mp->tlv_len_in_words; i++)
4261 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4265 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4268 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4270 rmp->sw_if_index = ntohl (sw_if_index);
4275 vl_api_lisp_gpe_add_del_tunnel_t_handler
4276 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4278 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4280 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4281 u32 encap_fib_index, decap_fib_index;
4282 u32 decap_next_index;
4284 ip4_main_t * im = &ip4_main;
4285 u32 sw_if_index = ~0;
4287 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4289 rv = VNET_API_ERROR_NO_SUCH_FIB;
4292 encap_fib_index = p[0];
4294 decap_next_index = ntohl(mp->decap_next_index);
4296 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4297 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4298 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4300 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4303 decap_fib_index = p[0];
4305 decap_fib_index = ntohl(mp->decap_vrf_id);
4308 memset (a, 0, sizeof (*a));
4310 a->is_add = mp->is_add;
4311 /* ip addresses sent in network byte order */
4312 a->src.as_u32 = mp->src;
4313 a->dst.as_u32 = mp->dst;
4314 a->encap_fib_index = encap_fib_index;
4315 a->decap_fib_index = decap_fib_index;
4316 a->decap_next_index = decap_next_index;
4317 a->flags = mp->flags;
4318 a->ver_res = mp->ver_res;
4320 a->next_protocol = mp->next_protocol;
4321 a->iid = clib_net_to_host_u32 (mp->iid);
4323 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4326 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4328 rmp->sw_if_index = ntohl (sw_if_index);
4333 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4335 vl_api_interface_name_renumber_reply_t * rmp;
4338 VALIDATE_SW_IF_INDEX(mp);
4340 rv = vnet_interface_name_renumber
4341 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4343 BAD_SW_IF_INDEX_LABEL;
4345 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4348 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4349 u32 sw_if_index, u32 address)
4351 vpe_api_main_t * am = &vpe_api_main;
4352 vlib_main_t * vm = am->vlib_main;
4353 vl_api_ip4_arp_event_t * event;
4354 static f64 arp_event_last_time;
4355 f64 now = vlib_time_now (vm);
4357 if (pool_is_free_index (am->arp_events, pool_index))
4360 event = pool_elt_at_index (am->arp_events, pool_index);
4361 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4362 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4363 } else { /* same mac */
4364 if ((sw_if_index == event->sw_if_index) &&
4366 /* for BD case, also check IP address with 10 sec timeout */
4367 ((address == event->address) &&
4368 ((now - arp_event_last_time) < 10.0))))
4372 arp_event_last_time = now;
4373 event->sw_if_index = sw_if_index;
4374 if (address) event->address = address;
4378 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4380 vpe_api_main_t * am = &vpe_api_main;
4382 if (pool_is_free_index (am->arp_events, pool_index))
4385 pool_put_index (am->arp_events, pool_index);
4390 vl_api_want_ip4_arp_events_t_handler
4391 (vl_api_want_ip4_arp_events_t * mp)
4393 vpe_api_main_t * am = &vpe_api_main;
4394 vnet_main_t * vnm = vnet_get_main();
4395 vl_api_want_ip4_arp_events_reply_t *rmp;
4396 vl_api_ip4_arp_event_t * event;
4399 if (mp->enable_disable) {
4400 pool_get (am->arp_events, event);
4401 memset (event, 0, sizeof (*event));
4403 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4404 event->client_index = mp->client_index;
4405 event->context = mp->context;
4406 event->address = mp->address;
4407 event->pid = mp->pid;
4409 rv = vnet_add_del_ip4_arp_change_event
4410 (vnm, arp_change_data_callback,
4412 &mp->address /* addr, in net byte order */,
4413 vpe_resolver_process_node.index,
4414 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4416 rv = vnet_add_del_ip4_arp_change_event
4417 (vnm, arp_change_delete_callback,
4419 &mp->address /* addr, in net byte order */,
4420 vpe_resolver_process_node.index,
4421 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4423 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4426 static void vl_api_input_acl_set_interface_t_handler
4427 (vl_api_input_acl_set_interface_t * mp)
4429 vlib_main_t *vm = vlib_get_main();
4430 vl_api_input_acl_set_interface_reply_t * rmp;
4432 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4434 ip4_table_index = ntohl(mp->ip4_table_index);
4435 ip6_table_index = ntohl(mp->ip6_table_index);
4436 l2_table_index = ntohl(mp->l2_table_index);
4437 sw_if_index = ntohl(mp->sw_if_index);
4439 VALIDATE_SW_IF_INDEX(mp);
4441 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4442 ip6_table_index, l2_table_index,
4445 BAD_SW_IF_INDEX_LABEL;
4447 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4450 static void vl_api_ipsec_spd_add_del_t_handler
4451 (vl_api_ipsec_spd_add_del_t * mp)
4453 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4454 vl_api_ipsec_spd_add_del_reply_t * rmp;
4458 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4460 rv = VNET_API_ERROR_UNIMPLEMENTED;
4463 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4466 static void vl_api_ipsec_interface_add_del_spd_t_handler
4467 (vl_api_ipsec_interface_add_del_spd_t * mp)
4469 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4470 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4472 u32 sw_if_index __attribute__((unused));
4473 u32 spd_id __attribute__((unused));
4475 sw_if_index = ntohl(mp->sw_if_index);
4476 spd_id = ntohl(mp->spd_id);
4478 VALIDATE_SW_IF_INDEX(mp);
4481 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4483 rv = VNET_API_ERROR_UNIMPLEMENTED;
4486 BAD_SW_IF_INDEX_LABEL;
4488 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4491 static void vl_api_ipsec_spd_add_del_entry_t_handler
4492 (vl_api_ipsec_spd_add_del_entry_t * mp)
4494 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4495 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4501 p.id = ntohl(mp->spd_id);
4502 p.priority = ntohl(mp->priority);
4503 p.is_outbound = mp->is_outbound;
4504 p.is_ipv6 = mp->is_ipv6;
4506 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4507 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4508 memcpy(&p.laddr.start, mp->local_address_start, 16);
4509 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4511 p.protocol = mp->protocol;
4512 p.rport.start = ntohs(mp->remote_port_start);
4513 p.rport.stop = ntohs(mp->remote_port_stop);
4514 p.lport.start = ntohs(mp->local_port_start);
4515 p.lport.stop = ntohs(mp->local_port_stop);
4516 /* policy action resolve unsupported */
4517 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4518 clib_warning("unsupported action: 'resolve'");
4519 rv = VNET_API_ERROR_UNIMPLEMENTED;
4522 p.policy = mp->policy;
4523 p.sa_id = ntohl(mp->sa_id);
4525 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4529 if (mp->is_ip_any) {
4531 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4534 rv = VNET_API_ERROR_UNIMPLEMENTED;
4539 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4542 static void vl_api_ipsec_sad_add_del_entry_t_handler
4543 (vl_api_ipsec_sad_add_del_entry_t * mp)
4545 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4546 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4551 sa.id = ntohl(mp->sad_id);
4552 sa.spi = ntohl(mp->spi);
4553 /* security protocol AH unsupported */
4554 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4555 clib_warning("unsupported security protocol 'AH'");
4556 rv = VNET_API_ERROR_UNIMPLEMENTED;
4559 sa.protocol = mp->protocol;
4560 /* check for unsupported crypto-alg */
4561 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4562 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4563 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4564 mp->crypto_algorithm);
4565 rv = VNET_API_ERROR_UNIMPLEMENTED;
4568 sa.crypto_alg = mp->crypto_algorithm;
4569 sa.crypto_key_len = mp->crypto_key_length;
4570 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4571 /* check for unsupported integ-alg */
4572 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4573 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4574 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4575 mp->integrity_algorithm);
4576 rv = VNET_API_ERROR_UNIMPLEMENTED;
4579 sa.integ_alg = mp->integrity_algorithm;
4580 sa.integ_key_len = mp->integrity_key_length;
4581 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4582 sa.use_esn = mp->use_extended_sequence_number;
4583 sa.is_tunnel = mp->is_tunnel;
4584 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4585 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4586 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4588 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4590 rv = VNET_API_ERROR_UNIMPLEMENTED;
4595 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4598 vl_api_map_add_domain_t_handler
4599 (vl_api_map_add_domain_t * mp)
4601 vl_api_map_add_domain_reply_t * rmp;
4604 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4605 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4606 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4607 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4608 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4610 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4612 rmp->index = ntohl(index);
4617 vl_api_map_del_domain_t_handler
4618 (vl_api_map_del_domain_t * mp)
4620 vl_api_map_del_domain_reply_t * rmp;
4623 rv = map_delete_domain(ntohl(mp->index));
4625 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4629 vl_api_map_add_del_rule_t_handler
4630 (vl_api_map_add_del_rule_t * mp)
4632 vl_api_map_del_domain_reply_t * rmp;
4635 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4637 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4641 vl_api_map_domain_dump_t_handler
4642 (vl_api_map_domain_dump_t * mp)
4644 vl_api_map_domain_details_t * rmp;
4645 map_main_t *mm = &map_main;
4647 unix_shared_memory_queue_t * q;
4649 if (pool_elts (mm->domains) == 0)
4652 q = vl_api_client_index_to_input_queue (mp->client_index);
4657 pool_foreach(d, mm->domains, ({
4658 rmp = vl_msg_api_alloc (sizeof (*rmp));
4659 memset (rmp, 0, sizeof (*rmp));
4660 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4661 rmp->domain_index = htonl(d - mm->domains);
4662 rmp->ea_bits_len = d->ea_bits_len;
4663 rmp->psid_offset = d->psid_offset;
4664 rmp->psid_length = d->psid_length;
4665 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4666 rmp->ip4_prefix_len = d->ip4_prefix_len;
4667 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4668 rmp->ip6_prefix_len = d->ip6_prefix_len;
4669 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4670 rmp->ip6_src_len = d->ip6_src_len;
4671 rmp->mtu = htons(d->mtu);
4672 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4674 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4679 vl_api_map_rule_dump_t_handler
4680 (vl_api_map_rule_dump_t * mp)
4682 unix_shared_memory_queue_t * q;
4685 vl_api_map_rule_details_t * rmp;
4686 map_main_t *mm = &map_main;
4687 u32 domain_index = ntohl(mp->domain_index);
4690 if (pool_elts (mm->domains) == 0)
4693 d = pool_elt_at_index(mm->domains, domain_index);
4694 if (!d || !d->rules) {
4698 q = vl_api_client_index_to_input_queue (mp->client_index);
4703 for (i = 0; i < (0x1 << d->psid_length); i++) {
4705 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4708 rmp = vl_msg_api_alloc(sizeof(*rmp));
4709 memset(rmp, 0, sizeof(*rmp));
4710 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4711 rmp->psid = htons(i);
4712 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4713 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4718 vl_api_map_summary_stats_t_handler (
4719 vl_api_map_summary_stats_t *mp)
4721 vl_api_map_summary_stats_reply_t *rmp;
4722 vlib_combined_counter_main_t *cm;
4725 u64 total_pkts[VLIB_N_RX_TX];
4726 u64 total_bytes[VLIB_N_RX_TX];
4727 map_main_t *mm = &map_main;
4728 unix_shared_memory_queue_t *q =
4729 vl_api_client_index_to_input_queue(mp->client_index);
4734 rmp = vl_msg_api_alloc (sizeof (*rmp));
4735 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
4736 rmp->context = mp->context;
4739 memset (total_pkts, 0, sizeof (total_pkts));
4740 memset (total_bytes, 0, sizeof (total_bytes));
4742 map_domain_counter_lock (mm);
4743 vec_foreach(cm, mm->domain_counters) {
4744 which = cm - mm->domain_counters;
4746 for (i = 0; i < vec_len(cm->maxi); i++) {
4747 vlib_get_combined_counter (cm, i, &v);
4748 total_pkts[which] += v.packets;
4749 total_bytes[which] += v.bytes;
4753 map_domain_counter_unlock (mm);
4755 /* Note: in HOST byte order! */
4756 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
4757 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
4758 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
4759 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
4760 rmp->total_bindings = pool_elts(mm->domains);
4761 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
4762 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
4763 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
4765 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4768 static void vl_api_ipsec_sa_set_key_t_handler
4769 (vl_api_ipsec_sa_set_key_t * mp)
4771 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4772 vl_api_ipsec_sa_set_key_reply_t *rmp;
4776 sa.id = ntohl(mp->sa_id);
4777 sa.crypto_key_len = mp->crypto_key_length;
4778 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4779 sa.integ_key_len = mp->integrity_key_length;
4780 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4782 rv = ipsec_set_sa_key(vm, &sa);
4784 rv = VNET_API_ERROR_UNIMPLEMENTED;
4787 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
4790 #define BOUNCE_HANDLER(nn) \
4791 static void vl_api_##nn##_t_handler ( \
4792 vl_api_##nn##_t *mp) \
4794 vpe_client_registration_t *reg; \
4795 vpe_api_main_t * vam = &vpe_api_main; \
4796 unix_shared_memory_queue_t * q; \
4798 /* One registration only... */ \
4799 pool_foreach(reg, vam->nn##_registrations, \
4801 q = vl_api_client_index_to_input_queue (reg->client_index); \
4804 * If the queue is stuffed, turf the msg and complain \
4805 * It's unlikely that the intended recipient is \
4806 * alive; avoid deadlock at all costs. \
4808 if (q->cursize == q->maxsize) { \
4809 clib_warning ("ERROR: receiver queue full, drop msg"); \
4810 vl_msg_api_free (mp); \
4813 vl_msg_api_send_shmem (q, (u8 *)&mp); \
4817 vl_msg_api_free (mp); \
4820 BOUNCE_HANDLER(to_netconf_server);
4821 BOUNCE_HANDLER(from_netconf_server);
4822 BOUNCE_HANDLER(to_netconf_client);
4823 BOUNCE_HANDLER(from_netconf_client);
4827 * Add vpe's API message handlers to the table.
4828 * vlib has alread mapped shared memory and
4829 * added the client registration handlers.
4830 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
4833 static clib_error_t *
4834 vpe_api_hookup (vlib_main_t *vm)
4836 api_main_t * am = &api_main;
4839 vl_msg_api_set_handlers(VL_API_##N, #n, \
4840 vl_api_##n##_t_handler, \
4842 vl_api_##n##_t_endian, \
4843 vl_api_##n##_t_print, \
4844 sizeof(vl_api_##n##_t), 1);
4845 foreach_vpe_api_msg;
4849 * Manually register the sr tunnel add del msg, so we trace
4850 * enough bytes to capture a typical segment list
4852 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
4853 "sr_tunnel_add_del",
4854 vl_api_sr_tunnel_add_del_t_handler,
4856 vl_api_sr_tunnel_add_del_t_endian,
4857 vl_api_sr_tunnel_add_del_t_print,
4860 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
4861 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
4862 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
4863 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
4866 * Trace space for 8 MPLS encap labels, classifier mask+match
4868 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
4869 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
4870 += 5 * sizeof (u32x4);
4871 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
4872 += 5 * sizeof (u32x4);
4873 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
4874 += 16 * sizeof (u32);
4877 * trace space for 4 nsh-gre variable TLV words
4879 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
4880 += 4 * sizeof (u32);
4885 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
4887 static clib_error_t *
4888 vpe_api_init (vlib_main_t *vm)
4890 vpe_api_main_t *am = &vpe_api_main;
4893 am->vnet_main = vnet_get_main();
4894 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
4895 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
4896 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
4897 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
4898 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
4899 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
4902 vl_set_memory_region_name ("/vpe-api");
4903 vl_enable_disable_memory_api (vm, 1 /* enable it */);
4908 VLIB_INIT_FUNCTION(vpe_api_init);
4910 void * get_unformat_vnet_sw_interface (void)
4912 return (void *) &unformat_vnet_sw_interface;
4915 #undef vl_api_version
4916 #define vl_api_version(n,v) static u32 vpe_api_version = v;
4917 #include <api/vpe.api.h>
4918 #undef vl_api_version
4920 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
4922 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
4923 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
4924 clib_host_to_net_u32 (mp->api_versions[0]),
4931 static u8 * format_arp_event (u8 * s, va_list * args)
4933 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
4935 s = format (s, "pid %d: %U", event->pid,
4936 format_ip4_address, &event->address);
4940 static clib_error_t *
4941 show_ip4_arp_events_fn (vlib_main_t * vm,
4942 unformat_input_t * input,
4943 vlib_cli_command_t * cmd)
4945 vpe_api_main_t * am = &vpe_api_main;
4946 vl_api_ip4_arp_event_t * event;
4948 if (pool_elts (am->arp_events) == 0) {
4949 vlib_cli_output (vm, "No active arp event registrations");
4953 pool_foreach (event, am->arp_events,
4955 vlib_cli_output (vm, "%U", format_arp_event, event);
4961 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
4962 .path = "show arp event registrations",
4963 .function = show_ip4_arp_events_fn,
4964 .short_help = "Show arp event registrations",