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>
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
48 #include <vnet/api_errno.h> // alagalah TODO : committers please pay note, is this ok?
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/l2tp/l2tp.h>
53 #include <vnet/ip/ip.h>
54 #include <vnet/unix/tuntap.h>
55 #include <vnet/unix/tapcli.h>
56 #include <vnet/mpls-gre/mpls.h>
57 #include <vnet/dhcp/proxy.h>
58 #include <vnet/dhcp/client.h>
60 #include <vnet/sr/sr.h>
62 #include <vnet/dhcpv6/proxy.h>
63 #include <vlib/vlib.h>
64 #include <vlib/unix/unix.h>
65 #include <vlibapi/api.h>
66 #include <vlibmemory/api.h>
67 #include <vnet/classify/vnet_classify.h>
68 #include <vnet/classify/input_acl.h>
69 #include <vnet/l2/l2_classify.h>
70 #include <vnet/vxlan/vxlan.h>
71 #include <vnet/gre/gre.h>
72 #include <vnet/l2/l2_vtr.h>
73 #include <vnet/vxlan-gpe/vxlan_gpe.h>
74 #include <vnet/lisp-gpe/lisp_gpe.h>
75 #include <vnet/lisp-cp/control.h>
76 #include <vnet/map/map.h>
77 #include <vnet/cop/cop.h>
78 #include <vnet/ip/ip6_hop_by_hop.h>
79 #include <vnet/devices/af_packet/af_packet.h>
80 #include <vnet/policer/policer.h>
81 #include <vnet/devices/netmap/netmap.h>
84 #undef __included_bihash_template_h__
85 #include <vnet/l2/l2_fib.h>
88 #include <vnet/ipsec/ipsec.h>
89 #include <vnet/ipsec/ikev2.h>
92 #include <vnet/devices/virtio/vhost-user.h>
95 #include <stats/stats.h>
98 #include <vnet/ethernet/ethernet.h>
99 #include <vnet/ethernet/arp_packet.h>
100 #include <vnet/interface.h>
102 #include <vnet/l2/l2_fib.h>
103 #include <vnet/l2/l2_bd.h>
104 #include <api/vpe_msg_enum.h>
106 #define f64_endian(a)
107 #define f64_print(a,b)
109 #define vl_typedefs /* define message structures */
110 #include <api/vpe_all_api_h.h>
113 #define vl_endianfun /* define message structures */
114 #include <api/vpe_all_api_h.h>
117 /* instantiate all the print functions we know about */
118 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
120 #include <api/vpe_all_api_h.h>
123 #define REPLY_MACRO(t) \
125 unix_shared_memory_queue_t * q; \
126 rv = vl_msg_api_pd_handler (mp, rv); \
127 q = vl_api_client_index_to_input_queue (mp->client_index); \
131 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
132 rmp->_vl_msg_id = ntohs((t)); \
133 rmp->context = mp->context; \
134 rmp->retval = ntohl(rv); \
136 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
139 #define REPLY_MACRO2(t, body) \
141 unix_shared_memory_queue_t * q; \
142 rv = vl_msg_api_pd_handler (mp, rv); \
143 q = vl_api_client_index_to_input_queue (mp->client_index); \
147 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
148 rmp->_vl_msg_id = ntohs((t)); \
149 rmp->context = mp->context; \
150 rmp->retval = ntohl(rv); \
151 do {body;} while (0); \
152 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
155 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
157 #define VALIDATE_SW_IF_INDEX(mp) \
158 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
159 vnet_main_t *__vnm = vnet_get_main(); \
160 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
162 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
163 goto bad_sw_if_index; \
167 #define BAD_SW_IF_INDEX_LABEL \
173 #define VALIDATE_RX_SW_IF_INDEX(mp) \
174 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
175 vnet_main_t *__vnm = vnet_get_main(); \
176 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
177 __rx_sw_if_index)) { \
178 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
179 goto bad_rx_sw_if_index; \
183 #define BAD_RX_SW_IF_INDEX_LABEL \
185 bad_rx_sw_if_index: \
189 #define VALIDATE_TX_SW_IF_INDEX(mp) \
190 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
191 vnet_main_t *__vnm = vnet_get_main(); \
192 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
193 __tx_sw_if_index)) { \
194 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
195 goto bad_tx_sw_if_index; \
199 #define BAD_TX_SW_IF_INDEX_LABEL \
201 bad_tx_sw_if_index: \
207 #define VALIDATE_SW_IF_INDEX(mp)
208 #define BAD_SW_IF_INDEX_LABEL
209 #define VALIDATE_RX_SW_IF_INDEX(mp)
210 #define BAD_RX_SW_IF_INDEX_LABEL
211 #define VALIDATE_TX_SW_IF_INDEX(mp)
212 #define BAD_TX_SW_IF_INDEX_LABEL
214 #endif /* CLIB_DEBUG > 0 */
216 #define foreach_vpe_api_msg \
217 _(WANT_INTERFACE_EVENTS, want_interface_events) \
218 _(WANT_OAM_EVENTS, want_oam_events) \
219 _(OAM_ADD_DEL, oam_add_del) \
220 _(SW_INTERFACE_DUMP, sw_interface_dump) \
221 _(SW_INTERFACE_DETAILS, sw_interface_details) \
222 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
223 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
224 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
225 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
226 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
227 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
228 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
229 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
230 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
231 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
232 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
233 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
234 _(L2FIB_ADD_DEL, l2fib_add_del) \
235 _(L2_FLAGS, l2_flags) \
236 _(BRIDGE_FLAGS, bridge_flags) \
237 _(TAP_CONNECT, tap_connect) \
238 _(TAP_MODIFY, tap_modify) \
239 _(TAP_DELETE, tap_delete) \
240 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
241 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
242 _(CREATE_SUBIF, create_subif) \
243 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
244 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
245 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
246 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
247 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
248 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
249 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
250 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
251 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
252 _(RESET_FIB, reset_fib) \
253 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
254 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
255 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
256 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
257 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
258 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
259 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
260 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
261 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
262 sw_interface_ip6_set_link_local_address) \
263 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
264 _(CREATE_LOOPBACK, create_loopback) \
265 _(CONTROL_PING, control_ping) \
266 _(CLI_REQUEST, cli_request) \
267 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
268 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
269 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
270 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
271 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
272 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
273 _(GET_NODE_INDEX, get_node_index) \
274 _(ADD_NODE_NEXT, add_node_next) \
275 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
276 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
277 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
278 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
279 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
280 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
281 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
282 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
283 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
284 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
285 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
286 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
287 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
288 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
289 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
290 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
291 _(IP_ADDRESS_DUMP, ip_address_dump) \
292 _(IP_DUMP, ip_dump) \
293 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
294 _(SHOW_VERSION, show_version) \
295 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
296 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
297 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
298 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
299 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
300 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
301 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
302 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
303 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
304 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
305 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
306 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
307 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
308 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
309 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
310 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
311 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
312 _(DELETE_LOOPBACK, delete_loopback) \
313 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
314 _(MAP_ADD_DOMAIN, map_add_domain) \
315 _(MAP_DEL_DOMAIN, map_del_domain) \
316 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
317 _(MAP_DOMAIN_DUMP, map_domain_dump) \
318 _(MAP_RULE_DUMP, map_rule_dump) \
319 _(MAP_SUMMARY_STATS, map_summary_stats) \
320 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
321 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
322 _(GET_NODE_GRAPH, get_node_graph) \
323 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
324 _(TRACE_PROFILE_ADD, trace_profile_add) \
325 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
326 _(TRACE_PROFILE_DEL, trace_profile_del) \
327 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
328 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
329 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
330 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
331 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
332 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
333 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
334 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
335 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
336 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
337 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
338 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
339 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
340 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
341 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
342 lisp_enable_disable_status_dump) \
343 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
344 _(AF_PACKET_CREATE, af_packet_create) \
345 _(AF_PACKET_DELETE, af_packet_delete) \
346 _(POLICER_ADD_DEL, policer_add_del) \
347 _(POLICER_DUMP, policer_dump) \
348 _(NETMAP_CREATE, netmap_create) \
349 _(NETMAP_DELETE, netmap_delete)
352 #define QUOTE(x) QUOTE_(x)
354 #define foreach_registration_hash \
355 _(interface_events) \
356 _(to_netconf_server) \
357 _(from_netconf_server) \
358 _(to_netconf_client) \
359 _(from_netconf_client) \
363 RESOLVE_IP4_ADD_DEL_ROUTE=1,
364 RESOLVE_IP6_ADD_DEL_ROUTE,
365 RESOLVE_MPLS_ETHERNET_ADD_DEL,
371 vl_api_ip_add_del_route_t r;
372 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
378 #define _(a) uword *a##_registration_hash; \
379 vpe_client_registration_t * a##_registrations;
380 foreach_registration_hash
383 /* notifications happen really early in the game */
384 u8 link_state_process_up;
386 /* ip4 pending route adds */
387 pending_route_t * pending_routes;
389 /* ip4 arp event registration pool */
390 vl_api_ip4_arp_event_t * arp_events;
393 vlib_main_t * vlib_main;
394 vnet_main_t * vnet_main;
397 static vlib_node_registration_t vpe_resolver_process_node;
398 static vpe_api_main_t vpe_api_main;
400 static void send_sw_interface_flags (vpe_api_main_t * am,
401 unix_shared_memory_queue_t *q,
402 vnet_sw_interface_t * swif);
403 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
404 unix_shared_memory_queue_t *q,
407 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
410 /* Clean up all registrations belonging to the indicated client */
411 int vl_api_memclnt_delete_callback (u32 client_index)
413 vpe_api_main_t * vam = &vpe_api_main;
414 vpe_client_registration_t *rp;
416 int stats_memclnt_delete_callback (u32 client_index);
418 stats_memclnt_delete_callback (client_index);
421 p = hash_get (vam->a##_registration_hash, client_index); \
423 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
424 pool_put (vam->a##_registrations, rp); \
425 hash_unset (vam->a##_registration_hash, client_index); \
427 foreach_registration_hash;
432 #define API_LINK_STATE_EVENT 1
433 #define API_ADMIN_UP_DOWN_EVENT 2
436 event_data_cmp (void * a1, void * a2)
441 return (word) e1[0] - (word) e2[0];
445 link_state_process (vlib_main_t * vm,
446 vlib_node_runtime_t * rt,
449 vpe_api_main_t * vam = &vpe_api_main;
450 vnet_main_t * vnm = vam->vnet_main;
451 vnet_sw_interface_t * swif;
452 uword * event_data = 0;
453 vpe_client_registration_t *reg;
455 u32 prev_sw_if_index;
456 unix_shared_memory_queue_t * q;
458 vam->link_state_process_up = 1;
461 vlib_process_wait_for_event (vm);
463 /* Unified list of changed link or admin state sw_if_indices */
464 vlib_process_get_events_with_type
465 (vm, &event_data, API_LINK_STATE_EVENT);
466 vlib_process_get_events_with_type
467 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
469 /* Sort, so we can eliminate duplicates */
470 vec_sort_with_function (event_data, event_data_cmp);
472 prev_sw_if_index = ~0;
474 for (i = 0; i < vec_len(event_data); i++) {
475 /* Only one message per swif */
476 if (prev_sw_if_index == event_data[i])
478 prev_sw_if_index = event_data[i];
480 pool_foreach(reg, vam->interface_events_registrations,
482 q = vl_api_client_index_to_input_queue (reg->client_index);
484 // sw_interface may be deleted already
485 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
488 swif = vnet_get_sw_interface (vnm, event_data[i]);
489 send_sw_interface_flags (vam, q, swif);
494 vec_reset_length (event_data);
500 static clib_error_t *
501 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
502 static clib_error_t *
503 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
505 VLIB_REGISTER_NODE (link_state_process_node,static) = {
506 .function = link_state_process,
507 .type = VLIB_NODE_TYPE_PROCESS,
508 .name = "vpe-link-state-process",
511 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
512 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
514 static clib_error_t *
515 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
517 vpe_api_main_t * vam = &vpe_api_main;
518 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
520 if (vam->link_state_process_up)
521 vlib_process_signal_event (vam->vlib_main,
522 link_state_process_node.index,
523 API_LINK_STATE_EVENT,
528 static clib_error_t *
529 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
531 vpe_api_main_t * vam = &vpe_api_main;
534 * Note: it's perfectly fair to set a subif admin up / admin down.
535 * Note the subtle distinction between this routine and the previous
538 if (vam->link_state_process_up)
539 vlib_process_signal_event (vam->vlib_main,
540 link_state_process_node.index,
541 API_ADMIN_UP_DOWN_EVENT,
546 #define pub_sub_handler(lca,UCA) \
547 static void vl_api_want_##lca##_t_handler ( \
548 vl_api_want_##lca##_t *mp) \
550 vpe_api_main_t *vam = &vpe_api_main; \
551 vpe_client_registration_t *rp; \
552 vl_api_want_##lca##_reply_t *rmp; \
556 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
558 if (mp->enable_disable) { \
559 clib_warning ("pid %d: already enabled...", mp->pid); \
560 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
563 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
564 pool_put (vam->lca##_registrations, rp); \
565 hash_unset (vam->lca##_registration_hash, \
570 if (mp->enable_disable == 0) { \
571 clib_warning ("pid %d: already disabled...", mp->pid); \
572 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
575 pool_get (vam->lca##_registrations, rp); \
576 rp->client_index = mp->client_index; \
577 rp->client_pid = mp->pid; \
578 hash_set (vam->lca##_registration_hash, rp->client_index, \
579 rp - vam->lca##_registrations); \
582 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
585 pub_sub_handler (interface_events,INTERFACE_EVENTS)
586 pub_sub_handler (oam_events,OAM_EVENTS)
588 #define RESOLUTION_EVENT 1
589 #define RESOLUTION_PENDING_EVENT 2
590 #define IP4_ARP_EVENT 3
592 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
593 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
594 static int mpls_ethernet_add_del_tunnel_2_t_handler
595 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
597 void handle_ip4_arp_event (u32 pool_index)
599 vpe_api_main_t * vam = &vpe_api_main;
600 vnet_main_t * vnm = vam->vnet_main;
601 vlib_main_t * vm = vam->vlib_main;
602 vl_api_ip4_arp_event_t * event;
603 vl_api_ip4_arp_event_t * mp;
604 unix_shared_memory_queue_t * q;
606 /* Client can cancel, die, etc. */
607 if (pool_is_free_index (vam->arp_events, pool_index))
610 event = pool_elt_at_index (vam->arp_events, pool_index);
612 q = vl_api_client_index_to_input_queue (event->client_index);
614 (void) vnet_add_del_ip4_arp_change_event
615 (vnm, arp_change_delete_callback,
616 event->pid, &event->address,
617 vpe_resolver_process_node.index, IP4_ARP_EVENT,
618 ~0 /* pool index, notused */, 0 /* is_add */);
622 if (q->cursize < q->maxsize) {
623 mp = vl_msg_api_alloc (sizeof (*mp));
624 clib_memcpy (mp, event, sizeof (*mp));
625 vl_msg_api_send_shmem (q, (u8 *)&mp);
627 static f64 last_time;
629 * Throttle syslog msgs.
630 * It's pretty tempting to just revoke the registration...
632 if (vlib_time_now (vm) > last_time + 10.0) {
633 clib_warning ("arp event for %U to pid %d: queue stuffed!",
634 format_ip4_address, &event->address, event->pid);
635 last_time = vlib_time_now(vm);
641 resolver_process (vlib_main_t * vm,
642 vlib_node_runtime_t * rt,
646 uword *event_data = 0;
648 vpe_api_main_t * vam = &vpe_api_main;
649 pending_route_t * pr;
650 vl_api_ip_add_del_route_t * adr;
651 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
652 u32 * resolution_failures = 0;
657 vlib_process_wait_for_event_or_clock (vm, timeout);
659 event_type = vlib_process_get_events (vm, &event_data);
661 switch (event_type) {
662 case RESOLUTION_PENDING_EVENT:
666 case RESOLUTION_EVENT:
667 for (i = 0; i < vec_len(event_data); i++) {
669 * Resolution events can occur long after the
670 * original request has timed out. $$$ add a cancel
673 if (pool_is_free_index (vam->pending_routes, event_data[i]))
676 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
680 switch (pr->resolve_type) {
681 case RESOLVE_IP4_ADD_DEL_ROUTE:
682 rv = ip4_add_del_route_t_handler (adr);
683 clib_warning ("resolver: add %U/%d via %U %s",
685 (ip4_address_t *)&(adr->dst_address),
686 adr->dst_address_length,
688 (ip4_address_t *)&(adr->next_hop_address),
689 (rv >= 0) ? "succeeded" : "failed");
692 case RESOLVE_IP6_ADD_DEL_ROUTE:
693 rv = ip6_add_del_route_t_handler (adr);
694 clib_warning ("resolver: add %U/%d via %U %s",
696 (ip6_address_t *)&(adr->dst_address),
697 adr->dst_address_length,
699 (ip6_address_t *)&(adr->next_hop_address),
700 (rv >= 0) ? "succeeded" : "failed");
703 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
704 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
705 clib_warning ("resolver: add mpls-o-e via %U %s",
707 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
708 (rv >= 0) ? "succeeded" : "failed");
712 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
714 pool_put (vam->pending_routes, pr);
719 for (i = 0; i < vec_len(event_data); i++)
720 handle_ip4_arp_event (event_data[i]);
723 case ~0: /* timeout, retry pending resolutions */
724 pool_foreach (pr, vam->pending_routes,
730 /* May fail, e.g. due to interface down */
731 switch (pr->resolve_type) {
732 case RESOLVE_IP4_ADD_DEL_ROUTE:
733 e = ip4_probe_neighbor
734 (vm, (ip4_address_t *)&(adr->next_hop_address),
735 ntohl(adr->next_hop_sw_if_index));
738 case RESOLVE_IP6_ADD_DEL_ROUTE:
739 e = ip6_probe_neighbor
740 (vm, (ip6_address_t *)&(adr->next_hop_address),
741 ntohl(adr->next_hop_sw_if_index));
744 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
746 e = ip4_probe_neighbor
748 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
749 pme->resolve_opaque);
753 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
757 clib_error_report (e);
759 adr->resolve_attempts = 1;
761 pme->resolve_attempts = 1;
765 adr->resolve_attempts -= 1;
766 if (adr->resolve_attempts == 0)
767 vec_add1 (resolution_failures,
768 pr - vam->pending_routes);
770 pme->resolve_attempts -= 1;
771 if (pme->resolve_attempts == 0)
772 vec_add1 (resolution_failures,
773 pr - vam->pending_routes);
777 for (i = 0; i < vec_len (resolution_failures); i++) {
778 pr = pool_elt_at_index (vam->pending_routes,
779 resolution_failures[i]);
783 switch (pr->resolve_type) {
784 case RESOLVE_IP4_ADD_DEL_ROUTE:
785 clib_warning ("resolver: add %U/%d via %U retry failure",
787 (ip4_address_t *)&(adr->dst_address),
788 adr->dst_address_length,
790 (ip4_address_t *)&(adr->next_hop_address));
793 case RESOLVE_IP6_ADD_DEL_ROUTE:
794 clib_warning ("resolver: add %U/%d via %U retry failure",
796 (ip6_address_t *)&(adr->dst_address),
797 adr->dst_address_length,
799 (ip6_address_t *)&(adr->next_hop_address));
802 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
803 clib_warning ("resolver: add mpls-o-e via %U retry failure",
805 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
809 clib_warning ("BUG");
811 pool_put(vam->pending_routes, pr);
813 vec_reset_length (resolution_failures);
816 if (pool_elts (vam->pending_routes) == 0)
818 vec_reset_length (event_data);
820 return 0; /* or not */
823 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
824 .function = resolver_process,
825 .type = VLIB_NODE_TYPE_PROCESS,
826 .name = "vpe-route-resolver-process",
829 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
831 ip4_main_t * im = &ip4_main;
832 ip_lookup_main_t * lm = &im->lookup_main;
833 vnet_classify_main_t * cm = &vnet_classify_main;
834 stats_main_t * sm = &stats_main;
835 ip4_add_del_route_args_t a;
836 ip4_address_t next_hop_address;
838 vpe_api_main_t * vam = &vpe_api_main;
839 vnet_main_t * vnm = vam->vnet_main;
840 vlib_main_t * vm = vlib_get_main();
841 pending_route_t * pr;
842 vl_api_ip_add_del_route_t * adr;
846 ip_adjacency_t *nh_adj, *add_adj = 0;
848 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
850 if (mp->create_vrf_if_needed) {
852 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
854 fib_index = f->index;
856 /* No such VRF, and we weren't asked to create one */
857 return VNET_API_ERROR_NO_SUCH_FIB;
863 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
864 ntohl(mp->next_hop_sw_if_index)))
865 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
867 clib_memcpy (next_hop_address.data, mp->next_hop_address,
868 sizeof (next_hop_address.data));
870 /* Arp for the next_hop if necessary */
871 if (mp->is_add && mp->resolve_if_needed) {
873 ip_adjacency_t * adj;
875 lookup_result = ip4_fib_lookup_with_table
876 (im, fib_index, &next_hop_address, 1 /* disable default route */);
878 adj = ip_get_adjacency (lm, lookup_result);
880 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
881 pool_get (vam->pending_routes, pr);
882 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
884 clib_memcpy (adr, mp, sizeof (*adr));
885 /* recursion block, "just in case" */
886 adr->resolve_if_needed = 0;
887 adr->resolve_attempts = ntohl(mp->resolve_attempts);
888 vnet_register_ip4_arp_resolution_event
889 (vnm, &next_hop_address, vpe_resolver_process_node.index,
890 RESOLUTION_EVENT, pr - vam->pending_routes);
892 vlib_process_signal_event
893 (vm, vpe_resolver_process_node.index,
894 RESOLUTION_PENDING_EVENT, 0 /* data */);
896 /* The interface may be down, etc. */
897 e = ip4_probe_neighbor
898 (vm, (ip4_address_t *)&(mp->next_hop_address),
899 ntohl(mp->next_hop_sw_if_index));
902 clib_error_report(e);
904 return VNET_API_ERROR_IN_PROGRESS;
908 if (mp->is_multipath) {
911 dslock (sm, 1 /* release hint */, 10 /* tag */);
914 flags = IP4_ROUTE_FLAG_ADD;
916 flags = IP4_ROUTE_FLAG_DEL;
919 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
921 ip4_add_del_route_next_hop (im, flags,
922 (ip4_address_t *) mp->dst_address,
923 (u32) mp->dst_address_length,
924 (ip4_address_t *) mp->next_hop_address,
925 ntohl(mp->next_hop_sw_if_index),
926 (u32) mp->next_hop_weight,
933 memset (&a, 0, sizeof (a));
934 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
936 a.dst_address_length = mp->dst_address_length;
938 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
939 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
940 a.table_index_or_table_id = fib_index;
945 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
947 dslock (sm, 1 /* release hint */, 2 /* tag */);
951 ai = lm->drop_adj_index;
952 else if (mp->is_local)
953 ai = lm->local_adj_index;
954 else if (mp->is_classify) {
956 memset(&cadj, 0, sizeof(cadj));
957 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
958 cadj.classify.table_index = ntohl(mp->classify_table_index);
959 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
961 return VNET_API_ERROR_NO_SUCH_TABLE;
963 vec_add1 (add_adj, cadj);
967 ai = ip4_fib_lookup_with_table
968 (im, fib_index, &next_hop_address,
969 1 /* disable default route */);
970 if (ai == lm->miss_adj_index) {
972 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
976 nh_adj = ip_get_adjacency (lm, ai);
977 vec_add1 (add_adj, nh_adj[0]);
978 if (mp->lookup_in_vrf) {
979 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
981 add_adj[0].explicit_fib_index = p[0];
985 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
989 ip_adjacency_t * adj;
990 int disable_default_route = 1;
992 /* Trying to delete the default route? */
993 if (a.dst_address.as_u32 == 0 &&
994 a.dst_address_length == 0)
995 disable_default_route = 0;
997 ai = ip4_fib_lookup_with_table
998 (im, fib_index, &a.dst_address, disable_default_route);
999 if (ai == lm->miss_adj_index) {
1001 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1004 adj = ip_get_adjacency (lm, ai);
1005 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1007 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1013 a.add_adj = add_adj;
1014 a.n_add_adj = vec_len(add_adj);
1015 ip4_add_del_route (im, &a);
1023 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1025 ip6_main_t * im = &ip6_main;
1026 ip_lookup_main_t * lm = &im->lookup_main;
1027 vnet_main_t * vnm = vnet_get_main();
1028 vlib_main_t * vm = vlib_get_main();
1029 vpe_api_main_t * vam = &vpe_api_main;
1030 stats_main_t * sm = &stats_main;
1031 ip6_add_del_route_args_t a;
1032 ip6_address_t next_hop_address;
1033 pending_route_t * pr;
1034 vl_api_ip_add_del_route_t * adr;
1039 ip_adjacency_t * nh_adj, * add_adj = 0;
1042 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1045 if (mp->create_vrf_if_needed) {
1047 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1049 fib_index = f->index;
1051 /* No such VRF, and we weren't asked to create one */
1052 return VNET_API_ERROR_NO_SUCH_FIB;
1058 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1059 ntohl(mp->next_hop_sw_if_index)))
1060 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1062 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1063 sizeof (next_hop_address.as_u8));
1065 /* Arp for the next_hop if necessary */
1066 if (mp->is_add && mp->resolve_if_needed) {
1068 ip_adjacency_t * adj;
1070 lookup_result = ip6_fib_lookup_with_table
1071 (im, fib_index, &next_hop_address);
1073 adj = ip_get_adjacency (lm, lookup_result);
1075 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1076 pool_get (vam->pending_routes, pr);
1078 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1079 clib_memcpy (adr, mp, sizeof (*adr));
1080 /* recursion block, "just in case" */
1081 adr->resolve_if_needed = 0;
1082 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1083 vnet_register_ip6_neighbor_resolution_event
1084 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1085 RESOLUTION_EVENT, pr - vam->pending_routes);
1087 vlib_process_signal_event
1088 (vm, vpe_resolver_process_node.index,
1089 RESOLUTION_PENDING_EVENT, 0 /* data */);
1091 /* The interface may be down, etc. */
1092 e = ip6_probe_neighbor
1093 (vm, (ip6_address_t *)&(mp->next_hop_address),
1094 ntohl(mp->next_hop_sw_if_index));
1097 clib_error_report(e);
1099 return VNET_API_ERROR_IN_PROGRESS;
1103 if (mp->is_multipath) {
1106 dslock (sm, 1 /* release hint */, 11 /* tag */);
1109 flags = IP6_ROUTE_FLAG_ADD;
1111 flags = IP6_ROUTE_FLAG_DEL;
1114 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1116 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1117 (u32) mp->dst_address_length,
1118 (ip6_address_t *)mp->next_hop_address,
1119 ntohl(mp->next_hop_sw_if_index),
1120 (u32) mp->next_hop_weight,
1127 memset (&a, 0, sizeof (a));
1128 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1130 a.dst_address_length = mp->dst_address_length;
1132 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1133 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1134 a.table_index_or_table_id = fib_index;
1139 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1141 dslock (sm, 1 /* release hint */, 3 /* tag */);
1145 ai = lm->drop_adj_index;
1146 else if (mp->is_local)
1147 ai = lm->local_adj_index;
1149 ai = ip6_fib_lookup_with_table
1150 (im, fib_index, &next_hop_address);
1151 if (ai == lm->miss_adj_index) {
1153 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1157 nh_adj = ip_get_adjacency (lm, ai);
1158 vec_add1 (add_adj, nh_adj[0]);
1159 if (mp->lookup_in_vrf) {
1160 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1162 add_adj[0].explicit_fib_index = p[0];
1166 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1170 ip_adjacency_t * adj;
1172 ai = ip6_fib_lookup_with_table
1173 (im, fib_index, &a.dst_address);
1174 if (ai == lm->miss_adj_index) {
1176 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1178 adj = ip_get_adjacency (lm, ai);
1179 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1181 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1186 a.add_adj = add_adj;
1187 a.n_add_adj = vec_len(add_adj);
1188 ip6_add_del_route (im, &a);
1196 void vl_api_ip_add_del_route_t_handler (
1197 vl_api_ip_add_del_route_t *mp)
1199 vl_api_ip_add_del_route_reply_t * rmp;
1201 vnet_main_t * vnm = vnet_get_main();
1206 rv = ip6_add_del_route_t_handler (mp);
1208 rv = ip4_add_del_route_t_handler (mp);
1210 rv = (rv == 0) ? vnm->api_errno : rv;
1212 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1215 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1216 u32 sw_if_index, u8 *next_hop_addr)
1218 vl_api_ip_add_del_route_t mp;
1221 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1224 * Configure default IP route:
1225 * - ip route add 0.0.0.0/1 via <GW IP>
1226 * - ip route add 128.0.0.0/1 via <GW IP>
1228 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1230 mp.resolve_attempts = ~0;
1231 mp.resolve_if_needed = 1;
1233 mp.is_ipv6 = is_ipv6;
1234 mp.next_hop_weight = 1;
1236 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1239 rv = ip6_add_del_route_t_handler (&mp);
1242 mp.dst_address_length = 1;
1244 mp.dst_address[0] = 0;
1245 rv = ip4_add_del_route_t_handler (&mp);
1247 mp.dst_address[0] = 128;
1248 rv |= ip4_add_del_route_t_handler (&mp);
1252 clib_error_return (0, "failed to config default IP route");
1257 vl_api_sw_interface_add_del_address_t_handler
1258 (vl_api_sw_interface_add_del_address_t *mp)
1260 vlib_main_t *vm = vlib_get_main();
1261 vl_api_sw_interface_add_del_address_reply_t * rmp;
1265 VALIDATE_SW_IF_INDEX(mp);
1267 is_del = mp->is_add == 0;
1270 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1271 else if (mp->is_ipv6)
1272 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1273 (void *)mp->address,
1274 mp->address_length, is_del);
1276 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1277 (void *) mp->address,
1278 mp->address_length, is_del);
1280 BAD_SW_IF_INDEX_LABEL;
1282 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1286 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1289 u32 table_id = ntohl(mp->vrf_id);
1290 u32 sw_if_index = ntohl(mp->sw_if_index);
1291 vl_api_sw_interface_set_table_reply_t * rmp;
1292 stats_main_t * sm = &stats_main;
1294 VALIDATE_SW_IF_INDEX(mp);
1296 dslock (sm, 1 /* release hint */, 4 /* tag */);
1299 ip6_main_t * im = &ip6_main;
1301 find_ip6_fib_by_table_index_or_id (im, table_id,
1302 IP6_ROUTE_FLAG_TABLE_ID);
1304 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1305 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1307 rv = VNET_API_ERROR_NO_SUCH_FIB;
1310 ip4_main_t * im = &ip4_main;
1311 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1312 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1314 /* Truthfully this can't fail */
1316 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1317 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1319 rv = VNET_API_ERROR_NO_SUCH_FIB;
1324 BAD_SW_IF_INDEX_LABEL;
1326 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1330 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1332 vlib_main_t *vm = vlib_get_main();
1333 vl_api_sw_interface_set_vpath_reply_t * rmp;
1336 u32 sw_if_index = ntohl(mp->sw_if_index);
1337 ip4_main_t *ip4m = &ip4_main;
1338 ip6_main_t *ip6m = &ip6_main;
1339 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1340 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1341 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1342 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1343 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1344 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1346 VALIDATE_SW_IF_INDEX(mp);
1348 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1350 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1351 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1352 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1353 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1354 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1355 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1356 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1357 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1358 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1359 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1360 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1361 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1362 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1363 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1364 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1365 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1367 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1368 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1369 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1370 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1371 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1372 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1373 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1374 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1375 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1376 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1377 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1378 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1379 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1380 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1381 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1382 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1385 BAD_SW_IF_INDEX_LABEL;
1387 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1391 vl_api_sw_interface_set_l2_xconnect_t_handler (
1392 vl_api_sw_interface_set_l2_xconnect_t *mp)
1394 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1396 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1397 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1398 vlib_main_t *vm = vlib_get_main();
1399 vnet_main_t *vnm = vnet_get_main();
1401 VALIDATE_RX_SW_IF_INDEX(mp);
1404 VALIDATE_TX_SW_IF_INDEX(mp);
1405 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1406 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1408 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1411 BAD_RX_SW_IF_INDEX_LABEL;
1412 BAD_TX_SW_IF_INDEX_LABEL;
1414 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1418 vl_api_sw_interface_set_l2_bridge_t_handler (
1419 vl_api_sw_interface_set_l2_bridge_t *mp)
1421 bd_main_t * bdm = &bd_main;
1422 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1424 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1425 u32 bd_id = ntohl(mp->bd_id);
1429 vlib_main_t *vm = vlib_get_main();
1430 vnet_main_t *vnm = vnet_get_main();
1432 VALIDATE_RX_SW_IF_INDEX(mp);
1434 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1437 //VALIDATE_TX_SW_IF_INDEX(mp);
1438 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1439 rx_sw_if_index, bd_index, bvi, shg, 0);
1441 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1444 BAD_RX_SW_IF_INDEX_LABEL;
1446 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1450 vl_api_bridge_domain_add_del_t_handler (
1451 vl_api_bridge_domain_add_del_t *mp)
1453 vlib_main_t * vm = vlib_get_main ();
1454 bd_main_t * bdm = &bd_main;
1455 vl_api_bridge_domain_add_del_reply_t * rmp;
1457 u32 enable_flags = 0, disable_flags = 0;
1458 u32 bd_id = ntohl(mp->bd_id);
1462 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1465 enable_flags |= L2_FLOOD;
1467 disable_flags |= L2_FLOOD;
1470 enable_flags |= L2_UU_FLOOD;
1472 disable_flags |= L2_UU_FLOOD;
1475 enable_flags |= L2_FWD;
1477 disable_flags |= L2_FWD;
1480 enable_flags |= L2_ARP_TERM;
1482 disable_flags |= L2_ARP_TERM;
1485 enable_flags |= L2_LEARN;
1487 disable_flags |= L2_LEARN;
1490 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1493 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1496 rv = bd_delete_bd_index(bdm, bd_id);
1498 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1501 static void vl_api_bridge_domain_details_t_handler (
1502 vl_api_bridge_domain_details_t * mp)
1504 clib_warning ("BUG");
1507 static void vl_api_bridge_domain_sw_if_details_t_handler (
1508 vl_api_bridge_domain_sw_if_details_t * mp)
1510 clib_warning ("BUG");
1513 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1514 l2_bridge_domain_t * bd_config,
1518 vl_api_bridge_domain_details_t * mp;
1520 mp = vl_msg_api_alloc (sizeof (*mp));
1521 memset (mp, 0, sizeof (*mp));
1522 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1523 mp->bd_id = ntohl (bd_config->bd_id);
1524 mp->flood = bd_feature_flood (bd_config);
1525 mp->uu_flood = bd_feature_uu_flood (bd_config);
1526 mp->forward = bd_feature_forward (bd_config);
1527 mp->learn = bd_feature_learn (bd_config);
1528 mp->arp_term = bd_feature_arp_term (bd_config);
1529 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1530 mp->n_sw_ifs = ntohl (n_sw_ifs);
1531 mp->context = context;
1533 vl_msg_api_send_shmem (q, (u8 *)&mp);
1536 static void send_bd_sw_if_details (l2input_main_t * l2im,
1537 unix_shared_memory_queue_t *q,
1538 l2_flood_member_t * member, u32 bd_id,
1541 vl_api_bridge_domain_sw_if_details_t * mp;
1542 l2_input_config_t * input_cfg;
1544 mp = vl_msg_api_alloc (sizeof (*mp));
1545 memset (mp, 0, sizeof (*mp));
1546 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1547 mp->bd_id = ntohl (bd_id);
1548 mp->sw_if_index = ntohl (member->sw_if_index);
1549 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1550 mp->shg = input_cfg->shg;
1551 mp->context = context;
1553 vl_msg_api_send_shmem (q, (u8 *)&mp);
1556 static void vl_api_bridge_domain_dump_t_handler (
1557 vl_api_bridge_domain_dump_t *mp)
1559 bd_main_t * bdm = &bd_main;
1560 l2input_main_t * l2im = &l2input_main;
1561 unix_shared_memory_queue_t * q;
1562 l2_bridge_domain_t * bd_config;
1563 u32 bd_id, bd_index;
1566 q = vl_api_client_index_to_input_queue (mp->client_index);
1571 bd_id = ntohl(mp->bd_id);
1573 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1574 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1575 for (; bd_index < end; bd_index++) {
1576 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1577 /* skip dummy bd_id 0 */
1578 if (bd_config && (bd_config->bd_id > 0)) {
1580 l2_flood_member_t * m;
1582 n_sw_ifs = vec_len (bd_config->members);
1583 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1585 vec_foreach (m, bd_config->members) {
1586 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1593 vl_api_l2fib_add_del_t_handler (
1594 vl_api_l2fib_add_del_t *mp)
1596 bd_main_t * bdm = &bd_main;
1597 l2input_main_t * l2im = &l2input_main;
1598 vl_api_l2fib_add_del_reply_t * rmp;
1601 u32 sw_if_index = ntohl(mp->sw_if_index);
1602 u32 bd_id = ntohl(mp->bd_id);
1610 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1612 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1613 goto bad_sw_if_index;
1618 VALIDATE_SW_IF_INDEX(mp);
1619 if (vec_len(l2im->configs) <= sw_if_index) {
1620 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1621 goto bad_sw_if_index;
1623 l2_input_config_t * config;
1624 config = vec_elt_at_index(l2im->configs, sw_if_index);
1625 if (config->bridge == 0) {
1626 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1627 goto bad_sw_if_index;
1630 static_mac = mp->static_mac ? 1 : 0;
1631 filter_mac = mp->filter_mac ? 1 : 0;
1632 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1635 l2fib_del_entry(mac, bd_index);
1638 BAD_SW_IF_INDEX_LABEL;
1640 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1644 vl_api_l2_flags_t_handler (
1645 vl_api_l2_flags_t *mp)
1647 vl_api_l2_flags_reply_t * rmp;
1649 u32 sw_if_index = ntohl(mp->sw_if_index);
1650 u32 flags = ntohl(mp->feature_bitmap);
1653 VALIDATE_SW_IF_INDEX(mp);
1656 if (flags & L2INPUT_FEAT_ ## a) \
1657 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1658 foreach_l2input_feat;
1661 BAD_SW_IF_INDEX_LABEL;
1663 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1667 vl_api_bridge_flags_t_handler (
1668 vl_api_bridge_flags_t *mp)
1670 vlib_main_t *vm = vlib_get_main();
1671 bd_main_t * bdm = &bd_main;
1672 vl_api_bridge_flags_reply_t * rmp;
1674 u32 bd_id = ntohl(mp->bd_id);
1676 u32 flags = ntohl(mp->feature_bitmap);
1679 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1681 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1687 bd_set_flags(vm, bd_index, flags, mp->is_set);
1690 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1691 rmp->resulting_feature_bitmap = ntohl(flags));
1695 vl_api_bd_ip_mac_add_del_t_handler (
1696 vl_api_bd_ip_mac_add_del_t *mp)
1698 bd_main_t * bdm = &bd_main;
1699 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1701 u32 bd_id = ntohl(mp->bd_id);
1705 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1707 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1712 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1713 mp->mac_address, mp->is_ipv6, mp->is_add))
1714 rv = VNET_API_ERROR_UNSPECIFIED;
1717 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1721 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1724 vl_api_tap_connect_reply_t * rmp;
1725 unix_shared_memory_queue_t * q;
1726 u32 sw_if_index = (u32)~0;
1728 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1729 mp->use_random_mac ? 0 : mp->mac_address,
1730 &sw_if_index, mp->renumber,
1731 ntohl(mp->custom_dev_instance));
1733 q = vl_api_client_index_to_input_queue (mp->client_index);
1737 rmp = vl_msg_api_alloc (sizeof (*rmp));
1738 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1739 rmp->context = mp->context;
1740 rmp->retval = ntohl(rv);
1741 rmp->sw_if_index = ntohl(sw_if_index);
1743 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1747 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1750 vl_api_tap_modify_reply_t * rmp;
1751 unix_shared_memory_queue_t * q;
1752 u32 sw_if_index = (u32)~0;
1754 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1755 mp->use_random_mac ? 0 : mp->mac_address,
1756 &sw_if_index, mp->renumber,
1757 ntohl(mp->custom_dev_instance));
1759 q = vl_api_client_index_to_input_queue (mp->client_index);
1763 rmp = vl_msg_api_alloc (sizeof (*rmp));
1764 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1765 rmp->context = mp->context;
1766 rmp->retval = ntohl(rv);
1767 rmp->sw_if_index = ntohl(sw_if_index);
1769 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1773 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1776 vpe_api_main_t * vam = &vpe_api_main;
1777 vl_api_tap_delete_reply_t * rmp;
1778 unix_shared_memory_queue_t * q;
1779 u32 sw_if_index = ntohl(mp->sw_if_index);
1781 rv = vnet_tap_delete (vm, sw_if_index);
1783 q = vl_api_client_index_to_input_queue (mp->client_index);
1787 rmp = vl_msg_api_alloc (sizeof (*rmp));
1788 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1789 rmp->context = mp->context;
1790 rmp->retval = ntohl(rv);
1792 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1795 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1799 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1801 vl_api_create_vlan_subif_reply_t * rmp;
1802 vnet_main_t * vnm = vnet_get_main();
1803 u32 hw_if_index, sw_if_index = (u32)~0;
1804 vnet_hw_interface_t * hi;
1807 vnet_sw_interface_t template;
1809 vnet_interface_main_t * im = &vnm->interface_main;
1810 u64 sup_and_sub_key;
1812 unix_shared_memory_queue_t * q;
1813 clib_error_t * error;
1815 VALIDATE_SW_IF_INDEX(mp);
1817 hw_if_index = ntohl(mp->sw_if_index);
1818 hi = vnet_get_hw_interface (vnm, hw_if_index);
1820 id = ntohl(mp->vlan_id);
1821 if (id == 0 || id > 4095) {
1822 rv = VNET_API_ERROR_INVALID_VLAN;
1826 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1828 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1830 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1834 kp = clib_mem_alloc (sizeof (*kp));
1835 *kp = sup_and_sub_key;
1837 memset (&template, 0, sizeof (template));
1838 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1839 template.sup_sw_if_index = hi->sw_if_index;
1840 template.sub.id = id;
1841 template.sub.eth.raw_flags = 0;
1842 template.sub.eth.flags.one_tag = 1;
1843 template.sub.eth.outer_vlan_id = id;
1844 template.sub.eth.flags.exact_match = 1;
1846 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1848 clib_error_report(error);
1849 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1852 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1853 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1855 BAD_SW_IF_INDEX_LABEL;
1858 q = vl_api_client_index_to_input_queue (mp->client_index);
1862 rmp = vl_msg_api_alloc (sizeof (*rmp));
1863 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1864 rmp->context = mp->context;
1865 rmp->retval = ntohl(rv);
1866 rmp->sw_if_index = ntohl(sw_if_index);
1867 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1871 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1873 vl_api_create_subif_reply_t * rmp;
1874 vnet_main_t * vnm = vnet_get_main();
1875 u32 sw_if_index = ~0;
1878 vnet_sw_interface_t *si;
1879 vnet_hw_interface_t *hi;
1880 vnet_sw_interface_t template;
1882 vnet_interface_main_t * im = &vnm->interface_main;
1883 u64 sup_and_sub_key;
1885 clib_error_t * error;
1887 VALIDATE_SW_IF_INDEX(mp);
1889 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1890 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1892 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1893 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1897 sw_if_index = si->sw_if_index;
1898 sub_id = ntohl(mp->sub_id);
1900 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1902 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1905 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1906 sw_if_index, sub_id);
1907 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1911 kp = clib_mem_alloc (sizeof (*kp));
1912 *kp = sup_and_sub_key;
1914 memset (&template, 0, sizeof (template));
1915 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1916 template.sup_sw_if_index = sw_if_index;
1917 template.sub.id = sub_id;
1918 template.sub.eth.flags.no_tags = mp->no_tags;
1919 template.sub.eth.flags.one_tag = mp->one_tag;
1920 template.sub.eth.flags.two_tags = mp->two_tags;
1921 template.sub.eth.flags.dot1ad = mp->dot1ad;
1922 template.sub.eth.flags.exact_match = mp->exact_match;
1923 template.sub.eth.flags.default_sub = mp->default_sub;
1924 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1925 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1926 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1927 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1929 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1931 clib_error_report (error);
1932 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1936 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1937 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1939 BAD_SW_IF_INDEX_LABEL;
1943 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1945 rmp->sw_if_index = ntohl(sw_if_index);
1950 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1952 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1954 stats_main_t * sm = &stats_main;
1955 u32 tunnel_sw_if_index = ~0;
1957 dslock (sm, 1 /* release hint */, 5 /* tag */);
1959 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1960 (ip4_address_t *)(mp->dst_address),
1961 (ip4_address_t *)(mp->intfc_address),
1962 (u32)(mp->intfc_address_length),
1963 ntohl(mp->inner_vrf_id),
1964 ntohl(mp->outer_vrf_id),
1965 &tunnel_sw_if_index,
1970 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1972 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1977 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1978 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1980 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1982 stats_main_t * sm = &stats_main;
1983 u32 tunnel_sw_if_index;
1985 dslock (sm, 1 /* release hint */, 5 /* tag */);
1987 rv = vnet_mpls_ethernet_add_del_tunnel
1988 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1989 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1990 ntohl(mp->tx_sw_if_index),
1991 &tunnel_sw_if_index,
1997 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1999 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2004 * This piece of misery brought to you because the control-plane
2005 * can't figure out the tx interface + dst-mac address all by itself
2007 static int mpls_ethernet_add_del_tunnel_2_t_handler
2008 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2010 pending_route_t * pr;
2011 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2012 vnet_main_t * vnm = vnet_get_main();
2013 vlib_main_t * vm = vlib_get_main();
2014 stats_main_t * sm = &stats_main;
2015 vpe_api_main_t * vam = &vpe_api_main;
2016 u32 inner_fib_index, outer_fib_index;
2017 ip4_main_t * im = &ip4_main;
2018 ip_lookup_main_t * lm = &im->lookup_main;
2019 ip_adjacency_t * adj = 0;
2022 u8 * dst_mac_address;
2026 u32 tunnel_sw_if_index;
2028 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2030 return VNET_API_ERROR_NO_SUCH_FIB;
2032 outer_fib_index = p[0];
2035 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2037 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2039 inner_fib_index = p[0];
2041 if (inner_fib_index == outer_fib_index)
2042 return VNET_API_ERROR_INVALID_VALUE;
2044 lookup_result = ip4_fib_lookup_with_table
2045 (im, outer_fib_index,
2046 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2047 1 /* disable default route */);
2049 adj = ip_get_adjacency (lm, lookup_result);
2050 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2052 if (mp->is_add && mp->resolve_if_needed) {
2053 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2054 pool_get (vam->pending_routes, pr);
2055 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2057 clib_memcpy (pme, mp, sizeof (*pme));
2058 /* recursion block, "just in case" */
2059 pme->resolve_if_needed = 0;
2060 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2061 pme->resolve_opaque = tx_sw_if_index;
2062 vnet_register_ip4_arp_resolution_event
2064 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2065 vpe_resolver_process_node.index,
2066 RESOLUTION_EVENT, pr - vam->pending_routes);
2068 vlib_process_signal_event
2069 (vm, vpe_resolver_process_node.index,
2070 RESOLUTION_PENDING_EVENT, 0 /* data */);
2072 /* The interface may be down, etc. */
2073 e = ip4_probe_neighbor
2074 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2078 clib_error_report(e);
2080 return VNET_API_ERROR_IN_PROGRESS;
2084 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2085 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2088 vnet_rewrite_get_data_internal
2089 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2091 dslock (sm, 1 /* release hint */, 10 /* tag */);
2093 rv = vnet_mpls_ethernet_add_del_tunnel
2094 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2095 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2096 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2104 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2105 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2107 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2110 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2112 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2117 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2119 vl_api_mpls_add_del_encap_reply_t * rmp;
2121 static u32 * labels;
2124 vec_reset_length (labels);
2126 for (i = 0; i < mp->nlabels; i++)
2127 vec_add1 (labels, ntohl(mp->labels[i]));
2130 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2131 ntohl(mp->vrf_id), labels,
2132 ~0 /* policy_tunnel_index */,
2133 0 /* no_dst_hash */,
2137 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2141 vl_api_mpls_add_del_decap_t_handler
2142 (vl_api_mpls_add_del_decap_t *mp)
2144 vl_api_mpls_add_del_decap_reply_t * rmp;
2147 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2148 ntohl(mp->label), ntohl(mp->next_index),
2149 mp->s_bit, mp->is_add);
2151 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2155 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2157 vl_api_proxy_arp_add_del_reply_t * rmp;
2160 ip4_main_t * im = &ip4_main;
2161 stats_main_t * sm = &stats_main;
2162 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2163 ip4_address_t *hi_addr,
2164 u32 fib_index, int is_del);
2167 dslock (sm, 1 /* release hint */, 6 /* tag */);
2169 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2172 rv = VNET_API_ERROR_NO_SUCH_FIB;
2178 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2179 (ip4_address_t *)mp->hi_address,
2180 fib_index, mp->is_add == 0);
2184 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2188 vl_api_proxy_arp_intfc_enable_disable_t_handler
2189 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2192 vnet_main_t * vnm = vnet_get_main();
2193 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2194 vnet_sw_interface_t * si;
2197 VALIDATE_SW_IF_INDEX(mp);
2199 sw_if_index = ntohl(mp->sw_if_index);
2201 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2203 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2207 si = vnet_get_sw_interface (vnm, sw_if_index);
2211 if (mp->enable_disable)
2212 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2214 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2216 BAD_SW_IF_INDEX_LABEL;
2219 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2223 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2225 vl_api_ip_neighbor_add_del_reply_t * rmp;
2226 vnet_main_t * vnm = vnet_get_main();
2229 stats_main_t * sm = &stats_main;
2231 VALIDATE_SW_IF_INDEX(mp);
2233 dslock (sm, 1 /* release hint */, 7 /* tag */);
2237 rv = vnet_set_ip6_ethernet_neighbor
2238 (vm, ntohl(mp->sw_if_index),
2239 (ip6_address_t *)(mp->dst_address),
2240 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2242 rv = vnet_unset_ip6_ethernet_neighbor
2243 (vm, ntohl(mp->sw_if_index),
2244 (ip6_address_t *)(mp->dst_address),
2245 mp->mac_address, sizeof(mp->mac_address));
2247 ip4_main_t * im = &ip4_main;
2248 ip_lookup_main_t * lm = &im->lookup_main;
2249 ethernet_arp_ip4_over_ethernet_address_t a;
2251 ip_adjacency_t *nh_adj;
2253 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2255 rv = VNET_API_ERROR_NO_SUCH_FIB;
2261 * Unfortunately, folks have a penchant for
2262 * adding interface addresses to the ARP cache, and
2263 * wondering why the forwarder eventually ASSERTs...
2265 ai = ip4_fib_lookup_with_table
2266 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2267 1 /* disable default route */);
2270 nh_adj = ip_get_adjacency (lm, ai);
2271 /* Never allow manipulation of a local adj! */
2272 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2273 clib_warning("%U matches local adj",
2275 (ip4_address_t *)(mp->dst_address));
2276 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2281 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2282 clib_memcpy (&a.ip4, mp->dst_address, 4);
2285 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2286 fib_index, &a, mp->is_static);
2288 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2292 BAD_SW_IF_INDEX_LABEL;
2295 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2299 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2302 vpe_main_t *rm = &vpe_main;
2303 ip4_main_t *im4 = &ip4_main;
2304 ip6_main_t *im6 = &ip6_main;
2305 ip_lookup_main_t * lm;
2310 u32 adj_index, sw_if_index;
2311 vl_api_is_address_reachable_t *rmp;
2312 ip_adjacency_t * adj;
2313 unix_shared_memory_queue_t *q;
2315 q = vl_api_client_index_to_input_queue (mp->client_index);
2317 increment_missing_api_client_counter (rm->vlib_main);
2321 rmp = vl_msg_api_alloc (sizeof (*rmp));
2322 clib_memcpy (rmp, mp, sizeof (*rmp));
2324 sw_if_index = mp->next_hop_sw_if_index;
2325 clib_memcpy (&addr, mp->address, sizeof (addr));
2327 lm = &im6->lookup_main;
2329 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2331 lm = &im4->lookup_main;
2333 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2335 if (adj_index == ~0) {
2339 adj = ip_get_adjacency (lm, adj_index);
2341 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2342 && adj->rewrite_header.sw_if_index == sw_if_index) {
2345 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2346 && adj->rewrite_header.sw_if_index == sw_if_index) {
2348 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2350 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2351 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2359 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2363 static void vl_api_sw_interface_details_t_handler (
2364 vl_api_sw_interface_details_t * mp)
2366 clib_warning ("BUG");
2369 static void vl_api_sw_interface_set_flags_t_handler (
2370 vl_api_sw_interface_set_flags_t * mp)
2372 vl_api_sw_interface_set_flags_reply_t *rmp;
2373 vnet_main_t * vnm = vnet_get_main();
2375 clib_error_t * error;
2378 VALIDATE_SW_IF_INDEX(mp);
2380 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2382 error = vnet_sw_interface_set_flags (vnm,
2383 ntohl(mp->sw_if_index),
2387 clib_error_report (error);
2390 BAD_SW_IF_INDEX_LABEL;
2391 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2394 static void vl_api_sw_interface_clear_stats_t_handler (
2395 vl_api_sw_interface_clear_stats_t * mp)
2397 vl_api_sw_interface_clear_stats_reply_t *rmp;
2399 vnet_main_t * vnm = vnet_get_main();
2400 vnet_interface_main_t * im = &vnm->interface_main;
2401 vlib_simple_counter_main_t * sm;
2402 vlib_combined_counter_main_t * cm;
2403 static vnet_main_t ** my_vnet_mains;
2404 int i, j, n_counters;
2408 vec_reset_length (my_vnet_mains);
2410 for (i = 0; i < vec_len (vnet_mains); i++)
2413 vec_add1 (my_vnet_mains, vnet_mains[i]);
2416 if (vec_len (vnet_mains) == 0)
2417 vec_add1 (my_vnet_mains, vnm);
2419 n_counters = vec_len (im->combined_sw_if_counters);
2421 for (j = 0; j < n_counters; j++)
2423 for (i = 0; i < vec_len(my_vnet_mains); i++)
2425 im = &my_vnet_mains[i]->interface_main;
2426 cm = im->combined_sw_if_counters + j;
2427 if (mp->sw_if_index == (u32)~0)
2428 vlib_clear_combined_counters (cm);
2430 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2434 n_counters = vec_len (im->sw_if_counters);
2436 for (j = 0; j < n_counters; j++)
2438 for (i = 0; i < vec_len(my_vnet_mains); i++)
2440 im = &my_vnet_mains[i]->interface_main;
2441 sm = im->sw_if_counters + j;
2442 if (mp->sw_if_index == (u32)~0)
2443 vlib_clear_simple_counters (sm);
2445 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2449 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2452 static void send_sw_interface_details (vpe_api_main_t * am,
2453 unix_shared_memory_queue_t *q,
2454 vnet_sw_interface_t * swif,
2455 u8 * interface_name,
2458 vl_api_sw_interface_details_t * mp;
2459 vnet_hw_interface_t * hi;
2461 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2463 mp = vl_msg_api_alloc (sizeof (*mp));
2464 memset (mp, 0, sizeof (*mp));
2465 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2466 mp->sw_if_index = ntohl(swif->sw_if_index);
2467 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2468 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2470 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2472 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2473 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2474 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2475 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2476 mp->link_mtu = ntohs(hi->max_packet_bytes);
2477 mp->context = context;
2479 strncpy ((char *) mp->interface_name,
2480 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2482 /* Send the L2 address for ethernet physical intfcs */
2483 if (swif->sup_sw_if_index == swif->sw_if_index
2484 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2485 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2486 ethernet_interface_t *ei;
2488 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2489 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2490 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2491 mp->l2_address_length = ntohl(sizeof (ei->address));
2492 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2493 vnet_sub_interface_t *sub = &swif->sub;
2494 mp->sub_id = ntohl(sub->id);
2495 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2496 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2497 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2498 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2499 mp->sub_exact_match = sub->eth.flags.exact_match;
2500 mp->sub_default = sub->eth.flags.default_sub;
2501 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2502 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2504 /* vlan tag rewrite data */
2505 u32 vtr_op = L2_VTR_DISABLED;
2506 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2508 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2509 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2510 // error - default to disabled
2511 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2512 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2515 mp->vtr_op = ntohl(vtr_op);
2516 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2517 mp->vtr_tag1 = ntohl(vtr_tag1);
2518 mp->vtr_tag2 = ntohl(vtr_tag2);
2522 vl_msg_api_send_shmem (q, (u8 *)&mp);
2525 static void send_sw_interface_flags (vpe_api_main_t * am,
2526 unix_shared_memory_queue_t *q,
2527 vnet_sw_interface_t * swif)
2529 vl_api_sw_interface_set_flags_t *mp;
2530 vnet_main_t * vnm = am->vnet_main;
2532 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2534 mp = vl_msg_api_alloc (sizeof (*mp));
2535 memset (mp, 0, sizeof (*mp));
2536 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2537 mp->sw_if_index = ntohl(swif->sw_if_index);
2539 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2541 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2543 vl_msg_api_send_shmem (q, (u8 *)&mp);
2546 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2547 unix_shared_memory_queue_t *q,
2549 __attribute__((unused));
2551 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2552 unix_shared_memory_queue_t *q,
2555 vl_api_sw_interface_set_flags_t *mp;
2557 mp = vl_msg_api_alloc (sizeof (*mp));
2558 memset (mp, 0, sizeof (*mp));
2559 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2560 mp->sw_if_index = ntohl(sw_if_index);
2562 mp->admin_up_down = 0;
2563 mp->link_up_down = 0;
2565 vl_msg_api_send_shmem (q, (u8 *)&mp);
2568 static void vl_api_sw_interface_dump_t_handler (
2569 vl_api_sw_interface_dump_t *mp)
2571 vpe_api_main_t * am = &vpe_api_main;
2572 vnet_sw_interface_t * swif;
2573 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2574 u8 * filter_string = 0, * name_string = 0;
2575 unix_shared_memory_queue_t * q;
2576 char * strcasestr (char *, char *); /* lnx hdr file botch */
2578 q = vl_api_client_index_to_input_queue (mp->client_index);
2583 if (mp->name_filter_valid) {
2584 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2585 filter_string = format (0, "%s%c", mp->name_filter, 0);
2588 pool_foreach (swif, im->sw_interfaces,
2590 name_string = format (name_string, "%U%c",
2591 format_vnet_sw_interface_name,
2592 am->vnet_main, swif, 0);
2594 if (mp->name_filter_valid == 0 ||
2595 strcasestr((char *) name_string, (char *) filter_string)) {
2597 send_sw_interface_details (am, q, swif, name_string, mp->context);
2599 _vec_len (name_string) = 0;
2602 vec_free (name_string);
2603 vec_free (filter_string);
2606 void send_oam_event (oam_target_t * t)
2608 vpe_api_main_t * vam = &vpe_api_main;
2609 unix_shared_memory_queue_t * q;
2610 vpe_client_registration_t *reg;
2611 vl_api_oam_event_t * mp;
2613 pool_foreach(reg, vam->oam_events_registrations,
2615 q = vl_api_client_index_to_input_queue (reg->client_index);
2617 mp = vl_msg_api_alloc (sizeof (*mp));
2618 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2619 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2620 mp->state = t->state;
2621 vl_msg_api_send_shmem (q, (u8 *)&mp);
2627 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2629 vl_api_oam_add_del_reply_t * rmp;
2632 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2633 (ip4_address_t *)mp->dst_address,
2637 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2641 vl_api_vnet_get_summary_stats_t_handler (
2642 vl_api_vnet_get_summary_stats_t *mp)
2644 stats_main_t * sm = &stats_main;
2645 vnet_interface_main_t * im = sm->interface_main;
2646 vl_api_vnet_summary_stats_reply_t *rmp;
2647 vlib_combined_counter_main_t * cm;
2650 u64 total_pkts[VLIB_N_RX_TX];
2651 u64 total_bytes[VLIB_N_RX_TX];
2653 unix_shared_memory_queue_t * q =
2654 vl_api_client_index_to_input_queue (mp->client_index);
2659 rmp = vl_msg_api_alloc (sizeof (*rmp));
2660 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2661 rmp->context = mp->context;
2664 memset (total_pkts, 0, sizeof (total_pkts));
2665 memset (total_bytes, 0, sizeof (total_bytes));
2667 vnet_interface_counter_lock (im);
2669 vec_foreach (cm, im->combined_sw_if_counters) {
2670 which = cm - im->combined_sw_if_counters;
2672 for (i = 0; i < vec_len (cm->maxi); i++) {
2673 vlib_get_combined_counter (cm, i, &v);
2674 total_pkts[which] += v.packets;
2675 total_bytes[which] += v.bytes;
2678 vnet_interface_counter_unlock (im);
2680 /* Note: in HOST byte order! */
2681 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2682 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2683 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2684 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2685 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2687 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2690 typedef CLIB_PACKED (struct {
2691 ip4_address_t address;
2693 u32 address_length : 6;
2698 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2700 vnet_main_t * vnm = vnet_get_main();
2701 vnet_interface_main_t * im = &vnm->interface_main;
2702 ip4_main_t * im4 = &ip4_main;
2703 static ip4_route_t * routes;
2704 static u32 * sw_if_indices_to_shut;
2705 stats_main_t * sm = &stats_main;
2710 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2711 u32 target_fib_id = ntohl(mp->vrf_id);
2713 dslock (sm, 1 /* release hint */, 8 /* tag */);
2715 vec_foreach (fib, im4->fibs) {
2716 vnet_sw_interface_t * si;
2718 if (fib->table_id != target_fib_id)
2721 /* remove any mpls/gre tunnels in this fib */
2722 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2724 /* remove any mpls encap/decap labels */
2725 mpls_fib_reset_labels (fib->table_id);
2727 /* remove any proxy arps in this fib */
2728 vnet_proxy_arp_fib_reset (fib->table_id);
2730 /* Set the flow hash for this fib to the default */
2731 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2733 vec_reset_length (sw_if_indices_to_shut);
2735 /* Shut down interfaces in this FIB / clean out intfc routes */
2736 pool_foreach (si, im->sw_interfaces,
2738 u32 sw_if_index = si->sw_if_index;
2740 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2741 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2743 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2746 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2747 sw_if_index = sw_if_indices_to_shut[i];
2748 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2750 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2751 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2752 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2755 vec_reset_length (routes);
2757 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2758 uword * hash = fib->adj_index_by_dst_address[i];
2762 x.address_length = i;
2764 hash_foreach_pair (p, hash,
2766 x.address.data_u32 = p->key;
2767 vec_add1 (routes, x);
2771 vec_foreach (r, routes) {
2772 ip4_add_del_route_args_t a;
2774 memset (&a, 0, sizeof (a));
2775 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2776 a.table_index_or_table_id = fib - im4->fibs;
2777 a.dst_address = r->address;
2778 a.dst_address_length = r->address_length;
2781 ip4_add_del_route (im4, &a);
2782 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2783 IP4_ROUTE_FLAG_FIB_INDEX);
2787 } /* vec_foreach (fib) */
2794 ip6_address_t address;
2801 ip6_route_t ** routep;
2802 } add_routes_in_fib_arg_t;
2804 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2806 add_routes_in_fib_arg_t * ap = arg;
2808 if (kvp->key[2]>>32 == ap->fib_index)
2810 ip6_address_t *addr;
2812 addr = (ip6_address_t *) kvp;
2813 vec_add2 (*ap->routep, r, 1);
2814 r->address = addr[0];
2815 r->address_length = kvp->key[2] & 0xFF;
2816 r->index = kvp->value;
2820 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2822 vnet_main_t * vnm = vnet_get_main();
2823 vnet_interface_main_t * im = &vnm->interface_main;
2824 ip6_main_t * im6 = &ip6_main;
2825 stats_main_t * sm = &stats_main;
2826 static ip6_route_t * routes;
2827 static u32 * sw_if_indices_to_shut;
2832 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2833 u32 target_fib_id = ntohl(mp->vrf_id);
2834 add_routes_in_fib_arg_t _a, *a=&_a;
2835 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2837 dslock (sm, 1 /* release hint */, 9 /* tag */);
2839 vec_foreach (fib, im6->fibs) {
2840 vnet_sw_interface_t * si;
2842 if (fib->table_id != target_fib_id)
2845 vec_reset_length (sw_if_indices_to_shut);
2847 /* Shut down interfaces in this FIB / clean out intfc routes */
2848 pool_foreach (si, im->sw_interfaces,
2850 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2852 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2855 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2856 sw_if_index = sw_if_indices_to_shut[i];
2857 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2859 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2860 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2861 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2864 vec_reset_length (routes);
2866 a->fib_index = fib - im6->fibs;
2867 a->routep = &routes;
2869 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2871 vec_foreach (r, routes) {
2872 ip6_add_del_route_args_t a;
2874 memset (&a, 0, sizeof (a));
2875 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2876 a.table_index_or_table_id = fib - im6->fibs;
2877 a.dst_address = r->address;
2878 a.dst_address_length = r->address_length;
2881 ip6_add_del_route (im6, &a);
2882 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2883 IP6_ROUTE_FLAG_FIB_INDEX);
2886 /* Reinstall the neighbor / router discovery routes */
2887 vnet_ip6_fib_init (im6, fib - im6->fibs);
2889 } /* vec_foreach (fib) */
2895 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2898 vl_api_reset_fib_reply_t * rmp;
2901 rv = ip6_reset_fib_t_handler (mp);
2903 rv = ip4_reset_fib_t_handler (mp);
2905 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2910 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2912 vl_api_dhcp_proxy_config_reply_t * rmp;
2915 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2916 (ip4_address_t *)(&mp->dhcp_src_address),
2917 (u32) ntohl(mp->vrf_id),
2918 (int) mp->insert_circuit_id,
2919 (int) (mp->is_add == 0));
2921 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2926 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2928 vl_api_dhcp_proxy_config_reply_t * rmp;
2931 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2932 (ip6_address_t *)(&mp->dhcp_src_address),
2933 (u32) ntohl(mp->vrf_id),
2934 (int) mp->insert_circuit_id,
2935 (int) (mp->is_add == 0));
2937 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2941 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2943 vl_api_dhcp_proxy_config_reply_t * rmp;
2946 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2947 (ip4_address_t *)(&mp->dhcp_src_address),
2948 (u32) ntohl(mp->rx_vrf_id),
2949 (u32) ntohl(mp->server_vrf_id),
2950 (int) mp->insert_circuit_id,
2951 (int) (mp->is_add == 0));
2953 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2958 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2960 vl_api_dhcp_proxy_config_reply_t * rmp;
2964 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2965 (ip6_address_t *)(&mp->dhcp_src_address),
2966 (u32) ntohl(mp->rx_vrf_id),
2967 (u32) ntohl(mp->server_vrf_id),
2968 (int) mp->insert_circuit_id,
2969 (int) (mp->is_add == 0));
2971 rv = VNET_API_ERROR_UNIMPLEMENTED;
2974 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2979 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2981 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2984 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2987 (int)mp->is_add == 0);
2989 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2992 (int)mp->is_add == 0);
2994 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2998 static void vl_api_dhcp_proxy_config_t_handler
2999 (vl_api_dhcp_proxy_config_t *mp)
3001 if (mp->is_ipv6 == 0)
3002 dhcpv4_proxy_config (mp);
3004 dhcpv6_proxy_config (mp);
3007 static void vl_api_dhcp_proxy_config_2_t_handler
3008 (vl_api_dhcp_proxy_config_2_t *mp)
3010 if (mp->is_ipv6 == 0)
3011 dhcpv4_proxy_config_2 (mp);
3013 dhcpv6_proxy_config_2 (mp);
3016 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3017 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3019 unix_shared_memory_queue_t * q;
3020 vl_api_dhcp_compl_event_t * mp;
3022 q = vl_api_client_index_to_input_queue (client_index);
3026 mp = vl_msg_api_alloc (sizeof (*mp));
3027 mp->client_index = client_index;
3029 mp->is_ipv6 = is_ipv6;
3030 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3031 mp->hostname[vec_len(hostname) + 1] = '\n';
3032 clib_memcpy (&mp->host_address[0], host_address, 16);
3033 clib_memcpy (&mp->router_address[0], router_address, 16);
3034 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3036 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3038 vl_msg_api_send_shmem (q, (u8 *)&mp);
3041 static void vl_api_dhcp_client_config_t_handler
3042 (vl_api_dhcp_client_config_t *mp)
3044 vlib_main_t *vm = vlib_get_main();
3045 vl_api_dhcp_client_config_reply_t * rmp;
3048 VALIDATE_SW_IF_INDEX(mp);
3050 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3051 mp->hostname, mp->is_add, mp->client_index,
3052 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3055 BAD_SW_IF_INDEX_LABEL;
3057 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3061 vl_api_sw_interface_ip6nd_ra_config_t_handler
3062 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3064 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3066 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3068 is_no = mp->is_no == 1;
3069 surpress = mp->surpress == 1;
3070 managed = mp->managed == 1;
3071 other = mp->other == 1;
3072 ll_option = mp->ll_option == 1;
3073 send_unicast = mp->send_unicast == 1;
3074 cease = mp->cease == 1;
3075 default_router = mp->default_router == 1;
3077 VALIDATE_SW_IF_INDEX(mp);
3079 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3080 surpress, managed, other,
3081 ll_option, send_unicast, cease,
3082 default_router, ntohl (mp->lifetime),
3083 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3084 ntohl(mp->max_interval), ntohl( mp->min_interval),
3087 BAD_SW_IF_INDEX_LABEL;
3089 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3093 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3094 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3096 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3098 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3100 VALIDATE_SW_IF_INDEX(mp);
3102 is_no = mp->is_no == 1;
3103 use_default = mp->use_default == 1;
3104 no_advertise = mp->no_advertise == 1;
3105 off_link = mp->off_link == 1;
3106 no_autoconfig = mp->no_autoconfig == 1;
3107 no_onlink = mp->no_onlink == 1;
3109 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3110 (ip6_address_t *)mp->address, mp->address_length,
3111 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3112 no_advertise, off_link, no_autoconfig, no_onlink,
3115 BAD_SW_IF_INDEX_LABEL;
3116 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3120 vl_api_sw_interface_ip6_enable_disable_t_handler
3121 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3123 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3124 vnet_main_t * vnm = vnet_get_main();
3126 clib_error_t * error;
3130 VALIDATE_SW_IF_INDEX(mp);
3132 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3133 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3136 clib_error_report(error);
3137 rv = VNET_API_ERROR_UNSPECIFIED;
3139 rv = vnm->api_errno;
3142 BAD_SW_IF_INDEX_LABEL;
3144 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3148 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3149 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3151 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3153 clib_error_t * error;
3154 vnet_main_t * vnm = vnet_get_main();
3158 VALIDATE_SW_IF_INDEX(mp);
3160 error = set_ip6_link_local_address(vm,
3161 ntohl(mp->sw_if_index),
3162 (ip6_address_t *)mp->address,
3163 mp->address_length);
3165 clib_error_report(error);
3166 rv = VNET_API_ERROR_UNSPECIFIED;
3168 rv = vnm->api_errno;
3171 BAD_SW_IF_INDEX_LABEL;
3173 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3176 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3178 vl_api_set_ip_flow_hash_reply_t *rmp;
3179 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3181 clib_warning ("unimplemented...");
3183 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3186 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3188 vl_api_set_ip_flow_hash_reply_t *rmp;
3191 u32 flow_hash_config = 0;
3193 table_id = ntohl(mp->vrf_id);
3195 #define _(a,b) if (mp->a) flow_hash_config |= b;
3196 foreach_flow_hash_bit;
3199 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3201 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3205 static void vl_api_set_ip_flow_hash_t_handler
3206 (vl_api_set_ip_flow_hash_t *mp)
3208 if (mp->is_ipv6 == 0)
3209 set_ip4_flow_hash (mp);
3211 set_ip6_flow_hash (mp);
3214 static void vl_api_sw_interface_set_unnumbered_t_handler
3215 (vl_api_sw_interface_set_unnumbered_t *mp)
3217 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3219 vnet_sw_interface_t * si;
3220 vnet_main_t *vnm = vnet_get_main();
3221 u32 sw_if_index, unnumbered_sw_if_index;
3223 sw_if_index = ntohl(mp->sw_if_index);
3224 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3227 * The API message field names are backwards from
3228 * the underlying data structure names.
3229 * It's not worth changing them now.
3231 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3232 unnumbered_sw_if_index)) {
3233 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3237 /* Only check the "use loop0" field when setting the binding */
3239 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3240 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3244 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3247 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3248 si->unnumbered_sw_if_index = sw_if_index;
3250 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3251 si->unnumbered_sw_if_index = (u32)~0;
3255 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3258 static void vl_api_create_loopback_t_handler
3259 (vl_api_create_loopback_t *mp)
3261 vl_api_create_loopback_reply_t * rmp;
3265 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3267 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3269 rmp->sw_if_index = ntohl (sw_if_index);
3273 static void vl_api_delete_loopback_t_handler
3274 (vl_api_delete_loopback_t *mp)
3276 vl_api_delete_loopback_reply_t * rmp;
3280 sw_if_index = ntohl (mp->sw_if_index);
3281 rv = vnet_delete_loopback_interface (sw_if_index);
3283 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3286 static void vl_api_control_ping_t_handler
3287 (vl_api_control_ping_t *mp)
3289 vl_api_control_ping_reply_t * rmp;
3292 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3294 rmp->vpe_pid = ntohl (getpid());
3298 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3300 u8 **shmem_vecp = (u8 **)arg;
3303 api_main_t * am = &api_main;
3306 shmem_vec = *shmem_vecp;
3308 offset = vec_len (shmem_vec);
3310 pthread_mutex_lock (&am->vlib_rp->mutex);
3311 oldheap = svm_push_data_heap (am->vlib_rp);
3313 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3315 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3317 svm_pop_heap (oldheap);
3318 pthread_mutex_unlock (&am->vlib_rp->mutex);
3320 *shmem_vecp = shmem_vec;
3324 static void vl_api_cli_request_t_handler
3325 (vl_api_cli_request_t *mp)
3327 vl_api_cli_reply_t *rp;
3328 unix_shared_memory_queue_t *q;
3329 vlib_main_t * vm = vlib_get_main();
3330 api_main_t * am = &api_main;
3331 unformat_input_t input;
3335 q = vl_api_client_index_to_input_queue (mp->client_index);
3339 rp = vl_msg_api_alloc (sizeof (*rp));
3340 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3341 rp->context = mp->context;
3343 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3345 vlib_cli_input (vm, &input, shmem_cli_output,
3348 pthread_mutex_lock (&am->vlib_rp->mutex);
3349 oldheap = svm_push_data_heap (am->vlib_rp);
3351 vec_add1(shmem_vec, 0);
3353 svm_pop_heap (oldheap);
3354 pthread_mutex_unlock (&am->vlib_rp->mutex);
3356 rp->reply_in_shmem = (uword)shmem_vec;
3358 vl_msg_api_send_shmem (q, (u8 *)&rp);
3361 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3364 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3365 vnet_main_t *vnm = vnet_get_main();
3366 clib_error_t * error;
3371 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3373 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3376 clib_error_report(error);
3377 rv = VNET_API_ERROR_UNSPECIFIED;
3379 rv = vnm->api_errno;
3382 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3385 static void vl_api_sr_tunnel_add_del_t_handler
3386 (vl_api_sr_tunnel_add_del_t *mp)
3389 clib_warning ("unimplemented");
3391 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3393 vl_api_sr_tunnel_add_del_reply_t * rmp;
3394 ip6_address_t * segments = 0, * seg;
3395 ip6_address_t * tags = 0, *tag;
3396 ip6_address_t * this_address;
3399 if (mp->n_segments == 0) {
3404 memset (a, 0, sizeof (*a));
3405 a->src_address = (ip6_address_t *)&mp->src_address;
3406 a->dst_address = (ip6_address_t *)&mp->dst_address;
3407 a->dst_mask_width = mp->dst_mask_width;
3408 a->flags_net_byte_order = mp->flags_net_byte_order;
3409 a->is_del = (mp->is_add == 0);
3410 a->rx_table_id = ntohl(mp->outer_vrf_id);
3411 a->tx_table_id = ntohl(mp->inner_vrf_id);
3413 a->name = format(0, "%s", mp->name);
3414 if (!(vec_len(a->name)))
3417 a->policy_name = format(0, "%s", mp->policy_name);
3418 if (!(vec_len(a->policy_name)))
3421 /* Yank segments and tags out of the API message */
3422 this_address = (ip6_address_t *)mp->segs_and_tags;
3423 for (i = 0; i < mp->n_segments; i++) {
3424 vec_add2 (segments, seg, 1);
3425 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3428 for (i = 0; i < mp->n_tags; i++) {
3429 vec_add2 (tags, tag, 1);
3430 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3434 a->segments = segments;
3437 rv = ip6_sr_add_del_tunnel (a);
3441 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3445 static void vl_api_sr_policy_add_del_t_handler
3446 (vl_api_sr_policy_add_del_t *mp)
3449 clib_warning ("unimplemented");
3451 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3453 vl_api_sr_policy_add_del_reply_t * rmp;
3456 memset (a, 0, sizeof (*a));
3457 a->is_del = (mp->is_add == 0);
3459 a->name = format(0, "%s", mp->name);
3460 if (!(vec_len(a->name)))
3462 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3466 if (!(mp->tunnel_names[0]))
3468 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3472 // start deserializing tunnel_names
3473 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3474 u8 * deser_tun_names = mp->tunnel_names;
3475 deser_tun_names += 1; //moving along
3478 int tun_name_len = 0;
3480 for (i=0; i < num_tunnels; i++)
3482 tun_name_len= *deser_tun_names;
3483 deser_tun_names += 1;
3484 vec_resize (tun_name, tun_name_len);
3485 memcpy(tun_name, deser_tun_names, tun_name_len);
3486 vec_add1 (a->tunnel_names, tun_name);
3487 deser_tun_names += tun_name_len;
3491 rv = ip6_sr_add_del_policy (a);
3495 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3499 static void vl_api_sr_multicast_map_add_del_t_handler
3500 (vl_api_sr_multicast_map_add_del_t *mp)
3503 clib_warning ("unimplemented");
3505 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3507 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3509 memset (a, 0, sizeof (*a));
3510 a->is_del = (mp->is_add == 0);
3512 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3513 a->policy_name = format(0, "%s", mp->policy_name);
3515 if (a->multicast_address == 0)
3521 if (!(a->policy_name))
3527 #if DPDK > 0 /* Cannot call replicate without DPDK */
3528 rv = ip6_sr_add_del_multicastmap (a);
3530 clib_warning ("multicast replication without DPDK not implemented");
3531 rv = VNET_API_ERROR_UNIMPLEMENTED;
3536 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3540 #define foreach_classify_add_del_table_field \
3545 _(match_n_vectors) \
3546 _(next_table_index) \
3549 static void vl_api_classify_add_del_table_t_handler
3550 (vl_api_classify_add_del_table_t * mp)
3552 vl_api_classify_add_del_table_reply_t * rmp;
3553 vnet_classify_main_t * cm = &vnet_classify_main;
3554 vnet_classify_table_t * t;
3558 foreach_classify_add_del_table_field;
3561 #define _(a) a = ntohl(mp->a);
3562 foreach_classify_add_del_table_field;
3565 /* The underlying API fails silently, on purpose, so check here */
3566 if (mp->is_add == 0)
3567 if (pool_is_free_index (cm->tables, table_index)) {
3568 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3572 rv = vnet_classify_add_del_table
3573 (cm, mp->mask, nbuckets, memory_size,
3574 skip_n_vectors, match_n_vectors,
3575 next_table_index, miss_next_index,
3576 &table_index, mp->is_add);
3579 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3581 if (rv == 0 && mp->is_add) {
3582 t = pool_elt_at_index (cm->tables, table_index);
3583 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3584 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3585 rmp->new_table_index = ntohl(table_index);
3587 rmp->skip_n_vectors = ~0;
3588 rmp->match_n_vectors = ~0;
3589 rmp->new_table_index = ~0;
3594 static void vl_api_classify_add_del_session_t_handler
3595 (vl_api_classify_add_del_session_t * mp)
3597 vnet_classify_main_t * cm = &vnet_classify_main;
3598 vl_api_classify_add_del_session_reply_t * rmp;
3600 u32 table_index, hit_next_index, opaque_index;
3603 table_index = ntohl (mp->table_index);
3604 hit_next_index = ntohl (mp->hit_next_index);
3605 opaque_index = ntohl (mp->opaque_index);
3606 advance = ntohl (mp->advance);
3608 rv = vnet_classify_add_del_session
3609 (cm, table_index, mp->match, hit_next_index, opaque_index,
3610 advance, mp->is_add);
3612 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3615 static void vl_api_classify_set_interface_ip_table_t_handler
3616 (vl_api_classify_set_interface_ip_table_t * mp)
3618 vlib_main_t * vm = vlib_get_main();
3619 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3621 u32 table_index, sw_if_index;
3623 table_index = ntohl (mp->table_index);
3624 sw_if_index = ntohl (mp->sw_if_index);
3626 VALIDATE_SW_IF_INDEX(mp);
3629 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3631 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3633 BAD_SW_IF_INDEX_LABEL;
3635 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3638 static void vl_api_classify_set_interface_l2_tables_t_handler
3639 (vl_api_classify_set_interface_l2_tables_t * mp)
3641 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3643 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3646 ip4_table_index = ntohl(mp->ip4_table_index);
3647 ip6_table_index = ntohl(mp->ip6_table_index);
3648 other_table_index = ntohl(mp->other_table_index);
3649 sw_if_index = ntohl(mp->sw_if_index);
3651 VALIDATE_SW_IF_INDEX(mp);
3653 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3654 ip6_table_index, other_table_index);
3657 if (ip4_table_index != ~0 || ip6_table_index != ~0
3658 || other_table_index != ~0)
3663 vnet_l2_classify_enable_disable (sw_if_index, enable);
3666 BAD_SW_IF_INDEX_LABEL;
3668 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3672 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3675 vl_api_l2_fib_clear_table_reply_t * rmp;
3677 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3678 * that is not currently implemented. When that TODO is fixed
3679 * this call should be changed to pass 1 instead of 0.
3681 l2fib_clear_table (0);
3683 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3686 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3691 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3694 vl_api_l2_interface_efp_filter_reply_t * rmp;
3695 vnet_main_t *vnm = vnet_get_main();
3697 // enable/disable the feature
3698 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3699 rv = vnm->api_errno;
3701 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3705 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3708 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3709 vnet_main_t * vnm = vnet_get_main();
3710 vlib_main_t * vm = vlib_get_main();
3713 VALIDATE_SW_IF_INDEX(mp);
3715 vtr_op = ntohl(mp->vtr_op);
3717 /* The L2 code is unsuspicious */
3719 case L2_VTR_DISABLED:
3724 case L2_VTR_TRANSLATE_1_1:
3725 case L2_VTR_TRANSLATE_1_2:
3726 case L2_VTR_TRANSLATE_2_1:
3727 case L2_VTR_TRANSLATE_2_2:
3731 rv = VNET_API_ERROR_INVALID_VALUE;
3732 goto bad_sw_if_index;
3735 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3736 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3739 BAD_SW_IF_INDEX_LABEL;
3741 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3745 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3749 vl_api_create_vhost_user_if_reply_t * rmp;
3750 u32 sw_if_index = (u32)~0;
3752 vnet_main_t * vnm = vnet_get_main();
3753 vlib_main_t * vm = vlib_get_main();
3755 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3756 mp->is_server, &sw_if_index, (u64)~0,
3757 mp->renumber, ntohl(mp->custom_dev_instance),
3758 (mp->use_custom_mac)?mp->mac_address:NULL);
3760 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3762 rmp->sw_if_index = ntohl (sw_if_index);
3768 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3772 vl_api_modify_vhost_user_if_reply_t * rmp;
3773 u32 sw_if_index = ntohl(mp->sw_if_index);
3775 vnet_main_t * vnm = vnet_get_main();
3776 vlib_main_t * vm = vlib_get_main();
3778 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3779 mp->is_server, sw_if_index, (u64)~0,
3780 mp->renumber, ntohl(mp->custom_dev_instance));
3782 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3787 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3791 vpe_api_main_t * vam = &vpe_api_main;
3792 vl_api_delete_vhost_user_if_reply_t * rmp;
3793 u32 sw_if_index = ntohl(mp->sw_if_index);
3795 vnet_main_t * vnm = vnet_get_main();
3796 vlib_main_t * vm = vlib_get_main();
3798 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3800 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3802 unix_shared_memory_queue_t * q =
3803 vl_api_client_index_to_input_queue (mp->client_index);
3807 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3812 static void vl_api_sw_interface_vhost_user_details_t_handler (
3813 vl_api_sw_interface_vhost_user_details_t * mp)
3815 clib_warning ("BUG");
3819 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3820 unix_shared_memory_queue_t *q,
3821 vhost_user_intf_details_t * vui,
3824 vl_api_sw_interface_vhost_user_details_t * mp;
3826 mp = vl_msg_api_alloc (sizeof (*mp));
3827 memset (mp, 0, sizeof (*mp));
3828 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3829 mp->sw_if_index = ntohl(vui->sw_if_index);
3830 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3831 mp->features = clib_net_to_host_u64 (vui->features);
3832 mp->is_server = vui->is_server;
3833 mp->num_regions = ntohl(vui->num_regions);
3834 mp->sock_errno = ntohl(vui->sock_errno);
3835 mp->context = context;
3837 strncpy ((char *) mp->sock_filename,
3838 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3839 strncpy ((char *) mp->interface_name,
3840 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3842 vl_msg_api_send_shmem (q, (u8 *)&mp);
3847 vl_api_sw_interface_vhost_user_dump_t_handler (
3848 vl_api_sw_interface_vhost_user_dump_t *mp)
3852 vpe_api_main_t * am = &vpe_api_main;
3853 vnet_main_t * vnm = vnet_get_main();
3854 vlib_main_t * vm = vlib_get_main();
3855 vhost_user_intf_details_t *ifaces = NULL;
3856 vhost_user_intf_details_t *vuid = NULL;
3857 unix_shared_memory_queue_t * q;
3859 q = vl_api_client_index_to_input_queue (mp->client_index);
3863 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3867 vec_foreach (vuid, ifaces) {
3868 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3874 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3875 unix_shared_memory_queue_t *q,
3880 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3881 u8 * if_name = NULL;
3882 vnet_sw_interface_t * si = NULL;
3884 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3886 if_name = format(if_name, "%U",
3887 format_vnet_sw_interface_name, lm->vnet_main, si);
3889 mp = vl_msg_api_alloc (sizeof (*mp));
3890 memset (mp, 0, sizeof (*mp));
3891 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3892 strncpy((char *)mp->interface_name,
3893 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3894 mp->sw_if_index = ntohl(si->sw_if_index);
3895 mp->local_session_id = s->local_session_id;
3896 mp->remote_session_id = s->remote_session_id;
3897 mp->local_cookie[0] = s->local_cookie[0];
3898 mp->local_cookie[1] = s->local_cookie[1];
3899 mp->remote_cookie = s->remote_cookie;
3900 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3901 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3902 mp->l2_sublayer_present = s->l2_sublayer_present;
3903 mp->context = context;
3905 vl_msg_api_send_shmem (q, (u8 *)&mp);
3908 static void send_ip_address_details (vpe_api_main_t * am,
3909 unix_shared_memory_queue_t * q,
3915 vl_api_ip_address_details_t * mp;
3917 mp = vl_msg_api_alloc (sizeof (*mp));
3918 memset (mp, 0, sizeof (*mp));
3919 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3922 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3924 u32 * tp = (u32 *)mp->ip;
3925 *tp = ntohl(*(u32*)ip);
3927 mp->prefix_length = prefix_length;
3928 mp->context = context;
3930 vl_msg_api_send_shmem (q, (u8 *)&mp);
3934 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3936 vpe_api_main_t * am = &vpe_api_main;
3937 unix_shared_memory_queue_t * q;
3940 ip6_main_t * im6 = &ip6_main;
3941 ip4_main_t * im4 = &ip4_main;
3942 ip_lookup_main_t * lm6 = &im6->lookup_main;
3943 ip_lookup_main_t * lm4 = &im4->lookup_main;
3944 ip_interface_address_t * ia = 0;
3945 u32 sw_if_index = ~0;
3946 int rv __attribute__ ((unused)) = 0;
3948 VALIDATE_SW_IF_INDEX(mp);
3950 sw_if_index = ntohl(mp->sw_if_index);
3952 q = vl_api_client_index_to_input_queue (mp->client_index);
3958 foreach_ip_interface_address (lm6, ia, sw_if_index,
3959 1 /* honor unnumbered */,
3961 r6 = ip_interface_address_get_address (lm6, ia);
3962 u16 prefix_length = ia->address_length;
3963 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3966 foreach_ip_interface_address (lm4, ia, sw_if_index,
3967 1 /* honor unnumbered */,
3969 r4 = ip_interface_address_get_address (lm4, ia);
3970 u16 prefix_length = ia->address_length;
3971 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3974 BAD_SW_IF_INDEX_LABEL;
3977 static void send_ip_details (vpe_api_main_t * am,
3978 unix_shared_memory_queue_t *q,
3982 vl_api_ip_details_t * mp;
3984 mp = vl_msg_api_alloc (sizeof (*mp));
3985 memset (mp, 0, sizeof (*mp));
3986 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3988 mp->sw_if_index = ntohl(sw_if_index);
3989 mp->context = context;
3991 vl_msg_api_send_shmem (q, (u8 *)&mp);
3995 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3996 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3998 vpe_api_main_t * am = &vpe_api_main;
3999 l2t_main_t * lm = &l2t_main;
4000 unix_shared_memory_queue_t * q;
4001 l2t_session_t *session;
4003 q = vl_api_client_index_to_input_queue (mp->client_index);
4007 pool_foreach (session, lm->sessions,
4009 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4014 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4015 unix_shared_memory_queue_t *q,
4016 tapcli_interface_details_t *tap_if,
4019 vl_api_sw_interface_tap_details_t * mp;
4020 mp = vl_msg_api_alloc (sizeof (*mp));
4021 memset (mp, 0, sizeof (*mp));
4022 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4023 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4024 strncpy((char *)mp->dev_name,
4025 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4026 mp->context = context;
4028 vl_msg_api_send_shmem (q, (u8 *)&mp);
4032 vl_api_sw_interface_tap_dump_t_handler (
4033 vl_api_sw_interface_tap_dump_t *mp)
4036 vpe_api_main_t * am = &vpe_api_main;
4037 unix_shared_memory_queue_t * q;
4038 tapcli_interface_details_t *tapifs = NULL;
4039 tapcli_interface_details_t *tap_if = NULL;
4041 q = vl_api_client_index_to_input_queue (mp->client_index);
4045 rv = vnet_tap_dump_ifs(&tapifs);
4049 vec_foreach(tap_if, tapifs) {
4050 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4057 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4059 vpe_api_main_t * am = &vpe_api_main;
4060 vnet_main_t * vnm = vnet_get_main();
4061 vlib_main_t * vm = vlib_get_main();
4062 vnet_interface_main_t * im = &vnm->interface_main;
4063 unix_shared_memory_queue_t * q;
4064 vnet_sw_interface_t * si, * sorted_sis;
4065 u32 sw_if_index = ~0;
4067 q = vl_api_client_index_to_input_queue (mp->client_index);
4072 /* Gather interfaces. */
4073 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4074 _vec_len (sorted_sis) = 0;
4075 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4077 vec_foreach (si, sorted_sis) {
4078 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4079 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4082 sw_if_index = si->sw_if_index;
4083 send_ip_details(am, q, sw_if_index, mp->context);
4088 static void vl_api_l2_fib_table_entry_t_handler (
4089 vl_api_l2_fib_table_entry_t * mp)
4091 clib_warning ("BUG");
4094 static void send_l2fib_table_entry (vpe_api_main_t * am,
4095 unix_shared_memory_queue_t *q,
4096 l2fib_entry_key_t * l2fe_key,
4097 l2fib_entry_result_t * l2fe_res,
4100 vl_api_l2_fib_table_entry_t * mp;
4102 mp = vl_msg_api_alloc (sizeof (*mp));
4103 memset (mp, 0, sizeof (*mp));
4104 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4106 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4108 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4109 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4110 mp->static_mac = l2fe_res->fields.static_mac;
4111 mp->filter_mac = l2fe_res->fields.filter;
4112 mp->bvi_mac = l2fe_res->fields.bvi;
4113 mp->context = context;
4115 vl_msg_api_send_shmem (q, (u8 *)&mp);
4119 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4121 vpe_api_main_t * am = &vpe_api_main;
4122 bd_main_t * bdm = &bd_main;
4123 l2fib_entry_key_t *l2fe_key = NULL;
4124 l2fib_entry_result_t *l2fe_res = NULL;
4125 u32 ni, bd_id = ntohl (mp->bd_id);
4127 unix_shared_memory_queue_t * q;
4130 q = vl_api_client_index_to_input_queue (mp->client_index);
4134 /* see l2fib_table_dump: ~0 means "any" */
4138 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4145 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4147 vec_foreach_index (ni, l2fe_key) {
4148 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4149 vec_elt_at_index(l2fe_res, ni), mp->context);
4156 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4158 vl_api_show_version_reply_t *rmp;
4160 char * vpe_api_get_build_directory(void);
4161 char * vpe_api_get_version(void);
4162 char * vpe_api_get_build_date(void);
4164 unix_shared_memory_queue_t * q =
4165 vl_api_client_index_to_input_queue (mp->client_index);
4170 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4172 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4173 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4174 ARRAY_LEN(rmp->build_directory)-1);
4175 strncpy ((char *) rmp->version, vpe_api_get_version(),
4176 ARRAY_LEN(rmp->version)-1);
4177 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4178 ARRAY_LEN(rmp->build_date)-1);
4182 static void vl_api_get_node_index_t_handler
4183 (vl_api_get_node_index_t * mp)
4185 vlib_main_t * vm = vlib_get_main();
4186 vl_api_get_node_index_reply_t * rmp;
4189 u32 node_index = ~0;
4191 n = vlib_get_node_by_name (vm, mp->node_name);
4194 rv = VNET_API_ERROR_NO_SUCH_NODE;
4196 node_index = n->index;
4198 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4200 rmp->node_index = ntohl(node_index);
4204 static void vl_api_add_node_next_t_handler
4205 (vl_api_add_node_next_t * mp)
4207 vlib_main_t * vm = vlib_get_main();
4208 vl_api_add_node_next_reply_t * rmp;
4209 vlib_node_t * n, * next;
4211 u32 next_index = ~0;
4213 n = vlib_get_node_by_name (vm, mp->node_name);
4216 rv = VNET_API_ERROR_NO_SUCH_NODE;
4220 next = vlib_get_node_by_name (vm, mp->next_name);
4223 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4225 next_index = vlib_node_add_next (vm, n->index, next->index);
4228 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4230 rmp->next_index = ntohl(next_index);
4234 static void vl_api_l2tpv3_create_tunnel_t_handler
4235 (vl_api_l2tpv3_create_tunnel_t *mp)
4237 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4238 l2t_main_t *lm = &l2t_main;
4239 u32 sw_if_index = (u32)~0;
4242 if (mp->is_ipv6 != 1) {
4243 rv = VNET_API_ERROR_UNIMPLEMENTED;
4247 rv = create_l2tpv3_ipv6_tunnel (lm,
4248 (ip6_address_t *) mp->client_address,
4249 (ip6_address_t *) mp->our_address,
4250 ntohl(mp->local_session_id),
4251 ntohl(mp->remote_session_id),
4252 clib_net_to_host_u64(mp->local_cookie),
4253 clib_net_to_host_u64(mp->remote_cookie),
4254 mp->l2_sublayer_present,
4258 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4260 rmp->sw_if_index = ntohl (sw_if_index);
4264 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4265 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4267 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4268 l2t_main_t *lm = &l2t_main;
4271 VALIDATE_SW_IF_INDEX(mp);
4273 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4274 clib_net_to_host_u64(mp->new_local_cookie),
4275 clib_net_to_host_u64(mp->new_remote_cookie));
4277 BAD_SW_IF_INDEX_LABEL;
4279 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4282 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4283 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4286 vnet_main_t * vnm = vnet_get_main();
4287 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4289 VALIDATE_SW_IF_INDEX(mp);
4291 rv = l2tpv3_interface_enable_disable
4292 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4294 BAD_SW_IF_INDEX_LABEL;
4296 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4299 static void vl_api_l2tpv3_set_lookup_key_t_handler
4300 (vl_api_l2tpv3_set_lookup_key_t * mp)
4303 l2t_main_t *lm = &l2t_main;
4304 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4306 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4307 rv = VNET_API_ERROR_INVALID_VALUE;
4311 lm->lookup_type = mp->key;
4314 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4317 static void vl_api_vxlan_add_del_tunnel_t_handler
4318 (vl_api_vxlan_add_del_tunnel_t * mp)
4320 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4322 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4323 u32 encap_fib_index;
4325 ip4_main_t * im = &ip4_main;
4326 u32 sw_if_index = ~0;
4328 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4330 rv = VNET_API_ERROR_NO_SUCH_FIB;
4333 encap_fib_index = p[0];
4335 /* Check src & dst are different */
4336 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4337 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4338 rv = VNET_API_ERROR_SAME_SRC_DST;
4341 memset (a, 0, sizeof (*a));
4343 a->is_add = mp->is_add;
4344 a->is_ip6 = mp->is_ipv6;
4346 /* ip addresses sent in network byte order */
4348 memcpy(&(a->src.ip6), mp->src_address, 16);
4349 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4351 memcpy(&(a->src.ip4), mp->src_address, 4);
4352 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4355 a->encap_fib_index = encap_fib_index;
4356 a->decap_next_index = ntohl(mp->decap_next_index);
4357 a->vni = ntohl(mp->vni);
4358 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4361 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4363 rmp->sw_if_index = ntohl (sw_if_index);
4367 static void send_vxlan_tunnel_details
4368 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4370 vl_api_vxlan_tunnel_details_t * rmp;
4371 ip4_main_t * im4 = &ip4_main;
4372 ip6_main_t * im6 = &ip6_main;
4373 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4375 rmp = vl_msg_api_alloc (sizeof (*rmp));
4376 memset (rmp, 0, sizeof (*rmp));
4377 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4379 memcpy(rmp->src_address, &(t->src.ip6), 16);
4380 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4381 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4383 memcpy(rmp->src_address, &(t->src.ip4), 4);
4384 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4385 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4387 rmp->vni = htonl(t->vni);
4388 rmp->decap_next_index = htonl(t->decap_next_index);
4389 rmp->sw_if_index = htonl(t->sw_if_index);
4390 rmp->is_ipv6 = is_ipv6;
4391 rmp->context = context;
4393 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4396 static void vl_api_vxlan_tunnel_dump_t_handler
4397 (vl_api_vxlan_tunnel_dump_t * mp)
4399 unix_shared_memory_queue_t * q;
4400 vxlan_main_t * vxm = &vxlan_main;
4404 q = vl_api_client_index_to_input_queue (mp->client_index);
4409 sw_if_index = ntohl(mp->sw_if_index);
4411 if (~0 == sw_if_index) {
4412 pool_foreach (t, vxm->tunnels,
4414 send_vxlan_tunnel_details(t, q, mp->context);
4417 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4418 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4421 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4422 send_vxlan_tunnel_details(t, q, mp->context);
4426 static void vl_api_gre_add_del_tunnel_t_handler
4427 (vl_api_gre_add_del_tunnel_t * mp)
4429 vl_api_gre_add_del_tunnel_reply_t * rmp;
4431 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4434 ip4_main_t * im = &ip4_main;
4435 u32 sw_if_index = ~0;
4437 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4439 rv = VNET_API_ERROR_NO_SUCH_FIB;
4442 outer_table_id = p[0];
4444 /* Check src & dst are different */
4445 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4446 rv = VNET_API_ERROR_SAME_SRC_DST;
4450 memset (a, 0, sizeof (*a));
4452 a->is_add = mp->is_add;
4454 /* ip addresses sent in network byte order */
4455 a->src.as_u32 = mp->src_address;
4456 a->dst.as_u32 = mp->dst_address;
4458 a->outer_table_id = outer_table_id;
4459 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4462 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4464 rmp->sw_if_index = ntohl (sw_if_index);
4468 static void send_gre_tunnel_details
4469 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4471 vl_api_gre_tunnel_details_t * rmp;
4472 ip4_main_t * im = &ip4_main;
4474 rmp = vl_msg_api_alloc (sizeof (*rmp));
4475 memset (rmp, 0, sizeof (*rmp));
4476 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4477 rmp->src_address = t->tunnel_src.data_u32;
4478 rmp->dst_address = t->tunnel_dst.data_u32;
4479 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4480 rmp->sw_if_index = htonl(t->sw_if_index);
4481 rmp->context = context;
4483 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4486 static void vl_api_gre_tunnel_dump_t_handler
4487 (vl_api_gre_tunnel_dump_t * mp)
4489 unix_shared_memory_queue_t * q;
4490 gre_main_t * gm = &gre_main;
4494 q = vl_api_client_index_to_input_queue (mp->client_index);
4499 sw_if_index = ntohl(mp->sw_if_index);
4501 if (~0 == sw_if_index) {
4502 pool_foreach (t, gm->tunnels,
4504 send_gre_tunnel_details(t, q, mp->context);
4507 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4508 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4511 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4512 send_gre_tunnel_details(t, q, mp->context);
4517 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4519 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4521 vl_api_l2_patch_add_del_reply_t * rmp;
4522 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4526 VALIDATE_RX_SW_IF_INDEX(mp);
4527 VALIDATE_TX_SW_IF_INDEX(mp);
4529 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4530 ntohl(mp->tx_sw_if_index),
4531 (int)(mp->is_add != 0));
4533 BAD_RX_SW_IF_INDEX_LABEL;
4534 BAD_TX_SW_IF_INDEX_LABEL;
4536 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4540 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4541 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4543 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4545 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4546 u32 encap_fib_index, decap_fib_index;
4549 ip4_main_t * im = &ip4_main;
4550 u32 sw_if_index = ~0;
4553 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4555 rv = VNET_API_ERROR_NO_SUCH_FIB;
4558 encap_fib_index = p[0];
4560 protocol = mp->protocol;
4562 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4563 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4564 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4566 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4569 decap_fib_index = p[0];
4571 decap_fib_index = ntohl(mp->decap_vrf_id);
4574 /* Check src & dst are different */
4575 if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4576 (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4577 rv = VNET_API_ERROR_SAME_SRC_DST;
4580 memset (a, 0, sizeof (*a));
4582 a->is_add = mp->is_add;
4583 a->is_ip6 = mp->is_ipv6;
4584 /* ip addresses sent in network byte order */
4586 clib_memcpy(&(a->local.ip6), mp->local, 16);
4587 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4589 clib_memcpy(&(a->local.ip4), mp->local, 4);
4590 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4592 a->encap_fib_index = encap_fib_index;
4593 a->decap_fib_index = decap_fib_index;
4594 a->protocol = protocol;
4595 a->vni = ntohl(mp->vni);
4596 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4599 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4601 rmp->sw_if_index = ntohl (sw_if_index);
4605 static void send_vxlan_gpe_tunnel_details
4606 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4608 vl_api_vxlan_gpe_tunnel_details_t * rmp;
4609 ip4_main_t * im4 = &ip4_main;
4610 ip6_main_t * im6 = &ip6_main;
4611 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4613 rmp = vl_msg_api_alloc (sizeof (*rmp));
4614 memset (rmp, 0, sizeof (*rmp));
4615 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4617 memcpy(rmp->local, &(t->local.ip6), 16);
4618 memcpy(rmp->remote, &(t->remote.ip6), 16);
4619 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4620 rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
4622 memcpy(rmp->local, &(t->local.ip4), 4);
4623 memcpy(rmp->remote, &(t->remote.ip4), 4);
4624 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4625 rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
4627 rmp->vni = htonl(t->vni);
4628 rmp->protocol = t->protocol;
4629 rmp->sw_if_index = htonl(t->sw_if_index);
4630 rmp->is_ipv6 = is_ipv6;
4631 rmp->context = context;
4633 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4636 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4637 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4639 unix_shared_memory_queue_t * q;
4640 vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
4641 vxlan_gpe_tunnel_t * t;
4644 q = vl_api_client_index_to_input_queue (mp->client_index);
4649 sw_if_index = ntohl(mp->sw_if_index);
4651 if (~0 == sw_if_index) {
4652 pool_foreach (t, vgm->tunnels,
4654 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4657 if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
4658 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
4661 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4662 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4667 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4669 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4671 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4673 u8 *locator_name = NULL;
4675 memset(a, 0, sizeof(a[0]));
4677 locator_name = format(0, "%s", mp->locator_set_name);
4679 a->name = locator_name;
4681 a->is_add = mp->is_add;
4684 rv = vnet_lisp_add_del_locator_set(a, &ls_index);
4686 vec_free(locator_name);
4688 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4692 vl_api_lisp_add_del_locator_t_handler(
4693 vl_api_lisp_add_del_locator_t *mp)
4695 vl_api_lisp_add_del_locator_reply_t *rmp;
4697 locator_t locator, *locators = NULL;
4698 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4700 u8 *locator_name = NULL;
4702 memset(&locator, 0, sizeof(locator));
4703 memset(a, 0, sizeof(a[0]));
4705 locator.sw_if_index = ntohl(mp->sw_if_index);
4706 locator.priority = mp->priority;
4707 locator.weight = mp->weight;
4709 vec_add1(locators, locator);
4711 locator_name = format(0, "%s", mp->locator_set_name);
4713 a->name = locator_name;
4714 a->locators = locators;
4715 a->is_add = mp->is_add;
4718 rv = vnet_lisp_add_del_locator(a, NULL, &ls_index);
4721 vec_free(locator_name);
4723 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4727 vl_api_lisp_add_del_local_eid_t_handler(
4728 vl_api_lisp_add_del_local_eid_t *mp)
4730 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4731 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4733 ip_prefix_t *prefp = NULL;
4734 ip_address_t *ip_eid = NULL;
4737 u32 locator_set_index = ~0, map_index = ~0;
4738 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4741 prefp = &gid_address_ippref(&eid);
4742 ip_eid = &ip_prefix_addr(prefp);
4743 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4746 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4747 sizeof(ip_addr_v6(ip_eid)));
4748 ip_addr_version(ip_eid) = IP6;
4750 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4751 sizeof(ip_addr_v4(ip_eid)));
4752 ip_addr_version(ip_eid) = IP4;
4754 ip_prefix_len(prefp) = mp->prefix_len;
4756 name = format(0, "%s", mp->locator_set_name);
4757 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4759 rv = VNET_API_ERROR_INVALID_VALUE;
4762 locator_set_index = p[0];
4764 /* XXX treat batch configuration */
4765 a->is_add = mp->is_add;
4767 a->locator_set_index = locator_set_index;
4770 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4775 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4779 lisp_gpe_add_del_fwd_entry_set_address(
4780 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4781 ip_address_t *slocator,
4782 ip_address_t *dlocator,
4785 ip_address_t *ip_eid = NULL;
4786 ip_prefix_t *prefp = NULL;
4788 prefp = &gid_address_ippref(eid);
4789 ip_eid = &ip_prefix_addr(prefp);
4791 if (mp->eid_is_ipv6) {
4792 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4793 sizeof(ip_addr_v6(ip_eid)));
4794 ip_addr_version(ip_eid) = IP6;
4796 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4797 sizeof(ip_addr_v4(ip_eid)));
4798 ip_addr_version(ip_eid) = IP4;
4800 ip_prefix_len(prefp) = mp->eid_prefix_len;
4802 if (mp->address_is_ipv6) {
4803 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4804 sizeof(ip_addr_v6(slocator)));
4805 ip_addr_version(slocator) = IP6;
4806 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4807 sizeof(ip_addr_v6(dlocator)));
4808 ip_addr_version(dlocator) = IP6;
4810 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4811 sizeof(ip_addr_v4(slocator)));
4812 ip_addr_version(slocator) = IP4;
4813 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4814 sizeof(ip_addr_v4(dlocator)));
4815 ip_addr_version(dlocator) = IP4;
4820 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4821 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4823 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4825 ip_address_t slocator, dlocator;
4827 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4829 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4831 memset (&a, 0, sizeof(a));
4833 a.is_add = mp->is_add;
4835 a.slocator = slocator;
4836 a.dlocator = dlocator;
4837 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4839 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4843 vl_api_lisp_add_del_map_resolver_t_handler(
4844 vl_api_lisp_add_del_map_resolver_t *mp)
4846 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4848 ip_address_t *ip_addr = NULL;
4849 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4851 a->is_add = mp->is_add;
4852 ip_addr = &a->address;
4855 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4856 sizeof(ip_addr_v6(ip_addr)));
4857 ip_addr_version(ip_addr) = IP6;
4859 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4860 sizeof(ip_addr_v4(ip_addr)));
4861 ip_addr_version(ip_addr) = IP4;
4864 rv = vnet_lisp_add_del_map_resolver (a);
4866 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4870 vl_api_lisp_gpe_enable_disable_t_handler(
4871 vl_api_lisp_gpe_enable_disable_t *mp)
4873 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4875 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4877 a->is_en = mp->is_en;
4878 vnet_lisp_gpe_enable_disable (a);
4880 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4884 vl_api_lisp_enable_disable_t_handler(
4885 vl_api_lisp_enable_disable_t *mp)
4887 vl_api_lisp_enable_disable_reply_t *rmp;
4890 vnet_lisp_enable_disable (mp->is_en);
4891 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4895 vl_api_lisp_gpe_add_del_iface_t_handler(
4896 vl_api_lisp_gpe_add_del_iface_t *mp)
4898 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4900 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4902 a->is_add = mp->is_add;
4903 a->table_id = mp->table_id;
4905 vnet_lisp_gpe_add_del_iface (a, 0);
4907 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4911 vl_api_lisp_pitr_set_locator_set_t_handler(
4912 vl_api_lisp_pitr_set_locator_set_t *mp)
4914 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4918 ls_name = format (0, "%s", mp->ls_name);
4919 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4922 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4925 /** Used for transferring locators via VPP API */
4926 typedef CLIB_PACKED(struct
4928 u8 is_ip4; /**< is locator an IPv4 address */
4929 u8 addr[16]; /**< IPv4/IPv6 address */
4933 send_lisp_locator_set_details_set_address
4934 (vl_api_lisp_locator_set_details_t *rmp,
4935 gid_address_t *gid_address)
4937 ip_prefix_t *ip_addr;
4939 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4943 ip_addr = &gid_address_ippref(gid_address);
4944 rmp->prefix_len = ip_prefix_len(ip_addr);
4945 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4946 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4950 vl_api_lisp_add_del_remote_mapping_t_handler (
4951 vl_api_lisp_add_del_remote_mapping_t *mp)
4954 ip_address_t rloc, * rlocs = 0;
4955 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
4957 gid_address_t _seid, * seid = &_seid;
4958 gid_address_t _deid, * deid = &_deid;
4959 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
4960 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
4962 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
4963 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
4964 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
4965 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
4966 ip_prefix_len(seid_pref) = mp->seid_len;
4967 ip_prefix_len(deid_pref) = mp->deid_len;
4968 gid_address_set_vni (seid, ntohl (mp->vni));
4969 gid_address_set_vni (deid, ntohl (mp->vni));
4971 if (mp->eid_is_ip4) {
4972 ip_prefix_version(seid_pref) = IP4;
4973 ip_prefix_version(deid_pref) = IP4;
4974 clib_memcpy (&ip_addr_v4(seid_addr),
4975 mp->seid, sizeof (ip_addr_v4(seid_addr)));
4976 clib_memcpy (&ip_addr_v4(deid_addr),
4977 mp->deid, sizeof (ip_addr_v4(deid_addr)));
4979 ip_prefix_version(seid_pref) = IP6;
4980 ip_prefix_version(deid_pref) = IP6;
4981 clib_memcpy (&ip_addr_v6(seid_addr),
4982 mp->seid, sizeof (ip_addr_v6(seid_addr)));
4983 clib_memcpy (&ip_addr_v6(deid_addr),
4984 mp->deid, sizeof (ip_addr_v6(deid_addr)));
4987 for (i = 0; i < mp->rloc_num; i++) {
4988 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
4990 clib_memcpy (&ip_addr_v4(&rloc), &r->addr, sizeof (rloc_t));
4991 ip_addr_version (&rloc) = IP4;
4993 clib_memcpy (&ip_addr_v6(&rloc), &r->addr, sizeof (rloc_t));
4994 ip_addr_version (&rloc) = IP6;
4996 vec_add1 (rlocs, rloc);
4999 rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs, mp->action,
5000 mp->is_add, mp->del_all);
5002 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5006 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
5007 locator_set_t *lsit,
5008 unix_shared_memory_queue_t *q,
5012 vl_api_lisp_locator_set_details_t *rmp;
5013 locator_t *loc = NULL;
5017 vec_foreach (locit, lsit->locator_indices) {
5018 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5019 rmp = vl_msg_api_alloc (sizeof (*rmp));
5020 memset (rmp, 0, sizeof (*rmp));
5021 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
5022 rmp->local = lsit->local;
5024 ASSERT(lsit->name != NULL);
5025 strncpy((char *) rmp->locator_set_name,
5026 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5027 rmp->sw_if_index = htonl(loc->sw_if_index);
5029 str = format(0, "remote-%d", index);
5030 strncpy((char *) rmp->locator_set_name, (char *) str,
5031 ARRAY_LEN(rmp->locator_set_name) - 1);
5032 send_lisp_locator_set_details_set_address(rmp, &loc->address);
5036 rmp->priority = loc->priority;
5037 rmp->weight = loc->weight;
5038 rmp->context = context;
5040 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5045 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
5047 unix_shared_memory_queue_t * q = NULL;
5048 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5049 locator_set_t * lsit = NULL;
5052 q = vl_api_client_index_to_input_queue (mp->client_index);
5058 pool_foreach (lsit, lcm->locator_set_pool,
5060 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5065 send_lisp_local_eid_table_details (mapping_t *mapit,
5066 unix_shared_memory_queue_t *q,
5069 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5070 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5071 locator_set_t *ls = NULL;
5072 gid_address_t *gid = NULL;
5073 ip_prefix_t *ip_prefix = NULL;
5077 ls = pool_elt_at_index (lcm->locator_set_pool,
5078 mapit->locator_set_index);
5081 type = gid_address_type(gid);
5083 if (type != GID_ADDR_IP_PREFIX) {
5087 ip_prefix = &gid_address_ippref(gid);
5089 rmp = vl_msg_api_alloc (sizeof (*rmp));
5090 memset (rmp, 0, sizeof (*rmp));
5091 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5093 ASSERT(ls->name != NULL);
5094 strncpy((char *) rmp->locator_set_name,
5095 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5097 str = format(0, "remote-%d", mapit->locator_set_index);
5098 strncpy((char *) rmp->locator_set_name, (char *) str,
5099 ARRAY_LEN(rmp->locator_set_name) - 1);
5103 switch (ip_prefix_version(ip_prefix)) {
5105 rmp->eid_is_ipv6 = 0;
5106 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5107 sizeof(ip_prefix_v4(ip_prefix)));
5111 rmp->eid_is_ipv6 = 1;
5112 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5113 sizeof(ip_prefix_v6(ip_prefix)));
5119 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5120 rmp->context = context;
5122 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5126 vl_api_lisp_local_eid_table_dump_t_handler (
5127 vl_api_lisp_local_eid_table_dump_t *mp)
5129 unix_shared_memory_queue_t * q = NULL;
5130 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5131 mapping_t * mapit = NULL;
5133 q = vl_api_client_index_to_input_queue (mp->client_index);
5138 pool_foreach (mapit, lcm->mapping_pool,
5140 send_lisp_local_eid_table_details(mapit, q, mp->context);
5145 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5146 unix_shared_memory_queue_t *q,
5149 vl_api_lisp_gpe_tunnel_details_t *rmp;
5150 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5152 rmp = vl_msg_api_alloc (sizeof (*rmp));
5153 memset (rmp, 0, sizeof (*rmp));
5154 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5156 rmp->tunnels = tunnel - lgm->tunnels;
5158 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5159 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5160 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5162 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5163 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5164 rmp->dcap_next = htonl(tunnel->decap_next_index);
5165 rmp->lisp_ver = tunnel->ver_res;
5166 rmp->next_protocol = tunnel->next_protocol;
5167 rmp->flags = tunnel->flags;
5168 rmp->ver_res = tunnel->ver_res;
5169 rmp->res = tunnel->res;
5170 rmp->iid = htonl(tunnel->vni);
5171 rmp->context = context;
5173 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5177 vl_api_lisp_gpe_tunnel_dump_t_handler (
5178 vl_api_lisp_local_eid_table_dump_t *mp)
5180 unix_shared_memory_queue_t * q = NULL;
5181 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5182 lisp_gpe_tunnel_t * tunnel = NULL;
5184 if (pool_elts(lgm->tunnels) == 0) {
5188 q = vl_api_client_index_to_input_queue (mp->client_index);
5193 pool_foreach(tunnel, lgm->tunnels,
5195 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5200 send_lisp_map_resolver_details (ip_address_t *ip,
5201 unix_shared_memory_queue_t *q,
5204 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5206 rmp = vl_msg_api_alloc (sizeof (*rmp));
5207 memset (rmp, 0, sizeof (*rmp));
5208 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5210 switch (ip_addr_version(ip)) {
5213 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5218 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5224 rmp->context = context;
5226 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5230 vl_api_lisp_map_resolver_dump_t_handler (
5231 vl_api_lisp_local_eid_table_dump_t *mp)
5233 unix_shared_memory_queue_t * q = NULL;
5234 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5235 ip_address_t *ip = NULL;
5237 q = vl_api_client_index_to_input_queue (mp->client_index);
5242 vec_foreach(ip, lcm->map_resolvers) {
5243 send_lisp_map_resolver_details(ip, q, mp->context);
5249 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5252 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5254 rmp = vl_msg_api_alloc (sizeof (*rmp));
5255 memset (rmp, 0, sizeof (*rmp));
5256 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5258 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5259 rmp->feature_status = vnet_lisp_enable_disable_status ();
5260 rmp->context = context;
5262 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5266 vl_api_lisp_enable_disable_status_dump_t_handler
5267 (vl_api_lisp_enable_disable_status_dump_t *mp)
5269 unix_shared_memory_queue_t * q = NULL;
5271 q = vl_api_client_index_to_input_queue (mp->client_index);
5276 send_lisp_enable_disable_details(q, mp->context);
5280 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5282 vl_api_interface_name_renumber_reply_t * rmp;
5285 VALIDATE_SW_IF_INDEX(mp);
5287 rv = vnet_interface_name_renumber
5288 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5290 BAD_SW_IF_INDEX_LABEL;
5292 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5295 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5296 u32 sw_if_index, u32 address)
5298 vpe_api_main_t * am = &vpe_api_main;
5299 vlib_main_t * vm = am->vlib_main;
5300 vl_api_ip4_arp_event_t * event;
5301 static f64 arp_event_last_time;
5302 f64 now = vlib_time_now (vm);
5304 if (pool_is_free_index (am->arp_events, pool_index))
5307 event = pool_elt_at_index (am->arp_events, pool_index);
5308 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5309 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5310 } else { /* same mac */
5311 if ((sw_if_index == event->sw_if_index) &&
5313 /* for BD case, also check IP address with 10 sec timeout */
5314 ((address == event->address) &&
5315 ((now - arp_event_last_time) < 10.0))))
5319 arp_event_last_time = now;
5320 event->sw_if_index = sw_if_index;
5321 if (address) event->address = address;
5325 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5327 vpe_api_main_t * am = &vpe_api_main;
5329 if (pool_is_free_index (am->arp_events, pool_index))
5332 pool_put_index (am->arp_events, pool_index);
5337 vl_api_want_ip4_arp_events_t_handler
5338 (vl_api_want_ip4_arp_events_t * mp)
5340 vpe_api_main_t * am = &vpe_api_main;
5341 vnet_main_t * vnm = vnet_get_main();
5342 vl_api_want_ip4_arp_events_reply_t *rmp;
5343 vl_api_ip4_arp_event_t * event;
5346 if (mp->enable_disable) {
5347 pool_get (am->arp_events, event);
5348 memset (event, 0, sizeof (*event));
5350 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5351 event->client_index = mp->client_index;
5352 event->context = mp->context;
5353 event->address = mp->address;
5354 event->pid = mp->pid;
5356 rv = vnet_add_del_ip4_arp_change_event
5357 (vnm, arp_change_data_callback,
5359 &mp->address /* addr, in net byte order */,
5360 vpe_resolver_process_node.index,
5361 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5363 rv = vnet_add_del_ip4_arp_change_event
5364 (vnm, arp_change_delete_callback,
5366 &mp->address /* addr, in net byte order */,
5367 vpe_resolver_process_node.index,
5368 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5370 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5373 static void vl_api_input_acl_set_interface_t_handler
5374 (vl_api_input_acl_set_interface_t * mp)
5376 vlib_main_t *vm = vlib_get_main();
5377 vl_api_input_acl_set_interface_reply_t * rmp;
5379 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5381 ip4_table_index = ntohl(mp->ip4_table_index);
5382 ip6_table_index = ntohl(mp->ip6_table_index);
5383 l2_table_index = ntohl(mp->l2_table_index);
5384 sw_if_index = ntohl(mp->sw_if_index);
5386 VALIDATE_SW_IF_INDEX(mp);
5388 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5389 ip6_table_index, l2_table_index,
5392 BAD_SW_IF_INDEX_LABEL;
5394 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5397 static void vl_api_ipsec_spd_add_del_t_handler
5398 (vl_api_ipsec_spd_add_del_t * mp)
5401 clib_warning ("unimplemented");
5404 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5405 vl_api_ipsec_spd_add_del_reply_t * rmp;
5409 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5411 rv = VNET_API_ERROR_UNIMPLEMENTED;
5414 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5418 static void vl_api_ipsec_interface_add_del_spd_t_handler
5419 (vl_api_ipsec_interface_add_del_spd_t * mp)
5421 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5422 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5424 u32 sw_if_index __attribute__((unused));
5425 u32 spd_id __attribute__((unused));
5427 sw_if_index = ntohl(mp->sw_if_index);
5428 spd_id = ntohl(mp->spd_id);
5430 VALIDATE_SW_IF_INDEX(mp);
5433 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5435 rv = VNET_API_ERROR_UNIMPLEMENTED;
5438 BAD_SW_IF_INDEX_LABEL;
5440 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5443 static void vl_api_ipsec_spd_add_del_entry_t_handler
5444 (vl_api_ipsec_spd_add_del_entry_t * mp)
5446 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5447 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5453 memset(&p, 0, sizeof(p));
5455 p.id = ntohl(mp->spd_id);
5456 p.priority = ntohl(mp->priority);
5457 p.is_outbound = mp->is_outbound;
5458 p.is_ipv6 = mp->is_ipv6;
5460 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5461 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5462 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5463 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5465 p.protocol = mp->protocol;
5466 p.rport.start = ntohs(mp->remote_port_start);
5467 p.rport.stop = ntohs(mp->remote_port_stop);
5468 p.lport.start = ntohs(mp->local_port_start);
5469 p.lport.stop = ntohs(mp->local_port_stop);
5470 /* policy action resolve unsupported */
5471 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5472 clib_warning("unsupported action: 'resolve'");
5473 rv = VNET_API_ERROR_UNIMPLEMENTED;
5476 p.policy = mp->policy;
5477 p.sa_id = ntohl(mp->sa_id);
5479 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5483 if (mp->is_ip_any) {
5485 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5488 rv = VNET_API_ERROR_UNIMPLEMENTED;
5493 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5496 static void vl_api_ipsec_sad_add_del_entry_t_handler
5497 (vl_api_ipsec_sad_add_del_entry_t * mp)
5499 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5500 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5505 memset(&sa, 0, sizeof(sa));
5507 sa.id = ntohl(mp->sad_id);
5508 sa.spi = ntohl(mp->spi);
5509 /* security protocol AH unsupported */
5510 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5511 clib_warning("unsupported security protocol 'AH'");
5512 rv = VNET_API_ERROR_UNIMPLEMENTED;
5515 sa.protocol = mp->protocol;
5516 /* check for unsupported crypto-alg */
5517 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5518 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5519 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5520 mp->crypto_algorithm);
5521 rv = VNET_API_ERROR_UNIMPLEMENTED;
5524 sa.crypto_alg = mp->crypto_algorithm;
5525 sa.crypto_key_len = mp->crypto_key_length;
5526 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5527 /* check for unsupported integ-alg */
5528 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5529 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5530 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5531 mp->integrity_algorithm);
5532 rv = VNET_API_ERROR_UNIMPLEMENTED;
5535 sa.integ_alg = mp->integrity_algorithm;
5536 sa.integ_key_len = mp->integrity_key_length;
5537 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5538 sa.use_esn = mp->use_extended_sequence_number;
5539 sa.is_tunnel = mp->is_tunnel;
5540 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5541 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5542 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5544 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5546 rv = VNET_API_ERROR_UNIMPLEMENTED;
5551 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5555 vl_api_ikev2_profile_add_del_t_handler
5556 (vl_api_ikev2_profile_add_del_t * mp)
5558 vl_api_ikev2_profile_add_del_reply_t * rmp;
5562 vlib_main_t * vm = vlib_get_main();
5563 clib_error_t * error;
5564 u8 * tmp = format(0, "%s", mp->name);
5565 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5568 rv = VNET_API_ERROR_UNSPECIFIED;
5570 rv = VNET_API_ERROR_UNIMPLEMENTED;
5573 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5577 vl_api_ikev2_profile_set_auth_t_handler
5578 (vl_api_ikev2_profile_set_auth_t * mp)
5580 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5584 vlib_main_t * vm = vlib_get_main();
5585 clib_error_t * error;
5586 u8 * tmp = format(0, "%s", mp->name);
5587 u8 * data = vec_new (u8, mp->data_len);
5588 clib_memcpy(data, mp->data, mp->data_len);
5589 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5593 rv = VNET_API_ERROR_UNSPECIFIED;
5595 rv = VNET_API_ERROR_UNIMPLEMENTED;
5598 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5602 vl_api_ikev2_profile_set_id_t_handler
5603 (vl_api_ikev2_profile_set_id_t * mp)
5605 vl_api_ikev2_profile_add_del_reply_t * rmp;
5609 vlib_main_t * vm = vlib_get_main();
5610 clib_error_t * error;
5611 u8 * tmp = format(0, "%s", mp->name);
5612 u8 * data = vec_new (u8, mp->data_len);
5613 clib_memcpy(data, mp->data, mp->data_len);
5614 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5618 rv = VNET_API_ERROR_UNSPECIFIED;
5620 rv = VNET_API_ERROR_UNIMPLEMENTED;
5623 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5627 vl_api_ikev2_profile_set_ts_t_handler
5628 (vl_api_ikev2_profile_set_ts_t * mp)
5630 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5634 vlib_main_t * vm = vlib_get_main();
5635 clib_error_t * error;
5636 u8 * tmp = format(0, "%s", mp->name);
5637 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5638 mp->end_port, (ip4_address_t) mp->start_addr,
5639 (ip4_address_t) mp->end_addr, mp->is_local);
5642 rv = VNET_API_ERROR_UNSPECIFIED;
5644 rv = VNET_API_ERROR_UNIMPLEMENTED;
5647 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5651 vl_api_ikev2_set_local_key_t_handler
5652 (vl_api_ikev2_set_local_key_t * mp)
5654 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5658 vlib_main_t * vm = vlib_get_main();
5659 clib_error_t * error;
5661 error = ikev2_set_local_key(vm, mp->key_file);
5663 rv = VNET_API_ERROR_UNSPECIFIED;
5665 rv = VNET_API_ERROR_UNIMPLEMENTED;
5668 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5672 vl_api_map_add_domain_t_handler
5673 (vl_api_map_add_domain_t * mp)
5675 vl_api_map_add_domain_reply_t * rmp;
5678 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5679 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5680 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5681 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5682 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5684 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5686 rmp->index = ntohl(index);
5691 vl_api_map_del_domain_t_handler
5692 (vl_api_map_del_domain_t * mp)
5694 vl_api_map_del_domain_reply_t * rmp;
5697 rv = map_delete_domain(ntohl(mp->index));
5699 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5703 vl_api_map_add_del_rule_t_handler
5704 (vl_api_map_add_del_rule_t * mp)
5706 vl_api_map_del_domain_reply_t * rmp;
5709 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5711 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5715 vl_api_map_domain_dump_t_handler
5716 (vl_api_map_domain_dump_t * mp)
5718 vl_api_map_domain_details_t * rmp;
5719 map_main_t *mm = &map_main;
5721 unix_shared_memory_queue_t * q;
5723 if (pool_elts (mm->domains) == 0)
5726 q = vl_api_client_index_to_input_queue (mp->client_index);
5731 pool_foreach(d, mm->domains, ({
5732 /* Make sure every field is initiated (or don't skip the memset()) */
5733 rmp = vl_msg_api_alloc (sizeof (*rmp));
5734 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5735 rmp->domain_index = htonl(d - mm->domains);
5736 rmp->ea_bits_len = d->ea_bits_len;
5737 rmp->psid_offset = d->psid_offset;
5738 rmp->psid_length = d->psid_length;
5739 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5740 rmp->ip4_prefix_len = d->ip4_prefix_len;
5741 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5742 rmp->ip6_prefix_len = d->ip6_prefix_len;
5743 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5744 rmp->ip6_src_len = d->ip6_src_len;
5745 rmp->mtu = htons(d->mtu);
5746 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5747 rmp->context = mp->context;
5749 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5754 vl_api_map_rule_dump_t_handler
5755 (vl_api_map_rule_dump_t * mp)
5757 unix_shared_memory_queue_t * q;
5760 vl_api_map_rule_details_t * rmp;
5761 map_main_t *mm = &map_main;
5762 u32 domain_index = ntohl(mp->domain_index);
5765 if (pool_elts (mm->domains) == 0)
5768 d = pool_elt_at_index(mm->domains, domain_index);
5769 if (!d || !d->rules) {
5773 q = vl_api_client_index_to_input_queue (mp->client_index);
5778 for (i = 0; i < (0x1 << d->psid_length); i++) {
5780 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5783 rmp = vl_msg_api_alloc(sizeof(*rmp));
5784 memset(rmp, 0, sizeof(*rmp));
5785 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5786 rmp->psid = htons(i);
5787 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5788 rmp->context = mp->context;
5789 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5794 vl_api_map_summary_stats_t_handler (
5795 vl_api_map_summary_stats_t *mp)
5797 vl_api_map_summary_stats_reply_t *rmp;
5798 vlib_combined_counter_main_t *cm;
5801 u64 total_pkts[VLIB_N_RX_TX];
5802 u64 total_bytes[VLIB_N_RX_TX];
5803 map_main_t *mm = &map_main;
5804 unix_shared_memory_queue_t *q =
5805 vl_api_client_index_to_input_queue(mp->client_index);
5810 rmp = vl_msg_api_alloc (sizeof (*rmp));
5811 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5812 rmp->context = mp->context;
5815 memset (total_pkts, 0, sizeof (total_pkts));
5816 memset (total_bytes, 0, sizeof (total_bytes));
5818 map_domain_counter_lock (mm);
5819 vec_foreach(cm, mm->domain_counters) {
5820 which = cm - mm->domain_counters;
5822 for (i = 0; i < vec_len(cm->maxi); i++) {
5823 vlib_get_combined_counter (cm, i, &v);
5824 total_pkts[which] += v.packets;
5825 total_bytes[which] += v.bytes;
5829 map_domain_counter_unlock (mm);
5831 /* Note: in network byte order! */
5832 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5833 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5834 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5835 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5836 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5837 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5838 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));
5839 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));
5841 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5844 static void vl_api_ipsec_sa_set_key_t_handler
5845 (vl_api_ipsec_sa_set_key_t * mp)
5847 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5848 vl_api_ipsec_sa_set_key_reply_t *rmp;
5852 sa.id = ntohl(mp->sa_id);
5853 sa.crypto_key_len = mp->crypto_key_length;
5854 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5855 sa.integ_key_len = mp->integrity_key_length;
5856 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5858 rv = ipsec_set_sa_key(vm, &sa);
5860 rv = VNET_API_ERROR_UNIMPLEMENTED;
5863 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5866 static void vl_api_cop_interface_enable_disable_t_handler
5867 (vl_api_cop_interface_enable_disable_t * mp)
5869 vl_api_cop_interface_enable_disable_reply_t * rmp;
5871 u32 sw_if_index = ntohl(mp->sw_if_index);
5874 VALIDATE_SW_IF_INDEX(mp);
5876 enable_disable = (int) mp->enable_disable;
5878 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5880 BAD_SW_IF_INDEX_LABEL;
5882 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5885 static void vl_api_cop_whitelist_enable_disable_t_handler
5886 (vl_api_cop_whitelist_enable_disable_t * mp)
5888 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5889 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5890 u32 sw_if_index = ntohl(mp->sw_if_index);
5893 VALIDATE_SW_IF_INDEX(mp);
5895 a->sw_if_index = sw_if_index;
5898 a->default_cop = mp->default_cop;
5899 a->fib_id = ntohl(mp->fib_id);
5901 rv = cop_whitelist_enable_disable (a);
5903 BAD_SW_IF_INDEX_LABEL;
5905 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5908 static void vl_api_get_node_graph_t_handler
5909 (vl_api_get_node_graph_t * mp)
5913 api_main_t * am = &api_main;
5914 vlib_main_t * vm = vlib_get_main();
5916 vl_api_get_node_graph_reply_t * rmp;
5918 pthread_mutex_lock (&am->vlib_rp->mutex);
5919 oldheap = svm_push_data_heap (am->vlib_rp);
5922 * Keep the number of memcpy ops to a minimum (e.g. 1).
5924 vec_validate (vector, 16384);
5925 vec_reset_length (vector);
5928 vector = vlib_node_serialize (&vm->node_main, vector,
5929 (u32)~0 /* all threads */,
5930 1 /* include nexts */,
5931 1 /* include stats */);
5933 svm_pop_heap (oldheap);
5934 pthread_mutex_unlock (&am->vlib_rp->mutex);
5936 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5937 rmp->reply_in_shmem = (uword) vector);
5940 static void vl_api_trace_profile_add_t_handler
5941 (vl_api_trace_profile_add_t *mp)
5944 vl_api_trace_profile_add_reply_t * rmp;
5945 clib_error_t *error;
5947 /* Ignoring the profile id as currently a single profile
5949 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5950 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5951 mp->pow_enable, mp->trace_tsp,
5954 clib_error_report(error);
5955 rv = clib_error_get_code(error);
5958 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5961 static void vl_api_trace_profile_apply_t_handler
5962 (vl_api_trace_profile_apply_t *mp)
5965 vl_api_trace_profile_apply_reply_t * rmp;
5967 if (mp->enable != 0) {
5968 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5969 ntohl(mp->prefix_length),
5971 mp->trace_op == IOAM_HBYH_ADD,
5972 mp->trace_op == IOAM_HBYH_POP,
5973 mp->trace_op == IOAM_HBYH_MOD);
5975 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5977 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5980 static void vl_api_trace_profile_del_t_handler
5981 (vl_api_trace_profile_del_t *mp)
5984 vl_api_trace_profile_del_reply_t * rmp;
5985 clib_error_t *error;
5987 error = clear_ioam_rewrite_fn();
5989 clib_error_report(error);
5990 rv = clib_error_get_code(error);
5993 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5997 vl_api_af_packet_create_t_handler
5998 (vl_api_af_packet_create_t *mp)
6000 vlib_main_t *vm = vlib_get_main();
6001 vl_api_af_packet_create_reply_t *rmp;
6003 u8 *host_if_name = NULL;
6006 host_if_name = format(0, "%s", mp->host_if_name);
6007 vec_add1 (host_if_name, 0);
6009 rv = af_packet_create_if(vm, host_if_name,
6010 mp->use_random_hw_addr ? 0 : mp->hw_addr, &sw_if_index);
6012 vec_free(host_if_name);
6014 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6015 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index));
6019 vl_api_af_packet_delete_t_handler
6020 (vl_api_af_packet_delete_t *mp)
6022 vlib_main_t * vm = vlib_get_main();
6023 vl_api_af_packet_delete_reply_t *rmp;
6025 u8 *host_if_name = NULL;
6027 host_if_name = format(0, "%s", mp->host_if_name);
6028 vec_add1 (host_if_name, 0);
6030 rv = af_packet_delete_if(vm, host_if_name);
6032 vec_free(host_if_name);
6034 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
6038 vl_api_policer_add_del_t_handler
6039 (vl_api_policer_add_del_t *mp)
6041 vlib_main_t * vm = vlib_get_main();
6042 vl_api_policer_add_del_reply_t *rmp;
6045 sse2_qos_pol_cfg_params_st cfg;
6046 clib_error_t * error;
6048 name = format(0, "%s", mp->name);
6050 memset (&cfg, 0, sizeof (cfg));
6052 cfg.rnd_type = mp->round_type;
6053 cfg.rate_type = mp->rate_type;
6054 cfg.rb.kbps.cir_kbps = mp->cir;
6055 cfg.rb.kbps.eir_kbps = mp->eir;
6056 cfg.rb.kbps.cb_bytes = mp->cb;
6057 cfg.rb.kbps.eb_bytes = mp->eb;
6059 error = policer_add_del(vm, name, &cfg, mp->is_add);
6062 rv = VNET_API_ERROR_UNSPECIFIED;
6064 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
6068 send_policer_details (u8 *name,
6069 sse2_qos_pol_cfg_params_st *config,
6070 policer_read_response_type_st *templ,
6071 unix_shared_memory_queue_t *q,
6074 vl_api_policer_details_t * mp;
6076 mp = vl_msg_api_alloc (sizeof (*mp));
6077 memset (mp, 0, sizeof (*mp));
6078 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6079 mp->context = context;
6080 mp->cir = htonl(config->rb.kbps.cir_kbps);
6081 mp->eir = htonl(config->rb.kbps.eir_kbps);
6082 mp->cb = htonl(config->rb.kbps.cb_bytes);
6083 mp->eb = htonl(config->rb.kbps.eb_bytes);
6084 mp->rate_type = config->rate_type;
6085 mp->round_type = config->rnd_type;
6086 mp->type = config->rfc;
6087 mp->single_rate = templ->single_rate ? 1 : 0;
6088 mp->color_aware = templ->color_aware ? 1 : 0;
6089 mp->scale = htonl(templ->scale);
6090 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6091 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6092 mp->current_limit = htonl(templ->current_limit);
6093 mp->current_bucket = htonl(templ->current_bucket);
6094 mp->extended_limit = htonl(templ->extended_limit);
6095 mp->extended_bucket = htonl(templ->extended_bucket);
6096 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6098 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6100 vl_msg_api_send_shmem (q, (u8 *)&mp);
6104 vl_api_policer_dump_t_handler
6105 (vl_api_policer_dump_t *mp)
6107 unix_shared_memory_queue_t * q;
6108 vnet_policer_main_t * pm = &vnet_policer_main;
6112 u8 * match_name = 0;
6114 sse2_qos_pol_cfg_params_st *config;
6115 policer_read_response_type_st *templ;
6117 q = vl_api_client_index_to_input_queue (mp->client_index);
6121 if (mp->match_name_valid) {
6122 match_name = format(0, "%s%c", mp->match_name, 0);
6125 if (mp->match_name_valid) {
6126 p = hash_get_mem (pm->policer_config_by_name, match_name);
6129 config = pool_elt_at_index (pm->configs, pool_index);
6130 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6131 send_policer_details(match_name, config, templ, q, mp->context);
6134 hash_foreach_pair (hp, pm->policer_config_by_name,
6136 name = (u8 *) hp->key;
6137 pool_index = hp->value[0];
6138 config = pool_elt_at_index (pm->configs, pool_index);
6139 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6140 send_policer_details(name, config, templ, q, mp->context);
6146 vl_api_netmap_create_t_handler
6147 (vl_api_netmap_create_t *mp)
6149 vlib_main_t *vm = vlib_get_main();
6150 vl_api_netmap_create_reply_t *rmp;
6154 if_name = format(0, "%s", mp->netmap_if_name);
6155 vec_add1 (if_name, 0);
6157 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6158 mp->is_pipe, mp->is_master, 0);
6162 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6166 vl_api_netmap_delete_t_handler
6167 (vl_api_netmap_delete_t *mp)
6169 vlib_main_t * vm = vlib_get_main();
6170 vl_api_netmap_delete_reply_t *rmp;
6174 if_name = format(0, "%s", mp->netmap_if_name);
6175 vec_add1 (if_name, 0);
6177 rv = netmap_delete_if(vm, if_name);
6181 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6184 #define BOUNCE_HANDLER(nn) \
6185 static void vl_api_##nn##_t_handler ( \
6186 vl_api_##nn##_t *mp) \
6188 vpe_client_registration_t *reg; \
6189 vpe_api_main_t * vam = &vpe_api_main; \
6190 unix_shared_memory_queue_t * q; \
6192 /* One registration only... */ \
6193 pool_foreach(reg, vam->nn##_registrations, \
6195 q = vl_api_client_index_to_input_queue (reg->client_index); \
6198 * If the queue is stuffed, turf the msg and complain \
6199 * It's unlikely that the intended recipient is \
6200 * alive; avoid deadlock at all costs. \
6202 if (q->cursize == q->maxsize) { \
6203 clib_warning ("ERROR: receiver queue full, drop msg"); \
6204 vl_msg_api_free (mp); \
6207 vl_msg_api_send_shmem (q, (u8 *)&mp); \
6211 vl_msg_api_free (mp); \
6216 * Add vpe's API message handlers to the table.
6217 * vlib has alread mapped shared memory and
6218 * added the client registration handlers.
6219 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
6222 static clib_error_t *
6223 vpe_api_hookup (vlib_main_t *vm)
6225 api_main_t * am = &api_main;
6228 vl_msg_api_set_handlers(VL_API_##N, #n, \
6229 vl_api_##n##_t_handler, \
6231 vl_api_##n##_t_endian, \
6232 vl_api_##n##_t_print, \
6233 sizeof(vl_api_##n##_t), 1);
6234 foreach_vpe_api_msg;
6238 * Manually register the sr tunnel add del msg, so we trace
6239 * enough bytes to capture a typical segment list
6241 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6242 "sr_tunnel_add_del",
6243 vl_api_sr_tunnel_add_del_t_handler,
6245 vl_api_sr_tunnel_add_del_t_endian,
6246 vl_api_sr_tunnel_add_del_t_print,
6251 * Manually register the sr policy add del msg, so we trace
6252 * enough bytes to capture a typical tunnel name list
6254 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6255 "sr_policy_add_del",
6256 vl_api_sr_policy_add_del_t_handler,
6258 vl_api_sr_policy_add_del_t_endian,
6259 vl_api_sr_policy_add_del_t_print,
6263 * Trace space for 8 MPLS encap labels, classifier mask+match
6265 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6266 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6267 += 5 * sizeof (u32x4);
6268 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6269 += 5 * sizeof (u32x4);
6270 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6271 += 16 * sizeof (u32);
6274 * Thread-safe API messages
6276 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6277 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
6282 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6284 static clib_error_t *
6285 vpe_api_init (vlib_main_t *vm)
6287 vpe_api_main_t *am = &vpe_api_main;
6290 am->vnet_main = vnet_get_main();
6291 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6292 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6293 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6294 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6295 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6296 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6299 vl_set_memory_region_name ("/vpe-api");
6300 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6305 VLIB_INIT_FUNCTION(vpe_api_init);
6308 static clib_error_t *
6309 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
6314 struct passwd _pw, *pw;
6315 struct group _grp, *grp;
6318 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6320 if (unformat (input, "prefix %s", &chroot_path))
6322 vec_add1 (chroot_path, 0);
6323 vl_set_memory_root_path ((char *)chroot_path);
6325 else if (unformat (input, "uid %d", &uid))
6326 vl_set_memory_uid (uid);
6327 else if (unformat (input, "gid %d", &gid))
6328 vl_set_memory_gid (gid);
6329 else if (unformat (input, "uid %s", &s))
6331 /* lookup the username */
6333 rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
6336 e = clib_error_return_code(0, rv,
6337 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
6338 "cannot fetch username %s", s);
6344 e = clib_error_return_fatal(0, "username %s does not exist", s);
6349 vl_set_memory_uid (pw->pw_uid);
6351 else if (unformat (input, "gid %s", &s))
6353 /* lookup the group name */
6355 rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
6358 e = clib_error_return_code(0, rv,
6359 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
6360 "cannot fetch group %s", s);
6366 e = clib_error_return_fatal(0, "group %s does not exist", s);
6371 vl_set_memory_gid (grp->gr_gid);
6374 return clib_error_return (0, "unknown input `%U'",
6375 format_unformat_error, input);
6379 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
6381 void * get_unformat_vnet_sw_interface (void)
6383 return (void *) &unformat_vnet_sw_interface;
6386 #undef vl_api_version
6387 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6388 #include <api/vpe.api.h>
6389 #undef vl_api_version
6391 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6393 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6394 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6395 clib_host_to_net_u32 (mp->api_versions[0]),
6402 static u8 * format_arp_event (u8 * s, va_list * args)
6404 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6406 s = format (s, "pid %d: %U", event->pid,
6407 format_ip4_address, &event->address);
6411 static clib_error_t *
6412 show_ip4_arp_events_fn (vlib_main_t * vm,
6413 unformat_input_t * input,
6414 vlib_cli_command_t * cmd)
6416 vpe_api_main_t * am = &vpe_api_main;
6417 vl_api_ip4_arp_event_t * event;
6419 if (pool_elts (am->arp_events) == 0) {
6420 vlib_cli_output (vm, "No active arp event registrations");
6424 pool_foreach (event, am->arp_events,
6426 vlib_cli_output (vm, "%U", format_arp_event, event);
6432 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6433 .path = "show arp event registrations",
6434 .function = show_ip4_arp_events_fn,
6435 .short_help = "Show arp event registrations",