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_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
325 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
326 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
327 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
328 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump)
331 #define QUOTE(x) QUOTE_(x)
333 #define foreach_registration_hash \
334 _(interface_events) \
335 _(to_netconf_server) \
336 _(from_netconf_server) \
337 _(to_netconf_client) \
338 _(from_netconf_client) \
342 RESOLVE_IP4_ADD_DEL_ROUTE=1,
343 RESOLVE_IP6_ADD_DEL_ROUTE,
344 RESOLVE_MPLS_ETHERNET_ADD_DEL,
350 vl_api_ip_add_del_route_t r;
351 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
357 #define _(a) uword *a##_registration_hash; \
358 vpe_client_registration_t * a##_registrations;
359 foreach_registration_hash
362 /* notifications happen really early in the game */
363 u8 link_state_process_up;
365 /* ip4 pending route adds */
366 pending_route_t * pending_routes;
368 /* ip4 arp event registration pool */
369 vl_api_ip4_arp_event_t * arp_events;
372 vlib_main_t * vlib_main;
373 vnet_main_t * vnet_main;
376 static vlib_node_registration_t vpe_resolver_process_node;
377 static vpe_api_main_t vpe_api_main;
379 static void send_sw_interface_flags (vpe_api_main_t * am,
380 unix_shared_memory_queue_t *q,
381 vnet_sw_interface_t * swif);
382 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
383 unix_shared_memory_queue_t *q,
386 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
389 /* Clean up all registrations belonging to the indicated client */
390 int vl_api_memclnt_delete_callback (u32 client_index)
392 vpe_api_main_t * vam = &vpe_api_main;
393 vpe_client_registration_t *rp;
395 int stats_memclnt_delete_callback (u32 client_index);
397 stats_memclnt_delete_callback (client_index);
400 p = hash_get (vam->a##_registration_hash, client_index); \
402 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
403 pool_put (vam->a##_registrations, rp); \
404 hash_unset (vam->a##_registration_hash, client_index); \
406 foreach_registration_hash;
411 #define API_LINK_STATE_EVENT 1
412 #define API_ADMIN_UP_DOWN_EVENT 2
415 event_data_cmp (void * a1, void * a2)
420 return (word) e1[0] - (word) e2[0];
424 link_state_process (vlib_main_t * vm,
425 vlib_node_runtime_t * rt,
428 vpe_api_main_t * vam = &vpe_api_main;
429 vnet_main_t * vnm = vam->vnet_main;
430 vnet_sw_interface_t * swif;
431 uword * event_data = 0;
432 vpe_client_registration_t *reg;
434 u32 prev_sw_if_index;
435 unix_shared_memory_queue_t * q;
437 vam->link_state_process_up = 1;
440 vlib_process_wait_for_event (vm);
442 /* Unified list of changed link or admin state sw_if_indices */
443 vlib_process_get_events_with_type
444 (vm, &event_data, API_LINK_STATE_EVENT);
445 vlib_process_get_events_with_type
446 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
448 /* Sort, so we can eliminate duplicates */
449 vec_sort_with_function (event_data, event_data_cmp);
451 prev_sw_if_index = ~0;
453 for (i = 0; i < vec_len(event_data); i++) {
454 /* Only one message per swif */
455 if (prev_sw_if_index == event_data[i])
457 prev_sw_if_index = event_data[i];
459 pool_foreach(reg, vam->interface_events_registrations,
461 q = vl_api_client_index_to_input_queue (reg->client_index);
463 // sw_interface may be deleted already
464 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
467 swif = vnet_get_sw_interface (vnm, event_data[i]);
468 send_sw_interface_flags (vam, q, swif);
473 vec_reset_length (event_data);
479 static clib_error_t *
480 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
481 static clib_error_t *
482 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
484 VLIB_REGISTER_NODE (link_state_process_node,static) = {
485 .function = link_state_process,
486 .type = VLIB_NODE_TYPE_PROCESS,
487 .name = "vpe-link-state-process",
490 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
491 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
493 static clib_error_t *
494 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
496 vpe_api_main_t * vam = &vpe_api_main;
497 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
499 if (vam->link_state_process_up)
500 vlib_process_signal_event (vam->vlib_main,
501 link_state_process_node.index,
502 API_LINK_STATE_EVENT,
507 static clib_error_t *
508 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
510 vpe_api_main_t * vam = &vpe_api_main;
513 * Note: it's perfectly fair to set a subif admin up / admin down.
514 * Note the subtle distinction between this routine and the previous
517 if (vam->link_state_process_up)
518 vlib_process_signal_event (vam->vlib_main,
519 link_state_process_node.index,
520 API_ADMIN_UP_DOWN_EVENT,
525 #define pub_sub_handler(lca,UCA) \
526 static void vl_api_want_##lca##_t_handler ( \
527 vl_api_want_##lca##_t *mp) \
529 vpe_api_main_t *vam = &vpe_api_main; \
530 vpe_client_registration_t *rp; \
531 vl_api_want_##lca##_reply_t *rmp; \
535 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
537 if (mp->enable_disable) { \
538 clib_warning ("pid %d: already enabled...", mp->pid); \
539 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
542 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
543 pool_put (vam->lca##_registrations, rp); \
544 hash_unset (vam->lca##_registration_hash, \
549 if (mp->enable_disable == 0) { \
550 clib_warning ("pid %d: already disabled...", mp->pid); \
551 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
554 pool_get (vam->lca##_registrations, rp); \
555 rp->client_index = mp->client_index; \
556 rp->client_pid = mp->pid; \
557 hash_set (vam->lca##_registration_hash, rp->client_index, \
558 rp - vam->lca##_registrations); \
561 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
564 pub_sub_handler (interface_events,INTERFACE_EVENTS)
565 pub_sub_handler (oam_events,OAM_EVENTS)
567 #define RESOLUTION_EVENT 1
568 #define RESOLUTION_PENDING_EVENT 2
569 #define IP4_ARP_EVENT 3
571 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
572 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
573 static int mpls_ethernet_add_del_tunnel_2_t_handler
574 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
576 void handle_ip4_arp_event (u32 pool_index)
578 vpe_api_main_t * vam = &vpe_api_main;
579 vnet_main_t * vnm = vam->vnet_main;
580 vlib_main_t * vm = vam->vlib_main;
581 vl_api_ip4_arp_event_t * event;
582 vl_api_ip4_arp_event_t * mp;
583 unix_shared_memory_queue_t * q;
585 /* Client can cancel, die, etc. */
586 if (pool_is_free_index (vam->arp_events, pool_index))
589 event = pool_elt_at_index (vam->arp_events, pool_index);
591 q = vl_api_client_index_to_input_queue (event->client_index);
593 (void) vnet_add_del_ip4_arp_change_event
594 (vnm, arp_change_delete_callback,
595 event->pid, &event->address,
596 vpe_resolver_process_node.index, IP4_ARP_EVENT,
597 ~0 /* pool index, notused */, 0 /* is_add */);
601 if (q->cursize < q->maxsize) {
602 mp = vl_msg_api_alloc (sizeof (*mp));
603 memcpy (mp, event, sizeof (*mp));
604 vl_msg_api_send_shmem (q, (u8 *)&mp);
606 static f64 last_time;
608 * Throttle syslog msgs.
609 * It's pretty tempting to just revoke the registration...
611 if (vlib_time_now (vm) > last_time + 10.0) {
612 clib_warning ("arp event for %U to pid %d: queue stuffed!",
613 format_ip4_address, &event->address, event->pid);
614 last_time = vlib_time_now(vm);
620 resolver_process (vlib_main_t * vm,
621 vlib_node_runtime_t * rt,
625 uword *event_data = 0;
627 vpe_api_main_t * vam = &vpe_api_main;
628 pending_route_t * pr;
629 vl_api_ip_add_del_route_t * adr;
630 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
631 u32 * resolution_failures = 0;
636 vlib_process_wait_for_event_or_clock (vm, timeout);
638 event_type = vlib_process_get_events (vm, &event_data);
640 switch (event_type) {
641 case RESOLUTION_PENDING_EVENT:
645 case RESOLUTION_EVENT:
646 for (i = 0; i < vec_len(event_data); i++) {
648 * Resolution events can occur long after the
649 * original request has timed out. $$$ add a cancel
652 if (pool_is_free_index (vam->pending_routes, event_data[i]))
655 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
659 switch (pr->resolve_type) {
660 case RESOLVE_IP4_ADD_DEL_ROUTE:
661 rv = ip4_add_del_route_t_handler (adr);
662 clib_warning ("resolver: add %U/%d via %U %s",
664 (ip4_address_t *)&(adr->dst_address),
665 adr->dst_address_length,
667 (ip4_address_t *)&(adr->next_hop_address),
668 (rv >= 0) ? "succeeded" : "failed");
671 case RESOLVE_IP6_ADD_DEL_ROUTE:
672 rv = ip6_add_del_route_t_handler (adr);
673 clib_warning ("resolver: add %U/%d via %U %s",
675 (ip6_address_t *)&(adr->dst_address),
676 adr->dst_address_length,
678 (ip6_address_t *)&(adr->next_hop_address),
679 (rv >= 0) ? "succeeded" : "failed");
682 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
683 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
684 clib_warning ("resolver: add mpls-o-e via %U %s",
686 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
687 (rv >= 0) ? "succeeded" : "failed");
691 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
693 pool_put (vam->pending_routes, pr);
698 for (i = 0; i < vec_len(event_data); i++)
699 handle_ip4_arp_event (event_data[i]);
702 case ~0: /* timeout, retry pending resolutions */
703 pool_foreach (pr, vam->pending_routes,
709 /* May fail, e.g. due to interface down */
710 switch (pr->resolve_type) {
711 case RESOLVE_IP4_ADD_DEL_ROUTE:
712 e = ip4_probe_neighbor
713 (vm, (ip4_address_t *)&(adr->next_hop_address),
714 ntohl(adr->next_hop_sw_if_index));
717 case RESOLVE_IP6_ADD_DEL_ROUTE:
718 e = ip6_probe_neighbor
719 (vm, (ip6_address_t *)&(adr->next_hop_address),
720 ntohl(adr->next_hop_sw_if_index));
723 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
725 e = ip4_probe_neighbor
727 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
728 pme->resolve_opaque);
732 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
736 clib_error_report (e);
738 adr->resolve_attempts = 1;
740 pme->resolve_attempts = 1;
744 adr->resolve_attempts -= 1;
745 if (adr->resolve_attempts == 0)
746 vec_add1 (resolution_failures,
747 pr - vam->pending_routes);
749 pme->resolve_attempts -= 1;
750 if (pme->resolve_attempts == 0)
751 vec_add1 (resolution_failures,
752 pr - vam->pending_routes);
756 for (i = 0; i < vec_len (resolution_failures); i++) {
757 pr = pool_elt_at_index (vam->pending_routes,
758 resolution_failures[i]);
762 switch (pr->resolve_type) {
763 case RESOLVE_IP4_ADD_DEL_ROUTE:
764 clib_warning ("resolver: add %U/%d via %U retry failure",
766 (ip4_address_t *)&(adr->dst_address),
767 adr->dst_address_length,
769 (ip4_address_t *)&(adr->next_hop_address));
772 case RESOLVE_IP6_ADD_DEL_ROUTE:
773 clib_warning ("resolver: add %U/%d via %U retry failure",
775 (ip6_address_t *)&(adr->dst_address),
776 adr->dst_address_length,
778 (ip6_address_t *)&(adr->next_hop_address));
781 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
782 clib_warning ("resolver: add mpls-o-e via %U retry failure",
784 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
788 clib_warning ("BUG");
790 pool_put(vam->pending_routes, pr);
792 vec_reset_length (resolution_failures);
795 if (pool_elts (vam->pending_routes) == 0)
797 vec_reset_length (event_data);
799 return 0; /* or not */
802 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
803 .function = resolver_process,
804 .type = VLIB_NODE_TYPE_PROCESS,
805 .name = "vpe-route-resolver-process",
808 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
810 ip4_main_t * im = &ip4_main;
811 ip_lookup_main_t * lm = &im->lookup_main;
812 vnet_classify_main_t * cm = &vnet_classify_main;
813 stats_main_t * sm = &stats_main;
814 ip4_add_del_route_args_t a;
815 ip4_address_t next_hop_address;
817 vpe_api_main_t * vam = &vpe_api_main;
818 vnet_main_t * vnm = vam->vnet_main;
819 vlib_main_t * vm = vlib_get_main();
820 pending_route_t * pr;
821 vl_api_ip_add_del_route_t * adr;
825 ip_adjacency_t *nh_adj, *add_adj = 0;
827 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
829 if (mp->create_vrf_if_needed) {
831 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
833 fib_index = f->index;
835 /* No such VRF, and we weren't asked to create one */
836 return VNET_API_ERROR_NO_SUCH_FIB;
842 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
843 ntohl(mp->next_hop_sw_if_index)))
844 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
846 memcpy (next_hop_address.data, mp->next_hop_address,
847 sizeof (next_hop_address.data));
849 /* Arp for the next_hop if necessary */
850 if (mp->is_add && mp->resolve_if_needed) {
852 ip_adjacency_t * adj;
854 lookup_result = ip4_fib_lookup_with_table
855 (im, fib_index, &next_hop_address, 1 /* disable default route */);
857 adj = ip_get_adjacency (lm, lookup_result);
859 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
860 pool_get (vam->pending_routes, pr);
861 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
863 memcpy (adr, mp, sizeof (*adr));
864 /* recursion block, "just in case" */
865 adr->resolve_if_needed = 0;
866 adr->resolve_attempts = ntohl(mp->resolve_attempts);
867 vnet_register_ip4_arp_resolution_event
868 (vnm, &next_hop_address, vpe_resolver_process_node.index,
869 RESOLUTION_EVENT, pr - vam->pending_routes);
871 vlib_process_signal_event
872 (vm, vpe_resolver_process_node.index,
873 RESOLUTION_PENDING_EVENT, 0 /* data */);
875 /* The interface may be down, etc. */
876 e = ip4_probe_neighbor
877 (vm, (ip4_address_t *)&(mp->next_hop_address),
878 ntohl(mp->next_hop_sw_if_index));
881 clib_error_report(e);
883 return VNET_API_ERROR_IN_PROGRESS;
887 if (mp->is_multipath) {
890 dslock (sm, 1 /* release hint */, 10 /* tag */);
893 flags = IP4_ROUTE_FLAG_ADD;
895 flags = IP4_ROUTE_FLAG_DEL;
898 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
900 ip4_add_del_route_next_hop (im, flags,
901 (ip4_address_t *) mp->dst_address,
902 (u32) mp->dst_address_length,
903 (ip4_address_t *) mp->next_hop_address,
904 ntohl(mp->next_hop_sw_if_index),
905 (u32) mp->next_hop_weight,
912 memset (&a, 0, sizeof (a));
913 memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
915 a.dst_address_length = mp->dst_address_length;
917 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
918 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
919 a.table_index_or_table_id = fib_index;
924 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
926 dslock (sm, 1 /* release hint */, 2 /* tag */);
930 ai = lm->drop_adj_index;
931 else if (mp->is_local)
932 ai = lm->local_adj_index;
933 else if (mp->is_classify) {
935 memset(&cadj, 0, sizeof(cadj));
936 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
937 cadj.classify.table_index = ntohl(mp->classify_table_index);
938 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
940 return VNET_API_ERROR_NO_SUCH_TABLE;
942 vec_add1 (add_adj, cadj);
946 ai = ip4_fib_lookup_with_table
947 (im, fib_index, &next_hop_address,
948 1 /* disable default route */);
949 if (ai == lm->miss_adj_index) {
951 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
955 nh_adj = ip_get_adjacency (lm, ai);
956 vec_add1 (add_adj, nh_adj[0]);
957 if (mp->lookup_in_vrf) {
958 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
960 add_adj[0].explicit_fib_index = p[0];
964 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
968 ip_adjacency_t * adj;
969 int disable_default_route = 1;
971 /* Trying to delete the default route? */
972 if (a.dst_address.as_u32 == 0 &&
973 a.dst_address_length == 0)
974 disable_default_route = 0;
976 ai = ip4_fib_lookup_with_table
977 (im, fib_index, &a.dst_address, disable_default_route);
978 if (ai == lm->miss_adj_index) {
980 return VNET_API_ERROR_UNKNOWN_DESTINATION;
983 adj = ip_get_adjacency (lm, ai);
984 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
986 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
993 a.n_add_adj = vec_len(add_adj);
994 ip4_add_del_route (im, &a);
1002 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1004 ip6_main_t * im = &ip6_main;
1005 ip_lookup_main_t * lm = &im->lookup_main;
1006 vnet_main_t * vnm = vnet_get_main();
1007 vlib_main_t * vm = vlib_get_main();
1008 vpe_api_main_t * vam = &vpe_api_main;
1009 stats_main_t * sm = &stats_main;
1010 ip6_add_del_route_args_t a;
1011 ip6_address_t next_hop_address;
1012 pending_route_t * pr;
1013 vl_api_ip_add_del_route_t * adr;
1018 ip_adjacency_t * nh_adj, * add_adj = 0;
1021 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1024 if (mp->create_vrf_if_needed) {
1026 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1028 fib_index = f->index;
1030 /* No such VRF, and we weren't asked to create one */
1031 return VNET_API_ERROR_NO_SUCH_FIB;
1037 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1038 ntohl(mp->next_hop_sw_if_index)))
1039 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1041 memcpy (next_hop_address.as_u8, mp->next_hop_address,
1042 sizeof (next_hop_address.as_u8));
1044 /* Arp for the next_hop if necessary */
1045 if (mp->is_add && mp->resolve_if_needed) {
1047 ip_adjacency_t * adj;
1049 lookup_result = ip6_fib_lookup_with_table
1050 (im, fib_index, &next_hop_address);
1052 adj = ip_get_adjacency (lm, lookup_result);
1054 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1055 pool_get (vam->pending_routes, pr);
1057 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1058 memcpy (adr, mp, sizeof (*adr));
1059 /* recursion block, "just in case" */
1060 adr->resolve_if_needed = 0;
1061 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1062 vnet_register_ip6_neighbor_resolution_event
1063 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1064 RESOLUTION_EVENT, pr - vam->pending_routes);
1066 vlib_process_signal_event
1067 (vm, vpe_resolver_process_node.index,
1068 RESOLUTION_PENDING_EVENT, 0 /* data */);
1070 /* The interface may be down, etc. */
1071 e = ip6_probe_neighbor
1072 (vm, (ip6_address_t *)&(mp->next_hop_address),
1073 ntohl(mp->next_hop_sw_if_index));
1076 clib_error_report(e);
1078 return VNET_API_ERROR_IN_PROGRESS;
1082 if (mp->is_multipath) {
1085 dslock (sm, 1 /* release hint */, 11 /* tag */);
1088 flags = IP6_ROUTE_FLAG_ADD;
1090 flags = IP6_ROUTE_FLAG_DEL;
1093 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1095 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1096 (u32) mp->dst_address_length,
1097 (ip6_address_t *)mp->next_hop_address,
1098 ntohl(mp->next_hop_sw_if_index),
1099 (u32) mp->next_hop_weight,
1106 memset (&a, 0, sizeof (a));
1107 memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1109 a.dst_address_length = mp->dst_address_length;
1111 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1112 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1113 a.table_index_or_table_id = fib_index;
1118 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1120 dslock (sm, 1 /* release hint */, 3 /* tag */);
1124 ai = lm->drop_adj_index;
1125 else if (mp->is_local)
1126 ai = lm->local_adj_index;
1128 ai = ip6_fib_lookup_with_table
1129 (im, fib_index, &next_hop_address);
1130 if (ai == lm->miss_adj_index) {
1132 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1136 nh_adj = ip_get_adjacency (lm, ai);
1137 vec_add1 (add_adj, nh_adj[0]);
1138 if (mp->lookup_in_vrf) {
1139 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1141 add_adj[0].explicit_fib_index = p[0];
1145 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1149 ip_adjacency_t * adj;
1151 ai = ip6_fib_lookup_with_table
1152 (im, fib_index, &a.dst_address);
1153 if (ai == lm->miss_adj_index) {
1155 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1157 adj = ip_get_adjacency (lm, ai);
1158 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1160 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1165 a.add_adj = add_adj;
1166 a.n_add_adj = vec_len(add_adj);
1167 ip6_add_del_route (im, &a);
1175 void vl_api_ip_add_del_route_t_handler (
1176 vl_api_ip_add_del_route_t *mp)
1178 vl_api_ip_add_del_route_reply_t * rmp;
1180 vnet_main_t * vnm = vnet_get_main();
1185 rv = ip6_add_del_route_t_handler (mp);
1187 rv = ip4_add_del_route_t_handler (mp);
1189 rv = (rv == 0) ? vnm->api_errno : rv;
1191 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1194 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1195 u32 sw_if_index, u8 *next_hop_addr)
1197 vl_api_ip_add_del_route_t mp;
1200 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1203 * Configure default IP route:
1204 * - ip route add 0.0.0.0/1 via <GW IP>
1205 * - ip route add 128.0.0.0/1 via <GW IP>
1207 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1209 mp.resolve_attempts = ~0;
1210 mp.resolve_if_needed = 1;
1212 mp.is_ipv6 = is_ipv6;
1213 mp.next_hop_weight = 1;
1215 memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1218 rv = ip6_add_del_route_t_handler (&mp);
1221 mp.dst_address_length = 1;
1223 mp.dst_address[0] = 0;
1224 rv = ip4_add_del_route_t_handler (&mp);
1226 mp.dst_address[0] = 128;
1227 rv |= ip4_add_del_route_t_handler (&mp);
1231 clib_error_return (0, "failed to config default IP route");
1236 vl_api_sw_interface_add_del_address_t_handler
1237 (vl_api_sw_interface_add_del_address_t *mp)
1239 vlib_main_t *vm = vlib_get_main();
1240 vl_api_sw_interface_add_del_address_reply_t * rmp;
1244 VALIDATE_SW_IF_INDEX(mp);
1246 is_del = mp->is_add == 0;
1249 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1250 else if (mp->is_ipv6)
1251 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1252 (void *)mp->address,
1253 mp->address_length, is_del);
1255 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1256 (void *) mp->address,
1257 mp->address_length, is_del);
1259 BAD_SW_IF_INDEX_LABEL;
1261 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1265 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1268 u32 table_id = ntohl(mp->vrf_id);
1269 u32 sw_if_index = ntohl(mp->sw_if_index);
1270 vl_api_sw_interface_set_table_reply_t * rmp;
1271 stats_main_t * sm = &stats_main;
1273 VALIDATE_SW_IF_INDEX(mp);
1275 dslock (sm, 1 /* release hint */, 4 /* tag */);
1278 ip6_main_t * im = &ip6_main;
1280 find_ip6_fib_by_table_index_or_id (im, table_id,
1281 IP6_ROUTE_FLAG_TABLE_ID);
1283 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1284 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1286 rv = VNET_API_ERROR_NO_SUCH_FIB;
1289 ip4_main_t * im = &ip4_main;
1290 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1291 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1293 /* Truthfully this can't fail */
1295 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1296 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1298 rv = VNET_API_ERROR_NO_SUCH_FIB;
1303 BAD_SW_IF_INDEX_LABEL;
1305 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1309 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1311 vlib_main_t *vm = vlib_get_main();
1312 vl_api_sw_interface_set_vpath_reply_t * rmp;
1315 u32 sw_if_index = ntohl(mp->sw_if_index);
1316 ip4_main_t *ip4m = &ip4_main;
1317 ip6_main_t *ip6m = &ip6_main;
1318 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1319 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1320 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1321 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1322 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1323 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1325 VALIDATE_SW_IF_INDEX(mp);
1327 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1329 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1330 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1331 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1332 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1333 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1334 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1335 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1336 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1337 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1338 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1339 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1340 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1341 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1342 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1343 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1344 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1346 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1347 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1348 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1349 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1350 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1351 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1352 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1353 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1354 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1355 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1356 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1357 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1358 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1359 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1360 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1361 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1364 BAD_SW_IF_INDEX_LABEL;
1366 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1370 vl_api_sw_interface_set_l2_xconnect_t_handler (
1371 vl_api_sw_interface_set_l2_xconnect_t *mp)
1373 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1375 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1376 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1377 vlib_main_t *vm = vlib_get_main();
1378 vnet_main_t *vnm = vnet_get_main();
1380 VALIDATE_RX_SW_IF_INDEX(mp);
1383 VALIDATE_TX_SW_IF_INDEX(mp);
1384 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1385 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1387 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1390 BAD_RX_SW_IF_INDEX_LABEL;
1391 BAD_TX_SW_IF_INDEX_LABEL;
1393 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1397 vl_api_sw_interface_set_l2_bridge_t_handler (
1398 vl_api_sw_interface_set_l2_bridge_t *mp)
1400 bd_main_t * bdm = &bd_main;
1401 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1403 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1404 u32 bd_id = ntohl(mp->bd_id);
1408 vlib_main_t *vm = vlib_get_main();
1409 vnet_main_t *vnm = vnet_get_main();
1411 VALIDATE_RX_SW_IF_INDEX(mp);
1413 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1416 //VALIDATE_TX_SW_IF_INDEX(mp);
1417 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1418 rx_sw_if_index, bd_index, bvi, shg, 0);
1420 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1423 BAD_RX_SW_IF_INDEX_LABEL;
1425 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1429 vl_api_bridge_domain_add_del_t_handler (
1430 vl_api_bridge_domain_add_del_t *mp)
1432 vlib_main_t * vm = vlib_get_main ();
1433 bd_main_t * bdm = &bd_main;
1434 vl_api_bridge_domain_add_del_reply_t * rmp;
1436 u32 enable_flags = 0, disable_flags = 0;
1437 u32 bd_id = ntohl(mp->bd_id);
1441 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1444 enable_flags |= L2_FLOOD;
1446 disable_flags |= L2_FLOOD;
1449 enable_flags |= L2_UU_FLOOD;
1451 disable_flags |= L2_UU_FLOOD;
1454 enable_flags |= L2_FWD;
1456 disable_flags |= L2_FWD;
1459 enable_flags |= L2_ARP_TERM;
1461 disable_flags |= L2_ARP_TERM;
1464 enable_flags |= L2_LEARN;
1466 disable_flags |= L2_LEARN;
1469 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1472 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1475 rv = bd_delete_bd_index(bdm, bd_id);
1477 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1480 static void vl_api_bridge_domain_details_t_handler (
1481 vl_api_bridge_domain_details_t * mp)
1483 clib_warning ("BUG");
1486 static void vl_api_bridge_domain_sw_if_details_t_handler (
1487 vl_api_bridge_domain_sw_if_details_t * mp)
1489 clib_warning ("BUG");
1492 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1493 l2_bridge_domain_t * bd_config,
1496 vl_api_bridge_domain_details_t * mp;
1498 mp = vl_msg_api_alloc (sizeof (*mp));
1499 memset (mp, 0, sizeof (*mp));
1500 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1501 mp->bd_id = ntohl (bd_config->bd_id);
1502 mp->flood = bd_feature_flood (bd_config);
1503 mp->uu_flood = bd_feature_uu_flood (bd_config);
1504 mp->forward = bd_feature_forward (bd_config);
1505 mp->learn = bd_feature_learn (bd_config);
1506 mp->arp_term = bd_feature_arp_term (bd_config);
1507 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1508 mp->n_sw_ifs = ntohl (n_sw_ifs);
1510 vl_msg_api_send_shmem (q, (u8 *)&mp);
1513 static void send_bd_sw_if_details (l2input_main_t * l2im,
1514 unix_shared_memory_queue_t *q,
1515 l2_flood_member_t * member, u32 bd_id)
1517 vl_api_bridge_domain_sw_if_details_t * mp;
1518 l2_input_config_t * input_cfg;
1520 mp = vl_msg_api_alloc (sizeof (*mp));
1521 memset (mp, 0, sizeof (*mp));
1522 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1523 mp->bd_id = ntohl (bd_id);
1524 mp->sw_if_index = ntohl (member->sw_if_index);
1525 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1526 mp->shg = input_cfg->shg;
1528 vl_msg_api_send_shmem (q, (u8 *)&mp);
1531 static void vl_api_bridge_domain_dump_t_handler (
1532 vl_api_bridge_domain_dump_t *mp)
1534 bd_main_t * bdm = &bd_main;
1535 l2input_main_t * l2im = &l2input_main;
1536 unix_shared_memory_queue_t * q;
1537 l2_bridge_domain_t * bd_config;
1538 u32 bd_id, bd_index;
1541 q = vl_api_client_index_to_input_queue (mp->client_index);
1546 bd_id = ntohl(mp->bd_id);
1548 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1549 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1550 for (; bd_index < end; bd_index++) {
1551 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1552 /* skip dummy bd_id 0 */
1553 if (bd_config && (bd_config->bd_id > 0)) {
1555 l2_flood_member_t * m;
1557 n_sw_ifs = vec_len (bd_config->members);
1558 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1560 vec_foreach (m, bd_config->members) {
1561 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1568 vl_api_l2fib_add_del_t_handler (
1569 vl_api_l2fib_add_del_t *mp)
1571 bd_main_t * bdm = &bd_main;
1572 l2input_main_t * l2im = &l2input_main;
1573 vl_api_l2fib_add_del_reply_t * rmp;
1576 u32 sw_if_index = ntohl(mp->sw_if_index);
1577 u32 bd_id = ntohl(mp->bd_id);
1585 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1587 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1588 goto bad_sw_if_index;
1593 VALIDATE_SW_IF_INDEX(mp);
1594 if (vec_len(l2im->configs) <= sw_if_index) {
1595 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1596 goto bad_sw_if_index;
1598 l2_input_config_t * config;
1599 config = vec_elt_at_index(l2im->configs, sw_if_index);
1600 if (config->bridge == 0) {
1601 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1602 goto bad_sw_if_index;
1605 static_mac = mp->static_mac ? 1 : 0;
1606 filter_mac = mp->filter_mac ? 1 : 0;
1607 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1610 l2fib_del_entry(mac, bd_index);
1613 BAD_SW_IF_INDEX_LABEL;
1615 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1619 vl_api_l2_flags_t_handler (
1620 vl_api_l2_flags_t *mp)
1622 vl_api_l2_flags_reply_t * rmp;
1624 u32 sw_if_index = ntohl(mp->sw_if_index);
1625 u32 flags = ntohl(mp->feature_bitmap);
1628 VALIDATE_SW_IF_INDEX(mp);
1631 if (flags & L2INPUT_FEAT_ ## a) \
1632 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1633 foreach_l2input_feat;
1636 BAD_SW_IF_INDEX_LABEL;
1638 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1642 vl_api_bridge_flags_t_handler (
1643 vl_api_bridge_flags_t *mp)
1645 vlib_main_t *vm = vlib_get_main();
1646 bd_main_t * bdm = &bd_main;
1647 vl_api_bridge_flags_reply_t * rmp;
1649 u32 bd_id = ntohl(mp->bd_id);
1651 u32 flags = ntohl(mp->feature_bitmap);
1654 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1656 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1662 bd_set_flags(vm, bd_index, flags, mp->is_set);
1665 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1666 rmp->resulting_feature_bitmap = ntohl(flags));
1670 vl_api_bd_ip_mac_add_del_t_handler (
1671 vl_api_bd_ip_mac_add_del_t *mp)
1673 bd_main_t * bdm = &bd_main;
1674 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1676 u32 bd_id = ntohl(mp->bd_id);
1680 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1682 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1687 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1688 mp->mac_address, mp->is_ipv6, mp->is_add))
1689 rv = VNET_API_ERROR_UNSPECIFIED;
1692 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1696 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1699 vl_api_tap_connect_reply_t * rmp;
1700 unix_shared_memory_queue_t * q;
1701 u32 sw_if_index = (u32)~0;
1703 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1704 mp->use_random_mac ? 0 : mp->mac_address,
1705 &sw_if_index, mp->renumber,
1706 ntohl(mp->custom_dev_instance));
1708 q = vl_api_client_index_to_input_queue (mp->client_index);
1712 rmp = vl_msg_api_alloc (sizeof (*rmp));
1713 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1714 rmp->context = mp->context;
1715 rmp->retval = ntohl(rv);
1716 rmp->sw_if_index = ntohl(sw_if_index);
1718 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1722 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1725 vl_api_tap_modify_reply_t * rmp;
1726 unix_shared_memory_queue_t * q;
1727 u32 sw_if_index = (u32)~0;
1729 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1730 mp->use_random_mac ? 0 : mp->mac_address,
1731 &sw_if_index, mp->renumber,
1732 ntohl(mp->custom_dev_instance));
1734 q = vl_api_client_index_to_input_queue (mp->client_index);
1738 rmp = vl_msg_api_alloc (sizeof (*rmp));
1739 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1740 rmp->context = mp->context;
1741 rmp->retval = ntohl(rv);
1742 rmp->sw_if_index = ntohl(sw_if_index);
1744 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1748 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1751 vpe_api_main_t * vam = &vpe_api_main;
1752 vl_api_tap_delete_reply_t * rmp;
1753 unix_shared_memory_queue_t * q;
1754 u32 sw_if_index = ntohl(mp->sw_if_index);
1756 rv = vnet_tap_delete (vm, sw_if_index);
1758 q = vl_api_client_index_to_input_queue (mp->client_index);
1762 rmp = vl_msg_api_alloc (sizeof (*rmp));
1763 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1764 rmp->context = mp->context;
1765 rmp->retval = ntohl(rv);
1767 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1770 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1774 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1776 vl_api_create_vlan_subif_reply_t * rmp;
1777 vnet_main_t * vnm = vnet_get_main();
1778 u32 hw_if_index, sw_if_index = (u32)~0;
1779 vnet_hw_interface_t * hi;
1782 vnet_sw_interface_t template;
1784 vnet_interface_main_t * im = &vnm->interface_main;
1785 u64 sup_and_sub_key;
1787 unix_shared_memory_queue_t * q;
1788 clib_error_t * error;
1790 VALIDATE_SW_IF_INDEX(mp);
1792 hw_if_index = ntohl(mp->sw_if_index);
1793 hi = vnet_get_hw_interface (vnm, hw_if_index);
1795 id = ntohl(mp->vlan_id);
1796 if (id == 0 || id > 4095) {
1797 rv = VNET_API_ERROR_INVALID_VLAN;
1801 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1803 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1805 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1809 kp = clib_mem_alloc (sizeof (*kp));
1810 *kp = sup_and_sub_key;
1812 memset (&template, 0, sizeof (template));
1813 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1814 template.sup_sw_if_index = hi->sw_if_index;
1815 template.sub.id = id;
1816 template.sub.eth.raw_flags = 0;
1817 template.sub.eth.flags.one_tag = 1;
1818 template.sub.eth.outer_vlan_id = id;
1819 template.sub.eth.flags.exact_match = 1;
1821 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1823 clib_error_report(error);
1824 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1827 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1828 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1830 BAD_SW_IF_INDEX_LABEL;
1833 q = vl_api_client_index_to_input_queue (mp->client_index);
1837 rmp = vl_msg_api_alloc (sizeof (*rmp));
1838 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1839 rmp->context = mp->context;
1840 rmp->retval = ntohl(rv);
1841 rmp->sw_if_index = ntohl(sw_if_index);
1842 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1846 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1848 vl_api_create_subif_reply_t * rmp;
1849 vnet_main_t * vnm = vnet_get_main();
1850 u32 sw_if_index = ~0;
1853 vnet_sw_interface_t *si;
1854 vnet_hw_interface_t *hi;
1855 vnet_sw_interface_t template;
1857 vnet_interface_main_t * im = &vnm->interface_main;
1858 u64 sup_and_sub_key;
1860 clib_error_t * error;
1862 VALIDATE_SW_IF_INDEX(mp);
1864 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1865 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1867 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1868 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1872 sw_if_index = si->sw_if_index;
1873 sub_id = ntohl(mp->sub_id);
1875 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1877 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1880 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1881 sw_if_index, sub_id);
1882 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1886 kp = clib_mem_alloc (sizeof (*kp));
1887 *kp = sup_and_sub_key;
1889 memset (&template, 0, sizeof (template));
1890 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1891 template.sup_sw_if_index = sw_if_index;
1892 template.sub.id = sub_id;
1893 template.sub.eth.flags.no_tags = mp->no_tags;
1894 template.sub.eth.flags.one_tag = mp->one_tag;
1895 template.sub.eth.flags.two_tags = mp->two_tags;
1896 template.sub.eth.flags.dot1ad = mp->dot1ad;
1897 template.sub.eth.flags.exact_match = mp->exact_match;
1898 template.sub.eth.flags.default_sub = mp->default_sub;
1899 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1900 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1901 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1902 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1904 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1906 clib_error_report (error);
1907 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1911 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1912 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1914 BAD_SW_IF_INDEX_LABEL;
1918 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1920 rmp->sw_if_index = ntohl(sw_if_index);
1925 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1927 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1929 stats_main_t * sm = &stats_main;
1930 u32 tunnel_sw_if_index = ~0;
1932 dslock (sm, 1 /* release hint */, 5 /* tag */);
1934 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1935 (ip4_address_t *)(mp->dst_address),
1936 (ip4_address_t *)(mp->intfc_address),
1937 (u32)(mp->intfc_address_length),
1938 ntohl(mp->inner_vrf_id),
1939 ntohl(mp->outer_vrf_id),
1940 &tunnel_sw_if_index,
1945 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1947 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1952 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1953 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1955 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1957 stats_main_t * sm = &stats_main;
1958 u32 tunnel_sw_if_index;
1960 dslock (sm, 1 /* release hint */, 5 /* tag */);
1962 rv = vnet_mpls_ethernet_add_del_tunnel
1963 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1964 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1965 ntohl(mp->tx_sw_if_index),
1966 &tunnel_sw_if_index,
1972 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1974 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1979 * This piece of misery brought to you because the control-plane
1980 * can't figure out the tx interface + dst-mac address all by itself
1982 static int mpls_ethernet_add_del_tunnel_2_t_handler
1983 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1985 pending_route_t * pr;
1986 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1987 vnet_main_t * vnm = vnet_get_main();
1988 vlib_main_t * vm = vlib_get_main();
1989 stats_main_t * sm = &stats_main;
1990 vpe_api_main_t * vam = &vpe_api_main;
1991 u32 inner_fib_index, outer_fib_index;
1992 ip4_main_t * im = &ip4_main;
1993 ip_lookup_main_t * lm = &im->lookup_main;
1994 ip_adjacency_t * adj = 0;
1997 u8 * dst_mac_address;
2001 u32 tunnel_sw_if_index;
2003 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2005 return VNET_API_ERROR_NO_SUCH_FIB;
2007 outer_fib_index = p[0];
2010 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2012 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2014 inner_fib_index = p[0];
2016 if (inner_fib_index == outer_fib_index)
2017 return VNET_API_ERROR_INVALID_VALUE;
2019 lookup_result = ip4_fib_lookup_with_table
2020 (im, outer_fib_index,
2021 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2022 1 /* disable default route */);
2024 adj = ip_get_adjacency (lm, lookup_result);
2025 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2027 if (mp->is_add && mp->resolve_if_needed) {
2028 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2029 pool_get (vam->pending_routes, pr);
2030 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2032 memcpy (pme, mp, sizeof (*pme));
2033 /* recursion block, "just in case" */
2034 pme->resolve_if_needed = 0;
2035 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2036 pme->resolve_opaque = tx_sw_if_index;
2037 vnet_register_ip4_arp_resolution_event
2039 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2040 vpe_resolver_process_node.index,
2041 RESOLUTION_EVENT, pr - vam->pending_routes);
2043 vlib_process_signal_event
2044 (vm, vpe_resolver_process_node.index,
2045 RESOLUTION_PENDING_EVENT, 0 /* data */);
2047 /* The interface may be down, etc. */
2048 e = ip4_probe_neighbor
2049 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2053 clib_error_report(e);
2055 return VNET_API_ERROR_IN_PROGRESS;
2059 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2060 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2063 vnet_rewrite_get_data_internal
2064 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2066 dslock (sm, 1 /* release hint */, 10 /* tag */);
2068 rv = vnet_mpls_ethernet_add_del_tunnel
2069 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2070 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2071 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2079 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2080 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2082 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2085 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2087 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2092 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2094 vl_api_mpls_add_del_encap_reply_t * rmp;
2096 static u32 * labels;
2099 vec_reset_length (labels);
2101 for (i = 0; i < mp->nlabels; i++)
2102 vec_add1 (labels, ntohl(mp->labels[i]));
2105 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2106 ntohl(mp->vrf_id), labels,
2107 ~0 /* policy_tunnel_index */,
2108 0 /* no_dst_hash */,
2112 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2116 vl_api_mpls_add_del_decap_t_handler
2117 (vl_api_mpls_add_del_decap_t *mp)
2119 vl_api_mpls_add_del_decap_reply_t * rmp;
2122 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2123 ntohl(mp->label), ntohl(mp->next_index),
2124 mp->s_bit, mp->is_add);
2126 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2130 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2132 vl_api_proxy_arp_add_del_reply_t * rmp;
2135 ip4_main_t * im = &ip4_main;
2136 stats_main_t * sm = &stats_main;
2137 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2138 ip4_address_t *hi_addr,
2139 u32 fib_index, int is_del);
2142 dslock (sm, 1 /* release hint */, 6 /* tag */);
2144 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2147 rv = VNET_API_ERROR_NO_SUCH_FIB;
2153 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2154 (ip4_address_t *)mp->hi_address,
2155 fib_index, mp->is_add == 0);
2159 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2163 vl_api_proxy_arp_intfc_enable_disable_t_handler
2164 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2167 vnet_main_t * vnm = vnet_get_main();
2168 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2169 vnet_sw_interface_t * si;
2172 VALIDATE_SW_IF_INDEX(mp);
2174 sw_if_index = ntohl(mp->sw_if_index);
2176 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2178 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2182 si = vnet_get_sw_interface (vnm, sw_if_index);
2186 if (mp->enable_disable)
2187 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2189 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2191 BAD_SW_IF_INDEX_LABEL;
2194 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2198 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2200 vl_api_ip_neighbor_add_del_reply_t * rmp;
2201 vnet_main_t * vnm = vnet_get_main();
2204 stats_main_t * sm = &stats_main;
2206 VALIDATE_SW_IF_INDEX(mp);
2208 dslock (sm, 1 /* release hint */, 7 /* tag */);
2212 rv = vnet_set_ip6_ethernet_neighbor
2213 (vm, ntohl(mp->sw_if_index),
2214 (ip6_address_t *)(mp->dst_address),
2215 mp->mac_address, sizeof (mp->mac_address));
2217 rv = vnet_unset_ip6_ethernet_neighbor
2218 (vm, ntohl(mp->sw_if_index),
2219 (ip6_address_t *)(mp->dst_address),
2220 mp->mac_address, sizeof(mp->mac_address));
2222 ip4_main_t * im = &ip4_main;
2223 ip_lookup_main_t * lm = &im->lookup_main;
2224 ethernet_arp_ip4_over_ethernet_address_t a;
2226 ip_adjacency_t *nh_adj;
2228 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2230 rv = VNET_API_ERROR_NO_SUCH_FIB;
2236 * Unfortunately, folks have a penchant for
2237 * adding interface addresses to the ARP cache, and
2238 * wondering why the forwarder eventually ASSERTs...
2240 ai = ip4_fib_lookup_with_table
2241 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2242 1 /* disable default route */);
2245 nh_adj = ip_get_adjacency (lm, ai);
2246 /* Never allow manipulation of a local adj! */
2247 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2248 clib_warning("%U matches local adj",
2250 (ip4_address_t *)(mp->dst_address));
2251 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2256 memcpy (&a.ethernet, mp->mac_address, 6);
2257 memcpy (&a.ip4, mp->dst_address, 4);
2260 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2261 fib_index, &a, mp->is_static);
2263 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2267 BAD_SW_IF_INDEX_LABEL;
2270 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2274 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2277 vpe_main_t *rm = &vpe_main;
2278 ip4_main_t *im4 = &ip4_main;
2279 ip6_main_t *im6 = &ip6_main;
2280 ip_lookup_main_t * lm;
2285 u32 adj_index, sw_if_index;
2286 vl_api_is_address_reachable_t *rmp;
2287 ip_adjacency_t * adj;
2288 unix_shared_memory_queue_t *q;
2290 q = vl_api_client_index_to_input_queue (mp->client_index);
2292 increment_missing_api_client_counter (rm->vlib_main);
2296 rmp = vl_msg_api_alloc (sizeof (*rmp));
2297 memcpy (rmp, mp, sizeof (*rmp));
2299 sw_if_index = mp->next_hop_sw_if_index;
2300 memcpy (&addr, mp->address, sizeof (addr));
2302 lm = &im6->lookup_main;
2304 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2306 lm = &im4->lookup_main;
2308 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2310 if (adj_index == ~0) {
2314 adj = ip_get_adjacency (lm, adj_index);
2316 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2317 && adj->rewrite_header.sw_if_index == sw_if_index) {
2320 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2321 && adj->rewrite_header.sw_if_index == sw_if_index) {
2323 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2325 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2326 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2334 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2338 static void vl_api_sw_interface_details_t_handler (
2339 vl_api_sw_interface_details_t * mp)
2341 clib_warning ("BUG");
2344 static void vl_api_sw_interface_set_flags_t_handler (
2345 vl_api_sw_interface_set_flags_t * mp)
2347 vl_api_sw_interface_set_flags_reply_t *rmp;
2348 vnet_main_t * vnm = vnet_get_main();
2350 clib_error_t * error;
2353 VALIDATE_SW_IF_INDEX(mp);
2355 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2357 error = vnet_sw_interface_set_flags (vnm,
2358 ntohl(mp->sw_if_index),
2362 clib_error_report (error);
2365 BAD_SW_IF_INDEX_LABEL;
2366 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2369 static void vl_api_sw_interface_clear_stats_t_handler (
2370 vl_api_sw_interface_clear_stats_t * mp)
2372 vl_api_sw_interface_clear_stats_reply_t *rmp;
2374 vnet_main_t * vnm = vnet_get_main();
2375 vnet_interface_main_t * im = &vnm->interface_main;
2376 vlib_simple_counter_main_t * sm;
2377 vlib_combined_counter_main_t * cm;
2378 static vnet_main_t ** my_vnet_mains;
2379 int i, j, n_counters;
2383 vec_reset_length (my_vnet_mains);
2385 for (i = 0; i < vec_len (vnet_mains); i++)
2388 vec_add1 (my_vnet_mains, vnet_mains[i]);
2391 if (vec_len (vnet_mains) == 0)
2392 vec_add1 (my_vnet_mains, vnm);
2394 n_counters = vec_len (im->combined_sw_if_counters);
2396 for (j = 0; j < n_counters; j++)
2398 for (i = 0; i < vec_len(my_vnet_mains); i++)
2400 im = &my_vnet_mains[i]->interface_main;
2401 cm = im->combined_sw_if_counters + j;
2402 if (mp->sw_if_index == (u32)~0)
2403 vlib_clear_combined_counters (cm);
2405 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2409 n_counters = vec_len (im->sw_if_counters);
2411 for (j = 0; j < n_counters; j++)
2413 for (i = 0; i < vec_len(my_vnet_mains); i++)
2415 im = &my_vnet_mains[i]->interface_main;
2416 sm = im->sw_if_counters + j;
2417 if (mp->sw_if_index == (u32)~0)
2418 vlib_clear_simple_counters (sm);
2420 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2424 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2427 static void send_sw_interface_details (vpe_api_main_t * am,
2428 unix_shared_memory_queue_t *q,
2429 vnet_sw_interface_t * swif,
2430 u8 * interface_name)
2432 vl_api_sw_interface_details_t * mp;
2433 vnet_hw_interface_t * hi;
2435 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2437 mp = vl_msg_api_alloc (sizeof (*mp));
2438 memset (mp, 0, sizeof (*mp));
2439 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2440 mp->sw_if_index = ntohl(swif->sw_if_index);
2441 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2442 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2444 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2446 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2447 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2448 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2449 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2450 mp->link_mtu = ntohs(hi->max_packet_bytes);
2452 strncpy ((char *) mp->interface_name,
2453 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2455 /* Send the L2 address for ethernet physical intfcs */
2456 if (swif->sup_sw_if_index == swif->sw_if_index
2457 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2458 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2459 ethernet_interface_t *ei;
2461 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2462 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2463 memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2464 mp->l2_address_length = ntohl(sizeof (ei->address));
2465 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2466 vnet_sub_interface_t *sub = &swif->sub;
2467 mp->sub_id = ntohl(sub->id);
2468 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2469 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2470 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2471 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2472 mp->sub_exact_match = sub->eth.flags.exact_match;
2473 mp->sub_default = sub->eth.flags.default_sub;
2474 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2475 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2477 /* vlan tag rewrite data */
2478 u32 vtr_op = L2_VTR_DISABLED;
2479 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2481 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2482 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2483 // error - default to disabled
2484 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2485 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2488 mp->vtr_op = ntohl(vtr_op);
2489 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2490 mp->vtr_tag1 = ntohl(vtr_tag1);
2491 mp->vtr_tag2 = ntohl(vtr_tag2);
2495 vl_msg_api_send_shmem (q, (u8 *)&mp);
2498 static void send_sw_interface_flags (vpe_api_main_t * am,
2499 unix_shared_memory_queue_t *q,
2500 vnet_sw_interface_t * swif)
2502 vl_api_sw_interface_set_flags_t *mp;
2503 vnet_main_t * vnm = am->vnet_main;
2505 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2507 mp = vl_msg_api_alloc (sizeof (*mp));
2508 memset (mp, 0, sizeof (*mp));
2509 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2510 mp->sw_if_index = ntohl(swif->sw_if_index);
2512 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2514 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2516 vl_msg_api_send_shmem (q, (u8 *)&mp);
2519 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2520 unix_shared_memory_queue_t *q,
2522 __attribute__((unused));
2524 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2525 unix_shared_memory_queue_t *q,
2528 vl_api_sw_interface_set_flags_t *mp;
2530 mp = vl_msg_api_alloc (sizeof (*mp));
2531 memset (mp, 0, sizeof (*mp));
2532 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2533 mp->sw_if_index = ntohl(sw_if_index);
2535 mp->admin_up_down = 0;
2536 mp->link_up_down = 0;
2538 vl_msg_api_send_shmem (q, (u8 *)&mp);
2541 static void vl_api_sw_interface_dump_t_handler (
2542 vl_api_sw_interface_dump_t *mp)
2544 vpe_api_main_t * am = &vpe_api_main;
2545 vnet_sw_interface_t * swif;
2546 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2547 u8 * filter_string = 0, * name_string = 0;
2548 unix_shared_memory_queue_t * q;
2549 char * strcasestr (char *, char *); /* lnx hdr file botch */
2551 q = vl_api_client_index_to_input_queue (mp->client_index);
2556 if (mp->name_filter_valid) {
2557 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2558 filter_string = format (0, "%s%c", mp->name_filter, 0);
2561 pool_foreach (swif, im->sw_interfaces,
2563 name_string = format (name_string, "%U%c",
2564 format_vnet_sw_interface_name,
2565 am->vnet_main, swif, 0);
2567 if (mp->name_filter_valid == 0 ||
2568 strcasestr((char *) name_string, (char *) filter_string)) {
2570 send_sw_interface_details (am, q, swif, name_string);
2571 send_sw_interface_flags (am, q, swif);
2573 _vec_len (name_string) = 0;
2576 vec_free (name_string);
2577 vec_free (filter_string);
2580 void send_oam_event (oam_target_t * t)
2582 vpe_api_main_t * vam = &vpe_api_main;
2583 unix_shared_memory_queue_t * q;
2584 vpe_client_registration_t *reg;
2585 vl_api_oam_event_t * mp;
2587 pool_foreach(reg, vam->oam_events_registrations,
2589 q = vl_api_client_index_to_input_queue (reg->client_index);
2591 mp = vl_msg_api_alloc (sizeof (*mp));
2592 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2593 memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2594 mp->state = t->state;
2595 vl_msg_api_send_shmem (q, (u8 *)&mp);
2601 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2603 vl_api_oam_add_del_reply_t * rmp;
2606 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2607 (ip4_address_t *)mp->dst_address,
2611 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2615 vl_api_vnet_get_summary_stats_t_handler (
2616 vl_api_vnet_get_summary_stats_t *mp)
2618 stats_main_t * sm = &stats_main;
2619 vnet_interface_main_t * im = sm->interface_main;
2620 vl_api_vnet_summary_stats_reply_t *rmp;
2621 vlib_combined_counter_main_t * cm;
2624 u64 total_pkts[VLIB_N_RX_TX];
2625 u64 total_bytes[VLIB_N_RX_TX];
2627 unix_shared_memory_queue_t * q =
2628 vl_api_client_index_to_input_queue (mp->client_index);
2633 rmp = vl_msg_api_alloc (sizeof (*rmp));
2634 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2635 rmp->context = mp->context;
2638 memset (total_pkts, 0, sizeof (total_pkts));
2639 memset (total_bytes, 0, sizeof (total_bytes));
2641 vnet_interface_counter_lock (im);
2643 vec_foreach (cm, im->combined_sw_if_counters) {
2644 which = cm - im->combined_sw_if_counters;
2646 for (i = 0; i < vec_len (cm->maxi); i++) {
2647 vlib_get_combined_counter (cm, i, &v);
2648 total_pkts[which] += v.packets;
2649 total_bytes[which] += v.bytes;
2652 vnet_interface_counter_unlock (im);
2654 /* Note: in HOST byte order! */
2655 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2656 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2657 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2658 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2659 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2661 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2664 typedef CLIB_PACKED (struct {
2665 ip4_address_t address;
2667 u32 address_length : 6;
2672 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2674 vnet_main_t * vnm = vnet_get_main();
2675 vnet_interface_main_t * im = &vnm->interface_main;
2676 ip4_main_t * im4 = &ip4_main;
2677 static ip4_route_t * routes;
2678 static u32 * sw_if_indices_to_shut;
2679 stats_main_t * sm = &stats_main;
2684 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2685 u32 target_fib_id = ntohl(mp->vrf_id);
2687 dslock (sm, 1 /* release hint */, 8 /* tag */);
2689 vec_foreach (fib, im4->fibs) {
2690 vnet_sw_interface_t * si;
2692 if (fib->table_id != target_fib_id)
2695 /* remove any mpls/gre tunnels in this fib */
2696 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2698 /* remove any mpls encap/decap labels */
2699 mpls_fib_reset_labels (fib->table_id);
2701 /* remove any proxy arps in this fib */
2702 vnet_proxy_arp_fib_reset (fib->table_id);
2704 /* Set the flow hash for this fib to the default */
2705 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2707 vec_reset_length (sw_if_indices_to_shut);
2709 /* Shut down interfaces in this FIB / clean out intfc routes */
2710 pool_foreach (si, im->sw_interfaces,
2712 u32 sw_if_index = si->sw_if_index;
2714 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2715 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2717 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2720 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2721 sw_if_index = sw_if_indices_to_shut[i];
2722 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2724 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2725 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2726 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2729 vec_reset_length (routes);
2731 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2732 uword * hash = fib->adj_index_by_dst_address[i];
2736 x.address_length = i;
2738 hash_foreach_pair (p, hash,
2740 x.address.data_u32 = p->key;
2741 vec_add1 (routes, x);
2745 vec_foreach (r, routes) {
2746 ip4_add_del_route_args_t a;
2748 memset (&a, 0, sizeof (a));
2749 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2750 a.table_index_or_table_id = fib - im4->fibs;
2751 a.dst_address = r->address;
2752 a.dst_address_length = r->address_length;
2755 ip4_add_del_route (im4, &a);
2756 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2757 IP4_ROUTE_FLAG_FIB_INDEX);
2761 } /* vec_foreach (fib) */
2768 ip6_address_t address;
2775 ip6_route_t ** routep;
2776 } add_routes_in_fib_arg_t;
2778 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2780 add_routes_in_fib_arg_t * ap = arg;
2782 if (kvp->key[2]>>32 == ap->fib_index)
2784 ip6_address_t *addr;
2786 addr = (ip6_address_t *) kvp;
2787 vec_add2 (*ap->routep, r, 1);
2788 r->address = addr[0];
2789 r->address_length = kvp->key[2] & 0xFF;
2790 r->index = kvp->value;
2794 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2796 vnet_main_t * vnm = vnet_get_main();
2797 vnet_interface_main_t * im = &vnm->interface_main;
2798 ip6_main_t * im6 = &ip6_main;
2799 stats_main_t * sm = &stats_main;
2800 static ip6_route_t * routes;
2801 static u32 * sw_if_indices_to_shut;
2806 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2807 u32 target_fib_id = ntohl(mp->vrf_id);
2808 add_routes_in_fib_arg_t _a, *a=&_a;
2809 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2811 dslock (sm, 1 /* release hint */, 9 /* tag */);
2813 vec_foreach (fib, im6->fibs) {
2814 vnet_sw_interface_t * si;
2816 if (fib->table_id != target_fib_id)
2819 vec_reset_length (sw_if_indices_to_shut);
2821 /* Shut down interfaces in this FIB / clean out intfc routes */
2822 pool_foreach (si, im->sw_interfaces,
2824 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2826 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2829 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2830 sw_if_index = sw_if_indices_to_shut[i];
2831 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2833 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2834 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2835 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2838 vec_reset_length (routes);
2840 a->fib_index = fib - im6->fibs;
2841 a->routep = &routes;
2843 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2845 vec_foreach (r, routes) {
2846 ip6_add_del_route_args_t a;
2848 memset (&a, 0, sizeof (a));
2849 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2850 a.table_index_or_table_id = fib - im6->fibs;
2851 a.dst_address = r->address;
2852 a.dst_address_length = r->address_length;
2855 ip6_add_del_route (im6, &a);
2856 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2857 IP6_ROUTE_FLAG_FIB_INDEX);
2860 /* Reinstall the neighbor / router discovery routes */
2861 vnet_ip6_fib_init (im6, fib - im6->fibs);
2863 } /* vec_foreach (fib) */
2869 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2872 vl_api_reset_fib_reply_t * rmp;
2875 rv = ip6_reset_fib_t_handler (mp);
2877 rv = ip4_reset_fib_t_handler (mp);
2879 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2884 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2886 vl_api_dhcp_proxy_config_reply_t * rmp;
2889 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2890 (ip4_address_t *)(&mp->dhcp_src_address),
2891 (u32) ntohl(mp->vrf_id),
2892 (int) mp->insert_circuit_id,
2893 (int) (mp->is_add == 0));
2895 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2900 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2902 vl_api_dhcp_proxy_config_reply_t * rmp;
2905 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2906 (ip6_address_t *)(&mp->dhcp_src_address),
2907 (u32) ntohl(mp->vrf_id),
2908 (int) mp->insert_circuit_id,
2909 (int) (mp->is_add == 0));
2911 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2915 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2917 vl_api_dhcp_proxy_config_reply_t * rmp;
2920 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2921 (ip4_address_t *)(&mp->dhcp_src_address),
2922 (u32) ntohl(mp->rx_vrf_id),
2923 (u32) ntohl(mp->server_vrf_id),
2924 (int) mp->insert_circuit_id,
2925 (int) (mp->is_add == 0));
2927 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2932 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2934 vl_api_dhcp_proxy_config_reply_t * rmp;
2938 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2939 (ip6_address_t *)(&mp->dhcp_src_address),
2940 (u32) ntohl(mp->rx_vrf_id),
2941 (u32) ntohl(mp->server_vrf_id),
2942 (int) mp->insert_circuit_id,
2943 (int) (mp->is_add == 0));
2945 rv = VNET_API_ERROR_UNIMPLEMENTED;
2948 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2953 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2955 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2958 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2961 (int)mp->is_add == 0);
2963 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2966 (int)mp->is_add == 0);
2968 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2972 static void vl_api_dhcp_proxy_config_t_handler
2973 (vl_api_dhcp_proxy_config_t *mp)
2975 if (mp->is_ipv6 == 0)
2976 dhcpv4_proxy_config (mp);
2978 dhcpv6_proxy_config (mp);
2981 static void vl_api_dhcp_proxy_config_2_t_handler
2982 (vl_api_dhcp_proxy_config_2_t *mp)
2984 if (mp->is_ipv6 == 0)
2985 dhcpv4_proxy_config_2 (mp);
2987 dhcpv6_proxy_config_2 (mp);
2990 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2991 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
2993 unix_shared_memory_queue_t * q;
2994 vl_api_dhcp_compl_event_t * mp;
2996 q = vl_api_client_index_to_input_queue (client_index);
3000 mp = vl_msg_api_alloc (sizeof (*mp));
3001 mp->client_index = client_index;
3003 mp->is_ipv6 = is_ipv6;
3004 memcpy (&mp->hostname, hostname, vec_len(hostname));
3005 mp->hostname[vec_len(hostname) + 1] = '\n';
3006 memcpy (&mp->host_address[0], host_address, 16);
3007 memcpy (&mp->router_address[0], router_address, 16);
3008 memcpy (&mp->host_mac[0], host_mac, 6);
3010 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3012 vl_msg_api_send_shmem (q, (u8 *)&mp);
3015 static void vl_api_dhcp_client_config_t_handler
3016 (vl_api_dhcp_client_config_t *mp)
3018 vlib_main_t *vm = vlib_get_main();
3019 vl_api_dhcp_client_config_reply_t * rmp;
3022 VALIDATE_SW_IF_INDEX(mp);
3024 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3025 mp->hostname, mp->is_add, mp->client_index,
3026 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3029 BAD_SW_IF_INDEX_LABEL;
3031 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3035 vl_api_sw_interface_ip6nd_ra_config_t_handler
3036 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3038 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3040 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3042 is_no = mp->is_no == 1;
3043 surpress = mp->surpress == 1;
3044 managed = mp->managed == 1;
3045 other = mp->other == 1;
3046 ll_option = mp->ll_option == 1;
3047 send_unicast = mp->send_unicast == 1;
3048 cease = mp->cease == 1;
3049 default_router = mp->default_router == 1;
3051 VALIDATE_SW_IF_INDEX(mp);
3053 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3054 surpress, managed, other,
3055 ll_option, send_unicast, cease,
3056 default_router, ntohl (mp->lifetime),
3057 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3058 ntohl(mp->max_interval), ntohl( mp->min_interval),
3061 BAD_SW_IF_INDEX_LABEL;
3063 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3067 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3068 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3070 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3072 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3074 VALIDATE_SW_IF_INDEX(mp);
3076 is_no = mp->is_no == 1;
3077 use_default = mp->use_default == 1;
3078 no_advertise = mp->no_advertise == 1;
3079 off_link = mp->off_link == 1;
3080 no_autoconfig = mp->no_autoconfig == 1;
3081 no_onlink = mp->no_onlink == 1;
3083 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3084 (ip6_address_t *)mp->address, mp->address_length,
3085 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3086 no_advertise, off_link, no_autoconfig, no_onlink,
3089 BAD_SW_IF_INDEX_LABEL;
3090 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3094 vl_api_sw_interface_ip6_enable_disable_t_handler
3095 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3097 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3098 vnet_main_t * vnm = vnet_get_main();
3100 clib_error_t * error;
3104 VALIDATE_SW_IF_INDEX(mp);
3106 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3107 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3110 clib_error_report(error);
3111 rv = VNET_API_ERROR_UNSPECIFIED;
3113 rv = vnm->api_errno;
3116 BAD_SW_IF_INDEX_LABEL;
3118 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3122 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3123 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3125 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3127 clib_error_t * error;
3128 vnet_main_t * vnm = vnet_get_main();
3132 VALIDATE_SW_IF_INDEX(mp);
3134 error = set_ip6_link_local_address(vm,
3135 ntohl(mp->sw_if_index),
3136 (ip6_address_t *)mp->address,
3137 mp->address_length);
3139 clib_error_report(error);
3140 rv = VNET_API_ERROR_UNSPECIFIED;
3142 rv = vnm->api_errno;
3145 BAD_SW_IF_INDEX_LABEL;
3147 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3150 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3152 vl_api_set_ip_flow_hash_reply_t *rmp;
3153 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3155 clib_warning ("unimplemented...");
3157 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3160 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3162 vl_api_set_ip_flow_hash_reply_t *rmp;
3165 u32 flow_hash_config = 0;
3167 table_id = ntohl(mp->vrf_id);
3169 #define _(a,b) if (mp->a) flow_hash_config |= b;
3170 foreach_flow_hash_bit;
3173 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3175 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3179 static void vl_api_set_ip_flow_hash_t_handler
3180 (vl_api_set_ip_flow_hash_t *mp)
3182 if (mp->is_ipv6 == 0)
3183 set_ip4_flow_hash (mp);
3185 set_ip6_flow_hash (mp);
3188 static void vl_api_sw_interface_set_unnumbered_t_handler
3189 (vl_api_sw_interface_set_unnumbered_t *mp)
3191 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3193 vnet_sw_interface_t * si;
3194 vnet_main_t *vnm = vnet_get_main();
3195 u32 sw_if_index, unnumbered_sw_if_index;
3197 sw_if_index = ntohl(mp->sw_if_index);
3198 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3201 * The API message field names are backwards from
3202 * the underlying data structure names.
3203 * It's not worth changing them now.
3205 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3206 unnumbered_sw_if_index)) {
3207 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3211 /* Only check the "use loop0" field when setting the binding */
3213 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3214 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3218 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3221 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3222 si->unnumbered_sw_if_index = sw_if_index;
3224 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3225 si->unnumbered_sw_if_index = (u32)~0;
3229 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3232 static void vl_api_create_loopback_t_handler
3233 (vl_api_create_loopback_t *mp)
3235 vl_api_create_loopback_reply_t * rmp;
3239 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3241 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3243 rmp->sw_if_index = ntohl (sw_if_index);
3247 static void vl_api_delete_loopback_t_handler
3248 (vl_api_delete_loopback_t *mp)
3250 vl_api_delete_loopback_reply_t * rmp;
3254 sw_if_index = ntohl (mp->sw_if_index);
3255 rv = vnet_delete_loopback_interface (sw_if_index);
3257 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3260 static void vl_api_control_ping_t_handler
3261 (vl_api_control_ping_t *mp)
3263 vl_api_control_ping_reply_t * rmp;
3266 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3268 rmp->vpe_pid = ntohl (getpid());
3272 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3274 u8 **shmem_vecp = (u8 **)arg;
3277 api_main_t * am = &api_main;
3280 shmem_vec = *shmem_vecp;
3282 offset = vec_len (shmem_vec);
3284 pthread_mutex_lock (&am->vlib_rp->mutex);
3285 oldheap = svm_push_data_heap (am->vlib_rp);
3287 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3289 memcpy (shmem_vec + offset, buffer, buffer_bytes);
3291 svm_pop_heap (oldheap);
3292 pthread_mutex_unlock (&am->vlib_rp->mutex);
3294 *shmem_vecp = shmem_vec;
3298 static void vl_api_cli_request_t_handler
3299 (vl_api_cli_request_t *mp)
3301 vl_api_cli_reply_t *rp;
3302 unix_shared_memory_queue_t *q;
3303 vlib_main_t * vm = vlib_get_main();
3304 api_main_t * am = &api_main;
3305 unformat_input_t input;
3309 q = vl_api_client_index_to_input_queue (mp->client_index);
3313 rp = vl_msg_api_alloc (sizeof (*rp));
3314 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3315 rp->context = mp->context;
3317 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3319 vlib_cli_input (vm, &input, shmem_cli_output,
3322 pthread_mutex_lock (&am->vlib_rp->mutex);
3323 oldheap = svm_push_data_heap (am->vlib_rp);
3325 vec_add1(shmem_vec, 0);
3327 svm_pop_heap (oldheap);
3328 pthread_mutex_unlock (&am->vlib_rp->mutex);
3330 rp->reply_in_shmem = (uword)shmem_vec;
3332 vl_msg_api_send_shmem (q, (u8 *)&rp);
3335 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3338 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3339 vnet_main_t *vnm = vnet_get_main();
3340 clib_error_t * error;
3345 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3347 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3350 clib_error_report(error);
3351 rv = VNET_API_ERROR_UNSPECIFIED;
3353 rv = vnm->api_errno;
3356 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3359 static void vl_api_sr_tunnel_add_del_t_handler
3360 (vl_api_sr_tunnel_add_del_t *mp)
3363 clib_warning ("unimplemented");
3365 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3367 vl_api_sr_tunnel_add_del_reply_t * rmp;
3368 ip6_address_t * segments = 0, * seg;
3369 ip6_address_t * tags = 0, *tag;
3370 ip6_address_t * this_address;
3373 if (mp->n_segments == 0) {
3378 memset (a, 0, sizeof (*a));
3379 a->src_address = (ip6_address_t *)&mp->src_address;
3380 a->dst_address = (ip6_address_t *)&mp->dst_address;
3381 a->dst_mask_width = mp->dst_mask_width;
3382 a->flags_net_byte_order = mp->flags_net_byte_order;
3383 a->is_del = (mp->is_add == 0);
3384 a->rx_table_id = ntohl(mp->outer_vrf_id);
3385 a->tx_table_id = ntohl(mp->inner_vrf_id);
3387 /* Yank segments and tags out of the API message */
3388 this_address = (ip6_address_t *)mp->segs_and_tags;
3389 for (i = 0; i < mp->n_segments; i++) {
3390 vec_add2 (segments, seg, 1);
3391 memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3394 for (i = 0; i < mp->n_tags; i++) {
3395 vec_add2 (tags, tag, 1);
3396 memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3400 a->segments = segments;
3403 rv = ip6_sr_add_del_tunnel (a);
3407 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3411 #define foreach_classify_add_del_table_field \
3416 _(match_n_vectors) \
3417 _(next_table_index) \
3420 static void vl_api_classify_add_del_table_t_handler
3421 (vl_api_classify_add_del_table_t * mp)
3423 vl_api_classify_add_del_table_reply_t * rmp;
3424 vnet_classify_main_t * cm = &vnet_classify_main;
3425 vnet_classify_table_t * t;
3429 foreach_classify_add_del_table_field;
3432 #define _(a) a = ntohl(mp->a);
3433 foreach_classify_add_del_table_field;
3436 /* The underlying API fails silently, on purpose, so check here */
3437 if (mp->is_add == 0)
3438 if (pool_is_free_index (cm->tables, table_index)) {
3439 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3443 rv = vnet_classify_add_del_table
3444 (cm, mp->mask, nbuckets, memory_size,
3445 skip_n_vectors, match_n_vectors,
3446 next_table_index, miss_next_index,
3447 &table_index, mp->is_add);
3450 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3452 if (rv == 0 && mp->is_add) {
3453 t = pool_elt_at_index (cm->tables, table_index);
3454 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3455 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3456 rmp->new_table_index = ntohl(table_index);
3458 rmp->skip_n_vectors = ~0;
3459 rmp->match_n_vectors = ~0;
3460 rmp->new_table_index = ~0;
3465 static void vl_api_classify_add_del_session_t_handler
3466 (vl_api_classify_add_del_session_t * mp)
3468 vnet_classify_main_t * cm = &vnet_classify_main;
3469 vl_api_classify_add_del_session_reply_t * rmp;
3471 u32 table_index, hit_next_index, opaque_index;
3474 table_index = ntohl (mp->table_index);
3475 hit_next_index = ntohl (mp->hit_next_index);
3476 opaque_index = ntohl (mp->opaque_index);
3477 advance = ntohl (mp->advance);
3479 rv = vnet_classify_add_del_session
3480 (cm, table_index, mp->match, hit_next_index, opaque_index,
3481 advance, mp->is_add);
3483 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3486 static void vl_api_classify_set_interface_ip_table_t_handler
3487 (vl_api_classify_set_interface_ip_table_t * mp)
3489 vlib_main_t * vm = vlib_get_main();
3490 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3492 u32 table_index, sw_if_index;
3494 table_index = ntohl (mp->table_index);
3495 sw_if_index = ntohl (mp->sw_if_index);
3497 VALIDATE_SW_IF_INDEX(mp);
3500 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3502 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3504 BAD_SW_IF_INDEX_LABEL;
3506 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3509 static void vl_api_classify_set_interface_l2_tables_t_handler
3510 (vl_api_classify_set_interface_l2_tables_t * mp)
3512 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3514 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3517 ip4_table_index = ntohl(mp->ip4_table_index);
3518 ip6_table_index = ntohl(mp->ip6_table_index);
3519 other_table_index = ntohl(mp->other_table_index);
3520 sw_if_index = ntohl(mp->sw_if_index);
3522 VALIDATE_SW_IF_INDEX(mp);
3524 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3525 ip6_table_index, other_table_index);
3528 if (ip4_table_index != ~0 || ip6_table_index != ~0
3529 || other_table_index != ~0)
3534 vnet_l2_classify_enable_disable (sw_if_index, enable);
3537 BAD_SW_IF_INDEX_LABEL;
3539 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3543 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3546 vl_api_l2_fib_clear_table_reply_t * rmp;
3548 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3549 * that is not currently implemented. When that TODO is fixed
3550 * this call should be changed to pass 1 instead of 0.
3552 l2fib_clear_table (0);
3554 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3557 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3562 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3565 vl_api_l2_interface_efp_filter_reply_t * rmp;
3566 vnet_main_t *vnm = vnet_get_main();
3568 // enable/disable the feature
3569 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3570 rv = vnm->api_errno;
3572 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3576 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3579 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3580 vnet_main_t * vnm = vnet_get_main();
3581 vlib_main_t * vm = vlib_get_main();
3584 VALIDATE_SW_IF_INDEX(mp);
3586 vtr_op = ntohl(mp->vtr_op);
3588 /* The L2 code is unsuspicious */
3590 case L2_VTR_DISABLED:
3595 case L2_VTR_TRANSLATE_1_1:
3596 case L2_VTR_TRANSLATE_1_2:
3597 case L2_VTR_TRANSLATE_2_1:
3598 case L2_VTR_TRANSLATE_2_2:
3602 rv = VNET_API_ERROR_INVALID_VALUE;
3603 goto bad_sw_if_index;
3606 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3607 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3610 BAD_SW_IF_INDEX_LABEL;
3612 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3616 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3620 vl_api_create_vhost_user_if_reply_t * rmp;
3621 u32 sw_if_index = (u32)~0;
3623 vnet_main_t * vnm = vnet_get_main();
3624 vlib_main_t * vm = vlib_get_main();
3626 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3627 mp->is_server, &sw_if_index, (u64)~0,
3628 mp->renumber, ntohl(mp->custom_dev_instance),
3629 (mp->use_custom_mac)?mp->mac_address:NULL);
3631 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3633 rmp->sw_if_index = ntohl (sw_if_index);
3639 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3643 vl_api_modify_vhost_user_if_reply_t * rmp;
3644 u32 sw_if_index = ntohl(mp->sw_if_index);
3646 vnet_main_t * vnm = vnet_get_main();
3647 vlib_main_t * vm = vlib_get_main();
3649 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3650 mp->is_server, sw_if_index, (u64)~0,
3651 mp->renumber, ntohl(mp->custom_dev_instance));
3653 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3658 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3662 vpe_api_main_t * vam = &vpe_api_main;
3663 vl_api_delete_vhost_user_if_reply_t * rmp;
3664 u32 sw_if_index = ntohl(mp->sw_if_index);
3666 vnet_main_t * vnm = vnet_get_main();
3667 vlib_main_t * vm = vlib_get_main();
3669 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3671 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3673 unix_shared_memory_queue_t * q =
3674 vl_api_client_index_to_input_queue (mp->client_index);
3678 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3683 static void vl_api_sw_interface_vhost_user_details_t_handler (
3684 vl_api_sw_interface_vhost_user_details_t * mp)
3686 clib_warning ("BUG");
3690 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3691 unix_shared_memory_queue_t *q,
3692 vhost_user_intf_details_t * vui)
3694 vl_api_sw_interface_vhost_user_details_t * mp;
3696 mp = vl_msg_api_alloc (sizeof (*mp));
3697 memset (mp, 0, sizeof (*mp));
3698 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3699 mp->sw_if_index = ntohl(vui->sw_if_index);
3700 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3701 mp->features = clib_net_to_host_u64 (vui->features);
3702 mp->is_server = vui->is_server;
3703 mp->num_regions = ntohl(vui->num_regions);
3704 mp->sock_errno = ntohl(vui->sock_errno);
3706 strncpy ((char *) mp->sock_filename,
3707 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3708 strncpy ((char *) mp->interface_name,
3709 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3711 vl_msg_api_send_shmem (q, (u8 *)&mp);
3716 vl_api_sw_interface_vhost_user_dump_t_handler (
3717 vl_api_sw_interface_vhost_user_dump_t *mp)
3721 vpe_api_main_t * am = &vpe_api_main;
3722 vnet_main_t * vnm = vnet_get_main();
3723 vlib_main_t * vm = vlib_get_main();
3724 vhost_user_intf_details_t *ifaces = NULL;
3725 vhost_user_intf_details_t *vuid = NULL;
3726 unix_shared_memory_queue_t * q;
3728 q = vl_api_client_index_to_input_queue (mp->client_index);
3732 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3736 vec_foreach (vuid, ifaces) {
3737 send_sw_interface_vhost_user_details (am, q, vuid);
3743 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3744 unix_shared_memory_queue_t *q,
3748 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3749 u8 * if_name = NULL;
3750 vnet_sw_interface_t * si = NULL;
3752 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3754 if_name = format(if_name, "%U",
3755 format_vnet_sw_interface_name, lm->vnet_main, si);
3757 mp = vl_msg_api_alloc (sizeof (*mp));
3758 memset (mp, 0, sizeof (*mp));
3759 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3760 strncpy((char *)mp->interface_name,
3761 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3762 mp->sw_if_index = ntohl(si->sw_if_index);
3763 mp->local_session_id = s->local_session_id;
3764 mp->remote_session_id = s->remote_session_id;
3765 mp->local_cookie[0] = s->local_cookie[0];
3766 mp->local_cookie[1] = s->local_cookie[1];
3767 mp->remote_cookie = s->remote_cookie;
3768 memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3769 memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3770 mp->l2_sublayer_present = s->l2_sublayer_present;
3772 vl_msg_api_send_shmem (q, (u8 *)&mp);
3775 static void send_ip_address_details (vpe_api_main_t * am,
3776 unix_shared_memory_queue_t * q,
3781 vl_api_ip_address_details_t * mp;
3783 mp = vl_msg_api_alloc (sizeof (*mp));
3784 memset (mp, 0, sizeof (*mp));
3785 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3788 memcpy(&mp->ip, ip, sizeof(mp->ip));
3790 u32 * tp = (u32 *)mp->ip;
3791 *tp = ntohl(*(u32*)ip);
3793 mp->prefix_length = prefix_length;
3795 vl_msg_api_send_shmem (q, (u8 *)&mp);
3799 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3801 vpe_api_main_t * am = &vpe_api_main;
3802 unix_shared_memory_queue_t * q;
3805 ip6_main_t * im6 = &ip6_main;
3806 ip4_main_t * im4 = &ip4_main;
3807 ip_lookup_main_t * lm6 = &im6->lookup_main;
3808 ip_lookup_main_t * lm4 = &im4->lookup_main;
3809 ip_interface_address_t * ia = 0;
3810 u32 sw_if_index = ~0;
3812 sw_if_index = ntohl(mp->sw_if_index);
3814 q = vl_api_client_index_to_input_queue (mp->client_index);
3820 foreach_ip_interface_address (lm6, ia, sw_if_index,
3821 1 /* honor unnumbered */,
3823 r6 = ip_interface_address_get_address (lm6, ia);
3824 u16 prefix_length = ia->address_length;
3825 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3828 foreach_ip_interface_address (lm4, ia, sw_if_index,
3829 1 /* honor unnumbered */,
3831 r4 = ip_interface_address_get_address (lm4, ia);
3832 u16 prefix_length = ia->address_length;
3833 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3838 static void send_ip_details (vpe_api_main_t * am,
3839 unix_shared_memory_queue_t *q,
3842 vl_api_ip_details_t * mp;
3844 mp = vl_msg_api_alloc (sizeof (*mp));
3845 memset (mp, 0, sizeof (*mp));
3846 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3848 mp->sw_if_index = ntohl(sw_if_index);
3850 vl_msg_api_send_shmem (q, (u8 *)&mp);
3854 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3855 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3857 vpe_api_main_t * am = &vpe_api_main;
3858 l2t_main_t * lm = &l2t_main;
3859 unix_shared_memory_queue_t * q;
3860 l2t_session_t *session;
3862 q = vl_api_client_index_to_input_queue (mp->client_index);
3866 pool_foreach (session, lm->sessions,
3868 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm);
3873 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3874 unix_shared_memory_queue_t *q,
3875 tapcli_interface_details_t *tap_if)
3877 vl_api_sw_interface_tap_details_t * mp;
3878 mp = vl_msg_api_alloc (sizeof (*mp));
3879 memset (mp, 0, sizeof (*mp));
3880 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3881 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3882 strncpy((char *)mp->dev_name,
3883 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3885 vl_msg_api_send_shmem (q, (u8 *)&mp);
3889 vl_api_sw_interface_tap_dump_t_handler (
3890 vl_api_sw_interface_tap_dump_t *mp)
3893 vpe_api_main_t * am = &vpe_api_main;
3894 unix_shared_memory_queue_t * q;
3895 tapcli_interface_details_t *tapifs = NULL;
3896 tapcli_interface_details_t *tap_if = NULL;
3898 q = vl_api_client_index_to_input_queue (mp->client_index);
3902 rv = vnet_tap_dump_ifs(&tapifs);
3906 vec_foreach(tap_if, tapifs) {
3907 send_sw_interface_tap_details(am, q, tap_if);
3914 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
3916 vpe_api_main_t * am = &vpe_api_main;
3917 vnet_main_t * vnm = vnet_get_main();
3918 vlib_main_t * vm = vlib_get_main();
3919 vnet_interface_main_t * im = &vnm->interface_main;
3920 unix_shared_memory_queue_t * q;
3921 vnet_sw_interface_t * si, * sorted_sis;
3922 u32 sw_if_index = ~0;
3924 q = vl_api_client_index_to_input_queue (mp->client_index);
3929 /* Gather interfaces. */
3930 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
3931 _vec_len (sorted_sis) = 0;
3932 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
3934 vec_foreach (si, sorted_sis) {
3935 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
3936 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
3939 sw_if_index = si->sw_if_index;
3940 send_ip_details(am, q, sw_if_index);
3945 static void vl_api_l2_fib_table_entry_t_handler (
3946 vl_api_l2_fib_table_entry_t * mp)
3948 clib_warning ("BUG");
3951 static void send_l2fib_table_entry (vpe_api_main_t * am,
3952 unix_shared_memory_queue_t *q,
3953 l2fib_entry_key_t * l2fe_key,
3954 l2fib_entry_result_t * l2fe_res)
3956 vl_api_l2_fib_table_entry_t * mp;
3958 mp = vl_msg_api_alloc (sizeof (*mp));
3959 memset (mp, 0, sizeof (*mp));
3960 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
3962 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
3964 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
3965 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
3966 mp->static_mac = l2fe_res->fields.static_mac;
3967 mp->filter_mac = l2fe_res->fields.filter;
3968 mp->bvi_mac = l2fe_res->fields.bvi;
3970 vl_msg_api_send_shmem (q, (u8 *)&mp);
3974 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
3976 vpe_api_main_t * am = &vpe_api_main;
3977 bd_main_t * bdm = &bd_main;
3978 l2fib_entry_key_t *l2fe_key = NULL;
3979 l2fib_entry_result_t *l2fe_res = NULL;
3980 u32 ni, bd_id = ntohl (mp->bd_id);
3982 unix_shared_memory_queue_t * q;
3985 q = vl_api_client_index_to_input_queue (mp->client_index);
3989 /* see l2fib_table_dump: ~0 means "any" */
3993 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4000 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4002 vec_foreach_index (ni, l2fe_key) {
4003 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4004 vec_elt_at_index(l2fe_res, ni));
4011 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4013 vl_api_show_version_reply_t *rmp;
4015 char * vpe_api_get_build_directory(void);
4016 char * vpe_api_get_version(void);
4017 char * vpe_api_get_build_date(void);
4019 unix_shared_memory_queue_t * q =
4020 vl_api_client_index_to_input_queue (mp->client_index);
4025 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4027 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4028 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4029 ARRAY_LEN(rmp->build_directory)-1);
4030 strncpy ((char *) rmp->version, vpe_api_get_version(),
4031 ARRAY_LEN(rmp->version)-1);
4032 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4033 ARRAY_LEN(rmp->build_date)-1);
4037 static void vl_api_get_node_index_t_handler
4038 (vl_api_get_node_index_t * mp)
4040 vlib_main_t * vm = vlib_get_main();
4041 vl_api_get_node_index_reply_t * rmp;
4044 u32 node_index = ~0;
4046 n = vlib_get_node_by_name (vm, mp->node_name);
4049 rv = VNET_API_ERROR_NO_SUCH_NODE;
4051 node_index = n->index;
4053 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4055 rmp->node_index = ntohl(node_index);
4059 static void vl_api_add_node_next_t_handler
4060 (vl_api_add_node_next_t * mp)
4062 vlib_main_t * vm = vlib_get_main();
4063 vl_api_add_node_next_reply_t * rmp;
4064 vlib_node_t * n, * next;
4066 u32 next_index = ~0;
4068 n = vlib_get_node_by_name (vm, mp->node_name);
4071 rv = VNET_API_ERROR_NO_SUCH_NODE;
4075 next = vlib_get_node_by_name (vm, mp->next_name);
4078 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4080 next_index = vlib_node_add_next (vm, n->index, next->index);
4083 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4085 rmp->next_index = ntohl(next_index);
4089 static void vl_api_l2tpv3_create_tunnel_t_handler
4090 (vl_api_l2tpv3_create_tunnel_t *mp)
4092 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4093 l2t_main_t *lm = &l2t_main;
4094 u32 sw_if_index = (u32)~0;
4097 if (mp->is_ipv6 != 1) {
4098 rv = VNET_API_ERROR_UNIMPLEMENTED;
4102 rv = create_l2tpv3_ipv6_tunnel (lm,
4103 (ip6_address_t *) mp->client_address,
4104 (ip6_address_t *) mp->our_address,
4105 ntohl(mp->local_session_id),
4106 ntohl(mp->remote_session_id),
4107 clib_net_to_host_u64(mp->local_cookie),
4108 clib_net_to_host_u64(mp->remote_cookie),
4109 mp->l2_sublayer_present,
4113 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4115 rmp->sw_if_index = ntohl (sw_if_index);
4119 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4120 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4122 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4123 l2t_main_t *lm = &l2t_main;
4126 VALIDATE_SW_IF_INDEX(mp);
4128 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4129 clib_net_to_host_u64(mp->new_local_cookie),
4130 clib_net_to_host_u64(mp->new_remote_cookie));
4132 BAD_SW_IF_INDEX_LABEL;
4134 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4137 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4138 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4141 vnet_main_t * vnm = vnet_get_main();
4142 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4144 VALIDATE_SW_IF_INDEX(mp);
4146 rv = l2tpv3_interface_enable_disable
4147 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4149 BAD_SW_IF_INDEX_LABEL;
4151 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4154 static void vl_api_l2tpv3_set_lookup_key_t_handler
4155 (vl_api_l2tpv3_set_lookup_key_t * mp)
4158 l2t_main_t *lm = &l2t_main;
4159 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4161 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4162 rv = VNET_API_ERROR_INVALID_VALUE;
4166 lm->lookup_type = mp->key;
4169 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4172 static void vl_api_vxlan_add_del_tunnel_t_handler
4173 (vl_api_vxlan_add_del_tunnel_t * mp)
4175 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4177 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4178 u32 encap_fib_index;
4180 ip4_main_t * im = &ip4_main;
4181 u32 sw_if_index = ~0;
4183 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4185 rv = VNET_API_ERROR_NO_SUCH_FIB;
4188 encap_fib_index = p[0];
4190 memset (a, 0, sizeof (*a));
4192 a->is_add = mp->is_add;
4194 /* ip addresses sent in network byte order */
4195 a->src.as_u32 = mp->src_address;
4196 a->dst.as_u32 = mp->dst_address;
4198 a->encap_fib_index = encap_fib_index;
4199 a->decap_next_index = ntohl(mp->decap_next_index);
4200 a->vni = ntohl(mp->vni);
4201 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4204 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4206 rmp->sw_if_index = ntohl (sw_if_index);
4210 static void send_vxlan_tunnel_details
4211 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4213 vl_api_vxlan_tunnel_details_t * rmp;
4214 ip4_main_t * im = &ip4_main;
4216 rmp = vl_msg_api_alloc (sizeof (*rmp));
4217 memset (rmp, 0, sizeof (*rmp));
4218 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4219 rmp->src_address = t->src.data_u32;
4220 rmp->dst_address = t->dst.data_u32;
4221 rmp->encap_vrf_id = htonl(im->fibs[t->encap_fib_index].table_id);
4222 rmp->vni = htonl(t->vni);
4223 rmp->decap_next_index = htonl(t->decap_next_index);
4224 rmp->sw_if_index = htonl(t->sw_if_index);
4226 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4229 static void vl_api_vxlan_tunnel_dump_t_handler
4230 (vl_api_vxlan_tunnel_dump_t * mp)
4232 unix_shared_memory_queue_t * q;
4233 vxlan_main_t * vxm = &vxlan_main;
4237 q = vl_api_client_index_to_input_queue (mp->client_index);
4242 sw_if_index = ntohl(mp->sw_if_index);
4244 if (~0 == sw_if_index) {
4245 pool_foreach (t, vxm->tunnels,
4247 send_vxlan_tunnel_details(t, q);
4250 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4251 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4254 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4255 send_vxlan_tunnel_details(t, q);
4260 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4262 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4264 vl_api_l2_patch_add_del_reply_t * rmp;
4265 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4269 VALIDATE_RX_SW_IF_INDEX(mp);
4270 VALIDATE_TX_SW_IF_INDEX(mp);
4272 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4273 ntohl(mp->tx_sw_if_index),
4274 (int)(mp->is_add != 0));
4276 BAD_RX_SW_IF_INDEX_LABEL;
4277 BAD_TX_SW_IF_INDEX_LABEL;
4279 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4283 vl_api_nsh_gre_add_del_tunnel_t_handler
4284 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4286 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4288 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4289 u32 encap_fib_index, decap_fib_index;
4290 u32 decap_next_index;
4292 ip4_main_t * im = &ip4_main;
4294 u32 sw_if_index = ~0;
4297 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4299 rv = VNET_API_ERROR_NO_SUCH_FIB;
4302 encap_fib_index = p[0];
4304 decap_next_index = ntohl(mp->decap_next_index);
4306 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4307 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4308 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4310 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4313 decap_fib_index = p[0];
4315 decap_fib_index = ntohl(mp->decap_vrf_id);
4318 memset (a, 0, sizeof (*a));
4320 a->is_add = mp->is_add;
4321 /* ip addresses sent in network byte order */
4322 a->src.as_u32 = ntohl(mp->src);
4323 a->dst.as_u32 = ntohl(mp->dst);
4324 a->encap_fib_index = encap_fib_index;
4325 a->decap_fib_index = decap_fib_index;
4326 a->decap_next_index = decap_next_index;
4327 a->ver_o_c = mp->ver_o_c;
4328 a->length = mp->length;
4329 a->md_type = mp->md_type;
4330 a->next_protocol = mp->next_protocol;
4331 a->spi_si = ntohl(mp->spi_si);
4332 a->c1 = ntohl(mp->c1);
4333 a->c2 = ntohl(mp->c2);
4334 a->c3 = ntohl(mp->c3);
4335 a->c4 = ntohl(mp->c4);
4337 for (i = 0; i < mp->tlv_len_in_words; i++)
4338 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4342 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4345 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4347 rmp->sw_if_index = ntohl (sw_if_index);
4352 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4353 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4355 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4357 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4358 u32 encap_fib_index, decap_fib_index;
4359 u32 decap_next_index;
4361 ip4_main_t * im = &ip4_main;
4363 u32 sw_if_index = ~0;
4366 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4368 rv = VNET_API_ERROR_NO_SUCH_FIB;
4371 encap_fib_index = p[0];
4373 decap_next_index = ntohl(mp->decap_next_index);
4375 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4376 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4377 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4379 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4382 decap_fib_index = p[0];
4384 decap_fib_index = ntohl(mp->decap_vrf_id);
4387 memset (a, 0, sizeof (*a));
4389 a->is_add = mp->is_add;
4390 /* ip addresses sent in network byte order */
4391 a->src.as_u32 = ntohl(mp->src);
4392 a->dst.as_u32 = ntohl(mp->dst);
4393 a->encap_fib_index = encap_fib_index;
4394 a->decap_fib_index = decap_fib_index;
4395 a->decap_next_index = decap_next_index;
4396 a->vni = ntohl(mp->vni);
4397 a->ver_o_c = mp->ver_o_c;
4398 a->length = mp->length;
4399 a->md_type = mp->md_type;
4400 a->next_protocol = mp->next_protocol;
4401 a->spi_si = ntohl(mp->spi_si);
4402 a->c1 = ntohl(mp->c1);
4403 a->c2 = ntohl(mp->c2);
4404 a->c3 = ntohl(mp->c3);
4405 a->c4 = ntohl(mp->c4);
4407 for (i = 0; i < mp->tlv_len_in_words; i++)
4408 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4412 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4415 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4417 rmp->sw_if_index = ntohl (sw_if_index);
4422 vl_api_lisp_gpe_add_del_tunnel_t_handler
4423 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4425 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4427 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4428 u32 encap_fib_index, decap_fib_index;
4429 u32 decap_next_index;
4431 ip4_main_t * im = &ip4_main;
4432 u32 sw_if_index = ~0;
4434 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4436 rv = VNET_API_ERROR_NO_SUCH_FIB;
4439 encap_fib_index = p[0];
4441 decap_next_index = ntohl(mp->decap_next_index);
4443 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4444 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4445 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4447 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4450 decap_fib_index = p[0];
4452 decap_fib_index = ntohl(mp->decap_vrf_id);
4455 memset (a, 0, sizeof (*a));
4457 a->is_add = mp->is_add;
4458 /* ip addresses sent in network byte order */
4459 a->src.as_u32 = mp->src;
4460 a->dst.as_u32 = mp->dst;
4461 a->encap_fib_index = encap_fib_index;
4462 a->decap_fib_index = decap_fib_index;
4463 a->decap_next_index = decap_next_index;
4464 a->flags = mp->flags;
4465 a->ver_res = mp->ver_res;
4467 a->next_protocol = mp->next_protocol;
4468 a->iid = clib_net_to_host_u32 (mp->iid);
4470 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4473 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4475 rmp->sw_if_index = ntohl (sw_if_index);
4480 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4482 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4484 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4486 u8 *locator_name = NULL;
4488 memset(a, 0, sizeof(a[0]));
4490 locator_name = format(0, "%s", mp->locator_set_name);
4492 a->name = locator_name;
4494 a->is_add = mp->is_add;
4497 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4499 vec_free(locator_name);
4501 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4505 vl_api_lisp_add_del_locator_t_handler(
4506 vl_api_lisp_add_del_locator_t *mp)
4508 vl_api_lisp_add_del_locator_reply_t *rmp;
4510 locator_t locator, *locators = NULL;
4511 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4513 u8 *locator_name = NULL;
4515 memset(&locator, 0, sizeof(locator));
4516 memset(a, 0, sizeof(a[0]));
4518 locator.sw_if_index = ntohl(mp->sw_if_index);
4519 locator.priority = mp->priority;
4520 locator.weight = mp->weight;
4522 vec_add1(locators, locator);
4524 locator_name = format(0, "%s", mp->locator_set_name);
4526 a->name = locator_name;
4527 a->locators = locators;
4528 a->is_add = mp->is_add;
4531 rv = vnet_lisp_add_del_locator(a, &ls_index);
4534 vec_free(locator_name);
4536 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4540 vl_api_lisp_add_del_local_eid_t_handler(
4541 vl_api_lisp_add_del_local_eid_t *mp)
4543 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4544 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4546 ip_prefix_t *prefp = NULL;
4547 ip_address_t *ip_eid = NULL;
4550 u32 locator_set_index = ~0, map_index = ~0;
4551 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4554 prefp = &gid_address_ippref(&eid);
4555 ip_eid = &ip_prefix_addr(prefp);
4556 gid_address_type (&eid) = IP_PREFIX;
4559 memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4560 sizeof(ip_addr_v6(ip_eid)));
4561 ip_addr_version(ip_eid) = IP6;
4563 memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4564 sizeof(ip_addr_v4(ip_eid)));
4565 ip_addr_version(ip_eid) = IP4;
4567 ip_prefix_len(prefp) = mp->prefix_len;
4569 name = format(0, "%s", mp->locator_set_name);
4570 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4572 rv = VNET_API_ERROR_INVALID_VALUE;
4575 locator_set_index = p[0];
4577 /* XXX treat batch configuration */
4578 a->is_add = mp->is_add;
4580 a->locator_set_index = locator_set_index;
4583 rv = vnet_lisp_add_del_mapping(a, &map_index);
4588 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4592 lisp_gpe_add_del_fwd_entry_set_address(
4593 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4594 ip_address_t *slocator,
4595 ip_address_t *dlocator,
4598 ip_address_t *ip_eid = NULL;
4599 ip_prefix_t *prefp = NULL;
4601 prefp = &gid_address_ippref(eid);
4602 ip_eid = &ip_prefix_addr(prefp);
4604 if (mp->eid_is_ipv6) {
4605 memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4606 sizeof(ip_addr_v6(ip_eid)));
4607 ip_addr_version(ip_eid) = IP6;
4609 memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4610 sizeof(ip_addr_v4(ip_eid)));
4611 ip_addr_version(ip_eid) = IP4;
4613 ip_prefix_len(prefp) = mp->eid_prefix_len;
4615 if (mp->address_is_ipv6) {
4616 memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4617 sizeof(ip_addr_v6(slocator)));
4618 ip_addr_version(slocator) = IP6;
4619 memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4620 sizeof(ip_addr_v6(dlocator)));
4621 ip_addr_version(dlocator) = IP6;
4623 memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4624 sizeof(ip_addr_v4(slocator)));
4625 ip_addr_version(slocator) = IP4;
4626 memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4627 sizeof(ip_addr_v4(dlocator)));
4628 ip_addr_version(dlocator) = IP4;
4633 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4634 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4636 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4638 ip_address_t slocator, dlocator;
4639 ip_prefix_t * prefp = NULL;
4641 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4643 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4645 memset (&a, 0, sizeof(a));
4647 a.is_add = mp->is_add;
4649 a.slocator = slocator;
4650 a.dlocator = dlocator;
4651 prefp = &gid_address_ippref(&a.deid);
4652 a.decap_next_index = (ip_prefix_version(prefp) == IP4) ?
4653 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
4654 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4656 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4660 vl_api_lisp_add_del_map_resolver_t_handler(
4661 vl_api_lisp_add_del_map_resolver_t *mp)
4663 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4665 ip_address_t *ip_addr = NULL;
4666 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4668 a->is_add = mp->is_add;
4669 ip_addr = &a->address;
4672 memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4673 sizeof(ip_addr_v6(ip_addr)));
4674 ip_addr_version(ip_addr) = IP6;
4676 memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4677 sizeof(ip_addr_v4(ip_addr)));
4678 ip_addr_version(ip_addr) = IP4;
4681 rv = vnet_lisp_add_del_map_resolver (a);
4683 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4687 vl_api_lisp_gpe_add_del_iface_t_handler(
4688 vl_api_lisp_gpe_add_del_iface_t *mp)
4690 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4692 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4694 a->is_add = mp->is_add;
4695 vnet_lisp_gpe_add_del_iface (a, 0);
4697 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4701 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4702 locator_set_t *lsit,
4703 unix_shared_memory_queue_t *q)
4705 vl_api_lisp_locator_set_details_t *rmp;
4706 locator_t *loc = NULL;
4709 vec_foreach (locit, lsit->locator_indices) {
4710 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4711 rmp = vl_msg_api_alloc (sizeof (*rmp));
4712 memset (rmp, 0, sizeof (*rmp));
4713 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4714 strncpy((char *) rmp->locator_set_name,
4715 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4716 rmp->sw_if_index = htonl(loc->sw_if_index);
4717 rmp->priority = loc->priority;
4718 rmp->weight = loc->weight;
4720 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4725 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4727 unix_shared_memory_queue_t * q = NULL;
4728 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4729 locator_set_t * lsit = NULL;
4731 q = vl_api_client_index_to_input_queue (mp->client_index);
4736 pool_foreach (lsit, lcm->locator_set_pool,
4738 send_lisp_locator_set_details(lcm, lsit, q);
4743 send_lisp_local_eid_table_details (mapping_t *mapit,
4744 unix_shared_memory_queue_t *q)
4746 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4747 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4748 locator_set_t *ls = NULL;
4749 gid_address_t *gid = NULL;
4750 ip_prefix_t *ip_prefix = NULL;
4753 ls = pool_elt_at_index (lcm->locator_set_pool,
4754 mapit->locator_set_index);
4757 type = gid_address_type(gid);
4759 if (type != IP_PREFIX) {
4763 ip_prefix = &gid_address_ippref(gid);
4765 rmp = vl_msg_api_alloc (sizeof (*rmp));
4766 memset (rmp, 0, sizeof (*rmp));
4767 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
4768 strncpy((char *) rmp->locator_set_name,
4769 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4771 switch (ip_prefix_version(ip_prefix)) {
4773 rmp->eid_is_ipv6 = 0;
4774 memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
4775 sizeof(ip_prefix_v4(ip_prefix)));
4779 rmp->eid_is_ipv6 = 1;
4780 memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
4781 sizeof(ip_prefix_v6(ip_prefix)));
4787 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
4789 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4793 vl_api_lisp_local_eid_table_dump_t_handler (
4794 vl_api_lisp_local_eid_table_dump_t *mp)
4796 unix_shared_memory_queue_t * q = NULL;
4797 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4798 mapping_t * mapit = NULL;
4800 q = vl_api_client_index_to_input_queue (mp->client_index);
4805 pool_foreach (mapit, lcm->mapping_pool,
4807 send_lisp_local_eid_table_details(mapit, q);
4812 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
4813 unix_shared_memory_queue_t *q)
4815 vl_api_lisp_gpe_tunnel_details_t *rmp;
4816 lisp_gpe_main_t * lgm = &lisp_gpe_main;
4817 ip4_address_t *ip4 = NULL;
4819 rmp = vl_msg_api_alloc (sizeof (*rmp));
4820 memset (rmp, 0, sizeof (*rmp));
4821 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
4823 rmp->tunnels = tunnel - lgm->tunnels;
4825 /*list_gpe_tunnel now support only IPv4*/
4828 memcpy(rmp->source_ip, ip4, sizeof(*ip4));
4830 memcpy(rmp->destination_ip, ip4, sizeof(*ip4));
4832 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
4833 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
4834 rmp->dcap_next = htonl(tunnel->decap_next_index);
4835 rmp->lisp_ver = tunnel->ver_res;
4836 rmp->next_protocol = tunnel->next_protocol;
4837 rmp->flags = tunnel->flags;
4838 rmp->ver_res = tunnel->ver_res;
4839 rmp->res = tunnel->res;
4840 rmp->iid = htonl(tunnel->iid);
4842 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4846 vl_api_lisp_gpe_tunnel_dump_t_handler (
4847 vl_api_lisp_local_eid_table_dump_t *mp)
4849 unix_shared_memory_queue_t * q = NULL;
4850 lisp_gpe_main_t * lgm = &lisp_gpe_main;
4851 lisp_gpe_tunnel_t * tunnel = NULL;
4853 if (pool_elts(lgm->tunnels) == 0) {
4857 q = vl_api_client_index_to_input_queue (mp->client_index);
4862 pool_foreach(tunnel, lgm->tunnels,
4864 send_lisp_gpe_tunnel_details(tunnel, q);
4869 send_lisp_map_resolver_details (ip_address_t *ip,
4870 unix_shared_memory_queue_t *q)
4872 vl_api_lisp_map_resolver_details_t *rmp = NULL;
4874 rmp = vl_msg_api_alloc (sizeof (*rmp));
4875 memset (rmp, 0, sizeof (*rmp));
4876 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
4878 switch (ip_addr_version(ip)) {
4881 memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
4886 memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
4893 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4897 vl_api_lisp_map_resolver_dump_t_handler (
4898 vl_api_lisp_local_eid_table_dump_t *mp)
4900 unix_shared_memory_queue_t * q = NULL;
4901 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4902 ip_address_t *ip = NULL;
4904 q = vl_api_client_index_to_input_queue (mp->client_index);
4909 vec_foreach(ip, lcm->map_resolvers) {
4910 send_lisp_map_resolver_details(ip, q);
4916 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
4918 vl_api_interface_name_renumber_reply_t * rmp;
4921 VALIDATE_SW_IF_INDEX(mp);
4923 rv = vnet_interface_name_renumber
4924 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
4926 BAD_SW_IF_INDEX_LABEL;
4928 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
4931 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
4932 u32 sw_if_index, u32 address)
4934 vpe_api_main_t * am = &vpe_api_main;
4935 vlib_main_t * vm = am->vlib_main;
4936 vl_api_ip4_arp_event_t * event;
4937 static f64 arp_event_last_time;
4938 f64 now = vlib_time_now (vm);
4940 if (pool_is_free_index (am->arp_events, pool_index))
4943 event = pool_elt_at_index (am->arp_events, pool_index);
4944 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
4945 memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
4946 } else { /* same mac */
4947 if ((sw_if_index == event->sw_if_index) &&
4949 /* for BD case, also check IP address with 10 sec timeout */
4950 ((address == event->address) &&
4951 ((now - arp_event_last_time) < 10.0))))
4955 arp_event_last_time = now;
4956 event->sw_if_index = sw_if_index;
4957 if (address) event->address = address;
4961 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
4963 vpe_api_main_t * am = &vpe_api_main;
4965 if (pool_is_free_index (am->arp_events, pool_index))
4968 pool_put_index (am->arp_events, pool_index);
4973 vl_api_want_ip4_arp_events_t_handler
4974 (vl_api_want_ip4_arp_events_t * mp)
4976 vpe_api_main_t * am = &vpe_api_main;
4977 vnet_main_t * vnm = vnet_get_main();
4978 vl_api_want_ip4_arp_events_reply_t *rmp;
4979 vl_api_ip4_arp_event_t * event;
4982 if (mp->enable_disable) {
4983 pool_get (am->arp_events, event);
4984 memset (event, 0, sizeof (*event));
4986 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
4987 event->client_index = mp->client_index;
4988 event->context = mp->context;
4989 event->address = mp->address;
4990 event->pid = mp->pid;
4992 rv = vnet_add_del_ip4_arp_change_event
4993 (vnm, arp_change_data_callback,
4995 &mp->address /* addr, in net byte order */,
4996 vpe_resolver_process_node.index,
4997 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
4999 rv = vnet_add_del_ip4_arp_change_event
5000 (vnm, arp_change_delete_callback,
5002 &mp->address /* addr, in net byte order */,
5003 vpe_resolver_process_node.index,
5004 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5006 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5009 static void vl_api_input_acl_set_interface_t_handler
5010 (vl_api_input_acl_set_interface_t * mp)
5012 vlib_main_t *vm = vlib_get_main();
5013 vl_api_input_acl_set_interface_reply_t * rmp;
5015 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5017 ip4_table_index = ntohl(mp->ip4_table_index);
5018 ip6_table_index = ntohl(mp->ip6_table_index);
5019 l2_table_index = ntohl(mp->l2_table_index);
5020 sw_if_index = ntohl(mp->sw_if_index);
5022 VALIDATE_SW_IF_INDEX(mp);
5024 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5025 ip6_table_index, l2_table_index,
5028 BAD_SW_IF_INDEX_LABEL;
5030 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5033 static void vl_api_ipsec_spd_add_del_t_handler
5034 (vl_api_ipsec_spd_add_del_t * mp)
5037 clib_warning ("unimplemented");
5040 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5041 vl_api_ipsec_spd_add_del_reply_t * rmp;
5045 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5047 rv = VNET_API_ERROR_UNIMPLEMENTED;
5050 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5054 static void vl_api_ipsec_interface_add_del_spd_t_handler
5055 (vl_api_ipsec_interface_add_del_spd_t * mp)
5057 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5058 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5060 u32 sw_if_index __attribute__((unused));
5061 u32 spd_id __attribute__((unused));
5063 sw_if_index = ntohl(mp->sw_if_index);
5064 spd_id = ntohl(mp->spd_id);
5066 VALIDATE_SW_IF_INDEX(mp);
5069 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5071 rv = VNET_API_ERROR_UNIMPLEMENTED;
5074 BAD_SW_IF_INDEX_LABEL;
5076 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5079 static void vl_api_ipsec_spd_add_del_entry_t_handler
5080 (vl_api_ipsec_spd_add_del_entry_t * mp)
5082 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5083 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5089 memset(&p, 0, sizeof(p));
5091 p.id = ntohl(mp->spd_id);
5092 p.priority = ntohl(mp->priority);
5093 p.is_outbound = mp->is_outbound;
5094 p.is_ipv6 = mp->is_ipv6;
5096 memcpy(&p.raddr.start, mp->remote_address_start, 16);
5097 memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5098 memcpy(&p.laddr.start, mp->local_address_start, 16);
5099 memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5101 p.protocol = mp->protocol;
5102 p.rport.start = ntohs(mp->remote_port_start);
5103 p.rport.stop = ntohs(mp->remote_port_stop);
5104 p.lport.start = ntohs(mp->local_port_start);
5105 p.lport.stop = ntohs(mp->local_port_stop);
5106 /* policy action resolve unsupported */
5107 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5108 clib_warning("unsupported action: 'resolve'");
5109 rv = VNET_API_ERROR_UNIMPLEMENTED;
5112 p.policy = mp->policy;
5113 p.sa_id = ntohl(mp->sa_id);
5115 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5119 if (mp->is_ip_any) {
5121 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5124 rv = VNET_API_ERROR_UNIMPLEMENTED;
5129 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5132 static void vl_api_ipsec_sad_add_del_entry_t_handler
5133 (vl_api_ipsec_sad_add_del_entry_t * mp)
5135 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5136 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5141 memset(&sa, 0, sizeof(sa));
5143 sa.id = ntohl(mp->sad_id);
5144 sa.spi = ntohl(mp->spi);
5145 /* security protocol AH unsupported */
5146 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5147 clib_warning("unsupported security protocol 'AH'");
5148 rv = VNET_API_ERROR_UNIMPLEMENTED;
5151 sa.protocol = mp->protocol;
5152 /* check for unsupported crypto-alg */
5153 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5154 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5155 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5156 mp->crypto_algorithm);
5157 rv = VNET_API_ERROR_UNIMPLEMENTED;
5160 sa.crypto_alg = mp->crypto_algorithm;
5161 sa.crypto_key_len = mp->crypto_key_length;
5162 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5163 /* check for unsupported integ-alg */
5164 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5165 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5166 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5167 mp->integrity_algorithm);
5168 rv = VNET_API_ERROR_UNIMPLEMENTED;
5171 sa.integ_alg = mp->integrity_algorithm;
5172 sa.integ_key_len = mp->integrity_key_length;
5173 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5174 sa.use_esn = mp->use_extended_sequence_number;
5175 sa.is_tunnel = mp->is_tunnel;
5176 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5177 memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5178 memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5180 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5182 rv = VNET_API_ERROR_UNIMPLEMENTED;
5187 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5191 vl_api_ikev2_profile_add_del_t_handler
5192 (vl_api_ikev2_profile_add_del_t * mp)
5194 vl_api_ikev2_profile_add_del_reply_t * rmp;
5198 vlib_main_t * vm = vlib_get_main();
5199 clib_error_t * error;
5200 u8 * tmp = format(0, "%s", mp->name);
5201 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5204 rv = VNET_API_ERROR_UNSPECIFIED;
5206 rv = VNET_API_ERROR_UNIMPLEMENTED;
5209 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5213 vl_api_ikev2_profile_set_auth_t_handler
5214 (vl_api_ikev2_profile_set_auth_t * mp)
5216 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5220 vlib_main_t * vm = vlib_get_main();
5221 clib_error_t * error;
5222 u8 * tmp = format(0, "%s", mp->name);
5223 u8 * data = vec_new (u8, mp->data_len);
5224 memcpy(data, mp->data, mp->data_len);
5225 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5229 rv = VNET_API_ERROR_UNSPECIFIED;
5231 rv = VNET_API_ERROR_UNIMPLEMENTED;
5234 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5238 vl_api_ikev2_profile_set_id_t_handler
5239 (vl_api_ikev2_profile_set_id_t * mp)
5241 vl_api_ikev2_profile_add_del_reply_t * rmp;
5245 vlib_main_t * vm = vlib_get_main();
5246 clib_error_t * error;
5247 u8 * tmp = format(0, "%s", mp->name);
5248 u8 * data = vec_new (u8, mp->data_len);
5249 memcpy(data, mp->data, mp->data_len);
5250 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5254 rv = VNET_API_ERROR_UNSPECIFIED;
5256 rv = VNET_API_ERROR_UNIMPLEMENTED;
5259 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5263 vl_api_ikev2_profile_set_ts_t_handler
5264 (vl_api_ikev2_profile_set_ts_t * mp)
5266 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5270 vlib_main_t * vm = vlib_get_main();
5271 clib_error_t * error;
5272 u8 * tmp = format(0, "%s", mp->name);
5273 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5274 mp->end_port, (ip4_address_t) mp->start_addr,
5275 (ip4_address_t) mp->end_addr, mp->is_local);
5278 rv = VNET_API_ERROR_UNSPECIFIED;
5280 rv = VNET_API_ERROR_UNIMPLEMENTED;
5283 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5287 vl_api_ikev2_set_local_key_t_handler
5288 (vl_api_ikev2_set_local_key_t * mp)
5290 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5294 vlib_main_t * vm = vlib_get_main();
5295 clib_error_t * error;
5297 error = ikev2_set_local_key(vm, mp->key_file);
5299 rv = VNET_API_ERROR_UNSPECIFIED;
5301 rv = VNET_API_ERROR_UNIMPLEMENTED;
5304 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5308 vl_api_map_add_domain_t_handler
5309 (vl_api_map_add_domain_t * mp)
5311 vl_api_map_add_domain_reply_t * rmp;
5314 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5315 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5316 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5317 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5318 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5320 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5322 rmp->index = ntohl(index);
5327 vl_api_map_del_domain_t_handler
5328 (vl_api_map_del_domain_t * mp)
5330 vl_api_map_del_domain_reply_t * rmp;
5333 rv = map_delete_domain(ntohl(mp->index));
5335 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5339 vl_api_map_add_del_rule_t_handler
5340 (vl_api_map_add_del_rule_t * mp)
5342 vl_api_map_del_domain_reply_t * rmp;
5345 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5347 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5351 vl_api_map_domain_dump_t_handler
5352 (vl_api_map_domain_dump_t * mp)
5354 vl_api_map_domain_details_t * rmp;
5355 map_main_t *mm = &map_main;
5357 unix_shared_memory_queue_t * q;
5359 if (pool_elts (mm->domains) == 0)
5362 q = vl_api_client_index_to_input_queue (mp->client_index);
5367 pool_foreach(d, mm->domains, ({
5368 /* Make sure every field is initiated (or don't skip the memset()) */
5369 rmp = vl_msg_api_alloc (sizeof (*rmp));
5370 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5371 rmp->domain_index = htonl(d - mm->domains);
5372 rmp->ea_bits_len = d->ea_bits_len;
5373 rmp->psid_offset = d->psid_offset;
5374 rmp->psid_length = d->psid_length;
5375 memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5376 rmp->ip4_prefix_len = d->ip4_prefix_len;
5377 memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5378 rmp->ip6_prefix_len = d->ip6_prefix_len;
5379 memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5380 rmp->ip6_src_len = d->ip6_src_len;
5381 rmp->mtu = htons(d->mtu);
5382 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5384 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5389 vl_api_map_rule_dump_t_handler
5390 (vl_api_map_rule_dump_t * mp)
5392 unix_shared_memory_queue_t * q;
5395 vl_api_map_rule_details_t * rmp;
5396 map_main_t *mm = &map_main;
5397 u32 domain_index = ntohl(mp->domain_index);
5400 if (pool_elts (mm->domains) == 0)
5403 d = pool_elt_at_index(mm->domains, domain_index);
5404 if (!d || !d->rules) {
5408 q = vl_api_client_index_to_input_queue (mp->client_index);
5413 for (i = 0; i < (0x1 << d->psid_length); i++) {
5415 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5418 rmp = vl_msg_api_alloc(sizeof(*rmp));
5419 memset(rmp, 0, sizeof(*rmp));
5420 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5421 rmp->psid = htons(i);
5422 memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5423 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5428 vl_api_map_summary_stats_t_handler (
5429 vl_api_map_summary_stats_t *mp)
5431 vl_api_map_summary_stats_reply_t *rmp;
5432 vlib_combined_counter_main_t *cm;
5435 u64 total_pkts[VLIB_N_RX_TX];
5436 u64 total_bytes[VLIB_N_RX_TX];
5437 map_main_t *mm = &map_main;
5438 unix_shared_memory_queue_t *q =
5439 vl_api_client_index_to_input_queue(mp->client_index);
5444 rmp = vl_msg_api_alloc (sizeof (*rmp));
5445 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5446 rmp->context = mp->context;
5449 memset (total_pkts, 0, sizeof (total_pkts));
5450 memset (total_bytes, 0, sizeof (total_bytes));
5452 map_domain_counter_lock (mm);
5453 vec_foreach(cm, mm->domain_counters) {
5454 which = cm - mm->domain_counters;
5456 for (i = 0; i < vec_len(cm->maxi); i++) {
5457 vlib_get_combined_counter (cm, i, &v);
5458 total_pkts[which] += v.packets;
5459 total_bytes[which] += v.bytes;
5463 map_domain_counter_unlock (mm);
5465 /* Note: in network byte order! */
5466 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5467 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5468 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5469 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5470 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5471 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5472 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));
5473 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));
5475 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5478 static void vl_api_ipsec_sa_set_key_t_handler
5479 (vl_api_ipsec_sa_set_key_t * mp)
5481 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5482 vl_api_ipsec_sa_set_key_reply_t *rmp;
5486 sa.id = ntohl(mp->sa_id);
5487 sa.crypto_key_len = mp->crypto_key_length;
5488 memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5489 sa.integ_key_len = mp->integrity_key_length;
5490 memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5492 rv = ipsec_set_sa_key(vm, &sa);
5494 rv = VNET_API_ERROR_UNIMPLEMENTED;
5497 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5500 static void vl_api_cop_interface_enable_disable_t_handler
5501 (vl_api_cop_interface_enable_disable_t * mp)
5503 vl_api_cop_interface_enable_disable_reply_t * rmp;
5505 u32 sw_if_index = ntohl(mp->sw_if_index);
5508 VALIDATE_SW_IF_INDEX(mp);
5510 enable_disable = (int) mp->enable_disable;
5512 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5514 BAD_SW_IF_INDEX_LABEL;
5516 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5519 static void vl_api_cop_whitelist_enable_disable_t_handler
5520 (vl_api_cop_whitelist_enable_disable_t * mp)
5522 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5523 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5524 u32 sw_if_index = ntohl(mp->sw_if_index);
5527 VALIDATE_SW_IF_INDEX(mp);
5529 a->sw_if_index = sw_if_index;
5532 a->default_cop = mp->default_cop;
5533 a->fib_id = ntohl(mp->fib_id);
5535 rv = cop_whitelist_enable_disable (a);
5537 BAD_SW_IF_INDEX_LABEL;
5539 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5542 static void vl_api_get_node_graph_t_handler
5543 (vl_api_get_node_graph_t * mp)
5547 api_main_t * am = &api_main;
5548 vlib_main_t * vm = vlib_get_main();
5550 vl_api_get_node_graph_reply_t * rmp;
5552 pthread_mutex_lock (&am->vlib_rp->mutex);
5553 oldheap = svm_push_data_heap (am->vlib_rp);
5556 * Keep the number of memcpy ops to a minimum (e.g. 1).
5557 * The current size of the serialized vector is
5558 * slightly under 4K.
5560 vec_validate (vector, 4095);
5561 vec_reset_length (vector);
5563 vector = vlib_node_serialize (&vm->node_main, vector);
5565 svm_pop_heap (oldheap);
5566 pthread_mutex_unlock (&am->vlib_rp->mutex);
5568 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5569 rmp->reply_in_shmem = (uword) vector);
5572 static void vl_api_trace_profile_add_t_handler
5573 (vl_api_trace_profile_add_t *mp)
5576 vl_api_trace_profile_add_reply_t * rmp;
5577 clib_error_t *error;
5579 /* Ignoring the profile id as currently a single profile
5581 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5582 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5583 mp->pow_enable, mp->trace_tsp,
5586 clib_error_report(error);
5587 rv = clib_error_get_code(error);
5590 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5593 static void vl_api_trace_profile_apply_t_handler
5594 (vl_api_trace_profile_apply_t *mp)
5597 vl_api_trace_profile_apply_reply_t * rmp;
5599 if (mp->enable != 0) {
5600 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5601 ntohl(mp->prefix_length),
5603 mp->trace_op == IOAM_HBYH_ADD,
5604 mp->trace_op == IOAM_HBYH_POP,
5605 mp->trace_op == IOAM_HBYH_MOD);
5607 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5609 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5612 static void vl_api_trace_profile_del_t_handler
5613 (vl_api_trace_profile_del_t *mp)
5616 vl_api_trace_profile_del_reply_t * rmp;
5617 clib_error_t *error;
5619 error = clear_ioam_rewrite_fn();
5621 clib_error_report(error);
5622 rv = clib_error_get_code(error);
5625 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5629 #define BOUNCE_HANDLER(nn) \
5630 static void vl_api_##nn##_t_handler ( \
5631 vl_api_##nn##_t *mp) \
5633 vpe_client_registration_t *reg; \
5634 vpe_api_main_t * vam = &vpe_api_main; \
5635 unix_shared_memory_queue_t * q; \
5637 /* One registration only... */ \
5638 pool_foreach(reg, vam->nn##_registrations, \
5640 q = vl_api_client_index_to_input_queue (reg->client_index); \
5643 * If the queue is stuffed, turf the msg and complain \
5644 * It's unlikely that the intended recipient is \
5645 * alive; avoid deadlock at all costs. \
5647 if (q->cursize == q->maxsize) { \
5648 clib_warning ("ERROR: receiver queue full, drop msg"); \
5649 vl_msg_api_free (mp); \
5652 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5656 vl_msg_api_free (mp); \
5661 * Add vpe's API message handlers to the table.
5662 * vlib has alread mapped shared memory and
5663 * added the client registration handlers.
5664 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5667 static clib_error_t *
5668 vpe_api_hookup (vlib_main_t *vm)
5670 api_main_t * am = &api_main;
5673 vl_msg_api_set_handlers(VL_API_##N, #n, \
5674 vl_api_##n##_t_handler, \
5676 vl_api_##n##_t_endian, \
5677 vl_api_##n##_t_print, \
5678 sizeof(vl_api_##n##_t), 1);
5679 foreach_vpe_api_msg;
5683 * Manually register the sr tunnel add del msg, so we trace
5684 * enough bytes to capture a typical segment list
5686 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5687 "sr_tunnel_add_del",
5688 vl_api_sr_tunnel_add_del_t_handler,
5690 vl_api_sr_tunnel_add_del_t_endian,
5691 vl_api_sr_tunnel_add_del_t_print,
5695 * Trace space for 8 MPLS encap labels, classifier mask+match
5697 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5698 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5699 += 5 * sizeof (u32x4);
5700 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5701 += 5 * sizeof (u32x4);
5702 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5703 += 16 * sizeof (u32);
5706 * trace space for 4 nsh-gre variable TLV words
5708 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5709 += 4 * sizeof (u32);
5712 * Thread-safe API messages
5714 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
5719 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5721 static clib_error_t *
5722 vpe_api_init (vlib_main_t *vm)
5724 vpe_api_main_t *am = &vpe_api_main;
5727 am->vnet_main = vnet_get_main();
5728 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5729 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5730 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5731 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5732 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5733 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5736 vl_set_memory_region_name ("/vpe-api");
5737 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5742 VLIB_INIT_FUNCTION(vpe_api_init);
5744 static clib_error_t *
5745 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5749 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5751 if (unformat (input, "prefix %s", &chroot_path))
5753 vec_add1 (chroot_path, 0);
5754 vl_set_memory_root_path ((char *)chroot_path);
5757 return clib_error_return (0, "unknown input `%U'",
5758 format_unformat_error, input);
5762 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
5764 void * get_unformat_vnet_sw_interface (void)
5766 return (void *) &unformat_vnet_sw_interface;
5769 #undef vl_api_version
5770 #define vl_api_version(n,v) static u32 vpe_api_version = v;
5771 #include <api/vpe.api.h>
5772 #undef vl_api_version
5774 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
5776 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
5777 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
5778 clib_host_to_net_u32 (mp->api_versions[0]),
5785 static u8 * format_arp_event (u8 * s, va_list * args)
5787 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
5789 s = format (s, "pid %d: %U", event->pid,
5790 format_ip4_address, &event->address);
5794 static clib_error_t *
5795 show_ip4_arp_events_fn (vlib_main_t * vm,
5796 unformat_input_t * input,
5797 vlib_cli_command_t * cmd)
5799 vpe_api_main_t * am = &vpe_api_main;
5800 vl_api_ip4_arp_event_t * event;
5802 if (pool_elts (am->arp_events) == 0) {
5803 vlib_cli_output (vm, "No active arp event registrations");
5807 pool_foreach (event, am->arp_events,
5809 vlib_cli_output (vm, "%U", format_arp_event, event);
5815 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
5816 .path = "show arp event registrations",
5817 .function = show_ip4_arp_events_fn,
5818 .short_help = "Show arp event registrations",