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/nsh-gre/nsh_gre.h>
71 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
72 #include <vnet/lisp-gpe/lisp_gpe.h>
73 #include <vnet/lisp-cp/control.h>
74 #include <vnet/map/map.h>
75 #include <vnet/cop/cop.h>
76 #include <vnet/ip/ip6_hop_by_hop.h>
79 #undef __included_bihash_template_h__
80 #include <vnet/l2/l2_fib.h>
83 #include <vnet/ipsec/ipsec.h>
84 #include <vnet/ipsec/ikev2.h>
87 #include <vnet/devices/virtio/vhost-user.h>
90 #include <stats/stats.h>
93 #include <vnet/ethernet/ethernet.h>
94 #include <vnet/ethernet/arp_packet.h>
95 #include <vnet/interface.h>
97 #include <vnet/l2/l2_fib.h>
98 #include <vnet/l2/l2_bd.h>
99 #include <api/vpe_msg_enum.h>
101 #define f64_endian(a)
102 #define f64_print(a,b)
104 #define vl_typedefs /* define message structures */
105 #include <api/vpe_all_api_h.h>
108 #define vl_endianfun /* define message structures */
109 #include <api/vpe_all_api_h.h>
112 /* instantiate all the print functions we know about */
113 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
115 #include <api/vpe_all_api_h.h>
118 #define REPLY_MACRO(t) \
120 unix_shared_memory_queue_t * q; \
121 rv = vl_msg_api_pd_handler (mp, rv); \
122 q = vl_api_client_index_to_input_queue (mp->client_index); \
126 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
127 rmp->_vl_msg_id = ntohs((t)); \
128 rmp->context = mp->context; \
129 rmp->retval = ntohl(rv); \
131 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
134 #define REPLY_MACRO2(t, body) \
136 unix_shared_memory_queue_t * q; \
137 rv = vl_msg_api_pd_handler (mp, rv); \
138 q = vl_api_client_index_to_input_queue (mp->client_index); \
142 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
143 rmp->_vl_msg_id = ntohs((t)); \
144 rmp->context = mp->context; \
145 rmp->retval = ntohl(rv); \
146 do {body;} while (0); \
147 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
150 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
152 #define VALIDATE_SW_IF_INDEX(mp) \
153 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
154 vnet_main_t *__vnm = vnet_get_main(); \
155 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
157 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
158 goto bad_sw_if_index; \
162 #define BAD_SW_IF_INDEX_LABEL \
168 #define VALIDATE_RX_SW_IF_INDEX(mp) \
169 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
170 vnet_main_t *__vnm = vnet_get_main(); \
171 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
172 __rx_sw_if_index)) { \
173 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
174 goto bad_rx_sw_if_index; \
178 #define BAD_RX_SW_IF_INDEX_LABEL \
180 bad_rx_sw_if_index: \
184 #define VALIDATE_TX_SW_IF_INDEX(mp) \
185 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
186 vnet_main_t *__vnm = vnet_get_main(); \
187 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
188 __tx_sw_if_index)) { \
189 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
190 goto bad_tx_sw_if_index; \
194 #define BAD_TX_SW_IF_INDEX_LABEL \
196 bad_tx_sw_if_index: \
202 #define VALIDATE_SW_IF_INDEX(mp)
203 #define BAD_SW_IF_INDEX_LABEL
204 #define VALIDATE_RX_SW_IF_INDEX(mp)
205 #define BAD_RX_SW_IF_INDEX_LABEL
206 #define VALIDATE_TX_SW_IF_INDEX(mp)
207 #define BAD_TX_SW_IF_INDEX_LABEL
209 #endif /* CLIB_DEBUG > 0 */
211 #define foreach_vpe_api_msg \
212 _(WANT_INTERFACE_EVENTS, want_interface_events) \
213 _(WANT_OAM_EVENTS, want_oam_events) \
214 _(OAM_ADD_DEL, oam_add_del) \
215 _(SW_INTERFACE_DUMP, sw_interface_dump) \
216 _(SW_INTERFACE_DETAILS, sw_interface_details) \
217 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
218 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
219 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
220 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
221 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
222 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
223 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
224 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
225 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
226 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
227 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
228 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
229 _(L2FIB_ADD_DEL, l2fib_add_del) \
230 _(L2_FLAGS, l2_flags) \
231 _(BRIDGE_FLAGS, bridge_flags) \
232 _(TAP_CONNECT, tap_connect) \
233 _(TAP_MODIFY, tap_modify) \
234 _(TAP_DELETE, tap_delete) \
235 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
236 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
237 _(CREATE_SUBIF, create_subif) \
238 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
239 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
240 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
241 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
242 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
243 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
244 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
245 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
246 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
247 _(RESET_FIB, reset_fib) \
248 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
249 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
250 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
251 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
252 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
253 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
254 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
255 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
256 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
257 sw_interface_ip6_set_link_local_address) \
258 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
259 _(CREATE_LOOPBACK, create_loopback) \
260 _(CONTROL_PING, control_ping) \
261 _(CLI_REQUEST, cli_request) \
262 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
263 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
264 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
265 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
266 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
267 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
268 _(GET_NODE_INDEX, get_node_index) \
269 _(ADD_NODE_NEXT, add_node_next) \
270 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
271 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
272 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
273 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
274 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
275 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
276 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
277 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
278 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
279 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
280 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
281 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
282 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
283 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
284 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
285 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
286 _(IP_ADDRESS_DUMP, ip_address_dump) \
287 _(IP_DUMP, ip_dump) \
288 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
289 _(SHOW_VERSION, show_version) \
290 _(NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel) \
291 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
292 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
293 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel) \
294 _(LISP_GPE_ADD_DEL_TUNNEL, lisp_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_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
330 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
331 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
332 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
333 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
334 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del)
337 #define QUOTE(x) QUOTE_(x)
339 #define foreach_registration_hash \
340 _(interface_events) \
341 _(to_netconf_server) \
342 _(from_netconf_server) \
343 _(to_netconf_client) \
344 _(from_netconf_client) \
348 RESOLVE_IP4_ADD_DEL_ROUTE=1,
349 RESOLVE_IP6_ADD_DEL_ROUTE,
350 RESOLVE_MPLS_ETHERNET_ADD_DEL,
356 vl_api_ip_add_del_route_t r;
357 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
363 #define _(a) uword *a##_registration_hash; \
364 vpe_client_registration_t * a##_registrations;
365 foreach_registration_hash
368 /* notifications happen really early in the game */
369 u8 link_state_process_up;
371 /* ip4 pending route adds */
372 pending_route_t * pending_routes;
374 /* ip4 arp event registration pool */
375 vl_api_ip4_arp_event_t * arp_events;
378 vlib_main_t * vlib_main;
379 vnet_main_t * vnet_main;
382 static vlib_node_registration_t vpe_resolver_process_node;
383 static vpe_api_main_t vpe_api_main;
385 static void send_sw_interface_flags (vpe_api_main_t * am,
386 unix_shared_memory_queue_t *q,
387 vnet_sw_interface_t * swif);
388 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
389 unix_shared_memory_queue_t *q,
392 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
395 /* Clean up all registrations belonging to the indicated client */
396 int vl_api_memclnt_delete_callback (u32 client_index)
398 vpe_api_main_t * vam = &vpe_api_main;
399 vpe_client_registration_t *rp;
401 int stats_memclnt_delete_callback (u32 client_index);
403 stats_memclnt_delete_callback (client_index);
406 p = hash_get (vam->a##_registration_hash, client_index); \
408 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
409 pool_put (vam->a##_registrations, rp); \
410 hash_unset (vam->a##_registration_hash, client_index); \
412 foreach_registration_hash;
417 #define API_LINK_STATE_EVENT 1
418 #define API_ADMIN_UP_DOWN_EVENT 2
421 event_data_cmp (void * a1, void * a2)
426 return (word) e1[0] - (word) e2[0];
430 link_state_process (vlib_main_t * vm,
431 vlib_node_runtime_t * rt,
434 vpe_api_main_t * vam = &vpe_api_main;
435 vnet_main_t * vnm = vam->vnet_main;
436 vnet_sw_interface_t * swif;
437 uword * event_data = 0;
438 vpe_client_registration_t *reg;
440 u32 prev_sw_if_index;
441 unix_shared_memory_queue_t * q;
443 vam->link_state_process_up = 1;
446 vlib_process_wait_for_event (vm);
448 /* Unified list of changed link or admin state sw_if_indices */
449 vlib_process_get_events_with_type
450 (vm, &event_data, API_LINK_STATE_EVENT);
451 vlib_process_get_events_with_type
452 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
454 /* Sort, so we can eliminate duplicates */
455 vec_sort_with_function (event_data, event_data_cmp);
457 prev_sw_if_index = ~0;
459 for (i = 0; i < vec_len(event_data); i++) {
460 /* Only one message per swif */
461 if (prev_sw_if_index == event_data[i])
463 prev_sw_if_index = event_data[i];
465 pool_foreach(reg, vam->interface_events_registrations,
467 q = vl_api_client_index_to_input_queue (reg->client_index);
469 // sw_interface may be deleted already
470 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
473 swif = vnet_get_sw_interface (vnm, event_data[i]);
474 send_sw_interface_flags (vam, q, swif);
479 vec_reset_length (event_data);
485 static clib_error_t *
486 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
487 static clib_error_t *
488 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
490 VLIB_REGISTER_NODE (link_state_process_node,static) = {
491 .function = link_state_process,
492 .type = VLIB_NODE_TYPE_PROCESS,
493 .name = "vpe-link-state-process",
496 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
497 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
499 static clib_error_t *
500 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
502 vpe_api_main_t * vam = &vpe_api_main;
503 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
505 if (vam->link_state_process_up)
506 vlib_process_signal_event (vam->vlib_main,
507 link_state_process_node.index,
508 API_LINK_STATE_EVENT,
513 static clib_error_t *
514 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
516 vpe_api_main_t * vam = &vpe_api_main;
519 * Note: it's perfectly fair to set a subif admin up / admin down.
520 * Note the subtle distinction between this routine and the previous
523 if (vam->link_state_process_up)
524 vlib_process_signal_event (vam->vlib_main,
525 link_state_process_node.index,
526 API_ADMIN_UP_DOWN_EVENT,
531 #define pub_sub_handler(lca,UCA) \
532 static void vl_api_want_##lca##_t_handler ( \
533 vl_api_want_##lca##_t *mp) \
535 vpe_api_main_t *vam = &vpe_api_main; \
536 vpe_client_registration_t *rp; \
537 vl_api_want_##lca##_reply_t *rmp; \
541 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
543 if (mp->enable_disable) { \
544 clib_warning ("pid %d: already enabled...", mp->pid); \
545 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
548 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
549 pool_put (vam->lca##_registrations, rp); \
550 hash_unset (vam->lca##_registration_hash, \
555 if (mp->enable_disable == 0) { \
556 clib_warning ("pid %d: already disabled...", mp->pid); \
557 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
560 pool_get (vam->lca##_registrations, rp); \
561 rp->client_index = mp->client_index; \
562 rp->client_pid = mp->pid; \
563 hash_set (vam->lca##_registration_hash, rp->client_index, \
564 rp - vam->lca##_registrations); \
567 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
570 pub_sub_handler (interface_events,INTERFACE_EVENTS)
571 pub_sub_handler (oam_events,OAM_EVENTS)
573 #define RESOLUTION_EVENT 1
574 #define RESOLUTION_PENDING_EVENT 2
575 #define IP4_ARP_EVENT 3
577 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
578 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
579 static int mpls_ethernet_add_del_tunnel_2_t_handler
580 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
582 void handle_ip4_arp_event (u32 pool_index)
584 vpe_api_main_t * vam = &vpe_api_main;
585 vnet_main_t * vnm = vam->vnet_main;
586 vlib_main_t * vm = vam->vlib_main;
587 vl_api_ip4_arp_event_t * event;
588 vl_api_ip4_arp_event_t * mp;
589 unix_shared_memory_queue_t * q;
591 /* Client can cancel, die, etc. */
592 if (pool_is_free_index (vam->arp_events, pool_index))
595 event = pool_elt_at_index (vam->arp_events, pool_index);
597 q = vl_api_client_index_to_input_queue (event->client_index);
599 (void) vnet_add_del_ip4_arp_change_event
600 (vnm, arp_change_delete_callback,
601 event->pid, &event->address,
602 vpe_resolver_process_node.index, IP4_ARP_EVENT,
603 ~0 /* pool index, notused */, 0 /* is_add */);
607 if (q->cursize < q->maxsize) {
608 mp = vl_msg_api_alloc (sizeof (*mp));
609 clib_memcpy (mp, event, sizeof (*mp));
610 vl_msg_api_send_shmem (q, (u8 *)&mp);
612 static f64 last_time;
614 * Throttle syslog msgs.
615 * It's pretty tempting to just revoke the registration...
617 if (vlib_time_now (vm) > last_time + 10.0) {
618 clib_warning ("arp event for %U to pid %d: queue stuffed!",
619 format_ip4_address, &event->address, event->pid);
620 last_time = vlib_time_now(vm);
626 resolver_process (vlib_main_t * vm,
627 vlib_node_runtime_t * rt,
631 uword *event_data = 0;
633 vpe_api_main_t * vam = &vpe_api_main;
634 pending_route_t * pr;
635 vl_api_ip_add_del_route_t * adr;
636 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
637 u32 * resolution_failures = 0;
642 vlib_process_wait_for_event_or_clock (vm, timeout);
644 event_type = vlib_process_get_events (vm, &event_data);
646 switch (event_type) {
647 case RESOLUTION_PENDING_EVENT:
651 case RESOLUTION_EVENT:
652 for (i = 0; i < vec_len(event_data); i++) {
654 * Resolution events can occur long after the
655 * original request has timed out. $$$ add a cancel
658 if (pool_is_free_index (vam->pending_routes, event_data[i]))
661 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
665 switch (pr->resolve_type) {
666 case RESOLVE_IP4_ADD_DEL_ROUTE:
667 rv = ip4_add_del_route_t_handler (adr);
668 clib_warning ("resolver: add %U/%d via %U %s",
670 (ip4_address_t *)&(adr->dst_address),
671 adr->dst_address_length,
673 (ip4_address_t *)&(adr->next_hop_address),
674 (rv >= 0) ? "succeeded" : "failed");
677 case RESOLVE_IP6_ADD_DEL_ROUTE:
678 rv = ip6_add_del_route_t_handler (adr);
679 clib_warning ("resolver: add %U/%d via %U %s",
681 (ip6_address_t *)&(adr->dst_address),
682 adr->dst_address_length,
684 (ip6_address_t *)&(adr->next_hop_address),
685 (rv >= 0) ? "succeeded" : "failed");
688 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
689 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
690 clib_warning ("resolver: add mpls-o-e via %U %s",
692 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
693 (rv >= 0) ? "succeeded" : "failed");
697 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
699 pool_put (vam->pending_routes, pr);
704 for (i = 0; i < vec_len(event_data); i++)
705 handle_ip4_arp_event (event_data[i]);
708 case ~0: /* timeout, retry pending resolutions */
709 pool_foreach (pr, vam->pending_routes,
715 /* May fail, e.g. due to interface down */
716 switch (pr->resolve_type) {
717 case RESOLVE_IP4_ADD_DEL_ROUTE:
718 e = ip4_probe_neighbor
719 (vm, (ip4_address_t *)&(adr->next_hop_address),
720 ntohl(adr->next_hop_sw_if_index));
723 case RESOLVE_IP6_ADD_DEL_ROUTE:
724 e = ip6_probe_neighbor
725 (vm, (ip6_address_t *)&(adr->next_hop_address),
726 ntohl(adr->next_hop_sw_if_index));
729 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
731 e = ip4_probe_neighbor
733 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
734 pme->resolve_opaque);
738 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
742 clib_error_report (e);
744 adr->resolve_attempts = 1;
746 pme->resolve_attempts = 1;
750 adr->resolve_attempts -= 1;
751 if (adr->resolve_attempts == 0)
752 vec_add1 (resolution_failures,
753 pr - vam->pending_routes);
755 pme->resolve_attempts -= 1;
756 if (pme->resolve_attempts == 0)
757 vec_add1 (resolution_failures,
758 pr - vam->pending_routes);
762 for (i = 0; i < vec_len (resolution_failures); i++) {
763 pr = pool_elt_at_index (vam->pending_routes,
764 resolution_failures[i]);
768 switch (pr->resolve_type) {
769 case RESOLVE_IP4_ADD_DEL_ROUTE:
770 clib_warning ("resolver: add %U/%d via %U retry failure",
772 (ip4_address_t *)&(adr->dst_address),
773 adr->dst_address_length,
775 (ip4_address_t *)&(adr->next_hop_address));
778 case RESOLVE_IP6_ADD_DEL_ROUTE:
779 clib_warning ("resolver: add %U/%d via %U retry failure",
781 (ip6_address_t *)&(adr->dst_address),
782 adr->dst_address_length,
784 (ip6_address_t *)&(adr->next_hop_address));
787 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
788 clib_warning ("resolver: add mpls-o-e via %U retry failure",
790 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
794 clib_warning ("BUG");
796 pool_put(vam->pending_routes, pr);
798 vec_reset_length (resolution_failures);
801 if (pool_elts (vam->pending_routes) == 0)
803 vec_reset_length (event_data);
805 return 0; /* or not */
808 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
809 .function = resolver_process,
810 .type = VLIB_NODE_TYPE_PROCESS,
811 .name = "vpe-route-resolver-process",
814 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
816 ip4_main_t * im = &ip4_main;
817 ip_lookup_main_t * lm = &im->lookup_main;
818 vnet_classify_main_t * cm = &vnet_classify_main;
819 stats_main_t * sm = &stats_main;
820 ip4_add_del_route_args_t a;
821 ip4_address_t next_hop_address;
823 vpe_api_main_t * vam = &vpe_api_main;
824 vnet_main_t * vnm = vam->vnet_main;
825 vlib_main_t * vm = vlib_get_main();
826 pending_route_t * pr;
827 vl_api_ip_add_del_route_t * adr;
831 ip_adjacency_t *nh_adj, *add_adj = 0;
833 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
835 if (mp->create_vrf_if_needed) {
837 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
839 fib_index = f->index;
841 /* No such VRF, and we weren't asked to create one */
842 return VNET_API_ERROR_NO_SUCH_FIB;
848 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
849 ntohl(mp->next_hop_sw_if_index)))
850 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
852 clib_memcpy (next_hop_address.data, mp->next_hop_address,
853 sizeof (next_hop_address.data));
855 /* Arp for the next_hop if necessary */
856 if (mp->is_add && mp->resolve_if_needed) {
858 ip_adjacency_t * adj;
860 lookup_result = ip4_fib_lookup_with_table
861 (im, fib_index, &next_hop_address, 1 /* disable default route */);
863 adj = ip_get_adjacency (lm, lookup_result);
865 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
866 pool_get (vam->pending_routes, pr);
867 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
869 clib_memcpy (adr, mp, sizeof (*adr));
870 /* recursion block, "just in case" */
871 adr->resolve_if_needed = 0;
872 adr->resolve_attempts = ntohl(mp->resolve_attempts);
873 vnet_register_ip4_arp_resolution_event
874 (vnm, &next_hop_address, vpe_resolver_process_node.index,
875 RESOLUTION_EVENT, pr - vam->pending_routes);
877 vlib_process_signal_event
878 (vm, vpe_resolver_process_node.index,
879 RESOLUTION_PENDING_EVENT, 0 /* data */);
881 /* The interface may be down, etc. */
882 e = ip4_probe_neighbor
883 (vm, (ip4_address_t *)&(mp->next_hop_address),
884 ntohl(mp->next_hop_sw_if_index));
887 clib_error_report(e);
889 return VNET_API_ERROR_IN_PROGRESS;
893 if (mp->is_multipath) {
896 dslock (sm, 1 /* release hint */, 10 /* tag */);
899 flags = IP4_ROUTE_FLAG_ADD;
901 flags = IP4_ROUTE_FLAG_DEL;
904 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
906 ip4_add_del_route_next_hop (im, flags,
907 (ip4_address_t *) mp->dst_address,
908 (u32) mp->dst_address_length,
909 (ip4_address_t *) mp->next_hop_address,
910 ntohl(mp->next_hop_sw_if_index),
911 (u32) mp->next_hop_weight,
918 memset (&a, 0, sizeof (a));
919 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
921 a.dst_address_length = mp->dst_address_length;
923 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
924 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
925 a.table_index_or_table_id = fib_index;
930 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
932 dslock (sm, 1 /* release hint */, 2 /* tag */);
936 ai = lm->drop_adj_index;
937 else if (mp->is_local)
938 ai = lm->local_adj_index;
939 else if (mp->is_classify) {
941 memset(&cadj, 0, sizeof(cadj));
942 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
943 cadj.classify.table_index = ntohl(mp->classify_table_index);
944 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
946 return VNET_API_ERROR_NO_SUCH_TABLE;
948 vec_add1 (add_adj, cadj);
952 ai = ip4_fib_lookup_with_table
953 (im, fib_index, &next_hop_address,
954 1 /* disable default route */);
955 if (ai == lm->miss_adj_index) {
957 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
961 nh_adj = ip_get_adjacency (lm, ai);
962 vec_add1 (add_adj, nh_adj[0]);
963 if (mp->lookup_in_vrf) {
964 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
966 add_adj[0].explicit_fib_index = p[0];
970 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
974 ip_adjacency_t * adj;
975 int disable_default_route = 1;
977 /* Trying to delete the default route? */
978 if (a.dst_address.as_u32 == 0 &&
979 a.dst_address_length == 0)
980 disable_default_route = 0;
982 ai = ip4_fib_lookup_with_table
983 (im, fib_index, &a.dst_address, disable_default_route);
984 if (ai == lm->miss_adj_index) {
986 return VNET_API_ERROR_UNKNOWN_DESTINATION;
989 adj = ip_get_adjacency (lm, ai);
990 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
992 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
999 a.n_add_adj = vec_len(add_adj);
1000 ip4_add_del_route (im, &a);
1008 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1010 ip6_main_t * im = &ip6_main;
1011 ip_lookup_main_t * lm = &im->lookup_main;
1012 vnet_main_t * vnm = vnet_get_main();
1013 vlib_main_t * vm = vlib_get_main();
1014 vpe_api_main_t * vam = &vpe_api_main;
1015 stats_main_t * sm = &stats_main;
1016 ip6_add_del_route_args_t a;
1017 ip6_address_t next_hop_address;
1018 pending_route_t * pr;
1019 vl_api_ip_add_del_route_t * adr;
1024 ip_adjacency_t * nh_adj, * add_adj = 0;
1027 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1030 if (mp->create_vrf_if_needed) {
1032 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1034 fib_index = f->index;
1036 /* No such VRF, and we weren't asked to create one */
1037 return VNET_API_ERROR_NO_SUCH_FIB;
1043 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1044 ntohl(mp->next_hop_sw_if_index)))
1045 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1047 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1048 sizeof (next_hop_address.as_u8));
1050 /* Arp for the next_hop if necessary */
1051 if (mp->is_add && mp->resolve_if_needed) {
1053 ip_adjacency_t * adj;
1055 lookup_result = ip6_fib_lookup_with_table
1056 (im, fib_index, &next_hop_address);
1058 adj = ip_get_adjacency (lm, lookup_result);
1060 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1061 pool_get (vam->pending_routes, pr);
1063 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1064 clib_memcpy (adr, mp, sizeof (*adr));
1065 /* recursion block, "just in case" */
1066 adr->resolve_if_needed = 0;
1067 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1068 vnet_register_ip6_neighbor_resolution_event
1069 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1070 RESOLUTION_EVENT, pr - vam->pending_routes);
1072 vlib_process_signal_event
1073 (vm, vpe_resolver_process_node.index,
1074 RESOLUTION_PENDING_EVENT, 0 /* data */);
1076 /* The interface may be down, etc. */
1077 e = ip6_probe_neighbor
1078 (vm, (ip6_address_t *)&(mp->next_hop_address),
1079 ntohl(mp->next_hop_sw_if_index));
1082 clib_error_report(e);
1084 return VNET_API_ERROR_IN_PROGRESS;
1088 if (mp->is_multipath) {
1091 dslock (sm, 1 /* release hint */, 11 /* tag */);
1094 flags = IP6_ROUTE_FLAG_ADD;
1096 flags = IP6_ROUTE_FLAG_DEL;
1099 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1101 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1102 (u32) mp->dst_address_length,
1103 (ip6_address_t *)mp->next_hop_address,
1104 ntohl(mp->next_hop_sw_if_index),
1105 (u32) mp->next_hop_weight,
1112 memset (&a, 0, sizeof (a));
1113 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1115 a.dst_address_length = mp->dst_address_length;
1117 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1118 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1119 a.table_index_or_table_id = fib_index;
1124 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1126 dslock (sm, 1 /* release hint */, 3 /* tag */);
1130 ai = lm->drop_adj_index;
1131 else if (mp->is_local)
1132 ai = lm->local_adj_index;
1134 ai = ip6_fib_lookup_with_table
1135 (im, fib_index, &next_hop_address);
1136 if (ai == lm->miss_adj_index) {
1138 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1142 nh_adj = ip_get_adjacency (lm, ai);
1143 vec_add1 (add_adj, nh_adj[0]);
1144 if (mp->lookup_in_vrf) {
1145 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1147 add_adj[0].explicit_fib_index = p[0];
1151 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1155 ip_adjacency_t * adj;
1157 ai = ip6_fib_lookup_with_table
1158 (im, fib_index, &a.dst_address);
1159 if (ai == lm->miss_adj_index) {
1161 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1163 adj = ip_get_adjacency (lm, ai);
1164 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1166 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1171 a.add_adj = add_adj;
1172 a.n_add_adj = vec_len(add_adj);
1173 ip6_add_del_route (im, &a);
1181 void vl_api_ip_add_del_route_t_handler (
1182 vl_api_ip_add_del_route_t *mp)
1184 vl_api_ip_add_del_route_reply_t * rmp;
1186 vnet_main_t * vnm = vnet_get_main();
1191 rv = ip6_add_del_route_t_handler (mp);
1193 rv = ip4_add_del_route_t_handler (mp);
1195 rv = (rv == 0) ? vnm->api_errno : rv;
1197 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1200 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1201 u32 sw_if_index, u8 *next_hop_addr)
1203 vl_api_ip_add_del_route_t mp;
1206 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1209 * Configure default IP route:
1210 * - ip route add 0.0.0.0/1 via <GW IP>
1211 * - ip route add 128.0.0.0/1 via <GW IP>
1213 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1215 mp.resolve_attempts = ~0;
1216 mp.resolve_if_needed = 1;
1218 mp.is_ipv6 = is_ipv6;
1219 mp.next_hop_weight = 1;
1221 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1224 rv = ip6_add_del_route_t_handler (&mp);
1227 mp.dst_address_length = 1;
1229 mp.dst_address[0] = 0;
1230 rv = ip4_add_del_route_t_handler (&mp);
1232 mp.dst_address[0] = 128;
1233 rv |= ip4_add_del_route_t_handler (&mp);
1237 clib_error_return (0, "failed to config default IP route");
1242 vl_api_sw_interface_add_del_address_t_handler
1243 (vl_api_sw_interface_add_del_address_t *mp)
1245 vlib_main_t *vm = vlib_get_main();
1246 vl_api_sw_interface_add_del_address_reply_t * rmp;
1250 VALIDATE_SW_IF_INDEX(mp);
1252 is_del = mp->is_add == 0;
1255 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1256 else if (mp->is_ipv6)
1257 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1258 (void *)mp->address,
1259 mp->address_length, is_del);
1261 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1262 (void *) mp->address,
1263 mp->address_length, is_del);
1265 BAD_SW_IF_INDEX_LABEL;
1267 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1271 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1274 u32 table_id = ntohl(mp->vrf_id);
1275 u32 sw_if_index = ntohl(mp->sw_if_index);
1276 vl_api_sw_interface_set_table_reply_t * rmp;
1277 stats_main_t * sm = &stats_main;
1279 VALIDATE_SW_IF_INDEX(mp);
1281 dslock (sm, 1 /* release hint */, 4 /* tag */);
1284 ip6_main_t * im = &ip6_main;
1286 find_ip6_fib_by_table_index_or_id (im, table_id,
1287 IP6_ROUTE_FLAG_TABLE_ID);
1289 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1290 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1292 rv = VNET_API_ERROR_NO_SUCH_FIB;
1295 ip4_main_t * im = &ip4_main;
1296 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1297 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1299 /* Truthfully this can't fail */
1301 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1302 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1304 rv = VNET_API_ERROR_NO_SUCH_FIB;
1309 BAD_SW_IF_INDEX_LABEL;
1311 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1315 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1317 vlib_main_t *vm = vlib_get_main();
1318 vl_api_sw_interface_set_vpath_reply_t * rmp;
1321 u32 sw_if_index = ntohl(mp->sw_if_index);
1322 ip4_main_t *ip4m = &ip4_main;
1323 ip6_main_t *ip6m = &ip6_main;
1324 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1325 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1326 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1327 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1328 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1329 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1331 VALIDATE_SW_IF_INDEX(mp);
1333 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1335 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1336 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1337 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1338 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1339 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1340 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1341 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1342 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1343 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1344 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1345 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1346 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1347 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1348 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1349 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1350 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1352 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1353 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1354 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1355 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1356 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1357 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1358 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1359 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1360 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1361 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1362 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1363 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1364 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1365 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1366 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1367 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1370 BAD_SW_IF_INDEX_LABEL;
1372 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1376 vl_api_sw_interface_set_l2_xconnect_t_handler (
1377 vl_api_sw_interface_set_l2_xconnect_t *mp)
1379 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1381 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1382 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1383 vlib_main_t *vm = vlib_get_main();
1384 vnet_main_t *vnm = vnet_get_main();
1386 VALIDATE_RX_SW_IF_INDEX(mp);
1389 VALIDATE_TX_SW_IF_INDEX(mp);
1390 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1391 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1393 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1396 BAD_RX_SW_IF_INDEX_LABEL;
1397 BAD_TX_SW_IF_INDEX_LABEL;
1399 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1403 vl_api_sw_interface_set_l2_bridge_t_handler (
1404 vl_api_sw_interface_set_l2_bridge_t *mp)
1406 bd_main_t * bdm = &bd_main;
1407 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1409 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1410 u32 bd_id = ntohl(mp->bd_id);
1414 vlib_main_t *vm = vlib_get_main();
1415 vnet_main_t *vnm = vnet_get_main();
1417 VALIDATE_RX_SW_IF_INDEX(mp);
1419 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1422 //VALIDATE_TX_SW_IF_INDEX(mp);
1423 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1424 rx_sw_if_index, bd_index, bvi, shg, 0);
1426 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1429 BAD_RX_SW_IF_INDEX_LABEL;
1431 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1435 vl_api_bridge_domain_add_del_t_handler (
1436 vl_api_bridge_domain_add_del_t *mp)
1438 vlib_main_t * vm = vlib_get_main ();
1439 bd_main_t * bdm = &bd_main;
1440 vl_api_bridge_domain_add_del_reply_t * rmp;
1442 u32 enable_flags = 0, disable_flags = 0;
1443 u32 bd_id = ntohl(mp->bd_id);
1447 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1450 enable_flags |= L2_FLOOD;
1452 disable_flags |= L2_FLOOD;
1455 enable_flags |= L2_UU_FLOOD;
1457 disable_flags |= L2_UU_FLOOD;
1460 enable_flags |= L2_FWD;
1462 disable_flags |= L2_FWD;
1465 enable_flags |= L2_ARP_TERM;
1467 disable_flags |= L2_ARP_TERM;
1470 enable_flags |= L2_LEARN;
1472 disable_flags |= L2_LEARN;
1475 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1478 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1481 rv = bd_delete_bd_index(bdm, bd_id);
1483 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1486 static void vl_api_bridge_domain_details_t_handler (
1487 vl_api_bridge_domain_details_t * mp)
1489 clib_warning ("BUG");
1492 static void vl_api_bridge_domain_sw_if_details_t_handler (
1493 vl_api_bridge_domain_sw_if_details_t * mp)
1495 clib_warning ("BUG");
1498 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1499 l2_bridge_domain_t * bd_config,
1503 vl_api_bridge_domain_details_t * mp;
1505 mp = vl_msg_api_alloc (sizeof (*mp));
1506 memset (mp, 0, sizeof (*mp));
1507 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1508 mp->bd_id = ntohl (bd_config->bd_id);
1509 mp->flood = bd_feature_flood (bd_config);
1510 mp->uu_flood = bd_feature_uu_flood (bd_config);
1511 mp->forward = bd_feature_forward (bd_config);
1512 mp->learn = bd_feature_learn (bd_config);
1513 mp->arp_term = bd_feature_arp_term (bd_config);
1514 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1515 mp->n_sw_ifs = ntohl (n_sw_ifs);
1516 mp->context = context;
1518 vl_msg_api_send_shmem (q, (u8 *)&mp);
1521 static void send_bd_sw_if_details (l2input_main_t * l2im,
1522 unix_shared_memory_queue_t *q,
1523 l2_flood_member_t * member, u32 bd_id,
1526 vl_api_bridge_domain_sw_if_details_t * mp;
1527 l2_input_config_t * input_cfg;
1529 mp = vl_msg_api_alloc (sizeof (*mp));
1530 memset (mp, 0, sizeof (*mp));
1531 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1532 mp->bd_id = ntohl (bd_id);
1533 mp->sw_if_index = ntohl (member->sw_if_index);
1534 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1535 mp->shg = input_cfg->shg;
1536 mp->context = context;
1538 vl_msg_api_send_shmem (q, (u8 *)&mp);
1541 static void vl_api_bridge_domain_dump_t_handler (
1542 vl_api_bridge_domain_dump_t *mp)
1544 bd_main_t * bdm = &bd_main;
1545 l2input_main_t * l2im = &l2input_main;
1546 unix_shared_memory_queue_t * q;
1547 l2_bridge_domain_t * bd_config;
1548 u32 bd_id, bd_index;
1551 q = vl_api_client_index_to_input_queue (mp->client_index);
1556 bd_id = ntohl(mp->bd_id);
1558 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1559 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1560 for (; bd_index < end; bd_index++) {
1561 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1562 /* skip dummy bd_id 0 */
1563 if (bd_config && (bd_config->bd_id > 0)) {
1565 l2_flood_member_t * m;
1567 n_sw_ifs = vec_len (bd_config->members);
1568 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1570 vec_foreach (m, bd_config->members) {
1571 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1578 vl_api_l2fib_add_del_t_handler (
1579 vl_api_l2fib_add_del_t *mp)
1581 bd_main_t * bdm = &bd_main;
1582 l2input_main_t * l2im = &l2input_main;
1583 vl_api_l2fib_add_del_reply_t * rmp;
1586 u32 sw_if_index = ntohl(mp->sw_if_index);
1587 u32 bd_id = ntohl(mp->bd_id);
1595 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1597 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1598 goto bad_sw_if_index;
1603 VALIDATE_SW_IF_INDEX(mp);
1604 if (vec_len(l2im->configs) <= sw_if_index) {
1605 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1606 goto bad_sw_if_index;
1608 l2_input_config_t * config;
1609 config = vec_elt_at_index(l2im->configs, sw_if_index);
1610 if (config->bridge == 0) {
1611 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1612 goto bad_sw_if_index;
1615 static_mac = mp->static_mac ? 1 : 0;
1616 filter_mac = mp->filter_mac ? 1 : 0;
1617 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1620 l2fib_del_entry(mac, bd_index);
1623 BAD_SW_IF_INDEX_LABEL;
1625 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1629 vl_api_l2_flags_t_handler (
1630 vl_api_l2_flags_t *mp)
1632 vl_api_l2_flags_reply_t * rmp;
1634 u32 sw_if_index = ntohl(mp->sw_if_index);
1635 u32 flags = ntohl(mp->feature_bitmap);
1638 VALIDATE_SW_IF_INDEX(mp);
1641 if (flags & L2INPUT_FEAT_ ## a) \
1642 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1643 foreach_l2input_feat;
1646 BAD_SW_IF_INDEX_LABEL;
1648 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1652 vl_api_bridge_flags_t_handler (
1653 vl_api_bridge_flags_t *mp)
1655 vlib_main_t *vm = vlib_get_main();
1656 bd_main_t * bdm = &bd_main;
1657 vl_api_bridge_flags_reply_t * rmp;
1659 u32 bd_id = ntohl(mp->bd_id);
1661 u32 flags = ntohl(mp->feature_bitmap);
1664 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1666 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1672 bd_set_flags(vm, bd_index, flags, mp->is_set);
1675 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1676 rmp->resulting_feature_bitmap = ntohl(flags));
1680 vl_api_bd_ip_mac_add_del_t_handler (
1681 vl_api_bd_ip_mac_add_del_t *mp)
1683 bd_main_t * bdm = &bd_main;
1684 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1686 u32 bd_id = ntohl(mp->bd_id);
1690 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1692 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1697 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1698 mp->mac_address, mp->is_ipv6, mp->is_add))
1699 rv = VNET_API_ERROR_UNSPECIFIED;
1702 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1706 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1709 vl_api_tap_connect_reply_t * rmp;
1710 unix_shared_memory_queue_t * q;
1711 u32 sw_if_index = (u32)~0;
1713 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1714 mp->use_random_mac ? 0 : mp->mac_address,
1715 &sw_if_index, mp->renumber,
1716 ntohl(mp->custom_dev_instance));
1718 q = vl_api_client_index_to_input_queue (mp->client_index);
1722 rmp = vl_msg_api_alloc (sizeof (*rmp));
1723 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1724 rmp->context = mp->context;
1725 rmp->retval = ntohl(rv);
1726 rmp->sw_if_index = ntohl(sw_if_index);
1728 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1732 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1735 vl_api_tap_modify_reply_t * rmp;
1736 unix_shared_memory_queue_t * q;
1737 u32 sw_if_index = (u32)~0;
1739 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1740 mp->use_random_mac ? 0 : mp->mac_address,
1741 &sw_if_index, mp->renumber,
1742 ntohl(mp->custom_dev_instance));
1744 q = vl_api_client_index_to_input_queue (mp->client_index);
1748 rmp = vl_msg_api_alloc (sizeof (*rmp));
1749 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1750 rmp->context = mp->context;
1751 rmp->retval = ntohl(rv);
1752 rmp->sw_if_index = ntohl(sw_if_index);
1754 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1758 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1761 vpe_api_main_t * vam = &vpe_api_main;
1762 vl_api_tap_delete_reply_t * rmp;
1763 unix_shared_memory_queue_t * q;
1764 u32 sw_if_index = ntohl(mp->sw_if_index);
1766 rv = vnet_tap_delete (vm, sw_if_index);
1768 q = vl_api_client_index_to_input_queue (mp->client_index);
1772 rmp = vl_msg_api_alloc (sizeof (*rmp));
1773 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1774 rmp->context = mp->context;
1775 rmp->retval = ntohl(rv);
1777 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1780 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1784 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1786 vl_api_create_vlan_subif_reply_t * rmp;
1787 vnet_main_t * vnm = vnet_get_main();
1788 u32 hw_if_index, sw_if_index = (u32)~0;
1789 vnet_hw_interface_t * hi;
1792 vnet_sw_interface_t template;
1794 vnet_interface_main_t * im = &vnm->interface_main;
1795 u64 sup_and_sub_key;
1797 unix_shared_memory_queue_t * q;
1798 clib_error_t * error;
1800 VALIDATE_SW_IF_INDEX(mp);
1802 hw_if_index = ntohl(mp->sw_if_index);
1803 hi = vnet_get_hw_interface (vnm, hw_if_index);
1805 id = ntohl(mp->vlan_id);
1806 if (id == 0 || id > 4095) {
1807 rv = VNET_API_ERROR_INVALID_VLAN;
1811 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1813 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1815 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1819 kp = clib_mem_alloc (sizeof (*kp));
1820 *kp = sup_and_sub_key;
1822 memset (&template, 0, sizeof (template));
1823 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1824 template.sup_sw_if_index = hi->sw_if_index;
1825 template.sub.id = id;
1826 template.sub.eth.raw_flags = 0;
1827 template.sub.eth.flags.one_tag = 1;
1828 template.sub.eth.outer_vlan_id = id;
1829 template.sub.eth.flags.exact_match = 1;
1831 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1833 clib_error_report(error);
1834 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1837 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1838 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1840 BAD_SW_IF_INDEX_LABEL;
1843 q = vl_api_client_index_to_input_queue (mp->client_index);
1847 rmp = vl_msg_api_alloc (sizeof (*rmp));
1848 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1849 rmp->context = mp->context;
1850 rmp->retval = ntohl(rv);
1851 rmp->sw_if_index = ntohl(sw_if_index);
1852 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1856 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1858 vl_api_create_subif_reply_t * rmp;
1859 vnet_main_t * vnm = vnet_get_main();
1860 u32 sw_if_index = ~0;
1863 vnet_sw_interface_t *si;
1864 vnet_hw_interface_t *hi;
1865 vnet_sw_interface_t template;
1867 vnet_interface_main_t * im = &vnm->interface_main;
1868 u64 sup_and_sub_key;
1870 clib_error_t * error;
1872 VALIDATE_SW_IF_INDEX(mp);
1874 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1875 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1877 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1878 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1882 sw_if_index = si->sw_if_index;
1883 sub_id = ntohl(mp->sub_id);
1885 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1887 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1890 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1891 sw_if_index, sub_id);
1892 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1896 kp = clib_mem_alloc (sizeof (*kp));
1897 *kp = sup_and_sub_key;
1899 memset (&template, 0, sizeof (template));
1900 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1901 template.sup_sw_if_index = sw_if_index;
1902 template.sub.id = sub_id;
1903 template.sub.eth.flags.no_tags = mp->no_tags;
1904 template.sub.eth.flags.one_tag = mp->one_tag;
1905 template.sub.eth.flags.two_tags = mp->two_tags;
1906 template.sub.eth.flags.dot1ad = mp->dot1ad;
1907 template.sub.eth.flags.exact_match = mp->exact_match;
1908 template.sub.eth.flags.default_sub = mp->default_sub;
1909 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1910 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1911 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1912 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1914 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1916 clib_error_report (error);
1917 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1921 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1922 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1924 BAD_SW_IF_INDEX_LABEL;
1928 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1930 rmp->sw_if_index = ntohl(sw_if_index);
1935 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1937 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1939 stats_main_t * sm = &stats_main;
1940 u32 tunnel_sw_if_index = ~0;
1942 dslock (sm, 1 /* release hint */, 5 /* tag */);
1944 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1945 (ip4_address_t *)(mp->dst_address),
1946 (ip4_address_t *)(mp->intfc_address),
1947 (u32)(mp->intfc_address_length),
1948 ntohl(mp->inner_vrf_id),
1949 ntohl(mp->outer_vrf_id),
1950 &tunnel_sw_if_index,
1955 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1957 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1962 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1963 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1965 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1967 stats_main_t * sm = &stats_main;
1968 u32 tunnel_sw_if_index;
1970 dslock (sm, 1 /* release hint */, 5 /* tag */);
1972 rv = vnet_mpls_ethernet_add_del_tunnel
1973 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1974 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1975 ntohl(mp->tx_sw_if_index),
1976 &tunnel_sw_if_index,
1982 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1984 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1989 * This piece of misery brought to you because the control-plane
1990 * can't figure out the tx interface + dst-mac address all by itself
1992 static int mpls_ethernet_add_del_tunnel_2_t_handler
1993 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1995 pending_route_t * pr;
1996 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1997 vnet_main_t * vnm = vnet_get_main();
1998 vlib_main_t * vm = vlib_get_main();
1999 stats_main_t * sm = &stats_main;
2000 vpe_api_main_t * vam = &vpe_api_main;
2001 u32 inner_fib_index, outer_fib_index;
2002 ip4_main_t * im = &ip4_main;
2003 ip_lookup_main_t * lm = &im->lookup_main;
2004 ip_adjacency_t * adj = 0;
2007 u8 * dst_mac_address;
2011 u32 tunnel_sw_if_index;
2013 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2015 return VNET_API_ERROR_NO_SUCH_FIB;
2017 outer_fib_index = p[0];
2020 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2022 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2024 inner_fib_index = p[0];
2026 if (inner_fib_index == outer_fib_index)
2027 return VNET_API_ERROR_INVALID_VALUE;
2029 lookup_result = ip4_fib_lookup_with_table
2030 (im, outer_fib_index,
2031 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2032 1 /* disable default route */);
2034 adj = ip_get_adjacency (lm, lookup_result);
2035 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2037 if (mp->is_add && mp->resolve_if_needed) {
2038 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2039 pool_get (vam->pending_routes, pr);
2040 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2042 clib_memcpy (pme, mp, sizeof (*pme));
2043 /* recursion block, "just in case" */
2044 pme->resolve_if_needed = 0;
2045 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2046 pme->resolve_opaque = tx_sw_if_index;
2047 vnet_register_ip4_arp_resolution_event
2049 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2050 vpe_resolver_process_node.index,
2051 RESOLUTION_EVENT, pr - vam->pending_routes);
2053 vlib_process_signal_event
2054 (vm, vpe_resolver_process_node.index,
2055 RESOLUTION_PENDING_EVENT, 0 /* data */);
2057 /* The interface may be down, etc. */
2058 e = ip4_probe_neighbor
2059 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2063 clib_error_report(e);
2065 return VNET_API_ERROR_IN_PROGRESS;
2069 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2070 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2073 vnet_rewrite_get_data_internal
2074 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2076 dslock (sm, 1 /* release hint */, 10 /* tag */);
2078 rv = vnet_mpls_ethernet_add_del_tunnel
2079 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2080 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2081 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2089 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2090 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2092 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2095 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2097 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2102 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2104 vl_api_mpls_add_del_encap_reply_t * rmp;
2106 static u32 * labels;
2109 vec_reset_length (labels);
2111 for (i = 0; i < mp->nlabels; i++)
2112 vec_add1 (labels, ntohl(mp->labels[i]));
2115 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2116 ntohl(mp->vrf_id), labels,
2117 ~0 /* policy_tunnel_index */,
2118 0 /* no_dst_hash */,
2122 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2126 vl_api_mpls_add_del_decap_t_handler
2127 (vl_api_mpls_add_del_decap_t *mp)
2129 vl_api_mpls_add_del_decap_reply_t * rmp;
2132 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2133 ntohl(mp->label), ntohl(mp->next_index),
2134 mp->s_bit, mp->is_add);
2136 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2140 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2142 vl_api_proxy_arp_add_del_reply_t * rmp;
2145 ip4_main_t * im = &ip4_main;
2146 stats_main_t * sm = &stats_main;
2147 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2148 ip4_address_t *hi_addr,
2149 u32 fib_index, int is_del);
2152 dslock (sm, 1 /* release hint */, 6 /* tag */);
2154 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2157 rv = VNET_API_ERROR_NO_SUCH_FIB;
2163 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2164 (ip4_address_t *)mp->hi_address,
2165 fib_index, mp->is_add == 0);
2169 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2173 vl_api_proxy_arp_intfc_enable_disable_t_handler
2174 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2177 vnet_main_t * vnm = vnet_get_main();
2178 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2179 vnet_sw_interface_t * si;
2182 VALIDATE_SW_IF_INDEX(mp);
2184 sw_if_index = ntohl(mp->sw_if_index);
2186 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2188 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2192 si = vnet_get_sw_interface (vnm, sw_if_index);
2196 if (mp->enable_disable)
2197 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2199 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2201 BAD_SW_IF_INDEX_LABEL;
2204 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2208 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2210 vl_api_ip_neighbor_add_del_reply_t * rmp;
2211 vnet_main_t * vnm = vnet_get_main();
2214 stats_main_t * sm = &stats_main;
2216 VALIDATE_SW_IF_INDEX(mp);
2218 dslock (sm, 1 /* release hint */, 7 /* tag */);
2222 rv = vnet_set_ip6_ethernet_neighbor
2223 (vm, ntohl(mp->sw_if_index),
2224 (ip6_address_t *)(mp->dst_address),
2225 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2227 rv = vnet_unset_ip6_ethernet_neighbor
2228 (vm, ntohl(mp->sw_if_index),
2229 (ip6_address_t *)(mp->dst_address),
2230 mp->mac_address, sizeof(mp->mac_address));
2232 ip4_main_t * im = &ip4_main;
2233 ip_lookup_main_t * lm = &im->lookup_main;
2234 ethernet_arp_ip4_over_ethernet_address_t a;
2236 ip_adjacency_t *nh_adj;
2238 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2240 rv = VNET_API_ERROR_NO_SUCH_FIB;
2246 * Unfortunately, folks have a penchant for
2247 * adding interface addresses to the ARP cache, and
2248 * wondering why the forwarder eventually ASSERTs...
2250 ai = ip4_fib_lookup_with_table
2251 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2252 1 /* disable default route */);
2255 nh_adj = ip_get_adjacency (lm, ai);
2256 /* Never allow manipulation of a local adj! */
2257 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2258 clib_warning("%U matches local adj",
2260 (ip4_address_t *)(mp->dst_address));
2261 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2266 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2267 clib_memcpy (&a.ip4, mp->dst_address, 4);
2270 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2271 fib_index, &a, mp->is_static);
2273 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2277 BAD_SW_IF_INDEX_LABEL;
2280 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2284 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2287 vpe_main_t *rm = &vpe_main;
2288 ip4_main_t *im4 = &ip4_main;
2289 ip6_main_t *im6 = &ip6_main;
2290 ip_lookup_main_t * lm;
2295 u32 adj_index, sw_if_index;
2296 vl_api_is_address_reachable_t *rmp;
2297 ip_adjacency_t * adj;
2298 unix_shared_memory_queue_t *q;
2300 q = vl_api_client_index_to_input_queue (mp->client_index);
2302 increment_missing_api_client_counter (rm->vlib_main);
2306 rmp = vl_msg_api_alloc (sizeof (*rmp));
2307 clib_memcpy (rmp, mp, sizeof (*rmp));
2309 sw_if_index = mp->next_hop_sw_if_index;
2310 clib_memcpy (&addr, mp->address, sizeof (addr));
2312 lm = &im6->lookup_main;
2314 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2316 lm = &im4->lookup_main;
2318 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2320 if (adj_index == ~0) {
2324 adj = ip_get_adjacency (lm, adj_index);
2326 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2327 && adj->rewrite_header.sw_if_index == sw_if_index) {
2330 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2331 && adj->rewrite_header.sw_if_index == sw_if_index) {
2333 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2335 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2336 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2344 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2348 static void vl_api_sw_interface_details_t_handler (
2349 vl_api_sw_interface_details_t * mp)
2351 clib_warning ("BUG");
2354 static void vl_api_sw_interface_set_flags_t_handler (
2355 vl_api_sw_interface_set_flags_t * mp)
2357 vl_api_sw_interface_set_flags_reply_t *rmp;
2358 vnet_main_t * vnm = vnet_get_main();
2360 clib_error_t * error;
2363 VALIDATE_SW_IF_INDEX(mp);
2365 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2367 error = vnet_sw_interface_set_flags (vnm,
2368 ntohl(mp->sw_if_index),
2372 clib_error_report (error);
2375 BAD_SW_IF_INDEX_LABEL;
2376 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2379 static void vl_api_sw_interface_clear_stats_t_handler (
2380 vl_api_sw_interface_clear_stats_t * mp)
2382 vl_api_sw_interface_clear_stats_reply_t *rmp;
2384 vnet_main_t * vnm = vnet_get_main();
2385 vnet_interface_main_t * im = &vnm->interface_main;
2386 vlib_simple_counter_main_t * sm;
2387 vlib_combined_counter_main_t * cm;
2388 static vnet_main_t ** my_vnet_mains;
2389 int i, j, n_counters;
2393 vec_reset_length (my_vnet_mains);
2395 for (i = 0; i < vec_len (vnet_mains); i++)
2398 vec_add1 (my_vnet_mains, vnet_mains[i]);
2401 if (vec_len (vnet_mains) == 0)
2402 vec_add1 (my_vnet_mains, vnm);
2404 n_counters = vec_len (im->combined_sw_if_counters);
2406 for (j = 0; j < n_counters; j++)
2408 for (i = 0; i < vec_len(my_vnet_mains); i++)
2410 im = &my_vnet_mains[i]->interface_main;
2411 cm = im->combined_sw_if_counters + j;
2412 if (mp->sw_if_index == (u32)~0)
2413 vlib_clear_combined_counters (cm);
2415 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2419 n_counters = vec_len (im->sw_if_counters);
2421 for (j = 0; j < n_counters; j++)
2423 for (i = 0; i < vec_len(my_vnet_mains); i++)
2425 im = &my_vnet_mains[i]->interface_main;
2426 sm = im->sw_if_counters + j;
2427 if (mp->sw_if_index == (u32)~0)
2428 vlib_clear_simple_counters (sm);
2430 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2434 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2437 static void send_sw_interface_details (vpe_api_main_t * am,
2438 unix_shared_memory_queue_t *q,
2439 vnet_sw_interface_t * swif,
2440 u8 * interface_name,
2443 vl_api_sw_interface_details_t * mp;
2444 vnet_hw_interface_t * hi;
2446 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2448 mp = vl_msg_api_alloc (sizeof (*mp));
2449 memset (mp, 0, sizeof (*mp));
2450 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2451 mp->sw_if_index = ntohl(swif->sw_if_index);
2452 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2453 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2455 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2457 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2458 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2459 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2460 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2461 mp->link_mtu = ntohs(hi->max_packet_bytes);
2462 mp->context = context;
2464 strncpy ((char *) mp->interface_name,
2465 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2467 /* Send the L2 address for ethernet physical intfcs */
2468 if (swif->sup_sw_if_index == swif->sw_if_index
2469 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2470 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2471 ethernet_interface_t *ei;
2473 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2474 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2475 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2476 mp->l2_address_length = ntohl(sizeof (ei->address));
2477 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2478 vnet_sub_interface_t *sub = &swif->sub;
2479 mp->sub_id = ntohl(sub->id);
2480 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2481 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2482 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2483 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2484 mp->sub_exact_match = sub->eth.flags.exact_match;
2485 mp->sub_default = sub->eth.flags.default_sub;
2486 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2487 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2489 /* vlan tag rewrite data */
2490 u32 vtr_op = L2_VTR_DISABLED;
2491 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2493 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2494 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2495 // error - default to disabled
2496 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2497 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2500 mp->vtr_op = ntohl(vtr_op);
2501 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2502 mp->vtr_tag1 = ntohl(vtr_tag1);
2503 mp->vtr_tag2 = ntohl(vtr_tag2);
2507 vl_msg_api_send_shmem (q, (u8 *)&mp);
2510 static void send_sw_interface_flags (vpe_api_main_t * am,
2511 unix_shared_memory_queue_t *q,
2512 vnet_sw_interface_t * swif)
2514 vl_api_sw_interface_set_flags_t *mp;
2515 vnet_main_t * vnm = am->vnet_main;
2517 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2519 mp = vl_msg_api_alloc (sizeof (*mp));
2520 memset (mp, 0, sizeof (*mp));
2521 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2522 mp->sw_if_index = ntohl(swif->sw_if_index);
2524 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2526 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2528 vl_msg_api_send_shmem (q, (u8 *)&mp);
2531 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2532 unix_shared_memory_queue_t *q,
2534 __attribute__((unused));
2536 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2537 unix_shared_memory_queue_t *q,
2540 vl_api_sw_interface_set_flags_t *mp;
2542 mp = vl_msg_api_alloc (sizeof (*mp));
2543 memset (mp, 0, sizeof (*mp));
2544 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2545 mp->sw_if_index = ntohl(sw_if_index);
2547 mp->admin_up_down = 0;
2548 mp->link_up_down = 0;
2550 vl_msg_api_send_shmem (q, (u8 *)&mp);
2553 static void vl_api_sw_interface_dump_t_handler (
2554 vl_api_sw_interface_dump_t *mp)
2556 vpe_api_main_t * am = &vpe_api_main;
2557 vnet_sw_interface_t * swif;
2558 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2559 u8 * filter_string = 0, * name_string = 0;
2560 unix_shared_memory_queue_t * q;
2561 char * strcasestr (char *, char *); /* lnx hdr file botch */
2563 q = vl_api_client_index_to_input_queue (mp->client_index);
2568 if (mp->name_filter_valid) {
2569 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2570 filter_string = format (0, "%s%c", mp->name_filter, 0);
2573 pool_foreach (swif, im->sw_interfaces,
2575 name_string = format (name_string, "%U%c",
2576 format_vnet_sw_interface_name,
2577 am->vnet_main, swif, 0);
2579 if (mp->name_filter_valid == 0 ||
2580 strcasestr((char *) name_string, (char *) filter_string)) {
2582 send_sw_interface_details (am, q, swif, name_string, mp->context);
2583 send_sw_interface_flags (am, q, swif);
2585 _vec_len (name_string) = 0;
2588 vec_free (name_string);
2589 vec_free (filter_string);
2592 void send_oam_event (oam_target_t * t)
2594 vpe_api_main_t * vam = &vpe_api_main;
2595 unix_shared_memory_queue_t * q;
2596 vpe_client_registration_t *reg;
2597 vl_api_oam_event_t * mp;
2599 pool_foreach(reg, vam->oam_events_registrations,
2601 q = vl_api_client_index_to_input_queue (reg->client_index);
2603 mp = vl_msg_api_alloc (sizeof (*mp));
2604 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2605 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2606 mp->state = t->state;
2607 vl_msg_api_send_shmem (q, (u8 *)&mp);
2613 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2615 vl_api_oam_add_del_reply_t * rmp;
2618 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2619 (ip4_address_t *)mp->dst_address,
2623 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2627 vl_api_vnet_get_summary_stats_t_handler (
2628 vl_api_vnet_get_summary_stats_t *mp)
2630 stats_main_t * sm = &stats_main;
2631 vnet_interface_main_t * im = sm->interface_main;
2632 vl_api_vnet_summary_stats_reply_t *rmp;
2633 vlib_combined_counter_main_t * cm;
2636 u64 total_pkts[VLIB_N_RX_TX];
2637 u64 total_bytes[VLIB_N_RX_TX];
2639 unix_shared_memory_queue_t * q =
2640 vl_api_client_index_to_input_queue (mp->client_index);
2645 rmp = vl_msg_api_alloc (sizeof (*rmp));
2646 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2647 rmp->context = mp->context;
2650 memset (total_pkts, 0, sizeof (total_pkts));
2651 memset (total_bytes, 0, sizeof (total_bytes));
2653 vnet_interface_counter_lock (im);
2655 vec_foreach (cm, im->combined_sw_if_counters) {
2656 which = cm - im->combined_sw_if_counters;
2658 for (i = 0; i < vec_len (cm->maxi); i++) {
2659 vlib_get_combined_counter (cm, i, &v);
2660 total_pkts[which] += v.packets;
2661 total_bytes[which] += v.bytes;
2664 vnet_interface_counter_unlock (im);
2666 /* Note: in HOST byte order! */
2667 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2668 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2669 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2670 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2671 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2673 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2676 typedef CLIB_PACKED (struct {
2677 ip4_address_t address;
2679 u32 address_length : 6;
2684 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2686 vnet_main_t * vnm = vnet_get_main();
2687 vnet_interface_main_t * im = &vnm->interface_main;
2688 ip4_main_t * im4 = &ip4_main;
2689 static ip4_route_t * routes;
2690 static u32 * sw_if_indices_to_shut;
2691 stats_main_t * sm = &stats_main;
2696 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2697 u32 target_fib_id = ntohl(mp->vrf_id);
2699 dslock (sm, 1 /* release hint */, 8 /* tag */);
2701 vec_foreach (fib, im4->fibs) {
2702 vnet_sw_interface_t * si;
2704 if (fib->table_id != target_fib_id)
2707 /* remove any mpls/gre tunnels in this fib */
2708 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2710 /* remove any mpls encap/decap labels */
2711 mpls_fib_reset_labels (fib->table_id);
2713 /* remove any proxy arps in this fib */
2714 vnet_proxy_arp_fib_reset (fib->table_id);
2716 /* Set the flow hash for this fib to the default */
2717 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2719 vec_reset_length (sw_if_indices_to_shut);
2721 /* Shut down interfaces in this FIB / clean out intfc routes */
2722 pool_foreach (si, im->sw_interfaces,
2724 u32 sw_if_index = si->sw_if_index;
2726 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2727 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2729 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2732 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2733 sw_if_index = sw_if_indices_to_shut[i];
2734 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2736 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2737 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2738 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2741 vec_reset_length (routes);
2743 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2744 uword * hash = fib->adj_index_by_dst_address[i];
2748 x.address_length = i;
2750 hash_foreach_pair (p, hash,
2752 x.address.data_u32 = p->key;
2753 vec_add1 (routes, x);
2757 vec_foreach (r, routes) {
2758 ip4_add_del_route_args_t a;
2760 memset (&a, 0, sizeof (a));
2761 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2762 a.table_index_or_table_id = fib - im4->fibs;
2763 a.dst_address = r->address;
2764 a.dst_address_length = r->address_length;
2767 ip4_add_del_route (im4, &a);
2768 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2769 IP4_ROUTE_FLAG_FIB_INDEX);
2773 } /* vec_foreach (fib) */
2780 ip6_address_t address;
2787 ip6_route_t ** routep;
2788 } add_routes_in_fib_arg_t;
2790 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2792 add_routes_in_fib_arg_t * ap = arg;
2794 if (kvp->key[2]>>32 == ap->fib_index)
2796 ip6_address_t *addr;
2798 addr = (ip6_address_t *) kvp;
2799 vec_add2 (*ap->routep, r, 1);
2800 r->address = addr[0];
2801 r->address_length = kvp->key[2] & 0xFF;
2802 r->index = kvp->value;
2806 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2808 vnet_main_t * vnm = vnet_get_main();
2809 vnet_interface_main_t * im = &vnm->interface_main;
2810 ip6_main_t * im6 = &ip6_main;
2811 stats_main_t * sm = &stats_main;
2812 static ip6_route_t * routes;
2813 static u32 * sw_if_indices_to_shut;
2818 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2819 u32 target_fib_id = ntohl(mp->vrf_id);
2820 add_routes_in_fib_arg_t _a, *a=&_a;
2821 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2823 dslock (sm, 1 /* release hint */, 9 /* tag */);
2825 vec_foreach (fib, im6->fibs) {
2826 vnet_sw_interface_t * si;
2828 if (fib->table_id != target_fib_id)
2831 vec_reset_length (sw_if_indices_to_shut);
2833 /* Shut down interfaces in this FIB / clean out intfc routes */
2834 pool_foreach (si, im->sw_interfaces,
2836 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2838 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2841 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2842 sw_if_index = sw_if_indices_to_shut[i];
2843 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2845 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2846 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2847 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2850 vec_reset_length (routes);
2852 a->fib_index = fib - im6->fibs;
2853 a->routep = &routes;
2855 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2857 vec_foreach (r, routes) {
2858 ip6_add_del_route_args_t a;
2860 memset (&a, 0, sizeof (a));
2861 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2862 a.table_index_or_table_id = fib - im6->fibs;
2863 a.dst_address = r->address;
2864 a.dst_address_length = r->address_length;
2867 ip6_add_del_route (im6, &a);
2868 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2869 IP6_ROUTE_FLAG_FIB_INDEX);
2872 /* Reinstall the neighbor / router discovery routes */
2873 vnet_ip6_fib_init (im6, fib - im6->fibs);
2875 } /* vec_foreach (fib) */
2881 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2884 vl_api_reset_fib_reply_t * rmp;
2887 rv = ip6_reset_fib_t_handler (mp);
2889 rv = ip4_reset_fib_t_handler (mp);
2891 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2896 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2898 vl_api_dhcp_proxy_config_reply_t * rmp;
2901 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2902 (ip4_address_t *)(&mp->dhcp_src_address),
2903 (u32) ntohl(mp->vrf_id),
2904 (int) mp->insert_circuit_id,
2905 (int) (mp->is_add == 0));
2907 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2912 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2914 vl_api_dhcp_proxy_config_reply_t * rmp;
2917 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2918 (ip6_address_t *)(&mp->dhcp_src_address),
2919 (u32) ntohl(mp->vrf_id),
2920 (int) mp->insert_circuit_id,
2921 (int) (mp->is_add == 0));
2923 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2927 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2929 vl_api_dhcp_proxy_config_reply_t * rmp;
2932 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2933 (ip4_address_t *)(&mp->dhcp_src_address),
2934 (u32) ntohl(mp->rx_vrf_id),
2935 (u32) ntohl(mp->server_vrf_id),
2936 (int) mp->insert_circuit_id,
2937 (int) (mp->is_add == 0));
2939 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2944 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2946 vl_api_dhcp_proxy_config_reply_t * rmp;
2950 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2951 (ip6_address_t *)(&mp->dhcp_src_address),
2952 (u32) ntohl(mp->rx_vrf_id),
2953 (u32) ntohl(mp->server_vrf_id),
2954 (int) mp->insert_circuit_id,
2955 (int) (mp->is_add == 0));
2957 rv = VNET_API_ERROR_UNIMPLEMENTED;
2960 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2965 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2967 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2970 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2973 (int)mp->is_add == 0);
2975 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2978 (int)mp->is_add == 0);
2980 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2984 static void vl_api_dhcp_proxy_config_t_handler
2985 (vl_api_dhcp_proxy_config_t *mp)
2987 if (mp->is_ipv6 == 0)
2988 dhcpv4_proxy_config (mp);
2990 dhcpv6_proxy_config (mp);
2993 static void vl_api_dhcp_proxy_config_2_t_handler
2994 (vl_api_dhcp_proxy_config_2_t *mp)
2996 if (mp->is_ipv6 == 0)
2997 dhcpv4_proxy_config_2 (mp);
2999 dhcpv6_proxy_config_2 (mp);
3002 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3003 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3005 unix_shared_memory_queue_t * q;
3006 vl_api_dhcp_compl_event_t * mp;
3008 q = vl_api_client_index_to_input_queue (client_index);
3012 mp = vl_msg_api_alloc (sizeof (*mp));
3013 mp->client_index = client_index;
3015 mp->is_ipv6 = is_ipv6;
3016 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3017 mp->hostname[vec_len(hostname) + 1] = '\n';
3018 clib_memcpy (&mp->host_address[0], host_address, 16);
3019 clib_memcpy (&mp->router_address[0], router_address, 16);
3020 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3022 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3024 vl_msg_api_send_shmem (q, (u8 *)&mp);
3027 static void vl_api_dhcp_client_config_t_handler
3028 (vl_api_dhcp_client_config_t *mp)
3030 vlib_main_t *vm = vlib_get_main();
3031 vl_api_dhcp_client_config_reply_t * rmp;
3034 VALIDATE_SW_IF_INDEX(mp);
3036 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3037 mp->hostname, mp->is_add, mp->client_index,
3038 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3041 BAD_SW_IF_INDEX_LABEL;
3043 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3047 vl_api_sw_interface_ip6nd_ra_config_t_handler
3048 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3050 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3052 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3054 is_no = mp->is_no == 1;
3055 surpress = mp->surpress == 1;
3056 managed = mp->managed == 1;
3057 other = mp->other == 1;
3058 ll_option = mp->ll_option == 1;
3059 send_unicast = mp->send_unicast == 1;
3060 cease = mp->cease == 1;
3061 default_router = mp->default_router == 1;
3063 VALIDATE_SW_IF_INDEX(mp);
3065 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3066 surpress, managed, other,
3067 ll_option, send_unicast, cease,
3068 default_router, ntohl (mp->lifetime),
3069 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3070 ntohl(mp->max_interval), ntohl( mp->min_interval),
3073 BAD_SW_IF_INDEX_LABEL;
3075 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3079 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3080 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3082 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3084 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3086 VALIDATE_SW_IF_INDEX(mp);
3088 is_no = mp->is_no == 1;
3089 use_default = mp->use_default == 1;
3090 no_advertise = mp->no_advertise == 1;
3091 off_link = mp->off_link == 1;
3092 no_autoconfig = mp->no_autoconfig == 1;
3093 no_onlink = mp->no_onlink == 1;
3095 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3096 (ip6_address_t *)mp->address, mp->address_length,
3097 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3098 no_advertise, off_link, no_autoconfig, no_onlink,
3101 BAD_SW_IF_INDEX_LABEL;
3102 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3106 vl_api_sw_interface_ip6_enable_disable_t_handler
3107 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3109 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3110 vnet_main_t * vnm = vnet_get_main();
3112 clib_error_t * error;
3116 VALIDATE_SW_IF_INDEX(mp);
3118 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3119 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3122 clib_error_report(error);
3123 rv = VNET_API_ERROR_UNSPECIFIED;
3125 rv = vnm->api_errno;
3128 BAD_SW_IF_INDEX_LABEL;
3130 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3134 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3135 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3137 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3139 clib_error_t * error;
3140 vnet_main_t * vnm = vnet_get_main();
3144 VALIDATE_SW_IF_INDEX(mp);
3146 error = set_ip6_link_local_address(vm,
3147 ntohl(mp->sw_if_index),
3148 (ip6_address_t *)mp->address,
3149 mp->address_length);
3151 clib_error_report(error);
3152 rv = VNET_API_ERROR_UNSPECIFIED;
3154 rv = vnm->api_errno;
3157 BAD_SW_IF_INDEX_LABEL;
3159 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3162 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3164 vl_api_set_ip_flow_hash_reply_t *rmp;
3165 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3167 clib_warning ("unimplemented...");
3169 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3172 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3174 vl_api_set_ip_flow_hash_reply_t *rmp;
3177 u32 flow_hash_config = 0;
3179 table_id = ntohl(mp->vrf_id);
3181 #define _(a,b) if (mp->a) flow_hash_config |= b;
3182 foreach_flow_hash_bit;
3185 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3187 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3191 static void vl_api_set_ip_flow_hash_t_handler
3192 (vl_api_set_ip_flow_hash_t *mp)
3194 if (mp->is_ipv6 == 0)
3195 set_ip4_flow_hash (mp);
3197 set_ip6_flow_hash (mp);
3200 static void vl_api_sw_interface_set_unnumbered_t_handler
3201 (vl_api_sw_interface_set_unnumbered_t *mp)
3203 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3205 vnet_sw_interface_t * si;
3206 vnet_main_t *vnm = vnet_get_main();
3207 u32 sw_if_index, unnumbered_sw_if_index;
3209 sw_if_index = ntohl(mp->sw_if_index);
3210 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3213 * The API message field names are backwards from
3214 * the underlying data structure names.
3215 * It's not worth changing them now.
3217 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3218 unnumbered_sw_if_index)) {
3219 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3223 /* Only check the "use loop0" field when setting the binding */
3225 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3226 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3230 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3233 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3234 si->unnumbered_sw_if_index = sw_if_index;
3236 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3237 si->unnumbered_sw_if_index = (u32)~0;
3241 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3244 static void vl_api_create_loopback_t_handler
3245 (vl_api_create_loopback_t *mp)
3247 vl_api_create_loopback_reply_t * rmp;
3251 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3253 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3255 rmp->sw_if_index = ntohl (sw_if_index);
3259 static void vl_api_delete_loopback_t_handler
3260 (vl_api_delete_loopback_t *mp)
3262 vl_api_delete_loopback_reply_t * rmp;
3266 sw_if_index = ntohl (mp->sw_if_index);
3267 rv = vnet_delete_loopback_interface (sw_if_index);
3269 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3272 static void vl_api_control_ping_t_handler
3273 (vl_api_control_ping_t *mp)
3275 vl_api_control_ping_reply_t * rmp;
3278 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3280 rmp->vpe_pid = ntohl (getpid());
3284 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3286 u8 **shmem_vecp = (u8 **)arg;
3289 api_main_t * am = &api_main;
3292 shmem_vec = *shmem_vecp;
3294 offset = vec_len (shmem_vec);
3296 pthread_mutex_lock (&am->vlib_rp->mutex);
3297 oldheap = svm_push_data_heap (am->vlib_rp);
3299 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3301 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3303 svm_pop_heap (oldheap);
3304 pthread_mutex_unlock (&am->vlib_rp->mutex);
3306 *shmem_vecp = shmem_vec;
3310 static void vl_api_cli_request_t_handler
3311 (vl_api_cli_request_t *mp)
3313 vl_api_cli_reply_t *rp;
3314 unix_shared_memory_queue_t *q;
3315 vlib_main_t * vm = vlib_get_main();
3316 api_main_t * am = &api_main;
3317 unformat_input_t input;
3321 q = vl_api_client_index_to_input_queue (mp->client_index);
3325 rp = vl_msg_api_alloc (sizeof (*rp));
3326 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3327 rp->context = mp->context;
3329 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3331 vlib_cli_input (vm, &input, shmem_cli_output,
3334 pthread_mutex_lock (&am->vlib_rp->mutex);
3335 oldheap = svm_push_data_heap (am->vlib_rp);
3337 vec_add1(shmem_vec, 0);
3339 svm_pop_heap (oldheap);
3340 pthread_mutex_unlock (&am->vlib_rp->mutex);
3342 rp->reply_in_shmem = (uword)shmem_vec;
3344 vl_msg_api_send_shmem (q, (u8 *)&rp);
3347 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3350 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3351 vnet_main_t *vnm = vnet_get_main();
3352 clib_error_t * error;
3357 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3359 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3362 clib_error_report(error);
3363 rv = VNET_API_ERROR_UNSPECIFIED;
3365 rv = vnm->api_errno;
3368 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3371 static void vl_api_sr_tunnel_add_del_t_handler
3372 (vl_api_sr_tunnel_add_del_t *mp)
3375 clib_warning ("unimplemented");
3377 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3379 vl_api_sr_tunnel_add_del_reply_t * rmp;
3380 ip6_address_t * segments = 0, * seg;
3381 ip6_address_t * tags = 0, *tag;
3382 ip6_address_t * this_address;
3385 if (mp->n_segments == 0) {
3390 memset (a, 0, sizeof (*a));
3391 a->src_address = (ip6_address_t *)&mp->src_address;
3392 a->dst_address = (ip6_address_t *)&mp->dst_address;
3393 a->dst_mask_width = mp->dst_mask_width;
3394 a->flags_net_byte_order = mp->flags_net_byte_order;
3395 a->is_del = (mp->is_add == 0);
3396 a->rx_table_id = ntohl(mp->outer_vrf_id);
3397 a->tx_table_id = ntohl(mp->inner_vrf_id);
3399 a->name = format(0, "%s", mp->name);
3400 if (!(vec_len(a->name)))
3403 a->policy_name = format(0, "%s", mp->policy_name);
3404 if (!(vec_len(a->policy_name)))
3407 /* Yank segments and tags out of the API message */
3408 this_address = (ip6_address_t *)mp->segs_and_tags;
3409 for (i = 0; i < mp->n_segments; i++) {
3410 vec_add2 (segments, seg, 1);
3411 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3414 for (i = 0; i < mp->n_tags; i++) {
3415 vec_add2 (tags, tag, 1);
3416 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3420 a->segments = segments;
3423 rv = ip6_sr_add_del_tunnel (a);
3427 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3431 static void vl_api_sr_policy_add_del_t_handler
3432 (vl_api_sr_policy_add_del_t *mp)
3435 clib_warning ("unimplemented");
3437 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3439 vl_api_sr_policy_add_del_reply_t * rmp;
3442 memset (a, 0, sizeof (*a));
3443 a->is_del = (mp->is_add == 0);
3445 a->name = format(0, "%s", mp->name);
3446 if (!(vec_len(a->name)))
3448 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3452 if (!(mp->tunnel_names))
3454 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3458 // start deserializing tunnel_names
3459 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3460 u8 * deser_tun_names = mp->tunnel_names;
3461 deser_tun_names += 1; //moving along
3464 int tun_name_len = 0;
3466 for (i=0; i < num_tunnels; i++)
3468 tun_name_len= *deser_tun_names;
3469 deser_tun_names += 1;
3470 vec_resize (tun_name, tun_name_len);
3471 memcpy(tun_name, deser_tun_names, tun_name_len);
3472 vec_add1 (a->tunnel_names, tun_name);
3473 deser_tun_names += tun_name_len;
3477 rv = ip6_sr_add_del_policy (a);
3481 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3485 static void vl_api_sr_multicast_map_add_del_t_handler
3486 (vl_api_sr_multicast_map_add_del_t *mp)
3489 clib_warning ("unimplemented");
3491 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3493 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3495 memset (a, 0, sizeof (*a));
3496 a->is_del = (mp->is_add == 0);
3498 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3499 a->policy_name = format(0, "%s", mp->policy_name);
3501 if (a->multicast_address == 0)
3507 if (!(a->policy_name))
3513 #if DPDK > 0 /* Cannot call replicate without DPDK */
3514 rv = ip6_sr_add_del_multicastmap (a);
3516 clib_warning ("multicast replication without DPDK not implemented");
3517 rv = VNET_API_ERROR_UNIMPLEMENTED;
3522 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3526 #define foreach_classify_add_del_table_field \
3531 _(match_n_vectors) \
3532 _(next_table_index) \
3535 static void vl_api_classify_add_del_table_t_handler
3536 (vl_api_classify_add_del_table_t * mp)
3538 vl_api_classify_add_del_table_reply_t * rmp;
3539 vnet_classify_main_t * cm = &vnet_classify_main;
3540 vnet_classify_table_t * t;
3544 foreach_classify_add_del_table_field;
3547 #define _(a) a = ntohl(mp->a);
3548 foreach_classify_add_del_table_field;
3551 /* The underlying API fails silently, on purpose, so check here */
3552 if (mp->is_add == 0)
3553 if (pool_is_free_index (cm->tables, table_index)) {
3554 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3558 rv = vnet_classify_add_del_table
3559 (cm, mp->mask, nbuckets, memory_size,
3560 skip_n_vectors, match_n_vectors,
3561 next_table_index, miss_next_index,
3562 &table_index, mp->is_add);
3565 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3567 if (rv == 0 && mp->is_add) {
3568 t = pool_elt_at_index (cm->tables, table_index);
3569 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3570 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3571 rmp->new_table_index = ntohl(table_index);
3573 rmp->skip_n_vectors = ~0;
3574 rmp->match_n_vectors = ~0;
3575 rmp->new_table_index = ~0;
3580 static void vl_api_classify_add_del_session_t_handler
3581 (vl_api_classify_add_del_session_t * mp)
3583 vnet_classify_main_t * cm = &vnet_classify_main;
3584 vl_api_classify_add_del_session_reply_t * rmp;
3586 u32 table_index, hit_next_index, opaque_index;
3589 table_index = ntohl (mp->table_index);
3590 hit_next_index = ntohl (mp->hit_next_index);
3591 opaque_index = ntohl (mp->opaque_index);
3592 advance = ntohl (mp->advance);
3594 rv = vnet_classify_add_del_session
3595 (cm, table_index, mp->match, hit_next_index, opaque_index,
3596 advance, mp->is_add);
3598 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3601 static void vl_api_classify_set_interface_ip_table_t_handler
3602 (vl_api_classify_set_interface_ip_table_t * mp)
3604 vlib_main_t * vm = vlib_get_main();
3605 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3607 u32 table_index, sw_if_index;
3609 table_index = ntohl (mp->table_index);
3610 sw_if_index = ntohl (mp->sw_if_index);
3612 VALIDATE_SW_IF_INDEX(mp);
3615 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3617 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3619 BAD_SW_IF_INDEX_LABEL;
3621 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3624 static void vl_api_classify_set_interface_l2_tables_t_handler
3625 (vl_api_classify_set_interface_l2_tables_t * mp)
3627 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3629 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3632 ip4_table_index = ntohl(mp->ip4_table_index);
3633 ip6_table_index = ntohl(mp->ip6_table_index);
3634 other_table_index = ntohl(mp->other_table_index);
3635 sw_if_index = ntohl(mp->sw_if_index);
3637 VALIDATE_SW_IF_INDEX(mp);
3639 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3640 ip6_table_index, other_table_index);
3643 if (ip4_table_index != ~0 || ip6_table_index != ~0
3644 || other_table_index != ~0)
3649 vnet_l2_classify_enable_disable (sw_if_index, enable);
3652 BAD_SW_IF_INDEX_LABEL;
3654 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3658 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3661 vl_api_l2_fib_clear_table_reply_t * rmp;
3663 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3664 * that is not currently implemented. When that TODO is fixed
3665 * this call should be changed to pass 1 instead of 0.
3667 l2fib_clear_table (0);
3669 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3672 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3677 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3680 vl_api_l2_interface_efp_filter_reply_t * rmp;
3681 vnet_main_t *vnm = vnet_get_main();
3683 // enable/disable the feature
3684 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3685 rv = vnm->api_errno;
3687 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3691 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3694 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3695 vnet_main_t * vnm = vnet_get_main();
3696 vlib_main_t * vm = vlib_get_main();
3699 VALIDATE_SW_IF_INDEX(mp);
3701 vtr_op = ntohl(mp->vtr_op);
3703 /* The L2 code is unsuspicious */
3705 case L2_VTR_DISABLED:
3710 case L2_VTR_TRANSLATE_1_1:
3711 case L2_VTR_TRANSLATE_1_2:
3712 case L2_VTR_TRANSLATE_2_1:
3713 case L2_VTR_TRANSLATE_2_2:
3717 rv = VNET_API_ERROR_INVALID_VALUE;
3718 goto bad_sw_if_index;
3721 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3722 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3725 BAD_SW_IF_INDEX_LABEL;
3727 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3731 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3735 vl_api_create_vhost_user_if_reply_t * rmp;
3736 u32 sw_if_index = (u32)~0;
3738 vnet_main_t * vnm = vnet_get_main();
3739 vlib_main_t * vm = vlib_get_main();
3741 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3742 mp->is_server, &sw_if_index, (u64)~0,
3743 mp->renumber, ntohl(mp->custom_dev_instance),
3744 (mp->use_custom_mac)?mp->mac_address:NULL);
3746 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3748 rmp->sw_if_index = ntohl (sw_if_index);
3754 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3758 vl_api_modify_vhost_user_if_reply_t * rmp;
3759 u32 sw_if_index = ntohl(mp->sw_if_index);
3761 vnet_main_t * vnm = vnet_get_main();
3762 vlib_main_t * vm = vlib_get_main();
3764 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3765 mp->is_server, sw_if_index, (u64)~0,
3766 mp->renumber, ntohl(mp->custom_dev_instance));
3768 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3773 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3777 vpe_api_main_t * vam = &vpe_api_main;
3778 vl_api_delete_vhost_user_if_reply_t * rmp;
3779 u32 sw_if_index = ntohl(mp->sw_if_index);
3781 vnet_main_t * vnm = vnet_get_main();
3782 vlib_main_t * vm = vlib_get_main();
3784 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3786 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3788 unix_shared_memory_queue_t * q =
3789 vl_api_client_index_to_input_queue (mp->client_index);
3793 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3798 static void vl_api_sw_interface_vhost_user_details_t_handler (
3799 vl_api_sw_interface_vhost_user_details_t * mp)
3801 clib_warning ("BUG");
3805 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3806 unix_shared_memory_queue_t *q,
3807 vhost_user_intf_details_t * vui,
3810 vl_api_sw_interface_vhost_user_details_t * mp;
3812 mp = vl_msg_api_alloc (sizeof (*mp));
3813 memset (mp, 0, sizeof (*mp));
3814 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3815 mp->sw_if_index = ntohl(vui->sw_if_index);
3816 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3817 mp->features = clib_net_to_host_u64 (vui->features);
3818 mp->is_server = vui->is_server;
3819 mp->num_regions = ntohl(vui->num_regions);
3820 mp->sock_errno = ntohl(vui->sock_errno);
3821 mp->context = context;
3823 strncpy ((char *) mp->sock_filename,
3824 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3825 strncpy ((char *) mp->interface_name,
3826 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3828 vl_msg_api_send_shmem (q, (u8 *)&mp);
3833 vl_api_sw_interface_vhost_user_dump_t_handler (
3834 vl_api_sw_interface_vhost_user_dump_t *mp)
3838 vpe_api_main_t * am = &vpe_api_main;
3839 vnet_main_t * vnm = vnet_get_main();
3840 vlib_main_t * vm = vlib_get_main();
3841 vhost_user_intf_details_t *ifaces = NULL;
3842 vhost_user_intf_details_t *vuid = NULL;
3843 unix_shared_memory_queue_t * q;
3845 q = vl_api_client_index_to_input_queue (mp->client_index);
3849 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3853 vec_foreach (vuid, ifaces) {
3854 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3860 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3861 unix_shared_memory_queue_t *q,
3866 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3867 u8 * if_name = NULL;
3868 vnet_sw_interface_t * si = NULL;
3870 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3872 if_name = format(if_name, "%U",
3873 format_vnet_sw_interface_name, lm->vnet_main, si);
3875 mp = vl_msg_api_alloc (sizeof (*mp));
3876 memset (mp, 0, sizeof (*mp));
3877 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3878 strncpy((char *)mp->interface_name,
3879 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3880 mp->sw_if_index = ntohl(si->sw_if_index);
3881 mp->local_session_id = s->local_session_id;
3882 mp->remote_session_id = s->remote_session_id;
3883 mp->local_cookie[0] = s->local_cookie[0];
3884 mp->local_cookie[1] = s->local_cookie[1];
3885 mp->remote_cookie = s->remote_cookie;
3886 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3887 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3888 mp->l2_sublayer_present = s->l2_sublayer_present;
3889 mp->context = context;
3891 vl_msg_api_send_shmem (q, (u8 *)&mp);
3894 static void send_ip_address_details (vpe_api_main_t * am,
3895 unix_shared_memory_queue_t * q,
3901 vl_api_ip_address_details_t * mp;
3903 mp = vl_msg_api_alloc (sizeof (*mp));
3904 memset (mp, 0, sizeof (*mp));
3905 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3908 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3910 u32 * tp = (u32 *)mp->ip;
3911 *tp = ntohl(*(u32*)ip);
3913 mp->prefix_length = prefix_length;
3914 mp->context = context;
3916 vl_msg_api_send_shmem (q, (u8 *)&mp);
3920 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3922 vpe_api_main_t * am = &vpe_api_main;
3923 unix_shared_memory_queue_t * q;
3926 ip6_main_t * im6 = &ip6_main;
3927 ip4_main_t * im4 = &ip4_main;
3928 ip_lookup_main_t * lm6 = &im6->lookup_main;
3929 ip_lookup_main_t * lm4 = &im4->lookup_main;
3930 ip_interface_address_t * ia = 0;
3931 u32 sw_if_index = ~0;
3933 sw_if_index = ntohl(mp->sw_if_index);
3935 q = vl_api_client_index_to_input_queue (mp->client_index);
3941 foreach_ip_interface_address (lm6, ia, sw_if_index,
3942 1 /* honor unnumbered */,
3944 r6 = ip_interface_address_get_address (lm6, ia);
3945 u16 prefix_length = ia->address_length;
3946 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3949 foreach_ip_interface_address (lm4, ia, sw_if_index,
3950 1 /* honor unnumbered */,
3952 r4 = ip_interface_address_get_address (lm4, ia);
3953 u16 prefix_length = ia->address_length;
3954 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3959 static void send_ip_details (vpe_api_main_t * am,
3960 unix_shared_memory_queue_t *q,
3964 vl_api_ip_details_t * mp;
3966 mp = vl_msg_api_alloc (sizeof (*mp));
3967 memset (mp, 0, sizeof (*mp));
3968 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3970 mp->sw_if_index = ntohl(sw_if_index);
3971 mp->context = context;
3973 vl_msg_api_send_shmem (q, (u8 *)&mp);
3977 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3978 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3980 vpe_api_main_t * am = &vpe_api_main;
3981 l2t_main_t * lm = &l2t_main;
3982 unix_shared_memory_queue_t * q;
3983 l2t_session_t *session;
3985 q = vl_api_client_index_to_input_queue (mp->client_index);
3989 pool_foreach (session, lm->sessions,
3991 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
3996 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3997 unix_shared_memory_queue_t *q,
3998 tapcli_interface_details_t *tap_if,
4001 vl_api_sw_interface_tap_details_t * mp;
4002 mp = vl_msg_api_alloc (sizeof (*mp));
4003 memset (mp, 0, sizeof (*mp));
4004 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4005 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4006 strncpy((char *)mp->dev_name,
4007 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4008 mp->context = context;
4010 vl_msg_api_send_shmem (q, (u8 *)&mp);
4014 vl_api_sw_interface_tap_dump_t_handler (
4015 vl_api_sw_interface_tap_dump_t *mp)
4018 vpe_api_main_t * am = &vpe_api_main;
4019 unix_shared_memory_queue_t * q;
4020 tapcli_interface_details_t *tapifs = NULL;
4021 tapcli_interface_details_t *tap_if = NULL;
4023 q = vl_api_client_index_to_input_queue (mp->client_index);
4027 rv = vnet_tap_dump_ifs(&tapifs);
4031 vec_foreach(tap_if, tapifs) {
4032 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4039 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4041 vpe_api_main_t * am = &vpe_api_main;
4042 vnet_main_t * vnm = vnet_get_main();
4043 vlib_main_t * vm = vlib_get_main();
4044 vnet_interface_main_t * im = &vnm->interface_main;
4045 unix_shared_memory_queue_t * q;
4046 vnet_sw_interface_t * si, * sorted_sis;
4047 u32 sw_if_index = ~0;
4049 q = vl_api_client_index_to_input_queue (mp->client_index);
4054 /* Gather interfaces. */
4055 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4056 _vec_len (sorted_sis) = 0;
4057 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4059 vec_foreach (si, sorted_sis) {
4060 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4061 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4064 sw_if_index = si->sw_if_index;
4065 send_ip_details(am, q, sw_if_index, mp->context);
4070 static void vl_api_l2_fib_table_entry_t_handler (
4071 vl_api_l2_fib_table_entry_t * mp)
4073 clib_warning ("BUG");
4076 static void send_l2fib_table_entry (vpe_api_main_t * am,
4077 unix_shared_memory_queue_t *q,
4078 l2fib_entry_key_t * l2fe_key,
4079 l2fib_entry_result_t * l2fe_res,
4082 vl_api_l2_fib_table_entry_t * mp;
4084 mp = vl_msg_api_alloc (sizeof (*mp));
4085 memset (mp, 0, sizeof (*mp));
4086 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4088 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4090 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4091 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4092 mp->static_mac = l2fe_res->fields.static_mac;
4093 mp->filter_mac = l2fe_res->fields.filter;
4094 mp->bvi_mac = l2fe_res->fields.bvi;
4095 mp->context = context;
4097 vl_msg_api_send_shmem (q, (u8 *)&mp);
4101 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4103 vpe_api_main_t * am = &vpe_api_main;
4104 bd_main_t * bdm = &bd_main;
4105 l2fib_entry_key_t *l2fe_key = NULL;
4106 l2fib_entry_result_t *l2fe_res = NULL;
4107 u32 ni, bd_id = ntohl (mp->bd_id);
4109 unix_shared_memory_queue_t * q;
4112 q = vl_api_client_index_to_input_queue (mp->client_index);
4116 /* see l2fib_table_dump: ~0 means "any" */
4120 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4127 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4129 vec_foreach_index (ni, l2fe_key) {
4130 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4131 vec_elt_at_index(l2fe_res, ni), mp->context);
4138 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4140 vl_api_show_version_reply_t *rmp;
4142 char * vpe_api_get_build_directory(void);
4143 char * vpe_api_get_version(void);
4144 char * vpe_api_get_build_date(void);
4146 unix_shared_memory_queue_t * q =
4147 vl_api_client_index_to_input_queue (mp->client_index);
4152 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4154 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4155 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4156 ARRAY_LEN(rmp->build_directory)-1);
4157 strncpy ((char *) rmp->version, vpe_api_get_version(),
4158 ARRAY_LEN(rmp->version)-1);
4159 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4160 ARRAY_LEN(rmp->build_date)-1);
4164 static void vl_api_get_node_index_t_handler
4165 (vl_api_get_node_index_t * mp)
4167 vlib_main_t * vm = vlib_get_main();
4168 vl_api_get_node_index_reply_t * rmp;
4171 u32 node_index = ~0;
4173 n = vlib_get_node_by_name (vm, mp->node_name);
4176 rv = VNET_API_ERROR_NO_SUCH_NODE;
4178 node_index = n->index;
4180 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4182 rmp->node_index = ntohl(node_index);
4186 static void vl_api_add_node_next_t_handler
4187 (vl_api_add_node_next_t * mp)
4189 vlib_main_t * vm = vlib_get_main();
4190 vl_api_add_node_next_reply_t * rmp;
4191 vlib_node_t * n, * next;
4193 u32 next_index = ~0;
4195 n = vlib_get_node_by_name (vm, mp->node_name);
4198 rv = VNET_API_ERROR_NO_SUCH_NODE;
4202 next = vlib_get_node_by_name (vm, mp->next_name);
4205 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4207 next_index = vlib_node_add_next (vm, n->index, next->index);
4210 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4212 rmp->next_index = ntohl(next_index);
4216 static void vl_api_l2tpv3_create_tunnel_t_handler
4217 (vl_api_l2tpv3_create_tunnel_t *mp)
4219 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4220 l2t_main_t *lm = &l2t_main;
4221 u32 sw_if_index = (u32)~0;
4224 if (mp->is_ipv6 != 1) {
4225 rv = VNET_API_ERROR_UNIMPLEMENTED;
4229 rv = create_l2tpv3_ipv6_tunnel (lm,
4230 (ip6_address_t *) mp->client_address,
4231 (ip6_address_t *) mp->our_address,
4232 ntohl(mp->local_session_id),
4233 ntohl(mp->remote_session_id),
4234 clib_net_to_host_u64(mp->local_cookie),
4235 clib_net_to_host_u64(mp->remote_cookie),
4236 mp->l2_sublayer_present,
4240 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4242 rmp->sw_if_index = ntohl (sw_if_index);
4246 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4247 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4249 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4250 l2t_main_t *lm = &l2t_main;
4253 VALIDATE_SW_IF_INDEX(mp);
4255 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4256 clib_net_to_host_u64(mp->new_local_cookie),
4257 clib_net_to_host_u64(mp->new_remote_cookie));
4259 BAD_SW_IF_INDEX_LABEL;
4261 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4264 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4265 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4268 vnet_main_t * vnm = vnet_get_main();
4269 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4271 VALIDATE_SW_IF_INDEX(mp);
4273 rv = l2tpv3_interface_enable_disable
4274 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4276 BAD_SW_IF_INDEX_LABEL;
4278 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4281 static void vl_api_l2tpv3_set_lookup_key_t_handler
4282 (vl_api_l2tpv3_set_lookup_key_t * mp)
4285 l2t_main_t *lm = &l2t_main;
4286 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4288 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4289 rv = VNET_API_ERROR_INVALID_VALUE;
4293 lm->lookup_type = mp->key;
4296 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4299 static void vl_api_vxlan_add_del_tunnel_t_handler
4300 (vl_api_vxlan_add_del_tunnel_t * mp)
4302 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4304 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4305 u32 encap_fib_index;
4307 ip4_main_t * im = &ip4_main;
4308 u32 sw_if_index = ~0;
4310 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4312 rv = VNET_API_ERROR_NO_SUCH_FIB;
4315 encap_fib_index = p[0];
4317 /* Check src & dst are different */
4318 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4319 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4320 rv = VNET_API_ERROR_SAME_SRC_DST;
4323 memset (a, 0, sizeof (*a));
4325 a->is_add = mp->is_add;
4326 a->is_ip6 = mp->is_ipv6;
4328 /* ip addresses sent in network byte order */
4330 memcpy(&(a->src.ip6), mp->src_address, 16);
4331 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4333 memcpy(&(a->src.ip4), mp->src_address, 4);
4334 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4337 a->encap_fib_index = encap_fib_index;
4338 a->decap_next_index = ntohl(mp->decap_next_index);
4339 a->vni = ntohl(mp->vni);
4340 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4343 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4345 rmp->sw_if_index = ntohl (sw_if_index);
4349 static void send_vxlan_tunnel_details
4350 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4352 vl_api_vxlan_tunnel_details_t * rmp;
4353 ip4_main_t * im4 = &ip4_main;
4354 ip6_main_t * im6 = &ip6_main;
4355 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4357 rmp = vl_msg_api_alloc (sizeof (*rmp));
4358 memset (rmp, 0, sizeof (*rmp));
4359 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4361 memcpy(rmp->src_address, &(t->src.ip6), 16);
4362 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4363 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4365 memcpy(rmp->src_address, &(t->src.ip4), 4);
4366 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4367 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4369 rmp->vni = htonl(t->vni);
4370 rmp->decap_next_index = htonl(t->decap_next_index);
4371 rmp->sw_if_index = htonl(t->sw_if_index);
4372 rmp->is_ipv6 = is_ipv6;
4373 rmp->context = context;
4375 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4378 static void vl_api_vxlan_tunnel_dump_t_handler
4379 (vl_api_vxlan_tunnel_dump_t * mp)
4381 unix_shared_memory_queue_t * q;
4382 vxlan_main_t * vxm = &vxlan_main;
4386 q = vl_api_client_index_to_input_queue (mp->client_index);
4391 sw_if_index = ntohl(mp->sw_if_index);
4393 if (~0 == sw_if_index) {
4394 pool_foreach (t, vxm->tunnels,
4396 send_vxlan_tunnel_details(t, q, mp->context);
4399 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4400 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4403 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4404 send_vxlan_tunnel_details(t, q, mp->context);
4408 static void vl_api_gre_add_del_tunnel_t_handler
4409 (vl_api_gre_add_del_tunnel_t * mp)
4411 vl_api_gre_add_del_tunnel_reply_t * rmp;
4413 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4416 ip4_main_t * im = &ip4_main;
4417 u32 sw_if_index = ~0;
4419 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4421 rv = VNET_API_ERROR_NO_SUCH_FIB;
4424 outer_table_id = p[0];
4426 /* Check src & dst are different */
4427 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4428 rv = VNET_API_ERROR_SAME_SRC_DST;
4432 memset (a, 0, sizeof (*a));
4434 a->is_add = mp->is_add;
4436 /* ip addresses sent in network byte order */
4437 a->src.as_u32 = mp->src_address;
4438 a->dst.as_u32 = mp->dst_address;
4440 a->outer_table_id = outer_table_id;
4441 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4444 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4446 rmp->sw_if_index = ntohl (sw_if_index);
4450 static void send_gre_tunnel_details
4451 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4453 vl_api_gre_tunnel_details_t * rmp;
4454 ip4_main_t * im = &ip4_main;
4456 rmp = vl_msg_api_alloc (sizeof (*rmp));
4457 memset (rmp, 0, sizeof (*rmp));
4458 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4459 rmp->src_address = t->tunnel_src.data_u32;
4460 rmp->dst_address = t->tunnel_dst.data_u32;
4461 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4462 rmp->sw_if_index = htonl(t->sw_if_index);
4463 rmp->context = context;
4465 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4468 static void vl_api_gre_tunnel_dump_t_handler
4469 (vl_api_gre_tunnel_dump_t * mp)
4471 unix_shared_memory_queue_t * q;
4472 gre_main_t * gm = &gre_main;
4476 q = vl_api_client_index_to_input_queue (mp->client_index);
4481 sw_if_index = ntohl(mp->sw_if_index);
4483 if (~0 == sw_if_index) {
4484 pool_foreach (t, gm->tunnels,
4486 send_gre_tunnel_details(t, q, mp->context);
4489 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4490 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4493 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4494 send_gre_tunnel_details(t, q, mp->context);
4499 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4501 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4503 vl_api_l2_patch_add_del_reply_t * rmp;
4504 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4508 VALIDATE_RX_SW_IF_INDEX(mp);
4509 VALIDATE_TX_SW_IF_INDEX(mp);
4511 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4512 ntohl(mp->tx_sw_if_index),
4513 (int)(mp->is_add != 0));
4515 BAD_RX_SW_IF_INDEX_LABEL;
4516 BAD_TX_SW_IF_INDEX_LABEL;
4518 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4522 vl_api_nsh_gre_add_del_tunnel_t_handler
4523 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4525 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4527 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4528 u32 encap_fib_index, decap_fib_index;
4529 u32 decap_next_index;
4531 ip4_main_t * im = &ip4_main;
4533 u32 sw_if_index = ~0;
4536 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4538 rv = VNET_API_ERROR_NO_SUCH_FIB;
4541 encap_fib_index = p[0];
4543 decap_next_index = ntohl(mp->decap_next_index);
4545 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4546 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4547 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4549 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4552 decap_fib_index = p[0];
4554 decap_fib_index = ntohl(mp->decap_vrf_id);
4557 memset (a, 0, sizeof (*a));
4559 a->is_add = mp->is_add;
4560 /* ip addresses sent in network byte order */
4561 a->src.as_u32 = ntohl(mp->src);
4562 a->dst.as_u32 = ntohl(mp->dst);
4563 a->encap_fib_index = encap_fib_index;
4564 a->decap_fib_index = decap_fib_index;
4565 a->decap_next_index = decap_next_index;
4566 a->nsh_hdr.ver_o_c = mp->ver_o_c;
4567 a->nsh_hdr.length = mp->length;
4568 a->nsh_hdr.md_type = mp->md_type;
4569 a->nsh_hdr.next_protocol = mp->next_protocol;
4570 a->nsh_hdr.spi_si = ntohl(mp->spi_si);
4571 a->nsh_hdr.c1 = ntohl(mp->c1);
4572 a->nsh_hdr.c2 = ntohl(mp->c2);
4573 a->nsh_hdr.c3 = ntohl(mp->c3);
4574 a->nsh_hdr.c4 = ntohl(mp->c4);
4576 for (i = 0; i < mp->tlv_len_in_words; i++)
4577 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4579 a->nsh_hdr.tlvs = tlvs;
4581 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4584 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4586 rmp->sw_if_index = ntohl (sw_if_index);
4591 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4592 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4594 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4596 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4597 u32 encap_fib_index, decap_fib_index;
4598 u32 decap_next_index;
4600 ip4_main_t * im = &ip4_main;
4602 u32 sw_if_index = ~0;
4605 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4607 rv = VNET_API_ERROR_NO_SUCH_FIB;
4610 encap_fib_index = p[0];
4612 decap_next_index = ntohl(mp->decap_next_index);
4614 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4615 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4616 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4618 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4621 decap_fib_index = p[0];
4623 decap_fib_index = ntohl(mp->decap_vrf_id);
4626 memset (a, 0, sizeof (*a));
4628 a->is_add = mp->is_add;
4629 /* ip addresses sent in network byte order */
4630 a->src.as_u32 = ntohl(mp->src);
4631 a->dst.as_u32 = ntohl(mp->dst);
4632 a->encap_fib_index = encap_fib_index;
4633 a->decap_fib_index = decap_fib_index;
4634 a->decap_next_index = decap_next_index;
4635 a->vni = ntohl(mp->vni);
4636 a->nsh_hdr.ver_o_c = mp->ver_o_c;
4637 a->nsh_hdr.length = mp->length;
4638 a->nsh_hdr.md_type = mp->md_type;
4639 a->nsh_hdr.next_protocol = mp->next_protocol;
4640 a->nsh_hdr.spi_si = ntohl(mp->spi_si);
4641 a->nsh_hdr.c1 = ntohl(mp->c1);
4642 a->nsh_hdr.c2 = ntohl(mp->c2);
4643 a->nsh_hdr.c3 = ntohl(mp->c3);
4644 a->nsh_hdr.c4 = ntohl(mp->c4);
4646 for (i = 0; i < mp->tlv_len_in_words; i++)
4647 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4649 a->nsh_hdr.tlvs = tlvs;
4651 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4654 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4656 rmp->sw_if_index = ntohl (sw_if_index);
4661 vl_api_lisp_gpe_add_del_tunnel_t_handler
4662 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4664 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4666 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4667 u32 encap_fib_index, decap_fib_index;
4668 u32 decap_next_index;
4670 ip4_main_t * im = &ip4_main;
4671 u32 sw_if_index = ~0;
4673 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4675 rv = VNET_API_ERROR_NO_SUCH_FIB;
4678 encap_fib_index = p[0];
4680 decap_next_index = ntohl(mp->decap_next_index);
4682 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4683 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4684 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4686 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4689 decap_fib_index = p[0];
4691 decap_fib_index = ntohl(mp->decap_vrf_id);
4694 memset (a, 0, sizeof (*a));
4696 a->is_add = mp->is_add;
4697 /* ip addresses sent in network byte order */
4698 a->src.as_u32 = mp->src;
4699 a->dst.as_u32 = mp->dst;
4700 a->encap_fib_index = encap_fib_index;
4701 a->decap_fib_index = decap_fib_index;
4702 a->decap_next_index = decap_next_index;
4703 a->flags = mp->flags;
4704 a->ver_res = mp->ver_res;
4706 a->next_protocol = mp->next_protocol;
4707 a->vni = clib_net_to_host_u32 (mp->iid);
4709 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4712 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4714 rmp->sw_if_index = ntohl (sw_if_index);
4719 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4721 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4723 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4725 u8 *locator_name = NULL;
4727 memset(a, 0, sizeof(a[0]));
4729 locator_name = format(0, "%s", mp->locator_set_name);
4731 a->name = locator_name;
4733 a->is_add = mp->is_add;
4736 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4738 vec_free(locator_name);
4740 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4744 vl_api_lisp_add_del_locator_t_handler(
4745 vl_api_lisp_add_del_locator_t *mp)
4747 vl_api_lisp_add_del_locator_reply_t *rmp;
4749 locator_t locator, *locators = NULL;
4750 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4752 u8 *locator_name = NULL;
4754 memset(&locator, 0, sizeof(locator));
4755 memset(a, 0, sizeof(a[0]));
4757 locator.sw_if_index = ntohl(mp->sw_if_index);
4758 locator.priority = mp->priority;
4759 locator.weight = mp->weight;
4761 vec_add1(locators, locator);
4763 locator_name = format(0, "%s", mp->locator_set_name);
4765 a->name = locator_name;
4766 a->locators = locators;
4767 a->is_add = mp->is_add;
4770 rv = vnet_lisp_add_del_locator(a, &ls_index);
4773 vec_free(locator_name);
4775 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4779 vl_api_lisp_add_del_local_eid_t_handler(
4780 vl_api_lisp_add_del_local_eid_t *mp)
4782 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4783 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4785 ip_prefix_t *prefp = NULL;
4786 ip_address_t *ip_eid = NULL;
4789 u32 locator_set_index = ~0, map_index = ~0;
4790 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4793 prefp = &gid_address_ippref(&eid);
4794 ip_eid = &ip_prefix_addr(prefp);
4795 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4798 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4799 sizeof(ip_addr_v6(ip_eid)));
4800 ip_addr_version(ip_eid) = IP6;
4802 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4803 sizeof(ip_addr_v4(ip_eid)));
4804 ip_addr_version(ip_eid) = IP4;
4806 ip_prefix_len(prefp) = mp->prefix_len;
4808 name = format(0, "%s", mp->locator_set_name);
4809 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4811 rv = VNET_API_ERROR_INVALID_VALUE;
4814 locator_set_index = p[0];
4816 /* XXX treat batch configuration */
4817 a->is_add = mp->is_add;
4819 a->locator_set_index = locator_set_index;
4822 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4827 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4831 lisp_gpe_add_del_fwd_entry_set_address(
4832 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4833 ip_address_t *slocator,
4834 ip_address_t *dlocator,
4837 ip_address_t *ip_eid = NULL;
4838 ip_prefix_t *prefp = NULL;
4840 prefp = &gid_address_ippref(eid);
4841 ip_eid = &ip_prefix_addr(prefp);
4843 if (mp->eid_is_ipv6) {
4844 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4845 sizeof(ip_addr_v6(ip_eid)));
4846 ip_addr_version(ip_eid) = IP6;
4848 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4849 sizeof(ip_addr_v4(ip_eid)));
4850 ip_addr_version(ip_eid) = IP4;
4852 ip_prefix_len(prefp) = mp->eid_prefix_len;
4854 if (mp->address_is_ipv6) {
4855 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4856 sizeof(ip_addr_v6(slocator)));
4857 ip_addr_version(slocator) = IP6;
4858 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4859 sizeof(ip_addr_v6(dlocator)));
4860 ip_addr_version(dlocator) = IP6;
4862 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4863 sizeof(ip_addr_v4(slocator)));
4864 ip_addr_version(slocator) = IP4;
4865 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4866 sizeof(ip_addr_v4(dlocator)));
4867 ip_addr_version(dlocator) = IP4;
4872 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4873 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4875 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4877 ip_address_t slocator, dlocator;
4878 ip_prefix_t * prefp = NULL;
4880 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4882 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4884 memset (&a, 0, sizeof(a));
4886 a.is_add = mp->is_add;
4888 a.slocator = slocator;
4889 a.dlocator = dlocator;
4890 prefp = &gid_address_ippref(&a.deid);
4891 a.decap_next_index = (ip_prefix_version(prefp) == IP4) ?
4892 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
4893 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4895 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4899 vl_api_lisp_add_del_map_resolver_t_handler(
4900 vl_api_lisp_add_del_map_resolver_t *mp)
4902 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4904 ip_address_t *ip_addr = NULL;
4905 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4907 a->is_add = mp->is_add;
4908 ip_addr = &a->address;
4911 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4912 sizeof(ip_addr_v6(ip_addr)));
4913 ip_addr_version(ip_addr) = IP6;
4915 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4916 sizeof(ip_addr_v4(ip_addr)));
4917 ip_addr_version(ip_addr) = IP4;
4920 rv = vnet_lisp_add_del_map_resolver (a);
4922 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4926 vl_api_lisp_gpe_enable_disable_t_handler(
4927 vl_api_lisp_gpe_enable_disable_t *mp)
4929 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4931 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4933 a->is_en = mp->is_en;
4934 vnet_lisp_gpe_enable_disable (a);
4936 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4940 vl_api_lisp_gpe_add_del_iface_t_handler(
4941 vl_api_lisp_gpe_add_del_iface_t *mp)
4943 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4945 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4947 a->is_add = mp->is_add;
4948 a->table_id = mp->table_id;
4950 vnet_lisp_gpe_add_del_iface (a, 0);
4952 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4956 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4957 locator_set_t *lsit,
4958 unix_shared_memory_queue_t *q,
4961 vl_api_lisp_locator_set_details_t *rmp;
4962 locator_t *loc = NULL;
4965 vec_foreach (locit, lsit->locator_indices) {
4966 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4967 rmp = vl_msg_api_alloc (sizeof (*rmp));
4968 memset (rmp, 0, sizeof (*rmp));
4969 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4970 strncpy((char *) rmp->locator_set_name,
4971 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4972 rmp->sw_if_index = htonl(loc->sw_if_index);
4973 rmp->priority = loc->priority;
4974 rmp->weight = loc->weight;
4975 rmp->context = context;
4977 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4982 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4984 unix_shared_memory_queue_t * q = NULL;
4985 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4986 locator_set_t * lsit = NULL;
4988 q = vl_api_client_index_to_input_queue (mp->client_index);
4993 pool_foreach (lsit, lcm->locator_set_pool,
4995 send_lisp_locator_set_details(lcm, lsit, q, mp->context);
5000 send_lisp_local_eid_table_details (mapping_t *mapit,
5001 unix_shared_memory_queue_t *q,
5004 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5005 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5006 locator_set_t *ls = NULL;
5007 gid_address_t *gid = NULL;
5008 ip_prefix_t *ip_prefix = NULL;
5011 ls = pool_elt_at_index (lcm->locator_set_pool,
5012 mapit->locator_set_index);
5015 type = gid_address_type(gid);
5017 if (type != GID_ADDR_IP_PREFIX) {
5021 ip_prefix = &gid_address_ippref(gid);
5023 rmp = vl_msg_api_alloc (sizeof (*rmp));
5024 memset (rmp, 0, sizeof (*rmp));
5025 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5026 strncpy((char *) rmp->locator_set_name,
5027 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5029 switch (ip_prefix_version(ip_prefix)) {
5031 rmp->eid_is_ipv6 = 0;
5032 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5033 sizeof(ip_prefix_v4(ip_prefix)));
5037 rmp->eid_is_ipv6 = 1;
5038 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5039 sizeof(ip_prefix_v6(ip_prefix)));
5045 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5046 rmp->context = context;
5048 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5052 vl_api_lisp_local_eid_table_dump_t_handler (
5053 vl_api_lisp_local_eid_table_dump_t *mp)
5055 unix_shared_memory_queue_t * q = NULL;
5056 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5057 mapping_t * mapit = NULL;
5059 q = vl_api_client_index_to_input_queue (mp->client_index);
5064 pool_foreach (mapit, lcm->mapping_pool,
5066 send_lisp_local_eid_table_details(mapit, q, mp->context);
5071 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5072 unix_shared_memory_queue_t *q,
5075 vl_api_lisp_gpe_tunnel_details_t *rmp;
5076 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5078 rmp = vl_msg_api_alloc (sizeof (*rmp));
5079 memset (rmp, 0, sizeof (*rmp));
5080 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5082 rmp->tunnels = tunnel - lgm->tunnels;
5084 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5085 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5086 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5088 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5089 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5090 rmp->dcap_next = htonl(tunnel->decap_next_index);
5091 rmp->lisp_ver = tunnel->ver_res;
5092 rmp->next_protocol = tunnel->next_protocol;
5093 rmp->flags = tunnel->flags;
5094 rmp->ver_res = tunnel->ver_res;
5095 rmp->res = tunnel->res;
5096 rmp->iid = htonl(tunnel->vni);
5097 rmp->context = context;
5099 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5103 vl_api_lisp_gpe_tunnel_dump_t_handler (
5104 vl_api_lisp_local_eid_table_dump_t *mp)
5106 unix_shared_memory_queue_t * q = NULL;
5107 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5108 lisp_gpe_tunnel_t * tunnel = NULL;
5110 if (pool_elts(lgm->tunnels) == 0) {
5114 q = vl_api_client_index_to_input_queue (mp->client_index);
5119 pool_foreach(tunnel, lgm->tunnels,
5121 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5126 send_lisp_map_resolver_details (ip_address_t *ip,
5127 unix_shared_memory_queue_t *q,
5130 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5132 rmp = vl_msg_api_alloc (sizeof (*rmp));
5133 memset (rmp, 0, sizeof (*rmp));
5134 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5136 switch (ip_addr_version(ip)) {
5139 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5144 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5150 rmp->context = context;
5152 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5156 vl_api_lisp_map_resolver_dump_t_handler (
5157 vl_api_lisp_local_eid_table_dump_t *mp)
5159 unix_shared_memory_queue_t * q = NULL;
5160 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5161 ip_address_t *ip = NULL;
5163 q = vl_api_client_index_to_input_queue (mp->client_index);
5168 vec_foreach(ip, lcm->map_resolvers) {
5169 send_lisp_map_resolver_details(ip, q, mp->context);
5175 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5177 vl_api_interface_name_renumber_reply_t * rmp;
5180 VALIDATE_SW_IF_INDEX(mp);
5182 rv = vnet_interface_name_renumber
5183 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5185 BAD_SW_IF_INDEX_LABEL;
5187 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5190 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5191 u32 sw_if_index, u32 address)
5193 vpe_api_main_t * am = &vpe_api_main;
5194 vlib_main_t * vm = am->vlib_main;
5195 vl_api_ip4_arp_event_t * event;
5196 static f64 arp_event_last_time;
5197 f64 now = vlib_time_now (vm);
5199 if (pool_is_free_index (am->arp_events, pool_index))
5202 event = pool_elt_at_index (am->arp_events, pool_index);
5203 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5204 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5205 } else { /* same mac */
5206 if ((sw_if_index == event->sw_if_index) &&
5208 /* for BD case, also check IP address with 10 sec timeout */
5209 ((address == event->address) &&
5210 ((now - arp_event_last_time) < 10.0))))
5214 arp_event_last_time = now;
5215 event->sw_if_index = sw_if_index;
5216 if (address) event->address = address;
5220 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5222 vpe_api_main_t * am = &vpe_api_main;
5224 if (pool_is_free_index (am->arp_events, pool_index))
5227 pool_put_index (am->arp_events, pool_index);
5232 vl_api_want_ip4_arp_events_t_handler
5233 (vl_api_want_ip4_arp_events_t * mp)
5235 vpe_api_main_t * am = &vpe_api_main;
5236 vnet_main_t * vnm = vnet_get_main();
5237 vl_api_want_ip4_arp_events_reply_t *rmp;
5238 vl_api_ip4_arp_event_t * event;
5241 if (mp->enable_disable) {
5242 pool_get (am->arp_events, event);
5243 memset (event, 0, sizeof (*event));
5245 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5246 event->client_index = mp->client_index;
5247 event->context = mp->context;
5248 event->address = mp->address;
5249 event->pid = mp->pid;
5251 rv = vnet_add_del_ip4_arp_change_event
5252 (vnm, arp_change_data_callback,
5254 &mp->address /* addr, in net byte order */,
5255 vpe_resolver_process_node.index,
5256 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5258 rv = vnet_add_del_ip4_arp_change_event
5259 (vnm, arp_change_delete_callback,
5261 &mp->address /* addr, in net byte order */,
5262 vpe_resolver_process_node.index,
5263 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5265 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5268 static void vl_api_input_acl_set_interface_t_handler
5269 (vl_api_input_acl_set_interface_t * mp)
5271 vlib_main_t *vm = vlib_get_main();
5272 vl_api_input_acl_set_interface_reply_t * rmp;
5274 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5276 ip4_table_index = ntohl(mp->ip4_table_index);
5277 ip6_table_index = ntohl(mp->ip6_table_index);
5278 l2_table_index = ntohl(mp->l2_table_index);
5279 sw_if_index = ntohl(mp->sw_if_index);
5281 VALIDATE_SW_IF_INDEX(mp);
5283 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5284 ip6_table_index, l2_table_index,
5287 BAD_SW_IF_INDEX_LABEL;
5289 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5292 static void vl_api_ipsec_spd_add_del_t_handler
5293 (vl_api_ipsec_spd_add_del_t * mp)
5296 clib_warning ("unimplemented");
5299 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5300 vl_api_ipsec_spd_add_del_reply_t * rmp;
5304 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5306 rv = VNET_API_ERROR_UNIMPLEMENTED;
5309 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5313 static void vl_api_ipsec_interface_add_del_spd_t_handler
5314 (vl_api_ipsec_interface_add_del_spd_t * mp)
5316 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5317 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5319 u32 sw_if_index __attribute__((unused));
5320 u32 spd_id __attribute__((unused));
5322 sw_if_index = ntohl(mp->sw_if_index);
5323 spd_id = ntohl(mp->spd_id);
5325 VALIDATE_SW_IF_INDEX(mp);
5328 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5330 rv = VNET_API_ERROR_UNIMPLEMENTED;
5333 BAD_SW_IF_INDEX_LABEL;
5335 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5338 static void vl_api_ipsec_spd_add_del_entry_t_handler
5339 (vl_api_ipsec_spd_add_del_entry_t * mp)
5341 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5342 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5348 memset(&p, 0, sizeof(p));
5350 p.id = ntohl(mp->spd_id);
5351 p.priority = ntohl(mp->priority);
5352 p.is_outbound = mp->is_outbound;
5353 p.is_ipv6 = mp->is_ipv6;
5355 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5356 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5357 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5358 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5360 p.protocol = mp->protocol;
5361 p.rport.start = ntohs(mp->remote_port_start);
5362 p.rport.stop = ntohs(mp->remote_port_stop);
5363 p.lport.start = ntohs(mp->local_port_start);
5364 p.lport.stop = ntohs(mp->local_port_stop);
5365 /* policy action resolve unsupported */
5366 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5367 clib_warning("unsupported action: 'resolve'");
5368 rv = VNET_API_ERROR_UNIMPLEMENTED;
5371 p.policy = mp->policy;
5372 p.sa_id = ntohl(mp->sa_id);
5374 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5378 if (mp->is_ip_any) {
5380 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5383 rv = VNET_API_ERROR_UNIMPLEMENTED;
5388 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5391 static void vl_api_ipsec_sad_add_del_entry_t_handler
5392 (vl_api_ipsec_sad_add_del_entry_t * mp)
5394 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5395 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5400 memset(&sa, 0, sizeof(sa));
5402 sa.id = ntohl(mp->sad_id);
5403 sa.spi = ntohl(mp->spi);
5404 /* security protocol AH unsupported */
5405 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5406 clib_warning("unsupported security protocol 'AH'");
5407 rv = VNET_API_ERROR_UNIMPLEMENTED;
5410 sa.protocol = mp->protocol;
5411 /* check for unsupported crypto-alg */
5412 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5413 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5414 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5415 mp->crypto_algorithm);
5416 rv = VNET_API_ERROR_UNIMPLEMENTED;
5419 sa.crypto_alg = mp->crypto_algorithm;
5420 sa.crypto_key_len = mp->crypto_key_length;
5421 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5422 /* check for unsupported integ-alg */
5423 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5424 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5425 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5426 mp->integrity_algorithm);
5427 rv = VNET_API_ERROR_UNIMPLEMENTED;
5430 sa.integ_alg = mp->integrity_algorithm;
5431 sa.integ_key_len = mp->integrity_key_length;
5432 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5433 sa.use_esn = mp->use_extended_sequence_number;
5434 sa.is_tunnel = mp->is_tunnel;
5435 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5436 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5437 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5439 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5441 rv = VNET_API_ERROR_UNIMPLEMENTED;
5446 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5450 vl_api_ikev2_profile_add_del_t_handler
5451 (vl_api_ikev2_profile_add_del_t * mp)
5453 vl_api_ikev2_profile_add_del_reply_t * rmp;
5457 vlib_main_t * vm = vlib_get_main();
5458 clib_error_t * error;
5459 u8 * tmp = format(0, "%s", mp->name);
5460 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5463 rv = VNET_API_ERROR_UNSPECIFIED;
5465 rv = VNET_API_ERROR_UNIMPLEMENTED;
5468 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5472 vl_api_ikev2_profile_set_auth_t_handler
5473 (vl_api_ikev2_profile_set_auth_t * mp)
5475 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5479 vlib_main_t * vm = vlib_get_main();
5480 clib_error_t * error;
5481 u8 * tmp = format(0, "%s", mp->name);
5482 u8 * data = vec_new (u8, mp->data_len);
5483 clib_memcpy(data, mp->data, mp->data_len);
5484 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5488 rv = VNET_API_ERROR_UNSPECIFIED;
5490 rv = VNET_API_ERROR_UNIMPLEMENTED;
5493 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5497 vl_api_ikev2_profile_set_id_t_handler
5498 (vl_api_ikev2_profile_set_id_t * mp)
5500 vl_api_ikev2_profile_add_del_reply_t * rmp;
5504 vlib_main_t * vm = vlib_get_main();
5505 clib_error_t * error;
5506 u8 * tmp = format(0, "%s", mp->name);
5507 u8 * data = vec_new (u8, mp->data_len);
5508 clib_memcpy(data, mp->data, mp->data_len);
5509 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5513 rv = VNET_API_ERROR_UNSPECIFIED;
5515 rv = VNET_API_ERROR_UNIMPLEMENTED;
5518 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5522 vl_api_ikev2_profile_set_ts_t_handler
5523 (vl_api_ikev2_profile_set_ts_t * mp)
5525 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5529 vlib_main_t * vm = vlib_get_main();
5530 clib_error_t * error;
5531 u8 * tmp = format(0, "%s", mp->name);
5532 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5533 mp->end_port, (ip4_address_t) mp->start_addr,
5534 (ip4_address_t) mp->end_addr, mp->is_local);
5537 rv = VNET_API_ERROR_UNSPECIFIED;
5539 rv = VNET_API_ERROR_UNIMPLEMENTED;
5542 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5546 vl_api_ikev2_set_local_key_t_handler
5547 (vl_api_ikev2_set_local_key_t * mp)
5549 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5553 vlib_main_t * vm = vlib_get_main();
5554 clib_error_t * error;
5556 error = ikev2_set_local_key(vm, mp->key_file);
5558 rv = VNET_API_ERROR_UNSPECIFIED;
5560 rv = VNET_API_ERROR_UNIMPLEMENTED;
5563 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5567 vl_api_map_add_domain_t_handler
5568 (vl_api_map_add_domain_t * mp)
5570 vl_api_map_add_domain_reply_t * rmp;
5573 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5574 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5575 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5576 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5577 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5579 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5581 rmp->index = ntohl(index);
5586 vl_api_map_del_domain_t_handler
5587 (vl_api_map_del_domain_t * mp)
5589 vl_api_map_del_domain_reply_t * rmp;
5592 rv = map_delete_domain(ntohl(mp->index));
5594 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5598 vl_api_map_add_del_rule_t_handler
5599 (vl_api_map_add_del_rule_t * mp)
5601 vl_api_map_del_domain_reply_t * rmp;
5604 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5606 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5610 vl_api_map_domain_dump_t_handler
5611 (vl_api_map_domain_dump_t * mp)
5613 vl_api_map_domain_details_t * rmp;
5614 map_main_t *mm = &map_main;
5616 unix_shared_memory_queue_t * q;
5618 if (pool_elts (mm->domains) == 0)
5621 q = vl_api_client_index_to_input_queue (mp->client_index);
5626 pool_foreach(d, mm->domains, ({
5627 /* Make sure every field is initiated (or don't skip the memset()) */
5628 rmp = vl_msg_api_alloc (sizeof (*rmp));
5629 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5630 rmp->domain_index = htonl(d - mm->domains);
5631 rmp->ea_bits_len = d->ea_bits_len;
5632 rmp->psid_offset = d->psid_offset;
5633 rmp->psid_length = d->psid_length;
5634 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5635 rmp->ip4_prefix_len = d->ip4_prefix_len;
5636 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5637 rmp->ip6_prefix_len = d->ip6_prefix_len;
5638 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5639 rmp->ip6_src_len = d->ip6_src_len;
5640 rmp->mtu = htons(d->mtu);
5641 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5642 rmp->context = mp->context;
5644 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5649 vl_api_map_rule_dump_t_handler
5650 (vl_api_map_rule_dump_t * mp)
5652 unix_shared_memory_queue_t * q;
5655 vl_api_map_rule_details_t * rmp;
5656 map_main_t *mm = &map_main;
5657 u32 domain_index = ntohl(mp->domain_index);
5660 if (pool_elts (mm->domains) == 0)
5663 d = pool_elt_at_index(mm->domains, domain_index);
5664 if (!d || !d->rules) {
5668 q = vl_api_client_index_to_input_queue (mp->client_index);
5673 for (i = 0; i < (0x1 << d->psid_length); i++) {
5675 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5678 rmp = vl_msg_api_alloc(sizeof(*rmp));
5679 memset(rmp, 0, sizeof(*rmp));
5680 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5681 rmp->psid = htons(i);
5682 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5683 rmp->context = mp->context;
5684 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5689 vl_api_map_summary_stats_t_handler (
5690 vl_api_map_summary_stats_t *mp)
5692 vl_api_map_summary_stats_reply_t *rmp;
5693 vlib_combined_counter_main_t *cm;
5696 u64 total_pkts[VLIB_N_RX_TX];
5697 u64 total_bytes[VLIB_N_RX_TX];
5698 map_main_t *mm = &map_main;
5699 unix_shared_memory_queue_t *q =
5700 vl_api_client_index_to_input_queue(mp->client_index);
5705 rmp = vl_msg_api_alloc (sizeof (*rmp));
5706 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5707 rmp->context = mp->context;
5710 memset (total_pkts, 0, sizeof (total_pkts));
5711 memset (total_bytes, 0, sizeof (total_bytes));
5713 map_domain_counter_lock (mm);
5714 vec_foreach(cm, mm->domain_counters) {
5715 which = cm - mm->domain_counters;
5717 for (i = 0; i < vec_len(cm->maxi); i++) {
5718 vlib_get_combined_counter (cm, i, &v);
5719 total_pkts[which] += v.packets;
5720 total_bytes[which] += v.bytes;
5724 map_domain_counter_unlock (mm);
5726 /* Note: in network byte order! */
5727 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5728 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5729 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5730 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5731 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5732 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5733 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));
5734 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));
5736 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5739 static void vl_api_ipsec_sa_set_key_t_handler
5740 (vl_api_ipsec_sa_set_key_t * mp)
5742 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5743 vl_api_ipsec_sa_set_key_reply_t *rmp;
5747 sa.id = ntohl(mp->sa_id);
5748 sa.crypto_key_len = mp->crypto_key_length;
5749 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5750 sa.integ_key_len = mp->integrity_key_length;
5751 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5753 rv = ipsec_set_sa_key(vm, &sa);
5755 rv = VNET_API_ERROR_UNIMPLEMENTED;
5758 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5761 static void vl_api_cop_interface_enable_disable_t_handler
5762 (vl_api_cop_interface_enable_disable_t * mp)
5764 vl_api_cop_interface_enable_disable_reply_t * rmp;
5766 u32 sw_if_index = ntohl(mp->sw_if_index);
5769 VALIDATE_SW_IF_INDEX(mp);
5771 enable_disable = (int) mp->enable_disable;
5773 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5775 BAD_SW_IF_INDEX_LABEL;
5777 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5780 static void vl_api_cop_whitelist_enable_disable_t_handler
5781 (vl_api_cop_whitelist_enable_disable_t * mp)
5783 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5784 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5785 u32 sw_if_index = ntohl(mp->sw_if_index);
5788 VALIDATE_SW_IF_INDEX(mp);
5790 a->sw_if_index = sw_if_index;
5793 a->default_cop = mp->default_cop;
5794 a->fib_id = ntohl(mp->fib_id);
5796 rv = cop_whitelist_enable_disable (a);
5798 BAD_SW_IF_INDEX_LABEL;
5800 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5803 static void vl_api_get_node_graph_t_handler
5804 (vl_api_get_node_graph_t * mp)
5808 api_main_t * am = &api_main;
5809 vlib_main_t * vm = vlib_get_main();
5811 vl_api_get_node_graph_reply_t * rmp;
5813 pthread_mutex_lock (&am->vlib_rp->mutex);
5814 oldheap = svm_push_data_heap (am->vlib_rp);
5817 * Keep the number of memcpy ops to a minimum (e.g. 1).
5818 * The current size of the serialized vector is
5819 * slightly under 4K.
5821 vec_validate (vector, 4095);
5822 vec_reset_length (vector);
5824 vector = vlib_node_serialize (&vm->node_main, vector);
5826 svm_pop_heap (oldheap);
5827 pthread_mutex_unlock (&am->vlib_rp->mutex);
5829 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5830 rmp->reply_in_shmem = (uword) vector);
5833 static void vl_api_trace_profile_add_t_handler
5834 (vl_api_trace_profile_add_t *mp)
5837 vl_api_trace_profile_add_reply_t * rmp;
5838 clib_error_t *error;
5840 /* Ignoring the profile id as currently a single profile
5842 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5843 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5844 mp->pow_enable, mp->trace_tsp,
5847 clib_error_report(error);
5848 rv = clib_error_get_code(error);
5851 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5854 static void vl_api_trace_profile_apply_t_handler
5855 (vl_api_trace_profile_apply_t *mp)
5858 vl_api_trace_profile_apply_reply_t * rmp;
5860 if (mp->enable != 0) {
5861 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5862 ntohl(mp->prefix_length),
5864 mp->trace_op == IOAM_HBYH_ADD,
5865 mp->trace_op == IOAM_HBYH_POP,
5866 mp->trace_op == IOAM_HBYH_MOD);
5868 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5870 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5873 static void vl_api_trace_profile_del_t_handler
5874 (vl_api_trace_profile_del_t *mp)
5877 vl_api_trace_profile_del_reply_t * rmp;
5878 clib_error_t *error;
5880 error = clear_ioam_rewrite_fn();
5882 clib_error_report(error);
5883 rv = clib_error_get_code(error);
5886 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5890 #define BOUNCE_HANDLER(nn) \
5891 static void vl_api_##nn##_t_handler ( \
5892 vl_api_##nn##_t *mp) \
5894 vpe_client_registration_t *reg; \
5895 vpe_api_main_t * vam = &vpe_api_main; \
5896 unix_shared_memory_queue_t * q; \
5898 /* One registration only... */ \
5899 pool_foreach(reg, vam->nn##_registrations, \
5901 q = vl_api_client_index_to_input_queue (reg->client_index); \
5904 * If the queue is stuffed, turf the msg and complain \
5905 * It's unlikely that the intended recipient is \
5906 * alive; avoid deadlock at all costs. \
5908 if (q->cursize == q->maxsize) { \
5909 clib_warning ("ERROR: receiver queue full, drop msg"); \
5910 vl_msg_api_free (mp); \
5913 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5917 vl_msg_api_free (mp); \
5922 * Add vpe's API message handlers to the table.
5923 * vlib has alread mapped shared memory and
5924 * added the client registration handlers.
5925 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5928 static clib_error_t *
5929 vpe_api_hookup (vlib_main_t *vm)
5931 api_main_t * am = &api_main;
5934 vl_msg_api_set_handlers(VL_API_##N, #n, \
5935 vl_api_##n##_t_handler, \
5937 vl_api_##n##_t_endian, \
5938 vl_api_##n##_t_print, \
5939 sizeof(vl_api_##n##_t), 1);
5940 foreach_vpe_api_msg;
5944 * Manually register the sr tunnel add del msg, so we trace
5945 * enough bytes to capture a typical segment list
5947 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5948 "sr_tunnel_add_del",
5949 vl_api_sr_tunnel_add_del_t_handler,
5951 vl_api_sr_tunnel_add_del_t_endian,
5952 vl_api_sr_tunnel_add_del_t_print,
5957 * Manually register the sr policy add del msg, so we trace
5958 * enough bytes to capture a typical tunnel name list
5960 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
5961 "sr_policy_add_del",
5962 vl_api_sr_policy_add_del_t_handler,
5964 vl_api_sr_policy_add_del_t_endian,
5965 vl_api_sr_policy_add_del_t_print,
5969 * Trace space for 8 MPLS encap labels, classifier mask+match
5971 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5972 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5973 += 5 * sizeof (u32x4);
5974 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5975 += 5 * sizeof (u32x4);
5976 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5977 += 16 * sizeof (u32);
5980 * trace space for 4 nsh-gre variable TLV words
5982 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5983 += 4 * sizeof (u32);
5986 * Thread-safe API messages
5988 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
5993 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5995 static clib_error_t *
5996 vpe_api_init (vlib_main_t *vm)
5998 vpe_api_main_t *am = &vpe_api_main;
6001 am->vnet_main = vnet_get_main();
6002 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
6003 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6004 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
6005 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6006 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
6007 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
6010 vl_set_memory_region_name ("/vpe-api");
6011 vl_enable_disable_memory_api (vm, 1 /* enable it */);
6016 VLIB_INIT_FUNCTION(vpe_api_init);
6018 static clib_error_t *
6019 chroot_config (vlib_main_t * vm, unformat_input_t * input)
6023 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6025 if (unformat (input, "prefix %s", &chroot_path))
6027 vec_add1 (chroot_path, 0);
6028 vl_set_memory_root_path ((char *)chroot_path);
6031 return clib_error_return (0, "unknown input `%U'",
6032 format_unformat_error, input);
6036 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6038 void * get_unformat_vnet_sw_interface (void)
6040 return (void *) &unformat_vnet_sw_interface;
6043 #undef vl_api_version
6044 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6045 #include <api/vpe.api.h>
6046 #undef vl_api_version
6048 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6050 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6051 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6052 clib_host_to_net_u32 (mp->api_versions[0]),
6059 static u8 * format_arp_event (u8 * s, va_list * args)
6061 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6063 s = format (s, "pid %d: %U", event->pid,
6064 format_ip4_address, &event->address);
6068 static clib_error_t *
6069 show_ip4_arp_events_fn (vlib_main_t * vm,
6070 unformat_input_t * input,
6071 vlib_cli_command_t * cmd)
6073 vpe_api_main_t * am = &vpe_api_main;
6074 vl_api_ip4_arp_event_t * event;
6076 if (pool_elts (am->arp_events) == 0) {
6077 vlib_cli_output (vm, "No active arp event registrations");
6081 pool_foreach (event, am->arp_events,
6083 vlib_cli_output (vm, "%U", format_arp_event, event);
6089 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6090 .path = "show arp event registrations",
6091 .function = show_ip4_arp_events_fn,
6092 .short_help = "Show arp event registrations",