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 memset (&template, 0, sizeof (template));
1799 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1800 template.sup_sw_if_index = hi->sw_if_index;
1801 template.sub.id = id;
1802 template.sub.eth.raw_flags = 0;
1803 template.sub.eth.flags.one_tag = 1;
1804 template.sub.eth.outer_vlan_id = id;
1805 template.sub.eth.flags.exact_match = 1;
1807 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1809 clib_error_report(error);
1810 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1813 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1814 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1816 BAD_SW_IF_INDEX_LABEL;
1819 q = vl_api_client_index_to_input_queue (mp->client_index);
1823 rmp = vl_msg_api_alloc (sizeof (*rmp));
1824 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1825 rmp->context = mp->context;
1826 rmp->retval = ntohl(rv);
1827 rmp->sw_if_index = ntohl(sw_if_index);
1828 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1832 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1834 vl_api_create_subif_reply_t * rmp;
1835 vnet_main_t * vnm = vnet_get_main();
1836 u32 sw_if_index = ~0;
1839 vnet_sw_interface_t *si;
1840 vnet_hw_interface_t *hi;
1841 vnet_sw_interface_t template;
1843 vnet_interface_main_t * im = &vnm->interface_main;
1844 u64 sup_and_sub_key;
1846 clib_error_t * error;
1848 VALIDATE_SW_IF_INDEX(mp);
1850 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1851 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1853 sw_if_index = si->sw_if_index;
1854 sub_id = ntohl(mp->sub_id);
1856 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1858 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1861 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1862 sw_if_index, sub_id);
1863 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1867 kp = clib_mem_alloc (sizeof (*kp));
1868 *kp = sup_and_sub_key;
1870 memset (&template, 0, sizeof (template));
1871 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1872 template.sup_sw_if_index = sw_if_index;
1873 template.sub.id = sub_id;
1874 template.sub.eth.flags.no_tags = mp->no_tags;
1875 template.sub.eth.flags.one_tag = mp->one_tag;
1876 template.sub.eth.flags.two_tags = mp->two_tags;
1877 template.sub.eth.flags.dot1ad = mp->dot1ad;
1878 template.sub.eth.flags.exact_match = mp->exact_match;
1879 template.sub.eth.flags.default_sub = mp->default_sub;
1880 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1881 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1882 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1883 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1885 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1887 clib_error_report (error);
1888 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1892 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1893 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1895 BAD_SW_IF_INDEX_LABEL;
1899 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1901 rmp->sw_if_index = ntohl(sw_if_index);
1906 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1908 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1910 stats_main_t * sm = &stats_main;
1911 u32 tunnel_sw_if_index = ~0;
1913 dslock (sm, 1 /* release hint */, 5 /* tag */);
1915 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1916 (ip4_address_t *)(mp->dst_address),
1917 (ip4_address_t *)(mp->intfc_address),
1918 (u32)(mp->intfc_address_length),
1919 ntohl(mp->inner_vrf_id),
1920 ntohl(mp->outer_vrf_id),
1921 &tunnel_sw_if_index,
1926 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1928 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1933 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1934 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1936 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1938 stats_main_t * sm = &stats_main;
1939 u32 tunnel_sw_if_index;
1941 dslock (sm, 1 /* release hint */, 5 /* tag */);
1943 rv = vnet_mpls_ethernet_add_del_tunnel
1944 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1945 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1946 ntohl(mp->tx_sw_if_index),
1947 &tunnel_sw_if_index,
1953 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1955 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1960 * This piece of misery brought to you because the control-plane
1961 * can't figure out the tx interface + dst-mac address all by itself
1963 static int mpls_ethernet_add_del_tunnel_2_t_handler
1964 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1966 pending_route_t * pr;
1967 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1968 vnet_main_t * vnm = vnet_get_main();
1969 vlib_main_t * vm = vlib_get_main();
1970 stats_main_t * sm = &stats_main;
1971 vpe_api_main_t * vam = &vpe_api_main;
1972 u32 inner_fib_index, outer_fib_index;
1973 ip4_main_t * im = &ip4_main;
1974 ip_lookup_main_t * lm = &im->lookup_main;
1975 ip_adjacency_t * adj = 0;
1978 u8 * dst_mac_address;
1982 u32 tunnel_sw_if_index;
1984 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
1986 return VNET_API_ERROR_NO_SUCH_FIB;
1988 outer_fib_index = p[0];
1991 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
1993 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1995 inner_fib_index = p[0];
1997 if (inner_fib_index == outer_fib_index)
1998 return VNET_API_ERROR_INVALID_VALUE;
2000 lookup_result = ip4_fib_lookup_with_table
2001 (im, outer_fib_index,
2002 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2003 1 /* disable default route */);
2005 adj = ip_get_adjacency (lm, lookup_result);
2006 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2008 if (mp->is_add && mp->resolve_if_needed) {
2009 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2010 pool_get (vam->pending_routes, pr);
2011 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2013 memcpy (pme, mp, sizeof (*pme));
2014 /* recursion block, "just in case" */
2015 pme->resolve_if_needed = 0;
2016 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2017 pme->resolve_opaque = tx_sw_if_index;
2018 vnet_register_ip4_arp_resolution_event
2020 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2021 vpe_resolver_process_node.index,
2022 RESOLUTION_EVENT, pr - vam->pending_routes);
2024 vlib_process_signal_event
2025 (vm, vpe_resolver_process_node.index,
2026 RESOLUTION_PENDING_EVENT, 0 /* data */);
2028 /* The interface may be down, etc. */
2029 e = ip4_probe_neighbor
2030 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2034 clib_error_report(e);
2036 return VNET_API_ERROR_IN_PROGRESS;
2040 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2041 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2044 vnet_rewrite_get_data_internal
2045 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2047 dslock (sm, 1 /* release hint */, 10 /* tag */);
2049 rv = vnet_mpls_ethernet_add_del_tunnel
2050 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2051 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2052 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2060 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2061 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2063 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2066 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2068 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2073 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2075 vl_api_mpls_add_del_encap_reply_t * rmp;
2077 static u32 * labels;
2080 vec_reset_length (labels);
2082 for (i = 0; i < mp->nlabels; i++)
2083 vec_add1 (labels, ntohl(mp->labels[i]));
2086 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2087 ntohl(mp->vrf_id), labels,
2088 ~0 /* policy_tunnel_index */,
2089 0 /* no_dst_hash */,
2093 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2097 vl_api_mpls_add_del_decap_t_handler
2098 (vl_api_mpls_add_del_decap_t *mp)
2100 vl_api_mpls_add_del_decap_reply_t * rmp;
2103 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2104 ntohl(mp->label), ntohl(mp->next_index),
2105 mp->s_bit, mp->is_add);
2107 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2111 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2113 vl_api_proxy_arp_add_del_reply_t * rmp;
2116 ip4_main_t * im = &ip4_main;
2117 stats_main_t * sm = &stats_main;
2118 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2119 ip4_address_t *hi_addr,
2120 u32 fib_index, int is_del);
2123 dslock (sm, 1 /* release hint */, 6 /* tag */);
2125 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2128 rv = VNET_API_ERROR_NO_SUCH_FIB;
2134 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2135 (ip4_address_t *)mp->hi_address,
2136 fib_index, mp->is_add == 0);
2140 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2144 vl_api_proxy_arp_intfc_enable_disable_t_handler
2145 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2148 vnet_main_t * vnm = vnet_get_main();
2149 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2150 vnet_sw_interface_t * si;
2153 VALIDATE_SW_IF_INDEX(mp);
2155 sw_if_index = ntohl(mp->sw_if_index);
2157 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2159 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2163 si = vnet_get_sw_interface (vnm, sw_if_index);
2167 if (mp->enable_disable)
2168 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2170 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2172 BAD_SW_IF_INDEX_LABEL;
2175 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2179 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2181 vl_api_ip_neighbor_add_del_reply_t * rmp;
2182 vnet_main_t * vnm = vnet_get_main();
2185 stats_main_t * sm = &stats_main;
2187 VALIDATE_SW_IF_INDEX(mp);
2189 dslock (sm, 1 /* release hint */, 7 /* tag */);
2193 rv = vnet_set_ip6_ethernet_neighbor
2194 (vm, ntohl(mp->sw_if_index),
2195 (ip6_address_t *)(mp->dst_address),
2196 mp->mac_address, sizeof (mp->mac_address));
2198 rv = vnet_unset_ip6_ethernet_neighbor
2199 (vm, ntohl(mp->sw_if_index),
2200 (ip6_address_t *)(mp->dst_address),
2201 mp->mac_address, sizeof(mp->mac_address));
2203 ip4_main_t * im = &ip4_main;
2204 ip_lookup_main_t * lm = &im->lookup_main;
2205 ethernet_arp_ip4_over_ethernet_address_t a;
2207 ip_adjacency_t *nh_adj;
2209 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2211 rv = VNET_API_ERROR_NO_SUCH_FIB;
2217 * Unfortunately, folks have a penchant for
2218 * adding interface addresses to the ARP cache, and
2219 * wondering why the forwarder eventually ASSERTs...
2221 ai = ip4_fib_lookup_with_table
2222 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2223 1 /* disable default route */);
2226 nh_adj = ip_get_adjacency (lm, ai);
2227 /* Never allow manipulation of a local adj! */
2228 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2229 clib_warning("%U matches local adj",
2231 (ip4_address_t *)(mp->dst_address));
2232 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2237 memcpy (&a.ethernet, mp->mac_address, 6);
2238 memcpy (&a.ip4, mp->dst_address, 4);
2241 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2242 fib_index, &a, mp->is_static);
2244 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2248 BAD_SW_IF_INDEX_LABEL;
2251 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2255 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2258 vpe_main_t *rm = &vpe_main;
2259 ip4_main_t *im4 = &ip4_main;
2260 ip6_main_t *im6 = &ip6_main;
2261 ip_lookup_main_t * lm;
2266 u32 adj_index, sw_if_index;
2267 vl_api_is_address_reachable_t *rmp;
2268 ip_adjacency_t * adj;
2269 unix_shared_memory_queue_t *q;
2271 q = vl_api_client_index_to_input_queue (mp->client_index);
2273 increment_missing_api_client_counter (rm->vlib_main);
2277 rmp = vl_msg_api_alloc (sizeof (*rmp));
2278 memcpy (rmp, mp, sizeof (*rmp));
2280 sw_if_index = mp->next_hop_sw_if_index;
2281 memcpy (&addr, mp->address, sizeof (addr));
2283 lm = &im6->lookup_main;
2285 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2287 lm = &im4->lookup_main;
2289 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2291 if (adj_index == ~0) {
2295 adj = ip_get_adjacency (lm, adj_index);
2297 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2298 && adj->rewrite_header.sw_if_index == sw_if_index) {
2301 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2302 && adj->rewrite_header.sw_if_index == sw_if_index) {
2304 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2306 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2307 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2315 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2319 static void vl_api_sw_interface_details_t_handler (
2320 vl_api_sw_interface_details_t * mp)
2322 clib_warning ("BUG");
2325 static void vl_api_sw_interface_set_flags_t_handler (
2326 vl_api_sw_interface_set_flags_t * mp)
2328 vl_api_sw_interface_set_flags_reply_t *rmp;
2329 vnet_main_t * vnm = vnet_get_main();
2331 clib_error_t * error;
2334 VALIDATE_SW_IF_INDEX(mp);
2336 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2338 error = vnet_sw_interface_set_flags (vnm,
2339 ntohl(mp->sw_if_index),
2343 clib_error_report (error);
2346 BAD_SW_IF_INDEX_LABEL;
2347 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2350 static void send_sw_interface_details (vpe_api_main_t * am,
2351 unix_shared_memory_queue_t *q,
2352 vnet_sw_interface_t * swif,
2353 u8 * interface_name)
2355 vl_api_sw_interface_details_t * mp;
2356 vnet_hw_interface_t * hi;
2358 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2360 mp = vl_msg_api_alloc (sizeof (*mp));
2361 memset (mp, 0, sizeof (*mp));
2362 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2363 mp->sw_if_index = ntohl(swif->sw_if_index);
2364 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2365 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2367 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2369 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2370 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2371 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2372 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2374 strncpy ((char *) mp->interface_name,
2375 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2377 /* Send the L2 address for ethernet physical intfcs */
2378 if (swif->sup_sw_if_index == swif->sw_if_index
2379 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2380 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2381 ethernet_interface_t *ei;
2383 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2384 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2385 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2386 mp->l2_address_length = ntohl(sizeof (ei->address));
2387 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2388 vnet_sub_interface_t *sub = &swif->sub;
2389 mp->sub_id = ntohl(sub->id);
2390 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2391 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2392 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2393 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2394 mp->sub_exact_match = sub->eth.flags.exact_match;
2395 mp->sub_default = sub->eth.flags.default_sub;
2396 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2397 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2399 /* vlan tag rewrite data */
2400 u32 vtr_op = L2_VTR_DISABLED;
2401 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2403 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2404 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2405 // error - default to disabled
2406 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2407 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2410 mp->vtr_op = ntohl(vtr_op);
2411 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2412 mp->vtr_tag1 = ntohl(vtr_tag1);
2413 mp->vtr_tag2 = ntohl(vtr_tag2);
2417 vl_msg_api_send_shmem (q, (u8 *)&mp);
2420 static void send_sw_interface_flags (vpe_api_main_t * am,
2421 unix_shared_memory_queue_t *q,
2422 vnet_sw_interface_t * swif)
2424 vl_api_sw_interface_set_flags_t *mp;
2425 vnet_main_t * vnm = am->vnet_main;
2427 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2429 mp = vl_msg_api_alloc (sizeof (*mp));
2430 memset (mp, 0, sizeof (*mp));
2431 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2432 mp->sw_if_index = ntohl(swif->sw_if_index);
2434 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2436 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2438 vl_msg_api_send_shmem (q, (u8 *)&mp);
2441 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2442 unix_shared_memory_queue_t *q,
2444 __attribute__((unused));
2446 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2447 unix_shared_memory_queue_t *q,
2450 vl_api_sw_interface_set_flags_t *mp;
2452 mp = vl_msg_api_alloc (sizeof (*mp));
2453 memset (mp, 0, sizeof (*mp));
2454 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2455 mp->sw_if_index = ntohl(sw_if_index);
2457 mp->admin_up_down = 0;
2458 mp->link_up_down = 0;
2460 vl_msg_api_send_shmem (q, (u8 *)&mp);
2463 static void vl_api_sw_interface_dump_t_handler (
2464 vl_api_sw_interface_dump_t *mp)
2466 vpe_api_main_t * am = &vpe_api_main;
2467 vnet_sw_interface_t * swif;
2468 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2469 u8 * filter_string = 0, * name_string = 0;
2470 unix_shared_memory_queue_t * q;
2471 char * strcasestr (char *, char *); /* lnx hdr file botch */
2473 q = vl_api_client_index_to_input_queue (mp->client_index);
2478 if (mp->name_filter_valid) {
2479 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2480 filter_string = format (0, "%s%c", mp->name_filter, 0);
2483 pool_foreach (swif, im->sw_interfaces,
2485 name_string = format (name_string, "%U%c",
2486 format_vnet_sw_interface_name,
2487 am->vnet_main, swif, 0);
2489 if (mp->name_filter_valid == 0 ||
2490 strcasestr((char *) name_string, (char *) filter_string)) {
2492 send_sw_interface_details (am, q, swif, name_string);
2493 send_sw_interface_flags (am, q, swif);
2495 _vec_len (name_string) = 0;
2498 vec_free (name_string);
2499 vec_free (filter_string);
2502 void send_oam_event (oam_target_t * t)
2504 vpe_api_main_t * vam = &vpe_api_main;
2505 unix_shared_memory_queue_t * q;
2506 vpe_client_registration_t *reg;
2507 vl_api_oam_event_t * mp;
2509 pool_foreach(reg, vam->oam_events_registrations,
2511 q = vl_api_client_index_to_input_queue (reg->client_index);
2513 mp = vl_msg_api_alloc (sizeof (*mp));
2514 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2515 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2516 mp->state = t->state;
2517 vl_msg_api_send_shmem (q, (u8 *)&mp);
2523 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2525 vl_api_oam_add_del_reply_t * rmp;
2528 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2529 (ip4_address_t *)mp->dst_address,
2533 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2537 vl_api_vnet_get_summary_stats_t_handler (
2538 vl_api_vnet_get_summary_stats_t *mp)
2540 stats_main_t * sm = &stats_main;
2541 vnet_interface_main_t * im = sm->interface_main;
2542 vl_api_vnet_summary_stats_reply_t *rmp;
2543 vlib_combined_counter_main_t * cm;
2546 u64 total_pkts[VLIB_N_RX_TX];
2547 u64 total_bytes[VLIB_N_RX_TX];
2549 unix_shared_memory_queue_t * q =
2550 vl_api_client_index_to_input_queue (mp->client_index);
2555 rmp = vl_msg_api_alloc (sizeof (*rmp));
2556 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2557 rmp->context = mp->context;
2560 memset (total_pkts, 0, sizeof (total_pkts));
2561 memset (total_bytes, 0, sizeof (total_bytes));
2563 vnet_interface_counter_lock (im);
2565 vec_foreach (cm, im->combined_sw_if_counters) {
2566 which = cm - im->combined_sw_if_counters;
2568 for (i = 0; i < vec_len (cm->maxi); i++) {
2569 vlib_get_combined_counter (cm, i, &v);
2570 total_pkts[which] += v.packets;
2571 total_bytes[which] += v.bytes;
2574 vnet_interface_counter_unlock (im);
2576 /* Note: in HOST byte order! */
2577 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2578 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2579 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2580 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2581 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2583 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2586 typedef CLIB_PACKED (struct {
2587 ip4_address_t address;
2589 u32 address_length : 6;
2594 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2596 vnet_main_t * vnm = vnet_get_main();
2597 vnet_interface_main_t * im = &vnm->interface_main;
2598 ip4_main_t * im4 = &ip4_main;
2599 static ip4_route_t * routes;
2600 static u32 * sw_if_indices_to_shut;
2601 stats_main_t * sm = &stats_main;
2606 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2607 u32 target_fib_id = ntohl(mp->vrf_id);
2609 dslock (sm, 1 /* release hint */, 8 /* tag */);
2611 vec_foreach (fib, im4->fibs) {
2612 vnet_sw_interface_t * si;
2614 if (fib->table_id != target_fib_id)
2617 /* remove any mpls/gre tunnels in this fib */
2618 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2620 /* remove any mpls encap/decap labels */
2621 mpls_fib_reset_labels (fib->table_id);
2623 /* remove any proxy arps in this fib */
2624 vnet_proxy_arp_fib_reset (fib->table_id);
2626 /* Set the flow hash for this fib to the default */
2627 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2629 vec_reset_length (sw_if_indices_to_shut);
2631 /* Shut down interfaces in this FIB / clean out intfc routes */
2632 pool_foreach (si, im->sw_interfaces,
2634 u32 sw_if_index = si->sw_if_index;
2636 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2637 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2639 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2642 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2643 sw_if_index = sw_if_indices_to_shut[i];
2644 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2646 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2647 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2648 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2651 vec_reset_length (routes);
2653 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2654 uword * hash = fib->adj_index_by_dst_address[i];
2658 x.address_length = i;
2660 hash_foreach_pair (p, hash,
2662 x.address.data_u32 = p->key;
2663 vec_add1 (routes, x);
2667 vec_foreach (r, routes) {
2668 ip4_add_del_route_args_t a;
2670 memset (&a, 0, sizeof (a));
2671 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2672 a.table_index_or_table_id = fib - im4->fibs;
2673 a.dst_address = r->address;
2674 a.dst_address_length = r->address_length;
2677 ip4_add_del_route (im4, &a);
2678 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2679 IP4_ROUTE_FLAG_FIB_INDEX);
2683 } /* vec_foreach (fib) */
2690 ip6_address_t address;
2697 ip6_route_t ** routep;
2698 } add_routes_in_fib_arg_t;
2700 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2702 add_routes_in_fib_arg_t * ap = arg;
2704 if (kvp->key[2]>>32 == ap->fib_index)
2706 ip6_address_t *addr;
2708 addr = (ip6_address_t *) kvp;
2709 vec_add2 (*ap->routep, r, 1);
2710 r->address = addr[0];
2711 r->address_length = kvp->key[2] & 0xFF;
2712 r->index = kvp->value;
2716 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2718 vnet_main_t * vnm = vnet_get_main();
2719 vnet_interface_main_t * im = &vnm->interface_main;
2720 ip6_main_t * im6 = &ip6_main;
2721 stats_main_t * sm = &stats_main;
2722 static ip6_route_t * routes;
2723 static u32 * sw_if_indices_to_shut;
2728 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2729 u32 target_fib_id = ntohl(mp->vrf_id);
2730 add_routes_in_fib_arg_t _a, *a=&_a;
2731 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2733 dslock (sm, 1 /* release hint */, 9 /* tag */);
2735 vec_foreach (fib, im6->fibs) {
2736 vnet_sw_interface_t * si;
2738 if (fib->table_id != target_fib_id)
2741 vec_reset_length (sw_if_indices_to_shut);
2743 /* Shut down interfaces in this FIB / clean out intfc routes */
2744 pool_foreach (si, im->sw_interfaces,
2746 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2748 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2751 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2752 sw_if_index = sw_if_indices_to_shut[i];
2753 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2755 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2756 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2757 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2760 vec_reset_length (routes);
2762 a->fib_index = fib - im6->fibs;
2763 a->routep = &routes;
2765 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2767 vec_foreach (r, routes) {
2768 ip6_add_del_route_args_t a;
2770 memset (&a, 0, sizeof (a));
2771 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2772 a.table_index_or_table_id = fib - im6->fibs;
2773 a.dst_address = r->address;
2774 a.dst_address_length = r->address_length;
2777 ip6_add_del_route (im6, &a);
2778 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2779 IP6_ROUTE_FLAG_FIB_INDEX);
2782 /* Reinstall the neighbor / router discovery routes */
2783 vnet_ip6_fib_init (im6, fib - im6->fibs);
2785 } /* vec_foreach (fib) */
2791 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2794 vl_api_reset_fib_reply_t * rmp;
2797 rv = ip6_reset_fib_t_handler (mp);
2799 rv = ip4_reset_fib_t_handler (mp);
2801 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2806 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2808 vl_api_dhcp_proxy_config_reply_t * rmp;
2811 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2812 (ip4_address_t *)(&mp->dhcp_src_address),
2813 (u32) ntohl(mp->vrf_id),
2814 (int) mp->insert_circuit_id,
2815 (int) (mp->is_add == 0));
2817 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2822 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2824 vl_api_dhcp_proxy_config_reply_t * rmp;
2827 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2828 (ip6_address_t *)(&mp->dhcp_src_address),
2829 (u32) ntohl(mp->vrf_id),
2830 (int) mp->insert_circuit_id,
2831 (int) (mp->is_add == 0));
2833 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2837 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2839 vl_api_dhcp_proxy_config_reply_t * rmp;
2842 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2843 (ip4_address_t *)(&mp->dhcp_src_address),
2844 (u32) ntohl(mp->rx_vrf_id),
2845 (u32) ntohl(mp->server_vrf_id),
2846 (int) mp->insert_circuit_id,
2847 (int) (mp->is_add == 0));
2849 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2854 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2856 vl_api_dhcp_proxy_config_reply_t * rmp;
2860 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2861 (ip6_address_t *)(&mp->dhcp_src_address),
2862 (u32) ntohl(mp->rx_vrf_id),
2863 (u32) ntohl(mp->server_vrf_id),
2864 (int) mp->insert_circuit_id,
2865 (int) (mp->is_add == 0));
2867 rv = VNET_API_ERROR_UNIMPLEMENTED;
2870 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2875 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2877 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2880 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2883 (int)mp->is_add == 0);
2885 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2888 (int)mp->is_add == 0);
2890 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2894 static void vl_api_dhcp_proxy_config_t_handler
2895 (vl_api_dhcp_proxy_config_t *mp)
2897 if (mp->is_ipv6 == 0)
2898 dhcpv4_proxy_config (mp);
2900 dhcpv6_proxy_config (mp);
2903 static void vl_api_dhcp_proxy_config_2_t_handler
2904 (vl_api_dhcp_proxy_config_2_t *mp)
2906 if (mp->is_ipv6 == 0)
2907 dhcpv4_proxy_config_2 (mp);
2909 dhcpv6_proxy_config_2 (mp);
2912 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2913 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2915 unix_shared_memory_queue_t * q;
2916 vl_api_dhcp_compl_event_t * mp;
2918 q = vl_api_client_index_to_input_queue (client_index);
2922 mp = vl_msg_api_alloc (sizeof (*mp));
2923 mp->client_index = client_index;
2925 mp->is_ipv6 = is_ipv6;
2926 memcpy (&mp->hostname, hostname, vec_len(hostname));
2927 mp->hostname[vec_len(hostname) + 1] = '\n';
2928 memcpy (&mp->host_address[0], host_address, 16);
2929 memcpy (&mp->router_address[0], router_address, 16);
2930 memcpy (&mp->host_mac[0], host_mac, 6);
2932 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
2934 vl_msg_api_send_shmem (q, (u8 *)&mp);
2937 static void vl_api_dhcp_client_config_t_handler
2938 (vl_api_dhcp_client_config_t *mp)
2940 vlib_main_t *vm = vlib_get_main();
2941 vl_api_dhcp_client_config_reply_t * rmp;
2944 VALIDATE_SW_IF_INDEX(mp);
2946 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
2947 mp->hostname, mp->is_add, mp->client_index,
2948 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
2951 BAD_SW_IF_INDEX_LABEL;
2953 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
2957 vl_api_sw_interface_ip6nd_ra_config_t_handler
2958 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
2960 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
2962 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
2964 is_no = mp->is_no == 1;
2965 surpress = mp->surpress == 1;
2966 managed = mp->managed == 1;
2967 other = mp->other == 1;
2968 ll_option = mp->ll_option == 1;
2969 send_unicast = mp->send_unicast == 1;
2970 cease = mp->cease == 1;
2971 default_router = mp->default_router == 1;
2973 VALIDATE_SW_IF_INDEX(mp);
2975 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
2976 surpress, managed, other,
2977 ll_option, send_unicast, cease,
2978 default_router, ntohl (mp->lifetime),
2979 ntohl(mp->initial_count), ntohl(mp->initial_interval),
2980 ntohl(mp->max_interval), ntohl( mp->min_interval),
2983 BAD_SW_IF_INDEX_LABEL;
2985 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
2989 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
2990 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
2992 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
2994 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
2996 VALIDATE_SW_IF_INDEX(mp);
2998 is_no = mp->is_no == 1;
2999 use_default = mp->use_default == 1;
3000 no_advertise = mp->no_advertise == 1;
3001 off_link = mp->off_link == 1;
3002 no_autoconfig = mp->no_autoconfig == 1;
3003 no_onlink = mp->no_onlink == 1;
3005 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3006 (ip6_address_t *)mp->address, mp->address_length,
3007 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3008 no_advertise, off_link, no_autoconfig, no_onlink,
3011 BAD_SW_IF_INDEX_LABEL;
3012 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3016 vl_api_sw_interface_ip6_enable_disable_t_handler
3017 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3019 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3020 vnet_main_t * vnm = vnet_get_main();
3022 clib_error_t * error;
3026 VALIDATE_SW_IF_INDEX(mp);
3028 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3029 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3032 clib_error_report(error);
3033 rv = VNET_API_ERROR_UNSPECIFIED;
3035 rv = vnm->api_errno;
3038 BAD_SW_IF_INDEX_LABEL;
3040 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3044 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3045 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3047 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3049 clib_error_t * error;
3050 vnet_main_t * vnm = vnet_get_main();
3054 VALIDATE_SW_IF_INDEX(mp);
3056 error = set_ip6_link_local_address(vm,
3057 ntohl(mp->sw_if_index),
3058 (ip6_address_t *)mp->address,
3059 mp->address_length);
3061 clib_error_report(error);
3062 rv = VNET_API_ERROR_UNSPECIFIED;
3064 rv = vnm->api_errno;
3067 BAD_SW_IF_INDEX_LABEL;
3069 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3072 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3074 vl_api_set_ip_flow_hash_reply_t *rmp;
3075 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3077 clib_warning ("unimplemented...");
3079 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3082 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3084 vl_api_set_ip_flow_hash_reply_t *rmp;
3087 u32 flow_hash_config = 0;
3089 table_id = ntohl(mp->vrf_id);
3091 #define _(a,b) if (mp->a) flow_hash_config |= b;
3092 foreach_flow_hash_bit;
3095 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3097 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3101 static void vl_api_set_ip_flow_hash_t_handler
3102 (vl_api_set_ip_flow_hash_t *mp)
3104 if (mp->is_ipv6 == 0)
3105 set_ip4_flow_hash (mp);
3107 set_ip6_flow_hash (mp);
3110 static void vl_api_sw_interface_set_unnumbered_t_handler
3111 (vl_api_sw_interface_set_unnumbered_t *mp)
3113 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3115 vnet_sw_interface_t * si;
3116 vnet_main_t *vnm = vnet_get_main();
3117 u32 sw_if_index, unnumbered_sw_if_index;
3119 sw_if_index = ntohl(mp->sw_if_index);
3120 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3123 * The API message field names are backwards from
3124 * the underlying data structure names.
3125 * It's not worth changing them now.
3127 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3128 unnumbered_sw_if_index)) {
3129 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3133 /* Only check the "use loop0" field when setting the binding */
3135 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3136 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3140 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3143 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3144 si->unnumbered_sw_if_index = sw_if_index;
3146 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3147 si->unnumbered_sw_if_index = (u32)~0;
3151 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3154 static void vl_api_create_loopback_t_handler
3155 (vl_api_create_loopback_t *mp)
3157 vl_api_create_loopback_reply_t * rmp;
3161 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3163 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3165 rmp->sw_if_index = ntohl (sw_if_index);
3169 static void vl_api_delete_loopback_t_handler
3170 (vl_api_delete_loopback_t *mp)
3172 vl_api_delete_loopback_reply_t * rmp;
3176 sw_if_index = ntohl (mp->sw_if_index);
3177 rv = vnet_delete_loopback_interface (sw_if_index);
3179 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3182 static void vl_api_control_ping_t_handler
3183 (vl_api_control_ping_t *mp)
3185 vl_api_control_ping_reply_t * rmp;
3188 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3190 rmp->vpe_pid = ntohl (getpid());
3194 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3196 u8 **shmem_vecp = (u8 **)arg;
3199 api_main_t * am = &api_main;
3202 shmem_vec = *shmem_vecp;
3204 offset = vec_len (shmem_vec);
3206 pthread_mutex_lock (&am->vlib_rp->mutex);
3207 oldheap = svm_push_data_heap (am->vlib_rp);
3209 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3211 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3213 svm_pop_heap (oldheap);
3214 pthread_mutex_unlock (&am->vlib_rp->mutex);
3216 *shmem_vecp = shmem_vec;
3220 static void vl_api_cli_request_t_handler
3221 (vl_api_cli_request_t *mp)
3223 vl_api_cli_reply_t *rp;
3224 unix_shared_memory_queue_t *q;
3225 vlib_main_t * vm = vlib_get_main();
3226 api_main_t * am = &api_main;
3227 unformat_input_t input;
3231 q = vl_api_client_index_to_input_queue (mp->client_index);
3235 rp = vl_msg_api_alloc (sizeof (*rp));
3236 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3237 rp->context = mp->context;
3239 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3241 vlib_cli_input (vm, &input, shmem_cli_output,
3244 pthread_mutex_lock (&am->vlib_rp->mutex);
3245 oldheap = svm_push_data_heap (am->vlib_rp);
3247 vec_add1(shmem_vec, 0);
3249 svm_pop_heap (oldheap);
3250 pthread_mutex_unlock (&am->vlib_rp->mutex);
3252 rp->reply_in_shmem = (uword)shmem_vec;
3254 vl_msg_api_send_shmem (q, (u8 *)&rp);
3257 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3260 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3261 vnet_main_t *vnm = vnet_get_main();
3262 clib_error_t * error;
3267 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3269 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3272 clib_error_report(error);
3273 rv = VNET_API_ERROR_UNSPECIFIED;
3275 rv = vnm->api_errno;
3278 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3281 static void vl_api_sr_tunnel_add_del_t_handler
3282 (vl_api_sr_tunnel_add_del_t *mp)
3285 clib_warning ("unimplemented");
3287 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3289 vl_api_sr_tunnel_add_del_reply_t * rmp;
3290 ip6_address_t * segments = 0, * seg;
3291 ip6_address_t * tags = 0, *tag;
3292 ip6_address_t * this_address;
3295 if (mp->n_segments == 0) {
3300 memset (a, 0, sizeof (*a));
3301 a->src_address = (ip6_address_t *)&mp->src_address;
3302 a->dst_address = (ip6_address_t *)&mp->dst_address;
3303 a->dst_mask_width = mp->dst_mask_width;
3304 a->flags_net_byte_order = mp->flags_net_byte_order;
3305 a->is_del = (mp->is_add == 0);
3306 a->rx_table_id = ntohl(mp->outer_vrf_id);
3307 a->tx_table_id = ntohl(mp->inner_vrf_id);
3309 /* Yank segments and tags out of the API message */
3310 this_address = (ip6_address_t *)mp->segs_and_tags;
3311 for (i = 0; i < mp->n_segments; i++) {
3312 vec_add2 (segments, seg, 1);
3313 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3316 for (i = 0; i < mp->n_tags; i++) {
3317 vec_add2 (tags, tag, 1);
3318 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3322 a->segments = segments;
3325 rv = ip6_sr_add_del_tunnel (a);
3329 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3333 #define foreach_classify_add_del_table_field \
3338 _(match_n_vectors) \
3339 _(next_table_index) \
3342 static void vl_api_classify_add_del_table_t_handler
3343 (vl_api_classify_add_del_table_t * mp)
3345 vl_api_classify_add_del_table_reply_t * rmp;
3346 vnet_classify_main_t * cm = &vnet_classify_main;
3347 vnet_classify_table_t * t;
3351 foreach_classify_add_del_table_field;
3354 #define _(a) a = ntohl(mp->a);
3355 foreach_classify_add_del_table_field;
3358 /* The underlying API fails silently, on purpose, so check here */
3359 if (mp->is_add == 0)
3360 if (pool_is_free_index (cm->tables, table_index)) {
3361 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3365 rv = vnet_classify_add_del_table
3366 (cm, mp->mask, nbuckets, memory_size,
3367 skip_n_vectors, match_n_vectors,
3368 next_table_index, miss_next_index,
3369 &table_index, mp->is_add);
3372 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3374 if (rv == 0 && mp->is_add) {
3375 t = pool_elt_at_index (cm->tables, table_index);
3376 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3377 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3378 rmp->new_table_index = ntohl(table_index);
3380 rmp->skip_n_vectors = ~0;
3381 rmp->match_n_vectors = ~0;
3382 rmp->new_table_index = ~0;
3387 static void vl_api_classify_add_del_session_t_handler
3388 (vl_api_classify_add_del_session_t * mp)
3390 vnet_classify_main_t * cm = &vnet_classify_main;
3391 vl_api_classify_add_del_session_reply_t * rmp;
3393 u32 table_index, hit_next_index, opaque_index;
3396 table_index = ntohl (mp->table_index);
3397 hit_next_index = ntohl (mp->hit_next_index);
3398 opaque_index = ntohl (mp->opaque_index);
3399 advance = ntohl (mp->advance);
3401 rv = vnet_classify_add_del_session
3402 (cm, table_index, mp->match, hit_next_index, opaque_index,
3403 advance, mp->is_add);
3405 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3408 static void vl_api_classify_set_interface_ip_table_t_handler
3409 (vl_api_classify_set_interface_ip_table_t * mp)
3411 vlib_main_t * vm = vlib_get_main();
3412 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3414 u32 table_index, sw_if_index;
3416 table_index = ntohl (mp->table_index);
3417 sw_if_index = ntohl (mp->sw_if_index);
3419 VALIDATE_SW_IF_INDEX(mp);
3422 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3424 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3426 BAD_SW_IF_INDEX_LABEL;
3428 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3431 static void vl_api_classify_set_interface_l2_tables_t_handler
3432 (vl_api_classify_set_interface_l2_tables_t * mp)
3434 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3436 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3439 ip4_table_index = ntohl(mp->ip4_table_index);
3440 ip6_table_index = ntohl(mp->ip6_table_index);
3441 other_table_index = ntohl(mp->other_table_index);
3442 sw_if_index = ntohl(mp->sw_if_index);
3444 VALIDATE_SW_IF_INDEX(mp);
3446 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3447 ip6_table_index, other_table_index);
3450 if (ip4_table_index != ~0 || ip6_table_index != ~0
3451 || other_table_index != ~0)
3456 vnet_l2_classify_enable_disable (sw_if_index, enable);
3459 BAD_SW_IF_INDEX_LABEL;
3461 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3465 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3468 vl_api_l2_fib_clear_table_reply_t * rmp;
3470 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3471 * that is not currently implemented. When that TODO is fixed
3472 * this call should be changed to pass 1 instead of 0.
3474 l2fib_clear_table (0);
3476 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3479 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3484 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3487 vl_api_l2_interface_efp_filter_reply_t * rmp;
3488 vnet_main_t *vnm = vnet_get_main();
3490 // enable/disable the feature
3491 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3492 rv = vnm->api_errno;
3494 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3498 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3501 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3502 vnet_main_t * vnm = vnet_get_main();
3503 vlib_main_t * vm = vlib_get_main();
3506 VALIDATE_SW_IF_INDEX(mp);
3508 vtr_op = ntohl(mp->vtr_op);
3510 /* The L2 code is unsuspicious */
3512 case L2_VTR_DISABLED:
3517 case L2_VTR_TRANSLATE_1_1:
3518 case L2_VTR_TRANSLATE_1_2:
3519 case L2_VTR_TRANSLATE_2_1:
3520 case L2_VTR_TRANSLATE_2_2:
3524 rv = VNET_API_ERROR_INVALID_VALUE;
3525 goto bad_sw_if_index;
3528 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3529 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3532 BAD_SW_IF_INDEX_LABEL;
3534 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3538 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3542 vl_api_create_vhost_user_if_reply_t * rmp;
3543 u32 sw_if_index = (u32)~0;
3545 vnet_main_t * vnm = vnet_get_main();
3546 vlib_main_t * vm = vlib_get_main();
3548 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3549 mp->is_server, &sw_if_index, (u64)~0,
3550 mp->renumber, ntohl(mp->custom_dev_instance));
3552 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3554 rmp->sw_if_index = ntohl (sw_if_index);
3560 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3564 vl_api_modify_vhost_user_if_reply_t * rmp;
3565 u32 sw_if_index = ntohl(mp->sw_if_index);
3567 vnet_main_t * vnm = vnet_get_main();
3568 vlib_main_t * vm = vlib_get_main();
3570 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3571 mp->is_server, sw_if_index, (u64)~0,
3572 mp->renumber, ntohl(mp->custom_dev_instance));
3574 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3579 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3583 vpe_api_main_t * vam = &vpe_api_main;
3584 vl_api_delete_vhost_user_if_reply_t * rmp;
3585 u32 sw_if_index = ntohl(mp->sw_if_index);
3587 vnet_main_t * vnm = vnet_get_main();
3588 vlib_main_t * vm = vlib_get_main();
3590 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3592 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3594 unix_shared_memory_queue_t * q =
3595 vl_api_client_index_to_input_queue (mp->client_index);
3599 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3604 static void vl_api_sw_interface_vhost_user_details_t_handler (
3605 vl_api_sw_interface_vhost_user_details_t * mp)
3607 clib_warning ("BUG");
3611 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3612 unix_shared_memory_queue_t *q,
3613 vhost_user_intf_details_t * vui)
3615 vl_api_sw_interface_vhost_user_details_t * mp;
3617 mp = vl_msg_api_alloc (sizeof (*mp));
3618 memset (mp, 0, sizeof (*mp));
3619 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3620 mp->sw_if_index = ntohl(vui->sw_if_index);
3621 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3622 mp->features = clib_net_to_host_u64 (vui->features);
3623 mp->is_server = vui->is_server;
3624 mp->num_regions = ntohl(vui->num_regions);
3625 mp->sock_errno = ntohl(vui->sock_errno);
3627 strncpy ((char *) mp->sock_filename,
3628 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3629 strncpy ((char *) mp->interface_name,
3630 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3632 vl_msg_api_send_shmem (q, (u8 *)&mp);
3637 vl_api_sw_interface_vhost_user_dump_t_handler (
3638 vl_api_sw_interface_vhost_user_dump_t *mp)
3642 vpe_api_main_t * am = &vpe_api_main;
3643 vnet_main_t * vnm = vnet_get_main();
3644 vlib_main_t * vm = vlib_get_main();
3645 vhost_user_intf_details_t *ifaces = NULL;
3646 vhost_user_intf_details_t *vuid = NULL;
3647 unix_shared_memory_queue_t * q;
3649 q = vl_api_client_index_to_input_queue (mp->client_index);
3653 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3657 vec_foreach (vuid, ifaces) {
3658 send_sw_interface_vhost_user_details (am, q, vuid);
3664 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3665 unix_shared_memory_queue_t *q,
3669 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3670 u8 * if_name = NULL;
3671 vnet_sw_interface_t * si = NULL;
3673 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3675 if_name = format(if_name, "%U",
3676 format_vnet_sw_interface_name, lm->vnet_main, si);
3678 mp = vl_msg_api_alloc (sizeof (*mp));
3679 memset (mp, 0, sizeof (*mp));
3680 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3681 strncpy((char *)mp->interface_name,
3682 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3683 mp->sw_if_index = ntohl(si->sw_if_index);
3684 mp->local_session_id = s->local_session_id;
3685 mp->remote_session_id = s->remote_session_id;
3686 mp->local_cookie[0] = s->local_cookie[0];
3687 mp->local_cookie[1] = s->local_cookie[1];
3688 mp->remote_cookie = s->remote_cookie;
3689 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3690 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3691 mp->l2_sublayer_present = s->l2_sublayer_present;
3693 vl_msg_api_send_shmem (q, (u8 *)&mp);
3696 static void send_ip_address_details (vpe_api_main_t * am,
3697 unix_shared_memory_queue_t * q,
3702 vl_api_ip_address_details_t * mp;
3704 mp = vl_msg_api_alloc (sizeof (*mp));
3705 memset (mp, 0, sizeof (*mp));
3706 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3709 memcpy(&mp->ip, ip, sizeof(mp->ip));
3711 u32 * tp = (u32 *)mp->ip;
3712 *tp = ntohl(*(u32*)ip);
3714 mp->prefix_length = prefix_length;
3716 vl_msg_api_send_shmem (q, (u8 *)&mp);
3720 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3722 vpe_api_main_t * am = &vpe_api_main;
3723 unix_shared_memory_queue_t * q;
3726 ip6_main_t * im6 = &ip6_main;
3727 ip4_main_t * im4 = &ip4_main;
3728 ip_lookup_main_t * lm6 = &im6->lookup_main;
3729 ip_lookup_main_t * lm4 = &im4->lookup_main;
3730 ip_interface_address_t * ia = 0;
3731 u32 sw_if_index = ~0;
3733 sw_if_index = ntohl(mp->sw_if_index);
3735 q = vl_api_client_index_to_input_queue (mp->client_index);
3741 foreach_ip_interface_address (lm6, ia, sw_if_index,
3742 1 /* honor unnumbered */,
3744 r6 = ip_interface_address_get_address (lm6, ia);
3745 u16 prefix_length = ia->address_length;
3746 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3749 foreach_ip_interface_address (lm4, ia, sw_if_index,
3750 1 /* honor unnumbered */,
3752 r4 = ip_interface_address_get_address (lm4, ia);
3753 u16 prefix_length = ia->address_length;
3754 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3759 static void send_ip_details (vpe_api_main_t * am,
3760 unix_shared_memory_queue_t *q,
3763 vl_api_ip_details_t * mp;
3765 mp = vl_msg_api_alloc (sizeof (*mp));
3766 memset (mp, 0, sizeof (*mp));
3767 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3769 mp->sw_if_index = ntohl(sw_if_index);
3771 vl_msg_api_send_shmem (q, (u8 *)&mp);
3775 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3776 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3778 vpe_api_main_t * am = &vpe_api_main;
3779 l2t_main_t * lm = &l2t_main;
3780 unix_shared_memory_queue_t * q;
3781 l2t_session_t *session;
3783 q = vl_api_client_index_to_input_queue (mp->client_index);
3787 pool_foreach (session, lm->sessions,
3789 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3794 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3795 unix_shared_memory_queue_t *q,
3796 tapcli_interface_details_t *tap_if)
3798 vl_api_sw_interface_tap_details_t * mp;
3799 mp = vl_msg_api_alloc (sizeof (*mp));
3800 memset (mp, 0, sizeof (*mp));
3801 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3802 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3803 strncpy((char *)mp->dev_name,
3804 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3806 vl_msg_api_send_shmem (q, (u8 *)&mp);
3810 vl_api_sw_interface_tap_dump_t_handler (
3811 vl_api_sw_interface_tap_dump_t *mp)
3814 vpe_api_main_t * am = &vpe_api_main;
3815 unix_shared_memory_queue_t * q;
3816 tapcli_interface_details_t *tapifs = NULL;
3817 tapcli_interface_details_t *tap_if = NULL;
3819 q = vl_api_client_index_to_input_queue (mp->client_index);
3823 rv = vnet_tap_dump_ifs(&tapifs);
3827 vec_foreach(tap_if, tapifs) {
3828 send_sw_interface_tap_details(am, q, tap_if);
3835 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3837 vpe_api_main_t * am = &vpe_api_main;
3838 vnet_main_t * vnm = vnet_get_main();
3839 vlib_main_t * vm = vlib_get_main();
3840 vnet_interface_main_t * im = &vnm->interface_main;
3841 unix_shared_memory_queue_t * q;
3842 vnet_sw_interface_t * si, * sorted_sis;
3843 u32 sw_if_index = ~0;
3845 q = vl_api_client_index_to_input_queue (mp->client_index);
3850 /* Gather interfaces. */
3851 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3852 _vec_len (sorted_sis) = 0;
3853 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3855 vec_foreach (si, sorted_sis) {
3856 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3857 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3860 sw_if_index = si->sw_if_index;
3861 send_ip_details(am, q, sw_if_index);
3866 static void vl_api_l2_fib_table_entry_t_handler (
3867 vl_api_l2_fib_table_entry_t * mp)
3869 clib_warning ("BUG");
3872 static void send_l2fib_table_entry (vpe_api_main_t * am,
3873 unix_shared_memory_queue_t *q,
3874 l2fib_entry_key_t * l2fe_key,
3875 l2fib_entry_result_t * l2fe_res)
3877 vl_api_l2_fib_table_entry_t * mp;
3879 mp = vl_msg_api_alloc (sizeof (*mp));
3880 memset (mp, 0, sizeof (*mp));
3881 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3883 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3885 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3886 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3887 mp->static_mac = l2fe_res->fields.static_mac;
3888 mp->filter_mac = l2fe_res->fields.filter;
3889 mp->bvi_mac = l2fe_res->fields.bvi;
3891 vl_msg_api_send_shmem (q, (u8 *)&mp);
3895 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3897 vpe_api_main_t * am = &vpe_api_main;
3898 bd_main_t * bdm = &bd_main;
3899 l2fib_entry_key_t *l2fe_key = NULL;
3900 l2fib_entry_result_t *l2fe_res = NULL;
3901 u32 ni, bd_id = ntohl (mp->bd_id);
3903 unix_shared_memory_queue_t * q;
3906 q = vl_api_client_index_to_input_queue (mp->client_index);
3910 /* see l2fib_table_dump: ~0 means "any" */
3914 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3921 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3923 vec_foreach_index (ni, l2fe_key) {
3924 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
3925 vec_elt_at_index(l2fe_res, ni));
3932 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
3934 vl_api_show_version_reply_t *rmp;
3936 char * vpe_api_get_build_directory(void);
3937 char * vpe_api_get_version(void);
3938 char * vpe_api_get_build_date(void);
3940 unix_shared_memory_queue_t * q =
3941 vl_api_client_index_to_input_queue (mp->client_index);
3946 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
3948 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
3949 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
3950 ARRAY_LEN(rmp->build_directory)-1);
3951 strncpy ((char *) rmp->version, vpe_api_get_version(),
3952 ARRAY_LEN(rmp->version)-1);
3953 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
3954 ARRAY_LEN(rmp->build_date)-1);
3958 static void vl_api_get_node_index_t_handler
3959 (vl_api_get_node_index_t * mp)
3961 vlib_main_t * vm = vlib_get_main();
3962 vl_api_get_node_index_reply_t * rmp;
3965 u32 node_index = ~0;
3967 n = vlib_get_node_by_name (vm, mp->node_name);
3970 rv = VNET_API_ERROR_NO_SUCH_NODE;
3972 node_index = n->index;
3974 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
3976 rmp->node_index = ntohl(node_index);
3980 static void vl_api_add_node_next_t_handler
3981 (vl_api_add_node_next_t * mp)
3983 vlib_main_t * vm = vlib_get_main();
3984 vl_api_add_node_next_reply_t * rmp;
3985 vlib_node_t * n, * next;
3987 u32 next_index = ~0;
3989 n = vlib_get_node_by_name (vm, mp->node_name);
3992 rv = VNET_API_ERROR_NO_SUCH_NODE;
3996 next = vlib_get_node_by_name (vm, mp->next_name);
3999 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4001 next_index = vlib_node_add_next (vm, n->index, next->index);
4004 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4006 rmp->next_index = ntohl(next_index);
4010 static void vl_api_l2tpv3_create_tunnel_t_handler
4011 (vl_api_l2tpv3_create_tunnel_t *mp)
4013 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4014 l2t_main_t *lm = &l2t_main;
4015 u32 sw_if_index = (u32)~0;
4018 if (mp->is_ipv6 != 1) {
4019 rv = VNET_API_ERROR_UNIMPLEMENTED;
4023 rv = create_l2tpv3_ipv6_tunnel (lm,
4024 (ip6_address_t *) mp->client_address,
4025 (ip6_address_t *) mp->our_address,
4026 ntohl(mp->local_session_id),
4027 ntohl(mp->remote_session_id),
4028 clib_net_to_host_u64(mp->local_cookie),
4029 clib_net_to_host_u64(mp->remote_cookie),
4030 mp->l2_sublayer_present,
4034 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4036 rmp->sw_if_index = ntohl (sw_if_index);
4040 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4041 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4043 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4044 l2t_main_t *lm = &l2t_main;
4047 VALIDATE_SW_IF_INDEX(mp);
4049 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4050 clib_net_to_host_u64(mp->new_local_cookie),
4051 clib_net_to_host_u64(mp->new_remote_cookie));
4053 BAD_SW_IF_INDEX_LABEL;
4055 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4058 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4059 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4062 vnet_main_t * vnm = vnet_get_main();
4063 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4065 VALIDATE_SW_IF_INDEX(mp);
4067 rv = l2tpv3_interface_enable_disable
4068 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4070 BAD_SW_IF_INDEX_LABEL;
4072 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4075 static void vl_api_l2tpv3_set_lookup_key_t_handler
4076 (vl_api_l2tpv3_set_lookup_key_t * mp)
4079 l2t_main_t *lm = &l2t_main;
4080 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4082 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4083 rv = VNET_API_ERROR_INVALID_VALUE;
4087 lm->lookup_type = mp->key;
4090 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4093 static void vl_api_vxlan_add_del_tunnel_t_handler
4094 (vl_api_vxlan_add_del_tunnel_t * mp)
4096 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4098 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4099 u32 encap_fib_index;
4101 ip4_main_t * im = &ip4_main;
4102 u32 sw_if_index = ~0;
4104 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4106 rv = VNET_API_ERROR_NO_SUCH_FIB;
4109 encap_fib_index = p[0];
4111 memset (a, 0, sizeof (*a));
4113 a->is_add = mp->is_add;
4115 /* ip addresses sent in network byte order */
4116 a->src.as_u32 = mp->src_address;
4117 a->dst.as_u32 = mp->dst_address;
4119 a->encap_fib_index = encap_fib_index;
4120 a->decap_next_index = ntohl(mp->decap_next_index);
4121 a->vni = ntohl(mp->vni);
4122 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4125 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4127 rmp->sw_if_index = ntohl (sw_if_index);
4131 static void send_vxlan_tunnel_details
4132 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4134 vl_api_vxlan_tunnel_details_t * rmp;
4135 ip4_main_t * im = &ip4_main;
4137 rmp = vl_msg_api_alloc (sizeof (*rmp));
4138 memset (rmp, 0, sizeof (*rmp));
4139 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4140 rmp->src_address = t->src.data_u32;
4141 rmp->dst_address = t->dst.data_u32;
4142 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4143 rmp->vni = htonl(t->vni);
4144 rmp->decap_next_index = htonl(t->decap_next_index);
4145 rmp->sw_if_index = htonl(t->sw_if_index);
4147 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4150 static void vl_api_vxlan_tunnel_dump_t_handler
4151 (vl_api_vxlan_tunnel_dump_t * mp)
4153 unix_shared_memory_queue_t * q;
4154 vxlan_main_t * vxm = &vxlan_main;
4158 q = vl_api_client_index_to_input_queue (mp->client_index);
4163 sw_if_index = ntohl(mp->sw_if_index);
4165 if (~0 == sw_if_index) {
4166 pool_foreach (t, vxm->tunnels,
4168 send_vxlan_tunnel_details(t, q);
4171 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4172 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4175 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4176 send_vxlan_tunnel_details(t, q);
4181 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4183 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4185 vl_api_l2_patch_add_del_reply_t * rmp;
4186 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4190 VALIDATE_RX_SW_IF_INDEX(mp);
4191 VALIDATE_TX_SW_IF_INDEX(mp);
4193 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4194 ntohl(mp->tx_sw_if_index),
4195 (int)(mp->is_add != 0));
4197 BAD_RX_SW_IF_INDEX_LABEL;
4198 BAD_TX_SW_IF_INDEX_LABEL;
4200 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4204 vl_api_nsh_gre_add_del_tunnel_t_handler
4205 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4207 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4209 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4210 u32 encap_fib_index, decap_fib_index;
4211 u32 decap_next_index;
4213 ip4_main_t * im = &ip4_main;
4215 u32 sw_if_index = ~0;
4218 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4220 rv = VNET_API_ERROR_NO_SUCH_FIB;
4223 encap_fib_index = p[0];
4225 decap_next_index = ntohl(mp->decap_next_index);
4227 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4228 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4229 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4231 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4234 decap_fib_index = p[0];
4236 decap_fib_index = ntohl(mp->decap_vrf_id);
4239 memset (a, 0, sizeof (*a));
4241 a->is_add = mp->is_add;
4242 /* ip addresses sent in network byte order */
4243 a->src.as_u32 = ntohl(mp->src);
4244 a->dst.as_u32 = ntohl(mp->dst);
4245 a->encap_fib_index = encap_fib_index;
4246 a->decap_fib_index = decap_fib_index;
4247 a->decap_next_index = decap_next_index;
4248 a->ver_o_c = mp->ver_o_c;
4249 a->length = mp->length;
4250 a->md_type = mp->md_type;
4251 a->next_protocol = mp->next_protocol;
4252 a->spi_si = ntohl(mp->spi_si);
4253 a->c1 = ntohl(mp->c1);
4254 a->c2 = ntohl(mp->c2);
4255 a->c3 = ntohl(mp->c3);
4256 a->c4 = ntohl(mp->c4);
4258 for (i = 0; i < mp->tlv_len_in_words; i++)
4259 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4263 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4266 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4268 rmp->sw_if_index = ntohl (sw_if_index);
4273 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4274 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4276 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4278 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4279 u32 encap_fib_index, decap_fib_index;
4280 u32 decap_next_index;
4282 ip4_main_t * im = &ip4_main;
4284 u32 sw_if_index = ~0;
4287 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4289 rv = VNET_API_ERROR_NO_SUCH_FIB;
4292 encap_fib_index = p[0];
4294 decap_next_index = ntohl(mp->decap_next_index);
4296 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4297 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4298 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4300 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4303 decap_fib_index = p[0];
4305 decap_fib_index = ntohl(mp->decap_vrf_id);
4308 memset (a, 0, sizeof (*a));
4310 a->is_add = mp->is_add;
4311 /* ip addresses sent in network byte order */
4312 a->src.as_u32 = ntohl(mp->src);
4313 a->dst.as_u32 = ntohl(mp->dst);
4314 a->encap_fib_index = encap_fib_index;
4315 a->decap_fib_index = decap_fib_index;
4316 a->decap_next_index = decap_next_index;
4317 a->vni = ntohl(mp->vni);
4318 a->ver_o_c = mp->ver_o_c;
4319 a->length = mp->length;
4320 a->md_type = mp->md_type;
4321 a->next_protocol = mp->next_protocol;
4322 a->spi_si = ntohl(mp->spi_si);
4323 a->c1 = ntohl(mp->c1);
4324 a->c2 = ntohl(mp->c2);
4325 a->c3 = ntohl(mp->c3);
4326 a->c4 = ntohl(mp->c4);
4328 for (i = 0; i < mp->tlv_len_in_words; i++)
4329 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4333 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4336 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4338 rmp->sw_if_index = ntohl (sw_if_index);
4343 vl_api_lisp_gpe_add_del_tunnel_t_handler
4344 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4346 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4348 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4349 u32 encap_fib_index, decap_fib_index;
4350 u32 decap_next_index;
4352 ip4_main_t * im = &ip4_main;
4353 u32 sw_if_index = ~0;
4355 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4357 rv = VNET_API_ERROR_NO_SUCH_FIB;
4360 encap_fib_index = p[0];
4362 decap_next_index = ntohl(mp->decap_next_index);
4364 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4365 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4366 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4368 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4371 decap_fib_index = p[0];
4373 decap_fib_index = ntohl(mp->decap_vrf_id);
4376 memset (a, 0, sizeof (*a));
4378 a->is_add = mp->is_add;
4379 /* ip addresses sent in network byte order */
4380 a->src.as_u32 = mp->src;
4381 a->dst.as_u32 = mp->dst;
4382 a->encap_fib_index = encap_fib_index;
4383 a->decap_fib_index = decap_fib_index;
4384 a->decap_next_index = decap_next_index;
4385 a->flags = mp->flags;
4386 a->ver_res = mp->ver_res;
4388 a->next_protocol = mp->next_protocol;
4389 a->iid = clib_net_to_host_u32 (mp->iid);
4391 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4394 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4396 rmp->sw_if_index = ntohl (sw_if_index);
4401 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4403 vl_api_interface_name_renumber_reply_t * rmp;
4406 VALIDATE_SW_IF_INDEX(mp);
4408 rv = vnet_interface_name_renumber
4409 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4411 BAD_SW_IF_INDEX_LABEL;
4413 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4416 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4417 u32 sw_if_index, u32 address)
4419 vpe_api_main_t * am = &vpe_api_main;
4420 vlib_main_t * vm = am->vlib_main;
4421 vl_api_ip4_arp_event_t * event;
4422 static f64 arp_event_last_time;
4423 f64 now = vlib_time_now (vm);
4425 if (pool_is_free_index (am->arp_events, pool_index))
4428 event = pool_elt_at_index (am->arp_events, pool_index);
4429 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4430 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4431 } else { /* same mac */
4432 if ((sw_if_index == event->sw_if_index) &&
4434 /* for BD case, also check IP address with 10 sec timeout */
4435 ((address == event->address) &&
4436 ((now - arp_event_last_time) < 10.0))))
4440 arp_event_last_time = now;
4441 event->sw_if_index = sw_if_index;
4442 if (address) event->address = address;
4446 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4448 vpe_api_main_t * am = &vpe_api_main;
4450 if (pool_is_free_index (am->arp_events, pool_index))
4453 pool_put_index (am->arp_events, pool_index);
4458 vl_api_want_ip4_arp_events_t_handler
4459 (vl_api_want_ip4_arp_events_t * mp)
4461 vpe_api_main_t * am = &vpe_api_main;
4462 vnet_main_t * vnm = vnet_get_main();
4463 vl_api_want_ip4_arp_events_reply_t *rmp;
4464 vl_api_ip4_arp_event_t * event;
4467 if (mp->enable_disable) {
4468 pool_get (am->arp_events, event);
4469 memset (event, 0, sizeof (*event));
4471 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4472 event->client_index = mp->client_index;
4473 event->context = mp->context;
4474 event->address = mp->address;
4475 event->pid = mp->pid;
4477 rv = vnet_add_del_ip4_arp_change_event
4478 (vnm, arp_change_data_callback,
4480 &mp->address /* addr, in net byte order */,
4481 vpe_resolver_process_node.index,
4482 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4484 rv = vnet_add_del_ip4_arp_change_event
4485 (vnm, arp_change_delete_callback,
4487 &mp->address /* addr, in net byte order */,
4488 vpe_resolver_process_node.index,
4489 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4491 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4494 static void vl_api_input_acl_set_interface_t_handler
4495 (vl_api_input_acl_set_interface_t * mp)
4497 vlib_main_t *vm = vlib_get_main();
4498 vl_api_input_acl_set_interface_reply_t * rmp;
4500 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4502 ip4_table_index = ntohl(mp->ip4_table_index);
4503 ip6_table_index = ntohl(mp->ip6_table_index);
4504 l2_table_index = ntohl(mp->l2_table_index);
4505 sw_if_index = ntohl(mp->sw_if_index);
4507 VALIDATE_SW_IF_INDEX(mp);
4509 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4510 ip6_table_index, l2_table_index,
4513 BAD_SW_IF_INDEX_LABEL;
4515 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4518 static void vl_api_ipsec_spd_add_del_t_handler
4519 (vl_api_ipsec_spd_add_del_t * mp)
4522 clib_warning ("unimplemented");
4525 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4526 vl_api_ipsec_spd_add_del_reply_t * rmp;
4530 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4532 rv = VNET_API_ERROR_UNIMPLEMENTED;
4535 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4539 static void vl_api_ipsec_interface_add_del_spd_t_handler
4540 (vl_api_ipsec_interface_add_del_spd_t * mp)
4542 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4543 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4545 u32 sw_if_index __attribute__((unused));
4546 u32 spd_id __attribute__((unused));
4548 sw_if_index = ntohl(mp->sw_if_index);
4549 spd_id = ntohl(mp->spd_id);
4551 VALIDATE_SW_IF_INDEX(mp);
4554 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4556 rv = VNET_API_ERROR_UNIMPLEMENTED;
4559 BAD_SW_IF_INDEX_LABEL;
4561 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4564 static void vl_api_ipsec_spd_add_del_entry_t_handler
4565 (vl_api_ipsec_spd_add_del_entry_t * mp)
4567 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4568 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4574 p.id = ntohl(mp->spd_id);
4575 p.priority = ntohl(mp->priority);
4576 p.is_outbound = mp->is_outbound;
4577 p.is_ipv6 = mp->is_ipv6;
4579 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4580 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4581 memcpy(&p.laddr.start, mp->local_address_start, 16);
4582 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4584 p.protocol = mp->protocol;
4585 p.rport.start = ntohs(mp->remote_port_start);
4586 p.rport.stop = ntohs(mp->remote_port_stop);
4587 p.lport.start = ntohs(mp->local_port_start);
4588 p.lport.stop = ntohs(mp->local_port_stop);
4589 /* policy action resolve unsupported */
4590 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4591 clib_warning("unsupported action: 'resolve'");
4592 rv = VNET_API_ERROR_UNIMPLEMENTED;
4595 p.policy = mp->policy;
4596 p.sa_id = ntohl(mp->sa_id);
4598 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4602 if (mp->is_ip_any) {
4604 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4607 rv = VNET_API_ERROR_UNIMPLEMENTED;
4612 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4615 static void vl_api_ipsec_sad_add_del_entry_t_handler
4616 (vl_api_ipsec_sad_add_del_entry_t * mp)
4618 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4619 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4624 sa.id = ntohl(mp->sad_id);
4625 sa.spi = ntohl(mp->spi);
4626 /* security protocol AH unsupported */
4627 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4628 clib_warning("unsupported security protocol 'AH'");
4629 rv = VNET_API_ERROR_UNIMPLEMENTED;
4632 sa.protocol = mp->protocol;
4633 /* check for unsupported crypto-alg */
4634 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4635 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4636 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4637 mp->crypto_algorithm);
4638 rv = VNET_API_ERROR_UNIMPLEMENTED;
4641 sa.crypto_alg = mp->crypto_algorithm;
4642 sa.crypto_key_len = mp->crypto_key_length;
4643 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4644 /* check for unsupported integ-alg */
4645 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4646 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4647 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4648 mp->integrity_algorithm);
4649 rv = VNET_API_ERROR_UNIMPLEMENTED;
4652 sa.integ_alg = mp->integrity_algorithm;
4653 sa.integ_key_len = mp->integrity_key_length;
4654 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4655 sa.use_esn = mp->use_extended_sequence_number;
4656 sa.is_tunnel = mp->is_tunnel;
4657 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4658 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4659 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4661 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4663 rv = VNET_API_ERROR_UNIMPLEMENTED;
4668 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4671 vl_api_map_add_domain_t_handler
4672 (vl_api_map_add_domain_t * mp)
4674 vl_api_map_add_domain_reply_t * rmp;
4677 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4678 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4679 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4680 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4681 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4683 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4685 rmp->index = ntohl(index);
4690 vl_api_map_del_domain_t_handler
4691 (vl_api_map_del_domain_t * mp)
4693 vl_api_map_del_domain_reply_t * rmp;
4696 rv = map_delete_domain(ntohl(mp->index));
4698 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4702 vl_api_map_add_del_rule_t_handler
4703 (vl_api_map_add_del_rule_t * mp)
4705 vl_api_map_del_domain_reply_t * rmp;
4708 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4710 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4714 vl_api_map_domain_dump_t_handler
4715 (vl_api_map_domain_dump_t * mp)
4717 vl_api_map_domain_details_t * rmp;
4718 map_main_t *mm = &map_main;
4720 unix_shared_memory_queue_t * q;
4722 if (pool_elts (mm->domains) == 0)
4725 q = vl_api_client_index_to_input_queue (mp->client_index);
4730 pool_foreach(d, mm->domains, ({
4731 rmp = vl_msg_api_alloc (sizeof (*rmp));
4732 memset (rmp, 0, sizeof (*rmp));
4733 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4734 rmp->domain_index = htonl(d - mm->domains);
4735 rmp->ea_bits_len = d->ea_bits_len;
4736 rmp->psid_offset = d->psid_offset;
4737 rmp->psid_length = d->psid_length;
4738 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4739 rmp->ip4_prefix_len = d->ip4_prefix_len;
4740 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4741 rmp->ip6_prefix_len = d->ip6_prefix_len;
4742 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4743 rmp->ip6_src_len = d->ip6_src_len;
4744 rmp->mtu = htons(d->mtu);
4745 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4747 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4752 vl_api_map_rule_dump_t_handler
4753 (vl_api_map_rule_dump_t * mp)
4755 unix_shared_memory_queue_t * q;
4758 vl_api_map_rule_details_t * rmp;
4759 map_main_t *mm = &map_main;
4760 u32 domain_index = ntohl(mp->domain_index);
4763 if (pool_elts (mm->domains) == 0)
4766 d = pool_elt_at_index(mm->domains, domain_index);
4767 if (!d || !d->rules) {
4771 q = vl_api_client_index_to_input_queue (mp->client_index);
4776 for (i = 0; i < (0x1 << d->psid_length); i++) {
4778 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4781 rmp = vl_msg_api_alloc(sizeof(*rmp));
4782 memset(rmp, 0, sizeof(*rmp));
4783 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4784 rmp->psid = htons(i);
4785 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4786 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4791 vl_api_map_summary_stats_t_handler (
4792 vl_api_map_summary_stats_t *mp)
4794 vl_api_map_summary_stats_reply_t *rmp;
4795 vlib_combined_counter_main_t *cm;
4798 u64 total_pkts[VLIB_N_RX_TX];
4799 u64 total_bytes[VLIB_N_RX_TX];
4800 map_main_t *mm = &map_main;
4801 unix_shared_memory_queue_t *q =
4802 vl_api_client_index_to_input_queue(mp->client_index);
4807 rmp = vl_msg_api_alloc (sizeof (*rmp));
4808 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
4809 rmp->context = mp->context;
4812 memset (total_pkts, 0, sizeof (total_pkts));
4813 memset (total_bytes, 0, sizeof (total_bytes));
4815 map_domain_counter_lock (mm);
4816 vec_foreach(cm, mm->domain_counters) {
4817 which = cm - mm->domain_counters;
4819 for (i = 0; i < vec_len(cm->maxi); i++) {
4820 vlib_get_combined_counter (cm, i, &v);
4821 total_pkts[which] += v.packets;
4822 total_bytes[which] += v.bytes;
4826 map_domain_counter_unlock (mm);
4828 /* Note: in HOST byte order! */
4829 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
4830 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
4831 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
4832 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
4833 rmp->total_bindings = pool_elts(mm->domains);
4834 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
4835 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
4836 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
4838 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4841 static void vl_api_ipsec_sa_set_key_t_handler
4842 (vl_api_ipsec_sa_set_key_t * mp)
4844 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4845 vl_api_ipsec_sa_set_key_reply_t *rmp;
4849 sa.id = ntohl(mp->sa_id);
4850 sa.crypto_key_len = mp->crypto_key_length;
4851 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4852 sa.integ_key_len = mp->integrity_key_length;
4853 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4855 rv = ipsec_set_sa_key(vm, &sa);
4857 rv = VNET_API_ERROR_UNIMPLEMENTED;
4860 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
4863 #define BOUNCE_HANDLER(nn) \
4864 static void vl_api_##nn##_t_handler ( \
4865 vl_api_##nn##_t *mp) \
4867 vpe_client_registration_t *reg; \
4868 vpe_api_main_t * vam = &vpe_api_main; \
4869 unix_shared_memory_queue_t * q; \
4871 /* One registration only... */ \
4872 pool_foreach(reg, vam->nn##_registrations, \
4874 q = vl_api_client_index_to_input_queue (reg->client_index); \
4877 * If the queue is stuffed, turf the msg and complain \
4878 * It's unlikely that the intended recipient is \
4879 * alive; avoid deadlock at all costs. \
4881 if (q->cursize == q->maxsize) { \
4882 clib_warning ("ERROR: receiver queue full, drop msg"); \
4883 vl_msg_api_free (mp); \
4886 vl_msg_api_send_shmem (q, (u8 *)&mp); \
4890 vl_msg_api_free (mp); \
4893 BOUNCE_HANDLER(to_netconf_server);
4894 BOUNCE_HANDLER(from_netconf_server);
4895 BOUNCE_HANDLER(to_netconf_client);
4896 BOUNCE_HANDLER(from_netconf_client);
4900 * Add vpe's API message handlers to the table.
4901 * vlib has alread mapped shared memory and
4902 * added the client registration handlers.
4903 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
4906 static clib_error_t *
4907 vpe_api_hookup (vlib_main_t *vm)
4909 api_main_t * am = &api_main;
4912 vl_msg_api_set_handlers(VL_API_##N, #n, \
4913 vl_api_##n##_t_handler, \
4915 vl_api_##n##_t_endian, \
4916 vl_api_##n##_t_print, \
4917 sizeof(vl_api_##n##_t), 1);
4918 foreach_vpe_api_msg;
4922 * Manually register the sr tunnel add del msg, so we trace
4923 * enough bytes to capture a typical segment list
4925 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
4926 "sr_tunnel_add_del",
4927 vl_api_sr_tunnel_add_del_t_handler,
4929 vl_api_sr_tunnel_add_del_t_endian,
4930 vl_api_sr_tunnel_add_del_t_print,
4933 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
4934 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
4935 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
4936 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
4939 * Trace space for 8 MPLS encap labels, classifier mask+match
4941 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
4942 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
4943 += 5 * sizeof (u32x4);
4944 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
4945 += 5 * sizeof (u32x4);
4946 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
4947 += 16 * sizeof (u32);
4950 * trace space for 4 nsh-gre variable TLV words
4952 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
4953 += 4 * sizeof (u32);
4958 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
4960 static clib_error_t *
4961 vpe_api_init (vlib_main_t *vm)
4963 vpe_api_main_t *am = &vpe_api_main;
4966 am->vnet_main = vnet_get_main();
4967 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
4968 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
4969 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
4970 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
4971 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
4972 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
4975 vl_set_memory_region_name ("/vpe-api");
4976 vl_enable_disable_memory_api (vm, 1 /* enable it */);
4981 VLIB_INIT_FUNCTION(vpe_api_init);
4983 static clib_error_t *
4984 chroot_config (vlib_main_t * vm, unformat_input_t * input)
4988 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
4990 if (unformat (input, "prefix %s", &chroot_path))
4992 vec_add1 (chroot_path, 0);
4993 vl_set_memory_root_path ((char *)chroot_path);
4996 return clib_error_return (0, "unknown input `%U'",
4997 format_unformat_error, input);
5001 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5003 void * get_unformat_vnet_sw_interface (void)
5005 return (void *) &unformat_vnet_sw_interface;
5008 #undef vl_api_version
5009 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5010 #include <api/vpe.api.h>
5011 #undef vl_api_version
5013 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5015 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5016 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5017 clib_host_to_net_u32 (mp->api_versions[0]),
5024 static u8 * format_arp_event (u8 * s, va_list * args)
5026 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5028 s = format (s, "pid %d: %U", event->pid,
5029 format_ip4_address, &event->address);
5033 static clib_error_t *
5034 show_ip4_arp_events_fn (vlib_main_t * vm,
5035 unformat_input_t * input,
5036 vlib_cli_command_t * cmd)
5038 vpe_api_main_t * am = &vpe_api_main;
5039 vl_api_ip4_arp_event_t * event;
5041 if (pool_elts (am->arp_events) == 0) {
5042 vlib_cli_output (vm, "No active arp event registrations");
5046 pool_foreach (event, am->arp_events,
5048 vlib_cli_output (vm, "%U", format_arp_event, event);
5054 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5055 .path = "show arp event registrations",
5056 .function = show_ip4_arp_events_fn,
5057 .short_help = "Show arp event registrations",