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);
2598 send_sw_interface_flags (am, q, swif);
2600 _vec_len (name_string) = 0;
2603 vec_free (name_string);
2604 vec_free (filter_string);
2607 void send_oam_event (oam_target_t * t)
2609 vpe_api_main_t * vam = &vpe_api_main;
2610 unix_shared_memory_queue_t * q;
2611 vpe_client_registration_t *reg;
2612 vl_api_oam_event_t * mp;
2614 pool_foreach(reg, vam->oam_events_registrations,
2616 q = vl_api_client_index_to_input_queue (reg->client_index);
2618 mp = vl_msg_api_alloc (sizeof (*mp));
2619 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2620 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2621 mp->state = t->state;
2622 vl_msg_api_send_shmem (q, (u8 *)&mp);
2628 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2630 vl_api_oam_add_del_reply_t * rmp;
2633 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2634 (ip4_address_t *)mp->dst_address,
2638 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2642 vl_api_vnet_get_summary_stats_t_handler (
2643 vl_api_vnet_get_summary_stats_t *mp)
2645 stats_main_t * sm = &stats_main;
2646 vnet_interface_main_t * im = sm->interface_main;
2647 vl_api_vnet_summary_stats_reply_t *rmp;
2648 vlib_combined_counter_main_t * cm;
2651 u64 total_pkts[VLIB_N_RX_TX];
2652 u64 total_bytes[VLIB_N_RX_TX];
2654 unix_shared_memory_queue_t * q =
2655 vl_api_client_index_to_input_queue (mp->client_index);
2660 rmp = vl_msg_api_alloc (sizeof (*rmp));
2661 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2662 rmp->context = mp->context;
2665 memset (total_pkts, 0, sizeof (total_pkts));
2666 memset (total_bytes, 0, sizeof (total_bytes));
2668 vnet_interface_counter_lock (im);
2670 vec_foreach (cm, im->combined_sw_if_counters) {
2671 which = cm - im->combined_sw_if_counters;
2673 for (i = 0; i < vec_len (cm->maxi); i++) {
2674 vlib_get_combined_counter (cm, i, &v);
2675 total_pkts[which] += v.packets;
2676 total_bytes[which] += v.bytes;
2679 vnet_interface_counter_unlock (im);
2681 /* Note: in HOST byte order! */
2682 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2683 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2684 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2685 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2686 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2688 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2691 typedef CLIB_PACKED (struct {
2692 ip4_address_t address;
2694 u32 address_length : 6;
2699 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2701 vnet_main_t * vnm = vnet_get_main();
2702 vnet_interface_main_t * im = &vnm->interface_main;
2703 ip4_main_t * im4 = &ip4_main;
2704 static ip4_route_t * routes;
2705 static u32 * sw_if_indices_to_shut;
2706 stats_main_t * sm = &stats_main;
2711 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2712 u32 target_fib_id = ntohl(mp->vrf_id);
2714 dslock (sm, 1 /* release hint */, 8 /* tag */);
2716 vec_foreach (fib, im4->fibs) {
2717 vnet_sw_interface_t * si;
2719 if (fib->table_id != target_fib_id)
2722 /* remove any mpls/gre tunnels in this fib */
2723 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2725 /* remove any mpls encap/decap labels */
2726 mpls_fib_reset_labels (fib->table_id);
2728 /* remove any proxy arps in this fib */
2729 vnet_proxy_arp_fib_reset (fib->table_id);
2731 /* Set the flow hash for this fib to the default */
2732 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2734 vec_reset_length (sw_if_indices_to_shut);
2736 /* Shut down interfaces in this FIB / clean out intfc routes */
2737 pool_foreach (si, im->sw_interfaces,
2739 u32 sw_if_index = si->sw_if_index;
2741 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2742 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2744 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2747 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2748 sw_if_index = sw_if_indices_to_shut[i];
2749 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2751 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2752 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2753 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2756 vec_reset_length (routes);
2758 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2759 uword * hash = fib->adj_index_by_dst_address[i];
2763 x.address_length = i;
2765 hash_foreach_pair (p, hash,
2767 x.address.data_u32 = p->key;
2768 vec_add1 (routes, x);
2772 vec_foreach (r, routes) {
2773 ip4_add_del_route_args_t a;
2775 memset (&a, 0, sizeof (a));
2776 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2777 a.table_index_or_table_id = fib - im4->fibs;
2778 a.dst_address = r->address;
2779 a.dst_address_length = r->address_length;
2782 ip4_add_del_route (im4, &a);
2783 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2784 IP4_ROUTE_FLAG_FIB_INDEX);
2788 } /* vec_foreach (fib) */
2795 ip6_address_t address;
2802 ip6_route_t ** routep;
2803 } add_routes_in_fib_arg_t;
2805 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2807 add_routes_in_fib_arg_t * ap = arg;
2809 if (kvp->key[2]>>32 == ap->fib_index)
2811 ip6_address_t *addr;
2813 addr = (ip6_address_t *) kvp;
2814 vec_add2 (*ap->routep, r, 1);
2815 r->address = addr[0];
2816 r->address_length = kvp->key[2] & 0xFF;
2817 r->index = kvp->value;
2821 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2823 vnet_main_t * vnm = vnet_get_main();
2824 vnet_interface_main_t * im = &vnm->interface_main;
2825 ip6_main_t * im6 = &ip6_main;
2826 stats_main_t * sm = &stats_main;
2827 static ip6_route_t * routes;
2828 static u32 * sw_if_indices_to_shut;
2833 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2834 u32 target_fib_id = ntohl(mp->vrf_id);
2835 add_routes_in_fib_arg_t _a, *a=&_a;
2836 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2838 dslock (sm, 1 /* release hint */, 9 /* tag */);
2840 vec_foreach (fib, im6->fibs) {
2841 vnet_sw_interface_t * si;
2843 if (fib->table_id != target_fib_id)
2846 vec_reset_length (sw_if_indices_to_shut);
2848 /* Shut down interfaces in this FIB / clean out intfc routes */
2849 pool_foreach (si, im->sw_interfaces,
2851 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2853 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2856 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2857 sw_if_index = sw_if_indices_to_shut[i];
2858 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2860 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2861 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2862 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2865 vec_reset_length (routes);
2867 a->fib_index = fib - im6->fibs;
2868 a->routep = &routes;
2870 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2872 vec_foreach (r, routes) {
2873 ip6_add_del_route_args_t a;
2875 memset (&a, 0, sizeof (a));
2876 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2877 a.table_index_or_table_id = fib - im6->fibs;
2878 a.dst_address = r->address;
2879 a.dst_address_length = r->address_length;
2882 ip6_add_del_route (im6, &a);
2883 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2884 IP6_ROUTE_FLAG_FIB_INDEX);
2887 /* Reinstall the neighbor / router discovery routes */
2888 vnet_ip6_fib_init (im6, fib - im6->fibs);
2890 } /* vec_foreach (fib) */
2896 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2899 vl_api_reset_fib_reply_t * rmp;
2902 rv = ip6_reset_fib_t_handler (mp);
2904 rv = ip4_reset_fib_t_handler (mp);
2906 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2911 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2913 vl_api_dhcp_proxy_config_reply_t * rmp;
2916 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2917 (ip4_address_t *)(&mp->dhcp_src_address),
2918 (u32) ntohl(mp->vrf_id),
2919 (int) mp->insert_circuit_id,
2920 (int) (mp->is_add == 0));
2922 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2927 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2929 vl_api_dhcp_proxy_config_reply_t * rmp;
2932 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2933 (ip6_address_t *)(&mp->dhcp_src_address),
2934 (u32) ntohl(mp->vrf_id),
2935 (int) mp->insert_circuit_id,
2936 (int) (mp->is_add == 0));
2938 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2942 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2944 vl_api_dhcp_proxy_config_reply_t * rmp;
2947 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2948 (ip4_address_t *)(&mp->dhcp_src_address),
2949 (u32) ntohl(mp->rx_vrf_id),
2950 (u32) ntohl(mp->server_vrf_id),
2951 (int) mp->insert_circuit_id,
2952 (int) (mp->is_add == 0));
2954 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2959 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2961 vl_api_dhcp_proxy_config_reply_t * rmp;
2965 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2966 (ip6_address_t *)(&mp->dhcp_src_address),
2967 (u32) ntohl(mp->rx_vrf_id),
2968 (u32) ntohl(mp->server_vrf_id),
2969 (int) mp->insert_circuit_id,
2970 (int) (mp->is_add == 0));
2972 rv = VNET_API_ERROR_UNIMPLEMENTED;
2975 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2980 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2982 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2985 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2988 (int)mp->is_add == 0);
2990 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2993 (int)mp->is_add == 0);
2995 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2999 static void vl_api_dhcp_proxy_config_t_handler
3000 (vl_api_dhcp_proxy_config_t *mp)
3002 if (mp->is_ipv6 == 0)
3003 dhcpv4_proxy_config (mp);
3005 dhcpv6_proxy_config (mp);
3008 static void vl_api_dhcp_proxy_config_2_t_handler
3009 (vl_api_dhcp_proxy_config_2_t *mp)
3011 if (mp->is_ipv6 == 0)
3012 dhcpv4_proxy_config_2 (mp);
3014 dhcpv6_proxy_config_2 (mp);
3017 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3018 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3020 unix_shared_memory_queue_t * q;
3021 vl_api_dhcp_compl_event_t * mp;
3023 q = vl_api_client_index_to_input_queue (client_index);
3027 mp = vl_msg_api_alloc (sizeof (*mp));
3028 mp->client_index = client_index;
3030 mp->is_ipv6 = is_ipv6;
3031 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3032 mp->hostname[vec_len(hostname) + 1] = '\n';
3033 clib_memcpy (&mp->host_address[0], host_address, 16);
3034 clib_memcpy (&mp->router_address[0], router_address, 16);
3035 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3037 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3039 vl_msg_api_send_shmem (q, (u8 *)&mp);
3042 static void vl_api_dhcp_client_config_t_handler
3043 (vl_api_dhcp_client_config_t *mp)
3045 vlib_main_t *vm = vlib_get_main();
3046 vl_api_dhcp_client_config_reply_t * rmp;
3049 VALIDATE_SW_IF_INDEX(mp);
3051 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3052 mp->hostname, mp->is_add, mp->client_index,
3053 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3056 BAD_SW_IF_INDEX_LABEL;
3058 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3062 vl_api_sw_interface_ip6nd_ra_config_t_handler
3063 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3065 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3067 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3069 is_no = mp->is_no == 1;
3070 surpress = mp->surpress == 1;
3071 managed = mp->managed == 1;
3072 other = mp->other == 1;
3073 ll_option = mp->ll_option == 1;
3074 send_unicast = mp->send_unicast == 1;
3075 cease = mp->cease == 1;
3076 default_router = mp->default_router == 1;
3078 VALIDATE_SW_IF_INDEX(mp);
3080 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3081 surpress, managed, other,
3082 ll_option, send_unicast, cease,
3083 default_router, ntohl (mp->lifetime),
3084 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3085 ntohl(mp->max_interval), ntohl( mp->min_interval),
3088 BAD_SW_IF_INDEX_LABEL;
3090 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3094 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3095 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3097 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3099 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3101 VALIDATE_SW_IF_INDEX(mp);
3103 is_no = mp->is_no == 1;
3104 use_default = mp->use_default == 1;
3105 no_advertise = mp->no_advertise == 1;
3106 off_link = mp->off_link == 1;
3107 no_autoconfig = mp->no_autoconfig == 1;
3108 no_onlink = mp->no_onlink == 1;
3110 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3111 (ip6_address_t *)mp->address, mp->address_length,
3112 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3113 no_advertise, off_link, no_autoconfig, no_onlink,
3116 BAD_SW_IF_INDEX_LABEL;
3117 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3121 vl_api_sw_interface_ip6_enable_disable_t_handler
3122 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3124 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3125 vnet_main_t * vnm = vnet_get_main();
3127 clib_error_t * error;
3131 VALIDATE_SW_IF_INDEX(mp);
3133 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3134 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3137 clib_error_report(error);
3138 rv = VNET_API_ERROR_UNSPECIFIED;
3140 rv = vnm->api_errno;
3143 BAD_SW_IF_INDEX_LABEL;
3145 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3149 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3150 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3152 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3154 clib_error_t * error;
3155 vnet_main_t * vnm = vnet_get_main();
3159 VALIDATE_SW_IF_INDEX(mp);
3161 error = set_ip6_link_local_address(vm,
3162 ntohl(mp->sw_if_index),
3163 (ip6_address_t *)mp->address,
3164 mp->address_length);
3166 clib_error_report(error);
3167 rv = VNET_API_ERROR_UNSPECIFIED;
3169 rv = vnm->api_errno;
3172 BAD_SW_IF_INDEX_LABEL;
3174 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3177 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3179 vl_api_set_ip_flow_hash_reply_t *rmp;
3180 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3182 clib_warning ("unimplemented...");
3184 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3187 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3189 vl_api_set_ip_flow_hash_reply_t *rmp;
3192 u32 flow_hash_config = 0;
3194 table_id = ntohl(mp->vrf_id);
3196 #define _(a,b) if (mp->a) flow_hash_config |= b;
3197 foreach_flow_hash_bit;
3200 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3202 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3206 static void vl_api_set_ip_flow_hash_t_handler
3207 (vl_api_set_ip_flow_hash_t *mp)
3209 if (mp->is_ipv6 == 0)
3210 set_ip4_flow_hash (mp);
3212 set_ip6_flow_hash (mp);
3215 static void vl_api_sw_interface_set_unnumbered_t_handler
3216 (vl_api_sw_interface_set_unnumbered_t *mp)
3218 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3220 vnet_sw_interface_t * si;
3221 vnet_main_t *vnm = vnet_get_main();
3222 u32 sw_if_index, unnumbered_sw_if_index;
3224 sw_if_index = ntohl(mp->sw_if_index);
3225 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3228 * The API message field names are backwards from
3229 * the underlying data structure names.
3230 * It's not worth changing them now.
3232 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3233 unnumbered_sw_if_index)) {
3234 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3238 /* Only check the "use loop0" field when setting the binding */
3240 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3241 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3245 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3248 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3249 si->unnumbered_sw_if_index = sw_if_index;
3251 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3252 si->unnumbered_sw_if_index = (u32)~0;
3256 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3259 static void vl_api_create_loopback_t_handler
3260 (vl_api_create_loopback_t *mp)
3262 vl_api_create_loopback_reply_t * rmp;
3266 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3268 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3270 rmp->sw_if_index = ntohl (sw_if_index);
3274 static void vl_api_delete_loopback_t_handler
3275 (vl_api_delete_loopback_t *mp)
3277 vl_api_delete_loopback_reply_t * rmp;
3281 sw_if_index = ntohl (mp->sw_if_index);
3282 rv = vnet_delete_loopback_interface (sw_if_index);
3284 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3287 static void vl_api_control_ping_t_handler
3288 (vl_api_control_ping_t *mp)
3290 vl_api_control_ping_reply_t * rmp;
3293 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3295 rmp->vpe_pid = ntohl (getpid());
3299 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3301 u8 **shmem_vecp = (u8 **)arg;
3304 api_main_t * am = &api_main;
3307 shmem_vec = *shmem_vecp;
3309 offset = vec_len (shmem_vec);
3311 pthread_mutex_lock (&am->vlib_rp->mutex);
3312 oldheap = svm_push_data_heap (am->vlib_rp);
3314 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3316 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3318 svm_pop_heap (oldheap);
3319 pthread_mutex_unlock (&am->vlib_rp->mutex);
3321 *shmem_vecp = shmem_vec;
3325 static void vl_api_cli_request_t_handler
3326 (vl_api_cli_request_t *mp)
3328 vl_api_cli_reply_t *rp;
3329 unix_shared_memory_queue_t *q;
3330 vlib_main_t * vm = vlib_get_main();
3331 api_main_t * am = &api_main;
3332 unformat_input_t input;
3336 q = vl_api_client_index_to_input_queue (mp->client_index);
3340 rp = vl_msg_api_alloc (sizeof (*rp));
3341 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3342 rp->context = mp->context;
3344 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3346 vlib_cli_input (vm, &input, shmem_cli_output,
3349 pthread_mutex_lock (&am->vlib_rp->mutex);
3350 oldheap = svm_push_data_heap (am->vlib_rp);
3352 vec_add1(shmem_vec, 0);
3354 svm_pop_heap (oldheap);
3355 pthread_mutex_unlock (&am->vlib_rp->mutex);
3357 rp->reply_in_shmem = (uword)shmem_vec;
3359 vl_msg_api_send_shmem (q, (u8 *)&rp);
3362 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3365 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3366 vnet_main_t *vnm = vnet_get_main();
3367 clib_error_t * error;
3372 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3374 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3377 clib_error_report(error);
3378 rv = VNET_API_ERROR_UNSPECIFIED;
3380 rv = vnm->api_errno;
3383 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3386 static void vl_api_sr_tunnel_add_del_t_handler
3387 (vl_api_sr_tunnel_add_del_t *mp)
3390 clib_warning ("unimplemented");
3392 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3394 vl_api_sr_tunnel_add_del_reply_t * rmp;
3395 ip6_address_t * segments = 0, * seg;
3396 ip6_address_t * tags = 0, *tag;
3397 ip6_address_t * this_address;
3400 if (mp->n_segments == 0) {
3405 memset (a, 0, sizeof (*a));
3406 a->src_address = (ip6_address_t *)&mp->src_address;
3407 a->dst_address = (ip6_address_t *)&mp->dst_address;
3408 a->dst_mask_width = mp->dst_mask_width;
3409 a->flags_net_byte_order = mp->flags_net_byte_order;
3410 a->is_del = (mp->is_add == 0);
3411 a->rx_table_id = ntohl(mp->outer_vrf_id);
3412 a->tx_table_id = ntohl(mp->inner_vrf_id);
3414 a->name = format(0, "%s", mp->name);
3415 if (!(vec_len(a->name)))
3418 a->policy_name = format(0, "%s", mp->policy_name);
3419 if (!(vec_len(a->policy_name)))
3422 /* Yank segments and tags out of the API message */
3423 this_address = (ip6_address_t *)mp->segs_and_tags;
3424 for (i = 0; i < mp->n_segments; i++) {
3425 vec_add2 (segments, seg, 1);
3426 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3429 for (i = 0; i < mp->n_tags; i++) {
3430 vec_add2 (tags, tag, 1);
3431 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3435 a->segments = segments;
3438 rv = ip6_sr_add_del_tunnel (a);
3442 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3446 static void vl_api_sr_policy_add_del_t_handler
3447 (vl_api_sr_policy_add_del_t *mp)
3450 clib_warning ("unimplemented");
3452 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3454 vl_api_sr_policy_add_del_reply_t * rmp;
3457 memset (a, 0, sizeof (*a));
3458 a->is_del = (mp->is_add == 0);
3460 a->name = format(0, "%s", mp->name);
3461 if (!(vec_len(a->name)))
3463 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3467 if (!(mp->tunnel_names[0]))
3469 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3473 // start deserializing tunnel_names
3474 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3475 u8 * deser_tun_names = mp->tunnel_names;
3476 deser_tun_names += 1; //moving along
3479 int tun_name_len = 0;
3481 for (i=0; i < num_tunnels; i++)
3483 tun_name_len= *deser_tun_names;
3484 deser_tun_names += 1;
3485 vec_resize (tun_name, tun_name_len);
3486 memcpy(tun_name, deser_tun_names, tun_name_len);
3487 vec_add1 (a->tunnel_names, tun_name);
3488 deser_tun_names += tun_name_len;
3492 rv = ip6_sr_add_del_policy (a);
3496 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3500 static void vl_api_sr_multicast_map_add_del_t_handler
3501 (vl_api_sr_multicast_map_add_del_t *mp)
3504 clib_warning ("unimplemented");
3506 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3508 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3510 memset (a, 0, sizeof (*a));
3511 a->is_del = (mp->is_add == 0);
3513 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3514 a->policy_name = format(0, "%s", mp->policy_name);
3516 if (a->multicast_address == 0)
3522 if (!(a->policy_name))
3528 #if DPDK > 0 /* Cannot call replicate without DPDK */
3529 rv = ip6_sr_add_del_multicastmap (a);
3531 clib_warning ("multicast replication without DPDK not implemented");
3532 rv = VNET_API_ERROR_UNIMPLEMENTED;
3537 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3541 #define foreach_classify_add_del_table_field \
3546 _(match_n_vectors) \
3547 _(next_table_index) \
3550 static void vl_api_classify_add_del_table_t_handler
3551 (vl_api_classify_add_del_table_t * mp)
3553 vl_api_classify_add_del_table_reply_t * rmp;
3554 vnet_classify_main_t * cm = &vnet_classify_main;
3555 vnet_classify_table_t * t;
3559 foreach_classify_add_del_table_field;
3562 #define _(a) a = ntohl(mp->a);
3563 foreach_classify_add_del_table_field;
3566 /* The underlying API fails silently, on purpose, so check here */
3567 if (mp->is_add == 0)
3568 if (pool_is_free_index (cm->tables, table_index)) {
3569 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3573 rv = vnet_classify_add_del_table
3574 (cm, mp->mask, nbuckets, memory_size,
3575 skip_n_vectors, match_n_vectors,
3576 next_table_index, miss_next_index,
3577 &table_index, mp->is_add);
3580 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3582 if (rv == 0 && mp->is_add) {
3583 t = pool_elt_at_index (cm->tables, table_index);
3584 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3585 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3586 rmp->new_table_index = ntohl(table_index);
3588 rmp->skip_n_vectors = ~0;
3589 rmp->match_n_vectors = ~0;
3590 rmp->new_table_index = ~0;
3595 static void vl_api_classify_add_del_session_t_handler
3596 (vl_api_classify_add_del_session_t * mp)
3598 vnet_classify_main_t * cm = &vnet_classify_main;
3599 vl_api_classify_add_del_session_reply_t * rmp;
3601 u32 table_index, hit_next_index, opaque_index;
3604 table_index = ntohl (mp->table_index);
3605 hit_next_index = ntohl (mp->hit_next_index);
3606 opaque_index = ntohl (mp->opaque_index);
3607 advance = ntohl (mp->advance);
3609 rv = vnet_classify_add_del_session
3610 (cm, table_index, mp->match, hit_next_index, opaque_index,
3611 advance, mp->is_add);
3613 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3616 static void vl_api_classify_set_interface_ip_table_t_handler
3617 (vl_api_classify_set_interface_ip_table_t * mp)
3619 vlib_main_t * vm = vlib_get_main();
3620 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3622 u32 table_index, sw_if_index;
3624 table_index = ntohl (mp->table_index);
3625 sw_if_index = ntohl (mp->sw_if_index);
3627 VALIDATE_SW_IF_INDEX(mp);
3630 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3632 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3634 BAD_SW_IF_INDEX_LABEL;
3636 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3639 static void vl_api_classify_set_interface_l2_tables_t_handler
3640 (vl_api_classify_set_interface_l2_tables_t * mp)
3642 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3644 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3647 ip4_table_index = ntohl(mp->ip4_table_index);
3648 ip6_table_index = ntohl(mp->ip6_table_index);
3649 other_table_index = ntohl(mp->other_table_index);
3650 sw_if_index = ntohl(mp->sw_if_index);
3652 VALIDATE_SW_IF_INDEX(mp);
3654 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3655 ip6_table_index, other_table_index);
3658 if (ip4_table_index != ~0 || ip6_table_index != ~0
3659 || other_table_index != ~0)
3664 vnet_l2_classify_enable_disable (sw_if_index, enable);
3667 BAD_SW_IF_INDEX_LABEL;
3669 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3673 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3676 vl_api_l2_fib_clear_table_reply_t * rmp;
3678 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3679 * that is not currently implemented. When that TODO is fixed
3680 * this call should be changed to pass 1 instead of 0.
3682 l2fib_clear_table (0);
3684 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3687 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3692 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3695 vl_api_l2_interface_efp_filter_reply_t * rmp;
3696 vnet_main_t *vnm = vnet_get_main();
3698 // enable/disable the feature
3699 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3700 rv = vnm->api_errno;
3702 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3706 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3709 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3710 vnet_main_t * vnm = vnet_get_main();
3711 vlib_main_t * vm = vlib_get_main();
3714 VALIDATE_SW_IF_INDEX(mp);
3716 vtr_op = ntohl(mp->vtr_op);
3718 /* The L2 code is unsuspicious */
3720 case L2_VTR_DISABLED:
3725 case L2_VTR_TRANSLATE_1_1:
3726 case L2_VTR_TRANSLATE_1_2:
3727 case L2_VTR_TRANSLATE_2_1:
3728 case L2_VTR_TRANSLATE_2_2:
3732 rv = VNET_API_ERROR_INVALID_VALUE;
3733 goto bad_sw_if_index;
3736 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3737 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3740 BAD_SW_IF_INDEX_LABEL;
3742 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3746 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3750 vl_api_create_vhost_user_if_reply_t * rmp;
3751 u32 sw_if_index = (u32)~0;
3753 vnet_main_t * vnm = vnet_get_main();
3754 vlib_main_t * vm = vlib_get_main();
3756 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3757 mp->is_server, &sw_if_index, (u64)~0,
3758 mp->renumber, ntohl(mp->custom_dev_instance),
3759 (mp->use_custom_mac)?mp->mac_address:NULL);
3761 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3763 rmp->sw_if_index = ntohl (sw_if_index);
3769 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3773 vl_api_modify_vhost_user_if_reply_t * rmp;
3774 u32 sw_if_index = ntohl(mp->sw_if_index);
3776 vnet_main_t * vnm = vnet_get_main();
3777 vlib_main_t * vm = vlib_get_main();
3779 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3780 mp->is_server, sw_if_index, (u64)~0,
3781 mp->renumber, ntohl(mp->custom_dev_instance));
3783 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3788 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3792 vpe_api_main_t * vam = &vpe_api_main;
3793 vl_api_delete_vhost_user_if_reply_t * rmp;
3794 u32 sw_if_index = ntohl(mp->sw_if_index);
3796 vnet_main_t * vnm = vnet_get_main();
3797 vlib_main_t * vm = vlib_get_main();
3799 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3801 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3803 unix_shared_memory_queue_t * q =
3804 vl_api_client_index_to_input_queue (mp->client_index);
3808 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3813 static void vl_api_sw_interface_vhost_user_details_t_handler (
3814 vl_api_sw_interface_vhost_user_details_t * mp)
3816 clib_warning ("BUG");
3820 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3821 unix_shared_memory_queue_t *q,
3822 vhost_user_intf_details_t * vui,
3825 vl_api_sw_interface_vhost_user_details_t * mp;
3827 mp = vl_msg_api_alloc (sizeof (*mp));
3828 memset (mp, 0, sizeof (*mp));
3829 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3830 mp->sw_if_index = ntohl(vui->sw_if_index);
3831 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3832 mp->features = clib_net_to_host_u64 (vui->features);
3833 mp->is_server = vui->is_server;
3834 mp->num_regions = ntohl(vui->num_regions);
3835 mp->sock_errno = ntohl(vui->sock_errno);
3836 mp->context = context;
3838 strncpy ((char *) mp->sock_filename,
3839 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3840 strncpy ((char *) mp->interface_name,
3841 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3843 vl_msg_api_send_shmem (q, (u8 *)&mp);
3848 vl_api_sw_interface_vhost_user_dump_t_handler (
3849 vl_api_sw_interface_vhost_user_dump_t *mp)
3853 vpe_api_main_t * am = &vpe_api_main;
3854 vnet_main_t * vnm = vnet_get_main();
3855 vlib_main_t * vm = vlib_get_main();
3856 vhost_user_intf_details_t *ifaces = NULL;
3857 vhost_user_intf_details_t *vuid = NULL;
3858 unix_shared_memory_queue_t * q;
3860 q = vl_api_client_index_to_input_queue (mp->client_index);
3864 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3868 vec_foreach (vuid, ifaces) {
3869 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3875 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3876 unix_shared_memory_queue_t *q,
3881 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3882 u8 * if_name = NULL;
3883 vnet_sw_interface_t * si = NULL;
3885 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3887 if_name = format(if_name, "%U",
3888 format_vnet_sw_interface_name, lm->vnet_main, si);
3890 mp = vl_msg_api_alloc (sizeof (*mp));
3891 memset (mp, 0, sizeof (*mp));
3892 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3893 strncpy((char *)mp->interface_name,
3894 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3895 mp->sw_if_index = ntohl(si->sw_if_index);
3896 mp->local_session_id = s->local_session_id;
3897 mp->remote_session_id = s->remote_session_id;
3898 mp->local_cookie[0] = s->local_cookie[0];
3899 mp->local_cookie[1] = s->local_cookie[1];
3900 mp->remote_cookie = s->remote_cookie;
3901 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3902 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3903 mp->l2_sublayer_present = s->l2_sublayer_present;
3904 mp->context = context;
3906 vl_msg_api_send_shmem (q, (u8 *)&mp);
3909 static void send_ip_address_details (vpe_api_main_t * am,
3910 unix_shared_memory_queue_t * q,
3916 vl_api_ip_address_details_t * mp;
3918 mp = vl_msg_api_alloc (sizeof (*mp));
3919 memset (mp, 0, sizeof (*mp));
3920 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3923 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3925 u32 * tp = (u32 *)mp->ip;
3926 *tp = ntohl(*(u32*)ip);
3928 mp->prefix_length = prefix_length;
3929 mp->context = context;
3931 vl_msg_api_send_shmem (q, (u8 *)&mp);
3935 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3937 vpe_api_main_t * am = &vpe_api_main;
3938 unix_shared_memory_queue_t * q;
3941 ip6_main_t * im6 = &ip6_main;
3942 ip4_main_t * im4 = &ip4_main;
3943 ip_lookup_main_t * lm6 = &im6->lookup_main;
3944 ip_lookup_main_t * lm4 = &im4->lookup_main;
3945 ip_interface_address_t * ia = 0;
3946 u32 sw_if_index = ~0;
3947 int rv __attribute__ ((unused)) = 0;
3949 VALIDATE_SW_IF_INDEX(mp);
3951 sw_if_index = ntohl(mp->sw_if_index);
3953 q = vl_api_client_index_to_input_queue (mp->client_index);
3959 foreach_ip_interface_address (lm6, ia, sw_if_index,
3960 1 /* honor unnumbered */,
3962 r6 = ip_interface_address_get_address (lm6, ia);
3963 u16 prefix_length = ia->address_length;
3964 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3967 foreach_ip_interface_address (lm4, ia, sw_if_index,
3968 1 /* honor unnumbered */,
3970 r4 = ip_interface_address_get_address (lm4, ia);
3971 u16 prefix_length = ia->address_length;
3972 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3975 BAD_SW_IF_INDEX_LABEL;
3978 static void send_ip_details (vpe_api_main_t * am,
3979 unix_shared_memory_queue_t *q,
3983 vl_api_ip_details_t * mp;
3985 mp = vl_msg_api_alloc (sizeof (*mp));
3986 memset (mp, 0, sizeof (*mp));
3987 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3989 mp->sw_if_index = ntohl(sw_if_index);
3990 mp->context = context;
3992 vl_msg_api_send_shmem (q, (u8 *)&mp);
3996 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3997 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3999 vpe_api_main_t * am = &vpe_api_main;
4000 l2t_main_t * lm = &l2t_main;
4001 unix_shared_memory_queue_t * q;
4002 l2t_session_t *session;
4004 q = vl_api_client_index_to_input_queue (mp->client_index);
4008 pool_foreach (session, lm->sessions,
4010 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4015 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4016 unix_shared_memory_queue_t *q,
4017 tapcli_interface_details_t *tap_if,
4020 vl_api_sw_interface_tap_details_t * mp;
4021 mp = vl_msg_api_alloc (sizeof (*mp));
4022 memset (mp, 0, sizeof (*mp));
4023 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4024 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4025 strncpy((char *)mp->dev_name,
4026 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4027 mp->context = context;
4029 vl_msg_api_send_shmem (q, (u8 *)&mp);
4033 vl_api_sw_interface_tap_dump_t_handler (
4034 vl_api_sw_interface_tap_dump_t *mp)
4037 vpe_api_main_t * am = &vpe_api_main;
4038 unix_shared_memory_queue_t * q;
4039 tapcli_interface_details_t *tapifs = NULL;
4040 tapcli_interface_details_t *tap_if = NULL;
4042 q = vl_api_client_index_to_input_queue (mp->client_index);
4046 rv = vnet_tap_dump_ifs(&tapifs);
4050 vec_foreach(tap_if, tapifs) {
4051 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4058 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4060 vpe_api_main_t * am = &vpe_api_main;
4061 vnet_main_t * vnm = vnet_get_main();
4062 vlib_main_t * vm = vlib_get_main();
4063 vnet_interface_main_t * im = &vnm->interface_main;
4064 unix_shared_memory_queue_t * q;
4065 vnet_sw_interface_t * si, * sorted_sis;
4066 u32 sw_if_index = ~0;
4068 q = vl_api_client_index_to_input_queue (mp->client_index);
4073 /* Gather interfaces. */
4074 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4075 _vec_len (sorted_sis) = 0;
4076 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4078 vec_foreach (si, sorted_sis) {
4079 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4080 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4083 sw_if_index = si->sw_if_index;
4084 send_ip_details(am, q, sw_if_index, mp->context);
4089 static void vl_api_l2_fib_table_entry_t_handler (
4090 vl_api_l2_fib_table_entry_t * mp)
4092 clib_warning ("BUG");
4095 static void send_l2fib_table_entry (vpe_api_main_t * am,
4096 unix_shared_memory_queue_t *q,
4097 l2fib_entry_key_t * l2fe_key,
4098 l2fib_entry_result_t * l2fe_res,
4101 vl_api_l2_fib_table_entry_t * mp;
4103 mp = vl_msg_api_alloc (sizeof (*mp));
4104 memset (mp, 0, sizeof (*mp));
4105 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4107 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4109 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4110 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4111 mp->static_mac = l2fe_res->fields.static_mac;
4112 mp->filter_mac = l2fe_res->fields.filter;
4113 mp->bvi_mac = l2fe_res->fields.bvi;
4114 mp->context = context;
4116 vl_msg_api_send_shmem (q, (u8 *)&mp);
4120 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4122 vpe_api_main_t * am = &vpe_api_main;
4123 bd_main_t * bdm = &bd_main;
4124 l2fib_entry_key_t *l2fe_key = NULL;
4125 l2fib_entry_result_t *l2fe_res = NULL;
4126 u32 ni, bd_id = ntohl (mp->bd_id);
4128 unix_shared_memory_queue_t * q;
4131 q = vl_api_client_index_to_input_queue (mp->client_index);
4135 /* see l2fib_table_dump: ~0 means "any" */
4139 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4146 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4148 vec_foreach_index (ni, l2fe_key) {
4149 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4150 vec_elt_at_index(l2fe_res, ni), mp->context);
4157 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4159 vl_api_show_version_reply_t *rmp;
4161 char * vpe_api_get_build_directory(void);
4162 char * vpe_api_get_version(void);
4163 char * vpe_api_get_build_date(void);
4165 unix_shared_memory_queue_t * q =
4166 vl_api_client_index_to_input_queue (mp->client_index);
4171 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4173 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4174 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4175 ARRAY_LEN(rmp->build_directory)-1);
4176 strncpy ((char *) rmp->version, vpe_api_get_version(),
4177 ARRAY_LEN(rmp->version)-1);
4178 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4179 ARRAY_LEN(rmp->build_date)-1);
4183 static void vl_api_get_node_index_t_handler
4184 (vl_api_get_node_index_t * mp)
4186 vlib_main_t * vm = vlib_get_main();
4187 vl_api_get_node_index_reply_t * rmp;
4190 u32 node_index = ~0;
4192 n = vlib_get_node_by_name (vm, mp->node_name);
4195 rv = VNET_API_ERROR_NO_SUCH_NODE;
4197 node_index = n->index;
4199 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4201 rmp->node_index = ntohl(node_index);
4205 static void vl_api_add_node_next_t_handler
4206 (vl_api_add_node_next_t * mp)
4208 vlib_main_t * vm = vlib_get_main();
4209 vl_api_add_node_next_reply_t * rmp;
4210 vlib_node_t * n, * next;
4212 u32 next_index = ~0;
4214 n = vlib_get_node_by_name (vm, mp->node_name);
4217 rv = VNET_API_ERROR_NO_SUCH_NODE;
4221 next = vlib_get_node_by_name (vm, mp->next_name);
4224 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4226 next_index = vlib_node_add_next (vm, n->index, next->index);
4229 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4231 rmp->next_index = ntohl(next_index);
4235 static void vl_api_l2tpv3_create_tunnel_t_handler
4236 (vl_api_l2tpv3_create_tunnel_t *mp)
4238 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4239 l2t_main_t *lm = &l2t_main;
4240 u32 sw_if_index = (u32)~0;
4243 if (mp->is_ipv6 != 1) {
4244 rv = VNET_API_ERROR_UNIMPLEMENTED;
4248 rv = create_l2tpv3_ipv6_tunnel (lm,
4249 (ip6_address_t *) mp->client_address,
4250 (ip6_address_t *) mp->our_address,
4251 ntohl(mp->local_session_id),
4252 ntohl(mp->remote_session_id),
4253 clib_net_to_host_u64(mp->local_cookie),
4254 clib_net_to_host_u64(mp->remote_cookie),
4255 mp->l2_sublayer_present,
4259 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4261 rmp->sw_if_index = ntohl (sw_if_index);
4265 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4266 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4268 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4269 l2t_main_t *lm = &l2t_main;
4272 VALIDATE_SW_IF_INDEX(mp);
4274 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4275 clib_net_to_host_u64(mp->new_local_cookie),
4276 clib_net_to_host_u64(mp->new_remote_cookie));
4278 BAD_SW_IF_INDEX_LABEL;
4280 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4283 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4284 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4287 vnet_main_t * vnm = vnet_get_main();
4288 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4290 VALIDATE_SW_IF_INDEX(mp);
4292 rv = l2tpv3_interface_enable_disable
4293 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4295 BAD_SW_IF_INDEX_LABEL;
4297 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4300 static void vl_api_l2tpv3_set_lookup_key_t_handler
4301 (vl_api_l2tpv3_set_lookup_key_t * mp)
4304 l2t_main_t *lm = &l2t_main;
4305 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4307 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4308 rv = VNET_API_ERROR_INVALID_VALUE;
4312 lm->lookup_type = mp->key;
4315 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4318 static void vl_api_vxlan_add_del_tunnel_t_handler
4319 (vl_api_vxlan_add_del_tunnel_t * mp)
4321 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4323 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4324 u32 encap_fib_index;
4326 ip4_main_t * im = &ip4_main;
4327 u32 sw_if_index = ~0;
4329 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4331 rv = VNET_API_ERROR_NO_SUCH_FIB;
4334 encap_fib_index = p[0];
4336 /* Check src & dst are different */
4337 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4338 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4339 rv = VNET_API_ERROR_SAME_SRC_DST;
4342 memset (a, 0, sizeof (*a));
4344 a->is_add = mp->is_add;
4345 a->is_ip6 = mp->is_ipv6;
4347 /* ip addresses sent in network byte order */
4349 memcpy(&(a->src.ip6), mp->src_address, 16);
4350 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4352 memcpy(&(a->src.ip4), mp->src_address, 4);
4353 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4356 a->encap_fib_index = encap_fib_index;
4357 a->decap_next_index = ntohl(mp->decap_next_index);
4358 a->vni = ntohl(mp->vni);
4359 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4362 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4364 rmp->sw_if_index = ntohl (sw_if_index);
4368 static void send_vxlan_tunnel_details
4369 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4371 vl_api_vxlan_tunnel_details_t * rmp;
4372 ip4_main_t * im4 = &ip4_main;
4373 ip6_main_t * im6 = &ip6_main;
4374 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4376 rmp = vl_msg_api_alloc (sizeof (*rmp));
4377 memset (rmp, 0, sizeof (*rmp));
4378 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4380 memcpy(rmp->src_address, &(t->src.ip6), 16);
4381 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4382 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4384 memcpy(rmp->src_address, &(t->src.ip4), 4);
4385 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4386 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4388 rmp->vni = htonl(t->vni);
4389 rmp->decap_next_index = htonl(t->decap_next_index);
4390 rmp->sw_if_index = htonl(t->sw_if_index);
4391 rmp->is_ipv6 = is_ipv6;
4392 rmp->context = context;
4394 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4397 static void vl_api_vxlan_tunnel_dump_t_handler
4398 (vl_api_vxlan_tunnel_dump_t * mp)
4400 unix_shared_memory_queue_t * q;
4401 vxlan_main_t * vxm = &vxlan_main;
4405 q = vl_api_client_index_to_input_queue (mp->client_index);
4410 sw_if_index = ntohl(mp->sw_if_index);
4412 if (~0 == sw_if_index) {
4413 pool_foreach (t, vxm->tunnels,
4415 send_vxlan_tunnel_details(t, q, mp->context);
4418 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4419 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4422 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4423 send_vxlan_tunnel_details(t, q, mp->context);
4427 static void vl_api_gre_add_del_tunnel_t_handler
4428 (vl_api_gre_add_del_tunnel_t * mp)
4430 vl_api_gre_add_del_tunnel_reply_t * rmp;
4432 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4435 ip4_main_t * im = &ip4_main;
4436 u32 sw_if_index = ~0;
4438 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4440 rv = VNET_API_ERROR_NO_SUCH_FIB;
4443 outer_table_id = p[0];
4445 /* Check src & dst are different */
4446 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4447 rv = VNET_API_ERROR_SAME_SRC_DST;
4451 memset (a, 0, sizeof (*a));
4453 a->is_add = mp->is_add;
4455 /* ip addresses sent in network byte order */
4456 a->src.as_u32 = mp->src_address;
4457 a->dst.as_u32 = mp->dst_address;
4459 a->outer_table_id = outer_table_id;
4460 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4463 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4465 rmp->sw_if_index = ntohl (sw_if_index);
4469 static void send_gre_tunnel_details
4470 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4472 vl_api_gre_tunnel_details_t * rmp;
4473 ip4_main_t * im = &ip4_main;
4475 rmp = vl_msg_api_alloc (sizeof (*rmp));
4476 memset (rmp, 0, sizeof (*rmp));
4477 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4478 rmp->src_address = t->tunnel_src.data_u32;
4479 rmp->dst_address = t->tunnel_dst.data_u32;
4480 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4481 rmp->sw_if_index = htonl(t->sw_if_index);
4482 rmp->context = context;
4484 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4487 static void vl_api_gre_tunnel_dump_t_handler
4488 (vl_api_gre_tunnel_dump_t * mp)
4490 unix_shared_memory_queue_t * q;
4491 gre_main_t * gm = &gre_main;
4495 q = vl_api_client_index_to_input_queue (mp->client_index);
4500 sw_if_index = ntohl(mp->sw_if_index);
4502 if (~0 == sw_if_index) {
4503 pool_foreach (t, gm->tunnels,
4505 send_gre_tunnel_details(t, q, mp->context);
4508 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4509 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4512 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4513 send_gre_tunnel_details(t, q, mp->context);
4518 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4520 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4522 vl_api_l2_patch_add_del_reply_t * rmp;
4523 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4527 VALIDATE_RX_SW_IF_INDEX(mp);
4528 VALIDATE_TX_SW_IF_INDEX(mp);
4530 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4531 ntohl(mp->tx_sw_if_index),
4532 (int)(mp->is_add != 0));
4534 BAD_RX_SW_IF_INDEX_LABEL;
4535 BAD_TX_SW_IF_INDEX_LABEL;
4537 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4541 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4542 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4544 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4546 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4547 u32 encap_fib_index, decap_fib_index;
4550 ip4_main_t * im = &ip4_main;
4551 u32 sw_if_index = ~0;
4554 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4556 rv = VNET_API_ERROR_NO_SUCH_FIB;
4559 encap_fib_index = p[0];
4561 protocol = ntohl(mp->protocol);
4563 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4564 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4565 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4567 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4570 decap_fib_index = p[0];
4572 decap_fib_index = ntohl(mp->decap_vrf_id);
4575 /* Check src & dst are different */
4576 if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4577 (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4578 rv = VNET_API_ERROR_SAME_SRC_DST;
4581 memset (a, 0, sizeof (*a));
4583 a->is_add = mp->is_add;
4584 a->is_ip6 = mp->is_ipv6;
4585 /* ip addresses sent in network byte order */
4587 clib_memcpy(&(a->local.ip6), mp->local, 16);
4588 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4590 clib_memcpy(&(a->local.ip4), mp->local, 4);
4591 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4593 a->encap_fib_index = encap_fib_index;
4594 a->decap_fib_index = decap_fib_index;
4595 a->protocol = protocol;
4596 a->vni = ntohl(mp->vni);
4597 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4600 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4602 rmp->sw_if_index = ntohl (sw_if_index);
4606 static void send_vxlan_gpe_tunnel_details
4607 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4609 vl_api_vxlan_gpe_tunnel_details_t * rmp;
4610 ip4_main_t * im4 = &ip4_main;
4611 ip6_main_t * im6 = &ip6_main;
4612 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4614 rmp = vl_msg_api_alloc (sizeof (*rmp));
4615 memset (rmp, 0, sizeof (*rmp));
4616 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4618 memcpy(rmp->local, &(t->local.ip6), 16);
4619 memcpy(rmp->remote, &(t->remote.ip6), 16);
4620 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4621 rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
4623 memcpy(rmp->local, &(t->local.ip4), 4);
4624 memcpy(rmp->remote, &(t->remote.ip4), 4);
4625 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4626 rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
4628 rmp->vni = htonl(t->vni);
4629 rmp->protocol = t->protocol;
4630 rmp->sw_if_index = htonl(t->sw_if_index);
4631 rmp->is_ipv6 = is_ipv6;
4632 rmp->context = context;
4634 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4637 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4638 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4640 unix_shared_memory_queue_t * q;
4641 vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
4642 vxlan_gpe_tunnel_t * t;
4645 q = vl_api_client_index_to_input_queue (mp->client_index);
4650 sw_if_index = ntohl(mp->sw_if_index);
4652 if (~0 == sw_if_index) {
4653 pool_foreach (t, vgm->tunnels,
4655 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4658 if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
4659 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
4662 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4663 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4668 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4670 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4672 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4674 u8 *locator_name = NULL;
4676 memset(a, 0, sizeof(a[0]));
4678 locator_name = format(0, "%s", mp->locator_set_name);
4680 a->name = locator_name;
4682 a->is_add = mp->is_add;
4685 rv = vnet_lisp_add_del_locator_set(a, &ls_index);
4687 vec_free(locator_name);
4689 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4693 vl_api_lisp_add_del_locator_t_handler(
4694 vl_api_lisp_add_del_locator_t *mp)
4696 vl_api_lisp_add_del_locator_reply_t *rmp;
4698 locator_t locator, *locators = NULL;
4699 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4701 u8 *locator_name = NULL;
4703 memset(&locator, 0, sizeof(locator));
4704 memset(a, 0, sizeof(a[0]));
4706 locator.sw_if_index = ntohl(mp->sw_if_index);
4707 locator.priority = mp->priority;
4708 locator.weight = mp->weight;
4710 vec_add1(locators, locator);
4712 locator_name = format(0, "%s", mp->locator_set_name);
4714 a->name = locator_name;
4715 a->locators = locators;
4716 a->is_add = mp->is_add;
4719 rv = vnet_lisp_add_del_locator(a, NULL, &ls_index);
4722 vec_free(locator_name);
4724 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4728 vl_api_lisp_add_del_local_eid_t_handler(
4729 vl_api_lisp_add_del_local_eid_t *mp)
4731 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4732 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4734 ip_prefix_t *prefp = NULL;
4735 ip_address_t *ip_eid = NULL;
4738 u32 locator_set_index = ~0, map_index = ~0;
4739 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4742 prefp = &gid_address_ippref(&eid);
4743 ip_eid = &ip_prefix_addr(prefp);
4744 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4747 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4748 sizeof(ip_addr_v6(ip_eid)));
4749 ip_addr_version(ip_eid) = IP6;
4751 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4752 sizeof(ip_addr_v4(ip_eid)));
4753 ip_addr_version(ip_eid) = IP4;
4755 ip_prefix_len(prefp) = mp->prefix_len;
4757 name = format(0, "%s", mp->locator_set_name);
4758 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4760 rv = VNET_API_ERROR_INVALID_VALUE;
4763 locator_set_index = p[0];
4765 /* XXX treat batch configuration */
4766 a->is_add = mp->is_add;
4768 a->locator_set_index = locator_set_index;
4771 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4776 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4780 lisp_gpe_add_del_fwd_entry_set_address(
4781 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4782 ip_address_t *slocator,
4783 ip_address_t *dlocator,
4786 ip_address_t *ip_eid = NULL;
4787 ip_prefix_t *prefp = NULL;
4789 prefp = &gid_address_ippref(eid);
4790 ip_eid = &ip_prefix_addr(prefp);
4792 if (mp->eid_is_ipv6) {
4793 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4794 sizeof(ip_addr_v6(ip_eid)));
4795 ip_addr_version(ip_eid) = IP6;
4797 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4798 sizeof(ip_addr_v4(ip_eid)));
4799 ip_addr_version(ip_eid) = IP4;
4801 ip_prefix_len(prefp) = mp->eid_prefix_len;
4803 if (mp->address_is_ipv6) {
4804 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4805 sizeof(ip_addr_v6(slocator)));
4806 ip_addr_version(slocator) = IP6;
4807 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4808 sizeof(ip_addr_v6(dlocator)));
4809 ip_addr_version(dlocator) = IP6;
4811 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4812 sizeof(ip_addr_v4(slocator)));
4813 ip_addr_version(slocator) = IP4;
4814 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4815 sizeof(ip_addr_v4(dlocator)));
4816 ip_addr_version(dlocator) = IP4;
4821 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4822 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4824 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4826 ip_address_t slocator, dlocator;
4828 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4830 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4832 memset (&a, 0, sizeof(a));
4834 a.is_add = mp->is_add;
4836 a.slocator = slocator;
4837 a.dlocator = dlocator;
4838 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4840 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4844 vl_api_lisp_add_del_map_resolver_t_handler(
4845 vl_api_lisp_add_del_map_resolver_t *mp)
4847 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4849 ip_address_t *ip_addr = NULL;
4850 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4852 a->is_add = mp->is_add;
4853 ip_addr = &a->address;
4856 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4857 sizeof(ip_addr_v6(ip_addr)));
4858 ip_addr_version(ip_addr) = IP6;
4860 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4861 sizeof(ip_addr_v4(ip_addr)));
4862 ip_addr_version(ip_addr) = IP4;
4865 rv = vnet_lisp_add_del_map_resolver (a);
4867 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4871 vl_api_lisp_gpe_enable_disable_t_handler(
4872 vl_api_lisp_gpe_enable_disable_t *mp)
4874 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4876 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4878 a->is_en = mp->is_en;
4879 vnet_lisp_gpe_enable_disable (a);
4881 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4885 vl_api_lisp_enable_disable_t_handler(
4886 vl_api_lisp_enable_disable_t *mp)
4888 vl_api_lisp_enable_disable_reply_t *rmp;
4891 vnet_lisp_enable_disable (mp->is_en);
4892 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4896 vl_api_lisp_gpe_add_del_iface_t_handler(
4897 vl_api_lisp_gpe_add_del_iface_t *mp)
4899 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4901 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4903 a->is_add = mp->is_add;
4904 a->table_id = mp->table_id;
4906 vnet_lisp_gpe_add_del_iface (a, 0);
4908 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4912 vl_api_lisp_pitr_set_locator_set_t_handler(
4913 vl_api_lisp_pitr_set_locator_set_t *mp)
4915 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
4919 ls_name = format (0, "%s", mp->ls_name);
4920 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
4923 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
4926 /** Used for transferring locators via VPP API */
4927 typedef CLIB_PACKED(struct
4929 u8 is_ip4; /**< is locator an IPv4 address */
4930 u8 addr[16]; /**< IPv4/IPv6 address */
4934 send_lisp_locator_set_details_set_address
4935 (vl_api_lisp_locator_set_details_t *rmp,
4936 gid_address_t *gid_address)
4938 ip_prefix_t *ip_addr;
4940 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4944 ip_addr = &gid_address_ippref(gid_address);
4945 rmp->prefix_len = ip_prefix_len(ip_addr);
4946 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4947 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4951 vl_api_lisp_add_del_remote_mapping_t_handler (
4952 vl_api_lisp_add_del_remote_mapping_t *mp)
4955 ip_address_t rloc, * rlocs = 0;
4956 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
4958 gid_address_t _seid, * seid = &_seid;
4959 gid_address_t _deid, * deid = &_deid;
4960 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
4961 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
4963 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
4964 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
4965 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
4966 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
4967 ip_prefix_len(seid_pref) = mp->seid_len;
4968 ip_prefix_len(deid_pref) = mp->deid_len;
4969 gid_address_set_vni (seid, ntohl (mp->vni));
4970 gid_address_set_vni (deid, ntohl (mp->vni));
4972 if (mp->eid_is_ip4) {
4973 ip_prefix_version(seid_pref) = IP4;
4974 ip_prefix_version(deid_pref) = IP4;
4975 clib_memcpy (&ip_addr_v4(seid_addr),
4976 mp->seid, sizeof (ip_addr_v4(seid_addr)));
4977 clib_memcpy (&ip_addr_v4(deid_addr),
4978 mp->deid, sizeof (ip_addr_v4(deid_addr)));
4980 ip_prefix_version(seid_pref) = IP6;
4981 ip_prefix_version(deid_pref) = IP6;
4982 clib_memcpy (&ip_addr_v6(seid_addr),
4983 mp->seid, sizeof (ip_addr_v6(seid_addr)));
4984 clib_memcpy (&ip_addr_v6(deid_addr),
4985 mp->deid, sizeof (ip_addr_v6(deid_addr)));
4988 for (i = 0; i < mp->rloc_num; i++) {
4989 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
4991 clib_memcpy (&ip_addr_v4(&rloc), &r->addr, sizeof (rloc_t));
4992 ip_addr_version (&rloc) = IP4;
4994 clib_memcpy (&ip_addr_v6(&rloc), &r->addr, sizeof (rloc_t));
4995 ip_addr_version (&rloc) = IP6;
4997 vec_add1 (rlocs, rloc);
5000 rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs, mp->action,
5001 mp->is_add, mp->del_all);
5003 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5007 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
5008 locator_set_t *lsit,
5009 unix_shared_memory_queue_t *q,
5013 vl_api_lisp_locator_set_details_t *rmp;
5014 locator_t *loc = NULL;
5018 vec_foreach (locit, lsit->locator_indices) {
5019 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5020 rmp = vl_msg_api_alloc (sizeof (*rmp));
5021 memset (rmp, 0, sizeof (*rmp));
5022 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
5023 rmp->local = lsit->local;
5025 ASSERT(lsit->name != NULL);
5026 strncpy((char *) rmp->locator_set_name,
5027 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5028 rmp->sw_if_index = htonl(loc->sw_if_index);
5030 str = format(0, "remote-%d", index);
5031 strncpy((char *) rmp->locator_set_name, (char *) str,
5032 ARRAY_LEN(rmp->locator_set_name) - 1);
5033 send_lisp_locator_set_details_set_address(rmp, &loc->address);
5037 rmp->priority = loc->priority;
5038 rmp->weight = loc->weight;
5039 rmp->context = context;
5041 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5046 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
5048 unix_shared_memory_queue_t * q = NULL;
5049 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5050 locator_set_t * lsit = NULL;
5053 q = vl_api_client_index_to_input_queue (mp->client_index);
5059 pool_foreach (lsit, lcm->locator_set_pool,
5061 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5066 send_lisp_local_eid_table_details (mapping_t *mapit,
5067 unix_shared_memory_queue_t *q,
5070 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5071 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5072 locator_set_t *ls = NULL;
5073 gid_address_t *gid = NULL;
5074 ip_prefix_t *ip_prefix = NULL;
5078 ls = pool_elt_at_index (lcm->locator_set_pool,
5079 mapit->locator_set_index);
5082 type = gid_address_type(gid);
5084 if (type != GID_ADDR_IP_PREFIX) {
5088 ip_prefix = &gid_address_ippref(gid);
5090 rmp = vl_msg_api_alloc (sizeof (*rmp));
5091 memset (rmp, 0, sizeof (*rmp));
5092 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5094 ASSERT(ls->name != NULL);
5095 strncpy((char *) rmp->locator_set_name,
5096 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5098 str = format(0, "remote-%d", mapit->locator_set_index);
5099 strncpy((char *) rmp->locator_set_name, (char *) str,
5100 ARRAY_LEN(rmp->locator_set_name) - 1);
5104 switch (ip_prefix_version(ip_prefix)) {
5106 rmp->eid_is_ipv6 = 0;
5107 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5108 sizeof(ip_prefix_v4(ip_prefix)));
5112 rmp->eid_is_ipv6 = 1;
5113 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5114 sizeof(ip_prefix_v6(ip_prefix)));
5120 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5121 rmp->context = context;
5123 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5127 vl_api_lisp_local_eid_table_dump_t_handler (
5128 vl_api_lisp_local_eid_table_dump_t *mp)
5130 unix_shared_memory_queue_t * q = NULL;
5131 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5132 mapping_t * mapit = NULL;
5134 q = vl_api_client_index_to_input_queue (mp->client_index);
5139 pool_foreach (mapit, lcm->mapping_pool,
5141 send_lisp_local_eid_table_details(mapit, q, mp->context);
5146 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5147 unix_shared_memory_queue_t *q,
5150 vl_api_lisp_gpe_tunnel_details_t *rmp;
5151 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5153 rmp = vl_msg_api_alloc (sizeof (*rmp));
5154 memset (rmp, 0, sizeof (*rmp));
5155 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5157 rmp->tunnels = tunnel - lgm->tunnels;
5159 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5160 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5161 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5163 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5164 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5165 rmp->dcap_next = htonl(tunnel->decap_next_index);
5166 rmp->lisp_ver = tunnel->ver_res;
5167 rmp->next_protocol = tunnel->next_protocol;
5168 rmp->flags = tunnel->flags;
5169 rmp->ver_res = tunnel->ver_res;
5170 rmp->res = tunnel->res;
5171 rmp->iid = htonl(tunnel->vni);
5172 rmp->context = context;
5174 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5178 vl_api_lisp_gpe_tunnel_dump_t_handler (
5179 vl_api_lisp_local_eid_table_dump_t *mp)
5181 unix_shared_memory_queue_t * q = NULL;
5182 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5183 lisp_gpe_tunnel_t * tunnel = NULL;
5185 if (pool_elts(lgm->tunnels) == 0) {
5189 q = vl_api_client_index_to_input_queue (mp->client_index);
5194 pool_foreach(tunnel, lgm->tunnels,
5196 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5201 send_lisp_map_resolver_details (ip_address_t *ip,
5202 unix_shared_memory_queue_t *q,
5205 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5207 rmp = vl_msg_api_alloc (sizeof (*rmp));
5208 memset (rmp, 0, sizeof (*rmp));
5209 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5211 switch (ip_addr_version(ip)) {
5214 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5219 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5225 rmp->context = context;
5227 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5231 vl_api_lisp_map_resolver_dump_t_handler (
5232 vl_api_lisp_local_eid_table_dump_t *mp)
5234 unix_shared_memory_queue_t * q = NULL;
5235 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5236 ip_address_t *ip = NULL;
5238 q = vl_api_client_index_to_input_queue (mp->client_index);
5243 vec_foreach(ip, lcm->map_resolvers) {
5244 send_lisp_map_resolver_details(ip, q, mp->context);
5250 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5253 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5255 rmp = vl_msg_api_alloc (sizeof (*rmp));
5256 memset (rmp, 0, sizeof (*rmp));
5257 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5259 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5260 rmp->feature_status = vnet_lisp_enable_disable_status ();
5261 rmp->context = context;
5263 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5267 vl_api_lisp_enable_disable_status_dump_t_handler
5268 (vl_api_lisp_enable_disable_status_dump_t *mp)
5270 unix_shared_memory_queue_t * q = NULL;
5272 q = vl_api_client_index_to_input_queue (mp->client_index);
5277 send_lisp_enable_disable_details(q, mp->context);
5281 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5283 vl_api_interface_name_renumber_reply_t * rmp;
5286 VALIDATE_SW_IF_INDEX(mp);
5288 rv = vnet_interface_name_renumber
5289 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5291 BAD_SW_IF_INDEX_LABEL;
5293 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5296 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5297 u32 sw_if_index, u32 address)
5299 vpe_api_main_t * am = &vpe_api_main;
5300 vlib_main_t * vm = am->vlib_main;
5301 vl_api_ip4_arp_event_t * event;
5302 static f64 arp_event_last_time;
5303 f64 now = vlib_time_now (vm);
5305 if (pool_is_free_index (am->arp_events, pool_index))
5308 event = pool_elt_at_index (am->arp_events, pool_index);
5309 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5310 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5311 } else { /* same mac */
5312 if ((sw_if_index == event->sw_if_index) &&
5314 /* for BD case, also check IP address with 10 sec timeout */
5315 ((address == event->address) &&
5316 ((now - arp_event_last_time) < 10.0))))
5320 arp_event_last_time = now;
5321 event->sw_if_index = sw_if_index;
5322 if (address) event->address = address;
5326 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5328 vpe_api_main_t * am = &vpe_api_main;
5330 if (pool_is_free_index (am->arp_events, pool_index))
5333 pool_put_index (am->arp_events, pool_index);
5338 vl_api_want_ip4_arp_events_t_handler
5339 (vl_api_want_ip4_arp_events_t * mp)
5341 vpe_api_main_t * am = &vpe_api_main;
5342 vnet_main_t * vnm = vnet_get_main();
5343 vl_api_want_ip4_arp_events_reply_t *rmp;
5344 vl_api_ip4_arp_event_t * event;
5347 if (mp->enable_disable) {
5348 pool_get (am->arp_events, event);
5349 memset (event, 0, sizeof (*event));
5351 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5352 event->client_index = mp->client_index;
5353 event->context = mp->context;
5354 event->address = mp->address;
5355 event->pid = mp->pid;
5357 rv = vnet_add_del_ip4_arp_change_event
5358 (vnm, arp_change_data_callback,
5360 &mp->address /* addr, in net byte order */,
5361 vpe_resolver_process_node.index,
5362 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5364 rv = vnet_add_del_ip4_arp_change_event
5365 (vnm, arp_change_delete_callback,
5367 &mp->address /* addr, in net byte order */,
5368 vpe_resolver_process_node.index,
5369 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5371 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5374 static void vl_api_input_acl_set_interface_t_handler
5375 (vl_api_input_acl_set_interface_t * mp)
5377 vlib_main_t *vm = vlib_get_main();
5378 vl_api_input_acl_set_interface_reply_t * rmp;
5380 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5382 ip4_table_index = ntohl(mp->ip4_table_index);
5383 ip6_table_index = ntohl(mp->ip6_table_index);
5384 l2_table_index = ntohl(mp->l2_table_index);
5385 sw_if_index = ntohl(mp->sw_if_index);
5387 VALIDATE_SW_IF_INDEX(mp);
5389 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5390 ip6_table_index, l2_table_index,
5393 BAD_SW_IF_INDEX_LABEL;
5395 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5398 static void vl_api_ipsec_spd_add_del_t_handler
5399 (vl_api_ipsec_spd_add_del_t * mp)
5402 clib_warning ("unimplemented");
5405 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5406 vl_api_ipsec_spd_add_del_reply_t * rmp;
5410 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5412 rv = VNET_API_ERROR_UNIMPLEMENTED;
5415 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5419 static void vl_api_ipsec_interface_add_del_spd_t_handler
5420 (vl_api_ipsec_interface_add_del_spd_t * mp)
5422 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5423 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5425 u32 sw_if_index __attribute__((unused));
5426 u32 spd_id __attribute__((unused));
5428 sw_if_index = ntohl(mp->sw_if_index);
5429 spd_id = ntohl(mp->spd_id);
5431 VALIDATE_SW_IF_INDEX(mp);
5434 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5436 rv = VNET_API_ERROR_UNIMPLEMENTED;
5439 BAD_SW_IF_INDEX_LABEL;
5441 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5444 static void vl_api_ipsec_spd_add_del_entry_t_handler
5445 (vl_api_ipsec_spd_add_del_entry_t * mp)
5447 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5448 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5454 memset(&p, 0, sizeof(p));
5456 p.id = ntohl(mp->spd_id);
5457 p.priority = ntohl(mp->priority);
5458 p.is_outbound = mp->is_outbound;
5459 p.is_ipv6 = mp->is_ipv6;
5461 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5462 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5463 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5464 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5466 p.protocol = mp->protocol;
5467 p.rport.start = ntohs(mp->remote_port_start);
5468 p.rport.stop = ntohs(mp->remote_port_stop);
5469 p.lport.start = ntohs(mp->local_port_start);
5470 p.lport.stop = ntohs(mp->local_port_stop);
5471 /* policy action resolve unsupported */
5472 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5473 clib_warning("unsupported action: 'resolve'");
5474 rv = VNET_API_ERROR_UNIMPLEMENTED;
5477 p.policy = mp->policy;
5478 p.sa_id = ntohl(mp->sa_id);
5480 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5484 if (mp->is_ip_any) {
5486 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5489 rv = VNET_API_ERROR_UNIMPLEMENTED;
5494 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5497 static void vl_api_ipsec_sad_add_del_entry_t_handler
5498 (vl_api_ipsec_sad_add_del_entry_t * mp)
5500 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5501 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5506 memset(&sa, 0, sizeof(sa));
5508 sa.id = ntohl(mp->sad_id);
5509 sa.spi = ntohl(mp->spi);
5510 /* security protocol AH unsupported */
5511 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5512 clib_warning("unsupported security protocol 'AH'");
5513 rv = VNET_API_ERROR_UNIMPLEMENTED;
5516 sa.protocol = mp->protocol;
5517 /* check for unsupported crypto-alg */
5518 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5519 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5520 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5521 mp->crypto_algorithm);
5522 rv = VNET_API_ERROR_UNIMPLEMENTED;
5525 sa.crypto_alg = mp->crypto_algorithm;
5526 sa.crypto_key_len = mp->crypto_key_length;
5527 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5528 /* check for unsupported integ-alg */
5529 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5530 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5531 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5532 mp->integrity_algorithm);
5533 rv = VNET_API_ERROR_UNIMPLEMENTED;
5536 sa.integ_alg = mp->integrity_algorithm;
5537 sa.integ_key_len = mp->integrity_key_length;
5538 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5539 sa.use_esn = mp->use_extended_sequence_number;
5540 sa.is_tunnel = mp->is_tunnel;
5541 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5542 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5543 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5545 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5547 rv = VNET_API_ERROR_UNIMPLEMENTED;
5552 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5556 vl_api_ikev2_profile_add_del_t_handler
5557 (vl_api_ikev2_profile_add_del_t * mp)
5559 vl_api_ikev2_profile_add_del_reply_t * rmp;
5563 vlib_main_t * vm = vlib_get_main();
5564 clib_error_t * error;
5565 u8 * tmp = format(0, "%s", mp->name);
5566 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5569 rv = VNET_API_ERROR_UNSPECIFIED;
5571 rv = VNET_API_ERROR_UNIMPLEMENTED;
5574 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5578 vl_api_ikev2_profile_set_auth_t_handler
5579 (vl_api_ikev2_profile_set_auth_t * mp)
5581 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5585 vlib_main_t * vm = vlib_get_main();
5586 clib_error_t * error;
5587 u8 * tmp = format(0, "%s", mp->name);
5588 u8 * data = vec_new (u8, mp->data_len);
5589 clib_memcpy(data, mp->data, mp->data_len);
5590 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5594 rv = VNET_API_ERROR_UNSPECIFIED;
5596 rv = VNET_API_ERROR_UNIMPLEMENTED;
5599 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5603 vl_api_ikev2_profile_set_id_t_handler
5604 (vl_api_ikev2_profile_set_id_t * mp)
5606 vl_api_ikev2_profile_add_del_reply_t * rmp;
5610 vlib_main_t * vm = vlib_get_main();
5611 clib_error_t * error;
5612 u8 * tmp = format(0, "%s", mp->name);
5613 u8 * data = vec_new (u8, mp->data_len);
5614 clib_memcpy(data, mp->data, mp->data_len);
5615 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5619 rv = VNET_API_ERROR_UNSPECIFIED;
5621 rv = VNET_API_ERROR_UNIMPLEMENTED;
5624 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5628 vl_api_ikev2_profile_set_ts_t_handler
5629 (vl_api_ikev2_profile_set_ts_t * mp)
5631 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5635 vlib_main_t * vm = vlib_get_main();
5636 clib_error_t * error;
5637 u8 * tmp = format(0, "%s", mp->name);
5638 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5639 mp->end_port, (ip4_address_t) mp->start_addr,
5640 (ip4_address_t) mp->end_addr, mp->is_local);
5643 rv = VNET_API_ERROR_UNSPECIFIED;
5645 rv = VNET_API_ERROR_UNIMPLEMENTED;
5648 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5652 vl_api_ikev2_set_local_key_t_handler
5653 (vl_api_ikev2_set_local_key_t * mp)
5655 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5659 vlib_main_t * vm = vlib_get_main();
5660 clib_error_t * error;
5662 error = ikev2_set_local_key(vm, mp->key_file);
5664 rv = VNET_API_ERROR_UNSPECIFIED;
5666 rv = VNET_API_ERROR_UNIMPLEMENTED;
5669 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5673 vl_api_map_add_domain_t_handler
5674 (vl_api_map_add_domain_t * mp)
5676 vl_api_map_add_domain_reply_t * rmp;
5679 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5680 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5681 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5682 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5683 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5685 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5687 rmp->index = ntohl(index);
5692 vl_api_map_del_domain_t_handler
5693 (vl_api_map_del_domain_t * mp)
5695 vl_api_map_del_domain_reply_t * rmp;
5698 rv = map_delete_domain(ntohl(mp->index));
5700 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5704 vl_api_map_add_del_rule_t_handler
5705 (vl_api_map_add_del_rule_t * mp)
5707 vl_api_map_del_domain_reply_t * rmp;
5710 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5712 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5716 vl_api_map_domain_dump_t_handler
5717 (vl_api_map_domain_dump_t * mp)
5719 vl_api_map_domain_details_t * rmp;
5720 map_main_t *mm = &map_main;
5722 unix_shared_memory_queue_t * q;
5724 if (pool_elts (mm->domains) == 0)
5727 q = vl_api_client_index_to_input_queue (mp->client_index);
5732 pool_foreach(d, mm->domains, ({
5733 /* Make sure every field is initiated (or don't skip the memset()) */
5734 rmp = vl_msg_api_alloc (sizeof (*rmp));
5735 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5736 rmp->domain_index = htonl(d - mm->domains);
5737 rmp->ea_bits_len = d->ea_bits_len;
5738 rmp->psid_offset = d->psid_offset;
5739 rmp->psid_length = d->psid_length;
5740 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5741 rmp->ip4_prefix_len = d->ip4_prefix_len;
5742 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5743 rmp->ip6_prefix_len = d->ip6_prefix_len;
5744 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5745 rmp->ip6_src_len = d->ip6_src_len;
5746 rmp->mtu = htons(d->mtu);
5747 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5748 rmp->context = mp->context;
5750 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5755 vl_api_map_rule_dump_t_handler
5756 (vl_api_map_rule_dump_t * mp)
5758 unix_shared_memory_queue_t * q;
5761 vl_api_map_rule_details_t * rmp;
5762 map_main_t *mm = &map_main;
5763 u32 domain_index = ntohl(mp->domain_index);
5766 if (pool_elts (mm->domains) == 0)
5769 d = pool_elt_at_index(mm->domains, domain_index);
5770 if (!d || !d->rules) {
5774 q = vl_api_client_index_to_input_queue (mp->client_index);
5779 for (i = 0; i < (0x1 << d->psid_length); i++) {
5781 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5784 rmp = vl_msg_api_alloc(sizeof(*rmp));
5785 memset(rmp, 0, sizeof(*rmp));
5786 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5787 rmp->psid = htons(i);
5788 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5789 rmp->context = mp->context;
5790 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5795 vl_api_map_summary_stats_t_handler (
5796 vl_api_map_summary_stats_t *mp)
5798 vl_api_map_summary_stats_reply_t *rmp;
5799 vlib_combined_counter_main_t *cm;
5802 u64 total_pkts[VLIB_N_RX_TX];
5803 u64 total_bytes[VLIB_N_RX_TX];
5804 map_main_t *mm = &map_main;
5805 unix_shared_memory_queue_t *q =
5806 vl_api_client_index_to_input_queue(mp->client_index);
5811 rmp = vl_msg_api_alloc (sizeof (*rmp));
5812 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5813 rmp->context = mp->context;
5816 memset (total_pkts, 0, sizeof (total_pkts));
5817 memset (total_bytes, 0, sizeof (total_bytes));
5819 map_domain_counter_lock (mm);
5820 vec_foreach(cm, mm->domain_counters) {
5821 which = cm - mm->domain_counters;
5823 for (i = 0; i < vec_len(cm->maxi); i++) {
5824 vlib_get_combined_counter (cm, i, &v);
5825 total_pkts[which] += v.packets;
5826 total_bytes[which] += v.bytes;
5830 map_domain_counter_unlock (mm);
5832 /* Note: in network byte order! */
5833 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5834 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5835 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5836 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5837 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5838 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5839 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));
5840 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));
5842 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5845 static void vl_api_ipsec_sa_set_key_t_handler
5846 (vl_api_ipsec_sa_set_key_t * mp)
5848 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5849 vl_api_ipsec_sa_set_key_reply_t *rmp;
5853 sa.id = ntohl(mp->sa_id);
5854 sa.crypto_key_len = mp->crypto_key_length;
5855 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5856 sa.integ_key_len = mp->integrity_key_length;
5857 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5859 rv = ipsec_set_sa_key(vm, &sa);
5861 rv = VNET_API_ERROR_UNIMPLEMENTED;
5864 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5867 static void vl_api_cop_interface_enable_disable_t_handler
5868 (vl_api_cop_interface_enable_disable_t * mp)
5870 vl_api_cop_interface_enable_disable_reply_t * rmp;
5872 u32 sw_if_index = ntohl(mp->sw_if_index);
5875 VALIDATE_SW_IF_INDEX(mp);
5877 enable_disable = (int) mp->enable_disable;
5879 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5881 BAD_SW_IF_INDEX_LABEL;
5883 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5886 static void vl_api_cop_whitelist_enable_disable_t_handler
5887 (vl_api_cop_whitelist_enable_disable_t * mp)
5889 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5890 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5891 u32 sw_if_index = ntohl(mp->sw_if_index);
5894 VALIDATE_SW_IF_INDEX(mp);
5896 a->sw_if_index = sw_if_index;
5899 a->default_cop = mp->default_cop;
5900 a->fib_id = ntohl(mp->fib_id);
5902 rv = cop_whitelist_enable_disable (a);
5904 BAD_SW_IF_INDEX_LABEL;
5906 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5909 static void vl_api_get_node_graph_t_handler
5910 (vl_api_get_node_graph_t * mp)
5914 api_main_t * am = &api_main;
5915 vlib_main_t * vm = vlib_get_main();
5917 vl_api_get_node_graph_reply_t * rmp;
5919 pthread_mutex_lock (&am->vlib_rp->mutex);
5920 oldheap = svm_push_data_heap (am->vlib_rp);
5923 * Keep the number of memcpy ops to a minimum (e.g. 1).
5925 vec_validate (vector, 16384);
5926 vec_reset_length (vector);
5929 vector = vlib_node_serialize (&vm->node_main, vector,
5930 (u32)~0 /* all threads */,
5931 1 /* include nexts */,
5932 1 /* include stats */);
5934 svm_pop_heap (oldheap);
5935 pthread_mutex_unlock (&am->vlib_rp->mutex);
5937 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5938 rmp->reply_in_shmem = (uword) vector);
5941 static void vl_api_trace_profile_add_t_handler
5942 (vl_api_trace_profile_add_t *mp)
5945 vl_api_trace_profile_add_reply_t * rmp;
5946 clib_error_t *error;
5948 /* Ignoring the profile id as currently a single profile
5950 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5951 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5952 mp->pow_enable, mp->trace_tsp,
5955 clib_error_report(error);
5956 rv = clib_error_get_code(error);
5959 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5962 static void vl_api_trace_profile_apply_t_handler
5963 (vl_api_trace_profile_apply_t *mp)
5966 vl_api_trace_profile_apply_reply_t * rmp;
5968 if (mp->enable != 0) {
5969 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5970 ntohl(mp->prefix_length),
5972 mp->trace_op == IOAM_HBYH_ADD,
5973 mp->trace_op == IOAM_HBYH_POP,
5974 mp->trace_op == IOAM_HBYH_MOD);
5976 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5978 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5981 static void vl_api_trace_profile_del_t_handler
5982 (vl_api_trace_profile_del_t *mp)
5985 vl_api_trace_profile_del_reply_t * rmp;
5986 clib_error_t *error;
5988 error = clear_ioam_rewrite_fn();
5990 clib_error_report(error);
5991 rv = clib_error_get_code(error);
5994 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5998 vl_api_af_packet_create_t_handler
5999 (vl_api_af_packet_create_t *mp)
6001 vlib_main_t *vm = vlib_get_main();
6002 vl_api_af_packet_create_reply_t *rmp;
6004 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, 0);
6012 vec_free(host_if_name);
6014 REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
6018 vl_api_af_packet_delete_t_handler
6019 (vl_api_af_packet_delete_t *mp)
6021 vlib_main_t * vm = vlib_get_main();
6022 vl_api_af_packet_delete_reply_t *rmp;
6024 u8 *host_if_name = NULL;
6026 host_if_name = format(0, "%s", mp->host_if_name);
6027 vec_add1 (host_if_name, 0);
6029 rv = af_packet_delete_if(vm, host_if_name);
6031 vec_free(host_if_name);
6033 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
6037 vl_api_policer_add_del_t_handler
6038 (vl_api_policer_add_del_t *mp)
6040 vlib_main_t * vm = vlib_get_main();
6041 vl_api_policer_add_del_reply_t *rmp;
6044 sse2_qos_pol_cfg_params_st cfg;
6045 clib_error_t * error;
6047 name = format(0, "%s", mp->name);
6049 memset (&cfg, 0, sizeof (cfg));
6051 cfg.rnd_type = mp->round_type;
6052 cfg.rate_type = mp->rate_type;
6053 cfg.rb.kbps.cir_kbps = mp->cir;
6054 cfg.rb.kbps.eir_kbps = mp->eir;
6055 cfg.rb.kbps.cb_bytes = mp->cb;
6056 cfg.rb.kbps.eb_bytes = mp->eb;
6058 error = policer_add_del(vm, name, &cfg, mp->is_add);
6061 rv = VNET_API_ERROR_UNSPECIFIED;
6063 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
6067 send_policer_details (u8 *name,
6068 sse2_qos_pol_cfg_params_st *config,
6069 policer_read_response_type_st *templ,
6070 unix_shared_memory_queue_t *q,
6073 vl_api_policer_details_t * mp;
6075 mp = vl_msg_api_alloc (sizeof (*mp));
6076 memset (mp, 0, sizeof (*mp));
6077 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6078 mp->context = context;
6079 mp->cir = htonl(config->rb.kbps.cir_kbps);
6080 mp->eir = htonl(config->rb.kbps.eir_kbps);
6081 mp->cb = htonl(config->rb.kbps.cb_bytes);
6082 mp->eb = htonl(config->rb.kbps.eb_bytes);
6083 mp->rate_type = config->rate_type;
6084 mp->round_type = config->rnd_type;
6085 mp->type = config->rfc;
6086 mp->single_rate = templ->single_rate ? 1 : 0;
6087 mp->color_aware = templ->color_aware ? 1 : 0;
6088 mp->scale = htonl(templ->scale);
6089 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6090 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6091 mp->current_limit = htonl(templ->current_limit);
6092 mp->current_bucket = htonl(templ->current_bucket);
6093 mp->extended_limit = htonl(templ->extended_limit);
6094 mp->extended_bucket = htonl(templ->extended_bucket);
6095 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6097 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6099 vl_msg_api_send_shmem (q, (u8 *)&mp);
6103 vl_api_policer_dump_t_handler
6104 (vl_api_policer_dump_t *mp)
6106 unix_shared_memory_queue_t * q;
6107 vnet_policer_main_t * pm = &vnet_policer_main;
6111 u8 * match_name = 0;
6113 sse2_qos_pol_cfg_params_st *config;
6114 policer_read_response_type_st *templ;
6116 q = vl_api_client_index_to_input_queue (mp->client_index);
6120 if (mp->match_name_valid) {
6121 match_name = format(0, "%s%c", mp->match_name, 0);
6124 if (mp->match_name_valid) {
6125 p = hash_get_mem (pm->policer_config_by_name, match_name);
6128 config = pool_elt_at_index (pm->configs, pool_index);
6129 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6130 send_policer_details(match_name, config, templ, q, mp->context);
6133 hash_foreach_pair (hp, pm->policer_config_by_name,
6135 name = (u8 *) hp->key;
6136 pool_index = hp->value[0];
6137 config = pool_elt_at_index (pm->configs, pool_index);
6138 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6139 send_policer_details(name, config, templ, q, mp->context);
6145 vl_api_netmap_create_t_handler
6146 (vl_api_netmap_create_t *mp)
6148 vlib_main_t *vm = vlib_get_main();
6149 vl_api_netmap_create_reply_t *rmp;
6153 if_name = format(0, "%s", mp->netmap_if_name);
6154 vec_add1 (if_name, 0);
6156 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6157 mp->is_pipe, mp->is_master, 0);
6161 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6165 vl_api_netmap_delete_t_handler
6166 (vl_api_netmap_delete_t *mp)
6168 vlib_main_t * vm = vlib_get_main();
6169 vl_api_netmap_delete_reply_t *rmp;
6173 if_name = format(0, "%s", mp->netmap_if_name);
6174 vec_add1 (if_name, 0);
6176 rv = netmap_delete_if(vm, if_name);
6180 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6183 #define BOUNCE_HANDLER(nn) \
6184 static void vl_api_##nn##_t_handler ( \
6185 vl_api_##nn##_t *mp) \
6187 vpe_client_registration_t *reg; \
6188 vpe_api_main_t * vam = &vpe_api_main; \
6189 unix_shared_memory_queue_t * q; \
6191 /* One registration only... */ \
6192 pool_foreach(reg, vam->nn##_registrations, \
6194 q = vl_api_client_index_to_input_queue (reg->client_index); \
6197 * If the queue is stuffed, turf the msg and complain \
6198 * It's unlikely that the intended recipient is \
6199 * alive; avoid deadlock at all costs. \
6201 if (q->cursize == q->maxsize) { \
6202 clib_warning ("ERROR: receiver queue full, drop msg"); \
6203 vl_msg_api_free (mp); \
6206 vl_msg_api_send_shmem (q, (u8 *)&mp); \
6210 vl_msg_api_free (mp); \
6215 * Add vpe's API message handlers to the table.
6216 * vlib has alread mapped shared memory and
6217 * added the client registration handlers.
6218 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
6221 static clib_error_t *
6222 vpe_api_hookup (vlib_main_t *vm)
6224 api_main_t * am = &api_main;
6227 vl_msg_api_set_handlers(VL_API_##N, #n, \
6228 vl_api_##n##_t_handler, \
6230 vl_api_##n##_t_endian, \
6231 vl_api_##n##_t_print, \
6232 sizeof(vl_api_##n##_t), 1);
6233 foreach_vpe_api_msg;
6237 * Manually register the sr tunnel add del msg, so we trace
6238 * enough bytes to capture a typical segment list
6240 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6241 "sr_tunnel_add_del",
6242 vl_api_sr_tunnel_add_del_t_handler,
6244 vl_api_sr_tunnel_add_del_t_endian,
6245 vl_api_sr_tunnel_add_del_t_print,
6250 * Manually register the sr policy add del msg, so we trace
6251 * enough bytes to capture a typical tunnel name list
6253 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6254 "sr_policy_add_del",
6255 vl_api_sr_policy_add_del_t_handler,
6257 vl_api_sr_policy_add_del_t_endian,
6258 vl_api_sr_policy_add_del_t_print,
6262 * Trace space for 8 MPLS encap labels, classifier mask+match
6264 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6265 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6266 += 5 * sizeof (u32x4);
6267 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6268 += 5 * sizeof (u32x4);
6269 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6270 += 16 * sizeof (u32);
6273 * Thread-safe API messages
6275 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6276 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
6281 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6283 static clib_error_t *
6284 vpe_api_init (vlib_main_t *vm)
6286 vpe_api_main_t *am = &vpe_api_main;
6289 am->vnet_main = vnet_get_main();
6290 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6291 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6292 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6293 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6294 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6295 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6298 vl_set_memory_region_name ("/vpe-api");
6299 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6304 VLIB_INIT_FUNCTION(vpe_api_init);
6307 static clib_error_t *
6308 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
6313 struct passwd _pw, *pw;
6314 struct group _grp, *grp;
6317 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6319 if (unformat (input, "prefix %s", &chroot_path))
6321 vec_add1 (chroot_path, 0);
6322 vl_set_memory_root_path ((char *)chroot_path);
6324 else if (unformat (input, "uid %d", &uid))
6325 vl_set_memory_uid (uid);
6326 else if (unformat (input, "gid %d", &gid))
6327 vl_set_memory_gid (gid);
6328 else if (unformat (input, "uid %s", &s))
6330 /* lookup the username */
6332 rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
6335 e = clib_error_return_code(0, rv,
6336 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
6337 "cannot fetch username %s", s);
6343 e = clib_error_return_fatal(0, "username %s does not exist", s);
6348 vl_set_memory_uid (pw->pw_uid);
6350 else if (unformat (input, "gid %s", &s))
6352 /* lookup the group name */
6354 rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
6357 e = clib_error_return_code(0, rv,
6358 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
6359 "cannot fetch group %s", s);
6365 e = clib_error_return_fatal(0, "group %s does not exist", s);
6370 vl_set_memory_gid (grp->gr_gid);
6373 return clib_error_return (0, "unknown input `%U'",
6374 format_unformat_error, input);
6378 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
6380 void * get_unformat_vnet_sw_interface (void)
6382 return (void *) &unformat_vnet_sw_interface;
6385 #undef vl_api_version
6386 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6387 #include <api/vpe.api.h>
6388 #undef vl_api_version
6390 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6392 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6393 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6394 clib_host_to_net_u32 (mp->api_versions[0]),
6401 static u8 * format_arp_event (u8 * s, va_list * args)
6403 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6405 s = format (s, "pid %d: %U", event->pid,
6406 format_ip4_address, &event->address);
6410 static clib_error_t *
6411 show_ip4_arp_events_fn (vlib_main_t * vm,
6412 unformat_input_t * input,
6413 vlib_cli_command_t * cmd)
6415 vpe_api_main_t * am = &vpe_api_main;
6416 vl_api_ip4_arp_event_t * event;
6418 if (pool_elts (am->arp_events) == 0) {
6419 vlib_cli_output (vm, "No active arp event registrations");
6423 pool_foreach (event, am->arp_events,
6425 vlib_cli_output (vm, "%U", format_arp_event, event);
6431 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6432 .path = "show arp event registrations",
6433 .function = show_ip4_arp_events_fn,
6434 .short_help = "Show arp event registrations",