2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
23 #include <sys/types.h>
26 #include <netinet/in.h>
33 #include <vppinfra/clib.h>
34 #include <vppinfra/vec.h>
35 #include <vppinfra/hash.h>
36 #include <vppinfra/bitmap.h>
37 #include <vppinfra/fifo.h>
38 #include <vppinfra/time.h>
39 #include <vppinfra/mheap.h>
40 #include <vppinfra/heap.h>
41 #include <vppinfra/pool.h>
42 #include <vppinfra/format.h>
43 #include <vppinfra/error.h>
45 #include <vnet/api_errno.h> // alagalah TODO : committers please pay note, is this ok?
46 #include <vnet/vnet.h>
47 #include <vnet/l2/l2_input.h>
48 #include <vnet/l2/l2_bd.h>
49 #include <vnet/l2tp/l2tp.h>
50 #include <vnet/ip/ip.h>
51 #include <vnet/unix/tuntap.h>
52 #include <vnet/unix/tapcli.h>
53 #include <vnet/mpls-gre/mpls.h>
54 #include <vnet/dhcp/proxy.h>
55 #include <vnet/dhcp/client.h>
57 #include <vnet/sr/sr.h>
59 #include <vnet/dhcpv6/proxy.h>
60 #include <vlib/vlib.h>
61 #include <vlib/unix/unix.h>
62 #include <vlibapi/api.h>
63 #include <vlibmemory/api.h>
64 #include <vnet/classify/vnet_classify.h>
65 #include <vnet/classify/input_acl.h>
66 #include <vnet/l2/l2_classify.h>
67 #include <vnet/vxlan/vxlan.h>
68 #include <vnet/gre/gre.h>
69 #include <vnet/l2/l2_vtr.h>
70 #include <vnet/vxlan-gpe/vxlan_gpe.h>
71 #include <vnet/lisp-gpe/lisp_gpe.h>
72 #include <vnet/lisp-cp/control.h>
73 #include <vnet/map/map.h>
74 #include <vnet/cop/cop.h>
75 #include <vnet/ip/ip6_hop_by_hop.h>
76 #include <vnet/devices/af_packet/af_packet.h>
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 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
291 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
292 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
293 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
294 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
295 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
296 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
297 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
298 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
299 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
300 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
301 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
302 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
303 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
304 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
305 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
306 _(DELETE_LOOPBACK, delete_loopback) \
307 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
308 _(MAP_ADD_DOMAIN, map_add_domain) \
309 _(MAP_DEL_DOMAIN, map_del_domain) \
310 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
311 _(MAP_DOMAIN_DUMP, map_domain_dump) \
312 _(MAP_RULE_DUMP, map_rule_dump) \
313 _(MAP_SUMMARY_STATS, map_summary_stats) \
314 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
315 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
316 _(GET_NODE_GRAPH, get_node_graph) \
317 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
318 _(TRACE_PROFILE_ADD, trace_profile_add) \
319 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
320 _(TRACE_PROFILE_DEL, trace_profile_del) \
321 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
322 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
323 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
324 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
325 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
326 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
327 _(LISP_ENABLE_DISABLE, lisp_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_ENABLE_DISABLE_STATUS_DUMP, \
334 lisp_enable_disable_status_dump) \
335 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
336 _(AF_PACKET_CREATE, af_packet_create) \
337 _(AF_PACKET_DELETE, af_packet_delete)
340 #define QUOTE(x) QUOTE_(x)
342 #define foreach_registration_hash \
343 _(interface_events) \
344 _(to_netconf_server) \
345 _(from_netconf_server) \
346 _(to_netconf_client) \
347 _(from_netconf_client) \
351 RESOLVE_IP4_ADD_DEL_ROUTE=1,
352 RESOLVE_IP6_ADD_DEL_ROUTE,
353 RESOLVE_MPLS_ETHERNET_ADD_DEL,
359 vl_api_ip_add_del_route_t r;
360 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
366 #define _(a) uword *a##_registration_hash; \
367 vpe_client_registration_t * a##_registrations;
368 foreach_registration_hash
371 /* notifications happen really early in the game */
372 u8 link_state_process_up;
374 /* ip4 pending route adds */
375 pending_route_t * pending_routes;
377 /* ip4 arp event registration pool */
378 vl_api_ip4_arp_event_t * arp_events;
381 vlib_main_t * vlib_main;
382 vnet_main_t * vnet_main;
385 static vlib_node_registration_t vpe_resolver_process_node;
386 static vpe_api_main_t vpe_api_main;
388 static void send_sw_interface_flags (vpe_api_main_t * am,
389 unix_shared_memory_queue_t *q,
390 vnet_sw_interface_t * swif);
391 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
392 unix_shared_memory_queue_t *q,
395 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
398 /* Clean up all registrations belonging to the indicated client */
399 int vl_api_memclnt_delete_callback (u32 client_index)
401 vpe_api_main_t * vam = &vpe_api_main;
402 vpe_client_registration_t *rp;
404 int stats_memclnt_delete_callback (u32 client_index);
406 stats_memclnt_delete_callback (client_index);
409 p = hash_get (vam->a##_registration_hash, client_index); \
411 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
412 pool_put (vam->a##_registrations, rp); \
413 hash_unset (vam->a##_registration_hash, client_index); \
415 foreach_registration_hash;
420 #define API_LINK_STATE_EVENT 1
421 #define API_ADMIN_UP_DOWN_EVENT 2
424 event_data_cmp (void * a1, void * a2)
429 return (word) e1[0] - (word) e2[0];
433 link_state_process (vlib_main_t * vm,
434 vlib_node_runtime_t * rt,
437 vpe_api_main_t * vam = &vpe_api_main;
438 vnet_main_t * vnm = vam->vnet_main;
439 vnet_sw_interface_t * swif;
440 uword * event_data = 0;
441 vpe_client_registration_t *reg;
443 u32 prev_sw_if_index;
444 unix_shared_memory_queue_t * q;
446 vam->link_state_process_up = 1;
449 vlib_process_wait_for_event (vm);
451 /* Unified list of changed link or admin state sw_if_indices */
452 vlib_process_get_events_with_type
453 (vm, &event_data, API_LINK_STATE_EVENT);
454 vlib_process_get_events_with_type
455 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
457 /* Sort, so we can eliminate duplicates */
458 vec_sort_with_function (event_data, event_data_cmp);
460 prev_sw_if_index = ~0;
462 for (i = 0; i < vec_len(event_data); i++) {
463 /* Only one message per swif */
464 if (prev_sw_if_index == event_data[i])
466 prev_sw_if_index = event_data[i];
468 pool_foreach(reg, vam->interface_events_registrations,
470 q = vl_api_client_index_to_input_queue (reg->client_index);
472 // sw_interface may be deleted already
473 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
476 swif = vnet_get_sw_interface (vnm, event_data[i]);
477 send_sw_interface_flags (vam, q, swif);
482 vec_reset_length (event_data);
488 static clib_error_t *
489 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
490 static clib_error_t *
491 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
493 VLIB_REGISTER_NODE (link_state_process_node,static) = {
494 .function = link_state_process,
495 .type = VLIB_NODE_TYPE_PROCESS,
496 .name = "vpe-link-state-process",
499 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
500 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
502 static clib_error_t *
503 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
505 vpe_api_main_t * vam = &vpe_api_main;
506 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
508 if (vam->link_state_process_up)
509 vlib_process_signal_event (vam->vlib_main,
510 link_state_process_node.index,
511 API_LINK_STATE_EVENT,
516 static clib_error_t *
517 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
519 vpe_api_main_t * vam = &vpe_api_main;
522 * Note: it's perfectly fair to set a subif admin up / admin down.
523 * Note the subtle distinction between this routine and the previous
526 if (vam->link_state_process_up)
527 vlib_process_signal_event (vam->vlib_main,
528 link_state_process_node.index,
529 API_ADMIN_UP_DOWN_EVENT,
534 #define pub_sub_handler(lca,UCA) \
535 static void vl_api_want_##lca##_t_handler ( \
536 vl_api_want_##lca##_t *mp) \
538 vpe_api_main_t *vam = &vpe_api_main; \
539 vpe_client_registration_t *rp; \
540 vl_api_want_##lca##_reply_t *rmp; \
544 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
546 if (mp->enable_disable) { \
547 clib_warning ("pid %d: already enabled...", mp->pid); \
548 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
551 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
552 pool_put (vam->lca##_registrations, rp); \
553 hash_unset (vam->lca##_registration_hash, \
558 if (mp->enable_disable == 0) { \
559 clib_warning ("pid %d: already disabled...", mp->pid); \
560 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
563 pool_get (vam->lca##_registrations, rp); \
564 rp->client_index = mp->client_index; \
565 rp->client_pid = mp->pid; \
566 hash_set (vam->lca##_registration_hash, rp->client_index, \
567 rp - vam->lca##_registrations); \
570 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
573 pub_sub_handler (interface_events,INTERFACE_EVENTS)
574 pub_sub_handler (oam_events,OAM_EVENTS)
576 #define RESOLUTION_EVENT 1
577 #define RESOLUTION_PENDING_EVENT 2
578 #define IP4_ARP_EVENT 3
580 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
581 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
582 static int mpls_ethernet_add_del_tunnel_2_t_handler
583 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
585 void handle_ip4_arp_event (u32 pool_index)
587 vpe_api_main_t * vam = &vpe_api_main;
588 vnet_main_t * vnm = vam->vnet_main;
589 vlib_main_t * vm = vam->vlib_main;
590 vl_api_ip4_arp_event_t * event;
591 vl_api_ip4_arp_event_t * mp;
592 unix_shared_memory_queue_t * q;
594 /* Client can cancel, die, etc. */
595 if (pool_is_free_index (vam->arp_events, pool_index))
598 event = pool_elt_at_index (vam->arp_events, pool_index);
600 q = vl_api_client_index_to_input_queue (event->client_index);
602 (void) vnet_add_del_ip4_arp_change_event
603 (vnm, arp_change_delete_callback,
604 event->pid, &event->address,
605 vpe_resolver_process_node.index, IP4_ARP_EVENT,
606 ~0 /* pool index, notused */, 0 /* is_add */);
610 if (q->cursize < q->maxsize) {
611 mp = vl_msg_api_alloc (sizeof (*mp));
612 clib_memcpy (mp, event, sizeof (*mp));
613 vl_msg_api_send_shmem (q, (u8 *)&mp);
615 static f64 last_time;
617 * Throttle syslog msgs.
618 * It's pretty tempting to just revoke the registration...
620 if (vlib_time_now (vm) > last_time + 10.0) {
621 clib_warning ("arp event for %U to pid %d: queue stuffed!",
622 format_ip4_address, &event->address, event->pid);
623 last_time = vlib_time_now(vm);
629 resolver_process (vlib_main_t * vm,
630 vlib_node_runtime_t * rt,
634 uword *event_data = 0;
636 vpe_api_main_t * vam = &vpe_api_main;
637 pending_route_t * pr;
638 vl_api_ip_add_del_route_t * adr;
639 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
640 u32 * resolution_failures = 0;
645 vlib_process_wait_for_event_or_clock (vm, timeout);
647 event_type = vlib_process_get_events (vm, &event_data);
649 switch (event_type) {
650 case RESOLUTION_PENDING_EVENT:
654 case RESOLUTION_EVENT:
655 for (i = 0; i < vec_len(event_data); i++) {
657 * Resolution events can occur long after the
658 * original request has timed out. $$$ add a cancel
661 if (pool_is_free_index (vam->pending_routes, event_data[i]))
664 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
668 switch (pr->resolve_type) {
669 case RESOLVE_IP4_ADD_DEL_ROUTE:
670 rv = ip4_add_del_route_t_handler (adr);
671 clib_warning ("resolver: add %U/%d via %U %s",
673 (ip4_address_t *)&(adr->dst_address),
674 adr->dst_address_length,
676 (ip4_address_t *)&(adr->next_hop_address),
677 (rv >= 0) ? "succeeded" : "failed");
680 case RESOLVE_IP6_ADD_DEL_ROUTE:
681 rv = ip6_add_del_route_t_handler (adr);
682 clib_warning ("resolver: add %U/%d via %U %s",
684 (ip6_address_t *)&(adr->dst_address),
685 adr->dst_address_length,
687 (ip6_address_t *)&(adr->next_hop_address),
688 (rv >= 0) ? "succeeded" : "failed");
691 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
692 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
693 clib_warning ("resolver: add mpls-o-e via %U %s",
695 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
696 (rv >= 0) ? "succeeded" : "failed");
700 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
702 pool_put (vam->pending_routes, pr);
707 for (i = 0; i < vec_len(event_data); i++)
708 handle_ip4_arp_event (event_data[i]);
711 case ~0: /* timeout, retry pending resolutions */
712 pool_foreach (pr, vam->pending_routes,
718 /* May fail, e.g. due to interface down */
719 switch (pr->resolve_type) {
720 case RESOLVE_IP4_ADD_DEL_ROUTE:
721 e = ip4_probe_neighbor
722 (vm, (ip4_address_t *)&(adr->next_hop_address),
723 ntohl(adr->next_hop_sw_if_index));
726 case RESOLVE_IP6_ADD_DEL_ROUTE:
727 e = ip6_probe_neighbor
728 (vm, (ip6_address_t *)&(adr->next_hop_address),
729 ntohl(adr->next_hop_sw_if_index));
732 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
734 e = ip4_probe_neighbor
736 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
737 pme->resolve_opaque);
741 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
745 clib_error_report (e);
747 adr->resolve_attempts = 1;
749 pme->resolve_attempts = 1;
753 adr->resolve_attempts -= 1;
754 if (adr->resolve_attempts == 0)
755 vec_add1 (resolution_failures,
756 pr - vam->pending_routes);
758 pme->resolve_attempts -= 1;
759 if (pme->resolve_attempts == 0)
760 vec_add1 (resolution_failures,
761 pr - vam->pending_routes);
765 for (i = 0; i < vec_len (resolution_failures); i++) {
766 pr = pool_elt_at_index (vam->pending_routes,
767 resolution_failures[i]);
771 switch (pr->resolve_type) {
772 case RESOLVE_IP4_ADD_DEL_ROUTE:
773 clib_warning ("resolver: add %U/%d via %U retry failure",
775 (ip4_address_t *)&(adr->dst_address),
776 adr->dst_address_length,
778 (ip4_address_t *)&(adr->next_hop_address));
781 case RESOLVE_IP6_ADD_DEL_ROUTE:
782 clib_warning ("resolver: add %U/%d via %U retry failure",
784 (ip6_address_t *)&(adr->dst_address),
785 adr->dst_address_length,
787 (ip6_address_t *)&(adr->next_hop_address));
790 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
791 clib_warning ("resolver: add mpls-o-e via %U retry failure",
793 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
797 clib_warning ("BUG");
799 pool_put(vam->pending_routes, pr);
801 vec_reset_length (resolution_failures);
804 if (pool_elts (vam->pending_routes) == 0)
806 vec_reset_length (event_data);
808 return 0; /* or not */
811 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
812 .function = resolver_process,
813 .type = VLIB_NODE_TYPE_PROCESS,
814 .name = "vpe-route-resolver-process",
817 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
819 ip4_main_t * im = &ip4_main;
820 ip_lookup_main_t * lm = &im->lookup_main;
821 vnet_classify_main_t * cm = &vnet_classify_main;
822 stats_main_t * sm = &stats_main;
823 ip4_add_del_route_args_t a;
824 ip4_address_t next_hop_address;
826 vpe_api_main_t * vam = &vpe_api_main;
827 vnet_main_t * vnm = vam->vnet_main;
828 vlib_main_t * vm = vlib_get_main();
829 pending_route_t * pr;
830 vl_api_ip_add_del_route_t * adr;
834 ip_adjacency_t *nh_adj, *add_adj = 0;
836 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
838 if (mp->create_vrf_if_needed) {
840 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
842 fib_index = f->index;
844 /* No such VRF, and we weren't asked to create one */
845 return VNET_API_ERROR_NO_SUCH_FIB;
851 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
852 ntohl(mp->next_hop_sw_if_index)))
853 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
855 clib_memcpy (next_hop_address.data, mp->next_hop_address,
856 sizeof (next_hop_address.data));
858 /* Arp for the next_hop if necessary */
859 if (mp->is_add && mp->resolve_if_needed) {
861 ip_adjacency_t * adj;
863 lookup_result = ip4_fib_lookup_with_table
864 (im, fib_index, &next_hop_address, 1 /* disable default route */);
866 adj = ip_get_adjacency (lm, lookup_result);
868 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
869 pool_get (vam->pending_routes, pr);
870 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
872 clib_memcpy (adr, mp, sizeof (*adr));
873 /* recursion block, "just in case" */
874 adr->resolve_if_needed = 0;
875 adr->resolve_attempts = ntohl(mp->resolve_attempts);
876 vnet_register_ip4_arp_resolution_event
877 (vnm, &next_hop_address, vpe_resolver_process_node.index,
878 RESOLUTION_EVENT, pr - vam->pending_routes);
880 vlib_process_signal_event
881 (vm, vpe_resolver_process_node.index,
882 RESOLUTION_PENDING_EVENT, 0 /* data */);
884 /* The interface may be down, etc. */
885 e = ip4_probe_neighbor
886 (vm, (ip4_address_t *)&(mp->next_hop_address),
887 ntohl(mp->next_hop_sw_if_index));
890 clib_error_report(e);
892 return VNET_API_ERROR_IN_PROGRESS;
896 if (mp->is_multipath) {
899 dslock (sm, 1 /* release hint */, 10 /* tag */);
902 flags = IP4_ROUTE_FLAG_ADD;
904 flags = IP4_ROUTE_FLAG_DEL;
907 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
909 ip4_add_del_route_next_hop (im, flags,
910 (ip4_address_t *) mp->dst_address,
911 (u32) mp->dst_address_length,
912 (ip4_address_t *) mp->next_hop_address,
913 ntohl(mp->next_hop_sw_if_index),
914 (u32) mp->next_hop_weight,
921 memset (&a, 0, sizeof (a));
922 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
924 a.dst_address_length = mp->dst_address_length;
926 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
927 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
928 a.table_index_or_table_id = fib_index;
933 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
935 dslock (sm, 1 /* release hint */, 2 /* tag */);
939 ai = lm->drop_adj_index;
940 else if (mp->is_local)
941 ai = lm->local_adj_index;
942 else if (mp->is_classify) {
944 memset(&cadj, 0, sizeof(cadj));
945 cadj.lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
946 cadj.classify.table_index = ntohl(mp->classify_table_index);
947 if (pool_is_free_index (cm->tables, cadj.classify.table_index)) {
949 return VNET_API_ERROR_NO_SUCH_TABLE;
951 vec_add1 (add_adj, cadj);
955 ai = ip4_fib_lookup_with_table
956 (im, fib_index, &next_hop_address,
957 1 /* disable default route */);
958 if (ai == lm->miss_adj_index) {
960 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
964 nh_adj = ip_get_adjacency (lm, ai);
965 vec_add1 (add_adj, nh_adj[0]);
966 if (mp->lookup_in_vrf) {
967 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
969 add_adj[0].explicit_fib_index = p[0];
973 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
977 ip_adjacency_t * adj;
978 int disable_default_route = 1;
980 /* Trying to delete the default route? */
981 if (a.dst_address.as_u32 == 0 &&
982 a.dst_address_length == 0)
983 disable_default_route = 0;
985 ai = ip4_fib_lookup_with_table
986 (im, fib_index, &a.dst_address, disable_default_route);
987 if (ai == lm->miss_adj_index) {
989 return VNET_API_ERROR_UNKNOWN_DESTINATION;
992 adj = ip_get_adjacency (lm, ai);
993 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
995 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1001 a.add_adj = add_adj;
1002 a.n_add_adj = vec_len(add_adj);
1003 ip4_add_del_route (im, &a);
1011 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1013 ip6_main_t * im = &ip6_main;
1014 ip_lookup_main_t * lm = &im->lookup_main;
1015 vnet_main_t * vnm = vnet_get_main();
1016 vlib_main_t * vm = vlib_get_main();
1017 vpe_api_main_t * vam = &vpe_api_main;
1018 stats_main_t * sm = &stats_main;
1019 ip6_add_del_route_args_t a;
1020 ip6_address_t next_hop_address;
1021 pending_route_t * pr;
1022 vl_api_ip_add_del_route_t * adr;
1027 ip_adjacency_t * nh_adj, * add_adj = 0;
1030 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1033 if (mp->create_vrf_if_needed) {
1035 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1037 fib_index = f->index;
1039 /* No such VRF, and we weren't asked to create one */
1040 return VNET_API_ERROR_NO_SUCH_FIB;
1046 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
1047 ntohl(mp->next_hop_sw_if_index)))
1048 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1050 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1051 sizeof (next_hop_address.as_u8));
1053 /* Arp for the next_hop if necessary */
1054 if (mp->is_add && mp->resolve_if_needed) {
1056 ip_adjacency_t * adj;
1058 lookup_result = ip6_fib_lookup_with_table
1059 (im, fib_index, &next_hop_address);
1061 adj = ip_get_adjacency (lm, lookup_result);
1063 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1064 pool_get (vam->pending_routes, pr);
1066 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1067 clib_memcpy (adr, mp, sizeof (*adr));
1068 /* recursion block, "just in case" */
1069 adr->resolve_if_needed = 0;
1070 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1071 vnet_register_ip6_neighbor_resolution_event
1072 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1073 RESOLUTION_EVENT, pr - vam->pending_routes);
1075 vlib_process_signal_event
1076 (vm, vpe_resolver_process_node.index,
1077 RESOLUTION_PENDING_EVENT, 0 /* data */);
1079 /* The interface may be down, etc. */
1080 e = ip6_probe_neighbor
1081 (vm, (ip6_address_t *)&(mp->next_hop_address),
1082 ntohl(mp->next_hop_sw_if_index));
1085 clib_error_report(e);
1087 return VNET_API_ERROR_IN_PROGRESS;
1091 if (mp->is_multipath) {
1094 dslock (sm, 1 /* release hint */, 11 /* tag */);
1097 flags = IP6_ROUTE_FLAG_ADD;
1099 flags = IP6_ROUTE_FLAG_DEL;
1102 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1104 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1105 (u32) mp->dst_address_length,
1106 (ip6_address_t *)mp->next_hop_address,
1107 ntohl(mp->next_hop_sw_if_index),
1108 (u32) mp->next_hop_weight,
1115 memset (&a, 0, sizeof (a));
1116 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1118 a.dst_address_length = mp->dst_address_length;
1120 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1121 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1122 a.table_index_or_table_id = fib_index;
1127 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1129 dslock (sm, 1 /* release hint */, 3 /* tag */);
1133 ai = lm->drop_adj_index;
1134 else if (mp->is_local)
1135 ai = lm->local_adj_index;
1137 ai = ip6_fib_lookup_with_table
1138 (im, fib_index, &next_hop_address);
1139 if (ai == lm->miss_adj_index) {
1141 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1145 nh_adj = ip_get_adjacency (lm, ai);
1146 vec_add1 (add_adj, nh_adj[0]);
1147 if (mp->lookup_in_vrf) {
1148 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1150 add_adj[0].explicit_fib_index = p[0];
1154 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1158 ip_adjacency_t * adj;
1160 ai = ip6_fib_lookup_with_table
1161 (im, fib_index, &a.dst_address);
1162 if (ai == lm->miss_adj_index) {
1164 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1166 adj = ip_get_adjacency (lm, ai);
1167 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1169 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1174 a.add_adj = add_adj;
1175 a.n_add_adj = vec_len(add_adj);
1176 ip6_add_del_route (im, &a);
1184 void vl_api_ip_add_del_route_t_handler (
1185 vl_api_ip_add_del_route_t *mp)
1187 vl_api_ip_add_del_route_reply_t * rmp;
1189 vnet_main_t * vnm = vnet_get_main();
1194 rv = ip6_add_del_route_t_handler (mp);
1196 rv = ip4_add_del_route_t_handler (mp);
1198 rv = (rv == 0) ? vnm->api_errno : rv;
1200 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1203 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1204 u32 sw_if_index, u8 *next_hop_addr)
1206 vl_api_ip_add_del_route_t mp;
1209 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1212 * Configure default IP route:
1213 * - ip route add 0.0.0.0/1 via <GW IP>
1214 * - ip route add 128.0.0.0/1 via <GW IP>
1216 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1218 mp.resolve_attempts = ~0;
1219 mp.resolve_if_needed = 1;
1221 mp.is_ipv6 = is_ipv6;
1222 mp.next_hop_weight = 1;
1224 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1227 rv = ip6_add_del_route_t_handler (&mp);
1230 mp.dst_address_length = 1;
1232 mp.dst_address[0] = 0;
1233 rv = ip4_add_del_route_t_handler (&mp);
1235 mp.dst_address[0] = 128;
1236 rv |= ip4_add_del_route_t_handler (&mp);
1240 clib_error_return (0, "failed to config default IP route");
1245 vl_api_sw_interface_add_del_address_t_handler
1246 (vl_api_sw_interface_add_del_address_t *mp)
1248 vlib_main_t *vm = vlib_get_main();
1249 vl_api_sw_interface_add_del_address_reply_t * rmp;
1253 VALIDATE_SW_IF_INDEX(mp);
1255 is_del = mp->is_add == 0;
1258 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1259 else if (mp->is_ipv6)
1260 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1261 (void *)mp->address,
1262 mp->address_length, is_del);
1264 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1265 (void *) mp->address,
1266 mp->address_length, is_del);
1268 BAD_SW_IF_INDEX_LABEL;
1270 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1274 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1277 u32 table_id = ntohl(mp->vrf_id);
1278 u32 sw_if_index = ntohl(mp->sw_if_index);
1279 vl_api_sw_interface_set_table_reply_t * rmp;
1280 stats_main_t * sm = &stats_main;
1282 VALIDATE_SW_IF_INDEX(mp);
1284 dslock (sm, 1 /* release hint */, 4 /* tag */);
1287 ip6_main_t * im = &ip6_main;
1289 find_ip6_fib_by_table_index_or_id (im, table_id,
1290 IP6_ROUTE_FLAG_TABLE_ID);
1292 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1293 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1295 rv = VNET_API_ERROR_NO_SUCH_FIB;
1298 ip4_main_t * im = &ip4_main;
1299 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1300 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1302 /* Truthfully this can't fail */
1304 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1305 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1307 rv = VNET_API_ERROR_NO_SUCH_FIB;
1312 BAD_SW_IF_INDEX_LABEL;
1314 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1318 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1320 vlib_main_t *vm = vlib_get_main();
1321 vl_api_sw_interface_set_vpath_reply_t * rmp;
1324 u32 sw_if_index = ntohl(mp->sw_if_index);
1325 ip4_main_t *ip4m = &ip4_main;
1326 ip6_main_t *ip6m = &ip6_main;
1327 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1328 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1329 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1330 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1331 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1332 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1334 VALIDATE_SW_IF_INDEX(mp);
1336 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1338 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1339 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1340 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1341 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1342 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1343 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1344 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1345 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1346 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1347 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1348 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1349 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1350 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1351 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1352 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1353 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1355 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1356 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1357 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1358 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1359 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1360 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1361 ci, IP4_RX_FEATURE_VPATH, 0, 0);
1362 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1363 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1364 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1365 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1366 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1367 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1368 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1369 ci, IP6_RX_FEATURE_VPATH, 0, 0);
1370 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1373 BAD_SW_IF_INDEX_LABEL;
1375 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1379 vl_api_sw_interface_set_l2_xconnect_t_handler (
1380 vl_api_sw_interface_set_l2_xconnect_t *mp)
1382 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1384 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1385 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1386 vlib_main_t *vm = vlib_get_main();
1387 vnet_main_t *vnm = vnet_get_main();
1389 VALIDATE_RX_SW_IF_INDEX(mp);
1392 VALIDATE_TX_SW_IF_INDEX(mp);
1393 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1394 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1396 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1399 BAD_RX_SW_IF_INDEX_LABEL;
1400 BAD_TX_SW_IF_INDEX_LABEL;
1402 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1406 vl_api_sw_interface_set_l2_bridge_t_handler (
1407 vl_api_sw_interface_set_l2_bridge_t *mp)
1409 bd_main_t * bdm = &bd_main;
1410 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1412 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1413 u32 bd_id = ntohl(mp->bd_id);
1417 vlib_main_t *vm = vlib_get_main();
1418 vnet_main_t *vnm = vnet_get_main();
1420 VALIDATE_RX_SW_IF_INDEX(mp);
1422 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1425 //VALIDATE_TX_SW_IF_INDEX(mp);
1426 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1427 rx_sw_if_index, bd_index, bvi, shg, 0);
1429 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1432 BAD_RX_SW_IF_INDEX_LABEL;
1434 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1438 vl_api_bridge_domain_add_del_t_handler (
1439 vl_api_bridge_domain_add_del_t *mp)
1441 vlib_main_t * vm = vlib_get_main ();
1442 bd_main_t * bdm = &bd_main;
1443 vl_api_bridge_domain_add_del_reply_t * rmp;
1445 u32 enable_flags = 0, disable_flags = 0;
1446 u32 bd_id = ntohl(mp->bd_id);
1450 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1453 enable_flags |= L2_FLOOD;
1455 disable_flags |= L2_FLOOD;
1458 enable_flags |= L2_UU_FLOOD;
1460 disable_flags |= L2_UU_FLOOD;
1463 enable_flags |= L2_FWD;
1465 disable_flags |= L2_FWD;
1468 enable_flags |= L2_ARP_TERM;
1470 disable_flags |= L2_ARP_TERM;
1473 enable_flags |= L2_LEARN;
1475 disable_flags |= L2_LEARN;
1478 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1481 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1484 rv = bd_delete_bd_index(bdm, bd_id);
1486 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1489 static void vl_api_bridge_domain_details_t_handler (
1490 vl_api_bridge_domain_details_t * mp)
1492 clib_warning ("BUG");
1495 static void vl_api_bridge_domain_sw_if_details_t_handler (
1496 vl_api_bridge_domain_sw_if_details_t * mp)
1498 clib_warning ("BUG");
1501 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1502 l2_bridge_domain_t * bd_config,
1506 vl_api_bridge_domain_details_t * mp;
1508 mp = vl_msg_api_alloc (sizeof (*mp));
1509 memset (mp, 0, sizeof (*mp));
1510 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1511 mp->bd_id = ntohl (bd_config->bd_id);
1512 mp->flood = bd_feature_flood (bd_config);
1513 mp->uu_flood = bd_feature_uu_flood (bd_config);
1514 mp->forward = bd_feature_forward (bd_config);
1515 mp->learn = bd_feature_learn (bd_config);
1516 mp->arp_term = bd_feature_arp_term (bd_config);
1517 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1518 mp->n_sw_ifs = ntohl (n_sw_ifs);
1519 mp->context = context;
1521 vl_msg_api_send_shmem (q, (u8 *)&mp);
1524 static void send_bd_sw_if_details (l2input_main_t * l2im,
1525 unix_shared_memory_queue_t *q,
1526 l2_flood_member_t * member, u32 bd_id,
1529 vl_api_bridge_domain_sw_if_details_t * mp;
1530 l2_input_config_t * input_cfg;
1532 mp = vl_msg_api_alloc (sizeof (*mp));
1533 memset (mp, 0, sizeof (*mp));
1534 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1535 mp->bd_id = ntohl (bd_id);
1536 mp->sw_if_index = ntohl (member->sw_if_index);
1537 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1538 mp->shg = input_cfg->shg;
1539 mp->context = context;
1541 vl_msg_api_send_shmem (q, (u8 *)&mp);
1544 static void vl_api_bridge_domain_dump_t_handler (
1545 vl_api_bridge_domain_dump_t *mp)
1547 bd_main_t * bdm = &bd_main;
1548 l2input_main_t * l2im = &l2input_main;
1549 unix_shared_memory_queue_t * q;
1550 l2_bridge_domain_t * bd_config;
1551 u32 bd_id, bd_index;
1554 q = vl_api_client_index_to_input_queue (mp->client_index);
1559 bd_id = ntohl(mp->bd_id);
1561 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1562 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1563 for (; bd_index < end; bd_index++) {
1564 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1565 /* skip dummy bd_id 0 */
1566 if (bd_config && (bd_config->bd_id > 0)) {
1568 l2_flood_member_t * m;
1570 n_sw_ifs = vec_len (bd_config->members);
1571 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1573 vec_foreach (m, bd_config->members) {
1574 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1581 vl_api_l2fib_add_del_t_handler (
1582 vl_api_l2fib_add_del_t *mp)
1584 bd_main_t * bdm = &bd_main;
1585 l2input_main_t * l2im = &l2input_main;
1586 vl_api_l2fib_add_del_reply_t * rmp;
1589 u32 sw_if_index = ntohl(mp->sw_if_index);
1590 u32 bd_id = ntohl(mp->bd_id);
1598 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1600 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1601 goto bad_sw_if_index;
1606 VALIDATE_SW_IF_INDEX(mp);
1607 if (vec_len(l2im->configs) <= sw_if_index) {
1608 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1609 goto bad_sw_if_index;
1611 l2_input_config_t * config;
1612 config = vec_elt_at_index(l2im->configs, sw_if_index);
1613 if (config->bridge == 0) {
1614 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1615 goto bad_sw_if_index;
1618 static_mac = mp->static_mac ? 1 : 0;
1619 filter_mac = mp->filter_mac ? 1 : 0;
1620 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1623 l2fib_del_entry(mac, bd_index);
1626 BAD_SW_IF_INDEX_LABEL;
1628 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1632 vl_api_l2_flags_t_handler (
1633 vl_api_l2_flags_t *mp)
1635 vl_api_l2_flags_reply_t * rmp;
1637 u32 sw_if_index = ntohl(mp->sw_if_index);
1638 u32 flags = ntohl(mp->feature_bitmap);
1641 VALIDATE_SW_IF_INDEX(mp);
1644 if (flags & L2INPUT_FEAT_ ## a) \
1645 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1646 foreach_l2input_feat;
1649 BAD_SW_IF_INDEX_LABEL;
1651 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1655 vl_api_bridge_flags_t_handler (
1656 vl_api_bridge_flags_t *mp)
1658 vlib_main_t *vm = vlib_get_main();
1659 bd_main_t * bdm = &bd_main;
1660 vl_api_bridge_flags_reply_t * rmp;
1662 u32 bd_id = ntohl(mp->bd_id);
1664 u32 flags = ntohl(mp->feature_bitmap);
1667 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1669 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1675 bd_set_flags(vm, bd_index, flags, mp->is_set);
1678 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1679 rmp->resulting_feature_bitmap = ntohl(flags));
1683 vl_api_bd_ip_mac_add_del_t_handler (
1684 vl_api_bd_ip_mac_add_del_t *mp)
1686 bd_main_t * bdm = &bd_main;
1687 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1689 u32 bd_id = ntohl(mp->bd_id);
1693 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1695 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1700 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1701 mp->mac_address, mp->is_ipv6, mp->is_add))
1702 rv = VNET_API_ERROR_UNSPECIFIED;
1705 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1709 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1712 vl_api_tap_connect_reply_t * rmp;
1713 unix_shared_memory_queue_t * q;
1714 u32 sw_if_index = (u32)~0;
1716 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1717 mp->use_random_mac ? 0 : mp->mac_address,
1718 &sw_if_index, mp->renumber,
1719 ntohl(mp->custom_dev_instance));
1721 q = vl_api_client_index_to_input_queue (mp->client_index);
1725 rmp = vl_msg_api_alloc (sizeof (*rmp));
1726 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1727 rmp->context = mp->context;
1728 rmp->retval = ntohl(rv);
1729 rmp->sw_if_index = ntohl(sw_if_index);
1731 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1735 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1738 vl_api_tap_modify_reply_t * rmp;
1739 unix_shared_memory_queue_t * q;
1740 u32 sw_if_index = (u32)~0;
1742 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1743 mp->use_random_mac ? 0 : mp->mac_address,
1744 &sw_if_index, mp->renumber,
1745 ntohl(mp->custom_dev_instance));
1747 q = vl_api_client_index_to_input_queue (mp->client_index);
1751 rmp = vl_msg_api_alloc (sizeof (*rmp));
1752 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1753 rmp->context = mp->context;
1754 rmp->retval = ntohl(rv);
1755 rmp->sw_if_index = ntohl(sw_if_index);
1757 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1761 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1764 vpe_api_main_t * vam = &vpe_api_main;
1765 vl_api_tap_delete_reply_t * rmp;
1766 unix_shared_memory_queue_t * q;
1767 u32 sw_if_index = ntohl(mp->sw_if_index);
1769 rv = vnet_tap_delete (vm, sw_if_index);
1771 q = vl_api_client_index_to_input_queue (mp->client_index);
1775 rmp = vl_msg_api_alloc (sizeof (*rmp));
1776 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1777 rmp->context = mp->context;
1778 rmp->retval = ntohl(rv);
1780 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1783 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1787 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1789 vl_api_create_vlan_subif_reply_t * rmp;
1790 vnet_main_t * vnm = vnet_get_main();
1791 u32 hw_if_index, sw_if_index = (u32)~0;
1792 vnet_hw_interface_t * hi;
1795 vnet_sw_interface_t template;
1797 vnet_interface_main_t * im = &vnm->interface_main;
1798 u64 sup_and_sub_key;
1800 unix_shared_memory_queue_t * q;
1801 clib_error_t * error;
1803 VALIDATE_SW_IF_INDEX(mp);
1805 hw_if_index = ntohl(mp->sw_if_index);
1806 hi = vnet_get_hw_interface (vnm, hw_if_index);
1808 id = ntohl(mp->vlan_id);
1809 if (id == 0 || id > 4095) {
1810 rv = VNET_API_ERROR_INVALID_VLAN;
1814 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1816 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1818 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1822 kp = clib_mem_alloc (sizeof (*kp));
1823 *kp = sup_and_sub_key;
1825 memset (&template, 0, sizeof (template));
1826 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1827 template.sup_sw_if_index = hi->sw_if_index;
1828 template.sub.id = id;
1829 template.sub.eth.raw_flags = 0;
1830 template.sub.eth.flags.one_tag = 1;
1831 template.sub.eth.outer_vlan_id = id;
1832 template.sub.eth.flags.exact_match = 1;
1834 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1836 clib_error_report(error);
1837 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1840 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1841 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1843 BAD_SW_IF_INDEX_LABEL;
1846 q = vl_api_client_index_to_input_queue (mp->client_index);
1850 rmp = vl_msg_api_alloc (sizeof (*rmp));
1851 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1852 rmp->context = mp->context;
1853 rmp->retval = ntohl(rv);
1854 rmp->sw_if_index = ntohl(sw_if_index);
1855 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1859 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1861 vl_api_create_subif_reply_t * rmp;
1862 vnet_main_t * vnm = vnet_get_main();
1863 u32 sw_if_index = ~0;
1866 vnet_sw_interface_t *si;
1867 vnet_hw_interface_t *hi;
1868 vnet_sw_interface_t template;
1870 vnet_interface_main_t * im = &vnm->interface_main;
1871 u64 sup_and_sub_key;
1873 clib_error_t * error;
1875 VALIDATE_SW_IF_INDEX(mp);
1877 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1878 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1880 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1881 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1885 sw_if_index = si->sw_if_index;
1886 sub_id = ntohl(mp->sub_id);
1888 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1890 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1893 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1894 sw_if_index, sub_id);
1895 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1899 kp = clib_mem_alloc (sizeof (*kp));
1900 *kp = sup_and_sub_key;
1902 memset (&template, 0, sizeof (template));
1903 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1904 template.sup_sw_if_index = sw_if_index;
1905 template.sub.id = sub_id;
1906 template.sub.eth.flags.no_tags = mp->no_tags;
1907 template.sub.eth.flags.one_tag = mp->one_tag;
1908 template.sub.eth.flags.two_tags = mp->two_tags;
1909 template.sub.eth.flags.dot1ad = mp->dot1ad;
1910 template.sub.eth.flags.exact_match = mp->exact_match;
1911 template.sub.eth.flags.default_sub = mp->default_sub;
1912 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1913 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1914 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1915 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1917 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1919 clib_error_report (error);
1920 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1924 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1925 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1927 BAD_SW_IF_INDEX_LABEL;
1931 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1933 rmp->sw_if_index = ntohl(sw_if_index);
1938 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
1940 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
1942 stats_main_t * sm = &stats_main;
1943 u32 tunnel_sw_if_index = ~0;
1945 dslock (sm, 1 /* release hint */, 5 /* tag */);
1947 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
1948 (ip4_address_t *)(mp->dst_address),
1949 (ip4_address_t *)(mp->intfc_address),
1950 (u32)(mp->intfc_address_length),
1951 ntohl(mp->inner_vrf_id),
1952 ntohl(mp->outer_vrf_id),
1953 &tunnel_sw_if_index,
1958 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
1960 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1965 vl_api_mpls_ethernet_add_del_tunnel_t_handler
1966 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
1968 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
1970 stats_main_t * sm = &stats_main;
1971 u32 tunnel_sw_if_index;
1973 dslock (sm, 1 /* release hint */, 5 /* tag */);
1975 rv = vnet_mpls_ethernet_add_del_tunnel
1976 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
1977 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
1978 ntohl(mp->tx_sw_if_index),
1979 &tunnel_sw_if_index,
1985 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
1987 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
1992 * This piece of misery brought to you because the control-plane
1993 * can't figure out the tx interface + dst-mac address all by itself
1995 static int mpls_ethernet_add_del_tunnel_2_t_handler
1996 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
1998 pending_route_t * pr;
1999 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2000 vnet_main_t * vnm = vnet_get_main();
2001 vlib_main_t * vm = vlib_get_main();
2002 stats_main_t * sm = &stats_main;
2003 vpe_api_main_t * vam = &vpe_api_main;
2004 u32 inner_fib_index, outer_fib_index;
2005 ip4_main_t * im = &ip4_main;
2006 ip_lookup_main_t * lm = &im->lookup_main;
2007 ip_adjacency_t * adj = 0;
2010 u8 * dst_mac_address;
2014 u32 tunnel_sw_if_index;
2016 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2018 return VNET_API_ERROR_NO_SUCH_FIB;
2020 outer_fib_index = p[0];
2023 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2025 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2027 inner_fib_index = p[0];
2029 if (inner_fib_index == outer_fib_index)
2030 return VNET_API_ERROR_INVALID_VALUE;
2032 lookup_result = ip4_fib_lookup_with_table
2033 (im, outer_fib_index,
2034 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2035 1 /* disable default route */);
2037 adj = ip_get_adjacency (lm, lookup_result);
2038 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2040 if (mp->is_add && mp->resolve_if_needed) {
2041 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2042 pool_get (vam->pending_routes, pr);
2043 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2045 clib_memcpy (pme, mp, sizeof (*pme));
2046 /* recursion block, "just in case" */
2047 pme->resolve_if_needed = 0;
2048 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2049 pme->resolve_opaque = tx_sw_if_index;
2050 vnet_register_ip4_arp_resolution_event
2052 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2053 vpe_resolver_process_node.index,
2054 RESOLUTION_EVENT, pr - vam->pending_routes);
2056 vlib_process_signal_event
2057 (vm, vpe_resolver_process_node.index,
2058 RESOLUTION_PENDING_EVENT, 0 /* data */);
2060 /* The interface may be down, etc. */
2061 e = ip4_probe_neighbor
2062 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2066 clib_error_report(e);
2068 return VNET_API_ERROR_IN_PROGRESS;
2072 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2073 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2076 vnet_rewrite_get_data_internal
2077 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2079 dslock (sm, 1 /* release hint */, 10 /* tag */);
2081 rv = vnet_mpls_ethernet_add_del_tunnel
2082 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2083 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2084 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2092 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2093 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2095 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2098 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2100 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2105 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2107 vl_api_mpls_add_del_encap_reply_t * rmp;
2109 static u32 * labels;
2112 vec_reset_length (labels);
2114 for (i = 0; i < mp->nlabels; i++)
2115 vec_add1 (labels, ntohl(mp->labels[i]));
2118 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2119 ntohl(mp->vrf_id), labels,
2120 ~0 /* policy_tunnel_index */,
2121 0 /* no_dst_hash */,
2125 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2129 vl_api_mpls_add_del_decap_t_handler
2130 (vl_api_mpls_add_del_decap_t *mp)
2132 vl_api_mpls_add_del_decap_reply_t * rmp;
2135 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2136 ntohl(mp->label), ntohl(mp->next_index),
2137 mp->s_bit, mp->is_add);
2139 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2143 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2145 vl_api_proxy_arp_add_del_reply_t * rmp;
2148 ip4_main_t * im = &ip4_main;
2149 stats_main_t * sm = &stats_main;
2150 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2151 ip4_address_t *hi_addr,
2152 u32 fib_index, int is_del);
2155 dslock (sm, 1 /* release hint */, 6 /* tag */);
2157 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2160 rv = VNET_API_ERROR_NO_SUCH_FIB;
2166 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2167 (ip4_address_t *)mp->hi_address,
2168 fib_index, mp->is_add == 0);
2172 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2176 vl_api_proxy_arp_intfc_enable_disable_t_handler
2177 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2180 vnet_main_t * vnm = vnet_get_main();
2181 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2182 vnet_sw_interface_t * si;
2185 VALIDATE_SW_IF_INDEX(mp);
2187 sw_if_index = ntohl(mp->sw_if_index);
2189 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2191 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2195 si = vnet_get_sw_interface (vnm, sw_if_index);
2199 if (mp->enable_disable)
2200 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2202 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2204 BAD_SW_IF_INDEX_LABEL;
2207 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2211 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2213 vl_api_ip_neighbor_add_del_reply_t * rmp;
2214 vnet_main_t * vnm = vnet_get_main();
2217 stats_main_t * sm = &stats_main;
2219 VALIDATE_SW_IF_INDEX(mp);
2221 dslock (sm, 1 /* release hint */, 7 /* tag */);
2225 rv = vnet_set_ip6_ethernet_neighbor
2226 (vm, ntohl(mp->sw_if_index),
2227 (ip6_address_t *)(mp->dst_address),
2228 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2230 rv = vnet_unset_ip6_ethernet_neighbor
2231 (vm, ntohl(mp->sw_if_index),
2232 (ip6_address_t *)(mp->dst_address),
2233 mp->mac_address, sizeof(mp->mac_address));
2235 ip4_main_t * im = &ip4_main;
2236 ip_lookup_main_t * lm = &im->lookup_main;
2237 ethernet_arp_ip4_over_ethernet_address_t a;
2239 ip_adjacency_t *nh_adj;
2241 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2243 rv = VNET_API_ERROR_NO_SUCH_FIB;
2249 * Unfortunately, folks have a penchant for
2250 * adding interface addresses to the ARP cache, and
2251 * wondering why the forwarder eventually ASSERTs...
2253 ai = ip4_fib_lookup_with_table
2254 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2255 1 /* disable default route */);
2258 nh_adj = ip_get_adjacency (lm, ai);
2259 /* Never allow manipulation of a local adj! */
2260 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2261 clib_warning("%U matches local adj",
2263 (ip4_address_t *)(mp->dst_address));
2264 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2269 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2270 clib_memcpy (&a.ip4, mp->dst_address, 4);
2273 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2274 fib_index, &a, mp->is_static);
2276 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2280 BAD_SW_IF_INDEX_LABEL;
2283 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2287 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2290 vpe_main_t *rm = &vpe_main;
2291 ip4_main_t *im4 = &ip4_main;
2292 ip6_main_t *im6 = &ip6_main;
2293 ip_lookup_main_t * lm;
2298 u32 adj_index, sw_if_index;
2299 vl_api_is_address_reachable_t *rmp;
2300 ip_adjacency_t * adj;
2301 unix_shared_memory_queue_t *q;
2303 q = vl_api_client_index_to_input_queue (mp->client_index);
2305 increment_missing_api_client_counter (rm->vlib_main);
2309 rmp = vl_msg_api_alloc (sizeof (*rmp));
2310 clib_memcpy (rmp, mp, sizeof (*rmp));
2312 sw_if_index = mp->next_hop_sw_if_index;
2313 clib_memcpy (&addr, mp->address, sizeof (addr));
2315 lm = &im6->lookup_main;
2317 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2319 lm = &im4->lookup_main;
2321 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2323 if (adj_index == ~0) {
2327 adj = ip_get_adjacency (lm, adj_index);
2329 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2330 && adj->rewrite_header.sw_if_index == sw_if_index) {
2333 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2334 && adj->rewrite_header.sw_if_index == sw_if_index) {
2336 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2338 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2339 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2347 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2351 static void vl_api_sw_interface_details_t_handler (
2352 vl_api_sw_interface_details_t * mp)
2354 clib_warning ("BUG");
2357 static void vl_api_sw_interface_set_flags_t_handler (
2358 vl_api_sw_interface_set_flags_t * mp)
2360 vl_api_sw_interface_set_flags_reply_t *rmp;
2361 vnet_main_t * vnm = vnet_get_main();
2363 clib_error_t * error;
2366 VALIDATE_SW_IF_INDEX(mp);
2368 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2370 error = vnet_sw_interface_set_flags (vnm,
2371 ntohl(mp->sw_if_index),
2375 clib_error_report (error);
2378 BAD_SW_IF_INDEX_LABEL;
2379 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2382 static void vl_api_sw_interface_clear_stats_t_handler (
2383 vl_api_sw_interface_clear_stats_t * mp)
2385 vl_api_sw_interface_clear_stats_reply_t *rmp;
2387 vnet_main_t * vnm = vnet_get_main();
2388 vnet_interface_main_t * im = &vnm->interface_main;
2389 vlib_simple_counter_main_t * sm;
2390 vlib_combined_counter_main_t * cm;
2391 static vnet_main_t ** my_vnet_mains;
2392 int i, j, n_counters;
2396 vec_reset_length (my_vnet_mains);
2398 for (i = 0; i < vec_len (vnet_mains); i++)
2401 vec_add1 (my_vnet_mains, vnet_mains[i]);
2404 if (vec_len (vnet_mains) == 0)
2405 vec_add1 (my_vnet_mains, vnm);
2407 n_counters = vec_len (im->combined_sw_if_counters);
2409 for (j = 0; j < n_counters; j++)
2411 for (i = 0; i < vec_len(my_vnet_mains); i++)
2413 im = &my_vnet_mains[i]->interface_main;
2414 cm = im->combined_sw_if_counters + j;
2415 if (mp->sw_if_index == (u32)~0)
2416 vlib_clear_combined_counters (cm);
2418 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2422 n_counters = vec_len (im->sw_if_counters);
2424 for (j = 0; j < n_counters; j++)
2426 for (i = 0; i < vec_len(my_vnet_mains); i++)
2428 im = &my_vnet_mains[i]->interface_main;
2429 sm = im->sw_if_counters + j;
2430 if (mp->sw_if_index == (u32)~0)
2431 vlib_clear_simple_counters (sm);
2433 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2437 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2440 static void send_sw_interface_details (vpe_api_main_t * am,
2441 unix_shared_memory_queue_t *q,
2442 vnet_sw_interface_t * swif,
2443 u8 * interface_name,
2446 vl_api_sw_interface_details_t * mp;
2447 vnet_hw_interface_t * hi;
2449 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2451 mp = vl_msg_api_alloc (sizeof (*mp));
2452 memset (mp, 0, sizeof (*mp));
2453 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2454 mp->sw_if_index = ntohl(swif->sw_if_index);
2455 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2456 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2458 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2460 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2461 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2462 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2463 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2464 mp->link_mtu = ntohs(hi->max_packet_bytes);
2465 mp->context = context;
2467 strncpy ((char *) mp->interface_name,
2468 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2470 /* Send the L2 address for ethernet physical intfcs */
2471 if (swif->sup_sw_if_index == swif->sw_if_index
2472 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2473 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2474 ethernet_interface_t *ei;
2476 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2477 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2478 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2479 mp->l2_address_length = ntohl(sizeof (ei->address));
2480 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2481 vnet_sub_interface_t *sub = &swif->sub;
2482 mp->sub_id = ntohl(sub->id);
2483 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2484 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2485 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2486 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2487 mp->sub_exact_match = sub->eth.flags.exact_match;
2488 mp->sub_default = sub->eth.flags.default_sub;
2489 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2490 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2492 /* vlan tag rewrite data */
2493 u32 vtr_op = L2_VTR_DISABLED;
2494 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2496 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2497 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2498 // error - default to disabled
2499 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2500 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2503 mp->vtr_op = ntohl(vtr_op);
2504 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2505 mp->vtr_tag1 = ntohl(vtr_tag1);
2506 mp->vtr_tag2 = ntohl(vtr_tag2);
2510 vl_msg_api_send_shmem (q, (u8 *)&mp);
2513 static void send_sw_interface_flags (vpe_api_main_t * am,
2514 unix_shared_memory_queue_t *q,
2515 vnet_sw_interface_t * swif)
2517 vl_api_sw_interface_set_flags_t *mp;
2518 vnet_main_t * vnm = am->vnet_main;
2520 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2522 mp = vl_msg_api_alloc (sizeof (*mp));
2523 memset (mp, 0, sizeof (*mp));
2524 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2525 mp->sw_if_index = ntohl(swif->sw_if_index);
2527 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2529 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2531 vl_msg_api_send_shmem (q, (u8 *)&mp);
2534 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2535 unix_shared_memory_queue_t *q,
2537 __attribute__((unused));
2539 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2540 unix_shared_memory_queue_t *q,
2543 vl_api_sw_interface_set_flags_t *mp;
2545 mp = vl_msg_api_alloc (sizeof (*mp));
2546 memset (mp, 0, sizeof (*mp));
2547 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2548 mp->sw_if_index = ntohl(sw_if_index);
2550 mp->admin_up_down = 0;
2551 mp->link_up_down = 0;
2553 vl_msg_api_send_shmem (q, (u8 *)&mp);
2556 static void vl_api_sw_interface_dump_t_handler (
2557 vl_api_sw_interface_dump_t *mp)
2559 vpe_api_main_t * am = &vpe_api_main;
2560 vnet_sw_interface_t * swif;
2561 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2562 u8 * filter_string = 0, * name_string = 0;
2563 unix_shared_memory_queue_t * q;
2564 char * strcasestr (char *, char *); /* lnx hdr file botch */
2566 q = vl_api_client_index_to_input_queue (mp->client_index);
2571 if (mp->name_filter_valid) {
2572 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2573 filter_string = format (0, "%s%c", mp->name_filter, 0);
2576 pool_foreach (swif, im->sw_interfaces,
2578 name_string = format (name_string, "%U%c",
2579 format_vnet_sw_interface_name,
2580 am->vnet_main, swif, 0);
2582 if (mp->name_filter_valid == 0 ||
2583 strcasestr((char *) name_string, (char *) filter_string)) {
2585 send_sw_interface_details (am, q, swif, name_string, mp->context);
2586 send_sw_interface_flags (am, q, swif);
2588 _vec_len (name_string) = 0;
2591 vec_free (name_string);
2592 vec_free (filter_string);
2595 void send_oam_event (oam_target_t * t)
2597 vpe_api_main_t * vam = &vpe_api_main;
2598 unix_shared_memory_queue_t * q;
2599 vpe_client_registration_t *reg;
2600 vl_api_oam_event_t * mp;
2602 pool_foreach(reg, vam->oam_events_registrations,
2604 q = vl_api_client_index_to_input_queue (reg->client_index);
2606 mp = vl_msg_api_alloc (sizeof (*mp));
2607 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2608 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2609 mp->state = t->state;
2610 vl_msg_api_send_shmem (q, (u8 *)&mp);
2616 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2618 vl_api_oam_add_del_reply_t * rmp;
2621 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2622 (ip4_address_t *)mp->dst_address,
2626 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2630 vl_api_vnet_get_summary_stats_t_handler (
2631 vl_api_vnet_get_summary_stats_t *mp)
2633 stats_main_t * sm = &stats_main;
2634 vnet_interface_main_t * im = sm->interface_main;
2635 vl_api_vnet_summary_stats_reply_t *rmp;
2636 vlib_combined_counter_main_t * cm;
2639 u64 total_pkts[VLIB_N_RX_TX];
2640 u64 total_bytes[VLIB_N_RX_TX];
2642 unix_shared_memory_queue_t * q =
2643 vl_api_client_index_to_input_queue (mp->client_index);
2648 rmp = vl_msg_api_alloc (sizeof (*rmp));
2649 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2650 rmp->context = mp->context;
2653 memset (total_pkts, 0, sizeof (total_pkts));
2654 memset (total_bytes, 0, sizeof (total_bytes));
2656 vnet_interface_counter_lock (im);
2658 vec_foreach (cm, im->combined_sw_if_counters) {
2659 which = cm - im->combined_sw_if_counters;
2661 for (i = 0; i < vec_len (cm->maxi); i++) {
2662 vlib_get_combined_counter (cm, i, &v);
2663 total_pkts[which] += v.packets;
2664 total_bytes[which] += v.bytes;
2667 vnet_interface_counter_unlock (im);
2669 /* Note: in HOST byte order! */
2670 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2671 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2672 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2673 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2674 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2676 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2679 typedef CLIB_PACKED (struct {
2680 ip4_address_t address;
2682 u32 address_length : 6;
2687 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2689 vnet_main_t * vnm = vnet_get_main();
2690 vnet_interface_main_t * im = &vnm->interface_main;
2691 ip4_main_t * im4 = &ip4_main;
2692 static ip4_route_t * routes;
2693 static u32 * sw_if_indices_to_shut;
2694 stats_main_t * sm = &stats_main;
2699 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2700 u32 target_fib_id = ntohl(mp->vrf_id);
2702 dslock (sm, 1 /* release hint */, 8 /* tag */);
2704 vec_foreach (fib, im4->fibs) {
2705 vnet_sw_interface_t * si;
2707 if (fib->table_id != target_fib_id)
2710 /* remove any mpls/gre tunnels in this fib */
2711 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2713 /* remove any mpls encap/decap labels */
2714 mpls_fib_reset_labels (fib->table_id);
2716 /* remove any proxy arps in this fib */
2717 vnet_proxy_arp_fib_reset (fib->table_id);
2719 /* Set the flow hash for this fib to the default */
2720 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2722 vec_reset_length (sw_if_indices_to_shut);
2724 /* Shut down interfaces in this FIB / clean out intfc routes */
2725 pool_foreach (si, im->sw_interfaces,
2727 u32 sw_if_index = si->sw_if_index;
2729 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2730 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2732 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2735 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2736 sw_if_index = sw_if_indices_to_shut[i];
2737 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2739 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2740 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2741 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2744 vec_reset_length (routes);
2746 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2747 uword * hash = fib->adj_index_by_dst_address[i];
2751 x.address_length = i;
2753 hash_foreach_pair (p, hash,
2755 x.address.data_u32 = p->key;
2756 vec_add1 (routes, x);
2760 vec_foreach (r, routes) {
2761 ip4_add_del_route_args_t a;
2763 memset (&a, 0, sizeof (a));
2764 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2765 a.table_index_or_table_id = fib - im4->fibs;
2766 a.dst_address = r->address;
2767 a.dst_address_length = r->address_length;
2770 ip4_add_del_route (im4, &a);
2771 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2772 IP4_ROUTE_FLAG_FIB_INDEX);
2776 } /* vec_foreach (fib) */
2783 ip6_address_t address;
2790 ip6_route_t ** routep;
2791 } add_routes_in_fib_arg_t;
2793 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2795 add_routes_in_fib_arg_t * ap = arg;
2797 if (kvp->key[2]>>32 == ap->fib_index)
2799 ip6_address_t *addr;
2801 addr = (ip6_address_t *) kvp;
2802 vec_add2 (*ap->routep, r, 1);
2803 r->address = addr[0];
2804 r->address_length = kvp->key[2] & 0xFF;
2805 r->index = kvp->value;
2809 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2811 vnet_main_t * vnm = vnet_get_main();
2812 vnet_interface_main_t * im = &vnm->interface_main;
2813 ip6_main_t * im6 = &ip6_main;
2814 stats_main_t * sm = &stats_main;
2815 static ip6_route_t * routes;
2816 static u32 * sw_if_indices_to_shut;
2821 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2822 u32 target_fib_id = ntohl(mp->vrf_id);
2823 add_routes_in_fib_arg_t _a, *a=&_a;
2824 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2826 dslock (sm, 1 /* release hint */, 9 /* tag */);
2828 vec_foreach (fib, im6->fibs) {
2829 vnet_sw_interface_t * si;
2831 if (fib->table_id != target_fib_id)
2834 vec_reset_length (sw_if_indices_to_shut);
2836 /* Shut down interfaces in this FIB / clean out intfc routes */
2837 pool_foreach (si, im->sw_interfaces,
2839 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2841 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2844 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2845 sw_if_index = sw_if_indices_to_shut[i];
2846 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2848 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2849 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2850 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2853 vec_reset_length (routes);
2855 a->fib_index = fib - im6->fibs;
2856 a->routep = &routes;
2858 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2860 vec_foreach (r, routes) {
2861 ip6_add_del_route_args_t a;
2863 memset (&a, 0, sizeof (a));
2864 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2865 a.table_index_or_table_id = fib - im6->fibs;
2866 a.dst_address = r->address;
2867 a.dst_address_length = r->address_length;
2870 ip6_add_del_route (im6, &a);
2871 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2872 IP6_ROUTE_FLAG_FIB_INDEX);
2875 /* Reinstall the neighbor / router discovery routes */
2876 vnet_ip6_fib_init (im6, fib - im6->fibs);
2878 } /* vec_foreach (fib) */
2884 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2887 vl_api_reset_fib_reply_t * rmp;
2890 rv = ip6_reset_fib_t_handler (mp);
2892 rv = ip4_reset_fib_t_handler (mp);
2894 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2899 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2901 vl_api_dhcp_proxy_config_reply_t * rmp;
2904 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2905 (ip4_address_t *)(&mp->dhcp_src_address),
2906 (u32) ntohl(mp->vrf_id),
2907 (int) mp->insert_circuit_id,
2908 (int) (mp->is_add == 0));
2910 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2915 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2917 vl_api_dhcp_proxy_config_reply_t * rmp;
2920 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2921 (ip6_address_t *)(&mp->dhcp_src_address),
2922 (u32) ntohl(mp->vrf_id),
2923 (int) mp->insert_circuit_id,
2924 (int) (mp->is_add == 0));
2926 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2930 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2932 vl_api_dhcp_proxy_config_reply_t * rmp;
2935 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2936 (ip4_address_t *)(&mp->dhcp_src_address),
2937 (u32) ntohl(mp->rx_vrf_id),
2938 (u32) ntohl(mp->server_vrf_id),
2939 (int) mp->insert_circuit_id,
2940 (int) (mp->is_add == 0));
2942 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2947 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2949 vl_api_dhcp_proxy_config_reply_t * rmp;
2953 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
2954 (ip6_address_t *)(&mp->dhcp_src_address),
2955 (u32) ntohl(mp->rx_vrf_id),
2956 (u32) ntohl(mp->server_vrf_id),
2957 (int) mp->insert_circuit_id,
2958 (int) (mp->is_add == 0));
2960 rv = VNET_API_ERROR_UNIMPLEMENTED;
2963 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
2968 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
2970 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
2973 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
2976 (int)mp->is_add == 0);
2978 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
2981 (int)mp->is_add == 0);
2983 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
2987 static void vl_api_dhcp_proxy_config_t_handler
2988 (vl_api_dhcp_proxy_config_t *mp)
2990 if (mp->is_ipv6 == 0)
2991 dhcpv4_proxy_config (mp);
2993 dhcpv6_proxy_config (mp);
2996 static void vl_api_dhcp_proxy_config_2_t_handler
2997 (vl_api_dhcp_proxy_config_2_t *mp)
2999 if (mp->is_ipv6 == 0)
3000 dhcpv4_proxy_config_2 (mp);
3002 dhcpv6_proxy_config_2 (mp);
3005 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3006 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3008 unix_shared_memory_queue_t * q;
3009 vl_api_dhcp_compl_event_t * mp;
3011 q = vl_api_client_index_to_input_queue (client_index);
3015 mp = vl_msg_api_alloc (sizeof (*mp));
3016 mp->client_index = client_index;
3018 mp->is_ipv6 = is_ipv6;
3019 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3020 mp->hostname[vec_len(hostname) + 1] = '\n';
3021 clib_memcpy (&mp->host_address[0], host_address, 16);
3022 clib_memcpy (&mp->router_address[0], router_address, 16);
3023 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3025 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3027 vl_msg_api_send_shmem (q, (u8 *)&mp);
3030 static void vl_api_dhcp_client_config_t_handler
3031 (vl_api_dhcp_client_config_t *mp)
3033 vlib_main_t *vm = vlib_get_main();
3034 vl_api_dhcp_client_config_reply_t * rmp;
3037 VALIDATE_SW_IF_INDEX(mp);
3039 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3040 mp->hostname, mp->is_add, mp->client_index,
3041 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3044 BAD_SW_IF_INDEX_LABEL;
3046 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3050 vl_api_sw_interface_ip6nd_ra_config_t_handler
3051 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3053 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3055 u8 is_no, surpress, managed, other, ll_option, send_unicast, cease, default_router;
3057 is_no = mp->is_no == 1;
3058 surpress = mp->surpress == 1;
3059 managed = mp->managed == 1;
3060 other = mp->other == 1;
3061 ll_option = mp->ll_option == 1;
3062 send_unicast = mp->send_unicast == 1;
3063 cease = mp->cease == 1;
3064 default_router = mp->default_router == 1;
3066 VALIDATE_SW_IF_INDEX(mp);
3068 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3069 surpress, managed, other,
3070 ll_option, send_unicast, cease,
3071 default_router, ntohl (mp->lifetime),
3072 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3073 ntohl(mp->max_interval), ntohl( mp->min_interval),
3076 BAD_SW_IF_INDEX_LABEL;
3078 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3082 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3083 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3085 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3087 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3089 VALIDATE_SW_IF_INDEX(mp);
3091 is_no = mp->is_no == 1;
3092 use_default = mp->use_default == 1;
3093 no_advertise = mp->no_advertise == 1;
3094 off_link = mp->off_link == 1;
3095 no_autoconfig = mp->no_autoconfig == 1;
3096 no_onlink = mp->no_onlink == 1;
3098 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3099 (ip6_address_t *)mp->address, mp->address_length,
3100 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3101 no_advertise, off_link, no_autoconfig, no_onlink,
3104 BAD_SW_IF_INDEX_LABEL;
3105 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3109 vl_api_sw_interface_ip6_enable_disable_t_handler
3110 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3112 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3113 vnet_main_t * vnm = vnet_get_main();
3115 clib_error_t * error;
3119 VALIDATE_SW_IF_INDEX(mp);
3121 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3122 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3125 clib_error_report(error);
3126 rv = VNET_API_ERROR_UNSPECIFIED;
3128 rv = vnm->api_errno;
3131 BAD_SW_IF_INDEX_LABEL;
3133 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3137 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3138 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3140 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3142 clib_error_t * error;
3143 vnet_main_t * vnm = vnet_get_main();
3147 VALIDATE_SW_IF_INDEX(mp);
3149 error = set_ip6_link_local_address(vm,
3150 ntohl(mp->sw_if_index),
3151 (ip6_address_t *)mp->address,
3152 mp->address_length);
3154 clib_error_report(error);
3155 rv = VNET_API_ERROR_UNSPECIFIED;
3157 rv = vnm->api_errno;
3160 BAD_SW_IF_INDEX_LABEL;
3162 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3165 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3167 vl_api_set_ip_flow_hash_reply_t *rmp;
3168 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3170 clib_warning ("unimplemented...");
3172 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3175 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3177 vl_api_set_ip_flow_hash_reply_t *rmp;
3180 u32 flow_hash_config = 0;
3182 table_id = ntohl(mp->vrf_id);
3184 #define _(a,b) if (mp->a) flow_hash_config |= b;
3185 foreach_flow_hash_bit;
3188 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3190 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3194 static void vl_api_set_ip_flow_hash_t_handler
3195 (vl_api_set_ip_flow_hash_t *mp)
3197 if (mp->is_ipv6 == 0)
3198 set_ip4_flow_hash (mp);
3200 set_ip6_flow_hash (mp);
3203 static void vl_api_sw_interface_set_unnumbered_t_handler
3204 (vl_api_sw_interface_set_unnumbered_t *mp)
3206 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3208 vnet_sw_interface_t * si;
3209 vnet_main_t *vnm = vnet_get_main();
3210 u32 sw_if_index, unnumbered_sw_if_index;
3212 sw_if_index = ntohl(mp->sw_if_index);
3213 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3216 * The API message field names are backwards from
3217 * the underlying data structure names.
3218 * It's not worth changing them now.
3220 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3221 unnumbered_sw_if_index)) {
3222 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3226 /* Only check the "use loop0" field when setting the binding */
3228 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3229 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3233 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3236 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3237 si->unnumbered_sw_if_index = sw_if_index;
3239 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3240 si->unnumbered_sw_if_index = (u32)~0;
3244 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3247 static void vl_api_create_loopback_t_handler
3248 (vl_api_create_loopback_t *mp)
3250 vl_api_create_loopback_reply_t * rmp;
3254 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3256 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3258 rmp->sw_if_index = ntohl (sw_if_index);
3262 static void vl_api_delete_loopback_t_handler
3263 (vl_api_delete_loopback_t *mp)
3265 vl_api_delete_loopback_reply_t * rmp;
3269 sw_if_index = ntohl (mp->sw_if_index);
3270 rv = vnet_delete_loopback_interface (sw_if_index);
3272 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3275 static void vl_api_control_ping_t_handler
3276 (vl_api_control_ping_t *mp)
3278 vl_api_control_ping_reply_t * rmp;
3281 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3283 rmp->vpe_pid = ntohl (getpid());
3287 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3289 u8 **shmem_vecp = (u8 **)arg;
3292 api_main_t * am = &api_main;
3295 shmem_vec = *shmem_vecp;
3297 offset = vec_len (shmem_vec);
3299 pthread_mutex_lock (&am->vlib_rp->mutex);
3300 oldheap = svm_push_data_heap (am->vlib_rp);
3302 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3304 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3306 svm_pop_heap (oldheap);
3307 pthread_mutex_unlock (&am->vlib_rp->mutex);
3309 *shmem_vecp = shmem_vec;
3313 static void vl_api_cli_request_t_handler
3314 (vl_api_cli_request_t *mp)
3316 vl_api_cli_reply_t *rp;
3317 unix_shared_memory_queue_t *q;
3318 vlib_main_t * vm = vlib_get_main();
3319 api_main_t * am = &api_main;
3320 unformat_input_t input;
3324 q = vl_api_client_index_to_input_queue (mp->client_index);
3328 rp = vl_msg_api_alloc (sizeof (*rp));
3329 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3330 rp->context = mp->context;
3332 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3334 vlib_cli_input (vm, &input, shmem_cli_output,
3337 pthread_mutex_lock (&am->vlib_rp->mutex);
3338 oldheap = svm_push_data_heap (am->vlib_rp);
3340 vec_add1(shmem_vec, 0);
3342 svm_pop_heap (oldheap);
3343 pthread_mutex_unlock (&am->vlib_rp->mutex);
3345 rp->reply_in_shmem = (uword)shmem_vec;
3347 vl_msg_api_send_shmem (q, (u8 *)&rp);
3350 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3353 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3354 vnet_main_t *vnm = vnet_get_main();
3355 clib_error_t * error;
3360 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3362 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3365 clib_error_report(error);
3366 rv = VNET_API_ERROR_UNSPECIFIED;
3368 rv = vnm->api_errno;
3371 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3374 static void vl_api_sr_tunnel_add_del_t_handler
3375 (vl_api_sr_tunnel_add_del_t *mp)
3378 clib_warning ("unimplemented");
3380 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3382 vl_api_sr_tunnel_add_del_reply_t * rmp;
3383 ip6_address_t * segments = 0, * seg;
3384 ip6_address_t * tags = 0, *tag;
3385 ip6_address_t * this_address;
3388 if (mp->n_segments == 0) {
3393 memset (a, 0, sizeof (*a));
3394 a->src_address = (ip6_address_t *)&mp->src_address;
3395 a->dst_address = (ip6_address_t *)&mp->dst_address;
3396 a->dst_mask_width = mp->dst_mask_width;
3397 a->flags_net_byte_order = mp->flags_net_byte_order;
3398 a->is_del = (mp->is_add == 0);
3399 a->rx_table_id = ntohl(mp->outer_vrf_id);
3400 a->tx_table_id = ntohl(mp->inner_vrf_id);
3402 a->name = format(0, "%s", mp->name);
3403 if (!(vec_len(a->name)))
3406 a->policy_name = format(0, "%s", mp->policy_name);
3407 if (!(vec_len(a->policy_name)))
3410 /* Yank segments and tags out of the API message */
3411 this_address = (ip6_address_t *)mp->segs_and_tags;
3412 for (i = 0; i < mp->n_segments; i++) {
3413 vec_add2 (segments, seg, 1);
3414 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3417 for (i = 0; i < mp->n_tags; i++) {
3418 vec_add2 (tags, tag, 1);
3419 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3423 a->segments = segments;
3426 rv = ip6_sr_add_del_tunnel (a);
3430 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3434 static void vl_api_sr_policy_add_del_t_handler
3435 (vl_api_sr_policy_add_del_t *mp)
3438 clib_warning ("unimplemented");
3440 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3442 vl_api_sr_policy_add_del_reply_t * rmp;
3445 memset (a, 0, sizeof (*a));
3446 a->is_del = (mp->is_add == 0);
3448 a->name = format(0, "%s", mp->name);
3449 if (!(vec_len(a->name)))
3451 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3455 if (!(mp->tunnel_names[0]))
3457 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3461 // start deserializing tunnel_names
3462 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3463 u8 * deser_tun_names = mp->tunnel_names;
3464 deser_tun_names += 1; //moving along
3467 int tun_name_len = 0;
3469 for (i=0; i < num_tunnels; i++)
3471 tun_name_len= *deser_tun_names;
3472 deser_tun_names += 1;
3473 vec_resize (tun_name, tun_name_len);
3474 memcpy(tun_name, deser_tun_names, tun_name_len);
3475 vec_add1 (a->tunnel_names, tun_name);
3476 deser_tun_names += tun_name_len;
3480 rv = ip6_sr_add_del_policy (a);
3484 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3488 static void vl_api_sr_multicast_map_add_del_t_handler
3489 (vl_api_sr_multicast_map_add_del_t *mp)
3492 clib_warning ("unimplemented");
3494 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3496 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3498 memset (a, 0, sizeof (*a));
3499 a->is_del = (mp->is_add == 0);
3501 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3502 a->policy_name = format(0, "%s", mp->policy_name);
3504 if (a->multicast_address == 0)
3510 if (!(a->policy_name))
3516 #if DPDK > 0 /* Cannot call replicate without DPDK */
3517 rv = ip6_sr_add_del_multicastmap (a);
3519 clib_warning ("multicast replication without DPDK not implemented");
3520 rv = VNET_API_ERROR_UNIMPLEMENTED;
3525 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3529 #define foreach_classify_add_del_table_field \
3534 _(match_n_vectors) \
3535 _(next_table_index) \
3538 static void vl_api_classify_add_del_table_t_handler
3539 (vl_api_classify_add_del_table_t * mp)
3541 vl_api_classify_add_del_table_reply_t * rmp;
3542 vnet_classify_main_t * cm = &vnet_classify_main;
3543 vnet_classify_table_t * t;
3547 foreach_classify_add_del_table_field;
3550 #define _(a) a = ntohl(mp->a);
3551 foreach_classify_add_del_table_field;
3554 /* The underlying API fails silently, on purpose, so check here */
3555 if (mp->is_add == 0)
3556 if (pool_is_free_index (cm->tables, table_index)) {
3557 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3561 rv = vnet_classify_add_del_table
3562 (cm, mp->mask, nbuckets, memory_size,
3563 skip_n_vectors, match_n_vectors,
3564 next_table_index, miss_next_index,
3565 &table_index, mp->is_add);
3568 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3570 if (rv == 0 && mp->is_add) {
3571 t = pool_elt_at_index (cm->tables, table_index);
3572 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3573 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3574 rmp->new_table_index = ntohl(table_index);
3576 rmp->skip_n_vectors = ~0;
3577 rmp->match_n_vectors = ~0;
3578 rmp->new_table_index = ~0;
3583 static void vl_api_classify_add_del_session_t_handler
3584 (vl_api_classify_add_del_session_t * mp)
3586 vnet_classify_main_t * cm = &vnet_classify_main;
3587 vl_api_classify_add_del_session_reply_t * rmp;
3589 u32 table_index, hit_next_index, opaque_index;
3592 table_index = ntohl (mp->table_index);
3593 hit_next_index = ntohl (mp->hit_next_index);
3594 opaque_index = ntohl (mp->opaque_index);
3595 advance = ntohl (mp->advance);
3597 rv = vnet_classify_add_del_session
3598 (cm, table_index, mp->match, hit_next_index, opaque_index,
3599 advance, mp->is_add);
3601 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3604 static void vl_api_classify_set_interface_ip_table_t_handler
3605 (vl_api_classify_set_interface_ip_table_t * mp)
3607 vlib_main_t * vm = vlib_get_main();
3608 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3610 u32 table_index, sw_if_index;
3612 table_index = ntohl (mp->table_index);
3613 sw_if_index = ntohl (mp->sw_if_index);
3615 VALIDATE_SW_IF_INDEX(mp);
3618 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3620 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3622 BAD_SW_IF_INDEX_LABEL;
3624 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3627 static void vl_api_classify_set_interface_l2_tables_t_handler
3628 (vl_api_classify_set_interface_l2_tables_t * mp)
3630 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3632 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3635 ip4_table_index = ntohl(mp->ip4_table_index);
3636 ip6_table_index = ntohl(mp->ip6_table_index);
3637 other_table_index = ntohl(mp->other_table_index);
3638 sw_if_index = ntohl(mp->sw_if_index);
3640 VALIDATE_SW_IF_INDEX(mp);
3642 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3643 ip6_table_index, other_table_index);
3646 if (ip4_table_index != ~0 || ip6_table_index != ~0
3647 || other_table_index != ~0)
3652 vnet_l2_classify_enable_disable (sw_if_index, enable);
3655 BAD_SW_IF_INDEX_LABEL;
3657 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3661 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3664 vl_api_l2_fib_clear_table_reply_t * rmp;
3666 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3667 * that is not currently implemented. When that TODO is fixed
3668 * this call should be changed to pass 1 instead of 0.
3670 l2fib_clear_table (0);
3672 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3675 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3680 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3683 vl_api_l2_interface_efp_filter_reply_t * rmp;
3684 vnet_main_t *vnm = vnet_get_main();
3686 // enable/disable the feature
3687 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3688 rv = vnm->api_errno;
3690 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3694 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3697 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3698 vnet_main_t * vnm = vnet_get_main();
3699 vlib_main_t * vm = vlib_get_main();
3702 VALIDATE_SW_IF_INDEX(mp);
3704 vtr_op = ntohl(mp->vtr_op);
3706 /* The L2 code is unsuspicious */
3708 case L2_VTR_DISABLED:
3713 case L2_VTR_TRANSLATE_1_1:
3714 case L2_VTR_TRANSLATE_1_2:
3715 case L2_VTR_TRANSLATE_2_1:
3716 case L2_VTR_TRANSLATE_2_2:
3720 rv = VNET_API_ERROR_INVALID_VALUE;
3721 goto bad_sw_if_index;
3724 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3725 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3728 BAD_SW_IF_INDEX_LABEL;
3730 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3734 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3738 vl_api_create_vhost_user_if_reply_t * rmp;
3739 u32 sw_if_index = (u32)~0;
3741 vnet_main_t * vnm = vnet_get_main();
3742 vlib_main_t * vm = vlib_get_main();
3744 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3745 mp->is_server, &sw_if_index, (u64)~0,
3746 mp->renumber, ntohl(mp->custom_dev_instance),
3747 (mp->use_custom_mac)?mp->mac_address:NULL);
3749 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3751 rmp->sw_if_index = ntohl (sw_if_index);
3757 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3761 vl_api_modify_vhost_user_if_reply_t * rmp;
3762 u32 sw_if_index = ntohl(mp->sw_if_index);
3764 vnet_main_t * vnm = vnet_get_main();
3765 vlib_main_t * vm = vlib_get_main();
3767 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3768 mp->is_server, sw_if_index, (u64)~0,
3769 mp->renumber, ntohl(mp->custom_dev_instance));
3771 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3776 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3780 vpe_api_main_t * vam = &vpe_api_main;
3781 vl_api_delete_vhost_user_if_reply_t * rmp;
3782 u32 sw_if_index = ntohl(mp->sw_if_index);
3784 vnet_main_t * vnm = vnet_get_main();
3785 vlib_main_t * vm = vlib_get_main();
3787 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3789 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3791 unix_shared_memory_queue_t * q =
3792 vl_api_client_index_to_input_queue (mp->client_index);
3796 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3801 static void vl_api_sw_interface_vhost_user_details_t_handler (
3802 vl_api_sw_interface_vhost_user_details_t * mp)
3804 clib_warning ("BUG");
3808 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3809 unix_shared_memory_queue_t *q,
3810 vhost_user_intf_details_t * vui,
3813 vl_api_sw_interface_vhost_user_details_t * mp;
3815 mp = vl_msg_api_alloc (sizeof (*mp));
3816 memset (mp, 0, sizeof (*mp));
3817 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3818 mp->sw_if_index = ntohl(vui->sw_if_index);
3819 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3820 mp->features = clib_net_to_host_u64 (vui->features);
3821 mp->is_server = vui->is_server;
3822 mp->num_regions = ntohl(vui->num_regions);
3823 mp->sock_errno = ntohl(vui->sock_errno);
3824 mp->context = context;
3826 strncpy ((char *) mp->sock_filename,
3827 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3828 strncpy ((char *) mp->interface_name,
3829 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3831 vl_msg_api_send_shmem (q, (u8 *)&mp);
3836 vl_api_sw_interface_vhost_user_dump_t_handler (
3837 vl_api_sw_interface_vhost_user_dump_t *mp)
3841 vpe_api_main_t * am = &vpe_api_main;
3842 vnet_main_t * vnm = vnet_get_main();
3843 vlib_main_t * vm = vlib_get_main();
3844 vhost_user_intf_details_t *ifaces = NULL;
3845 vhost_user_intf_details_t *vuid = NULL;
3846 unix_shared_memory_queue_t * q;
3848 q = vl_api_client_index_to_input_queue (mp->client_index);
3852 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3856 vec_foreach (vuid, ifaces) {
3857 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3863 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3864 unix_shared_memory_queue_t *q,
3869 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3870 u8 * if_name = NULL;
3871 vnet_sw_interface_t * si = NULL;
3873 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3875 if_name = format(if_name, "%U",
3876 format_vnet_sw_interface_name, lm->vnet_main, si);
3878 mp = vl_msg_api_alloc (sizeof (*mp));
3879 memset (mp, 0, sizeof (*mp));
3880 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3881 strncpy((char *)mp->interface_name,
3882 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3883 mp->sw_if_index = ntohl(si->sw_if_index);
3884 mp->local_session_id = s->local_session_id;
3885 mp->remote_session_id = s->remote_session_id;
3886 mp->local_cookie[0] = s->local_cookie[0];
3887 mp->local_cookie[1] = s->local_cookie[1];
3888 mp->remote_cookie = s->remote_cookie;
3889 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3890 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3891 mp->l2_sublayer_present = s->l2_sublayer_present;
3892 mp->context = context;
3894 vl_msg_api_send_shmem (q, (u8 *)&mp);
3897 static void send_ip_address_details (vpe_api_main_t * am,
3898 unix_shared_memory_queue_t * q,
3904 vl_api_ip_address_details_t * mp;
3906 mp = vl_msg_api_alloc (sizeof (*mp));
3907 memset (mp, 0, sizeof (*mp));
3908 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3911 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3913 u32 * tp = (u32 *)mp->ip;
3914 *tp = ntohl(*(u32*)ip);
3916 mp->prefix_length = prefix_length;
3917 mp->context = context;
3919 vl_msg_api_send_shmem (q, (u8 *)&mp);
3923 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3925 vpe_api_main_t * am = &vpe_api_main;
3926 unix_shared_memory_queue_t * q;
3929 ip6_main_t * im6 = &ip6_main;
3930 ip4_main_t * im4 = &ip4_main;
3931 ip_lookup_main_t * lm6 = &im6->lookup_main;
3932 ip_lookup_main_t * lm4 = &im4->lookup_main;
3933 ip_interface_address_t * ia = 0;
3934 u32 sw_if_index = ~0;
3935 int rv __attribute__ ((unused)) = 0;
3937 VALIDATE_SW_IF_INDEX(mp);
3939 sw_if_index = ntohl(mp->sw_if_index);
3941 q = vl_api_client_index_to_input_queue (mp->client_index);
3947 foreach_ip_interface_address (lm6, ia, sw_if_index,
3948 1 /* honor unnumbered */,
3950 r6 = ip_interface_address_get_address (lm6, ia);
3951 u16 prefix_length = ia->address_length;
3952 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
3955 foreach_ip_interface_address (lm4, ia, sw_if_index,
3956 1 /* honor unnumbered */,
3958 r4 = ip_interface_address_get_address (lm4, ia);
3959 u16 prefix_length = ia->address_length;
3960 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
3963 BAD_SW_IF_INDEX_LABEL;
3966 static void send_ip_details (vpe_api_main_t * am,
3967 unix_shared_memory_queue_t *q,
3971 vl_api_ip_details_t * mp;
3973 mp = vl_msg_api_alloc (sizeof (*mp));
3974 memset (mp, 0, sizeof (*mp));
3975 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
3977 mp->sw_if_index = ntohl(sw_if_index);
3978 mp->context = context;
3980 vl_msg_api_send_shmem (q, (u8 *)&mp);
3984 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
3985 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
3987 vpe_api_main_t * am = &vpe_api_main;
3988 l2t_main_t * lm = &l2t_main;
3989 unix_shared_memory_queue_t * q;
3990 l2t_session_t *session;
3992 q = vl_api_client_index_to_input_queue (mp->client_index);
3996 pool_foreach (session, lm->sessions,
3998 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4003 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4004 unix_shared_memory_queue_t *q,
4005 tapcli_interface_details_t *tap_if,
4008 vl_api_sw_interface_tap_details_t * mp;
4009 mp = vl_msg_api_alloc (sizeof (*mp));
4010 memset (mp, 0, sizeof (*mp));
4011 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4012 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4013 strncpy((char *)mp->dev_name,
4014 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4015 mp->context = context;
4017 vl_msg_api_send_shmem (q, (u8 *)&mp);
4021 vl_api_sw_interface_tap_dump_t_handler (
4022 vl_api_sw_interface_tap_dump_t *mp)
4025 vpe_api_main_t * am = &vpe_api_main;
4026 unix_shared_memory_queue_t * q;
4027 tapcli_interface_details_t *tapifs = NULL;
4028 tapcli_interface_details_t *tap_if = NULL;
4030 q = vl_api_client_index_to_input_queue (mp->client_index);
4034 rv = vnet_tap_dump_ifs(&tapifs);
4038 vec_foreach(tap_if, tapifs) {
4039 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4046 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4048 vpe_api_main_t * am = &vpe_api_main;
4049 vnet_main_t * vnm = vnet_get_main();
4050 vlib_main_t * vm = vlib_get_main();
4051 vnet_interface_main_t * im = &vnm->interface_main;
4052 unix_shared_memory_queue_t * q;
4053 vnet_sw_interface_t * si, * sorted_sis;
4054 u32 sw_if_index = ~0;
4056 q = vl_api_client_index_to_input_queue (mp->client_index);
4061 /* Gather interfaces. */
4062 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4063 _vec_len (sorted_sis) = 0;
4064 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4066 vec_foreach (si, sorted_sis) {
4067 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4068 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4071 sw_if_index = si->sw_if_index;
4072 send_ip_details(am, q, sw_if_index, mp->context);
4077 static void vl_api_l2_fib_table_entry_t_handler (
4078 vl_api_l2_fib_table_entry_t * mp)
4080 clib_warning ("BUG");
4083 static void send_l2fib_table_entry (vpe_api_main_t * am,
4084 unix_shared_memory_queue_t *q,
4085 l2fib_entry_key_t * l2fe_key,
4086 l2fib_entry_result_t * l2fe_res,
4089 vl_api_l2_fib_table_entry_t * mp;
4091 mp = vl_msg_api_alloc (sizeof (*mp));
4092 memset (mp, 0, sizeof (*mp));
4093 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4095 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4097 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4098 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4099 mp->static_mac = l2fe_res->fields.static_mac;
4100 mp->filter_mac = l2fe_res->fields.filter;
4101 mp->bvi_mac = l2fe_res->fields.bvi;
4102 mp->context = context;
4104 vl_msg_api_send_shmem (q, (u8 *)&mp);
4108 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4110 vpe_api_main_t * am = &vpe_api_main;
4111 bd_main_t * bdm = &bd_main;
4112 l2fib_entry_key_t *l2fe_key = NULL;
4113 l2fib_entry_result_t *l2fe_res = NULL;
4114 u32 ni, bd_id = ntohl (mp->bd_id);
4116 unix_shared_memory_queue_t * q;
4119 q = vl_api_client_index_to_input_queue (mp->client_index);
4123 /* see l2fib_table_dump: ~0 means "any" */
4127 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4134 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4136 vec_foreach_index (ni, l2fe_key) {
4137 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4138 vec_elt_at_index(l2fe_res, ni), mp->context);
4145 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4147 vl_api_show_version_reply_t *rmp;
4149 char * vpe_api_get_build_directory(void);
4150 char * vpe_api_get_version(void);
4151 char * vpe_api_get_build_date(void);
4153 unix_shared_memory_queue_t * q =
4154 vl_api_client_index_to_input_queue (mp->client_index);
4159 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4161 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4162 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4163 ARRAY_LEN(rmp->build_directory)-1);
4164 strncpy ((char *) rmp->version, vpe_api_get_version(),
4165 ARRAY_LEN(rmp->version)-1);
4166 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4167 ARRAY_LEN(rmp->build_date)-1);
4171 static void vl_api_get_node_index_t_handler
4172 (vl_api_get_node_index_t * mp)
4174 vlib_main_t * vm = vlib_get_main();
4175 vl_api_get_node_index_reply_t * rmp;
4178 u32 node_index = ~0;
4180 n = vlib_get_node_by_name (vm, mp->node_name);
4183 rv = VNET_API_ERROR_NO_SUCH_NODE;
4185 node_index = n->index;
4187 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4189 rmp->node_index = ntohl(node_index);
4193 static void vl_api_add_node_next_t_handler
4194 (vl_api_add_node_next_t * mp)
4196 vlib_main_t * vm = vlib_get_main();
4197 vl_api_add_node_next_reply_t * rmp;
4198 vlib_node_t * n, * next;
4200 u32 next_index = ~0;
4202 n = vlib_get_node_by_name (vm, mp->node_name);
4205 rv = VNET_API_ERROR_NO_SUCH_NODE;
4209 next = vlib_get_node_by_name (vm, mp->next_name);
4212 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4214 next_index = vlib_node_add_next (vm, n->index, next->index);
4217 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4219 rmp->next_index = ntohl(next_index);
4223 static void vl_api_l2tpv3_create_tunnel_t_handler
4224 (vl_api_l2tpv3_create_tunnel_t *mp)
4226 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4227 l2t_main_t *lm = &l2t_main;
4228 u32 sw_if_index = (u32)~0;
4231 if (mp->is_ipv6 != 1) {
4232 rv = VNET_API_ERROR_UNIMPLEMENTED;
4236 rv = create_l2tpv3_ipv6_tunnel (lm,
4237 (ip6_address_t *) mp->client_address,
4238 (ip6_address_t *) mp->our_address,
4239 ntohl(mp->local_session_id),
4240 ntohl(mp->remote_session_id),
4241 clib_net_to_host_u64(mp->local_cookie),
4242 clib_net_to_host_u64(mp->remote_cookie),
4243 mp->l2_sublayer_present,
4247 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4249 rmp->sw_if_index = ntohl (sw_if_index);
4253 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4254 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4256 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4257 l2t_main_t *lm = &l2t_main;
4260 VALIDATE_SW_IF_INDEX(mp);
4262 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4263 clib_net_to_host_u64(mp->new_local_cookie),
4264 clib_net_to_host_u64(mp->new_remote_cookie));
4266 BAD_SW_IF_INDEX_LABEL;
4268 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4271 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4272 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4275 vnet_main_t * vnm = vnet_get_main();
4276 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4278 VALIDATE_SW_IF_INDEX(mp);
4280 rv = l2tpv3_interface_enable_disable
4281 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4283 BAD_SW_IF_INDEX_LABEL;
4285 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4288 static void vl_api_l2tpv3_set_lookup_key_t_handler
4289 (vl_api_l2tpv3_set_lookup_key_t * mp)
4292 l2t_main_t *lm = &l2t_main;
4293 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4295 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4296 rv = VNET_API_ERROR_INVALID_VALUE;
4300 lm->lookup_type = mp->key;
4303 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4306 static void vl_api_vxlan_add_del_tunnel_t_handler
4307 (vl_api_vxlan_add_del_tunnel_t * mp)
4309 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4311 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4312 u32 encap_fib_index;
4314 ip4_main_t * im = &ip4_main;
4315 u32 sw_if_index = ~0;
4317 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4319 rv = VNET_API_ERROR_NO_SUCH_FIB;
4322 encap_fib_index = p[0];
4324 /* Check src & dst are different */
4325 if ((a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4326 (!a->is_ip6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4327 rv = VNET_API_ERROR_SAME_SRC_DST;
4330 memset (a, 0, sizeof (*a));
4332 a->is_add = mp->is_add;
4333 a->is_ip6 = mp->is_ipv6;
4335 /* ip addresses sent in network byte order */
4337 memcpy(&(a->src.ip6), mp->src_address, 16);
4338 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4340 memcpy(&(a->src.ip4), mp->src_address, 4);
4341 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4344 a->encap_fib_index = encap_fib_index;
4345 a->decap_next_index = ntohl(mp->decap_next_index);
4346 a->vni = ntohl(mp->vni);
4347 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4350 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4352 rmp->sw_if_index = ntohl (sw_if_index);
4356 static void send_vxlan_tunnel_details
4357 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4359 vl_api_vxlan_tunnel_details_t * rmp;
4360 ip4_main_t * im4 = &ip4_main;
4361 ip6_main_t * im6 = &ip6_main;
4362 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4364 rmp = vl_msg_api_alloc (sizeof (*rmp));
4365 memset (rmp, 0, sizeof (*rmp));
4366 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4368 memcpy(rmp->src_address, &(t->src.ip6), 16);
4369 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4370 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4372 memcpy(rmp->src_address, &(t->src.ip4), 4);
4373 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4374 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4376 rmp->vni = htonl(t->vni);
4377 rmp->decap_next_index = htonl(t->decap_next_index);
4378 rmp->sw_if_index = htonl(t->sw_if_index);
4379 rmp->is_ipv6 = is_ipv6;
4380 rmp->context = context;
4382 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4385 static void vl_api_vxlan_tunnel_dump_t_handler
4386 (vl_api_vxlan_tunnel_dump_t * mp)
4388 unix_shared_memory_queue_t * q;
4389 vxlan_main_t * vxm = &vxlan_main;
4393 q = vl_api_client_index_to_input_queue (mp->client_index);
4398 sw_if_index = ntohl(mp->sw_if_index);
4400 if (~0 == sw_if_index) {
4401 pool_foreach (t, vxm->tunnels,
4403 send_vxlan_tunnel_details(t, q, mp->context);
4406 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4407 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4410 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4411 send_vxlan_tunnel_details(t, q, mp->context);
4415 static void vl_api_gre_add_del_tunnel_t_handler
4416 (vl_api_gre_add_del_tunnel_t * mp)
4418 vl_api_gre_add_del_tunnel_reply_t * rmp;
4420 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4423 ip4_main_t * im = &ip4_main;
4424 u32 sw_if_index = ~0;
4426 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_table_id));
4428 rv = VNET_API_ERROR_NO_SUCH_FIB;
4431 outer_table_id = p[0];
4433 /* Check src & dst are different */
4434 if (memcmp(&mp->src_address, &mp->dst_address, 4) == 0) {
4435 rv = VNET_API_ERROR_SAME_SRC_DST;
4439 memset (a, 0, sizeof (*a));
4441 a->is_add = mp->is_add;
4443 /* ip addresses sent in network byte order */
4444 a->src.as_u32 = mp->src_address;
4445 a->dst.as_u32 = mp->dst_address;
4447 a->outer_table_id = outer_table_id;
4448 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4451 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4453 rmp->sw_if_index = ntohl (sw_if_index);
4457 static void send_gre_tunnel_details
4458 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4460 vl_api_gre_tunnel_details_t * rmp;
4461 ip4_main_t * im = &ip4_main;
4463 rmp = vl_msg_api_alloc (sizeof (*rmp));
4464 memset (rmp, 0, sizeof (*rmp));
4465 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4466 rmp->src_address = t->tunnel_src.data_u32;
4467 rmp->dst_address = t->tunnel_dst.data_u32;
4468 rmp->outer_table_id = htonl(im->fibs[t->outer_fib_index].table_id);
4469 rmp->sw_if_index = htonl(t->sw_if_index);
4470 rmp->context = context;
4472 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4475 static void vl_api_gre_tunnel_dump_t_handler
4476 (vl_api_gre_tunnel_dump_t * mp)
4478 unix_shared_memory_queue_t * q;
4479 gre_main_t * gm = &gre_main;
4483 q = vl_api_client_index_to_input_queue (mp->client_index);
4488 sw_if_index = ntohl(mp->sw_if_index);
4490 if (~0 == sw_if_index) {
4491 pool_foreach (t, gm->tunnels,
4493 send_gre_tunnel_details(t, q, mp->context);
4496 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4497 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4500 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4501 send_gre_tunnel_details(t, q, mp->context);
4506 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4508 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4510 vl_api_l2_patch_add_del_reply_t * rmp;
4511 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4515 VALIDATE_RX_SW_IF_INDEX(mp);
4516 VALIDATE_TX_SW_IF_INDEX(mp);
4518 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4519 ntohl(mp->tx_sw_if_index),
4520 (int)(mp->is_add != 0));
4522 BAD_RX_SW_IF_INDEX_LABEL;
4523 BAD_TX_SW_IF_INDEX_LABEL;
4525 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4529 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4530 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4532 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4534 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4535 u32 encap_fib_index, decap_fib_index;
4538 ip4_main_t * im = &ip4_main;
4539 u32 sw_if_index = ~0;
4542 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4544 rv = VNET_API_ERROR_NO_SUCH_FIB;
4547 encap_fib_index = p[0];
4549 protocol = ntohl(mp->protocol);
4551 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4552 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4553 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4555 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4558 decap_fib_index = p[0];
4560 decap_fib_index = ntohl(mp->decap_vrf_id);
4563 memset (a, 0, sizeof (*a));
4565 a->is_add = mp->is_add;
4566 /* ip addresses sent in network byte order */
4567 a->local.as_u32 = ntohl(mp->local);
4568 a->remote.as_u32 = ntohl(mp->remote);
4569 a->encap_fib_index = encap_fib_index;
4570 a->decap_fib_index = decap_fib_index;
4571 a->protocol = protocol;
4572 a->vni = ntohl(mp->vni);
4573 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4576 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4578 rmp->sw_if_index = ntohl (sw_if_index);
4583 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4585 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4587 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4589 u8 *locator_name = NULL;
4591 memset(a, 0, sizeof(a[0]));
4593 locator_name = format(0, "%s", mp->locator_set_name);
4595 a->name = locator_name;
4597 a->is_add = mp->is_add;
4600 rv = vnet_lisp_add_del_locator_set_name(a, &ls_index);
4602 vec_free(locator_name);
4604 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4608 vl_api_lisp_add_del_locator_t_handler(
4609 vl_api_lisp_add_del_locator_t *mp)
4611 vl_api_lisp_add_del_locator_reply_t *rmp;
4613 locator_t locator, *locators = NULL;
4614 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4616 u8 *locator_name = NULL;
4618 memset(&locator, 0, sizeof(locator));
4619 memset(a, 0, sizeof(a[0]));
4621 locator.sw_if_index = ntohl(mp->sw_if_index);
4622 locator.priority = mp->priority;
4623 locator.weight = mp->weight;
4625 vec_add1(locators, locator);
4627 locator_name = format(0, "%s", mp->locator_set_name);
4629 a->name = locator_name;
4630 a->locators = locators;
4631 a->is_add = mp->is_add;
4634 rv = vnet_lisp_add_del_locator(a, &ls_index);
4637 vec_free(locator_name);
4639 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4643 vl_api_lisp_add_del_local_eid_t_handler(
4644 vl_api_lisp_add_del_local_eid_t *mp)
4646 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4647 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4649 ip_prefix_t *prefp = NULL;
4650 ip_address_t *ip_eid = NULL;
4653 u32 locator_set_index = ~0, map_index = ~0;
4654 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4657 prefp = &gid_address_ippref(&eid);
4658 ip_eid = &ip_prefix_addr(prefp);
4659 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4662 clib_memcpy(&ip_addr_v6(ip_eid), mp->ip_address,
4663 sizeof(ip_addr_v6(ip_eid)));
4664 ip_addr_version(ip_eid) = IP6;
4666 clib_memcpy(&ip_addr_v4(ip_eid), mp->ip_address,
4667 sizeof(ip_addr_v4(ip_eid)));
4668 ip_addr_version(ip_eid) = IP4;
4670 ip_prefix_len(prefp) = mp->prefix_len;
4672 name = format(0, "%s", mp->locator_set_name);
4673 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4675 rv = VNET_API_ERROR_INVALID_VALUE;
4678 locator_set_index = p[0];
4680 /* XXX treat batch configuration */
4681 a->is_add = mp->is_add;
4683 a->locator_set_index = locator_set_index;
4686 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4691 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4695 lisp_gpe_add_del_fwd_entry_set_address(
4696 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4697 ip_address_t *slocator,
4698 ip_address_t *dlocator,
4701 ip_address_t *ip_eid = NULL;
4702 ip_prefix_t *prefp = NULL;
4704 prefp = &gid_address_ippref(eid);
4705 ip_eid = &ip_prefix_addr(prefp);
4707 if (mp->eid_is_ipv6) {
4708 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4709 sizeof(ip_addr_v6(ip_eid)));
4710 ip_addr_version(ip_eid) = IP6;
4712 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4713 sizeof(ip_addr_v4(ip_eid)));
4714 ip_addr_version(ip_eid) = IP4;
4716 ip_prefix_len(prefp) = mp->eid_prefix_len;
4718 if (mp->address_is_ipv6) {
4719 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4720 sizeof(ip_addr_v6(slocator)));
4721 ip_addr_version(slocator) = IP6;
4722 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4723 sizeof(ip_addr_v6(dlocator)));
4724 ip_addr_version(dlocator) = IP6;
4726 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4727 sizeof(ip_addr_v4(slocator)));
4728 ip_addr_version(slocator) = IP4;
4729 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4730 sizeof(ip_addr_v4(dlocator)));
4731 ip_addr_version(dlocator) = IP4;
4736 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4737 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4739 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4741 ip_address_t slocator, dlocator;
4743 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4745 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4747 memset (&a, 0, sizeof(a));
4749 a.is_add = mp->is_add;
4751 a.slocator = slocator;
4752 a.dlocator = dlocator;
4753 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
4755 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
4759 vl_api_lisp_add_del_map_resolver_t_handler(
4760 vl_api_lisp_add_del_map_resolver_t *mp)
4762 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
4764 ip_address_t *ip_addr = NULL;
4765 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
4767 a->is_add = mp->is_add;
4768 ip_addr = &a->address;
4771 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
4772 sizeof(ip_addr_v6(ip_addr)));
4773 ip_addr_version(ip_addr) = IP6;
4775 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
4776 sizeof(ip_addr_v4(ip_addr)));
4777 ip_addr_version(ip_addr) = IP4;
4780 rv = vnet_lisp_add_del_map_resolver (a);
4782 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
4786 vl_api_lisp_gpe_enable_disable_t_handler(
4787 vl_api_lisp_gpe_enable_disable_t *mp)
4789 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
4791 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
4793 a->is_en = mp->is_en;
4794 vnet_lisp_gpe_enable_disable (a);
4796 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
4800 vl_api_lisp_enable_disable_t_handler(
4801 vl_api_lisp_enable_disable_t *mp)
4803 vl_api_lisp_enable_disable_reply_t *rmp;
4806 vnet_lisp_enable_disable (mp->is_en);
4807 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
4811 vl_api_lisp_gpe_add_del_iface_t_handler(
4812 vl_api_lisp_gpe_add_del_iface_t *mp)
4814 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
4816 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
4818 a->is_add = mp->is_add;
4819 a->table_id = mp->table_id;
4821 vnet_lisp_gpe_add_del_iface (a, 0);
4823 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
4827 send_lisp_locator_set_details_set_address
4828 (vl_api_lisp_locator_set_details_t *rmp,
4829 gid_address_t *gid_address)
4831 ip_prefix_t *ip_addr;
4833 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
4837 ip_addr = &gid_address_ippref(gid_address);
4838 rmp->prefix_len = ip_prefix_len(ip_addr);
4839 rmp->is_ipv6 = ip_prefix_version(ip_addr);
4840 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
4844 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
4845 locator_set_t *lsit,
4846 unix_shared_memory_queue_t *q,
4850 vl_api_lisp_locator_set_details_t *rmp;
4851 locator_t *loc = NULL;
4855 vec_foreach (locit, lsit->locator_indices) {
4856 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
4857 rmp = vl_msg_api_alloc (sizeof (*rmp));
4858 memset (rmp, 0, sizeof (*rmp));
4859 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
4860 rmp->local = lsit->local;
4862 ASSERT(lsit->name != NULL);
4863 strncpy((char *) rmp->locator_set_name,
4864 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4865 rmp->sw_if_index = htonl(loc->sw_if_index);
4867 str = format(0, "remote-%d", index);
4868 strncpy((char *) rmp->locator_set_name, (char *) str,
4869 ARRAY_LEN(rmp->locator_set_name) - 1);
4870 send_lisp_locator_set_details_set_address(rmp, &loc->address);
4874 rmp->priority = loc->priority;
4875 rmp->weight = loc->weight;
4876 rmp->context = context;
4878 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4883 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
4885 unix_shared_memory_queue_t * q = NULL;
4886 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4887 locator_set_t * lsit = NULL;
4890 q = vl_api_client_index_to_input_queue (mp->client_index);
4896 pool_foreach (lsit, lcm->locator_set_pool,
4898 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
4903 send_lisp_local_eid_table_details (mapping_t *mapit,
4904 unix_shared_memory_queue_t *q,
4907 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
4908 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4909 locator_set_t *ls = NULL;
4910 gid_address_t *gid = NULL;
4911 ip_prefix_t *ip_prefix = NULL;
4915 ls = pool_elt_at_index (lcm->locator_set_pool,
4916 mapit->locator_set_index);
4919 type = gid_address_type(gid);
4921 if (type != GID_ADDR_IP_PREFIX) {
4925 ip_prefix = &gid_address_ippref(gid);
4927 rmp = vl_msg_api_alloc (sizeof (*rmp));
4928 memset (rmp, 0, sizeof (*rmp));
4929 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
4931 ASSERT(ls->name != NULL);
4932 strncpy((char *) rmp->locator_set_name,
4933 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
4935 str = format(0, "remote-%d", mapit->locator_set_index);
4936 strncpy((char *) rmp->locator_set_name, (char *) str,
4937 ARRAY_LEN(rmp->locator_set_name) - 1);
4941 switch (ip_prefix_version(ip_prefix)) {
4943 rmp->eid_is_ipv6 = 0;
4944 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v4(ip_prefix),
4945 sizeof(ip_prefix_v4(ip_prefix)));
4949 rmp->eid_is_ipv6 = 1;
4950 clib_memcpy(rmp->eid_ip_address, &ip_prefix_v6(ip_prefix),
4951 sizeof(ip_prefix_v6(ip_prefix)));
4957 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
4958 rmp->context = context;
4960 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4964 vl_api_lisp_local_eid_table_dump_t_handler (
4965 vl_api_lisp_local_eid_table_dump_t *mp)
4967 unix_shared_memory_queue_t * q = NULL;
4968 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4969 mapping_t * mapit = NULL;
4971 q = vl_api_client_index_to_input_queue (mp->client_index);
4976 pool_foreach (mapit, lcm->mapping_pool,
4978 send_lisp_local_eid_table_details(mapit, q, mp->context);
4983 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
4984 unix_shared_memory_queue_t *q,
4987 vl_api_lisp_gpe_tunnel_details_t *rmp;
4988 lisp_gpe_main_t * lgm = &lisp_gpe_main;
4990 rmp = vl_msg_api_alloc (sizeof (*rmp));
4991 memset (rmp, 0, sizeof (*rmp));
4992 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
4994 rmp->tunnels = tunnel - lgm->tunnels;
4996 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
4997 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
4998 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5000 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5001 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5002 rmp->dcap_next = htonl(tunnel->decap_next_index);
5003 rmp->lisp_ver = tunnel->ver_res;
5004 rmp->next_protocol = tunnel->next_protocol;
5005 rmp->flags = tunnel->flags;
5006 rmp->ver_res = tunnel->ver_res;
5007 rmp->res = tunnel->res;
5008 rmp->iid = htonl(tunnel->vni);
5009 rmp->context = context;
5011 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5015 vl_api_lisp_gpe_tunnel_dump_t_handler (
5016 vl_api_lisp_local_eid_table_dump_t *mp)
5018 unix_shared_memory_queue_t * q = NULL;
5019 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5020 lisp_gpe_tunnel_t * tunnel = NULL;
5022 if (pool_elts(lgm->tunnels) == 0) {
5026 q = vl_api_client_index_to_input_queue (mp->client_index);
5031 pool_foreach(tunnel, lgm->tunnels,
5033 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5038 send_lisp_map_resolver_details (ip_address_t *ip,
5039 unix_shared_memory_queue_t *q,
5042 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5044 rmp = vl_msg_api_alloc (sizeof (*rmp));
5045 memset (rmp, 0, sizeof (*rmp));
5046 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5048 switch (ip_addr_version(ip)) {
5051 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5056 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5062 rmp->context = context;
5064 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5068 vl_api_lisp_map_resolver_dump_t_handler (
5069 vl_api_lisp_local_eid_table_dump_t *mp)
5071 unix_shared_memory_queue_t * q = NULL;
5072 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5073 ip_address_t *ip = NULL;
5075 q = vl_api_client_index_to_input_queue (mp->client_index);
5080 vec_foreach(ip, lcm->map_resolvers) {
5081 send_lisp_map_resolver_details(ip, q, mp->context);
5087 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5090 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5092 rmp = vl_msg_api_alloc (sizeof (*rmp));
5093 memset (rmp, 0, sizeof (*rmp));
5094 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5096 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5097 rmp->feature_status = vnet_lisp_enable_disable_status ();
5098 rmp->context = context;
5100 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5104 vl_api_lisp_enable_disable_status_dump_t_handler
5105 (vl_api_lisp_enable_disable_status_dump_t *mp)
5107 unix_shared_memory_queue_t * q = NULL;
5109 q = vl_api_client_index_to_input_queue (mp->client_index);
5114 send_lisp_enable_disable_details(q, mp->context);
5118 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5120 vl_api_interface_name_renumber_reply_t * rmp;
5123 VALIDATE_SW_IF_INDEX(mp);
5125 rv = vnet_interface_name_renumber
5126 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5128 BAD_SW_IF_INDEX_LABEL;
5130 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5133 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5134 u32 sw_if_index, u32 address)
5136 vpe_api_main_t * am = &vpe_api_main;
5137 vlib_main_t * vm = am->vlib_main;
5138 vl_api_ip4_arp_event_t * event;
5139 static f64 arp_event_last_time;
5140 f64 now = vlib_time_now (vm);
5142 if (pool_is_free_index (am->arp_events, pool_index))
5145 event = pool_elt_at_index (am->arp_events, pool_index);
5146 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5147 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5148 } else { /* same mac */
5149 if ((sw_if_index == event->sw_if_index) &&
5151 /* for BD case, also check IP address with 10 sec timeout */
5152 ((address == event->address) &&
5153 ((now - arp_event_last_time) < 10.0))))
5157 arp_event_last_time = now;
5158 event->sw_if_index = sw_if_index;
5159 if (address) event->address = address;
5163 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5165 vpe_api_main_t * am = &vpe_api_main;
5167 if (pool_is_free_index (am->arp_events, pool_index))
5170 pool_put_index (am->arp_events, pool_index);
5175 vl_api_want_ip4_arp_events_t_handler
5176 (vl_api_want_ip4_arp_events_t * mp)
5178 vpe_api_main_t * am = &vpe_api_main;
5179 vnet_main_t * vnm = vnet_get_main();
5180 vl_api_want_ip4_arp_events_reply_t *rmp;
5181 vl_api_ip4_arp_event_t * event;
5184 if (mp->enable_disable) {
5185 pool_get (am->arp_events, event);
5186 memset (event, 0, sizeof (*event));
5188 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5189 event->client_index = mp->client_index;
5190 event->context = mp->context;
5191 event->address = mp->address;
5192 event->pid = mp->pid;
5194 rv = vnet_add_del_ip4_arp_change_event
5195 (vnm, arp_change_data_callback,
5197 &mp->address /* addr, in net byte order */,
5198 vpe_resolver_process_node.index,
5199 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5201 rv = vnet_add_del_ip4_arp_change_event
5202 (vnm, arp_change_delete_callback,
5204 &mp->address /* addr, in net byte order */,
5205 vpe_resolver_process_node.index,
5206 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5208 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5211 static void vl_api_input_acl_set_interface_t_handler
5212 (vl_api_input_acl_set_interface_t * mp)
5214 vlib_main_t *vm = vlib_get_main();
5215 vl_api_input_acl_set_interface_reply_t * rmp;
5217 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5219 ip4_table_index = ntohl(mp->ip4_table_index);
5220 ip6_table_index = ntohl(mp->ip6_table_index);
5221 l2_table_index = ntohl(mp->l2_table_index);
5222 sw_if_index = ntohl(mp->sw_if_index);
5224 VALIDATE_SW_IF_INDEX(mp);
5226 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5227 ip6_table_index, l2_table_index,
5230 BAD_SW_IF_INDEX_LABEL;
5232 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5235 static void vl_api_ipsec_spd_add_del_t_handler
5236 (vl_api_ipsec_spd_add_del_t * mp)
5239 clib_warning ("unimplemented");
5242 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5243 vl_api_ipsec_spd_add_del_reply_t * rmp;
5247 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5249 rv = VNET_API_ERROR_UNIMPLEMENTED;
5252 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5256 static void vl_api_ipsec_interface_add_del_spd_t_handler
5257 (vl_api_ipsec_interface_add_del_spd_t * mp)
5259 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5260 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5262 u32 sw_if_index __attribute__((unused));
5263 u32 spd_id __attribute__((unused));
5265 sw_if_index = ntohl(mp->sw_if_index);
5266 spd_id = ntohl(mp->spd_id);
5268 VALIDATE_SW_IF_INDEX(mp);
5271 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5273 rv = VNET_API_ERROR_UNIMPLEMENTED;
5276 BAD_SW_IF_INDEX_LABEL;
5278 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5281 static void vl_api_ipsec_spd_add_del_entry_t_handler
5282 (vl_api_ipsec_spd_add_del_entry_t * mp)
5284 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5285 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5291 memset(&p, 0, sizeof(p));
5293 p.id = ntohl(mp->spd_id);
5294 p.priority = ntohl(mp->priority);
5295 p.is_outbound = mp->is_outbound;
5296 p.is_ipv6 = mp->is_ipv6;
5298 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5299 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5300 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5301 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5303 p.protocol = mp->protocol;
5304 p.rport.start = ntohs(mp->remote_port_start);
5305 p.rport.stop = ntohs(mp->remote_port_stop);
5306 p.lport.start = ntohs(mp->local_port_start);
5307 p.lport.stop = ntohs(mp->local_port_stop);
5308 /* policy action resolve unsupported */
5309 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5310 clib_warning("unsupported action: 'resolve'");
5311 rv = VNET_API_ERROR_UNIMPLEMENTED;
5314 p.policy = mp->policy;
5315 p.sa_id = ntohl(mp->sa_id);
5317 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5321 if (mp->is_ip_any) {
5323 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5326 rv = VNET_API_ERROR_UNIMPLEMENTED;
5331 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5334 static void vl_api_ipsec_sad_add_del_entry_t_handler
5335 (vl_api_ipsec_sad_add_del_entry_t * mp)
5337 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5338 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5343 memset(&sa, 0, sizeof(sa));
5345 sa.id = ntohl(mp->sad_id);
5346 sa.spi = ntohl(mp->spi);
5347 /* security protocol AH unsupported */
5348 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5349 clib_warning("unsupported security protocol 'AH'");
5350 rv = VNET_API_ERROR_UNIMPLEMENTED;
5353 sa.protocol = mp->protocol;
5354 /* check for unsupported crypto-alg */
5355 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5356 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5357 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5358 mp->crypto_algorithm);
5359 rv = VNET_API_ERROR_UNIMPLEMENTED;
5362 sa.crypto_alg = mp->crypto_algorithm;
5363 sa.crypto_key_len = mp->crypto_key_length;
5364 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5365 /* check for unsupported integ-alg */
5366 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5367 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5368 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5369 mp->integrity_algorithm);
5370 rv = VNET_API_ERROR_UNIMPLEMENTED;
5373 sa.integ_alg = mp->integrity_algorithm;
5374 sa.integ_key_len = mp->integrity_key_length;
5375 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5376 sa.use_esn = mp->use_extended_sequence_number;
5377 sa.is_tunnel = mp->is_tunnel;
5378 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5379 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5380 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5382 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5384 rv = VNET_API_ERROR_UNIMPLEMENTED;
5389 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5393 vl_api_ikev2_profile_add_del_t_handler
5394 (vl_api_ikev2_profile_add_del_t * mp)
5396 vl_api_ikev2_profile_add_del_reply_t * rmp;
5400 vlib_main_t * vm = vlib_get_main();
5401 clib_error_t * error;
5402 u8 * tmp = format(0, "%s", mp->name);
5403 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5406 rv = VNET_API_ERROR_UNSPECIFIED;
5408 rv = VNET_API_ERROR_UNIMPLEMENTED;
5411 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5415 vl_api_ikev2_profile_set_auth_t_handler
5416 (vl_api_ikev2_profile_set_auth_t * mp)
5418 vl_api_ikev2_profile_set_auth_reply_t * rmp;
5422 vlib_main_t * vm = vlib_get_main();
5423 clib_error_t * error;
5424 u8 * tmp = format(0, "%s", mp->name);
5425 u8 * data = vec_new (u8, mp->data_len);
5426 clib_memcpy(data, mp->data, mp->data_len);
5427 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
5431 rv = VNET_API_ERROR_UNSPECIFIED;
5433 rv = VNET_API_ERROR_UNIMPLEMENTED;
5436 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
5440 vl_api_ikev2_profile_set_id_t_handler
5441 (vl_api_ikev2_profile_set_id_t * mp)
5443 vl_api_ikev2_profile_add_del_reply_t * rmp;
5447 vlib_main_t * vm = vlib_get_main();
5448 clib_error_t * error;
5449 u8 * tmp = format(0, "%s", mp->name);
5450 u8 * data = vec_new (u8, mp->data_len);
5451 clib_memcpy(data, mp->data, mp->data_len);
5452 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
5456 rv = VNET_API_ERROR_UNSPECIFIED;
5458 rv = VNET_API_ERROR_UNIMPLEMENTED;
5461 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
5465 vl_api_ikev2_profile_set_ts_t_handler
5466 (vl_api_ikev2_profile_set_ts_t * mp)
5468 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5472 vlib_main_t * vm = vlib_get_main();
5473 clib_error_t * error;
5474 u8 * tmp = format(0, "%s", mp->name);
5475 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
5476 mp->end_port, (ip4_address_t) mp->start_addr,
5477 (ip4_address_t) mp->end_addr, mp->is_local);
5480 rv = VNET_API_ERROR_UNSPECIFIED;
5482 rv = VNET_API_ERROR_UNIMPLEMENTED;
5485 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
5489 vl_api_ikev2_set_local_key_t_handler
5490 (vl_api_ikev2_set_local_key_t * mp)
5492 vl_api_ikev2_profile_set_ts_reply_t * rmp;
5496 vlib_main_t * vm = vlib_get_main();
5497 clib_error_t * error;
5499 error = ikev2_set_local_key(vm, mp->key_file);
5501 rv = VNET_API_ERROR_UNSPECIFIED;
5503 rv = VNET_API_ERROR_UNIMPLEMENTED;
5506 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
5510 vl_api_map_add_domain_t_handler
5511 (vl_api_map_add_domain_t * mp)
5513 vl_api_map_add_domain_reply_t * rmp;
5516 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
5517 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
5518 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
5519 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
5520 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
5522 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
5524 rmp->index = ntohl(index);
5529 vl_api_map_del_domain_t_handler
5530 (vl_api_map_del_domain_t * mp)
5532 vl_api_map_del_domain_reply_t * rmp;
5535 rv = map_delete_domain(ntohl(mp->index));
5537 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
5541 vl_api_map_add_del_rule_t_handler
5542 (vl_api_map_add_del_rule_t * mp)
5544 vl_api_map_del_domain_reply_t * rmp;
5547 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
5549 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
5553 vl_api_map_domain_dump_t_handler
5554 (vl_api_map_domain_dump_t * mp)
5556 vl_api_map_domain_details_t * rmp;
5557 map_main_t *mm = &map_main;
5559 unix_shared_memory_queue_t * q;
5561 if (pool_elts (mm->domains) == 0)
5564 q = vl_api_client_index_to_input_queue (mp->client_index);
5569 pool_foreach(d, mm->domains, ({
5570 /* Make sure every field is initiated (or don't skip the memset()) */
5571 rmp = vl_msg_api_alloc (sizeof (*rmp));
5572 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
5573 rmp->domain_index = htonl(d - mm->domains);
5574 rmp->ea_bits_len = d->ea_bits_len;
5575 rmp->psid_offset = d->psid_offset;
5576 rmp->psid_length = d->psid_length;
5577 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
5578 rmp->ip4_prefix_len = d->ip4_prefix_len;
5579 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
5580 rmp->ip6_prefix_len = d->ip6_prefix_len;
5581 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
5582 rmp->ip6_src_len = d->ip6_src_len;
5583 rmp->mtu = htons(d->mtu);
5584 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
5585 rmp->context = mp->context;
5587 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5592 vl_api_map_rule_dump_t_handler
5593 (vl_api_map_rule_dump_t * mp)
5595 unix_shared_memory_queue_t * q;
5598 vl_api_map_rule_details_t * rmp;
5599 map_main_t *mm = &map_main;
5600 u32 domain_index = ntohl(mp->domain_index);
5603 if (pool_elts (mm->domains) == 0)
5606 d = pool_elt_at_index(mm->domains, domain_index);
5607 if (!d || !d->rules) {
5611 q = vl_api_client_index_to_input_queue (mp->client_index);
5616 for (i = 0; i < (0x1 << d->psid_length); i++) {
5618 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
5621 rmp = vl_msg_api_alloc(sizeof(*rmp));
5622 memset(rmp, 0, sizeof(*rmp));
5623 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
5624 rmp->psid = htons(i);
5625 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
5626 rmp->context = mp->context;
5627 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5632 vl_api_map_summary_stats_t_handler (
5633 vl_api_map_summary_stats_t *mp)
5635 vl_api_map_summary_stats_reply_t *rmp;
5636 vlib_combined_counter_main_t *cm;
5639 u64 total_pkts[VLIB_N_RX_TX];
5640 u64 total_bytes[VLIB_N_RX_TX];
5641 map_main_t *mm = &map_main;
5642 unix_shared_memory_queue_t *q =
5643 vl_api_client_index_to_input_queue(mp->client_index);
5648 rmp = vl_msg_api_alloc (sizeof (*rmp));
5649 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
5650 rmp->context = mp->context;
5653 memset (total_pkts, 0, sizeof (total_pkts));
5654 memset (total_bytes, 0, sizeof (total_bytes));
5656 map_domain_counter_lock (mm);
5657 vec_foreach(cm, mm->domain_counters) {
5658 which = cm - mm->domain_counters;
5660 for (i = 0; i < vec_len(cm->maxi); i++) {
5661 vlib_get_combined_counter (cm, i, &v);
5662 total_pkts[which] += v.packets;
5663 total_bytes[which] += v.bytes;
5667 map_domain_counter_unlock (mm);
5669 /* Note: in network byte order! */
5670 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
5671 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
5672 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
5673 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
5674 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
5675 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
5676 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));
5677 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));
5679 vl_msg_api_send_shmem(q, (u8 *)&rmp);
5682 static void vl_api_ipsec_sa_set_key_t_handler
5683 (vl_api_ipsec_sa_set_key_t * mp)
5685 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5686 vl_api_ipsec_sa_set_key_reply_t *rmp;
5690 sa.id = ntohl(mp->sa_id);
5691 sa.crypto_key_len = mp->crypto_key_length;
5692 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5693 sa.integ_key_len = mp->integrity_key_length;
5694 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5696 rv = ipsec_set_sa_key(vm, &sa);
5698 rv = VNET_API_ERROR_UNIMPLEMENTED;
5701 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
5704 static void vl_api_cop_interface_enable_disable_t_handler
5705 (vl_api_cop_interface_enable_disable_t * mp)
5707 vl_api_cop_interface_enable_disable_reply_t * rmp;
5709 u32 sw_if_index = ntohl(mp->sw_if_index);
5712 VALIDATE_SW_IF_INDEX(mp);
5714 enable_disable = (int) mp->enable_disable;
5716 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
5718 BAD_SW_IF_INDEX_LABEL;
5720 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
5723 static void vl_api_cop_whitelist_enable_disable_t_handler
5724 (vl_api_cop_whitelist_enable_disable_t * mp)
5726 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
5727 cop_whitelist_enable_disable_args_t _a, *a=&_a;
5728 u32 sw_if_index = ntohl(mp->sw_if_index);
5731 VALIDATE_SW_IF_INDEX(mp);
5733 a->sw_if_index = sw_if_index;
5736 a->default_cop = mp->default_cop;
5737 a->fib_id = ntohl(mp->fib_id);
5739 rv = cop_whitelist_enable_disable (a);
5741 BAD_SW_IF_INDEX_LABEL;
5743 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
5746 static void vl_api_get_node_graph_t_handler
5747 (vl_api_get_node_graph_t * mp)
5751 api_main_t * am = &api_main;
5752 vlib_main_t * vm = vlib_get_main();
5754 vl_api_get_node_graph_reply_t * rmp;
5756 pthread_mutex_lock (&am->vlib_rp->mutex);
5757 oldheap = svm_push_data_heap (am->vlib_rp);
5760 * Keep the number of memcpy ops to a minimum (e.g. 1).
5761 * The current size of the serialized vector is
5762 * slightly under 4K.
5764 vec_validate (vector, 4095);
5765 vec_reset_length (vector);
5767 vector = vlib_node_serialize (&vm->node_main, vector);
5769 svm_pop_heap (oldheap);
5770 pthread_mutex_unlock (&am->vlib_rp->mutex);
5772 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
5773 rmp->reply_in_shmem = (uword) vector);
5776 static void vl_api_trace_profile_add_t_handler
5777 (vl_api_trace_profile_add_t *mp)
5780 vl_api_trace_profile_add_reply_t * rmp;
5781 clib_error_t *error;
5783 /* Ignoring the profile id as currently a single profile
5785 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
5786 ntohl(mp->node_id), ntohl(mp->trace_app_data),
5787 mp->pow_enable, mp->trace_tsp,
5790 clib_error_report(error);
5791 rv = clib_error_get_code(error);
5794 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
5797 static void vl_api_trace_profile_apply_t_handler
5798 (vl_api_trace_profile_apply_t *mp)
5801 vl_api_trace_profile_apply_reply_t * rmp;
5803 if (mp->enable != 0) {
5804 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
5805 ntohl(mp->prefix_length),
5807 mp->trace_op == IOAM_HBYH_ADD,
5808 mp->trace_op == IOAM_HBYH_POP,
5809 mp->trace_op == IOAM_HBYH_MOD);
5811 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
5813 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
5816 static void vl_api_trace_profile_del_t_handler
5817 (vl_api_trace_profile_del_t *mp)
5820 vl_api_trace_profile_del_reply_t * rmp;
5821 clib_error_t *error;
5823 error = clear_ioam_rewrite_fn();
5825 clib_error_report(error);
5826 rv = clib_error_get_code(error);
5829 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
5833 vl_api_af_packet_create_t_handler
5834 (vl_api_af_packet_create_t *mp)
5836 vlib_main_t *vm = vlib_get_main();
5837 vl_api_af_packet_create_reply_t *rmp;
5839 u8 *host_if_name = NULL;
5841 host_if_name = format(0, "%s", mp->host_if_name);
5842 vec_add1 (host_if_name, 0);
5844 rv = af_packet_create_if(vm, host_if_name,
5845 mp->use_random_hw_addr ? 0 : mp->hw_addr);
5847 vec_free(host_if_name);
5849 REPLY_MACRO(VL_API_AF_PACKET_CREATE_REPLY);
5853 vl_api_af_packet_delete_t_handler
5854 (vl_api_af_packet_delete_t *mp)
5856 vlib_main_t * vm = vlib_get_main();
5857 vl_api_af_packet_delete_reply_t *rmp;
5859 u8 *host_if_name = NULL;
5861 host_if_name = format(0, "%s", mp->host_if_name);
5862 vec_add1 (host_if_name, 0);
5864 rv = af_packet_delete_if(vm, host_if_name);
5866 vec_free(host_if_name);
5868 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
5871 #define BOUNCE_HANDLER(nn) \
5872 static void vl_api_##nn##_t_handler ( \
5873 vl_api_##nn##_t *mp) \
5875 vpe_client_registration_t *reg; \
5876 vpe_api_main_t * vam = &vpe_api_main; \
5877 unix_shared_memory_queue_t * q; \
5879 /* One registration only... */ \
5880 pool_foreach(reg, vam->nn##_registrations, \
5882 q = vl_api_client_index_to_input_queue (reg->client_index); \
5885 * If the queue is stuffed, turf the msg and complain \
5886 * It's unlikely that the intended recipient is \
5887 * alive; avoid deadlock at all costs. \
5889 if (q->cursize == q->maxsize) { \
5890 clib_warning ("ERROR: receiver queue full, drop msg"); \
5891 vl_msg_api_free (mp); \
5894 vl_msg_api_send_shmem (q, (u8 *)&mp); \
5898 vl_msg_api_free (mp); \
5903 * Add vpe's API message handlers to the table.
5904 * vlib has alread mapped shared memory and
5905 * added the client registration handlers.
5906 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
5909 static clib_error_t *
5910 vpe_api_hookup (vlib_main_t *vm)
5912 api_main_t * am = &api_main;
5915 vl_msg_api_set_handlers(VL_API_##N, #n, \
5916 vl_api_##n##_t_handler, \
5918 vl_api_##n##_t_endian, \
5919 vl_api_##n##_t_print, \
5920 sizeof(vl_api_##n##_t), 1);
5921 foreach_vpe_api_msg;
5925 * Manually register the sr tunnel add del msg, so we trace
5926 * enough bytes to capture a typical segment list
5928 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
5929 "sr_tunnel_add_del",
5930 vl_api_sr_tunnel_add_del_t_handler,
5932 vl_api_sr_tunnel_add_del_t_endian,
5933 vl_api_sr_tunnel_add_del_t_print,
5938 * Manually register the sr policy add del msg, so we trace
5939 * enough bytes to capture a typical tunnel name list
5941 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
5942 "sr_policy_add_del",
5943 vl_api_sr_policy_add_del_t_handler,
5945 vl_api_sr_policy_add_del_t_endian,
5946 vl_api_sr_policy_add_del_t_print,
5950 * Trace space for 8 MPLS encap labels, classifier mask+match
5952 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
5953 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
5954 += 5 * sizeof (u32x4);
5955 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
5956 += 5 * sizeof (u32x4);
5957 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
5958 += 16 * 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",