2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
33 #include <vppinfra/clib.h>
34 #include <vppinfra/vec.h>
35 #include <vppinfra/hash.h>
36 #include <vppinfra/bitmap.h>
37 #include <vppinfra/fifo.h>
38 #include <vppinfra/time.h>
39 #include <vppinfra/mheap.h>
40 #include <vppinfra/heap.h>
41 #include <vppinfra/pool.h>
42 #include <vppinfra/format.h>
43 #include <vppinfra/error.h>
45 #include <vnet/api_errno.h> // alagalah TODO : committers please pay note, is this ok?
46 #include <vnet/vnet.h>
47 #include <vnet/l2/l2_input.h>
48 #include <vnet/l2/l2_bd.h>
49 #include <vnet/l2tp/l2tp.h>
50 #include <vnet/ip/ip.h>
51 #include <vnet/unix/tuntap.h>
52 #include <vnet/unix/tapcli.h>
53 #include <vnet/mpls-gre/mpls.h>
54 #include <vnet/dhcp/proxy.h>
55 #include <vnet/dhcp/client.h>
57 #include <vnet/sr/sr.h>
59 #include <vnet/dhcpv6/proxy.h>
60 #include <vlib/vlib.h>
61 #include <vlib/unix/unix.h>
62 #include <vlibapi/api.h>
63 #include <vlibmemory/api.h>
64 #include <vnet/classify/vnet_classify.h>
65 #include <vnet/classify/input_acl.h>
66 #include <vnet/l2/l2_classify.h>
67 #include <vnet/vxlan/vxlan.h>
68 #include <vnet/gre/gre.h>
69 #include <vnet/l2/l2_vtr.h>
70 #include <vnet/vxlan-gpe/vxlan_gpe.h>
71 #include <vnet/lisp-gpe/lisp_gpe.h>
72 #include <vnet/lisp-cp/control.h>
73 #include <vnet/map/map.h>
74 #include <vnet/cop/cop.h>
75 #include <vnet/ip/ip6_hop_by_hop.h>
76 #include <vnet/devices/af_packet/af_packet.h>
77 #include <vnet/policer/policer.h>
78 #include <vnet/devices/netmap/netmap.h>
81 #undef __included_bihash_template_h__
82 #include <vnet/l2/l2_fib.h>
85 #include <vnet/ipsec/ipsec.h>
86 #include <vnet/ipsec/ikev2.h>
89 #include <vnet/devices/virtio/vhost-user.h>
92 #include <stats/stats.h>
95 #include <vnet/ethernet/ethernet.h>
96 #include <vnet/ethernet/arp_packet.h>
97 #include <vnet/interface.h>
99 #include <vnet/l2/l2_fib.h>
100 #include <vnet/l2/l2_bd.h>
101 #include <api/vpe_msg_enum.h>
103 #define f64_endian(a)
104 #define f64_print(a,b)
106 #define vl_typedefs /* define message structures */
107 #include <api/vpe_all_api_h.h>
110 #define vl_endianfun /* define message structures */
111 #include <api/vpe_all_api_h.h>
114 /* instantiate all the print functions we know about */
115 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
117 #include <api/vpe_all_api_h.h>
120 #define REPLY_MACRO(t) \
122 unix_shared_memory_queue_t * q; \
123 rv = vl_msg_api_pd_handler (mp, rv); \
124 q = vl_api_client_index_to_input_queue (mp->client_index); \
128 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
129 rmp->_vl_msg_id = ntohs((t)); \
130 rmp->context = mp->context; \
131 rmp->retval = ntohl(rv); \
133 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
136 #define REPLY_MACRO2(t, body) \
138 unix_shared_memory_queue_t * q; \
139 rv = vl_msg_api_pd_handler (mp, rv); \
140 q = vl_api_client_index_to_input_queue (mp->client_index); \
144 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
145 rmp->_vl_msg_id = ntohs((t)); \
146 rmp->context = mp->context; \
147 rmp->retval = ntohl(rv); \
148 do {body;} while (0); \
149 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
152 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
154 #define VALIDATE_SW_IF_INDEX(mp) \
155 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
156 vnet_main_t *__vnm = vnet_get_main(); \
157 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
159 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
160 goto bad_sw_if_index; \
164 #define BAD_SW_IF_INDEX_LABEL \
170 #define VALIDATE_RX_SW_IF_INDEX(mp) \
171 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
172 vnet_main_t *__vnm = vnet_get_main(); \
173 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
174 __rx_sw_if_index)) { \
175 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
176 goto bad_rx_sw_if_index; \
180 #define BAD_RX_SW_IF_INDEX_LABEL \
182 bad_rx_sw_if_index: \
186 #define VALIDATE_TX_SW_IF_INDEX(mp) \
187 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
188 vnet_main_t *__vnm = vnet_get_main(); \
189 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
190 __tx_sw_if_index)) { \
191 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
192 goto bad_tx_sw_if_index; \
196 #define BAD_TX_SW_IF_INDEX_LABEL \
198 bad_tx_sw_if_index: \
204 #define VALIDATE_SW_IF_INDEX(mp)
205 #define BAD_SW_IF_INDEX_LABEL
206 #define VALIDATE_RX_SW_IF_INDEX(mp)
207 #define BAD_RX_SW_IF_INDEX_LABEL
208 #define VALIDATE_TX_SW_IF_INDEX(mp)
209 #define BAD_TX_SW_IF_INDEX_LABEL
211 #endif /* CLIB_DEBUG > 0 */
213 #define foreach_vpe_api_msg \
214 _(WANT_INTERFACE_EVENTS, want_interface_events) \
215 _(WANT_OAM_EVENTS, want_oam_events) \
216 _(OAM_ADD_DEL, oam_add_del) \
217 _(SW_INTERFACE_DUMP, sw_interface_dump) \
218 _(SW_INTERFACE_DETAILS, sw_interface_details) \
219 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
220 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
221 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
222 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
223 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
224 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
225 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
226 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
227 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
228 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
229 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
230 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
231 _(L2FIB_ADD_DEL, l2fib_add_del) \
232 _(L2_FLAGS, l2_flags) \
233 _(BRIDGE_FLAGS, bridge_flags) \
234 _(TAP_CONNECT, tap_connect) \
235 _(TAP_MODIFY, tap_modify) \
236 _(TAP_DELETE, tap_delete) \
237 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
238 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
239 _(CREATE_SUBIF, create_subif) \
240 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
241 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
242 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
243 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
244 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
245 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
246 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
247 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
248 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
249 _(RESET_FIB, reset_fib) \
250 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
251 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
252 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
253 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
254 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
255 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
256 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
257 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
258 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
259 sw_interface_ip6_set_link_local_address) \
260 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
261 _(CREATE_LOOPBACK, create_loopback) \
262 _(CONTROL_PING, control_ping) \
263 _(CLI_REQUEST, cli_request) \
264 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
265 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
266 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
267 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
268 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
269 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
270 _(GET_NODE_INDEX, get_node_index) \
271 _(ADD_NODE_NEXT, add_node_next) \
272 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
273 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
274 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
275 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
276 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
277 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
278 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
279 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
280 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
281 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
282 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
283 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
284 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
285 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
286 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
287 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
288 _(IP_ADDRESS_DUMP, ip_address_dump) \
289 _(IP_DUMP, ip_dump) \
290 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
291 _(SHOW_VERSION, show_version) \
292 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
293 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
294 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
295 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
296 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
297 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
298 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
299 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
300 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
301 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
302 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
303 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
304 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
305 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
306 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
307 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
308 _(DELETE_LOOPBACK, delete_loopback) \
309 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
310 _(MAP_ADD_DOMAIN, map_add_domain) \
311 _(MAP_DEL_DOMAIN, map_del_domain) \
312 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
313 _(MAP_DOMAIN_DUMP, map_domain_dump) \
314 _(MAP_RULE_DUMP, map_rule_dump) \
315 _(MAP_SUMMARY_STATS, map_summary_stats) \
316 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
317 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
318 _(GET_NODE_GRAPH, get_node_graph) \
319 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
320 _(TRACE_PROFILE_ADD, trace_profile_add) \
321 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
322 _(TRACE_PROFILE_DEL, trace_profile_del) \
323 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
324 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
325 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
326 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
327 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
328 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
329 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
330 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
331 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
332 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
333 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
334 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
335 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
336 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
337 lisp_enable_disable_status_dump) \
338 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
339 _(AF_PACKET_CREATE, af_packet_create) \
340 _(AF_PACKET_DELETE, af_packet_delete) \
341 _(POLICER_ADD_DEL, policer_add_del) \
342 _(NETMAP_CREATE, netmap_create) \
343 _(NETMAP_DELETE, netmap_delete)
346 #define QUOTE(x) QUOTE_(x)
348 #define foreach_registration_hash \
349 _(interface_events) \
350 _(to_netconf_server) \
351 _(from_netconf_server) \
352 _(to_netconf_client) \
353 _(from_netconf_client) \
357 RESOLVE_IP4_ADD_DEL_ROUTE=1,
358 RESOLVE_IP6_ADD_DEL_ROUTE,
359 RESOLVE_MPLS_ETHERNET_ADD_DEL,
365 vl_api_ip_add_del_route_t r;
366 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
372 #define _(a) uword *a##_registration_hash; \
373 vpe_client_registration_t * a##_registrations;
374 foreach_registration_hash
377 /* notifications happen really early in the game */
378 u8 link_state_process_up;
380 /* ip4 pending route adds */
381 pending_route_t * pending_routes;
383 /* ip4 arp event registration pool */
384 vl_api_ip4_arp_event_t * arp_events;
387 vlib_main_t * vlib_main;
388 vnet_main_t * vnet_main;
391 static vlib_node_registration_t vpe_resolver_process_node;
392 static vpe_api_main_t vpe_api_main;
394 static void send_sw_interface_flags (vpe_api_main_t * am,
395 unix_shared_memory_queue_t *q,
396 vnet_sw_interface_t * swif);
397 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
398 unix_shared_memory_queue_t *q,
401 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
404 /* Clean up all registrations belonging to the indicated client */
405 int vl_api_memclnt_delete_callback (u32 client_index)
407 vpe_api_main_t * vam = &vpe_api_main;
408 vpe_client_registration_t *rp;
410 int stats_memclnt_delete_callback (u32 client_index);
412 stats_memclnt_delete_callback (client_index);
415 p = hash_get (vam->a##_registration_hash, client_index); \
417 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
418 pool_put (vam->a##_registrations, rp); \
419 hash_unset (vam->a##_registration_hash, client_index); \
421 foreach_registration_hash;
426 #define API_LINK_STATE_EVENT 1
427 #define API_ADMIN_UP_DOWN_EVENT 2
430 event_data_cmp (void * a1, void * a2)
435 return (word) e1[0] - (word) e2[0];
439 link_state_process (vlib_main_t * vm,
440 vlib_node_runtime_t * rt,
443 vpe_api_main_t * vam = &vpe_api_main;
444 vnet_main_t * vnm = vam->vnet_main;
445 vnet_sw_interface_t * swif;
446 uword * event_data = 0;
447 vpe_client_registration_t *reg;
449 u32 prev_sw_if_index;
450 unix_shared_memory_queue_t * q;
452 vam->link_state_process_up = 1;
455 vlib_process_wait_for_event (vm);
457 /* Unified list of changed link or admin state sw_if_indices */
458 vlib_process_get_events_with_type
459 (vm, &event_data, API_LINK_STATE_EVENT);
460 vlib_process_get_events_with_type
461 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
463 /* Sort, so we can eliminate duplicates */
464 vec_sort_with_function (event_data, event_data_cmp);
466 prev_sw_if_index = ~0;
468 for (i = 0; i < vec_len(event_data); i++) {
469 /* Only one message per swif */
470 if (prev_sw_if_index == event_data[i])
472 prev_sw_if_index = event_data[i];
474 pool_foreach(reg, vam->interface_events_registrations,
476 q = vl_api_client_index_to_input_queue (reg->client_index);
478 // sw_interface may be deleted already
479 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
482 swif = vnet_get_sw_interface (vnm, event_data[i]);
483 send_sw_interface_flags (vam, q, swif);
488 vec_reset_length (event_data);
494 static clib_error_t *
495 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
496 static clib_error_t *
497 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
499 VLIB_REGISTER_NODE (link_state_process_node,static) = {
500 .function = link_state_process,
501 .type = VLIB_NODE_TYPE_PROCESS,
502 .name = "vpe-link-state-process",
505 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
506 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
508 static clib_error_t *
509 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
511 vpe_api_main_t * vam = &vpe_api_main;
512 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
514 if (vam->link_state_process_up)
515 vlib_process_signal_event (vam->vlib_main,
516 link_state_process_node.index,
517 API_LINK_STATE_EVENT,
522 static clib_error_t *
523 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
525 vpe_api_main_t * vam = &vpe_api_main;
528 * Note: it's perfectly fair to set a subif admin up / admin down.
529 * Note the subtle distinction between this routine and the previous
532 if (vam->link_state_process_up)
533 vlib_process_signal_event (vam->vlib_main,
534 link_state_process_node.index,
535 API_ADMIN_UP_DOWN_EVENT,
540 #define pub_sub_handler(lca,UCA) \
541 static void vl_api_want_##lca##_t_handler ( \
542 vl_api_want_##lca##_t *mp) \
544 vpe_api_main_t *vam = &vpe_api_main; \
545 vpe_client_registration_t *rp; \
546 vl_api_want_##lca##_reply_t *rmp; \
550 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
552 if (mp->enable_disable) { \
553 clib_warning ("pid %d: already enabled...", mp->pid); \
554 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
557 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
558 pool_put (vam->lca##_registrations, rp); \
559 hash_unset (vam->lca##_registration_hash, \
564 if (mp->enable_disable == 0) { \
565 clib_warning ("pid %d: already disabled...", mp->pid); \
566 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
569 pool_get (vam->lca##_registrations, rp); \
570 rp->client_index = mp->client_index; \
571 rp->client_pid = mp->pid; \
572 hash_set (vam->lca##_registration_hash, rp->client_index, \
573 rp - vam->lca##_registrations); \
576 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
579 pub_sub_handler (interface_events,INTERFACE_EVENTS)
580 pub_sub_handler (oam_events,OAM_EVENTS)
582 #define RESOLUTION_EVENT 1
583 #define RESOLUTION_PENDING_EVENT 2
584 #define IP4_ARP_EVENT 3
586 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
587 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
588 static int mpls_ethernet_add_del_tunnel_2_t_handler
589 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
591 void handle_ip4_arp_event (u32 pool_index)
593 vpe_api_main_t * vam = &vpe_api_main;
594 vnet_main_t * vnm = vam->vnet_main;
595 vlib_main_t * vm = vam->vlib_main;
596 vl_api_ip4_arp_event_t * event;
597 vl_api_ip4_arp_event_t * mp;
598 unix_shared_memory_queue_t * q;
600 /* Client can cancel, die, etc. */
601 if (pool_is_free_index (vam->arp_events, pool_index))
604 event = pool_elt_at_index (vam->arp_events, pool_index);
606 q = vl_api_client_index_to_input_queue (event->client_index);
608 (void) vnet_add_del_ip4_arp_change_event
609 (vnm, arp_change_delete_callback,
610 event->pid, &event->address,
611 vpe_resolver_process_node.index, IP4_ARP_EVENT,
612 ~0 /* pool index, notused */, 0 /* is_add */);
616 if (q->cursize < q->maxsize) {
617 mp = vl_msg_api_alloc (sizeof (*mp));
618 clib_memcpy (mp, event, sizeof (*mp));
619 vl_msg_api_send_shmem (q, (u8 *)&mp);
621 static f64 last_time;
623 * Throttle syslog msgs.
624 * It's pretty tempting to just revoke the registration...
626 if (vlib_time_now (vm) > last_time + 10.0) {
627 clib_warning ("arp event for %U to pid %d: queue stuffed!",
628 format_ip4_address, &event->address, event->pid);
629 last_time = vlib_time_now(vm);
635 resolver_process (vlib_main_t * vm,
636 vlib_node_runtime_t * rt,
640 uword *event_data = 0;
642 vpe_api_main_t * vam = &vpe_api_main;
643 pending_route_t * pr;
644 vl_api_ip_add_del_route_t * adr;
645 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
646 u32 * resolution_failures = 0;
651 vlib_process_wait_for_event_or_clock (vm, timeout);
653 event_type = vlib_process_get_events (vm, &event_data);
655 switch (event_type) {
656 case RESOLUTION_PENDING_EVENT:
660 case RESOLUTION_EVENT:
661 for (i = 0; i < vec_len(event_data); i++) {
663 * Resolution events can occur long after the
664 * original request has timed out. $$$ add a cancel
667 if (pool_is_free_index (vam->pending_routes, event_data[i]))
670 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
674 switch (pr->resolve_type) {
675 case RESOLVE_IP4_ADD_DEL_ROUTE:
676 rv = ip4_add_del_route_t_handler (adr);
677 clib_warning ("resolver: add %U/%d via %U %s",
679 (ip4_address_t *)&(adr->dst_address),
680 adr->dst_address_length,
682 (ip4_address_t *)&(adr->next_hop_address),
683 (rv >= 0) ? "succeeded" : "failed");
686 case RESOLVE_IP6_ADD_DEL_ROUTE:
687 rv = ip6_add_del_route_t_handler (adr);
688 clib_warning ("resolver: add %U/%d via %U %s",
690 (ip6_address_t *)&(adr->dst_address),
691 adr->dst_address_length,
693 (ip6_address_t *)&(adr->next_hop_address),
694 (rv >= 0) ? "succeeded" : "failed");
697 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
698 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
699 clib_warning ("resolver: add mpls-o-e via %U %s",
701 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
702 (rv >= 0) ? "succeeded" : "failed");
706 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
708 pool_put (vam->pending_routes, pr);
713 for (i = 0; i < vec_len(event_data); i++)
714 handle_ip4_arp_event (event_data[i]);
717 case ~0: /* timeout, retry pending resolutions */
718 pool_foreach (pr, vam->pending_routes,
724 /* May fail, e.g. due to interface down */
725 switch (pr->resolve_type) {
726 case RESOLVE_IP4_ADD_DEL_ROUTE:
727 e = ip4_probe_neighbor
728 (vm, (ip4_address_t *)&(adr->next_hop_address),
729 ntohl(adr->next_hop_sw_if_index));
732 case RESOLVE_IP6_ADD_DEL_ROUTE:
733 e = ip6_probe_neighbor
734 (vm, (ip6_address_t *)&(adr->next_hop_address),
735 ntohl(adr->next_hop_sw_if_index));
738 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
740 e = ip4_probe_neighbor
742 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
743 pme->resolve_opaque);
747 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
751 clib_error_report (e);
753 adr->resolve_attempts = 1;
755 pme->resolve_attempts = 1;
759 adr->resolve_attempts -= 1;
760 if (adr->resolve_attempts == 0)
761 vec_add1 (resolution_failures,
762 pr - vam->pending_routes);
764 pme->resolve_attempts -= 1;
765 if (pme->resolve_attempts == 0)
766 vec_add1 (resolution_failures,
767 pr - vam->pending_routes);
771 for (i = 0; i < vec_len (resolution_failures); i++) {
772 pr = pool_elt_at_index (vam->pending_routes,
773 resolution_failures[i]);
777 switch (pr->resolve_type) {
778 case RESOLVE_IP4_ADD_DEL_ROUTE:
779 clib_warning ("resolver: add %U/%d via %U retry failure",
781 (ip4_address_t *)&(adr->dst_address),
782 adr->dst_address_length,
784 (ip4_address_t *)&(adr->next_hop_address));
787 case RESOLVE_IP6_ADD_DEL_ROUTE:
788 clib_warning ("resolver: add %U/%d via %U retry failure",
790 (ip6_address_t *)&(adr->dst_address),
791 adr->dst_address_length,
793 (ip6_address_t *)&(adr->next_hop_address));
796 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
797 clib_warning ("resolver: add mpls-o-e via %U retry failure",
799 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
803 clib_warning ("BUG");
805 pool_put(vam->pending_routes, pr);
807 vec_reset_length (resolution_failures);
810 if (pool_elts (vam->pending_routes) == 0)
812 vec_reset_length (event_data);
814 return 0; /* or not */
817 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
818 .function = resolver_process,
819 .type = VLIB_NODE_TYPE_PROCESS,
820 .name = "vpe-route-resolver-process",
823 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
825 ip4_main_t * im = &ip4_main;
826 ip_lookup_main_t * lm = &im->lookup_main;
827 vnet_classify_main_t * cm = &vnet_classify_main;
828 stats_main_t * sm = &stats_main;
829 ip4_add_del_route_args_t a;
830 ip4_address_t next_hop_address;
832 vpe_api_main_t * vam = &vpe_api_main;
833 vnet_main_t * vnm = vam->vnet_main;
834 vlib_main_t * vm = vlib_get_main();
835 pending_route_t * pr;
836 vl_api_ip_add_del_route_t * adr;
840 ip_adjacency_t *nh_adj, *add_adj = 0;
842 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
844 if (mp->create_vrf_if_needed) {
846 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
848 fib_index = f->index;
850 /* No such VRF, and we weren't asked to create one */
851 return VNET_API_ERROR_NO_SUCH_FIB;
857 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
858 ntohl(mp->next_hop_sw_if_index)))
859 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
861 clib_memcpy (next_hop_address.data, mp->next_hop_address,
862 sizeof (next_hop_address.data));
864 /* Arp for the next_hop if necessary */
865 if (mp->is_add && mp->resolve_if_needed) {
867 ip_adjacency_t * adj;
869 lookup_result = ip4_fib_lookup_with_table
870 (im, fib_index, &next_hop_address, 1 /* disable default route */);
872 adj = ip_get_adjacency (lm, lookup_result);
874 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
875 pool_get (vam->pending_routes, pr);
876 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
878 clib_memcpy (adr, mp, sizeof (*adr));
879 /* recursion block, "just in case" */
880 adr->resolve_if_needed = 0;
881 adr->resolve_attempts = ntohl(mp->resolve_attempts);
882 vnet_register_ip4_arp_resolution_event
883 (vnm, &next_hop_address, vpe_resolver_process_node.index,
884 RESOLUTION_EVENT, pr - vam->pending_routes);
886 vlib_process_signal_event
887 (vm, vpe_resolver_process_node.index,
888 RESOLUTION_PENDING_EVENT, 0 /* data */);
890 /* The interface may be down, etc. */
891 e = ip4_probe_neighbor
892 (vm, (ip4_address_t *)&(mp->next_hop_address),
893 ntohl(mp->next_hop_sw_if_index));
896 clib_error_report(e);
898 return VNET_API_ERROR_IN_PROGRESS;
902 if (mp->is_multipath) {
905 dslock (sm, 1 /* release hint */, 10 /* tag */);
908 flags = IP4_ROUTE_FLAG_ADD;
910 flags = IP4_ROUTE_FLAG_DEL;
913 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
915 ip4_add_del_route_next_hop (im, flags,
916 (ip4_address_t *) mp->dst_address,
917 (u32) mp->dst_address_length,
918 (ip4_address_t *) mp->next_hop_address,
919 ntohl(mp->next_hop_sw_if_index),
920 (u32) mp->next_hop_weight,
927 memset (&a, 0, sizeof (a));
928 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
930 a.dst_address_length = mp->dst_address_length;
932 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
933 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
934 a.table_index_or_table_id = fib_index;
939 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
941 dslock (sm, 1 /* release hint */, 2 /* tag */);
945 ai = lm->drop_adj_index;
946 else if (mp->is_local)
947 ai = lm->local_adj_index;
948 else if (mp->is_classify) {
950 memset(&cadj, 0, sizeof(cadj));
951 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
952 cadj.classify.table_index = ntohl(mp->classify_table_index);
953 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
955 return VNET_API_ERROR_NO_SUCH_TABLE;
957 vec_add1 (add_adj, cadj);
961 ai = ip4_fib_lookup_with_table
962 (im, fib_index, &next_hop_address,
963 1 /* disable default route */);
964 if (ai == lm->miss_adj_index) {
966 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
970 nh_adj = ip_get_adjacency (lm, ai);
971 vec_add1 (add_adj, nh_adj[0]);
972 if (mp->lookup_in_vrf) {
973 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
975 add_adj[0].explicit_fib_index = p[0];
979 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
983 ip_adjacency_t * adj;
984 int disable_default_route = 1;
986 /* Trying to delete the default route? */
987 if (a.dst_address.as_u32 == 0 &&
988 a.dst_address_length == 0)
989 disable_default_route = 0;
991 ai = ip4_fib_lookup_with_table
992 (im, fib_index, &a.dst_address, disable_default_route);
993 if (ai == lm->miss_adj_index) {
995 return VNET_API_ERROR_UNKNOWN_DESTINATION;
998 adj = ip_get_adjacency (lm, ai);
999 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1001 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1007 a.add_adj = add_adj;
1008 a.n_add_adj = vec_len(add_adj);
1009 ip4_add_del_route (im, &a);
1017 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1019 ip6_main_t * im = &ip6_main;
1020 ip_lookup_main_t * lm = &im->lookup_main;
1021 vnet_main_t * vnm = vnet_get_main();
1022 vlib_main_t * vm = vlib_get_main();
1023 vpe_api_main_t * vam = &vpe_api_main;
1024 stats_main_t * sm = &stats_main;
1025 ip6_add_del_route_args_t a;
1026 ip6_address_t next_hop_address;
1027 pending_route_t * pr;
1028 vl_api_ip_add_del_route_t * adr;
1033 ip_adjacency_t * nh_adj, * add_adj = 0;
1036 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1039 if (mp->create_vrf_if_needed) {
1041 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1043 fib_index = f->index;
1045 /* No such VRF, and we weren't asked to create one */
1046 return VNET_API_ERROR_NO_SUCH_FIB;
1052 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1053 ntohl(mp->next_hop_sw_if_index)))
1054 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1056 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1057 sizeof (next_hop_address.as_u8));
1059 /* Arp for the next_hop if necessary */
1060 if (mp->is_add && mp->resolve_if_needed) {
1062 ip_adjacency_t * adj;
1064 lookup_result = ip6_fib_lookup_with_table
1065 (im, fib_index, &next_hop_address);
1067 adj = ip_get_adjacency (lm, lookup_result);
1069 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1070 pool_get (vam->pending_routes, pr);
1072 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1073 clib_memcpy (adr, mp, sizeof (*adr));
1074 /* recursion block, "just in case" */
1075 adr->resolve_if_needed = 0;
1076 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1077 vnet_register_ip6_neighbor_resolution_event
1078 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1079 RESOLUTION_EVENT, pr - vam->pending_routes);
1081 vlib_process_signal_event
1082 (vm, vpe_resolver_process_node.index,
1083 RESOLUTION_PENDING_EVENT, 0 /* data */);
1085 /* The interface may be down, etc. */
1086 e = ip6_probe_neighbor
1087 (vm, (ip6_address_t *)&(mp->next_hop_address),
1088 ntohl(mp->next_hop_sw_if_index));
1091 clib_error_report(e);
1093 return VNET_API_ERROR_IN_PROGRESS;
1097 if (mp->is_multipath) {
1100 dslock (sm, 1 /* release hint */, 11 /* tag */);
1103 flags = IP6_ROUTE_FLAG_ADD;
1105 flags = IP6_ROUTE_FLAG_DEL;
1108 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1110 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1111 (u32) mp->dst_address_length,
1112 (ip6_address_t *)mp->next_hop_address,
1113 ntohl(mp->next_hop_sw_if_index),
1114 (u32) mp->next_hop_weight,
1121 memset (&a, 0, sizeof (a));
1122 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1124 a.dst_address_length = mp->dst_address_length;
1126 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1127 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1128 a.table_index_or_table_id = fib_index;
1133 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1135 dslock (sm, 1 /* release hint */, 3 /* tag */);
1139 ai = lm->drop_adj_index;
1140 else if (mp->is_local)
1141 ai = lm->local_adj_index;
1143 ai = ip6_fib_lookup_with_table
1144 (im, fib_index, &next_hop_address);
1145 if (ai == lm->miss_adj_index) {
1147 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1151 nh_adj = ip_get_adjacency (lm, ai);
1152 vec_add1 (add_adj, nh_adj[0]);
1153 if (mp->lookup_in_vrf) {
1154 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1156 add_adj[0].explicit_fib_index = p[0];
1160 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1164 ip_adjacency_t * adj;
1166 ai = ip6_fib_lookup_with_table
1167 (im, fib_index, &a.dst_address);
1168 if (ai == lm->miss_adj_index) {
1170 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1172 adj = ip_get_adjacency (lm, ai);
1173 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1175 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1180 a.add_adj = add_adj;
1181 a.n_add_adj = vec_len(add_adj);
1182 ip6_add_del_route (im, &a);
1190 void vl_api_ip_add_del_route_t_handler (
1191 vl_api_ip_add_del_route_t *mp)
1193 vl_api_ip_add_del_route_reply_t * rmp;
1195 vnet_main_t * vnm = vnet_get_main();
1200 rv = ip6_add_del_route_t_handler (mp);
1202 rv = ip4_add_del_route_t_handler (mp);
1204 rv = (rv == 0) ? vnm->api_errno : rv;
1206 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1209 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1210 u32 sw_if_index, u8 *next_hop_addr)
1212 vl_api_ip_add_del_route_t mp;
1215 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1218 * Configure default IP route:
1219 * - ip route add 0.0.0.0/1 via <GW IP>
1220 * - ip route add 128.0.0.0/1 via <GW IP>
1222 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1224 mp.resolve_attempts = ~0;
1225 mp.resolve_if_needed = 1;
1227 mp.is_ipv6 = is_ipv6;
1228 mp.next_hop_weight = 1;
1230 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1233 rv = ip6_add_del_route_t_handler (&mp);
1236 mp.dst_address_length = 1;
1238 mp.dst_address[0] = 0;
1239 rv = ip4_add_del_route_t_handler (&mp);
1241 mp.dst_address[0] = 128;
1242 rv |= ip4_add_del_route_t_handler (&mp);
1246 clib_error_return (0, "failed to config default IP route");
1251 vl_api_sw_interface_add_del_address_t_handler
1252 (vl_api_sw_interface_add_del_address_t *mp)
1254 vlib_main_t *vm = vlib_get_main();
1255 vl_api_sw_interface_add_del_address_reply_t * rmp;
1259 VALIDATE_SW_IF_INDEX(mp);
1261 is_del = mp->is_add == 0;
1264 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1265 else if (mp->is_ipv6)
1266 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1267 (void *)mp->address,
1268 mp->address_length, is_del);
1270 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1271 (void *) mp->address,
1272 mp->address_length, is_del);
1274 BAD_SW_IF_INDEX_LABEL;
1276 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1280 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1283 u32 table_id = ntohl(mp->vrf_id);
1284 u32 sw_if_index = ntohl(mp->sw_if_index);
1285 vl_api_sw_interface_set_table_reply_t * rmp;
1286 stats_main_t * sm = &stats_main;
1288 VALIDATE_SW_IF_INDEX(mp);
1290 dslock (sm, 1 /* release hint */, 4 /* tag */);
1293 ip6_main_t * im = &ip6_main;
1295 find_ip6_fib_by_table_index_or_id (im, table_id,
1296 IP6_ROUTE_FLAG_TABLE_ID);
1298 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1299 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1301 rv = VNET_API_ERROR_NO_SUCH_FIB;
1304 ip4_main_t * im = &ip4_main;
1305 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1306 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1308 /* Truthfully this can't fail */
1310 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1311 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1313 rv = VNET_API_ERROR_NO_SUCH_FIB;
1318 BAD_SW_IF_INDEX_LABEL;
1320 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1324 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1326 vlib_main_t *vm = vlib_get_main();
1327 vl_api_sw_interface_set_vpath_reply_t * rmp;
1330 u32 sw_if_index = ntohl(mp->sw_if_index);
1331 ip4_main_t *ip4m = &ip4_main;
1332 ip6_main_t *ip6m = &ip6_main;
1333 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1334 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1335 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1336 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1337 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1338 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1340 VALIDATE_SW_IF_INDEX(mp);
1342 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1344 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1345 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1346 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1347 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1348 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1349 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1350 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1351 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1352 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1353 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1354 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1355 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1356 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1357 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1358 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1359 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1361 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1362 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1363 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1364 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1365 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1366 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1367 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1368 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1369 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1370 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1371 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1372 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1373 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1374 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1375 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1376 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1379 BAD_SW_IF_INDEX_LABEL;
1381 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1385 vl_api_sw_interface_set_l2_xconnect_t_handler (
1386 vl_api_sw_interface_set_l2_xconnect_t *mp)
1388 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1390 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1391 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1392 vlib_main_t *vm = vlib_get_main();
1393 vnet_main_t *vnm = vnet_get_main();
1395 VALIDATE_RX_SW_IF_INDEX(mp);
1398 VALIDATE_TX_SW_IF_INDEX(mp);
1399 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1400 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1402 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1405 BAD_RX_SW_IF_INDEX_LABEL;
1406 BAD_TX_SW_IF_INDEX_LABEL;
1408 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1412 vl_api_sw_interface_set_l2_bridge_t_handler (
1413 vl_api_sw_interface_set_l2_bridge_t *mp)
1415 bd_main_t * bdm = &bd_main;
1416 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1418 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1419 u32 bd_id = ntohl(mp->bd_id);
1423 vlib_main_t *vm = vlib_get_main();
1424 vnet_main_t *vnm = vnet_get_main();
1426 VALIDATE_RX_SW_IF_INDEX(mp);
1428 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1431 //VALIDATE_TX_SW_IF_INDEX(mp);
1432 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1433 rx_sw_if_index, bd_index, bvi, shg, 0);
1435 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1438 BAD_RX_SW_IF_INDEX_LABEL;
1440 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1444 vl_api_bridge_domain_add_del_t_handler (
1445 vl_api_bridge_domain_add_del_t *mp)
1447 vlib_main_t * vm = vlib_get_main ();
1448 bd_main_t * bdm = &bd_main;
1449 vl_api_bridge_domain_add_del_reply_t * rmp;
1451 u32 enable_flags = 0, disable_flags = 0;
1452 u32 bd_id = ntohl(mp->bd_id);
1456 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1459 enable_flags |= L2_FLOOD;
1461 disable_flags |= L2_FLOOD;
1464 enable_flags |= L2_UU_FLOOD;
1466 disable_flags |= L2_UU_FLOOD;
1469 enable_flags |= L2_FWD;
1471 disable_flags |= L2_FWD;
1474 enable_flags |= L2_ARP_TERM;
1476 disable_flags |= L2_ARP_TERM;
1479 enable_flags |= L2_LEARN;
1481 disable_flags |= L2_LEARN;
1484 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1487 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1490 rv = bd_delete_bd_index(bdm, bd_id);
1492 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1495 static void vl_api_bridge_domain_details_t_handler (
1496 vl_api_bridge_domain_details_t * mp)
1498 clib_warning ("BUG");
1501 static void vl_api_bridge_domain_sw_if_details_t_handler (
1502 vl_api_bridge_domain_sw_if_details_t * mp)
1504 clib_warning ("BUG");
1507 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1508 l2_bridge_domain_t * bd_config,
1512 vl_api_bridge_domain_details_t * mp;
1514 mp = vl_msg_api_alloc (sizeof (*mp));
1515 memset (mp, 0, sizeof (*mp));
1516 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1517 mp->bd_id = ntohl (bd_config->bd_id);
1518 mp->flood = bd_feature_flood (bd_config);
1519 mp->uu_flood = bd_feature_uu_flood (bd_config);
1520 mp->forward = bd_feature_forward (bd_config);
1521 mp->learn = bd_feature_learn (bd_config);
1522 mp->arp_term = bd_feature_arp_term (bd_config);
1523 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1524 mp->n_sw_ifs = ntohl (n_sw_ifs);
1525 mp->context = context;
1527 vl_msg_api_send_shmem (q, (u8 *)&mp);
1530 static void send_bd_sw_if_details (l2input_main_t * l2im,
1531 unix_shared_memory_queue_t *q,
1532 l2_flood_member_t * member, u32 bd_id,
1535 vl_api_bridge_domain_sw_if_details_t * mp;
1536 l2_input_config_t * input_cfg;
1538 mp = vl_msg_api_alloc (sizeof (*mp));
1539 memset (mp, 0, sizeof (*mp));
1540 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1541 mp->bd_id = ntohl (bd_id);
1542 mp->sw_if_index = ntohl (member->sw_if_index);
1543 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1544 mp->shg = input_cfg->shg;
1545 mp->context = context;
1547 vl_msg_api_send_shmem (q, (u8 *)&mp);
1550 static void vl_api_bridge_domain_dump_t_handler (
1551 vl_api_bridge_domain_dump_t *mp)
1553 bd_main_t * bdm = &bd_main;
1554 l2input_main_t * l2im = &l2input_main;
1555 unix_shared_memory_queue_t * q;
1556 l2_bridge_domain_t * bd_config;
1557 u32 bd_id, bd_index;
1560 q = vl_api_client_index_to_input_queue (mp->client_index);
1565 bd_id = ntohl(mp->bd_id);
1567 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1568 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1569 for (; bd_index < end; bd_index++) {
1570 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1571 /* skip dummy bd_id 0 */
1572 if (bd_config && (bd_config->bd_id > 0)) {
1574 l2_flood_member_t * m;
1576 n_sw_ifs = vec_len (bd_config->members);
1577 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1579 vec_foreach (m, bd_config->members) {
1580 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1587 vl_api_l2fib_add_del_t_handler (
1588 vl_api_l2fib_add_del_t *mp)
1590 bd_main_t * bdm = &bd_main;
1591 l2input_main_t * l2im = &l2input_main;
1592 vl_api_l2fib_add_del_reply_t * rmp;
1595 u32 sw_if_index = ntohl(mp->sw_if_index);
1596 u32 bd_id = ntohl(mp->bd_id);
1604 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1606 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1607 goto bad_sw_if_index;
1612 VALIDATE_SW_IF_INDEX(mp);
1613 if (vec_len(l2im->configs) <= sw_if_index) {
1614 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1615 goto bad_sw_if_index;
1617 l2_input_config_t * config;
1618 config = vec_elt_at_index(l2im->configs, sw_if_index);
1619 if (config->bridge == 0) {
1620 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1621 goto bad_sw_if_index;
1624 static_mac = mp->static_mac ? 1 : 0;
1625 filter_mac = mp->filter_mac ? 1 : 0;
1626 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1629 l2fib_del_entry(mac, bd_index);
1632 BAD_SW_IF_INDEX_LABEL;
1634 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1638 vl_api_l2_flags_t_handler (
1639 vl_api_l2_flags_t *mp)
1641 vl_api_l2_flags_reply_t * rmp;
1643 u32 sw_if_index = ntohl(mp->sw_if_index);
1644 u32 flags = ntohl(mp->feature_bitmap);
1647 VALIDATE_SW_IF_INDEX(mp);
1650 if (flags & L2INPUT_FEAT_ ## a) \
1651 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1652 foreach_l2input_feat;
1655 BAD_SW_IF_INDEX_LABEL;
1657 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1661 vl_api_bridge_flags_t_handler (
1662 vl_api_bridge_flags_t *mp)
1664 vlib_main_t *vm = vlib_get_main();
1665 bd_main_t * bdm = &bd_main;
1666 vl_api_bridge_flags_reply_t * rmp;
1668 u32 bd_id = ntohl(mp->bd_id);
1670 u32 flags = ntohl(mp->feature_bitmap);
1673 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1675 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1681 bd_set_flags(vm, bd_index, flags, mp->is_set);
1684 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1685 rmp->resulting_feature_bitmap = ntohl(flags));
1689 vl_api_bd_ip_mac_add_del_t_handler (
1690 vl_api_bd_ip_mac_add_del_t *mp)
1692 bd_main_t * bdm = &bd_main;
1693 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1695 u32 bd_id = ntohl(mp->bd_id);
1699 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1701 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1706 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1707 mp->mac_address, mp->is_ipv6, mp->is_add))
1708 rv = VNET_API_ERROR_UNSPECIFIED;
1711 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1715 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1718 vl_api_tap_connect_reply_t * rmp;
1719 unix_shared_memory_queue_t * q;
1720 u32 sw_if_index = (u32)~0;
1722 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1723 mp->use_random_mac ? 0 : mp->mac_address,
1724 &sw_if_index, mp->renumber,
1725 ntohl(mp->custom_dev_instance));
1727 q = vl_api_client_index_to_input_queue (mp->client_index);
1731 rmp = vl_msg_api_alloc (sizeof (*rmp));
1732 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1733 rmp->context = mp->context;
1734 rmp->retval = ntohl(rv);
1735 rmp->sw_if_index = ntohl(sw_if_index);
1737 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1741 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1744 vl_api_tap_modify_reply_t * rmp;
1745 unix_shared_memory_queue_t * q;
1746 u32 sw_if_index = (u32)~0;
1748 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1749 mp->use_random_mac ? 0 : mp->mac_address,
1750 &sw_if_index, mp->renumber,
1751 ntohl(mp->custom_dev_instance));
1753 q = vl_api_client_index_to_input_queue (mp->client_index);
1757 rmp = vl_msg_api_alloc (sizeof (*rmp));
1758 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1759 rmp->context = mp->context;
1760 rmp->retval = ntohl(rv);
1761 rmp->sw_if_index = ntohl(sw_if_index);
1763 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1767 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1770 vpe_api_main_t * vam = &vpe_api_main;
1771 vl_api_tap_delete_reply_t * rmp;
1772 unix_shared_memory_queue_t * q;
1773 u32 sw_if_index = ntohl(mp->sw_if_index);
1775 rv = vnet_tap_delete (vm, sw_if_index);
1777 q = vl_api_client_index_to_input_queue (mp->client_index);
1781 rmp = vl_msg_api_alloc (sizeof (*rmp));
1782 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1783 rmp->context = mp->context;
1784 rmp->retval = ntohl(rv);
1786 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1789 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1793 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1795 vl_api_create_vlan_subif_reply_t * rmp;
1796 vnet_main_t * vnm = vnet_get_main();
1797 u32 hw_if_index, sw_if_index = (u32)~0;
1798 vnet_hw_interface_t * hi;
1801 vnet_sw_interface_t template;
1803 vnet_interface_main_t * im = &vnm->interface_main;
1804 u64 sup_and_sub_key;
1806 unix_shared_memory_queue_t * q;
1807 clib_error_t * error;
1809 VALIDATE_SW_IF_INDEX(mp);
1811 hw_if_index = ntohl(mp->sw_if_index);
1812 hi = vnet_get_hw_interface (vnm, hw_if_index);
1814 id = ntohl(mp->vlan_id);
1815 if (id == 0 || id > 4095) {
1816 rv = VNET_API_ERROR_INVALID_VLAN;
1820 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1822 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1824 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1828 kp = clib_mem_alloc (sizeof (*kp));
1829 *kp = sup_and_sub_key;
1831 memset (&template, 0, sizeof (template));
1832 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1833 template.sup_sw_if_index = hi->sw_if_index;
1834 template.sub.id = id;
1835 template.sub.eth.raw_flags = 0;
1836 template.sub.eth.flags.one_tag = 1;
1837 template.sub.eth.outer_vlan_id = id;
1838 template.sub.eth.flags.exact_match = 1;
1840 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1842 clib_error_report(error);
1843 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1846 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1847 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1849 BAD_SW_IF_INDEX_LABEL;
1852 q = vl_api_client_index_to_input_queue (mp->client_index);
1856 rmp = vl_msg_api_alloc (sizeof (*rmp));
1857 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1858 rmp->context = mp->context;
1859 rmp->retval = ntohl(rv);
1860 rmp->sw_if_index = ntohl(sw_if_index);
1861 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1865 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1867 vl_api_create_subif_reply_t * rmp;
1868 vnet_main_t * vnm = vnet_get_main();
1869 u32 sw_if_index = ~0;
1872 vnet_sw_interface_t *si;
1873 vnet_hw_interface_t *hi;
1874 vnet_sw_interface_t template;
1876 vnet_interface_main_t * im = &vnm->interface_main;
1877 u64 sup_and_sub_key;
1879 clib_error_t * error;
1881 VALIDATE_SW_IF_INDEX(mp);
1883 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1884 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1886 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1887 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1891 sw_if_index = si->sw_if_index;
1892 sub_id = ntohl(mp->sub_id);
1894 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1896 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1899 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1900 sw_if_index, sub_id);
1901 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1905 kp = clib_mem_alloc (sizeof (*kp));
1906 *kp = sup_and_sub_key;
1908 memset (&template, 0, sizeof (template));
1909 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1910 template.sup_sw_if_index = sw_if_index;
1911 template.sub.id = sub_id;
1912 template.sub.eth.flags.no_tags = mp->no_tags;
1913 template.sub.eth.flags.one_tag = mp->one_tag;
1914 template.sub.eth.flags.two_tags = mp->two_tags;
1915 template.sub.eth.flags.dot1ad = mp->dot1ad;
1916 template.sub.eth.flags.exact_match = mp->exact_match;
1917 template.sub.eth.flags.default_sub = mp->default_sub;
1918 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1919 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1920 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1921 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1923 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1925 clib_error_report (error);
1926 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1930 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1931 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1933 BAD_SW_IF_INDEX_LABEL;
1937 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1939 rmp->sw_if_index = ntohl(sw_if_index);
1944 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1946 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1948 stats_main_t * sm = &stats_main;
1949 u32 tunnel_sw_if_index = ~0;
1951 dslock (sm, 1 /* release hint */, 5 /* tag */);
1953 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1954 (ip4_address_t *)(mp->dst_address),
1955 (ip4_address_t *)(mp->intfc_address),
1956 (u32)(mp->intfc_address_length),
1957 ntohl(mp->inner_vrf_id),
1958 ntohl(mp->outer_vrf_id),
1959 &tunnel_sw_if_index,
1964 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1966 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1971 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1972 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1974 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1976 stats_main_t * sm = &stats_main;
1977 u32 tunnel_sw_if_index;
1979 dslock (sm, 1 /* release hint */, 5 /* tag */);
1981 rv = vnet_mpls_ethernet_add_del_tunnel
1982 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1983 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1984 ntohl(mp->tx_sw_if_index),
1985 &tunnel_sw_if_index,
1991 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1993 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1998 * This piece of misery brought to you because the control-plane
1999 * can't figure out the tx interface + dst-mac address all by itself
2001 static int mpls_ethernet_add_del_tunnel_2_t_handler
2002 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2004 pending_route_t * pr;
2005 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2006 vnet_main_t * vnm = vnet_get_main();
2007 vlib_main_t * vm = vlib_get_main();
2008 stats_main_t * sm = &stats_main;
2009 vpe_api_main_t * vam = &vpe_api_main;
2010 u32 inner_fib_index, outer_fib_index;
2011 ip4_main_t * im = &ip4_main;
2012 ip_lookup_main_t * lm = &im->lookup_main;
2013 ip_adjacency_t * adj = 0;
2016 u8 * dst_mac_address;
2020 u32 tunnel_sw_if_index;
2022 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2024 return VNET_API_ERROR_NO_SUCH_FIB;
2026 outer_fib_index = p[0];
2029 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2031 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2033 inner_fib_index = p[0];
2035 if (inner_fib_index == outer_fib_index)
2036 return VNET_API_ERROR_INVALID_VALUE;
2038 lookup_result = ip4_fib_lookup_with_table
2039 (im, outer_fib_index,
2040 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2041 1 /* disable default route */);
2043 adj = ip_get_adjacency (lm, lookup_result);
2044 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2046 if (mp->is_add && mp->resolve_if_needed) {
2047 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2048 pool_get (vam->pending_routes, pr);
2049 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2051 clib_memcpy (pme, mp, sizeof (*pme));
2052 /* recursion block, "just in case" */
2053 pme->resolve_if_needed = 0;
2054 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2055 pme->resolve_opaque = tx_sw_if_index;
2056 vnet_register_ip4_arp_resolution_event
2058 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2059 vpe_resolver_process_node.index,
2060 RESOLUTION_EVENT, pr - vam->pending_routes);
2062 vlib_process_signal_event
2063 (vm, vpe_resolver_process_node.index,
2064 RESOLUTION_PENDING_EVENT, 0 /* data */);
2066 /* The interface may be down, etc. */
2067 e = ip4_probe_neighbor
2068 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2072 clib_error_report(e);
2074 return VNET_API_ERROR_IN_PROGRESS;
2078 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2079 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2082 vnet_rewrite_get_data_internal
2083 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2085 dslock (sm, 1 /* release hint */, 10 /* tag */);
2087 rv = vnet_mpls_ethernet_add_del_tunnel
2088 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2089 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2090 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2098 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2099 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2101 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2104 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2106 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2111 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2113 vl_api_mpls_add_del_encap_reply_t * rmp;
2115 static u32 * labels;
2118 vec_reset_length (labels);
2120 for (i = 0; i < mp->nlabels; i++)
2121 vec_add1 (labels, ntohl(mp->labels[i]));
2124 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2125 ntohl(mp->vrf_id), labels,
2126 ~0 /* policy_tunnel_index */,
2127 0 /* no_dst_hash */,
2131 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2135 vl_api_mpls_add_del_decap_t_handler
2136 (vl_api_mpls_add_del_decap_t *mp)
2138 vl_api_mpls_add_del_decap_reply_t * rmp;
2141 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2142 ntohl(mp->label), ntohl(mp->next_index),
2143 mp->s_bit, mp->is_add);
2145 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2149 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2151 vl_api_proxy_arp_add_del_reply_t * rmp;
2154 ip4_main_t * im = &ip4_main;
2155 stats_main_t * sm = &stats_main;
2156 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2157 ip4_address_t *hi_addr,
2158 u32 fib_index, int is_del);
2161 dslock (sm, 1 /* release hint */, 6 /* tag */);
2163 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2166 rv = VNET_API_ERROR_NO_SUCH_FIB;
2172 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2173 (ip4_address_t *)mp->hi_address,
2174 fib_index, mp->is_add == 0);
2178 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2182 vl_api_proxy_arp_intfc_enable_disable_t_handler
2183 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2186 vnet_main_t * vnm = vnet_get_main();
2187 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2188 vnet_sw_interface_t * si;
2191 VALIDATE_SW_IF_INDEX(mp);
2193 sw_if_index = ntohl(mp->sw_if_index);
2195 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2197 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2201 si = vnet_get_sw_interface (vnm, sw_if_index);
2205 if (mp->enable_disable)
2206 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2208 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2210 BAD_SW_IF_INDEX_LABEL;
2213 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2217 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2219 vl_api_ip_neighbor_add_del_reply_t * rmp;
2220 vnet_main_t * vnm = vnet_get_main();
2223 stats_main_t * sm = &stats_main;
2225 VALIDATE_SW_IF_INDEX(mp);
2227 dslock (sm, 1 /* release hint */, 7 /* tag */);
2231 rv = vnet_set_ip6_ethernet_neighbor
2232 (vm, ntohl(mp->sw_if_index),
2233 (ip6_address_t *)(mp->dst_address),
2234 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2236 rv = vnet_unset_ip6_ethernet_neighbor
2237 (vm, ntohl(mp->sw_if_index),
2238 (ip6_address_t *)(mp->dst_address),
2239 mp->mac_address, sizeof(mp->mac_address));
2241 ip4_main_t * im = &ip4_main;
2242 ip_lookup_main_t * lm = &im->lookup_main;
2243 ethernet_arp_ip4_over_ethernet_address_t a;
2245 ip_adjacency_t *nh_adj;
2247 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2249 rv = VNET_API_ERROR_NO_SUCH_FIB;
2255 * Unfortunately, folks have a penchant for
2256 * adding interface addresses to the ARP cache, and
2257 * wondering why the forwarder eventually ASSERTs...
2259 ai = ip4_fib_lookup_with_table
2260 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2261 1 /* disable default route */);
2264 nh_adj = ip_get_adjacency (lm, ai);
2265 /* Never allow manipulation of a local adj! */
2266 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2267 clib_warning("%U matches local adj",
2269 (ip4_address_t *)(mp->dst_address));
2270 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2275 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2276 clib_memcpy (&a.ip4, mp->dst_address, 4);
2279 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2280 fib_index, &a, mp->is_static);
2282 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2286 BAD_SW_IF_INDEX_LABEL;
2289 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2293 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2296 vpe_main_t *rm = &vpe_main;
2297 ip4_main_t *im4 = &ip4_main;
2298 ip6_main_t *im6 = &ip6_main;
2299 ip_lookup_main_t * lm;
2304 u32 adj_index, sw_if_index;
2305 vl_api_is_address_reachable_t *rmp;
2306 ip_adjacency_t * adj;
2307 unix_shared_memory_queue_t *q;
2309 q = vl_api_client_index_to_input_queue (mp->client_index);
2311 increment_missing_api_client_counter (rm->vlib_main);
2315 rmp = vl_msg_api_alloc (sizeof (*rmp));
2316 clib_memcpy (rmp, mp, sizeof (*rmp));
2318 sw_if_index = mp->next_hop_sw_if_index;
2319 clib_memcpy (&addr, mp->address, sizeof (addr));
2321 lm = &im6->lookup_main;
2323 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2325 lm = &im4->lookup_main;
2327 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2329 if (adj_index == ~0) {
2333 adj = ip_get_adjacency (lm, adj_index);
2335 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2336 && adj->rewrite_header.sw_if_index == sw_if_index) {
2339 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2340 && adj->rewrite_header.sw_if_index == sw_if_index) {
2342 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2344 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2345 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2353 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2357 static void vl_api_sw_interface_details_t_handler (
2358 vl_api_sw_interface_details_t * mp)
2360 clib_warning ("BUG");
2363 static void vl_api_sw_interface_set_flags_t_handler (
2364 vl_api_sw_interface_set_flags_t * mp)
2366 vl_api_sw_interface_set_flags_reply_t *rmp;
2367 vnet_main_t * vnm = vnet_get_main();
2369 clib_error_t * error;
2372 VALIDATE_SW_IF_INDEX(mp);
2374 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2376 error = vnet_sw_interface_set_flags (vnm,
2377 ntohl(mp->sw_if_index),
2381 clib_error_report (error);
2384 BAD_SW_IF_INDEX_LABEL;
2385 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2388 static void vl_api_sw_interface_clear_stats_t_handler (
2389 vl_api_sw_interface_clear_stats_t * mp)
2391 vl_api_sw_interface_clear_stats_reply_t *rmp;
2393 vnet_main_t * vnm = vnet_get_main();
2394 vnet_interface_main_t * im = &vnm->interface_main;
2395 vlib_simple_counter_main_t * sm;
2396 vlib_combined_counter_main_t * cm;
2397 static vnet_main_t ** my_vnet_mains;
2398 int i, j, n_counters;
2402 vec_reset_length (my_vnet_mains);
2404 for (i = 0; i < vec_len (vnet_mains); i++)
2407 vec_add1 (my_vnet_mains, vnet_mains[i]);
2410 if (vec_len (vnet_mains) == 0)
2411 vec_add1 (my_vnet_mains, vnm);
2413 n_counters = vec_len (im->combined_sw_if_counters);
2415 for (j = 0; j < n_counters; j++)
2417 for (i = 0; i < vec_len(my_vnet_mains); i++)
2419 im = &my_vnet_mains[i]->interface_main;
2420 cm = im->combined_sw_if_counters + j;
2421 if (mp->sw_if_index == (u32)~0)
2422 vlib_clear_combined_counters (cm);
2424 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2428 n_counters = vec_len (im->sw_if_counters);
2430 for (j = 0; j < n_counters; j++)
2432 for (i = 0; i < vec_len(my_vnet_mains); i++)
2434 im = &my_vnet_mains[i]->interface_main;
2435 sm = im->sw_if_counters + j;
2436 if (mp->sw_if_index == (u32)~0)
2437 vlib_clear_simple_counters (sm);
2439 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2443 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2446 static void send_sw_interface_details (vpe_api_main_t * am,
2447 unix_shared_memory_queue_t *q,
2448 vnet_sw_interface_t * swif,
2449 u8 * interface_name,
2452 vl_api_sw_interface_details_t * mp;
2453 vnet_hw_interface_t * hi;
2455 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2457 mp = vl_msg_api_alloc (sizeof (*mp));
2458 memset (mp, 0, sizeof (*mp));
2459 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2460 mp->sw_if_index = ntohl(swif->sw_if_index);
2461 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2462 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2464 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2466 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2467 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2468 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2469 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2470 mp->link_mtu = ntohs(hi->max_packet_bytes);
2471 mp->context = context;
2473 strncpy ((char *) mp->interface_name,
2474 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2476 /* Send the L2 address for ethernet physical intfcs */
2477 if (swif->sup_sw_if_index == swif->sw_if_index
2478 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2479 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2480 ethernet_interface_t *ei;
2482 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2483 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2484 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2485 mp->l2_address_length = ntohl(sizeof (ei->address));
2486 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2487 vnet_sub_interface_t *sub = &swif->sub;
2488 mp->sub_id = ntohl(sub->id);
2489 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2490 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2491 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2492 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2493 mp->sub_exact_match = sub->eth.flags.exact_match;
2494 mp->sub_default = sub->eth.flags.default_sub;
2495 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2496 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2498 /* vlan tag rewrite data */
2499 u32 vtr_op = L2_VTR_DISABLED;
2500 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2502 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2503 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2504 // error - default to disabled
2505 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2506 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2509 mp->vtr_op = ntohl(vtr_op);
2510 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2511 mp->vtr_tag1 = ntohl(vtr_tag1);
2512 mp->vtr_tag2 = ntohl(vtr_tag2);
2516 vl_msg_api_send_shmem (q, (u8 *)&mp);
2519 static void send_sw_interface_flags (vpe_api_main_t * am,
2520 unix_shared_memory_queue_t *q,
2521 vnet_sw_interface_t * swif)
2523 vl_api_sw_interface_set_flags_t *mp;
2524 vnet_main_t * vnm = am->vnet_main;
2526 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2528 mp = vl_msg_api_alloc (sizeof (*mp));
2529 memset (mp, 0, sizeof (*mp));
2530 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2531 mp->sw_if_index = ntohl(swif->sw_if_index);
2533 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2535 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2537 vl_msg_api_send_shmem (q, (u8 *)&mp);
2540 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2541 unix_shared_memory_queue_t *q,
2543 __attribute__((unused));
2545 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2546 unix_shared_memory_queue_t *q,
2549 vl_api_sw_interface_set_flags_t *mp;
2551 mp = vl_msg_api_alloc (sizeof (*mp));
2552 memset (mp, 0, sizeof (*mp));
2553 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2554 mp->sw_if_index = ntohl(sw_if_index);
2556 mp->admin_up_down = 0;
2557 mp->link_up_down = 0;
2559 vl_msg_api_send_shmem (q, (u8 *)&mp);
2562 static void vl_api_sw_interface_dump_t_handler (
2563 vl_api_sw_interface_dump_t *mp)
2565 vpe_api_main_t * am = &vpe_api_main;
2566 vnet_sw_interface_t * swif;
2567 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2568 u8 * filter_string = 0, * name_string = 0;
2569 unix_shared_memory_queue_t * q;
2570 char * strcasestr (char *, char *); /* lnx hdr file botch */
2572 q = vl_api_client_index_to_input_queue (mp->client_index);
2577 if (mp->name_filter_valid) {
2578 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2579 filter_string = format (0, "%s%c", mp->name_filter, 0);
2582 pool_foreach (swif, im->sw_interfaces,
2584 name_string = format (name_string, "%U%c",
2585 format_vnet_sw_interface_name,
2586 am->vnet_main, swif, 0);
2588 if (mp->name_filter_valid == 0 ||
2589 strcasestr((char *) name_string, (char *) filter_string)) {
2591 send_sw_interface_details (am, q, swif, name_string, mp->context);
2592 send_sw_interface_flags (am, q, swif);
2594 _vec_len (name_string) = 0;
2597 vec_free (name_string);
2598 vec_free (filter_string);
2601 void send_oam_event (oam_target_t * t)
2603 vpe_api_main_t * vam = &vpe_api_main;
2604 unix_shared_memory_queue_t * q;
2605 vpe_client_registration_t *reg;
2606 vl_api_oam_event_t * mp;
2608 pool_foreach(reg, vam->oam_events_registrations,
2610 q = vl_api_client_index_to_input_queue (reg->client_index);
2612 mp = vl_msg_api_alloc (sizeof (*mp));
2613 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2614 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2615 mp->state = t->state;
2616 vl_msg_api_send_shmem (q, (u8 *)&mp);
2622 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2624 vl_api_oam_add_del_reply_t * rmp;
2627 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2628 (ip4_address_t *)mp->dst_address,
2632 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2636 vl_api_vnet_get_summary_stats_t_handler (
2637 vl_api_vnet_get_summary_stats_t *mp)
2639 stats_main_t * sm = &stats_main;
2640 vnet_interface_main_t * im = sm->interface_main;
2641 vl_api_vnet_summary_stats_reply_t *rmp;
2642 vlib_combined_counter_main_t * cm;
2645 u64 total_pkts[VLIB_N_RX_TX];
2646 u64 total_bytes[VLIB_N_RX_TX];
2648 unix_shared_memory_queue_t * q =
2649 vl_api_client_index_to_input_queue (mp->client_index);
2654 rmp = vl_msg_api_alloc (sizeof (*rmp));
2655 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2656 rmp->context = mp->context;
2659 memset (total_pkts, 0, sizeof (total_pkts));
2660 memset (total_bytes, 0, sizeof (total_bytes));
2662 vnet_interface_counter_lock (im);
2664 vec_foreach (cm, im->combined_sw_if_counters) {
2665 which = cm - im->combined_sw_if_counters;
2667 for (i = 0; i < vec_len (cm->maxi); i++) {
2668 vlib_get_combined_counter (cm, i, &v);
2669 total_pkts[which] += v.packets;
2670 total_bytes[which] += v.bytes;
2673 vnet_interface_counter_unlock (im);
2675 /* Note: in HOST byte order! */
2676 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2677 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2678 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2679 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2680 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2682 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2685 typedef CLIB_PACKED (struct {
2686 ip4_address_t address;
2688 u32 address_length : 6;
2693 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2695 vnet_main_t * vnm = vnet_get_main();
2696 vnet_interface_main_t * im = &vnm->interface_main;
2697 ip4_main_t * im4 = &ip4_main;
2698 static ip4_route_t * routes;
2699 static u32 * sw_if_indices_to_shut;
2700 stats_main_t * sm = &stats_main;
2705 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2706 u32 target_fib_id = ntohl(mp->vrf_id);
2708 dslock (sm, 1 /* release hint */, 8 /* tag */);
2710 vec_foreach (fib, im4->fibs) {
2711 vnet_sw_interface_t * si;
2713 if (fib->table_id != target_fib_id)
2716 /* remove any mpls/gre tunnels in this fib */
2717 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2719 /* remove any mpls encap/decap labels */
2720 mpls_fib_reset_labels (fib->table_id);
2722 /* remove any proxy arps in this fib */
2723 vnet_proxy_arp_fib_reset (fib->table_id);
2725 /* Set the flow hash for this fib to the default */
2726 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2728 vec_reset_length (sw_if_indices_to_shut);
2730 /* Shut down interfaces in this FIB / clean out intfc routes */
2731 pool_foreach (si, im->sw_interfaces,
2733 u32 sw_if_index = si->sw_if_index;
2735 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2736 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2738 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2741 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2742 sw_if_index = sw_if_indices_to_shut[i];
2743 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2745 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2746 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2747 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2750 vec_reset_length (routes);
2752 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2753 uword * hash = fib->adj_index_by_dst_address[i];
2757 x.address_length = i;
2759 hash_foreach_pair (p, hash,
2761 x.address.data_u32 = p->key;
2762 vec_add1 (routes, x);
2766 vec_foreach (r, routes) {
2767 ip4_add_del_route_args_t a;
2769 memset (&a, 0, sizeof (a));
2770 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2771 a.table_index_or_table_id = fib - im4->fibs;
2772 a.dst_address = r->address;
2773 a.dst_address_length = r->address_length;
2776 ip4_add_del_route (im4, &a);
2777 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2778 IP4_ROUTE_FLAG_FIB_INDEX);
2782 } /* vec_foreach (fib) */
2789 ip6_address_t address;
2796 ip6_route_t ** routep;
2797 } add_routes_in_fib_arg_t;
2799 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2801 add_routes_in_fib_arg_t * ap = arg;
2803 if (kvp->key[2]>>32 == ap->fib_index)
2805 ip6_address_t *addr;
2807 addr = (ip6_address_t *) kvp;
2808 vec_add2 (*ap->routep, r, 1);
2809 r->address = addr[0];
2810 r->address_length = kvp->key[2] & 0xFF;
2811 r->index = kvp->value;
2815 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2817 vnet_main_t * vnm = vnet_get_main();
2818 vnet_interface_main_t * im = &vnm->interface_main;
2819 ip6_main_t * im6 = &ip6_main;
2820 stats_main_t * sm = &stats_main;
2821 static ip6_route_t * routes;
2822 static u32 * sw_if_indices_to_shut;
2827 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2828 u32 target_fib_id = ntohl(mp->vrf_id);
2829 add_routes_in_fib_arg_t _a, *a=&_a;
2830 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2832 dslock (sm, 1 /* release hint */, 9 /* tag */);
2834 vec_foreach (fib, im6->fibs) {
2835 vnet_sw_interface_t * si;
2837 if (fib->table_id != target_fib_id)
2840 vec_reset_length (sw_if_indices_to_shut);
2842 /* Shut down interfaces in this FIB / clean out intfc routes */
2843 pool_foreach (si, im->sw_interfaces,
2845 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2847 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2850 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2851 sw_if_index = sw_if_indices_to_shut[i];
2852 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2854 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2855 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2856 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2859 vec_reset_length (routes);
2861 a->fib_index = fib - im6->fibs;
2862 a->routep = &routes;
2864 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2866 vec_foreach (r, routes) {
2867 ip6_add_del_route_args_t a;
2869 memset (&a, 0, sizeof (a));
2870 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2871 a.table_index_or_table_id = fib - im6->fibs;
2872 a.dst_address = r->address;
2873 a.dst_address_length = r->address_length;
2876 ip6_add_del_route (im6, &a);
2877 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2878 IP6_ROUTE_FLAG_FIB_INDEX);
2881 /* Reinstall the neighbor / router discovery routes */
2882 vnet_ip6_fib_init (im6, fib - im6->fibs);
2884 } /* vec_foreach (fib) */
2890 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2893 vl_api_reset_fib_reply_t * rmp;
2896 rv = ip6_reset_fib_t_handler (mp);
2898 rv = ip4_reset_fib_t_handler (mp);
2900 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2905 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2907 vl_api_dhcp_proxy_config_reply_t * rmp;
2910 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2911 (ip4_address_t *)(&mp->dhcp_src_address),
2912 (u32) ntohl(mp->vrf_id),
2913 (int) mp->insert_circuit_id,
2914 (int) (mp->is_add == 0));
2916 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2921 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2923 vl_api_dhcp_proxy_config_reply_t * rmp;
2926 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2927 (ip6_address_t *)(&mp->dhcp_src_address),
2928 (u32) ntohl(mp->vrf_id),
2929 (int) mp->insert_circuit_id,
2930 (int) (mp->is_add == 0));
2932 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2936 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2938 vl_api_dhcp_proxy_config_reply_t * rmp;
2941 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2942 (ip4_address_t *)(&mp->dhcp_src_address),
2943 (u32) ntohl(mp->rx_vrf_id),
2944 (u32) ntohl(mp->server_vrf_id),
2945 (int) mp->insert_circuit_id,
2946 (int) (mp->is_add == 0));
2948 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2953 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2955 vl_api_dhcp_proxy_config_reply_t * rmp;
2959 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2960 (ip6_address_t *)(&mp->dhcp_src_address),
2961 (u32) ntohl(mp->rx_vrf_id),
2962 (u32) ntohl(mp->server_vrf_id),
2963 (int) mp->insert_circuit_id,
2964 (int) (mp->is_add == 0));
2966 rv = VNET_API_ERROR_UNIMPLEMENTED;
2969 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2974 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2976 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2979 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2982 (int)mp->is_add == 0);
2984 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2987 (int)mp->is_add == 0);
2989 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2993 static void vl_api_dhcp_proxy_config_t_handler
2994 (vl_api_dhcp_proxy_config_t *mp)
2996 if (mp->is_ipv6 == 0)
2997 dhcpv4_proxy_config (mp);
2999 dhcpv6_proxy_config (mp);
3002 static void vl_api_dhcp_proxy_config_2_t_handler
3003 (vl_api_dhcp_proxy_config_2_t *mp)
3005 if (mp->is_ipv6 == 0)
3006 dhcpv4_proxy_config_2 (mp);
3008 dhcpv6_proxy_config_2 (mp);
3011 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3012 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3014 unix_shared_memory_queue_t * q;
3015 vl_api_dhcp_compl_event_t * mp;
3017 q = vl_api_client_index_to_input_queue (client_index);
3021 mp = vl_msg_api_alloc (sizeof (*mp));
3022 mp->client_index = client_index;
3024 mp->is_ipv6 = is_ipv6;
3025 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3026 mp->hostname[vec_len(hostname) + 1] = '\n';
3027 clib_memcpy (&mp->host_address[0], host_address, 16);
3028 clib_memcpy (&mp->router_address[0], router_address, 16);
3029 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3031 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3033 vl_msg_api_send_shmem (q, (u8 *)&mp);
3036 static void vl_api_dhcp_client_config_t_handler
3037 (vl_api_dhcp_client_config_t *mp)
3039 vlib_main_t *vm = vlib_get_main();
3040 vl_api_dhcp_client_config_reply_t * rmp;
3043 VALIDATE_SW_IF_INDEX(mp);
3045 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3046 mp->hostname, mp->is_add, mp->client_index,
3047 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3050 BAD_SW_IF_INDEX_LABEL;
3052 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3056 vl_api_sw_interface_ip6nd_ra_config_t_handler
3057 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3059 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3061 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3063 is_no = mp->is_no == 1;
3064 surpress = mp->surpress == 1;
3065 managed = mp->managed == 1;
3066 other = mp->other == 1;
3067 ll_option = mp->ll_option == 1;
3068 send_unicast = mp->send_unicast == 1;
3069 cease = mp->cease == 1;
3070 default_router = mp->default_router == 1;
3072 VALIDATE_SW_IF_INDEX(mp);
3074 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3075 surpress, managed, other,
3076 ll_option, send_unicast, cease,
3077 default_router, ntohl (mp->lifetime),
3078 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3079 ntohl(mp->max_interval), ntohl( mp->min_interval),
3082 BAD_SW_IF_INDEX_LABEL;
3084 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3088 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3089 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3091 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3093 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3095 VALIDATE_SW_IF_INDEX(mp);
3097 is_no = mp->is_no == 1;
3098 use_default = mp->use_default == 1;
3099 no_advertise = mp->no_advertise == 1;
3100 off_link = mp->off_link == 1;
3101 no_autoconfig = mp->no_autoconfig == 1;
3102 no_onlink = mp->no_onlink == 1;
3104 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3105 (ip6_address_t *)mp->address, mp->address_length,
3106 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3107 no_advertise, off_link, no_autoconfig, no_onlink,
3110 BAD_SW_IF_INDEX_LABEL;
3111 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3115 vl_api_sw_interface_ip6_enable_disable_t_handler
3116 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3118 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3119 vnet_main_t * vnm = vnet_get_main();
3121 clib_error_t * error;
3125 VALIDATE_SW_IF_INDEX(mp);
3127 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3128 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3131 clib_error_report(error);
3132 rv = VNET_API_ERROR_UNSPECIFIED;
3134 rv = vnm->api_errno;
3137 BAD_SW_IF_INDEX_LABEL;
3139 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3143 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3144 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3146 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3148 clib_error_t * error;
3149 vnet_main_t * vnm = vnet_get_main();
3153 VALIDATE_SW_IF_INDEX(mp);
3155 error = set_ip6_link_local_address(vm,
3156 ntohl(mp->sw_if_index),
3157 (ip6_address_t *)mp->address,
3158 mp->address_length);
3160 clib_error_report(error);
3161 rv = VNET_API_ERROR_UNSPECIFIED;
3163 rv = vnm->api_errno;
3166 BAD_SW_IF_INDEX_LABEL;
3168 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3171 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3173 vl_api_set_ip_flow_hash_reply_t *rmp;
3174 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3176 clib_warning ("unimplemented...");
3178 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3181 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3183 vl_api_set_ip_flow_hash_reply_t *rmp;
3186 u32 flow_hash_config = 0;
3188 table_id = ntohl(mp->vrf_id);
3190 #define _(a,b) if (mp->a) flow_hash_config |= b;
3191 foreach_flow_hash_bit;
3194 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3196 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3200 static void vl_api_set_ip_flow_hash_t_handler
3201 (vl_api_set_ip_flow_hash_t *mp)
3203 if (mp->is_ipv6 == 0)
3204 set_ip4_flow_hash (mp);
3206 set_ip6_flow_hash (mp);
3209 static void vl_api_sw_interface_set_unnumbered_t_handler
3210 (vl_api_sw_interface_set_unnumbered_t *mp)
3212 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3214 vnet_sw_interface_t * si;
3215 vnet_main_t *vnm = vnet_get_main();
3216 u32 sw_if_index, unnumbered_sw_if_index;
3218 sw_if_index = ntohl(mp->sw_if_index);
3219 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3222 * The API message field names are backwards from
3223 * the underlying data structure names.
3224 * It's not worth changing them now.
3226 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3227 unnumbered_sw_if_index)) {
3228 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3232 /* Only check the "use loop0" field when setting the binding */
3234 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3235 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3239 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3242 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3243 si->unnumbered_sw_if_index = sw_if_index;
3245 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3246 si->unnumbered_sw_if_index = (u32)~0;
3250 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3253 static void vl_api_create_loopback_t_handler
3254 (vl_api_create_loopback_t *mp)
3256 vl_api_create_loopback_reply_t * rmp;
3260 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3262 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3264 rmp->sw_if_index = ntohl (sw_if_index);
3268 static void vl_api_delete_loopback_t_handler
3269 (vl_api_delete_loopback_t *mp)
3271 vl_api_delete_loopback_reply_t * rmp;
3275 sw_if_index = ntohl (mp->sw_if_index);
3276 rv = vnet_delete_loopback_interface (sw_if_index);
3278 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3281 static void vl_api_control_ping_t_handler
3282 (vl_api_control_ping_t *mp)
3284 vl_api_control_ping_reply_t * rmp;
3287 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3289 rmp->vpe_pid = ntohl (getpid());
3293 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3295 u8 **shmem_vecp = (u8 **)arg;
3298 api_main_t * am = &api_main;
3301 shmem_vec = *shmem_vecp;
3303 offset = vec_len (shmem_vec);
3305 pthread_mutex_lock (&am->vlib_rp->mutex);
3306 oldheap = svm_push_data_heap (am->vlib_rp);
3308 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3310 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3312 svm_pop_heap (oldheap);
3313 pthread_mutex_unlock (&am->vlib_rp->mutex);
3315 *shmem_vecp = shmem_vec;
3319 static void vl_api_cli_request_t_handler
3320 (vl_api_cli_request_t *mp)
3322 vl_api_cli_reply_t *rp;
3323 unix_shared_memory_queue_t *q;
3324 vlib_main_t * vm = vlib_get_main();
3325 api_main_t * am = &api_main;
3326 unformat_input_t input;
3330 q = vl_api_client_index_to_input_queue (mp->client_index);
3334 rp = vl_msg_api_alloc (sizeof (*rp));
3335 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3336 rp->context = mp->context;
3338 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3340 vlib_cli_input (vm, &input, shmem_cli_output,
3343 pthread_mutex_lock (&am->vlib_rp->mutex);
3344 oldheap = svm_push_data_heap (am->vlib_rp);
3346 vec_add1(shmem_vec, 0);
3348 svm_pop_heap (oldheap);
3349 pthread_mutex_unlock (&am->vlib_rp->mutex);
3351 rp->reply_in_shmem = (uword)shmem_vec;
3353 vl_msg_api_send_shmem (q, (u8 *)&rp);
3356 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3359 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3360 vnet_main_t *vnm = vnet_get_main();
3361 clib_error_t * error;
3366 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3368 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3371 clib_error_report(error);
3372 rv = VNET_API_ERROR_UNSPECIFIED;
3374 rv = vnm->api_errno;
3377 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3380 static void vl_api_sr_tunnel_add_del_t_handler
3381 (vl_api_sr_tunnel_add_del_t *mp)
3384 clib_warning ("unimplemented");
3386 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3388 vl_api_sr_tunnel_add_del_reply_t * rmp;
3389 ip6_address_t * segments = 0, * seg;
3390 ip6_address_t * tags = 0, *tag;
3391 ip6_address_t * this_address;
3394 if (mp->n_segments == 0) {
3399 memset (a, 0, sizeof (*a));
3400 a->src_address = (ip6_address_t *)&mp->src_address;
3401 a->dst_address = (ip6_address_t *)&mp->dst_address;
3402 a->dst_mask_width = mp->dst_mask_width;
3403 a->flags_net_byte_order = mp->flags_net_byte_order;
3404 a->is_del = (mp->is_add == 0);
3405 a->rx_table_id = ntohl(mp->outer_vrf_id);
3406 a->tx_table_id = ntohl(mp->inner_vrf_id);
3408 a->name = format(0, "%s", mp->name);
3409 if (!(vec_len(a->name)))
3412 a->policy_name = format(0, "%s", mp->policy_name);
3413 if (!(vec_len(a->policy_name)))
3416 /* Yank segments and tags out of the API message */
3417 this_address = (ip6_address_t *)mp->segs_and_tags;
3418 for (i = 0; i < mp->n_segments; i++) {
3419 vec_add2 (segments, seg, 1);
3420 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3423 for (i = 0; i < mp->n_tags; i++) {
3424 vec_add2 (tags, tag, 1);
3425 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3429 a->segments = segments;
3432 rv = ip6_sr_add_del_tunnel (a);
3436 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3440 static void vl_api_sr_policy_add_del_t_handler
3441 (vl_api_sr_policy_add_del_t *mp)
3444 clib_warning ("unimplemented");
3446 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3448 vl_api_sr_policy_add_del_reply_t * rmp;
3451 memset (a, 0, sizeof (*a));
3452 a->is_del = (mp->is_add == 0);
3454 a->name = format(0, "%s", mp->name);
3455 if (!(vec_len(a->name)))
3457 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3461 if (!(mp->tunnel_names[0]))
3463 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3467 // start deserializing tunnel_names
3468 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3469 u8 * deser_tun_names = mp->tunnel_names;
3470 deser_tun_names += 1; //moving along
3473 int tun_name_len = 0;
3475 for (i=0; i < num_tunnels; i++)
3477 tun_name_len= *deser_tun_names;
3478 deser_tun_names += 1;
3479 vec_resize (tun_name, tun_name_len);
3480 memcpy(tun_name, deser_tun_names, tun_name_len);
3481 vec_add1 (a->tunnel_names, tun_name);
3482 deser_tun_names += tun_name_len;
3486 rv = ip6_sr_add_del_policy (a);
3490 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3494 static void vl_api_sr_multicast_map_add_del_t_handler
3495 (vl_api_sr_multicast_map_add_del_t *mp)
3498 clib_warning ("unimplemented");
3500 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3502 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3504 memset (a, 0, sizeof (*a));
3505 a->is_del = (mp->is_add == 0);
3507 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3508 a->policy_name = format(0, "%s", mp->policy_name);
3510 if (a->multicast_address == 0)
3516 if (!(a->policy_name))
3522 #if DPDK > 0 /* Cannot call replicate without DPDK */
3523 rv = ip6_sr_add_del_multicastmap (a);
3525 clib_warning ("multicast replication without DPDK not implemented");
3526 rv = VNET_API_ERROR_UNIMPLEMENTED;
3531 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3535 #define foreach_classify_add_del_table_field \
3540 _(match_n_vectors) \
3541 _(next_table_index) \
3544 static void vl_api_classify_add_del_table_t_handler
3545 (vl_api_classify_add_del_table_t * mp)
3547 vl_api_classify_add_del_table_reply_t * rmp;
3548 vnet_classify_main_t * cm = &vnet_classify_main;
3549 vnet_classify_table_t * t;
3553 foreach_classify_add_del_table_field;
3556 #define _(a) a = ntohl(mp->a);
3557 foreach_classify_add_del_table_field;
3560 /* The underlying API fails silently, on purpose, so check here */
3561 if (mp->is_add == 0)
3562 if (pool_is_free_index (cm->tables, table_index)) {
3563 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3567 rv = vnet_classify_add_del_table
3568 (cm, mp->mask, nbuckets, memory_size,
3569 skip_n_vectors, match_n_vectors,
3570 next_table_index, miss_next_index,
3571 &table_index, mp->is_add);
3574 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3576 if (rv == 0 && mp->is_add) {
3577 t = pool_elt_at_index (cm->tables, table_index);
3578 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3579 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3580 rmp->new_table_index = ntohl(table_index);
3582 rmp->skip_n_vectors = ~0;
3583 rmp->match_n_vectors = ~0;
3584 rmp->new_table_index = ~0;
3589 static void vl_api_classify_add_del_session_t_handler
3590 (vl_api_classify_add_del_session_t * mp)
3592 vnet_classify_main_t * cm = &vnet_classify_main;
3593 vl_api_classify_add_del_session_reply_t * rmp;
3595 u32 table_index, hit_next_index, opaque_index;
3598 table_index = ntohl (mp->table_index);
3599 hit_next_index = ntohl (mp->hit_next_index);
3600 opaque_index = ntohl (mp->opaque_index);
3601 advance = ntohl (mp->advance);
3603 rv = vnet_classify_add_del_session
3604 (cm, table_index, mp->match, hit_next_index, opaque_index,
3605 advance, mp->is_add);
3607 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3610 static void vl_api_classify_set_interface_ip_table_t_handler
3611 (vl_api_classify_set_interface_ip_table_t * mp)
3613 vlib_main_t * vm = vlib_get_main();
3614 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3616 u32 table_index, sw_if_index;
3618 table_index = ntohl (mp->table_index);
3619 sw_if_index = ntohl (mp->sw_if_index);
3621 VALIDATE_SW_IF_INDEX(mp);
3624 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3626 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3628 BAD_SW_IF_INDEX_LABEL;
3630 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3633 static void vl_api_classify_set_interface_l2_tables_t_handler
3634 (vl_api_classify_set_interface_l2_tables_t * mp)
3636 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3638 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3641 ip4_table_index = ntohl(mp->ip4_table_index);
3642 ip6_table_index = ntohl(mp->ip6_table_index);
3643 other_table_index = ntohl(mp->other_table_index);
3644 sw_if_index = ntohl(mp->sw_if_index);
3646 VALIDATE_SW_IF_INDEX(mp);
3648 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3649 ip6_table_index, other_table_index);
3652 if (ip4_table_index != ~0 || ip6_table_index != ~0
3653 || other_table_index != ~0)
3658 vnet_l2_classify_enable_disable (sw_if_index, enable);
3661 BAD_SW_IF_INDEX_LABEL;
3663 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3667 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3670 vl_api_l2_fib_clear_table_reply_t * rmp;
3672 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3673 * that is not currently implemented. When that TODO is fixed
3674 * this call should be changed to pass 1 instead of 0.
3676 l2fib_clear_table (0);
3678 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3681 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3686 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3689 vl_api_l2_interface_efp_filter_reply_t * rmp;
3690 vnet_main_t *vnm = vnet_get_main();
3692 // enable/disable the feature
3693 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3694 rv = vnm->api_errno;
3696 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3700 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3703 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3704 vnet_main_t * vnm = vnet_get_main();
3705 vlib_main_t * vm = vlib_get_main();
3708 VALIDATE_SW_IF_INDEX(mp);
3710 vtr_op = ntohl(mp->vtr_op);
3712 /* The L2 code is unsuspicious */
3714 case L2_VTR_DISABLED:
3719 case L2_VTR_TRANSLATE_1_1:
3720 case L2_VTR_TRANSLATE_1_2:
3721 case L2_VTR_TRANSLATE_2_1:
3722 case L2_VTR_TRANSLATE_2_2:
3726 rv = VNET_API_ERROR_INVALID_VALUE;
3727 goto bad_sw_if_index;
3730 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3731 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3734 BAD_SW_IF_INDEX_LABEL;
3736 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3740 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3744 vl_api_create_vhost_user_if_reply_t * rmp;
3745 u32 sw_if_index = (u32)~0;
3747 vnet_main_t * vnm = vnet_get_main();
3748 vlib_main_t * vm = vlib_get_main();
3750 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3751 mp->is_server, &sw_if_index, (u64)~0,
3752 mp->renumber, ntohl(mp->custom_dev_instance),
3753 (mp->use_custom_mac)?mp->mac_address:NULL);
3755 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3757 rmp->sw_if_index = ntohl (sw_if_index);
3763 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3767 vl_api_modify_vhost_user_if_reply_t * rmp;
3768 u32 sw_if_index = ntohl(mp->sw_if_index);
3770 vnet_main_t * vnm = vnet_get_main();
3771 vlib_main_t * vm = vlib_get_main();
3773 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3774 mp->is_server, sw_if_index, (u64)~0,
3775 mp->renumber, ntohl(mp->custom_dev_instance));
3777 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3782 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3786 vpe_api_main_t * vam = &vpe_api_main;
3787 vl_api_delete_vhost_user_if_reply_t * rmp;
3788 u32 sw_if_index = ntohl(mp->sw_if_index);
3790 vnet_main_t * vnm = vnet_get_main();
3791 vlib_main_t * vm = vlib_get_main();
3793 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3795 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3797 unix_shared_memory_queue_t * q =
3798 vl_api_client_index_to_input_queue (mp->client_index);
3802 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3807 static void vl_api_sw_interface_vhost_user_details_t_handler (
3808 vl_api_sw_interface_vhost_user_details_t * mp)
3810 clib_warning ("BUG");
3814 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3815 unix_shared_memory_queue_t *q,
3816 vhost_user_intf_details_t * vui,
3819 vl_api_sw_interface_vhost_user_details_t * mp;
3821 mp = vl_msg_api_alloc (sizeof (*mp));
3822 memset (mp, 0, sizeof (*mp));
3823 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3824 mp->sw_if_index = ntohl(vui->sw_if_index);
3825 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3826 mp->features = clib_net_to_host_u64 (vui->features);
3827 mp->is_server = vui->is_server;
3828 mp->num_regions = ntohl(vui->num_regions);
3829 mp->sock_errno = ntohl(vui->sock_errno);
3830 mp->context = context;
3832 strncpy ((char *) mp->sock_filename,
3833 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3834 strncpy ((char *) mp->interface_name,
3835 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3837 vl_msg_api_send_shmem (q, (u8 *)&mp);
3842 vl_api_sw_interface_vhost_user_dump_t_handler (
3843 vl_api_sw_interface_vhost_user_dump_t *mp)
3847 vpe_api_main_t * am = &vpe_api_main;
3848 vnet_main_t * vnm = vnet_get_main();
3849 vlib_main_t * vm = vlib_get_main();
3850 vhost_user_intf_details_t *ifaces = NULL;
3851 vhost_user_intf_details_t *vuid = NULL;
3852 unix_shared_memory_queue_t * q;
3854 q = vl_api_client_index_to_input_queue (mp->client_index);
3858 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3862 vec_foreach (vuid, ifaces) {
3863 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3869 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3870 unix_shared_memory_queue_t *q,
3875 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3876 u8 * if_name = NULL;
3877 vnet_sw_interface_t * si = NULL;
3879 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3881 if_name = format(if_name, "%U",
3882 format_vnet_sw_interface_name, lm->vnet_main, si);
3884 mp = vl_msg_api_alloc (sizeof (*mp));
3885 memset (mp, 0, sizeof (*mp));
3886 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3887 strncpy((char *)mp->interface_name,
3888 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3889 mp->sw_if_index = ntohl(si->sw_if_index);
3890 mp->local_session_id = s->local_session_id;
3891 mp->remote_session_id = s->remote_session_id;
3892 mp->local_cookie[0] = s->local_cookie[0];
3893 mp->local_cookie[1] = s->local_cookie[1];
3894 mp->remote_cookie = s->remote_cookie;
3895 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3896 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3897 mp->l2_sublayer_present = s->l2_sublayer_present;
3898 mp->context = context;
3900 vl_msg_api_send_shmem (q, (u8 *)&mp);
3903 static void send_ip_address_details (vpe_api_main_t * am,
3904 unix_shared_memory_queue_t * q,
3910 vl_api_ip_address_details_t * mp;
3912 mp = vl_msg_api_alloc (sizeof (*mp));
3913 memset (mp, 0, sizeof (*mp));
3914 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3917 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3919 u32 * tp = (u32 *)mp->ip;
3920 *tp = ntohl(*(u32*)ip);
3922 mp->prefix_length = prefix_length;
3923 mp->context = context;
3925 vl_msg_api_send_shmem (q, (u8 *)&mp);
3929 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3931 vpe_api_main_t * am = &vpe_api_main;
3932 unix_shared_memory_queue_t * q;
3935 ip6_main_t * im6 = &ip6_main;
3936 ip4_main_t * im4 = &ip4_main;
3937 ip_lookup_main_t * lm6 = &im6->lookup_main;
3938 ip_lookup_main_t * lm4 = &im4->lookup_main;
3939 ip_interface_address_t * ia = 0;
3940 u32 sw_if_index = ~0;
3941 int rv __attribute__ ((unused)) = 0;
3943 VALIDATE_SW_IF_INDEX(mp);
3945 sw_if_index = ntohl(mp->sw_if_index);
3947 q = vl_api_client_index_to_input_queue (mp->client_index);
3953 foreach_ip_interface_address (lm6, ia, sw_if_index,
3954 1 /* honor unnumbered */,
3956 r6 = ip_interface_address_get_address (lm6, ia);
3957 u16 prefix_length = ia->address_length;
3958 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3961 foreach_ip_interface_address (lm4, ia, sw_if_index,
3962 1 /* honor unnumbered */,
3964 r4 = ip_interface_address_get_address (lm4, ia);
3965 u16 prefix_length = ia->address_length;
3966 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3969 BAD_SW_IF_INDEX_LABEL;
3972 static void send_ip_details (vpe_api_main_t * am,
3973 unix_shared_memory_queue_t *q,
3977 vl_api_ip_details_t * mp;
3979 mp = vl_msg_api_alloc (sizeof (*mp));
3980 memset (mp, 0, sizeof (*mp));
3981 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3983 mp->sw_if_index = ntohl(sw_if_index);
3984 mp->context = context;
3986 vl_msg_api_send_shmem (q, (u8 *)&mp);
3990 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3991 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3993 vpe_api_main_t * am = &vpe_api_main;
3994 l2t_main_t * lm = &l2t_main;
3995 unix_shared_memory_queue_t * q;
3996 l2t_session_t *session;
3998 q = vl_api_client_index_to_input_queue (mp->client_index);
4002 pool_foreach (session, lm->sessions,
4004 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4009 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4010 unix_shared_memory_queue_t *q,
4011 tapcli_interface_details_t *tap_if,
4014 vl_api_sw_interface_tap_details_t * mp;
4015 mp = vl_msg_api_alloc (sizeof (*mp));
4016 memset (mp, 0, sizeof (*mp));
4017 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4018 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4019 strncpy((char *)mp->dev_name,
4020 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4021 mp->context = context;
4023 vl_msg_api_send_shmem (q, (u8 *)&mp);
4027 vl_api_sw_interface_tap_dump_t_handler (
4028 vl_api_sw_interface_tap_dump_t *mp)
4031 vpe_api_main_t * am = &vpe_api_main;
4032 unix_shared_memory_queue_t * q;
4033 tapcli_interface_details_t *tapifs = NULL;
4034 tapcli_interface_details_t *tap_if = NULL;
4036 q = vl_api_client_index_to_input_queue (mp->client_index);
4040 rv = vnet_tap_dump_ifs(&tapifs);
4044 vec_foreach(tap_if, tapifs) {
4045 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4052 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4054 vpe_api_main_t * am = &vpe_api_main;
4055 vnet_main_t * vnm = vnet_get_main();
4056 vlib_main_t * vm = vlib_get_main();
4057 vnet_interface_main_t * im = &vnm->interface_main;
4058 unix_shared_memory_queue_t * q;
4059 vnet_sw_interface_t * si, * sorted_sis;
4060 u32 sw_if_index = ~0;
4062 q = vl_api_client_index_to_input_queue (mp->client_index);
4067 /* Gather interfaces. */
4068 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4069 _vec_len (sorted_sis) = 0;
4070 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4072 vec_foreach (si, sorted_sis) {
4073 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4074 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4077 sw_if_index = si->sw_if_index;
4078 send_ip_details(am, q, sw_if_index, mp->context);
4083 static void vl_api_l2_fib_table_entry_t_handler (
4084 vl_api_l2_fib_table_entry_t * mp)
4086 clib_warning ("BUG");
4089 static void send_l2fib_table_entry (vpe_api_main_t * am,
4090 unix_shared_memory_queue_t *q,
4091 l2fib_entry_key_t * l2fe_key,
4092 l2fib_entry_result_t * l2fe_res,
4095 vl_api_l2_fib_table_entry_t * mp;
4097 mp = vl_msg_api_alloc (sizeof (*mp));
4098 memset (mp, 0, sizeof (*mp));
4099 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4101 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4103 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4104 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4105 mp->static_mac = l2fe_res->fields.static_mac;
4106 mp->filter_mac = l2fe_res->fields.filter;
4107 mp->bvi_mac = l2fe_res->fields.bvi;
4108 mp->context = context;
4110 vl_msg_api_send_shmem (q, (u8 *)&mp);
4114 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4116 vpe_api_main_t * am = &vpe_api_main;
4117 bd_main_t * bdm = &bd_main;
4118 l2fib_entry_key_t *l2fe_key = NULL;
4119 l2fib_entry_result_t *l2fe_res = NULL;
4120 u32 ni, bd_id = ntohl (mp->bd_id);
4122 unix_shared_memory_queue_t * q;
4125 q = vl_api_client_index_to_input_queue (mp->client_index);
4129 /* see l2fib_table_dump: ~0 means "any" */
4133 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4140 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4142 vec_foreach_index (ni, l2fe_key) {
4143 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4144 vec_elt_at_index(l2fe_res, ni), mp->context);
4151 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4153 vl_api_show_version_reply_t *rmp;
4155 char * vpe_api_get_build_directory(void);
4156 char * vpe_api_get_version(void);
4157 char * vpe_api_get_build_date(void);
4159 unix_shared_memory_queue_t * q =
4160 vl_api_client_index_to_input_queue (mp->client_index);
4165 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4167 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4168 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4169 ARRAY_LEN(rmp->build_directory)-1);
4170 strncpy ((char *) rmp->version, vpe_api_get_version(),
4171 ARRAY_LEN(rmp->version)-1);
4172 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4173 ARRAY_LEN(rmp->build_date)-1);
4177 static void vl_api_get_node_index_t_handler
4178 (vl_api_get_node_index_t * mp)
4180 vlib_main_t * vm = vlib_get_main();
4181 vl_api_get_node_index_reply_t * rmp;
4184 u32 node_index = ~0;
4186 n = vlib_get_node_by_name (vm, mp->node_name);
4189 rv = VNET_API_ERROR_NO_SUCH_NODE;
4191 node_index = n->index;
4193 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4195 rmp->node_index = ntohl(node_index);
4199 static void vl_api_add_node_next_t_handler
4200 (vl_api_add_node_next_t * mp)
4202 vlib_main_t * vm = vlib_get_main();
4203 vl_api_add_node_next_reply_t * rmp;
4204 vlib_node_t * n, * next;
4206 u32 next_index = ~0;
4208 n = vlib_get_node_by_name (vm, mp->node_name);
4211 rv = VNET_API_ERROR_NO_SUCH_NODE;
4215 next = vlib_get_node_by_name (vm, mp->next_name);
4218 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4220 next_index = vlib_node_add_next (vm, n->index, next->index);
4223 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4225 rmp->next_index = ntohl(next_index);
4229 static void vl_api_l2tpv3_create_tunnel_t_handler
4230 (vl_api_l2tpv3_create_tunnel_t *mp)
4232 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4233 l2t_main_t *lm = &l2t_main;
4234 u32 sw_if_index = (u32)~0;
4237 if (mp->is_ipv6 != 1) {
4238 rv = VNET_API_ERROR_UNIMPLEMENTED;
4242 rv = create_l2tpv3_ipv6_tunnel (lm,
4243 (ip6_address_t *) mp->client_address,
4244 (ip6_address_t *) mp->our_address,
4245 ntohl(mp->local_session_id),
4246 ntohl(mp->remote_session_id),
4247 clib_net_to_host_u64(mp->local_cookie),
4248 clib_net_to_host_u64(mp->remote_cookie),
4249 mp->l2_sublayer_present,
4253 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4255 rmp->sw_if_index = ntohl (sw_if_index);
4259 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4260 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4262 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4263 l2t_main_t *lm = &l2t_main;
4266 VALIDATE_SW_IF_INDEX(mp);
4268 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4269 clib_net_to_host_u64(mp->new_local_cookie),
4270 clib_net_to_host_u64(mp->new_remote_cookie));
4272 BAD_SW_IF_INDEX_LABEL;
4274 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4277 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4278 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4281 vnet_main_t * vnm = vnet_get_main();
4282 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4284 VALIDATE_SW_IF_INDEX(mp);
4286 rv = l2tpv3_interface_enable_disable
4287 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4289 BAD_SW_IF_INDEX_LABEL;
4291 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4294 static void vl_api_l2tpv3_set_lookup_key_t_handler
4295 (vl_api_l2tpv3_set_lookup_key_t * mp)
4298 l2t_main_t *lm = &l2t_main;
4299 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4301 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4302 rv = VNET_API_ERROR_INVALID_VALUE;
4306 lm->lookup_type = mp->key;
4309 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4312 static void vl_api_vxlan_add_del_tunnel_t_handler
4313 (vl_api_vxlan_add_del_tunnel_t * mp)
4315 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4317 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4318 u32 encap_fib_index;
4320 ip4_main_t * im = &ip4_main;
4321 u32 sw_if_index = ~0;
4323 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4325 rv = VNET_API_ERROR_NO_SUCH_FIB;
4328 encap_fib_index = p[0];
4330 /* Check src & dst are different */
4331 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4332 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4333 rv = VNET_API_ERROR_SAME_SRC_DST;
4336 memset (a, 0, sizeof (*a));
4338 a->is_add = mp->is_add;
4339 a->is_ip6 = mp->is_ipv6;
4341 /* ip addresses sent in network byte order */
4343 memcpy(&(a->src.ip6), mp->src_address, 16);
4344 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4346 memcpy(&(a->src.ip4), mp->src_address, 4);
4347 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4350 a->encap_fib_index = encap_fib_index;
4351 a->decap_next_index = ntohl(mp->decap_next_index);
4352 a->vni = ntohl(mp->vni);
4353 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4356 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4358 rmp->sw_if_index = ntohl (sw_if_index);
4362 static void send_vxlan_tunnel_details
4363 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4365 vl_api_vxlan_tunnel_details_t * rmp;
4366 ip4_main_t * im4 = &ip4_main;
4367 ip6_main_t * im6 = &ip6_main;
4368 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4370 rmp = vl_msg_api_alloc (sizeof (*rmp));
4371 memset (rmp, 0, sizeof (*rmp));
4372 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4374 memcpy(rmp->src_address, &(t->src.ip6), 16);
4375 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4376 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4378 memcpy(rmp->src_address, &(t->src.ip4), 4);
4379 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4380 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4382 rmp->vni = htonl(t->vni);
4383 rmp->decap_next_index = htonl(t->decap_next_index);
4384 rmp->sw_if_index = htonl(t->sw_if_index);
4385 rmp->is_ipv6 = is_ipv6;
4386 rmp->context = context;
4388 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4391 static void vl_api_vxlan_tunnel_dump_t_handler
4392 (vl_api_vxlan_tunnel_dump_t * mp)
4394 unix_shared_memory_queue_t * q;
4395 vxlan_main_t * vxm = &vxlan_main;
4399 q = vl_api_client_index_to_input_queue (mp->client_index);
4404 sw_if_index = ntohl(mp->sw_if_index);
4406 if (~0 == sw_if_index) {
4407 pool_foreach (t, vxm->tunnels,
4409 send_vxlan_tunnel_details(t, q, mp->context);
4412 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4413 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4416 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4417 send_vxlan_tunnel_details(t, q, mp->context);
4421 static void vl_api_gre_add_del_tunnel_t_handler
4422 (vl_api_gre_add_del_tunnel_t * mp)
4424 vl_api_gre_add_del_tunnel_reply_t * rmp;
4426 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4429 ip4_main_t * im = &ip4_main;
4430 u32 sw_if_index = ~0;
4432 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4434 rv = VNET_API_ERROR_NO_SUCH_FIB;
4437 outer_table_id = p[0];
4439 /* Check src & dst are different */
4440 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4441 rv = VNET_API_ERROR_SAME_SRC_DST;
4445 memset (a, 0, sizeof (*a));
4447 a->is_add = mp->is_add;
4449 /* ip addresses sent in network byte order */
4450 a->src.as_u32 = mp->src_address;
4451 a->dst.as_u32 = mp->dst_address;
4453 a->outer_table_id = outer_table_id;
4454 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4457 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4459 rmp->sw_if_index = ntohl (sw_if_index);
4463 static void send_gre_tunnel_details
4464 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4466 vl_api_gre_tunnel_details_t * rmp;
4467 ip4_main_t * im = &ip4_main;
4469 rmp = vl_msg_api_alloc (sizeof (*rmp));
4470 memset (rmp, 0, sizeof (*rmp));
4471 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4472 rmp->src_address = t->tunnel_src.data_u32;
4473 rmp->dst_address = t->tunnel_dst.data_u32;
4474 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4475 rmp->sw_if_index = htonl(t->sw_if_index);
4476 rmp->context = context;
4478 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4481 static void vl_api_gre_tunnel_dump_t_handler
4482 (vl_api_gre_tunnel_dump_t * mp)
4484 unix_shared_memory_queue_t * q;
4485 gre_main_t * gm = &gre_main;
4489 q = vl_api_client_index_to_input_queue (mp->client_index);
4494 sw_if_index = ntohl(mp->sw_if_index);
4496 if (~0 == sw_if_index) {
4497 pool_foreach (t, gm->tunnels,
4499 send_gre_tunnel_details(t, q, mp->context);
4502 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4503 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4506 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4507 send_gre_tunnel_details(t, q, mp->context);
4512 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4514 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4516 vl_api_l2_patch_add_del_reply_t * rmp;
4517 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4521 VALIDATE_RX_SW_IF_INDEX(mp);
4522 VALIDATE_TX_SW_IF_INDEX(mp);
4524 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4525 ntohl(mp->tx_sw_if_index),
4526 (int)(mp->is_add != 0));
4528 BAD_RX_SW_IF_INDEX_LABEL;
4529 BAD_TX_SW_IF_INDEX_LABEL;
4531 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4535 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4536 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4538 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4540 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4541 u32 encap_fib_index, decap_fib_index;
4544 ip4_main_t * im = &ip4_main;
4545 u32 sw_if_index = ~0;
4548 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4550 rv = VNET_API_ERROR_NO_SUCH_FIB;
4553 encap_fib_index = p[0];
4555 protocol = ntohl(mp->protocol);
4557 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4558 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4559 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4561 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4564 decap_fib_index = p[0];
4566 decap_fib_index = ntohl(mp->decap_vrf_id);
4569 memset (a, 0, sizeof (*a));
4571 a->is_add = mp->is_add;
4572 /* ip addresses sent in network byte order */
4573 a->local.as_u32 = ntohl(mp->local);
4574 a->remote.as_u32 = ntohl(mp->remote);
4575 a->encap_fib_index = encap_fib_index;
4576 a->decap_fib_index = decap_fib_index;
4577 a->protocol = protocol;
4578 a->vni = ntohl(mp->vni);
4579 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4582 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4584 rmp->sw_if_index = ntohl (sw_if_index);
4589 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4591 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4593 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4595 u8 *locator_name = NULL;
4597 memset(a, 0, sizeof(a[0]));
4599 locator_name = format(0, "%s", mp->locator_set_name);
4601 a->name = locator_name;
4603 a->is_add = mp->is_add;
4606 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4608 vec_free(locator_name);
4610 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4614 vl_api_lisp_add_del_locator_t_handler(
4615 vl_api_lisp_add_del_locator_t *mp)
4617 vl_api_lisp_add_del_locator_reply_t *rmp;
4619 locator_t locator, *locators = NULL;
4620 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4622 u8 *locator_name = NULL;
4624 memset(&locator, 0, sizeof(locator));
4625 memset(a, 0, sizeof(a[0]));
4627 locator.sw_if_index = ntohl(mp->sw_if_index);
4628 locator.priority = mp->priority;
4629 locator.weight = mp->weight;
4631 vec_add1(locators, locator);
4633 locator_name = format(0, "%s", mp->locator_set_name);
4635 a->name = locator_name;
4636 a->locators = locators;
4637 a->is_add = mp->is_add;
4640 rv = vnet_lisp_add_del_locator(a, &ls_index);
4643 vec_free(locator_name);
4645 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4649 vl_api_lisp_add_del_local_eid_t_handler(
4650 vl_api_lisp_add_del_local_eid_t *mp)
4652 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4653 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4655 ip_prefix_t *prefp = NULL;
4656 ip_address_t *ip_eid = NULL;
4659 u32 locator_set_index = ~0, map_index = ~0;
4660 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4663 prefp = &gid_address_ippref(&eid);
4664 ip_eid = &ip_prefix_addr(prefp);
4665 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4668 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4669 sizeof(ip_addr_v6(ip_eid)));
4670 ip_addr_version(ip_eid) = IP6;
4672 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4673 sizeof(ip_addr_v4(ip_eid)));
4674 ip_addr_version(ip_eid) = IP4;
4676 ip_prefix_len(prefp) = mp->prefix_len;
4678 name = format(0, "%s", mp->locator_set_name);
4679 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4681 rv = VNET_API_ERROR_INVALID_VALUE;
4684 locator_set_index = p[0];
4686 /* XXX treat batch configuration */
4687 a->is_add = mp->is_add;
4689 a->locator_set_index = locator_set_index;
4692 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4697 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4701 lisp_gpe_add_del_fwd_entry_set_address(
4702 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4703 ip_address_t *slocator,
4704 ip_address_t *dlocator,
4707 ip_address_t *ip_eid = NULL;
4708 ip_prefix_t *prefp = NULL;
4710 prefp = &gid_address_ippref(eid);
4711 ip_eid = &ip_prefix_addr(prefp);
4713 if (mp->eid_is_ipv6) {
4714 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4715 sizeof(ip_addr_v6(ip_eid)));
4716 ip_addr_version(ip_eid) = IP6;
4718 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4719 sizeof(ip_addr_v4(ip_eid)));
4720 ip_addr_version(ip_eid) = IP4;
4722 ip_prefix_len(prefp) = mp->eid_prefix_len;
4724 if (mp->address_is_ipv6) {
4725 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4726 sizeof(ip_addr_v6(slocator)));
4727 ip_addr_version(slocator) = IP6;
4728 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4729 sizeof(ip_addr_v6(dlocator)));
4730 ip_addr_version(dlocator) = IP6;
4732 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4733 sizeof(ip_addr_v4(slocator)));
4734 ip_addr_version(slocator) = IP4;
4735 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4736 sizeof(ip_addr_v4(dlocator)));
4737 ip_addr_version(dlocator) = IP4;
4742 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4743 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4745 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4747 ip_address_t slocator, dlocator;
4749 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4751 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4753 memset (&a, 0, sizeof(a));
4755 a.is_add = mp->is_add;
4757 a.slocator = slocator;
4758 a.dlocator = dlocator;
4759 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4761 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4765 vl_api_lisp_add_del_map_resolver_t_handler(
4766 vl_api_lisp_add_del_map_resolver_t *mp)
4768 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4770 ip_address_t *ip_addr = NULL;
4771 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4773 a->is_add = mp->is_add;
4774 ip_addr = &a->address;
4777 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4778 sizeof(ip_addr_v6(ip_addr)));
4779 ip_addr_version(ip_addr) = IP6;
4781 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4782 sizeof(ip_addr_v4(ip_addr)));
4783 ip_addr_version(ip_addr) = IP4;
4786 rv = vnet_lisp_add_del_map_resolver (a);
4788 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4792 vl_api_lisp_gpe_enable_disable_t_handler(
4793 vl_api_lisp_gpe_enable_disable_t *mp)
4795 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4797 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4799 a->is_en = mp->is_en;
4800 vnet_lisp_gpe_enable_disable (a);
4802 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4806 vl_api_lisp_enable_disable_t_handler(
4807 vl_api_lisp_enable_disable_t *mp)
4809 vl_api_lisp_enable_disable_reply_t *rmp;
4812 vnet_lisp_enable_disable (mp->is_en);
4813 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4817 vl_api_lisp_gpe_add_del_iface_t_handler(
4818 vl_api_lisp_gpe_add_del_iface_t *mp)
4820 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4822 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4824 a->is_add = mp->is_add;
4825 a->table_id = mp->table_id;
4827 vnet_lisp_gpe_add_del_iface (a, 0);
4829 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4832 /** Used for transferring locators via VPP API */
4833 typedef CLIB_PACKED(struct
4835 u8 is_ip4; /**< is locator an IPv4 address */
4836 u8 addr[16]; /**< IPv4/IPv6 address */
4840 send_lisp_locator_set_details_set_address
4841 (vl_api_lisp_locator_set_details_t *rmp,
4842 gid_address_t *gid_address)
4844 ip_prefix_t *ip_addr;
4846 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4850 ip_addr = &gid_address_ippref(gid_address);
4851 rmp->prefix_len = ip_prefix_len(ip_addr);
4852 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4853 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4857 vl_api_lisp_add_del_remote_mapping_t_handler (
4858 vl_api_lisp_add_del_remote_mapping_t *mp)
4861 ip_address_t rloc, * rlocs = 0;
4862 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
4864 gid_address_t _seid, * seid = &_seid;
4865 gid_address_t _deid, * deid = &_deid;
4866 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
4867 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
4869 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
4870 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
4871 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
4872 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
4873 ip_prefix_len(seid_pref) = mp->seid_len;
4874 ip_prefix_len(deid_pref) = mp->deid_len;
4875 gid_address_set_vni (seid, ntohl (mp->vni));
4876 gid_address_set_vni (deid, ntohl (mp->vni));
4878 if (mp->eid_is_ip4) {
4879 ip_prefix_version(seid_pref) = IP4;
4880 ip_prefix_version(deid_pref) = IP4;
4881 clib_memcpy (&ip_addr_v4(seid_addr),
4882 mp->seid, sizeof (ip_addr_v4(seid_addr)));
4883 clib_memcpy (&ip_addr_v4(deid_addr),
4884 mp->deid, sizeof (ip_addr_v4(deid_addr)));
4886 ip_prefix_version(seid_pref) = IP6;
4887 ip_prefix_version(deid_pref) = IP6;
4888 clib_memcpy (&ip_addr_v6(seid_addr),
4889 mp->seid, sizeof (ip_addr_v6(seid_addr)));
4890 clib_memcpy (&ip_addr_v6(deid_addr),
4891 mp->deid, sizeof (ip_addr_v6(deid_addr)));
4894 for (i = 0; i < mp->rloc_num; i++) {
4895 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
4897 clib_memcpy (&ip_addr_v4(&rloc), &r->addr, sizeof (rloc_t));
4898 ip_addr_version (&rloc) = IP4;
4900 clib_memcpy (&ip_addr_v6(&rloc), &r->addr, sizeof (rloc_t));
4901 ip_addr_version (&rloc) = IP6;
4903 vec_add1 (rlocs, rloc);
4906 rv = vnet_lisp_add_del_remote_mapping (deid, seid, rlocs,
4907 mp->action, mp->is_add);
4909 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4913 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4914 locator_set_t *lsit,
4915 unix_shared_memory_queue_t *q,
4919 vl_api_lisp_locator_set_details_t *rmp;
4920 locator_t *loc = NULL;
4924 vec_foreach (locit, lsit->locator_indices) {
4925 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4926 rmp = vl_msg_api_alloc (sizeof (*rmp));
4927 memset (rmp, 0, sizeof (*rmp));
4928 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4929 rmp->local = lsit->local;
4931 ASSERT(lsit->name != NULL);
4932 strncpy((char *) rmp->locator_set_name,
4933 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4934 rmp->sw_if_index = htonl(loc->sw_if_index);
4936 str = format(0, "remote-%d", index);
4937 strncpy((char *) rmp->locator_set_name, (char *) str,
4938 ARRAY_LEN(rmp->locator_set_name) - 1);
4939 send_lisp_locator_set_details_set_address(rmp, &loc->address);
4943 rmp->priority = loc->priority;
4944 rmp->weight = loc->weight;
4945 rmp->context = context;
4947 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4952 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4954 unix_shared_memory_queue_t * q = NULL;
4955 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4956 locator_set_t * lsit = NULL;
4959 q = vl_api_client_index_to_input_queue (mp->client_index);
4965 pool_foreach (lsit, lcm->locator_set_pool,
4967 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
4972 send_lisp_local_eid_table_details (mapping_t *mapit,
4973 unix_shared_memory_queue_t *q,
4976 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4977 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4978 locator_set_t *ls = NULL;
4979 gid_address_t *gid = NULL;
4980 ip_prefix_t *ip_prefix = NULL;
4984 ls = pool_elt_at_index (lcm->locator_set_pool,
4985 mapit->locator_set_index);
4988 type = gid_address_type(gid);
4990 if (type != GID_ADDR_IP_PREFIX) {
4994 ip_prefix = &gid_address_ippref(gid);
4996 rmp = vl_msg_api_alloc (sizeof (*rmp));
4997 memset (rmp, 0, sizeof (*rmp));
4998 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5000 ASSERT(ls->name != NULL);
5001 strncpy((char *) rmp->locator_set_name,
5002 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5004 str = format(0, "remote-%d", mapit->locator_set_index);
5005 strncpy((char *) rmp->locator_set_name, (char *) str,
5006 ARRAY_LEN(rmp->locator_set_name) - 1);
5010 switch (ip_prefix_version(ip_prefix)) {
5012 rmp->eid_is_ipv6 = 0;
5013 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5014 sizeof(ip_prefix_v4(ip_prefix)));
5018 rmp->eid_is_ipv6 = 1;
5019 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5020 sizeof(ip_prefix_v6(ip_prefix)));
5026 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5027 rmp->context = context;
5029 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5033 vl_api_lisp_local_eid_table_dump_t_handler (
5034 vl_api_lisp_local_eid_table_dump_t *mp)
5036 unix_shared_memory_queue_t * q = NULL;
5037 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5038 mapping_t * mapit = NULL;
5040 q = vl_api_client_index_to_input_queue (mp->client_index);
5045 pool_foreach (mapit, lcm->mapping_pool,
5047 send_lisp_local_eid_table_details(mapit, q, mp->context);
5052 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5053 unix_shared_memory_queue_t *q,
5056 vl_api_lisp_gpe_tunnel_details_t *rmp;
5057 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5059 rmp = vl_msg_api_alloc (sizeof (*rmp));
5060 memset (rmp, 0, sizeof (*rmp));
5061 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5063 rmp->tunnels = tunnel - lgm->tunnels;
5065 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5066 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5067 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5069 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5070 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5071 rmp->dcap_next = htonl(tunnel->decap_next_index);
5072 rmp->lisp_ver = tunnel->ver_res;
5073 rmp->next_protocol = tunnel->next_protocol;
5074 rmp->flags = tunnel->flags;
5075 rmp->ver_res = tunnel->ver_res;
5076 rmp->res = tunnel->res;
5077 rmp->iid = htonl(tunnel->vni);
5078 rmp->context = context;
5080 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5084 vl_api_lisp_gpe_tunnel_dump_t_handler (
5085 vl_api_lisp_local_eid_table_dump_t *mp)
5087 unix_shared_memory_queue_t * q = NULL;
5088 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5089 lisp_gpe_tunnel_t * tunnel = NULL;
5091 if (pool_elts(lgm->tunnels) == 0) {
5095 q = vl_api_client_index_to_input_queue (mp->client_index);
5100 pool_foreach(tunnel, lgm->tunnels,
5102 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5107 send_lisp_map_resolver_details (ip_address_t *ip,
5108 unix_shared_memory_queue_t *q,
5111 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5113 rmp = vl_msg_api_alloc (sizeof (*rmp));
5114 memset (rmp, 0, sizeof (*rmp));
5115 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5117 switch (ip_addr_version(ip)) {
5120 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5125 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5131 rmp->context = context;
5133 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5137 vl_api_lisp_map_resolver_dump_t_handler (
5138 vl_api_lisp_local_eid_table_dump_t *mp)
5140 unix_shared_memory_queue_t * q = NULL;
5141 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5142 ip_address_t *ip = NULL;
5144 q = vl_api_client_index_to_input_queue (mp->client_index);
5149 vec_foreach(ip, lcm->map_resolvers) {
5150 send_lisp_map_resolver_details(ip, q, mp->context);
5156 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5159 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5161 rmp = vl_msg_api_alloc (sizeof (*rmp));
5162 memset (rmp, 0, sizeof (*rmp));
5163 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5165 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5166 rmp->feature_status = vnet_lisp_enable_disable_status ();
5167 rmp->context = context;
5169 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5173 vl_api_lisp_enable_disable_status_dump_t_handler
5174 (vl_api_lisp_enable_disable_status_dump_t *mp)
5176 unix_shared_memory_queue_t * q = NULL;
5178 q = vl_api_client_index_to_input_queue (mp->client_index);
5183 send_lisp_enable_disable_details(q, mp->context);
5187 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5189 vl_api_interface_name_renumber_reply_t * rmp;
5192 VALIDATE_SW_IF_INDEX(mp);
5194 rv = vnet_interface_name_renumber
5195 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5197 BAD_SW_IF_INDEX_LABEL;
5199 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5202 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5203 u32 sw_if_index, u32 address)
5205 vpe_api_main_t * am = &vpe_api_main;
5206 vlib_main_t * vm = am->vlib_main;
5207 vl_api_ip4_arp_event_t * event;
5208 static f64 arp_event_last_time;
5209 f64 now = vlib_time_now (vm);
5211 if (pool_is_free_index (am->arp_events, pool_index))
5214 event = pool_elt_at_index (am->arp_events, pool_index);
5215 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5216 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5217 } else { /* same mac */
5218 if ((sw_if_index == event->sw_if_index) &&
5220 /* for BD case, also check IP address with 10 sec timeout */
5221 ((address == event->address) &&
5222 ((now - arp_event_last_time) < 10.0))))
5226 arp_event_last_time = now;
5227 event->sw_if_index = sw_if_index;
5228 if (address) event->address = address;
5232 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5234 vpe_api_main_t * am = &vpe_api_main;
5236 if (pool_is_free_index (am->arp_events, pool_index))
5239 pool_put_index (am->arp_events, pool_index);
5244 vl_api_want_ip4_arp_events_t_handler
5245 (vl_api_want_ip4_arp_events_t * mp)
5247 vpe_api_main_t * am = &vpe_api_main;
5248 vnet_main_t * vnm = vnet_get_main();
5249 vl_api_want_ip4_arp_events_reply_t *rmp;
5250 vl_api_ip4_arp_event_t * event;
5253 if (mp->enable_disable) {
5254 pool_get (am->arp_events, event);
5255 memset (event, 0, sizeof (*event));
5257 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5258 event->client_index = mp->client_index;
5259 event->context = mp->context;
5260 event->address = mp->address;
5261 event->pid = mp->pid;
5263 rv = vnet_add_del_ip4_arp_change_event
5264 (vnm, arp_change_data_callback,
5266 &mp->address /* addr, in net byte order */,
5267 vpe_resolver_process_node.index,
5268 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5270 rv = vnet_add_del_ip4_arp_change_event
5271 (vnm, arp_change_delete_callback,
5273 &mp->address /* addr, in net byte order */,
5274 vpe_resolver_process_node.index,
5275 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5277 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5280 static void vl_api_input_acl_set_interface_t_handler
5281 (vl_api_input_acl_set_interface_t * mp)
5283 vlib_main_t *vm = vlib_get_main();
5284 vl_api_input_acl_set_interface_reply_t * rmp;
5286 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5288 ip4_table_index = ntohl(mp->ip4_table_index);
5289 ip6_table_index = ntohl(mp->ip6_table_index);
5290 l2_table_index = ntohl(mp->l2_table_index);
5291 sw_if_index = ntohl(mp->sw_if_index);
5293 VALIDATE_SW_IF_INDEX(mp);
5295 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5296 ip6_table_index, l2_table_index,
5299 BAD_SW_IF_INDEX_LABEL;
5301 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5304 static void vl_api_ipsec_spd_add_del_t_handler
5305 (vl_api_ipsec_spd_add_del_t * mp)
5308 clib_warning ("unimplemented");
5311 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5312 vl_api_ipsec_spd_add_del_reply_t * rmp;
5316 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5318 rv = VNET_API_ERROR_UNIMPLEMENTED;
5321 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5325 static void vl_api_ipsec_interface_add_del_spd_t_handler
5326 (vl_api_ipsec_interface_add_del_spd_t * mp)
5328 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5329 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5331 u32 sw_if_index __attribute__((unused));
5332 u32 spd_id __attribute__((unused));
5334 sw_if_index = ntohl(mp->sw_if_index);
5335 spd_id = ntohl(mp->spd_id);
5337 VALIDATE_SW_IF_INDEX(mp);
5340 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5342 rv = VNET_API_ERROR_UNIMPLEMENTED;
5345 BAD_SW_IF_INDEX_LABEL;
5347 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5350 static void vl_api_ipsec_spd_add_del_entry_t_handler
5351 (vl_api_ipsec_spd_add_del_entry_t * mp)
5353 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5354 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5360 memset(&p, 0, sizeof(p));
5362 p.id = ntohl(mp->spd_id);
5363 p.priority = ntohl(mp->priority);
5364 p.is_outbound = mp->is_outbound;
5365 p.is_ipv6 = mp->is_ipv6;
5367 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5368 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5369 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5370 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5372 p.protocol = mp->protocol;
5373 p.rport.start = ntohs(mp->remote_port_start);
5374 p.rport.stop = ntohs(mp->remote_port_stop);
5375 p.lport.start = ntohs(mp->local_port_start);
5376 p.lport.stop = ntohs(mp->local_port_stop);
5377 /* policy action resolve unsupported */
5378 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5379 clib_warning("unsupported action: 'resolve'");
5380 rv = VNET_API_ERROR_UNIMPLEMENTED;
5383 p.policy = mp->policy;
5384 p.sa_id = ntohl(mp->sa_id);
5386 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5390 if (mp->is_ip_any) {
5392 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5395 rv = VNET_API_ERROR_UNIMPLEMENTED;
5400 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5403 static void vl_api_ipsec_sad_add_del_entry_t_handler
5404 (vl_api_ipsec_sad_add_del_entry_t * mp)
5406 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5407 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5412 memset(&sa, 0, sizeof(sa));
5414 sa.id = ntohl(mp->sad_id);
5415 sa.spi = ntohl(mp->spi);
5416 /* security protocol AH unsupported */
5417 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5418 clib_warning("unsupported security protocol 'AH'");
5419 rv = VNET_API_ERROR_UNIMPLEMENTED;
5422 sa.protocol = mp->protocol;
5423 /* check for unsupported crypto-alg */
5424 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5425 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5426 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5427 mp->crypto_algorithm);
5428 rv = VNET_API_ERROR_UNIMPLEMENTED;
5431 sa.crypto_alg = mp->crypto_algorithm;
5432 sa.crypto_key_len = mp->crypto_key_length;
5433 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5434 /* check for unsupported integ-alg */
5435 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5436 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5437 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5438 mp->integrity_algorithm);
5439 rv = VNET_API_ERROR_UNIMPLEMENTED;
5442 sa.integ_alg = mp->integrity_algorithm;
5443 sa.integ_key_len = mp->integrity_key_length;
5444 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5445 sa.use_esn = mp->use_extended_sequence_number;
5446 sa.is_tunnel = mp->is_tunnel;
5447 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5448 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5449 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5451 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5453 rv = VNET_API_ERROR_UNIMPLEMENTED;
5458 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5462 vl_api_ikev2_profile_add_del_t_handler
5463 (vl_api_ikev2_profile_add_del_t * mp)
5465 vl_api_ikev2_profile_add_del_reply_t * rmp;
5469 vlib_main_t * vm = vlib_get_main();
5470 clib_error_t * error;
5471 u8 * tmp = format(0, "%s", mp->name);
5472 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5475 rv = VNET_API_ERROR_UNSPECIFIED;
5477 rv = VNET_API_ERROR_UNIMPLEMENTED;
5480 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5484 vl_api_ikev2_profile_set_auth_t_handler
5485 (vl_api_ikev2_profile_set_auth_t * mp)
5487 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5491 vlib_main_t * vm = vlib_get_main();
5492 clib_error_t * error;
5493 u8 * tmp = format(0, "%s", mp->name);
5494 u8 * data = vec_new (u8, mp->data_len);
5495 clib_memcpy(data, mp->data, mp->data_len);
5496 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5500 rv = VNET_API_ERROR_UNSPECIFIED;
5502 rv = VNET_API_ERROR_UNIMPLEMENTED;
5505 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5509 vl_api_ikev2_profile_set_id_t_handler
5510 (vl_api_ikev2_profile_set_id_t * mp)
5512 vl_api_ikev2_profile_add_del_reply_t * rmp;
5516 vlib_main_t * vm = vlib_get_main();
5517 clib_error_t * error;
5518 u8 * tmp = format(0, "%s", mp->name);
5519 u8 * data = vec_new (u8, mp->data_len);
5520 clib_memcpy(data, mp->data, mp->data_len);
5521 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5525 rv = VNET_API_ERROR_UNSPECIFIED;
5527 rv = VNET_API_ERROR_UNIMPLEMENTED;
5530 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5534 vl_api_ikev2_profile_set_ts_t_handler
5535 (vl_api_ikev2_profile_set_ts_t * mp)
5537 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5541 vlib_main_t * vm = vlib_get_main();
5542 clib_error_t * error;
5543 u8 * tmp = format(0, "%s", mp->name);
5544 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5545 mp->end_port, (ip4_address_t) mp->start_addr,
5546 (ip4_address_t) mp->end_addr, mp->is_local);
5549 rv = VNET_API_ERROR_UNSPECIFIED;
5551 rv = VNET_API_ERROR_UNIMPLEMENTED;
5554 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5558 vl_api_ikev2_set_local_key_t_handler
5559 (vl_api_ikev2_set_local_key_t * mp)
5561 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5565 vlib_main_t * vm = vlib_get_main();
5566 clib_error_t * error;
5568 error = ikev2_set_local_key(vm, mp->key_file);
5570 rv = VNET_API_ERROR_UNSPECIFIED;
5572 rv = VNET_API_ERROR_UNIMPLEMENTED;
5575 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5579 vl_api_map_add_domain_t_handler
5580 (vl_api_map_add_domain_t * mp)
5582 vl_api_map_add_domain_reply_t * rmp;
5585 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5586 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5587 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5588 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5589 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5591 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5593 rmp->index = ntohl(index);
5598 vl_api_map_del_domain_t_handler
5599 (vl_api_map_del_domain_t * mp)
5601 vl_api_map_del_domain_reply_t * rmp;
5604 rv = map_delete_domain(ntohl(mp->index));
5606 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5610 vl_api_map_add_del_rule_t_handler
5611 (vl_api_map_add_del_rule_t * mp)
5613 vl_api_map_del_domain_reply_t * rmp;
5616 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5618 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5622 vl_api_map_domain_dump_t_handler
5623 (vl_api_map_domain_dump_t * mp)
5625 vl_api_map_domain_details_t * rmp;
5626 map_main_t *mm = &map_main;
5628 unix_shared_memory_queue_t * q;
5630 if (pool_elts (mm->domains) == 0)
5633 q = vl_api_client_index_to_input_queue (mp->client_index);
5638 pool_foreach(d, mm->domains, ({
5639 /* Make sure every field is initiated (or don't skip the memset()) */
5640 rmp = vl_msg_api_alloc (sizeof (*rmp));
5641 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5642 rmp->domain_index = htonl(d - mm->domains);
5643 rmp->ea_bits_len = d->ea_bits_len;
5644 rmp->psid_offset = d->psid_offset;
5645 rmp->psid_length = d->psid_length;
5646 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5647 rmp->ip4_prefix_len = d->ip4_prefix_len;
5648 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5649 rmp->ip6_prefix_len = d->ip6_prefix_len;
5650 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5651 rmp->ip6_src_len = d->ip6_src_len;
5652 rmp->mtu = htons(d->mtu);
5653 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5654 rmp->context = mp->context;
5656 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5661 vl_api_map_rule_dump_t_handler
5662 (vl_api_map_rule_dump_t * mp)
5664 unix_shared_memory_queue_t * q;
5667 vl_api_map_rule_details_t * rmp;
5668 map_main_t *mm = &map_main;
5669 u32 domain_index = ntohl(mp->domain_index);
5672 if (pool_elts (mm->domains) == 0)
5675 d = pool_elt_at_index(mm->domains, domain_index);
5676 if (!d || !d->rules) {
5680 q = vl_api_client_index_to_input_queue (mp->client_index);
5685 for (i = 0; i < (0x1 << d->psid_length); i++) {
5687 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5690 rmp = vl_msg_api_alloc(sizeof(*rmp));
5691 memset(rmp, 0, sizeof(*rmp));
5692 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5693 rmp->psid = htons(i);
5694 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5695 rmp->context = mp->context;
5696 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5701 vl_api_map_summary_stats_t_handler (
5702 vl_api_map_summary_stats_t *mp)
5704 vl_api_map_summary_stats_reply_t *rmp;
5705 vlib_combined_counter_main_t *cm;
5708 u64 total_pkts[VLIB_N_RX_TX];
5709 u64 total_bytes[VLIB_N_RX_TX];
5710 map_main_t *mm = &map_main;
5711 unix_shared_memory_queue_t *q =
5712 vl_api_client_index_to_input_queue(mp->client_index);
5717 rmp = vl_msg_api_alloc (sizeof (*rmp));
5718 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5719 rmp->context = mp->context;
5722 memset (total_pkts, 0, sizeof (total_pkts));
5723 memset (total_bytes, 0, sizeof (total_bytes));
5725 map_domain_counter_lock (mm);
5726 vec_foreach(cm, mm->domain_counters) {
5727 which = cm - mm->domain_counters;
5729 for (i = 0; i < vec_len(cm->maxi); i++) {
5730 vlib_get_combined_counter (cm, i, &v);
5731 total_pkts[which] += v.packets;
5732 total_bytes[which] += v.bytes;
5736 map_domain_counter_unlock (mm);
5738 /* Note: in network byte order! */
5739 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5740 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5741 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5742 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5743 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5744 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5745 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));
5746 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));
5748 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5751 static void vl_api_ipsec_sa_set_key_t_handler
5752 (vl_api_ipsec_sa_set_key_t * mp)
5754 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5755 vl_api_ipsec_sa_set_key_reply_t *rmp;
5759 sa.id = ntohl(mp->sa_id);
5760 sa.crypto_key_len = mp->crypto_key_length;
5761 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5762 sa.integ_key_len = mp->integrity_key_length;
5763 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5765 rv = ipsec_set_sa_key(vm, &sa);
5767 rv = VNET_API_ERROR_UNIMPLEMENTED;
5770 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5773 static void vl_api_cop_interface_enable_disable_t_handler
5774 (vl_api_cop_interface_enable_disable_t * mp)
5776 vl_api_cop_interface_enable_disable_reply_t * rmp;
5778 u32 sw_if_index = ntohl(mp->sw_if_index);
5781 VALIDATE_SW_IF_INDEX(mp);
5783 enable_disable = (int) mp->enable_disable;
5785 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5787 BAD_SW_IF_INDEX_LABEL;
5789 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5792 static void vl_api_cop_whitelist_enable_disable_t_handler
5793 (vl_api_cop_whitelist_enable_disable_t * mp)
5795 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5796 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5797 u32 sw_if_index = ntohl(mp->sw_if_index);
5800 VALIDATE_SW_IF_INDEX(mp);
5802 a->sw_if_index = sw_if_index;
5805 a->default_cop = mp->default_cop;
5806 a->fib_id = ntohl(mp->fib_id);
5808 rv = cop_whitelist_enable_disable (a);
5810 BAD_SW_IF_INDEX_LABEL;
5812 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5815 static void vl_api_get_node_graph_t_handler
5816 (vl_api_get_node_graph_t * mp)
5820 api_main_t * am = &api_main;
5821 vlib_main_t * vm = vlib_get_main();
5823 vl_api_get_node_graph_reply_t * rmp;
5825 pthread_mutex_lock (&am->vlib_rp->mutex);
5826 oldheap = svm_push_data_heap (am->vlib_rp);
5829 * Keep the number of memcpy ops to a minimum (e.g. 1).
5830 * The current size of the serialized vector is
5831 * slightly under 4K.
5833 vec_validate (vector, 4095);
5834 vec_reset_length (vector);
5836 vector = vlib_node_serialize (&vm->node_main, vector);
5838 svm_pop_heap (oldheap);
5839 pthread_mutex_unlock (&am->vlib_rp->mutex);
5841 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5842 rmp->reply_in_shmem = (uword) vector);
5845 static void vl_api_trace_profile_add_t_handler
5846 (vl_api_trace_profile_add_t *mp)
5849 vl_api_trace_profile_add_reply_t * rmp;
5850 clib_error_t *error;
5852 /* Ignoring the profile id as currently a single profile
5854 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5855 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5856 mp->pow_enable, mp->trace_tsp,
5859 clib_error_report(error);
5860 rv = clib_error_get_code(error);
5863 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5866 static void vl_api_trace_profile_apply_t_handler
5867 (vl_api_trace_profile_apply_t *mp)
5870 vl_api_trace_profile_apply_reply_t * rmp;
5872 if (mp->enable != 0) {
5873 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5874 ntohl(mp->prefix_length),
5876 mp->trace_op == IOAM_HBYH_ADD,
5877 mp->trace_op == IOAM_HBYH_POP,
5878 mp->trace_op == IOAM_HBYH_MOD);
5880 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5882 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5885 static void vl_api_trace_profile_del_t_handler
5886 (vl_api_trace_profile_del_t *mp)
5889 vl_api_trace_profile_del_reply_t * rmp;
5890 clib_error_t *error;
5892 error = clear_ioam_rewrite_fn();
5894 clib_error_report(error);
5895 rv = clib_error_get_code(error);
5898 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5902 vl_api_af_packet_create_t_handler
5903 (vl_api_af_packet_create_t *mp)
5905 vlib_main_t *vm = vlib_get_main();
5906 vl_api_af_packet_create_reply_t *rmp;
5908 u8 *host_if_name = NULL;
5910 host_if_name = format(0, "%s", mp->host_if_name);
5911 vec_add1 (host_if_name, 0);
5913 rv = af_packet_create_if(vm, host_if_name,
5914 mp->use_random_hw_addr ? 0 : mp->hw_addr);
5916 vec_free(host_if_name);
5918 REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
5922 vl_api_af_packet_delete_t_handler
5923 (vl_api_af_packet_delete_t *mp)
5925 vlib_main_t * vm = vlib_get_main();
5926 vl_api_af_packet_delete_reply_t *rmp;
5928 u8 *host_if_name = NULL;
5930 host_if_name = format(0, "%s", mp->host_if_name);
5931 vec_add1 (host_if_name, 0);
5933 rv = af_packet_delete_if(vm, host_if_name);
5935 vec_free(host_if_name);
5937 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
5941 vl_api_policer_add_del_t_handler
5942 (vl_api_policer_add_del_t *mp)
5944 vlib_main_t * vm = vlib_get_main();
5945 vl_api_policer_add_del_reply_t *rmp;
5948 sse2_qos_pol_cfg_params_st cfg;
5949 clib_error_t * error;
5951 name = format(0, "%s", mp->name);
5953 memset (&cfg, 0, sizeof (cfg));
5955 cfg.rnd_type = mp->round_type;
5956 cfg.rate_type = mp->rate_type;
5957 cfg.rb.kbps.cir_kbps = mp->cir;
5958 cfg.rb.kbps.eir_kbps = mp->eir;
5959 cfg.rb.kbps.cb_bytes = mp->cb;
5960 cfg.rb.kbps.eb_bytes = mp->eb;
5962 error = policer_add_del(vm, name, &cfg, mp->is_add);
5965 rv = VNET_API_ERROR_UNSPECIFIED;
5967 REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
5971 vl_api_netmap_create_t_handler
5972 (vl_api_netmap_create_t *mp)
5974 vlib_main_t *vm = vlib_get_main();
5975 vl_api_netmap_create_reply_t *rmp;
5979 if_name = format(0, "%s", mp->if_name);
5980 vec_add1 (if_name, 0);
5982 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
5983 mp->is_pipe, mp->is_master);
5987 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
5991 vl_api_netmap_delete_t_handler
5992 (vl_api_netmap_delete_t *mp)
5994 vlib_main_t * vm = vlib_get_main();
5995 vl_api_netmap_delete_reply_t *rmp;
5999 if_name = format(0, "%s", mp->if_name);
6000 vec_add1 (if_name, 0);
6002 rv = netmap_delete_if(vm, if_name);
6006 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6009 #define BOUNCE_HANDLER(nn) \
6010 static void vl_api_##nn##_t_handler ( \
6011 vl_api_##nn##_t *mp) \
6013 vpe_client_registration_t *reg; \
6014 vpe_api_main_t * vam = &vpe_api_main; \
6015 unix_shared_memory_queue_t * q; \
6017 /* One registration only... */ \
6018 pool_foreach(reg, vam->nn##_registrations, \
6020 q = vl_api_client_index_to_input_queue (reg->client_index); \
6023 * If the queue is stuffed, turf the msg and complain \
6024 * It's unlikely that the intended recipient is \
6025 * alive; avoid deadlock at all costs. \
6027 if (q->cursize == q->maxsize) { \
6028 clib_warning ("ERROR: receiver queue full, drop msg"); \
6029 vl_msg_api_free (mp); \
6032 vl_msg_api_send_shmem (q, (u8 *)&mp); \
6036 vl_msg_api_free (mp); \
6041 * Add vpe's API message handlers to the table.
6042 * vlib has alread mapped shared memory and
6043 * added the client registration handlers.
6044 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
6047 static clib_error_t *
6048 vpe_api_hookup (vlib_main_t *vm)
6050 api_main_t * am = &api_main;
6053 vl_msg_api_set_handlers(VL_API_##N, #n, \
6054 vl_api_##n##_t_handler, \
6056 vl_api_##n##_t_endian, \
6057 vl_api_##n##_t_print, \
6058 sizeof(vl_api_##n##_t), 1);
6059 foreach_vpe_api_msg;
6063 * Manually register the sr tunnel add del msg, so we trace
6064 * enough bytes to capture a typical segment list
6066 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
6067 "sr_tunnel_add_del",
6068 vl_api_sr_tunnel_add_del_t_handler,
6070 vl_api_sr_tunnel_add_del_t_endian,
6071 vl_api_sr_tunnel_add_del_t_print,
6076 * Manually register the sr policy add del msg, so we trace
6077 * enough bytes to capture a typical tunnel name list
6079 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
6080 "sr_policy_add_del",
6081 vl_api_sr_policy_add_del_t_handler,
6083 vl_api_sr_policy_add_del_t_endian,
6084 vl_api_sr_policy_add_del_t_print,
6088 * Trace space for 8 MPLS encap labels, classifier mask+match
6090 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
6091 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
6092 += 5 * sizeof (u32x4);
6093 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
6094 += 5 * sizeof (u32x4);
6095 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
6096 += 16 * sizeof (u32);
6099 * Thread-safe API messages
6101 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
6106 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
6108 static clib_error_t *
6109 vpe_api_init (vlib_main_t *vm)
6111 vpe_api_main_t *am = &vpe_api_main;
6114 am->vnet_main = vnet_get_main();
6115 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6116 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6117 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6118 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6119 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6120 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6123 vl_set_memory_region_name ("/vpe-api");
6124 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6129 VLIB_INIT_FUNCTION(vpe_api_init);
6131 static clib_error_t *
6132 chroot_config (vlib_main_t * vm, unformat_input_t * input)
6136 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6138 if (unformat (input, "prefix %s", &chroot_path))
6140 vec_add1 (chroot_path, 0);
6141 vl_set_memory_root_path ((char *)chroot_path);
6144 return clib_error_return (0, "unknown input `%U'",
6145 format_unformat_error, input);
6149 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6151 void * get_unformat_vnet_sw_interface (void)
6153 return (void *) &unformat_vnet_sw_interface;
6156 #undef vl_api_version
6157 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6158 #include <api/vpe.api.h>
6159 #undef vl_api_version
6161 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6163 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6164 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6165 clib_host_to_net_u32 (mp->api_versions[0]),
6172 static u8 * format_arp_event (u8 * s, va_list * args)
6174 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6176 s = format (s, "pid %d: %U", event->pid,
6177 format_ip4_address, &event->address);
6181 static clib_error_t *
6182 show_ip4_arp_events_fn (vlib_main_t * vm,
6183 unformat_input_t * input,
6184 vlib_cli_command_t * cmd)
6186 vpe_api_main_t * am = &vpe_api_main;
6187 vl_api_ip4_arp_event_t * event;
6189 if (pool_elts (am->arp_events) == 0) {
6190 vlib_cli_output (vm, "No active arp event registrations");
6194 pool_foreach (event, am->arp_events,
6196 vlib_cli_output (vm, "%U", format_arp_event, event);
6202 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6203 .path = "show arp event registrations",
6204 .function = show_ip4_arp_events_fn,
6205 .short_help = "Show arp event registrations",