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 event_data_cmp (void * a1, void * a2)
397 return (word) e1[0] - (word) e2[0];
401 link_state_process (vlib_main_t * vm,
402 vlib_node_runtime_t * rt,
405 vpe_api_main_t * vam = &vpe_api_main;
406 vnet_main_t * vnm = vam->vnet_main;
407 vnet_sw_interface_t * swif;
408 uword * event_data = 0;
409 vpe_client_registration_t *reg;
411 u32 prev_sw_if_index;
412 unix_shared_memory_queue_t * q;
414 vam->link_state_process_up = 1;
417 vlib_process_wait_for_event (vm);
419 /* Unified list of changed link or admin state sw_if_indices */
420 vlib_process_get_events_with_type
421 (vm, &event_data, API_LINK_STATE_EVENT);
422 vlib_process_get_events_with_type
423 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
425 /* Sort, so we can eliminate duplicates */
426 vec_sort_with_function (event_data, event_data_cmp);
428 prev_sw_if_index = ~0;
430 for (i = 0; i < vec_len(event_data); i++) {
431 /* Only one message per swif */
432 if (prev_sw_if_index == event_data[i])
434 prev_sw_if_index = event_data[i];
436 pool_foreach(reg, vam->interface_events_registrations,
438 q = vl_api_client_index_to_input_queue (reg->client_index);
440 // sw_interface may be deleted already
441 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
444 swif = vnet_get_sw_interface (vnm, event_data[i]);
445 send_sw_interface_flags (vam, q, swif);
450 vec_reset_length (event_data);
456 static clib_error_t *
457 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
458 static clib_error_t *
459 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
461 VLIB_REGISTER_NODE (link_state_process_node,static) = {
462 .function = link_state_process,
463 .type = VLIB_NODE_TYPE_PROCESS,
464 .name = "vpe-link-state-process",
467 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
468 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
470 static clib_error_t *
471 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
473 vpe_api_main_t * vam = &vpe_api_main;
474 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
476 if (vam->link_state_process_up)
477 vlib_process_signal_event (vam->vlib_main,
478 link_state_process_node.index,
479 API_LINK_STATE_EVENT,
484 static clib_error_t *
485 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
487 vpe_api_main_t * vam = &vpe_api_main;
490 * Note: it's perfectly fair to set a subif admin up / admin down.
491 * Note the subtle distinction between this routine and the previous
494 if (vam->link_state_process_up)
495 vlib_process_signal_event (vam->vlib_main,
496 link_state_process_node.index,
497 API_ADMIN_UP_DOWN_EVENT,
502 #define pub_sub_handler(lca,UCA) \
503 static void vl_api_want_##lca##_t_handler ( \
504 vl_api_want_##lca##_t *mp) \
506 vpe_api_main_t *vam = &vpe_api_main; \
507 vpe_client_registration_t *rp; \
508 vl_api_want_##lca##_reply_t *rmp; \
512 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
514 if (mp->enable_disable) { \
515 clib_warning ("pid %d: already enabled...", mp->pid); \
516 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
519 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
520 pool_put (vam->lca##_registrations, rp); \
521 hash_unset (vam->lca##_registration_hash, \
526 if (mp->enable_disable == 0) { \
527 clib_warning ("pid %d: already disabled...", mp->pid); \
528 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
531 pool_get (vam->lca##_registrations, rp); \
532 rp->client_index = mp->client_index; \
533 rp->client_pid = mp->pid; \
534 hash_set (vam->lca##_registration_hash, rp->client_index, \
535 rp - vam->lca##_registrations); \
538 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
541 pub_sub_handler (interface_events,INTERFACE_EVENTS)
542 pub_sub_handler (from_netconf_server,FROM_NETCONF_SERVER)
543 pub_sub_handler (to_netconf_server,TO_NETCONF_SERVER)
544 pub_sub_handler (from_netconf_client,FROM_NETCONF_CLIENT)
545 pub_sub_handler (to_netconf_client,TO_NETCONF_CLIENT)
546 pub_sub_handler (oam_events,OAM_EVENTS)
548 #define RESOLUTION_EVENT 1
549 #define RESOLUTION_PENDING_EVENT 2
550 #define IP4_ARP_EVENT 3
552 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
553 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
554 static int mpls_ethernet_add_del_tunnel_2_t_handler
555 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
557 void handle_ip4_arp_event (u32 pool_index)
559 vpe_api_main_t * vam = &vpe_api_main;
560 vnet_main_t * vnm = vam->vnet_main;
561 vlib_main_t * vm = vam->vlib_main;
562 vl_api_ip4_arp_event_t * event;
563 vl_api_ip4_arp_event_t * mp;
564 unix_shared_memory_queue_t * q;
566 /* Client can cancel, die, etc. */
567 if (pool_is_free_index (vam->arp_events, pool_index))
570 event = pool_elt_at_index (vam->arp_events, pool_index);
572 q = vl_api_client_index_to_input_queue (event->client_index);
574 (void) vnet_add_del_ip4_arp_change_event
575 (vnm, arp_change_delete_callback,
576 event->pid, &event->address,
577 vpe_resolver_process_node.index, IP4_ARP_EVENT,
578 ~0 /* pool index, notused */, 0 /* is_add */);
582 if (q->cursize < q->maxsize) {
583 mp = vl_msg_api_alloc (sizeof (*mp));
584 memcpy (mp, event, sizeof (*mp));
585 vl_msg_api_send_shmem (q, (u8 *)&mp);
587 static f64 last_time;
589 * Throttle syslog msgs.
590 * It's pretty tempting to just revoke the registration...
592 if (vlib_time_now (vm) > last_time + 10.0) {
593 clib_warning ("arp event for %U to pid %d: queue stuffed!",
594 format_ip4_address, &event->address, event->pid);
595 last_time = vlib_time_now(vm);
601 resolver_process (vlib_main_t * vm,
602 vlib_node_runtime_t * rt,
606 uword *event_data = 0;
608 vpe_api_main_t * vam = &vpe_api_main;
609 pending_route_t * pr;
610 vl_api_ip_add_del_route_t * adr;
611 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
612 u32 * resolution_failures = 0;
617 vlib_process_wait_for_event_or_clock (vm, timeout);
619 event_type = vlib_process_get_events (vm, &event_data);
621 switch (event_type) {
622 case RESOLUTION_PENDING_EVENT:
626 case RESOLUTION_EVENT:
627 for (i = 0; i < vec_len(event_data); i++) {
629 * Resolution events can occur long after the
630 * original request has timed out. $$$ add a cancel
633 if (pool_is_free_index (vam->pending_routes, event_data[i]))
636 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
640 switch (pr->resolve_type) {
641 case RESOLVE_IP4_ADD_DEL_ROUTE:
642 rv = ip4_add_del_route_t_handler (adr);
643 clib_warning ("resolver: add %U/%d via %U %s",
645 (ip4_address_t *)&(adr->dst_address),
646 adr->dst_address_length,
648 (ip4_address_t *)&(adr->next_hop_address),
649 (rv >= 0) ? "succeeded" : "failed");
652 case RESOLVE_IP6_ADD_DEL_ROUTE:
653 rv = ip6_add_del_route_t_handler (adr);
654 clib_warning ("resolver: add %U/%d via %U %s",
656 (ip6_address_t *)&(adr->dst_address),
657 adr->dst_address_length,
659 (ip6_address_t *)&(adr->next_hop_address),
660 (rv >= 0) ? "succeeded" : "failed");
663 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
664 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
665 clib_warning ("resolver: add mpls-o-e via %U %s",
667 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
668 (rv >= 0) ? "succeeded" : "failed");
672 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
674 pool_put (vam->pending_routes, pr);
679 for (i = 0; i < vec_len(event_data); i++)
680 handle_ip4_arp_event (event_data[i]);
683 case ~0: /* timeout, retry pending resolutions */
684 pool_foreach (pr, vam->pending_routes,
690 /* May fail, e.g. due to interface down */
691 switch (pr->resolve_type) {
692 case RESOLVE_IP4_ADD_DEL_ROUTE:
693 e = ip4_probe_neighbor
694 (vm, (ip4_address_t *)&(adr->next_hop_address),
695 ntohl(adr->next_hop_sw_if_index));
698 case RESOLVE_IP6_ADD_DEL_ROUTE:
699 e = ip6_probe_neighbor
700 (vm, (ip6_address_t *)&(adr->next_hop_address),
701 ntohl(adr->next_hop_sw_if_index));
704 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
706 e = ip4_probe_neighbor
708 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
709 pme->resolve_opaque);
713 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
717 clib_error_report (e);
719 adr->resolve_attempts = 1;
721 pme->resolve_attempts = 1;
725 adr->resolve_attempts -= 1;
726 if (adr->resolve_attempts == 0)
727 vec_add1 (resolution_failures,
728 pr - vam->pending_routes);
730 pme->resolve_attempts -= 1;
731 if (pme->resolve_attempts == 0)
732 vec_add1 (resolution_failures,
733 pr - vam->pending_routes);
737 for (i = 0; i < vec_len (resolution_failures); i++) {
738 pr = pool_elt_at_index (vam->pending_routes,
739 resolution_failures[i]);
743 switch (pr->resolve_type) {
744 case RESOLVE_IP4_ADD_DEL_ROUTE:
745 clib_warning ("resolver: add %U/%d via %U retry failure",
747 (ip4_address_t *)&(adr->dst_address),
748 adr->dst_address_length,
750 (ip4_address_t *)&(adr->next_hop_address));
753 case RESOLVE_IP6_ADD_DEL_ROUTE:
754 clib_warning ("resolver: add %U/%d via %U retry failure",
756 (ip6_address_t *)&(adr->dst_address),
757 adr->dst_address_length,
759 (ip6_address_t *)&(adr->next_hop_address));
762 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
763 clib_warning ("resolver: add mpls-o-e via %U retry failure",
765 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
769 clib_warning ("BUG");
771 pool_put(vam->pending_routes, pr);
773 vec_reset_length (resolution_failures);
776 if (pool_elts (vam->pending_routes) == 0)
778 vec_reset_length (event_data);
780 return 0; /* or not */
783 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
784 .function = resolver_process,
785 .type = VLIB_NODE_TYPE_PROCESS,
786 .name = "vpe-route-resolver-process",
789 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
791 ip4_main_t * im = &ip4_main;
792 ip_lookup_main_t * lm = &im->lookup_main;
793 vnet_classify_main_t * cm = &vnet_classify_main;
794 stats_main_t * sm = &stats_main;
795 ip4_add_del_route_args_t a;
796 ip4_address_t next_hop_address;
798 vpe_api_main_t * vam = &vpe_api_main;
799 vnet_main_t * vnm = vam->vnet_main;
800 vlib_main_t * vm = vlib_get_main();
801 pending_route_t * pr;
802 vl_api_ip_add_del_route_t * adr;
806 ip_adjacency_t *nh_adj, *add_adj = 0;
808 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
810 if (mp->create_vrf_if_needed) {
812 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
814 fib_index = f->index;
816 /* No such VRF, and we weren't asked to create one */
817 return VNET_API_ERROR_NO_SUCH_FIB;
823 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
824 ntohl(mp->next_hop_sw_if_index)))
825 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
827 memcpy (next_hop_address.data, mp->next_hop_address,
828 sizeof (next_hop_address.data));
830 /* Arp for the next_hop if necessary */
831 if (mp->is_add && mp->resolve_if_needed) {
833 ip_adjacency_t * adj;
835 lookup_result = ip4_fib_lookup_with_table
836 (im, fib_index, &next_hop_address, 1 /* disable default route */);
838 adj = ip_get_adjacency (lm, lookup_result);
840 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
841 pool_get (vam->pending_routes, pr);
842 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
844 memcpy (adr, mp, sizeof (*adr));
845 /* recursion block, "just in case" */
846 adr->resolve_if_needed = 0;
847 adr->resolve_attempts = ntohl(mp->resolve_attempts);
848 vnet_register_ip4_arp_resolution_event
849 (vnm, &next_hop_address, vpe_resolver_process_node.index,
850 RESOLUTION_EVENT, pr - vam->pending_routes);
852 vlib_process_signal_event
853 (vm, vpe_resolver_process_node.index,
854 RESOLUTION_PENDING_EVENT, 0 /* data */);
856 /* The interface may be down, etc. */
857 e = ip4_probe_neighbor
858 (vm, (ip4_address_t *)&(mp->next_hop_address),
859 ntohl(mp->next_hop_sw_if_index));
862 clib_error_report(e);
864 return VNET_API_ERROR_IN_PROGRESS;
868 if (mp->is_multipath) {
871 dslock (sm, 1 /* release hint */, 10 /* tag */);
874 flags = IP4_ROUTE_FLAG_ADD;
876 flags = IP4_ROUTE_FLAG_DEL;
879 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
881 ip4_add_del_route_next_hop (im, flags,
882 (ip4_address_t *) mp->dst_address,
883 (u32) mp->dst_address_length,
884 (ip4_address_t *) mp->next_hop_address,
885 ntohl(mp->next_hop_sw_if_index),
886 (u32) mp->next_hop_weight,
893 memset (&a, 0, sizeof (a));
894 memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
896 a.dst_address_length = mp->dst_address_length;
898 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
899 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
900 a.table_index_or_table_id = fib_index;
905 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
907 dslock (sm, 1 /* release hint */, 2 /* tag */);
911 ai = lm->drop_adj_index;
912 else if (mp->is_local)
913 ai = lm->local_adj_index;
914 else if (mp->is_classify) {
916 memset(&cadj, 0, sizeof(cadj));
917 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
918 cadj.classify_table_index = ntohl(mp->classify_table_index);
919 if (pool_is_free_index (cm->tables, cadj.classify_table_index)) {
921 return VNET_API_ERROR_NO_SUCH_TABLE;
923 vec_add1 (add_adj, cadj);
927 ai = ip4_fib_lookup_with_table
928 (im, fib_index, &next_hop_address,
929 1 /* disable default route */);
930 if (ai == lm->miss_adj_index) {
932 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
936 nh_adj = ip_get_adjacency (lm, ai);
937 vec_add1 (add_adj, nh_adj[0]);
938 if (mp->lookup_in_vrf) {
939 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
941 add_adj[0].explicit_fib_index = p[0];
945 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
949 ip_adjacency_t * adj;
950 int disable_default_route = 1;
952 /* Trying to delete the default route? */
953 if (a.dst_address.as_u32 == 0 &&
954 a.dst_address_length == 0)
955 disable_default_route = 0;
957 ai = ip4_fib_lookup_with_table
958 (im, fib_index, &a.dst_address, disable_default_route);
959 if (ai == lm->miss_adj_index) {
961 return VNET_API_ERROR_UNKNOWN_DESTINATION;
964 adj = ip_get_adjacency (lm, ai);
965 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
967 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
974 a.n_add_adj = vec_len(add_adj);
975 ip4_add_del_route (im, &a);
983 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
985 ip6_main_t * im = &ip6_main;
986 ip_lookup_main_t * lm = &im->lookup_main;
987 vnet_main_t * vnm = vnet_get_main();
988 vlib_main_t * vm = vlib_get_main();
989 vpe_api_main_t * vam = &vpe_api_main;
990 stats_main_t * sm = &stats_main;
991 ip6_add_del_route_args_t a;
992 ip6_address_t next_hop_address;
993 pending_route_t * pr;
994 vl_api_ip_add_del_route_t * adr;
999 ip_adjacency_t * nh_adj, * add_adj = 0;
1002 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1005 if (mp->create_vrf_if_needed) {
1007 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1009 fib_index = f->index;
1011 /* No such VRF, and we weren't asked to create one */
1012 return VNET_API_ERROR_NO_SUCH_FIB;
1018 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1019 ntohl(mp->next_hop_sw_if_index)))
1020 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1022 memcpy (next_hop_address.as_u8, mp->next_hop_address,
1023 sizeof (next_hop_address.as_u8));
1025 /* Arp for the next_hop if necessary */
1026 if (mp->is_add && mp->resolve_if_needed) {
1028 ip_adjacency_t * adj;
1030 lookup_result = ip6_fib_lookup_with_table
1031 (im, fib_index, &next_hop_address);
1033 adj = ip_get_adjacency (lm, lookup_result);
1035 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1036 pool_get (vam->pending_routes, pr);
1038 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1039 memcpy (adr, mp, sizeof (*adr));
1040 /* recursion block, "just in case" */
1041 adr->resolve_if_needed = 0;
1042 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1043 vnet_register_ip6_neighbor_resolution_event
1044 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1045 RESOLUTION_EVENT, pr - vam->pending_routes);
1047 vlib_process_signal_event
1048 (vm, vpe_resolver_process_node.index,
1049 RESOLUTION_PENDING_EVENT, 0 /* data */);
1051 /* The interface may be down, etc. */
1052 e = ip6_probe_neighbor
1053 (vm, (ip6_address_t *)&(mp->next_hop_address),
1054 ntohl(mp->next_hop_sw_if_index));
1057 clib_error_report(e);
1059 return VNET_API_ERROR_IN_PROGRESS;
1063 if (mp->is_multipath) {
1066 dslock (sm, 1 /* release hint */, 11 /* tag */);
1069 flags = IP6_ROUTE_FLAG_ADD;
1071 flags = IP6_ROUTE_FLAG_DEL;
1074 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1076 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1077 (u32) mp->dst_address_length,
1078 (ip6_address_t *)mp->next_hop_address,
1079 ntohl(mp->next_hop_sw_if_index),
1080 (u32) mp->next_hop_weight,
1087 memset (&a, 0, sizeof (a));
1088 memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1090 a.dst_address_length = mp->dst_address_length;
1092 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1093 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1094 a.table_index_or_table_id = fib_index;
1099 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1101 dslock (sm, 1 /* release hint */, 3 /* tag */);
1105 ai = lm->drop_adj_index;
1106 else if (mp->is_local)
1107 ai = lm->local_adj_index;
1109 ai = ip6_fib_lookup_with_table
1110 (im, fib_index, &next_hop_address);
1111 if (ai == lm->miss_adj_index) {
1113 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1117 nh_adj = ip_get_adjacency (lm, ai);
1118 vec_add1 (add_adj, nh_adj[0]);
1119 if (mp->lookup_in_vrf) {
1120 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1122 add_adj[0].explicit_fib_index = p[0];
1126 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1130 ip_adjacency_t * adj;
1132 ai = ip6_fib_lookup_with_table
1133 (im, fib_index, &a.dst_address);
1134 if (ai == lm->miss_adj_index) {
1136 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1138 adj = ip_get_adjacency (lm, ai);
1139 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1141 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1146 a.add_adj = add_adj;
1147 a.n_add_adj = vec_len(add_adj);
1148 ip6_add_del_route (im, &a);
1156 void vl_api_ip_add_del_route_t_handler (
1157 vl_api_ip_add_del_route_t *mp)
1159 vl_api_ip_add_del_route_reply_t * rmp;
1161 vnet_main_t * vnm = vnet_get_main();
1166 rv = ip6_add_del_route_t_handler (mp);
1168 rv = ip4_add_del_route_t_handler (mp);
1170 rv = (rv == 0) ? vnm->api_errno : rv;
1172 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1175 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1176 u32 sw_if_index, u8 *next_hop_addr)
1178 vl_api_ip_add_del_route_t mp;
1181 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1184 * Configure default IP route:
1185 * - ip route add 0.0.0.0/1 via <GW IP>
1186 * - ip route add 128.0.0.0/1 via <GW IP>
1188 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1190 mp.resolve_attempts = ~0;
1191 mp.resolve_if_needed = 1;
1193 mp.is_ipv6 = is_ipv6;
1194 mp.next_hop_weight = 1;
1196 memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1199 rv = ip6_add_del_route_t_handler (&mp);
1202 mp.dst_address_length = 1;
1204 mp.dst_address[0] = 0;
1205 rv = ip4_add_del_route_t_handler (&mp);
1207 mp.dst_address[0] = 128;
1208 rv |= ip4_add_del_route_t_handler (&mp);
1212 clib_error_return (0, "failed to config default IP route");
1217 vl_api_sw_interface_add_del_address_t_handler
1218 (vl_api_sw_interface_add_del_address_t *mp)
1220 vlib_main_t *vm = vlib_get_main();
1221 vl_api_sw_interface_add_del_address_reply_t * rmp;
1225 VALIDATE_SW_IF_INDEX(mp);
1227 is_del = mp->is_add == 0;
1230 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1231 else if (mp->is_ipv6)
1232 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1233 (void *)mp->address,
1234 mp->address_length, is_del);
1236 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1237 (void *) mp->address,
1238 mp->address_length, is_del);
1240 BAD_SW_IF_INDEX_LABEL;
1242 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1246 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1249 u32 table_id = ntohl(mp->vrf_id);
1250 u32 sw_if_index = ntohl(mp->sw_if_index);
1251 vl_api_sw_interface_set_table_reply_t * rmp;
1252 stats_main_t * sm = &stats_main;
1254 VALIDATE_SW_IF_INDEX(mp);
1256 dslock (sm, 1 /* release hint */, 4 /* tag */);
1259 ip6_main_t * im = &ip6_main;
1261 find_ip6_fib_by_table_index_or_id (im, table_id,
1262 IP6_ROUTE_FLAG_TABLE_ID);
1264 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1265 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1267 rv = VNET_API_ERROR_NO_SUCH_FIB;
1270 ip4_main_t * im = &ip4_main;
1271 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1272 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1274 /* Truthfully this can't fail */
1276 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1277 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1279 rv = VNET_API_ERROR_NO_SUCH_FIB;
1284 BAD_SW_IF_INDEX_LABEL;
1286 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1290 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1292 vlib_main_t *vm = vlib_get_main();
1293 vl_api_sw_interface_set_vpath_reply_t * rmp;
1296 u32 sw_if_index = ntohl(mp->sw_if_index);
1297 ip4_main_t *ip4m = &ip4_main;
1298 ip6_main_t *ip6m = &ip6_main;
1299 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1300 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1301 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1302 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1303 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1304 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1306 VALIDATE_SW_IF_INDEX(mp);
1308 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1310 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1311 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1312 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1313 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1314 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1315 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1316 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1317 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1318 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1319 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1320 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1321 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1322 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1323 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1324 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1325 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1327 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1328 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1329 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1330 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1331 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1332 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1333 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1334 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1335 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1336 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1337 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1338 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1339 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1340 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1341 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1342 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1345 BAD_SW_IF_INDEX_LABEL;
1347 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1351 vl_api_sw_interface_set_l2_xconnect_t_handler (
1352 vl_api_sw_interface_set_l2_xconnect_t *mp)
1354 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1356 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1357 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1358 vlib_main_t *vm = vlib_get_main();
1359 vnet_main_t *vnm = vnet_get_main();
1361 VALIDATE_RX_SW_IF_INDEX(mp);
1364 VALIDATE_TX_SW_IF_INDEX(mp);
1365 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1366 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1368 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1371 BAD_RX_SW_IF_INDEX_LABEL;
1372 BAD_TX_SW_IF_INDEX_LABEL;
1374 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1378 vl_api_sw_interface_set_l2_bridge_t_handler (
1379 vl_api_sw_interface_set_l2_bridge_t *mp)
1381 bd_main_t * bdm = &bd_main;
1382 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1384 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1385 u32 bd_id = ntohl(mp->bd_id);
1389 vlib_main_t *vm = vlib_get_main();
1390 vnet_main_t *vnm = vnet_get_main();
1392 VALIDATE_RX_SW_IF_INDEX(mp);
1394 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1397 //VALIDATE_TX_SW_IF_INDEX(mp);
1398 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1399 rx_sw_if_index, bd_index, bvi, shg, 0);
1401 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1404 BAD_RX_SW_IF_INDEX_LABEL;
1406 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1410 vl_api_bridge_domain_add_del_t_handler (
1411 vl_api_bridge_domain_add_del_t *mp)
1413 vlib_main_t * vm = vlib_get_main ();
1414 bd_main_t * bdm = &bd_main;
1415 vl_api_bridge_domain_add_del_reply_t * rmp;
1417 u32 enable_flags = 0, disable_flags = 0;
1418 u32 bd_id = ntohl(mp->bd_id);
1422 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1425 enable_flags |= L2_FLOOD;
1427 disable_flags |= L2_FLOOD;
1430 enable_flags |= L2_UU_FLOOD;
1432 disable_flags |= L2_UU_FLOOD;
1435 enable_flags |= L2_FWD;
1437 disable_flags |= L2_FWD;
1440 enable_flags |= L2_ARP_TERM;
1442 disable_flags |= L2_ARP_TERM;
1445 enable_flags |= L2_LEARN;
1447 disable_flags |= L2_LEARN;
1450 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1453 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1456 rv = bd_delete_bd_index(bdm, bd_id);
1458 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1461 static void vl_api_bridge_domain_details_t_handler (
1462 vl_api_bridge_domain_details_t * mp)
1464 clib_warning ("BUG");
1467 static void vl_api_bridge_domain_sw_if_details_t_handler (
1468 vl_api_bridge_domain_sw_if_details_t * mp)
1470 clib_warning ("BUG");
1473 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1474 l2_bridge_domain_t * bd_config,
1477 vl_api_bridge_domain_details_t * mp;
1479 mp = vl_msg_api_alloc (sizeof (*mp));
1480 memset (mp, 0, sizeof (*mp));
1481 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1482 mp->bd_id = ntohl (bd_config->bd_id);
1483 mp->flood = bd_feature_flood (bd_config);
1484 mp->uu_flood = bd_feature_uu_flood (bd_config);
1485 mp->forward = bd_feature_forward (bd_config);
1486 mp->learn = bd_feature_learn (bd_config);
1487 mp->arp_term = bd_feature_arp_term (bd_config);
1488 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1489 mp->n_sw_ifs = ntohl (n_sw_ifs);
1491 vl_msg_api_send_shmem (q, (u8 *)&mp);
1494 static void send_bd_sw_if_details (l2input_main_t * l2im,
1495 unix_shared_memory_queue_t *q,
1496 l2_flood_member_t * member, u32 bd_id)
1498 vl_api_bridge_domain_sw_if_details_t * mp;
1499 l2_input_config_t * input_cfg;
1501 mp = vl_msg_api_alloc (sizeof (*mp));
1502 memset (mp, 0, sizeof (*mp));
1503 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1504 mp->bd_id = ntohl (bd_id);
1505 mp->sw_if_index = ntohl (member->sw_if_index);
1506 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1507 mp->shg = input_cfg->shg;
1509 vl_msg_api_send_shmem (q, (u8 *)&mp);
1512 static void vl_api_bridge_domain_dump_t_handler (
1513 vl_api_bridge_domain_dump_t *mp)
1515 bd_main_t * bdm = &bd_main;
1516 l2input_main_t * l2im = &l2input_main;
1517 unix_shared_memory_queue_t * q;
1518 l2_bridge_domain_t * bd_config;
1519 u32 bd_id, bd_index;
1522 q = vl_api_client_index_to_input_queue (mp->client_index);
1527 bd_id = ntohl(mp->bd_id);
1529 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1530 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1531 for (; bd_index < end; bd_index++) {
1532 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1533 /* skip dummy bd_id 0 */
1534 if (bd_config && (bd_config->bd_id > 0)) {
1536 l2_flood_member_t * m;
1538 n_sw_ifs = vec_len (bd_config->members);
1539 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1541 vec_foreach (m, bd_config->members) {
1542 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1549 vl_api_l2fib_add_del_t_handler (
1550 vl_api_l2fib_add_del_t *mp)
1552 bd_main_t * bdm = &bd_main;
1553 l2input_main_t * l2im = &l2input_main;
1554 vl_api_l2fib_add_del_reply_t * rmp;
1557 u32 sw_if_index = ntohl(mp->sw_if_index);
1558 u32 bd_id = ntohl(mp->bd_id);
1566 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1568 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1569 goto bad_sw_if_index;
1574 VALIDATE_SW_IF_INDEX(mp);
1575 if (vec_len(l2im->configs) <= sw_if_index) {
1576 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1577 goto bad_sw_if_index;
1579 l2_input_config_t * config;
1580 config = vec_elt_at_index(l2im->configs, sw_if_index);
1581 if (config->bridge == 0) {
1582 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1583 goto bad_sw_if_index;
1586 static_mac = mp->static_mac ? 1 : 0;
1587 filter_mac = mp->filter_mac ? 1 : 0;
1588 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1591 l2fib_del_entry(mac, bd_index);
1594 BAD_SW_IF_INDEX_LABEL;
1596 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1600 vl_api_l2_flags_t_handler (
1601 vl_api_l2_flags_t *mp)
1603 vl_api_l2_flags_reply_t * rmp;
1605 u32 sw_if_index = ntohl(mp->sw_if_index);
1606 u32 flags = ntohl(mp->feature_bitmap);
1609 VALIDATE_SW_IF_INDEX(mp);
1612 if (flags & L2INPUT_FEAT_ ## a) \
1613 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1614 foreach_l2input_feat;
1617 BAD_SW_IF_INDEX_LABEL;
1619 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1623 vl_api_bridge_flags_t_handler (
1624 vl_api_bridge_flags_t *mp)
1626 vlib_main_t *vm = vlib_get_main();
1627 bd_main_t * bdm = &bd_main;
1628 vl_api_bridge_flags_reply_t * rmp;
1630 u32 bd_id = ntohl(mp->bd_id);
1632 u32 flags = ntohl(mp->feature_bitmap);
1635 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1637 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1643 bd_set_flags(vm, bd_index, flags, mp->is_set);
1646 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1647 rmp->resulting_feature_bitmap = ntohl(flags));
1651 vl_api_bd_ip_mac_add_del_t_handler (
1652 vl_api_bd_ip_mac_add_del_t *mp)
1654 bd_main_t * bdm = &bd_main;
1655 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1657 u32 bd_id = ntohl(mp->bd_id);
1661 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1663 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1668 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1669 mp->mac_address, mp->is_ipv6, mp->is_add))
1670 rv = VNET_API_ERROR_UNSPECIFIED;
1673 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1677 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1680 vl_api_tap_connect_reply_t * rmp;
1681 unix_shared_memory_queue_t * q;
1682 u32 sw_if_index = (u32)~0;
1684 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1685 mp->use_random_mac ? 0 : mp->mac_address,
1686 &sw_if_index, mp->renumber,
1687 ntohl(mp->custom_dev_instance));
1689 q = vl_api_client_index_to_input_queue (mp->client_index);
1693 rmp = vl_msg_api_alloc (sizeof (*rmp));
1694 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1695 rmp->context = mp->context;
1696 rmp->retval = ntohl(rv);
1697 rmp->sw_if_index = ntohl(sw_if_index);
1699 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1703 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1706 vl_api_tap_modify_reply_t * rmp;
1707 unix_shared_memory_queue_t * q;
1708 u32 sw_if_index = (u32)~0;
1710 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1711 mp->use_random_mac ? 0 : mp->mac_address,
1712 &sw_if_index, mp->renumber,
1713 ntohl(mp->custom_dev_instance));
1715 q = vl_api_client_index_to_input_queue (mp->client_index);
1719 rmp = vl_msg_api_alloc (sizeof (*rmp));
1720 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1721 rmp->context = mp->context;
1722 rmp->retval = ntohl(rv);
1723 rmp->sw_if_index = ntohl(sw_if_index);
1725 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1729 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1732 vpe_api_main_t * vam = &vpe_api_main;
1733 vl_api_tap_delete_reply_t * rmp;
1734 unix_shared_memory_queue_t * q;
1735 u32 sw_if_index = ntohl(mp->sw_if_index);
1737 rv = vnet_tap_delete (vm, sw_if_index);
1739 q = vl_api_client_index_to_input_queue (mp->client_index);
1743 rmp = vl_msg_api_alloc (sizeof (*rmp));
1744 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1745 rmp->context = mp->context;
1746 rmp->retval = ntohl(rv);
1748 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1751 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1755 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1757 vl_api_create_vlan_subif_reply_t * rmp;
1758 vnet_main_t * vnm = vnet_get_main();
1759 u32 hw_if_index, sw_if_index = (u32)~0;
1760 vnet_hw_interface_t * hi;
1763 vnet_sw_interface_t template;
1765 vnet_interface_main_t * im = &vnm->interface_main;
1766 u64 sup_and_sub_key;
1768 unix_shared_memory_queue_t * q;
1769 clib_error_t * error;
1771 VALIDATE_SW_IF_INDEX(mp);
1773 hw_if_index = ntohl(mp->sw_if_index);
1774 hi = vnet_get_hw_interface (vnm, hw_if_index);
1776 id = ntohl(mp->vlan_id);
1777 if (id == 0 || id > 4095) {
1778 rv = VNET_API_ERROR_INVALID_VLAN;
1782 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1784 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1786 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1790 kp = clib_mem_alloc (sizeof (*kp));
1791 *kp = sup_and_sub_key;
1793 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1794 template.sup_sw_if_index = hi->sw_if_index;
1795 template.sub.id = id;
1796 template.sub.eth.raw_flags = 0;
1797 template.sub.eth.flags.one_tag = 1;
1798 template.sub.eth.outer_vlan_id = id;
1799 template.sub.eth.flags.exact_match = 1;
1801 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1803 clib_error_report(error);
1804 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1807 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1808 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1810 BAD_SW_IF_INDEX_LABEL;
1813 q = vl_api_client_index_to_input_queue (mp->client_index);
1817 rmp = vl_msg_api_alloc (sizeof (*rmp));
1818 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1819 rmp->context = mp->context;
1820 rmp->retval = ntohl(rv);
1821 rmp->sw_if_index = ntohl(sw_if_index);
1822 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1826 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1828 vl_api_create_subif_reply_t * rmp;
1829 vnet_main_t * vnm = vnet_get_main();
1830 u32 sw_if_index = ~0;
1833 vnet_sw_interface_t *si;
1834 vnet_hw_interface_t *hi;
1835 vnet_sw_interface_t template;
1837 vnet_interface_main_t * im = &vnm->interface_main;
1838 u64 sup_and_sub_key;
1840 clib_error_t * error;
1842 VALIDATE_SW_IF_INDEX(mp);
1844 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1845 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1847 sw_if_index = si->sw_if_index;
1848 sub_id = ntohl(mp->sub_id);
1850 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1852 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1855 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1856 sw_if_index, sub_id);
1857 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1861 kp = clib_mem_alloc (sizeof (*kp));
1862 *kp = sup_and_sub_key;
1864 memset (&template, 0, sizeof (template));
1865 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1866 template.sup_sw_if_index = sw_if_index;
1867 template.sub.id = sub_id;
1868 template.sub.eth.flags.no_tags = mp->no_tags;
1869 template.sub.eth.flags.one_tag = mp->one_tag;
1870 template.sub.eth.flags.two_tags = mp->two_tags;
1871 template.sub.eth.flags.dot1ad = mp->dot1ad;
1872 template.sub.eth.flags.exact_match = mp->exact_match;
1873 template.sub.eth.flags.default_sub = mp->default_sub;
1874 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1875 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1876 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1877 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1879 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1881 clib_error_report (error);
1882 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1886 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1887 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1889 BAD_SW_IF_INDEX_LABEL;
1893 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1895 rmp->sw_if_index = ntohl(sw_if_index);
1900 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1902 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1904 stats_main_t * sm = &stats_main;
1905 u32 tunnel_sw_if_index = ~0;
1907 dslock (sm, 1 /* release hint */, 5 /* tag */);
1909 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1910 (ip4_address_t *)(mp->dst_address),
1911 (ip4_address_t *)(mp->intfc_address),
1912 (u32)(mp->intfc_address_length),
1913 ntohl(mp->inner_vrf_id),
1914 ntohl(mp->outer_vrf_id),
1915 &tunnel_sw_if_index,
1920 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1922 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1927 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1928 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1930 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1932 stats_main_t * sm = &stats_main;
1933 u32 tunnel_sw_if_index;
1935 dslock (sm, 1 /* release hint */, 5 /* tag */);
1937 rv = vnet_mpls_ethernet_add_del_tunnel
1938 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1939 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1940 ntohl(mp->tx_sw_if_index),
1941 &tunnel_sw_if_index,
1947 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1949 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1954 * This piece of misery brought to you because the control-plane
1955 * can't figure out the tx interface + dst-mac address all by itself
1957 static int mpls_ethernet_add_del_tunnel_2_t_handler
1958 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1960 pending_route_t * pr;
1961 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1962 vnet_main_t * vnm = vnet_get_main();
1963 vlib_main_t * vm = vlib_get_main();
1964 stats_main_t * sm = &stats_main;
1965 vpe_api_main_t * vam = &vpe_api_main;
1966 u32 inner_fib_index, outer_fib_index;
1967 ip4_main_t * im = &ip4_main;
1968 ip_lookup_main_t * lm = &im->lookup_main;
1969 ip_adjacency_t * adj = 0;
1972 u8 * dst_mac_address;
1976 u32 tunnel_sw_if_index;
1978 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
1980 return VNET_API_ERROR_NO_SUCH_FIB;
1982 outer_fib_index = p[0];
1985 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
1987 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1989 inner_fib_index = p[0];
1991 if (inner_fib_index == outer_fib_index)
1992 return VNET_API_ERROR_INVALID_VALUE;
1994 lookup_result = ip4_fib_lookup_with_table
1995 (im, outer_fib_index,
1996 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
1997 1 /* disable default route */);
1999 adj = ip_get_adjacency (lm, lookup_result);
2000 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2002 if (mp->is_add && mp->resolve_if_needed) {
2003 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2004 pool_get (vam->pending_routes, pr);
2005 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2007 memcpy (pme, mp, sizeof (*pme));
2008 /* recursion block, "just in case" */
2009 pme->resolve_if_needed = 0;
2010 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2011 pme->resolve_opaque = tx_sw_if_index;
2012 vnet_register_ip4_arp_resolution_event
2014 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2015 vpe_resolver_process_node.index,
2016 RESOLUTION_EVENT, pr - vam->pending_routes);
2018 vlib_process_signal_event
2019 (vm, vpe_resolver_process_node.index,
2020 RESOLUTION_PENDING_EVENT, 0 /* data */);
2022 /* The interface may be down, etc. */
2023 e = ip4_probe_neighbor
2024 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2028 clib_error_report(e);
2030 return VNET_API_ERROR_IN_PROGRESS;
2034 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2035 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2038 vnet_rewrite_get_data_internal
2039 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2041 dslock (sm, 1 /* release hint */, 10 /* tag */);
2043 rv = vnet_mpls_ethernet_add_del_tunnel
2044 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2045 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2046 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2054 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2055 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2057 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2060 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2062 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2067 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2069 vl_api_mpls_add_del_encap_reply_t * rmp;
2071 static u32 * labels;
2074 vec_reset_length (labels);
2076 for (i = 0; i < mp->nlabels; i++)
2077 vec_add1 (labels, ntohl(mp->labels[i]));
2080 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2081 ntohl(mp->vrf_id), labels,
2082 ~0 /* policy_tunnel_index */,
2083 0 /* no_dst_hash */,
2087 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2091 vl_api_mpls_add_del_decap_t_handler
2092 (vl_api_mpls_add_del_decap_t *mp)
2094 vl_api_mpls_add_del_decap_reply_t * rmp;
2097 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2098 ntohl(mp->label), ntohl(mp->next_index),
2099 mp->s_bit, mp->is_add);
2101 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2105 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2107 vl_api_proxy_arp_add_del_reply_t * rmp;
2110 ip4_main_t * im = &ip4_main;
2111 stats_main_t * sm = &stats_main;
2112 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2113 ip4_address_t *hi_addr,
2114 u32 fib_index, int is_del);
2117 dslock (sm, 1 /* release hint */, 6 /* tag */);
2119 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2122 rv = VNET_API_ERROR_NO_SUCH_FIB;
2128 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2129 (ip4_address_t *)mp->hi_address,
2130 fib_index, mp->is_add == 0);
2134 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2138 vl_api_proxy_arp_intfc_enable_disable_t_handler
2139 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2142 vnet_main_t * vnm = vnet_get_main();
2143 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2144 vnet_sw_interface_t * si;
2147 VALIDATE_SW_IF_INDEX(mp);
2149 sw_if_index = ntohl(mp->sw_if_index);
2151 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2153 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2157 si = vnet_get_sw_interface (vnm, sw_if_index);
2161 if (mp->enable_disable)
2162 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2164 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2166 BAD_SW_IF_INDEX_LABEL;
2169 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2173 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2175 vl_api_ip_neighbor_add_del_reply_t * rmp;
2176 vnet_main_t * vnm = vnet_get_main();
2179 stats_main_t * sm = &stats_main;
2181 VALIDATE_SW_IF_INDEX(mp);
2183 dslock (sm, 1 /* release hint */, 7 /* tag */);
2187 rv = vnet_set_ip6_ethernet_neighbor
2188 (vm, ntohl(mp->sw_if_index),
2189 (ip6_address_t *)(mp->dst_address),
2190 mp->mac_address, sizeof (mp->mac_address));
2192 rv = vnet_unset_ip6_ethernet_neighbor
2193 (vm, ntohl(mp->sw_if_index),
2194 (ip6_address_t *)(mp->dst_address),
2195 mp->mac_address, sizeof(mp->mac_address));
2197 ip4_main_t * im = &ip4_main;
2198 ip_lookup_main_t * lm = &im->lookup_main;
2199 ethernet_arp_ip4_over_ethernet_address_t a;
2201 ip_adjacency_t *nh_adj;
2203 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2205 rv = VNET_API_ERROR_NO_SUCH_FIB;
2211 * Unfortunately, folks have a penchant for
2212 * adding interface addresses to the ARP cache, and
2213 * wondering why the forwarder eventually ASSERTs...
2215 ai = ip4_fib_lookup_with_table
2216 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2217 1 /* disable default route */);
2220 nh_adj = ip_get_adjacency (lm, ai);
2221 /* Never allow manipulation of a local adj! */
2222 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2223 clib_warning("%U matches local adj",
2225 (ip4_address_t *)(mp->dst_address));
2226 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2231 memcpy (&a.ethernet, mp->mac_address, 6);
2232 memcpy (&a.ip4, mp->dst_address, 4);
2235 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2236 fib_index, &a, mp->is_static);
2238 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2242 BAD_SW_IF_INDEX_LABEL;
2245 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2249 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2252 vpe_main_t *rm = &vpe_main;
2253 ip4_main_t *im4 = &ip4_main;
2254 ip6_main_t *im6 = &ip6_main;
2255 ip_lookup_main_t * lm;
2260 u32 adj_index, sw_if_index;
2261 vl_api_is_address_reachable_t *rmp;
2262 ip_adjacency_t * adj;
2263 unix_shared_memory_queue_t *q;
2265 q = vl_api_client_index_to_input_queue (mp->client_index);
2267 increment_missing_api_client_counter (rm->vlib_main);
2271 rmp = vl_msg_api_alloc (sizeof (*rmp));
2272 memcpy (rmp, mp, sizeof (*rmp));
2274 sw_if_index = mp->next_hop_sw_if_index;
2275 memcpy (&addr, mp->address, sizeof (addr));
2277 lm = &im6->lookup_main;
2279 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2281 lm = &im4->lookup_main;
2283 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2285 if (adj_index == ~0) {
2289 adj = ip_get_adjacency (lm, adj_index);
2291 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2292 && adj->rewrite_header.sw_if_index == sw_if_index) {
2295 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2296 && adj->rewrite_header.sw_if_index == sw_if_index) {
2298 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2300 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2301 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2309 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2313 static void vl_api_sw_interface_details_t_handler (
2314 vl_api_sw_interface_details_t * mp)
2316 clib_warning ("BUG");
2319 static void vl_api_sw_interface_set_flags_t_handler (
2320 vl_api_sw_interface_set_flags_t * mp)
2322 vl_api_sw_interface_set_flags_reply_t *rmp;
2323 vnet_main_t * vnm = vnet_get_main();
2325 clib_error_t * error;
2328 VALIDATE_SW_IF_INDEX(mp);
2330 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2332 error = vnet_sw_interface_set_flags (vnm,
2333 ntohl(mp->sw_if_index),
2337 clib_error_report (error);
2340 BAD_SW_IF_INDEX_LABEL;
2341 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2344 static void send_sw_interface_details (vpe_api_main_t * am,
2345 unix_shared_memory_queue_t *q,
2346 vnet_sw_interface_t * swif,
2347 u8 * interface_name)
2349 vl_api_sw_interface_details_t * mp;
2350 vnet_hw_interface_t * hi;
2352 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2354 mp = vl_msg_api_alloc (sizeof (*mp));
2355 memset (mp, 0, sizeof (*mp));
2356 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2357 mp->sw_if_index = ntohl(swif->sw_if_index);
2358 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2359 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2361 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2363 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2364 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2365 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2366 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2368 strncpy ((char *) mp->interface_name,
2369 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2371 /* Send the L2 address for ethernet physical intfcs */
2372 if (swif->sup_sw_if_index == swif->sw_if_index
2373 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2374 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2375 ethernet_interface_t *ei;
2377 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2378 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2379 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2380 mp->l2_address_length = ntohl(sizeof (ei->address));
2381 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2382 vnet_sub_interface_t *sub = &swif->sub;
2383 mp->sub_id = ntohl(sub->id);
2384 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2385 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2386 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2387 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2388 mp->sub_exact_match = sub->eth.flags.exact_match;
2389 mp->sub_default = sub->eth.flags.default_sub;
2390 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2391 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2393 /* vlan tag rewrite data */
2394 u32 vtr_op = L2_VTR_DISABLED;
2395 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2397 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2398 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2399 // error - default to disabled
2400 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2401 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2404 mp->vtr_op = ntohl(vtr_op);
2405 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2406 mp->vtr_tag1 = ntohl(vtr_tag1);
2407 mp->vtr_tag2 = ntohl(vtr_tag2);
2411 vl_msg_api_send_shmem (q, (u8 *)&mp);
2414 static void send_sw_interface_flags (vpe_api_main_t * am,
2415 unix_shared_memory_queue_t *q,
2416 vnet_sw_interface_t * swif)
2418 vl_api_sw_interface_set_flags_t *mp;
2419 vnet_main_t * vnm = am->vnet_main;
2421 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2423 mp = vl_msg_api_alloc (sizeof (*mp));
2424 memset (mp, 0, sizeof (*mp));
2425 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2426 mp->sw_if_index = ntohl(swif->sw_if_index);
2428 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2430 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2432 vl_msg_api_send_shmem (q, (u8 *)&mp);
2435 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2436 unix_shared_memory_queue_t *q,
2438 __attribute__((unused));
2440 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2441 unix_shared_memory_queue_t *q,
2444 vl_api_sw_interface_set_flags_t *mp;
2446 mp = vl_msg_api_alloc (sizeof (*mp));
2447 memset (mp, 0, sizeof (*mp));
2448 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2449 mp->sw_if_index = ntohl(sw_if_index);
2451 mp->admin_up_down = 0;
2452 mp->link_up_down = 0;
2454 vl_msg_api_send_shmem (q, (u8 *)&mp);
2457 static void vl_api_sw_interface_dump_t_handler (
2458 vl_api_sw_interface_dump_t *mp)
2460 vpe_api_main_t * am = &vpe_api_main;
2461 vnet_sw_interface_t * swif;
2462 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2463 u8 * filter_string = 0, * name_string = 0;
2464 unix_shared_memory_queue_t * q;
2465 char * strcasestr (char *, char *); /* lnx hdr file botch */
2467 q = vl_api_client_index_to_input_queue (mp->client_index);
2472 if (mp->name_filter_valid) {
2473 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2474 filter_string = format (0, "%s%c", mp->name_filter, 0);
2477 pool_foreach (swif, im->sw_interfaces,
2479 name_string = format (name_string, "%U%c",
2480 format_vnet_sw_interface_name,
2481 am->vnet_main, swif, 0);
2483 if (mp->name_filter_valid == 0 ||
2484 strcasestr((char *) name_string, (char *) filter_string)) {
2486 send_sw_interface_details (am, q, swif, name_string);
2487 send_sw_interface_flags (am, q, swif);
2489 _vec_len (name_string) = 0;
2492 vec_free (name_string);
2493 vec_free (filter_string);
2496 void send_oam_event (oam_target_t * t)
2498 vpe_api_main_t * vam = &vpe_api_main;
2499 unix_shared_memory_queue_t * q;
2500 vpe_client_registration_t *reg;
2501 vl_api_oam_event_t * mp;
2503 pool_foreach(reg, vam->oam_events_registrations,
2505 q = vl_api_client_index_to_input_queue (reg->client_index);
2507 mp = vl_msg_api_alloc (sizeof (*mp));
2508 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2509 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2510 mp->state = t->state;
2511 vl_msg_api_send_shmem (q, (u8 *)&mp);
2517 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2519 vl_api_oam_add_del_reply_t * rmp;
2522 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2523 (ip4_address_t *)mp->dst_address,
2527 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2531 vl_api_vnet_get_summary_stats_t_handler (
2532 vl_api_vnet_get_summary_stats_t *mp)
2534 stats_main_t * sm = &stats_main;
2535 vnet_interface_main_t * im = sm->interface_main;
2536 vl_api_vnet_summary_stats_reply_t *rmp;
2537 vlib_combined_counter_main_t * cm;
2540 u64 total_pkts[VLIB_N_RX_TX];
2541 u64 total_bytes[VLIB_N_RX_TX];
2543 unix_shared_memory_queue_t * q =
2544 vl_api_client_index_to_input_queue (mp->client_index);
2549 rmp = vl_msg_api_alloc (sizeof (*rmp));
2550 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2551 rmp->context = mp->context;
2554 memset (total_pkts, 0, sizeof (total_pkts));
2555 memset (total_bytes, 0, sizeof (total_bytes));
2557 vnet_interface_counter_lock (im);
2559 vec_foreach (cm, im->combined_sw_if_counters) {
2560 which = cm - im->combined_sw_if_counters;
2562 for (i = 0; i < vec_len (cm->maxi); i++) {
2563 vlib_get_combined_counter (cm, i, &v);
2564 total_pkts[which] += v.packets;
2565 total_bytes[which] += v.bytes;
2568 vnet_interface_counter_unlock (im);
2570 /* Note: in HOST byte order! */
2571 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2572 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2573 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2574 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2575 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2577 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2580 typedef CLIB_PACKED (struct {
2581 ip4_address_t address;
2583 u32 address_length : 6;
2588 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2590 vnet_main_t * vnm = vnet_get_main();
2591 vnet_interface_main_t * im = &vnm->interface_main;
2592 ip4_main_t * im4 = &ip4_main;
2593 static ip4_route_t * routes;
2594 static u32 * sw_if_indices_to_shut;
2595 stats_main_t * sm = &stats_main;
2600 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2601 u32 target_fib_id = ntohl(mp->vrf_id);
2603 dslock (sm, 1 /* release hint */, 8 /* tag */);
2605 vec_foreach (fib, im4->fibs) {
2606 vnet_sw_interface_t * si;
2608 if (fib->table_id != target_fib_id)
2611 /* remove any mpls/gre tunnels in this fib */
2612 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2614 /* remove any mpls encap/decap labels */
2615 mpls_fib_reset_labels (fib->table_id);
2617 /* remove any proxy arps in this fib */
2618 vnet_proxy_arp_fib_reset (fib->table_id);
2620 /* Set the flow hash for this fib to the default */
2621 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2623 vec_reset_length (sw_if_indices_to_shut);
2625 /* Shut down interfaces in this FIB / clean out intfc routes */
2626 pool_foreach (si, im->sw_interfaces,
2628 u32 sw_if_index = si->sw_if_index;
2630 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2631 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2633 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2636 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2637 sw_if_index = sw_if_indices_to_shut[i];
2638 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2640 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2641 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2642 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2645 vec_reset_length (routes);
2647 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2648 uword * hash = fib->adj_index_by_dst_address[i];
2652 x.address_length = i;
2654 hash_foreach_pair (p, hash,
2656 x.address.data_u32 = p->key;
2657 vec_add1 (routes, x);
2661 vec_foreach (r, routes) {
2662 ip4_add_del_route_args_t a;
2664 memset (&a, 0, sizeof (a));
2665 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2666 a.table_index_or_table_id = fib - im4->fibs;
2667 a.dst_address = r->address;
2668 a.dst_address_length = r->address_length;
2671 ip4_add_del_route (im4, &a);
2672 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2673 IP4_ROUTE_FLAG_FIB_INDEX);
2677 } /* vec_foreach (fib) */
2684 ip6_address_t address;
2691 ip6_route_t ** routep;
2692 } add_routes_in_fib_arg_t;
2694 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2696 add_routes_in_fib_arg_t * ap = arg;
2698 if (kvp->key[2]>>32 == ap->fib_index)
2700 ip6_address_t *addr;
2702 addr = (ip6_address_t *) kvp;
2703 vec_add2 (*ap->routep, r, 1);
2704 r->address = addr[0];
2705 r->address_length = kvp->key[2] & 0xFF;
2706 r->index = kvp->value;
2710 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2712 vnet_main_t * vnm = vnet_get_main();
2713 vnet_interface_main_t * im = &vnm->interface_main;
2714 ip6_main_t * im6 = &ip6_main;
2715 stats_main_t * sm = &stats_main;
2716 static ip6_route_t * routes;
2717 static u32 * sw_if_indices_to_shut;
2722 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2723 u32 target_fib_id = ntohl(mp->vrf_id);
2724 add_routes_in_fib_arg_t _a, *a=&_a;
2725 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2727 dslock (sm, 1 /* release hint */, 9 /* tag */);
2729 vec_foreach (fib, im6->fibs) {
2730 vnet_sw_interface_t * si;
2732 if (fib->table_id != target_fib_id)
2735 vec_reset_length (sw_if_indices_to_shut);
2737 /* Shut down interfaces in this FIB / clean out intfc routes */
2738 pool_foreach (si, im->sw_interfaces,
2740 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2742 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2745 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2746 sw_if_index = sw_if_indices_to_shut[i];
2747 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2749 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2750 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2751 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2754 vec_reset_length (routes);
2756 a->fib_index = fib - im6->fibs;
2757 a->routep = &routes;
2759 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2761 vec_foreach (r, routes) {
2762 ip6_add_del_route_args_t a;
2764 memset (&a, 0, sizeof (a));
2765 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2766 a.table_index_or_table_id = fib - im6->fibs;
2767 a.dst_address = r->address;
2768 a.dst_address_length = r->address_length;
2771 ip6_add_del_route (im6, &a);
2772 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2773 IP6_ROUTE_FLAG_FIB_INDEX);
2776 /* Reinstall the neighbor / router discovery routes */
2777 vnet_ip6_fib_init (im6, fib - im6->fibs);
2779 } /* vec_foreach (fib) */
2785 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2788 vl_api_reset_fib_reply_t * rmp;
2791 rv = ip6_reset_fib_t_handler (mp);
2793 rv = ip4_reset_fib_t_handler (mp);
2795 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2800 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2802 vl_api_dhcp_proxy_config_reply_t * rmp;
2805 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2806 (ip4_address_t *)(&mp->dhcp_src_address),
2807 (u32) ntohl(mp->vrf_id),
2808 (int) mp->insert_circuit_id,
2809 (int) (mp->is_add == 0));
2811 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2816 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2818 vl_api_dhcp_proxy_config_reply_t * rmp;
2821 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2822 (ip6_address_t *)(&mp->dhcp_src_address),
2823 (u32) ntohl(mp->vrf_id),
2824 (int) mp->insert_circuit_id,
2825 (int) (mp->is_add == 0));
2827 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2831 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2833 vl_api_dhcp_proxy_config_reply_t * rmp;
2836 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2837 (ip4_address_t *)(&mp->dhcp_src_address),
2838 (u32) ntohl(mp->rx_vrf_id),
2839 (u32) ntohl(mp->server_vrf_id),
2840 (int) mp->insert_circuit_id,
2841 (int) (mp->is_add == 0));
2843 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2848 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2850 vl_api_dhcp_proxy_config_reply_t * rmp;
2854 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2855 (ip6_address_t *)(&mp->dhcp_src_address),
2856 (u32) ntohl(mp->rx_vrf_id),
2857 (u32) ntohl(mp->server_vrf_id),
2858 (int) mp->insert_circuit_id,
2859 (int) (mp->is_add == 0));
2861 rv = VNET_API_ERROR_UNIMPLEMENTED;
2864 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2869 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2871 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2874 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2877 (int)mp->is_add == 0);
2879 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2882 (int)mp->is_add == 0);
2884 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2888 static void vl_api_dhcp_proxy_config_t_handler
2889 (vl_api_dhcp_proxy_config_t *mp)
2891 if (mp->is_ipv6 == 0)
2892 dhcpv4_proxy_config (mp);
2894 dhcpv6_proxy_config (mp);
2897 static void vl_api_dhcp_proxy_config_2_t_handler
2898 (vl_api_dhcp_proxy_config_2_t *mp)
2900 if (mp->is_ipv6 == 0)
2901 dhcpv4_proxy_config_2 (mp);
2903 dhcpv6_proxy_config_2 (mp);
2906 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2907 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2909 unix_shared_memory_queue_t * q;
2910 vl_api_dhcp_compl_event_t * mp;
2912 q = vl_api_client_index_to_input_queue (client_index);
2916 mp = vl_msg_api_alloc (sizeof (*mp));
2917 mp->client_index = client_index;
2919 mp->is_ipv6 = is_ipv6;
2920 memcpy (&mp->hostname, hostname, vec_len(hostname));
2921 mp->hostname[vec_len(hostname) + 1] = '\n';
2922 memcpy (&mp->host_address[0], host_address, 16);
2923 memcpy (&mp->router_address[0], router_address, 16);
2924 memcpy (&mp->host_mac[0], host_mac, 6);
2926 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2928 vl_msg_api_send_shmem (q, (u8 *)&mp);
2931 static void vl_api_dhcp_client_config_t_handler
2932 (vl_api_dhcp_client_config_t *mp)
2934 vlib_main_t *vm = vlib_get_main();
2935 vl_api_dhcp_client_config_reply_t * rmp;
2938 VALIDATE_SW_IF_INDEX(mp);
2940 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
2941 mp->hostname, mp->is_add, mp->client_index,
2942 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
2945 BAD_SW_IF_INDEX_LABEL;
2947 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
2951 vl_api_sw_interface_ip6nd_ra_config_t_handler
2952 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
2954 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
2956 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
2958 is_no = mp->is_no == 1;
2959 surpress = mp->surpress == 1;
2960 managed = mp->managed == 1;
2961 other = mp->other == 1;
2962 ll_option = mp->ll_option == 1;
2963 send_unicast = mp->send_unicast == 1;
2964 cease = mp->cease == 1;
2965 default_router = mp->default_router == 1;
2967 VALIDATE_SW_IF_INDEX(mp);
2969 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
2970 surpress, managed, other,
2971 ll_option, send_unicast, cease,
2972 default_router, ntohl (mp->lifetime),
2973 ntohl(mp->initial_count), ntohl(mp->initial_interval),
2974 ntohl(mp->max_interval), ntohl( mp->min_interval),
2977 BAD_SW_IF_INDEX_LABEL;
2979 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2983 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2984 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
2986 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
2988 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
2990 VALIDATE_SW_IF_INDEX(mp);
2992 is_no = mp->is_no == 1;
2993 use_default = mp->use_default == 1;
2994 no_advertise = mp->no_advertise == 1;
2995 off_link = mp->off_link == 1;
2996 no_autoconfig = mp->no_autoconfig == 1;
2997 no_onlink = mp->no_onlink == 1;
2999 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3000 (ip6_address_t *)mp->address, mp->address_length,
3001 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3002 no_advertise, off_link, no_autoconfig, no_onlink,
3005 BAD_SW_IF_INDEX_LABEL;
3006 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3010 vl_api_sw_interface_ip6_enable_disable_t_handler
3011 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3013 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3014 vnet_main_t * vnm = vnet_get_main();
3016 clib_error_t * error;
3020 VALIDATE_SW_IF_INDEX(mp);
3022 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3023 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3026 clib_error_report(error);
3027 rv = VNET_API_ERROR_UNSPECIFIED;
3029 rv = vnm->api_errno;
3032 BAD_SW_IF_INDEX_LABEL;
3034 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3038 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3039 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3041 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3043 clib_error_t * error;
3044 vnet_main_t * vnm = vnet_get_main();
3048 VALIDATE_SW_IF_INDEX(mp);
3050 error = set_ip6_link_local_address(vm,
3051 ntohl(mp->sw_if_index),
3052 (ip6_address_t *)mp->address,
3053 mp->address_length);
3055 clib_error_report(error);
3056 rv = VNET_API_ERROR_UNSPECIFIED;
3058 rv = vnm->api_errno;
3061 BAD_SW_IF_INDEX_LABEL;
3063 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3066 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3068 vl_api_set_ip_flow_hash_reply_t *rmp;
3069 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3071 clib_warning ("unimplemented...");
3073 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3076 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3078 vl_api_set_ip_flow_hash_reply_t *rmp;
3081 u32 flow_hash_config = 0;
3083 table_id = ntohl(mp->vrf_id);
3085 #define _(a,b) if (mp->a) flow_hash_config |= b;
3086 foreach_flow_hash_bit;
3089 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3091 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3095 static void vl_api_set_ip_flow_hash_t_handler
3096 (vl_api_set_ip_flow_hash_t *mp)
3098 if (mp->is_ipv6 == 0)
3099 set_ip4_flow_hash (mp);
3101 set_ip6_flow_hash (mp);
3104 static void vl_api_sw_interface_set_unnumbered_t_handler
3105 (vl_api_sw_interface_set_unnumbered_t *mp)
3107 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3109 vnet_sw_interface_t * si;
3110 vnet_main_t *vnm = vnet_get_main();
3111 u32 sw_if_index, unnumbered_sw_if_index;
3113 sw_if_index = ntohl(mp->sw_if_index);
3114 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3117 * The API message field names are backwards from
3118 * the underlying data structure names.
3119 * It's not worth changing them now.
3121 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3122 unnumbered_sw_if_index)) {
3123 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3127 /* Only check the "use loop0" field when setting the binding */
3129 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3130 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3134 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3137 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3138 si->unnumbered_sw_if_index = sw_if_index;
3140 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3141 si->unnumbered_sw_if_index = (u32)~0;
3145 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3148 static void vl_api_create_loopback_t_handler
3149 (vl_api_create_loopback_t *mp)
3151 vl_api_create_loopback_reply_t * rmp;
3155 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3157 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3159 rmp->sw_if_index = ntohl (sw_if_index);
3163 static void vl_api_delete_loopback_t_handler
3164 (vl_api_delete_loopback_t *mp)
3166 vl_api_delete_loopback_reply_t * rmp;
3170 sw_if_index = ntohl (mp->sw_if_index);
3171 rv = vnet_delete_loopback_interface (sw_if_index);
3173 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3176 static void vl_api_control_ping_t_handler
3177 (vl_api_control_ping_t *mp)
3179 vl_api_control_ping_reply_t * rmp;
3182 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3184 rmp->vpe_pid = ntohl (getpid());
3188 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3190 u8 **shmem_vecp = (u8 **)arg;
3193 api_main_t * am = &api_main;
3196 shmem_vec = *shmem_vecp;
3198 offset = vec_len (shmem_vec);
3200 pthread_mutex_lock (&am->vlib_rp->mutex);
3201 oldheap = svm_push_data_heap (am->vlib_rp);
3203 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3205 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3207 svm_pop_heap (oldheap);
3208 pthread_mutex_unlock (&am->vlib_rp->mutex);
3210 *shmem_vecp = shmem_vec;
3214 static void vl_api_cli_request_t_handler
3215 (vl_api_cli_request_t *mp)
3217 vl_api_cli_reply_t *rp;
3218 unix_shared_memory_queue_t *q;
3219 vlib_main_t * vm = vlib_get_main();
3220 api_main_t * am = &api_main;
3221 unformat_input_t input;
3225 q = vl_api_client_index_to_input_queue (mp->client_index);
3229 rp = vl_msg_api_alloc (sizeof (*rp));
3230 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3231 rp->context = mp->context;
3233 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3235 vlib_cli_input (vm, &input, shmem_cli_output,
3238 pthread_mutex_lock (&am->vlib_rp->mutex);
3239 oldheap = svm_push_data_heap (am->vlib_rp);
3241 vec_add1(shmem_vec, 0);
3243 svm_pop_heap (oldheap);
3244 pthread_mutex_unlock (&am->vlib_rp->mutex);
3246 rp->reply_in_shmem = (uword)shmem_vec;
3248 vl_msg_api_send_shmem (q, (u8 *)&rp);
3251 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3254 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3255 vnet_main_t *vnm = vnet_get_main();
3256 clib_error_t * error;
3261 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3263 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3266 clib_error_report(error);
3267 rv = VNET_API_ERROR_UNSPECIFIED;
3269 rv = vnm->api_errno;
3272 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3275 static void vl_api_sr_tunnel_add_del_t_handler
3276 (vl_api_sr_tunnel_add_del_t *mp)
3278 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3280 vl_api_sr_tunnel_add_del_reply_t * rmp;
3281 ip6_address_t * segments = 0, * seg;
3282 ip6_address_t * tags = 0, *tag;
3283 ip6_address_t * this_address;
3286 if (mp->n_segments == 0) {
3291 memset (a, 0, sizeof (*a));
3292 a->src_address = (ip6_address_t *)&mp->src_address;
3293 a->dst_address = (ip6_address_t *)&mp->dst_address;
3294 a->dst_mask_width = mp->dst_mask_width;
3295 a->flags_net_byte_order = mp->flags_net_byte_order;
3296 a->is_del = (mp->is_add == 0);
3297 a->rx_table_id = ntohl(mp->outer_vrf_id);
3298 a->tx_table_id = ntohl(mp->inner_vrf_id);
3300 /* Yank segments and tags out of the API message */
3301 this_address = (ip6_address_t *)mp->segs_and_tags;
3302 for (i = 0; i < mp->n_segments; i++) {
3303 vec_add2 (segments, seg, 1);
3304 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3307 for (i = 0; i < mp->n_tags; i++) {
3308 vec_add2 (tags, tag, 1);
3309 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3313 a->segments = segments;
3316 rv = ip6_sr_add_del_tunnel (a);
3320 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3323 #define foreach_classify_add_del_table_field \
3328 _(match_n_vectors) \
3329 _(next_table_index) \
3332 static void vl_api_classify_add_del_table_t_handler
3333 (vl_api_classify_add_del_table_t * mp)
3335 vl_api_classify_add_del_table_reply_t * rmp;
3336 vnet_classify_main_t * cm = &vnet_classify_main;
3337 vnet_classify_table_t * t;
3341 foreach_classify_add_del_table_field;
3344 #define _(a) a = ntohl(mp->a);
3345 foreach_classify_add_del_table_field;
3348 /* The underlying API fails silently, on purpose, so check here */
3349 if (mp->is_add == 0)
3350 if (pool_is_free_index (cm->tables, table_index)) {
3351 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3355 rv = vnet_classify_add_del_table
3356 (cm, mp->mask, nbuckets, memory_size,
3357 skip_n_vectors, match_n_vectors,
3358 next_table_index, miss_next_index,
3359 &table_index, mp->is_add);
3362 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3364 if (rv == 0 && mp->is_add) {
3365 t = pool_elt_at_index (cm->tables, table_index);
3366 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3367 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3368 rmp->new_table_index = ntohl(table_index);
3370 rmp->skip_n_vectors = ~0;
3371 rmp->match_n_vectors = ~0;
3372 rmp->new_table_index = ~0;
3377 static void vl_api_classify_add_del_session_t_handler
3378 (vl_api_classify_add_del_session_t * mp)
3380 vnet_classify_main_t * cm = &vnet_classify_main;
3381 vl_api_classify_add_del_session_reply_t * rmp;
3383 u32 table_index, hit_next_index, opaque_index;
3386 table_index = ntohl (mp->table_index);
3387 hit_next_index = ntohl (mp->hit_next_index);
3388 opaque_index = ntohl (mp->opaque_index);
3389 advance = ntohl (mp->advance);
3391 rv = vnet_classify_add_del_session
3392 (cm, table_index, mp->match, hit_next_index, opaque_index,
3393 advance, mp->is_add);
3395 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3398 static void vl_api_classify_set_interface_ip_table_t_handler
3399 (vl_api_classify_set_interface_ip_table_t * mp)
3401 vlib_main_t * vm = vlib_get_main();
3402 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3404 u32 table_index, sw_if_index;
3406 table_index = ntohl (mp->table_index);
3407 sw_if_index = ntohl (mp->sw_if_index);
3409 VALIDATE_SW_IF_INDEX(mp);
3412 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3414 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3416 BAD_SW_IF_INDEX_LABEL;
3418 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3421 static void vl_api_classify_set_interface_l2_tables_t_handler
3422 (vl_api_classify_set_interface_l2_tables_t * mp)
3424 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3426 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3429 ip4_table_index = ntohl(mp->ip4_table_index);
3430 ip6_table_index = ntohl(mp->ip6_table_index);
3431 other_table_index = ntohl(mp->other_table_index);
3432 sw_if_index = ntohl(mp->sw_if_index);
3434 VALIDATE_SW_IF_INDEX(mp);
3436 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3437 ip6_table_index, other_table_index);
3440 if (ip4_table_index != ~0 || ip6_table_index != ~0
3441 || other_table_index != ~0)
3446 vnet_l2_classify_enable_disable (sw_if_index, enable);
3449 BAD_SW_IF_INDEX_LABEL;
3451 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3455 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3458 vl_api_l2_fib_clear_table_reply_t * rmp;
3460 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3461 * that is not currently implemented. When that TODO is fixed
3462 * this call should be changed to pass 1 instead of 0.
3464 l2fib_clear_table (0);
3466 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3469 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3474 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3477 vl_api_l2_interface_efp_filter_reply_t * rmp;
3478 vnet_main_t *vnm = vnet_get_main();
3480 // enable/disable the feature
3481 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3482 rv = vnm->api_errno;
3484 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3488 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3491 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3492 vnet_main_t * vnm = vnet_get_main();
3493 vlib_main_t * vm = vlib_get_main();
3496 VALIDATE_SW_IF_INDEX(mp);
3498 vtr_op = ntohl(mp->vtr_op);
3500 /* The L2 code is unsuspicious */
3502 case L2_VTR_DISABLED:
3507 case L2_VTR_TRANSLATE_1_1:
3508 case L2_VTR_TRANSLATE_1_2:
3509 case L2_VTR_TRANSLATE_2_1:
3510 case L2_VTR_TRANSLATE_2_2:
3514 rv = VNET_API_ERROR_INVALID_VALUE;
3515 goto bad_sw_if_index;
3518 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3519 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3522 BAD_SW_IF_INDEX_LABEL;
3524 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3528 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3532 vl_api_create_vhost_user_if_reply_t * rmp;
3533 u32 sw_if_index = (u32)~0;
3535 vnet_main_t * vnm = vnet_get_main();
3536 vlib_main_t * vm = vlib_get_main();
3538 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3539 mp->is_server, &sw_if_index, (u64)~0,
3540 mp->renumber, ntohl(mp->custom_dev_instance));
3542 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3544 rmp->sw_if_index = ntohl (sw_if_index);
3550 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3554 vl_api_modify_vhost_user_if_reply_t * rmp;
3555 u32 sw_if_index = ntohl(mp->sw_if_index);
3557 vnet_main_t * vnm = vnet_get_main();
3558 vlib_main_t * vm = vlib_get_main();
3560 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3561 mp->is_server, sw_if_index, (u64)~0,
3562 mp->renumber, ntohl(mp->custom_dev_instance));
3564 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3569 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3573 vpe_api_main_t * vam = &vpe_api_main;
3574 vl_api_delete_vhost_user_if_reply_t * rmp;
3575 u32 sw_if_index = ntohl(mp->sw_if_index);
3577 vnet_main_t * vnm = vnet_get_main();
3578 vlib_main_t * vm = vlib_get_main();
3580 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3582 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3584 unix_shared_memory_queue_t * q =
3585 vl_api_client_index_to_input_queue (mp->client_index);
3589 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3594 static void vl_api_sw_interface_vhost_user_details_t_handler (
3595 vl_api_sw_interface_vhost_user_details_t * mp)
3597 clib_warning ("BUG");
3601 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3602 unix_shared_memory_queue_t *q,
3603 vhost_user_intf_details_t * vui)
3605 vl_api_sw_interface_vhost_user_details_t * mp;
3607 mp = vl_msg_api_alloc (sizeof (*mp));
3608 memset (mp, 0, sizeof (*mp));
3609 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3610 mp->sw_if_index = ntohl(vui->sw_if_index);
3611 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3612 mp->features = clib_net_to_host_u64 (vui->features);
3613 mp->is_server = vui->is_server;
3614 mp->num_regions = ntohl(vui->num_regions);
3615 mp->sock_errno = ntohl(vui->sock_errno);
3617 strncpy ((char *) mp->sock_filename,
3618 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3619 strncpy ((char *) mp->interface_name,
3620 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3622 vl_msg_api_send_shmem (q, (u8 *)&mp);
3627 vl_api_sw_interface_vhost_user_dump_t_handler (
3628 vl_api_sw_interface_vhost_user_dump_t *mp)
3632 vpe_api_main_t * am = &vpe_api_main;
3633 vnet_main_t * vnm = vnet_get_main();
3634 vlib_main_t * vm = vlib_get_main();
3635 vhost_user_intf_details_t *ifaces = NULL;
3636 vhost_user_intf_details_t *vuid = NULL;
3637 unix_shared_memory_queue_t * q;
3639 q = vl_api_client_index_to_input_queue (mp->client_index);
3643 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3647 vec_foreach (vuid, ifaces) {
3648 send_sw_interface_vhost_user_details (am, q, vuid);
3654 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3655 unix_shared_memory_queue_t *q,
3659 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3660 u8 * if_name = NULL;
3661 vnet_sw_interface_t * si = NULL;
3663 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3665 if_name = format(if_name, "%U",
3666 format_vnet_sw_interface_name, lm->vnet_main, si);
3668 mp = vl_msg_api_alloc (sizeof (*mp));
3669 memset (mp, 0, sizeof (*mp));
3670 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3671 strncpy((char *)mp->interface_name,
3672 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3673 mp->sw_if_index = ntohl(si->sw_if_index);
3674 mp->local_session_id = s->local_session_id;
3675 mp->remote_session_id = s->remote_session_id;
3676 mp->local_cookie[0] = s->local_cookie[0];
3677 mp->local_cookie[1] = s->local_cookie[1];
3678 mp->remote_cookie = s->remote_cookie;
3679 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3680 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3681 mp->l2_sublayer_present = s->l2_sublayer_present;
3683 vl_msg_api_send_shmem (q, (u8 *)&mp);
3686 static void send_ip_address_details (vpe_api_main_t * am,
3687 unix_shared_memory_queue_t * q,
3692 vl_api_ip_address_details_t * mp;
3694 mp = vl_msg_api_alloc (sizeof (*mp));
3695 memset (mp, 0, sizeof (*mp));
3696 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3699 memcpy(&mp->ip, ip, sizeof(mp->ip));
3701 u32 * tp = (u32 *)mp->ip;
3702 *tp = ntohl(*(u32*)ip);
3704 mp->prefix_length = prefix_length;
3706 vl_msg_api_send_shmem (q, (u8 *)&mp);
3710 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3712 vpe_api_main_t * am = &vpe_api_main;
3713 unix_shared_memory_queue_t * q;
3716 ip6_main_t * im6 = &ip6_main;
3717 ip4_main_t * im4 = &ip4_main;
3718 ip_lookup_main_t * lm6 = &im6->lookup_main;
3719 ip_lookup_main_t * lm4 = &im4->lookup_main;
3720 ip_interface_address_t * ia = 0;
3721 u32 sw_if_index = ~0;
3723 sw_if_index = ntohl(mp->sw_if_index);
3725 q = vl_api_client_index_to_input_queue (mp->client_index);
3731 foreach_ip_interface_address (lm6, ia, sw_if_index,
3732 1 /* honor unnumbered */,
3734 r6 = ip_interface_address_get_address (lm6, ia);
3735 u16 prefix_length = ia->address_length;
3736 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3739 foreach_ip_interface_address (lm4, ia, sw_if_index,
3740 1 /* honor unnumbered */,
3742 r4 = ip_interface_address_get_address (lm4, ia);
3743 u16 prefix_length = ia->address_length;
3744 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3749 static void send_ip_details (vpe_api_main_t * am,
3750 unix_shared_memory_queue_t *q,
3753 vl_api_ip_details_t * mp;
3755 mp = vl_msg_api_alloc (sizeof (*mp));
3756 memset (mp, 0, sizeof (*mp));
3757 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3759 mp->sw_if_index = ntohl(sw_if_index);
3761 vl_msg_api_send_shmem (q, (u8 *)&mp);
3765 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3766 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3768 vpe_api_main_t * am = &vpe_api_main;
3769 l2t_main_t * lm = &l2t_main;
3770 unix_shared_memory_queue_t * q;
3771 l2t_session_t *session;
3773 q = vl_api_client_index_to_input_queue (mp->client_index);
3777 pool_foreach (session, lm->sessions,
3779 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3784 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3785 unix_shared_memory_queue_t *q,
3786 tapcli_interface_details_t *tap_if)
3788 vl_api_sw_interface_tap_details_t * mp;
3789 mp = vl_msg_api_alloc (sizeof (*mp));
3790 memset (mp, 0, sizeof (*mp));
3791 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3792 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3793 strncpy((char *)mp->dev_name,
3794 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3796 vl_msg_api_send_shmem (q, (u8 *)&mp);
3800 vl_api_sw_interface_tap_dump_t_handler (
3801 vl_api_sw_interface_tap_dump_t *mp)
3804 vpe_api_main_t * am = &vpe_api_main;
3805 unix_shared_memory_queue_t * q;
3806 tapcli_interface_details_t *tapifs = NULL;
3807 tapcli_interface_details_t *tap_if = NULL;
3809 q = vl_api_client_index_to_input_queue (mp->client_index);
3813 rv = vnet_tap_dump_ifs(&tapifs);
3817 vec_foreach(tap_if, tapifs) {
3818 send_sw_interface_tap_details(am, q, tap_if);
3825 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3827 vpe_api_main_t * am = &vpe_api_main;
3828 vnet_main_t * vnm = vnet_get_main();
3829 vlib_main_t * vm = vlib_get_main();
3830 vnet_interface_main_t * im = &vnm->interface_main;
3831 unix_shared_memory_queue_t * q;
3832 vnet_sw_interface_t * si, * sorted_sis;
3833 u32 sw_if_index = ~0;
3835 q = vl_api_client_index_to_input_queue (mp->client_index);
3840 /* Gather interfaces. */
3841 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3842 _vec_len (sorted_sis) = 0;
3843 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3845 vec_foreach (si, sorted_sis) {
3846 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3847 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3850 sw_if_index = si->sw_if_index;
3851 send_ip_details(am, q, sw_if_index);
3856 static void vl_api_l2_fib_table_entry_t_handler (
3857 vl_api_l2_fib_table_entry_t * mp)
3859 clib_warning ("BUG");
3862 static void send_l2fib_table_entry (vpe_api_main_t * am,
3863 unix_shared_memory_queue_t *q,
3864 l2fib_entry_key_t * l2fe_key,
3865 l2fib_entry_result_t * l2fe_res)
3867 vl_api_l2_fib_table_entry_t * mp;
3869 mp = vl_msg_api_alloc (sizeof (*mp));
3870 memset (mp, 0, sizeof (*mp));
3871 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3873 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3875 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3876 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3877 mp->static_mac = l2fe_res->fields.static_mac;
3878 mp->filter_mac = l2fe_res->fields.filter;
3879 mp->bvi_mac = l2fe_res->fields.bvi;
3881 vl_msg_api_send_shmem (q, (u8 *)&mp);
3885 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3887 vpe_api_main_t * am = &vpe_api_main;
3888 bd_main_t * bdm = &bd_main;
3889 l2fib_entry_key_t *l2fe_key = NULL;
3890 l2fib_entry_result_t *l2fe_res = NULL;
3891 u32 ni, bd_id = ntohl (mp->bd_id);
3893 unix_shared_memory_queue_t * q;
3896 q = vl_api_client_index_to_input_queue (mp->client_index);
3900 /* see l2fib_table_dump: ~0 means "any" */
3904 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3911 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3913 vec_foreach_index (ni, l2fe_key) {
3914 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
3915 vec_elt_at_index(l2fe_res, ni));
3922 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
3924 vl_api_show_version_reply_t *rmp;
3926 char * vpe_api_get_build_directory(void);
3927 char * vpe_api_get_version(void);
3928 char * vpe_api_get_build_date(void);
3930 unix_shared_memory_queue_t * q =
3931 vl_api_client_index_to_input_queue (mp->client_index);
3936 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3938 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3939 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3940 ARRAY_LEN(rmp->build_directory)-1);
3941 strncpy ((char *) rmp->version, vpe_api_get_version(),
3942 ARRAY_LEN(rmp->version)-1);
3943 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3944 ARRAY_LEN(rmp->build_date)-1);
3948 static void vl_api_get_node_index_t_handler
3949 (vl_api_get_node_index_t * mp)
3951 vlib_main_t * vm = vlib_get_main();
3952 vl_api_get_node_index_reply_t * rmp;
3955 u32 node_index = ~0;
3957 n = vlib_get_node_by_name (vm, mp->node_name);
3960 rv = VNET_API_ERROR_NO_SUCH_NODE;
3962 node_index = n->index;
3964 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3966 rmp->node_index = ntohl(node_index);
3970 static void vl_api_add_node_next_t_handler
3971 (vl_api_add_node_next_t * mp)
3973 vlib_main_t * vm = vlib_get_main();
3974 vl_api_add_node_next_reply_t * rmp;
3975 vlib_node_t * n, * next;
3977 u32 next_index = ~0;
3979 n = vlib_get_node_by_name (vm, mp->node_name);
3982 rv = VNET_API_ERROR_NO_SUCH_NODE;
3986 next = vlib_get_node_by_name (vm, mp->next_name);
3989 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3991 next_index = vlib_node_add_next (vm, n->index, next->index);
3994 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3996 rmp->next_index = ntohl(next_index);
4000 static void vl_api_l2tpv3_create_tunnel_t_handler
4001 (vl_api_l2tpv3_create_tunnel_t *mp)
4003 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4004 l2t_main_t *lm = &l2t_main;
4005 u32 sw_if_index = (u32)~0;
4008 if (mp->is_ipv6 != 1) {
4009 rv = VNET_API_ERROR_UNIMPLEMENTED;
4013 rv = create_l2tpv3_ipv6_tunnel (lm,
4014 (ip6_address_t *) mp->client_address,
4015 (ip6_address_t *) mp->our_address,
4016 ntohl(mp->local_session_id),
4017 ntohl(mp->remote_session_id),
4018 clib_net_to_host_u64(mp->local_cookie),
4019 clib_net_to_host_u64(mp->remote_cookie),
4020 mp->l2_sublayer_present,
4024 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4026 rmp->sw_if_index = ntohl (sw_if_index);
4030 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4031 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4033 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4034 l2t_main_t *lm = &l2t_main;
4037 VALIDATE_SW_IF_INDEX(mp);
4039 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4040 clib_net_to_host_u64(mp->new_local_cookie),
4041 clib_net_to_host_u64(mp->new_remote_cookie));
4043 BAD_SW_IF_INDEX_LABEL;
4045 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4048 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4049 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4052 vnet_main_t * vnm = vnet_get_main();
4053 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4055 VALIDATE_SW_IF_INDEX(mp);
4057 rv = l2tpv3_interface_enable_disable
4058 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4060 BAD_SW_IF_INDEX_LABEL;
4062 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4065 static void vl_api_l2tpv3_set_lookup_key_t_handler
4066 (vl_api_l2tpv3_set_lookup_key_t * mp)
4069 l2t_main_t *lm = &l2t_main;
4070 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4072 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4073 rv = VNET_API_ERROR_INVALID_VALUE;
4077 lm->lookup_type = mp->key;
4080 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4083 static void vl_api_vxlan_add_del_tunnel_t_handler
4084 (vl_api_vxlan_add_del_tunnel_t * mp)
4086 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4088 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4089 u32 encap_fib_index;
4091 ip4_main_t * im = &ip4_main;
4092 u32 sw_if_index = ~0;
4094 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4096 rv = VNET_API_ERROR_NO_SUCH_FIB;
4099 encap_fib_index = p[0];
4101 memset (a, 0, sizeof (*a));
4103 a->is_add = mp->is_add;
4105 /* ip addresses sent in network byte order */
4106 a->src.as_u32 = mp->src_address;
4107 a->dst.as_u32 = mp->dst_address;
4109 a->encap_fib_index = encap_fib_index;
4110 a->decap_next_index = ntohl(mp->decap_next_index);
4111 a->vni = ntohl(mp->vni);
4112 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4115 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4117 rmp->sw_if_index = ntohl (sw_if_index);
4122 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4124 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4126 vl_api_l2_patch_add_del_reply_t * rmp;
4127 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4131 VALIDATE_RX_SW_IF_INDEX(mp);
4132 VALIDATE_TX_SW_IF_INDEX(mp);
4134 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4135 ntohl(mp->tx_sw_if_index),
4136 (int)(mp->is_add != 0));
4138 BAD_RX_SW_IF_INDEX_LABEL;
4139 BAD_TX_SW_IF_INDEX_LABEL;
4141 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4145 vl_api_nsh_gre_add_del_tunnel_t_handler
4146 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4148 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4150 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4151 u32 encap_fib_index, decap_fib_index;
4152 u32 decap_next_index;
4154 ip4_main_t * im = &ip4_main;
4156 u32 sw_if_index = ~0;
4159 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4161 rv = VNET_API_ERROR_NO_SUCH_FIB;
4164 encap_fib_index = p[0];
4166 decap_next_index = ntohl(mp->decap_next_index);
4168 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4169 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4170 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4172 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4175 decap_fib_index = p[0];
4177 decap_fib_index = ntohl(mp->decap_vrf_id);
4180 memset (a, 0, sizeof (*a));
4182 a->is_add = mp->is_add;
4183 /* ip addresses sent in network byte order */
4184 a->src.as_u32 = ntohl(mp->src);
4185 a->dst.as_u32 = ntohl(mp->dst);
4186 a->encap_fib_index = encap_fib_index;
4187 a->decap_fib_index = decap_fib_index;
4188 a->decap_next_index = decap_next_index;
4189 a->ver_o_c = mp->ver_o_c;
4190 a->length = mp->length;
4191 a->md_type = mp->md_type;
4192 a->next_protocol = mp->next_protocol;
4193 a->spi_si = ntohl(mp->spi_si);
4194 a->c1 = ntohl(mp->c1);
4195 a->c2 = ntohl(mp->c2);
4196 a->c3 = ntohl(mp->c3);
4197 a->c4 = ntohl(mp->c4);
4199 for (i = 0; i < mp->tlv_len_in_words; i++)
4200 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4204 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4207 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4209 rmp->sw_if_index = ntohl (sw_if_index);
4214 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4215 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4217 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4219 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4220 u32 encap_fib_index, decap_fib_index;
4221 u32 decap_next_index;
4223 ip4_main_t * im = &ip4_main;
4225 u32 sw_if_index = ~0;
4228 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4230 rv = VNET_API_ERROR_NO_SUCH_FIB;
4233 encap_fib_index = p[0];
4235 decap_next_index = ntohl(mp->decap_next_index);
4237 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4238 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4239 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4241 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4244 decap_fib_index = p[0];
4246 decap_fib_index = ntohl(mp->decap_vrf_id);
4249 memset (a, 0, sizeof (*a));
4251 a->is_add = mp->is_add;
4252 /* ip addresses sent in network byte order */
4253 a->src.as_u32 = ntohl(mp->src);
4254 a->dst.as_u32 = ntohl(mp->dst);
4255 a->encap_fib_index = encap_fib_index;
4256 a->decap_fib_index = decap_fib_index;
4257 a->decap_next_index = decap_next_index;
4258 a->vni = ntohl(mp->vni);
4259 a->ver_o_c = mp->ver_o_c;
4260 a->length = mp->length;
4261 a->md_type = mp->md_type;
4262 a->next_protocol = mp->next_protocol;
4263 a->spi_si = ntohl(mp->spi_si);
4264 a->c1 = ntohl(mp->c1);
4265 a->c2 = ntohl(mp->c2);
4266 a->c3 = ntohl(mp->c3);
4267 a->c4 = ntohl(mp->c4);
4269 for (i = 0; i < mp->tlv_len_in_words; i++)
4270 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4274 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4277 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4279 rmp->sw_if_index = ntohl (sw_if_index);
4284 vl_api_lisp_gpe_add_del_tunnel_t_handler
4285 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4287 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4289 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4290 u32 encap_fib_index, decap_fib_index;
4291 u32 decap_next_index;
4293 ip4_main_t * im = &ip4_main;
4294 u32 sw_if_index = ~0;
4296 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4298 rv = VNET_API_ERROR_NO_SUCH_FIB;
4301 encap_fib_index = p[0];
4303 decap_next_index = ntohl(mp->decap_next_index);
4305 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4306 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4307 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4309 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4312 decap_fib_index = p[0];
4314 decap_fib_index = ntohl(mp->decap_vrf_id);
4317 memset (a, 0, sizeof (*a));
4319 a->is_add = mp->is_add;
4320 /* ip addresses sent in network byte order */
4321 a->src.as_u32 = mp->src;
4322 a->dst.as_u32 = mp->dst;
4323 a->encap_fib_index = encap_fib_index;
4324 a->decap_fib_index = decap_fib_index;
4325 a->decap_next_index = decap_next_index;
4326 a->flags = mp->flags;
4327 a->ver_res = mp->ver_res;
4329 a->next_protocol = mp->next_protocol;
4330 a->iid = clib_net_to_host_u32 (mp->iid);
4332 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4335 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4337 rmp->sw_if_index = ntohl (sw_if_index);
4342 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4344 vl_api_interface_name_renumber_reply_t * rmp;
4347 VALIDATE_SW_IF_INDEX(mp);
4349 rv = vnet_interface_name_renumber
4350 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4352 BAD_SW_IF_INDEX_LABEL;
4354 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4357 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4358 u32 sw_if_index, u32 address)
4360 vpe_api_main_t * am = &vpe_api_main;
4361 vlib_main_t * vm = am->vlib_main;
4362 vl_api_ip4_arp_event_t * event;
4363 static f64 arp_event_last_time;
4364 f64 now = vlib_time_now (vm);
4366 if (pool_is_free_index (am->arp_events, pool_index))
4369 event = pool_elt_at_index (am->arp_events, pool_index);
4370 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4371 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4372 } else { /* same mac */
4373 if ((sw_if_index == event->sw_if_index) &&
4375 /* for BD case, also check IP address with 10 sec timeout */
4376 ((address == event->address) &&
4377 ((now - arp_event_last_time) < 10.0))))
4381 arp_event_last_time = now;
4382 event->sw_if_index = sw_if_index;
4383 if (address) event->address = address;
4387 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4389 vpe_api_main_t * am = &vpe_api_main;
4391 if (pool_is_free_index (am->arp_events, pool_index))
4394 pool_put_index (am->arp_events, pool_index);
4399 vl_api_want_ip4_arp_events_t_handler
4400 (vl_api_want_ip4_arp_events_t * mp)
4402 vpe_api_main_t * am = &vpe_api_main;
4403 vnet_main_t * vnm = vnet_get_main();
4404 vl_api_want_ip4_arp_events_reply_t *rmp;
4405 vl_api_ip4_arp_event_t * event;
4408 if (mp->enable_disable) {
4409 pool_get (am->arp_events, event);
4410 memset (event, 0, sizeof (*event));
4412 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4413 event->client_index = mp->client_index;
4414 event->context = mp->context;
4415 event->address = mp->address;
4416 event->pid = mp->pid;
4418 rv = vnet_add_del_ip4_arp_change_event
4419 (vnm, arp_change_data_callback,
4421 &mp->address /* addr, in net byte order */,
4422 vpe_resolver_process_node.index,
4423 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4425 rv = vnet_add_del_ip4_arp_change_event
4426 (vnm, arp_change_delete_callback,
4428 &mp->address /* addr, in net byte order */,
4429 vpe_resolver_process_node.index,
4430 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4432 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4435 static void vl_api_input_acl_set_interface_t_handler
4436 (vl_api_input_acl_set_interface_t * mp)
4438 vlib_main_t *vm = vlib_get_main();
4439 vl_api_input_acl_set_interface_reply_t * rmp;
4441 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4443 ip4_table_index = ntohl(mp->ip4_table_index);
4444 ip6_table_index = ntohl(mp->ip6_table_index);
4445 l2_table_index = ntohl(mp->l2_table_index);
4446 sw_if_index = ntohl(mp->sw_if_index);
4448 VALIDATE_SW_IF_INDEX(mp);
4450 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4451 ip6_table_index, l2_table_index,
4454 BAD_SW_IF_INDEX_LABEL;
4456 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4459 static void vl_api_ipsec_spd_add_del_t_handler
4460 (vl_api_ipsec_spd_add_del_t * mp)
4462 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4463 vl_api_ipsec_spd_add_del_reply_t * rmp;
4467 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4469 rv = VNET_API_ERROR_UNIMPLEMENTED;
4472 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4475 static void vl_api_ipsec_interface_add_del_spd_t_handler
4476 (vl_api_ipsec_interface_add_del_spd_t * mp)
4478 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4479 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4481 u32 sw_if_index __attribute__((unused));
4482 u32 spd_id __attribute__((unused));
4484 sw_if_index = ntohl(mp->sw_if_index);
4485 spd_id = ntohl(mp->spd_id);
4487 VALIDATE_SW_IF_INDEX(mp);
4490 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4492 rv = VNET_API_ERROR_UNIMPLEMENTED;
4495 BAD_SW_IF_INDEX_LABEL;
4497 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4500 static void vl_api_ipsec_spd_add_del_entry_t_handler
4501 (vl_api_ipsec_spd_add_del_entry_t * mp)
4503 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4504 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4510 p.id = ntohl(mp->spd_id);
4511 p.priority = ntohl(mp->priority);
4512 p.is_outbound = mp->is_outbound;
4513 p.is_ipv6 = mp->is_ipv6;
4515 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4516 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4517 memcpy(&p.laddr.start, mp->local_address_start, 16);
4518 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4520 p.protocol = mp->protocol;
4521 p.rport.start = ntohs(mp->remote_port_start);
4522 p.rport.stop = ntohs(mp->remote_port_stop);
4523 p.lport.start = ntohs(mp->local_port_start);
4524 p.lport.stop = ntohs(mp->local_port_stop);
4525 /* policy action resolve unsupported */
4526 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4527 clib_warning("unsupported action: 'resolve'");
4528 rv = VNET_API_ERROR_UNIMPLEMENTED;
4531 p.policy = mp->policy;
4532 p.sa_id = ntohl(mp->sa_id);
4534 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4538 if (mp->is_ip_any) {
4540 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4543 rv = VNET_API_ERROR_UNIMPLEMENTED;
4548 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4551 static void vl_api_ipsec_sad_add_del_entry_t_handler
4552 (vl_api_ipsec_sad_add_del_entry_t * mp)
4554 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4555 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4560 sa.id = ntohl(mp->sad_id);
4561 sa.spi = ntohl(mp->spi);
4562 /* security protocol AH unsupported */
4563 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4564 clib_warning("unsupported security protocol 'AH'");
4565 rv = VNET_API_ERROR_UNIMPLEMENTED;
4568 sa.protocol = mp->protocol;
4569 /* check for unsupported crypto-alg */
4570 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4571 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4572 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4573 mp->crypto_algorithm);
4574 rv = VNET_API_ERROR_UNIMPLEMENTED;
4577 sa.crypto_alg = mp->crypto_algorithm;
4578 sa.crypto_key_len = mp->crypto_key_length;
4579 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4580 /* check for unsupported integ-alg */
4581 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4582 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4583 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4584 mp->integrity_algorithm);
4585 rv = VNET_API_ERROR_UNIMPLEMENTED;
4588 sa.integ_alg = mp->integrity_algorithm;
4589 sa.integ_key_len = mp->integrity_key_length;
4590 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4591 sa.use_esn = mp->use_extended_sequence_number;
4592 sa.is_tunnel = mp->is_tunnel;
4593 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4594 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4595 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4597 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4599 rv = VNET_API_ERROR_UNIMPLEMENTED;
4604 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4607 vl_api_map_add_domain_t_handler
4608 (vl_api_map_add_domain_t * mp)
4610 vl_api_map_add_domain_reply_t * rmp;
4613 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4614 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4615 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4616 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4617 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4619 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4621 rmp->index = ntohl(index);
4626 vl_api_map_del_domain_t_handler
4627 (vl_api_map_del_domain_t * mp)
4629 vl_api_map_del_domain_reply_t * rmp;
4632 rv = map_delete_domain(ntohl(mp->index));
4634 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4638 vl_api_map_add_del_rule_t_handler
4639 (vl_api_map_add_del_rule_t * mp)
4641 vl_api_map_del_domain_reply_t * rmp;
4644 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4646 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4650 vl_api_map_domain_dump_t_handler
4651 (vl_api_map_domain_dump_t * mp)
4653 vl_api_map_domain_details_t * rmp;
4654 map_main_t *mm = &map_main;
4656 unix_shared_memory_queue_t * q;
4658 if (pool_elts (mm->domains) == 0)
4661 q = vl_api_client_index_to_input_queue (mp->client_index);
4666 pool_foreach(d, mm->domains, ({
4667 rmp = vl_msg_api_alloc (sizeof (*rmp));
4668 memset (rmp, 0, sizeof (*rmp));
4669 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4670 rmp->domain_index = htonl(d - mm->domains);
4671 rmp->ea_bits_len = d->ea_bits_len;
4672 rmp->psid_offset = d->psid_offset;
4673 rmp->psid_length = d->psid_length;
4674 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4675 rmp->ip4_prefix_len = d->ip4_prefix_len;
4676 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4677 rmp->ip6_prefix_len = d->ip6_prefix_len;
4678 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4679 rmp->ip6_src_len = d->ip6_src_len;
4680 rmp->mtu = htons(d->mtu);
4681 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4683 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4688 vl_api_map_rule_dump_t_handler
4689 (vl_api_map_rule_dump_t * mp)
4691 unix_shared_memory_queue_t * q;
4694 vl_api_map_rule_details_t * rmp;
4695 map_main_t *mm = &map_main;
4696 u32 domain_index = ntohl(mp->domain_index);
4699 if (pool_elts (mm->domains) == 0)
4702 d = pool_elt_at_index(mm->domains, domain_index);
4703 if (!d || !d->rules) {
4707 q = vl_api_client_index_to_input_queue (mp->client_index);
4712 for (i = 0; i < (0x1 << d->psid_length); i++) {
4714 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4717 rmp = vl_msg_api_alloc(sizeof(*rmp));
4718 memset(rmp, 0, sizeof(*rmp));
4719 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4720 rmp->psid = htons(i);
4721 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4722 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4727 vl_api_map_summary_stats_t_handler (
4728 vl_api_map_summary_stats_t *mp)
4730 vl_api_map_summary_stats_reply_t *rmp;
4731 vlib_combined_counter_main_t *cm;
4734 u64 total_pkts[VLIB_N_RX_TX];
4735 u64 total_bytes[VLIB_N_RX_TX];
4736 map_main_t *mm = &map_main;
4737 unix_shared_memory_queue_t *q =
4738 vl_api_client_index_to_input_queue(mp->client_index);
4743 rmp = vl_msg_api_alloc (sizeof (*rmp));
4744 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
4745 rmp->context = mp->context;
4748 memset (total_pkts, 0, sizeof (total_pkts));
4749 memset (total_bytes, 0, sizeof (total_bytes));
4751 map_domain_counter_lock (mm);
4752 vec_foreach(cm, mm->domain_counters) {
4753 which = cm - mm->domain_counters;
4755 for (i = 0; i < vec_len(cm->maxi); i++) {
4756 vlib_get_combined_counter (cm, i, &v);
4757 total_pkts[which] += v.packets;
4758 total_bytes[which] += v.bytes;
4762 map_domain_counter_unlock (mm);
4764 /* Note: in HOST byte order! */
4765 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
4766 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
4767 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
4768 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
4769 rmp->total_bindings = pool_elts(mm->domains);
4770 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
4771 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
4772 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
4774 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4777 static void vl_api_ipsec_sa_set_key_t_handler
4778 (vl_api_ipsec_sa_set_key_t * mp)
4780 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4781 vl_api_ipsec_sa_set_key_reply_t *rmp;
4785 sa.id = ntohl(mp->sa_id);
4786 sa.crypto_key_len = mp->crypto_key_length;
4787 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4788 sa.integ_key_len = mp->integrity_key_length;
4789 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4791 rv = ipsec_set_sa_key(vm, &sa);
4793 rv = VNET_API_ERROR_UNIMPLEMENTED;
4796 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
4799 #define BOUNCE_HANDLER(nn) \
4800 static void vl_api_##nn##_t_handler ( \
4801 vl_api_##nn##_t *mp) \
4803 vpe_client_registration_t *reg; \
4804 vpe_api_main_t * vam = &vpe_api_main; \
4805 unix_shared_memory_queue_t * q; \
4807 /* One registration only... */ \
4808 pool_foreach(reg, vam->nn##_registrations, \
4810 q = vl_api_client_index_to_input_queue (reg->client_index); \
4813 * If the queue is stuffed, turf the msg and complain \
4814 * It's unlikely that the intended recipient is \
4815 * alive; avoid deadlock at all costs. \
4817 if (q->cursize == q->maxsize) { \
4818 clib_warning ("ERROR: receiver queue full, drop msg"); \
4819 vl_msg_api_free (mp); \
4822 vl_msg_api_send_shmem (q, (u8 *)&mp); \
4826 vl_msg_api_free (mp); \
4829 BOUNCE_HANDLER(to_netconf_server);
4830 BOUNCE_HANDLER(from_netconf_server);
4831 BOUNCE_HANDLER(to_netconf_client);
4832 BOUNCE_HANDLER(from_netconf_client);
4836 * Add vpe's API message handlers to the table.
4837 * vlib has alread mapped shared memory and
4838 * added the client registration handlers.
4839 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
4842 static clib_error_t *
4843 vpe_api_hookup (vlib_main_t *vm)
4845 api_main_t * am = &api_main;
4848 vl_msg_api_set_handlers(VL_API_##N, #n, \
4849 vl_api_##n##_t_handler, \
4851 vl_api_##n##_t_endian, \
4852 vl_api_##n##_t_print, \
4853 sizeof(vl_api_##n##_t), 1);
4854 foreach_vpe_api_msg;
4858 * Manually register the sr tunnel add del msg, so we trace
4859 * enough bytes to capture a typical segment list
4861 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
4862 "sr_tunnel_add_del",
4863 vl_api_sr_tunnel_add_del_t_handler,
4865 vl_api_sr_tunnel_add_del_t_endian,
4866 vl_api_sr_tunnel_add_del_t_print,
4869 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
4870 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
4871 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
4872 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
4875 * Trace space for 8 MPLS encap labels, classifier mask+match
4877 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
4878 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
4879 += 5 * sizeof (u32x4);
4880 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
4881 += 5 * sizeof (u32x4);
4882 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
4883 += 16 * sizeof (u32);
4886 * trace space for 4 nsh-gre variable TLV words
4888 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
4889 += 4 * sizeof (u32);
4894 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
4896 static clib_error_t *
4897 vpe_api_init (vlib_main_t *vm)
4899 vpe_api_main_t *am = &vpe_api_main;
4902 am->vnet_main = vnet_get_main();
4903 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
4904 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
4905 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
4906 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
4907 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
4908 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
4911 vl_set_memory_region_name ("/vpe-api");
4912 vl_enable_disable_memory_api (vm, 1 /* enable it */);
4917 VLIB_INIT_FUNCTION(vpe_api_init);
4919 void * get_unformat_vnet_sw_interface (void)
4921 return (void *) &unformat_vnet_sw_interface;
4924 #undef vl_api_version
4925 #define vl_api_version(n,v) static u32 vpe_api_version = v;
4926 #include <api/vpe.api.h>
4927 #undef vl_api_version
4929 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
4931 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
4932 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
4933 clib_host_to_net_u32 (mp->api_versions[0]),
4940 static u8 * format_arp_event (u8 * s, va_list * args)
4942 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
4944 s = format (s, "pid %d: %U", event->pid,
4945 format_ip4_address, &event->address);
4949 static clib_error_t *
4950 show_ip4_arp_events_fn (vlib_main_t * vm,
4951 unformat_input_t * input,
4952 vlib_cli_command_t * cmd)
4954 vpe_api_main_t * am = &vpe_api_main;
4955 vl_api_ip4_arp_event_t * event;
4957 if (pool_elts (am->arp_events) == 0) {
4958 vlib_cli_output (vm, "No active arp event registrations");
4962 pool_foreach (event, am->arp_events,
4964 vlib_cli_output (vm, "%U", format_arp_event, event);
4970 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
4971 .path = "show arp event registrations",
4972 .function = show_ip4_arp_events_fn,
4973 .short_help = "Show arp event registrations",