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 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1863 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1867 sw_if_index = si->sw_if_index;
1868 sub_id = ntohl(mp->sub_id);
1870 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1872 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1875 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1876 sw_if_index, sub_id);
1877 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1881 kp = clib_mem_alloc (sizeof (*kp));
1882 *kp = sup_and_sub_key;
1884 memset (&template, 0, sizeof (template));
1885 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1886 template.sup_sw_if_index = sw_if_index;
1887 template.sub.id = sub_id;
1888 template.sub.eth.flags.no_tags = mp->no_tags;
1889 template.sub.eth.flags.one_tag = mp->one_tag;
1890 template.sub.eth.flags.two_tags = mp->two_tags;
1891 template.sub.eth.flags.dot1ad = mp->dot1ad;
1892 template.sub.eth.flags.exact_match = mp->exact_match;
1893 template.sub.eth.flags.default_sub = mp->default_sub;
1894 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1895 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1896 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1897 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1899 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1901 clib_error_report (error);
1902 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1906 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1907 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1909 BAD_SW_IF_INDEX_LABEL;
1913 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1915 rmp->sw_if_index = ntohl(sw_if_index);
1920 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1922 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1924 stats_main_t * sm = &stats_main;
1925 u32 tunnel_sw_if_index = ~0;
1927 dslock (sm, 1 /* release hint */, 5 /* tag */);
1929 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1930 (ip4_address_t *)(mp->dst_address),
1931 (ip4_address_t *)(mp->intfc_address),
1932 (u32)(mp->intfc_address_length),
1933 ntohl(mp->inner_vrf_id),
1934 ntohl(mp->outer_vrf_id),
1935 &tunnel_sw_if_index,
1940 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1942 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1947 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1948 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1950 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1952 stats_main_t * sm = &stats_main;
1953 u32 tunnel_sw_if_index;
1955 dslock (sm, 1 /* release hint */, 5 /* tag */);
1957 rv = vnet_mpls_ethernet_add_del_tunnel
1958 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1959 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1960 ntohl(mp->tx_sw_if_index),
1961 &tunnel_sw_if_index,
1967 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1969 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1974 * This piece of misery brought to you because the control-plane
1975 * can't figure out the tx interface + dst-mac address all by itself
1977 static int mpls_ethernet_add_del_tunnel_2_t_handler
1978 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1980 pending_route_t * pr;
1981 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1982 vnet_main_t * vnm = vnet_get_main();
1983 vlib_main_t * vm = vlib_get_main();
1984 stats_main_t * sm = &stats_main;
1985 vpe_api_main_t * vam = &vpe_api_main;
1986 u32 inner_fib_index, outer_fib_index;
1987 ip4_main_t * im = &ip4_main;
1988 ip_lookup_main_t * lm = &im->lookup_main;
1989 ip_adjacency_t * adj = 0;
1992 u8 * dst_mac_address;
1996 u32 tunnel_sw_if_index;
1998 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2000 return VNET_API_ERROR_NO_SUCH_FIB;
2002 outer_fib_index = p[0];
2005 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2007 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2009 inner_fib_index = p[0];
2011 if (inner_fib_index == outer_fib_index)
2012 return VNET_API_ERROR_INVALID_VALUE;
2014 lookup_result = ip4_fib_lookup_with_table
2015 (im, outer_fib_index,
2016 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2017 1 /* disable default route */);
2019 adj = ip_get_adjacency (lm, lookup_result);
2020 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2022 if (mp->is_add && mp->resolve_if_needed) {
2023 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2024 pool_get (vam->pending_routes, pr);
2025 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2027 memcpy (pme, mp, sizeof (*pme));
2028 /* recursion block, "just in case" */
2029 pme->resolve_if_needed = 0;
2030 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2031 pme->resolve_opaque = tx_sw_if_index;
2032 vnet_register_ip4_arp_resolution_event
2034 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2035 vpe_resolver_process_node.index,
2036 RESOLUTION_EVENT, pr - vam->pending_routes);
2038 vlib_process_signal_event
2039 (vm, vpe_resolver_process_node.index,
2040 RESOLUTION_PENDING_EVENT, 0 /* data */);
2042 /* The interface may be down, etc. */
2043 e = ip4_probe_neighbor
2044 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2048 clib_error_report(e);
2050 return VNET_API_ERROR_IN_PROGRESS;
2054 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2055 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2058 vnet_rewrite_get_data_internal
2059 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2061 dslock (sm, 1 /* release hint */, 10 /* tag */);
2063 rv = vnet_mpls_ethernet_add_del_tunnel
2064 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2065 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2066 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2074 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2075 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2077 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2080 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2082 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2087 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2089 vl_api_mpls_add_del_encap_reply_t * rmp;
2091 static u32 * labels;
2094 vec_reset_length (labels);
2096 for (i = 0; i < mp->nlabels; i++)
2097 vec_add1 (labels, ntohl(mp->labels[i]));
2100 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2101 ntohl(mp->vrf_id), labels,
2102 ~0 /* policy_tunnel_index */,
2103 0 /* no_dst_hash */,
2107 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2111 vl_api_mpls_add_del_decap_t_handler
2112 (vl_api_mpls_add_del_decap_t *mp)
2114 vl_api_mpls_add_del_decap_reply_t * rmp;
2117 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2118 ntohl(mp->label), ntohl(mp->next_index),
2119 mp->s_bit, mp->is_add);
2121 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2125 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2127 vl_api_proxy_arp_add_del_reply_t * rmp;
2130 ip4_main_t * im = &ip4_main;
2131 stats_main_t * sm = &stats_main;
2132 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2133 ip4_address_t *hi_addr,
2134 u32 fib_index, int is_del);
2137 dslock (sm, 1 /* release hint */, 6 /* tag */);
2139 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2142 rv = VNET_API_ERROR_NO_SUCH_FIB;
2148 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2149 (ip4_address_t *)mp->hi_address,
2150 fib_index, mp->is_add == 0);
2154 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2158 vl_api_proxy_arp_intfc_enable_disable_t_handler
2159 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2162 vnet_main_t * vnm = vnet_get_main();
2163 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2164 vnet_sw_interface_t * si;
2167 VALIDATE_SW_IF_INDEX(mp);
2169 sw_if_index = ntohl(mp->sw_if_index);
2171 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2173 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2177 si = vnet_get_sw_interface (vnm, sw_if_index);
2181 if (mp->enable_disable)
2182 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2184 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2186 BAD_SW_IF_INDEX_LABEL;
2189 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2193 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2195 vl_api_ip_neighbor_add_del_reply_t * rmp;
2196 vnet_main_t * vnm = vnet_get_main();
2199 stats_main_t * sm = &stats_main;
2201 VALIDATE_SW_IF_INDEX(mp);
2203 dslock (sm, 1 /* release hint */, 7 /* tag */);
2207 rv = vnet_set_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 rv = vnet_unset_ip6_ethernet_neighbor
2213 (vm, ntohl(mp->sw_if_index),
2214 (ip6_address_t *)(mp->dst_address),
2215 mp->mac_address, sizeof(mp->mac_address));
2217 ip4_main_t * im = &ip4_main;
2218 ip_lookup_main_t * lm = &im->lookup_main;
2219 ethernet_arp_ip4_over_ethernet_address_t a;
2221 ip_adjacency_t *nh_adj;
2223 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2225 rv = VNET_API_ERROR_NO_SUCH_FIB;
2231 * Unfortunately, folks have a penchant for
2232 * adding interface addresses to the ARP cache, and
2233 * wondering why the forwarder eventually ASSERTs...
2235 ai = ip4_fib_lookup_with_table
2236 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2237 1 /* disable default route */);
2240 nh_adj = ip_get_adjacency (lm, ai);
2241 /* Never allow manipulation of a local adj! */
2242 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2243 clib_warning("%U matches local adj",
2245 (ip4_address_t *)(mp->dst_address));
2246 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2251 memcpy (&a.ethernet, mp->mac_address, 6);
2252 memcpy (&a.ip4, mp->dst_address, 4);
2255 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2256 fib_index, &a, mp->is_static);
2258 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2262 BAD_SW_IF_INDEX_LABEL;
2265 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2269 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2272 vpe_main_t *rm = &vpe_main;
2273 ip4_main_t *im4 = &ip4_main;
2274 ip6_main_t *im6 = &ip6_main;
2275 ip_lookup_main_t * lm;
2280 u32 adj_index, sw_if_index;
2281 vl_api_is_address_reachable_t *rmp;
2282 ip_adjacency_t * adj;
2283 unix_shared_memory_queue_t *q;
2285 q = vl_api_client_index_to_input_queue (mp->client_index);
2287 increment_missing_api_client_counter (rm->vlib_main);
2291 rmp = vl_msg_api_alloc (sizeof (*rmp));
2292 memcpy (rmp, mp, sizeof (*rmp));
2294 sw_if_index = mp->next_hop_sw_if_index;
2295 memcpy (&addr, mp->address, sizeof (addr));
2297 lm = &im6->lookup_main;
2299 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2301 lm = &im4->lookup_main;
2303 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2305 if (adj_index == ~0) {
2309 adj = ip_get_adjacency (lm, adj_index);
2311 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2312 && adj->rewrite_header.sw_if_index == sw_if_index) {
2315 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2316 && adj->rewrite_header.sw_if_index == sw_if_index) {
2318 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2320 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2321 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2329 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2333 static void vl_api_sw_interface_details_t_handler (
2334 vl_api_sw_interface_details_t * mp)
2336 clib_warning ("BUG");
2339 static void vl_api_sw_interface_set_flags_t_handler (
2340 vl_api_sw_interface_set_flags_t * mp)
2342 vl_api_sw_interface_set_flags_reply_t *rmp;
2343 vnet_main_t * vnm = vnet_get_main();
2345 clib_error_t * error;
2348 VALIDATE_SW_IF_INDEX(mp);
2350 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2352 error = vnet_sw_interface_set_flags (vnm,
2353 ntohl(mp->sw_if_index),
2357 clib_error_report (error);
2360 BAD_SW_IF_INDEX_LABEL;
2361 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2364 static void vl_api_sw_interface_clear_stats_t_handler (
2365 vl_api_sw_interface_clear_stats_t * mp)
2367 vl_api_sw_interface_clear_stats_reply_t *rmp;
2369 vnet_main_t * vnm = vnet_get_main();
2370 vnet_interface_main_t * im = &vnm->interface_main;
2371 vlib_simple_counter_main_t * sm;
2372 vlib_combined_counter_main_t * cm;
2373 static vnet_main_t ** my_vnet_mains;
2374 int i, j, n_counters;
2378 vec_reset_length (my_vnet_mains);
2380 for (i = 0; i < vec_len (vnet_mains); i++)
2383 vec_add1 (my_vnet_mains, vnet_mains[i]);
2386 if (vec_len (vnet_mains) == 0)
2387 vec_add1 (my_vnet_mains, vnm);
2389 n_counters = vec_len (im->combined_sw_if_counters);
2391 for (j = 0; j < n_counters; j++)
2393 for (i = 0; i < vec_len(my_vnet_mains); i++)
2395 im = &my_vnet_mains[i]->interface_main;
2396 cm = im->combined_sw_if_counters + j;
2397 if (mp->sw_if_index == (u32)~0)
2398 vlib_clear_combined_counters (cm);
2400 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2404 n_counters = vec_len (im->sw_if_counters);
2406 for (j = 0; j < n_counters; j++)
2408 for (i = 0; i < vec_len(my_vnet_mains); i++)
2410 im = &my_vnet_mains[i]->interface_main;
2411 sm = im->sw_if_counters + j;
2412 if (mp->sw_if_index == (u32)~0)
2413 vlib_clear_simple_counters (sm);
2415 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2419 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2422 static void send_sw_interface_details (vpe_api_main_t * am,
2423 unix_shared_memory_queue_t *q,
2424 vnet_sw_interface_t * swif,
2425 u8 * interface_name)
2427 vl_api_sw_interface_details_t * mp;
2428 vnet_hw_interface_t * hi;
2430 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2432 mp = vl_msg_api_alloc (sizeof (*mp));
2433 memset (mp, 0, sizeof (*mp));
2434 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2435 mp->sw_if_index = ntohl(swif->sw_if_index);
2436 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2437 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2439 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2441 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2442 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2443 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2444 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2445 mp->link_mtu = ntohs(hi->max_packet_bytes);
2447 strncpy ((char *) mp->interface_name,
2448 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2450 /* Send the L2 address for ethernet physical intfcs */
2451 if (swif->sup_sw_if_index == swif->sw_if_index
2452 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2453 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2454 ethernet_interface_t *ei;
2456 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2457 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2458 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2459 mp->l2_address_length = ntohl(sizeof (ei->address));
2460 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2461 vnet_sub_interface_t *sub = &swif->sub;
2462 mp->sub_id = ntohl(sub->id);
2463 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2464 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2465 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2466 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2467 mp->sub_exact_match = sub->eth.flags.exact_match;
2468 mp->sub_default = sub->eth.flags.default_sub;
2469 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2470 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2472 /* vlan tag rewrite data */
2473 u32 vtr_op = L2_VTR_DISABLED;
2474 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2476 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2477 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2478 // error - default to disabled
2479 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2480 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2483 mp->vtr_op = ntohl(vtr_op);
2484 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2485 mp->vtr_tag1 = ntohl(vtr_tag1);
2486 mp->vtr_tag2 = ntohl(vtr_tag2);
2490 vl_msg_api_send_shmem (q, (u8 *)&mp);
2493 static void send_sw_interface_flags (vpe_api_main_t * am,
2494 unix_shared_memory_queue_t *q,
2495 vnet_sw_interface_t * swif)
2497 vl_api_sw_interface_set_flags_t *mp;
2498 vnet_main_t * vnm = am->vnet_main;
2500 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2502 mp = vl_msg_api_alloc (sizeof (*mp));
2503 memset (mp, 0, sizeof (*mp));
2504 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2505 mp->sw_if_index = ntohl(swif->sw_if_index);
2507 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2509 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2511 vl_msg_api_send_shmem (q, (u8 *)&mp);
2514 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2515 unix_shared_memory_queue_t *q,
2517 __attribute__((unused));
2519 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2520 unix_shared_memory_queue_t *q,
2523 vl_api_sw_interface_set_flags_t *mp;
2525 mp = vl_msg_api_alloc (sizeof (*mp));
2526 memset (mp, 0, sizeof (*mp));
2527 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2528 mp->sw_if_index = ntohl(sw_if_index);
2530 mp->admin_up_down = 0;
2531 mp->link_up_down = 0;
2533 vl_msg_api_send_shmem (q, (u8 *)&mp);
2536 static void vl_api_sw_interface_dump_t_handler (
2537 vl_api_sw_interface_dump_t *mp)
2539 vpe_api_main_t * am = &vpe_api_main;
2540 vnet_sw_interface_t * swif;
2541 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2542 u8 * filter_string = 0, * name_string = 0;
2543 unix_shared_memory_queue_t * q;
2544 char * strcasestr (char *, char *); /* lnx hdr file botch */
2546 q = vl_api_client_index_to_input_queue (mp->client_index);
2551 if (mp->name_filter_valid) {
2552 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2553 filter_string = format (0, "%s%c", mp->name_filter, 0);
2556 pool_foreach (swif, im->sw_interfaces,
2558 name_string = format (name_string, "%U%c",
2559 format_vnet_sw_interface_name,
2560 am->vnet_main, swif, 0);
2562 if (mp->name_filter_valid == 0 ||
2563 strcasestr((char *) name_string, (char *) filter_string)) {
2565 send_sw_interface_details (am, q, swif, name_string);
2566 send_sw_interface_flags (am, q, swif);
2568 _vec_len (name_string) = 0;
2571 vec_free (name_string);
2572 vec_free (filter_string);
2575 void send_oam_event (oam_target_t * t)
2577 vpe_api_main_t * vam = &vpe_api_main;
2578 unix_shared_memory_queue_t * q;
2579 vpe_client_registration_t *reg;
2580 vl_api_oam_event_t * mp;
2582 pool_foreach(reg, vam->oam_events_registrations,
2584 q = vl_api_client_index_to_input_queue (reg->client_index);
2586 mp = vl_msg_api_alloc (sizeof (*mp));
2587 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2588 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2589 mp->state = t->state;
2590 vl_msg_api_send_shmem (q, (u8 *)&mp);
2596 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2598 vl_api_oam_add_del_reply_t * rmp;
2601 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2602 (ip4_address_t *)mp->dst_address,
2606 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2610 vl_api_vnet_get_summary_stats_t_handler (
2611 vl_api_vnet_get_summary_stats_t *mp)
2613 stats_main_t * sm = &stats_main;
2614 vnet_interface_main_t * im = sm->interface_main;
2615 vl_api_vnet_summary_stats_reply_t *rmp;
2616 vlib_combined_counter_main_t * cm;
2619 u64 total_pkts[VLIB_N_RX_TX];
2620 u64 total_bytes[VLIB_N_RX_TX];
2622 unix_shared_memory_queue_t * q =
2623 vl_api_client_index_to_input_queue (mp->client_index);
2628 rmp = vl_msg_api_alloc (sizeof (*rmp));
2629 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2630 rmp->context = mp->context;
2633 memset (total_pkts, 0, sizeof (total_pkts));
2634 memset (total_bytes, 0, sizeof (total_bytes));
2636 vnet_interface_counter_lock (im);
2638 vec_foreach (cm, im->combined_sw_if_counters) {
2639 which = cm - im->combined_sw_if_counters;
2641 for (i = 0; i < vec_len (cm->maxi); i++) {
2642 vlib_get_combined_counter (cm, i, &v);
2643 total_pkts[which] += v.packets;
2644 total_bytes[which] += v.bytes;
2647 vnet_interface_counter_unlock (im);
2649 /* Note: in HOST byte order! */
2650 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2651 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2652 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2653 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2654 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2656 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2659 typedef CLIB_PACKED (struct {
2660 ip4_address_t address;
2662 u32 address_length : 6;
2667 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2669 vnet_main_t * vnm = vnet_get_main();
2670 vnet_interface_main_t * im = &vnm->interface_main;
2671 ip4_main_t * im4 = &ip4_main;
2672 static ip4_route_t * routes;
2673 static u32 * sw_if_indices_to_shut;
2674 stats_main_t * sm = &stats_main;
2679 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2680 u32 target_fib_id = ntohl(mp->vrf_id);
2682 dslock (sm, 1 /* release hint */, 8 /* tag */);
2684 vec_foreach (fib, im4->fibs) {
2685 vnet_sw_interface_t * si;
2687 if (fib->table_id != target_fib_id)
2690 /* remove any mpls/gre tunnels in this fib */
2691 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2693 /* remove any mpls encap/decap labels */
2694 mpls_fib_reset_labels (fib->table_id);
2696 /* remove any proxy arps in this fib */
2697 vnet_proxy_arp_fib_reset (fib->table_id);
2699 /* Set the flow hash for this fib to the default */
2700 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2702 vec_reset_length (sw_if_indices_to_shut);
2704 /* Shut down interfaces in this FIB / clean out intfc routes */
2705 pool_foreach (si, im->sw_interfaces,
2707 u32 sw_if_index = si->sw_if_index;
2709 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2710 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2712 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2715 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2716 sw_if_index = sw_if_indices_to_shut[i];
2717 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2719 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2720 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2721 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2724 vec_reset_length (routes);
2726 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2727 uword * hash = fib->adj_index_by_dst_address[i];
2731 x.address_length = i;
2733 hash_foreach_pair (p, hash,
2735 x.address.data_u32 = p->key;
2736 vec_add1 (routes, x);
2740 vec_foreach (r, routes) {
2741 ip4_add_del_route_args_t a;
2743 memset (&a, 0, sizeof (a));
2744 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2745 a.table_index_or_table_id = fib - im4->fibs;
2746 a.dst_address = r->address;
2747 a.dst_address_length = r->address_length;
2750 ip4_add_del_route (im4, &a);
2751 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2752 IP4_ROUTE_FLAG_FIB_INDEX);
2756 } /* vec_foreach (fib) */
2763 ip6_address_t address;
2770 ip6_route_t ** routep;
2771 } add_routes_in_fib_arg_t;
2773 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2775 add_routes_in_fib_arg_t * ap = arg;
2777 if (kvp->key[2]>>32 == ap->fib_index)
2779 ip6_address_t *addr;
2781 addr = (ip6_address_t *) kvp;
2782 vec_add2 (*ap->routep, r, 1);
2783 r->address = addr[0];
2784 r->address_length = kvp->key[2] & 0xFF;
2785 r->index = kvp->value;
2789 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2791 vnet_main_t * vnm = vnet_get_main();
2792 vnet_interface_main_t * im = &vnm->interface_main;
2793 ip6_main_t * im6 = &ip6_main;
2794 stats_main_t * sm = &stats_main;
2795 static ip6_route_t * routes;
2796 static u32 * sw_if_indices_to_shut;
2801 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2802 u32 target_fib_id = ntohl(mp->vrf_id);
2803 add_routes_in_fib_arg_t _a, *a=&_a;
2804 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2806 dslock (sm, 1 /* release hint */, 9 /* tag */);
2808 vec_foreach (fib, im6->fibs) {
2809 vnet_sw_interface_t * si;
2811 if (fib->table_id != target_fib_id)
2814 vec_reset_length (sw_if_indices_to_shut);
2816 /* Shut down interfaces in this FIB / clean out intfc routes */
2817 pool_foreach (si, im->sw_interfaces,
2819 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2821 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2824 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2825 sw_if_index = sw_if_indices_to_shut[i];
2826 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2828 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2829 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2830 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2833 vec_reset_length (routes);
2835 a->fib_index = fib - im6->fibs;
2836 a->routep = &routes;
2838 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2840 vec_foreach (r, routes) {
2841 ip6_add_del_route_args_t a;
2843 memset (&a, 0, sizeof (a));
2844 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2845 a.table_index_or_table_id = fib - im6->fibs;
2846 a.dst_address = r->address;
2847 a.dst_address_length = r->address_length;
2850 ip6_add_del_route (im6, &a);
2851 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2852 IP6_ROUTE_FLAG_FIB_INDEX);
2855 /* Reinstall the neighbor / router discovery routes */
2856 vnet_ip6_fib_init (im6, fib - im6->fibs);
2858 } /* vec_foreach (fib) */
2864 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2867 vl_api_reset_fib_reply_t * rmp;
2870 rv = ip6_reset_fib_t_handler (mp);
2872 rv = ip4_reset_fib_t_handler (mp);
2874 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2879 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2881 vl_api_dhcp_proxy_config_reply_t * rmp;
2884 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2885 (ip4_address_t *)(&mp->dhcp_src_address),
2886 (u32) ntohl(mp->vrf_id),
2887 (int) mp->insert_circuit_id,
2888 (int) (mp->is_add == 0));
2890 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2895 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2897 vl_api_dhcp_proxy_config_reply_t * rmp;
2900 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2901 (ip6_address_t *)(&mp->dhcp_src_address),
2902 (u32) ntohl(mp->vrf_id),
2903 (int) mp->insert_circuit_id,
2904 (int) (mp->is_add == 0));
2906 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2910 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2912 vl_api_dhcp_proxy_config_reply_t * rmp;
2915 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2916 (ip4_address_t *)(&mp->dhcp_src_address),
2917 (u32) ntohl(mp->rx_vrf_id),
2918 (u32) ntohl(mp->server_vrf_id),
2919 (int) mp->insert_circuit_id,
2920 (int) (mp->is_add == 0));
2922 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2927 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2929 vl_api_dhcp_proxy_config_reply_t * rmp;
2933 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2934 (ip6_address_t *)(&mp->dhcp_src_address),
2935 (u32) ntohl(mp->rx_vrf_id),
2936 (u32) ntohl(mp->server_vrf_id),
2937 (int) mp->insert_circuit_id,
2938 (int) (mp->is_add == 0));
2940 rv = VNET_API_ERROR_UNIMPLEMENTED;
2943 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2948 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2950 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2953 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2956 (int)mp->is_add == 0);
2958 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2961 (int)mp->is_add == 0);
2963 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2967 static void vl_api_dhcp_proxy_config_t_handler
2968 (vl_api_dhcp_proxy_config_t *mp)
2970 if (mp->is_ipv6 == 0)
2971 dhcpv4_proxy_config (mp);
2973 dhcpv6_proxy_config (mp);
2976 static void vl_api_dhcp_proxy_config_2_t_handler
2977 (vl_api_dhcp_proxy_config_2_t *mp)
2979 if (mp->is_ipv6 == 0)
2980 dhcpv4_proxy_config_2 (mp);
2982 dhcpv6_proxy_config_2 (mp);
2985 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2986 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2988 unix_shared_memory_queue_t * q;
2989 vl_api_dhcp_compl_event_t * mp;
2991 q = vl_api_client_index_to_input_queue (client_index);
2995 mp = vl_msg_api_alloc (sizeof (*mp));
2996 mp->client_index = client_index;
2998 mp->is_ipv6 = is_ipv6;
2999 memcpy (&mp->hostname, hostname, vec_len(hostname));
3000 mp->hostname[vec_len(hostname) + 1] = '\n';
3001 memcpy (&mp->host_address[0], host_address, 16);
3002 memcpy (&mp->router_address[0], router_address, 16);
3003 memcpy (&mp->host_mac[0], host_mac, 6);
3005 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3007 vl_msg_api_send_shmem (q, (u8 *)&mp);
3010 static void vl_api_dhcp_client_config_t_handler
3011 (vl_api_dhcp_client_config_t *mp)
3013 vlib_main_t *vm = vlib_get_main();
3014 vl_api_dhcp_client_config_reply_t * rmp;
3017 VALIDATE_SW_IF_INDEX(mp);
3019 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3020 mp->hostname, mp->is_add, mp->client_index,
3021 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3024 BAD_SW_IF_INDEX_LABEL;
3026 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3030 vl_api_sw_interface_ip6nd_ra_config_t_handler
3031 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3033 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3035 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3037 is_no = mp->is_no == 1;
3038 surpress = mp->surpress == 1;
3039 managed = mp->managed == 1;
3040 other = mp->other == 1;
3041 ll_option = mp->ll_option == 1;
3042 send_unicast = mp->send_unicast == 1;
3043 cease = mp->cease == 1;
3044 default_router = mp->default_router == 1;
3046 VALIDATE_SW_IF_INDEX(mp);
3048 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3049 surpress, managed, other,
3050 ll_option, send_unicast, cease,
3051 default_router, ntohl (mp->lifetime),
3052 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3053 ntohl(mp->max_interval), ntohl( mp->min_interval),
3056 BAD_SW_IF_INDEX_LABEL;
3058 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3062 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3063 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3065 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3067 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3069 VALIDATE_SW_IF_INDEX(mp);
3071 is_no = mp->is_no == 1;
3072 use_default = mp->use_default == 1;
3073 no_advertise = mp->no_advertise == 1;
3074 off_link = mp->off_link == 1;
3075 no_autoconfig = mp->no_autoconfig == 1;
3076 no_onlink = mp->no_onlink == 1;
3078 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3079 (ip6_address_t *)mp->address, mp->address_length,
3080 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3081 no_advertise, off_link, no_autoconfig, no_onlink,
3084 BAD_SW_IF_INDEX_LABEL;
3085 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3089 vl_api_sw_interface_ip6_enable_disable_t_handler
3090 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3092 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3093 vnet_main_t * vnm = vnet_get_main();
3095 clib_error_t * error;
3099 VALIDATE_SW_IF_INDEX(mp);
3101 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3102 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3105 clib_error_report(error);
3106 rv = VNET_API_ERROR_UNSPECIFIED;
3108 rv = vnm->api_errno;
3111 BAD_SW_IF_INDEX_LABEL;
3113 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3117 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3118 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3120 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3122 clib_error_t * error;
3123 vnet_main_t * vnm = vnet_get_main();
3127 VALIDATE_SW_IF_INDEX(mp);
3129 error = set_ip6_link_local_address(vm,
3130 ntohl(mp->sw_if_index),
3131 (ip6_address_t *)mp->address,
3132 mp->address_length);
3134 clib_error_report(error);
3135 rv = VNET_API_ERROR_UNSPECIFIED;
3137 rv = vnm->api_errno;
3140 BAD_SW_IF_INDEX_LABEL;
3142 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3145 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3147 vl_api_set_ip_flow_hash_reply_t *rmp;
3148 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3150 clib_warning ("unimplemented...");
3152 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3155 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3157 vl_api_set_ip_flow_hash_reply_t *rmp;
3160 u32 flow_hash_config = 0;
3162 table_id = ntohl(mp->vrf_id);
3164 #define _(a,b) if (mp->a) flow_hash_config |= b;
3165 foreach_flow_hash_bit;
3168 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3170 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3174 static void vl_api_set_ip_flow_hash_t_handler
3175 (vl_api_set_ip_flow_hash_t *mp)
3177 if (mp->is_ipv6 == 0)
3178 set_ip4_flow_hash (mp);
3180 set_ip6_flow_hash (mp);
3183 static void vl_api_sw_interface_set_unnumbered_t_handler
3184 (vl_api_sw_interface_set_unnumbered_t *mp)
3186 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3188 vnet_sw_interface_t * si;
3189 vnet_main_t *vnm = vnet_get_main();
3190 u32 sw_if_index, unnumbered_sw_if_index;
3192 sw_if_index = ntohl(mp->sw_if_index);
3193 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3196 * The API message field names are backwards from
3197 * the underlying data structure names.
3198 * It's not worth changing them now.
3200 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3201 unnumbered_sw_if_index)) {
3202 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3206 /* Only check the "use loop0" field when setting the binding */
3208 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3209 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3213 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3216 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3217 si->unnumbered_sw_if_index = sw_if_index;
3219 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3220 si->unnumbered_sw_if_index = (u32)~0;
3224 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3227 static void vl_api_create_loopback_t_handler
3228 (vl_api_create_loopback_t *mp)
3230 vl_api_create_loopback_reply_t * rmp;
3234 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3236 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3238 rmp->sw_if_index = ntohl (sw_if_index);
3242 static void vl_api_delete_loopback_t_handler
3243 (vl_api_delete_loopback_t *mp)
3245 vl_api_delete_loopback_reply_t * rmp;
3249 sw_if_index = ntohl (mp->sw_if_index);
3250 rv = vnet_delete_loopback_interface (sw_if_index);
3252 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3255 static void vl_api_control_ping_t_handler
3256 (vl_api_control_ping_t *mp)
3258 vl_api_control_ping_reply_t * rmp;
3261 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3263 rmp->vpe_pid = ntohl (getpid());
3267 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3269 u8 **shmem_vecp = (u8 **)arg;
3272 api_main_t * am = &api_main;
3275 shmem_vec = *shmem_vecp;
3277 offset = vec_len (shmem_vec);
3279 pthread_mutex_lock (&am->vlib_rp->mutex);
3280 oldheap = svm_push_data_heap (am->vlib_rp);
3282 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3284 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3286 svm_pop_heap (oldheap);
3287 pthread_mutex_unlock (&am->vlib_rp->mutex);
3289 *shmem_vecp = shmem_vec;
3293 static void vl_api_cli_request_t_handler
3294 (vl_api_cli_request_t *mp)
3296 vl_api_cli_reply_t *rp;
3297 unix_shared_memory_queue_t *q;
3298 vlib_main_t * vm = vlib_get_main();
3299 api_main_t * am = &api_main;
3300 unformat_input_t input;
3304 q = vl_api_client_index_to_input_queue (mp->client_index);
3308 rp = vl_msg_api_alloc (sizeof (*rp));
3309 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3310 rp->context = mp->context;
3312 unformat_init_vector (&input, (u8 *)mp->cmd_in_shmem);
3314 vlib_cli_input (vm, &input, shmem_cli_output,
3317 pthread_mutex_lock (&am->vlib_rp->mutex);
3318 oldheap = svm_push_data_heap (am->vlib_rp);
3320 vec_add1(shmem_vec, 0);
3322 svm_pop_heap (oldheap);
3323 pthread_mutex_unlock (&am->vlib_rp->mutex);
3325 rp->reply_in_shmem = (uword)shmem_vec;
3327 vl_msg_api_send_shmem (q, (u8 *)&rp);
3330 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3333 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3334 vnet_main_t *vnm = vnet_get_main();
3335 clib_error_t * error;
3340 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3342 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3345 clib_error_report(error);
3346 rv = VNET_API_ERROR_UNSPECIFIED;
3348 rv = vnm->api_errno;
3351 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3354 static void vl_api_sr_tunnel_add_del_t_handler
3355 (vl_api_sr_tunnel_add_del_t *mp)
3358 clib_warning ("unimplemented");
3360 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3362 vl_api_sr_tunnel_add_del_reply_t * rmp;
3363 ip6_address_t * segments = 0, * seg;
3364 ip6_address_t * tags = 0, *tag;
3365 ip6_address_t * this_address;
3368 if (mp->n_segments == 0) {
3373 memset (a, 0, sizeof (*a));
3374 a->src_address = (ip6_address_t *)&mp->src_address;
3375 a->dst_address = (ip6_address_t *)&mp->dst_address;
3376 a->dst_mask_width = mp->dst_mask_width;
3377 a->flags_net_byte_order = mp->flags_net_byte_order;
3378 a->is_del = (mp->is_add == 0);
3379 a->rx_table_id = ntohl(mp->outer_vrf_id);
3380 a->tx_table_id = ntohl(mp->inner_vrf_id);
3382 /* Yank segments and tags out of the API message */
3383 this_address = (ip6_address_t *)mp->segs_and_tags;
3384 for (i = 0; i < mp->n_segments; i++) {
3385 vec_add2 (segments, seg, 1);
3386 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3389 for (i = 0; i < mp->n_tags; i++) {
3390 vec_add2 (tags, tag, 1);
3391 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3395 a->segments = segments;
3398 rv = ip6_sr_add_del_tunnel (a);
3402 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3406 #define foreach_classify_add_del_table_field \
3411 _(match_n_vectors) \
3412 _(next_table_index) \
3415 static void vl_api_classify_add_del_table_t_handler
3416 (vl_api_classify_add_del_table_t * mp)
3418 vl_api_classify_add_del_table_reply_t * rmp;
3419 vnet_classify_main_t * cm = &vnet_classify_main;
3420 vnet_classify_table_t * t;
3424 foreach_classify_add_del_table_field;
3427 #define _(a) a = ntohl(mp->a);
3428 foreach_classify_add_del_table_field;
3431 /* The underlying API fails silently, on purpose, so check here */
3432 if (mp->is_add == 0)
3433 if (pool_is_free_index (cm->tables, table_index)) {
3434 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3438 rv = vnet_classify_add_del_table
3439 (cm, mp->mask, nbuckets, memory_size,
3440 skip_n_vectors, match_n_vectors,
3441 next_table_index, miss_next_index,
3442 &table_index, mp->is_add);
3445 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3447 if (rv == 0 && mp->is_add) {
3448 t = pool_elt_at_index (cm->tables, table_index);
3449 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3450 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3451 rmp->new_table_index = ntohl(table_index);
3453 rmp->skip_n_vectors = ~0;
3454 rmp->match_n_vectors = ~0;
3455 rmp->new_table_index = ~0;
3460 static void vl_api_classify_add_del_session_t_handler
3461 (vl_api_classify_add_del_session_t * mp)
3463 vnet_classify_main_t * cm = &vnet_classify_main;
3464 vl_api_classify_add_del_session_reply_t * rmp;
3466 u32 table_index, hit_next_index, opaque_index;
3469 table_index = ntohl (mp->table_index);
3470 hit_next_index = ntohl (mp->hit_next_index);
3471 opaque_index = ntohl (mp->opaque_index);
3472 advance = ntohl (mp->advance);
3474 rv = vnet_classify_add_del_session
3475 (cm, table_index, mp->match, hit_next_index, opaque_index,
3476 advance, mp->is_add);
3478 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3481 static void vl_api_classify_set_interface_ip_table_t_handler
3482 (vl_api_classify_set_interface_ip_table_t * mp)
3484 vlib_main_t * vm = vlib_get_main();
3485 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3487 u32 table_index, sw_if_index;
3489 table_index = ntohl (mp->table_index);
3490 sw_if_index = ntohl (mp->sw_if_index);
3492 VALIDATE_SW_IF_INDEX(mp);
3495 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3497 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3499 BAD_SW_IF_INDEX_LABEL;
3501 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3504 static void vl_api_classify_set_interface_l2_tables_t_handler
3505 (vl_api_classify_set_interface_l2_tables_t * mp)
3507 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3509 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3512 ip4_table_index = ntohl(mp->ip4_table_index);
3513 ip6_table_index = ntohl(mp->ip6_table_index);
3514 other_table_index = ntohl(mp->other_table_index);
3515 sw_if_index = ntohl(mp->sw_if_index);
3517 VALIDATE_SW_IF_INDEX(mp);
3519 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3520 ip6_table_index, other_table_index);
3523 if (ip4_table_index != ~0 || ip6_table_index != ~0
3524 || other_table_index != ~0)
3529 vnet_l2_classify_enable_disable (sw_if_index, enable);
3532 BAD_SW_IF_INDEX_LABEL;
3534 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3538 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3541 vl_api_l2_fib_clear_table_reply_t * rmp;
3543 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3544 * that is not currently implemented. When that TODO is fixed
3545 * this call should be changed to pass 1 instead of 0.
3547 l2fib_clear_table (0);
3549 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3552 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3557 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3560 vl_api_l2_interface_efp_filter_reply_t * rmp;
3561 vnet_main_t *vnm = vnet_get_main();
3563 // enable/disable the feature
3564 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3565 rv = vnm->api_errno;
3567 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3571 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3574 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3575 vnet_main_t * vnm = vnet_get_main();
3576 vlib_main_t * vm = vlib_get_main();
3579 VALIDATE_SW_IF_INDEX(mp);
3581 vtr_op = ntohl(mp->vtr_op);
3583 /* The L2 code is unsuspicious */
3585 case L2_VTR_DISABLED:
3590 case L2_VTR_TRANSLATE_1_1:
3591 case L2_VTR_TRANSLATE_1_2:
3592 case L2_VTR_TRANSLATE_2_1:
3593 case L2_VTR_TRANSLATE_2_2:
3597 rv = VNET_API_ERROR_INVALID_VALUE;
3598 goto bad_sw_if_index;
3601 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3602 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3605 BAD_SW_IF_INDEX_LABEL;
3607 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3611 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3615 vl_api_create_vhost_user_if_reply_t * rmp;
3616 u32 sw_if_index = (u32)~0;
3618 vnet_main_t * vnm = vnet_get_main();
3619 vlib_main_t * vm = vlib_get_main();
3621 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3622 mp->is_server, &sw_if_index, (u64)~0,
3623 mp->renumber, ntohl(mp->custom_dev_instance),
3624 (mp->use_custom_mac)?mp->mac_address:NULL);
3626 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3628 rmp->sw_if_index = ntohl (sw_if_index);
3634 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3638 vl_api_modify_vhost_user_if_reply_t * rmp;
3639 u32 sw_if_index = ntohl(mp->sw_if_index);
3641 vnet_main_t * vnm = vnet_get_main();
3642 vlib_main_t * vm = vlib_get_main();
3644 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3645 mp->is_server, sw_if_index, (u64)~0,
3646 mp->renumber, ntohl(mp->custom_dev_instance));
3648 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3653 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3657 vpe_api_main_t * vam = &vpe_api_main;
3658 vl_api_delete_vhost_user_if_reply_t * rmp;
3659 u32 sw_if_index = ntohl(mp->sw_if_index);
3661 vnet_main_t * vnm = vnet_get_main();
3662 vlib_main_t * vm = vlib_get_main();
3664 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3666 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3668 unix_shared_memory_queue_t * q =
3669 vl_api_client_index_to_input_queue (mp->client_index);
3673 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3678 static void vl_api_sw_interface_vhost_user_details_t_handler (
3679 vl_api_sw_interface_vhost_user_details_t * mp)
3681 clib_warning ("BUG");
3685 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3686 unix_shared_memory_queue_t *q,
3687 vhost_user_intf_details_t * vui)
3689 vl_api_sw_interface_vhost_user_details_t * mp;
3691 mp = vl_msg_api_alloc (sizeof (*mp));
3692 memset (mp, 0, sizeof (*mp));
3693 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3694 mp->sw_if_index = ntohl(vui->sw_if_index);
3695 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3696 mp->features = clib_net_to_host_u64 (vui->features);
3697 mp->is_server = vui->is_server;
3698 mp->num_regions = ntohl(vui->num_regions);
3699 mp->sock_errno = ntohl(vui->sock_errno);
3701 strncpy ((char *) mp->sock_filename,
3702 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3703 strncpy ((char *) mp->interface_name,
3704 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3706 vl_msg_api_send_shmem (q, (u8 *)&mp);
3711 vl_api_sw_interface_vhost_user_dump_t_handler (
3712 vl_api_sw_interface_vhost_user_dump_t *mp)
3716 vpe_api_main_t * am = &vpe_api_main;
3717 vnet_main_t * vnm = vnet_get_main();
3718 vlib_main_t * vm = vlib_get_main();
3719 vhost_user_intf_details_t *ifaces = NULL;
3720 vhost_user_intf_details_t *vuid = NULL;
3721 unix_shared_memory_queue_t * q;
3723 q = vl_api_client_index_to_input_queue (mp->client_index);
3727 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3731 vec_foreach (vuid, ifaces) {
3732 send_sw_interface_vhost_user_details (am, q, vuid);
3738 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3739 unix_shared_memory_queue_t *q,
3743 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3744 u8 * if_name = NULL;
3745 vnet_sw_interface_t * si = NULL;
3747 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3749 if_name = format(if_name, "%U",
3750 format_vnet_sw_interface_name, lm->vnet_main, si);
3752 mp = vl_msg_api_alloc (sizeof (*mp));
3753 memset (mp, 0, sizeof (*mp));
3754 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3755 strncpy((char *)mp->interface_name,
3756 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3757 mp->sw_if_index = ntohl(si->sw_if_index);
3758 mp->local_session_id = s->local_session_id;
3759 mp->remote_session_id = s->remote_session_id;
3760 mp->local_cookie[0] = s->local_cookie[0];
3761 mp->local_cookie[1] = s->local_cookie[1];
3762 mp->remote_cookie = s->remote_cookie;
3763 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3764 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3765 mp->l2_sublayer_present = s->l2_sublayer_present;
3767 vl_msg_api_send_shmem (q, (u8 *)&mp);
3770 static void send_ip_address_details (vpe_api_main_t * am,
3771 unix_shared_memory_queue_t * q,
3776 vl_api_ip_address_details_t * mp;
3778 mp = vl_msg_api_alloc (sizeof (*mp));
3779 memset (mp, 0, sizeof (*mp));
3780 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3783 memcpy(&mp->ip, ip, sizeof(mp->ip));
3785 u32 * tp = (u32 *)mp->ip;
3786 *tp = ntohl(*(u32*)ip);
3788 mp->prefix_length = prefix_length;
3790 vl_msg_api_send_shmem (q, (u8 *)&mp);
3794 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3796 vpe_api_main_t * am = &vpe_api_main;
3797 unix_shared_memory_queue_t * q;
3800 ip6_main_t * im6 = &ip6_main;
3801 ip4_main_t * im4 = &ip4_main;
3802 ip_lookup_main_t * lm6 = &im6->lookup_main;
3803 ip_lookup_main_t * lm4 = &im4->lookup_main;
3804 ip_interface_address_t * ia = 0;
3805 u32 sw_if_index = ~0;
3807 sw_if_index = ntohl(mp->sw_if_index);
3809 q = vl_api_client_index_to_input_queue (mp->client_index);
3815 foreach_ip_interface_address (lm6, ia, sw_if_index,
3816 1 /* honor unnumbered */,
3818 r6 = ip_interface_address_get_address (lm6, ia);
3819 u16 prefix_length = ia->address_length;
3820 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3823 foreach_ip_interface_address (lm4, ia, sw_if_index,
3824 1 /* honor unnumbered */,
3826 r4 = ip_interface_address_get_address (lm4, ia);
3827 u16 prefix_length = ia->address_length;
3828 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3833 static void send_ip_details (vpe_api_main_t * am,
3834 unix_shared_memory_queue_t *q,
3837 vl_api_ip_details_t * mp;
3839 mp = vl_msg_api_alloc (sizeof (*mp));
3840 memset (mp, 0, sizeof (*mp));
3841 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3843 mp->sw_if_index = ntohl(sw_if_index);
3845 vl_msg_api_send_shmem (q, (u8 *)&mp);
3849 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3850 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3852 vpe_api_main_t * am = &vpe_api_main;
3853 l2t_main_t * lm = &l2t_main;
3854 unix_shared_memory_queue_t * q;
3855 l2t_session_t *session;
3857 q = vl_api_client_index_to_input_queue (mp->client_index);
3861 pool_foreach (session, lm->sessions,
3863 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3868 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3869 unix_shared_memory_queue_t *q,
3870 tapcli_interface_details_t *tap_if)
3872 vl_api_sw_interface_tap_details_t * mp;
3873 mp = vl_msg_api_alloc (sizeof (*mp));
3874 memset (mp, 0, sizeof (*mp));
3875 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3876 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3877 strncpy((char *)mp->dev_name,
3878 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3880 vl_msg_api_send_shmem (q, (u8 *)&mp);
3884 vl_api_sw_interface_tap_dump_t_handler (
3885 vl_api_sw_interface_tap_dump_t *mp)
3888 vpe_api_main_t * am = &vpe_api_main;
3889 unix_shared_memory_queue_t * q;
3890 tapcli_interface_details_t *tapifs = NULL;
3891 tapcli_interface_details_t *tap_if = NULL;
3893 q = vl_api_client_index_to_input_queue (mp->client_index);
3897 rv = vnet_tap_dump_ifs(&tapifs);
3901 vec_foreach(tap_if, tapifs) {
3902 send_sw_interface_tap_details(am, q, tap_if);
3909 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3911 vpe_api_main_t * am = &vpe_api_main;
3912 vnet_main_t * vnm = vnet_get_main();
3913 vlib_main_t * vm = vlib_get_main();
3914 vnet_interface_main_t * im = &vnm->interface_main;
3915 unix_shared_memory_queue_t * q;
3916 vnet_sw_interface_t * si, * sorted_sis;
3917 u32 sw_if_index = ~0;
3919 q = vl_api_client_index_to_input_queue (mp->client_index);
3924 /* Gather interfaces. */
3925 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3926 _vec_len (sorted_sis) = 0;
3927 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3929 vec_foreach (si, sorted_sis) {
3930 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3931 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3934 sw_if_index = si->sw_if_index;
3935 send_ip_details(am, q, sw_if_index);
3940 static void vl_api_l2_fib_table_entry_t_handler (
3941 vl_api_l2_fib_table_entry_t * mp)
3943 clib_warning ("BUG");
3946 static void send_l2fib_table_entry (vpe_api_main_t * am,
3947 unix_shared_memory_queue_t *q,
3948 l2fib_entry_key_t * l2fe_key,
3949 l2fib_entry_result_t * l2fe_res)
3951 vl_api_l2_fib_table_entry_t * mp;
3953 mp = vl_msg_api_alloc (sizeof (*mp));
3954 memset (mp, 0, sizeof (*mp));
3955 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3957 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3959 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3960 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3961 mp->static_mac = l2fe_res->fields.static_mac;
3962 mp->filter_mac = l2fe_res->fields.filter;
3963 mp->bvi_mac = l2fe_res->fields.bvi;
3965 vl_msg_api_send_shmem (q, (u8 *)&mp);
3969 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3971 vpe_api_main_t * am = &vpe_api_main;
3972 bd_main_t * bdm = &bd_main;
3973 l2fib_entry_key_t *l2fe_key = NULL;
3974 l2fib_entry_result_t *l2fe_res = NULL;
3975 u32 ni, bd_id = ntohl (mp->bd_id);
3977 unix_shared_memory_queue_t * q;
3980 q = vl_api_client_index_to_input_queue (mp->client_index);
3984 /* see l2fib_table_dump: ~0 means "any" */
3988 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
3995 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
3997 vec_foreach_index (ni, l2fe_key) {
3998 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
3999 vec_elt_at_index(l2fe_res, ni));
4006 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4008 vl_api_show_version_reply_t *rmp;
4010 char * vpe_api_get_build_directory(void);
4011 char * vpe_api_get_version(void);
4012 char * vpe_api_get_build_date(void);
4014 unix_shared_memory_queue_t * q =
4015 vl_api_client_index_to_input_queue (mp->client_index);
4020 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4022 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4023 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4024 ARRAY_LEN(rmp->build_directory)-1);
4025 strncpy ((char *) rmp->version, vpe_api_get_version(),
4026 ARRAY_LEN(rmp->version)-1);
4027 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4028 ARRAY_LEN(rmp->build_date)-1);
4032 static void vl_api_get_node_index_t_handler
4033 (vl_api_get_node_index_t * mp)
4035 vlib_main_t * vm = vlib_get_main();
4036 vl_api_get_node_index_reply_t * rmp;
4039 u32 node_index = ~0;
4041 n = vlib_get_node_by_name (vm, mp->node_name);
4044 rv = VNET_API_ERROR_NO_SUCH_NODE;
4046 node_index = n->index;
4048 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4050 rmp->node_index = ntohl(node_index);
4054 static void vl_api_add_node_next_t_handler
4055 (vl_api_add_node_next_t * mp)
4057 vlib_main_t * vm = vlib_get_main();
4058 vl_api_add_node_next_reply_t * rmp;
4059 vlib_node_t * n, * next;
4061 u32 next_index = ~0;
4063 n = vlib_get_node_by_name (vm, mp->node_name);
4066 rv = VNET_API_ERROR_NO_SUCH_NODE;
4070 next = vlib_get_node_by_name (vm, mp->next_name);
4073 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4075 next_index = vlib_node_add_next (vm, n->index, next->index);
4078 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4080 rmp->next_index = ntohl(next_index);
4084 static void vl_api_l2tpv3_create_tunnel_t_handler
4085 (vl_api_l2tpv3_create_tunnel_t *mp)
4087 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4088 l2t_main_t *lm = &l2t_main;
4089 u32 sw_if_index = (u32)~0;
4092 if (mp->is_ipv6 != 1) {
4093 rv = VNET_API_ERROR_UNIMPLEMENTED;
4097 rv = create_l2tpv3_ipv6_tunnel (lm,
4098 (ip6_address_t *) mp->client_address,
4099 (ip6_address_t *) mp->our_address,
4100 ntohl(mp->local_session_id),
4101 ntohl(mp->remote_session_id),
4102 clib_net_to_host_u64(mp->local_cookie),
4103 clib_net_to_host_u64(mp->remote_cookie),
4104 mp->l2_sublayer_present,
4108 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4110 rmp->sw_if_index = ntohl (sw_if_index);
4114 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4115 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4117 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4118 l2t_main_t *lm = &l2t_main;
4121 VALIDATE_SW_IF_INDEX(mp);
4123 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4124 clib_net_to_host_u64(mp->new_local_cookie),
4125 clib_net_to_host_u64(mp->new_remote_cookie));
4127 BAD_SW_IF_INDEX_LABEL;
4129 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4132 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4133 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4136 vnet_main_t * vnm = vnet_get_main();
4137 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4139 VALIDATE_SW_IF_INDEX(mp);
4141 rv = l2tpv3_interface_enable_disable
4142 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4144 BAD_SW_IF_INDEX_LABEL;
4146 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4149 static void vl_api_l2tpv3_set_lookup_key_t_handler
4150 (vl_api_l2tpv3_set_lookup_key_t * mp)
4153 l2t_main_t *lm = &l2t_main;
4154 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4156 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4157 rv = VNET_API_ERROR_INVALID_VALUE;
4161 lm->lookup_type = mp->key;
4164 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4167 static void vl_api_vxlan_add_del_tunnel_t_handler
4168 (vl_api_vxlan_add_del_tunnel_t * mp)
4170 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4172 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4173 u32 encap_fib_index;
4175 ip4_main_t * im = &ip4_main;
4176 u32 sw_if_index = ~0;
4178 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4180 rv = VNET_API_ERROR_NO_SUCH_FIB;
4183 encap_fib_index = p[0];
4185 memset (a, 0, sizeof (*a));
4187 a->is_add = mp->is_add;
4189 /* ip addresses sent in network byte order */
4190 a->src.as_u32 = mp->src_address;
4191 a->dst.as_u32 = mp->dst_address;
4193 a->encap_fib_index = encap_fib_index;
4194 a->decap_next_index = ntohl(mp->decap_next_index);
4195 a->vni = ntohl(mp->vni);
4196 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4199 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4201 rmp->sw_if_index = ntohl (sw_if_index);
4205 static void send_vxlan_tunnel_details
4206 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4208 vl_api_vxlan_tunnel_details_t * rmp;
4209 ip4_main_t * im = &ip4_main;
4211 rmp = vl_msg_api_alloc (sizeof (*rmp));
4212 memset (rmp, 0, sizeof (*rmp));
4213 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4214 rmp->src_address = t->src.data_u32;
4215 rmp->dst_address = t->dst.data_u32;
4216 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4217 rmp->vni = htonl(t->vni);
4218 rmp->decap_next_index = htonl(t->decap_next_index);
4219 rmp->sw_if_index = htonl(t->sw_if_index);
4221 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4224 static void vl_api_vxlan_tunnel_dump_t_handler
4225 (vl_api_vxlan_tunnel_dump_t * mp)
4227 unix_shared_memory_queue_t * q;
4228 vxlan_main_t * vxm = &vxlan_main;
4232 q = vl_api_client_index_to_input_queue (mp->client_index);
4237 sw_if_index = ntohl(mp->sw_if_index);
4239 if (~0 == sw_if_index) {
4240 pool_foreach (t, vxm->tunnels,
4242 send_vxlan_tunnel_details(t, q);
4245 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4246 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4249 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4250 send_vxlan_tunnel_details(t, q);
4255 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4257 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4259 vl_api_l2_patch_add_del_reply_t * rmp;
4260 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4264 VALIDATE_RX_SW_IF_INDEX(mp);
4265 VALIDATE_TX_SW_IF_INDEX(mp);
4267 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4268 ntohl(mp->tx_sw_if_index),
4269 (int)(mp->is_add != 0));
4271 BAD_RX_SW_IF_INDEX_LABEL;
4272 BAD_TX_SW_IF_INDEX_LABEL;
4274 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4278 vl_api_nsh_gre_add_del_tunnel_t_handler
4279 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4281 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4283 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4284 u32 encap_fib_index, decap_fib_index;
4285 u32 decap_next_index;
4287 ip4_main_t * im = &ip4_main;
4289 u32 sw_if_index = ~0;
4292 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4294 rv = VNET_API_ERROR_NO_SUCH_FIB;
4297 encap_fib_index = p[0];
4299 decap_next_index = ntohl(mp->decap_next_index);
4301 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4302 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4303 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4305 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4308 decap_fib_index = p[0];
4310 decap_fib_index = ntohl(mp->decap_vrf_id);
4313 memset (a, 0, sizeof (*a));
4315 a->is_add = mp->is_add;
4316 /* ip addresses sent in network byte order */
4317 a->src.as_u32 = ntohl(mp->src);
4318 a->dst.as_u32 = ntohl(mp->dst);
4319 a->encap_fib_index = encap_fib_index;
4320 a->decap_fib_index = decap_fib_index;
4321 a->decap_next_index = decap_next_index;
4322 a->ver_o_c = mp->ver_o_c;
4323 a->length = mp->length;
4324 a->md_type = mp->md_type;
4325 a->next_protocol = mp->next_protocol;
4326 a->spi_si = ntohl(mp->spi_si);
4327 a->c1 = ntohl(mp->c1);
4328 a->c2 = ntohl(mp->c2);
4329 a->c3 = ntohl(mp->c3);
4330 a->c4 = ntohl(mp->c4);
4332 for (i = 0; i < mp->tlv_len_in_words; i++)
4333 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4337 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4340 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4342 rmp->sw_if_index = ntohl (sw_if_index);
4347 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4348 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4350 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4352 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4353 u32 encap_fib_index, decap_fib_index;
4354 u32 decap_next_index;
4356 ip4_main_t * im = &ip4_main;
4358 u32 sw_if_index = ~0;
4361 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4363 rv = VNET_API_ERROR_NO_SUCH_FIB;
4366 encap_fib_index = p[0];
4368 decap_next_index = ntohl(mp->decap_next_index);
4370 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4371 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4372 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4374 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4377 decap_fib_index = p[0];
4379 decap_fib_index = ntohl(mp->decap_vrf_id);
4382 memset (a, 0, sizeof (*a));
4384 a->is_add = mp->is_add;
4385 /* ip addresses sent in network byte order */
4386 a->src.as_u32 = ntohl(mp->src);
4387 a->dst.as_u32 = ntohl(mp->dst);
4388 a->encap_fib_index = encap_fib_index;
4389 a->decap_fib_index = decap_fib_index;
4390 a->decap_next_index = decap_next_index;
4391 a->vni = ntohl(mp->vni);
4392 a->ver_o_c = mp->ver_o_c;
4393 a->length = mp->length;
4394 a->md_type = mp->md_type;
4395 a->next_protocol = mp->next_protocol;
4396 a->spi_si = ntohl(mp->spi_si);
4397 a->c1 = ntohl(mp->c1);
4398 a->c2 = ntohl(mp->c2);
4399 a->c3 = ntohl(mp->c3);
4400 a->c4 = ntohl(mp->c4);
4402 for (i = 0; i < mp->tlv_len_in_words; i++)
4403 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4407 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4410 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4412 rmp->sw_if_index = ntohl (sw_if_index);
4417 vl_api_lisp_gpe_add_del_tunnel_t_handler
4418 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4420 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4422 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4423 u32 encap_fib_index, decap_fib_index;
4424 u32 decap_next_index;
4426 ip4_main_t * im = &ip4_main;
4427 u32 sw_if_index = ~0;
4429 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4431 rv = VNET_API_ERROR_NO_SUCH_FIB;
4434 encap_fib_index = p[0];
4436 decap_next_index = ntohl(mp->decap_next_index);
4438 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4439 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4440 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4442 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4445 decap_fib_index = p[0];
4447 decap_fib_index = ntohl(mp->decap_vrf_id);
4450 memset (a, 0, sizeof (*a));
4452 a->is_add = mp->is_add;
4453 /* ip addresses sent in network byte order */
4454 a->src.as_u32 = mp->src;
4455 a->dst.as_u32 = mp->dst;
4456 a->encap_fib_index = encap_fib_index;
4457 a->decap_fib_index = decap_fib_index;
4458 a->decap_next_index = decap_next_index;
4459 a->flags = mp->flags;
4460 a->ver_res = mp->ver_res;
4462 a->next_protocol = mp->next_protocol;
4463 a->iid = clib_net_to_host_u32 (mp->iid);
4465 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4468 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4470 rmp->sw_if_index = ntohl (sw_if_index);
4475 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4477 vl_api_interface_name_renumber_reply_t * rmp;
4480 VALIDATE_SW_IF_INDEX(mp);
4482 rv = vnet_interface_name_renumber
4483 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4485 BAD_SW_IF_INDEX_LABEL;
4487 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4490 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4491 u32 sw_if_index, u32 address)
4493 vpe_api_main_t * am = &vpe_api_main;
4494 vlib_main_t * vm = am->vlib_main;
4495 vl_api_ip4_arp_event_t * event;
4496 static f64 arp_event_last_time;
4497 f64 now = vlib_time_now (vm);
4499 if (pool_is_free_index (am->arp_events, pool_index))
4502 event = pool_elt_at_index (am->arp_events, pool_index);
4503 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4504 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4505 } else { /* same mac */
4506 if ((sw_if_index == event->sw_if_index) &&
4508 /* for BD case, also check IP address with 10 sec timeout */
4509 ((address == event->address) &&
4510 ((now - arp_event_last_time) < 10.0))))
4514 arp_event_last_time = now;
4515 event->sw_if_index = sw_if_index;
4516 if (address) event->address = address;
4520 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4522 vpe_api_main_t * am = &vpe_api_main;
4524 if (pool_is_free_index (am->arp_events, pool_index))
4527 pool_put_index (am->arp_events, pool_index);
4532 vl_api_want_ip4_arp_events_t_handler
4533 (vl_api_want_ip4_arp_events_t * mp)
4535 vpe_api_main_t * am = &vpe_api_main;
4536 vnet_main_t * vnm = vnet_get_main();
4537 vl_api_want_ip4_arp_events_reply_t *rmp;
4538 vl_api_ip4_arp_event_t * event;
4541 if (mp->enable_disable) {
4542 pool_get (am->arp_events, event);
4543 memset (event, 0, sizeof (*event));
4545 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4546 event->client_index = mp->client_index;
4547 event->context = mp->context;
4548 event->address = mp->address;
4549 event->pid = mp->pid;
4551 rv = vnet_add_del_ip4_arp_change_event
4552 (vnm, arp_change_data_callback,
4554 &mp->address /* addr, in net byte order */,
4555 vpe_resolver_process_node.index,
4556 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4558 rv = vnet_add_del_ip4_arp_change_event
4559 (vnm, arp_change_delete_callback,
4561 &mp->address /* addr, in net byte order */,
4562 vpe_resolver_process_node.index,
4563 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
4565 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
4568 static void vl_api_input_acl_set_interface_t_handler
4569 (vl_api_input_acl_set_interface_t * mp)
4571 vlib_main_t *vm = vlib_get_main();
4572 vl_api_input_acl_set_interface_reply_t * rmp;
4574 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
4576 ip4_table_index = ntohl(mp->ip4_table_index);
4577 ip6_table_index = ntohl(mp->ip6_table_index);
4578 l2_table_index = ntohl(mp->l2_table_index);
4579 sw_if_index = ntohl(mp->sw_if_index);
4581 VALIDATE_SW_IF_INDEX(mp);
4583 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
4584 ip6_table_index, l2_table_index,
4587 BAD_SW_IF_INDEX_LABEL;
4589 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
4592 static void vl_api_ipsec_spd_add_del_t_handler
4593 (vl_api_ipsec_spd_add_del_t * mp)
4596 clib_warning ("unimplemented");
4599 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4600 vl_api_ipsec_spd_add_del_reply_t * rmp;
4604 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
4606 rv = VNET_API_ERROR_UNIMPLEMENTED;
4609 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
4613 static void vl_api_ipsec_interface_add_del_spd_t_handler
4614 (vl_api_ipsec_interface_add_del_spd_t * mp)
4616 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4617 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
4619 u32 sw_if_index __attribute__((unused));
4620 u32 spd_id __attribute__((unused));
4622 sw_if_index = ntohl(mp->sw_if_index);
4623 spd_id = ntohl(mp->spd_id);
4625 VALIDATE_SW_IF_INDEX(mp);
4628 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
4630 rv = VNET_API_ERROR_UNIMPLEMENTED;
4633 BAD_SW_IF_INDEX_LABEL;
4635 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
4638 static void vl_api_ipsec_spd_add_del_entry_t_handler
4639 (vl_api_ipsec_spd_add_del_entry_t * mp)
4641 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4642 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
4648 p.id = ntohl(mp->spd_id);
4649 p.priority = ntohl(mp->priority);
4650 p.is_outbound = mp->is_outbound;
4651 p.is_ipv6 = mp->is_ipv6;
4653 memcpy(&p.raddr.start, mp->remote_address_start, 16);
4654 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
4655 memcpy(&p.laddr.start, mp->local_address_start, 16);
4656 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
4658 p.protocol = mp->protocol;
4659 p.rport.start = ntohs(mp->remote_port_start);
4660 p.rport.stop = ntohs(mp->remote_port_stop);
4661 p.lport.start = ntohs(mp->local_port_start);
4662 p.lport.stop = ntohs(mp->local_port_stop);
4663 /* policy action resolve unsupported */
4664 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
4665 clib_warning("unsupported action: 'resolve'");
4666 rv = VNET_API_ERROR_UNIMPLEMENTED;
4669 p.policy = mp->policy;
4670 p.sa_id = ntohl(mp->sa_id);
4672 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4676 if (mp->is_ip_any) {
4678 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
4681 rv = VNET_API_ERROR_UNIMPLEMENTED;
4686 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
4689 static void vl_api_ipsec_sad_add_del_entry_t_handler
4690 (vl_api_ipsec_sad_add_del_entry_t * mp)
4692 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4693 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
4698 sa.id = ntohl(mp->sad_id);
4699 sa.spi = ntohl(mp->spi);
4700 /* security protocol AH unsupported */
4701 if (mp->protocol == IPSEC_PROTOCOL_AH) {
4702 clib_warning("unsupported security protocol 'AH'");
4703 rv = VNET_API_ERROR_UNIMPLEMENTED;
4706 sa.protocol = mp->protocol;
4707 /* check for unsupported crypto-alg */
4708 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
4709 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
4710 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
4711 mp->crypto_algorithm);
4712 rv = VNET_API_ERROR_UNIMPLEMENTED;
4715 sa.crypto_alg = mp->crypto_algorithm;
4716 sa.crypto_key_len = mp->crypto_key_length;
4717 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4718 /* check for unsupported integ-alg */
4719 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
4720 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
4721 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
4722 mp->integrity_algorithm);
4723 rv = VNET_API_ERROR_UNIMPLEMENTED;
4726 sa.integ_alg = mp->integrity_algorithm;
4727 sa.integ_key_len = mp->integrity_key_length;
4728 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4729 sa.use_esn = mp->use_extended_sequence_number;
4730 sa.is_tunnel = mp->is_tunnel;
4731 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
4732 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
4733 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
4735 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
4737 rv = VNET_API_ERROR_UNIMPLEMENTED;
4742 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
4745 vl_api_map_add_domain_t_handler
4746 (vl_api_map_add_domain_t * mp)
4748 vl_api_map_add_domain_reply_t * rmp;
4751 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
4752 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
4753 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
4754 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
4755 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
4757 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
4759 rmp->index = ntohl(index);
4764 vl_api_map_del_domain_t_handler
4765 (vl_api_map_del_domain_t * mp)
4767 vl_api_map_del_domain_reply_t * rmp;
4770 rv = map_delete_domain(ntohl(mp->index));
4772 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
4776 vl_api_map_add_del_rule_t_handler
4777 (vl_api_map_add_del_rule_t * mp)
4779 vl_api_map_del_domain_reply_t * rmp;
4782 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
4784 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
4788 vl_api_map_domain_dump_t_handler
4789 (vl_api_map_domain_dump_t * mp)
4791 vl_api_map_domain_details_t * rmp;
4792 map_main_t *mm = &map_main;
4794 unix_shared_memory_queue_t * q;
4796 if (pool_elts (mm->domains) == 0)
4799 q = vl_api_client_index_to_input_queue (mp->client_index);
4804 pool_foreach(d, mm->domains, ({
4805 rmp = vl_msg_api_alloc (sizeof (*rmp));
4806 memset (rmp, 0, sizeof (*rmp));
4807 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
4808 rmp->domain_index = htonl(d - mm->domains);
4809 rmp->ea_bits_len = d->ea_bits_len;
4810 rmp->psid_offset = d->psid_offset;
4811 rmp->psid_length = d->psid_length;
4812 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
4813 rmp->ip4_prefix_len = d->ip4_prefix_len;
4814 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
4815 rmp->ip6_prefix_len = d->ip6_prefix_len;
4816 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
4817 rmp->ip6_src_len = d->ip6_src_len;
4818 rmp->mtu = htons(d->mtu);
4819 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
4821 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4826 vl_api_map_rule_dump_t_handler
4827 (vl_api_map_rule_dump_t * mp)
4829 unix_shared_memory_queue_t * q;
4832 vl_api_map_rule_details_t * rmp;
4833 map_main_t *mm = &map_main;
4834 u32 domain_index = ntohl(mp->domain_index);
4837 if (pool_elts (mm->domains) == 0)
4840 d = pool_elt_at_index(mm->domains, domain_index);
4841 if (!d || !d->rules) {
4845 q = vl_api_client_index_to_input_queue (mp->client_index);
4850 for (i = 0; i < (0x1 << d->psid_length); i++) {
4852 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
4855 rmp = vl_msg_api_alloc(sizeof(*rmp));
4856 memset(rmp, 0, sizeof(*rmp));
4857 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
4858 rmp->psid = htons(i);
4859 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
4860 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4865 vl_api_map_summary_stats_t_handler (
4866 vl_api_map_summary_stats_t *mp)
4868 vl_api_map_summary_stats_reply_t *rmp;
4869 vlib_combined_counter_main_t *cm;
4872 u64 total_pkts[VLIB_N_RX_TX];
4873 u64 total_bytes[VLIB_N_RX_TX];
4874 map_main_t *mm = &map_main;
4875 unix_shared_memory_queue_t *q =
4876 vl_api_client_index_to_input_queue(mp->client_index);
4881 rmp = vl_msg_api_alloc (sizeof (*rmp));
4882 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
4883 rmp->context = mp->context;
4886 memset (total_pkts, 0, sizeof (total_pkts));
4887 memset (total_bytes, 0, sizeof (total_bytes));
4889 map_domain_counter_lock (mm);
4890 vec_foreach(cm, mm->domain_counters) {
4891 which = cm - mm->domain_counters;
4893 for (i = 0; i < vec_len(cm->maxi); i++) {
4894 vlib_get_combined_counter (cm, i, &v);
4895 total_pkts[which] += v.packets;
4896 total_bytes[which] += v.bytes;
4900 map_domain_counter_unlock (mm);
4902 /* Note: in HOST byte order! */
4903 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = total_pkts[MAP_DOMAIN_COUNTER_RX];
4904 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = total_bytes[MAP_DOMAIN_COUNTER_RX];
4905 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = total_pkts[MAP_DOMAIN_COUNTER_TX];
4906 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = total_bytes[MAP_DOMAIN_COUNTER_TX];
4907 rmp->total_bindings = pool_elts(mm->domains);
4908 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
4909 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK);
4910 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK);
4912 vl_msg_api_send_shmem(q, (u8 *)&rmp);
4915 static void vl_api_ipsec_sa_set_key_t_handler
4916 (vl_api_ipsec_sa_set_key_t * mp)
4918 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
4919 vl_api_ipsec_sa_set_key_reply_t *rmp;
4923 sa.id = ntohl(mp->sa_id);
4924 sa.crypto_key_len = mp->crypto_key_length;
4925 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
4926 sa.integ_key_len = mp->integrity_key_length;
4927 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
4929 rv = ipsec_set_sa_key(vm, &sa);
4931 rv = VNET_API_ERROR_UNIMPLEMENTED;
4934 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
4937 static void vl_api_cop_interface_enable_disable_t_handler
4938 (vl_api_cop_interface_enable_disable_t * mp)
4940 vl_api_cop_interface_enable_disable_reply_t * rmp;
4942 u32 sw_if_index = ntohl(mp->sw_if_index);
4945 VALIDATE_SW_IF_INDEX(mp);
4947 enable_disable = (int) mp->enable_disable;
4949 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
4951 BAD_SW_IF_INDEX_LABEL;
4953 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
4956 static void vl_api_cop_whitelist_enable_disable_t_handler
4957 (vl_api_cop_whitelist_enable_disable_t * mp)
4959 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
4960 cop_whitelist_enable_disable_args_t _a, *a=&_a;
4961 u32 sw_if_index = ntohl(mp->sw_if_index);
4964 VALIDATE_SW_IF_INDEX(mp);
4966 a->sw_if_index = sw_if_index;
4969 a->default_cop = mp->default_cop;
4970 a->fib_id = ntohl(mp->fib_id);
4972 rv = cop_whitelist_enable_disable (a);
4974 BAD_SW_IF_INDEX_LABEL;
4976 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
4979 static void vl_api_get_node_graph_t_handler
4980 (vl_api_get_node_graph_t * mp)
4984 api_main_t * am = &api_main;
4985 vlib_main_t * vm = vlib_get_main();
4987 vl_api_get_node_graph_reply_t * rmp;
4989 pthread_mutex_lock (&am->vlib_rp->mutex);
4990 oldheap = svm_push_data_heap (am->vlib_rp);
4993 * Keep the number of memcpy ops to a minimum (e.g. 1).
4994 * The current size of the serialized vector is
4995 * slightly under 4K.
4997 vec_validate (vector, 4095);
4998 vec_reset_length (vector);
5000 vector = vlib_node_serialize (&vm->node_main, vector);
5002 svm_pop_heap (oldheap);
5003 pthread_mutex_unlock (&am->vlib_rp->mutex);
5005 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5006 rmp->reply_in_shmem = (uword) vector);
5009 static void vl_api_trace_profile_add_t_handler
5010 (vl_api_trace_profile_add_t *mp)
5013 vl_api_trace_profile_add_reply_t * rmp;
5014 clib_error_t *error;
5016 /* Ignoring the profile id as currently a single profile
5018 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5019 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5020 mp->pow_enable, mp->trace_tsp,
5023 clib_error_report(error);
5024 rv = clib_error_get_code(error);
5027 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5030 static void vl_api_trace_profile_apply_t_handler
5031 (vl_api_trace_profile_apply_t *mp)
5034 vl_api_trace_profile_apply_reply_t * rmp;
5036 if (mp->enable != 0) {
5037 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5038 ntohl(mp->prefix_length),
5040 mp->trace_op == IOAM_HBYH_ADD,
5041 mp->trace_op == IOAM_HBYH_POP,
5042 mp->trace_op == IOAM_HBYH_MOD);
5044 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5046 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5049 static void vl_api_trace_profile_del_t_handler
5050 (vl_api_trace_profile_del_t *mp)
5053 vl_api_trace_profile_del_reply_t * rmp;
5054 clib_error_t *error;
5056 error = clear_ioam_rewrite_fn();
5058 clib_error_report(error);
5059 rv = clib_error_get_code(error);
5062 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5066 #define BOUNCE_HANDLER(nn) \
5067 static void vl_api_##nn##_t_handler ( \
5068 vl_api_##nn##_t *mp) \
5070 vpe_client_registration_t *reg; \
5071 vpe_api_main_t * vam = &vpe_api_main; \
5072 unix_shared_memory_queue_t * q; \
5074 /* One registration only... */ \
5075 pool_foreach(reg, vam->nn##_registrations, \
5077 q = vl_api_client_index_to_input_queue (reg->client_index); \
5080 * If the queue is stuffed, turf the msg and complain \
5081 * It's unlikely that the intended recipient is \
5082 * alive; avoid deadlock at all costs. \
5084 if (q->cursize == q->maxsize) { \
5085 clib_warning ("ERROR: receiver queue full, drop msg"); \
5086 vl_msg_api_free (mp); \
5089 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5093 vl_msg_api_free (mp); \
5096 BOUNCE_HANDLER(to_netconf_server);
5097 BOUNCE_HANDLER(from_netconf_server);
5098 BOUNCE_HANDLER(to_netconf_client);
5099 BOUNCE_HANDLER(from_netconf_client);
5103 * Add vpe's API message handlers to the table.
5104 * vlib has alread mapped shared memory and
5105 * added the client registration handlers.
5106 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5109 static clib_error_t *
5110 vpe_api_hookup (vlib_main_t *vm)
5112 api_main_t * am = &api_main;
5115 vl_msg_api_set_handlers(VL_API_##N, #n, \
5116 vl_api_##n##_t_handler, \
5118 vl_api_##n##_t_endian, \
5119 vl_api_##n##_t_print, \
5120 sizeof(vl_api_##n##_t), 1);
5121 foreach_vpe_api_msg;
5125 * Manually register the sr tunnel add del msg, so we trace
5126 * enough bytes to capture a typical segment list
5128 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5129 "sr_tunnel_add_del",
5130 vl_api_sr_tunnel_add_del_t_handler,
5132 vl_api_sr_tunnel_add_del_t_endian,
5133 vl_api_sr_tunnel_add_del_t_print,
5136 am->message_bounce [VL_API_FROM_NETCONF_SERVER] = 1;
5137 am->message_bounce [VL_API_TO_NETCONF_SERVER] = 1;
5138 am->message_bounce [VL_API_FROM_NETCONF_CLIENT] = 1;
5139 am->message_bounce [VL_API_TO_NETCONF_CLIENT] = 1;
5142 * Trace space for 8 MPLS encap labels, classifier mask+match
5144 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5145 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5146 += 5 * sizeof (u32x4);
5147 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5148 += 5 * sizeof (u32x4);
5149 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5150 += 16 * sizeof (u32);
5153 * trace space for 4 nsh-gre variable TLV words
5155 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5156 += 4 * sizeof (u32);
5159 * Thread-safe API messages
5161 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
5166 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5168 static clib_error_t *
5169 vpe_api_init (vlib_main_t *vm)
5171 vpe_api_main_t *am = &vpe_api_main;
5174 am->vnet_main = vnet_get_main();
5175 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5176 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5177 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5178 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5179 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5180 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5183 vl_set_memory_region_name ("/vpe-api");
5184 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5189 VLIB_INIT_FUNCTION(vpe_api_init);
5191 static clib_error_t *
5192 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5196 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5198 if (unformat (input, "prefix %s", &chroot_path))
5200 vec_add1 (chroot_path, 0);
5201 vl_set_memory_root_path ((char *)chroot_path);
5204 return clib_error_return (0, "unknown input `%U'",
5205 format_unformat_error, input);
5209 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5211 void * get_unformat_vnet_sw_interface (void)
5213 return (void *) &unformat_vnet_sw_interface;
5216 #undef vl_api_version
5217 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5218 #include <api/vpe.api.h>
5219 #undef vl_api_version
5221 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5223 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5224 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5225 clib_host_to_net_u32 (mp->api_versions[0]),
5232 static u8 * format_arp_event (u8 * s, va_list * args)
5234 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5236 s = format (s, "pid %d: %U", event->pid,
5237 format_ip4_address, &event->address);
5241 static clib_error_t *
5242 show_ip4_arp_events_fn (vlib_main_t * vm,
5243 unformat_input_t * input,
5244 vlib_cli_command_t * cmd)
5246 vpe_api_main_t * am = &vpe_api_main;
5247 vl_api_ip4_arp_event_t * event;
5249 if (pool_elts (am->arp_events) == 0) {
5250 vlib_cli_output (vm, "No active arp event registrations");
5254 pool_foreach (event, am->arp_events,
5256 vlib_cli_output (vm, "%U", format_arp_event, event);
5262 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5263 .path = "show arp event registrations",
5264 .function = show_ip4_arp_events_fn,
5265 .short_help = "Show arp event registrations",