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/lisp-cp/control.h>
72 #include <vnet/map/map.h>
73 #include <vnet/cop/cop.h>
74 #include <vnet/ip/ip6_hop_by_hop.h>
77 #undef __included_bihash_template_h__
78 #include <vnet/l2/l2_fib.h>
81 #include <vnet/ipsec/ipsec.h>
82 #include <vnet/ipsec/ikev2.h>
85 #include <vnet/devices/virtio/vhost-user.h>
88 #include <stats/stats.h>
91 #include <vnet/ethernet/ethernet.h>
92 #include <vnet/ethernet/arp_packet.h>
93 #include <vnet/interface.h>
95 #include <vnet/l2/l2_fib.h>
96 #include <vnet/l2/l2_bd.h>
97 #include <api/vpe_msg_enum.h>
100 #define f64_print(a,b)
102 #define vl_typedefs /* define message structures */
103 #include <api/vpe_all_api_h.h>
106 #define vl_endianfun /* define message structures */
107 #include <api/vpe_all_api_h.h>
110 /* instantiate all the print functions we know about */
111 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
113 #include <api/vpe_all_api_h.h>
116 #define REPLY_MACRO(t) \
118 unix_shared_memory_queue_t * q; \
119 rv = vl_msg_api_pd_handler (mp, rv); \
120 q = vl_api_client_index_to_input_queue (mp->client_index); \
124 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
125 rmp->_vl_msg_id = ntohs((t)); \
126 rmp->context = mp->context; \
127 rmp->retval = ntohl(rv); \
129 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
132 #define REPLY_MACRO2(t, body) \
134 unix_shared_memory_queue_t * q; \
135 rv = vl_msg_api_pd_handler (mp, rv); \
136 q = vl_api_client_index_to_input_queue (mp->client_index); \
140 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
141 rmp->_vl_msg_id = ntohs((t)); \
142 rmp->context = mp->context; \
143 rmp->retval = ntohl(rv); \
144 do {body;} while (0); \
145 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
148 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
150 #define VALIDATE_SW_IF_INDEX(mp) \
151 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
152 vnet_main_t *__vnm = vnet_get_main(); \
153 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
155 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
156 goto bad_sw_if_index; \
160 #define BAD_SW_IF_INDEX_LABEL \
166 #define VALIDATE_RX_SW_IF_INDEX(mp) \
167 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
168 vnet_main_t *__vnm = vnet_get_main(); \
169 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
170 __rx_sw_if_index)) { \
171 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
172 goto bad_rx_sw_if_index; \
176 #define BAD_RX_SW_IF_INDEX_LABEL \
178 bad_rx_sw_if_index: \
182 #define VALIDATE_TX_SW_IF_INDEX(mp) \
183 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
184 vnet_main_t *__vnm = vnet_get_main(); \
185 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
186 __tx_sw_if_index)) { \
187 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
188 goto bad_tx_sw_if_index; \
192 #define BAD_TX_SW_IF_INDEX_LABEL \
194 bad_tx_sw_if_index: \
200 #define VALIDATE_SW_IF_INDEX(mp)
201 #define BAD_SW_IF_INDEX_LABEL
202 #define VALIDATE_RX_SW_IF_INDEX(mp)
203 #define BAD_RX_SW_IF_INDEX_LABEL
204 #define VALIDATE_TX_SW_IF_INDEX(mp)
205 #define BAD_TX_SW_IF_INDEX_LABEL
207 #endif /* CLIB_DEBUG > 0 */
209 #define foreach_vpe_api_msg \
210 _(WANT_INTERFACE_EVENTS, want_interface_events) \
211 _(WANT_OAM_EVENTS, want_oam_events) \
212 _(OAM_ADD_DEL, oam_add_del) \
213 _(SW_INTERFACE_DUMP, sw_interface_dump) \
214 _(SW_INTERFACE_DETAILS, sw_interface_details) \
215 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
216 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
217 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
218 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
219 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
220 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
221 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
222 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
223 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
224 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
225 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
226 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
227 _(L2FIB_ADD_DEL, l2fib_add_del) \
228 _(L2_FLAGS, l2_flags) \
229 _(BRIDGE_FLAGS, bridge_flags) \
230 _(TAP_CONNECT, tap_connect) \
231 _(TAP_MODIFY, tap_modify) \
232 _(TAP_DELETE, tap_delete) \
233 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
234 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
235 _(CREATE_SUBIF, create_subif) \
236 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
237 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
238 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
239 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
240 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
241 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
242 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
243 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
244 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
245 _(RESET_FIB, reset_fib) \
246 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
247 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
248 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
249 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
250 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
251 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
252 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
253 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
254 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
255 sw_interface_ip6_set_link_local_address) \
256 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
257 _(CREATE_LOOPBACK, create_loopback) \
258 _(CONTROL_PING, control_ping) \
259 _(CLI_REQUEST, cli_request) \
260 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
261 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
262 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
263 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
264 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
265 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
266 _(GET_NODE_INDEX, get_node_index) \
267 _(ADD_NODE_NEXT, add_node_next) \
268 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
269 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
270 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
271 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
272 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
273 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
274 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
275 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
276 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
277 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
278 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
279 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
280 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
281 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
282 _(IP_ADDRESS_DUMP, ip_address_dump) \
283 _(IP_DUMP, ip_dump) \
284 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
285 _(SHOW_VERSION, show_version) \
286 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
287 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
288 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
289 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
290 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel) \
291 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
292 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
293 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
294 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
295 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
296 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
297 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
298 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
299 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
300 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
301 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
302 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
303 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
304 _(DELETE_LOOPBACK, delete_loopback) \
305 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
306 _(MAP_ADD_DOMAIN, map_add_domain) \
307 _(MAP_DEL_DOMAIN, map_del_domain) \
308 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
309 _(MAP_DOMAIN_DUMP, map_domain_dump) \
310 _(MAP_RULE_DUMP, map_rule_dump) \
311 _(MAP_SUMMARY_STATS, map_summary_stats) \
312 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
313 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
314 _(GET_NODE_GRAPH, get_node_graph) \
315 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
316 _(TRACE_PROFILE_ADD, trace_profile_add) \
317 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
318 _(TRACE_PROFILE_DEL, trace_profile_del) \
319 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
320 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
321 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
322 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
323 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
324 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
325 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
326 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
327 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
328 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
329 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump)
332 #define QUOTE(x) QUOTE_(x)
334 #define foreach_registration_hash \
335 _(interface_events) \
336 _(to_netconf_server) \
337 _(from_netconf_server) \
338 _(to_netconf_client) \
339 _(from_netconf_client) \
343 RESOLVE_IP4_ADD_DEL_ROUTE=1,
344 RESOLVE_IP6_ADD_DEL_ROUTE,
345 RESOLVE_MPLS_ETHERNET_ADD_DEL,
351 vl_api_ip_add_del_route_t r;
352 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
358 #define _(a) uword *a##_registration_hash; \
359 vpe_client_registration_t * a##_registrations;
360 foreach_registration_hash
363 /* notifications happen really early in the game */
364 u8 link_state_process_up;
366 /* ip4 pending route adds */
367 pending_route_t * pending_routes;
369 /* ip4 arp event registration pool */
370 vl_api_ip4_arp_event_t * arp_events;
373 vlib_main_t * vlib_main;
374 vnet_main_t * vnet_main;
377 static vlib_node_registration_t vpe_resolver_process_node;
378 static vpe_api_main_t vpe_api_main;
380 static void send_sw_interface_flags (vpe_api_main_t * am,
381 unix_shared_memory_queue_t *q,
382 vnet_sw_interface_t * swif);
383 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
384 unix_shared_memory_queue_t *q,
387 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
390 /* Clean up all registrations belonging to the indicated client */
391 int vl_api_memclnt_delete_callback (u32 client_index)
393 vpe_api_main_t * vam = &vpe_api_main;
394 vpe_client_registration_t *rp;
396 int stats_memclnt_delete_callback (u32 client_index);
398 stats_memclnt_delete_callback (client_index);
401 p = hash_get (vam->a##_registration_hash, client_index); \
403 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
404 pool_put (vam->a##_registrations, rp); \
405 hash_unset (vam->a##_registration_hash, client_index); \
407 foreach_registration_hash;
412 #define API_LINK_STATE_EVENT 1
413 #define API_ADMIN_UP_DOWN_EVENT 2
416 event_data_cmp (void * a1, void * a2)
421 return (word) e1[0] - (word) e2[0];
425 link_state_process (vlib_main_t * vm,
426 vlib_node_runtime_t * rt,
429 vpe_api_main_t * vam = &vpe_api_main;
430 vnet_main_t * vnm = vam->vnet_main;
431 vnet_sw_interface_t * swif;
432 uword * event_data = 0;
433 vpe_client_registration_t *reg;
435 u32 prev_sw_if_index;
436 unix_shared_memory_queue_t * q;
438 vam->link_state_process_up = 1;
441 vlib_process_wait_for_event (vm);
443 /* Unified list of changed link or admin state sw_if_indices */
444 vlib_process_get_events_with_type
445 (vm, &event_data, API_LINK_STATE_EVENT);
446 vlib_process_get_events_with_type
447 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
449 /* Sort, so we can eliminate duplicates */
450 vec_sort_with_function (event_data, event_data_cmp);
452 prev_sw_if_index = ~0;
454 for (i = 0; i < vec_len(event_data); i++) {
455 /* Only one message per swif */
456 if (prev_sw_if_index == event_data[i])
458 prev_sw_if_index = event_data[i];
460 pool_foreach(reg, vam->interface_events_registrations,
462 q = vl_api_client_index_to_input_queue (reg->client_index);
464 // sw_interface may be deleted already
465 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
468 swif = vnet_get_sw_interface (vnm, event_data[i]);
469 send_sw_interface_flags (vam, q, swif);
474 vec_reset_length (event_data);
480 static clib_error_t *
481 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
482 static clib_error_t *
483 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
485 VLIB_REGISTER_NODE (link_state_process_node,static) = {
486 .function = link_state_process,
487 .type = VLIB_NODE_TYPE_PROCESS,
488 .name = "vpe-link-state-process",
491 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
492 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
494 static clib_error_t *
495 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
497 vpe_api_main_t * vam = &vpe_api_main;
498 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
500 if (vam->link_state_process_up)
501 vlib_process_signal_event (vam->vlib_main,
502 link_state_process_node.index,
503 API_LINK_STATE_EVENT,
508 static clib_error_t *
509 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
511 vpe_api_main_t * vam = &vpe_api_main;
514 * Note: it's perfectly fair to set a subif admin up / admin down.
515 * Note the subtle distinction between this routine and the previous
518 if (vam->link_state_process_up)
519 vlib_process_signal_event (vam->vlib_main,
520 link_state_process_node.index,
521 API_ADMIN_UP_DOWN_EVENT,
526 #define pub_sub_handler(lca,UCA) \
527 static void vl_api_want_##lca##_t_handler ( \
528 vl_api_want_##lca##_t *mp) \
530 vpe_api_main_t *vam = &vpe_api_main; \
531 vpe_client_registration_t *rp; \
532 vl_api_want_##lca##_reply_t *rmp; \
536 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
538 if (mp->enable_disable) { \
539 clib_warning ("pid %d: already enabled...", mp->pid); \
540 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
543 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
544 pool_put (vam->lca##_registrations, rp); \
545 hash_unset (vam->lca##_registration_hash, \
550 if (mp->enable_disable == 0) { \
551 clib_warning ("pid %d: already disabled...", mp->pid); \
552 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
555 pool_get (vam->lca##_registrations, rp); \
556 rp->client_index = mp->client_index; \
557 rp->client_pid = mp->pid; \
558 hash_set (vam->lca##_registration_hash, rp->client_index, \
559 rp - vam->lca##_registrations); \
562 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
565 pub_sub_handler (interface_events,INTERFACE_EVENTS)
566 pub_sub_handler (oam_events,OAM_EVENTS)
568 #define RESOLUTION_EVENT 1
569 #define RESOLUTION_PENDING_EVENT 2
570 #define IP4_ARP_EVENT 3
572 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
573 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
574 static int mpls_ethernet_add_del_tunnel_2_t_handler
575 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
577 void handle_ip4_arp_event (u32 pool_index)
579 vpe_api_main_t * vam = &vpe_api_main;
580 vnet_main_t * vnm = vam->vnet_main;
581 vlib_main_t * vm = vam->vlib_main;
582 vl_api_ip4_arp_event_t * event;
583 vl_api_ip4_arp_event_t * mp;
584 unix_shared_memory_queue_t * q;
586 /* Client can cancel, die, etc. */
587 if (pool_is_free_index (vam->arp_events, pool_index))
590 event = pool_elt_at_index (vam->arp_events, pool_index);
592 q = vl_api_client_index_to_input_queue (event->client_index);
594 (void) vnet_add_del_ip4_arp_change_event
595 (vnm, arp_change_delete_callback,
596 event->pid, &event->address,
597 vpe_resolver_process_node.index, IP4_ARP_EVENT,
598 ~0 /* pool index, notused */, 0 /* is_add */);
602 if (q->cursize < q->maxsize) {
603 mp = vl_msg_api_alloc (sizeof (*mp));
604 clib_memcpy (mp, event, sizeof (*mp));
605 vl_msg_api_send_shmem (q, (u8 *)&mp);
607 static f64 last_time;
609 * Throttle syslog msgs.
610 * It's pretty tempting to just revoke the registration...
612 if (vlib_time_now (vm) > last_time + 10.0) {
613 clib_warning ("arp event for %U to pid %d: queue stuffed!",
614 format_ip4_address, &event->address, event->pid);
615 last_time = vlib_time_now(vm);
621 resolver_process (vlib_main_t * vm,
622 vlib_node_runtime_t * rt,
626 uword *event_data = 0;
628 vpe_api_main_t * vam = &vpe_api_main;
629 pending_route_t * pr;
630 vl_api_ip_add_del_route_t * adr;
631 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
632 u32 * resolution_failures = 0;
637 vlib_process_wait_for_event_or_clock (vm, timeout);
639 event_type = vlib_process_get_events (vm, &event_data);
641 switch (event_type) {
642 case RESOLUTION_PENDING_EVENT:
646 case RESOLUTION_EVENT:
647 for (i = 0; i < vec_len(event_data); i++) {
649 * Resolution events can occur long after the
650 * original request has timed out. $$$ add a cancel
653 if (pool_is_free_index (vam->pending_routes, event_data[i]))
656 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
660 switch (pr->resolve_type) {
661 case RESOLVE_IP4_ADD_DEL_ROUTE:
662 rv = ip4_add_del_route_t_handler (adr);
663 clib_warning ("resolver: add %U/%d via %U %s",
665 (ip4_address_t *)&(adr->dst_address),
666 adr->dst_address_length,
668 (ip4_address_t *)&(adr->next_hop_address),
669 (rv >= 0) ? "succeeded" : "failed");
672 case RESOLVE_IP6_ADD_DEL_ROUTE:
673 rv = ip6_add_del_route_t_handler (adr);
674 clib_warning ("resolver: add %U/%d via %U %s",
676 (ip6_address_t *)&(adr->dst_address),
677 adr->dst_address_length,
679 (ip6_address_t *)&(adr->next_hop_address),
680 (rv >= 0) ? "succeeded" : "failed");
683 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
684 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
685 clib_warning ("resolver: add mpls-o-e via %U %s",
687 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
688 (rv >= 0) ? "succeeded" : "failed");
692 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
694 pool_put (vam->pending_routes, pr);
699 for (i = 0; i < vec_len(event_data); i++)
700 handle_ip4_arp_event (event_data[i]);
703 case ~0: /* timeout, retry pending resolutions */
704 pool_foreach (pr, vam->pending_routes,
710 /* May fail, e.g. due to interface down */
711 switch (pr->resolve_type) {
712 case RESOLVE_IP4_ADD_DEL_ROUTE:
713 e = ip4_probe_neighbor
714 (vm, (ip4_address_t *)&(adr->next_hop_address),
715 ntohl(adr->next_hop_sw_if_index));
718 case RESOLVE_IP6_ADD_DEL_ROUTE:
719 e = ip6_probe_neighbor
720 (vm, (ip6_address_t *)&(adr->next_hop_address),
721 ntohl(adr->next_hop_sw_if_index));
724 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
726 e = ip4_probe_neighbor
728 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
729 pme->resolve_opaque);
733 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
737 clib_error_report (e);
739 adr->resolve_attempts = 1;
741 pme->resolve_attempts = 1;
745 adr->resolve_attempts -= 1;
746 if (adr->resolve_attempts == 0)
747 vec_add1 (resolution_failures,
748 pr - vam->pending_routes);
750 pme->resolve_attempts -= 1;
751 if (pme->resolve_attempts == 0)
752 vec_add1 (resolution_failures,
753 pr - vam->pending_routes);
757 for (i = 0; i < vec_len (resolution_failures); i++) {
758 pr = pool_elt_at_index (vam->pending_routes,
759 resolution_failures[i]);
763 switch (pr->resolve_type) {
764 case RESOLVE_IP4_ADD_DEL_ROUTE:
765 clib_warning ("resolver: add %U/%d via %U retry failure",
767 (ip4_address_t *)&(adr->dst_address),
768 adr->dst_address_length,
770 (ip4_address_t *)&(adr->next_hop_address));
773 case RESOLVE_IP6_ADD_DEL_ROUTE:
774 clib_warning ("resolver: add %U/%d via %U retry failure",
776 (ip6_address_t *)&(adr->dst_address),
777 adr->dst_address_length,
779 (ip6_address_t *)&(adr->next_hop_address));
782 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
783 clib_warning ("resolver: add mpls-o-e via %U retry failure",
785 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
789 clib_warning ("BUG");
791 pool_put(vam->pending_routes, pr);
793 vec_reset_length (resolution_failures);
796 if (pool_elts (vam->pending_routes) == 0)
798 vec_reset_length (event_data);
800 return 0; /* or not */
803 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
804 .function = resolver_process,
805 .type = VLIB_NODE_TYPE_PROCESS,
806 .name = "vpe-route-resolver-process",
809 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
811 ip4_main_t * im = &ip4_main;
812 ip_lookup_main_t * lm = &im->lookup_main;
813 vnet_classify_main_t * cm = &vnet_classify_main;
814 stats_main_t * sm = &stats_main;
815 ip4_add_del_route_args_t a;
816 ip4_address_t next_hop_address;
818 vpe_api_main_t * vam = &vpe_api_main;
819 vnet_main_t * vnm = vam->vnet_main;
820 vlib_main_t * vm = vlib_get_main();
821 pending_route_t * pr;
822 vl_api_ip_add_del_route_t * adr;
826 ip_adjacency_t *nh_adj, *add_adj = 0;
828 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
830 if (mp->create_vrf_if_needed) {
832 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
834 fib_index = f->index;
836 /* No such VRF, and we weren't asked to create one */
837 return VNET_API_ERROR_NO_SUCH_FIB;
843 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
844 ntohl(mp->next_hop_sw_if_index)))
845 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
847 clib_memcpy (next_hop_address.data, mp->next_hop_address,
848 sizeof (next_hop_address.data));
850 /* Arp for the next_hop if necessary */
851 if (mp->is_add && mp->resolve_if_needed) {
853 ip_adjacency_t * adj;
855 lookup_result = ip4_fib_lookup_with_table
856 (im, fib_index, &next_hop_address, 1 /* disable default route */);
858 adj = ip_get_adjacency (lm, lookup_result);
860 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
861 pool_get (vam->pending_routes, pr);
862 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
864 clib_memcpy (adr, mp, sizeof (*adr));
865 /* recursion block, "just in case" */
866 adr->resolve_if_needed = 0;
867 adr->resolve_attempts = ntohl(mp->resolve_attempts);
868 vnet_register_ip4_arp_resolution_event
869 (vnm, &next_hop_address, vpe_resolver_process_node.index,
870 RESOLUTION_EVENT, pr - vam->pending_routes);
872 vlib_process_signal_event
873 (vm, vpe_resolver_process_node.index,
874 RESOLUTION_PENDING_EVENT, 0 /* data */);
876 /* The interface may be down, etc. */
877 e = ip4_probe_neighbor
878 (vm, (ip4_address_t *)&(mp->next_hop_address),
879 ntohl(mp->next_hop_sw_if_index));
882 clib_error_report(e);
884 return VNET_API_ERROR_IN_PROGRESS;
888 if (mp->is_multipath) {
891 dslock (sm, 1 /* release hint */, 10 /* tag */);
894 flags = IP4_ROUTE_FLAG_ADD;
896 flags = IP4_ROUTE_FLAG_DEL;
899 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
901 ip4_add_del_route_next_hop (im, flags,
902 (ip4_address_t *) mp->dst_address,
903 (u32) mp->dst_address_length,
904 (ip4_address_t *) mp->next_hop_address,
905 ntohl(mp->next_hop_sw_if_index),
906 (u32) mp->next_hop_weight,
913 memset (&a, 0, sizeof (a));
914 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
916 a.dst_address_length = mp->dst_address_length;
918 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
919 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
920 a.table_index_or_table_id = fib_index;
925 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
927 dslock (sm, 1 /* release hint */, 2 /* tag */);
931 ai = lm->drop_adj_index;
932 else if (mp->is_local)
933 ai = lm->local_adj_index;
934 else if (mp->is_classify) {
936 memset(&cadj, 0, sizeof(cadj));
937 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
938 cadj.classify.table_index = ntohl(mp->classify_table_index);
939 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
941 return VNET_API_ERROR_NO_SUCH_TABLE;
943 vec_add1 (add_adj, cadj);
947 ai = ip4_fib_lookup_with_table
948 (im, fib_index, &next_hop_address,
949 1 /* disable default route */);
950 if (ai == lm->miss_adj_index) {
952 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
956 nh_adj = ip_get_adjacency (lm, ai);
957 vec_add1 (add_adj, nh_adj[0]);
958 if (mp->lookup_in_vrf) {
959 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
961 add_adj[0].explicit_fib_index = p[0];
965 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
969 ip_adjacency_t * adj;
970 int disable_default_route = 1;
972 /* Trying to delete the default route? */
973 if (a.dst_address.as_u32 == 0 &&
974 a.dst_address_length == 0)
975 disable_default_route = 0;
977 ai = ip4_fib_lookup_with_table
978 (im, fib_index, &a.dst_address, disable_default_route);
979 if (ai == lm->miss_adj_index) {
981 return VNET_API_ERROR_UNKNOWN_DESTINATION;
984 adj = ip_get_adjacency (lm, ai);
985 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
987 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
994 a.n_add_adj = vec_len(add_adj);
995 ip4_add_del_route (im, &a);
1003 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1005 ip6_main_t * im = &ip6_main;
1006 ip_lookup_main_t * lm = &im->lookup_main;
1007 vnet_main_t * vnm = vnet_get_main();
1008 vlib_main_t * vm = vlib_get_main();
1009 vpe_api_main_t * vam = &vpe_api_main;
1010 stats_main_t * sm = &stats_main;
1011 ip6_add_del_route_args_t a;
1012 ip6_address_t next_hop_address;
1013 pending_route_t * pr;
1014 vl_api_ip_add_del_route_t * adr;
1019 ip_adjacency_t * nh_adj, * add_adj = 0;
1022 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1025 if (mp->create_vrf_if_needed) {
1027 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1029 fib_index = f->index;
1031 /* No such VRF, and we weren't asked to create one */
1032 return VNET_API_ERROR_NO_SUCH_FIB;
1038 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1039 ntohl(mp->next_hop_sw_if_index)))
1040 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1042 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1043 sizeof (next_hop_address.as_u8));
1045 /* Arp for the next_hop if necessary */
1046 if (mp->is_add && mp->resolve_if_needed) {
1048 ip_adjacency_t * adj;
1050 lookup_result = ip6_fib_lookup_with_table
1051 (im, fib_index, &next_hop_address);
1053 adj = ip_get_adjacency (lm, lookup_result);
1055 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1056 pool_get (vam->pending_routes, pr);
1058 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1059 clib_memcpy (adr, mp, sizeof (*adr));
1060 /* recursion block, "just in case" */
1061 adr->resolve_if_needed = 0;
1062 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1063 vnet_register_ip6_neighbor_resolution_event
1064 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1065 RESOLUTION_EVENT, pr - vam->pending_routes);
1067 vlib_process_signal_event
1068 (vm, vpe_resolver_process_node.index,
1069 RESOLUTION_PENDING_EVENT, 0 /* data */);
1071 /* The interface may be down, etc. */
1072 e = ip6_probe_neighbor
1073 (vm, (ip6_address_t *)&(mp->next_hop_address),
1074 ntohl(mp->next_hop_sw_if_index));
1077 clib_error_report(e);
1079 return VNET_API_ERROR_IN_PROGRESS;
1083 if (mp->is_multipath) {
1086 dslock (sm, 1 /* release hint */, 11 /* tag */);
1089 flags = IP6_ROUTE_FLAG_ADD;
1091 flags = IP6_ROUTE_FLAG_DEL;
1094 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1096 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1097 (u32) mp->dst_address_length,
1098 (ip6_address_t *)mp->next_hop_address,
1099 ntohl(mp->next_hop_sw_if_index),
1100 (u32) mp->next_hop_weight,
1107 memset (&a, 0, sizeof (a));
1108 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1110 a.dst_address_length = mp->dst_address_length;
1112 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1113 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1114 a.table_index_or_table_id = fib_index;
1119 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1121 dslock (sm, 1 /* release hint */, 3 /* tag */);
1125 ai = lm->drop_adj_index;
1126 else if (mp->is_local)
1127 ai = lm->local_adj_index;
1129 ai = ip6_fib_lookup_with_table
1130 (im, fib_index, &next_hop_address);
1131 if (ai == lm->miss_adj_index) {
1133 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1137 nh_adj = ip_get_adjacency (lm, ai);
1138 vec_add1 (add_adj, nh_adj[0]);
1139 if (mp->lookup_in_vrf) {
1140 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1142 add_adj[0].explicit_fib_index = p[0];
1146 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1150 ip_adjacency_t * adj;
1152 ai = ip6_fib_lookup_with_table
1153 (im, fib_index, &a.dst_address);
1154 if (ai == lm->miss_adj_index) {
1156 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1158 adj = ip_get_adjacency (lm, ai);
1159 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1161 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1166 a.add_adj = add_adj;
1167 a.n_add_adj = vec_len(add_adj);
1168 ip6_add_del_route (im, &a);
1176 void vl_api_ip_add_del_route_t_handler (
1177 vl_api_ip_add_del_route_t *mp)
1179 vl_api_ip_add_del_route_reply_t * rmp;
1181 vnet_main_t * vnm = vnet_get_main();
1186 rv = ip6_add_del_route_t_handler (mp);
1188 rv = ip4_add_del_route_t_handler (mp);
1190 rv = (rv == 0) ? vnm->api_errno : rv;
1192 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1195 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1196 u32 sw_if_index, u8 *next_hop_addr)
1198 vl_api_ip_add_del_route_t mp;
1201 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1204 * Configure default IP route:
1205 * - ip route add 0.0.0.0/1 via <GW IP>
1206 * - ip route add 128.0.0.0/1 via <GW IP>
1208 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1210 mp.resolve_attempts = ~0;
1211 mp.resolve_if_needed = 1;
1213 mp.is_ipv6 = is_ipv6;
1214 mp.next_hop_weight = 1;
1216 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1219 rv = ip6_add_del_route_t_handler (&mp);
1222 mp.dst_address_length = 1;
1224 mp.dst_address[0] = 0;
1225 rv = ip4_add_del_route_t_handler (&mp);
1227 mp.dst_address[0] = 128;
1228 rv |= ip4_add_del_route_t_handler (&mp);
1232 clib_error_return (0, "failed to config default IP route");
1237 vl_api_sw_interface_add_del_address_t_handler
1238 (vl_api_sw_interface_add_del_address_t *mp)
1240 vlib_main_t *vm = vlib_get_main();
1241 vl_api_sw_interface_add_del_address_reply_t * rmp;
1245 VALIDATE_SW_IF_INDEX(mp);
1247 is_del = mp->is_add == 0;
1250 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1251 else if (mp->is_ipv6)
1252 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1253 (void *)mp->address,
1254 mp->address_length, is_del);
1256 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1257 (void *) mp->address,
1258 mp->address_length, is_del);
1260 BAD_SW_IF_INDEX_LABEL;
1262 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1266 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1269 u32 table_id = ntohl(mp->vrf_id);
1270 u32 sw_if_index = ntohl(mp->sw_if_index);
1271 vl_api_sw_interface_set_table_reply_t * rmp;
1272 stats_main_t * sm = &stats_main;
1274 VALIDATE_SW_IF_INDEX(mp);
1276 dslock (sm, 1 /* release hint */, 4 /* tag */);
1279 ip6_main_t * im = &ip6_main;
1281 find_ip6_fib_by_table_index_or_id (im, table_id,
1282 IP6_ROUTE_FLAG_TABLE_ID);
1284 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1285 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1287 rv = VNET_API_ERROR_NO_SUCH_FIB;
1290 ip4_main_t * im = &ip4_main;
1291 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1292 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1294 /* Truthfully this can't fail */
1296 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1297 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1299 rv = VNET_API_ERROR_NO_SUCH_FIB;
1304 BAD_SW_IF_INDEX_LABEL;
1306 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1310 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1312 vlib_main_t *vm = vlib_get_main();
1313 vl_api_sw_interface_set_vpath_reply_t * rmp;
1316 u32 sw_if_index = ntohl(mp->sw_if_index);
1317 ip4_main_t *ip4m = &ip4_main;
1318 ip6_main_t *ip6m = &ip6_main;
1319 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1320 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1321 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1322 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1323 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1324 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1326 VALIDATE_SW_IF_INDEX(mp);
1328 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1330 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1331 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1332 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1333 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1334 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1335 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1336 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1337 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1338 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1339 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1340 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1341 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1342 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1343 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1344 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1345 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1347 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1348 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1349 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1350 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1351 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1352 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1353 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1354 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1355 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1356 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1357 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1358 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1359 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1360 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1361 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1362 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1365 BAD_SW_IF_INDEX_LABEL;
1367 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1371 vl_api_sw_interface_set_l2_xconnect_t_handler (
1372 vl_api_sw_interface_set_l2_xconnect_t *mp)
1374 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1376 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1377 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1378 vlib_main_t *vm = vlib_get_main();
1379 vnet_main_t *vnm = vnet_get_main();
1381 VALIDATE_RX_SW_IF_INDEX(mp);
1384 VALIDATE_TX_SW_IF_INDEX(mp);
1385 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1386 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1388 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1391 BAD_RX_SW_IF_INDEX_LABEL;
1392 BAD_TX_SW_IF_INDEX_LABEL;
1394 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1398 vl_api_sw_interface_set_l2_bridge_t_handler (
1399 vl_api_sw_interface_set_l2_bridge_t *mp)
1401 bd_main_t * bdm = &bd_main;
1402 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1404 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1405 u32 bd_id = ntohl(mp->bd_id);
1409 vlib_main_t *vm = vlib_get_main();
1410 vnet_main_t *vnm = vnet_get_main();
1412 VALIDATE_RX_SW_IF_INDEX(mp);
1414 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1417 //VALIDATE_TX_SW_IF_INDEX(mp);
1418 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1419 rx_sw_if_index, bd_index, bvi, shg, 0);
1421 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1424 BAD_RX_SW_IF_INDEX_LABEL;
1426 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1430 vl_api_bridge_domain_add_del_t_handler (
1431 vl_api_bridge_domain_add_del_t *mp)
1433 vlib_main_t * vm = vlib_get_main ();
1434 bd_main_t * bdm = &bd_main;
1435 vl_api_bridge_domain_add_del_reply_t * rmp;
1437 u32 enable_flags = 0, disable_flags = 0;
1438 u32 bd_id = ntohl(mp->bd_id);
1442 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1445 enable_flags |= L2_FLOOD;
1447 disable_flags |= L2_FLOOD;
1450 enable_flags |= L2_UU_FLOOD;
1452 disable_flags |= L2_UU_FLOOD;
1455 enable_flags |= L2_FWD;
1457 disable_flags |= L2_FWD;
1460 enable_flags |= L2_ARP_TERM;
1462 disable_flags |= L2_ARP_TERM;
1465 enable_flags |= L2_LEARN;
1467 disable_flags |= L2_LEARN;
1470 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1473 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1476 rv = bd_delete_bd_index(bdm, bd_id);
1478 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1481 static void vl_api_bridge_domain_details_t_handler (
1482 vl_api_bridge_domain_details_t * mp)
1484 clib_warning ("BUG");
1487 static void vl_api_bridge_domain_sw_if_details_t_handler (
1488 vl_api_bridge_domain_sw_if_details_t * mp)
1490 clib_warning ("BUG");
1493 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1494 l2_bridge_domain_t * bd_config,
1497 vl_api_bridge_domain_details_t * mp;
1499 mp = vl_msg_api_alloc (sizeof (*mp));
1500 memset (mp, 0, sizeof (*mp));
1501 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1502 mp->bd_id = ntohl (bd_config->bd_id);
1503 mp->flood = bd_feature_flood (bd_config);
1504 mp->uu_flood = bd_feature_uu_flood (bd_config);
1505 mp->forward = bd_feature_forward (bd_config);
1506 mp->learn = bd_feature_learn (bd_config);
1507 mp->arp_term = bd_feature_arp_term (bd_config);
1508 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1509 mp->n_sw_ifs = ntohl (n_sw_ifs);
1511 vl_msg_api_send_shmem (q, (u8 *)&mp);
1514 static void send_bd_sw_if_details (l2input_main_t * l2im,
1515 unix_shared_memory_queue_t *q,
1516 l2_flood_member_t * member, u32 bd_id)
1518 vl_api_bridge_domain_sw_if_details_t * mp;
1519 l2_input_config_t * input_cfg;
1521 mp = vl_msg_api_alloc (sizeof (*mp));
1522 memset (mp, 0, sizeof (*mp));
1523 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1524 mp->bd_id = ntohl (bd_id);
1525 mp->sw_if_index = ntohl (member->sw_if_index);
1526 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1527 mp->shg = input_cfg->shg;
1529 vl_msg_api_send_shmem (q, (u8 *)&mp);
1532 static void vl_api_bridge_domain_dump_t_handler (
1533 vl_api_bridge_domain_dump_t *mp)
1535 bd_main_t * bdm = &bd_main;
1536 l2input_main_t * l2im = &l2input_main;
1537 unix_shared_memory_queue_t * q;
1538 l2_bridge_domain_t * bd_config;
1539 u32 bd_id, bd_index;
1542 q = vl_api_client_index_to_input_queue (mp->client_index);
1547 bd_id = ntohl(mp->bd_id);
1549 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1550 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1551 for (; bd_index < end; bd_index++) {
1552 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1553 /* skip dummy bd_id 0 */
1554 if (bd_config && (bd_config->bd_id > 0)) {
1556 l2_flood_member_t * m;
1558 n_sw_ifs = vec_len (bd_config->members);
1559 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1561 vec_foreach (m, bd_config->members) {
1562 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1569 vl_api_l2fib_add_del_t_handler (
1570 vl_api_l2fib_add_del_t *mp)
1572 bd_main_t * bdm = &bd_main;
1573 l2input_main_t * l2im = &l2input_main;
1574 vl_api_l2fib_add_del_reply_t * rmp;
1577 u32 sw_if_index = ntohl(mp->sw_if_index);
1578 u32 bd_id = ntohl(mp->bd_id);
1586 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1588 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1589 goto bad_sw_if_index;
1594 VALIDATE_SW_IF_INDEX(mp);
1595 if (vec_len(l2im->configs) <= sw_if_index) {
1596 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1597 goto bad_sw_if_index;
1599 l2_input_config_t * config;
1600 config = vec_elt_at_index(l2im->configs, sw_if_index);
1601 if (config->bridge == 0) {
1602 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1603 goto bad_sw_if_index;
1606 static_mac = mp->static_mac ? 1 : 0;
1607 filter_mac = mp->filter_mac ? 1 : 0;
1608 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1611 l2fib_del_entry(mac, bd_index);
1614 BAD_SW_IF_INDEX_LABEL;
1616 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1620 vl_api_l2_flags_t_handler (
1621 vl_api_l2_flags_t *mp)
1623 vl_api_l2_flags_reply_t * rmp;
1625 u32 sw_if_index = ntohl(mp->sw_if_index);
1626 u32 flags = ntohl(mp->feature_bitmap);
1629 VALIDATE_SW_IF_INDEX(mp);
1632 if (flags & L2INPUT_FEAT_ ## a) \
1633 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1634 foreach_l2input_feat;
1637 BAD_SW_IF_INDEX_LABEL;
1639 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1643 vl_api_bridge_flags_t_handler (
1644 vl_api_bridge_flags_t *mp)
1646 vlib_main_t *vm = vlib_get_main();
1647 bd_main_t * bdm = &bd_main;
1648 vl_api_bridge_flags_reply_t * rmp;
1650 u32 bd_id = ntohl(mp->bd_id);
1652 u32 flags = ntohl(mp->feature_bitmap);
1655 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1657 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1663 bd_set_flags(vm, bd_index, flags, mp->is_set);
1666 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1667 rmp->resulting_feature_bitmap = ntohl(flags));
1671 vl_api_bd_ip_mac_add_del_t_handler (
1672 vl_api_bd_ip_mac_add_del_t *mp)
1674 bd_main_t * bdm = &bd_main;
1675 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1677 u32 bd_id = ntohl(mp->bd_id);
1681 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1683 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1688 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1689 mp->mac_address, mp->is_ipv6, mp->is_add))
1690 rv = VNET_API_ERROR_UNSPECIFIED;
1693 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1697 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1700 vl_api_tap_connect_reply_t * rmp;
1701 unix_shared_memory_queue_t * q;
1702 u32 sw_if_index = (u32)~0;
1704 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1705 mp->use_random_mac ? 0 : mp->mac_address,
1706 &sw_if_index, mp->renumber,
1707 ntohl(mp->custom_dev_instance));
1709 q = vl_api_client_index_to_input_queue (mp->client_index);
1713 rmp = vl_msg_api_alloc (sizeof (*rmp));
1714 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1715 rmp->context = mp->context;
1716 rmp->retval = ntohl(rv);
1717 rmp->sw_if_index = ntohl(sw_if_index);
1719 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1723 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1726 vl_api_tap_modify_reply_t * rmp;
1727 unix_shared_memory_queue_t * q;
1728 u32 sw_if_index = (u32)~0;
1730 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1731 mp->use_random_mac ? 0 : mp->mac_address,
1732 &sw_if_index, mp->renumber,
1733 ntohl(mp->custom_dev_instance));
1735 q = vl_api_client_index_to_input_queue (mp->client_index);
1739 rmp = vl_msg_api_alloc (sizeof (*rmp));
1740 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1741 rmp->context = mp->context;
1742 rmp->retval = ntohl(rv);
1743 rmp->sw_if_index = ntohl(sw_if_index);
1745 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1749 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1752 vpe_api_main_t * vam = &vpe_api_main;
1753 vl_api_tap_delete_reply_t * rmp;
1754 unix_shared_memory_queue_t * q;
1755 u32 sw_if_index = ntohl(mp->sw_if_index);
1757 rv = vnet_tap_delete (vm, sw_if_index);
1759 q = vl_api_client_index_to_input_queue (mp->client_index);
1763 rmp = vl_msg_api_alloc (sizeof (*rmp));
1764 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1765 rmp->context = mp->context;
1766 rmp->retval = ntohl(rv);
1768 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1771 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1775 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1777 vl_api_create_vlan_subif_reply_t * rmp;
1778 vnet_main_t * vnm = vnet_get_main();
1779 u32 hw_if_index, sw_if_index = (u32)~0;
1780 vnet_hw_interface_t * hi;
1783 vnet_sw_interface_t template;
1785 vnet_interface_main_t * im = &vnm->interface_main;
1786 u64 sup_and_sub_key;
1788 unix_shared_memory_queue_t * q;
1789 clib_error_t * error;
1791 VALIDATE_SW_IF_INDEX(mp);
1793 hw_if_index = ntohl(mp->sw_if_index);
1794 hi = vnet_get_hw_interface (vnm, hw_if_index);
1796 id = ntohl(mp->vlan_id);
1797 if (id == 0 || id > 4095) {
1798 rv = VNET_API_ERROR_INVALID_VLAN;
1802 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1804 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1806 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1810 kp = clib_mem_alloc (sizeof (*kp));
1811 *kp = sup_and_sub_key;
1813 memset (&template, 0, sizeof (template));
1814 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1815 template.sup_sw_if_index = hi->sw_if_index;
1816 template.sub.id = id;
1817 template.sub.eth.raw_flags = 0;
1818 template.sub.eth.flags.one_tag = 1;
1819 template.sub.eth.outer_vlan_id = id;
1820 template.sub.eth.flags.exact_match = 1;
1822 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1824 clib_error_report(error);
1825 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1828 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1829 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1831 BAD_SW_IF_INDEX_LABEL;
1834 q = vl_api_client_index_to_input_queue (mp->client_index);
1838 rmp = vl_msg_api_alloc (sizeof (*rmp));
1839 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1840 rmp->context = mp->context;
1841 rmp->retval = ntohl(rv);
1842 rmp->sw_if_index = ntohl(sw_if_index);
1843 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1847 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1849 vl_api_create_subif_reply_t * rmp;
1850 vnet_main_t * vnm = vnet_get_main();
1851 u32 sw_if_index = ~0;
1854 vnet_sw_interface_t *si;
1855 vnet_hw_interface_t *hi;
1856 vnet_sw_interface_t template;
1858 vnet_interface_main_t * im = &vnm->interface_main;
1859 u64 sup_and_sub_key;
1861 clib_error_t * error;
1863 VALIDATE_SW_IF_INDEX(mp);
1865 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1866 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1868 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1869 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1873 sw_if_index = si->sw_if_index;
1874 sub_id = ntohl(mp->sub_id);
1876 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1878 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1881 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1882 sw_if_index, sub_id);
1883 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1887 kp = clib_mem_alloc (sizeof (*kp));
1888 *kp = sup_and_sub_key;
1890 memset (&template, 0, sizeof (template));
1891 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1892 template.sup_sw_if_index = sw_if_index;
1893 template.sub.id = sub_id;
1894 template.sub.eth.flags.no_tags = mp->no_tags;
1895 template.sub.eth.flags.one_tag = mp->one_tag;
1896 template.sub.eth.flags.two_tags = mp->two_tags;
1897 template.sub.eth.flags.dot1ad = mp->dot1ad;
1898 template.sub.eth.flags.exact_match = mp->exact_match;
1899 template.sub.eth.flags.default_sub = mp->default_sub;
1900 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1901 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1902 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1903 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1905 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1907 clib_error_report (error);
1908 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1912 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1913 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1915 BAD_SW_IF_INDEX_LABEL;
1919 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1921 rmp->sw_if_index = ntohl(sw_if_index);
1926 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1928 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1930 stats_main_t * sm = &stats_main;
1931 u32 tunnel_sw_if_index = ~0;
1933 dslock (sm, 1 /* release hint */, 5 /* tag */);
1935 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1936 (ip4_address_t *)(mp->dst_address),
1937 (ip4_address_t *)(mp->intfc_address),
1938 (u32)(mp->intfc_address_length),
1939 ntohl(mp->inner_vrf_id),
1940 ntohl(mp->outer_vrf_id),
1941 &tunnel_sw_if_index,
1946 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1948 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1953 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1954 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1956 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1958 stats_main_t * sm = &stats_main;
1959 u32 tunnel_sw_if_index;
1961 dslock (sm, 1 /* release hint */, 5 /* tag */);
1963 rv = vnet_mpls_ethernet_add_del_tunnel
1964 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1965 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1966 ntohl(mp->tx_sw_if_index),
1967 &tunnel_sw_if_index,
1973 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1975 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1980 * This piece of misery brought to you because the control-plane
1981 * can't figure out the tx interface + dst-mac address all by itself
1983 static int mpls_ethernet_add_del_tunnel_2_t_handler
1984 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1986 pending_route_t * pr;
1987 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1988 vnet_main_t * vnm = vnet_get_main();
1989 vlib_main_t * vm = vlib_get_main();
1990 stats_main_t * sm = &stats_main;
1991 vpe_api_main_t * vam = &vpe_api_main;
1992 u32 inner_fib_index, outer_fib_index;
1993 ip4_main_t * im = &ip4_main;
1994 ip_lookup_main_t * lm = &im->lookup_main;
1995 ip_adjacency_t * adj = 0;
1998 u8 * dst_mac_address;
2002 u32 tunnel_sw_if_index;
2004 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2006 return VNET_API_ERROR_NO_SUCH_FIB;
2008 outer_fib_index = p[0];
2011 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2013 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2015 inner_fib_index = p[0];
2017 if (inner_fib_index == outer_fib_index)
2018 return VNET_API_ERROR_INVALID_VALUE;
2020 lookup_result = ip4_fib_lookup_with_table
2021 (im, outer_fib_index,
2022 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2023 1 /* disable default route */);
2025 adj = ip_get_adjacency (lm, lookup_result);
2026 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2028 if (mp->is_add && mp->resolve_if_needed) {
2029 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2030 pool_get (vam->pending_routes, pr);
2031 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2033 clib_memcpy (pme, mp, sizeof (*pme));
2034 /* recursion block, "just in case" */
2035 pme->resolve_if_needed = 0;
2036 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2037 pme->resolve_opaque = tx_sw_if_index;
2038 vnet_register_ip4_arp_resolution_event
2040 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2041 vpe_resolver_process_node.index,
2042 RESOLUTION_EVENT, pr - vam->pending_routes);
2044 vlib_process_signal_event
2045 (vm, vpe_resolver_process_node.index,
2046 RESOLUTION_PENDING_EVENT, 0 /* data */);
2048 /* The interface may be down, etc. */
2049 e = ip4_probe_neighbor
2050 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2054 clib_error_report(e);
2056 return VNET_API_ERROR_IN_PROGRESS;
2060 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2061 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2064 vnet_rewrite_get_data_internal
2065 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2067 dslock (sm, 1 /* release hint */, 10 /* tag */);
2069 rv = vnet_mpls_ethernet_add_del_tunnel
2070 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2071 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2072 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2080 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2081 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2083 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2086 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2088 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2093 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2095 vl_api_mpls_add_del_encap_reply_t * rmp;
2097 static u32 * labels;
2100 vec_reset_length (labels);
2102 for (i = 0; i < mp->nlabels; i++)
2103 vec_add1 (labels, ntohl(mp->labels[i]));
2106 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2107 ntohl(mp->vrf_id), labels,
2108 ~0 /* policy_tunnel_index */,
2109 0 /* no_dst_hash */,
2113 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2117 vl_api_mpls_add_del_decap_t_handler
2118 (vl_api_mpls_add_del_decap_t *mp)
2120 vl_api_mpls_add_del_decap_reply_t * rmp;
2123 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2124 ntohl(mp->label), ntohl(mp->next_index),
2125 mp->s_bit, mp->is_add);
2127 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2131 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2133 vl_api_proxy_arp_add_del_reply_t * rmp;
2136 ip4_main_t * im = &ip4_main;
2137 stats_main_t * sm = &stats_main;
2138 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2139 ip4_address_t *hi_addr,
2140 u32 fib_index, int is_del);
2143 dslock (sm, 1 /* release hint */, 6 /* tag */);
2145 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2148 rv = VNET_API_ERROR_NO_SUCH_FIB;
2154 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2155 (ip4_address_t *)mp->hi_address,
2156 fib_index, mp->is_add == 0);
2160 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2164 vl_api_proxy_arp_intfc_enable_disable_t_handler
2165 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2168 vnet_main_t * vnm = vnet_get_main();
2169 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2170 vnet_sw_interface_t * si;
2173 VALIDATE_SW_IF_INDEX(mp);
2175 sw_if_index = ntohl(mp->sw_if_index);
2177 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2179 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2183 si = vnet_get_sw_interface (vnm, sw_if_index);
2187 if (mp->enable_disable)
2188 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2190 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2192 BAD_SW_IF_INDEX_LABEL;
2195 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2199 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2201 vl_api_ip_neighbor_add_del_reply_t * rmp;
2202 vnet_main_t * vnm = vnet_get_main();
2205 stats_main_t * sm = &stats_main;
2207 VALIDATE_SW_IF_INDEX(mp);
2209 dslock (sm, 1 /* release hint */, 7 /* tag */);
2213 rv = vnet_set_ip6_ethernet_neighbor
2214 (vm, ntohl(mp->sw_if_index),
2215 (ip6_address_t *)(mp->dst_address),
2216 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2218 rv = vnet_unset_ip6_ethernet_neighbor
2219 (vm, ntohl(mp->sw_if_index),
2220 (ip6_address_t *)(mp->dst_address),
2221 mp->mac_address, sizeof(mp->mac_address));
2223 ip4_main_t * im = &ip4_main;
2224 ip_lookup_main_t * lm = &im->lookup_main;
2225 ethernet_arp_ip4_over_ethernet_address_t a;
2227 ip_adjacency_t *nh_adj;
2229 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2231 rv = VNET_API_ERROR_NO_SUCH_FIB;
2237 * Unfortunately, folks have a penchant for
2238 * adding interface addresses to the ARP cache, and
2239 * wondering why the forwarder eventually ASSERTs...
2241 ai = ip4_fib_lookup_with_table
2242 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2243 1 /* disable default route */);
2246 nh_adj = ip_get_adjacency (lm, ai);
2247 /* Never allow manipulation of a local adj! */
2248 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2249 clib_warning("%U matches local adj",
2251 (ip4_address_t *)(mp->dst_address));
2252 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2257 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2258 clib_memcpy (&a.ip4, mp->dst_address, 4);
2261 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2262 fib_index, &a, mp->is_static);
2264 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2268 BAD_SW_IF_INDEX_LABEL;
2271 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2275 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2278 vpe_main_t *rm = &vpe_main;
2279 ip4_main_t *im4 = &ip4_main;
2280 ip6_main_t *im6 = &ip6_main;
2281 ip_lookup_main_t * lm;
2286 u32 adj_index, sw_if_index;
2287 vl_api_is_address_reachable_t *rmp;
2288 ip_adjacency_t * adj;
2289 unix_shared_memory_queue_t *q;
2291 q = vl_api_client_index_to_input_queue (mp->client_index);
2293 increment_missing_api_client_counter (rm->vlib_main);
2297 rmp = vl_msg_api_alloc (sizeof (*rmp));
2298 clib_memcpy (rmp, mp, sizeof (*rmp));
2300 sw_if_index = mp->next_hop_sw_if_index;
2301 clib_memcpy (&addr, mp->address, sizeof (addr));
2303 lm = &im6->lookup_main;
2305 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2307 lm = &im4->lookup_main;
2309 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2311 if (adj_index == ~0) {
2315 adj = ip_get_adjacency (lm, adj_index);
2317 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2318 && adj->rewrite_header.sw_if_index == sw_if_index) {
2321 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2322 && adj->rewrite_header.sw_if_index == sw_if_index) {
2324 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2326 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2327 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2335 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2339 static void vl_api_sw_interface_details_t_handler (
2340 vl_api_sw_interface_details_t * mp)
2342 clib_warning ("BUG");
2345 static void vl_api_sw_interface_set_flags_t_handler (
2346 vl_api_sw_interface_set_flags_t * mp)
2348 vl_api_sw_interface_set_flags_reply_t *rmp;
2349 vnet_main_t * vnm = vnet_get_main();
2351 clib_error_t * error;
2354 VALIDATE_SW_IF_INDEX(mp);
2356 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2358 error = vnet_sw_interface_set_flags (vnm,
2359 ntohl(mp->sw_if_index),
2363 clib_error_report (error);
2366 BAD_SW_IF_INDEX_LABEL;
2367 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2370 static void vl_api_sw_interface_clear_stats_t_handler (
2371 vl_api_sw_interface_clear_stats_t * mp)
2373 vl_api_sw_interface_clear_stats_reply_t *rmp;
2375 vnet_main_t * vnm = vnet_get_main();
2376 vnet_interface_main_t * im = &vnm->interface_main;
2377 vlib_simple_counter_main_t * sm;
2378 vlib_combined_counter_main_t * cm;
2379 static vnet_main_t ** my_vnet_mains;
2380 int i, j, n_counters;
2384 vec_reset_length (my_vnet_mains);
2386 for (i = 0; i < vec_len (vnet_mains); i++)
2389 vec_add1 (my_vnet_mains, vnet_mains[i]);
2392 if (vec_len (vnet_mains) == 0)
2393 vec_add1 (my_vnet_mains, vnm);
2395 n_counters = vec_len (im->combined_sw_if_counters);
2397 for (j = 0; j < n_counters; j++)
2399 for (i = 0; i < vec_len(my_vnet_mains); i++)
2401 im = &my_vnet_mains[i]->interface_main;
2402 cm = im->combined_sw_if_counters + j;
2403 if (mp->sw_if_index == (u32)~0)
2404 vlib_clear_combined_counters (cm);
2406 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2410 n_counters = vec_len (im->sw_if_counters);
2412 for (j = 0; j < n_counters; j++)
2414 for (i = 0; i < vec_len(my_vnet_mains); i++)
2416 im = &my_vnet_mains[i]->interface_main;
2417 sm = im->sw_if_counters + j;
2418 if (mp->sw_if_index == (u32)~0)
2419 vlib_clear_simple_counters (sm);
2421 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2425 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2428 static void send_sw_interface_details (vpe_api_main_t * am,
2429 unix_shared_memory_queue_t *q,
2430 vnet_sw_interface_t * swif,
2431 u8 * interface_name,
2434 vl_api_sw_interface_details_t * mp;
2435 vnet_hw_interface_t * hi;
2437 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2439 mp = vl_msg_api_alloc (sizeof (*mp));
2440 memset (mp, 0, sizeof (*mp));
2441 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2442 mp->sw_if_index = ntohl(swif->sw_if_index);
2443 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2444 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2446 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2448 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2449 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2450 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2451 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2452 mp->link_mtu = ntohs(hi->max_packet_bytes);
2453 mp->context = context;
2455 strncpy ((char *) mp->interface_name,
2456 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2458 /* Send the L2 address for ethernet physical intfcs */
2459 if (swif->sup_sw_if_index == swif->sw_if_index
2460 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2461 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2462 ethernet_interface_t *ei;
2464 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2465 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2466 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2467 mp->l2_address_length = ntohl(sizeof (ei->address));
2468 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2469 vnet_sub_interface_t *sub = &swif->sub;
2470 mp->sub_id = ntohl(sub->id);
2471 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2472 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2473 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2474 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2475 mp->sub_exact_match = sub->eth.flags.exact_match;
2476 mp->sub_default = sub->eth.flags.default_sub;
2477 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2478 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2480 /* vlan tag rewrite data */
2481 u32 vtr_op = L2_VTR_DISABLED;
2482 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2484 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2485 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2486 // error - default to disabled
2487 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2488 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2491 mp->vtr_op = ntohl(vtr_op);
2492 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2493 mp->vtr_tag1 = ntohl(vtr_tag1);
2494 mp->vtr_tag2 = ntohl(vtr_tag2);
2498 vl_msg_api_send_shmem (q, (u8 *)&mp);
2501 static void send_sw_interface_flags (vpe_api_main_t * am,
2502 unix_shared_memory_queue_t *q,
2503 vnet_sw_interface_t * swif)
2505 vl_api_sw_interface_set_flags_t *mp;
2506 vnet_main_t * vnm = am->vnet_main;
2508 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2510 mp = vl_msg_api_alloc (sizeof (*mp));
2511 memset (mp, 0, sizeof (*mp));
2512 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2513 mp->sw_if_index = ntohl(swif->sw_if_index);
2515 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2517 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2519 vl_msg_api_send_shmem (q, (u8 *)&mp);
2522 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2523 unix_shared_memory_queue_t *q,
2525 __attribute__((unused));
2527 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2528 unix_shared_memory_queue_t *q,
2531 vl_api_sw_interface_set_flags_t *mp;
2533 mp = vl_msg_api_alloc (sizeof (*mp));
2534 memset (mp, 0, sizeof (*mp));
2535 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2536 mp->sw_if_index = ntohl(sw_if_index);
2538 mp->admin_up_down = 0;
2539 mp->link_up_down = 0;
2541 vl_msg_api_send_shmem (q, (u8 *)&mp);
2544 static void vl_api_sw_interface_dump_t_handler (
2545 vl_api_sw_interface_dump_t *mp)
2547 vpe_api_main_t * am = &vpe_api_main;
2548 vnet_sw_interface_t * swif;
2549 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2550 u8 * filter_string = 0, * name_string = 0;
2551 unix_shared_memory_queue_t * q;
2552 char * strcasestr (char *, char *); /* lnx hdr file botch */
2554 q = vl_api_client_index_to_input_queue (mp->client_index);
2559 if (mp->name_filter_valid) {
2560 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2561 filter_string = format (0, "%s%c", mp->name_filter, 0);
2564 pool_foreach (swif, im->sw_interfaces,
2566 name_string = format (name_string, "%U%c",
2567 format_vnet_sw_interface_name,
2568 am->vnet_main, swif, 0);
2570 if (mp->name_filter_valid == 0 ||
2571 strcasestr((char *) name_string, (char *) filter_string)) {
2573 send_sw_interface_details (am, q, swif, name_string, mp->context);
2574 send_sw_interface_flags (am, q, swif);
2576 _vec_len (name_string) = 0;
2579 vec_free (name_string);
2580 vec_free (filter_string);
2583 void send_oam_event (oam_target_t * t)
2585 vpe_api_main_t * vam = &vpe_api_main;
2586 unix_shared_memory_queue_t * q;
2587 vpe_client_registration_t *reg;
2588 vl_api_oam_event_t * mp;
2590 pool_foreach(reg, vam->oam_events_registrations,
2592 q = vl_api_client_index_to_input_queue (reg->client_index);
2594 mp = vl_msg_api_alloc (sizeof (*mp));
2595 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2596 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2597 mp->state = t->state;
2598 vl_msg_api_send_shmem (q, (u8 *)&mp);
2604 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2606 vl_api_oam_add_del_reply_t * rmp;
2609 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2610 (ip4_address_t *)mp->dst_address,
2614 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2618 vl_api_vnet_get_summary_stats_t_handler (
2619 vl_api_vnet_get_summary_stats_t *mp)
2621 stats_main_t * sm = &stats_main;
2622 vnet_interface_main_t * im = sm->interface_main;
2623 vl_api_vnet_summary_stats_reply_t *rmp;
2624 vlib_combined_counter_main_t * cm;
2627 u64 total_pkts[VLIB_N_RX_TX];
2628 u64 total_bytes[VLIB_N_RX_TX];
2630 unix_shared_memory_queue_t * q =
2631 vl_api_client_index_to_input_queue (mp->client_index);
2636 rmp = vl_msg_api_alloc (sizeof (*rmp));
2637 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2638 rmp->context = mp->context;
2641 memset (total_pkts, 0, sizeof (total_pkts));
2642 memset (total_bytes, 0, sizeof (total_bytes));
2644 vnet_interface_counter_lock (im);
2646 vec_foreach (cm, im->combined_sw_if_counters) {
2647 which = cm - im->combined_sw_if_counters;
2649 for (i = 0; i < vec_len (cm->maxi); i++) {
2650 vlib_get_combined_counter (cm, i, &v);
2651 total_pkts[which] += v.packets;
2652 total_bytes[which] += v.bytes;
2655 vnet_interface_counter_unlock (im);
2657 /* Note: in HOST byte order! */
2658 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2659 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2660 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2661 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2662 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2664 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2667 typedef CLIB_PACKED (struct {
2668 ip4_address_t address;
2670 u32 address_length : 6;
2675 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2677 vnet_main_t * vnm = vnet_get_main();
2678 vnet_interface_main_t * im = &vnm->interface_main;
2679 ip4_main_t * im4 = &ip4_main;
2680 static ip4_route_t * routes;
2681 static u32 * sw_if_indices_to_shut;
2682 stats_main_t * sm = &stats_main;
2687 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2688 u32 target_fib_id = ntohl(mp->vrf_id);
2690 dslock (sm, 1 /* release hint */, 8 /* tag */);
2692 vec_foreach (fib, im4->fibs) {
2693 vnet_sw_interface_t * si;
2695 if (fib->table_id != target_fib_id)
2698 /* remove any mpls/gre tunnels in this fib */
2699 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2701 /* remove any mpls encap/decap labels */
2702 mpls_fib_reset_labels (fib->table_id);
2704 /* remove any proxy arps in this fib */
2705 vnet_proxy_arp_fib_reset (fib->table_id);
2707 /* Set the flow hash for this fib to the default */
2708 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2710 vec_reset_length (sw_if_indices_to_shut);
2712 /* Shut down interfaces in this FIB / clean out intfc routes */
2713 pool_foreach (si, im->sw_interfaces,
2715 u32 sw_if_index = si->sw_if_index;
2717 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2718 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2720 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2723 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2724 sw_if_index = sw_if_indices_to_shut[i];
2725 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2727 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2728 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2729 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2732 vec_reset_length (routes);
2734 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2735 uword * hash = fib->adj_index_by_dst_address[i];
2739 x.address_length = i;
2741 hash_foreach_pair (p, hash,
2743 x.address.data_u32 = p->key;
2744 vec_add1 (routes, x);
2748 vec_foreach (r, routes) {
2749 ip4_add_del_route_args_t a;
2751 memset (&a, 0, sizeof (a));
2752 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2753 a.table_index_or_table_id = fib - im4->fibs;
2754 a.dst_address = r->address;
2755 a.dst_address_length = r->address_length;
2758 ip4_add_del_route (im4, &a);
2759 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2760 IP4_ROUTE_FLAG_FIB_INDEX);
2764 } /* vec_foreach (fib) */
2771 ip6_address_t address;
2778 ip6_route_t ** routep;
2779 } add_routes_in_fib_arg_t;
2781 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2783 add_routes_in_fib_arg_t * ap = arg;
2785 if (kvp->key[2]>>32 == ap->fib_index)
2787 ip6_address_t *addr;
2789 addr = (ip6_address_t *) kvp;
2790 vec_add2 (*ap->routep, r, 1);
2791 r->address = addr[0];
2792 r->address_length = kvp->key[2] & 0xFF;
2793 r->index = kvp->value;
2797 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2799 vnet_main_t * vnm = vnet_get_main();
2800 vnet_interface_main_t * im = &vnm->interface_main;
2801 ip6_main_t * im6 = &ip6_main;
2802 stats_main_t * sm = &stats_main;
2803 static ip6_route_t * routes;
2804 static u32 * sw_if_indices_to_shut;
2809 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2810 u32 target_fib_id = ntohl(mp->vrf_id);
2811 add_routes_in_fib_arg_t _a, *a=&_a;
2812 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2814 dslock (sm, 1 /* release hint */, 9 /* tag */);
2816 vec_foreach (fib, im6->fibs) {
2817 vnet_sw_interface_t * si;
2819 if (fib->table_id != target_fib_id)
2822 vec_reset_length (sw_if_indices_to_shut);
2824 /* Shut down interfaces in this FIB / clean out intfc routes */
2825 pool_foreach (si, im->sw_interfaces,
2827 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2829 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2832 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2833 sw_if_index = sw_if_indices_to_shut[i];
2834 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2836 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2837 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2838 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2841 vec_reset_length (routes);
2843 a->fib_index = fib - im6->fibs;
2844 a->routep = &routes;
2846 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2848 vec_foreach (r, routes) {
2849 ip6_add_del_route_args_t a;
2851 memset (&a, 0, sizeof (a));
2852 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2853 a.table_index_or_table_id = fib - im6->fibs;
2854 a.dst_address = r->address;
2855 a.dst_address_length = r->address_length;
2858 ip6_add_del_route (im6, &a);
2859 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2860 IP6_ROUTE_FLAG_FIB_INDEX);
2863 /* Reinstall the neighbor / router discovery routes */
2864 vnet_ip6_fib_init (im6, fib - im6->fibs);
2866 } /* vec_foreach (fib) */
2872 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2875 vl_api_reset_fib_reply_t * rmp;
2878 rv = ip6_reset_fib_t_handler (mp);
2880 rv = ip4_reset_fib_t_handler (mp);
2882 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2887 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2889 vl_api_dhcp_proxy_config_reply_t * rmp;
2892 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2893 (ip4_address_t *)(&mp->dhcp_src_address),
2894 (u32) ntohl(mp->vrf_id),
2895 (int) mp->insert_circuit_id,
2896 (int) (mp->is_add == 0));
2898 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2903 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2905 vl_api_dhcp_proxy_config_reply_t * rmp;
2908 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2909 (ip6_address_t *)(&mp->dhcp_src_address),
2910 (u32) ntohl(mp->vrf_id),
2911 (int) mp->insert_circuit_id,
2912 (int) (mp->is_add == 0));
2914 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2918 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2920 vl_api_dhcp_proxy_config_reply_t * rmp;
2923 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2924 (ip4_address_t *)(&mp->dhcp_src_address),
2925 (u32) ntohl(mp->rx_vrf_id),
2926 (u32) ntohl(mp->server_vrf_id),
2927 (int) mp->insert_circuit_id,
2928 (int) (mp->is_add == 0));
2930 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2935 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2937 vl_api_dhcp_proxy_config_reply_t * rmp;
2941 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2942 (ip6_address_t *)(&mp->dhcp_src_address),
2943 (u32) ntohl(mp->rx_vrf_id),
2944 (u32) ntohl(mp->server_vrf_id),
2945 (int) mp->insert_circuit_id,
2946 (int) (mp->is_add == 0));
2948 rv = VNET_API_ERROR_UNIMPLEMENTED;
2951 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2956 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2958 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2961 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2964 (int)mp->is_add == 0);
2966 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2969 (int)mp->is_add == 0);
2971 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2975 static void vl_api_dhcp_proxy_config_t_handler
2976 (vl_api_dhcp_proxy_config_t *mp)
2978 if (mp->is_ipv6 == 0)
2979 dhcpv4_proxy_config (mp);
2981 dhcpv6_proxy_config (mp);
2984 static void vl_api_dhcp_proxy_config_2_t_handler
2985 (vl_api_dhcp_proxy_config_2_t *mp)
2987 if (mp->is_ipv6 == 0)
2988 dhcpv4_proxy_config_2 (mp);
2990 dhcpv6_proxy_config_2 (mp);
2993 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2994 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2996 unix_shared_memory_queue_t * q;
2997 vl_api_dhcp_compl_event_t * mp;
2999 q = vl_api_client_index_to_input_queue (client_index);
3003 mp = vl_msg_api_alloc (sizeof (*mp));
3004 mp->client_index = client_index;
3006 mp->is_ipv6 = is_ipv6;
3007 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3008 mp->hostname[vec_len(hostname) + 1] = '\n';
3009 clib_memcpy (&mp->host_address[0], host_address, 16);
3010 clib_memcpy (&mp->router_address[0], router_address, 16);
3011 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3013 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3015 vl_msg_api_send_shmem (q, (u8 *)&mp);
3018 static void vl_api_dhcp_client_config_t_handler
3019 (vl_api_dhcp_client_config_t *mp)
3021 vlib_main_t *vm = vlib_get_main();
3022 vl_api_dhcp_client_config_reply_t * rmp;
3025 VALIDATE_SW_IF_INDEX(mp);
3027 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3028 mp->hostname, mp->is_add, mp->client_index,
3029 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3032 BAD_SW_IF_INDEX_LABEL;
3034 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3038 vl_api_sw_interface_ip6nd_ra_config_t_handler
3039 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3041 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3043 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3045 is_no = mp->is_no == 1;
3046 surpress = mp->surpress == 1;
3047 managed = mp->managed == 1;
3048 other = mp->other == 1;
3049 ll_option = mp->ll_option == 1;
3050 send_unicast = mp->send_unicast == 1;
3051 cease = mp->cease == 1;
3052 default_router = mp->default_router == 1;
3054 VALIDATE_SW_IF_INDEX(mp);
3056 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3057 surpress, managed, other,
3058 ll_option, send_unicast, cease,
3059 default_router, ntohl (mp->lifetime),
3060 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3061 ntohl(mp->max_interval), ntohl( mp->min_interval),
3064 BAD_SW_IF_INDEX_LABEL;
3066 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3070 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3071 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3073 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3075 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3077 VALIDATE_SW_IF_INDEX(mp);
3079 is_no = mp->is_no == 1;
3080 use_default = mp->use_default == 1;
3081 no_advertise = mp->no_advertise == 1;
3082 off_link = mp->off_link == 1;
3083 no_autoconfig = mp->no_autoconfig == 1;
3084 no_onlink = mp->no_onlink == 1;
3086 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3087 (ip6_address_t *)mp->address, mp->address_length,
3088 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3089 no_advertise, off_link, no_autoconfig, no_onlink,
3092 BAD_SW_IF_INDEX_LABEL;
3093 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3097 vl_api_sw_interface_ip6_enable_disable_t_handler
3098 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3100 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3101 vnet_main_t * vnm = vnet_get_main();
3103 clib_error_t * error;
3107 VALIDATE_SW_IF_INDEX(mp);
3109 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3110 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3113 clib_error_report(error);
3114 rv = VNET_API_ERROR_UNSPECIFIED;
3116 rv = vnm->api_errno;
3119 BAD_SW_IF_INDEX_LABEL;
3121 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3125 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3126 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3128 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3130 clib_error_t * error;
3131 vnet_main_t * vnm = vnet_get_main();
3135 VALIDATE_SW_IF_INDEX(mp);
3137 error = set_ip6_link_local_address(vm,
3138 ntohl(mp->sw_if_index),
3139 (ip6_address_t *)mp->address,
3140 mp->address_length);
3142 clib_error_report(error);
3143 rv = VNET_API_ERROR_UNSPECIFIED;
3145 rv = vnm->api_errno;
3148 BAD_SW_IF_INDEX_LABEL;
3150 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3153 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3155 vl_api_set_ip_flow_hash_reply_t *rmp;
3156 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3158 clib_warning ("unimplemented...");
3160 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3163 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3165 vl_api_set_ip_flow_hash_reply_t *rmp;
3168 u32 flow_hash_config = 0;
3170 table_id = ntohl(mp->vrf_id);
3172 #define _(a,b) if (mp->a) flow_hash_config |= b;
3173 foreach_flow_hash_bit;
3176 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3178 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3182 static void vl_api_set_ip_flow_hash_t_handler
3183 (vl_api_set_ip_flow_hash_t *mp)
3185 if (mp->is_ipv6 == 0)
3186 set_ip4_flow_hash (mp);
3188 set_ip6_flow_hash (mp);
3191 static void vl_api_sw_interface_set_unnumbered_t_handler
3192 (vl_api_sw_interface_set_unnumbered_t *mp)
3194 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3196 vnet_sw_interface_t * si;
3197 vnet_main_t *vnm = vnet_get_main();
3198 u32 sw_if_index, unnumbered_sw_if_index;
3200 sw_if_index = ntohl(mp->sw_if_index);
3201 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3204 * The API message field names are backwards from
3205 * the underlying data structure names.
3206 * It's not worth changing them now.
3208 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3209 unnumbered_sw_if_index)) {
3210 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3214 /* Only check the "use loop0" field when setting the binding */
3216 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3217 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3221 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3224 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3225 si->unnumbered_sw_if_index = sw_if_index;
3227 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3228 si->unnumbered_sw_if_index = (u32)~0;
3232 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3235 static void vl_api_create_loopback_t_handler
3236 (vl_api_create_loopback_t *mp)
3238 vl_api_create_loopback_reply_t * rmp;
3242 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3244 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3246 rmp->sw_if_index = ntohl (sw_if_index);
3250 static void vl_api_delete_loopback_t_handler
3251 (vl_api_delete_loopback_t *mp)
3253 vl_api_delete_loopback_reply_t * rmp;
3257 sw_if_index = ntohl (mp->sw_if_index);
3258 rv = vnet_delete_loopback_interface (sw_if_index);
3260 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3263 static void vl_api_control_ping_t_handler
3264 (vl_api_control_ping_t *mp)
3266 vl_api_control_ping_reply_t * rmp;
3269 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3271 rmp->vpe_pid = ntohl (getpid());
3275 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3277 u8 **shmem_vecp = (u8 **)arg;
3280 api_main_t * am = &api_main;
3283 shmem_vec = *shmem_vecp;
3285 offset = vec_len (shmem_vec);
3287 pthread_mutex_lock (&am->vlib_rp->mutex);
3288 oldheap = svm_push_data_heap (am->vlib_rp);
3290 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3292 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3294 svm_pop_heap (oldheap);
3295 pthread_mutex_unlock (&am->vlib_rp->mutex);
3297 *shmem_vecp = shmem_vec;
3301 static void vl_api_cli_request_t_handler
3302 (vl_api_cli_request_t *mp)
3304 vl_api_cli_reply_t *rp;
3305 unix_shared_memory_queue_t *q;
3306 vlib_main_t * vm = vlib_get_main();
3307 api_main_t * am = &api_main;
3308 unformat_input_t input;
3312 q = vl_api_client_index_to_input_queue (mp->client_index);
3316 rp = vl_msg_api_alloc (sizeof (*rp));
3317 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3318 rp->context = mp->context;
3320 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3322 vlib_cli_input (vm, &input, shmem_cli_output,
3325 pthread_mutex_lock (&am->vlib_rp->mutex);
3326 oldheap = svm_push_data_heap (am->vlib_rp);
3328 vec_add1(shmem_vec, 0);
3330 svm_pop_heap (oldheap);
3331 pthread_mutex_unlock (&am->vlib_rp->mutex);
3333 rp->reply_in_shmem = (uword)shmem_vec;
3335 vl_msg_api_send_shmem (q, (u8 *)&rp);
3338 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3341 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3342 vnet_main_t *vnm = vnet_get_main();
3343 clib_error_t * error;
3348 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3350 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3353 clib_error_report(error);
3354 rv = VNET_API_ERROR_UNSPECIFIED;
3356 rv = vnm->api_errno;
3359 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3362 static void vl_api_sr_tunnel_add_del_t_handler
3363 (vl_api_sr_tunnel_add_del_t *mp)
3366 clib_warning ("unimplemented");
3368 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3370 vl_api_sr_tunnel_add_del_reply_t * rmp;
3371 ip6_address_t * segments = 0, * seg;
3372 ip6_address_t * tags = 0, *tag;
3373 ip6_address_t * this_address;
3376 if (mp->n_segments == 0) {
3381 memset (a, 0, sizeof (*a));
3382 a->src_address = (ip6_address_t *)&mp->src_address;
3383 a->dst_address = (ip6_address_t *)&mp->dst_address;
3384 a->dst_mask_width = mp->dst_mask_width;
3385 a->flags_net_byte_order = mp->flags_net_byte_order;
3386 a->is_del = (mp->is_add == 0);
3387 a->rx_table_id = ntohl(mp->outer_vrf_id);
3388 a->tx_table_id = ntohl(mp->inner_vrf_id);
3390 /* Yank segments and tags out of the API message */
3391 this_address = (ip6_address_t *)mp->segs_and_tags;
3392 for (i = 0; i < mp->n_segments; i++) {
3393 vec_add2 (segments, seg, 1);
3394 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3397 for (i = 0; i < mp->n_tags; i++) {
3398 vec_add2 (tags, tag, 1);
3399 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3403 a->segments = segments;
3406 rv = ip6_sr_add_del_tunnel (a);
3410 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3414 #define foreach_classify_add_del_table_field \
3419 _(match_n_vectors) \
3420 _(next_table_index) \
3423 static void vl_api_classify_add_del_table_t_handler
3424 (vl_api_classify_add_del_table_t * mp)
3426 vl_api_classify_add_del_table_reply_t * rmp;
3427 vnet_classify_main_t * cm = &vnet_classify_main;
3428 vnet_classify_table_t * t;
3432 foreach_classify_add_del_table_field;
3435 #define _(a) a = ntohl(mp->a);
3436 foreach_classify_add_del_table_field;
3439 /* The underlying API fails silently, on purpose, so check here */
3440 if (mp->is_add == 0)
3441 if (pool_is_free_index (cm->tables, table_index)) {
3442 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3446 rv = vnet_classify_add_del_table
3447 (cm, mp->mask, nbuckets, memory_size,
3448 skip_n_vectors, match_n_vectors,
3449 next_table_index, miss_next_index,
3450 &table_index, mp->is_add);
3453 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3455 if (rv == 0 && mp->is_add) {
3456 t = pool_elt_at_index (cm->tables, table_index);
3457 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3458 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3459 rmp->new_table_index = ntohl(table_index);
3461 rmp->skip_n_vectors = ~0;
3462 rmp->match_n_vectors = ~0;
3463 rmp->new_table_index = ~0;
3468 static void vl_api_classify_add_del_session_t_handler
3469 (vl_api_classify_add_del_session_t * mp)
3471 vnet_classify_main_t * cm = &vnet_classify_main;
3472 vl_api_classify_add_del_session_reply_t * rmp;
3474 u32 table_index, hit_next_index, opaque_index;
3477 table_index = ntohl (mp->table_index);
3478 hit_next_index = ntohl (mp->hit_next_index);
3479 opaque_index = ntohl (mp->opaque_index);
3480 advance = ntohl (mp->advance);
3482 rv = vnet_classify_add_del_session
3483 (cm, table_index, mp->match, hit_next_index, opaque_index,
3484 advance, mp->is_add);
3486 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3489 static void vl_api_classify_set_interface_ip_table_t_handler
3490 (vl_api_classify_set_interface_ip_table_t * mp)
3492 vlib_main_t * vm = vlib_get_main();
3493 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3495 u32 table_index, sw_if_index;
3497 table_index = ntohl (mp->table_index);
3498 sw_if_index = ntohl (mp->sw_if_index);
3500 VALIDATE_SW_IF_INDEX(mp);
3503 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3505 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3507 BAD_SW_IF_INDEX_LABEL;
3509 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3512 static void vl_api_classify_set_interface_l2_tables_t_handler
3513 (vl_api_classify_set_interface_l2_tables_t * mp)
3515 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3517 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3520 ip4_table_index = ntohl(mp->ip4_table_index);
3521 ip6_table_index = ntohl(mp->ip6_table_index);
3522 other_table_index = ntohl(mp->other_table_index);
3523 sw_if_index = ntohl(mp->sw_if_index);
3525 VALIDATE_SW_IF_INDEX(mp);
3527 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3528 ip6_table_index, other_table_index);
3531 if (ip4_table_index != ~0 || ip6_table_index != ~0
3532 || other_table_index != ~0)
3537 vnet_l2_classify_enable_disable (sw_if_index, enable);
3540 BAD_SW_IF_INDEX_LABEL;
3542 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3546 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3549 vl_api_l2_fib_clear_table_reply_t * rmp;
3551 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3552 * that is not currently implemented. When that TODO is fixed
3553 * this call should be changed to pass 1 instead of 0.
3555 l2fib_clear_table (0);
3557 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3560 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3565 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3568 vl_api_l2_interface_efp_filter_reply_t * rmp;
3569 vnet_main_t *vnm = vnet_get_main();
3571 // enable/disable the feature
3572 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3573 rv = vnm->api_errno;
3575 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3579 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3582 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3583 vnet_main_t * vnm = vnet_get_main();
3584 vlib_main_t * vm = vlib_get_main();
3587 VALIDATE_SW_IF_INDEX(mp);
3589 vtr_op = ntohl(mp->vtr_op);
3591 /* The L2 code is unsuspicious */
3593 case L2_VTR_DISABLED:
3598 case L2_VTR_TRANSLATE_1_1:
3599 case L2_VTR_TRANSLATE_1_2:
3600 case L2_VTR_TRANSLATE_2_1:
3601 case L2_VTR_TRANSLATE_2_2:
3605 rv = VNET_API_ERROR_INVALID_VALUE;
3606 goto bad_sw_if_index;
3609 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3610 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3613 BAD_SW_IF_INDEX_LABEL;
3615 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3619 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3623 vl_api_create_vhost_user_if_reply_t * rmp;
3624 u32 sw_if_index = (u32)~0;
3626 vnet_main_t * vnm = vnet_get_main();
3627 vlib_main_t * vm = vlib_get_main();
3629 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3630 mp->is_server, &sw_if_index, (u64)~0,
3631 mp->renumber, ntohl(mp->custom_dev_instance),
3632 (mp->use_custom_mac)?mp->mac_address:NULL);
3634 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3636 rmp->sw_if_index = ntohl (sw_if_index);
3642 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3646 vl_api_modify_vhost_user_if_reply_t * rmp;
3647 u32 sw_if_index = ntohl(mp->sw_if_index);
3649 vnet_main_t * vnm = vnet_get_main();
3650 vlib_main_t * vm = vlib_get_main();
3652 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3653 mp->is_server, sw_if_index, (u64)~0,
3654 mp->renumber, ntohl(mp->custom_dev_instance));
3656 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3661 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3665 vpe_api_main_t * vam = &vpe_api_main;
3666 vl_api_delete_vhost_user_if_reply_t * rmp;
3667 u32 sw_if_index = ntohl(mp->sw_if_index);
3669 vnet_main_t * vnm = vnet_get_main();
3670 vlib_main_t * vm = vlib_get_main();
3672 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3674 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3676 unix_shared_memory_queue_t * q =
3677 vl_api_client_index_to_input_queue (mp->client_index);
3681 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3686 static void vl_api_sw_interface_vhost_user_details_t_handler (
3687 vl_api_sw_interface_vhost_user_details_t * mp)
3689 clib_warning ("BUG");
3693 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3694 unix_shared_memory_queue_t *q,
3695 vhost_user_intf_details_t * vui,
3698 vl_api_sw_interface_vhost_user_details_t * mp;
3700 mp = vl_msg_api_alloc (sizeof (*mp));
3701 memset (mp, 0, sizeof (*mp));
3702 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3703 mp->sw_if_index = ntohl(vui->sw_if_index);
3704 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3705 mp->features = clib_net_to_host_u64 (vui->features);
3706 mp->is_server = vui->is_server;
3707 mp->num_regions = ntohl(vui->num_regions);
3708 mp->sock_errno = ntohl(vui->sock_errno);
3709 mp->context = context;
3711 strncpy ((char *) mp->sock_filename,
3712 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3713 strncpy ((char *) mp->interface_name,
3714 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3716 vl_msg_api_send_shmem (q, (u8 *)&mp);
3721 vl_api_sw_interface_vhost_user_dump_t_handler (
3722 vl_api_sw_interface_vhost_user_dump_t *mp)
3726 vpe_api_main_t * am = &vpe_api_main;
3727 vnet_main_t * vnm = vnet_get_main();
3728 vlib_main_t * vm = vlib_get_main();
3729 vhost_user_intf_details_t *ifaces = NULL;
3730 vhost_user_intf_details_t *vuid = NULL;
3731 unix_shared_memory_queue_t * q;
3733 q = vl_api_client_index_to_input_queue (mp->client_index);
3737 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3741 vec_foreach (vuid, ifaces) {
3742 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3748 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3749 unix_shared_memory_queue_t *q,
3754 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3755 u8 * if_name = NULL;
3756 vnet_sw_interface_t * si = NULL;
3758 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3760 if_name = format(if_name, "%U",
3761 format_vnet_sw_interface_name, lm->vnet_main, si);
3763 mp = vl_msg_api_alloc (sizeof (*mp));
3764 memset (mp, 0, sizeof (*mp));
3765 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3766 strncpy((char *)mp->interface_name,
3767 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3768 mp->sw_if_index = ntohl(si->sw_if_index);
3769 mp->local_session_id = s->local_session_id;
3770 mp->remote_session_id = s->remote_session_id;
3771 mp->local_cookie[0] = s->local_cookie[0];
3772 mp->local_cookie[1] = s->local_cookie[1];
3773 mp->remote_cookie = s->remote_cookie;
3774 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3775 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3776 mp->l2_sublayer_present = s->l2_sublayer_present;
3777 mp->context = context;
3779 vl_msg_api_send_shmem (q, (u8 *)&mp);
3782 static void send_ip_address_details (vpe_api_main_t * am,
3783 unix_shared_memory_queue_t * q,
3788 vl_api_ip_address_details_t * mp;
3790 mp = vl_msg_api_alloc (sizeof (*mp));
3791 memset (mp, 0, sizeof (*mp));
3792 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3795 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3797 u32 * tp = (u32 *)mp->ip;
3798 *tp = ntohl(*(u32*)ip);
3800 mp->prefix_length = prefix_length;
3802 vl_msg_api_send_shmem (q, (u8 *)&mp);
3806 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3808 vpe_api_main_t * am = &vpe_api_main;
3809 unix_shared_memory_queue_t * q;
3812 ip6_main_t * im6 = &ip6_main;
3813 ip4_main_t * im4 = &ip4_main;
3814 ip_lookup_main_t * lm6 = &im6->lookup_main;
3815 ip_lookup_main_t * lm4 = &im4->lookup_main;
3816 ip_interface_address_t * ia = 0;
3817 u32 sw_if_index = ~0;
3819 sw_if_index = ntohl(mp->sw_if_index);
3821 q = vl_api_client_index_to_input_queue (mp->client_index);
3827 foreach_ip_interface_address (lm6, ia, sw_if_index,
3828 1 /* honor unnumbered */,
3830 r6 = ip_interface_address_get_address (lm6, ia);
3831 u16 prefix_length = ia->address_length;
3832 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3835 foreach_ip_interface_address (lm4, ia, sw_if_index,
3836 1 /* honor unnumbered */,
3838 r4 = ip_interface_address_get_address (lm4, ia);
3839 u16 prefix_length = ia->address_length;
3840 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3845 static void send_ip_details (vpe_api_main_t * am,
3846 unix_shared_memory_queue_t *q,
3849 vl_api_ip_details_t * mp;
3851 mp = vl_msg_api_alloc (sizeof (*mp));
3852 memset (mp, 0, sizeof (*mp));
3853 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3855 mp->sw_if_index = ntohl(sw_if_index);
3857 vl_msg_api_send_shmem (q, (u8 *)&mp);
3861 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3862 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3864 vpe_api_main_t * am = &vpe_api_main;
3865 l2t_main_t * lm = &l2t_main;
3866 unix_shared_memory_queue_t * q;
3867 l2t_session_t *session;
3869 q = vl_api_client_index_to_input_queue (mp->client_index);
3873 pool_foreach (session, lm->sessions,
3875 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
3880 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3881 unix_shared_memory_queue_t *q,
3882 tapcli_interface_details_t *tap_if)
3884 vl_api_sw_interface_tap_details_t * mp;
3885 mp = vl_msg_api_alloc (sizeof (*mp));
3886 memset (mp, 0, sizeof (*mp));
3887 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3888 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3889 strncpy((char *)mp->dev_name,
3890 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3892 vl_msg_api_send_shmem (q, (u8 *)&mp);
3896 vl_api_sw_interface_tap_dump_t_handler (
3897 vl_api_sw_interface_tap_dump_t *mp)
3900 vpe_api_main_t * am = &vpe_api_main;
3901 unix_shared_memory_queue_t * q;
3902 tapcli_interface_details_t *tapifs = NULL;
3903 tapcli_interface_details_t *tap_if = NULL;
3905 q = vl_api_client_index_to_input_queue (mp->client_index);
3909 rv = vnet_tap_dump_ifs(&tapifs);
3913 vec_foreach(tap_if, tapifs) {
3914 send_sw_interface_tap_details(am, q, tap_if);
3921 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3923 vpe_api_main_t * am = &vpe_api_main;
3924 vnet_main_t * vnm = vnet_get_main();
3925 vlib_main_t * vm = vlib_get_main();
3926 vnet_interface_main_t * im = &vnm->interface_main;
3927 unix_shared_memory_queue_t * q;
3928 vnet_sw_interface_t * si, * sorted_sis;
3929 u32 sw_if_index = ~0;
3931 q = vl_api_client_index_to_input_queue (mp->client_index);
3936 /* Gather interfaces. */
3937 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3938 _vec_len (sorted_sis) = 0;
3939 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3941 vec_foreach (si, sorted_sis) {
3942 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3943 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3946 sw_if_index = si->sw_if_index;
3947 send_ip_details(am, q, sw_if_index);
3952 static void vl_api_l2_fib_table_entry_t_handler (
3953 vl_api_l2_fib_table_entry_t * mp)
3955 clib_warning ("BUG");
3958 static void send_l2fib_table_entry (vpe_api_main_t * am,
3959 unix_shared_memory_queue_t *q,
3960 l2fib_entry_key_t * l2fe_key,
3961 l2fib_entry_result_t * l2fe_res,
3964 vl_api_l2_fib_table_entry_t * mp;
3966 mp = vl_msg_api_alloc (sizeof (*mp));
3967 memset (mp, 0, sizeof (*mp));
3968 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3970 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3972 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3973 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3974 mp->static_mac = l2fe_res->fields.static_mac;
3975 mp->filter_mac = l2fe_res->fields.filter;
3976 mp->bvi_mac = l2fe_res->fields.bvi;
3977 mp->context = context;
3979 vl_msg_api_send_shmem (q, (u8 *)&mp);
3983 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3985 vpe_api_main_t * am = &vpe_api_main;
3986 bd_main_t * bdm = &bd_main;
3987 l2fib_entry_key_t *l2fe_key = NULL;
3988 l2fib_entry_result_t *l2fe_res = NULL;
3989 u32 ni, bd_id = ntohl (mp->bd_id);
3991 unix_shared_memory_queue_t * q;
3994 q = vl_api_client_index_to_input_queue (mp->client_index);
3998 /* see l2fib_table_dump: ~0 means "any" */
4002 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4009 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4011 vec_foreach_index (ni, l2fe_key) {
4012 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4013 vec_elt_at_index(l2fe_res, ni), mp->context);
4020 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4022 vl_api_show_version_reply_t *rmp;
4024 char * vpe_api_get_build_directory(void);
4025 char * vpe_api_get_version(void);
4026 char * vpe_api_get_build_date(void);
4028 unix_shared_memory_queue_t * q =
4029 vl_api_client_index_to_input_queue (mp->client_index);
4034 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4036 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4037 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4038 ARRAY_LEN(rmp->build_directory)-1);
4039 strncpy ((char *) rmp->version, vpe_api_get_version(),
4040 ARRAY_LEN(rmp->version)-1);
4041 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4042 ARRAY_LEN(rmp->build_date)-1);
4046 static void vl_api_get_node_index_t_handler
4047 (vl_api_get_node_index_t * mp)
4049 vlib_main_t * vm = vlib_get_main();
4050 vl_api_get_node_index_reply_t * rmp;
4053 u32 node_index = ~0;
4055 n = vlib_get_node_by_name (vm, mp->node_name);
4058 rv = VNET_API_ERROR_NO_SUCH_NODE;
4060 node_index = n->index;
4062 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4064 rmp->node_index = ntohl(node_index);
4068 static void vl_api_add_node_next_t_handler
4069 (vl_api_add_node_next_t * mp)
4071 vlib_main_t * vm = vlib_get_main();
4072 vl_api_add_node_next_reply_t * rmp;
4073 vlib_node_t * n, * next;
4075 u32 next_index = ~0;
4077 n = vlib_get_node_by_name (vm, mp->node_name);
4080 rv = VNET_API_ERROR_NO_SUCH_NODE;
4084 next = vlib_get_node_by_name (vm, mp->next_name);
4087 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4089 next_index = vlib_node_add_next (vm, n->index, next->index);
4092 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4094 rmp->next_index = ntohl(next_index);
4098 static void vl_api_l2tpv3_create_tunnel_t_handler
4099 (vl_api_l2tpv3_create_tunnel_t *mp)
4101 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4102 l2t_main_t *lm = &l2t_main;
4103 u32 sw_if_index = (u32)~0;
4106 if (mp->is_ipv6 != 1) {
4107 rv = VNET_API_ERROR_UNIMPLEMENTED;
4111 rv = create_l2tpv3_ipv6_tunnel (lm,
4112 (ip6_address_t *) mp->client_address,
4113 (ip6_address_t *) mp->our_address,
4114 ntohl(mp->local_session_id),
4115 ntohl(mp->remote_session_id),
4116 clib_net_to_host_u64(mp->local_cookie),
4117 clib_net_to_host_u64(mp->remote_cookie),
4118 mp->l2_sublayer_present,
4122 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4124 rmp->sw_if_index = ntohl (sw_if_index);
4128 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4129 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4131 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4132 l2t_main_t *lm = &l2t_main;
4135 VALIDATE_SW_IF_INDEX(mp);
4137 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4138 clib_net_to_host_u64(mp->new_local_cookie),
4139 clib_net_to_host_u64(mp->new_remote_cookie));
4141 BAD_SW_IF_INDEX_LABEL;
4143 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4146 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4147 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4150 vnet_main_t * vnm = vnet_get_main();
4151 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4153 VALIDATE_SW_IF_INDEX(mp);
4155 rv = l2tpv3_interface_enable_disable
4156 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4158 BAD_SW_IF_INDEX_LABEL;
4160 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4163 static void vl_api_l2tpv3_set_lookup_key_t_handler
4164 (vl_api_l2tpv3_set_lookup_key_t * mp)
4167 l2t_main_t *lm = &l2t_main;
4168 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4170 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4171 rv = VNET_API_ERROR_INVALID_VALUE;
4175 lm->lookup_type = mp->key;
4178 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4181 static void vl_api_vxlan_add_del_tunnel_t_handler
4182 (vl_api_vxlan_add_del_tunnel_t * mp)
4184 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4186 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4187 u32 encap_fib_index;
4189 ip4_main_t * im = &ip4_main;
4190 u32 sw_if_index = ~0;
4192 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4194 rv = VNET_API_ERROR_NO_SUCH_FIB;
4197 encap_fib_index = p[0];
4199 /* Check src & dst are different */
4200 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4201 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4202 rv = VNET_API_ERROR_SAME_SRC_DST;
4205 memset (a, 0, sizeof (*a));
4207 a->is_add = mp->is_add;
4208 a->is_ip6 = mp->is_ipv6;
4210 /* ip addresses sent in network byte order */
4212 memcpy(&(a->src.ip6), mp->src_address, 16);
4213 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4215 memcpy(&(a->src.ip4), mp->src_address, 4);
4216 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4219 a->encap_fib_index = encap_fib_index;
4220 a->decap_next_index = ntohl(mp->decap_next_index);
4221 a->vni = ntohl(mp->vni);
4222 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4225 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4227 rmp->sw_if_index = ntohl (sw_if_index);
4231 static void send_vxlan_tunnel_details
4232 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4234 vl_api_vxlan_tunnel_details_t * rmp;
4235 ip4_main_t * im4 = &ip4_main;
4236 ip6_main_t * im6 = &ip6_main;
4237 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4239 rmp = vl_msg_api_alloc (sizeof (*rmp));
4240 memset (rmp, 0, sizeof (*rmp));
4241 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4243 memcpy(rmp->src_address, &(t->src.ip6), 16);
4244 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4245 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4247 memcpy(rmp->src_address, &(t->src.ip4), 4);
4248 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4249 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4251 rmp->vni = htonl(t->vni);
4252 rmp->decap_next_index = htonl(t->decap_next_index);
4253 rmp->sw_if_index = htonl(t->sw_if_index);
4254 rmp->is_ipv6 = is_ipv6;
4256 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4259 static void vl_api_vxlan_tunnel_dump_t_handler
4260 (vl_api_vxlan_tunnel_dump_t * mp)
4262 unix_shared_memory_queue_t * q;
4263 vxlan_main_t * vxm = &vxlan_main;
4267 q = vl_api_client_index_to_input_queue (mp->client_index);
4272 sw_if_index = ntohl(mp->sw_if_index);
4274 if (~0 == sw_if_index) {
4275 pool_foreach (t, vxm->tunnels,
4277 send_vxlan_tunnel_details(t, q);
4280 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4281 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4284 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4285 send_vxlan_tunnel_details(t, q);
4290 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4292 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4294 vl_api_l2_patch_add_del_reply_t * rmp;
4295 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4299 VALIDATE_RX_SW_IF_INDEX(mp);
4300 VALIDATE_TX_SW_IF_INDEX(mp);
4302 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4303 ntohl(mp->tx_sw_if_index),
4304 (int)(mp->is_add != 0));
4306 BAD_RX_SW_IF_INDEX_LABEL;
4307 BAD_TX_SW_IF_INDEX_LABEL;
4309 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4313 vl_api_nsh_gre_add_del_tunnel_t_handler
4314 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4316 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4318 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4319 u32 encap_fib_index, decap_fib_index;
4320 u32 decap_next_index;
4322 ip4_main_t * im = &ip4_main;
4324 u32 sw_if_index = ~0;
4327 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4329 rv = VNET_API_ERROR_NO_SUCH_FIB;
4332 encap_fib_index = p[0];
4334 decap_next_index = ntohl(mp->decap_next_index);
4336 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4337 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4338 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4340 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4343 decap_fib_index = p[0];
4345 decap_fib_index = ntohl(mp->decap_vrf_id);
4348 memset (a, 0, sizeof (*a));
4350 a->is_add = mp->is_add;
4351 /* ip addresses sent in network byte order */
4352 a->src.as_u32 = ntohl(mp->src);
4353 a->dst.as_u32 = ntohl(mp->dst);
4354 a->encap_fib_index = encap_fib_index;
4355 a->decap_fib_index = decap_fib_index;
4356 a->decap_next_index = decap_next_index;
4357 a->ver_o_c = mp->ver_o_c;
4358 a->length = mp->length;
4359 a->md_type = mp->md_type;
4360 a->next_protocol = mp->next_protocol;
4361 a->spi_si = ntohl(mp->spi_si);
4362 a->c1 = ntohl(mp->c1);
4363 a->c2 = ntohl(mp->c2);
4364 a->c3 = ntohl(mp->c3);
4365 a->c4 = ntohl(mp->c4);
4367 for (i = 0; i < mp->tlv_len_in_words; i++)
4368 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4372 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4375 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4377 rmp->sw_if_index = ntohl (sw_if_index);
4382 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4383 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4385 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4387 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4388 u32 encap_fib_index, decap_fib_index;
4389 u32 decap_next_index;
4391 ip4_main_t * im = &ip4_main;
4393 u32 sw_if_index = ~0;
4396 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4398 rv = VNET_API_ERROR_NO_SUCH_FIB;
4401 encap_fib_index = p[0];
4403 decap_next_index = ntohl(mp->decap_next_index);
4405 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4406 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4407 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4409 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4412 decap_fib_index = p[0];
4414 decap_fib_index = ntohl(mp->decap_vrf_id);
4417 memset (a, 0, sizeof (*a));
4419 a->is_add = mp->is_add;
4420 /* ip addresses sent in network byte order */
4421 a->src.as_u32 = ntohl(mp->src);
4422 a->dst.as_u32 = ntohl(mp->dst);
4423 a->encap_fib_index = encap_fib_index;
4424 a->decap_fib_index = decap_fib_index;
4425 a->decap_next_index = decap_next_index;
4426 a->vni = ntohl(mp->vni);
4427 a->ver_o_c = mp->ver_o_c;
4428 a->length = mp->length;
4429 a->md_type = mp->md_type;
4430 a->next_protocol = mp->next_protocol;
4431 a->spi_si = ntohl(mp->spi_si);
4432 a->c1 = ntohl(mp->c1);
4433 a->c2 = ntohl(mp->c2);
4434 a->c3 = ntohl(mp->c3);
4435 a->c4 = ntohl(mp->c4);
4437 for (i = 0; i < mp->tlv_len_in_words; i++)
4438 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4442 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4445 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4447 rmp->sw_if_index = ntohl (sw_if_index);
4452 vl_api_lisp_gpe_add_del_tunnel_t_handler
4453 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4455 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4457 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4458 u32 encap_fib_index, decap_fib_index;
4459 u32 decap_next_index;
4461 ip4_main_t * im = &ip4_main;
4462 u32 sw_if_index = ~0;
4464 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4466 rv = VNET_API_ERROR_NO_SUCH_FIB;
4469 encap_fib_index = p[0];
4471 decap_next_index = ntohl(mp->decap_next_index);
4473 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4474 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4475 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4477 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4480 decap_fib_index = p[0];
4482 decap_fib_index = ntohl(mp->decap_vrf_id);
4485 memset (a, 0, sizeof (*a));
4487 a->is_add = mp->is_add;
4488 /* ip addresses sent in network byte order */
4489 a->src.as_u32 = mp->src;
4490 a->dst.as_u32 = mp->dst;
4491 a->encap_fib_index = encap_fib_index;
4492 a->decap_fib_index = decap_fib_index;
4493 a->decap_next_index = decap_next_index;
4494 a->flags = mp->flags;
4495 a->ver_res = mp->ver_res;
4497 a->next_protocol = mp->next_protocol;
4498 a->vni = clib_net_to_host_u32 (mp->iid);
4500 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4503 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4505 rmp->sw_if_index = ntohl (sw_if_index);
4510 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4512 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4514 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4516 u8 *locator_name = NULL;
4518 memset(a, 0, sizeof(a[0]));
4520 locator_name = format(0, "%s", mp->locator_set_name);
4522 a->name = locator_name;
4524 a->is_add = mp->is_add;
4527 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4529 vec_free(locator_name);
4531 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4535 vl_api_lisp_add_del_locator_t_handler(
4536 vl_api_lisp_add_del_locator_t *mp)
4538 vl_api_lisp_add_del_locator_reply_t *rmp;
4540 locator_t locator, *locators = NULL;
4541 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4543 u8 *locator_name = NULL;
4545 memset(&locator, 0, sizeof(locator));
4546 memset(a, 0, sizeof(a[0]));
4548 locator.sw_if_index = ntohl(mp->sw_if_index);
4549 locator.priority = mp->priority;
4550 locator.weight = mp->weight;
4552 vec_add1(locators, locator);
4554 locator_name = format(0, "%s", mp->locator_set_name);
4556 a->name = locator_name;
4557 a->locators = locators;
4558 a->is_add = mp->is_add;
4561 rv = vnet_lisp_add_del_locator(a, &ls_index);
4564 vec_free(locator_name);
4566 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4570 vl_api_lisp_add_del_local_eid_t_handler(
4571 vl_api_lisp_add_del_local_eid_t *mp)
4573 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4574 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4576 ip_prefix_t *prefp = NULL;
4577 ip_address_t *ip_eid = NULL;
4580 u32 locator_set_index = ~0, map_index = ~0;
4581 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4584 prefp = &gid_address_ippref(&eid);
4585 ip_eid = &ip_prefix_addr(prefp);
4586 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4589 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4590 sizeof(ip_addr_v6(ip_eid)));
4591 ip_addr_version(ip_eid) = IP6;
4593 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4594 sizeof(ip_addr_v4(ip_eid)));
4595 ip_addr_version(ip_eid) = IP4;
4597 ip_prefix_len(prefp) = mp->prefix_len;
4599 name = format(0, "%s", mp->locator_set_name);
4600 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4602 rv = VNET_API_ERROR_INVALID_VALUE;
4605 locator_set_index = p[0];
4607 /* XXX treat batch configuration */
4608 a->is_add = mp->is_add;
4610 a->locator_set_index = locator_set_index;
4613 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4618 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4622 lisp_gpe_add_del_fwd_entry_set_address(
4623 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4624 ip_address_t *slocator,
4625 ip_address_t *dlocator,
4628 ip_address_t *ip_eid = NULL;
4629 ip_prefix_t *prefp = NULL;
4631 prefp = &gid_address_ippref(eid);
4632 ip_eid = &ip_prefix_addr(prefp);
4634 if (mp->eid_is_ipv6) {
4635 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4636 sizeof(ip_addr_v6(ip_eid)));
4637 ip_addr_version(ip_eid) = IP6;
4639 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4640 sizeof(ip_addr_v4(ip_eid)));
4641 ip_addr_version(ip_eid) = IP4;
4643 ip_prefix_len(prefp) = mp->eid_prefix_len;
4645 if (mp->address_is_ipv6) {
4646 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4647 sizeof(ip_addr_v6(slocator)));
4648 ip_addr_version(slocator) = IP6;
4649 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4650 sizeof(ip_addr_v6(dlocator)));
4651 ip_addr_version(dlocator) = IP6;
4653 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4654 sizeof(ip_addr_v4(slocator)));
4655 ip_addr_version(slocator) = IP4;
4656 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4657 sizeof(ip_addr_v4(dlocator)));
4658 ip_addr_version(dlocator) = IP4;
4663 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4664 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4666 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4668 ip_address_t slocator, dlocator;
4669 ip_prefix_t * prefp = NULL;
4671 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4673 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4675 memset (&a, 0, sizeof(a));
4677 a.is_add = mp->is_add;
4679 a.slocator = slocator;
4680 a.dlocator = dlocator;
4681 prefp = &gid_address_ippref(&a.deid);
4682 a.decap_next_index = (ip_prefix_version(prefp) == IP4) ?
4683 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
4684 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4686 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4690 vl_api_lisp_add_del_map_resolver_t_handler(
4691 vl_api_lisp_add_del_map_resolver_t *mp)
4693 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4695 ip_address_t *ip_addr = NULL;
4696 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4698 a->is_add = mp->is_add;
4699 ip_addr = &a->address;
4702 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4703 sizeof(ip_addr_v6(ip_addr)));
4704 ip_addr_version(ip_addr) = IP6;
4706 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4707 sizeof(ip_addr_v4(ip_addr)));
4708 ip_addr_version(ip_addr) = IP4;
4711 rv = vnet_lisp_add_del_map_resolver (a);
4713 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4717 vl_api_lisp_gpe_enable_disable_t_handler(
4718 vl_api_lisp_gpe_enable_disable_t *mp)
4720 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4722 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4724 a->is_en = mp->is_en;
4725 vnet_lisp_gpe_enable_disable (a);
4727 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4731 vl_api_lisp_gpe_add_del_iface_t_handler(
4732 vl_api_lisp_gpe_add_del_iface_t *mp)
4734 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4736 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4738 a->is_add = mp->is_add;
4739 a->table_id = mp->table_id;
4741 vnet_lisp_gpe_add_del_iface (a, 0);
4743 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4747 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4748 locator_set_t *lsit,
4749 unix_shared_memory_queue_t *q)
4751 vl_api_lisp_locator_set_details_t *rmp;
4752 locator_t *loc = NULL;
4755 vec_foreach (locit, lsit->locator_indices) {
4756 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4757 rmp = vl_msg_api_alloc (sizeof (*rmp));
4758 memset (rmp, 0, sizeof (*rmp));
4759 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4760 strncpy((char *) rmp->locator_set_name,
4761 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4762 rmp->sw_if_index = htonl(loc->sw_if_index);
4763 rmp->priority = loc->priority;
4764 rmp->weight = loc->weight;
4766 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4771 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4773 unix_shared_memory_queue_t * q = NULL;
4774 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4775 locator_set_t * lsit = NULL;
4777 q = vl_api_client_index_to_input_queue (mp->client_index);
4782 pool_foreach (lsit, lcm->locator_set_pool,
4784 send_lisp_locator_set_details(lcm, lsit, q);
4789 send_lisp_local_eid_table_details (mapping_t *mapit,
4790 unix_shared_memory_queue_t *q)
4792 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4793 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4794 locator_set_t *ls = NULL;
4795 gid_address_t *gid = NULL;
4796 ip_prefix_t *ip_prefix = NULL;
4799 ls = pool_elt_at_index (lcm->locator_set_pool,
4800 mapit->locator_set_index);
4803 type = gid_address_type(gid);
4805 if (type != GID_ADDR_IP_PREFIX) {
4809 ip_prefix = &gid_address_ippref(gid);
4811 rmp = vl_msg_api_alloc (sizeof (*rmp));
4812 memset (rmp, 0, sizeof (*rmp));
4813 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
4814 strncpy((char *) rmp->locator_set_name,
4815 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4817 switch (ip_prefix_version(ip_prefix)) {
4819 rmp->eid_is_ipv6 = 0;
4820 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
4821 sizeof(ip_prefix_v4(ip_prefix)));
4825 rmp->eid_is_ipv6 = 1;
4826 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
4827 sizeof(ip_prefix_v6(ip_prefix)));
4833 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
4835 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4839 vl_api_lisp_local_eid_table_dump_t_handler (
4840 vl_api_lisp_local_eid_table_dump_t *mp)
4842 unix_shared_memory_queue_t * q = NULL;
4843 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4844 mapping_t * mapit = NULL;
4846 q = vl_api_client_index_to_input_queue (mp->client_index);
4851 pool_foreach (mapit, lcm->mapping_pool,
4853 send_lisp_local_eid_table_details(mapit, q);
4858 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
4859 unix_shared_memory_queue_t *q)
4861 vl_api_lisp_gpe_tunnel_details_t *rmp;
4862 lisp_gpe_main_t * lgm = &lisp_gpe_main;
4864 rmp = vl_msg_api_alloc (sizeof (*rmp));
4865 memset (rmp, 0, sizeof (*rmp));
4866 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
4868 rmp->tunnels = tunnel - lgm->tunnels;
4870 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
4871 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
4872 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
4874 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
4875 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
4876 rmp->dcap_next = htonl(tunnel->decap_next_index);
4877 rmp->lisp_ver = tunnel->ver_res;
4878 rmp->next_protocol = tunnel->next_protocol;
4879 rmp->flags = tunnel->flags;
4880 rmp->ver_res = tunnel->ver_res;
4881 rmp->res = tunnel->res;
4882 rmp->iid = htonl(tunnel->vni);
4884 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4888 vl_api_lisp_gpe_tunnel_dump_t_handler (
4889 vl_api_lisp_local_eid_table_dump_t *mp)
4891 unix_shared_memory_queue_t * q = NULL;
4892 lisp_gpe_main_t * lgm = &lisp_gpe_main;
4893 lisp_gpe_tunnel_t * tunnel = NULL;
4895 if (pool_elts(lgm->tunnels) == 0) {
4899 q = vl_api_client_index_to_input_queue (mp->client_index);
4904 pool_foreach(tunnel, lgm->tunnels,
4906 send_lisp_gpe_tunnel_details(tunnel, q);
4911 send_lisp_map_resolver_details (ip_address_t *ip,
4912 unix_shared_memory_queue_t *q)
4914 vl_api_lisp_map_resolver_details_t *rmp = NULL;
4916 rmp = vl_msg_api_alloc (sizeof (*rmp));
4917 memset (rmp, 0, sizeof (*rmp));
4918 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
4920 switch (ip_addr_version(ip)) {
4923 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
4928 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
4935 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4939 vl_api_lisp_map_resolver_dump_t_handler (
4940 vl_api_lisp_local_eid_table_dump_t *mp)
4942 unix_shared_memory_queue_t * q = NULL;
4943 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4944 ip_address_t *ip = NULL;
4946 q = vl_api_client_index_to_input_queue (mp->client_index);
4951 vec_foreach(ip, lcm->map_resolvers) {
4952 send_lisp_map_resolver_details(ip, q);
4958 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4960 vl_api_interface_name_renumber_reply_t * rmp;
4963 VALIDATE_SW_IF_INDEX(mp);
4965 rv = vnet_interface_name_renumber
4966 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4968 BAD_SW_IF_INDEX_LABEL;
4970 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4973 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4974 u32 sw_if_index, u32 address)
4976 vpe_api_main_t * am = &vpe_api_main;
4977 vlib_main_t * vm = am->vlib_main;
4978 vl_api_ip4_arp_event_t * event;
4979 static f64 arp_event_last_time;
4980 f64 now = vlib_time_now (vm);
4982 if (pool_is_free_index (am->arp_events, pool_index))
4985 event = pool_elt_at_index (am->arp_events, pool_index);
4986 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4987 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4988 } else { /* same mac */
4989 if ((sw_if_index == event->sw_if_index) &&
4991 /* for BD case, also check IP address with 10 sec timeout */
4992 ((address == event->address) &&
4993 ((now - arp_event_last_time) < 10.0))))
4997 arp_event_last_time = now;
4998 event->sw_if_index = sw_if_index;
4999 if (address) event->address = address;
5003 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5005 vpe_api_main_t * am = &vpe_api_main;
5007 if (pool_is_free_index (am->arp_events, pool_index))
5010 pool_put_index (am->arp_events, pool_index);
5015 vl_api_want_ip4_arp_events_t_handler
5016 (vl_api_want_ip4_arp_events_t * mp)
5018 vpe_api_main_t * am = &vpe_api_main;
5019 vnet_main_t * vnm = vnet_get_main();
5020 vl_api_want_ip4_arp_events_reply_t *rmp;
5021 vl_api_ip4_arp_event_t * event;
5024 if (mp->enable_disable) {
5025 pool_get (am->arp_events, event);
5026 memset (event, 0, sizeof (*event));
5028 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5029 event->client_index = mp->client_index;
5030 event->context = mp->context;
5031 event->address = mp->address;
5032 event->pid = mp->pid;
5034 rv = vnet_add_del_ip4_arp_change_event
5035 (vnm, arp_change_data_callback,
5037 &mp->address /* addr, in net byte order */,
5038 vpe_resolver_process_node.index,
5039 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5041 rv = vnet_add_del_ip4_arp_change_event
5042 (vnm, arp_change_delete_callback,
5044 &mp->address /* addr, in net byte order */,
5045 vpe_resolver_process_node.index,
5046 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5048 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5051 static void vl_api_input_acl_set_interface_t_handler
5052 (vl_api_input_acl_set_interface_t * mp)
5054 vlib_main_t *vm = vlib_get_main();
5055 vl_api_input_acl_set_interface_reply_t * rmp;
5057 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5059 ip4_table_index = ntohl(mp->ip4_table_index);
5060 ip6_table_index = ntohl(mp->ip6_table_index);
5061 l2_table_index = ntohl(mp->l2_table_index);
5062 sw_if_index = ntohl(mp->sw_if_index);
5064 VALIDATE_SW_IF_INDEX(mp);
5066 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5067 ip6_table_index, l2_table_index,
5070 BAD_SW_IF_INDEX_LABEL;
5072 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5075 static void vl_api_ipsec_spd_add_del_t_handler
5076 (vl_api_ipsec_spd_add_del_t * mp)
5079 clib_warning ("unimplemented");
5082 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5083 vl_api_ipsec_spd_add_del_reply_t * rmp;
5087 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5089 rv = VNET_API_ERROR_UNIMPLEMENTED;
5092 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5096 static void vl_api_ipsec_interface_add_del_spd_t_handler
5097 (vl_api_ipsec_interface_add_del_spd_t * mp)
5099 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5100 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5102 u32 sw_if_index __attribute__((unused));
5103 u32 spd_id __attribute__((unused));
5105 sw_if_index = ntohl(mp->sw_if_index);
5106 spd_id = ntohl(mp->spd_id);
5108 VALIDATE_SW_IF_INDEX(mp);
5111 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5113 rv = VNET_API_ERROR_UNIMPLEMENTED;
5116 BAD_SW_IF_INDEX_LABEL;
5118 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5121 static void vl_api_ipsec_spd_add_del_entry_t_handler
5122 (vl_api_ipsec_spd_add_del_entry_t * mp)
5124 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5125 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5131 memset(&p, 0, sizeof(p));
5133 p.id = ntohl(mp->spd_id);
5134 p.priority = ntohl(mp->priority);
5135 p.is_outbound = mp->is_outbound;
5136 p.is_ipv6 = mp->is_ipv6;
5138 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5139 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5140 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5141 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5143 p.protocol = mp->protocol;
5144 p.rport.start = ntohs(mp->remote_port_start);
5145 p.rport.stop = ntohs(mp->remote_port_stop);
5146 p.lport.start = ntohs(mp->local_port_start);
5147 p.lport.stop = ntohs(mp->local_port_stop);
5148 /* policy action resolve unsupported */
5149 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5150 clib_warning("unsupported action: 'resolve'");
5151 rv = VNET_API_ERROR_UNIMPLEMENTED;
5154 p.policy = mp->policy;
5155 p.sa_id = ntohl(mp->sa_id);
5157 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5161 if (mp->is_ip_any) {
5163 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5166 rv = VNET_API_ERROR_UNIMPLEMENTED;
5171 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5174 static void vl_api_ipsec_sad_add_del_entry_t_handler
5175 (vl_api_ipsec_sad_add_del_entry_t * mp)
5177 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5178 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5183 memset(&sa, 0, sizeof(sa));
5185 sa.id = ntohl(mp->sad_id);
5186 sa.spi = ntohl(mp->spi);
5187 /* security protocol AH unsupported */
5188 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5189 clib_warning("unsupported security protocol 'AH'");
5190 rv = VNET_API_ERROR_UNIMPLEMENTED;
5193 sa.protocol = mp->protocol;
5194 /* check for unsupported crypto-alg */
5195 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5196 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5197 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5198 mp->crypto_algorithm);
5199 rv = VNET_API_ERROR_UNIMPLEMENTED;
5202 sa.crypto_alg = mp->crypto_algorithm;
5203 sa.crypto_key_len = mp->crypto_key_length;
5204 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5205 /* check for unsupported integ-alg */
5206 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5207 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5208 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5209 mp->integrity_algorithm);
5210 rv = VNET_API_ERROR_UNIMPLEMENTED;
5213 sa.integ_alg = mp->integrity_algorithm;
5214 sa.integ_key_len = mp->integrity_key_length;
5215 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5216 sa.use_esn = mp->use_extended_sequence_number;
5217 sa.is_tunnel = mp->is_tunnel;
5218 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5219 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5220 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5222 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5224 rv = VNET_API_ERROR_UNIMPLEMENTED;
5229 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5233 vl_api_ikev2_profile_add_del_t_handler
5234 (vl_api_ikev2_profile_add_del_t * mp)
5236 vl_api_ikev2_profile_add_del_reply_t * rmp;
5240 vlib_main_t * vm = vlib_get_main();
5241 clib_error_t * error;
5242 u8 * tmp = format(0, "%s", mp->name);
5243 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5246 rv = VNET_API_ERROR_UNSPECIFIED;
5248 rv = VNET_API_ERROR_UNIMPLEMENTED;
5251 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5255 vl_api_ikev2_profile_set_auth_t_handler
5256 (vl_api_ikev2_profile_set_auth_t * mp)
5258 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5262 vlib_main_t * vm = vlib_get_main();
5263 clib_error_t * error;
5264 u8 * tmp = format(0, "%s", mp->name);
5265 u8 * data = vec_new (u8, mp->data_len);
5266 clib_memcpy(data, mp->data, mp->data_len);
5267 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5271 rv = VNET_API_ERROR_UNSPECIFIED;
5273 rv = VNET_API_ERROR_UNIMPLEMENTED;
5276 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5280 vl_api_ikev2_profile_set_id_t_handler
5281 (vl_api_ikev2_profile_set_id_t * mp)
5283 vl_api_ikev2_profile_add_del_reply_t * rmp;
5287 vlib_main_t * vm = vlib_get_main();
5288 clib_error_t * error;
5289 u8 * tmp = format(0, "%s", mp->name);
5290 u8 * data = vec_new (u8, mp->data_len);
5291 clib_memcpy(data, mp->data, mp->data_len);
5292 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5296 rv = VNET_API_ERROR_UNSPECIFIED;
5298 rv = VNET_API_ERROR_UNIMPLEMENTED;
5301 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5305 vl_api_ikev2_profile_set_ts_t_handler
5306 (vl_api_ikev2_profile_set_ts_t * mp)
5308 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5312 vlib_main_t * vm = vlib_get_main();
5313 clib_error_t * error;
5314 u8 * tmp = format(0, "%s", mp->name);
5315 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5316 mp->end_port, (ip4_address_t) mp->start_addr,
5317 (ip4_address_t) mp->end_addr, mp->is_local);
5320 rv = VNET_API_ERROR_UNSPECIFIED;
5322 rv = VNET_API_ERROR_UNIMPLEMENTED;
5325 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5329 vl_api_ikev2_set_local_key_t_handler
5330 (vl_api_ikev2_set_local_key_t * mp)
5332 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5336 vlib_main_t * vm = vlib_get_main();
5337 clib_error_t * error;
5339 error = ikev2_set_local_key(vm, mp->key_file);
5341 rv = VNET_API_ERROR_UNSPECIFIED;
5343 rv = VNET_API_ERROR_UNIMPLEMENTED;
5346 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5350 vl_api_map_add_domain_t_handler
5351 (vl_api_map_add_domain_t * mp)
5353 vl_api_map_add_domain_reply_t * rmp;
5356 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5357 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5358 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5359 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5360 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5362 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5364 rmp->index = ntohl(index);
5369 vl_api_map_del_domain_t_handler
5370 (vl_api_map_del_domain_t * mp)
5372 vl_api_map_del_domain_reply_t * rmp;
5375 rv = map_delete_domain(ntohl(mp->index));
5377 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5381 vl_api_map_add_del_rule_t_handler
5382 (vl_api_map_add_del_rule_t * mp)
5384 vl_api_map_del_domain_reply_t * rmp;
5387 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5389 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5393 vl_api_map_domain_dump_t_handler
5394 (vl_api_map_domain_dump_t * mp)
5396 vl_api_map_domain_details_t * rmp;
5397 map_main_t *mm = &map_main;
5399 unix_shared_memory_queue_t * q;
5401 if (pool_elts (mm->domains) == 0)
5404 q = vl_api_client_index_to_input_queue (mp->client_index);
5409 pool_foreach(d, mm->domains, ({
5410 /* Make sure every field is initiated (or don't skip the memset()) */
5411 rmp = vl_msg_api_alloc (sizeof (*rmp));
5412 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5413 rmp->domain_index = htonl(d - mm->domains);
5414 rmp->ea_bits_len = d->ea_bits_len;
5415 rmp->psid_offset = d->psid_offset;
5416 rmp->psid_length = d->psid_length;
5417 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5418 rmp->ip4_prefix_len = d->ip4_prefix_len;
5419 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5420 rmp->ip6_prefix_len = d->ip6_prefix_len;
5421 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5422 rmp->ip6_src_len = d->ip6_src_len;
5423 rmp->mtu = htons(d->mtu);
5424 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5425 rmp->context = mp->context;
5427 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5432 vl_api_map_rule_dump_t_handler
5433 (vl_api_map_rule_dump_t * mp)
5435 unix_shared_memory_queue_t * q;
5438 vl_api_map_rule_details_t * rmp;
5439 map_main_t *mm = &map_main;
5440 u32 domain_index = ntohl(mp->domain_index);
5443 if (pool_elts (mm->domains) == 0)
5446 d = pool_elt_at_index(mm->domains, domain_index);
5447 if (!d || !d->rules) {
5451 q = vl_api_client_index_to_input_queue (mp->client_index);
5456 for (i = 0; i < (0x1 << d->psid_length); i++) {
5458 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5461 rmp = vl_msg_api_alloc(sizeof(*rmp));
5462 memset(rmp, 0, sizeof(*rmp));
5463 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5464 rmp->psid = htons(i);
5465 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5466 rmp->context = mp->context;
5467 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5472 vl_api_map_summary_stats_t_handler (
5473 vl_api_map_summary_stats_t *mp)
5475 vl_api_map_summary_stats_reply_t *rmp;
5476 vlib_combined_counter_main_t *cm;
5479 u64 total_pkts[VLIB_N_RX_TX];
5480 u64 total_bytes[VLIB_N_RX_TX];
5481 map_main_t *mm = &map_main;
5482 unix_shared_memory_queue_t *q =
5483 vl_api_client_index_to_input_queue(mp->client_index);
5488 rmp = vl_msg_api_alloc (sizeof (*rmp));
5489 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5490 rmp->context = mp->context;
5493 memset (total_pkts, 0, sizeof (total_pkts));
5494 memset (total_bytes, 0, sizeof (total_bytes));
5496 map_domain_counter_lock (mm);
5497 vec_foreach(cm, mm->domain_counters) {
5498 which = cm - mm->domain_counters;
5500 for (i = 0; i < vec_len(cm->maxi); i++) {
5501 vlib_get_combined_counter (cm, i, &v);
5502 total_pkts[which] += v.packets;
5503 total_bytes[which] += v.bytes;
5507 map_domain_counter_unlock (mm);
5509 /* Note: in network byte order! */
5510 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5511 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5512 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5513 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5514 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5515 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5516 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
5517 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
5519 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5522 static void vl_api_ipsec_sa_set_key_t_handler
5523 (vl_api_ipsec_sa_set_key_t * mp)
5525 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5526 vl_api_ipsec_sa_set_key_reply_t *rmp;
5530 sa.id = ntohl(mp->sa_id);
5531 sa.crypto_key_len = mp->crypto_key_length;
5532 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5533 sa.integ_key_len = mp->integrity_key_length;
5534 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5536 rv = ipsec_set_sa_key(vm, &sa);
5538 rv = VNET_API_ERROR_UNIMPLEMENTED;
5541 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5544 static void vl_api_cop_interface_enable_disable_t_handler
5545 (vl_api_cop_interface_enable_disable_t * mp)
5547 vl_api_cop_interface_enable_disable_reply_t * rmp;
5549 u32 sw_if_index = ntohl(mp->sw_if_index);
5552 VALIDATE_SW_IF_INDEX(mp);
5554 enable_disable = (int) mp->enable_disable;
5556 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5558 BAD_SW_IF_INDEX_LABEL;
5560 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5563 static void vl_api_cop_whitelist_enable_disable_t_handler
5564 (vl_api_cop_whitelist_enable_disable_t * mp)
5566 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5567 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5568 u32 sw_if_index = ntohl(mp->sw_if_index);
5571 VALIDATE_SW_IF_INDEX(mp);
5573 a->sw_if_index = sw_if_index;
5576 a->default_cop = mp->default_cop;
5577 a->fib_id = ntohl(mp->fib_id);
5579 rv = cop_whitelist_enable_disable (a);
5581 BAD_SW_IF_INDEX_LABEL;
5583 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5586 static void vl_api_get_node_graph_t_handler
5587 (vl_api_get_node_graph_t * mp)
5591 api_main_t * am = &api_main;
5592 vlib_main_t * vm = vlib_get_main();
5594 vl_api_get_node_graph_reply_t * rmp;
5596 pthread_mutex_lock (&am->vlib_rp->mutex);
5597 oldheap = svm_push_data_heap (am->vlib_rp);
5600 * Keep the number of memcpy ops to a minimum (e.g. 1).
5601 * The current size of the serialized vector is
5602 * slightly under 4K.
5604 vec_validate (vector, 4095);
5605 vec_reset_length (vector);
5607 vector = vlib_node_serialize (&vm->node_main, vector);
5609 svm_pop_heap (oldheap);
5610 pthread_mutex_unlock (&am->vlib_rp->mutex);
5612 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5613 rmp->reply_in_shmem = (uword) vector);
5616 static void vl_api_trace_profile_add_t_handler
5617 (vl_api_trace_profile_add_t *mp)
5620 vl_api_trace_profile_add_reply_t * rmp;
5621 clib_error_t *error;
5623 /* Ignoring the profile id as currently a single profile
5625 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5626 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5627 mp->pow_enable, mp->trace_tsp,
5630 clib_error_report(error);
5631 rv = clib_error_get_code(error);
5634 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5637 static void vl_api_trace_profile_apply_t_handler
5638 (vl_api_trace_profile_apply_t *mp)
5641 vl_api_trace_profile_apply_reply_t * rmp;
5643 if (mp->enable != 0) {
5644 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5645 ntohl(mp->prefix_length),
5647 mp->trace_op == IOAM_HBYH_ADD,
5648 mp->trace_op == IOAM_HBYH_POP,
5649 mp->trace_op == IOAM_HBYH_MOD);
5651 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5653 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5656 static void vl_api_trace_profile_del_t_handler
5657 (vl_api_trace_profile_del_t *mp)
5660 vl_api_trace_profile_del_reply_t * rmp;
5661 clib_error_t *error;
5663 error = clear_ioam_rewrite_fn();
5665 clib_error_report(error);
5666 rv = clib_error_get_code(error);
5669 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5673 #define BOUNCE_HANDLER(nn) \
5674 static void vl_api_##nn##_t_handler ( \
5675 vl_api_##nn##_t *mp) \
5677 vpe_client_registration_t *reg; \
5678 vpe_api_main_t * vam = &vpe_api_main; \
5679 unix_shared_memory_queue_t * q; \
5681 /* One registration only... */ \
5682 pool_foreach(reg, vam->nn##_registrations, \
5684 q = vl_api_client_index_to_input_queue (reg->client_index); \
5687 * If the queue is stuffed, turf the msg and complain \
5688 * It's unlikely that the intended recipient is \
5689 * alive; avoid deadlock at all costs. \
5691 if (q->cursize == q->maxsize) { \
5692 clib_warning ("ERROR: receiver queue full, drop msg"); \
5693 vl_msg_api_free (mp); \
5696 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5700 vl_msg_api_free (mp); \
5705 * Add vpe's API message handlers to the table.
5706 * vlib has alread mapped shared memory and
5707 * added the client registration handlers.
5708 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5711 static clib_error_t *
5712 vpe_api_hookup (vlib_main_t *vm)
5714 api_main_t * am = &api_main;
5717 vl_msg_api_set_handlers(VL_API_##N, #n, \
5718 vl_api_##n##_t_handler, \
5720 vl_api_##n##_t_endian, \
5721 vl_api_##n##_t_print, \
5722 sizeof(vl_api_##n##_t), 1);
5723 foreach_vpe_api_msg;
5727 * Manually register the sr tunnel add del msg, so we trace
5728 * enough bytes to capture a typical segment list
5730 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5731 "sr_tunnel_add_del",
5732 vl_api_sr_tunnel_add_del_t_handler,
5734 vl_api_sr_tunnel_add_del_t_endian,
5735 vl_api_sr_tunnel_add_del_t_print,
5739 * Trace space for 8 MPLS encap labels, classifier mask+match
5741 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5742 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5743 += 5 * sizeof (u32x4);
5744 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5745 += 5 * sizeof (u32x4);
5746 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5747 += 16 * sizeof (u32);
5750 * trace space for 4 nsh-gre variable TLV words
5752 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5753 += 4 * sizeof (u32);
5756 * Thread-safe API messages
5758 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
5763 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5765 static clib_error_t *
5766 vpe_api_init (vlib_main_t *vm)
5768 vpe_api_main_t *am = &vpe_api_main;
5771 am->vnet_main = vnet_get_main();
5772 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5773 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5774 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5775 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5776 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5777 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5780 vl_set_memory_region_name ("/vpe-api");
5781 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5786 VLIB_INIT_FUNCTION(vpe_api_init);
5788 static clib_error_t *
5789 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5793 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5795 if (unformat (input, "prefix %s", &chroot_path))
5797 vec_add1 (chroot_path, 0);
5798 vl_set_memory_root_path ((char *)chroot_path);
5801 return clib_error_return (0, "unknown input `%U'",
5802 format_unformat_error, input);
5806 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5808 void * get_unformat_vnet_sw_interface (void)
5810 return (void *) &unformat_vnet_sw_interface;
5813 #undef vl_api_version
5814 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5815 #include <api/vpe.api.h>
5816 #undef vl_api_version
5818 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5820 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5821 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5822 clib_host_to_net_u32 (mp->api_versions[0]),
5829 static u8 * format_arp_event (u8 * s, va_list * args)
5831 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5833 s = format (s, "pid %d: %U", event->pid,
5834 format_ip4_address, &event->address);
5838 static clib_error_t *
5839 show_ip4_arp_events_fn (vlib_main_t * vm,
5840 unformat_input_t * input,
5841 vlib_cli_command_t * cmd)
5843 vpe_api_main_t * am = &vpe_api_main;
5844 vl_api_ip4_arp_event_t * event;
5846 if (pool_elts (am->arp_events) == 0) {
5847 vlib_cli_output (vm, "No active arp event registrations");
5851 pool_foreach (event, am->arp_events,
5853 vlib_cli_output (vm, "%U", format_arp_event, event);
5859 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5860 .path = "show arp event registrations",
5861 .function = show_ip4_arp_events_fn,
5862 .short_help = "Show arp event registrations",