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>
72 #include <vnet/cop/cop.h>
73 #include <vnet/ip/ip6_hop_by_hop.h>
76 #undef __included_bihash_template_h__
77 #include <vnet/l2/l2_fib.h>
80 #include <vnet/ipsec/ipsec.h>
83 #include <vnet/devices/virtio/vhost-user.h>
86 #include <stats/stats.h>
89 #include <vnet/ethernet/ethernet.h>
90 #include <vnet/ethernet/arp_packet.h>
91 #include <vnet/interface.h>
93 #include <vnet/l2/l2_fib.h>
94 #include <vnet/l2/l2_bd.h>
95 #include <api/vpe_msg_enum.h>
98 #define f64_print(a,b)
100 #define vl_typedefs /* define message structures */
101 #include <api/vpe_all_api_h.h>
104 #define vl_endianfun /* define message structures */
105 #include <api/vpe_all_api_h.h>
108 /* instantiate all the print functions we know about */
109 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
111 #include <api/vpe_all_api_h.h>
114 #define REPLY_MACRO(t) \
116 unix_shared_memory_queue_t * q; \
117 rv = vl_msg_api_pd_handler (mp, rv); \
118 q = vl_api_client_index_to_input_queue (mp->client_index); \
122 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
123 rmp->_vl_msg_id = ntohs((t)); \
124 rmp->context = mp->context; \
125 rmp->retval = ntohl(rv); \
127 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
130 #define REPLY_MACRO2(t, body) \
132 unix_shared_memory_queue_t * q; \
133 rv = vl_msg_api_pd_handler (mp, rv); \
134 q = vl_api_client_index_to_input_queue (mp->client_index); \
138 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
139 rmp->_vl_msg_id = ntohs((t)); \
140 rmp->context = mp->context; \
141 rmp->retval = ntohl(rv); \
142 do {body;} while (0); \
143 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
146 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
148 #define VALIDATE_SW_IF_INDEX(mp) \
149 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
150 vnet_main_t *__vnm = vnet_get_main(); \
151 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
153 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
154 goto bad_sw_if_index; \
158 #define BAD_SW_IF_INDEX_LABEL \
164 #define VALIDATE_RX_SW_IF_INDEX(mp) \
165 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
166 vnet_main_t *__vnm = vnet_get_main(); \
167 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
168 __rx_sw_if_index)) { \
169 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
170 goto bad_rx_sw_if_index; \
174 #define BAD_RX_SW_IF_INDEX_LABEL \
176 bad_rx_sw_if_index: \
180 #define VALIDATE_TX_SW_IF_INDEX(mp) \
181 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
182 vnet_main_t *__vnm = vnet_get_main(); \
183 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
184 __tx_sw_if_index)) { \
185 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
186 goto bad_tx_sw_if_index; \
190 #define BAD_TX_SW_IF_INDEX_LABEL \
192 bad_tx_sw_if_index: \
198 #define VALIDATE_SW_IF_INDEX(mp)
199 #define BAD_SW_IF_INDEX_LABEL
200 #define VALIDATE_RX_SW_IF_INDEX(mp)
201 #define BAD_RX_SW_IF_INDEX_LABEL
202 #define VALIDATE_TX_SW_IF_INDEX(mp)
203 #define BAD_TX_SW_IF_INDEX_LABEL
205 #endif /* CLIB_DEBUG > 0 */
207 #define foreach_vpe_api_msg \
208 _(WANT_INTERFACE_EVENTS, want_interface_events) \
209 _(WANT_FROM_NETCONF_SERVER, want_from_netconf_server) \
210 _(WANT_TO_NETCONF_SERVER, want_to_netconf_server) \
211 _(WANT_FROM_NETCONF_CLIENT, want_from_netconf_client) \
212 _(WANT_TO_NETCONF_CLIENT, want_to_netconf_client) \
213 _(FROM_NETCONF_SERVER, from_netconf_server) \
214 _(TO_NETCONF_SERVER, to_netconf_server) \
215 _(FROM_NETCONF_CLIENT, from_netconf_client) \
216 _(TO_NETCONF_CLIENT, to_netconf_client) \
217 _(WANT_OAM_EVENTS, want_oam_events) \
218 _(OAM_ADD_DEL, oam_add_del) \
219 _(SW_INTERFACE_DUMP, sw_interface_dump) \
220 _(SW_INTERFACE_DETAILS, sw_interface_details) \
221 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
222 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
223 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
224 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
225 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
226 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
227 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
228 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
229 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
230 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
231 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
232 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
233 _(L2FIB_ADD_DEL, l2fib_add_del) \
234 _(L2_FLAGS, l2_flags) \
235 _(BRIDGE_FLAGS, bridge_flags) \
236 _(TAP_CONNECT, tap_connect) \
237 _(TAP_MODIFY, tap_modify) \
238 _(TAP_DELETE, tap_delete) \
239 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
240 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
241 _(CREATE_SUBIF, create_subif) \
242 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
243 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
244 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
245 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
246 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
247 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
248 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
249 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
250 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
251 _(RESET_FIB, reset_fib) \
252 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
253 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
254 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
255 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
256 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
257 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
258 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
259 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
260 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
261 sw_interface_ip6_set_link_local_address) \
262 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
263 _(CREATE_LOOPBACK, create_loopback) \
264 _(CONTROL_PING, control_ping) \
265 _(CLI_REQUEST, cli_request) \
266 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
267 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
268 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
269 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
270 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
271 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
272 _(GET_NODE_INDEX, get_node_index) \
273 _(ADD_NODE_NEXT, add_node_next) \
274 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
275 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
276 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
277 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
278 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
279 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
280 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
281 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
282 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
283 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
284 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
285 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
286 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
287 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
288 _(IP_ADDRESS_DUMP, ip_address_dump) \
289 _(IP_DUMP, ip_dump) \
290 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
291 _(SHOW_VERSION, show_version) \
292 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
293 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
294 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
295 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
296 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel) \
297 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
298 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
299 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
300 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
301 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
302 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
303 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
304 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
305 _(DELETE_LOOPBACK, delete_loopback) \
306 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
307 _(MAP_ADD_DOMAIN, map_add_domain) \
308 _(MAP_DEL_DOMAIN, map_del_domain) \
309 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
310 _(MAP_DOMAIN_DUMP, map_domain_dump) \
311 _(MAP_RULE_DUMP, map_rule_dump) \
312 _(MAP_SUMMARY_STATS, map_summary_stats) \
313 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
314 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
315 _(GET_NODE_GRAPH, get_node_graph) \
316 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
317 _(TRACE_PROFILE_ADD, trace_profile_add) \
318 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
319 _(TRACE_PROFILE_DEL, trace_profile_del)
322 #define QUOTE(x) QUOTE_(x)
324 #define foreach_registration_hash \
325 _(interface_events) \
326 _(to_netconf_server) \
327 _(from_netconf_server) \
328 _(to_netconf_client) \
329 _(from_netconf_client) \
333 RESOLVE_IP4_ADD_DEL_ROUTE=1,
334 RESOLVE_IP6_ADD_DEL_ROUTE,
335 RESOLVE_MPLS_ETHERNET_ADD_DEL,
341 vl_api_ip_add_del_route_t r;
342 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
348 #define _(a) uword *a##_registration_hash; \
349 vpe_client_registration_t * a##_registrations;
350 foreach_registration_hash
353 /* notifications happen really early in the game */
354 u8 link_state_process_up;
356 /* ip4 pending route adds */
357 pending_route_t * pending_routes;
359 /* ip4 arp event registration pool */
360 vl_api_ip4_arp_event_t * arp_events;
363 vlib_main_t * vlib_main;
364 vnet_main_t * vnet_main;
367 static vlib_node_registration_t vpe_resolver_process_node;
368 static vpe_api_main_t vpe_api_main;
370 static void send_sw_interface_flags (vpe_api_main_t * am,
371 unix_shared_memory_queue_t *q,
372 vnet_sw_interface_t * swif);
373 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
374 unix_shared_memory_queue_t *q,
377 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
380 /* Clean up all registrations belonging to the indicated client */
381 int vl_api_memclnt_delete_callback (u32 client_index)
383 vpe_api_main_t * vam = &vpe_api_main;
384 vpe_client_registration_t *rp;
386 int stats_memclnt_delete_callback (u32 client_index);
388 stats_memclnt_delete_callback (client_index);
391 p = hash_get (vam->a##_registration_hash, client_index); \
393 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
394 pool_put (vam->a##_registrations, rp); \
395 hash_unset (vam->a##_registration_hash, client_index); \
397 foreach_registration_hash;
402 #define API_LINK_STATE_EVENT 1
403 #define API_ADMIN_UP_DOWN_EVENT 2
406 event_data_cmp (void * a1, void * a2)
411 return (word) e1[0] - (word) e2[0];
415 link_state_process (vlib_main_t * vm,
416 vlib_node_runtime_t * rt,
419 vpe_api_main_t * vam = &vpe_api_main;
420 vnet_main_t * vnm = vam->vnet_main;
421 vnet_sw_interface_t * swif;
422 uword * event_data = 0;
423 vpe_client_registration_t *reg;
425 u32 prev_sw_if_index;
426 unix_shared_memory_queue_t * q;
428 vam->link_state_process_up = 1;
431 vlib_process_wait_for_event (vm);
433 /* Unified list of changed link or admin state sw_if_indices */
434 vlib_process_get_events_with_type
435 (vm, &event_data, API_LINK_STATE_EVENT);
436 vlib_process_get_events_with_type
437 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
439 /* Sort, so we can eliminate duplicates */
440 vec_sort_with_function (event_data, event_data_cmp);
442 prev_sw_if_index = ~0;
444 for (i = 0; i < vec_len(event_data); i++) {
445 /* Only one message per swif */
446 if (prev_sw_if_index == event_data[i])
448 prev_sw_if_index = event_data[i];
450 pool_foreach(reg, vam->interface_events_registrations,
452 q = vl_api_client_index_to_input_queue (reg->client_index);
454 // sw_interface may be deleted already
455 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
458 swif = vnet_get_sw_interface (vnm, event_data[i]);
459 send_sw_interface_flags (vam, q, swif);
464 vec_reset_length (event_data);
470 static clib_error_t *
471 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
472 static clib_error_t *
473 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
475 VLIB_REGISTER_NODE (link_state_process_node,static) = {
476 .function = link_state_process,
477 .type = VLIB_NODE_TYPE_PROCESS,
478 .name = "vpe-link-state-process",
481 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
482 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
484 static clib_error_t *
485 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
487 vpe_api_main_t * vam = &vpe_api_main;
488 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
490 if (vam->link_state_process_up)
491 vlib_process_signal_event (vam->vlib_main,
492 link_state_process_node.index,
493 API_LINK_STATE_EVENT,
498 static clib_error_t *
499 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
501 vpe_api_main_t * vam = &vpe_api_main;
504 * Note: it's perfectly fair to set a subif admin up / admin down.
505 * Note the subtle distinction between this routine and the previous
508 if (vam->link_state_process_up)
509 vlib_process_signal_event (vam->vlib_main,
510 link_state_process_node.index,
511 API_ADMIN_UP_DOWN_EVENT,
516 #define pub_sub_handler(lca,UCA) \
517 static void vl_api_want_##lca##_t_handler ( \
518 vl_api_want_##lca##_t *mp) \
520 vpe_api_main_t *vam = &vpe_api_main; \
521 vpe_client_registration_t *rp; \
522 vl_api_want_##lca##_reply_t *rmp; \
526 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
528 if (mp->enable_disable) { \
529 clib_warning ("pid %d: already enabled...", mp->pid); \
530 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
533 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
534 pool_put (vam->lca##_registrations, rp); \
535 hash_unset (vam->lca##_registration_hash, \
540 if (mp->enable_disable == 0) { \
541 clib_warning ("pid %d: already disabled...", mp->pid); \
542 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
545 pool_get (vam->lca##_registrations, rp); \
546 rp->client_index = mp->client_index; \
547 rp->client_pid = mp->pid; \
548 hash_set (vam->lca##_registration_hash, rp->client_index, \
549 rp - vam->lca##_registrations); \
552 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
555 pub_sub_handler (interface_events,INTERFACE_EVENTS)
556 pub_sub_handler (from_netconf_server,FROM_NETCONF_SERVER)
557 pub_sub_handler (to_netconf_server,TO_NETCONF_SERVER)
558 pub_sub_handler (from_netconf_client,FROM_NETCONF_CLIENT)
559 pub_sub_handler (to_netconf_client,TO_NETCONF_CLIENT)
560 pub_sub_handler (oam_events,OAM_EVENTS)
562 #define RESOLUTION_EVENT 1
563 #define RESOLUTION_PENDING_EVENT 2
564 #define IP4_ARP_EVENT 3
566 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
567 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
568 static int mpls_ethernet_add_del_tunnel_2_t_handler
569 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
571 void handle_ip4_arp_event (u32 pool_index)
573 vpe_api_main_t * vam = &vpe_api_main;
574 vnet_main_t * vnm = vam->vnet_main;
575 vlib_main_t * vm = vam->vlib_main;
576 vl_api_ip4_arp_event_t * event;
577 vl_api_ip4_arp_event_t * mp;
578 unix_shared_memory_queue_t * q;
580 /* Client can cancel, die, etc. */
581 if (pool_is_free_index (vam->arp_events, pool_index))
584 event = pool_elt_at_index (vam->arp_events, pool_index);
586 q = vl_api_client_index_to_input_queue (event->client_index);
588 (void) vnet_add_del_ip4_arp_change_event
589 (vnm, arp_change_delete_callback,
590 event->pid, &event->address,
591 vpe_resolver_process_node.index, IP4_ARP_EVENT,
592 ~0 /* pool index, notused */, 0 /* is_add */);
596 if (q->cursize < q->maxsize) {
597 mp = vl_msg_api_alloc (sizeof (*mp));
598 memcpy (mp, event, sizeof (*mp));
599 vl_msg_api_send_shmem (q, (u8 *)&mp);
601 static f64 last_time;
603 * Throttle syslog msgs.
604 * It's pretty tempting to just revoke the registration...
606 if (vlib_time_now (vm) > last_time + 10.0) {
607 clib_warning ("arp event for %U to pid %d: queue stuffed!",
608 format_ip4_address, &event->address, event->pid);
609 last_time = vlib_time_now(vm);
615 resolver_process (vlib_main_t * vm,
616 vlib_node_runtime_t * rt,
620 uword *event_data = 0;
622 vpe_api_main_t * vam = &vpe_api_main;
623 pending_route_t * pr;
624 vl_api_ip_add_del_route_t * adr;
625 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
626 u32 * resolution_failures = 0;
631 vlib_process_wait_for_event_or_clock (vm, timeout);
633 event_type = vlib_process_get_events (vm, &event_data);
635 switch (event_type) {
636 case RESOLUTION_PENDING_EVENT:
640 case RESOLUTION_EVENT:
641 for (i = 0; i < vec_len(event_data); i++) {
643 * Resolution events can occur long after the
644 * original request has timed out. $$$ add a cancel
647 if (pool_is_free_index (vam->pending_routes, event_data[i]))
650 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
654 switch (pr->resolve_type) {
655 case RESOLVE_IP4_ADD_DEL_ROUTE:
656 rv = ip4_add_del_route_t_handler (adr);
657 clib_warning ("resolver: add %U/%d via %U %s",
659 (ip4_address_t *)&(adr->dst_address),
660 adr->dst_address_length,
662 (ip4_address_t *)&(adr->next_hop_address),
663 (rv >= 0) ? "succeeded" : "failed");
666 case RESOLVE_IP6_ADD_DEL_ROUTE:
667 rv = ip6_add_del_route_t_handler (adr);
668 clib_warning ("resolver: add %U/%d via %U %s",
670 (ip6_address_t *)&(adr->dst_address),
671 adr->dst_address_length,
673 (ip6_address_t *)&(adr->next_hop_address),
674 (rv >= 0) ? "succeeded" : "failed");
677 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
678 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
679 clib_warning ("resolver: add mpls-o-e via %U %s",
681 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
682 (rv >= 0) ? "succeeded" : "failed");
686 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
688 pool_put (vam->pending_routes, pr);
693 for (i = 0; i < vec_len(event_data); i++)
694 handle_ip4_arp_event (event_data[i]);
697 case ~0: /* timeout, retry pending resolutions */
698 pool_foreach (pr, vam->pending_routes,
704 /* May fail, e.g. due to interface down */
705 switch (pr->resolve_type) {
706 case RESOLVE_IP4_ADD_DEL_ROUTE:
707 e = ip4_probe_neighbor
708 (vm, (ip4_address_t *)&(adr->next_hop_address),
709 ntohl(adr->next_hop_sw_if_index));
712 case RESOLVE_IP6_ADD_DEL_ROUTE:
713 e = ip6_probe_neighbor
714 (vm, (ip6_address_t *)&(adr->next_hop_address),
715 ntohl(adr->next_hop_sw_if_index));
718 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
720 e = ip4_probe_neighbor
722 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
723 pme->resolve_opaque);
727 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
731 clib_error_report (e);
733 adr->resolve_attempts = 1;
735 pme->resolve_attempts = 1;
739 adr->resolve_attempts -= 1;
740 if (adr->resolve_attempts == 0)
741 vec_add1 (resolution_failures,
742 pr - vam->pending_routes);
744 pme->resolve_attempts -= 1;
745 if (pme->resolve_attempts == 0)
746 vec_add1 (resolution_failures,
747 pr - vam->pending_routes);
751 for (i = 0; i < vec_len (resolution_failures); i++) {
752 pr = pool_elt_at_index (vam->pending_routes,
753 resolution_failures[i]);
757 switch (pr->resolve_type) {
758 case RESOLVE_IP4_ADD_DEL_ROUTE:
759 clib_warning ("resolver: add %U/%d via %U retry failure",
761 (ip4_address_t *)&(adr->dst_address),
762 adr->dst_address_length,
764 (ip4_address_t *)&(adr->next_hop_address));
767 case RESOLVE_IP6_ADD_DEL_ROUTE:
768 clib_warning ("resolver: add %U/%d via %U retry failure",
770 (ip6_address_t *)&(adr->dst_address),
771 adr->dst_address_length,
773 (ip6_address_t *)&(adr->next_hop_address));
776 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
777 clib_warning ("resolver: add mpls-o-e via %U retry failure",
779 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
783 clib_warning ("BUG");
785 pool_put(vam->pending_routes, pr);
787 vec_reset_length (resolution_failures);
790 if (pool_elts (vam->pending_routes) == 0)
792 vec_reset_length (event_data);
794 return 0; /* or not */
797 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
798 .function = resolver_process,
799 .type = VLIB_NODE_TYPE_PROCESS,
800 .name = "vpe-route-resolver-process",
803 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
805 ip4_main_t * im = &ip4_main;
806 ip_lookup_main_t * lm = &im->lookup_main;
807 vnet_classify_main_t * cm = &vnet_classify_main;
808 stats_main_t * sm = &stats_main;
809 ip4_add_del_route_args_t a;
810 ip4_address_t next_hop_address;
812 vpe_api_main_t * vam = &vpe_api_main;
813 vnet_main_t * vnm = vam->vnet_main;
814 vlib_main_t * vm = vlib_get_main();
815 pending_route_t * pr;
816 vl_api_ip_add_del_route_t * adr;
820 ip_adjacency_t *nh_adj, *add_adj = 0;
822 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
824 if (mp->create_vrf_if_needed) {
826 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
828 fib_index = f->index;
830 /* No such VRF, and we weren't asked to create one */
831 return VNET_API_ERROR_NO_SUCH_FIB;
837 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
838 ntohl(mp->next_hop_sw_if_index)))
839 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
841 memcpy (next_hop_address.data, mp->next_hop_address,
842 sizeof (next_hop_address.data));
844 /* Arp for the next_hop if necessary */
845 if (mp->is_add && mp->resolve_if_needed) {
847 ip_adjacency_t * adj;
849 lookup_result = ip4_fib_lookup_with_table
850 (im, fib_index, &next_hop_address, 1 /* disable default route */);
852 adj = ip_get_adjacency (lm, lookup_result);
854 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
855 pool_get (vam->pending_routes, pr);
856 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
858 memcpy (adr, mp, sizeof (*adr));
859 /* recursion block, "just in case" */
860 adr->resolve_if_needed = 0;
861 adr->resolve_attempts = ntohl(mp->resolve_attempts);
862 vnet_register_ip4_arp_resolution_event
863 (vnm, &next_hop_address, vpe_resolver_process_node.index,
864 RESOLUTION_EVENT, pr - vam->pending_routes);
866 vlib_process_signal_event
867 (vm, vpe_resolver_process_node.index,
868 RESOLUTION_PENDING_EVENT, 0 /* data */);
870 /* The interface may be down, etc. */
871 e = ip4_probe_neighbor
872 (vm, (ip4_address_t *)&(mp->next_hop_address),
873 ntohl(mp->next_hop_sw_if_index));
876 clib_error_report(e);
878 return VNET_API_ERROR_IN_PROGRESS;
882 if (mp->is_multipath) {
885 dslock (sm, 1 /* release hint */, 10 /* tag */);
888 flags = IP4_ROUTE_FLAG_ADD;
890 flags = IP4_ROUTE_FLAG_DEL;
893 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
895 ip4_add_del_route_next_hop (im, flags,
896 (ip4_address_t *) mp->dst_address,
897 (u32) mp->dst_address_length,
898 (ip4_address_t *) mp->next_hop_address,
899 ntohl(mp->next_hop_sw_if_index),
900 (u32) mp->next_hop_weight,
907 memset (&a, 0, sizeof (a));
908 memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
910 a.dst_address_length = mp->dst_address_length;
912 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
913 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
914 a.table_index_or_table_id = fib_index;
919 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
921 dslock (sm, 1 /* release hint */, 2 /* tag */);
925 ai = lm->drop_adj_index;
926 else if (mp->is_local)
927 ai = lm->local_adj_index;
928 else if (mp->is_classify) {
930 memset(&cadj, 0, sizeof(cadj));
931 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
932 cadj.classify_table_index = ntohl(mp->classify_table_index);
933 if (pool_is_free_index (cm->tables, cadj.classify_table_index)) {
935 return VNET_API_ERROR_NO_SUCH_TABLE;
937 vec_add1 (add_adj, cadj);
941 ai = ip4_fib_lookup_with_table
942 (im, fib_index, &next_hop_address,
943 1 /* disable default route */);
944 if (ai == lm->miss_adj_index) {
946 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
950 nh_adj = ip_get_adjacency (lm, ai);
951 vec_add1 (add_adj, nh_adj[0]);
952 if (mp->lookup_in_vrf) {
953 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
955 add_adj[0].explicit_fib_index = p[0];
959 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
963 ip_adjacency_t * adj;
964 int disable_default_route = 1;
966 /* Trying to delete the default route? */
967 if (a.dst_address.as_u32 == 0 &&
968 a.dst_address_length == 0)
969 disable_default_route = 0;
971 ai = ip4_fib_lookup_with_table
972 (im, fib_index, &a.dst_address, disable_default_route);
973 if (ai == lm->miss_adj_index) {
975 return VNET_API_ERROR_UNKNOWN_DESTINATION;
978 adj = ip_get_adjacency (lm, ai);
979 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
981 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
988 a.n_add_adj = vec_len(add_adj);
989 ip4_add_del_route (im, &a);
997 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
999 ip6_main_t * im = &ip6_main;
1000 ip_lookup_main_t * lm = &im->lookup_main;
1001 vnet_main_t * vnm = vnet_get_main();
1002 vlib_main_t * vm = vlib_get_main();
1003 vpe_api_main_t * vam = &vpe_api_main;
1004 stats_main_t * sm = &stats_main;
1005 ip6_add_del_route_args_t a;
1006 ip6_address_t next_hop_address;
1007 pending_route_t * pr;
1008 vl_api_ip_add_del_route_t * adr;
1013 ip_adjacency_t * nh_adj, * add_adj = 0;
1016 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1019 if (mp->create_vrf_if_needed) {
1021 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1023 fib_index = f->index;
1025 /* No such VRF, and we weren't asked to create one */
1026 return VNET_API_ERROR_NO_SUCH_FIB;
1032 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1033 ntohl(mp->next_hop_sw_if_index)))
1034 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1036 memcpy (next_hop_address.as_u8, mp->next_hop_address,
1037 sizeof (next_hop_address.as_u8));
1039 /* Arp for the next_hop if necessary */
1040 if (mp->is_add && mp->resolve_if_needed) {
1042 ip_adjacency_t * adj;
1044 lookup_result = ip6_fib_lookup_with_table
1045 (im, fib_index, &next_hop_address);
1047 adj = ip_get_adjacency (lm, lookup_result);
1049 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1050 pool_get (vam->pending_routes, pr);
1052 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1053 memcpy (adr, mp, sizeof (*adr));
1054 /* recursion block, "just in case" */
1055 adr->resolve_if_needed = 0;
1056 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1057 vnet_register_ip6_neighbor_resolution_event
1058 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1059 RESOLUTION_EVENT, pr - vam->pending_routes);
1061 vlib_process_signal_event
1062 (vm, vpe_resolver_process_node.index,
1063 RESOLUTION_PENDING_EVENT, 0 /* data */);
1065 /* The interface may be down, etc. */
1066 e = ip6_probe_neighbor
1067 (vm, (ip6_address_t *)&(mp->next_hop_address),
1068 ntohl(mp->next_hop_sw_if_index));
1071 clib_error_report(e);
1073 return VNET_API_ERROR_IN_PROGRESS;
1077 if (mp->is_multipath) {
1080 dslock (sm, 1 /* release hint */, 11 /* tag */);
1083 flags = IP6_ROUTE_FLAG_ADD;
1085 flags = IP6_ROUTE_FLAG_DEL;
1088 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1090 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1091 (u32) mp->dst_address_length,
1092 (ip6_address_t *)mp->next_hop_address,
1093 ntohl(mp->next_hop_sw_if_index),
1094 (u32) mp->next_hop_weight,
1101 memset (&a, 0, sizeof (a));
1102 memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1104 a.dst_address_length = mp->dst_address_length;
1106 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1107 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1108 a.table_index_or_table_id = fib_index;
1113 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1115 dslock (sm, 1 /* release hint */, 3 /* tag */);
1119 ai = lm->drop_adj_index;
1120 else if (mp->is_local)
1121 ai = lm->local_adj_index;
1123 ai = ip6_fib_lookup_with_table
1124 (im, fib_index, &next_hop_address);
1125 if (ai == lm->miss_adj_index) {
1127 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1131 nh_adj = ip_get_adjacency (lm, ai);
1132 vec_add1 (add_adj, nh_adj[0]);
1133 if (mp->lookup_in_vrf) {
1134 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1136 add_adj[0].explicit_fib_index = p[0];
1140 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1144 ip_adjacency_t * adj;
1146 ai = ip6_fib_lookup_with_table
1147 (im, fib_index, &a.dst_address);
1148 if (ai == lm->miss_adj_index) {
1150 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1152 adj = ip_get_adjacency (lm, ai);
1153 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1155 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1160 a.add_adj = add_adj;
1161 a.n_add_adj = vec_len(add_adj);
1162 ip6_add_del_route (im, &a);
1170 void vl_api_ip_add_del_route_t_handler (
1171 vl_api_ip_add_del_route_t *mp)
1173 vl_api_ip_add_del_route_reply_t * rmp;
1175 vnet_main_t * vnm = vnet_get_main();
1180 rv = ip6_add_del_route_t_handler (mp);
1182 rv = ip4_add_del_route_t_handler (mp);
1184 rv = (rv == 0) ? vnm->api_errno : rv;
1186 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1189 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1190 u32 sw_if_index, u8 *next_hop_addr)
1192 vl_api_ip_add_del_route_t mp;
1195 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1198 * Configure default IP route:
1199 * - ip route add 0.0.0.0/1 via <GW IP>
1200 * - ip route add 128.0.0.0/1 via <GW IP>
1202 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1204 mp.resolve_attempts = ~0;
1205 mp.resolve_if_needed = 1;
1207 mp.is_ipv6 = is_ipv6;
1208 mp.next_hop_weight = 1;
1210 memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1213 rv = ip6_add_del_route_t_handler (&mp);
1216 mp.dst_address_length = 1;
1218 mp.dst_address[0] = 0;
1219 rv = ip4_add_del_route_t_handler (&mp);
1221 mp.dst_address[0] = 128;
1222 rv |= ip4_add_del_route_t_handler (&mp);
1226 clib_error_return (0, "failed to config default IP route");
1231 vl_api_sw_interface_add_del_address_t_handler
1232 (vl_api_sw_interface_add_del_address_t *mp)
1234 vlib_main_t *vm = vlib_get_main();
1235 vl_api_sw_interface_add_del_address_reply_t * rmp;
1239 VALIDATE_SW_IF_INDEX(mp);
1241 is_del = mp->is_add == 0;
1244 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1245 else if (mp->is_ipv6)
1246 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1247 (void *)mp->address,
1248 mp->address_length, is_del);
1250 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1251 (void *) mp->address,
1252 mp->address_length, is_del);
1254 BAD_SW_IF_INDEX_LABEL;
1256 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1260 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1263 u32 table_id = ntohl(mp->vrf_id);
1264 u32 sw_if_index = ntohl(mp->sw_if_index);
1265 vl_api_sw_interface_set_table_reply_t * rmp;
1266 stats_main_t * sm = &stats_main;
1268 VALIDATE_SW_IF_INDEX(mp);
1270 dslock (sm, 1 /* release hint */, 4 /* tag */);
1273 ip6_main_t * im = &ip6_main;
1275 find_ip6_fib_by_table_index_or_id (im, table_id,
1276 IP6_ROUTE_FLAG_TABLE_ID);
1278 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1279 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1281 rv = VNET_API_ERROR_NO_SUCH_FIB;
1284 ip4_main_t * im = &ip4_main;
1285 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1286 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1288 /* Truthfully this can't fail */
1290 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1291 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1293 rv = VNET_API_ERROR_NO_SUCH_FIB;
1298 BAD_SW_IF_INDEX_LABEL;
1300 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1304 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1306 vlib_main_t *vm = vlib_get_main();
1307 vl_api_sw_interface_set_vpath_reply_t * rmp;
1310 u32 sw_if_index = ntohl(mp->sw_if_index);
1311 ip4_main_t *ip4m = &ip4_main;
1312 ip6_main_t *ip6m = &ip6_main;
1313 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1314 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1315 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1316 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1317 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1318 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1320 VALIDATE_SW_IF_INDEX(mp);
1322 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1324 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1325 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1326 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1327 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1328 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1329 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1330 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1331 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1332 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1333 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1334 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1335 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1336 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1337 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1338 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1339 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1341 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1342 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1343 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1344 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1345 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1346 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1347 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1348 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1349 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1350 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1351 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1352 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1353 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1354 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1355 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1356 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1359 BAD_SW_IF_INDEX_LABEL;
1361 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1365 vl_api_sw_interface_set_l2_xconnect_t_handler (
1366 vl_api_sw_interface_set_l2_xconnect_t *mp)
1368 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1370 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1371 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1372 vlib_main_t *vm = vlib_get_main();
1373 vnet_main_t *vnm = vnet_get_main();
1375 VALIDATE_RX_SW_IF_INDEX(mp);
1378 VALIDATE_TX_SW_IF_INDEX(mp);
1379 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1380 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1382 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1385 BAD_RX_SW_IF_INDEX_LABEL;
1386 BAD_TX_SW_IF_INDEX_LABEL;
1388 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1392 vl_api_sw_interface_set_l2_bridge_t_handler (
1393 vl_api_sw_interface_set_l2_bridge_t *mp)
1395 bd_main_t * bdm = &bd_main;
1396 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1398 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1399 u32 bd_id = ntohl(mp->bd_id);
1403 vlib_main_t *vm = vlib_get_main();
1404 vnet_main_t *vnm = vnet_get_main();
1406 VALIDATE_RX_SW_IF_INDEX(mp);
1408 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1411 //VALIDATE_TX_SW_IF_INDEX(mp);
1412 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1413 rx_sw_if_index, bd_index, bvi, shg, 0);
1415 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1418 BAD_RX_SW_IF_INDEX_LABEL;
1420 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1424 vl_api_bridge_domain_add_del_t_handler (
1425 vl_api_bridge_domain_add_del_t *mp)
1427 vlib_main_t * vm = vlib_get_main ();
1428 bd_main_t * bdm = &bd_main;
1429 vl_api_bridge_domain_add_del_reply_t * rmp;
1431 u32 enable_flags = 0, disable_flags = 0;
1432 u32 bd_id = ntohl(mp->bd_id);
1436 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1439 enable_flags |= L2_FLOOD;
1441 disable_flags |= L2_FLOOD;
1444 enable_flags |= L2_UU_FLOOD;
1446 disable_flags |= L2_UU_FLOOD;
1449 enable_flags |= L2_FWD;
1451 disable_flags |= L2_FWD;
1454 enable_flags |= L2_ARP_TERM;
1456 disable_flags |= L2_ARP_TERM;
1459 enable_flags |= L2_LEARN;
1461 disable_flags |= L2_LEARN;
1464 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1467 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1470 rv = bd_delete_bd_index(bdm, bd_id);
1472 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1475 static void vl_api_bridge_domain_details_t_handler (
1476 vl_api_bridge_domain_details_t * mp)
1478 clib_warning ("BUG");
1481 static void vl_api_bridge_domain_sw_if_details_t_handler (
1482 vl_api_bridge_domain_sw_if_details_t * mp)
1484 clib_warning ("BUG");
1487 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1488 l2_bridge_domain_t * bd_config,
1491 vl_api_bridge_domain_details_t * mp;
1493 mp = vl_msg_api_alloc (sizeof (*mp));
1494 memset (mp, 0, sizeof (*mp));
1495 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1496 mp->bd_id = ntohl (bd_config->bd_id);
1497 mp->flood = bd_feature_flood (bd_config);
1498 mp->uu_flood = bd_feature_uu_flood (bd_config);
1499 mp->forward = bd_feature_forward (bd_config);
1500 mp->learn = bd_feature_learn (bd_config);
1501 mp->arp_term = bd_feature_arp_term (bd_config);
1502 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1503 mp->n_sw_ifs = ntohl (n_sw_ifs);
1505 vl_msg_api_send_shmem (q, (u8 *)&mp);
1508 static void send_bd_sw_if_details (l2input_main_t * l2im,
1509 unix_shared_memory_queue_t *q,
1510 l2_flood_member_t * member, u32 bd_id)
1512 vl_api_bridge_domain_sw_if_details_t * mp;
1513 l2_input_config_t * input_cfg;
1515 mp = vl_msg_api_alloc (sizeof (*mp));
1516 memset (mp, 0, sizeof (*mp));
1517 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1518 mp->bd_id = ntohl (bd_id);
1519 mp->sw_if_index = ntohl (member->sw_if_index);
1520 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1521 mp->shg = input_cfg->shg;
1523 vl_msg_api_send_shmem (q, (u8 *)&mp);
1526 static void vl_api_bridge_domain_dump_t_handler (
1527 vl_api_bridge_domain_dump_t *mp)
1529 bd_main_t * bdm = &bd_main;
1530 l2input_main_t * l2im = &l2input_main;
1531 unix_shared_memory_queue_t * q;
1532 l2_bridge_domain_t * bd_config;
1533 u32 bd_id, bd_index;
1536 q = vl_api_client_index_to_input_queue (mp->client_index);
1541 bd_id = ntohl(mp->bd_id);
1543 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1544 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1545 for (; bd_index < end; bd_index++) {
1546 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1547 /* skip dummy bd_id 0 */
1548 if (bd_config && (bd_config->bd_id > 0)) {
1550 l2_flood_member_t * m;
1552 n_sw_ifs = vec_len (bd_config->members);
1553 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1555 vec_foreach (m, bd_config->members) {
1556 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1563 vl_api_l2fib_add_del_t_handler (
1564 vl_api_l2fib_add_del_t *mp)
1566 bd_main_t * bdm = &bd_main;
1567 l2input_main_t * l2im = &l2input_main;
1568 vl_api_l2fib_add_del_reply_t * rmp;
1571 u32 sw_if_index = ntohl(mp->sw_if_index);
1572 u32 bd_id = ntohl(mp->bd_id);
1580 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1582 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1583 goto bad_sw_if_index;
1588 VALIDATE_SW_IF_INDEX(mp);
1589 if (vec_len(l2im->configs) <= sw_if_index) {
1590 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1591 goto bad_sw_if_index;
1593 l2_input_config_t * config;
1594 config = vec_elt_at_index(l2im->configs, sw_if_index);
1595 if (config->bridge == 0) {
1596 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1597 goto bad_sw_if_index;
1600 static_mac = mp->static_mac ? 1 : 0;
1601 filter_mac = mp->filter_mac ? 1 : 0;
1602 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1605 l2fib_del_entry(mac, bd_index);
1608 BAD_SW_IF_INDEX_LABEL;
1610 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1614 vl_api_l2_flags_t_handler (
1615 vl_api_l2_flags_t *mp)
1617 vl_api_l2_flags_reply_t * rmp;
1619 u32 sw_if_index = ntohl(mp->sw_if_index);
1620 u32 flags = ntohl(mp->feature_bitmap);
1623 VALIDATE_SW_IF_INDEX(mp);
1626 if (flags & L2INPUT_FEAT_ ## a) \
1627 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1628 foreach_l2input_feat;
1631 BAD_SW_IF_INDEX_LABEL;
1633 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1637 vl_api_bridge_flags_t_handler (
1638 vl_api_bridge_flags_t *mp)
1640 vlib_main_t *vm = vlib_get_main();
1641 bd_main_t * bdm = &bd_main;
1642 vl_api_bridge_flags_reply_t * rmp;
1644 u32 bd_id = ntohl(mp->bd_id);
1646 u32 flags = ntohl(mp->feature_bitmap);
1649 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1651 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1657 bd_set_flags(vm, bd_index, flags, mp->is_set);
1660 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1661 rmp->resulting_feature_bitmap = ntohl(flags));
1665 vl_api_bd_ip_mac_add_del_t_handler (
1666 vl_api_bd_ip_mac_add_del_t *mp)
1668 bd_main_t * bdm = &bd_main;
1669 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1671 u32 bd_id = ntohl(mp->bd_id);
1675 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1677 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1682 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1683 mp->mac_address, mp->is_ipv6, mp->is_add))
1684 rv = VNET_API_ERROR_UNSPECIFIED;
1687 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1691 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1694 vl_api_tap_connect_reply_t * rmp;
1695 unix_shared_memory_queue_t * q;
1696 u32 sw_if_index = (u32)~0;
1698 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1699 mp->use_random_mac ? 0 : mp->mac_address,
1700 &sw_if_index, mp->renumber,
1701 ntohl(mp->custom_dev_instance));
1703 q = vl_api_client_index_to_input_queue (mp->client_index);
1707 rmp = vl_msg_api_alloc (sizeof (*rmp));
1708 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1709 rmp->context = mp->context;
1710 rmp->retval = ntohl(rv);
1711 rmp->sw_if_index = ntohl(sw_if_index);
1713 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1717 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1720 vl_api_tap_modify_reply_t * rmp;
1721 unix_shared_memory_queue_t * q;
1722 u32 sw_if_index = (u32)~0;
1724 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1725 mp->use_random_mac ? 0 : mp->mac_address,
1726 &sw_if_index, mp->renumber,
1727 ntohl(mp->custom_dev_instance));
1729 q = vl_api_client_index_to_input_queue (mp->client_index);
1733 rmp = vl_msg_api_alloc (sizeof (*rmp));
1734 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1735 rmp->context = mp->context;
1736 rmp->retval = ntohl(rv);
1737 rmp->sw_if_index = ntohl(sw_if_index);
1739 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1743 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1746 vpe_api_main_t * vam = &vpe_api_main;
1747 vl_api_tap_delete_reply_t * rmp;
1748 unix_shared_memory_queue_t * q;
1749 u32 sw_if_index = ntohl(mp->sw_if_index);
1751 rv = vnet_tap_delete (vm, sw_if_index);
1753 q = vl_api_client_index_to_input_queue (mp->client_index);
1757 rmp = vl_msg_api_alloc (sizeof (*rmp));
1758 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1759 rmp->context = mp->context;
1760 rmp->retval = ntohl(rv);
1762 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1765 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1769 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1771 vl_api_create_vlan_subif_reply_t * rmp;
1772 vnet_main_t * vnm = vnet_get_main();
1773 u32 hw_if_index, sw_if_index = (u32)~0;
1774 vnet_hw_interface_t * hi;
1777 vnet_sw_interface_t template;
1779 vnet_interface_main_t * im = &vnm->interface_main;
1780 u64 sup_and_sub_key;
1782 unix_shared_memory_queue_t * q;
1783 clib_error_t * error;
1785 VALIDATE_SW_IF_INDEX(mp);
1787 hw_if_index = ntohl(mp->sw_if_index);
1788 hi = vnet_get_hw_interface (vnm, hw_if_index);
1790 id = ntohl(mp->vlan_id);
1791 if (id == 0 || id > 4095) {
1792 rv = VNET_API_ERROR_INVALID_VLAN;
1796 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1798 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1800 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1804 kp = clib_mem_alloc (sizeof (*kp));
1805 *kp = sup_and_sub_key;
1807 memset (&template, 0, sizeof (template));
1808 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1809 template.sup_sw_if_index = hi->sw_if_index;
1810 template.sub.id = id;
1811 template.sub.eth.raw_flags = 0;
1812 template.sub.eth.flags.one_tag = 1;
1813 template.sub.eth.outer_vlan_id = id;
1814 template.sub.eth.flags.exact_match = 1;
1816 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1818 clib_error_report(error);
1819 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1822 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1823 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1825 BAD_SW_IF_INDEX_LABEL;
1828 q = vl_api_client_index_to_input_queue (mp->client_index);
1832 rmp = vl_msg_api_alloc (sizeof (*rmp));
1833 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1834 rmp->context = mp->context;
1835 rmp->retval = ntohl(rv);
1836 rmp->sw_if_index = ntohl(sw_if_index);
1837 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1841 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1843 vl_api_create_subif_reply_t * rmp;
1844 vnet_main_t * vnm = vnet_get_main();
1845 u32 sw_if_index = ~0;
1848 vnet_sw_interface_t *si;
1849 vnet_hw_interface_t *hi;
1850 vnet_sw_interface_t template;
1852 vnet_interface_main_t * im = &vnm->interface_main;
1853 u64 sup_and_sub_key;
1855 clib_error_t * error;
1857 VALIDATE_SW_IF_INDEX(mp);
1859 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1860 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1862 sw_if_index = si->sw_if_index;
1863 sub_id = ntohl(mp->sub_id);
1865 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1867 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1870 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1871 sw_if_index, sub_id);
1872 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1876 kp = clib_mem_alloc (sizeof (*kp));
1877 *kp = sup_and_sub_key;
1879 memset (&template, 0, sizeof (template));
1880 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1881 template.sup_sw_if_index = sw_if_index;
1882 template.sub.id = sub_id;
1883 template.sub.eth.flags.no_tags = mp->no_tags;
1884 template.sub.eth.flags.one_tag = mp->one_tag;
1885 template.sub.eth.flags.two_tags = mp->two_tags;
1886 template.sub.eth.flags.dot1ad = mp->dot1ad;
1887 template.sub.eth.flags.exact_match = mp->exact_match;
1888 template.sub.eth.flags.default_sub = mp->default_sub;
1889 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1890 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1891 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1892 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1894 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1896 clib_error_report (error);
1897 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1901 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1902 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1904 BAD_SW_IF_INDEX_LABEL;
1908 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1910 rmp->sw_if_index = ntohl(sw_if_index);
1915 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1917 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1919 stats_main_t * sm = &stats_main;
1920 u32 tunnel_sw_if_index = ~0;
1922 dslock (sm, 1 /* release hint */, 5 /* tag */);
1924 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1925 (ip4_address_t *)(mp->dst_address),
1926 (ip4_address_t *)(mp->intfc_address),
1927 (u32)(mp->intfc_address_length),
1928 ntohl(mp->inner_vrf_id),
1929 ntohl(mp->outer_vrf_id),
1930 &tunnel_sw_if_index,
1935 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1937 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1942 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1943 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1945 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1947 stats_main_t * sm = &stats_main;
1948 u32 tunnel_sw_if_index;
1950 dslock (sm, 1 /* release hint */, 5 /* tag */);
1952 rv = vnet_mpls_ethernet_add_del_tunnel
1953 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1954 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1955 ntohl(mp->tx_sw_if_index),
1956 &tunnel_sw_if_index,
1962 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1964 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1969 * This piece of misery brought to you because the control-plane
1970 * can't figure out the tx interface + dst-mac address all by itself
1972 static int mpls_ethernet_add_del_tunnel_2_t_handler
1973 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1975 pending_route_t * pr;
1976 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1977 vnet_main_t * vnm = vnet_get_main();
1978 vlib_main_t * vm = vlib_get_main();
1979 stats_main_t * sm = &stats_main;
1980 vpe_api_main_t * vam = &vpe_api_main;
1981 u32 inner_fib_index, outer_fib_index;
1982 ip4_main_t * im = &ip4_main;
1983 ip_lookup_main_t * lm = &im->lookup_main;
1984 ip_adjacency_t * adj = 0;
1987 u8 * dst_mac_address;
1991 u32 tunnel_sw_if_index;
1993 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
1995 return VNET_API_ERROR_NO_SUCH_FIB;
1997 outer_fib_index = p[0];
2000 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2002 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2004 inner_fib_index = p[0];
2006 if (inner_fib_index == outer_fib_index)
2007 return VNET_API_ERROR_INVALID_VALUE;
2009 lookup_result = ip4_fib_lookup_with_table
2010 (im, outer_fib_index,
2011 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2012 1 /* disable default route */);
2014 adj = ip_get_adjacency (lm, lookup_result);
2015 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2017 if (mp->is_add && mp->resolve_if_needed) {
2018 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2019 pool_get (vam->pending_routes, pr);
2020 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2022 memcpy (pme, mp, sizeof (*pme));
2023 /* recursion block, "just in case" */
2024 pme->resolve_if_needed = 0;
2025 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2026 pme->resolve_opaque = tx_sw_if_index;
2027 vnet_register_ip4_arp_resolution_event
2029 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2030 vpe_resolver_process_node.index,
2031 RESOLUTION_EVENT, pr - vam->pending_routes);
2033 vlib_process_signal_event
2034 (vm, vpe_resolver_process_node.index,
2035 RESOLUTION_PENDING_EVENT, 0 /* data */);
2037 /* The interface may be down, etc. */
2038 e = ip4_probe_neighbor
2039 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2043 clib_error_report(e);
2045 return VNET_API_ERROR_IN_PROGRESS;
2049 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2050 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2053 vnet_rewrite_get_data_internal
2054 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2056 dslock (sm, 1 /* release hint */, 10 /* tag */);
2058 rv = vnet_mpls_ethernet_add_del_tunnel
2059 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2060 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2061 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2069 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2070 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2072 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2075 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2077 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2082 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2084 vl_api_mpls_add_del_encap_reply_t * rmp;
2086 static u32 * labels;
2089 vec_reset_length (labels);
2091 for (i = 0; i < mp->nlabels; i++)
2092 vec_add1 (labels, ntohl(mp->labels[i]));
2095 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2096 ntohl(mp->vrf_id), labels,
2097 ~0 /* policy_tunnel_index */,
2098 0 /* no_dst_hash */,
2102 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2106 vl_api_mpls_add_del_decap_t_handler
2107 (vl_api_mpls_add_del_decap_t *mp)
2109 vl_api_mpls_add_del_decap_reply_t * rmp;
2112 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2113 ntohl(mp->label), ntohl(mp->next_index),
2114 mp->s_bit, mp->is_add);
2116 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2120 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2122 vl_api_proxy_arp_add_del_reply_t * rmp;
2125 ip4_main_t * im = &ip4_main;
2126 stats_main_t * sm = &stats_main;
2127 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2128 ip4_address_t *hi_addr,
2129 u32 fib_index, int is_del);
2132 dslock (sm, 1 /* release hint */, 6 /* tag */);
2134 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2137 rv = VNET_API_ERROR_NO_SUCH_FIB;
2143 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2144 (ip4_address_t *)mp->hi_address,
2145 fib_index, mp->is_add == 0);
2149 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2153 vl_api_proxy_arp_intfc_enable_disable_t_handler
2154 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2157 vnet_main_t * vnm = vnet_get_main();
2158 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2159 vnet_sw_interface_t * si;
2162 VALIDATE_SW_IF_INDEX(mp);
2164 sw_if_index = ntohl(mp->sw_if_index);
2166 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2168 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2172 si = vnet_get_sw_interface (vnm, sw_if_index);
2176 if (mp->enable_disable)
2177 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2179 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2181 BAD_SW_IF_INDEX_LABEL;
2184 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2188 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2190 vl_api_ip_neighbor_add_del_reply_t * rmp;
2191 vnet_main_t * vnm = vnet_get_main();
2194 stats_main_t * sm = &stats_main;
2196 VALIDATE_SW_IF_INDEX(mp);
2198 dslock (sm, 1 /* release hint */, 7 /* tag */);
2202 rv = vnet_set_ip6_ethernet_neighbor
2203 (vm, ntohl(mp->sw_if_index),
2204 (ip6_address_t *)(mp->dst_address),
2205 mp->mac_address, sizeof (mp->mac_address));
2207 rv = vnet_unset_ip6_ethernet_neighbor
2208 (vm, ntohl(mp->sw_if_index),
2209 (ip6_address_t *)(mp->dst_address),
2210 mp->mac_address, sizeof(mp->mac_address));
2212 ip4_main_t * im = &ip4_main;
2213 ip_lookup_main_t * lm = &im->lookup_main;
2214 ethernet_arp_ip4_over_ethernet_address_t a;
2216 ip_adjacency_t *nh_adj;
2218 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2220 rv = VNET_API_ERROR_NO_SUCH_FIB;
2226 * Unfortunately, folks have a penchant for
2227 * adding interface addresses to the ARP cache, and
2228 * wondering why the forwarder eventually ASSERTs...
2230 ai = ip4_fib_lookup_with_table
2231 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2232 1 /* disable default route */);
2235 nh_adj = ip_get_adjacency (lm, ai);
2236 /* Never allow manipulation of a local adj! */
2237 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2238 clib_warning("%U matches local adj",
2240 (ip4_address_t *)(mp->dst_address));
2241 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2246 memcpy (&a.ethernet, mp->mac_address, 6);
2247 memcpy (&a.ip4, mp->dst_address, 4);
2250 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2251 fib_index, &a, mp->is_static);
2253 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2257 BAD_SW_IF_INDEX_LABEL;
2260 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2264 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2267 vpe_main_t *rm = &vpe_main;
2268 ip4_main_t *im4 = &ip4_main;
2269 ip6_main_t *im6 = &ip6_main;
2270 ip_lookup_main_t * lm;
2275 u32 adj_index, sw_if_index;
2276 vl_api_is_address_reachable_t *rmp;
2277 ip_adjacency_t * adj;
2278 unix_shared_memory_queue_t *q;
2280 q = vl_api_client_index_to_input_queue (mp->client_index);
2282 increment_missing_api_client_counter (rm->vlib_main);
2286 rmp = vl_msg_api_alloc (sizeof (*rmp));
2287 memcpy (rmp, mp, sizeof (*rmp));
2289 sw_if_index = mp->next_hop_sw_if_index;
2290 memcpy (&addr, mp->address, sizeof (addr));
2292 lm = &im6->lookup_main;
2294 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2296 lm = &im4->lookup_main;
2298 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2300 if (adj_index == ~0) {
2304 adj = ip_get_adjacency (lm, adj_index);
2306 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2307 && adj->rewrite_header.sw_if_index == sw_if_index) {
2310 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2311 && adj->rewrite_header.sw_if_index == sw_if_index) {
2313 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2315 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2316 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2324 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2328 static void vl_api_sw_interface_details_t_handler (
2329 vl_api_sw_interface_details_t * mp)
2331 clib_warning ("BUG");
2334 static void vl_api_sw_interface_set_flags_t_handler (
2335 vl_api_sw_interface_set_flags_t * mp)
2337 vl_api_sw_interface_set_flags_reply_t *rmp;
2338 vnet_main_t * vnm = vnet_get_main();
2340 clib_error_t * error;
2343 VALIDATE_SW_IF_INDEX(mp);
2345 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2347 error = vnet_sw_interface_set_flags (vnm,
2348 ntohl(mp->sw_if_index),
2352 clib_error_report (error);
2355 BAD_SW_IF_INDEX_LABEL;
2356 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2359 static void vl_api_sw_interface_clear_stats_t_handler (
2360 vl_api_sw_interface_clear_stats_t * mp)
2362 vl_api_sw_interface_clear_stats_reply_t *rmp;
2364 vnet_main_t * vnm = vnet_get_main();
2365 vnet_interface_main_t * im = &vnm->interface_main;
2366 vlib_simple_counter_main_t * sm;
2367 vlib_combined_counter_main_t * cm;
2368 static vnet_main_t ** my_vnet_mains;
2369 int i, j, n_counters;
2373 vec_reset_length (my_vnet_mains);
2375 for (i = 0; i < vec_len (vnet_mains); i++)
2378 vec_add1 (my_vnet_mains, vnet_mains[i]);
2381 if (vec_len (vnet_mains) == 0)
2382 vec_add1 (my_vnet_mains, vnm);
2384 n_counters = vec_len (im->combined_sw_if_counters);
2386 for (j = 0; j < n_counters; j++)
2388 for (i = 0; i < vec_len(my_vnet_mains); i++)
2390 im = &my_vnet_mains[i]->interface_main;
2391 cm = im->combined_sw_if_counters + j;
2392 if (mp->sw_if_index == (u32)~0)
2393 vlib_clear_combined_counters (cm);
2395 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2399 n_counters = vec_len (im->sw_if_counters);
2401 for (j = 0; j < n_counters; j++)
2403 for (i = 0; i < vec_len(my_vnet_mains); i++)
2405 im = &my_vnet_mains[i]->interface_main;
2406 sm = im->sw_if_counters + j;
2407 if (mp->sw_if_index == (u32)~0)
2408 vlib_clear_simple_counters (sm);
2410 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2414 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2417 static void send_sw_interface_details (vpe_api_main_t * am,
2418 unix_shared_memory_queue_t *q,
2419 vnet_sw_interface_t * swif,
2420 u8 * interface_name)
2422 vl_api_sw_interface_details_t * mp;
2423 vnet_hw_interface_t * hi;
2425 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2427 mp = vl_msg_api_alloc (sizeof (*mp));
2428 memset (mp, 0, sizeof (*mp));
2429 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2430 mp->sw_if_index = ntohl(swif->sw_if_index);
2431 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2432 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2434 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2436 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2437 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2438 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2439 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2440 mp->link_mtu = ntohs(hi->max_packet_bytes);
2442 strncpy ((char *) mp->interface_name,
2443 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2445 /* Send the L2 address for ethernet physical intfcs */
2446 if (swif->sup_sw_if_index == swif->sw_if_index
2447 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2448 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2449 ethernet_interface_t *ei;
2451 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2452 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2453 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2454 mp->l2_address_length = ntohl(sizeof (ei->address));
2455 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2456 vnet_sub_interface_t *sub = &swif->sub;
2457 mp->sub_id = ntohl(sub->id);
2458 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2459 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2460 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2461 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2462 mp->sub_exact_match = sub->eth.flags.exact_match;
2463 mp->sub_default = sub->eth.flags.default_sub;
2464 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2465 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2467 /* vlan tag rewrite data */
2468 u32 vtr_op = L2_VTR_DISABLED;
2469 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2471 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2472 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2473 // error - default to disabled
2474 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2475 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2478 mp->vtr_op = ntohl(vtr_op);
2479 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2480 mp->vtr_tag1 = ntohl(vtr_tag1);
2481 mp->vtr_tag2 = ntohl(vtr_tag2);
2485 vl_msg_api_send_shmem (q, (u8 *)&mp);
2488 static void send_sw_interface_flags (vpe_api_main_t * am,
2489 unix_shared_memory_queue_t *q,
2490 vnet_sw_interface_t * swif)
2492 vl_api_sw_interface_set_flags_t *mp;
2493 vnet_main_t * vnm = am->vnet_main;
2495 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2497 mp = vl_msg_api_alloc (sizeof (*mp));
2498 memset (mp, 0, sizeof (*mp));
2499 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2500 mp->sw_if_index = ntohl(swif->sw_if_index);
2502 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2504 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2506 vl_msg_api_send_shmem (q, (u8 *)&mp);
2509 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2510 unix_shared_memory_queue_t *q,
2512 __attribute__((unused));
2514 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2515 unix_shared_memory_queue_t *q,
2518 vl_api_sw_interface_set_flags_t *mp;
2520 mp = vl_msg_api_alloc (sizeof (*mp));
2521 memset (mp, 0, sizeof (*mp));
2522 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2523 mp->sw_if_index = ntohl(sw_if_index);
2525 mp->admin_up_down = 0;
2526 mp->link_up_down = 0;
2528 vl_msg_api_send_shmem (q, (u8 *)&mp);
2531 static void vl_api_sw_interface_dump_t_handler (
2532 vl_api_sw_interface_dump_t *mp)
2534 vpe_api_main_t * am = &vpe_api_main;
2535 vnet_sw_interface_t * swif;
2536 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2537 u8 * filter_string = 0, * name_string = 0;
2538 unix_shared_memory_queue_t * q;
2539 char * strcasestr (char *, char *); /* lnx hdr file botch */
2541 q = vl_api_client_index_to_input_queue (mp->client_index);
2546 if (mp->name_filter_valid) {
2547 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2548 filter_string = format (0, "%s%c", mp->name_filter, 0);
2551 pool_foreach (swif, im->sw_interfaces,
2553 name_string = format (name_string, "%U%c",
2554 format_vnet_sw_interface_name,
2555 am->vnet_main, swif, 0);
2557 if (mp->name_filter_valid == 0 ||
2558 strcasestr((char *) name_string, (char *) filter_string)) {
2560 send_sw_interface_details (am, q, swif, name_string);
2561 send_sw_interface_flags (am, q, swif);
2563 _vec_len (name_string) = 0;
2566 vec_free (name_string);
2567 vec_free (filter_string);
2570 void send_oam_event (oam_target_t * t)
2572 vpe_api_main_t * vam = &vpe_api_main;
2573 unix_shared_memory_queue_t * q;
2574 vpe_client_registration_t *reg;
2575 vl_api_oam_event_t * mp;
2577 pool_foreach(reg, vam->oam_events_registrations,
2579 q = vl_api_client_index_to_input_queue (reg->client_index);
2581 mp = vl_msg_api_alloc (sizeof (*mp));
2582 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2583 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2584 mp->state = t->state;
2585 vl_msg_api_send_shmem (q, (u8 *)&mp);
2591 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2593 vl_api_oam_add_del_reply_t * rmp;
2596 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2597 (ip4_address_t *)mp->dst_address,
2601 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2605 vl_api_vnet_get_summary_stats_t_handler (
2606 vl_api_vnet_get_summary_stats_t *mp)
2608 stats_main_t * sm = &stats_main;
2609 vnet_interface_main_t * im = sm->interface_main;
2610 vl_api_vnet_summary_stats_reply_t *rmp;
2611 vlib_combined_counter_main_t * cm;
2614 u64 total_pkts[VLIB_N_RX_TX];
2615 u64 total_bytes[VLIB_N_RX_TX];
2617 unix_shared_memory_queue_t * q =
2618 vl_api_client_index_to_input_queue (mp->client_index);
2623 rmp = vl_msg_api_alloc (sizeof (*rmp));
2624 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2625 rmp->context = mp->context;
2628 memset (total_pkts, 0, sizeof (total_pkts));
2629 memset (total_bytes, 0, sizeof (total_bytes));
2631 vnet_interface_counter_lock (im);
2633 vec_foreach (cm, im->combined_sw_if_counters) {
2634 which = cm - im->combined_sw_if_counters;
2636 for (i = 0; i < vec_len (cm->maxi); i++) {
2637 vlib_get_combined_counter (cm, i, &v);
2638 total_pkts[which] += v.packets;
2639 total_bytes[which] += v.bytes;
2642 vnet_interface_counter_unlock (im);
2644 /* Note: in HOST byte order! */
2645 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2646 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2647 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2648 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2649 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2651 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2654 typedef CLIB_PACKED (struct {
2655 ip4_address_t address;
2657 u32 address_length : 6;
2662 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2664 vnet_main_t * vnm = vnet_get_main();
2665 vnet_interface_main_t * im = &vnm->interface_main;
2666 ip4_main_t * im4 = &ip4_main;
2667 static ip4_route_t * routes;
2668 static u32 * sw_if_indices_to_shut;
2669 stats_main_t * sm = &stats_main;
2674 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2675 u32 target_fib_id = ntohl(mp->vrf_id);
2677 dslock (sm, 1 /* release hint */, 8 /* tag */);
2679 vec_foreach (fib, im4->fibs) {
2680 vnet_sw_interface_t * si;
2682 if (fib->table_id != target_fib_id)
2685 /* remove any mpls/gre tunnels in this fib */
2686 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2688 /* remove any mpls encap/decap labels */
2689 mpls_fib_reset_labels (fib->table_id);
2691 /* remove any proxy arps in this fib */
2692 vnet_proxy_arp_fib_reset (fib->table_id);
2694 /* Set the flow hash for this fib to the default */
2695 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2697 vec_reset_length (sw_if_indices_to_shut);
2699 /* Shut down interfaces in this FIB / clean out intfc routes */
2700 pool_foreach (si, im->sw_interfaces,
2702 u32 sw_if_index = si->sw_if_index;
2704 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2705 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2707 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2710 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2711 sw_if_index = sw_if_indices_to_shut[i];
2712 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2714 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2715 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2716 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2719 vec_reset_length (routes);
2721 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2722 uword * hash = fib->adj_index_by_dst_address[i];
2726 x.address_length = i;
2728 hash_foreach_pair (p, hash,
2730 x.address.data_u32 = p->key;
2731 vec_add1 (routes, x);
2735 vec_foreach (r, routes) {
2736 ip4_add_del_route_args_t a;
2738 memset (&a, 0, sizeof (a));
2739 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2740 a.table_index_or_table_id = fib - im4->fibs;
2741 a.dst_address = r->address;
2742 a.dst_address_length = r->address_length;
2745 ip4_add_del_route (im4, &a);
2746 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2747 IP4_ROUTE_FLAG_FIB_INDEX);
2751 } /* vec_foreach (fib) */
2758 ip6_address_t address;
2765 ip6_route_t ** routep;
2766 } add_routes_in_fib_arg_t;
2768 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2770 add_routes_in_fib_arg_t * ap = arg;
2772 if (kvp->key[2]>>32 == ap->fib_index)
2774 ip6_address_t *addr;
2776 addr = (ip6_address_t *) kvp;
2777 vec_add2 (*ap->routep, r, 1);
2778 r->address = addr[0];
2779 r->address_length = kvp->key[2] & 0xFF;
2780 r->index = kvp->value;
2784 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2786 vnet_main_t * vnm = vnet_get_main();
2787 vnet_interface_main_t * im = &vnm->interface_main;
2788 ip6_main_t * im6 = &ip6_main;
2789 stats_main_t * sm = &stats_main;
2790 static ip6_route_t * routes;
2791 static u32 * sw_if_indices_to_shut;
2796 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2797 u32 target_fib_id = ntohl(mp->vrf_id);
2798 add_routes_in_fib_arg_t _a, *a=&_a;
2799 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2801 dslock (sm, 1 /* release hint */, 9 /* tag */);
2803 vec_foreach (fib, im6->fibs) {
2804 vnet_sw_interface_t * si;
2806 if (fib->table_id != target_fib_id)
2809 vec_reset_length (sw_if_indices_to_shut);
2811 /* Shut down interfaces in this FIB / clean out intfc routes */
2812 pool_foreach (si, im->sw_interfaces,
2814 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2816 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2819 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2820 sw_if_index = sw_if_indices_to_shut[i];
2821 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2823 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2824 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2825 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2828 vec_reset_length (routes);
2830 a->fib_index = fib - im6->fibs;
2831 a->routep = &routes;
2833 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2835 vec_foreach (r, routes) {
2836 ip6_add_del_route_args_t a;
2838 memset (&a, 0, sizeof (a));
2839 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2840 a.table_index_or_table_id = fib - im6->fibs;
2841 a.dst_address = r->address;
2842 a.dst_address_length = r->address_length;
2845 ip6_add_del_route (im6, &a);
2846 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2847 IP6_ROUTE_FLAG_FIB_INDEX);
2850 /* Reinstall the neighbor / router discovery routes */
2851 vnet_ip6_fib_init (im6, fib - im6->fibs);
2853 } /* vec_foreach (fib) */
2859 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2862 vl_api_reset_fib_reply_t * rmp;
2865 rv = ip6_reset_fib_t_handler (mp);
2867 rv = ip4_reset_fib_t_handler (mp);
2869 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2874 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2876 vl_api_dhcp_proxy_config_reply_t * rmp;
2879 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2880 (ip4_address_t *)(&mp->dhcp_src_address),
2881 (u32) ntohl(mp->vrf_id),
2882 (int) mp->insert_circuit_id,
2883 (int) (mp->is_add == 0));
2885 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2890 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2892 vl_api_dhcp_proxy_config_reply_t * rmp;
2895 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2896 (ip6_address_t *)(&mp->dhcp_src_address),
2897 (u32) ntohl(mp->vrf_id),
2898 (int) mp->insert_circuit_id,
2899 (int) (mp->is_add == 0));
2901 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2905 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2907 vl_api_dhcp_proxy_config_reply_t * rmp;
2910 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2911 (ip4_address_t *)(&mp->dhcp_src_address),
2912 (u32) ntohl(mp->rx_vrf_id),
2913 (u32) ntohl(mp->server_vrf_id),
2914 (int) mp->insert_circuit_id,
2915 (int) (mp->is_add == 0));
2917 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2922 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2924 vl_api_dhcp_proxy_config_reply_t * rmp;
2928 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2929 (ip6_address_t *)(&mp->dhcp_src_address),
2930 (u32) ntohl(mp->rx_vrf_id),
2931 (u32) ntohl(mp->server_vrf_id),
2932 (int) mp->insert_circuit_id,
2933 (int) (mp->is_add == 0));
2935 rv = VNET_API_ERROR_UNIMPLEMENTED;
2938 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2943 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2945 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2948 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2951 (int)mp->is_add == 0);
2953 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2956 (int)mp->is_add == 0);
2958 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2962 static void vl_api_dhcp_proxy_config_t_handler
2963 (vl_api_dhcp_proxy_config_t *mp)
2965 if (mp->is_ipv6 == 0)
2966 dhcpv4_proxy_config (mp);
2968 dhcpv6_proxy_config (mp);
2971 static void vl_api_dhcp_proxy_config_2_t_handler
2972 (vl_api_dhcp_proxy_config_2_t *mp)
2974 if (mp->is_ipv6 == 0)
2975 dhcpv4_proxy_config_2 (mp);
2977 dhcpv6_proxy_config_2 (mp);
2980 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2981 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2983 unix_shared_memory_queue_t * q;
2984 vl_api_dhcp_compl_event_t * mp;
2986 q = vl_api_client_index_to_input_queue (client_index);
2990 mp = vl_msg_api_alloc (sizeof (*mp));
2991 mp->client_index = client_index;
2993 mp->is_ipv6 = is_ipv6;
2994 memcpy (&mp->hostname, hostname, vec_len(hostname));
2995 mp->hostname[vec_len(hostname) + 1] = '\n';
2996 memcpy (&mp->host_address[0], host_address, 16);
2997 memcpy (&mp->router_address[0], router_address, 16);
2998 memcpy (&mp->host_mac[0], host_mac, 6);
3000 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3002 vl_msg_api_send_shmem (q, (u8 *)&mp);
3005 static void vl_api_dhcp_client_config_t_handler
3006 (vl_api_dhcp_client_config_t *mp)
3008 vlib_main_t *vm = vlib_get_main();
3009 vl_api_dhcp_client_config_reply_t * rmp;
3012 VALIDATE_SW_IF_INDEX(mp);
3014 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3015 mp->hostname, mp->is_add, mp->client_index,
3016 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3019 BAD_SW_IF_INDEX_LABEL;
3021 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3025 vl_api_sw_interface_ip6nd_ra_config_t_handler
3026 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3028 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3030 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3032 is_no = mp->is_no == 1;
3033 surpress = mp->surpress == 1;
3034 managed = mp->managed == 1;
3035 other = mp->other == 1;
3036 ll_option = mp->ll_option == 1;
3037 send_unicast = mp->send_unicast == 1;
3038 cease = mp->cease == 1;
3039 default_router = mp->default_router == 1;
3041 VALIDATE_SW_IF_INDEX(mp);
3043 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3044 surpress, managed, other,
3045 ll_option, send_unicast, cease,
3046 default_router, ntohl (mp->lifetime),
3047 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3048 ntohl(mp->max_interval), ntohl( mp->min_interval),
3051 BAD_SW_IF_INDEX_LABEL;
3053 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3057 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3058 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3060 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3062 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3064 VALIDATE_SW_IF_INDEX(mp);
3066 is_no = mp->is_no == 1;
3067 use_default = mp->use_default == 1;
3068 no_advertise = mp->no_advertise == 1;
3069 off_link = mp->off_link == 1;
3070 no_autoconfig = mp->no_autoconfig == 1;
3071 no_onlink = mp->no_onlink == 1;
3073 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3074 (ip6_address_t *)mp->address, mp->address_length,
3075 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3076 no_advertise, off_link, no_autoconfig, no_onlink,
3079 BAD_SW_IF_INDEX_LABEL;
3080 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3084 vl_api_sw_interface_ip6_enable_disable_t_handler
3085 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3087 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3088 vnet_main_t * vnm = vnet_get_main();
3090 clib_error_t * error;
3094 VALIDATE_SW_IF_INDEX(mp);
3096 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3097 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3100 clib_error_report(error);
3101 rv = VNET_API_ERROR_UNSPECIFIED;
3103 rv = vnm->api_errno;
3106 BAD_SW_IF_INDEX_LABEL;
3108 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3112 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3113 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3115 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3117 clib_error_t * error;
3118 vnet_main_t * vnm = vnet_get_main();
3122 VALIDATE_SW_IF_INDEX(mp);
3124 error = set_ip6_link_local_address(vm,
3125 ntohl(mp->sw_if_index),
3126 (ip6_address_t *)mp->address,
3127 mp->address_length);
3129 clib_error_report(error);
3130 rv = VNET_API_ERROR_UNSPECIFIED;
3132 rv = vnm->api_errno;
3135 BAD_SW_IF_INDEX_LABEL;
3137 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3140 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3142 vl_api_set_ip_flow_hash_reply_t *rmp;
3143 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3145 clib_warning ("unimplemented...");
3147 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3150 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3152 vl_api_set_ip_flow_hash_reply_t *rmp;
3155 u32 flow_hash_config = 0;
3157 table_id = ntohl(mp->vrf_id);
3159 #define _(a,b) if (mp->a) flow_hash_config |= b;
3160 foreach_flow_hash_bit;
3163 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3165 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3169 static void vl_api_set_ip_flow_hash_t_handler
3170 (vl_api_set_ip_flow_hash_t *mp)
3172 if (mp->is_ipv6 == 0)
3173 set_ip4_flow_hash (mp);
3175 set_ip6_flow_hash (mp);
3178 static void vl_api_sw_interface_set_unnumbered_t_handler
3179 (vl_api_sw_interface_set_unnumbered_t *mp)
3181 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3183 vnet_sw_interface_t * si;
3184 vnet_main_t *vnm = vnet_get_main();
3185 u32 sw_if_index, unnumbered_sw_if_index;
3187 sw_if_index = ntohl(mp->sw_if_index);
3188 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3191 * The API message field names are backwards from
3192 * the underlying data structure names.
3193 * It's not worth changing them now.
3195 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3196 unnumbered_sw_if_index)) {
3197 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3201 /* Only check the "use loop0" field when setting the binding */
3203 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3204 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3208 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3211 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3212 si->unnumbered_sw_if_index = sw_if_index;
3214 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3215 si->unnumbered_sw_if_index = (u32)~0;
3219 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3222 static void vl_api_create_loopback_t_handler
3223 (vl_api_create_loopback_t *mp)
3225 vl_api_create_loopback_reply_t * rmp;
3229 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3231 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3233 rmp->sw_if_index = ntohl (sw_if_index);
3237 static void vl_api_delete_loopback_t_handler
3238 (vl_api_delete_loopback_t *mp)
3240 vl_api_delete_loopback_reply_t * rmp;
3244 sw_if_index = ntohl (mp->sw_if_index);
3245 rv = vnet_delete_loopback_interface (sw_if_index);
3247 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3250 static void vl_api_control_ping_t_handler
3251 (vl_api_control_ping_t *mp)
3253 vl_api_control_ping_reply_t * rmp;
3256 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3258 rmp->vpe_pid = ntohl (getpid());
3262 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3264 u8 **shmem_vecp = (u8 **)arg;
3267 api_main_t * am = &api_main;
3270 shmem_vec = *shmem_vecp;
3272 offset = vec_len (shmem_vec);
3274 pthread_mutex_lock (&am->vlib_rp->mutex);
3275 oldheap = svm_push_data_heap (am->vlib_rp);
3277 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3279 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3281 svm_pop_heap (oldheap);
3282 pthread_mutex_unlock (&am->vlib_rp->mutex);
3284 *shmem_vecp = shmem_vec;
3288 static void vl_api_cli_request_t_handler
3289 (vl_api_cli_request_t *mp)
3291 vl_api_cli_reply_t *rp;
3292 unix_shared_memory_queue_t *q;
3293 vlib_main_t * vm = vlib_get_main();
3294 api_main_t * am = &api_main;
3295 unformat_input_t input;
3299 q = vl_api_client_index_to_input_queue (mp->client_index);
3303 rp = vl_msg_api_alloc (sizeof (*rp));
3304 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3305 rp->context = mp->context;
3307 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3309 vlib_cli_input (vm, &input, shmem_cli_output,
3312 pthread_mutex_lock (&am->vlib_rp->mutex);
3313 oldheap = svm_push_data_heap (am->vlib_rp);
3315 vec_add1(shmem_vec, 0);
3317 svm_pop_heap (oldheap);
3318 pthread_mutex_unlock (&am->vlib_rp->mutex);
3320 rp->reply_in_shmem = (uword)shmem_vec;
3322 vl_msg_api_send_shmem (q, (u8 *)&rp);
3325 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3328 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3329 vnet_main_t *vnm = vnet_get_main();
3330 clib_error_t * error;
3335 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3337 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3340 clib_error_report(error);
3341 rv = VNET_API_ERROR_UNSPECIFIED;
3343 rv = vnm->api_errno;
3346 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3349 static void vl_api_sr_tunnel_add_del_t_handler
3350 (vl_api_sr_tunnel_add_del_t *mp)
3353 clib_warning ("unimplemented");
3355 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3357 vl_api_sr_tunnel_add_del_reply_t * rmp;
3358 ip6_address_t * segments = 0, * seg;
3359 ip6_address_t * tags = 0, *tag;
3360 ip6_address_t * this_address;
3363 if (mp->n_segments == 0) {
3368 memset (a, 0, sizeof (*a));
3369 a->src_address = (ip6_address_t *)&mp->src_address;
3370 a->dst_address = (ip6_address_t *)&mp->dst_address;
3371 a->dst_mask_width = mp->dst_mask_width;
3372 a->flags_net_byte_order = mp->flags_net_byte_order;
3373 a->is_del = (mp->is_add == 0);
3374 a->rx_table_id = ntohl(mp->outer_vrf_id);
3375 a->tx_table_id = ntohl(mp->inner_vrf_id);
3377 /* Yank segments and tags out of the API message */
3378 this_address = (ip6_address_t *)mp->segs_and_tags;
3379 for (i = 0; i < mp->n_segments; i++) {
3380 vec_add2 (segments, seg, 1);
3381 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3384 for (i = 0; i < mp->n_tags; i++) {
3385 vec_add2 (tags, tag, 1);
3386 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3390 a->segments = segments;
3393 rv = ip6_sr_add_del_tunnel (a);
3397 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3401 #define foreach_classify_add_del_table_field \
3406 _(match_n_vectors) \
3407 _(next_table_index) \
3410 static void vl_api_classify_add_del_table_t_handler
3411 (vl_api_classify_add_del_table_t * mp)
3413 vl_api_classify_add_del_table_reply_t * rmp;
3414 vnet_classify_main_t * cm = &vnet_classify_main;
3415 vnet_classify_table_t * t;
3419 foreach_classify_add_del_table_field;
3422 #define _(a) a = ntohl(mp->a);
3423 foreach_classify_add_del_table_field;
3426 /* The underlying API fails silently, on purpose, so check here */
3427 if (mp->is_add == 0)
3428 if (pool_is_free_index (cm->tables, table_index)) {
3429 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3433 rv = vnet_classify_add_del_table
3434 (cm, mp->mask, nbuckets, memory_size,
3435 skip_n_vectors, match_n_vectors,
3436 next_table_index, miss_next_index,
3437 &table_index, mp->is_add);
3440 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3442 if (rv == 0 && mp->is_add) {
3443 t = pool_elt_at_index (cm->tables, table_index);
3444 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3445 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3446 rmp->new_table_index = ntohl(table_index);
3448 rmp->skip_n_vectors = ~0;
3449 rmp->match_n_vectors = ~0;
3450 rmp->new_table_index = ~0;
3455 static void vl_api_classify_add_del_session_t_handler
3456 (vl_api_classify_add_del_session_t * mp)
3458 vnet_classify_main_t * cm = &vnet_classify_main;
3459 vl_api_classify_add_del_session_reply_t * rmp;
3461 u32 table_index, hit_next_index, opaque_index;
3464 table_index = ntohl (mp->table_index);
3465 hit_next_index = ntohl (mp->hit_next_index);
3466 opaque_index = ntohl (mp->opaque_index);
3467 advance = ntohl (mp->advance);
3469 rv = vnet_classify_add_del_session
3470 (cm, table_index, mp->match, hit_next_index, opaque_index,
3471 advance, mp->is_add);
3473 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3476 static void vl_api_classify_set_interface_ip_table_t_handler
3477 (vl_api_classify_set_interface_ip_table_t * mp)
3479 vlib_main_t * vm = vlib_get_main();
3480 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3482 u32 table_index, sw_if_index;
3484 table_index = ntohl (mp->table_index);
3485 sw_if_index = ntohl (mp->sw_if_index);
3487 VALIDATE_SW_IF_INDEX(mp);
3490 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3492 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3494 BAD_SW_IF_INDEX_LABEL;
3496 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3499 static void vl_api_classify_set_interface_l2_tables_t_handler
3500 (vl_api_classify_set_interface_l2_tables_t * mp)
3502 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3504 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3507 ip4_table_index = ntohl(mp->ip4_table_index);
3508 ip6_table_index = ntohl(mp->ip6_table_index);
3509 other_table_index = ntohl(mp->other_table_index);
3510 sw_if_index = ntohl(mp->sw_if_index);
3512 VALIDATE_SW_IF_INDEX(mp);
3514 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3515 ip6_table_index, other_table_index);
3518 if (ip4_table_index != ~0 || ip6_table_index != ~0
3519 || other_table_index != ~0)
3524 vnet_l2_classify_enable_disable (sw_if_index, enable);
3527 BAD_SW_IF_INDEX_LABEL;
3529 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3533 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3536 vl_api_l2_fib_clear_table_reply_t * rmp;
3538 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3539 * that is not currently implemented. When that TODO is fixed
3540 * this call should be changed to pass 1 instead of 0.
3542 l2fib_clear_table (0);
3544 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3547 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3552 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3555 vl_api_l2_interface_efp_filter_reply_t * rmp;
3556 vnet_main_t *vnm = vnet_get_main();
3558 // enable/disable the feature
3559 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3560 rv = vnm->api_errno;
3562 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3566 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3569 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3570 vnet_main_t * vnm = vnet_get_main();
3571 vlib_main_t * vm = vlib_get_main();
3574 VALIDATE_SW_IF_INDEX(mp);
3576 vtr_op = ntohl(mp->vtr_op);
3578 /* The L2 code is unsuspicious */
3580 case L2_VTR_DISABLED:
3585 case L2_VTR_TRANSLATE_1_1:
3586 case L2_VTR_TRANSLATE_1_2:
3587 case L2_VTR_TRANSLATE_2_1:
3588 case L2_VTR_TRANSLATE_2_2:
3592 rv = VNET_API_ERROR_INVALID_VALUE;
3593 goto bad_sw_if_index;
3596 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3597 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3600 BAD_SW_IF_INDEX_LABEL;
3602 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3606 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3610 vl_api_create_vhost_user_if_reply_t * rmp;
3611 u32 sw_if_index = (u32)~0;
3613 vnet_main_t * vnm = vnet_get_main();
3614 vlib_main_t * vm = vlib_get_main();
3616 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3617 mp->is_server, &sw_if_index, (u64)~0,
3618 mp->renumber, ntohl(mp->custom_dev_instance),
3619 (mp->use_custom_mac)?mp->mac_address:NULL);
3621 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3623 rmp->sw_if_index = ntohl (sw_if_index);
3629 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3633 vl_api_modify_vhost_user_if_reply_t * rmp;
3634 u32 sw_if_index = ntohl(mp->sw_if_index);
3636 vnet_main_t * vnm = vnet_get_main();
3637 vlib_main_t * vm = vlib_get_main();
3639 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3640 mp->is_server, sw_if_index, (u64)~0,
3641 mp->renumber, ntohl(mp->custom_dev_instance));
3643 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3648 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3652 vpe_api_main_t * vam = &vpe_api_main;
3653 vl_api_delete_vhost_user_if_reply_t * rmp;
3654 u32 sw_if_index = ntohl(mp->sw_if_index);
3656 vnet_main_t * vnm = vnet_get_main();
3657 vlib_main_t * vm = vlib_get_main();
3659 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3661 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3663 unix_shared_memory_queue_t * q =
3664 vl_api_client_index_to_input_queue (mp->client_index);
3668 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3673 static void vl_api_sw_interface_vhost_user_details_t_handler (
3674 vl_api_sw_interface_vhost_user_details_t * mp)
3676 clib_warning ("BUG");
3680 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3681 unix_shared_memory_queue_t *q,
3682 vhost_user_intf_details_t * vui)
3684 vl_api_sw_interface_vhost_user_details_t * mp;
3686 mp = vl_msg_api_alloc (sizeof (*mp));
3687 memset (mp, 0, sizeof (*mp));
3688 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3689 mp->sw_if_index = ntohl(vui->sw_if_index);
3690 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3691 mp->features = clib_net_to_host_u64 (vui->features);
3692 mp->is_server = vui->is_server;
3693 mp->num_regions = ntohl(vui->num_regions);
3694 mp->sock_errno = ntohl(vui->sock_errno);
3696 strncpy ((char *) mp->sock_filename,
3697 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3698 strncpy ((char *) mp->interface_name,
3699 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3701 vl_msg_api_send_shmem (q, (u8 *)&mp);
3706 vl_api_sw_interface_vhost_user_dump_t_handler (
3707 vl_api_sw_interface_vhost_user_dump_t *mp)
3711 vpe_api_main_t * am = &vpe_api_main;
3712 vnet_main_t * vnm = vnet_get_main();
3713 vlib_main_t * vm = vlib_get_main();
3714 vhost_user_intf_details_t *ifaces = NULL;
3715 vhost_user_intf_details_t *vuid = NULL;
3716 unix_shared_memory_queue_t * q;
3718 q = vl_api_client_index_to_input_queue (mp->client_index);
3722 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3726 vec_foreach (vuid, ifaces) {
3727 send_sw_interface_vhost_user_details (am, q, vuid);
3733 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3734 unix_shared_memory_queue_t *q,
3738 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3739 u8 * if_name = NULL;
3740 vnet_sw_interface_t * si = NULL;
3742 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3744 if_name = format(if_name, "%U",
3745 format_vnet_sw_interface_name, lm->vnet_main, si);
3747 mp = vl_msg_api_alloc (sizeof (*mp));
3748 memset (mp, 0, sizeof (*mp));
3749 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3750 strncpy((char *)mp->interface_name,
3751 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3752 mp->sw_if_index = ntohl(si->sw_if_index);
3753 mp->local_session_id = s->local_session_id;
3754 mp->remote_session_id = s->remote_session_id;
3755 mp->local_cookie[0] = s->local_cookie[0];
3756 mp->local_cookie[1] = s->local_cookie[1];
3757 mp->remote_cookie = s->remote_cookie;
3758 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3759 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3760 mp->l2_sublayer_present = s->l2_sublayer_present;
3762 vl_msg_api_send_shmem (q, (u8 *)&mp);
3765 static void send_ip_address_details (vpe_api_main_t * am,
3766 unix_shared_memory_queue_t * q,
3771 vl_api_ip_address_details_t * mp;
3773 mp = vl_msg_api_alloc (sizeof (*mp));
3774 memset (mp, 0, sizeof (*mp));
3775 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3778 memcpy(&mp->ip, ip, sizeof(mp->ip));
3780 u32 * tp = (u32 *)mp->ip;
3781 *tp = ntohl(*(u32*)ip);
3783 mp->prefix_length = prefix_length;
3785 vl_msg_api_send_shmem (q, (u8 *)&mp);
3789 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3791 vpe_api_main_t * am = &vpe_api_main;
3792 unix_shared_memory_queue_t * q;
3795 ip6_main_t * im6 = &ip6_main;
3796 ip4_main_t * im4 = &ip4_main;
3797 ip_lookup_main_t * lm6 = &im6->lookup_main;
3798 ip_lookup_main_t * lm4 = &im4->lookup_main;
3799 ip_interface_address_t * ia = 0;
3800 u32 sw_if_index = ~0;
3802 sw_if_index = ntohl(mp->sw_if_index);
3804 q = vl_api_client_index_to_input_queue (mp->client_index);
3810 foreach_ip_interface_address (lm6, ia, sw_if_index,
3811 1 /* honor unnumbered */,
3813 r6 = ip_interface_address_get_address (lm6, ia);
3814 u16 prefix_length = ia->address_length;
3815 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3818 foreach_ip_interface_address (lm4, ia, sw_if_index,
3819 1 /* honor unnumbered */,
3821 r4 = ip_interface_address_get_address (lm4, ia);
3822 u16 prefix_length = ia->address_length;
3823 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3828 static void send_ip_details (vpe_api_main_t * am,
3829 unix_shared_memory_queue_t *q,
3832 vl_api_ip_details_t * mp;
3834 mp = vl_msg_api_alloc (sizeof (*mp));
3835 memset (mp, 0, sizeof (*mp));
3836 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3838 mp->sw_if_index = ntohl(sw_if_index);
3840 vl_msg_api_send_shmem (q, (u8 *)&mp);
3844 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3845 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3847 vpe_api_main_t * am = &vpe_api_main;
3848 l2t_main_t * lm = &l2t_main;
3849 unix_shared_memory_queue_t * q;
3850 l2t_session_t *session;
3852 q = vl_api_client_index_to_input_queue (mp->client_index);
3856 pool_foreach (session, lm->sessions,
3858 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3863 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3864 unix_shared_memory_queue_t *q,
3865 tapcli_interface_details_t *tap_if)
3867 vl_api_sw_interface_tap_details_t * mp;
3868 mp = vl_msg_api_alloc (sizeof (*mp));
3869 memset (mp, 0, sizeof (*mp));
3870 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3871 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3872 strncpy((char *)mp->dev_name,
3873 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3875 vl_msg_api_send_shmem (q, (u8 *)&mp);
3879 vl_api_sw_interface_tap_dump_t_handler (
3880 vl_api_sw_interface_tap_dump_t *mp)
3883 vpe_api_main_t * am = &vpe_api_main;
3884 unix_shared_memory_queue_t * q;
3885 tapcli_interface_details_t *tapifs = NULL;
3886 tapcli_interface_details_t *tap_if = NULL;
3888 q = vl_api_client_index_to_input_queue (mp->client_index);
3892 rv = vnet_tap_dump_ifs(&tapifs);
3896 vec_foreach(tap_if, tapifs) {
3897 send_sw_interface_tap_details(am, q, tap_if);
3904 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3906 vpe_api_main_t * am = &vpe_api_main;
3907 vnet_main_t * vnm = vnet_get_main();
3908 vlib_main_t * vm = vlib_get_main();
3909 vnet_interface_main_t * im = &vnm->interface_main;
3910 unix_shared_memory_queue_t * q;
3911 vnet_sw_interface_t * si, * sorted_sis;
3912 u32 sw_if_index = ~0;
3914 q = vl_api_client_index_to_input_queue (mp->client_index);
3919 /* Gather interfaces. */
3920 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3921 _vec_len (sorted_sis) = 0;
3922 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3924 vec_foreach (si, sorted_sis) {
3925 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3926 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3929 sw_if_index = si->sw_if_index;
3930 send_ip_details(am, q, sw_if_index);
3935 static void vl_api_l2_fib_table_entry_t_handler (
3936 vl_api_l2_fib_table_entry_t * mp)
3938 clib_warning ("BUG");
3941 static void send_l2fib_table_entry (vpe_api_main_t * am,
3942 unix_shared_memory_queue_t *q,
3943 l2fib_entry_key_t * l2fe_key,
3944 l2fib_entry_result_t * l2fe_res)
3946 vl_api_l2_fib_table_entry_t * mp;
3948 mp = vl_msg_api_alloc (sizeof (*mp));
3949 memset (mp, 0, sizeof (*mp));
3950 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3952 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3954 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3955 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3956 mp->static_mac = l2fe_res->fields.static_mac;
3957 mp->filter_mac = l2fe_res->fields.filter;
3958 mp->bvi_mac = l2fe_res->fields.bvi;
3960 vl_msg_api_send_shmem (q, (u8 *)&mp);
3964 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3966 vpe_api_main_t * am = &vpe_api_main;
3967 bd_main_t * bdm = &bd_main;
3968 l2fib_entry_key_t *l2fe_key = NULL;
3969 l2fib_entry_result_t *l2fe_res = NULL;
3970 u32 ni, bd_id = ntohl (mp->bd_id);
3972 unix_shared_memory_queue_t * q;
3975 q = vl_api_client_index_to_input_queue (mp->client_index);
3979 /* see l2fib_table_dump: ~0 means "any" */
3983 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3990 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3992 vec_foreach_index (ni, l2fe_key) {
3993 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
3994 vec_elt_at_index(l2fe_res, ni));
4001 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4003 vl_api_show_version_reply_t *rmp;
4005 char * vpe_api_get_build_directory(void);
4006 char * vpe_api_get_version(void);
4007 char * vpe_api_get_build_date(void);
4009 unix_shared_memory_queue_t * q =
4010 vl_api_client_index_to_input_queue (mp->client_index);
4015 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4017 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4018 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4019 ARRAY_LEN(rmp->build_directory)-1);
4020 strncpy ((char *) rmp->version, vpe_api_get_version(),
4021 ARRAY_LEN(rmp->version)-1);
4022 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4023 ARRAY_LEN(rmp->build_date)-1);
4027 static void vl_api_get_node_index_t_handler
4028 (vl_api_get_node_index_t * mp)
4030 vlib_main_t * vm = vlib_get_main();
4031 vl_api_get_node_index_reply_t * rmp;
4034 u32 node_index = ~0;
4036 n = vlib_get_node_by_name (vm, mp->node_name);
4039 rv = VNET_API_ERROR_NO_SUCH_NODE;
4041 node_index = n->index;
4043 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4045 rmp->node_index = ntohl(node_index);
4049 static void vl_api_add_node_next_t_handler
4050 (vl_api_add_node_next_t * mp)
4052 vlib_main_t * vm = vlib_get_main();
4053 vl_api_add_node_next_reply_t * rmp;
4054 vlib_node_t * n, * next;
4056 u32 next_index = ~0;
4058 n = vlib_get_node_by_name (vm, mp->node_name);
4061 rv = VNET_API_ERROR_NO_SUCH_NODE;
4065 next = vlib_get_node_by_name (vm, mp->next_name);
4068 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4070 next_index = vlib_node_add_next (vm, n->index, next->index);
4073 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4075 rmp->next_index = ntohl(next_index);
4079 static void vl_api_l2tpv3_create_tunnel_t_handler
4080 (vl_api_l2tpv3_create_tunnel_t *mp)
4082 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4083 l2t_main_t *lm = &l2t_main;
4084 u32 sw_if_index = (u32)~0;
4087 if (mp->is_ipv6 != 1) {
4088 rv = VNET_API_ERROR_UNIMPLEMENTED;
4092 rv = create_l2tpv3_ipv6_tunnel (lm,
4093 (ip6_address_t *) mp->client_address,
4094 (ip6_address_t *) mp->our_address,
4095 ntohl(mp->local_session_id),
4096 ntohl(mp->remote_session_id),
4097 clib_net_to_host_u64(mp->local_cookie),
4098 clib_net_to_host_u64(mp->remote_cookie),
4099 mp->l2_sublayer_present,
4103 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4105 rmp->sw_if_index = ntohl (sw_if_index);
4109 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4110 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4112 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4113 l2t_main_t *lm = &l2t_main;
4116 VALIDATE_SW_IF_INDEX(mp);
4118 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4119 clib_net_to_host_u64(mp->new_local_cookie),
4120 clib_net_to_host_u64(mp->new_remote_cookie));
4122 BAD_SW_IF_INDEX_LABEL;
4124 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4127 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4128 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4131 vnet_main_t * vnm = vnet_get_main();
4132 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4134 VALIDATE_SW_IF_INDEX(mp);
4136 rv = l2tpv3_interface_enable_disable
4137 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4139 BAD_SW_IF_INDEX_LABEL;
4141 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4144 static void vl_api_l2tpv3_set_lookup_key_t_handler
4145 (vl_api_l2tpv3_set_lookup_key_t * mp)
4148 l2t_main_t *lm = &l2t_main;
4149 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4151 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4152 rv = VNET_API_ERROR_INVALID_VALUE;
4156 lm->lookup_type = mp->key;
4159 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4162 static void vl_api_vxlan_add_del_tunnel_t_handler
4163 (vl_api_vxlan_add_del_tunnel_t * mp)
4165 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4167 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4168 u32 encap_fib_index;
4170 ip4_main_t * im = &ip4_main;
4171 u32 sw_if_index = ~0;
4173 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4175 rv = VNET_API_ERROR_NO_SUCH_FIB;
4178 encap_fib_index = p[0];
4180 memset (a, 0, sizeof (*a));
4182 a->is_add = mp->is_add;
4184 /* ip addresses sent in network byte order */
4185 a->src.as_u32 = mp->src_address;
4186 a->dst.as_u32 = mp->dst_address;
4188 a->encap_fib_index = encap_fib_index;
4189 a->decap_next_index = ntohl(mp->decap_next_index);
4190 a->vni = ntohl(mp->vni);
4191 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4194 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4196 rmp->sw_if_index = ntohl (sw_if_index);
4200 static void send_vxlan_tunnel_details
4201 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4203 vl_api_vxlan_tunnel_details_t * rmp;
4204 ip4_main_t * im = &ip4_main;
4206 rmp = vl_msg_api_alloc (sizeof (*rmp));
4207 memset (rmp, 0, sizeof (*rmp));
4208 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4209 rmp->src_address = t->src.data_u32;
4210 rmp->dst_address = t->dst.data_u32;
4211 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4212 rmp->vni = htonl(t->vni);
4213 rmp->decap_next_index = htonl(t->decap_next_index);
4214 rmp->sw_if_index = htonl(t->sw_if_index);
4216 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4219 static void vl_api_vxlan_tunnel_dump_t_handler
4220 (vl_api_vxlan_tunnel_dump_t * mp)
4222 unix_shared_memory_queue_t * q;
4223 vxlan_main_t * vxm = &vxlan_main;
4227 q = vl_api_client_index_to_input_queue (mp->client_index);
4232 sw_if_index = ntohl(mp->sw_if_index);
4234 if (~0 == sw_if_index) {
4235 pool_foreach (t, vxm->tunnels,
4237 send_vxlan_tunnel_details(t, q);
4240 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4241 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4244 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4245 send_vxlan_tunnel_details(t, q);
4250 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4252 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4254 vl_api_l2_patch_add_del_reply_t * rmp;
4255 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4259 VALIDATE_RX_SW_IF_INDEX(mp);
4260 VALIDATE_TX_SW_IF_INDEX(mp);
4262 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4263 ntohl(mp->tx_sw_if_index),
4264 (int)(mp->is_add != 0));
4266 BAD_RX_SW_IF_INDEX_LABEL;
4267 BAD_TX_SW_IF_INDEX_LABEL;
4269 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4273 vl_api_nsh_gre_add_del_tunnel_t_handler
4274 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4276 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4278 vnet_nsh_gre_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->ver_o_c = mp->ver_o_c;
4318 a->length = mp->length;
4319 a->md_type = mp->md_type;
4320 a->next_protocol = mp->next_protocol;
4321 a->spi_si = ntohl(mp->spi_si);
4322 a->c1 = ntohl(mp->c1);
4323 a->c2 = ntohl(mp->c2);
4324 a->c3 = ntohl(mp->c3);
4325 a->c4 = ntohl(mp->c4);
4327 for (i = 0; i < mp->tlv_len_in_words; i++)
4328 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4332 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4335 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4337 rmp->sw_if_index = ntohl (sw_if_index);
4342 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4343 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4345 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4347 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4348 u32 encap_fib_index, decap_fib_index;
4349 u32 decap_next_index;
4351 ip4_main_t * im = &ip4_main;
4353 u32 sw_if_index = ~0;
4356 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4358 rv = VNET_API_ERROR_NO_SUCH_FIB;
4361 encap_fib_index = p[0];
4363 decap_next_index = ntohl(mp->decap_next_index);
4365 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4366 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4367 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4369 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4372 decap_fib_index = p[0];
4374 decap_fib_index = ntohl(mp->decap_vrf_id);
4377 memset (a, 0, sizeof (*a));
4379 a->is_add = mp->is_add;
4380 /* ip addresses sent in network byte order */
4381 a->src.as_u32 = ntohl(mp->src);
4382 a->dst.as_u32 = ntohl(mp->dst);
4383 a->encap_fib_index = encap_fib_index;
4384 a->decap_fib_index = decap_fib_index;
4385 a->decap_next_index = decap_next_index;
4386 a->vni = ntohl(mp->vni);
4387 a->ver_o_c = mp->ver_o_c;
4388 a->length = mp->length;
4389 a->md_type = mp->md_type;
4390 a->next_protocol = mp->next_protocol;
4391 a->spi_si = ntohl(mp->spi_si);
4392 a->c1 = ntohl(mp->c1);
4393 a->c2 = ntohl(mp->c2);
4394 a->c3 = ntohl(mp->c3);
4395 a->c4 = ntohl(mp->c4);
4397 for (i = 0; i < mp->tlv_len_in_words; i++)
4398 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4402 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4405 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4407 rmp->sw_if_index = ntohl (sw_if_index);
4412 vl_api_lisp_gpe_add_del_tunnel_t_handler
4413 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4415 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4417 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4418 u32 encap_fib_index, decap_fib_index;
4419 u32 decap_next_index;
4421 ip4_main_t * im = &ip4_main;
4422 u32 sw_if_index = ~0;
4424 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4426 rv = VNET_API_ERROR_NO_SUCH_FIB;
4429 encap_fib_index = p[0];
4431 decap_next_index = ntohl(mp->decap_next_index);
4433 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4434 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4435 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4437 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4440 decap_fib_index = p[0];
4442 decap_fib_index = ntohl(mp->decap_vrf_id);
4445 memset (a, 0, sizeof (*a));
4447 a->is_add = mp->is_add;
4448 /* ip addresses sent in network byte order */
4449 a->src.as_u32 = mp->src;
4450 a->dst.as_u32 = mp->dst;
4451 a->encap_fib_index = encap_fib_index;
4452 a->decap_fib_index = decap_fib_index;
4453 a->decap_next_index = decap_next_index;
4454 a->flags = mp->flags;
4455 a->ver_res = mp->ver_res;
4457 a->next_protocol = mp->next_protocol;
4458 a->iid = clib_net_to_host_u32 (mp->iid);
4460 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4463 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4465 rmp->sw_if_index = ntohl (sw_if_index);
4470 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4472 vl_api_interface_name_renumber_reply_t * rmp;
4475 VALIDATE_SW_IF_INDEX(mp);
4477 rv = vnet_interface_name_renumber
4478 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4480 BAD_SW_IF_INDEX_LABEL;
4482 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4485 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4486 u32 sw_if_index, u32 address)
4488 vpe_api_main_t * am = &vpe_api_main;
4489 vlib_main_t * vm = am->vlib_main;
4490 vl_api_ip4_arp_event_t * event;
4491 static f64 arp_event_last_time;
4492 f64 now = vlib_time_now (vm);
4494 if (pool_is_free_index (am->arp_events, pool_index))
4497 event = pool_elt_at_index (am->arp_events, pool_index);
4498 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4499 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4500 } else { /* same mac */
4501 if ((sw_if_index == event->sw_if_index) &&
4503 /* for BD case, also check IP address with 10 sec timeout */
4504 ((address == event->address) &&
4505 ((now - arp_event_last_time) < 10.0))))
4509 arp_event_last_time = now;
4510 event->sw_if_index = sw_if_index;
4511 if (address) event->address = address;
4515 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4517 vpe_api_main_t * am = &vpe_api_main;
4519 if (pool_is_free_index (am->arp_events, pool_index))
4522 pool_put_index (am->arp_events, pool_index);
4527 vl_api_want_ip4_arp_events_t_handler
4528 (vl_api_want_ip4_arp_events_t * mp)
4530 vpe_api_main_t * am = &vpe_api_main;
4531 vnet_main_t * vnm = vnet_get_main();
4532 vl_api_want_ip4_arp_events_reply_t *rmp;
4533 vl_api_ip4_arp_event_t * event;
4536 if (mp->enable_disable) {
4537 pool_get (am->arp_events, event);
4538 memset (event, 0, sizeof (*event));
4540 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4541 event->client_index = mp->client_index;
4542 event->context = mp->context;
4543 event->address = mp->address;
4544 event->pid = mp->pid;
4546 rv = vnet_add_del_ip4_arp_change_event
4547 (vnm, arp_change_data_callback,
4549 &mp->address /* addr, in net byte order */,
4550 vpe_resolver_process_node.index,
4551 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4553 rv = vnet_add_del_ip4_arp_change_event
4554 (vnm, arp_change_delete_callback,
4556 &mp->address /* addr, in net byte order */,
4557 vpe_resolver_process_node.index,
4558 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4560 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4563 static void vl_api_input_acl_set_interface_t_handler
4564 (vl_api_input_acl_set_interface_t * mp)
4566 vlib_main_t *vm = vlib_get_main();
4567 vl_api_input_acl_set_interface_reply_t * rmp;
4569 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4571 ip4_table_index = ntohl(mp->ip4_table_index);
4572 ip6_table_index = ntohl(mp->ip6_table_index);
4573 l2_table_index = ntohl(mp->l2_table_index);
4574 sw_if_index = ntohl(mp->sw_if_index);
4576 VALIDATE_SW_IF_INDEX(mp);
4578 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4579 ip6_table_index, l2_table_index,
4582 BAD_SW_IF_INDEX_LABEL;
4584 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4587 static void vl_api_ipsec_spd_add_del_t_handler
4588 (vl_api_ipsec_spd_add_del_t * mp)
4591 clib_warning ("unimplemented");
4594 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4595 vl_api_ipsec_spd_add_del_reply_t * rmp;
4599 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4601 rv = VNET_API_ERROR_UNIMPLEMENTED;
4604 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4608 static void vl_api_ipsec_interface_add_del_spd_t_handler
4609 (vl_api_ipsec_interface_add_del_spd_t * mp)
4611 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4612 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4614 u32 sw_if_index __attribute__((unused));
4615 u32 spd_id __attribute__((unused));
4617 sw_if_index = ntohl(mp->sw_if_index);
4618 spd_id = ntohl(mp->spd_id);
4620 VALIDATE_SW_IF_INDEX(mp);
4623 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4625 rv = VNET_API_ERROR_UNIMPLEMENTED;
4628 BAD_SW_IF_INDEX_LABEL;
4630 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4633 static void vl_api_ipsec_spd_add_del_entry_t_handler
4634 (vl_api_ipsec_spd_add_del_entry_t * mp)
4636 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4637 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4643 p.id = ntohl(mp->spd_id);
4644 p.priority = ntohl(mp->priority);
4645 p.is_outbound = mp->is_outbound;
4646 p.is_ipv6 = mp->is_ipv6;
4648 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4649 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4650 memcpy(&p.laddr.start, mp->local_address_start, 16);
4651 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4653 p.protocol = mp->protocol;
4654 p.rport.start = ntohs(mp->remote_port_start);
4655 p.rport.stop = ntohs(mp->remote_port_stop);
4656 p.lport.start = ntohs(mp->local_port_start);
4657 p.lport.stop = ntohs(mp->local_port_stop);
4658 /* policy action resolve unsupported */
4659 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4660 clib_warning("unsupported action: 'resolve'");
4661 rv = VNET_API_ERROR_UNIMPLEMENTED;
4664 p.policy = mp->policy;
4665 p.sa_id = ntohl(mp->sa_id);
4667 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4671 if (mp->is_ip_any) {
4673 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4676 rv = VNET_API_ERROR_UNIMPLEMENTED;
4681 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4684 static void vl_api_ipsec_sad_add_del_entry_t_handler
4685 (vl_api_ipsec_sad_add_del_entry_t * mp)
4687 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4688 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4693 sa.id = ntohl(mp->sad_id);
4694 sa.spi = ntohl(mp->spi);
4695 /* security protocol AH unsupported */
4696 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4697 clib_warning("unsupported security protocol 'AH'");
4698 rv = VNET_API_ERROR_UNIMPLEMENTED;
4701 sa.protocol = mp->protocol;
4702 /* check for unsupported crypto-alg */
4703 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4704 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4705 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4706 mp->crypto_algorithm);
4707 rv = VNET_API_ERROR_UNIMPLEMENTED;
4710 sa.crypto_alg = mp->crypto_algorithm;
4711 sa.crypto_key_len = mp->crypto_key_length;
4712 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4713 /* check for unsupported integ-alg */
4714 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4715 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4716 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4717 mp->integrity_algorithm);
4718 rv = VNET_API_ERROR_UNIMPLEMENTED;
4721 sa.integ_alg = mp->integrity_algorithm;
4722 sa.integ_key_len = mp->integrity_key_length;
4723 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4724 sa.use_esn = mp->use_extended_sequence_number;
4725 sa.is_tunnel = mp->is_tunnel;
4726 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4727 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4728 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4730 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4732 rv = VNET_API_ERROR_UNIMPLEMENTED;
4737 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4740 vl_api_map_add_domain_t_handler
4741 (vl_api_map_add_domain_t * mp)
4743 vl_api_map_add_domain_reply_t * rmp;
4746 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4747 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4748 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4749 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4750 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4752 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4754 rmp->index = ntohl(index);
4759 vl_api_map_del_domain_t_handler
4760 (vl_api_map_del_domain_t * mp)
4762 vl_api_map_del_domain_reply_t * rmp;
4765 rv = map_delete_domain(ntohl(mp->index));
4767 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4771 vl_api_map_add_del_rule_t_handler
4772 (vl_api_map_add_del_rule_t * mp)
4774 vl_api_map_del_domain_reply_t * rmp;
4777 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4779 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4783 vl_api_map_domain_dump_t_handler
4784 (vl_api_map_domain_dump_t * mp)
4786 vl_api_map_domain_details_t * rmp;
4787 map_main_t *mm = &map_main;
4789 unix_shared_memory_queue_t * q;
4791 if (pool_elts (mm->domains) == 0)
4794 q = vl_api_client_index_to_input_queue (mp->client_index);
4799 pool_foreach(d, mm->domains, ({
4800 rmp = vl_msg_api_alloc (sizeof (*rmp));
4801 memset (rmp, 0, sizeof (*rmp));
4802 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4803 rmp->domain_index = htonl(d - mm->domains);
4804 rmp->ea_bits_len = d->ea_bits_len;
4805 rmp->psid_offset = d->psid_offset;
4806 rmp->psid_length = d->psid_length;
4807 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4808 rmp->ip4_prefix_len = d->ip4_prefix_len;
4809 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4810 rmp->ip6_prefix_len = d->ip6_prefix_len;
4811 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4812 rmp->ip6_src_len = d->ip6_src_len;
4813 rmp->mtu = htons(d->mtu);
4814 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4816 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4821 vl_api_map_rule_dump_t_handler
4822 (vl_api_map_rule_dump_t * mp)
4824 unix_shared_memory_queue_t * q;
4827 vl_api_map_rule_details_t * rmp;
4828 map_main_t *mm = &map_main;
4829 u32 domain_index = ntohl(mp->domain_index);
4832 if (pool_elts (mm->domains) == 0)
4835 d = pool_elt_at_index(mm->domains, domain_index);
4836 if (!d || !d->rules) {
4840 q = vl_api_client_index_to_input_queue (mp->client_index);
4845 for (i = 0; i < (0x1 << d->psid_length); i++) {
4847 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4850 rmp = vl_msg_api_alloc(sizeof(*rmp));
4851 memset(rmp, 0, sizeof(*rmp));
4852 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4853 rmp->psid = htons(i);
4854 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4855 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4860 vl_api_map_summary_stats_t_handler (
4861 vl_api_map_summary_stats_t *mp)
4863 vl_api_map_summary_stats_reply_t *rmp;
4864 vlib_combined_counter_main_t *cm;
4867 u64 total_pkts[VLIB_N_RX_TX];
4868 u64 total_bytes[VLIB_N_RX_TX];
4869 map_main_t *mm = &map_main;
4870 unix_shared_memory_queue_t *q =
4871 vl_api_client_index_to_input_queue(mp->client_index);
4876 rmp = vl_msg_api_alloc (sizeof (*rmp));
4877 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
4878 rmp->context = mp->context;
4881 memset (total_pkts, 0, sizeof (total_pkts));
4882 memset (total_bytes, 0, sizeof (total_bytes));
4884 map_domain_counter_lock (mm);
4885 vec_foreach(cm, mm->domain_counters) {
4886 which = cm - mm->domain_counters;
4888 for (i = 0; i < vec_len(cm->maxi); i++) {
4889 vlib_get_combined_counter (cm, i, &v);
4890 total_pkts[which] += v.packets;
4891 total_bytes[which] += v.bytes;
4895 map_domain_counter_unlock (mm);
4897 /* Note: in HOST byte order! */
4898 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
4899 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
4900 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
4901 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
4902 rmp->total_bindings = pool_elts(mm->domains);
4903 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
4904 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
4905 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
4907 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4910 static void vl_api_ipsec_sa_set_key_t_handler
4911 (vl_api_ipsec_sa_set_key_t * mp)
4913 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4914 vl_api_ipsec_sa_set_key_reply_t *rmp;
4918 sa.id = ntohl(mp->sa_id);
4919 sa.crypto_key_len = mp->crypto_key_length;
4920 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4921 sa.integ_key_len = mp->integrity_key_length;
4922 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4924 rv = ipsec_set_sa_key(vm, &sa);
4926 rv = VNET_API_ERROR_UNIMPLEMENTED;
4929 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
4932 static void vl_api_cop_interface_enable_disable_t_handler
4933 (vl_api_cop_interface_enable_disable_t * mp)
4935 vl_api_cop_interface_enable_disable_reply_t * rmp;
4937 u32 sw_if_index = ntohl(mp->sw_if_index);
4940 VALIDATE_SW_IF_INDEX(mp);
4942 enable_disable = (int) mp->enable_disable;
4944 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
4946 BAD_SW_IF_INDEX_LABEL;
4948 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
4951 static void vl_api_cop_whitelist_enable_disable_t_handler
4952 (vl_api_cop_whitelist_enable_disable_t * mp)
4954 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
4955 cop_whitelist_enable_disable_args_t _a, *a=&_a;
4956 u32 sw_if_index = ntohl(mp->sw_if_index);
4959 VALIDATE_SW_IF_INDEX(mp);
4961 a->sw_if_index = sw_if_index;
4964 a->default_cop = mp->default_cop;
4965 a->fib_id = ntohl(mp->fib_id);
4967 rv = cop_whitelist_enable_disable (a);
4969 BAD_SW_IF_INDEX_LABEL;
4971 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
4974 static void vl_api_get_node_graph_t_handler
4975 (vl_api_get_node_graph_t * mp)
4979 api_main_t * am = &api_main;
4980 vlib_main_t * vm = vlib_get_main();
4982 vl_api_get_node_graph_reply_t * rmp;
4984 pthread_mutex_lock (&am->vlib_rp->mutex);
4985 oldheap = svm_push_data_heap (am->vlib_rp);
4988 * Keep the number of memcpy ops to a minimum (e.g. 1).
4989 * The current size of the serialized vector is
4990 * slightly under 4K.
4992 vec_validate (vector, 4095);
4993 vec_reset_length (vector);
4995 vector = vlib_node_serialize (&vm->node_main, vector);
4997 svm_pop_heap (oldheap);
4998 pthread_mutex_unlock (&am->vlib_rp->mutex);
5000 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5001 rmp->reply_in_shmem = (uword) vector);
5004 static void vl_api_trace_profile_add_t_handler
5005 (vl_api_trace_profile_add_t *mp)
5008 vl_api_trace_profile_add_reply_t * rmp;
5009 clib_error_t *error;
5011 /* Ignoring the profile id as currently a single profile
5013 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5014 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5015 mp->pow_enable, mp->trace_tsp,
5018 clib_error_report(error);
5019 rv = clib_error_get_code(error);
5022 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5025 static void vl_api_trace_profile_apply_t_handler
5026 (vl_api_trace_profile_apply_t *mp)
5029 vl_api_trace_profile_apply_reply_t * rmp;
5031 if (mp->enable != 0) {
5032 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5033 ntohl(mp->prefix_length),
5035 mp->trace_op == IOAM_HBYH_ADD,
5036 mp->trace_op == IOAM_HBYH_POP,
5037 mp->trace_op == IOAM_HBYH_MOD);
5039 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5041 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5044 static void vl_api_trace_profile_del_t_handler
5045 (vl_api_trace_profile_del_t *mp)
5048 vl_api_trace_profile_del_reply_t * rmp;
5049 clib_error_t *error;
5051 error = clear_ioam_rewrite_fn();
5053 clib_error_report(error);
5054 rv = clib_error_get_code(error);
5057 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5061 #define BOUNCE_HANDLER(nn) \
5062 static void vl_api_##nn##_t_handler ( \
5063 vl_api_##nn##_t *mp) \
5065 vpe_client_registration_t *reg; \
5066 vpe_api_main_t * vam = &vpe_api_main; \
5067 unix_shared_memory_queue_t * q; \
5069 /* One registration only... */ \
5070 pool_foreach(reg, vam->nn##_registrations, \
5072 q = vl_api_client_index_to_input_queue (reg->client_index); \
5075 * If the queue is stuffed, turf the msg and complain \
5076 * It's unlikely that the intended recipient is \
5077 * alive; avoid deadlock at all costs. \
5079 if (q->cursize == q->maxsize) { \
5080 clib_warning ("ERROR: receiver queue full, drop msg"); \
5081 vl_msg_api_free (mp); \
5084 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5088 vl_msg_api_free (mp); \
5091 BOUNCE_HANDLER(to_netconf_server);
5092 BOUNCE_HANDLER(from_netconf_server);
5093 BOUNCE_HANDLER(to_netconf_client);
5094 BOUNCE_HANDLER(from_netconf_client);
5098 * Add vpe's API message handlers to the table.
5099 * vlib has alread mapped shared memory and
5100 * added the client registration handlers.
5101 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5104 static clib_error_t *
5105 vpe_api_hookup (vlib_main_t *vm)
5107 api_main_t * am = &api_main;
5110 vl_msg_api_set_handlers(VL_API_##N, #n, \
5111 vl_api_##n##_t_handler, \
5113 vl_api_##n##_t_endian, \
5114 vl_api_##n##_t_print, \
5115 sizeof(vl_api_##n##_t), 1);
5116 foreach_vpe_api_msg;
5120 * Manually register the sr tunnel add del msg, so we trace
5121 * enough bytes to capture a typical segment list
5123 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5124 "sr_tunnel_add_del",
5125 vl_api_sr_tunnel_add_del_t_handler,
5127 vl_api_sr_tunnel_add_del_t_endian,
5128 vl_api_sr_tunnel_add_del_t_print,
5131 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
5132 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
5133 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
5134 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
5137 * Trace space for 8 MPLS encap labels, classifier mask+match
5139 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5140 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5141 += 5 * sizeof (u32x4);
5142 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5143 += 5 * sizeof (u32x4);
5144 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5145 += 16 * sizeof (u32);
5148 * trace space for 4 nsh-gre variable TLV words
5150 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5151 += 4 * sizeof (u32);
5156 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5158 static clib_error_t *
5159 vpe_api_init (vlib_main_t *vm)
5161 vpe_api_main_t *am = &vpe_api_main;
5164 am->vnet_main = vnet_get_main();
5165 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5166 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5167 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5168 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5169 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5170 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5173 vl_set_memory_region_name ("/vpe-api");
5174 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5179 VLIB_INIT_FUNCTION(vpe_api_init);
5181 static clib_error_t *
5182 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5186 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5188 if (unformat (input, "prefix %s", &chroot_path))
5190 vec_add1 (chroot_path, 0);
5191 vl_set_memory_root_path ((char *)chroot_path);
5194 return clib_error_return (0, "unknown input `%U'",
5195 format_unformat_error, input);
5199 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5201 void * get_unformat_vnet_sw_interface (void)
5203 return (void *) &unformat_vnet_sw_interface;
5206 #undef vl_api_version
5207 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5208 #include <api/vpe.api.h>
5209 #undef vl_api_version
5211 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5213 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5214 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5215 clib_host_to_net_u32 (mp->api_versions[0]),
5222 static u8 * format_arp_event (u8 * s, va_list * args)
5224 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5226 s = format (s, "pid %d: %U", event->pid,
5227 format_ip4_address, &event->address);
5231 static clib_error_t *
5232 show_ip4_arp_events_fn (vlib_main_t * vm,
5233 unformat_input_t * input,
5234 vlib_cli_command_t * cmd)
5236 vpe_api_main_t * am = &vpe_api_main;
5237 vl_api_ip4_arp_event_t * event;
5239 if (pool_elts (am->arp_events) == 0) {
5240 vlib_cli_output (vm, "No active arp event registrations");
5244 pool_foreach (event, am->arp_events,
5246 vlib_cli_output (vm, "%U", format_arp_event, event);
5252 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5253 .path = "show arp event registrations",
5254 .function = show_ip4_arp_events_fn,
5255 .short_help = "Show arp event registrations",