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 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
295 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
296 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
297 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
298 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
299 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
300 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
301 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
302 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
303 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
304 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
305 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
306 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
307 _(DELETE_LOOPBACK, delete_loopback) \
308 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
309 _(MAP_ADD_DOMAIN, map_add_domain) \
310 _(MAP_DEL_DOMAIN, map_del_domain) \
311 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
312 _(MAP_DOMAIN_DUMP, map_domain_dump) \
313 _(MAP_RULE_DUMP, map_rule_dump) \
314 _(MAP_SUMMARY_STATS, map_summary_stats) \
315 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
316 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
317 _(GET_NODE_GRAPH, get_node_graph) \
318 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
319 _(TRACE_PROFILE_ADD, trace_profile_add) \
320 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
321 _(TRACE_PROFILE_DEL, trace_profile_del) \
322 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
323 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
324 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
325 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
326 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
327 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
328 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
329 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
330 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
331 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
332 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
333 _(LISP_GPE_ENABLE_DISABLE_STATUS_DUMP, \
334 lisp_gpe_enable_disable_status_dump) \
335 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del)
338 #define QUOTE(x) QUOTE_(x)
340 #define foreach_registration_hash \
341 _(interface_events) \
342 _(to_netconf_server) \
343 _(from_netconf_server) \
344 _(to_netconf_client) \
345 _(from_netconf_client) \
349 RESOLVE_IP4_ADD_DEL_ROUTE=1,
350 RESOLVE_IP6_ADD_DEL_ROUTE,
351 RESOLVE_MPLS_ETHERNET_ADD_DEL,
357 vl_api_ip_add_del_route_t r;
358 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
364 #define _(a) uword *a##_registration_hash; \
365 vpe_client_registration_t * a##_registrations;
366 foreach_registration_hash
369 /* notifications happen really early in the game */
370 u8 link_state_process_up;
372 /* ip4 pending route adds */
373 pending_route_t * pending_routes;
375 /* ip4 arp event registration pool */
376 vl_api_ip4_arp_event_t * arp_events;
379 vlib_main_t * vlib_main;
380 vnet_main_t * vnet_main;
383 static vlib_node_registration_t vpe_resolver_process_node;
384 static vpe_api_main_t vpe_api_main;
386 static void send_sw_interface_flags (vpe_api_main_t * am,
387 unix_shared_memory_queue_t *q,
388 vnet_sw_interface_t * swif);
389 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
390 unix_shared_memory_queue_t *q,
393 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
396 /* Clean up all registrations belonging to the indicated client */
397 int vl_api_memclnt_delete_callback (u32 client_index)
399 vpe_api_main_t * vam = &vpe_api_main;
400 vpe_client_registration_t *rp;
402 int stats_memclnt_delete_callback (u32 client_index);
404 stats_memclnt_delete_callback (client_index);
407 p = hash_get (vam->a##_registration_hash, client_index); \
409 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
410 pool_put (vam->a##_registrations, rp); \
411 hash_unset (vam->a##_registration_hash, client_index); \
413 foreach_registration_hash;
418 #define API_LINK_STATE_EVENT 1
419 #define API_ADMIN_UP_DOWN_EVENT 2
422 event_data_cmp (void * a1, void * a2)
427 return (word) e1[0] - (word) e2[0];
431 link_state_process (vlib_main_t * vm,
432 vlib_node_runtime_t * rt,
435 vpe_api_main_t * vam = &vpe_api_main;
436 vnet_main_t * vnm = vam->vnet_main;
437 vnet_sw_interface_t * swif;
438 uword * event_data = 0;
439 vpe_client_registration_t *reg;
441 u32 prev_sw_if_index;
442 unix_shared_memory_queue_t * q;
444 vam->link_state_process_up = 1;
447 vlib_process_wait_for_event (vm);
449 /* Unified list of changed link or admin state sw_if_indices */
450 vlib_process_get_events_with_type
451 (vm, &event_data, API_LINK_STATE_EVENT);
452 vlib_process_get_events_with_type
453 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
455 /* Sort, so we can eliminate duplicates */
456 vec_sort_with_function (event_data, event_data_cmp);
458 prev_sw_if_index = ~0;
460 for (i = 0; i < vec_len(event_data); i++) {
461 /* Only one message per swif */
462 if (prev_sw_if_index == event_data[i])
464 prev_sw_if_index = event_data[i];
466 pool_foreach(reg, vam->interface_events_registrations,
468 q = vl_api_client_index_to_input_queue (reg->client_index);
470 // sw_interface may be deleted already
471 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
474 swif = vnet_get_sw_interface (vnm, event_data[i]);
475 send_sw_interface_flags (vam, q, swif);
480 vec_reset_length (event_data);
486 static clib_error_t *
487 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
488 static clib_error_t *
489 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
491 VLIB_REGISTER_NODE (link_state_process_node,static) = {
492 .function = link_state_process,
493 .type = VLIB_NODE_TYPE_PROCESS,
494 .name = "vpe-link-state-process",
497 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
498 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
500 static clib_error_t *
501 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
503 vpe_api_main_t * vam = &vpe_api_main;
504 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
506 if (vam->link_state_process_up)
507 vlib_process_signal_event (vam->vlib_main,
508 link_state_process_node.index,
509 API_LINK_STATE_EVENT,
514 static clib_error_t *
515 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
517 vpe_api_main_t * vam = &vpe_api_main;
520 * Note: it's perfectly fair to set a subif admin up / admin down.
521 * Note the subtle distinction between this routine and the previous
524 if (vam->link_state_process_up)
525 vlib_process_signal_event (vam->vlib_main,
526 link_state_process_node.index,
527 API_ADMIN_UP_DOWN_EVENT,
532 #define pub_sub_handler(lca,UCA) \
533 static void vl_api_want_##lca##_t_handler ( \
534 vl_api_want_##lca##_t *mp) \
536 vpe_api_main_t *vam = &vpe_api_main; \
537 vpe_client_registration_t *rp; \
538 vl_api_want_##lca##_reply_t *rmp; \
542 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
544 if (mp->enable_disable) { \
545 clib_warning ("pid %d: already enabled...", mp->pid); \
546 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
549 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
550 pool_put (vam->lca##_registrations, rp); \
551 hash_unset (vam->lca##_registration_hash, \
556 if (mp->enable_disable == 0) { \
557 clib_warning ("pid %d: already disabled...", mp->pid); \
558 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
561 pool_get (vam->lca##_registrations, rp); \
562 rp->client_index = mp->client_index; \
563 rp->client_pid = mp->pid; \
564 hash_set (vam->lca##_registration_hash, rp->client_index, \
565 rp - vam->lca##_registrations); \
568 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
571 pub_sub_handler (interface_events,INTERFACE_EVENTS)
572 pub_sub_handler (oam_events,OAM_EVENTS)
574 #define RESOLUTION_EVENT 1
575 #define RESOLUTION_PENDING_EVENT 2
576 #define IP4_ARP_EVENT 3
578 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
579 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
580 static int mpls_ethernet_add_del_tunnel_2_t_handler
581 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
583 void handle_ip4_arp_event (u32 pool_index)
585 vpe_api_main_t * vam = &vpe_api_main;
586 vnet_main_t * vnm = vam->vnet_main;
587 vlib_main_t * vm = vam->vlib_main;
588 vl_api_ip4_arp_event_t * event;
589 vl_api_ip4_arp_event_t * mp;
590 unix_shared_memory_queue_t * q;
592 /* Client can cancel, die, etc. */
593 if (pool_is_free_index (vam->arp_events, pool_index))
596 event = pool_elt_at_index (vam->arp_events, pool_index);
598 q = vl_api_client_index_to_input_queue (event->client_index);
600 (void) vnet_add_del_ip4_arp_change_event
601 (vnm, arp_change_delete_callback,
602 event->pid, &event->address,
603 vpe_resolver_process_node.index, IP4_ARP_EVENT,
604 ~0 /* pool index, notused */, 0 /* is_add */);
608 if (q->cursize < q->maxsize) {
609 mp = vl_msg_api_alloc (sizeof (*mp));
610 clib_memcpy (mp, event, sizeof (*mp));
611 vl_msg_api_send_shmem (q, (u8 *)&mp);
613 static f64 last_time;
615 * Throttle syslog msgs.
616 * It's pretty tempting to just revoke the registration...
618 if (vlib_time_now (vm) > last_time + 10.0) {
619 clib_warning ("arp event for %U to pid %d: queue stuffed!",
620 format_ip4_address, &event->address, event->pid);
621 last_time = vlib_time_now(vm);
627 resolver_process (vlib_main_t * vm,
628 vlib_node_runtime_t * rt,
632 uword *event_data = 0;
634 vpe_api_main_t * vam = &vpe_api_main;
635 pending_route_t * pr;
636 vl_api_ip_add_del_route_t * adr;
637 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
638 u32 * resolution_failures = 0;
643 vlib_process_wait_for_event_or_clock (vm, timeout);
645 event_type = vlib_process_get_events (vm, &event_data);
647 switch (event_type) {
648 case RESOLUTION_PENDING_EVENT:
652 case RESOLUTION_EVENT:
653 for (i = 0; i < vec_len(event_data); i++) {
655 * Resolution events can occur long after the
656 * original request has timed out. $$$ add a cancel
659 if (pool_is_free_index (vam->pending_routes, event_data[i]))
662 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
666 switch (pr->resolve_type) {
667 case RESOLVE_IP4_ADD_DEL_ROUTE:
668 rv = ip4_add_del_route_t_handler (adr);
669 clib_warning ("resolver: add %U/%d via %U %s",
671 (ip4_address_t *)&(adr->dst_address),
672 adr->dst_address_length,
674 (ip4_address_t *)&(adr->next_hop_address),
675 (rv >= 0) ? "succeeded" : "failed");
678 case RESOLVE_IP6_ADD_DEL_ROUTE:
679 rv = ip6_add_del_route_t_handler (adr);
680 clib_warning ("resolver: add %U/%d via %U %s",
682 (ip6_address_t *)&(adr->dst_address),
683 adr->dst_address_length,
685 (ip6_address_t *)&(adr->next_hop_address),
686 (rv >= 0) ? "succeeded" : "failed");
689 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
690 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
691 clib_warning ("resolver: add mpls-o-e via %U %s",
693 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
694 (rv >= 0) ? "succeeded" : "failed");
698 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
700 pool_put (vam->pending_routes, pr);
705 for (i = 0; i < vec_len(event_data); i++)
706 handle_ip4_arp_event (event_data[i]);
709 case ~0: /* timeout, retry pending resolutions */
710 pool_foreach (pr, vam->pending_routes,
716 /* May fail, e.g. due to interface down */
717 switch (pr->resolve_type) {
718 case RESOLVE_IP4_ADD_DEL_ROUTE:
719 e = ip4_probe_neighbor
720 (vm, (ip4_address_t *)&(adr->next_hop_address),
721 ntohl(adr->next_hop_sw_if_index));
724 case RESOLVE_IP6_ADD_DEL_ROUTE:
725 e = ip6_probe_neighbor
726 (vm, (ip6_address_t *)&(adr->next_hop_address),
727 ntohl(adr->next_hop_sw_if_index));
730 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
732 e = ip4_probe_neighbor
734 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
735 pme->resolve_opaque);
739 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
743 clib_error_report (e);
745 adr->resolve_attempts = 1;
747 pme->resolve_attempts = 1;
751 adr->resolve_attempts -= 1;
752 if (adr->resolve_attempts == 0)
753 vec_add1 (resolution_failures,
754 pr - vam->pending_routes);
756 pme->resolve_attempts -= 1;
757 if (pme->resolve_attempts == 0)
758 vec_add1 (resolution_failures,
759 pr - vam->pending_routes);
763 for (i = 0; i < vec_len (resolution_failures); i++) {
764 pr = pool_elt_at_index (vam->pending_routes,
765 resolution_failures[i]);
769 switch (pr->resolve_type) {
770 case RESOLVE_IP4_ADD_DEL_ROUTE:
771 clib_warning ("resolver: add %U/%d via %U retry failure",
773 (ip4_address_t *)&(adr->dst_address),
774 adr->dst_address_length,
776 (ip4_address_t *)&(adr->next_hop_address));
779 case RESOLVE_IP6_ADD_DEL_ROUTE:
780 clib_warning ("resolver: add %U/%d via %U retry failure",
782 (ip6_address_t *)&(adr->dst_address),
783 adr->dst_address_length,
785 (ip6_address_t *)&(adr->next_hop_address));
788 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
789 clib_warning ("resolver: add mpls-o-e via %U retry failure",
791 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
795 clib_warning ("BUG");
797 pool_put(vam->pending_routes, pr);
799 vec_reset_length (resolution_failures);
802 if (pool_elts (vam->pending_routes) == 0)
804 vec_reset_length (event_data);
806 return 0; /* or not */
809 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
810 .function = resolver_process,
811 .type = VLIB_NODE_TYPE_PROCESS,
812 .name = "vpe-route-resolver-process",
815 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
817 ip4_main_t * im = &ip4_main;
818 ip_lookup_main_t * lm = &im->lookup_main;
819 vnet_classify_main_t * cm = &vnet_classify_main;
820 stats_main_t * sm = &stats_main;
821 ip4_add_del_route_args_t a;
822 ip4_address_t next_hop_address;
824 vpe_api_main_t * vam = &vpe_api_main;
825 vnet_main_t * vnm = vam->vnet_main;
826 vlib_main_t * vm = vlib_get_main();
827 pending_route_t * pr;
828 vl_api_ip_add_del_route_t * adr;
832 ip_adjacency_t *nh_adj, *add_adj = 0;
834 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
836 if (mp->create_vrf_if_needed) {
838 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
840 fib_index = f->index;
842 /* No such VRF, and we weren't asked to create one */
843 return VNET_API_ERROR_NO_SUCH_FIB;
849 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
850 ntohl(mp->next_hop_sw_if_index)))
851 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
853 clib_memcpy (next_hop_address.data, mp->next_hop_address,
854 sizeof (next_hop_address.data));
856 /* Arp for the next_hop if necessary */
857 if (mp->is_add && mp->resolve_if_needed) {
859 ip_adjacency_t * adj;
861 lookup_result = ip4_fib_lookup_with_table
862 (im, fib_index, &next_hop_address, 1 /* disable default route */);
864 adj = ip_get_adjacency (lm, lookup_result);
866 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
867 pool_get (vam->pending_routes, pr);
868 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
870 clib_memcpy (adr, mp, sizeof (*adr));
871 /* recursion block, "just in case" */
872 adr->resolve_if_needed = 0;
873 adr->resolve_attempts = ntohl(mp->resolve_attempts);
874 vnet_register_ip4_arp_resolution_event
875 (vnm, &next_hop_address, vpe_resolver_process_node.index,
876 RESOLUTION_EVENT, pr - vam->pending_routes);
878 vlib_process_signal_event
879 (vm, vpe_resolver_process_node.index,
880 RESOLUTION_PENDING_EVENT, 0 /* data */);
882 /* The interface may be down, etc. */
883 e = ip4_probe_neighbor
884 (vm, (ip4_address_t *)&(mp->next_hop_address),
885 ntohl(mp->next_hop_sw_if_index));
888 clib_error_report(e);
890 return VNET_API_ERROR_IN_PROGRESS;
894 if (mp->is_multipath) {
897 dslock (sm, 1 /* release hint */, 10 /* tag */);
900 flags = IP4_ROUTE_FLAG_ADD;
902 flags = IP4_ROUTE_FLAG_DEL;
905 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
907 ip4_add_del_route_next_hop (im, flags,
908 (ip4_address_t *) mp->dst_address,
909 (u32) mp->dst_address_length,
910 (ip4_address_t *) mp->next_hop_address,
911 ntohl(mp->next_hop_sw_if_index),
912 (u32) mp->next_hop_weight,
919 memset (&a, 0, sizeof (a));
920 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
922 a.dst_address_length = mp->dst_address_length;
924 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
925 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
926 a.table_index_or_table_id = fib_index;
931 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
933 dslock (sm, 1 /* release hint */, 2 /* tag */);
937 ai = lm->drop_adj_index;
938 else if (mp->is_local)
939 ai = lm->local_adj_index;
940 else if (mp->is_classify) {
942 memset(&cadj, 0, sizeof(cadj));
943 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
944 cadj.classify.table_index = ntohl(mp->classify_table_index);
945 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
947 return VNET_API_ERROR_NO_SUCH_TABLE;
949 vec_add1 (add_adj, cadj);
953 ai = ip4_fib_lookup_with_table
954 (im, fib_index, &next_hop_address,
955 1 /* disable default route */);
956 if (ai == lm->miss_adj_index) {
958 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
962 nh_adj = ip_get_adjacency (lm, ai);
963 vec_add1 (add_adj, nh_adj[0]);
964 if (mp->lookup_in_vrf) {
965 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
967 add_adj[0].explicit_fib_index = p[0];
971 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
975 ip_adjacency_t * adj;
976 int disable_default_route = 1;
978 /* Trying to delete the default route? */
979 if (a.dst_address.as_u32 == 0 &&
980 a.dst_address_length == 0)
981 disable_default_route = 0;
983 ai = ip4_fib_lookup_with_table
984 (im, fib_index, &a.dst_address, disable_default_route);
985 if (ai == lm->miss_adj_index) {
987 return VNET_API_ERROR_UNKNOWN_DESTINATION;
990 adj = ip_get_adjacency (lm, ai);
991 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
993 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1000 a.n_add_adj = vec_len(add_adj);
1001 ip4_add_del_route (im, &a);
1009 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1011 ip6_main_t * im = &ip6_main;
1012 ip_lookup_main_t * lm = &im->lookup_main;
1013 vnet_main_t * vnm = vnet_get_main();
1014 vlib_main_t * vm = vlib_get_main();
1015 vpe_api_main_t * vam = &vpe_api_main;
1016 stats_main_t * sm = &stats_main;
1017 ip6_add_del_route_args_t a;
1018 ip6_address_t next_hop_address;
1019 pending_route_t * pr;
1020 vl_api_ip_add_del_route_t * adr;
1025 ip_adjacency_t * nh_adj, * add_adj = 0;
1028 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1031 if (mp->create_vrf_if_needed) {
1033 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1035 fib_index = f->index;
1037 /* No such VRF, and we weren't asked to create one */
1038 return VNET_API_ERROR_NO_SUCH_FIB;
1044 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1045 ntohl(mp->next_hop_sw_if_index)))
1046 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1048 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1049 sizeof (next_hop_address.as_u8));
1051 /* Arp for the next_hop if necessary */
1052 if (mp->is_add && mp->resolve_if_needed) {
1054 ip_adjacency_t * adj;
1056 lookup_result = ip6_fib_lookup_with_table
1057 (im, fib_index, &next_hop_address);
1059 adj = ip_get_adjacency (lm, lookup_result);
1061 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1062 pool_get (vam->pending_routes, pr);
1064 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1065 clib_memcpy (adr, mp, sizeof (*adr));
1066 /* recursion block, "just in case" */
1067 adr->resolve_if_needed = 0;
1068 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1069 vnet_register_ip6_neighbor_resolution_event
1070 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1071 RESOLUTION_EVENT, pr - vam->pending_routes);
1073 vlib_process_signal_event
1074 (vm, vpe_resolver_process_node.index,
1075 RESOLUTION_PENDING_EVENT, 0 /* data */);
1077 /* The interface may be down, etc. */
1078 e = ip6_probe_neighbor
1079 (vm, (ip6_address_t *)&(mp->next_hop_address),
1080 ntohl(mp->next_hop_sw_if_index));
1083 clib_error_report(e);
1085 return VNET_API_ERROR_IN_PROGRESS;
1089 if (mp->is_multipath) {
1092 dslock (sm, 1 /* release hint */, 11 /* tag */);
1095 flags = IP6_ROUTE_FLAG_ADD;
1097 flags = IP6_ROUTE_FLAG_DEL;
1100 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1102 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1103 (u32) mp->dst_address_length,
1104 (ip6_address_t *)mp->next_hop_address,
1105 ntohl(mp->next_hop_sw_if_index),
1106 (u32) mp->next_hop_weight,
1113 memset (&a, 0, sizeof (a));
1114 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1116 a.dst_address_length = mp->dst_address_length;
1118 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1119 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1120 a.table_index_or_table_id = fib_index;
1125 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1127 dslock (sm, 1 /* release hint */, 3 /* tag */);
1131 ai = lm->drop_adj_index;
1132 else if (mp->is_local)
1133 ai = lm->local_adj_index;
1135 ai = ip6_fib_lookup_with_table
1136 (im, fib_index, &next_hop_address);
1137 if (ai == lm->miss_adj_index) {
1139 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1143 nh_adj = ip_get_adjacency (lm, ai);
1144 vec_add1 (add_adj, nh_adj[0]);
1145 if (mp->lookup_in_vrf) {
1146 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1148 add_adj[0].explicit_fib_index = p[0];
1152 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1156 ip_adjacency_t * adj;
1158 ai = ip6_fib_lookup_with_table
1159 (im, fib_index, &a.dst_address);
1160 if (ai == lm->miss_adj_index) {
1162 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1164 adj = ip_get_adjacency (lm, ai);
1165 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1167 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1172 a.add_adj = add_adj;
1173 a.n_add_adj = vec_len(add_adj);
1174 ip6_add_del_route (im, &a);
1182 void vl_api_ip_add_del_route_t_handler (
1183 vl_api_ip_add_del_route_t *mp)
1185 vl_api_ip_add_del_route_reply_t * rmp;
1187 vnet_main_t * vnm = vnet_get_main();
1192 rv = ip6_add_del_route_t_handler (mp);
1194 rv = ip4_add_del_route_t_handler (mp);
1196 rv = (rv == 0) ? vnm->api_errno : rv;
1198 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1201 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1202 u32 sw_if_index, u8 *next_hop_addr)
1204 vl_api_ip_add_del_route_t mp;
1207 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1210 * Configure default IP route:
1211 * - ip route add 0.0.0.0/1 via <GW IP>
1212 * - ip route add 128.0.0.0/1 via <GW IP>
1214 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1216 mp.resolve_attempts = ~0;
1217 mp.resolve_if_needed = 1;
1219 mp.is_ipv6 = is_ipv6;
1220 mp.next_hop_weight = 1;
1222 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1225 rv = ip6_add_del_route_t_handler (&mp);
1228 mp.dst_address_length = 1;
1230 mp.dst_address[0] = 0;
1231 rv = ip4_add_del_route_t_handler (&mp);
1233 mp.dst_address[0] = 128;
1234 rv |= ip4_add_del_route_t_handler (&mp);
1238 clib_error_return (0, "failed to config default IP route");
1243 vl_api_sw_interface_add_del_address_t_handler
1244 (vl_api_sw_interface_add_del_address_t *mp)
1246 vlib_main_t *vm = vlib_get_main();
1247 vl_api_sw_interface_add_del_address_reply_t * rmp;
1251 VALIDATE_SW_IF_INDEX(mp);
1253 is_del = mp->is_add == 0;
1256 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1257 else if (mp->is_ipv6)
1258 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1259 (void *)mp->address,
1260 mp->address_length, is_del);
1262 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1263 (void *) mp->address,
1264 mp->address_length, is_del);
1266 BAD_SW_IF_INDEX_LABEL;
1268 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1272 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1275 u32 table_id = ntohl(mp->vrf_id);
1276 u32 sw_if_index = ntohl(mp->sw_if_index);
1277 vl_api_sw_interface_set_table_reply_t * rmp;
1278 stats_main_t * sm = &stats_main;
1280 VALIDATE_SW_IF_INDEX(mp);
1282 dslock (sm, 1 /* release hint */, 4 /* tag */);
1285 ip6_main_t * im = &ip6_main;
1287 find_ip6_fib_by_table_index_or_id (im, table_id,
1288 IP6_ROUTE_FLAG_TABLE_ID);
1290 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1291 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1293 rv = VNET_API_ERROR_NO_SUCH_FIB;
1296 ip4_main_t * im = &ip4_main;
1297 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1298 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1300 /* Truthfully this can't fail */
1302 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1303 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1305 rv = VNET_API_ERROR_NO_SUCH_FIB;
1310 BAD_SW_IF_INDEX_LABEL;
1312 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1316 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1318 vlib_main_t *vm = vlib_get_main();
1319 vl_api_sw_interface_set_vpath_reply_t * rmp;
1322 u32 sw_if_index = ntohl(mp->sw_if_index);
1323 ip4_main_t *ip4m = &ip4_main;
1324 ip6_main_t *ip6m = &ip6_main;
1325 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1326 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1327 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1328 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1329 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1330 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1332 VALIDATE_SW_IF_INDEX(mp);
1334 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1336 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1337 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1338 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1339 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1340 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1341 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1342 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1343 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1344 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1345 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1346 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1347 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1348 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1349 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1350 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1351 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1353 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1354 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1355 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1356 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1357 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1358 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1359 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1360 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1361 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1362 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1363 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1364 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1365 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1366 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1367 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1368 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1371 BAD_SW_IF_INDEX_LABEL;
1373 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1377 vl_api_sw_interface_set_l2_xconnect_t_handler (
1378 vl_api_sw_interface_set_l2_xconnect_t *mp)
1380 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1382 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1383 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1384 vlib_main_t *vm = vlib_get_main();
1385 vnet_main_t *vnm = vnet_get_main();
1387 VALIDATE_RX_SW_IF_INDEX(mp);
1390 VALIDATE_TX_SW_IF_INDEX(mp);
1391 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1392 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1394 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1397 BAD_RX_SW_IF_INDEX_LABEL;
1398 BAD_TX_SW_IF_INDEX_LABEL;
1400 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1404 vl_api_sw_interface_set_l2_bridge_t_handler (
1405 vl_api_sw_interface_set_l2_bridge_t *mp)
1407 bd_main_t * bdm = &bd_main;
1408 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1410 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1411 u32 bd_id = ntohl(mp->bd_id);
1415 vlib_main_t *vm = vlib_get_main();
1416 vnet_main_t *vnm = vnet_get_main();
1418 VALIDATE_RX_SW_IF_INDEX(mp);
1420 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1423 //VALIDATE_TX_SW_IF_INDEX(mp);
1424 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1425 rx_sw_if_index, bd_index, bvi, shg, 0);
1427 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1430 BAD_RX_SW_IF_INDEX_LABEL;
1432 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1436 vl_api_bridge_domain_add_del_t_handler (
1437 vl_api_bridge_domain_add_del_t *mp)
1439 vlib_main_t * vm = vlib_get_main ();
1440 bd_main_t * bdm = &bd_main;
1441 vl_api_bridge_domain_add_del_reply_t * rmp;
1443 u32 enable_flags = 0, disable_flags = 0;
1444 u32 bd_id = ntohl(mp->bd_id);
1448 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1451 enable_flags |= L2_FLOOD;
1453 disable_flags |= L2_FLOOD;
1456 enable_flags |= L2_UU_FLOOD;
1458 disable_flags |= L2_UU_FLOOD;
1461 enable_flags |= L2_FWD;
1463 disable_flags |= L2_FWD;
1466 enable_flags |= L2_ARP_TERM;
1468 disable_flags |= L2_ARP_TERM;
1471 enable_flags |= L2_LEARN;
1473 disable_flags |= L2_LEARN;
1476 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1479 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1482 rv = bd_delete_bd_index(bdm, bd_id);
1484 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1487 static void vl_api_bridge_domain_details_t_handler (
1488 vl_api_bridge_domain_details_t * mp)
1490 clib_warning ("BUG");
1493 static void vl_api_bridge_domain_sw_if_details_t_handler (
1494 vl_api_bridge_domain_sw_if_details_t * mp)
1496 clib_warning ("BUG");
1499 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1500 l2_bridge_domain_t * bd_config,
1504 vl_api_bridge_domain_details_t * mp;
1506 mp = vl_msg_api_alloc (sizeof (*mp));
1507 memset (mp, 0, sizeof (*mp));
1508 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1509 mp->bd_id = ntohl (bd_config->bd_id);
1510 mp->flood = bd_feature_flood (bd_config);
1511 mp->uu_flood = bd_feature_uu_flood (bd_config);
1512 mp->forward = bd_feature_forward (bd_config);
1513 mp->learn = bd_feature_learn (bd_config);
1514 mp->arp_term = bd_feature_arp_term (bd_config);
1515 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1516 mp->n_sw_ifs = ntohl (n_sw_ifs);
1517 mp->context = context;
1519 vl_msg_api_send_shmem (q, (u8 *)&mp);
1522 static void send_bd_sw_if_details (l2input_main_t * l2im,
1523 unix_shared_memory_queue_t *q,
1524 l2_flood_member_t * member, u32 bd_id,
1527 vl_api_bridge_domain_sw_if_details_t * mp;
1528 l2_input_config_t * input_cfg;
1530 mp = vl_msg_api_alloc (sizeof (*mp));
1531 memset (mp, 0, sizeof (*mp));
1532 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1533 mp->bd_id = ntohl (bd_id);
1534 mp->sw_if_index = ntohl (member->sw_if_index);
1535 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1536 mp->shg = input_cfg->shg;
1537 mp->context = context;
1539 vl_msg_api_send_shmem (q, (u8 *)&mp);
1542 static void vl_api_bridge_domain_dump_t_handler (
1543 vl_api_bridge_domain_dump_t *mp)
1545 bd_main_t * bdm = &bd_main;
1546 l2input_main_t * l2im = &l2input_main;
1547 unix_shared_memory_queue_t * q;
1548 l2_bridge_domain_t * bd_config;
1549 u32 bd_id, bd_index;
1552 q = vl_api_client_index_to_input_queue (mp->client_index);
1557 bd_id = ntohl(mp->bd_id);
1559 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1560 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1561 for (; bd_index < end; bd_index++) {
1562 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1563 /* skip dummy bd_id 0 */
1564 if (bd_config && (bd_config->bd_id > 0)) {
1566 l2_flood_member_t * m;
1568 n_sw_ifs = vec_len (bd_config->members);
1569 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1571 vec_foreach (m, bd_config->members) {
1572 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1579 vl_api_l2fib_add_del_t_handler (
1580 vl_api_l2fib_add_del_t *mp)
1582 bd_main_t * bdm = &bd_main;
1583 l2input_main_t * l2im = &l2input_main;
1584 vl_api_l2fib_add_del_reply_t * rmp;
1587 u32 sw_if_index = ntohl(mp->sw_if_index);
1588 u32 bd_id = ntohl(mp->bd_id);
1596 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1598 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1599 goto bad_sw_if_index;
1604 VALIDATE_SW_IF_INDEX(mp);
1605 if (vec_len(l2im->configs) <= sw_if_index) {
1606 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1607 goto bad_sw_if_index;
1609 l2_input_config_t * config;
1610 config = vec_elt_at_index(l2im->configs, sw_if_index);
1611 if (config->bridge == 0) {
1612 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1613 goto bad_sw_if_index;
1616 static_mac = mp->static_mac ? 1 : 0;
1617 filter_mac = mp->filter_mac ? 1 : 0;
1618 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1621 l2fib_del_entry(mac, bd_index);
1624 BAD_SW_IF_INDEX_LABEL;
1626 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1630 vl_api_l2_flags_t_handler (
1631 vl_api_l2_flags_t *mp)
1633 vl_api_l2_flags_reply_t * rmp;
1635 u32 sw_if_index = ntohl(mp->sw_if_index);
1636 u32 flags = ntohl(mp->feature_bitmap);
1639 VALIDATE_SW_IF_INDEX(mp);
1642 if (flags & L2INPUT_FEAT_ ## a) \
1643 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1644 foreach_l2input_feat;
1647 BAD_SW_IF_INDEX_LABEL;
1649 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1653 vl_api_bridge_flags_t_handler (
1654 vl_api_bridge_flags_t *mp)
1656 vlib_main_t *vm = vlib_get_main();
1657 bd_main_t * bdm = &bd_main;
1658 vl_api_bridge_flags_reply_t * rmp;
1660 u32 bd_id = ntohl(mp->bd_id);
1662 u32 flags = ntohl(mp->feature_bitmap);
1665 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1667 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1673 bd_set_flags(vm, bd_index, flags, mp->is_set);
1676 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1677 rmp->resulting_feature_bitmap = ntohl(flags));
1681 vl_api_bd_ip_mac_add_del_t_handler (
1682 vl_api_bd_ip_mac_add_del_t *mp)
1684 bd_main_t * bdm = &bd_main;
1685 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1687 u32 bd_id = ntohl(mp->bd_id);
1691 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1693 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1698 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1699 mp->mac_address, mp->is_ipv6, mp->is_add))
1700 rv = VNET_API_ERROR_UNSPECIFIED;
1703 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1707 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1710 vl_api_tap_connect_reply_t * rmp;
1711 unix_shared_memory_queue_t * q;
1712 u32 sw_if_index = (u32)~0;
1714 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1715 mp->use_random_mac ? 0 : mp->mac_address,
1716 &sw_if_index, mp->renumber,
1717 ntohl(mp->custom_dev_instance));
1719 q = vl_api_client_index_to_input_queue (mp->client_index);
1723 rmp = vl_msg_api_alloc (sizeof (*rmp));
1724 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1725 rmp->context = mp->context;
1726 rmp->retval = ntohl(rv);
1727 rmp->sw_if_index = ntohl(sw_if_index);
1729 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1733 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1736 vl_api_tap_modify_reply_t * rmp;
1737 unix_shared_memory_queue_t * q;
1738 u32 sw_if_index = (u32)~0;
1740 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1741 mp->use_random_mac ? 0 : mp->mac_address,
1742 &sw_if_index, mp->renumber,
1743 ntohl(mp->custom_dev_instance));
1745 q = vl_api_client_index_to_input_queue (mp->client_index);
1749 rmp = vl_msg_api_alloc (sizeof (*rmp));
1750 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1751 rmp->context = mp->context;
1752 rmp->retval = ntohl(rv);
1753 rmp->sw_if_index = ntohl(sw_if_index);
1755 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1759 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1762 vpe_api_main_t * vam = &vpe_api_main;
1763 vl_api_tap_delete_reply_t * rmp;
1764 unix_shared_memory_queue_t * q;
1765 u32 sw_if_index = ntohl(mp->sw_if_index);
1767 rv = vnet_tap_delete (vm, sw_if_index);
1769 q = vl_api_client_index_to_input_queue (mp->client_index);
1773 rmp = vl_msg_api_alloc (sizeof (*rmp));
1774 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1775 rmp->context = mp->context;
1776 rmp->retval = ntohl(rv);
1778 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1781 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1785 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1787 vl_api_create_vlan_subif_reply_t * rmp;
1788 vnet_main_t * vnm = vnet_get_main();
1789 u32 hw_if_index, sw_if_index = (u32)~0;
1790 vnet_hw_interface_t * hi;
1793 vnet_sw_interface_t template;
1795 vnet_interface_main_t * im = &vnm->interface_main;
1796 u64 sup_and_sub_key;
1798 unix_shared_memory_queue_t * q;
1799 clib_error_t * error;
1801 VALIDATE_SW_IF_INDEX(mp);
1803 hw_if_index = ntohl(mp->sw_if_index);
1804 hi = vnet_get_hw_interface (vnm, hw_if_index);
1806 id = ntohl(mp->vlan_id);
1807 if (id == 0 || id > 4095) {
1808 rv = VNET_API_ERROR_INVALID_VLAN;
1812 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1814 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1816 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1820 kp = clib_mem_alloc (sizeof (*kp));
1821 *kp = sup_and_sub_key;
1823 memset (&template, 0, sizeof (template));
1824 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1825 template.sup_sw_if_index = hi->sw_if_index;
1826 template.sub.id = id;
1827 template.sub.eth.raw_flags = 0;
1828 template.sub.eth.flags.one_tag = 1;
1829 template.sub.eth.outer_vlan_id = id;
1830 template.sub.eth.flags.exact_match = 1;
1832 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1834 clib_error_report(error);
1835 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1838 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1839 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1841 BAD_SW_IF_INDEX_LABEL;
1844 q = vl_api_client_index_to_input_queue (mp->client_index);
1848 rmp = vl_msg_api_alloc (sizeof (*rmp));
1849 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1850 rmp->context = mp->context;
1851 rmp->retval = ntohl(rv);
1852 rmp->sw_if_index = ntohl(sw_if_index);
1853 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1857 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1859 vl_api_create_subif_reply_t * rmp;
1860 vnet_main_t * vnm = vnet_get_main();
1861 u32 sw_if_index = ~0;
1864 vnet_sw_interface_t *si;
1865 vnet_hw_interface_t *hi;
1866 vnet_sw_interface_t template;
1868 vnet_interface_main_t * im = &vnm->interface_main;
1869 u64 sup_and_sub_key;
1871 clib_error_t * error;
1873 VALIDATE_SW_IF_INDEX(mp);
1875 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1876 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1878 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1879 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1883 sw_if_index = si->sw_if_index;
1884 sub_id = ntohl(mp->sub_id);
1886 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1888 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1891 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1892 sw_if_index, sub_id);
1893 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1897 kp = clib_mem_alloc (sizeof (*kp));
1898 *kp = sup_and_sub_key;
1900 memset (&template, 0, sizeof (template));
1901 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1902 template.sup_sw_if_index = sw_if_index;
1903 template.sub.id = sub_id;
1904 template.sub.eth.flags.no_tags = mp->no_tags;
1905 template.sub.eth.flags.one_tag = mp->one_tag;
1906 template.sub.eth.flags.two_tags = mp->two_tags;
1907 template.sub.eth.flags.dot1ad = mp->dot1ad;
1908 template.sub.eth.flags.exact_match = mp->exact_match;
1909 template.sub.eth.flags.default_sub = mp->default_sub;
1910 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1911 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1912 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1913 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1915 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1917 clib_error_report (error);
1918 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1922 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1923 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1925 BAD_SW_IF_INDEX_LABEL;
1929 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1931 rmp->sw_if_index = ntohl(sw_if_index);
1936 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1938 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1940 stats_main_t * sm = &stats_main;
1941 u32 tunnel_sw_if_index = ~0;
1943 dslock (sm, 1 /* release hint */, 5 /* tag */);
1945 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1946 (ip4_address_t *)(mp->dst_address),
1947 (ip4_address_t *)(mp->intfc_address),
1948 (u32)(mp->intfc_address_length),
1949 ntohl(mp->inner_vrf_id),
1950 ntohl(mp->outer_vrf_id),
1951 &tunnel_sw_if_index,
1956 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1958 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1963 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1964 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1966 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1968 stats_main_t * sm = &stats_main;
1969 u32 tunnel_sw_if_index;
1971 dslock (sm, 1 /* release hint */, 5 /* tag */);
1973 rv = vnet_mpls_ethernet_add_del_tunnel
1974 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1975 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1976 ntohl(mp->tx_sw_if_index),
1977 &tunnel_sw_if_index,
1983 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1985 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1990 * This piece of misery brought to you because the control-plane
1991 * can't figure out the tx interface + dst-mac address all by itself
1993 static int mpls_ethernet_add_del_tunnel_2_t_handler
1994 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1996 pending_route_t * pr;
1997 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
1998 vnet_main_t * vnm = vnet_get_main();
1999 vlib_main_t * vm = vlib_get_main();
2000 stats_main_t * sm = &stats_main;
2001 vpe_api_main_t * vam = &vpe_api_main;
2002 u32 inner_fib_index, outer_fib_index;
2003 ip4_main_t * im = &ip4_main;
2004 ip_lookup_main_t * lm = &im->lookup_main;
2005 ip_adjacency_t * adj = 0;
2008 u8 * dst_mac_address;
2012 u32 tunnel_sw_if_index;
2014 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2016 return VNET_API_ERROR_NO_SUCH_FIB;
2018 outer_fib_index = p[0];
2021 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2023 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2025 inner_fib_index = p[0];
2027 if (inner_fib_index == outer_fib_index)
2028 return VNET_API_ERROR_INVALID_VALUE;
2030 lookup_result = ip4_fib_lookup_with_table
2031 (im, outer_fib_index,
2032 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2033 1 /* disable default route */);
2035 adj = ip_get_adjacency (lm, lookup_result);
2036 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2038 if (mp->is_add && mp->resolve_if_needed) {
2039 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2040 pool_get (vam->pending_routes, pr);
2041 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2043 clib_memcpy (pme, mp, sizeof (*pme));
2044 /* recursion block, "just in case" */
2045 pme->resolve_if_needed = 0;
2046 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2047 pme->resolve_opaque = tx_sw_if_index;
2048 vnet_register_ip4_arp_resolution_event
2050 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2051 vpe_resolver_process_node.index,
2052 RESOLUTION_EVENT, pr - vam->pending_routes);
2054 vlib_process_signal_event
2055 (vm, vpe_resolver_process_node.index,
2056 RESOLUTION_PENDING_EVENT, 0 /* data */);
2058 /* The interface may be down, etc. */
2059 e = ip4_probe_neighbor
2060 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2064 clib_error_report(e);
2066 return VNET_API_ERROR_IN_PROGRESS;
2070 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2071 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2074 vnet_rewrite_get_data_internal
2075 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2077 dslock (sm, 1 /* release hint */, 10 /* tag */);
2079 rv = vnet_mpls_ethernet_add_del_tunnel
2080 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2081 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2082 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2090 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2091 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2093 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2096 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2098 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2103 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2105 vl_api_mpls_add_del_encap_reply_t * rmp;
2107 static u32 * labels;
2110 vec_reset_length (labels);
2112 for (i = 0; i < mp->nlabels; i++)
2113 vec_add1 (labels, ntohl(mp->labels[i]));
2116 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2117 ntohl(mp->vrf_id), labels,
2118 ~0 /* policy_tunnel_index */,
2119 0 /* no_dst_hash */,
2123 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2127 vl_api_mpls_add_del_decap_t_handler
2128 (vl_api_mpls_add_del_decap_t *mp)
2130 vl_api_mpls_add_del_decap_reply_t * rmp;
2133 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2134 ntohl(mp->label), ntohl(mp->next_index),
2135 mp->s_bit, mp->is_add);
2137 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2141 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2143 vl_api_proxy_arp_add_del_reply_t * rmp;
2146 ip4_main_t * im = &ip4_main;
2147 stats_main_t * sm = &stats_main;
2148 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2149 ip4_address_t *hi_addr,
2150 u32 fib_index, int is_del);
2153 dslock (sm, 1 /* release hint */, 6 /* tag */);
2155 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2158 rv = VNET_API_ERROR_NO_SUCH_FIB;
2164 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2165 (ip4_address_t *)mp->hi_address,
2166 fib_index, mp->is_add == 0);
2170 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2174 vl_api_proxy_arp_intfc_enable_disable_t_handler
2175 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2178 vnet_main_t * vnm = vnet_get_main();
2179 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2180 vnet_sw_interface_t * si;
2183 VALIDATE_SW_IF_INDEX(mp);
2185 sw_if_index = ntohl(mp->sw_if_index);
2187 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2189 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2193 si = vnet_get_sw_interface (vnm, sw_if_index);
2197 if (mp->enable_disable)
2198 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2200 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2202 BAD_SW_IF_INDEX_LABEL;
2205 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2209 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2211 vl_api_ip_neighbor_add_del_reply_t * rmp;
2212 vnet_main_t * vnm = vnet_get_main();
2215 stats_main_t * sm = &stats_main;
2217 VALIDATE_SW_IF_INDEX(mp);
2219 dslock (sm, 1 /* release hint */, 7 /* tag */);
2223 rv = vnet_set_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), mp->is_static);
2228 rv = vnet_unset_ip6_ethernet_neighbor
2229 (vm, ntohl(mp->sw_if_index),
2230 (ip6_address_t *)(mp->dst_address),
2231 mp->mac_address, sizeof(mp->mac_address));
2233 ip4_main_t * im = &ip4_main;
2234 ip_lookup_main_t * lm = &im->lookup_main;
2235 ethernet_arp_ip4_over_ethernet_address_t a;
2237 ip_adjacency_t *nh_adj;
2239 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2241 rv = VNET_API_ERROR_NO_SUCH_FIB;
2247 * Unfortunately, folks have a penchant for
2248 * adding interface addresses to the ARP cache, and
2249 * wondering why the forwarder eventually ASSERTs...
2251 ai = ip4_fib_lookup_with_table
2252 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2253 1 /* disable default route */);
2256 nh_adj = ip_get_adjacency (lm, ai);
2257 /* Never allow manipulation of a local adj! */
2258 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2259 clib_warning("%U matches local adj",
2261 (ip4_address_t *)(mp->dst_address));
2262 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2267 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2268 clib_memcpy (&a.ip4, mp->dst_address, 4);
2271 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2272 fib_index, &a, mp->is_static);
2274 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2278 BAD_SW_IF_INDEX_LABEL;
2281 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2285 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2288 vpe_main_t *rm = &vpe_main;
2289 ip4_main_t *im4 = &ip4_main;
2290 ip6_main_t *im6 = &ip6_main;
2291 ip_lookup_main_t * lm;
2296 u32 adj_index, sw_if_index;
2297 vl_api_is_address_reachable_t *rmp;
2298 ip_adjacency_t * adj;
2299 unix_shared_memory_queue_t *q;
2301 q = vl_api_client_index_to_input_queue (mp->client_index);
2303 increment_missing_api_client_counter (rm->vlib_main);
2307 rmp = vl_msg_api_alloc (sizeof (*rmp));
2308 clib_memcpy (rmp, mp, sizeof (*rmp));
2310 sw_if_index = mp->next_hop_sw_if_index;
2311 clib_memcpy (&addr, mp->address, sizeof (addr));
2313 lm = &im6->lookup_main;
2315 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2317 lm = &im4->lookup_main;
2319 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2321 if (adj_index == ~0) {
2325 adj = ip_get_adjacency (lm, adj_index);
2327 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2328 && adj->rewrite_header.sw_if_index == sw_if_index) {
2331 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2332 && adj->rewrite_header.sw_if_index == sw_if_index) {
2334 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2336 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2337 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2345 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2349 static void vl_api_sw_interface_details_t_handler (
2350 vl_api_sw_interface_details_t * mp)
2352 clib_warning ("BUG");
2355 static void vl_api_sw_interface_set_flags_t_handler (
2356 vl_api_sw_interface_set_flags_t * mp)
2358 vl_api_sw_interface_set_flags_reply_t *rmp;
2359 vnet_main_t * vnm = vnet_get_main();
2361 clib_error_t * error;
2364 VALIDATE_SW_IF_INDEX(mp);
2366 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2368 error = vnet_sw_interface_set_flags (vnm,
2369 ntohl(mp->sw_if_index),
2373 clib_error_report (error);
2376 BAD_SW_IF_INDEX_LABEL;
2377 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2380 static void vl_api_sw_interface_clear_stats_t_handler (
2381 vl_api_sw_interface_clear_stats_t * mp)
2383 vl_api_sw_interface_clear_stats_reply_t *rmp;
2385 vnet_main_t * vnm = vnet_get_main();
2386 vnet_interface_main_t * im = &vnm->interface_main;
2387 vlib_simple_counter_main_t * sm;
2388 vlib_combined_counter_main_t * cm;
2389 static vnet_main_t ** my_vnet_mains;
2390 int i, j, n_counters;
2394 vec_reset_length (my_vnet_mains);
2396 for (i = 0; i < vec_len (vnet_mains); i++)
2399 vec_add1 (my_vnet_mains, vnet_mains[i]);
2402 if (vec_len (vnet_mains) == 0)
2403 vec_add1 (my_vnet_mains, vnm);
2405 n_counters = vec_len (im->combined_sw_if_counters);
2407 for (j = 0; j < n_counters; j++)
2409 for (i = 0; i < vec_len(my_vnet_mains); i++)
2411 im = &my_vnet_mains[i]->interface_main;
2412 cm = im->combined_sw_if_counters + j;
2413 if (mp->sw_if_index == (u32)~0)
2414 vlib_clear_combined_counters (cm);
2416 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2420 n_counters = vec_len (im->sw_if_counters);
2422 for (j = 0; j < n_counters; j++)
2424 for (i = 0; i < vec_len(my_vnet_mains); i++)
2426 im = &my_vnet_mains[i]->interface_main;
2427 sm = im->sw_if_counters + j;
2428 if (mp->sw_if_index == (u32)~0)
2429 vlib_clear_simple_counters (sm);
2431 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2435 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2438 static void send_sw_interface_details (vpe_api_main_t * am,
2439 unix_shared_memory_queue_t *q,
2440 vnet_sw_interface_t * swif,
2441 u8 * interface_name,
2444 vl_api_sw_interface_details_t * mp;
2445 vnet_hw_interface_t * hi;
2447 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2449 mp = vl_msg_api_alloc (sizeof (*mp));
2450 memset (mp, 0, sizeof (*mp));
2451 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2452 mp->sw_if_index = ntohl(swif->sw_if_index);
2453 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2454 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2456 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2458 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2459 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2460 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2461 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2462 mp->link_mtu = ntohs(hi->max_packet_bytes);
2463 mp->context = context;
2465 strncpy ((char *) mp->interface_name,
2466 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2468 /* Send the L2 address for ethernet physical intfcs */
2469 if (swif->sup_sw_if_index == swif->sw_if_index
2470 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2471 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2472 ethernet_interface_t *ei;
2474 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2475 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2476 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2477 mp->l2_address_length = ntohl(sizeof (ei->address));
2478 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2479 vnet_sub_interface_t *sub = &swif->sub;
2480 mp->sub_id = ntohl(sub->id);
2481 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2482 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2483 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2484 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2485 mp->sub_exact_match = sub->eth.flags.exact_match;
2486 mp->sub_default = sub->eth.flags.default_sub;
2487 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2488 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2490 /* vlan tag rewrite data */
2491 u32 vtr_op = L2_VTR_DISABLED;
2492 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2494 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2495 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2496 // error - default to disabled
2497 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2498 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2501 mp->vtr_op = ntohl(vtr_op);
2502 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2503 mp->vtr_tag1 = ntohl(vtr_tag1);
2504 mp->vtr_tag2 = ntohl(vtr_tag2);
2508 vl_msg_api_send_shmem (q, (u8 *)&mp);
2511 static void send_sw_interface_flags (vpe_api_main_t * am,
2512 unix_shared_memory_queue_t *q,
2513 vnet_sw_interface_t * swif)
2515 vl_api_sw_interface_set_flags_t *mp;
2516 vnet_main_t * vnm = am->vnet_main;
2518 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2520 mp = vl_msg_api_alloc (sizeof (*mp));
2521 memset (mp, 0, sizeof (*mp));
2522 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2523 mp->sw_if_index = ntohl(swif->sw_if_index);
2525 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2527 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2529 vl_msg_api_send_shmem (q, (u8 *)&mp);
2532 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2533 unix_shared_memory_queue_t *q,
2535 __attribute__((unused));
2537 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2538 unix_shared_memory_queue_t *q,
2541 vl_api_sw_interface_set_flags_t *mp;
2543 mp = vl_msg_api_alloc (sizeof (*mp));
2544 memset (mp, 0, sizeof (*mp));
2545 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2546 mp->sw_if_index = ntohl(sw_if_index);
2548 mp->admin_up_down = 0;
2549 mp->link_up_down = 0;
2551 vl_msg_api_send_shmem (q, (u8 *)&mp);
2554 static void vl_api_sw_interface_dump_t_handler (
2555 vl_api_sw_interface_dump_t *mp)
2557 vpe_api_main_t * am = &vpe_api_main;
2558 vnet_sw_interface_t * swif;
2559 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2560 u8 * filter_string = 0, * name_string = 0;
2561 unix_shared_memory_queue_t * q;
2562 char * strcasestr (char *, char *); /* lnx hdr file botch */
2564 q = vl_api_client_index_to_input_queue (mp->client_index);
2569 if (mp->name_filter_valid) {
2570 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2571 filter_string = format (0, "%s%c", mp->name_filter, 0);
2574 pool_foreach (swif, im->sw_interfaces,
2576 name_string = format (name_string, "%U%c",
2577 format_vnet_sw_interface_name,
2578 am->vnet_main, swif, 0);
2580 if (mp->name_filter_valid == 0 ||
2581 strcasestr((char *) name_string, (char *) filter_string)) {
2583 send_sw_interface_details (am, q, swif, name_string, mp->context);
2584 send_sw_interface_flags (am, q, swif);
2586 _vec_len (name_string) = 0;
2589 vec_free (name_string);
2590 vec_free (filter_string);
2593 void send_oam_event (oam_target_t * t)
2595 vpe_api_main_t * vam = &vpe_api_main;
2596 unix_shared_memory_queue_t * q;
2597 vpe_client_registration_t *reg;
2598 vl_api_oam_event_t * mp;
2600 pool_foreach(reg, vam->oam_events_registrations,
2602 q = vl_api_client_index_to_input_queue (reg->client_index);
2604 mp = vl_msg_api_alloc (sizeof (*mp));
2605 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2606 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2607 mp->state = t->state;
2608 vl_msg_api_send_shmem (q, (u8 *)&mp);
2614 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2616 vl_api_oam_add_del_reply_t * rmp;
2619 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2620 (ip4_address_t *)mp->dst_address,
2624 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2628 vl_api_vnet_get_summary_stats_t_handler (
2629 vl_api_vnet_get_summary_stats_t *mp)
2631 stats_main_t * sm = &stats_main;
2632 vnet_interface_main_t * im = sm->interface_main;
2633 vl_api_vnet_summary_stats_reply_t *rmp;
2634 vlib_combined_counter_main_t * cm;
2637 u64 total_pkts[VLIB_N_RX_TX];
2638 u64 total_bytes[VLIB_N_RX_TX];
2640 unix_shared_memory_queue_t * q =
2641 vl_api_client_index_to_input_queue (mp->client_index);
2646 rmp = vl_msg_api_alloc (sizeof (*rmp));
2647 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2648 rmp->context = mp->context;
2651 memset (total_pkts, 0, sizeof (total_pkts));
2652 memset (total_bytes, 0, sizeof (total_bytes));
2654 vnet_interface_counter_lock (im);
2656 vec_foreach (cm, im->combined_sw_if_counters) {
2657 which = cm - im->combined_sw_if_counters;
2659 for (i = 0; i < vec_len (cm->maxi); i++) {
2660 vlib_get_combined_counter (cm, i, &v);
2661 total_pkts[which] += v.packets;
2662 total_bytes[which] += v.bytes;
2665 vnet_interface_counter_unlock (im);
2667 /* Note: in HOST byte order! */
2668 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2669 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2670 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2671 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2672 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2674 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2677 typedef CLIB_PACKED (struct {
2678 ip4_address_t address;
2680 u32 address_length : 6;
2685 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2687 vnet_main_t * vnm = vnet_get_main();
2688 vnet_interface_main_t * im = &vnm->interface_main;
2689 ip4_main_t * im4 = &ip4_main;
2690 static ip4_route_t * routes;
2691 static u32 * sw_if_indices_to_shut;
2692 stats_main_t * sm = &stats_main;
2697 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2698 u32 target_fib_id = ntohl(mp->vrf_id);
2700 dslock (sm, 1 /* release hint */, 8 /* tag */);
2702 vec_foreach (fib, im4->fibs) {
2703 vnet_sw_interface_t * si;
2705 if (fib->table_id != target_fib_id)
2708 /* remove any mpls/gre tunnels in this fib */
2709 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2711 /* remove any mpls encap/decap labels */
2712 mpls_fib_reset_labels (fib->table_id);
2714 /* remove any proxy arps in this fib */
2715 vnet_proxy_arp_fib_reset (fib->table_id);
2717 /* Set the flow hash for this fib to the default */
2718 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2720 vec_reset_length (sw_if_indices_to_shut);
2722 /* Shut down interfaces in this FIB / clean out intfc routes */
2723 pool_foreach (si, im->sw_interfaces,
2725 u32 sw_if_index = si->sw_if_index;
2727 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2728 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2730 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2733 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2734 sw_if_index = sw_if_indices_to_shut[i];
2735 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2737 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2738 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2739 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2742 vec_reset_length (routes);
2744 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2745 uword * hash = fib->adj_index_by_dst_address[i];
2749 x.address_length = i;
2751 hash_foreach_pair (p, hash,
2753 x.address.data_u32 = p->key;
2754 vec_add1 (routes, x);
2758 vec_foreach (r, routes) {
2759 ip4_add_del_route_args_t a;
2761 memset (&a, 0, sizeof (a));
2762 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2763 a.table_index_or_table_id = fib - im4->fibs;
2764 a.dst_address = r->address;
2765 a.dst_address_length = r->address_length;
2768 ip4_add_del_route (im4, &a);
2769 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2770 IP4_ROUTE_FLAG_FIB_INDEX);
2774 } /* vec_foreach (fib) */
2781 ip6_address_t address;
2788 ip6_route_t ** routep;
2789 } add_routes_in_fib_arg_t;
2791 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2793 add_routes_in_fib_arg_t * ap = arg;
2795 if (kvp->key[2]>>32 == ap->fib_index)
2797 ip6_address_t *addr;
2799 addr = (ip6_address_t *) kvp;
2800 vec_add2 (*ap->routep, r, 1);
2801 r->address = addr[0];
2802 r->address_length = kvp->key[2] & 0xFF;
2803 r->index = kvp->value;
2807 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2809 vnet_main_t * vnm = vnet_get_main();
2810 vnet_interface_main_t * im = &vnm->interface_main;
2811 ip6_main_t * im6 = &ip6_main;
2812 stats_main_t * sm = &stats_main;
2813 static ip6_route_t * routes;
2814 static u32 * sw_if_indices_to_shut;
2819 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2820 u32 target_fib_id = ntohl(mp->vrf_id);
2821 add_routes_in_fib_arg_t _a, *a=&_a;
2822 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2824 dslock (sm, 1 /* release hint */, 9 /* tag */);
2826 vec_foreach (fib, im6->fibs) {
2827 vnet_sw_interface_t * si;
2829 if (fib->table_id != target_fib_id)
2832 vec_reset_length (sw_if_indices_to_shut);
2834 /* Shut down interfaces in this FIB / clean out intfc routes */
2835 pool_foreach (si, im->sw_interfaces,
2837 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2839 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2842 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2843 sw_if_index = sw_if_indices_to_shut[i];
2844 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2846 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2847 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2848 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2851 vec_reset_length (routes);
2853 a->fib_index = fib - im6->fibs;
2854 a->routep = &routes;
2856 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2858 vec_foreach (r, routes) {
2859 ip6_add_del_route_args_t a;
2861 memset (&a, 0, sizeof (a));
2862 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2863 a.table_index_or_table_id = fib - im6->fibs;
2864 a.dst_address = r->address;
2865 a.dst_address_length = r->address_length;
2868 ip6_add_del_route (im6, &a);
2869 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2870 IP6_ROUTE_FLAG_FIB_INDEX);
2873 /* Reinstall the neighbor / router discovery routes */
2874 vnet_ip6_fib_init (im6, fib - im6->fibs);
2876 } /* vec_foreach (fib) */
2882 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2885 vl_api_reset_fib_reply_t * rmp;
2888 rv = ip6_reset_fib_t_handler (mp);
2890 rv = ip4_reset_fib_t_handler (mp);
2892 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2897 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2899 vl_api_dhcp_proxy_config_reply_t * rmp;
2902 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2903 (ip4_address_t *)(&mp->dhcp_src_address),
2904 (u32) ntohl(mp->vrf_id),
2905 (int) mp->insert_circuit_id,
2906 (int) (mp->is_add == 0));
2908 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2913 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2915 vl_api_dhcp_proxy_config_reply_t * rmp;
2918 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2919 (ip6_address_t *)(&mp->dhcp_src_address),
2920 (u32) ntohl(mp->vrf_id),
2921 (int) mp->insert_circuit_id,
2922 (int) (mp->is_add == 0));
2924 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2928 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2930 vl_api_dhcp_proxy_config_reply_t * rmp;
2933 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2934 (ip4_address_t *)(&mp->dhcp_src_address),
2935 (u32) ntohl(mp->rx_vrf_id),
2936 (u32) ntohl(mp->server_vrf_id),
2937 (int) mp->insert_circuit_id,
2938 (int) (mp->is_add == 0));
2940 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2945 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2947 vl_api_dhcp_proxy_config_reply_t * rmp;
2951 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2952 (ip6_address_t *)(&mp->dhcp_src_address),
2953 (u32) ntohl(mp->rx_vrf_id),
2954 (u32) ntohl(mp->server_vrf_id),
2955 (int) mp->insert_circuit_id,
2956 (int) (mp->is_add == 0));
2958 rv = VNET_API_ERROR_UNIMPLEMENTED;
2961 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2966 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2968 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2971 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2974 (int)mp->is_add == 0);
2976 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2979 (int)mp->is_add == 0);
2981 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2985 static void vl_api_dhcp_proxy_config_t_handler
2986 (vl_api_dhcp_proxy_config_t *mp)
2988 if (mp->is_ipv6 == 0)
2989 dhcpv4_proxy_config (mp);
2991 dhcpv6_proxy_config (mp);
2994 static void vl_api_dhcp_proxy_config_2_t_handler
2995 (vl_api_dhcp_proxy_config_2_t *mp)
2997 if (mp->is_ipv6 == 0)
2998 dhcpv4_proxy_config_2 (mp);
3000 dhcpv6_proxy_config_2 (mp);
3003 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3004 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3006 unix_shared_memory_queue_t * q;
3007 vl_api_dhcp_compl_event_t * mp;
3009 q = vl_api_client_index_to_input_queue (client_index);
3013 mp = vl_msg_api_alloc (sizeof (*mp));
3014 mp->client_index = client_index;
3016 mp->is_ipv6 = is_ipv6;
3017 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3018 mp->hostname[vec_len(hostname) + 1] = '\n';
3019 clib_memcpy (&mp->host_address[0], host_address, 16);
3020 clib_memcpy (&mp->router_address[0], router_address, 16);
3021 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3023 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3025 vl_msg_api_send_shmem (q, (u8 *)&mp);
3028 static void vl_api_dhcp_client_config_t_handler
3029 (vl_api_dhcp_client_config_t *mp)
3031 vlib_main_t *vm = vlib_get_main();
3032 vl_api_dhcp_client_config_reply_t * rmp;
3035 VALIDATE_SW_IF_INDEX(mp);
3037 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3038 mp->hostname, mp->is_add, mp->client_index,
3039 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3042 BAD_SW_IF_INDEX_LABEL;
3044 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3048 vl_api_sw_interface_ip6nd_ra_config_t_handler
3049 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3051 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3053 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3055 is_no = mp->is_no == 1;
3056 surpress = mp->surpress == 1;
3057 managed = mp->managed == 1;
3058 other = mp->other == 1;
3059 ll_option = mp->ll_option == 1;
3060 send_unicast = mp->send_unicast == 1;
3061 cease = mp->cease == 1;
3062 default_router = mp->default_router == 1;
3064 VALIDATE_SW_IF_INDEX(mp);
3066 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3067 surpress, managed, other,
3068 ll_option, send_unicast, cease,
3069 default_router, ntohl (mp->lifetime),
3070 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3071 ntohl(mp->max_interval), ntohl( mp->min_interval),
3074 BAD_SW_IF_INDEX_LABEL;
3076 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3080 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3081 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3083 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3085 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3087 VALIDATE_SW_IF_INDEX(mp);
3089 is_no = mp->is_no == 1;
3090 use_default = mp->use_default == 1;
3091 no_advertise = mp->no_advertise == 1;
3092 off_link = mp->off_link == 1;
3093 no_autoconfig = mp->no_autoconfig == 1;
3094 no_onlink = mp->no_onlink == 1;
3096 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3097 (ip6_address_t *)mp->address, mp->address_length,
3098 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3099 no_advertise, off_link, no_autoconfig, no_onlink,
3102 BAD_SW_IF_INDEX_LABEL;
3103 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3107 vl_api_sw_interface_ip6_enable_disable_t_handler
3108 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3110 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3111 vnet_main_t * vnm = vnet_get_main();
3113 clib_error_t * error;
3117 VALIDATE_SW_IF_INDEX(mp);
3119 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3120 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3123 clib_error_report(error);
3124 rv = VNET_API_ERROR_UNSPECIFIED;
3126 rv = vnm->api_errno;
3129 BAD_SW_IF_INDEX_LABEL;
3131 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3135 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3136 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3138 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3140 clib_error_t * error;
3141 vnet_main_t * vnm = vnet_get_main();
3145 VALIDATE_SW_IF_INDEX(mp);
3147 error = set_ip6_link_local_address(vm,
3148 ntohl(mp->sw_if_index),
3149 (ip6_address_t *)mp->address,
3150 mp->address_length);
3152 clib_error_report(error);
3153 rv = VNET_API_ERROR_UNSPECIFIED;
3155 rv = vnm->api_errno;
3158 BAD_SW_IF_INDEX_LABEL;
3160 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3163 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3165 vl_api_set_ip_flow_hash_reply_t *rmp;
3166 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3168 clib_warning ("unimplemented...");
3170 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3173 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3175 vl_api_set_ip_flow_hash_reply_t *rmp;
3178 u32 flow_hash_config = 0;
3180 table_id = ntohl(mp->vrf_id);
3182 #define _(a,b) if (mp->a) flow_hash_config |= b;
3183 foreach_flow_hash_bit;
3186 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3188 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3192 static void vl_api_set_ip_flow_hash_t_handler
3193 (vl_api_set_ip_flow_hash_t *mp)
3195 if (mp->is_ipv6 == 0)
3196 set_ip4_flow_hash (mp);
3198 set_ip6_flow_hash (mp);
3201 static void vl_api_sw_interface_set_unnumbered_t_handler
3202 (vl_api_sw_interface_set_unnumbered_t *mp)
3204 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3206 vnet_sw_interface_t * si;
3207 vnet_main_t *vnm = vnet_get_main();
3208 u32 sw_if_index, unnumbered_sw_if_index;
3210 sw_if_index = ntohl(mp->sw_if_index);
3211 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3214 * The API message field names are backwards from
3215 * the underlying data structure names.
3216 * It's not worth changing them now.
3218 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3219 unnumbered_sw_if_index)) {
3220 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3224 /* Only check the "use loop0" field when setting the binding */
3226 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3227 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3231 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3234 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3235 si->unnumbered_sw_if_index = sw_if_index;
3237 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3238 si->unnumbered_sw_if_index = (u32)~0;
3242 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3245 static void vl_api_create_loopback_t_handler
3246 (vl_api_create_loopback_t *mp)
3248 vl_api_create_loopback_reply_t * rmp;
3252 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3254 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3256 rmp->sw_if_index = ntohl (sw_if_index);
3260 static void vl_api_delete_loopback_t_handler
3261 (vl_api_delete_loopback_t *mp)
3263 vl_api_delete_loopback_reply_t * rmp;
3267 sw_if_index = ntohl (mp->sw_if_index);
3268 rv = vnet_delete_loopback_interface (sw_if_index);
3270 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3273 static void vl_api_control_ping_t_handler
3274 (vl_api_control_ping_t *mp)
3276 vl_api_control_ping_reply_t * rmp;
3279 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3281 rmp->vpe_pid = ntohl (getpid());
3285 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3287 u8 **shmem_vecp = (u8 **)arg;
3290 api_main_t * am = &api_main;
3293 shmem_vec = *shmem_vecp;
3295 offset = vec_len (shmem_vec);
3297 pthread_mutex_lock (&am->vlib_rp->mutex);
3298 oldheap = svm_push_data_heap (am->vlib_rp);
3300 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3302 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3304 svm_pop_heap (oldheap);
3305 pthread_mutex_unlock (&am->vlib_rp->mutex);
3307 *shmem_vecp = shmem_vec;
3311 static void vl_api_cli_request_t_handler
3312 (vl_api_cli_request_t *mp)
3314 vl_api_cli_reply_t *rp;
3315 unix_shared_memory_queue_t *q;
3316 vlib_main_t * vm = vlib_get_main();
3317 api_main_t * am = &api_main;
3318 unformat_input_t input;
3322 q = vl_api_client_index_to_input_queue (mp->client_index);
3326 rp = vl_msg_api_alloc (sizeof (*rp));
3327 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3328 rp->context = mp->context;
3330 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3332 vlib_cli_input (vm, &input, shmem_cli_output,
3335 pthread_mutex_lock (&am->vlib_rp->mutex);
3336 oldheap = svm_push_data_heap (am->vlib_rp);
3338 vec_add1(shmem_vec, 0);
3340 svm_pop_heap (oldheap);
3341 pthread_mutex_unlock (&am->vlib_rp->mutex);
3343 rp->reply_in_shmem = (uword)shmem_vec;
3345 vl_msg_api_send_shmem (q, (u8 *)&rp);
3348 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3351 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3352 vnet_main_t *vnm = vnet_get_main();
3353 clib_error_t * error;
3358 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3360 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3363 clib_error_report(error);
3364 rv = VNET_API_ERROR_UNSPECIFIED;
3366 rv = vnm->api_errno;
3369 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3372 static void vl_api_sr_tunnel_add_del_t_handler
3373 (vl_api_sr_tunnel_add_del_t *mp)
3376 clib_warning ("unimplemented");
3378 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3380 vl_api_sr_tunnel_add_del_reply_t * rmp;
3381 ip6_address_t * segments = 0, * seg;
3382 ip6_address_t * tags = 0, *tag;
3383 ip6_address_t * this_address;
3386 if (mp->n_segments == 0) {
3391 memset (a, 0, sizeof (*a));
3392 a->src_address = (ip6_address_t *)&mp->src_address;
3393 a->dst_address = (ip6_address_t *)&mp->dst_address;
3394 a->dst_mask_width = mp->dst_mask_width;
3395 a->flags_net_byte_order = mp->flags_net_byte_order;
3396 a->is_del = (mp->is_add == 0);
3397 a->rx_table_id = ntohl(mp->outer_vrf_id);
3398 a->tx_table_id = ntohl(mp->inner_vrf_id);
3400 a->name = format(0, "%s", mp->name);
3401 if (!(vec_len(a->name)))
3404 a->policy_name = format(0, "%s", mp->policy_name);
3405 if (!(vec_len(a->policy_name)))
3408 /* Yank segments and tags out of the API message */
3409 this_address = (ip6_address_t *)mp->segs_and_tags;
3410 for (i = 0; i < mp->n_segments; i++) {
3411 vec_add2 (segments, seg, 1);
3412 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3415 for (i = 0; i < mp->n_tags; i++) {
3416 vec_add2 (tags, tag, 1);
3417 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3421 a->segments = segments;
3424 rv = ip6_sr_add_del_tunnel (a);
3428 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3432 static void vl_api_sr_policy_add_del_t_handler
3433 (vl_api_sr_policy_add_del_t *mp)
3436 clib_warning ("unimplemented");
3438 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3440 vl_api_sr_policy_add_del_reply_t * rmp;
3443 memset (a, 0, sizeof (*a));
3444 a->is_del = (mp->is_add == 0);
3446 a->name = format(0, "%s", mp->name);
3447 if (!(vec_len(a->name)))
3449 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3453 if (!(mp->tunnel_names))
3455 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3459 // start deserializing tunnel_names
3460 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3461 u8 * deser_tun_names = mp->tunnel_names;
3462 deser_tun_names += 1; //moving along
3465 int tun_name_len = 0;
3467 for (i=0; i < num_tunnels; i++)
3469 tun_name_len= *deser_tun_names;
3470 deser_tun_names += 1;
3471 vec_resize (tun_name, tun_name_len);
3472 memcpy(tun_name, deser_tun_names, tun_name_len);
3473 vec_add1 (a->tunnel_names, tun_name);
3474 deser_tun_names += tun_name_len;
3478 rv = ip6_sr_add_del_policy (a);
3482 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3486 static void vl_api_sr_multicast_map_add_del_t_handler
3487 (vl_api_sr_multicast_map_add_del_t *mp)
3490 clib_warning ("unimplemented");
3492 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3494 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3496 memset (a, 0, sizeof (*a));
3497 a->is_del = (mp->is_add == 0);
3499 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3500 a->policy_name = format(0, "%s", mp->policy_name);
3502 if (a->multicast_address == 0)
3508 if (!(a->policy_name))
3514 #if DPDK > 0 /* Cannot call replicate without DPDK */
3515 rv = ip6_sr_add_del_multicastmap (a);
3517 clib_warning ("multicast replication without DPDK not implemented");
3518 rv = VNET_API_ERROR_UNIMPLEMENTED;
3523 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3527 #define foreach_classify_add_del_table_field \
3532 _(match_n_vectors) \
3533 _(next_table_index) \
3536 static void vl_api_classify_add_del_table_t_handler
3537 (vl_api_classify_add_del_table_t * mp)
3539 vl_api_classify_add_del_table_reply_t * rmp;
3540 vnet_classify_main_t * cm = &vnet_classify_main;
3541 vnet_classify_table_t * t;
3545 foreach_classify_add_del_table_field;
3548 #define _(a) a = ntohl(mp->a);
3549 foreach_classify_add_del_table_field;
3552 /* The underlying API fails silently, on purpose, so check here */
3553 if (mp->is_add == 0)
3554 if (pool_is_free_index (cm->tables, table_index)) {
3555 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3559 rv = vnet_classify_add_del_table
3560 (cm, mp->mask, nbuckets, memory_size,
3561 skip_n_vectors, match_n_vectors,
3562 next_table_index, miss_next_index,
3563 &table_index, mp->is_add);
3566 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3568 if (rv == 0 && mp->is_add) {
3569 t = pool_elt_at_index (cm->tables, table_index);
3570 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3571 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3572 rmp->new_table_index = ntohl(table_index);
3574 rmp->skip_n_vectors = ~0;
3575 rmp->match_n_vectors = ~0;
3576 rmp->new_table_index = ~0;
3581 static void vl_api_classify_add_del_session_t_handler
3582 (vl_api_classify_add_del_session_t * mp)
3584 vnet_classify_main_t * cm = &vnet_classify_main;
3585 vl_api_classify_add_del_session_reply_t * rmp;
3587 u32 table_index, hit_next_index, opaque_index;
3590 table_index = ntohl (mp->table_index);
3591 hit_next_index = ntohl (mp->hit_next_index);
3592 opaque_index = ntohl (mp->opaque_index);
3593 advance = ntohl (mp->advance);
3595 rv = vnet_classify_add_del_session
3596 (cm, table_index, mp->match, hit_next_index, opaque_index,
3597 advance, mp->is_add);
3599 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3602 static void vl_api_classify_set_interface_ip_table_t_handler
3603 (vl_api_classify_set_interface_ip_table_t * mp)
3605 vlib_main_t * vm = vlib_get_main();
3606 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3608 u32 table_index, sw_if_index;
3610 table_index = ntohl (mp->table_index);
3611 sw_if_index = ntohl (mp->sw_if_index);
3613 VALIDATE_SW_IF_INDEX(mp);
3616 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3618 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3620 BAD_SW_IF_INDEX_LABEL;
3622 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3625 static void vl_api_classify_set_interface_l2_tables_t_handler
3626 (vl_api_classify_set_interface_l2_tables_t * mp)
3628 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3630 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3633 ip4_table_index = ntohl(mp->ip4_table_index);
3634 ip6_table_index = ntohl(mp->ip6_table_index);
3635 other_table_index = ntohl(mp->other_table_index);
3636 sw_if_index = ntohl(mp->sw_if_index);
3638 VALIDATE_SW_IF_INDEX(mp);
3640 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3641 ip6_table_index, other_table_index);
3644 if (ip4_table_index != ~0 || ip6_table_index != ~0
3645 || other_table_index != ~0)
3650 vnet_l2_classify_enable_disable (sw_if_index, enable);
3653 BAD_SW_IF_INDEX_LABEL;
3655 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3659 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3662 vl_api_l2_fib_clear_table_reply_t * rmp;
3664 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3665 * that is not currently implemented. When that TODO is fixed
3666 * this call should be changed to pass 1 instead of 0.
3668 l2fib_clear_table (0);
3670 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3673 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3678 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3681 vl_api_l2_interface_efp_filter_reply_t * rmp;
3682 vnet_main_t *vnm = vnet_get_main();
3684 // enable/disable the feature
3685 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3686 rv = vnm->api_errno;
3688 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3692 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3695 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3696 vnet_main_t * vnm = vnet_get_main();
3697 vlib_main_t * vm = vlib_get_main();
3700 VALIDATE_SW_IF_INDEX(mp);
3702 vtr_op = ntohl(mp->vtr_op);
3704 /* The L2 code is unsuspicious */
3706 case L2_VTR_DISABLED:
3711 case L2_VTR_TRANSLATE_1_1:
3712 case L2_VTR_TRANSLATE_1_2:
3713 case L2_VTR_TRANSLATE_2_1:
3714 case L2_VTR_TRANSLATE_2_2:
3718 rv = VNET_API_ERROR_INVALID_VALUE;
3719 goto bad_sw_if_index;
3722 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3723 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3726 BAD_SW_IF_INDEX_LABEL;
3728 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3732 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3736 vl_api_create_vhost_user_if_reply_t * rmp;
3737 u32 sw_if_index = (u32)~0;
3739 vnet_main_t * vnm = vnet_get_main();
3740 vlib_main_t * vm = vlib_get_main();
3742 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3743 mp->is_server, &sw_if_index, (u64)~0,
3744 mp->renumber, ntohl(mp->custom_dev_instance),
3745 (mp->use_custom_mac)?mp->mac_address:NULL);
3747 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3749 rmp->sw_if_index = ntohl (sw_if_index);
3755 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3759 vl_api_modify_vhost_user_if_reply_t * rmp;
3760 u32 sw_if_index = ntohl(mp->sw_if_index);
3762 vnet_main_t * vnm = vnet_get_main();
3763 vlib_main_t * vm = vlib_get_main();
3765 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3766 mp->is_server, sw_if_index, (u64)~0,
3767 mp->renumber, ntohl(mp->custom_dev_instance));
3769 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3774 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3778 vpe_api_main_t * vam = &vpe_api_main;
3779 vl_api_delete_vhost_user_if_reply_t * rmp;
3780 u32 sw_if_index = ntohl(mp->sw_if_index);
3782 vnet_main_t * vnm = vnet_get_main();
3783 vlib_main_t * vm = vlib_get_main();
3785 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3787 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3789 unix_shared_memory_queue_t * q =
3790 vl_api_client_index_to_input_queue (mp->client_index);
3794 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3799 static void vl_api_sw_interface_vhost_user_details_t_handler (
3800 vl_api_sw_interface_vhost_user_details_t * mp)
3802 clib_warning ("BUG");
3806 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3807 unix_shared_memory_queue_t *q,
3808 vhost_user_intf_details_t * vui,
3811 vl_api_sw_interface_vhost_user_details_t * mp;
3813 mp = vl_msg_api_alloc (sizeof (*mp));
3814 memset (mp, 0, sizeof (*mp));
3815 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3816 mp->sw_if_index = ntohl(vui->sw_if_index);
3817 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3818 mp->features = clib_net_to_host_u64 (vui->features);
3819 mp->is_server = vui->is_server;
3820 mp->num_regions = ntohl(vui->num_regions);
3821 mp->sock_errno = ntohl(vui->sock_errno);
3822 mp->context = context;
3824 strncpy ((char *) mp->sock_filename,
3825 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3826 strncpy ((char *) mp->interface_name,
3827 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3829 vl_msg_api_send_shmem (q, (u8 *)&mp);
3834 vl_api_sw_interface_vhost_user_dump_t_handler (
3835 vl_api_sw_interface_vhost_user_dump_t *mp)
3839 vpe_api_main_t * am = &vpe_api_main;
3840 vnet_main_t * vnm = vnet_get_main();
3841 vlib_main_t * vm = vlib_get_main();
3842 vhost_user_intf_details_t *ifaces = NULL;
3843 vhost_user_intf_details_t *vuid = NULL;
3844 unix_shared_memory_queue_t * q;
3846 q = vl_api_client_index_to_input_queue (mp->client_index);
3850 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3854 vec_foreach (vuid, ifaces) {
3855 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3861 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3862 unix_shared_memory_queue_t *q,
3867 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3868 u8 * if_name = NULL;
3869 vnet_sw_interface_t * si = NULL;
3871 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3873 if_name = format(if_name, "%U",
3874 format_vnet_sw_interface_name, lm->vnet_main, si);
3876 mp = vl_msg_api_alloc (sizeof (*mp));
3877 memset (mp, 0, sizeof (*mp));
3878 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3879 strncpy((char *)mp->interface_name,
3880 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3881 mp->sw_if_index = ntohl(si->sw_if_index);
3882 mp->local_session_id = s->local_session_id;
3883 mp->remote_session_id = s->remote_session_id;
3884 mp->local_cookie[0] = s->local_cookie[0];
3885 mp->local_cookie[1] = s->local_cookie[1];
3886 mp->remote_cookie = s->remote_cookie;
3887 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3888 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3889 mp->l2_sublayer_present = s->l2_sublayer_present;
3890 mp->context = context;
3892 vl_msg_api_send_shmem (q, (u8 *)&mp);
3895 static void send_ip_address_details (vpe_api_main_t * am,
3896 unix_shared_memory_queue_t * q,
3902 vl_api_ip_address_details_t * mp;
3904 mp = vl_msg_api_alloc (sizeof (*mp));
3905 memset (mp, 0, sizeof (*mp));
3906 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3909 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3911 u32 * tp = (u32 *)mp->ip;
3912 *tp = ntohl(*(u32*)ip);
3914 mp->prefix_length = prefix_length;
3915 mp->context = context;
3917 vl_msg_api_send_shmem (q, (u8 *)&mp);
3921 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3923 vpe_api_main_t * am = &vpe_api_main;
3924 unix_shared_memory_queue_t * q;
3927 ip6_main_t * im6 = &ip6_main;
3928 ip4_main_t * im4 = &ip4_main;
3929 ip_lookup_main_t * lm6 = &im6->lookup_main;
3930 ip_lookup_main_t * lm4 = &im4->lookup_main;
3931 ip_interface_address_t * ia = 0;
3932 u32 sw_if_index = ~0;
3933 int rv __attribute__ ((unused)) = 0;
3935 VALIDATE_SW_IF_INDEX(mp);
3937 sw_if_index = ntohl(mp->sw_if_index);
3939 q = vl_api_client_index_to_input_queue (mp->client_index);
3945 foreach_ip_interface_address (lm6, ia, sw_if_index,
3946 1 /* honor unnumbered */,
3948 r6 = ip_interface_address_get_address (lm6, ia);
3949 u16 prefix_length = ia->address_length;
3950 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3953 foreach_ip_interface_address (lm4, ia, sw_if_index,
3954 1 /* honor unnumbered */,
3956 r4 = ip_interface_address_get_address (lm4, ia);
3957 u16 prefix_length = ia->address_length;
3958 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3961 BAD_SW_IF_INDEX_LABEL;
3964 static void send_ip_details (vpe_api_main_t * am,
3965 unix_shared_memory_queue_t *q,
3969 vl_api_ip_details_t * mp;
3971 mp = vl_msg_api_alloc (sizeof (*mp));
3972 memset (mp, 0, sizeof (*mp));
3973 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3975 mp->sw_if_index = ntohl(sw_if_index);
3976 mp->context = context;
3978 vl_msg_api_send_shmem (q, (u8 *)&mp);
3982 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3983 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3985 vpe_api_main_t * am = &vpe_api_main;
3986 l2t_main_t * lm = &l2t_main;
3987 unix_shared_memory_queue_t * q;
3988 l2t_session_t *session;
3990 q = vl_api_client_index_to_input_queue (mp->client_index);
3994 pool_foreach (session, lm->sessions,
3996 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4001 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4002 unix_shared_memory_queue_t *q,
4003 tapcli_interface_details_t *tap_if,
4006 vl_api_sw_interface_tap_details_t * mp;
4007 mp = vl_msg_api_alloc (sizeof (*mp));
4008 memset (mp, 0, sizeof (*mp));
4009 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4010 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4011 strncpy((char *)mp->dev_name,
4012 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4013 mp->context = context;
4015 vl_msg_api_send_shmem (q, (u8 *)&mp);
4019 vl_api_sw_interface_tap_dump_t_handler (
4020 vl_api_sw_interface_tap_dump_t *mp)
4023 vpe_api_main_t * am = &vpe_api_main;
4024 unix_shared_memory_queue_t * q;
4025 tapcli_interface_details_t *tapifs = NULL;
4026 tapcli_interface_details_t *tap_if = NULL;
4028 q = vl_api_client_index_to_input_queue (mp->client_index);
4032 rv = vnet_tap_dump_ifs(&tapifs);
4036 vec_foreach(tap_if, tapifs) {
4037 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4044 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4046 vpe_api_main_t * am = &vpe_api_main;
4047 vnet_main_t * vnm = vnet_get_main();
4048 vlib_main_t * vm = vlib_get_main();
4049 vnet_interface_main_t * im = &vnm->interface_main;
4050 unix_shared_memory_queue_t * q;
4051 vnet_sw_interface_t * si, * sorted_sis;
4052 u32 sw_if_index = ~0;
4054 q = vl_api_client_index_to_input_queue (mp->client_index);
4059 /* Gather interfaces. */
4060 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4061 _vec_len (sorted_sis) = 0;
4062 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4064 vec_foreach (si, sorted_sis) {
4065 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4066 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4069 sw_if_index = si->sw_if_index;
4070 send_ip_details(am, q, sw_if_index, mp->context);
4075 static void vl_api_l2_fib_table_entry_t_handler (
4076 vl_api_l2_fib_table_entry_t * mp)
4078 clib_warning ("BUG");
4081 static void send_l2fib_table_entry (vpe_api_main_t * am,
4082 unix_shared_memory_queue_t *q,
4083 l2fib_entry_key_t * l2fe_key,
4084 l2fib_entry_result_t * l2fe_res,
4087 vl_api_l2_fib_table_entry_t * mp;
4089 mp = vl_msg_api_alloc (sizeof (*mp));
4090 memset (mp, 0, sizeof (*mp));
4091 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4093 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4095 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4096 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4097 mp->static_mac = l2fe_res->fields.static_mac;
4098 mp->filter_mac = l2fe_res->fields.filter;
4099 mp->bvi_mac = l2fe_res->fields.bvi;
4100 mp->context = context;
4102 vl_msg_api_send_shmem (q, (u8 *)&mp);
4106 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4108 vpe_api_main_t * am = &vpe_api_main;
4109 bd_main_t * bdm = &bd_main;
4110 l2fib_entry_key_t *l2fe_key = NULL;
4111 l2fib_entry_result_t *l2fe_res = NULL;
4112 u32 ni, bd_id = ntohl (mp->bd_id);
4114 unix_shared_memory_queue_t * q;
4117 q = vl_api_client_index_to_input_queue (mp->client_index);
4121 /* see l2fib_table_dump: ~0 means "any" */
4125 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4132 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4134 vec_foreach_index (ni, l2fe_key) {
4135 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4136 vec_elt_at_index(l2fe_res, ni), mp->context);
4143 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4145 vl_api_show_version_reply_t *rmp;
4147 char * vpe_api_get_build_directory(void);
4148 char * vpe_api_get_version(void);
4149 char * vpe_api_get_build_date(void);
4151 unix_shared_memory_queue_t * q =
4152 vl_api_client_index_to_input_queue (mp->client_index);
4157 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4159 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4160 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4161 ARRAY_LEN(rmp->build_directory)-1);
4162 strncpy ((char *) rmp->version, vpe_api_get_version(),
4163 ARRAY_LEN(rmp->version)-1);
4164 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4165 ARRAY_LEN(rmp->build_date)-1);
4169 static void vl_api_get_node_index_t_handler
4170 (vl_api_get_node_index_t * mp)
4172 vlib_main_t * vm = vlib_get_main();
4173 vl_api_get_node_index_reply_t * rmp;
4176 u32 node_index = ~0;
4178 n = vlib_get_node_by_name (vm, mp->node_name);
4181 rv = VNET_API_ERROR_NO_SUCH_NODE;
4183 node_index = n->index;
4185 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4187 rmp->node_index = ntohl(node_index);
4191 static void vl_api_add_node_next_t_handler
4192 (vl_api_add_node_next_t * mp)
4194 vlib_main_t * vm = vlib_get_main();
4195 vl_api_add_node_next_reply_t * rmp;
4196 vlib_node_t * n, * next;
4198 u32 next_index = ~0;
4200 n = vlib_get_node_by_name (vm, mp->node_name);
4203 rv = VNET_API_ERROR_NO_SUCH_NODE;
4207 next = vlib_get_node_by_name (vm, mp->next_name);
4210 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4212 next_index = vlib_node_add_next (vm, n->index, next->index);
4215 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4217 rmp->next_index = ntohl(next_index);
4221 static void vl_api_l2tpv3_create_tunnel_t_handler
4222 (vl_api_l2tpv3_create_tunnel_t *mp)
4224 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4225 l2t_main_t *lm = &l2t_main;
4226 u32 sw_if_index = (u32)~0;
4229 if (mp->is_ipv6 != 1) {
4230 rv = VNET_API_ERROR_UNIMPLEMENTED;
4234 rv = create_l2tpv3_ipv6_tunnel (lm,
4235 (ip6_address_t *) mp->client_address,
4236 (ip6_address_t *) mp->our_address,
4237 ntohl(mp->local_session_id),
4238 ntohl(mp->remote_session_id),
4239 clib_net_to_host_u64(mp->local_cookie),
4240 clib_net_to_host_u64(mp->remote_cookie),
4241 mp->l2_sublayer_present,
4245 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4247 rmp->sw_if_index = ntohl (sw_if_index);
4251 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4252 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4254 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4255 l2t_main_t *lm = &l2t_main;
4258 VALIDATE_SW_IF_INDEX(mp);
4260 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4261 clib_net_to_host_u64(mp->new_local_cookie),
4262 clib_net_to_host_u64(mp->new_remote_cookie));
4264 BAD_SW_IF_INDEX_LABEL;
4266 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4269 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4270 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4273 vnet_main_t * vnm = vnet_get_main();
4274 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4276 VALIDATE_SW_IF_INDEX(mp);
4278 rv = l2tpv3_interface_enable_disable
4279 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4281 BAD_SW_IF_INDEX_LABEL;
4283 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4286 static void vl_api_l2tpv3_set_lookup_key_t_handler
4287 (vl_api_l2tpv3_set_lookup_key_t * mp)
4290 l2t_main_t *lm = &l2t_main;
4291 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4293 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4294 rv = VNET_API_ERROR_INVALID_VALUE;
4298 lm->lookup_type = mp->key;
4301 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4304 static void vl_api_vxlan_add_del_tunnel_t_handler
4305 (vl_api_vxlan_add_del_tunnel_t * mp)
4307 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4309 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4310 u32 encap_fib_index;
4312 ip4_main_t * im = &ip4_main;
4313 u32 sw_if_index = ~0;
4315 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4317 rv = VNET_API_ERROR_NO_SUCH_FIB;
4320 encap_fib_index = p[0];
4322 /* Check src & dst are different */
4323 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4324 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4325 rv = VNET_API_ERROR_SAME_SRC_DST;
4328 memset (a, 0, sizeof (*a));
4330 a->is_add = mp->is_add;
4331 a->is_ip6 = mp->is_ipv6;
4333 /* ip addresses sent in network byte order */
4335 memcpy(&(a->src.ip6), mp->src_address, 16);
4336 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4338 memcpy(&(a->src.ip4), mp->src_address, 4);
4339 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4342 a->encap_fib_index = encap_fib_index;
4343 a->decap_next_index = ntohl(mp->decap_next_index);
4344 a->vni = ntohl(mp->vni);
4345 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4348 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4350 rmp->sw_if_index = ntohl (sw_if_index);
4354 static void send_vxlan_tunnel_details
4355 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4357 vl_api_vxlan_tunnel_details_t * rmp;
4358 ip4_main_t * im4 = &ip4_main;
4359 ip6_main_t * im6 = &ip6_main;
4360 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4362 rmp = vl_msg_api_alloc (sizeof (*rmp));
4363 memset (rmp, 0, sizeof (*rmp));
4364 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4366 memcpy(rmp->src_address, &(t->src.ip6), 16);
4367 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4368 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4370 memcpy(rmp->src_address, &(t->src.ip4), 4);
4371 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4372 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4374 rmp->vni = htonl(t->vni);
4375 rmp->decap_next_index = htonl(t->decap_next_index);
4376 rmp->sw_if_index = htonl(t->sw_if_index);
4377 rmp->is_ipv6 = is_ipv6;
4378 rmp->context = context;
4380 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4383 static void vl_api_vxlan_tunnel_dump_t_handler
4384 (vl_api_vxlan_tunnel_dump_t * mp)
4386 unix_shared_memory_queue_t * q;
4387 vxlan_main_t * vxm = &vxlan_main;
4391 q = vl_api_client_index_to_input_queue (mp->client_index);
4396 sw_if_index = ntohl(mp->sw_if_index);
4398 if (~0 == sw_if_index) {
4399 pool_foreach (t, vxm->tunnels,
4401 send_vxlan_tunnel_details(t, q, mp->context);
4404 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4405 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4408 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4409 send_vxlan_tunnel_details(t, q, mp->context);
4413 static void vl_api_gre_add_del_tunnel_t_handler
4414 (vl_api_gre_add_del_tunnel_t * mp)
4416 vl_api_gre_add_del_tunnel_reply_t * rmp;
4418 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4421 ip4_main_t * im = &ip4_main;
4422 u32 sw_if_index = ~0;
4424 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4426 rv = VNET_API_ERROR_NO_SUCH_FIB;
4429 outer_table_id = p[0];
4431 /* Check src & dst are different */
4432 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4433 rv = VNET_API_ERROR_SAME_SRC_DST;
4437 memset (a, 0, sizeof (*a));
4439 a->is_add = mp->is_add;
4441 /* ip addresses sent in network byte order */
4442 a->src.as_u32 = mp->src_address;
4443 a->dst.as_u32 = mp->dst_address;
4445 a->outer_table_id = outer_table_id;
4446 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4449 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4451 rmp->sw_if_index = ntohl (sw_if_index);
4455 static void send_gre_tunnel_details
4456 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4458 vl_api_gre_tunnel_details_t * rmp;
4459 ip4_main_t * im = &ip4_main;
4461 rmp = vl_msg_api_alloc (sizeof (*rmp));
4462 memset (rmp, 0, sizeof (*rmp));
4463 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4464 rmp->src_address = t->tunnel_src.data_u32;
4465 rmp->dst_address = t->tunnel_dst.data_u32;
4466 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4467 rmp->sw_if_index = htonl(t->sw_if_index);
4468 rmp->context = context;
4470 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4473 static void vl_api_gre_tunnel_dump_t_handler
4474 (vl_api_gre_tunnel_dump_t * mp)
4476 unix_shared_memory_queue_t * q;
4477 gre_main_t * gm = &gre_main;
4481 q = vl_api_client_index_to_input_queue (mp->client_index);
4486 sw_if_index = ntohl(mp->sw_if_index);
4488 if (~0 == sw_if_index) {
4489 pool_foreach (t, gm->tunnels,
4491 send_gre_tunnel_details(t, q, mp->context);
4494 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4495 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4498 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4499 send_gre_tunnel_details(t, q, mp->context);
4504 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4506 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4508 vl_api_l2_patch_add_del_reply_t * rmp;
4509 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4513 VALIDATE_RX_SW_IF_INDEX(mp);
4514 VALIDATE_TX_SW_IF_INDEX(mp);
4516 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4517 ntohl(mp->tx_sw_if_index),
4518 (int)(mp->is_add != 0));
4520 BAD_RX_SW_IF_INDEX_LABEL;
4521 BAD_TX_SW_IF_INDEX_LABEL;
4523 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4527 vl_api_nsh_gre_add_del_tunnel_t_handler
4528 (vl_api_nsh_gre_add_del_tunnel_t * mp)
4530 vl_api_nsh_gre_add_del_tunnel_reply_t * rmp;
4532 vnet_nsh_gre_add_del_tunnel_args_t _a, *a = &_a;
4533 u32 encap_fib_index, decap_fib_index;
4534 u32 decap_next_index;
4536 ip4_main_t * im = &ip4_main;
4538 u32 sw_if_index = ~0;
4541 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4543 rv = VNET_API_ERROR_NO_SUCH_FIB;
4546 encap_fib_index = p[0];
4548 decap_next_index = ntohl(mp->decap_next_index);
4550 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4551 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4552 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4554 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4557 decap_fib_index = p[0];
4559 decap_fib_index = ntohl(mp->decap_vrf_id);
4562 memset (a, 0, sizeof (*a));
4564 a->is_add = mp->is_add;
4565 /* ip addresses sent in network byte order */
4566 a->src.as_u32 = ntohl(mp->src);
4567 a->dst.as_u32 = ntohl(mp->dst);
4568 a->encap_fib_index = encap_fib_index;
4569 a->decap_fib_index = decap_fib_index;
4570 a->decap_next_index = decap_next_index;
4571 a->nsh_hdr.ver_o_c = mp->ver_o_c;
4572 a->nsh_hdr.length = mp->length;
4573 a->nsh_hdr.md_type = mp->md_type;
4574 a->nsh_hdr.next_protocol = mp->next_protocol;
4575 a->nsh_hdr.spi_si = ntohl(mp->spi_si);
4576 a->nsh_hdr.c1 = ntohl(mp->c1);
4577 a->nsh_hdr.c2 = ntohl(mp->c2);
4578 a->nsh_hdr.c3 = ntohl(mp->c3);
4579 a->nsh_hdr.c4 = ntohl(mp->c4);
4581 for (i = 0; i < mp->tlv_len_in_words; i++)
4582 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4584 a->nsh_hdr.tlvs = tlvs;
4586 rv = vnet_nsh_gre_add_del_tunnel (a, &sw_if_index);
4589 REPLY_MACRO2(VL_API_NSH_GRE_ADD_DEL_TUNNEL_REPLY,
4591 rmp->sw_if_index = ntohl (sw_if_index);
4596 vl_api_nsh_vxlan_gpe_add_del_tunnel_t_handler
4597 (vl_api_nsh_vxlan_gpe_add_del_tunnel_t * mp)
4599 vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4601 vnet_nsh_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4602 u32 encap_fib_index, decap_fib_index;
4603 u32 decap_next_index;
4605 ip4_main_t * im = &ip4_main;
4607 u32 sw_if_index = ~0;
4610 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4612 rv = VNET_API_ERROR_NO_SUCH_FIB;
4615 encap_fib_index = p[0];
4617 decap_next_index = ntohl(mp->decap_next_index);
4619 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4620 if (decap_next_index == NSH_GRE_INPUT_NEXT_IP4_INPUT) {
4621 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4623 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4626 decap_fib_index = p[0];
4628 decap_fib_index = ntohl(mp->decap_vrf_id);
4631 memset (a, 0, sizeof (*a));
4633 a->is_add = mp->is_add;
4634 /* ip addresses sent in network byte order */
4635 a->src.as_u32 = ntohl(mp->src);
4636 a->dst.as_u32 = ntohl(mp->dst);
4637 a->encap_fib_index = encap_fib_index;
4638 a->decap_fib_index = decap_fib_index;
4639 a->decap_next_index = decap_next_index;
4640 a->vni = ntohl(mp->vni);
4641 a->nsh_hdr.ver_o_c = mp->ver_o_c;
4642 a->nsh_hdr.length = mp->length;
4643 a->nsh_hdr.md_type = mp->md_type;
4644 a->nsh_hdr.next_protocol = mp->next_protocol;
4645 a->nsh_hdr.spi_si = ntohl(mp->spi_si);
4646 a->nsh_hdr.c1 = ntohl(mp->c1);
4647 a->nsh_hdr.c2 = ntohl(mp->c2);
4648 a->nsh_hdr.c3 = ntohl(mp->c3);
4649 a->nsh_hdr.c4 = ntohl(mp->c4);
4651 for (i = 0; i < mp->tlv_len_in_words; i++)
4652 vec_add1 (tlvs, ntohl(mp->tlvs[i]));
4654 a->nsh_hdr.tlvs = tlvs;
4656 rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4659 REPLY_MACRO2(VL_API_NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4661 rmp->sw_if_index = ntohl (sw_if_index);
4666 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4668 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4670 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4672 u8 *locator_name = NULL;
4674 memset(a, 0, sizeof(a[0]));
4676 locator_name = format(0, "%s", mp->locator_set_name);
4678 a->name = locator_name;
4680 a->is_add = mp->is_add;
4683 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4685 vec_free(locator_name);
4687 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4691 vl_api_lisp_add_del_locator_t_handler(
4692 vl_api_lisp_add_del_locator_t *mp)
4694 vl_api_lisp_add_del_locator_reply_t *rmp;
4696 locator_t locator, *locators = NULL;
4697 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4699 u8 *locator_name = NULL;
4701 memset(&locator, 0, sizeof(locator));
4702 memset(a, 0, sizeof(a[0]));
4704 locator.sw_if_index = ntohl(mp->sw_if_index);
4705 locator.priority = mp->priority;
4706 locator.weight = mp->weight;
4708 vec_add1(locators, locator);
4710 locator_name = format(0, "%s", mp->locator_set_name);
4712 a->name = locator_name;
4713 a->locators = locators;
4714 a->is_add = mp->is_add;
4717 rv = vnet_lisp_add_del_locator(a, &ls_index);
4720 vec_free(locator_name);
4722 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4726 vl_api_lisp_add_del_local_eid_t_handler(
4727 vl_api_lisp_add_del_local_eid_t *mp)
4729 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4730 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4732 ip_prefix_t *prefp = NULL;
4733 ip_address_t *ip_eid = NULL;
4736 u32 locator_set_index = ~0, map_index = ~0;
4737 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4740 prefp = &gid_address_ippref(&eid);
4741 ip_eid = &ip_prefix_addr(prefp);
4742 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4745 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4746 sizeof(ip_addr_v6(ip_eid)));
4747 ip_addr_version(ip_eid) = IP6;
4749 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4750 sizeof(ip_addr_v4(ip_eid)));
4751 ip_addr_version(ip_eid) = IP4;
4753 ip_prefix_len(prefp) = mp->prefix_len;
4755 name = format(0, "%s", mp->locator_set_name);
4756 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4758 rv = VNET_API_ERROR_INVALID_VALUE;
4761 locator_set_index = p[0];
4763 /* XXX treat batch configuration */
4764 a->is_add = mp->is_add;
4766 a->locator_set_index = locator_set_index;
4769 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4774 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4778 lisp_gpe_add_del_fwd_entry_set_address(
4779 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4780 ip_address_t *slocator,
4781 ip_address_t *dlocator,
4784 ip_address_t *ip_eid = NULL;
4785 ip_prefix_t *prefp = NULL;
4787 prefp = &gid_address_ippref(eid);
4788 ip_eid = &ip_prefix_addr(prefp);
4790 if (mp->eid_is_ipv6) {
4791 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4792 sizeof(ip_addr_v6(ip_eid)));
4793 ip_addr_version(ip_eid) = IP6;
4795 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4796 sizeof(ip_addr_v4(ip_eid)));
4797 ip_addr_version(ip_eid) = IP4;
4799 ip_prefix_len(prefp) = mp->eid_prefix_len;
4801 if (mp->address_is_ipv6) {
4802 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4803 sizeof(ip_addr_v6(slocator)));
4804 ip_addr_version(slocator) = IP6;
4805 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4806 sizeof(ip_addr_v6(dlocator)));
4807 ip_addr_version(dlocator) = IP6;
4809 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4810 sizeof(ip_addr_v4(slocator)));
4811 ip_addr_version(slocator) = IP4;
4812 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4813 sizeof(ip_addr_v4(dlocator)));
4814 ip_addr_version(dlocator) = IP4;
4819 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4820 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4822 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4824 ip_address_t slocator, dlocator;
4826 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4828 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4830 memset (&a, 0, sizeof(a));
4832 a.is_add = mp->is_add;
4834 a.slocator = slocator;
4835 a.dlocator = dlocator;
4836 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4838 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4842 vl_api_lisp_add_del_map_resolver_t_handler(
4843 vl_api_lisp_add_del_map_resolver_t *mp)
4845 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4847 ip_address_t *ip_addr = NULL;
4848 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4850 a->is_add = mp->is_add;
4851 ip_addr = &a->address;
4854 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4855 sizeof(ip_addr_v6(ip_addr)));
4856 ip_addr_version(ip_addr) = IP6;
4858 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4859 sizeof(ip_addr_v4(ip_addr)));
4860 ip_addr_version(ip_addr) = IP4;
4863 rv = vnet_lisp_add_del_map_resolver (a);
4865 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4869 vl_api_lisp_gpe_enable_disable_t_handler(
4870 vl_api_lisp_gpe_enable_disable_t *mp)
4872 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4874 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4876 a->is_en = mp->is_en;
4877 vnet_lisp_gpe_enable_disable (a);
4879 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4883 vl_api_lisp_gpe_add_del_iface_t_handler(
4884 vl_api_lisp_gpe_add_del_iface_t *mp)
4886 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4888 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4890 a->is_add = mp->is_add;
4891 a->table_id = mp->table_id;
4893 vnet_lisp_gpe_add_del_iface (a, 0);
4895 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4899 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4900 locator_set_t *lsit,
4901 unix_shared_memory_queue_t *q,
4904 vl_api_lisp_locator_set_details_t *rmp;
4905 locator_t *loc = NULL;
4908 vec_foreach (locit, lsit->locator_indices) {
4909 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4910 rmp = vl_msg_api_alloc (sizeof (*rmp));
4911 memset (rmp, 0, sizeof (*rmp));
4912 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4913 strncpy((char *) rmp->locator_set_name,
4914 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4915 rmp->sw_if_index = htonl(loc->sw_if_index);
4916 rmp->priority = loc->priority;
4917 rmp->weight = loc->weight;
4918 rmp->context = context;
4920 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4925 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4927 unix_shared_memory_queue_t * q = NULL;
4928 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4929 locator_set_t * lsit = NULL;
4931 q = vl_api_client_index_to_input_queue (mp->client_index);
4936 pool_foreach (lsit, lcm->locator_set_pool,
4938 send_lisp_locator_set_details(lcm, lsit, q, mp->context);
4943 send_lisp_local_eid_table_details (mapping_t *mapit,
4944 unix_shared_memory_queue_t *q,
4947 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4948 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4949 locator_set_t *ls = NULL;
4950 gid_address_t *gid = NULL;
4951 ip_prefix_t *ip_prefix = NULL;
4954 ls = pool_elt_at_index (lcm->locator_set_pool,
4955 mapit->locator_set_index);
4958 type = gid_address_type(gid);
4960 if (type != GID_ADDR_IP_PREFIX) {
4964 ip_prefix = &gid_address_ippref(gid);
4966 rmp = vl_msg_api_alloc (sizeof (*rmp));
4967 memset (rmp, 0, sizeof (*rmp));
4968 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
4969 strncpy((char *) rmp->locator_set_name,
4970 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4972 switch (ip_prefix_version(ip_prefix)) {
4974 rmp->eid_is_ipv6 = 0;
4975 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
4976 sizeof(ip_prefix_v4(ip_prefix)));
4980 rmp->eid_is_ipv6 = 1;
4981 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
4982 sizeof(ip_prefix_v6(ip_prefix)));
4988 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
4989 rmp->context = context;
4991 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4995 vl_api_lisp_local_eid_table_dump_t_handler (
4996 vl_api_lisp_local_eid_table_dump_t *mp)
4998 unix_shared_memory_queue_t * q = NULL;
4999 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5000 mapping_t * mapit = NULL;
5002 q = vl_api_client_index_to_input_queue (mp->client_index);
5007 pool_foreach (mapit, lcm->mapping_pool,
5009 send_lisp_local_eid_table_details(mapit, q, mp->context);
5014 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5015 unix_shared_memory_queue_t *q,
5018 vl_api_lisp_gpe_tunnel_details_t *rmp;
5019 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5021 rmp = vl_msg_api_alloc (sizeof (*rmp));
5022 memset (rmp, 0, sizeof (*rmp));
5023 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5025 rmp->tunnels = tunnel - lgm->tunnels;
5027 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5028 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5029 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5031 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5032 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5033 rmp->dcap_next = htonl(tunnel->decap_next_index);
5034 rmp->lisp_ver = tunnel->ver_res;
5035 rmp->next_protocol = tunnel->next_protocol;
5036 rmp->flags = tunnel->flags;
5037 rmp->ver_res = tunnel->ver_res;
5038 rmp->res = tunnel->res;
5039 rmp->iid = htonl(tunnel->vni);
5040 rmp->context = context;
5042 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5046 vl_api_lisp_gpe_tunnel_dump_t_handler (
5047 vl_api_lisp_local_eid_table_dump_t *mp)
5049 unix_shared_memory_queue_t * q = NULL;
5050 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5051 lisp_gpe_tunnel_t * tunnel = NULL;
5053 if (pool_elts(lgm->tunnels) == 0) {
5057 q = vl_api_client_index_to_input_queue (mp->client_index);
5062 pool_foreach(tunnel, lgm->tunnels,
5064 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5069 send_lisp_map_resolver_details (ip_address_t *ip,
5070 unix_shared_memory_queue_t *q,
5073 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5075 rmp = vl_msg_api_alloc (sizeof (*rmp));
5076 memset (rmp, 0, sizeof (*rmp));
5077 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5079 switch (ip_addr_version(ip)) {
5082 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5087 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5093 rmp->context = context;
5095 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5099 vl_api_lisp_map_resolver_dump_t_handler (
5100 vl_api_lisp_local_eid_table_dump_t *mp)
5102 unix_shared_memory_queue_t * q = NULL;
5103 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5104 ip_address_t *ip = NULL;
5106 q = vl_api_client_index_to_input_queue (mp->client_index);
5111 vec_foreach(ip, lcm->map_resolvers) {
5112 send_lisp_map_resolver_details(ip, q, mp->context);
5118 send_lisp_gpe_enable_disable_details (unix_shared_memory_queue_t *q,
5121 vl_api_lisp_gpe_enable_disable_status_details_t *rmp = NULL;
5124 rmp = vl_msg_api_alloc (sizeof (*rmp));
5125 memset (rmp, 0, sizeof (*rmp));
5126 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_ENABLE_DISABLE_STATUS_DETAILS);
5128 is_en = vnet_lisp_gpe_enable_disable_status();
5130 rmp->context = context;
5132 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5136 vl_api_lisp_gpe_enable_disable_status_dump_t_handler
5137 (vl_api_lisp_gpe_enable_disable_status_dump_t *mp)
5139 unix_shared_memory_queue_t * q = NULL;
5141 q = vl_api_client_index_to_input_queue (mp->client_index);
5146 send_lisp_gpe_enable_disable_details(q, mp->context);
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",