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,
1502 vl_api_bridge_domain_details_t * mp;
1504 mp = vl_msg_api_alloc (sizeof (*mp));
1505 memset (mp, 0, sizeof (*mp));
1506 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1507 mp->bd_id = ntohl (bd_config->bd_id);
1508 mp->flood = bd_feature_flood (bd_config);
1509 mp->uu_flood = bd_feature_uu_flood (bd_config);
1510 mp->forward = bd_feature_forward (bd_config);
1511 mp->learn = bd_feature_learn (bd_config);
1512 mp->arp_term = bd_feature_arp_term (bd_config);
1513 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1514 mp->n_sw_ifs = ntohl (n_sw_ifs);
1516 vl_msg_api_send_shmem (q, (u8 *)&mp);
1519 static void send_bd_sw_if_details (l2input_main_t * l2im,
1520 unix_shared_memory_queue_t *q,
1521 l2_flood_member_t * member, u32 bd_id)
1523 vl_api_bridge_domain_sw_if_details_t * mp;
1524 l2_input_config_t * input_cfg;
1526 mp = vl_msg_api_alloc (sizeof (*mp));
1527 memset (mp, 0, sizeof (*mp));
1528 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1529 mp->bd_id = ntohl (bd_id);
1530 mp->sw_if_index = ntohl (member->sw_if_index);
1531 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1532 mp->shg = input_cfg->shg;
1534 vl_msg_api_send_shmem (q, (u8 *)&mp);
1537 static void vl_api_bridge_domain_dump_t_handler (
1538 vl_api_bridge_domain_dump_t *mp)
1540 bd_main_t * bdm = &bd_main;
1541 l2input_main_t * l2im = &l2input_main;
1542 unix_shared_memory_queue_t * q;
1543 l2_bridge_domain_t * bd_config;
1544 u32 bd_id, bd_index;
1547 q = vl_api_client_index_to_input_queue (mp->client_index);
1552 bd_id = ntohl(mp->bd_id);
1554 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1555 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1556 for (; bd_index < end; bd_index++) {
1557 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1558 /* skip dummy bd_id 0 */
1559 if (bd_config && (bd_config->bd_id > 0)) {
1561 l2_flood_member_t * m;
1563 n_sw_ifs = vec_len (bd_config->members);
1564 send_bridge_domain_details (q, bd_config, n_sw_ifs);
1566 vec_foreach (m, bd_config->members) {
1567 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id);
1574 vl_api_l2fib_add_del_t_handler (
1575 vl_api_l2fib_add_del_t *mp)
1577 bd_main_t * bdm = &bd_main;
1578 l2input_main_t * l2im = &l2input_main;
1579 vl_api_l2fib_add_del_reply_t * rmp;
1582 u32 sw_if_index = ntohl(mp->sw_if_index);
1583 u32 bd_id = ntohl(mp->bd_id);
1591 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1593 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1594 goto bad_sw_if_index;
1599 VALIDATE_SW_IF_INDEX(mp);
1600 if (vec_len(l2im->configs) <= sw_if_index) {
1601 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1602 goto bad_sw_if_index;
1604 l2_input_config_t * config;
1605 config = vec_elt_at_index(l2im->configs, sw_if_index);
1606 if (config->bridge == 0) {
1607 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1608 goto bad_sw_if_index;
1611 static_mac = mp->static_mac ? 1 : 0;
1612 filter_mac = mp->filter_mac ? 1 : 0;
1613 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1616 l2fib_del_entry(mac, bd_index);
1619 BAD_SW_IF_INDEX_LABEL;
1621 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1625 vl_api_l2_flags_t_handler (
1626 vl_api_l2_flags_t *mp)
1628 vl_api_l2_flags_reply_t * rmp;
1630 u32 sw_if_index = ntohl(mp->sw_if_index);
1631 u32 flags = ntohl(mp->feature_bitmap);
1634 VALIDATE_SW_IF_INDEX(mp);
1637 if (flags & L2INPUT_FEAT_ ## a) \
1638 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1639 foreach_l2input_feat;
1642 BAD_SW_IF_INDEX_LABEL;
1644 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1648 vl_api_bridge_flags_t_handler (
1649 vl_api_bridge_flags_t *mp)
1651 vlib_main_t *vm = vlib_get_main();
1652 bd_main_t * bdm = &bd_main;
1653 vl_api_bridge_flags_reply_t * rmp;
1655 u32 bd_id = ntohl(mp->bd_id);
1657 u32 flags = ntohl(mp->feature_bitmap);
1660 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1662 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1668 bd_set_flags(vm, bd_index, flags, mp->is_set);
1671 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1672 rmp->resulting_feature_bitmap = ntohl(flags));
1676 vl_api_bd_ip_mac_add_del_t_handler (
1677 vl_api_bd_ip_mac_add_del_t *mp)
1679 bd_main_t * bdm = &bd_main;
1680 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1682 u32 bd_id = ntohl(mp->bd_id);
1686 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1688 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1693 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1694 mp->mac_address, mp->is_ipv6, mp->is_add))
1695 rv = VNET_API_ERROR_UNSPECIFIED;
1698 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1702 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1705 vl_api_tap_connect_reply_t * rmp;
1706 unix_shared_memory_queue_t * q;
1707 u32 sw_if_index = (u32)~0;
1709 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1710 mp->use_random_mac ? 0 : mp->mac_address,
1711 &sw_if_index, mp->renumber,
1712 ntohl(mp->custom_dev_instance));
1714 q = vl_api_client_index_to_input_queue (mp->client_index);
1718 rmp = vl_msg_api_alloc (sizeof (*rmp));
1719 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1720 rmp->context = mp->context;
1721 rmp->retval = ntohl(rv);
1722 rmp->sw_if_index = ntohl(sw_if_index);
1724 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1728 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1731 vl_api_tap_modify_reply_t * rmp;
1732 unix_shared_memory_queue_t * q;
1733 u32 sw_if_index = (u32)~0;
1735 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1736 mp->use_random_mac ? 0 : mp->mac_address,
1737 &sw_if_index, mp->renumber,
1738 ntohl(mp->custom_dev_instance));
1740 q = vl_api_client_index_to_input_queue (mp->client_index);
1744 rmp = vl_msg_api_alloc (sizeof (*rmp));
1745 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1746 rmp->context = mp->context;
1747 rmp->retval = ntohl(rv);
1748 rmp->sw_if_index = ntohl(sw_if_index);
1750 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1754 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1757 vpe_api_main_t * vam = &vpe_api_main;
1758 vl_api_tap_delete_reply_t * rmp;
1759 unix_shared_memory_queue_t * q;
1760 u32 sw_if_index = ntohl(mp->sw_if_index);
1762 rv = vnet_tap_delete (vm, sw_if_index);
1764 q = vl_api_client_index_to_input_queue (mp->client_index);
1768 rmp = vl_msg_api_alloc (sizeof (*rmp));
1769 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1770 rmp->context = mp->context;
1771 rmp->retval = ntohl(rv);
1773 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1776 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1780 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1782 vl_api_create_vlan_subif_reply_t * rmp;
1783 vnet_main_t * vnm = vnet_get_main();
1784 u32 hw_if_index, sw_if_index = (u32)~0;
1785 vnet_hw_interface_t * hi;
1788 vnet_sw_interface_t template;
1790 vnet_interface_main_t * im = &vnm->interface_main;
1791 u64 sup_and_sub_key;
1793 unix_shared_memory_queue_t * q;
1794 clib_error_t * error;
1796 VALIDATE_SW_IF_INDEX(mp);
1798 hw_if_index = ntohl(mp->sw_if_index);
1799 hi = vnet_get_hw_interface (vnm, hw_if_index);
1801 id = ntohl(mp->vlan_id);
1802 if (id == 0 || id > 4095) {
1803 rv = VNET_API_ERROR_INVALID_VLAN;
1807 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1809 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1811 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1815 kp = clib_mem_alloc (sizeof (*kp));
1816 *kp = sup_and_sub_key;
1818 memset (&template, 0, sizeof (template));
1819 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1820 template.sup_sw_if_index = hi->sw_if_index;
1821 template.sub.id = id;
1822 template.sub.eth.raw_flags = 0;
1823 template.sub.eth.flags.one_tag = 1;
1824 template.sub.eth.outer_vlan_id = id;
1825 template.sub.eth.flags.exact_match = 1;
1827 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1829 clib_error_report(error);
1830 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1833 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1834 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1836 BAD_SW_IF_INDEX_LABEL;
1839 q = vl_api_client_index_to_input_queue (mp->client_index);
1843 rmp = vl_msg_api_alloc (sizeof (*rmp));
1844 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1845 rmp->context = mp->context;
1846 rmp->retval = ntohl(rv);
1847 rmp->sw_if_index = ntohl(sw_if_index);
1848 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1852 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1854 vl_api_create_subif_reply_t * rmp;
1855 vnet_main_t * vnm = vnet_get_main();
1856 u32 sw_if_index = ~0;
1859 vnet_sw_interface_t *si;
1860 vnet_hw_interface_t *hi;
1861 vnet_sw_interface_t template;
1863 vnet_interface_main_t * im = &vnm->interface_main;
1864 u64 sup_and_sub_key;
1866 clib_error_t * error;
1868 VALIDATE_SW_IF_INDEX(mp);
1870 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1871 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1873 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1874 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1878 sw_if_index = si->sw_if_index;
1879 sub_id = ntohl(mp->sub_id);
1881 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1883 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1886 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1887 sw_if_index, sub_id);
1888 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1892 kp = clib_mem_alloc (sizeof (*kp));
1893 *kp = sup_and_sub_key;
1895 memset (&template, 0, sizeof (template));
1896 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1897 template.sup_sw_if_index = sw_if_index;
1898 template.sub.id = sub_id;
1899 template.sub.eth.flags.no_tags = mp->no_tags;
1900 template.sub.eth.flags.one_tag = mp->one_tag;
1901 template.sub.eth.flags.two_tags = mp->two_tags;
1902 template.sub.eth.flags.dot1ad = mp->dot1ad;
1903 template.sub.eth.flags.exact_match = mp->exact_match;
1904 template.sub.eth.flags.default_sub = mp->default_sub;
1905 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1906 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1907 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1908 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1910 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1912 clib_error_report (error);
1913 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1917 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1918 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1920 BAD_SW_IF_INDEX_LABEL;
1924 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1926 rmp->sw_if_index = ntohl(sw_if_index);
1931 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1933 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1935 stats_main_t * sm = &stats_main;
1936 u32 tunnel_sw_if_index = ~0;
1938 dslock (sm, 1 /* release hint */, 5 /* tag */);
1940 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1941 (ip4_address_t *)(mp->dst_address),
1942 (ip4_address_t *)(mp->intfc_address),
1943 (u32)(mp->intfc_address_length),
1944 ntohl(mp->inner_vrf_id),
1945 ntohl(mp->outer_vrf_id),
1946 &tunnel_sw_if_index,
1951 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1953 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1958 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1959 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1961 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1963 stats_main_t * sm = &stats_main;
1964 u32 tunnel_sw_if_index;
1966 dslock (sm, 1 /* release hint */, 5 /* tag */);
1968 rv = vnet_mpls_ethernet_add_del_tunnel
1969 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1970 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1971 ntohl(mp->tx_sw_if_index),
1972 &tunnel_sw_if_index,
1978 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1980 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1985 * This piece of misery brought to you because the control-plane
1986 * can't figure out the tx interface + dst-mac address all by itself
1988 static int mpls_ethernet_add_del_tunnel_2_t_handler
1989 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1991 pending_route_t * pr;
1992 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1993 vnet_main_t * vnm = vnet_get_main();
1994 vlib_main_t * vm = vlib_get_main();
1995 stats_main_t * sm = &stats_main;
1996 vpe_api_main_t * vam = &vpe_api_main;
1997 u32 inner_fib_index, outer_fib_index;
1998 ip4_main_t * im = &ip4_main;
1999 ip_lookup_main_t * lm = &im->lookup_main;
2000 ip_adjacency_t * adj = 0;
2003 u8 * dst_mac_address;
2007 u32 tunnel_sw_if_index;
2009 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2011 return VNET_API_ERROR_NO_SUCH_FIB;
2013 outer_fib_index = p[0];
2016 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2018 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2020 inner_fib_index = p[0];
2022 if (inner_fib_index == outer_fib_index)
2023 return VNET_API_ERROR_INVALID_VALUE;
2025 lookup_result = ip4_fib_lookup_with_table
2026 (im, outer_fib_index,
2027 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2028 1 /* disable default route */);
2030 adj = ip_get_adjacency (lm, lookup_result);
2031 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2033 if (mp->is_add && mp->resolve_if_needed) {
2034 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2035 pool_get (vam->pending_routes, pr);
2036 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2038 clib_memcpy (pme, mp, sizeof (*pme));
2039 /* recursion block, "just in case" */
2040 pme->resolve_if_needed = 0;
2041 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2042 pme->resolve_opaque = tx_sw_if_index;
2043 vnet_register_ip4_arp_resolution_event
2045 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2046 vpe_resolver_process_node.index,
2047 RESOLUTION_EVENT, pr - vam->pending_routes);
2049 vlib_process_signal_event
2050 (vm, vpe_resolver_process_node.index,
2051 RESOLUTION_PENDING_EVENT, 0 /* data */);
2053 /* The interface may be down, etc. */
2054 e = ip4_probe_neighbor
2055 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2059 clib_error_report(e);
2061 return VNET_API_ERROR_IN_PROGRESS;
2065 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2066 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2069 vnet_rewrite_get_data_internal
2070 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2072 dslock (sm, 1 /* release hint */, 10 /* tag */);
2074 rv = vnet_mpls_ethernet_add_del_tunnel
2075 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2076 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2077 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2085 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2086 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2088 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2091 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2093 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2098 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2100 vl_api_mpls_add_del_encap_reply_t * rmp;
2102 static u32 * labels;
2105 vec_reset_length (labels);
2107 for (i = 0; i < mp->nlabels; i++)
2108 vec_add1 (labels, ntohl(mp->labels[i]));
2111 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2112 ntohl(mp->vrf_id), labels,
2113 ~0 /* policy_tunnel_index */,
2114 0 /* no_dst_hash */,
2118 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2122 vl_api_mpls_add_del_decap_t_handler
2123 (vl_api_mpls_add_del_decap_t *mp)
2125 vl_api_mpls_add_del_decap_reply_t * rmp;
2128 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2129 ntohl(mp->label), ntohl(mp->next_index),
2130 mp->s_bit, mp->is_add);
2132 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2136 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2138 vl_api_proxy_arp_add_del_reply_t * rmp;
2141 ip4_main_t * im = &ip4_main;
2142 stats_main_t * sm = &stats_main;
2143 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2144 ip4_address_t *hi_addr,
2145 u32 fib_index, int is_del);
2148 dslock (sm, 1 /* release hint */, 6 /* tag */);
2150 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2153 rv = VNET_API_ERROR_NO_SUCH_FIB;
2159 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2160 (ip4_address_t *)mp->hi_address,
2161 fib_index, mp->is_add == 0);
2165 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2169 vl_api_proxy_arp_intfc_enable_disable_t_handler
2170 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2173 vnet_main_t * vnm = vnet_get_main();
2174 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2175 vnet_sw_interface_t * si;
2178 VALIDATE_SW_IF_INDEX(mp);
2180 sw_if_index = ntohl(mp->sw_if_index);
2182 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2184 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2188 si = vnet_get_sw_interface (vnm, sw_if_index);
2192 if (mp->enable_disable)
2193 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2195 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2197 BAD_SW_IF_INDEX_LABEL;
2200 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2204 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2206 vl_api_ip_neighbor_add_del_reply_t * rmp;
2207 vnet_main_t * vnm = vnet_get_main();
2210 stats_main_t * sm = &stats_main;
2212 VALIDATE_SW_IF_INDEX(mp);
2214 dslock (sm, 1 /* release hint */, 7 /* tag */);
2218 rv = vnet_set_ip6_ethernet_neighbor
2219 (vm, ntohl(mp->sw_if_index),
2220 (ip6_address_t *)(mp->dst_address),
2221 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2223 rv = vnet_unset_ip6_ethernet_neighbor
2224 (vm, ntohl(mp->sw_if_index),
2225 (ip6_address_t *)(mp->dst_address),
2226 mp->mac_address, sizeof(mp->mac_address));
2228 ip4_main_t * im = &ip4_main;
2229 ip_lookup_main_t * lm = &im->lookup_main;
2230 ethernet_arp_ip4_over_ethernet_address_t a;
2232 ip_adjacency_t *nh_adj;
2234 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2236 rv = VNET_API_ERROR_NO_SUCH_FIB;
2242 * Unfortunately, folks have a penchant for
2243 * adding interface addresses to the ARP cache, and
2244 * wondering why the forwarder eventually ASSERTs...
2246 ai = ip4_fib_lookup_with_table
2247 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2248 1 /* disable default route */);
2251 nh_adj = ip_get_adjacency (lm, ai);
2252 /* Never allow manipulation of a local adj! */
2253 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2254 clib_warning("%U matches local adj",
2256 (ip4_address_t *)(mp->dst_address));
2257 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2262 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2263 clib_memcpy (&a.ip4, mp->dst_address, 4);
2266 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2267 fib_index, &a, mp->is_static);
2269 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2273 BAD_SW_IF_INDEX_LABEL;
2276 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2280 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2283 vpe_main_t *rm = &vpe_main;
2284 ip4_main_t *im4 = &ip4_main;
2285 ip6_main_t *im6 = &ip6_main;
2286 ip_lookup_main_t * lm;
2291 u32 adj_index, sw_if_index;
2292 vl_api_is_address_reachable_t *rmp;
2293 ip_adjacency_t * adj;
2294 unix_shared_memory_queue_t *q;
2296 q = vl_api_client_index_to_input_queue (mp->client_index);
2298 increment_missing_api_client_counter (rm->vlib_main);
2302 rmp = vl_msg_api_alloc (sizeof (*rmp));
2303 clib_memcpy (rmp, mp, sizeof (*rmp));
2305 sw_if_index = mp->next_hop_sw_if_index;
2306 clib_memcpy (&addr, mp->address, sizeof (addr));
2308 lm = &im6->lookup_main;
2310 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2312 lm = &im4->lookup_main;
2314 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2316 if (adj_index == ~0) {
2320 adj = ip_get_adjacency (lm, adj_index);
2322 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2323 && adj->rewrite_header.sw_if_index == sw_if_index) {
2326 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2327 && adj->rewrite_header.sw_if_index == sw_if_index) {
2329 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2331 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2332 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2340 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2344 static void vl_api_sw_interface_details_t_handler (
2345 vl_api_sw_interface_details_t * mp)
2347 clib_warning ("BUG");
2350 static void vl_api_sw_interface_set_flags_t_handler (
2351 vl_api_sw_interface_set_flags_t * mp)
2353 vl_api_sw_interface_set_flags_reply_t *rmp;
2354 vnet_main_t * vnm = vnet_get_main();
2356 clib_error_t * error;
2359 VALIDATE_SW_IF_INDEX(mp);
2361 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2363 error = vnet_sw_interface_set_flags (vnm,
2364 ntohl(mp->sw_if_index),
2368 clib_error_report (error);
2371 BAD_SW_IF_INDEX_LABEL;
2372 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2375 static void vl_api_sw_interface_clear_stats_t_handler (
2376 vl_api_sw_interface_clear_stats_t * mp)
2378 vl_api_sw_interface_clear_stats_reply_t *rmp;
2380 vnet_main_t * vnm = vnet_get_main();
2381 vnet_interface_main_t * im = &vnm->interface_main;
2382 vlib_simple_counter_main_t * sm;
2383 vlib_combined_counter_main_t * cm;
2384 static vnet_main_t ** my_vnet_mains;
2385 int i, j, n_counters;
2389 vec_reset_length (my_vnet_mains);
2391 for (i = 0; i < vec_len (vnet_mains); i++)
2394 vec_add1 (my_vnet_mains, vnet_mains[i]);
2397 if (vec_len (vnet_mains) == 0)
2398 vec_add1 (my_vnet_mains, vnm);
2400 n_counters = vec_len (im->combined_sw_if_counters);
2402 for (j = 0; j < n_counters; j++)
2404 for (i = 0; i < vec_len(my_vnet_mains); i++)
2406 im = &my_vnet_mains[i]->interface_main;
2407 cm = im->combined_sw_if_counters + j;
2408 if (mp->sw_if_index == (u32)~0)
2409 vlib_clear_combined_counters (cm);
2411 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2415 n_counters = vec_len (im->sw_if_counters);
2417 for (j = 0; j < n_counters; j++)
2419 for (i = 0; i < vec_len(my_vnet_mains); i++)
2421 im = &my_vnet_mains[i]->interface_main;
2422 sm = im->sw_if_counters + j;
2423 if (mp->sw_if_index == (u32)~0)
2424 vlib_clear_simple_counters (sm);
2426 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2430 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2433 static void send_sw_interface_details (vpe_api_main_t * am,
2434 unix_shared_memory_queue_t *q,
2435 vnet_sw_interface_t * swif,
2436 u8 * interface_name,
2439 vl_api_sw_interface_details_t * mp;
2440 vnet_hw_interface_t * hi;
2442 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2444 mp = vl_msg_api_alloc (sizeof (*mp));
2445 memset (mp, 0, sizeof (*mp));
2446 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2447 mp->sw_if_index = ntohl(swif->sw_if_index);
2448 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2449 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2451 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2453 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2454 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2455 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2456 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2457 mp->link_mtu = ntohs(hi->max_packet_bytes);
2458 mp->context = context;
2460 strncpy ((char *) mp->interface_name,
2461 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2463 /* Send the L2 address for ethernet physical intfcs */
2464 if (swif->sup_sw_if_index == swif->sw_if_index
2465 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2466 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2467 ethernet_interface_t *ei;
2469 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2470 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2471 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2472 mp->l2_address_length = ntohl(sizeof (ei->address));
2473 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2474 vnet_sub_interface_t *sub = &swif->sub;
2475 mp->sub_id = ntohl(sub->id);
2476 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2477 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2478 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2479 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2480 mp->sub_exact_match = sub->eth.flags.exact_match;
2481 mp->sub_default = sub->eth.flags.default_sub;
2482 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2483 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2485 /* vlan tag rewrite data */
2486 u32 vtr_op = L2_VTR_DISABLED;
2487 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2489 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2490 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2491 // error - default to disabled
2492 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2493 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2496 mp->vtr_op = ntohl(vtr_op);
2497 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2498 mp->vtr_tag1 = ntohl(vtr_tag1);
2499 mp->vtr_tag2 = ntohl(vtr_tag2);
2503 vl_msg_api_send_shmem (q, (u8 *)&mp);
2506 static void send_sw_interface_flags (vpe_api_main_t * am,
2507 unix_shared_memory_queue_t *q,
2508 vnet_sw_interface_t * swif)
2510 vl_api_sw_interface_set_flags_t *mp;
2511 vnet_main_t * vnm = am->vnet_main;
2513 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2515 mp = vl_msg_api_alloc (sizeof (*mp));
2516 memset (mp, 0, sizeof (*mp));
2517 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2518 mp->sw_if_index = ntohl(swif->sw_if_index);
2520 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2522 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2524 vl_msg_api_send_shmem (q, (u8 *)&mp);
2527 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2528 unix_shared_memory_queue_t *q,
2530 __attribute__((unused));
2532 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2533 unix_shared_memory_queue_t *q,
2536 vl_api_sw_interface_set_flags_t *mp;
2538 mp = vl_msg_api_alloc (sizeof (*mp));
2539 memset (mp, 0, sizeof (*mp));
2540 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2541 mp->sw_if_index = ntohl(sw_if_index);
2543 mp->admin_up_down = 0;
2544 mp->link_up_down = 0;
2546 vl_msg_api_send_shmem (q, (u8 *)&mp);
2549 static void vl_api_sw_interface_dump_t_handler (
2550 vl_api_sw_interface_dump_t *mp)
2552 vpe_api_main_t * am = &vpe_api_main;
2553 vnet_sw_interface_t * swif;
2554 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2555 u8 * filter_string = 0, * name_string = 0;
2556 unix_shared_memory_queue_t * q;
2557 char * strcasestr (char *, char *); /* lnx hdr file botch */
2559 q = vl_api_client_index_to_input_queue (mp->client_index);
2564 if (mp->name_filter_valid) {
2565 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2566 filter_string = format (0, "%s%c", mp->name_filter, 0);
2569 pool_foreach (swif, im->sw_interfaces,
2571 name_string = format (name_string, "%U%c",
2572 format_vnet_sw_interface_name,
2573 am->vnet_main, swif, 0);
2575 if (mp->name_filter_valid == 0 ||
2576 strcasestr((char *) name_string, (char *) filter_string)) {
2578 send_sw_interface_details (am, q, swif, name_string, mp->context);
2579 send_sw_interface_flags (am, q, swif);
2581 _vec_len (name_string) = 0;
2584 vec_free (name_string);
2585 vec_free (filter_string);
2588 void send_oam_event (oam_target_t * t)
2590 vpe_api_main_t * vam = &vpe_api_main;
2591 unix_shared_memory_queue_t * q;
2592 vpe_client_registration_t *reg;
2593 vl_api_oam_event_t * mp;
2595 pool_foreach(reg, vam->oam_events_registrations,
2597 q = vl_api_client_index_to_input_queue (reg->client_index);
2599 mp = vl_msg_api_alloc (sizeof (*mp));
2600 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2601 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2602 mp->state = t->state;
2603 vl_msg_api_send_shmem (q, (u8 *)&mp);
2609 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2611 vl_api_oam_add_del_reply_t * rmp;
2614 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2615 (ip4_address_t *)mp->dst_address,
2619 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2623 vl_api_vnet_get_summary_stats_t_handler (
2624 vl_api_vnet_get_summary_stats_t *mp)
2626 stats_main_t * sm = &stats_main;
2627 vnet_interface_main_t * im = sm->interface_main;
2628 vl_api_vnet_summary_stats_reply_t *rmp;
2629 vlib_combined_counter_main_t * cm;
2632 u64 total_pkts[VLIB_N_RX_TX];
2633 u64 total_bytes[VLIB_N_RX_TX];
2635 unix_shared_memory_queue_t * q =
2636 vl_api_client_index_to_input_queue (mp->client_index);
2641 rmp = vl_msg_api_alloc (sizeof (*rmp));
2642 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2643 rmp->context = mp->context;
2646 memset (total_pkts, 0, sizeof (total_pkts));
2647 memset (total_bytes, 0, sizeof (total_bytes));
2649 vnet_interface_counter_lock (im);
2651 vec_foreach (cm, im->combined_sw_if_counters) {
2652 which = cm - im->combined_sw_if_counters;
2654 for (i = 0; i < vec_len (cm->maxi); i++) {
2655 vlib_get_combined_counter (cm, i, &v);
2656 total_pkts[which] += v.packets;
2657 total_bytes[which] += v.bytes;
2660 vnet_interface_counter_unlock (im);
2662 /* Note: in HOST byte order! */
2663 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2664 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2665 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2666 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2667 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2669 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2672 typedef CLIB_PACKED (struct {
2673 ip4_address_t address;
2675 u32 address_length : 6;
2680 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2682 vnet_main_t * vnm = vnet_get_main();
2683 vnet_interface_main_t * im = &vnm->interface_main;
2684 ip4_main_t * im4 = &ip4_main;
2685 static ip4_route_t * routes;
2686 static u32 * sw_if_indices_to_shut;
2687 stats_main_t * sm = &stats_main;
2692 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2693 u32 target_fib_id = ntohl(mp->vrf_id);
2695 dslock (sm, 1 /* release hint */, 8 /* tag */);
2697 vec_foreach (fib, im4->fibs) {
2698 vnet_sw_interface_t * si;
2700 if (fib->table_id != target_fib_id)
2703 /* remove any mpls/gre tunnels in this fib */
2704 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2706 /* remove any mpls encap/decap labels */
2707 mpls_fib_reset_labels (fib->table_id);
2709 /* remove any proxy arps in this fib */
2710 vnet_proxy_arp_fib_reset (fib->table_id);
2712 /* Set the flow hash for this fib to the default */
2713 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2715 vec_reset_length (sw_if_indices_to_shut);
2717 /* Shut down interfaces in this FIB / clean out intfc routes */
2718 pool_foreach (si, im->sw_interfaces,
2720 u32 sw_if_index = si->sw_if_index;
2722 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2723 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2725 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2728 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2729 sw_if_index = sw_if_indices_to_shut[i];
2730 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2732 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2733 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2734 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2737 vec_reset_length (routes);
2739 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2740 uword * hash = fib->adj_index_by_dst_address[i];
2744 x.address_length = i;
2746 hash_foreach_pair (p, hash,
2748 x.address.data_u32 = p->key;
2749 vec_add1 (routes, x);
2753 vec_foreach (r, routes) {
2754 ip4_add_del_route_args_t a;
2756 memset (&a, 0, sizeof (a));
2757 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2758 a.table_index_or_table_id = fib - im4->fibs;
2759 a.dst_address = r->address;
2760 a.dst_address_length = r->address_length;
2763 ip4_add_del_route (im4, &a);
2764 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2765 IP4_ROUTE_FLAG_FIB_INDEX);
2769 } /* vec_foreach (fib) */
2776 ip6_address_t address;
2783 ip6_route_t ** routep;
2784 } add_routes_in_fib_arg_t;
2786 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2788 add_routes_in_fib_arg_t * ap = arg;
2790 if (kvp->key[2]>>32 == ap->fib_index)
2792 ip6_address_t *addr;
2794 addr = (ip6_address_t *) kvp;
2795 vec_add2 (*ap->routep, r, 1);
2796 r->address = addr[0];
2797 r->address_length = kvp->key[2] & 0xFF;
2798 r->index = kvp->value;
2802 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2804 vnet_main_t * vnm = vnet_get_main();
2805 vnet_interface_main_t * im = &vnm->interface_main;
2806 ip6_main_t * im6 = &ip6_main;
2807 stats_main_t * sm = &stats_main;
2808 static ip6_route_t * routes;
2809 static u32 * sw_if_indices_to_shut;
2814 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2815 u32 target_fib_id = ntohl(mp->vrf_id);
2816 add_routes_in_fib_arg_t _a, *a=&_a;
2817 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2819 dslock (sm, 1 /* release hint */, 9 /* tag */);
2821 vec_foreach (fib, im6->fibs) {
2822 vnet_sw_interface_t * si;
2824 if (fib->table_id != target_fib_id)
2827 vec_reset_length (sw_if_indices_to_shut);
2829 /* Shut down interfaces in this FIB / clean out intfc routes */
2830 pool_foreach (si, im->sw_interfaces,
2832 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2834 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2837 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2838 sw_if_index = sw_if_indices_to_shut[i];
2839 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2841 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2842 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2843 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2846 vec_reset_length (routes);
2848 a->fib_index = fib - im6->fibs;
2849 a->routep = &routes;
2851 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2853 vec_foreach (r, routes) {
2854 ip6_add_del_route_args_t a;
2856 memset (&a, 0, sizeof (a));
2857 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2858 a.table_index_or_table_id = fib - im6->fibs;
2859 a.dst_address = r->address;
2860 a.dst_address_length = r->address_length;
2863 ip6_add_del_route (im6, &a);
2864 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2865 IP6_ROUTE_FLAG_FIB_INDEX);
2868 /* Reinstall the neighbor / router discovery routes */
2869 vnet_ip6_fib_init (im6, fib - im6->fibs);
2871 } /* vec_foreach (fib) */
2877 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2880 vl_api_reset_fib_reply_t * rmp;
2883 rv = ip6_reset_fib_t_handler (mp);
2885 rv = ip4_reset_fib_t_handler (mp);
2887 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2892 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2894 vl_api_dhcp_proxy_config_reply_t * rmp;
2897 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2898 (ip4_address_t *)(&mp->dhcp_src_address),
2899 (u32) ntohl(mp->vrf_id),
2900 (int) mp->insert_circuit_id,
2901 (int) (mp->is_add == 0));
2903 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2908 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2910 vl_api_dhcp_proxy_config_reply_t * rmp;
2913 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2914 (ip6_address_t *)(&mp->dhcp_src_address),
2915 (u32) ntohl(mp->vrf_id),
2916 (int) mp->insert_circuit_id,
2917 (int) (mp->is_add == 0));
2919 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2923 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2925 vl_api_dhcp_proxy_config_reply_t * rmp;
2928 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2929 (ip4_address_t *)(&mp->dhcp_src_address),
2930 (u32) ntohl(mp->rx_vrf_id),
2931 (u32) ntohl(mp->server_vrf_id),
2932 (int) mp->insert_circuit_id,
2933 (int) (mp->is_add == 0));
2935 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2940 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2942 vl_api_dhcp_proxy_config_reply_t * rmp;
2946 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2947 (ip6_address_t *)(&mp->dhcp_src_address),
2948 (u32) ntohl(mp->rx_vrf_id),
2949 (u32) ntohl(mp->server_vrf_id),
2950 (int) mp->insert_circuit_id,
2951 (int) (mp->is_add == 0));
2953 rv = VNET_API_ERROR_UNIMPLEMENTED;
2956 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2961 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2963 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2966 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2969 (int)mp->is_add == 0);
2971 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2974 (int)mp->is_add == 0);
2976 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2980 static void vl_api_dhcp_proxy_config_t_handler
2981 (vl_api_dhcp_proxy_config_t *mp)
2983 if (mp->is_ipv6 == 0)
2984 dhcpv4_proxy_config (mp);
2986 dhcpv6_proxy_config (mp);
2989 static void vl_api_dhcp_proxy_config_2_t_handler
2990 (vl_api_dhcp_proxy_config_2_t *mp)
2992 if (mp->is_ipv6 == 0)
2993 dhcpv4_proxy_config_2 (mp);
2995 dhcpv6_proxy_config_2 (mp);
2998 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
2999 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3001 unix_shared_memory_queue_t * q;
3002 vl_api_dhcp_compl_event_t * mp;
3004 q = vl_api_client_index_to_input_queue (client_index);
3008 mp = vl_msg_api_alloc (sizeof (*mp));
3009 mp->client_index = client_index;
3011 mp->is_ipv6 = is_ipv6;
3012 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3013 mp->hostname[vec_len(hostname) + 1] = '\n';
3014 clib_memcpy (&mp->host_address[0], host_address, 16);
3015 clib_memcpy (&mp->router_address[0], router_address, 16);
3016 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3018 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3020 vl_msg_api_send_shmem (q, (u8 *)&mp);
3023 static void vl_api_dhcp_client_config_t_handler
3024 (vl_api_dhcp_client_config_t *mp)
3026 vlib_main_t *vm = vlib_get_main();
3027 vl_api_dhcp_client_config_reply_t * rmp;
3030 VALIDATE_SW_IF_INDEX(mp);
3032 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3033 mp->hostname, mp->is_add, mp->client_index,
3034 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3037 BAD_SW_IF_INDEX_LABEL;
3039 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3043 vl_api_sw_interface_ip6nd_ra_config_t_handler
3044 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3046 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3048 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3050 is_no = mp->is_no == 1;
3051 surpress = mp->surpress == 1;
3052 managed = mp->managed == 1;
3053 other = mp->other == 1;
3054 ll_option = mp->ll_option == 1;
3055 send_unicast = mp->send_unicast == 1;
3056 cease = mp->cease == 1;
3057 default_router = mp->default_router == 1;
3059 VALIDATE_SW_IF_INDEX(mp);
3061 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3062 surpress, managed, other,
3063 ll_option, send_unicast, cease,
3064 default_router, ntohl (mp->lifetime),
3065 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3066 ntohl(mp->max_interval), ntohl( mp->min_interval),
3069 BAD_SW_IF_INDEX_LABEL;
3071 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3075 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3076 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3078 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3080 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3082 VALIDATE_SW_IF_INDEX(mp);
3084 is_no = mp->is_no == 1;
3085 use_default = mp->use_default == 1;
3086 no_advertise = mp->no_advertise == 1;
3087 off_link = mp->off_link == 1;
3088 no_autoconfig = mp->no_autoconfig == 1;
3089 no_onlink = mp->no_onlink == 1;
3091 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3092 (ip6_address_t *)mp->address, mp->address_length,
3093 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3094 no_advertise, off_link, no_autoconfig, no_onlink,
3097 BAD_SW_IF_INDEX_LABEL;
3098 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3102 vl_api_sw_interface_ip6_enable_disable_t_handler
3103 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3105 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3106 vnet_main_t * vnm = vnet_get_main();
3108 clib_error_t * error;
3112 VALIDATE_SW_IF_INDEX(mp);
3114 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3115 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3118 clib_error_report(error);
3119 rv = VNET_API_ERROR_UNSPECIFIED;
3121 rv = vnm->api_errno;
3124 BAD_SW_IF_INDEX_LABEL;
3126 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3130 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3131 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3133 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3135 clib_error_t * error;
3136 vnet_main_t * vnm = vnet_get_main();
3140 VALIDATE_SW_IF_INDEX(mp);
3142 error = set_ip6_link_local_address(vm,
3143 ntohl(mp->sw_if_index),
3144 (ip6_address_t *)mp->address,
3145 mp->address_length);
3147 clib_error_report(error);
3148 rv = VNET_API_ERROR_UNSPECIFIED;
3150 rv = vnm->api_errno;
3153 BAD_SW_IF_INDEX_LABEL;
3155 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3158 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3160 vl_api_set_ip_flow_hash_reply_t *rmp;
3161 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3163 clib_warning ("unimplemented...");
3165 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3168 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3170 vl_api_set_ip_flow_hash_reply_t *rmp;
3173 u32 flow_hash_config = 0;
3175 table_id = ntohl(mp->vrf_id);
3177 #define _(a,b) if (mp->a) flow_hash_config |= b;
3178 foreach_flow_hash_bit;
3181 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3183 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3187 static void vl_api_set_ip_flow_hash_t_handler
3188 (vl_api_set_ip_flow_hash_t *mp)
3190 if (mp->is_ipv6 == 0)
3191 set_ip4_flow_hash (mp);
3193 set_ip6_flow_hash (mp);
3196 static void vl_api_sw_interface_set_unnumbered_t_handler
3197 (vl_api_sw_interface_set_unnumbered_t *mp)
3199 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3201 vnet_sw_interface_t * si;
3202 vnet_main_t *vnm = vnet_get_main();
3203 u32 sw_if_index, unnumbered_sw_if_index;
3205 sw_if_index = ntohl(mp->sw_if_index);
3206 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3209 * The API message field names are backwards from
3210 * the underlying data structure names.
3211 * It's not worth changing them now.
3213 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3214 unnumbered_sw_if_index)) {
3215 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3219 /* Only check the "use loop0" field when setting the binding */
3221 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3222 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3226 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3229 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3230 si->unnumbered_sw_if_index = sw_if_index;
3232 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3233 si->unnumbered_sw_if_index = (u32)~0;
3237 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3240 static void vl_api_create_loopback_t_handler
3241 (vl_api_create_loopback_t *mp)
3243 vl_api_create_loopback_reply_t * rmp;
3247 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3249 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3251 rmp->sw_if_index = ntohl (sw_if_index);
3255 static void vl_api_delete_loopback_t_handler
3256 (vl_api_delete_loopback_t *mp)
3258 vl_api_delete_loopback_reply_t * rmp;
3262 sw_if_index = ntohl (mp->sw_if_index);
3263 rv = vnet_delete_loopback_interface (sw_if_index);
3265 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3268 static void vl_api_control_ping_t_handler
3269 (vl_api_control_ping_t *mp)
3271 vl_api_control_ping_reply_t * rmp;
3274 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3276 rmp->vpe_pid = ntohl (getpid());
3280 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3282 u8 **shmem_vecp = (u8 **)arg;
3285 api_main_t * am = &api_main;
3288 shmem_vec = *shmem_vecp;
3290 offset = vec_len (shmem_vec);
3292 pthread_mutex_lock (&am->vlib_rp->mutex);
3293 oldheap = svm_push_data_heap (am->vlib_rp);
3295 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3297 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3299 svm_pop_heap (oldheap);
3300 pthread_mutex_unlock (&am->vlib_rp->mutex);
3302 *shmem_vecp = shmem_vec;
3306 static void vl_api_cli_request_t_handler
3307 (vl_api_cli_request_t *mp)
3309 vl_api_cli_reply_t *rp;
3310 unix_shared_memory_queue_t *q;
3311 vlib_main_t * vm = vlib_get_main();
3312 api_main_t * am = &api_main;
3313 unformat_input_t input;
3317 q = vl_api_client_index_to_input_queue (mp->client_index);
3321 rp = vl_msg_api_alloc (sizeof (*rp));
3322 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3323 rp->context = mp->context;
3325 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3327 vlib_cli_input (vm, &input, shmem_cli_output,
3330 pthread_mutex_lock (&am->vlib_rp->mutex);
3331 oldheap = svm_push_data_heap (am->vlib_rp);
3333 vec_add1(shmem_vec, 0);
3335 svm_pop_heap (oldheap);
3336 pthread_mutex_unlock (&am->vlib_rp->mutex);
3338 rp->reply_in_shmem = (uword)shmem_vec;
3340 vl_msg_api_send_shmem (q, (u8 *)&rp);
3343 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3346 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3347 vnet_main_t *vnm = vnet_get_main();
3348 clib_error_t * error;
3353 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3355 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3358 clib_error_report(error);
3359 rv = VNET_API_ERROR_UNSPECIFIED;
3361 rv = vnm->api_errno;
3364 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3367 static void vl_api_sr_tunnel_add_del_t_handler
3368 (vl_api_sr_tunnel_add_del_t *mp)
3371 clib_warning ("unimplemented");
3373 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3375 vl_api_sr_tunnel_add_del_reply_t * rmp;
3376 ip6_address_t * segments = 0, * seg;
3377 ip6_address_t * tags = 0, *tag;
3378 ip6_address_t * this_address;
3381 if (mp->n_segments == 0) {
3386 memset (a, 0, sizeof (*a));
3387 a->src_address = (ip6_address_t *)&mp->src_address;
3388 a->dst_address = (ip6_address_t *)&mp->dst_address;
3389 a->dst_mask_width = mp->dst_mask_width;
3390 a->flags_net_byte_order = mp->flags_net_byte_order;
3391 a->is_del = (mp->is_add == 0);
3392 a->rx_table_id = ntohl(mp->outer_vrf_id);
3393 a->tx_table_id = ntohl(mp->inner_vrf_id);
3395 a->name = format(0, "%s", mp->name);
3396 if (!(vec_len(a->name)))
3399 a->policy_name = format(0, "%s", mp->policy_name);
3400 if (!(vec_len(a->policy_name)))
3403 /* Yank segments and tags out of the API message */
3404 this_address = (ip6_address_t *)mp->segs_and_tags;
3405 for (i = 0; i < mp->n_segments; i++) {
3406 vec_add2 (segments, seg, 1);
3407 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3410 for (i = 0; i < mp->n_tags; i++) {
3411 vec_add2 (tags, tag, 1);
3412 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3416 a->segments = segments;
3419 rv = ip6_sr_add_del_tunnel (a);
3423 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3427 static void vl_api_sr_policy_add_del_t_handler
3428 (vl_api_sr_policy_add_del_t *mp)
3431 clib_warning ("unimplemented");
3433 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3435 vl_api_sr_policy_add_del_reply_t * rmp;
3438 memset (a, 0, sizeof (*a));
3439 a->is_del = (mp->is_add == 0);
3441 a->name = format(0, "%s", mp->name);
3442 if (!(vec_len(a->name)))
3444 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3448 if (!(mp->tunnel_names))
3450 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3454 // start deserializing tunnel_names
3455 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3456 u8 * deser_tun_names = mp->tunnel_names;
3457 deser_tun_names += 1; //moving along
3460 int tun_name_len = 0;
3462 for (i=0; i < num_tunnels; i++)
3464 tun_name_len= *deser_tun_names;
3465 deser_tun_names += 1;
3466 vec_resize (tun_name, tun_name_len);
3467 memcpy(tun_name, deser_tun_names, tun_name_len);
3468 vec_add1 (a->tunnel_names, tun_name);
3469 deser_tun_names += tun_name_len;
3473 rv = ip6_sr_add_del_policy (a);
3477 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3481 static void vl_api_sr_multicast_map_add_del_t_handler
3482 (vl_api_sr_multicast_map_add_del_t *mp)
3485 clib_warning ("unimplemented");
3487 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3489 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3491 memset (a, 0, sizeof (*a));
3492 a->is_del = (mp->is_add == 0);
3494 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3495 a->policy_name = format(0, "%s", mp->policy_name);
3497 if (a->multicast_address == 0)
3503 if (!(a->policy_name))
3509 rv = ip6_sr_add_del_multicastmap (a);
3513 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3517 #define foreach_classify_add_del_table_field \
3522 _(match_n_vectors) \
3523 _(next_table_index) \
3526 static void vl_api_classify_add_del_table_t_handler
3527 (vl_api_classify_add_del_table_t * mp)
3529 vl_api_classify_add_del_table_reply_t * rmp;
3530 vnet_classify_main_t * cm = &vnet_classify_main;
3531 vnet_classify_table_t * t;
3535 foreach_classify_add_del_table_field;
3538 #define _(a) a = ntohl(mp->a);
3539 foreach_classify_add_del_table_field;
3542 /* The underlying API fails silently, on purpose, so check here */
3543 if (mp->is_add == 0)
3544 if (pool_is_free_index (cm->tables, table_index)) {
3545 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3549 rv = vnet_classify_add_del_table
3550 (cm, mp->mask, nbuckets, memory_size,
3551 skip_n_vectors, match_n_vectors,
3552 next_table_index, miss_next_index,
3553 &table_index, mp->is_add);
3556 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3558 if (rv == 0 && mp->is_add) {
3559 t = pool_elt_at_index (cm->tables, table_index);
3560 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3561 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3562 rmp->new_table_index = ntohl(table_index);
3564 rmp->skip_n_vectors = ~0;
3565 rmp->match_n_vectors = ~0;
3566 rmp->new_table_index = ~0;
3571 static void vl_api_classify_add_del_session_t_handler
3572 (vl_api_classify_add_del_session_t * mp)
3574 vnet_classify_main_t * cm = &vnet_classify_main;
3575 vl_api_classify_add_del_session_reply_t * rmp;
3577 u32 table_index, hit_next_index, opaque_index;
3580 table_index = ntohl (mp->table_index);
3581 hit_next_index = ntohl (mp->hit_next_index);
3582 opaque_index = ntohl (mp->opaque_index);
3583 advance = ntohl (mp->advance);
3585 rv = vnet_classify_add_del_session
3586 (cm, table_index, mp->match, hit_next_index, opaque_index,
3587 advance, mp->is_add);
3589 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3592 static void vl_api_classify_set_interface_ip_table_t_handler
3593 (vl_api_classify_set_interface_ip_table_t * mp)
3595 vlib_main_t * vm = vlib_get_main();
3596 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3598 u32 table_index, sw_if_index;
3600 table_index = ntohl (mp->table_index);
3601 sw_if_index = ntohl (mp->sw_if_index);
3603 VALIDATE_SW_IF_INDEX(mp);
3606 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3608 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3610 BAD_SW_IF_INDEX_LABEL;
3612 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3615 static void vl_api_classify_set_interface_l2_tables_t_handler
3616 (vl_api_classify_set_interface_l2_tables_t * mp)
3618 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3620 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3623 ip4_table_index = ntohl(mp->ip4_table_index);
3624 ip6_table_index = ntohl(mp->ip6_table_index);
3625 other_table_index = ntohl(mp->other_table_index);
3626 sw_if_index = ntohl(mp->sw_if_index);
3628 VALIDATE_SW_IF_INDEX(mp);
3630 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3631 ip6_table_index, other_table_index);
3634 if (ip4_table_index != ~0 || ip6_table_index != ~0
3635 || other_table_index != ~0)
3640 vnet_l2_classify_enable_disable (sw_if_index, enable);
3643 BAD_SW_IF_INDEX_LABEL;
3645 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3649 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3652 vl_api_l2_fib_clear_table_reply_t * rmp;
3654 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3655 * that is not currently implemented. When that TODO is fixed
3656 * this call should be changed to pass 1 instead of 0.
3658 l2fib_clear_table (0);
3660 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3663 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3668 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3671 vl_api_l2_interface_efp_filter_reply_t * rmp;
3672 vnet_main_t *vnm = vnet_get_main();
3674 // enable/disable the feature
3675 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3676 rv = vnm->api_errno;
3678 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3682 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3685 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3686 vnet_main_t * vnm = vnet_get_main();
3687 vlib_main_t * vm = vlib_get_main();
3690 VALIDATE_SW_IF_INDEX(mp);
3692 vtr_op = ntohl(mp->vtr_op);
3694 /* The L2 code is unsuspicious */
3696 case L2_VTR_DISABLED:
3701 case L2_VTR_TRANSLATE_1_1:
3702 case L2_VTR_TRANSLATE_1_2:
3703 case L2_VTR_TRANSLATE_2_1:
3704 case L2_VTR_TRANSLATE_2_2:
3708 rv = VNET_API_ERROR_INVALID_VALUE;
3709 goto bad_sw_if_index;
3712 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3713 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3716 BAD_SW_IF_INDEX_LABEL;
3718 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3722 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3726 vl_api_create_vhost_user_if_reply_t * rmp;
3727 u32 sw_if_index = (u32)~0;
3729 vnet_main_t * vnm = vnet_get_main();
3730 vlib_main_t * vm = vlib_get_main();
3732 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3733 mp->is_server, &sw_if_index, (u64)~0,
3734 mp->renumber, ntohl(mp->custom_dev_instance),
3735 (mp->use_custom_mac)?mp->mac_address:NULL);
3737 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3739 rmp->sw_if_index = ntohl (sw_if_index);
3745 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3749 vl_api_modify_vhost_user_if_reply_t * rmp;
3750 u32 sw_if_index = ntohl(mp->sw_if_index);
3752 vnet_main_t * vnm = vnet_get_main();
3753 vlib_main_t * vm = vlib_get_main();
3755 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3756 mp->is_server, sw_if_index, (u64)~0,
3757 mp->renumber, ntohl(mp->custom_dev_instance));
3759 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3764 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3768 vpe_api_main_t * vam = &vpe_api_main;
3769 vl_api_delete_vhost_user_if_reply_t * rmp;
3770 u32 sw_if_index = ntohl(mp->sw_if_index);
3772 vnet_main_t * vnm = vnet_get_main();
3773 vlib_main_t * vm = vlib_get_main();
3775 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3777 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3779 unix_shared_memory_queue_t * q =
3780 vl_api_client_index_to_input_queue (mp->client_index);
3784 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3789 static void vl_api_sw_interface_vhost_user_details_t_handler (
3790 vl_api_sw_interface_vhost_user_details_t * mp)
3792 clib_warning ("BUG");
3796 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3797 unix_shared_memory_queue_t *q,
3798 vhost_user_intf_details_t * vui,
3801 vl_api_sw_interface_vhost_user_details_t * mp;
3803 mp = vl_msg_api_alloc (sizeof (*mp));
3804 memset (mp, 0, sizeof (*mp));
3805 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3806 mp->sw_if_index = ntohl(vui->sw_if_index);
3807 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3808 mp->features = clib_net_to_host_u64 (vui->features);
3809 mp->is_server = vui->is_server;
3810 mp->num_regions = ntohl(vui->num_regions);
3811 mp->sock_errno = ntohl(vui->sock_errno);
3812 mp->context = context;
3814 strncpy ((char *) mp->sock_filename,
3815 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3816 strncpy ((char *) mp->interface_name,
3817 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3819 vl_msg_api_send_shmem (q, (u8 *)&mp);
3824 vl_api_sw_interface_vhost_user_dump_t_handler (
3825 vl_api_sw_interface_vhost_user_dump_t *mp)
3829 vpe_api_main_t * am = &vpe_api_main;
3830 vnet_main_t * vnm = vnet_get_main();
3831 vlib_main_t * vm = vlib_get_main();
3832 vhost_user_intf_details_t *ifaces = NULL;
3833 vhost_user_intf_details_t *vuid = NULL;
3834 unix_shared_memory_queue_t * q;
3836 q = vl_api_client_index_to_input_queue (mp->client_index);
3840 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3844 vec_foreach (vuid, ifaces) {
3845 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3851 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3852 unix_shared_memory_queue_t *q,
3857 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3858 u8 * if_name = NULL;
3859 vnet_sw_interface_t * si = NULL;
3861 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3863 if_name = format(if_name, "%U",
3864 format_vnet_sw_interface_name, lm->vnet_main, si);
3866 mp = vl_msg_api_alloc (sizeof (*mp));
3867 memset (mp, 0, sizeof (*mp));
3868 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3869 strncpy((char *)mp->interface_name,
3870 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3871 mp->sw_if_index = ntohl(si->sw_if_index);
3872 mp->local_session_id = s->local_session_id;
3873 mp->remote_session_id = s->remote_session_id;
3874 mp->local_cookie[0] = s->local_cookie[0];
3875 mp->local_cookie[1] = s->local_cookie[1];
3876 mp->remote_cookie = s->remote_cookie;
3877 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3878 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3879 mp->l2_sublayer_present = s->l2_sublayer_present;
3880 mp->context = context;
3882 vl_msg_api_send_shmem (q, (u8 *)&mp);
3885 static void send_ip_address_details (vpe_api_main_t * am,
3886 unix_shared_memory_queue_t * q,
3891 vl_api_ip_address_details_t * mp;
3893 mp = vl_msg_api_alloc (sizeof (*mp));
3894 memset (mp, 0, sizeof (*mp));
3895 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3898 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3900 u32 * tp = (u32 *)mp->ip;
3901 *tp = ntohl(*(u32*)ip);
3903 mp->prefix_length = prefix_length;
3905 vl_msg_api_send_shmem (q, (u8 *)&mp);
3909 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3911 vpe_api_main_t * am = &vpe_api_main;
3912 unix_shared_memory_queue_t * q;
3915 ip6_main_t * im6 = &ip6_main;
3916 ip4_main_t * im4 = &ip4_main;
3917 ip_lookup_main_t * lm6 = &im6->lookup_main;
3918 ip_lookup_main_t * lm4 = &im4->lookup_main;
3919 ip_interface_address_t * ia = 0;
3920 u32 sw_if_index = ~0;
3922 sw_if_index = ntohl(mp->sw_if_index);
3924 q = vl_api_client_index_to_input_queue (mp->client_index);
3930 foreach_ip_interface_address (lm6, ia, sw_if_index,
3931 1 /* honor unnumbered */,
3933 r6 = ip_interface_address_get_address (lm6, ia);
3934 u16 prefix_length = ia->address_length;
3935 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1);
3938 foreach_ip_interface_address (lm4, ia, sw_if_index,
3939 1 /* honor unnumbered */,
3941 r4 = ip_interface_address_get_address (lm4, ia);
3942 u16 prefix_length = ia->address_length;
3943 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0);
3948 static void send_ip_details (vpe_api_main_t * am,
3949 unix_shared_memory_queue_t *q,
3952 vl_api_ip_details_t * mp;
3954 mp = vl_msg_api_alloc (sizeof (*mp));
3955 memset (mp, 0, sizeof (*mp));
3956 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3958 mp->sw_if_index = ntohl(sw_if_index);
3960 vl_msg_api_send_shmem (q, (u8 *)&mp);
3964 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3965 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3967 vpe_api_main_t * am = &vpe_api_main;
3968 l2t_main_t * lm = &l2t_main;
3969 unix_shared_memory_queue_t * q;
3970 l2t_session_t *session;
3972 q = vl_api_client_index_to_input_queue (mp->client_index);
3976 pool_foreach (session, lm->sessions,
3978 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
3983 static void send_sw_interface_tap_details (vpe_api_main_t * am,
3984 unix_shared_memory_queue_t *q,
3985 tapcli_interface_details_t *tap_if)
3987 vl_api_sw_interface_tap_details_t * mp;
3988 mp = vl_msg_api_alloc (sizeof (*mp));
3989 memset (mp, 0, sizeof (*mp));
3990 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
3991 mp->sw_if_index = ntohl(tap_if->sw_if_index);
3992 strncpy((char *)mp->dev_name,
3993 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
3995 vl_msg_api_send_shmem (q, (u8 *)&mp);
3999 vl_api_sw_interface_tap_dump_t_handler (
4000 vl_api_sw_interface_tap_dump_t *mp)
4003 vpe_api_main_t * am = &vpe_api_main;
4004 unix_shared_memory_queue_t * q;
4005 tapcli_interface_details_t *tapifs = NULL;
4006 tapcli_interface_details_t *tap_if = NULL;
4008 q = vl_api_client_index_to_input_queue (mp->client_index);
4012 rv = vnet_tap_dump_ifs(&tapifs);
4016 vec_foreach(tap_if, tapifs) {
4017 send_sw_interface_tap_details(am, q, tap_if);
4024 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4026 vpe_api_main_t * am = &vpe_api_main;
4027 vnet_main_t * vnm = vnet_get_main();
4028 vlib_main_t * vm = vlib_get_main();
4029 vnet_interface_main_t * im = &vnm->interface_main;
4030 unix_shared_memory_queue_t * q;
4031 vnet_sw_interface_t * si, * sorted_sis;
4032 u32 sw_if_index = ~0;
4034 q = vl_api_client_index_to_input_queue (mp->client_index);
4039 /* Gather interfaces. */
4040 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4041 _vec_len (sorted_sis) = 0;
4042 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4044 vec_foreach (si, sorted_sis) {
4045 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4046 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4049 sw_if_index = si->sw_if_index;
4050 send_ip_details(am, q, sw_if_index);
4055 static void vl_api_l2_fib_table_entry_t_handler (
4056 vl_api_l2_fib_table_entry_t * mp)
4058 clib_warning ("BUG");
4061 static void send_l2fib_table_entry (vpe_api_main_t * am,
4062 unix_shared_memory_queue_t *q,
4063 l2fib_entry_key_t * l2fe_key,
4064 l2fib_entry_result_t * l2fe_res,
4067 vl_api_l2_fib_table_entry_t * mp;
4069 mp = vl_msg_api_alloc (sizeof (*mp));
4070 memset (mp, 0, sizeof (*mp));
4071 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4073 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4075 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4076 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4077 mp->static_mac = l2fe_res->fields.static_mac;
4078 mp->filter_mac = l2fe_res->fields.filter;
4079 mp->bvi_mac = l2fe_res->fields.bvi;
4080 mp->context = context;
4082 vl_msg_api_send_shmem (q, (u8 *)&mp);
4086 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4088 vpe_api_main_t * am = &vpe_api_main;
4089 bd_main_t * bdm = &bd_main;
4090 l2fib_entry_key_t *l2fe_key = NULL;
4091 l2fib_entry_result_t *l2fe_res = NULL;
4092 u32 ni, bd_id = ntohl (mp->bd_id);
4094 unix_shared_memory_queue_t * q;
4097 q = vl_api_client_index_to_input_queue (mp->client_index);
4101 /* see l2fib_table_dump: ~0 means "any" */
4105 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4112 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4114 vec_foreach_index (ni, l2fe_key) {
4115 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4116 vec_elt_at_index(l2fe_res, ni), mp->context);
4123 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4125 vl_api_show_version_reply_t *rmp;
4127 char * vpe_api_get_build_directory(void);
4128 char * vpe_api_get_version(void);
4129 char * vpe_api_get_build_date(void);
4131 unix_shared_memory_queue_t * q =
4132 vl_api_client_index_to_input_queue (mp->client_index);
4137 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4139 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4140 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4141 ARRAY_LEN(rmp->build_directory)-1);
4142 strncpy ((char *) rmp->version, vpe_api_get_version(),
4143 ARRAY_LEN(rmp->version)-1);
4144 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4145 ARRAY_LEN(rmp->build_date)-1);
4149 static void vl_api_get_node_index_t_handler
4150 (vl_api_get_node_index_t * mp)
4152 vlib_main_t * vm = vlib_get_main();
4153 vl_api_get_node_index_reply_t * rmp;
4156 u32 node_index = ~0;
4158 n = vlib_get_node_by_name (vm, mp->node_name);
4161 rv = VNET_API_ERROR_NO_SUCH_NODE;
4163 node_index = n->index;
4165 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4167 rmp->node_index = ntohl(node_index);
4171 static void vl_api_add_node_next_t_handler
4172 (vl_api_add_node_next_t * mp)
4174 vlib_main_t * vm = vlib_get_main();
4175 vl_api_add_node_next_reply_t * rmp;
4176 vlib_node_t * n, * next;
4178 u32 next_index = ~0;
4180 n = vlib_get_node_by_name (vm, mp->node_name);
4183 rv = VNET_API_ERROR_NO_SUCH_NODE;
4187 next = vlib_get_node_by_name (vm, mp->next_name);
4190 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4192 next_index = vlib_node_add_next (vm, n->index, next->index);
4195 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4197 rmp->next_index = ntohl(next_index);
4201 static void vl_api_l2tpv3_create_tunnel_t_handler
4202 (vl_api_l2tpv3_create_tunnel_t *mp)
4204 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4205 l2t_main_t *lm = &l2t_main;
4206 u32 sw_if_index = (u32)~0;
4209 if (mp->is_ipv6 != 1) {
4210 rv = VNET_API_ERROR_UNIMPLEMENTED;
4214 rv = create_l2tpv3_ipv6_tunnel (lm,
4215 (ip6_address_t *) mp->client_address,
4216 (ip6_address_t *) mp->our_address,
4217 ntohl(mp->local_session_id),
4218 ntohl(mp->remote_session_id),
4219 clib_net_to_host_u64(mp->local_cookie),
4220 clib_net_to_host_u64(mp->remote_cookie),
4221 mp->l2_sublayer_present,
4225 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4227 rmp->sw_if_index = ntohl (sw_if_index);
4231 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4232 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4234 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4235 l2t_main_t *lm = &l2t_main;
4238 VALIDATE_SW_IF_INDEX(mp);
4240 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4241 clib_net_to_host_u64(mp->new_local_cookie),
4242 clib_net_to_host_u64(mp->new_remote_cookie));
4244 BAD_SW_IF_INDEX_LABEL;
4246 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4249 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4250 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4253 vnet_main_t * vnm = vnet_get_main();
4254 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4256 VALIDATE_SW_IF_INDEX(mp);
4258 rv = l2tpv3_interface_enable_disable
4259 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4261 BAD_SW_IF_INDEX_LABEL;
4263 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4266 static void vl_api_l2tpv3_set_lookup_key_t_handler
4267 (vl_api_l2tpv3_set_lookup_key_t * mp)
4270 l2t_main_t *lm = &l2t_main;
4271 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4273 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4274 rv = VNET_API_ERROR_INVALID_VALUE;
4278 lm->lookup_type = mp->key;
4281 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4284 static void vl_api_vxlan_add_del_tunnel_t_handler
4285 (vl_api_vxlan_add_del_tunnel_t * mp)
4287 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4289 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4290 u32 encap_fib_index;
4292 ip4_main_t * im = &ip4_main;
4293 u32 sw_if_index = ~0;
4295 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4297 rv = VNET_API_ERROR_NO_SUCH_FIB;
4300 encap_fib_index = p[0];
4302 /* Check src & dst are different */
4303 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4304 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4305 rv = VNET_API_ERROR_SAME_SRC_DST;
4308 memset (a, 0, sizeof (*a));
4310 a->is_add = mp->is_add;
4311 a->is_ip6 = mp->is_ipv6;
4313 /* ip addresses sent in network byte order */
4315 memcpy(&(a->src.ip6), mp->src_address, 16);
4316 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4318 memcpy(&(a->src.ip4), mp->src_address, 4);
4319 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4322 a->encap_fib_index = encap_fib_index;
4323 a->decap_next_index = ntohl(mp->decap_next_index);
4324 a->vni = ntohl(mp->vni);
4325 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4328 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4330 rmp->sw_if_index = ntohl (sw_if_index);
4334 static void send_vxlan_tunnel_details
4335 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q)
4337 vl_api_vxlan_tunnel_details_t * rmp;
4338 ip4_main_t * im4 = &ip4_main;
4339 ip6_main_t * im6 = &ip6_main;
4340 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4342 rmp = vl_msg_api_alloc (sizeof (*rmp));
4343 memset (rmp, 0, sizeof (*rmp));
4344 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4346 memcpy(rmp->src_address, &(t->src.ip6), 16);
4347 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4348 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4350 memcpy(rmp->src_address, &(t->src.ip4), 4);
4351 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4352 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4354 rmp->vni = htonl(t->vni);
4355 rmp->decap_next_index = htonl(t->decap_next_index);
4356 rmp->sw_if_index = htonl(t->sw_if_index);
4357 rmp->is_ipv6 = is_ipv6;
4359 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4362 static void vl_api_vxlan_tunnel_dump_t_handler
4363 (vl_api_vxlan_tunnel_dump_t * mp)
4365 unix_shared_memory_queue_t * q;
4366 vxlan_main_t * vxm = &vxlan_main;
4370 q = vl_api_client_index_to_input_queue (mp->client_index);
4375 sw_if_index = ntohl(mp->sw_if_index);
4377 if (~0 == sw_if_index) {
4378 pool_foreach (t, vxm->tunnels,
4380 send_vxlan_tunnel_details(t, q);
4383 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4384 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4387 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4388 send_vxlan_tunnel_details(t, q);
4392 static void vl_api_gre_add_del_tunnel_t_handler
4393 (vl_api_gre_add_del_tunnel_t * mp)
4395 vl_api_gre_add_del_tunnel_reply_t * rmp;
4397 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4400 ip4_main_t * im = &ip4_main;
4401 u32 sw_if_index = ~0;
4403 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4405 rv = VNET_API_ERROR_NO_SUCH_FIB;
4408 outer_table_id = p[0];
4410 /* Check src & dst are different */
4411 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4412 rv = VNET_API_ERROR_SAME_SRC_DST;
4416 memset (a, 0, sizeof (*a));
4418 a->is_add = mp->is_add;
4420 /* ip addresses sent in network byte order */
4421 a->src.as_u32 = mp->src_address;
4422 a->dst.as_u32 = mp->dst_address;
4424 a->outer_table_id = outer_table_id;
4425 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4428 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4430 rmp->sw_if_index = ntohl (sw_if_index);
4434 static void send_gre_tunnel_details
4435 (gre_tunnel_t * t, unix_shared_memory_queue_t * q)
4437 vl_api_gre_tunnel_details_t * rmp;
4438 ip4_main_t * im = &ip4_main;
4440 rmp = vl_msg_api_alloc (sizeof (*rmp));
4441 memset (rmp, 0, sizeof (*rmp));
4442 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4443 rmp->src_address = t->tunnel_src.data_u32;
4444 rmp->dst_address = t->tunnel_dst.data_u32;
4445 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4446 rmp->sw_if_index = htonl(t->sw_if_index);
4448 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4451 static void vl_api_gre_tunnel_dump_t_handler
4452 (vl_api_gre_tunnel_dump_t * mp)
4454 unix_shared_memory_queue_t * q;
4455 gre_main_t * gm = &gre_main;
4459 q = vl_api_client_index_to_input_queue (mp->client_index);
4464 sw_if_index = ntohl(mp->sw_if_index);
4466 if (~0 == sw_if_index) {
4467 pool_foreach (t, gm->tunnels,
4469 send_gre_tunnel_details(t, q);
4472 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4473 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4476 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4477 send_gre_tunnel_details(t, q);
4482 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4484 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4486 vl_api_l2_patch_add_del_reply_t * rmp;
4487 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4491 VALIDATE_RX_SW_IF_INDEX(mp);
4492 VALIDATE_TX_SW_IF_INDEX(mp);
4494 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4495 ntohl(mp->tx_sw_if_index),
4496 (int)(mp->is_add != 0));
4498 BAD_RX_SW_IF_INDEX_LABEL;
4499 BAD_TX_SW_IF_INDEX_LABEL;
4501 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4505 vl_api_nsh_gre_add_del_tunnel_t_handler
4506 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4508 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4510 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4511 u32 encap_fib_index, decap_fib_index;
4512 u32 decap_next_index;
4514 ip4_main_t * im = &ip4_main;
4516 u32 sw_if_index = ~0;
4519 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4521 rv = VNET_API_ERROR_NO_SUCH_FIB;
4524 encap_fib_index = p[0];
4526 decap_next_index = ntohl(mp->decap_next_index);
4528 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4529 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4530 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4532 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4535 decap_fib_index = p[0];
4537 decap_fib_index = ntohl(mp->decap_vrf_id);
4540 memset (a, 0, sizeof (*a));
4542 a->is_add = mp->is_add;
4543 /* ip addresses sent in network byte order */
4544 a->src.as_u32 = ntohl(mp->src);
4545 a->dst.as_u32 = ntohl(mp->dst);
4546 a->encap_fib_index = encap_fib_index;
4547 a->decap_fib_index = decap_fib_index;
4548 a->decap_next_index = decap_next_index;
4549 a->ver_o_c = mp->ver_o_c;
4550 a->length = mp->length;
4551 a->md_type = mp->md_type;
4552 a->next_protocol = mp->next_protocol;
4553 a->spi_si = ntohl(mp->spi_si);
4554 a->c1 = ntohl(mp->c1);
4555 a->c2 = ntohl(mp->c2);
4556 a->c3 = ntohl(mp->c3);
4557 a->c4 = ntohl(mp->c4);
4559 for (i = 0; i < mp->tlv_len_in_words; i++)
4560 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4564 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4567 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4569 rmp->sw_if_index = ntohl (sw_if_index);
4574 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4575 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4577 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4579 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4580 u32 encap_fib_index, decap_fib_index;
4581 u32 decap_next_index;
4583 ip4_main_t * im = &ip4_main;
4585 u32 sw_if_index = ~0;
4588 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4590 rv = VNET_API_ERROR_NO_SUCH_FIB;
4593 encap_fib_index = p[0];
4595 decap_next_index = ntohl(mp->decap_next_index);
4597 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4598 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4599 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4601 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4604 decap_fib_index = p[0];
4606 decap_fib_index = ntohl(mp->decap_vrf_id);
4609 memset (a, 0, sizeof (*a));
4611 a->is_add = mp->is_add;
4612 /* ip addresses sent in network byte order */
4613 a->src.as_u32 = ntohl(mp->src);
4614 a->dst.as_u32 = ntohl(mp->dst);
4615 a->encap_fib_index = encap_fib_index;
4616 a->decap_fib_index = decap_fib_index;
4617 a->decap_next_index = decap_next_index;
4618 a->vni = ntohl(mp->vni);
4619 a->ver_o_c = mp->ver_o_c;
4620 a->length = mp->length;
4621 a->md_type = mp->md_type;
4622 a->next_protocol = mp->next_protocol;
4623 a->spi_si = ntohl(mp->spi_si);
4624 a->c1 = ntohl(mp->c1);
4625 a->c2 = ntohl(mp->c2);
4626 a->c3 = ntohl(mp->c3);
4627 a->c4 = ntohl(mp->c4);
4629 for (i = 0; i < mp->tlv_len_in_words; i++)
4630 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4634 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4637 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4639 rmp->sw_if_index = ntohl (sw_if_index);
4644 vl_api_lisp_gpe_add_del_tunnel_t_handler
4645 (vl_api_lisp_gpe_add_del_tunnel_t * mp)
4647 vl_api_lisp_gpe_add_del_tunnel_reply_t * rmp;
4649 vnet_lisp_gpe_add_del_tunnel_args_t _a, *a = &_a;
4650 u32 encap_fib_index, decap_fib_index;
4651 u32 decap_next_index;
4653 ip4_main_t * im = &ip4_main;
4654 u32 sw_if_index = ~0;
4656 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4658 rv = VNET_API_ERROR_NO_SUCH_FIB;
4661 encap_fib_index = p[0];
4663 decap_next_index = ntohl(mp->decap_next_index);
4665 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4666 if (decap_next_index == NSH_INPUT_NEXT_IP4_INPUT) {
4667 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4669 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4672 decap_fib_index = p[0];
4674 decap_fib_index = ntohl(mp->decap_vrf_id);
4677 memset (a, 0, sizeof (*a));
4679 a->is_add = mp->is_add;
4680 /* ip addresses sent in network byte order */
4681 a->src.as_u32 = mp->src;
4682 a->dst.as_u32 = mp->dst;
4683 a->encap_fib_index = encap_fib_index;
4684 a->decap_fib_index = decap_fib_index;
4685 a->decap_next_index = decap_next_index;
4686 a->flags = mp->flags;
4687 a->ver_res = mp->ver_res;
4689 a->next_protocol = mp->next_protocol;
4690 a->vni = clib_net_to_host_u32 (mp->iid);
4692 rv = vnet_lisp_gpe_add_del_tunnel (a, &sw_if_index);
4695 REPLY_MACRO2(VL_API_LISP_GPE_ADD_DEL_TUNNEL_REPLY,
4697 rmp->sw_if_index = ntohl (sw_if_index);
4702 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4704 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4706 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4708 u8 *locator_name = NULL;
4710 memset(a, 0, sizeof(a[0]));
4712 locator_name = format(0, "%s", mp->locator_set_name);
4714 a->name = locator_name;
4716 a->is_add = mp->is_add;
4719 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4721 vec_free(locator_name);
4723 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4727 vl_api_lisp_add_del_locator_t_handler(
4728 vl_api_lisp_add_del_locator_t *mp)
4730 vl_api_lisp_add_del_locator_reply_t *rmp;
4732 locator_t locator, *locators = NULL;
4733 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4735 u8 *locator_name = NULL;
4737 memset(&locator, 0, sizeof(locator));
4738 memset(a, 0, sizeof(a[0]));
4740 locator.sw_if_index = ntohl(mp->sw_if_index);
4741 locator.priority = mp->priority;
4742 locator.weight = mp->weight;
4744 vec_add1(locators, locator);
4746 locator_name = format(0, "%s", mp->locator_set_name);
4748 a->name = locator_name;
4749 a->locators = locators;
4750 a->is_add = mp->is_add;
4753 rv = vnet_lisp_add_del_locator(a, &ls_index);
4756 vec_free(locator_name);
4758 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4762 vl_api_lisp_add_del_local_eid_t_handler(
4763 vl_api_lisp_add_del_local_eid_t *mp)
4765 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4766 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4768 ip_prefix_t *prefp = NULL;
4769 ip_address_t *ip_eid = NULL;
4772 u32 locator_set_index = ~0, map_index = ~0;
4773 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4776 prefp = &gid_address_ippref(&eid);
4777 ip_eid = &ip_prefix_addr(prefp);
4778 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4781 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4782 sizeof(ip_addr_v6(ip_eid)));
4783 ip_addr_version(ip_eid) = IP6;
4785 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4786 sizeof(ip_addr_v4(ip_eid)));
4787 ip_addr_version(ip_eid) = IP4;
4789 ip_prefix_len(prefp) = mp->prefix_len;
4791 name = format(0, "%s", mp->locator_set_name);
4792 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4794 rv = VNET_API_ERROR_INVALID_VALUE;
4797 locator_set_index = p[0];
4799 /* XXX treat batch configuration */
4800 a->is_add = mp->is_add;
4802 a->locator_set_index = locator_set_index;
4805 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4810 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4814 lisp_gpe_add_del_fwd_entry_set_address(
4815 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4816 ip_address_t *slocator,
4817 ip_address_t *dlocator,
4820 ip_address_t *ip_eid = NULL;
4821 ip_prefix_t *prefp = NULL;
4823 prefp = &gid_address_ippref(eid);
4824 ip_eid = &ip_prefix_addr(prefp);
4826 if (mp->eid_is_ipv6) {
4827 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4828 sizeof(ip_addr_v6(ip_eid)));
4829 ip_addr_version(ip_eid) = IP6;
4831 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4832 sizeof(ip_addr_v4(ip_eid)));
4833 ip_addr_version(ip_eid) = IP4;
4835 ip_prefix_len(prefp) = mp->eid_prefix_len;
4837 if (mp->address_is_ipv6) {
4838 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4839 sizeof(ip_addr_v6(slocator)));
4840 ip_addr_version(slocator) = IP6;
4841 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4842 sizeof(ip_addr_v6(dlocator)));
4843 ip_addr_version(dlocator) = IP6;
4845 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4846 sizeof(ip_addr_v4(slocator)));
4847 ip_addr_version(slocator) = IP4;
4848 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4849 sizeof(ip_addr_v4(dlocator)));
4850 ip_addr_version(dlocator) = IP4;
4855 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4856 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4858 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4860 ip_address_t slocator, dlocator;
4861 ip_prefix_t * prefp = NULL;
4863 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4865 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4867 memset (&a, 0, sizeof(a));
4869 a.is_add = mp->is_add;
4871 a.slocator = slocator;
4872 a.dlocator = dlocator;
4873 prefp = &gid_address_ippref(&a.deid);
4874 a.decap_next_index = (ip_prefix_version(prefp) == IP4) ?
4875 LISP_GPE_INPUT_NEXT_IP4_INPUT : LISP_GPE_INPUT_NEXT_IP6_INPUT;
4876 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4878 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4882 vl_api_lisp_add_del_map_resolver_t_handler(
4883 vl_api_lisp_add_del_map_resolver_t *mp)
4885 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4887 ip_address_t *ip_addr = NULL;
4888 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4890 a->is_add = mp->is_add;
4891 ip_addr = &a->address;
4894 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4895 sizeof(ip_addr_v6(ip_addr)));
4896 ip_addr_version(ip_addr) = IP6;
4898 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4899 sizeof(ip_addr_v4(ip_addr)));
4900 ip_addr_version(ip_addr) = IP4;
4903 rv = vnet_lisp_add_del_map_resolver (a);
4905 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4909 vl_api_lisp_gpe_enable_disable_t_handler(
4910 vl_api_lisp_gpe_enable_disable_t *mp)
4912 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4914 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4916 a->is_en = mp->is_en;
4917 vnet_lisp_gpe_enable_disable (a);
4919 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4923 vl_api_lisp_gpe_add_del_iface_t_handler(
4924 vl_api_lisp_gpe_add_del_iface_t *mp)
4926 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4928 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4930 a->is_add = mp->is_add;
4931 a->table_id = mp->table_id;
4933 vnet_lisp_gpe_add_del_iface (a, 0);
4935 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4939 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4940 locator_set_t *lsit,
4941 unix_shared_memory_queue_t *q)
4943 vl_api_lisp_locator_set_details_t *rmp;
4944 locator_t *loc = NULL;
4947 vec_foreach (locit, lsit->locator_indices) {
4948 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4949 rmp = vl_msg_api_alloc (sizeof (*rmp));
4950 memset (rmp, 0, sizeof (*rmp));
4951 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4952 strncpy((char *) rmp->locator_set_name,
4953 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4954 rmp->sw_if_index = htonl(loc->sw_if_index);
4955 rmp->priority = loc->priority;
4956 rmp->weight = loc->weight;
4958 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4963 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4965 unix_shared_memory_queue_t * q = NULL;
4966 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4967 locator_set_t * lsit = NULL;
4969 q = vl_api_client_index_to_input_queue (mp->client_index);
4974 pool_foreach (lsit, lcm->locator_set_pool,
4976 send_lisp_locator_set_details(lcm, lsit, q);
4981 send_lisp_local_eid_table_details (mapping_t *mapit,
4982 unix_shared_memory_queue_t *q)
4984 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4985 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4986 locator_set_t *ls = NULL;
4987 gid_address_t *gid = NULL;
4988 ip_prefix_t *ip_prefix = NULL;
4991 ls = pool_elt_at_index (lcm->locator_set_pool,
4992 mapit->locator_set_index);
4995 type = gid_address_type(gid);
4997 if (type != GID_ADDR_IP_PREFIX) {
5001 ip_prefix = &gid_address_ippref(gid);
5003 rmp = vl_msg_api_alloc (sizeof (*rmp));
5004 memset (rmp, 0, sizeof (*rmp));
5005 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5006 strncpy((char *) rmp->locator_set_name,
5007 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5009 switch (ip_prefix_version(ip_prefix)) {
5011 rmp->eid_is_ipv6 = 0;
5012 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
5013 sizeof(ip_prefix_v4(ip_prefix)));
5017 rmp->eid_is_ipv6 = 1;
5018 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
5019 sizeof(ip_prefix_v6(ip_prefix)));
5025 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5027 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5031 vl_api_lisp_local_eid_table_dump_t_handler (
5032 vl_api_lisp_local_eid_table_dump_t *mp)
5034 unix_shared_memory_queue_t * q = NULL;
5035 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5036 mapping_t * mapit = NULL;
5038 q = vl_api_client_index_to_input_queue (mp->client_index);
5043 pool_foreach (mapit, lcm->mapping_pool,
5045 send_lisp_local_eid_table_details(mapit, q);
5050 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5051 unix_shared_memory_queue_t *q)
5053 vl_api_lisp_gpe_tunnel_details_t *rmp;
5054 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5056 rmp = vl_msg_api_alloc (sizeof (*rmp));
5057 memset (rmp, 0, sizeof (*rmp));
5058 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5060 rmp->tunnels = tunnel - lgm->tunnels;
5062 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5063 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5064 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5066 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5067 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5068 rmp->dcap_next = htonl(tunnel->decap_next_index);
5069 rmp->lisp_ver = tunnel->ver_res;
5070 rmp->next_protocol = tunnel->next_protocol;
5071 rmp->flags = tunnel->flags;
5072 rmp->ver_res = tunnel->ver_res;
5073 rmp->res = tunnel->res;
5074 rmp->iid = htonl(tunnel->vni);
5076 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5080 vl_api_lisp_gpe_tunnel_dump_t_handler (
5081 vl_api_lisp_local_eid_table_dump_t *mp)
5083 unix_shared_memory_queue_t * q = NULL;
5084 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5085 lisp_gpe_tunnel_t * tunnel = NULL;
5087 if (pool_elts(lgm->tunnels) == 0) {
5091 q = vl_api_client_index_to_input_queue (mp->client_index);
5096 pool_foreach(tunnel, lgm->tunnels,
5098 send_lisp_gpe_tunnel_details(tunnel, q);
5103 send_lisp_map_resolver_details (ip_address_t *ip,
5104 unix_shared_memory_queue_t *q)
5106 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5108 rmp = vl_msg_api_alloc (sizeof (*rmp));
5109 memset (rmp, 0, sizeof (*rmp));
5110 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5112 switch (ip_addr_version(ip)) {
5115 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5120 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5127 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5131 vl_api_lisp_map_resolver_dump_t_handler (
5132 vl_api_lisp_local_eid_table_dump_t *mp)
5134 unix_shared_memory_queue_t * q = NULL;
5135 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5136 ip_address_t *ip = NULL;
5138 q = vl_api_client_index_to_input_queue (mp->client_index);
5143 vec_foreach(ip, lcm->map_resolvers) {
5144 send_lisp_map_resolver_details(ip, q);
5150 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5152 vl_api_interface_name_renumber_reply_t * rmp;
5155 VALIDATE_SW_IF_INDEX(mp);
5157 rv = vnet_interface_name_renumber
5158 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5160 BAD_SW_IF_INDEX_LABEL;
5162 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5165 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5166 u32 sw_if_index, u32 address)
5168 vpe_api_main_t * am = &vpe_api_main;
5169 vlib_main_t * vm = am->vlib_main;
5170 vl_api_ip4_arp_event_t * event;
5171 static f64 arp_event_last_time;
5172 f64 now = vlib_time_now (vm);
5174 if (pool_is_free_index (am->arp_events, pool_index))
5177 event = pool_elt_at_index (am->arp_events, pool_index);
5178 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5179 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5180 } else { /* same mac */
5181 if ((sw_if_index == event->sw_if_index) &&
5183 /* for BD case, also check IP address with 10 sec timeout */
5184 ((address == event->address) &&
5185 ((now - arp_event_last_time) < 10.0))))
5189 arp_event_last_time = now;
5190 event->sw_if_index = sw_if_index;
5191 if (address) event->address = address;
5195 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5197 vpe_api_main_t * am = &vpe_api_main;
5199 if (pool_is_free_index (am->arp_events, pool_index))
5202 pool_put_index (am->arp_events, pool_index);
5207 vl_api_want_ip4_arp_events_t_handler
5208 (vl_api_want_ip4_arp_events_t * mp)
5210 vpe_api_main_t * am = &vpe_api_main;
5211 vnet_main_t * vnm = vnet_get_main();
5212 vl_api_want_ip4_arp_events_reply_t *rmp;
5213 vl_api_ip4_arp_event_t * event;
5216 if (mp->enable_disable) {
5217 pool_get (am->arp_events, event);
5218 memset (event, 0, sizeof (*event));
5220 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5221 event->client_index = mp->client_index;
5222 event->context = mp->context;
5223 event->address = mp->address;
5224 event->pid = mp->pid;
5226 rv = vnet_add_del_ip4_arp_change_event
5227 (vnm, arp_change_data_callback,
5229 &mp->address /* addr, in net byte order */,
5230 vpe_resolver_process_node.index,
5231 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5233 rv = vnet_add_del_ip4_arp_change_event
5234 (vnm, arp_change_delete_callback,
5236 &mp->address /* addr, in net byte order */,
5237 vpe_resolver_process_node.index,
5238 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5240 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5243 static void vl_api_input_acl_set_interface_t_handler
5244 (vl_api_input_acl_set_interface_t * mp)
5246 vlib_main_t *vm = vlib_get_main();
5247 vl_api_input_acl_set_interface_reply_t * rmp;
5249 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5251 ip4_table_index = ntohl(mp->ip4_table_index);
5252 ip6_table_index = ntohl(mp->ip6_table_index);
5253 l2_table_index = ntohl(mp->l2_table_index);
5254 sw_if_index = ntohl(mp->sw_if_index);
5256 VALIDATE_SW_IF_INDEX(mp);
5258 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5259 ip6_table_index, l2_table_index,
5262 BAD_SW_IF_INDEX_LABEL;
5264 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5267 static void vl_api_ipsec_spd_add_del_t_handler
5268 (vl_api_ipsec_spd_add_del_t * mp)
5271 clib_warning ("unimplemented");
5274 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5275 vl_api_ipsec_spd_add_del_reply_t * rmp;
5279 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5281 rv = VNET_API_ERROR_UNIMPLEMENTED;
5284 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5288 static void vl_api_ipsec_interface_add_del_spd_t_handler
5289 (vl_api_ipsec_interface_add_del_spd_t * mp)
5291 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5292 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5294 u32 sw_if_index __attribute__((unused));
5295 u32 spd_id __attribute__((unused));
5297 sw_if_index = ntohl(mp->sw_if_index);
5298 spd_id = ntohl(mp->spd_id);
5300 VALIDATE_SW_IF_INDEX(mp);
5303 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5305 rv = VNET_API_ERROR_UNIMPLEMENTED;
5308 BAD_SW_IF_INDEX_LABEL;
5310 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5313 static void vl_api_ipsec_spd_add_del_entry_t_handler
5314 (vl_api_ipsec_spd_add_del_entry_t * mp)
5316 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5317 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5323 memset(&p, 0, sizeof(p));
5325 p.id = ntohl(mp->spd_id);
5326 p.priority = ntohl(mp->priority);
5327 p.is_outbound = mp->is_outbound;
5328 p.is_ipv6 = mp->is_ipv6;
5330 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5331 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5332 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5333 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5335 p.protocol = mp->protocol;
5336 p.rport.start = ntohs(mp->remote_port_start);
5337 p.rport.stop = ntohs(mp->remote_port_stop);
5338 p.lport.start = ntohs(mp->local_port_start);
5339 p.lport.stop = ntohs(mp->local_port_stop);
5340 /* policy action resolve unsupported */
5341 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5342 clib_warning("unsupported action: 'resolve'");
5343 rv = VNET_API_ERROR_UNIMPLEMENTED;
5346 p.policy = mp->policy;
5347 p.sa_id = ntohl(mp->sa_id);
5349 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5353 if (mp->is_ip_any) {
5355 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5358 rv = VNET_API_ERROR_UNIMPLEMENTED;
5363 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5366 static void vl_api_ipsec_sad_add_del_entry_t_handler
5367 (vl_api_ipsec_sad_add_del_entry_t * mp)
5369 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5370 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5375 memset(&sa, 0, sizeof(sa));
5377 sa.id = ntohl(mp->sad_id);
5378 sa.spi = ntohl(mp->spi);
5379 /* security protocol AH unsupported */
5380 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5381 clib_warning("unsupported security protocol 'AH'");
5382 rv = VNET_API_ERROR_UNIMPLEMENTED;
5385 sa.protocol = mp->protocol;
5386 /* check for unsupported crypto-alg */
5387 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5388 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5389 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5390 mp->crypto_algorithm);
5391 rv = VNET_API_ERROR_UNIMPLEMENTED;
5394 sa.crypto_alg = mp->crypto_algorithm;
5395 sa.crypto_key_len = mp->crypto_key_length;
5396 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5397 /* check for unsupported integ-alg */
5398 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5399 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5400 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5401 mp->integrity_algorithm);
5402 rv = VNET_API_ERROR_UNIMPLEMENTED;
5405 sa.integ_alg = mp->integrity_algorithm;
5406 sa.integ_key_len = mp->integrity_key_length;
5407 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5408 sa.use_esn = mp->use_extended_sequence_number;
5409 sa.is_tunnel = mp->is_tunnel;
5410 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5411 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5412 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5414 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5416 rv = VNET_API_ERROR_UNIMPLEMENTED;
5421 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5425 vl_api_ikev2_profile_add_del_t_handler
5426 (vl_api_ikev2_profile_add_del_t * mp)
5428 vl_api_ikev2_profile_add_del_reply_t * rmp;
5432 vlib_main_t * vm = vlib_get_main();
5433 clib_error_t * error;
5434 u8 * tmp = format(0, "%s", mp->name);
5435 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5438 rv = VNET_API_ERROR_UNSPECIFIED;
5440 rv = VNET_API_ERROR_UNIMPLEMENTED;
5443 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5447 vl_api_ikev2_profile_set_auth_t_handler
5448 (vl_api_ikev2_profile_set_auth_t * mp)
5450 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5454 vlib_main_t * vm = vlib_get_main();
5455 clib_error_t * error;
5456 u8 * tmp = format(0, "%s", mp->name);
5457 u8 * data = vec_new (u8, mp->data_len);
5458 clib_memcpy(data, mp->data, mp->data_len);
5459 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5463 rv = VNET_API_ERROR_UNSPECIFIED;
5465 rv = VNET_API_ERROR_UNIMPLEMENTED;
5468 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5472 vl_api_ikev2_profile_set_id_t_handler
5473 (vl_api_ikev2_profile_set_id_t * mp)
5475 vl_api_ikev2_profile_add_del_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_id(vm, tmp, mp->id_type, data, mp->is_local);
5488 rv = VNET_API_ERROR_UNSPECIFIED;
5490 rv = VNET_API_ERROR_UNIMPLEMENTED;
5493 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5497 vl_api_ikev2_profile_set_ts_t_handler
5498 (vl_api_ikev2_profile_set_ts_t * mp)
5500 vl_api_ikev2_profile_set_ts_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 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5508 mp->end_port, (ip4_address_t) mp->start_addr,
5509 (ip4_address_t) mp->end_addr, mp->is_local);
5512 rv = VNET_API_ERROR_UNSPECIFIED;
5514 rv = VNET_API_ERROR_UNIMPLEMENTED;
5517 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5521 vl_api_ikev2_set_local_key_t_handler
5522 (vl_api_ikev2_set_local_key_t * mp)
5524 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5528 vlib_main_t * vm = vlib_get_main();
5529 clib_error_t * error;
5531 error = ikev2_set_local_key(vm, mp->key_file);
5533 rv = VNET_API_ERROR_UNSPECIFIED;
5535 rv = VNET_API_ERROR_UNIMPLEMENTED;
5538 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5542 vl_api_map_add_domain_t_handler
5543 (vl_api_map_add_domain_t * mp)
5545 vl_api_map_add_domain_reply_t * rmp;
5548 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5549 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5550 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5551 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5552 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5554 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5556 rmp->index = ntohl(index);
5561 vl_api_map_del_domain_t_handler
5562 (vl_api_map_del_domain_t * mp)
5564 vl_api_map_del_domain_reply_t * rmp;
5567 rv = map_delete_domain(ntohl(mp->index));
5569 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5573 vl_api_map_add_del_rule_t_handler
5574 (vl_api_map_add_del_rule_t * mp)
5576 vl_api_map_del_domain_reply_t * rmp;
5579 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5581 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5585 vl_api_map_domain_dump_t_handler
5586 (vl_api_map_domain_dump_t * mp)
5588 vl_api_map_domain_details_t * rmp;
5589 map_main_t *mm = &map_main;
5591 unix_shared_memory_queue_t * q;
5593 if (pool_elts (mm->domains) == 0)
5596 q = vl_api_client_index_to_input_queue (mp->client_index);
5601 pool_foreach(d, mm->domains, ({
5602 /* Make sure every field is initiated (or don't skip the memset()) */
5603 rmp = vl_msg_api_alloc (sizeof (*rmp));
5604 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5605 rmp->domain_index = htonl(d - mm->domains);
5606 rmp->ea_bits_len = d->ea_bits_len;
5607 rmp->psid_offset = d->psid_offset;
5608 rmp->psid_length = d->psid_length;
5609 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5610 rmp->ip4_prefix_len = d->ip4_prefix_len;
5611 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5612 rmp->ip6_prefix_len = d->ip6_prefix_len;
5613 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5614 rmp->ip6_src_len = d->ip6_src_len;
5615 rmp->mtu = htons(d->mtu);
5616 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5617 rmp->context = mp->context;
5619 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5624 vl_api_map_rule_dump_t_handler
5625 (vl_api_map_rule_dump_t * mp)
5627 unix_shared_memory_queue_t * q;
5630 vl_api_map_rule_details_t * rmp;
5631 map_main_t *mm = &map_main;
5632 u32 domain_index = ntohl(mp->domain_index);
5635 if (pool_elts (mm->domains) == 0)
5638 d = pool_elt_at_index(mm->domains, domain_index);
5639 if (!d || !d->rules) {
5643 q = vl_api_client_index_to_input_queue (mp->client_index);
5648 for (i = 0; i < (0x1 << d->psid_length); i++) {
5650 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5653 rmp = vl_msg_api_alloc(sizeof(*rmp));
5654 memset(rmp, 0, sizeof(*rmp));
5655 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5656 rmp->psid = htons(i);
5657 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5658 rmp->context = mp->context;
5659 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5664 vl_api_map_summary_stats_t_handler (
5665 vl_api_map_summary_stats_t *mp)
5667 vl_api_map_summary_stats_reply_t *rmp;
5668 vlib_combined_counter_main_t *cm;
5671 u64 total_pkts[VLIB_N_RX_TX];
5672 u64 total_bytes[VLIB_N_RX_TX];
5673 map_main_t *mm = &map_main;
5674 unix_shared_memory_queue_t *q =
5675 vl_api_client_index_to_input_queue(mp->client_index);
5680 rmp = vl_msg_api_alloc (sizeof (*rmp));
5681 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5682 rmp->context = mp->context;
5685 memset (total_pkts, 0, sizeof (total_pkts));
5686 memset (total_bytes, 0, sizeof (total_bytes));
5688 map_domain_counter_lock (mm);
5689 vec_foreach(cm, mm->domain_counters) {
5690 which = cm - mm->domain_counters;
5692 for (i = 0; i < vec_len(cm->maxi); i++) {
5693 vlib_get_combined_counter (cm, i, &v);
5694 total_pkts[which] += v.packets;
5695 total_bytes[which] += v.bytes;
5699 map_domain_counter_unlock (mm);
5701 /* Note: in network byte order! */
5702 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5703 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5704 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5705 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5706 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5707 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5708 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));
5709 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));
5711 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5714 static void vl_api_ipsec_sa_set_key_t_handler
5715 (vl_api_ipsec_sa_set_key_t * mp)
5717 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5718 vl_api_ipsec_sa_set_key_reply_t *rmp;
5722 sa.id = ntohl(mp->sa_id);
5723 sa.crypto_key_len = mp->crypto_key_length;
5724 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5725 sa.integ_key_len = mp->integrity_key_length;
5726 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5728 rv = ipsec_set_sa_key(vm, &sa);
5730 rv = VNET_API_ERROR_UNIMPLEMENTED;
5733 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5736 static void vl_api_cop_interface_enable_disable_t_handler
5737 (vl_api_cop_interface_enable_disable_t * mp)
5739 vl_api_cop_interface_enable_disable_reply_t * rmp;
5741 u32 sw_if_index = ntohl(mp->sw_if_index);
5744 VALIDATE_SW_IF_INDEX(mp);
5746 enable_disable = (int) mp->enable_disable;
5748 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5750 BAD_SW_IF_INDEX_LABEL;
5752 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5755 static void vl_api_cop_whitelist_enable_disable_t_handler
5756 (vl_api_cop_whitelist_enable_disable_t * mp)
5758 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5759 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5760 u32 sw_if_index = ntohl(mp->sw_if_index);
5763 VALIDATE_SW_IF_INDEX(mp);
5765 a->sw_if_index = sw_if_index;
5768 a->default_cop = mp->default_cop;
5769 a->fib_id = ntohl(mp->fib_id);
5771 rv = cop_whitelist_enable_disable (a);
5773 BAD_SW_IF_INDEX_LABEL;
5775 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5778 static void vl_api_get_node_graph_t_handler
5779 (vl_api_get_node_graph_t * mp)
5783 api_main_t * am = &api_main;
5784 vlib_main_t * vm = vlib_get_main();
5786 vl_api_get_node_graph_reply_t * rmp;
5788 pthread_mutex_lock (&am->vlib_rp->mutex);
5789 oldheap = svm_push_data_heap (am->vlib_rp);
5792 * Keep the number of memcpy ops to a minimum (e.g. 1).
5793 * The current size of the serialized vector is
5794 * slightly under 4K.
5796 vec_validate (vector, 4095);
5797 vec_reset_length (vector);
5799 vector = vlib_node_serialize (&vm->node_main, vector);
5801 svm_pop_heap (oldheap);
5802 pthread_mutex_unlock (&am->vlib_rp->mutex);
5804 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5805 rmp->reply_in_shmem = (uword) vector);
5808 static void vl_api_trace_profile_add_t_handler
5809 (vl_api_trace_profile_add_t *mp)
5812 vl_api_trace_profile_add_reply_t * rmp;
5813 clib_error_t *error;
5815 /* Ignoring the profile id as currently a single profile
5817 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5818 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5819 mp->pow_enable, mp->trace_tsp,
5822 clib_error_report(error);
5823 rv = clib_error_get_code(error);
5826 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5829 static void vl_api_trace_profile_apply_t_handler
5830 (vl_api_trace_profile_apply_t *mp)
5833 vl_api_trace_profile_apply_reply_t * rmp;
5835 if (mp->enable != 0) {
5836 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5837 ntohl(mp->prefix_length),
5839 mp->trace_op == IOAM_HBYH_ADD,
5840 mp->trace_op == IOAM_HBYH_POP,
5841 mp->trace_op == IOAM_HBYH_MOD);
5843 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5845 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5848 static void vl_api_trace_profile_del_t_handler
5849 (vl_api_trace_profile_del_t *mp)
5852 vl_api_trace_profile_del_reply_t * rmp;
5853 clib_error_t *error;
5855 error = clear_ioam_rewrite_fn();
5857 clib_error_report(error);
5858 rv = clib_error_get_code(error);
5861 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5865 #define BOUNCE_HANDLER(nn) \
5866 static void vl_api_##nn##_t_handler ( \
5867 vl_api_##nn##_t *mp) \
5869 vpe_client_registration_t *reg; \
5870 vpe_api_main_t * vam = &vpe_api_main; \
5871 unix_shared_memory_queue_t * q; \
5873 /* One registration only... */ \
5874 pool_foreach(reg, vam->nn##_registrations, \
5876 q = vl_api_client_index_to_input_queue (reg->client_index); \
5879 * If the queue is stuffed, turf the msg and complain \
5880 * It's unlikely that the intended recipient is \
5881 * alive; avoid deadlock at all costs. \
5883 if (q->cursize == q->maxsize) { \
5884 clib_warning ("ERROR: receiver queue full, drop msg"); \
5885 vl_msg_api_free (mp); \
5888 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5892 vl_msg_api_free (mp); \
5897 * Add vpe's API message handlers to the table.
5898 * vlib has alread mapped shared memory and
5899 * added the client registration handlers.
5900 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5903 static clib_error_t *
5904 vpe_api_hookup (vlib_main_t *vm)
5906 api_main_t * am = &api_main;
5909 vl_msg_api_set_handlers(VL_API_##N, #n, \
5910 vl_api_##n##_t_handler, \
5912 vl_api_##n##_t_endian, \
5913 vl_api_##n##_t_print, \
5914 sizeof(vl_api_##n##_t), 1);
5915 foreach_vpe_api_msg;
5919 * Manually register the sr tunnel add del msg, so we trace
5920 * enough bytes to capture a typical segment list
5922 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5923 "sr_tunnel_add_del",
5924 vl_api_sr_tunnel_add_del_t_handler,
5926 vl_api_sr_tunnel_add_del_t_endian,
5927 vl_api_sr_tunnel_add_del_t_print,
5932 * Manually register the sr policy add del msg, so we trace
5933 * enough bytes to capture a typical tunnel name list
5935 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
5936 "sr_policy_add_del",
5937 vl_api_sr_policy_add_del_t_handler,
5939 vl_api_sr_policy_add_del_t_endian,
5940 vl_api_sr_policy_add_del_t_print,
5944 * Trace space for 8 MPLS encap labels, classifier mask+match
5946 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5947 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5948 += 5 * sizeof (u32x4);
5949 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5950 += 5 * sizeof (u32x4);
5951 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5952 += 16 * sizeof (u32);
5955 * trace space for 4 nsh-gre variable TLV words
5957 am->api_trace_cfg [VL_API_NSH_GRE_ADD_DEL_TUNNEL].size
5958 += 4 * sizeof (u32);
5961 * Thread-safe API messages
5963 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
5968 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
5970 static clib_error_t *
5971 vpe_api_init (vlib_main_t *vm)
5973 vpe_api_main_t *am = &vpe_api_main;
5976 am->vnet_main = vnet_get_main();
5977 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
5978 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5979 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
5980 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5981 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
5982 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
5985 vl_set_memory_region_name ("/vpe-api");
5986 vl_enable_disable_memory_api (vm, 1 /* enable it */);
5991 VLIB_INIT_FUNCTION(vpe_api_init);
5993 static clib_error_t *
5994 chroot_config (vlib_main_t * vm, unformat_input_t * input)
5998 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6000 if (unformat (input, "prefix %s", &chroot_path))
6002 vec_add1 (chroot_path, 0);
6003 vl_set_memory_root_path ((char *)chroot_path);
6006 return clib_error_return (0, "unknown input `%U'",
6007 format_unformat_error, input);
6011 VLIB_EARLY_CONFIG_FUNCTION (chroot_config, "chroot");
6013 void * get_unformat_vnet_sw_interface (void)
6015 return (void *) &unformat_vnet_sw_interface;
6018 #undef vl_api_version
6019 #define vl_api_version(n,v) static u32 vpe_api_version = v;
6020 #include <api/vpe.api.h>
6021 #undef vl_api_version
6023 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
6025 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
6026 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
6027 clib_host_to_net_u32 (mp->api_versions[0]),
6034 static u8 * format_arp_event (u8 * s, va_list * args)
6036 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
6038 s = format (s, "pid %d: %U", event->pid,
6039 format_ip4_address, &event->address);
6043 static clib_error_t *
6044 show_ip4_arp_events_fn (vlib_main_t * vm,
6045 unformat_input_t * input,
6046 vlib_cli_command_t * cmd)
6048 vpe_api_main_t * am = &vpe_api_main;
6049 vl_api_ip4_arp_event_t * event;
6051 if (pool_elts (am->arp_events) == 0) {
6052 vlib_cli_output (vm, "No active arp event registrations");
6056 pool_foreach (event, am->arp_events,
6058 vlib_cli_output (vm, "%U", format_arp_event, event);
6064 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
6065 .path = "show arp event registrations",
6066 .function = show_ip4_arp_events_fn,
6067 .short_help = "Show arp event registrations",