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>
56 #include <vnet/sr/sr.h>
58 #include <vnet/dhcpv6/proxy.h>
59 #include <vlib/vlib.h>
60 #include <vlib/unix/unix.h>
61 #include <vlibapi/api.h>
62 #include <vlibmemory/api.h>
63 #include <vnet/classify/vnet_classify.h>
64 #include <vnet/classify/input_acl.h>
65 #include <vnet/l2/l2_classify.h>
66 #include <vnet/vxlan/vxlan.h>
67 #include <vnet/l2/l2_vtr.h>
68 #include <vnet/nsh-gre/nsh_gre.h>
69 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
70 #include <vnet/lisp-gpe/lisp_gpe.h>
71 #include <vnet/map/map.h>
74 #undef __included_bihash_template_h__
75 #include <vnet/l2/l2_fib.h>
79 #include <vnet/ipsec/ipsec.h>
81 #include <vnet/devices/virtio/vhost-user.h>
84 #include <stats/stats.h>
87 #include <vnet/ethernet/ethernet.h>
88 #include <vnet/ethernet/arp_packet.h>
89 #include <vnet/interface.h>
91 #include <vnet/l2/l2_fib.h>
92 #include <vnet/l2/l2_bd.h>
93 #include <api/vpe_msg_enum.h>
96 #define f64_print(a,b)
98 #define vl_typedefs /* define message structures */
99 #include <api/vpe_all_api_h.h>
102 #define vl_endianfun /* define message structures */
103 #include <api/vpe_all_api_h.h>
106 /* instantiate all the print functions we know about */
107 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
109 #include <api/vpe_all_api_h.h>
112 #define REPLY_MACRO(t) \
114 unix_shared_memory_queue_t * q; \
115 rv = vl_msg_api_pd_handler (mp, rv); \
116 q = vl_api_client_index_to_input_queue (mp->client_index); \
120 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
121 rmp->_vl_msg_id = ntohs((t)); \
122 rmp->context = mp->context; \
123 rmp->retval = ntohl(rv); \
125 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
128 #define REPLY_MACRO2(t, body) \
130 unix_shared_memory_queue_t * q; \
131 rv = vl_msg_api_pd_handler (mp, rv); \
132 q = vl_api_client_index_to_input_queue (mp->client_index); \
136 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
137 rmp->_vl_msg_id = ntohs((t)); \
138 rmp->context = mp->context; \
139 rmp->retval = ntohl(rv); \
140 do {body;} while (0); \
141 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
144 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
146 #define VALIDATE_SW_IF_INDEX(mp) \
147 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
148 vnet_main_t *__vnm = vnet_get_main(); \
149 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
151 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
152 goto bad_sw_if_index; \
156 #define BAD_SW_IF_INDEX_LABEL \
162 #define VALIDATE_RX_SW_IF_INDEX(mp) \
163 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
164 vnet_main_t *__vnm = vnet_get_main(); \
165 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
166 __rx_sw_if_index)) { \
167 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
168 goto bad_rx_sw_if_index; \
172 #define BAD_RX_SW_IF_INDEX_LABEL \
174 bad_rx_sw_if_index: \
178 #define VALIDATE_TX_SW_IF_INDEX(mp) \
179 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
180 vnet_main_t *__vnm = vnet_get_main(); \
181 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
182 __tx_sw_if_index)) { \
183 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
184 goto bad_tx_sw_if_index; \
188 #define BAD_TX_SW_IF_INDEX_LABEL \
190 bad_tx_sw_if_index: \
196 #define VALIDATE_SW_IF_INDEX(mp)
197 #define BAD_SW_IF_INDEX_LABEL
198 #define VALIDATE_RX_SW_IF_INDEX(mp)
199 #define BAD_RX_SW_IF_INDEX_LABEL
200 #define VALIDATE_TX_SW_IF_INDEX(mp)
201 #define BAD_TX_SW_IF_INDEX_LABEL
203 #endif /* CLIB_DEBUG > 0 */
205 #define foreach_vpe_api_msg \
206 _(WANT_INTERFACE_EVENTS, want_interface_events) \
207 _(WANT_FROM_NETCONF_SERVER, want_from_netconf_server) \
208 _(WANT_TO_NETCONF_SERVER, want_to_netconf_server) \
209 _(WANT_FROM_NETCONF_CLIENT, want_from_netconf_client) \
210 _(WANT_TO_NETCONF_CLIENT, want_to_netconf_client) \
211 _(FROM_NETCONF_SERVER, from_netconf_server) \
212 _(TO_NETCONF_SERVER, to_netconf_server) \
213 _(FROM_NETCONF_CLIENT, from_netconf_client) \
214 _(TO_NETCONF_CLIENT, to_netconf_client) \
215 _(WANT_OAM_EVENTS, want_oam_events) \
216 _(OAM_ADD_DEL, oam_add_del) \
217 _(SW_INTERFACE_DUMP, sw_interface_dump) \
218 _(SW_INTERFACE_DETAILS, sw_interface_details) \
219 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
220 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
221 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
222 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
223 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
224 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
225 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
226 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
227 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
228 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
229 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
230 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
231 _(L2FIB_ADD_DEL, l2fib_add_del) \
232 _(L2_FLAGS, l2_flags) \
233 _(BRIDGE_FLAGS, bridge_flags) \
234 _(TAP_CONNECT, tap_connect) \
235 _(TAP_MODIFY, tap_modify) \
236 _(TAP_DELETE, tap_delete) \
237 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
238 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
239 _(CREATE_SUBIF, create_subif) \
240 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
241 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
242 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
243 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
244 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
245 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
246 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
247 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
248 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
249 _(RESET_FIB, reset_fib) \
250 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
251 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
252 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
253 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
254 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
255 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
256 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
257 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
258 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
259 sw_interface_ip6_set_link_local_address) \
260 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
261 _(CREATE_LOOPBACK, create_loopback) \
262 _(CONTROL_PING, control_ping) \
263 _(CLI_REQUEST, cli_request) \
264 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
265 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
266 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
267 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
268 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
269 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
270 _(GET_NODE_INDEX, get_node_index) \
271 _(ADD_NODE_NEXT, add_node_next) \
272 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
273 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
274 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
275 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
276 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
277 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
278 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
279 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
280 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
281 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
282 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
283 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
284 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
285 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
286 _(IP_ADDRESS_DUMP, ip_address_dump) \
287 _(IP_DUMP, ip_dump) \
288 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
289 _(SHOW_VERSION, show_version) \
290 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
291 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
292 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
293 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
294 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel) \
295 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
296 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
297 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
298 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
299 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
300 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
301 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
302 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
303 _(DELETE_LOOPBACK, delete_loopback) \
304 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
305 _(MAP_ADD_DOMAIN, map_add_domain) \
306 _(MAP_DEL_DOMAIN, map_del_domain) \
307 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
308 _(MAP_DOMAIN_DUMP, map_domain_dump) \
309 _(MAP_RULE_DUMP, map_rule_dump) \
310 _(MAP_SUMMARY_STATS, map_summary_stats)
313 #define QUOTE(x) QUOTE_(x)
315 #define foreach_registration_hash \
316 _(interface_events) \
317 _(to_netconf_server) \
318 _(from_netconf_server) \
319 _(to_netconf_client) \
320 _(from_netconf_client) \
324 RESOLVE_IP4_ADD_DEL_ROUTE=1,
325 RESOLVE_IP6_ADD_DEL_ROUTE,
326 RESOLVE_MPLS_ETHERNET_ADD_DEL,
332 vl_api_ip_add_del_route_t r;
333 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
339 #define _(a) uword *a##_registration_hash; \
340 vpe_client_registration_t * a##_registrations;
341 foreach_registration_hash
344 /* notifications happen really early in the game */
345 u8 link_state_process_up;
347 /* ip4 pending route adds */
348 pending_route_t * pending_routes;
350 /* ip4 arp event registration pool */
351 vl_api_ip4_arp_event_t * arp_events;
354 vlib_main_t * vlib_main;
355 vnet_main_t * vnet_main;
358 static vlib_node_registration_t vpe_resolver_process_node;
359 static vpe_api_main_t vpe_api_main;
361 static void send_sw_interface_flags (vpe_api_main_t * am,
362 unix_shared_memory_queue_t *q,
363 vnet_sw_interface_t * swif);
364 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
365 unix_shared_memory_queue_t *q,
368 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
371 /* Clean up all registrations belonging to the indicated client */
372 int vl_api_memclnt_delete_callback (u32 client_index)
374 vpe_api_main_t * vam = &vpe_api_main;
375 vpe_client_registration_t *rp;
377 int stats_memclnt_delete_callback (u32 client_index);
379 stats_memclnt_delete_callback (client_index);
382 p = hash_get (vam->a##_registration_hash, client_index); \
384 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
385 pool_put (vam->a##_registrations, rp); \
386 hash_unset (vam->a##_registration_hash, client_index); \
388 foreach_registration_hash;
393 #define API_LINK_STATE_EVENT 1
394 #define API_ADMIN_UP_DOWN_EVENT 2
397 event_data_cmp (void * a1, void * a2)
402 return (word) e1[0] - (word) e2[0];
406 link_state_process (vlib_main_t * vm,
407 vlib_node_runtime_t * rt,
410 vpe_api_main_t * vam = &vpe_api_main;
411 vnet_main_t * vnm = vam->vnet_main;
412 vnet_sw_interface_t * swif;
413 uword * event_data = 0;
414 vpe_client_registration_t *reg;
416 u32 prev_sw_if_index;
417 unix_shared_memory_queue_t * q;
419 vam->link_state_process_up = 1;
422 vlib_process_wait_for_event (vm);
424 /* Unified list of changed link or admin state sw_if_indices */
425 vlib_process_get_events_with_type
426 (vm, &event_data, API_LINK_STATE_EVENT);
427 vlib_process_get_events_with_type
428 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
430 /* Sort, so we can eliminate duplicates */
431 vec_sort_with_function (event_data, event_data_cmp);
433 prev_sw_if_index = ~0;
435 for (i = 0; i < vec_len(event_data); i++) {
436 /* Only one message per swif */
437 if (prev_sw_if_index == event_data[i])
439 prev_sw_if_index = event_data[i];
441 pool_foreach(reg, vam->interface_events_registrations,
443 q = vl_api_client_index_to_input_queue (reg->client_index);
445 // sw_interface may be deleted already
446 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
449 swif = vnet_get_sw_interface (vnm, event_data[i]);
450 send_sw_interface_flags (vam, q, swif);
455 vec_reset_length (event_data);
461 static clib_error_t *
462 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
463 static clib_error_t *
464 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
466 VLIB_REGISTER_NODE (link_state_process_node,static) = {
467 .function = link_state_process,
468 .type = VLIB_NODE_TYPE_PROCESS,
469 .name = "vpe-link-state-process",
472 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
473 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
475 static clib_error_t *
476 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
478 vpe_api_main_t * vam = &vpe_api_main;
479 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
481 if (vam->link_state_process_up)
482 vlib_process_signal_event (vam->vlib_main,
483 link_state_process_node.index,
484 API_LINK_STATE_EVENT,
489 static clib_error_t *
490 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
492 vpe_api_main_t * vam = &vpe_api_main;
495 * Note: it's perfectly fair to set a subif admin up / admin down.
496 * Note the subtle distinction between this routine and the previous
499 if (vam->link_state_process_up)
500 vlib_process_signal_event (vam->vlib_main,
501 link_state_process_node.index,
502 API_ADMIN_UP_DOWN_EVENT,
507 #define pub_sub_handler(lca,UCA) \
508 static void vl_api_want_##lca##_t_handler ( \
509 vl_api_want_##lca##_t *mp) \
511 vpe_api_main_t *vam = &vpe_api_main; \
512 vpe_client_registration_t *rp; \
513 vl_api_want_##lca##_reply_t *rmp; \
517 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
519 if (mp->enable_disable) { \
520 clib_warning ("pid %d: already enabled...", mp->pid); \
521 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
524 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
525 pool_put (vam->lca##_registrations, rp); \
526 hash_unset (vam->lca##_registration_hash, \
531 if (mp->enable_disable == 0) { \
532 clib_warning ("pid %d: already disabled...", mp->pid); \
533 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
536 pool_get (vam->lca##_registrations, rp); \
537 rp->client_index = mp->client_index; \
538 rp->client_pid = mp->pid; \
539 hash_set (vam->lca##_registration_hash, rp->client_index, \
540 rp - vam->lca##_registrations); \
543 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
546 pub_sub_handler (interface_events,INTERFACE_EVENTS)
547 pub_sub_handler (from_netconf_server,FROM_NETCONF_SERVER)
548 pub_sub_handler (to_netconf_server,TO_NETCONF_SERVER)
549 pub_sub_handler (from_netconf_client,FROM_NETCONF_CLIENT)
550 pub_sub_handler (to_netconf_client,TO_NETCONF_CLIENT)
551 pub_sub_handler (oam_events,OAM_EVENTS)
553 #define RESOLUTION_EVENT 1
554 #define RESOLUTION_PENDING_EVENT 2
555 #define IP4_ARP_EVENT 3
557 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
558 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
559 static int mpls_ethernet_add_del_tunnel_2_t_handler
560 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
562 void handle_ip4_arp_event (u32 pool_index)
564 vpe_api_main_t * vam = &vpe_api_main;
565 vnet_main_t * vnm = vam->vnet_main;
566 vlib_main_t * vm = vam->vlib_main;
567 vl_api_ip4_arp_event_t * event;
568 vl_api_ip4_arp_event_t * mp;
569 unix_shared_memory_queue_t * q;
571 /* Client can cancel, die, etc. */
572 if (pool_is_free_index (vam->arp_events, pool_index))
575 event = pool_elt_at_index (vam->arp_events, pool_index);
577 q = vl_api_client_index_to_input_queue (event->client_index);
579 (void) vnet_add_del_ip4_arp_change_event
580 (vnm, arp_change_delete_callback,
581 event->pid, &event->address,
582 vpe_resolver_process_node.index, IP4_ARP_EVENT,
583 ~0 /* pool index, notused */, 0 /* is_add */);
587 if (q->cursize < q->maxsize) {
588 mp = vl_msg_api_alloc (sizeof (*mp));
589 memcpy (mp, event, sizeof (*mp));
590 vl_msg_api_send_shmem (q, (u8 *)&mp);
592 static f64 last_time;
594 * Throttle syslog msgs.
595 * It's pretty tempting to just revoke the registration...
597 if (vlib_time_now (vm) > last_time + 10.0) {
598 clib_warning ("arp event for %U to pid %d: queue stuffed!",
599 format_ip4_address, &event->address, event->pid);
600 last_time = vlib_time_now(vm);
606 resolver_process (vlib_main_t * vm,
607 vlib_node_runtime_t * rt,
611 uword *event_data = 0;
613 vpe_api_main_t * vam = &vpe_api_main;
614 pending_route_t * pr;
615 vl_api_ip_add_del_route_t * adr;
616 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
617 u32 * resolution_failures = 0;
622 vlib_process_wait_for_event_or_clock (vm, timeout);
624 event_type = vlib_process_get_events (vm, &event_data);
626 switch (event_type) {
627 case RESOLUTION_PENDING_EVENT:
631 case RESOLUTION_EVENT:
632 for (i = 0; i < vec_len(event_data); i++) {
634 * Resolution events can occur long after the
635 * original request has timed out. $$$ add a cancel
638 if (pool_is_free_index (vam->pending_routes, event_data[i]))
641 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
645 switch (pr->resolve_type) {
646 case RESOLVE_IP4_ADD_DEL_ROUTE:
647 rv = ip4_add_del_route_t_handler (adr);
648 clib_warning ("resolver: add %U/%d via %U %s",
650 (ip4_address_t *)&(adr->dst_address),
651 adr->dst_address_length,
653 (ip4_address_t *)&(adr->next_hop_address),
654 (rv >= 0) ? "succeeded" : "failed");
657 case RESOLVE_IP6_ADD_DEL_ROUTE:
658 rv = ip6_add_del_route_t_handler (adr);
659 clib_warning ("resolver: add %U/%d via %U %s",
661 (ip6_address_t *)&(adr->dst_address),
662 adr->dst_address_length,
664 (ip6_address_t *)&(adr->next_hop_address),
665 (rv >= 0) ? "succeeded" : "failed");
668 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
669 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
670 clib_warning ("resolver: add mpls-o-e via %U %s",
672 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
673 (rv >= 0) ? "succeeded" : "failed");
677 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
679 pool_put (vam->pending_routes, pr);
684 for (i = 0; i < vec_len(event_data); i++)
685 handle_ip4_arp_event (event_data[i]);
688 case ~0: /* timeout, retry pending resolutions */
689 pool_foreach (pr, vam->pending_routes,
695 /* May fail, e.g. due to interface down */
696 switch (pr->resolve_type) {
697 case RESOLVE_IP4_ADD_DEL_ROUTE:
698 e = ip4_probe_neighbor
699 (vm, (ip4_address_t *)&(adr->next_hop_address),
700 ntohl(adr->next_hop_sw_if_index));
703 case RESOLVE_IP6_ADD_DEL_ROUTE:
704 e = ip6_probe_neighbor
705 (vm, (ip6_address_t *)&(adr->next_hop_address),
706 ntohl(adr->next_hop_sw_if_index));
709 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
711 e = ip4_probe_neighbor
713 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
714 pme->resolve_opaque);
718 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
722 clib_error_report (e);
724 adr->resolve_attempts = 1;
726 pme->resolve_attempts = 1;
730 adr->resolve_attempts -= 1;
731 if (adr->resolve_attempts == 0)
732 vec_add1 (resolution_failures,
733 pr - vam->pending_routes);
735 pme->resolve_attempts -= 1;
736 if (pme->resolve_attempts == 0)
737 vec_add1 (resolution_failures,
738 pr - vam->pending_routes);
742 for (i = 0; i < vec_len (resolution_failures); i++) {
743 pr = pool_elt_at_index (vam->pending_routes,
744 resolution_failures[i]);
748 switch (pr->resolve_type) {
749 case RESOLVE_IP4_ADD_DEL_ROUTE:
750 clib_warning ("resolver: add %U/%d via %U retry failure",
752 (ip4_address_t *)&(adr->dst_address),
753 adr->dst_address_length,
755 (ip4_address_t *)&(adr->next_hop_address));
758 case RESOLVE_IP6_ADD_DEL_ROUTE:
759 clib_warning ("resolver: add %U/%d via %U retry failure",
761 (ip6_address_t *)&(adr->dst_address),
762 adr->dst_address_length,
764 (ip6_address_t *)&(adr->next_hop_address));
767 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
768 clib_warning ("resolver: add mpls-o-e via %U retry failure",
770 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
774 clib_warning ("BUG");
776 pool_put(vam->pending_routes, pr);
778 vec_reset_length (resolution_failures);
781 if (pool_elts (vam->pending_routes) == 0)
783 vec_reset_length (event_data);
785 return 0; /* or not */
788 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
789 .function = resolver_process,
790 .type = VLIB_NODE_TYPE_PROCESS,
791 .name = "vpe-route-resolver-process",
794 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
796 ip4_main_t * im = &ip4_main;
797 ip_lookup_main_t * lm = &im->lookup_main;
798 vnet_classify_main_t * cm = &vnet_classify_main;
799 stats_main_t * sm = &stats_main;
800 ip4_add_del_route_args_t a;
801 ip4_address_t next_hop_address;
803 vpe_api_main_t * vam = &vpe_api_main;
804 vnet_main_t * vnm = vam->vnet_main;
805 vlib_main_t * vm = vlib_get_main();
806 pending_route_t * pr;
807 vl_api_ip_add_del_route_t * adr;
811 ip_adjacency_t *nh_adj, *add_adj = 0;
813 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
815 if (mp->create_vrf_if_needed) {
817 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
819 fib_index = f->index;
821 /* No such VRF, and we weren't asked to create one */
822 return VNET_API_ERROR_NO_SUCH_FIB;
828 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
829 ntohl(mp->next_hop_sw_if_index)))
830 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
832 memcpy (next_hop_address.data, mp->next_hop_address,
833 sizeof (next_hop_address.data));
835 /* Arp for the next_hop if necessary */
836 if (mp->is_add && mp->resolve_if_needed) {
838 ip_adjacency_t * adj;
840 lookup_result = ip4_fib_lookup_with_table
841 (im, fib_index, &next_hop_address, 1 /* disable default route */);
843 adj = ip_get_adjacency (lm, lookup_result);
845 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
846 pool_get (vam->pending_routes, pr);
847 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
849 memcpy (adr, mp, sizeof (*adr));
850 /* recursion block, "just in case" */
851 adr->resolve_if_needed = 0;
852 adr->resolve_attempts = ntohl(mp->resolve_attempts);
853 vnet_register_ip4_arp_resolution_event
854 (vnm, &next_hop_address, vpe_resolver_process_node.index,
855 RESOLUTION_EVENT, pr - vam->pending_routes);
857 vlib_process_signal_event
858 (vm, vpe_resolver_process_node.index,
859 RESOLUTION_PENDING_EVENT, 0 /* data */);
861 /* The interface may be down, etc. */
862 e = ip4_probe_neighbor
863 (vm, (ip4_address_t *)&(mp->next_hop_address),
864 ntohl(mp->next_hop_sw_if_index));
867 clib_error_report(e);
869 return VNET_API_ERROR_IN_PROGRESS;
873 if (mp->is_multipath) {
876 dslock (sm, 1 /* release hint */, 10 /* tag */);
879 flags = IP4_ROUTE_FLAG_ADD;
881 flags = IP4_ROUTE_FLAG_DEL;
884 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
886 ip4_add_del_route_next_hop (im, flags,
887 (ip4_address_t *) mp->dst_address,
888 (u32) mp->dst_address_length,
889 (ip4_address_t *) mp->next_hop_address,
890 ntohl(mp->next_hop_sw_if_index),
891 (u32) mp->next_hop_weight,
898 memset (&a, 0, sizeof (a));
899 memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
901 a.dst_address_length = mp->dst_address_length;
903 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
904 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
905 a.table_index_or_table_id = fib_index;
910 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
912 dslock (sm, 1 /* release hint */, 2 /* tag */);
916 ai = lm->drop_adj_index;
917 else if (mp->is_local)
918 ai = lm->local_adj_index;
919 else if (mp->is_classify) {
921 memset(&cadj, 0, sizeof(cadj));
922 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
923 cadj.classify_table_index = ntohl(mp->classify_table_index);
924 if (pool_is_free_index (cm->tables, cadj.classify_table_index)) {
926 return VNET_API_ERROR_NO_SUCH_TABLE;
928 vec_add1 (add_adj, cadj);
932 ai = ip4_fib_lookup_with_table
933 (im, fib_index, &next_hop_address,
934 1 /* disable default route */);
935 if (ai == lm->miss_adj_index) {
937 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
941 nh_adj = ip_get_adjacency (lm, ai);
942 vec_add1 (add_adj, nh_adj[0]);
943 if (mp->lookup_in_vrf) {
944 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
946 add_adj[0].explicit_fib_index = p[0];
950 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
954 ip_adjacency_t * adj;
955 int disable_default_route = 1;
957 /* Trying to delete the default route? */
958 if (a.dst_address.as_u32 == 0 &&
959 a.dst_address_length == 0)
960 disable_default_route = 0;
962 ai = ip4_fib_lookup_with_table
963 (im, fib_index, &a.dst_address, disable_default_route);
964 if (ai == lm->miss_adj_index) {
966 return VNET_API_ERROR_UNKNOWN_DESTINATION;
969 adj = ip_get_adjacency (lm, ai);
970 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
972 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
979 a.n_add_adj = vec_len(add_adj);
980 ip4_add_del_route (im, &a);
988 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
990 ip6_main_t * im = &ip6_main;
991 ip_lookup_main_t * lm = &im->lookup_main;
992 vnet_main_t * vnm = vnet_get_main();
993 vlib_main_t * vm = vlib_get_main();
994 vpe_api_main_t * vam = &vpe_api_main;
995 stats_main_t * sm = &stats_main;
996 ip6_add_del_route_args_t a;
997 ip6_address_t next_hop_address;
998 pending_route_t * pr;
999 vl_api_ip_add_del_route_t * adr;
1004 ip_adjacency_t * nh_adj, * add_adj = 0;
1007 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1010 if (mp->create_vrf_if_needed) {
1012 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1014 fib_index = f->index;
1016 /* No such VRF, and we weren't asked to create one */
1017 return VNET_API_ERROR_NO_SUCH_FIB;
1023 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1024 ntohl(mp->next_hop_sw_if_index)))
1025 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1027 memcpy (next_hop_address.as_u8, mp->next_hop_address,
1028 sizeof (next_hop_address.as_u8));
1030 /* Arp for the next_hop if necessary */
1031 if (mp->is_add && mp->resolve_if_needed) {
1033 ip_adjacency_t * adj;
1035 lookup_result = ip6_fib_lookup_with_table
1036 (im, fib_index, &next_hop_address);
1038 adj = ip_get_adjacency (lm, lookup_result);
1040 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1041 pool_get (vam->pending_routes, pr);
1043 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1044 memcpy (adr, mp, sizeof (*adr));
1045 /* recursion block, "just in case" */
1046 adr->resolve_if_needed = 0;
1047 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1048 vnet_register_ip6_neighbor_resolution_event
1049 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1050 RESOLUTION_EVENT, pr - vam->pending_routes);
1052 vlib_process_signal_event
1053 (vm, vpe_resolver_process_node.index,
1054 RESOLUTION_PENDING_EVENT, 0 /* data */);
1056 /* The interface may be down, etc. */
1057 e = ip6_probe_neighbor
1058 (vm, (ip6_address_t *)&(mp->next_hop_address),
1059 ntohl(mp->next_hop_sw_if_index));
1062 clib_error_report(e);
1064 return VNET_API_ERROR_IN_PROGRESS;
1068 if (mp->is_multipath) {
1071 dslock (sm, 1 /* release hint */, 11 /* tag */);
1074 flags = IP6_ROUTE_FLAG_ADD;
1076 flags = IP6_ROUTE_FLAG_DEL;
1079 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1081 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1082 (u32) mp->dst_address_length,
1083 (ip6_address_t *)mp->next_hop_address,
1084 ntohl(mp->next_hop_sw_if_index),
1085 (u32) mp->next_hop_weight,
1092 memset (&a, 0, sizeof (a));
1093 memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1095 a.dst_address_length = mp->dst_address_length;
1097 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1098 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1099 a.table_index_or_table_id = fib_index;
1104 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1106 dslock (sm, 1 /* release hint */, 3 /* tag */);
1110 ai = lm->drop_adj_index;
1111 else if (mp->is_local)
1112 ai = lm->local_adj_index;
1114 ai = ip6_fib_lookup_with_table
1115 (im, fib_index, &next_hop_address);
1116 if (ai == lm->miss_adj_index) {
1118 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1122 nh_adj = ip_get_adjacency (lm, ai);
1123 vec_add1 (add_adj, nh_adj[0]);
1124 if (mp->lookup_in_vrf) {
1125 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1127 add_adj[0].explicit_fib_index = p[0];
1131 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1135 ip_adjacency_t * adj;
1137 ai = ip6_fib_lookup_with_table
1138 (im, fib_index, &a.dst_address);
1139 if (ai == lm->miss_adj_index) {
1141 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1143 adj = ip_get_adjacency (lm, ai);
1144 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1146 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1151 a.add_adj = add_adj;
1152 a.n_add_adj = vec_len(add_adj);
1153 ip6_add_del_route (im, &a);
1161 void vl_api_ip_add_del_route_t_handler (
1162 vl_api_ip_add_del_route_t *mp)
1164 vl_api_ip_add_del_route_reply_t * rmp;
1166 vnet_main_t * vnm = vnet_get_main();
1171 rv = ip6_add_del_route_t_handler (mp);
1173 rv = ip4_add_del_route_t_handler (mp);
1175 rv = (rv == 0) ? vnm->api_errno : rv;
1177 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1180 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1181 u32 sw_if_index, u8 *next_hop_addr)
1183 vl_api_ip_add_del_route_t mp;
1186 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1189 * Configure default IP route:
1190 * - ip route add 0.0.0.0/1 via <GW IP>
1191 * - ip route add 128.0.0.0/1 via <GW IP>
1193 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1195 mp.resolve_attempts = ~0;
1196 mp.resolve_if_needed = 1;
1198 mp.is_ipv6 = is_ipv6;
1199 mp.next_hop_weight = 1;
1201 memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1204 rv = ip6_add_del_route_t_handler (&mp);
1207 mp.dst_address_length = 1;
1209 mp.dst_address[0] = 0;
1210 rv = ip4_add_del_route_t_handler (&mp);
1212 mp.dst_address[0] = 128;
1213 rv |= ip4_add_del_route_t_handler (&mp);
1217 clib_error_return (0, "failed to config default IP route");
1222 vl_api_sw_interface_add_del_address_t_handler
1223 (vl_api_sw_interface_add_del_address_t *mp)
1225 vlib_main_t *vm = vlib_get_main();
1226 vl_api_sw_interface_add_del_address_reply_t * rmp;
1230 VALIDATE_SW_IF_INDEX(mp);
1232 is_del = mp->is_add == 0;
1235 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1236 else if (mp->is_ipv6)
1237 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1238 (void *)mp->address,
1239 mp->address_length, is_del);
1241 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1242 (void *) mp->address,
1243 mp->address_length, is_del);
1245 BAD_SW_IF_INDEX_LABEL;
1247 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1251 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1254 u32 table_id = ntohl(mp->vrf_id);
1255 u32 sw_if_index = ntohl(mp->sw_if_index);
1256 vl_api_sw_interface_set_table_reply_t * rmp;
1257 stats_main_t * sm = &stats_main;
1259 VALIDATE_SW_IF_INDEX(mp);
1261 dslock (sm, 1 /* release hint */, 4 /* tag */);
1264 ip6_main_t * im = &ip6_main;
1266 find_ip6_fib_by_table_index_or_id (im, table_id,
1267 IP6_ROUTE_FLAG_TABLE_ID);
1269 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1270 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1272 rv = VNET_API_ERROR_NO_SUCH_FIB;
1275 ip4_main_t * im = &ip4_main;
1276 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1277 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1279 /* Truthfully this can't fail */
1281 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1282 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1284 rv = VNET_API_ERROR_NO_SUCH_FIB;
1289 BAD_SW_IF_INDEX_LABEL;
1291 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1295 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1297 vlib_main_t *vm = vlib_get_main();
1298 vl_api_sw_interface_set_vpath_reply_t * rmp;
1301 u32 sw_if_index = ntohl(mp->sw_if_index);
1302 ip4_main_t *ip4m = &ip4_main;
1303 ip6_main_t *ip6m = &ip6_main;
1304 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1305 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1306 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1307 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1308 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1309 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1311 VALIDATE_SW_IF_INDEX(mp);
1313 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1315 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1316 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1317 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1318 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1319 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1320 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1321 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1322 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1323 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1324 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1325 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1326 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1327 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1328 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1329 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1330 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1332 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1333 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1334 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1335 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1336 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1337 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1338 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1339 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1340 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1341 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1342 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1343 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1344 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1345 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1346 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1347 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1350 BAD_SW_IF_INDEX_LABEL;
1352 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1356 vl_api_sw_interface_set_l2_xconnect_t_handler (
1357 vl_api_sw_interface_set_l2_xconnect_t *mp)
1359 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1361 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1362 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1363 vlib_main_t *vm = vlib_get_main();
1364 vnet_main_t *vnm = vnet_get_main();
1366 VALIDATE_RX_SW_IF_INDEX(mp);
1369 VALIDATE_TX_SW_IF_INDEX(mp);
1370 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1371 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1373 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1376 BAD_RX_SW_IF_INDEX_LABEL;
1377 BAD_TX_SW_IF_INDEX_LABEL;
1379 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1383 vl_api_sw_interface_set_l2_bridge_t_handler (
1384 vl_api_sw_interface_set_l2_bridge_t *mp)
1386 bd_main_t * bdm = &bd_main;
1387 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1389 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1390 u32 bd_id = ntohl(mp->bd_id);
1394 vlib_main_t *vm = vlib_get_main();
1395 vnet_main_t *vnm = vnet_get_main();
1397 VALIDATE_RX_SW_IF_INDEX(mp);
1399 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1402 //VALIDATE_TX_SW_IF_INDEX(mp);
1403 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1404 rx_sw_if_index, bd_index, bvi, shg, 0);
1406 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1409 BAD_RX_SW_IF_INDEX_LABEL;
1411 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1415 vl_api_bridge_domain_add_del_t_handler (
1416 vl_api_bridge_domain_add_del_t *mp)
1418 vlib_main_t * vm = vlib_get_main ();
1419 bd_main_t * bdm = &bd_main;
1420 vl_api_bridge_domain_add_del_reply_t * rmp;
1422 u32 enable_flags = 0, disable_flags = 0;
1423 u32 bd_id = ntohl(mp->bd_id);
1427 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1430 enable_flags |= L2_FLOOD;
1432 disable_flags |= L2_FLOOD;
1435 enable_flags |= L2_UU_FLOOD;
1437 disable_flags |= L2_UU_FLOOD;
1440 enable_flags |= L2_FWD;
1442 disable_flags |= L2_FWD;
1445 enable_flags |= L2_ARP_TERM;
1447 disable_flags |= L2_ARP_TERM;
1450 enable_flags |= L2_LEARN;
1452 disable_flags |= L2_LEARN;
1455 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1458 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1461 rv = bd_delete_bd_index(bdm, bd_id);
1463 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1466 static void vl_api_bridge_domain_details_t_handler (
1467 vl_api_bridge_domain_details_t * mp)
1469 clib_warning ("BUG");
1472 static void vl_api_bridge_domain_sw_if_details_t_handler (
1473 vl_api_bridge_domain_sw_if_details_t * mp)
1475 clib_warning ("BUG");
1478 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1479 l2_bridge_domain_t * bd_config,
1482 vl_api_bridge_domain_details_t * mp;
1484 mp = vl_msg_api_alloc (sizeof (*mp));
1485 memset (mp, 0, sizeof (*mp));
1486 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1487 mp->bd_id = ntohl (bd_config->bd_id);
1488 mp->flood = bd_feature_flood (bd_config);
1489 mp->uu_flood = bd_feature_uu_flood (bd_config);
1490 mp->forward = bd_feature_forward (bd_config);
1491 mp->learn = bd_feature_learn (bd_config);
1492 mp->arp_term = bd_feature_arp_term (bd_config);
1493 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1494 mp->n_sw_ifs = ntohl (n_sw_ifs);
1496 vl_msg_api_send_shmem (q, (u8 *)&mp);
1499 static void send_bd_sw_if_details (l2input_main_t * l2im,
1500 unix_shared_memory_queue_t *q,
1501 l2_flood_member_t * member, u32 bd_id)
1503 vl_api_bridge_domain_sw_if_details_t * mp;
1504 l2_input_config_t * input_cfg;
1506 mp = vl_msg_api_alloc (sizeof (*mp));
1507 memset (mp, 0, sizeof (*mp));
1508 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1509 mp->bd_id = ntohl (bd_id);
1510 mp->sw_if_index = ntohl (member->sw_if_index);
1511 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1512 mp->shg = input_cfg->shg;
1514 vl_msg_api_send_shmem (q, (u8 *)&mp);
1517 static void vl_api_bridge_domain_dump_t_handler (
1518 vl_api_bridge_domain_dump_t *mp)
1520 bd_main_t * bdm = &bd_main;
1521 l2input_main_t * l2im = &l2input_main;
1522 unix_shared_memory_queue_t * q;
1523 l2_bridge_domain_t * bd_config;
1524 u32 bd_id, bd_index;
1527 q = vl_api_client_index_to_input_queue (mp->client_index);
1532 bd_id = ntohl(mp->bd_id);
1534 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1535 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1536 for (; bd_index < end; bd_index++) {
1537 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1538 /* skip dummy bd_id 0 */
1539 if (bd_config && (bd_config->bd_id > 0)) {
1541 l2_flood_member_t * m;
1543 n_sw_ifs = vec_len (bd_config->members);
1544 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1546 vec_foreach (m, bd_config->members) {
1547 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1554 vl_api_l2fib_add_del_t_handler (
1555 vl_api_l2fib_add_del_t *mp)
1557 bd_main_t * bdm = &bd_main;
1558 l2input_main_t * l2im = &l2input_main;
1559 vl_api_l2fib_add_del_reply_t * rmp;
1562 u32 sw_if_index = ntohl(mp->sw_if_index);
1563 u32 bd_id = ntohl(mp->bd_id);
1571 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1573 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1574 goto bad_sw_if_index;
1579 VALIDATE_SW_IF_INDEX(mp);
1580 if (vec_len(l2im->configs) <= sw_if_index) {
1581 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1582 goto bad_sw_if_index;
1584 l2_input_config_t * config;
1585 config = vec_elt_at_index(l2im->configs, sw_if_index);
1586 if (config->bridge == 0) {
1587 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1588 goto bad_sw_if_index;
1591 static_mac = mp->static_mac ? 1 : 0;
1592 filter_mac = mp->filter_mac ? 1 : 0;
1593 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1596 l2fib_del_entry(mac, bd_index);
1599 BAD_SW_IF_INDEX_LABEL;
1601 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1605 vl_api_l2_flags_t_handler (
1606 vl_api_l2_flags_t *mp)
1608 vl_api_l2_flags_reply_t * rmp;
1610 u32 sw_if_index = ntohl(mp->sw_if_index);
1611 u32 flags = ntohl(mp->feature_bitmap);
1614 VALIDATE_SW_IF_INDEX(mp);
1617 if (flags & L2INPUT_FEAT_ ## a) \
1618 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1619 foreach_l2input_feat;
1622 BAD_SW_IF_INDEX_LABEL;
1624 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1628 vl_api_bridge_flags_t_handler (
1629 vl_api_bridge_flags_t *mp)
1631 vlib_main_t *vm = vlib_get_main();
1632 bd_main_t * bdm = &bd_main;
1633 vl_api_bridge_flags_reply_t * rmp;
1635 u32 bd_id = ntohl(mp->bd_id);
1637 u32 flags = ntohl(mp->feature_bitmap);
1640 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1642 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1648 bd_set_flags(vm, bd_index, flags, mp->is_set);
1651 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1652 rmp->resulting_feature_bitmap = ntohl(flags));
1656 vl_api_bd_ip_mac_add_del_t_handler (
1657 vl_api_bd_ip_mac_add_del_t *mp)
1659 bd_main_t * bdm = &bd_main;
1660 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1662 u32 bd_id = ntohl(mp->bd_id);
1666 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1668 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1673 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1674 mp->mac_address, mp->is_ipv6, mp->is_add))
1675 rv = VNET_API_ERROR_UNSPECIFIED;
1678 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1682 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1685 vl_api_tap_connect_reply_t * rmp;
1686 unix_shared_memory_queue_t * q;
1687 u32 sw_if_index = (u32)~0;
1689 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1690 mp->use_random_mac ? 0 : mp->mac_address,
1691 &sw_if_index, mp->renumber,
1692 ntohl(mp->custom_dev_instance));
1694 q = vl_api_client_index_to_input_queue (mp->client_index);
1698 rmp = vl_msg_api_alloc (sizeof (*rmp));
1699 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1700 rmp->context = mp->context;
1701 rmp->retval = ntohl(rv);
1702 rmp->sw_if_index = ntohl(sw_if_index);
1704 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1708 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1711 vl_api_tap_modify_reply_t * rmp;
1712 unix_shared_memory_queue_t * q;
1713 u32 sw_if_index = (u32)~0;
1715 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1716 mp->use_random_mac ? 0 : mp->mac_address,
1717 &sw_if_index, mp->renumber,
1718 ntohl(mp->custom_dev_instance));
1720 q = vl_api_client_index_to_input_queue (mp->client_index);
1724 rmp = vl_msg_api_alloc (sizeof (*rmp));
1725 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1726 rmp->context = mp->context;
1727 rmp->retval = ntohl(rv);
1728 rmp->sw_if_index = ntohl(sw_if_index);
1730 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1734 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1737 vpe_api_main_t * vam = &vpe_api_main;
1738 vl_api_tap_delete_reply_t * rmp;
1739 unix_shared_memory_queue_t * q;
1740 u32 sw_if_index = ntohl(mp->sw_if_index);
1742 rv = vnet_tap_delete (vm, sw_if_index);
1744 q = vl_api_client_index_to_input_queue (mp->client_index);
1748 rmp = vl_msg_api_alloc (sizeof (*rmp));
1749 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1750 rmp->context = mp->context;
1751 rmp->retval = ntohl(rv);
1753 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1756 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1760 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1762 vl_api_create_vlan_subif_reply_t * rmp;
1763 vnet_main_t * vnm = vnet_get_main();
1764 u32 hw_if_index, sw_if_index = (u32)~0;
1765 vnet_hw_interface_t * hi;
1768 vnet_sw_interface_t template;
1770 vnet_interface_main_t * im = &vnm->interface_main;
1771 u64 sup_and_sub_key;
1773 unix_shared_memory_queue_t * q;
1774 clib_error_t * error;
1776 VALIDATE_SW_IF_INDEX(mp);
1778 hw_if_index = ntohl(mp->sw_if_index);
1779 hi = vnet_get_hw_interface (vnm, hw_if_index);
1781 id = ntohl(mp->vlan_id);
1782 if (id == 0 || id > 4095) {
1783 rv = VNET_API_ERROR_INVALID_VLAN;
1787 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1789 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1791 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1795 kp = clib_mem_alloc (sizeof (*kp));
1796 *kp = sup_and_sub_key;
1798 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1799 template.sup_sw_if_index = hi->sw_if_index;
1800 template.sub.id = id;
1801 template.sub.eth.raw_flags = 0;
1802 template.sub.eth.flags.one_tag = 1;
1803 template.sub.eth.outer_vlan_id = id;
1804 template.sub.eth.flags.exact_match = 1;
1806 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1808 clib_error_report(error);
1809 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1812 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1813 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1815 BAD_SW_IF_INDEX_LABEL;
1818 q = vl_api_client_index_to_input_queue (mp->client_index);
1822 rmp = vl_msg_api_alloc (sizeof (*rmp));
1823 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1824 rmp->context = mp->context;
1825 rmp->retval = ntohl(rv);
1826 rmp->sw_if_index = ntohl(sw_if_index);
1827 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1831 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1833 vl_api_create_subif_reply_t * rmp;
1834 vnet_main_t * vnm = vnet_get_main();
1835 u32 sw_if_index = ~0;
1838 vnet_sw_interface_t *si;
1839 vnet_hw_interface_t *hi;
1840 vnet_sw_interface_t template;
1842 vnet_interface_main_t * im = &vnm->interface_main;
1843 u64 sup_and_sub_key;
1845 clib_error_t * error;
1847 VALIDATE_SW_IF_INDEX(mp);
1849 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1850 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1852 sw_if_index = si->sw_if_index;
1853 sub_id = ntohl(mp->sub_id);
1855 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1857 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1860 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1861 sw_if_index, sub_id);
1862 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1866 kp = clib_mem_alloc (sizeof (*kp));
1867 *kp = sup_and_sub_key;
1869 memset (&template, 0, sizeof (template));
1870 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1871 template.sup_sw_if_index = sw_if_index;
1872 template.sub.id = sub_id;
1873 template.sub.eth.flags.no_tags = mp->no_tags;
1874 template.sub.eth.flags.one_tag = mp->one_tag;
1875 template.sub.eth.flags.two_tags = mp->two_tags;
1876 template.sub.eth.flags.dot1ad = mp->dot1ad;
1877 template.sub.eth.flags.exact_match = mp->exact_match;
1878 template.sub.eth.flags.default_sub = mp->default_sub;
1879 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1880 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1881 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1882 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1884 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1886 clib_error_report (error);
1887 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1891 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1892 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1894 BAD_SW_IF_INDEX_LABEL;
1898 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1900 rmp->sw_if_index = ntohl(sw_if_index);
1905 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1907 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1909 stats_main_t * sm = &stats_main;
1910 u32 tunnel_sw_if_index = ~0;
1912 dslock (sm, 1 /* release hint */, 5 /* tag */);
1914 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1915 (ip4_address_t *)(mp->dst_address),
1916 (ip4_address_t *)(mp->intfc_address),
1917 (u32)(mp->intfc_address_length),
1918 ntohl(mp->inner_vrf_id),
1919 ntohl(mp->outer_vrf_id),
1920 &tunnel_sw_if_index,
1925 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1927 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1932 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1933 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1935 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1937 stats_main_t * sm = &stats_main;
1938 u32 tunnel_sw_if_index;
1940 dslock (sm, 1 /* release hint */, 5 /* tag */);
1942 rv = vnet_mpls_ethernet_add_del_tunnel
1943 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1944 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1945 ntohl(mp->tx_sw_if_index),
1946 &tunnel_sw_if_index,
1952 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1954 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1959 * This piece of misery brought to you because the control-plane
1960 * can't figure out the tx interface + dst-mac address all by itself
1962 static int mpls_ethernet_add_del_tunnel_2_t_handler
1963 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1965 pending_route_t * pr;
1966 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1967 vnet_main_t * vnm = vnet_get_main();
1968 vlib_main_t * vm = vlib_get_main();
1969 stats_main_t * sm = &stats_main;
1970 vpe_api_main_t * vam = &vpe_api_main;
1971 u32 inner_fib_index, outer_fib_index;
1972 ip4_main_t * im = &ip4_main;
1973 ip_lookup_main_t * lm = &im->lookup_main;
1974 ip_adjacency_t * adj = 0;
1977 u8 * dst_mac_address;
1981 u32 tunnel_sw_if_index;
1983 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
1985 return VNET_API_ERROR_NO_SUCH_FIB;
1987 outer_fib_index = p[0];
1990 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
1992 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1994 inner_fib_index = p[0];
1996 if (inner_fib_index == outer_fib_index)
1997 return VNET_API_ERROR_INVALID_VALUE;
1999 lookup_result = ip4_fib_lookup_with_table
2000 (im, outer_fib_index,
2001 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2002 1 /* disable default route */);
2004 adj = ip_get_adjacency (lm, lookup_result);
2005 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2007 if (mp->is_add && mp->resolve_if_needed) {
2008 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2009 pool_get (vam->pending_routes, pr);
2010 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2012 memcpy (pme, mp, sizeof (*pme));
2013 /* recursion block, "just in case" */
2014 pme->resolve_if_needed = 0;
2015 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2016 pme->resolve_opaque = tx_sw_if_index;
2017 vnet_register_ip4_arp_resolution_event
2019 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2020 vpe_resolver_process_node.index,
2021 RESOLUTION_EVENT, pr - vam->pending_routes);
2023 vlib_process_signal_event
2024 (vm, vpe_resolver_process_node.index,
2025 RESOLUTION_PENDING_EVENT, 0 /* data */);
2027 /* The interface may be down, etc. */
2028 e = ip4_probe_neighbor
2029 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2033 clib_error_report(e);
2035 return VNET_API_ERROR_IN_PROGRESS;
2039 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2040 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2043 vnet_rewrite_get_data_internal
2044 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2046 dslock (sm, 1 /* release hint */, 10 /* tag */);
2048 rv = vnet_mpls_ethernet_add_del_tunnel
2049 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2050 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2051 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2059 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2060 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2062 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2065 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2067 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2072 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2074 vl_api_mpls_add_del_encap_reply_t * rmp;
2076 static u32 * labels;
2079 vec_reset_length (labels);
2081 for (i = 0; i < mp->nlabels; i++)
2082 vec_add1 (labels, ntohl(mp->labels[i]));
2085 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2086 ntohl(mp->vrf_id), labels,
2087 ~0 /* policy_tunnel_index */,
2088 0 /* no_dst_hash */,
2092 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2096 vl_api_mpls_add_del_decap_t_handler
2097 (vl_api_mpls_add_del_decap_t *mp)
2099 vl_api_mpls_add_del_decap_reply_t * rmp;
2102 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2103 ntohl(mp->label), ntohl(mp->next_index),
2104 mp->s_bit, mp->is_add);
2106 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2110 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2112 vl_api_proxy_arp_add_del_reply_t * rmp;
2115 ip4_main_t * im = &ip4_main;
2116 stats_main_t * sm = &stats_main;
2117 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2118 ip4_address_t *hi_addr,
2119 u32 fib_index, int is_del);
2122 dslock (sm, 1 /* release hint */, 6 /* tag */);
2124 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2127 rv = VNET_API_ERROR_NO_SUCH_FIB;
2133 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2134 (ip4_address_t *)mp->hi_address,
2135 fib_index, mp->is_add == 0);
2139 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2143 vl_api_proxy_arp_intfc_enable_disable_t_handler
2144 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2147 vnet_main_t * vnm = vnet_get_main();
2148 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2149 vnet_sw_interface_t * si;
2152 VALIDATE_SW_IF_INDEX(mp);
2154 sw_if_index = ntohl(mp->sw_if_index);
2156 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2158 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2162 si = vnet_get_sw_interface (vnm, sw_if_index);
2166 if (mp->enable_disable)
2167 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2169 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2171 BAD_SW_IF_INDEX_LABEL;
2174 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2178 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2180 vl_api_ip_neighbor_add_del_reply_t * rmp;
2181 vnet_main_t * vnm = vnet_get_main();
2184 stats_main_t * sm = &stats_main;
2186 VALIDATE_SW_IF_INDEX(mp);
2188 dslock (sm, 1 /* release hint */, 7 /* tag */);
2192 rv = vnet_set_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 rv = vnet_unset_ip6_ethernet_neighbor
2198 (vm, ntohl(mp->sw_if_index),
2199 (ip6_address_t *)(mp->dst_address),
2200 mp->mac_address, sizeof(mp->mac_address));
2202 ip4_main_t * im = &ip4_main;
2203 ip_lookup_main_t * lm = &im->lookup_main;
2204 ethernet_arp_ip4_over_ethernet_address_t a;
2206 ip_adjacency_t *nh_adj;
2208 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2210 rv = VNET_API_ERROR_NO_SUCH_FIB;
2216 * Unfortunately, folks have a penchant for
2217 * adding interface addresses to the ARP cache, and
2218 * wondering why the forwarder eventually ASSERTs...
2220 ai = ip4_fib_lookup_with_table
2221 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2222 1 /* disable default route */);
2225 nh_adj = ip_get_adjacency (lm, ai);
2226 /* Never allow manipulation of a local adj! */
2227 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2228 clib_warning("%U matches local adj",
2230 (ip4_address_t *)(mp->dst_address));
2231 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2236 memcpy (&a.ethernet, mp->mac_address, 6);
2237 memcpy (&a.ip4, mp->dst_address, 4);
2240 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2241 fib_index, &a, mp->is_static);
2243 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2247 BAD_SW_IF_INDEX_LABEL;
2250 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2254 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2257 vpe_main_t *rm = &vpe_main;
2258 ip4_main_t *im4 = &ip4_main;
2259 ip6_main_t *im6 = &ip6_main;
2260 ip_lookup_main_t * lm;
2265 u32 adj_index, sw_if_index;
2266 vl_api_is_address_reachable_t *rmp;
2267 ip_adjacency_t * adj;
2268 unix_shared_memory_queue_t *q;
2270 q = vl_api_client_index_to_input_queue (mp->client_index);
2272 increment_missing_api_client_counter (rm->vlib_main);
2276 rmp = vl_msg_api_alloc (sizeof (*rmp));
2277 memcpy (rmp, mp, sizeof (*rmp));
2279 sw_if_index = mp->next_hop_sw_if_index;
2280 memcpy (&addr, mp->address, sizeof (addr));
2282 lm = &im6->lookup_main;
2284 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2286 lm = &im4->lookup_main;
2288 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2290 if (adj_index == ~0) {
2294 adj = ip_get_adjacency (lm, adj_index);
2296 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2297 && adj->rewrite_header.sw_if_index == sw_if_index) {
2300 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2301 && adj->rewrite_header.sw_if_index == sw_if_index) {
2303 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2305 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2306 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2314 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2318 static void vl_api_sw_interface_details_t_handler (
2319 vl_api_sw_interface_details_t * mp)
2321 clib_warning ("BUG");
2324 static void vl_api_sw_interface_set_flags_t_handler (
2325 vl_api_sw_interface_set_flags_t * mp)
2327 vl_api_sw_interface_set_flags_reply_t *rmp;
2328 vnet_main_t * vnm = vnet_get_main();
2330 clib_error_t * error;
2333 VALIDATE_SW_IF_INDEX(mp);
2335 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2337 error = vnet_sw_interface_set_flags (vnm,
2338 ntohl(mp->sw_if_index),
2342 clib_error_report (error);
2345 BAD_SW_IF_INDEX_LABEL;
2346 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2349 static void send_sw_interface_details (vpe_api_main_t * am,
2350 unix_shared_memory_queue_t *q,
2351 vnet_sw_interface_t * swif,
2352 u8 * interface_name)
2354 vl_api_sw_interface_details_t * mp;
2355 vnet_hw_interface_t * hi;
2357 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2359 mp = vl_msg_api_alloc (sizeof (*mp));
2360 memset (mp, 0, sizeof (*mp));
2361 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2362 mp->sw_if_index = ntohl(swif->sw_if_index);
2363 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2364 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2366 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2368 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2369 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2370 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2371 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2373 strncpy ((char *) mp->interface_name,
2374 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2376 /* Send the L2 address for ethernet physical intfcs */
2377 if (swif->sup_sw_if_index == swif->sw_if_index
2378 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2379 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2380 ethernet_interface_t *ei;
2382 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2383 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2384 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2385 mp->l2_address_length = ntohl(sizeof (ei->address));
2386 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2387 vnet_sub_interface_t *sub = &swif->sub;
2388 mp->sub_id = ntohl(sub->id);
2389 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2390 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2391 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2392 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2393 mp->sub_exact_match = sub->eth.flags.exact_match;
2394 mp->sub_default = sub->eth.flags.default_sub;
2395 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2396 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2398 /* vlan tag rewrite data */
2399 u32 vtr_op = L2_VTR_DISABLED;
2400 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2402 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2403 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2404 // error - default to disabled
2405 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2406 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2409 mp->vtr_op = ntohl(vtr_op);
2410 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2411 mp->vtr_tag1 = ntohl(vtr_tag1);
2412 mp->vtr_tag2 = ntohl(vtr_tag2);
2416 vl_msg_api_send_shmem (q, (u8 *)&mp);
2419 static void send_sw_interface_flags (vpe_api_main_t * am,
2420 unix_shared_memory_queue_t *q,
2421 vnet_sw_interface_t * swif)
2423 vl_api_sw_interface_set_flags_t *mp;
2424 vnet_main_t * vnm = am->vnet_main;
2426 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2428 mp = vl_msg_api_alloc (sizeof (*mp));
2429 memset (mp, 0, sizeof (*mp));
2430 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2431 mp->sw_if_index = ntohl(swif->sw_if_index);
2433 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2435 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2437 vl_msg_api_send_shmem (q, (u8 *)&mp);
2440 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2441 unix_shared_memory_queue_t *q,
2443 __attribute__((unused));
2445 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2446 unix_shared_memory_queue_t *q,
2449 vl_api_sw_interface_set_flags_t *mp;
2451 mp = vl_msg_api_alloc (sizeof (*mp));
2452 memset (mp, 0, sizeof (*mp));
2453 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2454 mp->sw_if_index = ntohl(sw_if_index);
2456 mp->admin_up_down = 0;
2457 mp->link_up_down = 0;
2459 vl_msg_api_send_shmem (q, (u8 *)&mp);
2462 static void vl_api_sw_interface_dump_t_handler (
2463 vl_api_sw_interface_dump_t *mp)
2465 vpe_api_main_t * am = &vpe_api_main;
2466 vnet_sw_interface_t * swif;
2467 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2468 u8 * filter_string = 0, * name_string = 0;
2469 unix_shared_memory_queue_t * q;
2470 char * strcasestr (char *, char *); /* lnx hdr file botch */
2472 q = vl_api_client_index_to_input_queue (mp->client_index);
2477 if (mp->name_filter_valid) {
2478 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2479 filter_string = format (0, "%s%c", mp->name_filter, 0);
2482 pool_foreach (swif, im->sw_interfaces,
2484 name_string = format (name_string, "%U%c",
2485 format_vnet_sw_interface_name,
2486 am->vnet_main, swif, 0);
2488 if (mp->name_filter_valid == 0 ||
2489 strcasestr((char *) name_string, (char *) filter_string)) {
2491 send_sw_interface_details (am, q, swif, name_string);
2492 send_sw_interface_flags (am, q, swif);
2494 _vec_len (name_string) = 0;
2497 vec_free (name_string);
2498 vec_free (filter_string);
2501 void send_oam_event (oam_target_t * t)
2503 vpe_api_main_t * vam = &vpe_api_main;
2504 unix_shared_memory_queue_t * q;
2505 vpe_client_registration_t *reg;
2506 vl_api_oam_event_t * mp;
2508 pool_foreach(reg, vam->oam_events_registrations,
2510 q = vl_api_client_index_to_input_queue (reg->client_index);
2512 mp = vl_msg_api_alloc (sizeof (*mp));
2513 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2514 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2515 mp->state = t->state;
2516 vl_msg_api_send_shmem (q, (u8 *)&mp);
2522 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2524 vl_api_oam_add_del_reply_t * rmp;
2527 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2528 (ip4_address_t *)mp->dst_address,
2532 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2536 vl_api_vnet_get_summary_stats_t_handler (
2537 vl_api_vnet_get_summary_stats_t *mp)
2539 stats_main_t * sm = &stats_main;
2540 vnet_interface_main_t * im = sm->interface_main;
2541 vl_api_vnet_summary_stats_reply_t *rmp;
2542 vlib_combined_counter_main_t * cm;
2545 u64 total_pkts[VLIB_N_RX_TX];
2546 u64 total_bytes[VLIB_N_RX_TX];
2548 unix_shared_memory_queue_t * q =
2549 vl_api_client_index_to_input_queue (mp->client_index);
2554 rmp = vl_msg_api_alloc (sizeof (*rmp));
2555 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2556 rmp->context = mp->context;
2559 memset (total_pkts, 0, sizeof (total_pkts));
2560 memset (total_bytes, 0, sizeof (total_bytes));
2562 vnet_interface_counter_lock (im);
2564 vec_foreach (cm, im->combined_sw_if_counters) {
2565 which = cm - im->combined_sw_if_counters;
2567 for (i = 0; i < vec_len (cm->maxi); i++) {
2568 vlib_get_combined_counter (cm, i, &v);
2569 total_pkts[which] += v.packets;
2570 total_bytes[which] += v.bytes;
2573 vnet_interface_counter_unlock (im);
2575 /* Note: in HOST byte order! */
2576 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2577 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2578 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2579 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2580 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2582 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2585 typedef CLIB_PACKED (struct {
2586 ip4_address_t address;
2588 u32 address_length : 6;
2593 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2595 vnet_main_t * vnm = vnet_get_main();
2596 vnet_interface_main_t * im = &vnm->interface_main;
2597 ip4_main_t * im4 = &ip4_main;
2598 static ip4_route_t * routes;
2599 static u32 * sw_if_indices_to_shut;
2600 stats_main_t * sm = &stats_main;
2605 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2606 u32 target_fib_id = ntohl(mp->vrf_id);
2608 dslock (sm, 1 /* release hint */, 8 /* tag */);
2610 vec_foreach (fib, im4->fibs) {
2611 vnet_sw_interface_t * si;
2613 if (fib->table_id != target_fib_id)
2616 /* remove any mpls/gre tunnels in this fib */
2617 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2619 /* remove any mpls encap/decap labels */
2620 mpls_fib_reset_labels (fib->table_id);
2622 /* remove any proxy arps in this fib */
2623 vnet_proxy_arp_fib_reset (fib->table_id);
2625 /* Set the flow hash for this fib to the default */
2626 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2628 vec_reset_length (sw_if_indices_to_shut);
2630 /* Shut down interfaces in this FIB / clean out intfc routes */
2631 pool_foreach (si, im->sw_interfaces,
2633 u32 sw_if_index = si->sw_if_index;
2635 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2636 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2638 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2641 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2642 sw_if_index = sw_if_indices_to_shut[i];
2643 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2645 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2646 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2647 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2650 vec_reset_length (routes);
2652 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2653 uword * hash = fib->adj_index_by_dst_address[i];
2657 x.address_length = i;
2659 hash_foreach_pair (p, hash,
2661 x.address.data_u32 = p->key;
2662 vec_add1 (routes, x);
2666 vec_foreach (r, routes) {
2667 ip4_add_del_route_args_t a;
2669 memset (&a, 0, sizeof (a));
2670 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2671 a.table_index_or_table_id = fib - im4->fibs;
2672 a.dst_address = r->address;
2673 a.dst_address_length = r->address_length;
2676 ip4_add_del_route (im4, &a);
2677 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2678 IP4_ROUTE_FLAG_FIB_INDEX);
2682 } /* vec_foreach (fib) */
2689 ip6_address_t address;
2696 ip6_route_t ** routep;
2697 } add_routes_in_fib_arg_t;
2699 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2701 add_routes_in_fib_arg_t * ap = arg;
2703 if (kvp->key[2]>>32 == ap->fib_index)
2705 ip6_address_t *addr;
2707 addr = (ip6_address_t *) kvp;
2708 vec_add2 (*ap->routep, r, 1);
2709 r->address = addr[0];
2710 r->address_length = kvp->key[2] & 0xFF;
2711 r->index = kvp->value;
2715 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2717 vnet_main_t * vnm = vnet_get_main();
2718 vnet_interface_main_t * im = &vnm->interface_main;
2719 ip6_main_t * im6 = &ip6_main;
2720 stats_main_t * sm = &stats_main;
2721 static ip6_route_t * routes;
2722 static u32 * sw_if_indices_to_shut;
2727 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2728 u32 target_fib_id = ntohl(mp->vrf_id);
2729 add_routes_in_fib_arg_t _a, *a=&_a;
2730 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2732 dslock (sm, 1 /* release hint */, 9 /* tag */);
2734 vec_foreach (fib, im6->fibs) {
2735 vnet_sw_interface_t * si;
2737 if (fib->table_id != target_fib_id)
2740 vec_reset_length (sw_if_indices_to_shut);
2742 /* Shut down interfaces in this FIB / clean out intfc routes */
2743 pool_foreach (si, im->sw_interfaces,
2745 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2747 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2750 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2751 sw_if_index = sw_if_indices_to_shut[i];
2752 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2754 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2755 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2756 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2759 vec_reset_length (routes);
2761 a->fib_index = fib - im6->fibs;
2762 a->routep = &routes;
2764 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2766 vec_foreach (r, routes) {
2767 ip6_add_del_route_args_t a;
2769 memset (&a, 0, sizeof (a));
2770 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2771 a.table_index_or_table_id = fib - im6->fibs;
2772 a.dst_address = r->address;
2773 a.dst_address_length = r->address_length;
2776 ip6_add_del_route (im6, &a);
2777 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2778 IP6_ROUTE_FLAG_FIB_INDEX);
2781 /* Reinstall the neighbor / router discovery routes */
2782 vnet_ip6_fib_init (im6, fib - im6->fibs);
2784 } /* vec_foreach (fib) */
2790 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2793 vl_api_reset_fib_reply_t * rmp;
2796 rv = ip6_reset_fib_t_handler (mp);
2798 rv = ip4_reset_fib_t_handler (mp);
2800 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2805 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2807 vl_api_dhcp_proxy_config_reply_t * rmp;
2810 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2811 (ip4_address_t *)(&mp->dhcp_src_address),
2812 (u32) ntohl(mp->vrf_id),
2813 (int) mp->insert_circuit_id,
2814 (int) (mp->is_add == 0));
2816 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2821 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2823 vl_api_dhcp_proxy_config_reply_t * rmp;
2826 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2827 (ip6_address_t *)(&mp->dhcp_src_address),
2828 (u32) ntohl(mp->vrf_id),
2829 (int) mp->insert_circuit_id,
2830 (int) (mp->is_add == 0));
2832 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2836 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2838 vl_api_dhcp_proxy_config_reply_t * rmp;
2841 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2842 (ip4_address_t *)(&mp->dhcp_src_address),
2843 (u32) ntohl(mp->rx_vrf_id),
2844 (u32) ntohl(mp->server_vrf_id),
2845 (int) mp->insert_circuit_id,
2846 (int) (mp->is_add == 0));
2848 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2853 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2855 vl_api_dhcp_proxy_config_reply_t * rmp;
2859 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2860 (ip6_address_t *)(&mp->dhcp_src_address),
2861 (u32) ntohl(mp->rx_vrf_id),
2862 (u32) ntohl(mp->server_vrf_id),
2863 (int) mp->insert_circuit_id,
2864 (int) (mp->is_add == 0));
2866 rv = VNET_API_ERROR_UNIMPLEMENTED;
2869 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2874 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2876 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2879 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2882 (int)mp->is_add == 0);
2884 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2887 (int)mp->is_add == 0);
2889 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2893 static void vl_api_dhcp_proxy_config_t_handler
2894 (vl_api_dhcp_proxy_config_t *mp)
2896 if (mp->is_ipv6 == 0)
2897 dhcpv4_proxy_config (mp);
2899 dhcpv6_proxy_config (mp);
2902 static void vl_api_dhcp_proxy_config_2_t_handler
2903 (vl_api_dhcp_proxy_config_2_t *mp)
2905 if (mp->is_ipv6 == 0)
2906 dhcpv4_proxy_config_2 (mp);
2908 dhcpv6_proxy_config_2 (mp);
2911 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2912 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2914 unix_shared_memory_queue_t * q;
2915 vl_api_dhcp_compl_event_t * mp;
2917 q = vl_api_client_index_to_input_queue (client_index);
2921 mp = vl_msg_api_alloc (sizeof (*mp));
2922 mp->client_index = client_index;
2924 mp->is_ipv6 = is_ipv6;
2925 memcpy (&mp->hostname, hostname, vec_len(hostname));
2926 mp->hostname[vec_len(hostname) + 1] = '\n';
2927 memcpy (&mp->host_address[0], host_address, 16);
2928 memcpy (&mp->router_address[0], router_address, 16);
2929 memcpy (&mp->host_mac[0], host_mac, 6);
2931 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2933 vl_msg_api_send_shmem (q, (u8 *)&mp);
2936 static void vl_api_dhcp_client_config_t_handler
2937 (vl_api_dhcp_client_config_t *mp)
2939 vlib_main_t *vm = vlib_get_main();
2940 vl_api_dhcp_client_config_reply_t * rmp;
2943 VALIDATE_SW_IF_INDEX(mp);
2945 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
2946 mp->hostname, mp->is_add, mp->client_index,
2947 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
2950 BAD_SW_IF_INDEX_LABEL;
2952 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
2956 vl_api_sw_interface_ip6nd_ra_config_t_handler
2957 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
2959 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
2961 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
2963 is_no = mp->is_no == 1;
2964 surpress = mp->surpress == 1;
2965 managed = mp->managed == 1;
2966 other = mp->other == 1;
2967 ll_option = mp->ll_option == 1;
2968 send_unicast = mp->send_unicast == 1;
2969 cease = mp->cease == 1;
2970 default_router = mp->default_router == 1;
2972 VALIDATE_SW_IF_INDEX(mp);
2974 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
2975 surpress, managed, other,
2976 ll_option, send_unicast, cease,
2977 default_router, ntohl (mp->lifetime),
2978 ntohl(mp->initial_count), ntohl(mp->initial_interval),
2979 ntohl(mp->max_interval), ntohl( mp->min_interval),
2982 BAD_SW_IF_INDEX_LABEL;
2984 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2988 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2989 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
2991 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
2993 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
2995 VALIDATE_SW_IF_INDEX(mp);
2997 is_no = mp->is_no == 1;
2998 use_default = mp->use_default == 1;
2999 no_advertise = mp->no_advertise == 1;
3000 off_link = mp->off_link == 1;
3001 no_autoconfig = mp->no_autoconfig == 1;
3002 no_onlink = mp->no_onlink == 1;
3004 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3005 (ip6_address_t *)mp->address, mp->address_length,
3006 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3007 no_advertise, off_link, no_autoconfig, no_onlink,
3010 BAD_SW_IF_INDEX_LABEL;
3011 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3015 vl_api_sw_interface_ip6_enable_disable_t_handler
3016 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3018 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3019 vnet_main_t * vnm = vnet_get_main();
3021 clib_error_t * error;
3025 VALIDATE_SW_IF_INDEX(mp);
3027 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3028 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3031 clib_error_report(error);
3032 rv = VNET_API_ERROR_UNSPECIFIED;
3034 rv = vnm->api_errno;
3037 BAD_SW_IF_INDEX_LABEL;
3039 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3043 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3044 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3046 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3048 clib_error_t * error;
3049 vnet_main_t * vnm = vnet_get_main();
3053 VALIDATE_SW_IF_INDEX(mp);
3055 error = set_ip6_link_local_address(vm,
3056 ntohl(mp->sw_if_index),
3057 (ip6_address_t *)mp->address,
3058 mp->address_length);
3060 clib_error_report(error);
3061 rv = VNET_API_ERROR_UNSPECIFIED;
3063 rv = vnm->api_errno;
3066 BAD_SW_IF_INDEX_LABEL;
3068 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3071 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3073 vl_api_set_ip_flow_hash_reply_t *rmp;
3074 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3076 clib_warning ("unimplemented...");
3078 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3081 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3083 vl_api_set_ip_flow_hash_reply_t *rmp;
3086 u32 flow_hash_config = 0;
3088 table_id = ntohl(mp->vrf_id);
3090 #define _(a,b) if (mp->a) flow_hash_config |= b;
3091 foreach_flow_hash_bit;
3094 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3096 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3100 static void vl_api_set_ip_flow_hash_t_handler
3101 (vl_api_set_ip_flow_hash_t *mp)
3103 if (mp->is_ipv6 == 0)
3104 set_ip4_flow_hash (mp);
3106 set_ip6_flow_hash (mp);
3109 static void vl_api_sw_interface_set_unnumbered_t_handler
3110 (vl_api_sw_interface_set_unnumbered_t *mp)
3112 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3114 vnet_sw_interface_t * si;
3115 vnet_main_t *vnm = vnet_get_main();
3116 u32 sw_if_index, unnumbered_sw_if_index;
3118 sw_if_index = ntohl(mp->sw_if_index);
3119 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3122 * The API message field names are backwards from
3123 * the underlying data structure names.
3124 * It's not worth changing them now.
3126 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3127 unnumbered_sw_if_index)) {
3128 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3132 /* Only check the "use loop0" field when setting the binding */
3134 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3135 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3139 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3142 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3143 si->unnumbered_sw_if_index = sw_if_index;
3145 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3146 si->unnumbered_sw_if_index = (u32)~0;
3150 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3153 static void vl_api_create_loopback_t_handler
3154 (vl_api_create_loopback_t *mp)
3156 vl_api_create_loopback_reply_t * rmp;
3160 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3162 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3164 rmp->sw_if_index = ntohl (sw_if_index);
3168 static void vl_api_delete_loopback_t_handler
3169 (vl_api_delete_loopback_t *mp)
3171 vl_api_delete_loopback_reply_t * rmp;
3175 sw_if_index = ntohl (mp->sw_if_index);
3176 rv = vnet_delete_loopback_interface (sw_if_index);
3178 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3181 static void vl_api_control_ping_t_handler
3182 (vl_api_control_ping_t *mp)
3184 vl_api_control_ping_reply_t * rmp;
3187 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3189 rmp->vpe_pid = ntohl (getpid());
3193 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3195 u8 **shmem_vecp = (u8 **)arg;
3198 api_main_t * am = &api_main;
3201 shmem_vec = *shmem_vecp;
3203 offset = vec_len (shmem_vec);
3205 pthread_mutex_lock (&am->vlib_rp->mutex);
3206 oldheap = svm_push_data_heap (am->vlib_rp);
3208 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3210 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3212 svm_pop_heap (oldheap);
3213 pthread_mutex_unlock (&am->vlib_rp->mutex);
3215 *shmem_vecp = shmem_vec;
3219 static void vl_api_cli_request_t_handler
3220 (vl_api_cli_request_t *mp)
3222 vl_api_cli_reply_t *rp;
3223 unix_shared_memory_queue_t *q;
3224 vlib_main_t * vm = vlib_get_main();
3225 api_main_t * am = &api_main;
3226 unformat_input_t input;
3230 q = vl_api_client_index_to_input_queue (mp->client_index);
3234 rp = vl_msg_api_alloc (sizeof (*rp));
3235 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3236 rp->context = mp->context;
3238 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3240 vlib_cli_input (vm, &input, shmem_cli_output,
3243 pthread_mutex_lock (&am->vlib_rp->mutex);
3244 oldheap = svm_push_data_heap (am->vlib_rp);
3246 vec_add1(shmem_vec, 0);
3248 svm_pop_heap (oldheap);
3249 pthread_mutex_unlock (&am->vlib_rp->mutex);
3251 rp->reply_in_shmem = (uword)shmem_vec;
3253 vl_msg_api_send_shmem (q, (u8 *)&rp);
3256 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3259 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3260 vnet_main_t *vnm = vnet_get_main();
3261 clib_error_t * error;
3266 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3268 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3271 clib_error_report(error);
3272 rv = VNET_API_ERROR_UNSPECIFIED;
3274 rv = vnm->api_errno;
3277 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3280 static void vl_api_sr_tunnel_add_del_t_handler
3281 (vl_api_sr_tunnel_add_del_t *mp)
3284 clib_warning ("unimplemented");
3286 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3288 vl_api_sr_tunnel_add_del_reply_t * rmp;
3289 ip6_address_t * segments = 0, * seg;
3290 ip6_address_t * tags = 0, *tag;
3291 ip6_address_t * this_address;
3294 if (mp->n_segments == 0) {
3299 memset (a, 0, sizeof (*a));
3300 a->src_address = (ip6_address_t *)&mp->src_address;
3301 a->dst_address = (ip6_address_t *)&mp->dst_address;
3302 a->dst_mask_width = mp->dst_mask_width;
3303 a->flags_net_byte_order = mp->flags_net_byte_order;
3304 a->is_del = (mp->is_add == 0);
3305 a->rx_table_id = ntohl(mp->outer_vrf_id);
3306 a->tx_table_id = ntohl(mp->inner_vrf_id);
3308 /* Yank segments and tags out of the API message */
3309 this_address = (ip6_address_t *)mp->segs_and_tags;
3310 for (i = 0; i < mp->n_segments; i++) {
3311 vec_add2 (segments, seg, 1);
3312 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3315 for (i = 0; i < mp->n_tags; i++) {
3316 vec_add2 (tags, tag, 1);
3317 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3321 a->segments = segments;
3324 rv = ip6_sr_add_del_tunnel (a);
3328 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3332 #define foreach_classify_add_del_table_field \
3337 _(match_n_vectors) \
3338 _(next_table_index) \
3341 static void vl_api_classify_add_del_table_t_handler
3342 (vl_api_classify_add_del_table_t * mp)
3344 vl_api_classify_add_del_table_reply_t * rmp;
3345 vnet_classify_main_t * cm = &vnet_classify_main;
3346 vnet_classify_table_t * t;
3350 foreach_classify_add_del_table_field;
3353 #define _(a) a = ntohl(mp->a);
3354 foreach_classify_add_del_table_field;
3357 /* The underlying API fails silently, on purpose, so check here */
3358 if (mp->is_add == 0)
3359 if (pool_is_free_index (cm->tables, table_index)) {
3360 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3364 rv = vnet_classify_add_del_table
3365 (cm, mp->mask, nbuckets, memory_size,
3366 skip_n_vectors, match_n_vectors,
3367 next_table_index, miss_next_index,
3368 &table_index, mp->is_add);
3371 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3373 if (rv == 0 && mp->is_add) {
3374 t = pool_elt_at_index (cm->tables, table_index);
3375 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3376 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3377 rmp->new_table_index = ntohl(table_index);
3379 rmp->skip_n_vectors = ~0;
3380 rmp->match_n_vectors = ~0;
3381 rmp->new_table_index = ~0;
3386 static void vl_api_classify_add_del_session_t_handler
3387 (vl_api_classify_add_del_session_t * mp)
3389 vnet_classify_main_t * cm = &vnet_classify_main;
3390 vl_api_classify_add_del_session_reply_t * rmp;
3392 u32 table_index, hit_next_index, opaque_index;
3395 table_index = ntohl (mp->table_index);
3396 hit_next_index = ntohl (mp->hit_next_index);
3397 opaque_index = ntohl (mp->opaque_index);
3398 advance = ntohl (mp->advance);
3400 rv = vnet_classify_add_del_session
3401 (cm, table_index, mp->match, hit_next_index, opaque_index,
3402 advance, mp->is_add);
3404 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3407 static void vl_api_classify_set_interface_ip_table_t_handler
3408 (vl_api_classify_set_interface_ip_table_t * mp)
3410 vlib_main_t * vm = vlib_get_main();
3411 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3413 u32 table_index, sw_if_index;
3415 table_index = ntohl (mp->table_index);
3416 sw_if_index = ntohl (mp->sw_if_index);
3418 VALIDATE_SW_IF_INDEX(mp);
3421 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3423 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3425 BAD_SW_IF_INDEX_LABEL;
3427 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3430 static void vl_api_classify_set_interface_l2_tables_t_handler
3431 (vl_api_classify_set_interface_l2_tables_t * mp)
3433 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3435 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3438 ip4_table_index = ntohl(mp->ip4_table_index);
3439 ip6_table_index = ntohl(mp->ip6_table_index);
3440 other_table_index = ntohl(mp->other_table_index);
3441 sw_if_index = ntohl(mp->sw_if_index);
3443 VALIDATE_SW_IF_INDEX(mp);
3445 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3446 ip6_table_index, other_table_index);
3449 if (ip4_table_index != ~0 || ip6_table_index != ~0
3450 || other_table_index != ~0)
3455 vnet_l2_classify_enable_disable (sw_if_index, enable);
3458 BAD_SW_IF_INDEX_LABEL;
3460 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3464 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3467 vl_api_l2_fib_clear_table_reply_t * rmp;
3469 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3470 * that is not currently implemented. When that TODO is fixed
3471 * this call should be changed to pass 1 instead of 0.
3473 l2fib_clear_table (0);
3475 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3478 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3483 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3486 vl_api_l2_interface_efp_filter_reply_t * rmp;
3487 vnet_main_t *vnm = vnet_get_main();
3489 // enable/disable the feature
3490 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3491 rv = vnm->api_errno;
3493 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3497 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3500 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3501 vnet_main_t * vnm = vnet_get_main();
3502 vlib_main_t * vm = vlib_get_main();
3505 VALIDATE_SW_IF_INDEX(mp);
3507 vtr_op = ntohl(mp->vtr_op);
3509 /* The L2 code is unsuspicious */
3511 case L2_VTR_DISABLED:
3516 case L2_VTR_TRANSLATE_1_1:
3517 case L2_VTR_TRANSLATE_1_2:
3518 case L2_VTR_TRANSLATE_2_1:
3519 case L2_VTR_TRANSLATE_2_2:
3523 rv = VNET_API_ERROR_INVALID_VALUE;
3524 goto bad_sw_if_index;
3527 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3528 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3531 BAD_SW_IF_INDEX_LABEL;
3533 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3537 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3541 vl_api_create_vhost_user_if_reply_t * rmp;
3542 u32 sw_if_index = (u32)~0;
3544 vnet_main_t * vnm = vnet_get_main();
3545 vlib_main_t * vm = vlib_get_main();
3547 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3548 mp->is_server, &sw_if_index, (u64)~0,
3549 mp->renumber, ntohl(mp->custom_dev_instance));
3551 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3553 rmp->sw_if_index = ntohl (sw_if_index);
3559 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3563 vl_api_modify_vhost_user_if_reply_t * rmp;
3564 u32 sw_if_index = ntohl(mp->sw_if_index);
3566 vnet_main_t * vnm = vnet_get_main();
3567 vlib_main_t * vm = vlib_get_main();
3569 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3570 mp->is_server, sw_if_index, (u64)~0,
3571 mp->renumber, ntohl(mp->custom_dev_instance));
3573 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3578 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3582 vpe_api_main_t * vam = &vpe_api_main;
3583 vl_api_delete_vhost_user_if_reply_t * rmp;
3584 u32 sw_if_index = ntohl(mp->sw_if_index);
3586 vnet_main_t * vnm = vnet_get_main();
3587 vlib_main_t * vm = vlib_get_main();
3589 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3591 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3593 unix_shared_memory_queue_t * q =
3594 vl_api_client_index_to_input_queue (mp->client_index);
3598 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3603 static void vl_api_sw_interface_vhost_user_details_t_handler (
3604 vl_api_sw_interface_vhost_user_details_t * mp)
3606 clib_warning ("BUG");
3610 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3611 unix_shared_memory_queue_t *q,
3612 vhost_user_intf_details_t * vui)
3614 vl_api_sw_interface_vhost_user_details_t * mp;
3616 mp = vl_msg_api_alloc (sizeof (*mp));
3617 memset (mp, 0, sizeof (*mp));
3618 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3619 mp->sw_if_index = ntohl(vui->sw_if_index);
3620 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3621 mp->features = clib_net_to_host_u64 (vui->features);
3622 mp->is_server = vui->is_server;
3623 mp->num_regions = ntohl(vui->num_regions);
3624 mp->sock_errno = ntohl(vui->sock_errno);
3626 strncpy ((char *) mp->sock_filename,
3627 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3628 strncpy ((char *) mp->interface_name,
3629 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3631 vl_msg_api_send_shmem (q, (u8 *)&mp);
3636 vl_api_sw_interface_vhost_user_dump_t_handler (
3637 vl_api_sw_interface_vhost_user_dump_t *mp)
3641 vpe_api_main_t * am = &vpe_api_main;
3642 vnet_main_t * vnm = vnet_get_main();
3643 vlib_main_t * vm = vlib_get_main();
3644 vhost_user_intf_details_t *ifaces = NULL;
3645 vhost_user_intf_details_t *vuid = NULL;
3646 unix_shared_memory_queue_t * q;
3648 q = vl_api_client_index_to_input_queue (mp->client_index);
3652 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3656 vec_foreach (vuid, ifaces) {
3657 send_sw_interface_vhost_user_details (am, q, vuid);
3663 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3664 unix_shared_memory_queue_t *q,
3668 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3669 u8 * if_name = NULL;
3670 vnet_sw_interface_t * si = NULL;
3672 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3674 if_name = format(if_name, "%U",
3675 format_vnet_sw_interface_name, lm->vnet_main, si);
3677 mp = vl_msg_api_alloc (sizeof (*mp));
3678 memset (mp, 0, sizeof (*mp));
3679 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3680 strncpy((char *)mp->interface_name,
3681 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3682 mp->sw_if_index = ntohl(si->sw_if_index);
3683 mp->local_session_id = s->local_session_id;
3684 mp->remote_session_id = s->remote_session_id;
3685 mp->local_cookie[0] = s->local_cookie[0];
3686 mp->local_cookie[1] = s->local_cookie[1];
3687 mp->remote_cookie = s->remote_cookie;
3688 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3689 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3690 mp->l2_sublayer_present = s->l2_sublayer_present;
3692 vl_msg_api_send_shmem (q, (u8 *)&mp);
3695 static void send_ip_address_details (vpe_api_main_t * am,
3696 unix_shared_memory_queue_t * q,
3701 vl_api_ip_address_details_t * mp;
3703 mp = vl_msg_api_alloc (sizeof (*mp));
3704 memset (mp, 0, sizeof (*mp));
3705 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3708 memcpy(&mp->ip, ip, sizeof(mp->ip));
3710 u32 * tp = (u32 *)mp->ip;
3711 *tp = ntohl(*(u32*)ip);
3713 mp->prefix_length = prefix_length;
3715 vl_msg_api_send_shmem (q, (u8 *)&mp);
3719 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3721 vpe_api_main_t * am = &vpe_api_main;
3722 unix_shared_memory_queue_t * q;
3725 ip6_main_t * im6 = &ip6_main;
3726 ip4_main_t * im4 = &ip4_main;
3727 ip_lookup_main_t * lm6 = &im6->lookup_main;
3728 ip_lookup_main_t * lm4 = &im4->lookup_main;
3729 ip_interface_address_t * ia = 0;
3730 u32 sw_if_index = ~0;
3732 sw_if_index = ntohl(mp->sw_if_index);
3734 q = vl_api_client_index_to_input_queue (mp->client_index);
3740 foreach_ip_interface_address (lm6, ia, sw_if_index,
3741 1 /* honor unnumbered */,
3743 r6 = ip_interface_address_get_address (lm6, ia);
3744 u16 prefix_length = ia->address_length;
3745 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3748 foreach_ip_interface_address (lm4, ia, sw_if_index,
3749 1 /* honor unnumbered */,
3751 r4 = ip_interface_address_get_address (lm4, ia);
3752 u16 prefix_length = ia->address_length;
3753 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3758 static void send_ip_details (vpe_api_main_t * am,
3759 unix_shared_memory_queue_t *q,
3762 vl_api_ip_details_t * mp;
3764 mp = vl_msg_api_alloc (sizeof (*mp));
3765 memset (mp, 0, sizeof (*mp));
3766 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3768 mp->sw_if_index = ntohl(sw_if_index);
3770 vl_msg_api_send_shmem (q, (u8 *)&mp);
3774 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3775 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3777 vpe_api_main_t * am = &vpe_api_main;
3778 l2t_main_t * lm = &l2t_main;
3779 unix_shared_memory_queue_t * q;
3780 l2t_session_t *session;
3782 q = vl_api_client_index_to_input_queue (mp->client_index);
3786 pool_foreach (session, lm->sessions,
3788 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3793 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3794 unix_shared_memory_queue_t *q,
3795 tapcli_interface_details_t *tap_if)
3797 vl_api_sw_interface_tap_details_t * mp;
3798 mp = vl_msg_api_alloc (sizeof (*mp));
3799 memset (mp, 0, sizeof (*mp));
3800 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3801 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3802 strncpy((char *)mp->dev_name,
3803 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3805 vl_msg_api_send_shmem (q, (u8 *)&mp);
3809 vl_api_sw_interface_tap_dump_t_handler (
3810 vl_api_sw_interface_tap_dump_t *mp)
3813 vpe_api_main_t * am = &vpe_api_main;
3814 unix_shared_memory_queue_t * q;
3815 tapcli_interface_details_t *tapifs = NULL;
3816 tapcli_interface_details_t *tap_if = NULL;
3818 q = vl_api_client_index_to_input_queue (mp->client_index);
3822 rv = vnet_tap_dump_ifs(&tapifs);
3826 vec_foreach(tap_if, tapifs) {
3827 send_sw_interface_tap_details(am, q, tap_if);
3834 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3836 vpe_api_main_t * am = &vpe_api_main;
3837 vnet_main_t * vnm = vnet_get_main();
3838 vlib_main_t * vm = vlib_get_main();
3839 vnet_interface_main_t * im = &vnm->interface_main;
3840 unix_shared_memory_queue_t * q;
3841 vnet_sw_interface_t * si, * sorted_sis;
3842 u32 sw_if_index = ~0;
3844 q = vl_api_client_index_to_input_queue (mp->client_index);
3849 /* Gather interfaces. */
3850 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3851 _vec_len (sorted_sis) = 0;
3852 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3854 vec_foreach (si, sorted_sis) {
3855 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3856 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3859 sw_if_index = si->sw_if_index;
3860 send_ip_details(am, q, sw_if_index);
3865 static void vl_api_l2_fib_table_entry_t_handler (
3866 vl_api_l2_fib_table_entry_t * mp)
3868 clib_warning ("BUG");
3871 static void send_l2fib_table_entry (vpe_api_main_t * am,
3872 unix_shared_memory_queue_t *q,
3873 l2fib_entry_key_t * l2fe_key,
3874 l2fib_entry_result_t * l2fe_res)
3876 vl_api_l2_fib_table_entry_t * mp;
3878 mp = vl_msg_api_alloc (sizeof (*mp));
3879 memset (mp, 0, sizeof (*mp));
3880 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3882 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3884 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3885 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3886 mp->static_mac = l2fe_res->fields.static_mac;
3887 mp->filter_mac = l2fe_res->fields.filter;
3888 mp->bvi_mac = l2fe_res->fields.bvi;
3890 vl_msg_api_send_shmem (q, (u8 *)&mp);
3894 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3896 vpe_api_main_t * am = &vpe_api_main;
3897 bd_main_t * bdm = &bd_main;
3898 l2fib_entry_key_t *l2fe_key = NULL;
3899 l2fib_entry_result_t *l2fe_res = NULL;
3900 u32 ni, bd_id = ntohl (mp->bd_id);
3902 unix_shared_memory_queue_t * q;
3905 q = vl_api_client_index_to_input_queue (mp->client_index);
3909 /* see l2fib_table_dump: ~0 means "any" */
3913 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3920 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3922 vec_foreach_index (ni, l2fe_key) {
3923 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
3924 vec_elt_at_index(l2fe_res, ni));
3931 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
3933 vl_api_show_version_reply_t *rmp;
3935 char * vpe_api_get_build_directory(void);
3936 char * vpe_api_get_version(void);
3937 char * vpe_api_get_build_date(void);
3939 unix_shared_memory_queue_t * q =
3940 vl_api_client_index_to_input_queue (mp->client_index);
3945 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3947 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3948 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3949 ARRAY_LEN(rmp->build_directory)-1);
3950 strncpy ((char *) rmp->version, vpe_api_get_version(),
3951 ARRAY_LEN(rmp->version)-1);
3952 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3953 ARRAY_LEN(rmp->build_date)-1);
3957 static void vl_api_get_node_index_t_handler
3958 (vl_api_get_node_index_t * mp)
3960 vlib_main_t * vm = vlib_get_main();
3961 vl_api_get_node_index_reply_t * rmp;
3964 u32 node_index = ~0;
3966 n = vlib_get_node_by_name (vm, mp->node_name);
3969 rv = VNET_API_ERROR_NO_SUCH_NODE;
3971 node_index = n->index;
3973 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3975 rmp->node_index = ntohl(node_index);
3979 static void vl_api_add_node_next_t_handler
3980 (vl_api_add_node_next_t * mp)
3982 vlib_main_t * vm = vlib_get_main();
3983 vl_api_add_node_next_reply_t * rmp;
3984 vlib_node_t * n, * next;
3986 u32 next_index = ~0;
3988 n = vlib_get_node_by_name (vm, mp->node_name);
3991 rv = VNET_API_ERROR_NO_SUCH_NODE;
3995 next = vlib_get_node_by_name (vm, mp->next_name);
3998 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4000 next_index = vlib_node_add_next (vm, n->index, next->index);
4003 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4005 rmp->next_index = ntohl(next_index);
4009 static void vl_api_l2tpv3_create_tunnel_t_handler
4010 (vl_api_l2tpv3_create_tunnel_t *mp)
4012 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4013 l2t_main_t *lm = &l2t_main;
4014 u32 sw_if_index = (u32)~0;
4017 if (mp->is_ipv6 != 1) {
4018 rv = VNET_API_ERROR_UNIMPLEMENTED;
4022 rv = create_l2tpv3_ipv6_tunnel (lm,
4023 (ip6_address_t *) mp->client_address,
4024 (ip6_address_t *) mp->our_address,
4025 ntohl(mp->local_session_id),
4026 ntohl(mp->remote_session_id),
4027 clib_net_to_host_u64(mp->local_cookie),
4028 clib_net_to_host_u64(mp->remote_cookie),
4029 mp->l2_sublayer_present,
4033 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4035 rmp->sw_if_index = ntohl (sw_if_index);
4039 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4040 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4042 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4043 l2t_main_t *lm = &l2t_main;
4046 VALIDATE_SW_IF_INDEX(mp);
4048 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4049 clib_net_to_host_u64(mp->new_local_cookie),
4050 clib_net_to_host_u64(mp->new_remote_cookie));
4052 BAD_SW_IF_INDEX_LABEL;
4054 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4057 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4058 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4061 vnet_main_t * vnm = vnet_get_main();
4062 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4064 VALIDATE_SW_IF_INDEX(mp);
4066 rv = l2tpv3_interface_enable_disable
4067 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4069 BAD_SW_IF_INDEX_LABEL;
4071 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4074 static void vl_api_l2tpv3_set_lookup_key_t_handler
4075 (vl_api_l2tpv3_set_lookup_key_t * mp)
4078 l2t_main_t *lm = &l2t_main;
4079 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4081 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4082 rv = VNET_API_ERROR_INVALID_VALUE;
4086 lm->lookup_type = mp->key;
4089 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4092 static void vl_api_vxlan_add_del_tunnel_t_handler
4093 (vl_api_vxlan_add_del_tunnel_t * mp)
4095 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4097 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4098 u32 encap_fib_index;
4100 ip4_main_t * im = &ip4_main;
4101 u32 sw_if_index = ~0;
4103 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4105 rv = VNET_API_ERROR_NO_SUCH_FIB;
4108 encap_fib_index = p[0];
4110 memset (a, 0, sizeof (*a));
4112 a->is_add = mp->is_add;
4114 /* ip addresses sent in network byte order */
4115 a->src.as_u32 = mp->src_address;
4116 a->dst.as_u32 = mp->dst_address;
4118 a->encap_fib_index = encap_fib_index;
4119 a->decap_next_index = ntohl(mp->decap_next_index);
4120 a->vni = ntohl(mp->vni);
4121 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4124 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4126 rmp->sw_if_index = ntohl (sw_if_index);
4130 static void send_vxlan_tunnel_details
4131 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4133 vl_api_vxlan_tunnel_details_t * rmp;
4134 ip4_main_t * im = &ip4_main;
4136 rmp = vl_msg_api_alloc (sizeof (*rmp));
4137 memset (rmp, 0, sizeof (*rmp));
4138 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4139 rmp->src_address = t->src.data_u32;
4140 rmp->dst_address = t->dst.data_u32;
4141 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4142 rmp->vni = htonl(t->vni);
4143 rmp->decap_next_index = htonl(t->decap_next_index);
4144 rmp->sw_if_index = htonl(t->sw_if_index);
4146 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4149 static void vl_api_vxlan_tunnel_dump_t_handler
4150 (vl_api_vxlan_tunnel_dump_t * mp)
4152 unix_shared_memory_queue_t * q;
4153 vxlan_main_t * vxm = &vxlan_main;
4157 q = vl_api_client_index_to_input_queue (mp->client_index);
4162 sw_if_index = ntohl(mp->sw_if_index);
4164 if (~0 == sw_if_index) {
4165 pool_foreach (t, vxm->tunnels,
4167 send_vxlan_tunnel_details(t, q);
4170 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4171 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4174 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4175 send_vxlan_tunnel_details(t, q);
4180 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4182 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4184 vl_api_l2_patch_add_del_reply_t * rmp;
4185 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4189 VALIDATE_RX_SW_IF_INDEX(mp);
4190 VALIDATE_TX_SW_IF_INDEX(mp);
4192 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4193 ntohl(mp->tx_sw_if_index),
4194 (int)(mp->is_add != 0));
4196 BAD_RX_SW_IF_INDEX_LABEL;
4197 BAD_TX_SW_IF_INDEX_LABEL;
4199 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4203 vl_api_nsh_gre_add_del_tunnel_t_handler
4204 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4206 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4208 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4209 u32 encap_fib_index, decap_fib_index;
4210 u32 decap_next_index;
4212 ip4_main_t * im = &ip4_main;
4214 u32 sw_if_index = ~0;
4217 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4219 rv = VNET_API_ERROR_NO_SUCH_FIB;
4222 encap_fib_index = p[0];
4224 decap_next_index = ntohl(mp->decap_next_index);
4226 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4227 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4228 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4230 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4233 decap_fib_index = p[0];
4235 decap_fib_index = ntohl(mp->decap_vrf_id);
4238 memset (a, 0, sizeof (*a));
4240 a->is_add = mp->is_add;
4241 /* ip addresses sent in network byte order */
4242 a->src.as_u32 = ntohl(mp->src);
4243 a->dst.as_u32 = ntohl(mp->dst);
4244 a->encap_fib_index = encap_fib_index;
4245 a->decap_fib_index = decap_fib_index;
4246 a->decap_next_index = decap_next_index;
4247 a->ver_o_c = mp->ver_o_c;
4248 a->length = mp->length;
4249 a->md_type = mp->md_type;
4250 a->next_protocol = mp->next_protocol;
4251 a->spi_si = ntohl(mp->spi_si);
4252 a->c1 = ntohl(mp->c1);
4253 a->c2 = ntohl(mp->c2);
4254 a->c3 = ntohl(mp->c3);
4255 a->c4 = ntohl(mp->c4);
4257 for (i = 0; i < mp->tlv_len_in_words; i++)
4258 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4262 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4265 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4267 rmp->sw_if_index = ntohl (sw_if_index);
4272 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4273 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4275 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4277 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4278 u32 encap_fib_index, decap_fib_index;
4279 u32 decap_next_index;
4281 ip4_main_t * im = &ip4_main;
4283 u32 sw_if_index = ~0;
4286 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4288 rv = VNET_API_ERROR_NO_SUCH_FIB;
4291 encap_fib_index = p[0];
4293 decap_next_index = ntohl(mp->decap_next_index);
4295 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4296 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4297 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4299 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4302 decap_fib_index = p[0];
4304 decap_fib_index = ntohl(mp->decap_vrf_id);
4307 memset (a, 0, sizeof (*a));
4309 a->is_add = mp->is_add;
4310 /* ip addresses sent in network byte order */
4311 a->src.as_u32 = ntohl(mp->src);
4312 a->dst.as_u32 = ntohl(mp->dst);
4313 a->encap_fib_index = encap_fib_index;
4314 a->decap_fib_index = decap_fib_index;
4315 a->decap_next_index = decap_next_index;
4316 a->vni = ntohl(mp->vni);
4317 a->ver_o_c = mp->ver_o_c;
4318 a->length = mp->length;
4319 a->md_type = mp->md_type;
4320 a->next_protocol = mp->next_protocol;
4321 a->spi_si = ntohl(mp->spi_si);
4322 a->c1 = ntohl(mp->c1);
4323 a->c2 = ntohl(mp->c2);
4324 a->c3 = ntohl(mp->c3);
4325 a->c4 = ntohl(mp->c4);
4327 for (i = 0; i < mp->tlv_len_in_words; i++)
4328 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4332 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4335 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4337 rmp->sw_if_index = ntohl (sw_if_index);
4342 vl_api_lisp_gpe_add_del_tunnel_t_handler
4343 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4345 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4347 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4348 u32 encap_fib_index, decap_fib_index;
4349 u32 decap_next_index;
4351 ip4_main_t * im = &ip4_main;
4352 u32 sw_if_index = ~0;
4354 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4356 rv = VNET_API_ERROR_NO_SUCH_FIB;
4359 encap_fib_index = p[0];
4361 decap_next_index = ntohl(mp->decap_next_index);
4363 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4364 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4365 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4367 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4370 decap_fib_index = p[0];
4372 decap_fib_index = ntohl(mp->decap_vrf_id);
4375 memset (a, 0, sizeof (*a));
4377 a->is_add = mp->is_add;
4378 /* ip addresses sent in network byte order */
4379 a->src.as_u32 = mp->src;
4380 a->dst.as_u32 = mp->dst;
4381 a->encap_fib_index = encap_fib_index;
4382 a->decap_fib_index = decap_fib_index;
4383 a->decap_next_index = decap_next_index;
4384 a->flags = mp->flags;
4385 a->ver_res = mp->ver_res;
4387 a->next_protocol = mp->next_protocol;
4388 a->iid = clib_net_to_host_u32 (mp->iid);
4390 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4393 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4395 rmp->sw_if_index = ntohl (sw_if_index);
4400 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4402 vl_api_interface_name_renumber_reply_t * rmp;
4405 VALIDATE_SW_IF_INDEX(mp);
4407 rv = vnet_interface_name_renumber
4408 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4410 BAD_SW_IF_INDEX_LABEL;
4412 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4415 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4416 u32 sw_if_index, u32 address)
4418 vpe_api_main_t * am = &vpe_api_main;
4419 vlib_main_t * vm = am->vlib_main;
4420 vl_api_ip4_arp_event_t * event;
4421 static f64 arp_event_last_time;
4422 f64 now = vlib_time_now (vm);
4424 if (pool_is_free_index (am->arp_events, pool_index))
4427 event = pool_elt_at_index (am->arp_events, pool_index);
4428 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4429 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4430 } else { /* same mac */
4431 if ((sw_if_index == event->sw_if_index) &&
4433 /* for BD case, also check IP address with 10 sec timeout */
4434 ((address == event->address) &&
4435 ((now - arp_event_last_time) < 10.0))))
4439 arp_event_last_time = now;
4440 event->sw_if_index = sw_if_index;
4441 if (address) event->address = address;
4445 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4447 vpe_api_main_t * am = &vpe_api_main;
4449 if (pool_is_free_index (am->arp_events, pool_index))
4452 pool_put_index (am->arp_events, pool_index);
4457 vl_api_want_ip4_arp_events_t_handler
4458 (vl_api_want_ip4_arp_events_t * mp)
4460 vpe_api_main_t * am = &vpe_api_main;
4461 vnet_main_t * vnm = vnet_get_main();
4462 vl_api_want_ip4_arp_events_reply_t *rmp;
4463 vl_api_ip4_arp_event_t * event;
4466 if (mp->enable_disable) {
4467 pool_get (am->arp_events, event);
4468 memset (event, 0, sizeof (*event));
4470 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4471 event->client_index = mp->client_index;
4472 event->context = mp->context;
4473 event->address = mp->address;
4474 event->pid = mp->pid;
4476 rv = vnet_add_del_ip4_arp_change_event
4477 (vnm, arp_change_data_callback,
4479 &mp->address /* addr, in net byte order */,
4480 vpe_resolver_process_node.index,
4481 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4483 rv = vnet_add_del_ip4_arp_change_event
4484 (vnm, arp_change_delete_callback,
4486 &mp->address /* addr, in net byte order */,
4487 vpe_resolver_process_node.index,
4488 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4490 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4493 static void vl_api_input_acl_set_interface_t_handler
4494 (vl_api_input_acl_set_interface_t * mp)
4496 vlib_main_t *vm = vlib_get_main();
4497 vl_api_input_acl_set_interface_reply_t * rmp;
4499 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4501 ip4_table_index = ntohl(mp->ip4_table_index);
4502 ip6_table_index = ntohl(mp->ip6_table_index);
4503 l2_table_index = ntohl(mp->l2_table_index);
4504 sw_if_index = ntohl(mp->sw_if_index);
4506 VALIDATE_SW_IF_INDEX(mp);
4508 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4509 ip6_table_index, l2_table_index,
4512 BAD_SW_IF_INDEX_LABEL;
4514 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4517 static void vl_api_ipsec_spd_add_del_t_handler
4518 (vl_api_ipsec_spd_add_del_t * mp)
4521 clib_warning ("unimplemented");
4524 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4525 vl_api_ipsec_spd_add_del_reply_t * rmp;
4529 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4531 rv = VNET_API_ERROR_UNIMPLEMENTED;
4534 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4538 static void vl_api_ipsec_interface_add_del_spd_t_handler
4539 (vl_api_ipsec_interface_add_del_spd_t * mp)
4541 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4542 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4544 u32 sw_if_index __attribute__((unused));
4545 u32 spd_id __attribute__((unused));
4547 sw_if_index = ntohl(mp->sw_if_index);
4548 spd_id = ntohl(mp->spd_id);
4550 VALIDATE_SW_IF_INDEX(mp);
4553 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4555 rv = VNET_API_ERROR_UNIMPLEMENTED;
4558 BAD_SW_IF_INDEX_LABEL;
4560 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4563 static void vl_api_ipsec_spd_add_del_entry_t_handler
4564 (vl_api_ipsec_spd_add_del_entry_t * mp)
4566 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4567 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4573 p.id = ntohl(mp->spd_id);
4574 p.priority = ntohl(mp->priority);
4575 p.is_outbound = mp->is_outbound;
4576 p.is_ipv6 = mp->is_ipv6;
4578 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4579 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4580 memcpy(&p.laddr.start, mp->local_address_start, 16);
4581 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4583 p.protocol = mp->protocol;
4584 p.rport.start = ntohs(mp->remote_port_start);
4585 p.rport.stop = ntohs(mp->remote_port_stop);
4586 p.lport.start = ntohs(mp->local_port_start);
4587 p.lport.stop = ntohs(mp->local_port_stop);
4588 /* policy action resolve unsupported */
4589 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4590 clib_warning("unsupported action: 'resolve'");
4591 rv = VNET_API_ERROR_UNIMPLEMENTED;
4594 p.policy = mp->policy;
4595 p.sa_id = ntohl(mp->sa_id);
4597 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4601 if (mp->is_ip_any) {
4603 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4606 rv = VNET_API_ERROR_UNIMPLEMENTED;
4611 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4614 static void vl_api_ipsec_sad_add_del_entry_t_handler
4615 (vl_api_ipsec_sad_add_del_entry_t * mp)
4617 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4618 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4623 sa.id = ntohl(mp->sad_id);
4624 sa.spi = ntohl(mp->spi);
4625 /* security protocol AH unsupported */
4626 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4627 clib_warning("unsupported security protocol 'AH'");
4628 rv = VNET_API_ERROR_UNIMPLEMENTED;
4631 sa.protocol = mp->protocol;
4632 /* check for unsupported crypto-alg */
4633 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4634 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4635 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4636 mp->crypto_algorithm);
4637 rv = VNET_API_ERROR_UNIMPLEMENTED;
4640 sa.crypto_alg = mp->crypto_algorithm;
4641 sa.crypto_key_len = mp->crypto_key_length;
4642 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4643 /* check for unsupported integ-alg */
4644 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4645 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4646 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4647 mp->integrity_algorithm);
4648 rv = VNET_API_ERROR_UNIMPLEMENTED;
4651 sa.integ_alg = mp->integrity_algorithm;
4652 sa.integ_key_len = mp->integrity_key_length;
4653 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4654 sa.use_esn = mp->use_extended_sequence_number;
4655 sa.is_tunnel = mp->is_tunnel;
4656 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4657 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4658 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4660 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4662 rv = VNET_API_ERROR_UNIMPLEMENTED;
4667 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4670 vl_api_map_add_domain_t_handler
4671 (vl_api_map_add_domain_t * mp)
4673 vl_api_map_add_domain_reply_t * rmp;
4676 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4677 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4678 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4679 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4680 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4682 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4684 rmp->index = ntohl(index);
4689 vl_api_map_del_domain_t_handler
4690 (vl_api_map_del_domain_t * mp)
4692 vl_api_map_del_domain_reply_t * rmp;
4695 rv = map_delete_domain(ntohl(mp->index));
4697 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4701 vl_api_map_add_del_rule_t_handler
4702 (vl_api_map_add_del_rule_t * mp)
4704 vl_api_map_del_domain_reply_t * rmp;
4707 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4709 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4713 vl_api_map_domain_dump_t_handler
4714 (vl_api_map_domain_dump_t * mp)
4716 vl_api_map_domain_details_t * rmp;
4717 map_main_t *mm = &map_main;
4719 unix_shared_memory_queue_t * q;
4721 if (pool_elts (mm->domains) == 0)
4724 q = vl_api_client_index_to_input_queue (mp->client_index);
4729 pool_foreach(d, mm->domains, ({
4730 rmp = vl_msg_api_alloc (sizeof (*rmp));
4731 memset (rmp, 0, sizeof (*rmp));
4732 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4733 rmp->domain_index = htonl(d - mm->domains);
4734 rmp->ea_bits_len = d->ea_bits_len;
4735 rmp->psid_offset = d->psid_offset;
4736 rmp->psid_length = d->psid_length;
4737 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4738 rmp->ip4_prefix_len = d->ip4_prefix_len;
4739 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4740 rmp->ip6_prefix_len = d->ip6_prefix_len;
4741 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4742 rmp->ip6_src_len = d->ip6_src_len;
4743 rmp->mtu = htons(d->mtu);
4744 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4746 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4751 vl_api_map_rule_dump_t_handler
4752 (vl_api_map_rule_dump_t * mp)
4754 unix_shared_memory_queue_t * q;
4757 vl_api_map_rule_details_t * rmp;
4758 map_main_t *mm = &map_main;
4759 u32 domain_index = ntohl(mp->domain_index);
4762 if (pool_elts (mm->domains) == 0)
4765 d = pool_elt_at_index(mm->domains, domain_index);
4766 if (!d || !d->rules) {
4770 q = vl_api_client_index_to_input_queue (mp->client_index);
4775 for (i = 0; i < (0x1 << d->psid_length); i++) {
4777 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4780 rmp = vl_msg_api_alloc(sizeof(*rmp));
4781 memset(rmp, 0, sizeof(*rmp));
4782 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4783 rmp->psid = htons(i);
4784 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4785 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4790 vl_api_map_summary_stats_t_handler (
4791 vl_api_map_summary_stats_t *mp)
4793 vl_api_map_summary_stats_reply_t *rmp;
4794 vlib_combined_counter_main_t *cm;
4797 u64 total_pkts[VLIB_N_RX_TX];
4798 u64 total_bytes[VLIB_N_RX_TX];
4799 map_main_t *mm = &map_main;
4800 unix_shared_memory_queue_t *q =
4801 vl_api_client_index_to_input_queue(mp->client_index);
4806 rmp = vl_msg_api_alloc (sizeof (*rmp));
4807 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
4808 rmp->context = mp->context;
4811 memset (total_pkts, 0, sizeof (total_pkts));
4812 memset (total_bytes, 0, sizeof (total_bytes));
4814 map_domain_counter_lock (mm);
4815 vec_foreach(cm, mm->domain_counters) {
4816 which = cm - mm->domain_counters;
4818 for (i = 0; i < vec_len(cm->maxi); i++) {
4819 vlib_get_combined_counter (cm, i, &v);
4820 total_pkts[which] += v.packets;
4821 total_bytes[which] += v.bytes;
4825 map_domain_counter_unlock (mm);
4827 /* Note: in HOST byte order! */
4828 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
4829 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
4830 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
4831 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
4832 rmp->total_bindings = pool_elts(mm->domains);
4833 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
4834 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
4835 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
4837 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4840 static void vl_api_ipsec_sa_set_key_t_handler
4841 (vl_api_ipsec_sa_set_key_t * mp)
4843 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4844 vl_api_ipsec_sa_set_key_reply_t *rmp;
4848 sa.id = ntohl(mp->sa_id);
4849 sa.crypto_key_len = mp->crypto_key_length;
4850 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4851 sa.integ_key_len = mp->integrity_key_length;
4852 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4854 rv = ipsec_set_sa_key(vm, &sa);
4856 rv = VNET_API_ERROR_UNIMPLEMENTED;
4859 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
4862 #define BOUNCE_HANDLER(nn) \
4863 static void vl_api_##nn##_t_handler ( \
4864 vl_api_##nn##_t *mp) \
4866 vpe_client_registration_t *reg; \
4867 vpe_api_main_t * vam = &vpe_api_main; \
4868 unix_shared_memory_queue_t * q; \
4870 /* One registration only... */ \
4871 pool_foreach(reg, vam->nn##_registrations, \
4873 q = vl_api_client_index_to_input_queue (reg->client_index); \
4876 * If the queue is stuffed, turf the msg and complain \
4877 * It's unlikely that the intended recipient is \
4878 * alive; avoid deadlock at all costs. \
4880 if (q->cursize == q->maxsize) { \
4881 clib_warning ("ERROR: receiver queue full, drop msg"); \
4882 vl_msg_api_free (mp); \
4885 vl_msg_api_send_shmem (q, (u8 *)&mp); \
4889 vl_msg_api_free (mp); \
4892 BOUNCE_HANDLER(to_netconf_server);
4893 BOUNCE_HANDLER(from_netconf_server);
4894 BOUNCE_HANDLER(to_netconf_client);
4895 BOUNCE_HANDLER(from_netconf_client);
4899 * Add vpe's API message handlers to the table.
4900 * vlib has alread mapped shared memory and
4901 * added the client registration handlers.
4902 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
4905 static clib_error_t *
4906 vpe_api_hookup (vlib_main_t *vm)
4908 api_main_t * am = &api_main;
4911 vl_msg_api_set_handlers(VL_API_##N, #n, \
4912 vl_api_##n##_t_handler, \
4914 vl_api_##n##_t_endian, \
4915 vl_api_##n##_t_print, \
4916 sizeof(vl_api_##n##_t), 1);
4917 foreach_vpe_api_msg;
4921 * Manually register the sr tunnel add del msg, so we trace
4922 * enough bytes to capture a typical segment list
4924 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
4925 "sr_tunnel_add_del",
4926 vl_api_sr_tunnel_add_del_t_handler,
4928 vl_api_sr_tunnel_add_del_t_endian,
4929 vl_api_sr_tunnel_add_del_t_print,
4932 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
4933 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
4934 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
4935 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
4938 * Trace space for 8 MPLS encap labels, classifier mask+match
4940 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
4941 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
4942 += 5 * sizeof (u32x4);
4943 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
4944 += 5 * sizeof (u32x4);
4945 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
4946 += 16 * sizeof (u32);
4949 * trace space for 4 nsh-gre variable TLV words
4951 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
4952 += 4 * sizeof (u32);
4957 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
4959 static clib_error_t *
4960 vpe_api_init (vlib_main_t *vm)
4962 vpe_api_main_t *am = &vpe_api_main;
4965 am->vnet_main = vnet_get_main();
4966 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
4967 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
4968 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
4969 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
4970 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
4971 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
4974 vl_set_memory_region_name ("/vpe-api");
4975 vl_enable_disable_memory_api (vm, 1 /* enable it */);
4980 VLIB_INIT_FUNCTION(vpe_api_init);
4982 void * get_unformat_vnet_sw_interface (void)
4984 return (void *) &unformat_vnet_sw_interface;
4987 #undef vl_api_version
4988 #define vl_api_version(n,v) static u32 vpe_api_version = v;
4989 #include <api/vpe.api.h>
4990 #undef vl_api_version
4992 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
4994 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
4995 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
4996 clib_host_to_net_u32 (mp->api_versions[0]),
5003 static u8 * format_arp_event (u8 * s, va_list * args)
5005 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5007 s = format (s, "pid %d: %U", event->pid,
5008 format_ip4_address, &event->address);
5012 static clib_error_t *
5013 show_ip4_arp_events_fn (vlib_main_t * vm,
5014 unformat_input_t * input,
5015 vlib_cli_command_t * cmd)
5017 vpe_api_main_t * am = &vpe_api_main;
5018 vl_api_ip4_arp_event_t * event;
5020 if (pool_elts (am->arp_events) == 0) {
5021 vlib_cli_output (vm, "No active arp event registrations");
5025 pool_foreach (event, am->arp_events,
5027 vlib_cli_output (vm, "%U", format_arp_event, event);
5033 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5034 .path = "show arp event registrations",
5035 .function = show_ip4_arp_events_fn,
5036 .short_help = "Show arp event registrations",