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>
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
48 #include <vnet/api_errno.h> // alagalah TODO : committers please pay note, is this ok?
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/l2tp/l2tp.h>
53 #include <vnet/ip/ip.h>
54 #include <vnet/unix/tuntap.h>
55 #include <vnet/unix/tapcli.h>
56 #include <vnet/mpls-gre/mpls.h>
57 #include <vnet/dhcp/proxy.h>
58 #include <vnet/dhcp/client.h>
60 #include <vnet/sr/sr.h>
62 #include <vnet/dhcpv6/proxy.h>
63 #include <vlib/vlib.h>
64 #include <vlib/unix/unix.h>
65 #include <vlibapi/api.h>
66 #include <vlibmemory/api.h>
67 #include <vnet/classify/vnet_classify.h>
68 #include <vnet/classify/input_acl.h>
69 #include <vnet/classify/policer_classify.h>
70 #include <vnet/l2/l2_classify.h>
71 #include <vnet/vxlan/vxlan.h>
72 #include <vnet/gre/gre.h>
73 #include <vnet/l2/l2_vtr.h>
74 #include <vnet/vxlan-gpe/vxlan_gpe.h>
75 #include <vnet/lisp-gpe/lisp_gpe.h>
76 #include <vnet/lisp-cp/control.h>
77 #include <vnet/map/map.h>
78 #include <vnet/cop/cop.h>
79 #include <vnet/ip/ip6_hop_by_hop.h>
80 #include <vnet/devices/af_packet/af_packet.h>
81 #include <vnet/policer/policer.h>
82 #include <vnet/devices/netmap/netmap.h>
83 #include <vnet/flow/flow_report.h>
86 #undef __included_bihash_template_h__
87 #include <vnet/l2/l2_fib.h>
90 #include <vnet/ipsec/ipsec.h>
91 #include <vnet/ipsec/ikev2.h>
94 #include <vnet/devices/virtio/vhost-user.h>
97 #include <stats/stats.h>
100 #include <vnet/ethernet/ethernet.h>
101 #include <vnet/ethernet/arp_packet.h>
102 #include <vnet/interface.h>
104 #include <vnet/l2/l2_fib.h>
105 #include <vnet/l2/l2_bd.h>
106 #include <vpp-api/vpe_msg_enum.h>
108 #define f64_endian(a)
109 #define f64_print(a,b)
111 #define vl_typedefs /* define message structures */
112 #include <vpp-api/vpe_all_api_h.h>
115 #define vl_endianfun /* define message structures */
116 #include <vpp-api/vpe_all_api_h.h>
119 /* instantiate all the print functions we know about */
120 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
122 #include <vpp-api/vpe_all_api_h.h>
125 #define REPLY_MACRO(t) \
127 unix_shared_memory_queue_t * q; \
128 rv = vl_msg_api_pd_handler (mp, rv); \
129 q = vl_api_client_index_to_input_queue (mp->client_index); \
133 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
134 rmp->_vl_msg_id = ntohs((t)); \
135 rmp->context = mp->context; \
136 rmp->retval = ntohl(rv); \
138 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
141 #define REPLY_MACRO2(t, body) \
143 unix_shared_memory_queue_t * q; \
144 rv = vl_msg_api_pd_handler (mp, rv); \
145 q = vl_api_client_index_to_input_queue (mp->client_index); \
149 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
150 rmp->_vl_msg_id = ntohs((t)); \
151 rmp->context = mp->context; \
152 rmp->retval = ntohl(rv); \
153 do {body;} while (0); \
154 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
157 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
159 #define VALIDATE_SW_IF_INDEX(mp) \
160 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
161 vnet_main_t *__vnm = vnet_get_main(); \
162 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
164 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
165 goto bad_sw_if_index; \
169 #define BAD_SW_IF_INDEX_LABEL \
175 #define VALIDATE_RX_SW_IF_INDEX(mp) \
176 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
177 vnet_main_t *__vnm = vnet_get_main(); \
178 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
179 __rx_sw_if_index)) { \
180 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
181 goto bad_rx_sw_if_index; \
185 #define BAD_RX_SW_IF_INDEX_LABEL \
187 bad_rx_sw_if_index: \
191 #define VALIDATE_TX_SW_IF_INDEX(mp) \
192 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
193 vnet_main_t *__vnm = vnet_get_main(); \
194 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
195 __tx_sw_if_index)) { \
196 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
197 goto bad_tx_sw_if_index; \
201 #define BAD_TX_SW_IF_INDEX_LABEL \
203 bad_tx_sw_if_index: \
209 #define VALIDATE_SW_IF_INDEX(mp)
210 #define BAD_SW_IF_INDEX_LABEL
211 #define VALIDATE_RX_SW_IF_INDEX(mp)
212 #define BAD_RX_SW_IF_INDEX_LABEL
213 #define VALIDATE_TX_SW_IF_INDEX(mp)
214 #define BAD_TX_SW_IF_INDEX_LABEL
216 #endif /* CLIB_DEBUG > 0 */
218 #define foreach_vpe_api_msg \
219 _(WANT_INTERFACE_EVENTS, want_interface_events) \
220 _(WANT_OAM_EVENTS, want_oam_events) \
221 _(OAM_ADD_DEL, oam_add_del) \
222 _(SW_INTERFACE_DUMP, sw_interface_dump) \
223 _(SW_INTERFACE_DETAILS, sw_interface_details) \
224 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
225 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
226 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
227 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
228 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
229 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
230 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
231 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
232 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
233 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
234 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
235 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
236 _(L2FIB_ADD_DEL, l2fib_add_del) \
237 _(L2_FLAGS, l2_flags) \
238 _(BRIDGE_FLAGS, bridge_flags) \
239 _(TAP_CONNECT, tap_connect) \
240 _(TAP_MODIFY, tap_modify) \
241 _(TAP_DELETE, tap_delete) \
242 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
243 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
244 _(CREATE_SUBIF, create_subif) \
245 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
246 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
247 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
248 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
249 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
250 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
251 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
252 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
253 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
254 _(RESET_FIB, reset_fib) \
255 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
256 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
257 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
258 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
259 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
260 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
261 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
262 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
263 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
264 sw_interface_ip6_set_link_local_address) \
265 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
266 _(CREATE_LOOPBACK, create_loopback) \
267 _(CONTROL_PING, control_ping) \
268 _(CLI_REQUEST, cli_request) \
269 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
270 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
271 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
272 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
273 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
274 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
275 _(GET_NODE_INDEX, get_node_index) \
276 _(ADD_NODE_NEXT, add_node_next) \
277 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
278 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
279 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
280 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
281 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
282 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
283 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
284 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
285 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
286 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
287 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
288 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
289 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
290 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
291 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
292 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
293 _(IP_ADDRESS_DUMP, ip_address_dump) \
294 _(IP_DUMP, ip_dump) \
295 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
296 _(SHOW_VERSION, show_version) \
297 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
298 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
299 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
300 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
301 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
302 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
303 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
304 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
305 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
306 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
307 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
308 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
309 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
310 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
311 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
312 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
313 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
314 _(DELETE_LOOPBACK, delete_loopback) \
315 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
316 _(MAP_ADD_DOMAIN, map_add_domain) \
317 _(MAP_DEL_DOMAIN, map_del_domain) \
318 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
319 _(MAP_DOMAIN_DUMP, map_domain_dump) \
320 _(MAP_RULE_DUMP, map_rule_dump) \
321 _(MAP_SUMMARY_STATS, map_summary_stats) \
322 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
323 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
324 _(GET_NODE_GRAPH, get_node_graph) \
325 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
326 _(TRACE_PROFILE_ADD, trace_profile_add) \
327 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
328 _(TRACE_PROFILE_DEL, trace_profile_del) \
329 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
330 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
331 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
332 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
333 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
334 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
335 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
336 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
337 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
338 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
339 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
340 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
341 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
342 _(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump) \
343 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
344 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
345 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
346 _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
347 lisp_enable_disable_status_dump) \
348 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
349 lisp_add_del_map_request_itr_rlocs) \
350 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
351 _(SHOW_LISP_PITR, show_lisp_pitr) \
352 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
353 _(AF_PACKET_CREATE, af_packet_create) \
354 _(AF_PACKET_DELETE, af_packet_delete) \
355 _(POLICER_ADD_DEL, policer_add_del) \
356 _(POLICER_DUMP, policer_dump) \
357 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
358 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
359 _(NETMAP_CREATE, netmap_create) \
360 _(NETMAP_DELETE, netmap_delete) \
361 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
362 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
363 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
364 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
365 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
366 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
367 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
368 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
369 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
370 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
371 _(CLASSIFY_TABLE_INFO,classify_table_info) \
372 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
373 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
374 _(IPFIX_ENABLE,ipfix_enable) \
375 _(IPFIX_DUMP,ipfix_dump) \
376 _(GET_NEXT_INDEX, get_next_index) \
377 _(PG_CREATE_INTERFACE, pg_create_interface) \
378 _(PG_CAPTURE, pg_capture) \
379 _(PG_ENABLE_DISABLE, pg_enable_disable)
382 #define QUOTE(x) QUOTE_(x)
384 #define foreach_registration_hash \
385 _(interface_events) \
386 _(to_netconf_server) \
387 _(from_netconf_server) \
388 _(to_netconf_client) \
389 _(from_netconf_client) \
393 RESOLVE_IP4_ADD_DEL_ROUTE=1,
394 RESOLVE_IP6_ADD_DEL_ROUTE,
395 RESOLVE_MPLS_ETHERNET_ADD_DEL,
401 vl_api_ip_add_del_route_t r;
402 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
408 #define _(a) uword *a##_registration_hash; \
409 vpe_client_registration_t * a##_registrations;
410 foreach_registration_hash
413 /* notifications happen really early in the game */
414 u8 link_state_process_up;
416 /* ip4 pending route adds */
417 pending_route_t * pending_routes;
419 /* ip4 arp event registration pool */
420 vl_api_ip4_arp_event_t * arp_events;
423 vlib_main_t * vlib_main;
424 vnet_main_t * vnet_main;
427 static vlib_node_registration_t vpe_resolver_process_node;
428 static vpe_api_main_t vpe_api_main;
430 static void send_sw_interface_flags (vpe_api_main_t * am,
431 unix_shared_memory_queue_t *q,
432 vnet_sw_interface_t * swif);
433 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
434 unix_shared_memory_queue_t *q,
437 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
440 /* Clean up all registrations belonging to the indicated client */
441 int vl_api_memclnt_delete_callback (u32 client_index)
443 vpe_api_main_t * vam = &vpe_api_main;
444 vpe_client_registration_t *rp;
446 int stats_memclnt_delete_callback (u32 client_index);
448 stats_memclnt_delete_callback (client_index);
451 p = hash_get (vam->a##_registration_hash, client_index); \
453 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
454 pool_put (vam->a##_registrations, rp); \
455 hash_unset (vam->a##_registration_hash, client_index); \
457 foreach_registration_hash;
462 #define API_LINK_STATE_EVENT 1
463 #define API_ADMIN_UP_DOWN_EVENT 2
466 event_data_cmp (void * a1, void * a2)
471 return (word) e1[0] - (word) e2[0];
475 link_state_process (vlib_main_t * vm,
476 vlib_node_runtime_t * rt,
479 vpe_api_main_t * vam = &vpe_api_main;
480 vnet_main_t * vnm = vam->vnet_main;
481 vnet_sw_interface_t * swif;
482 uword * event_data = 0;
483 vpe_client_registration_t *reg;
485 u32 prev_sw_if_index;
486 unix_shared_memory_queue_t * q;
488 vam->link_state_process_up = 1;
491 vlib_process_wait_for_event (vm);
493 /* Unified list of changed link or admin state sw_if_indices */
494 vlib_process_get_events_with_type
495 (vm, &event_data, API_LINK_STATE_EVENT);
496 vlib_process_get_events_with_type
497 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
499 /* Sort, so we can eliminate duplicates */
500 vec_sort_with_function (event_data, event_data_cmp);
502 prev_sw_if_index = ~0;
504 for (i = 0; i < vec_len(event_data); i++) {
505 /* Only one message per swif */
506 if (prev_sw_if_index == event_data[i])
508 prev_sw_if_index = event_data[i];
510 pool_foreach(reg, vam->interface_events_registrations,
512 q = vl_api_client_index_to_input_queue (reg->client_index);
514 // sw_interface may be deleted already
515 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
518 swif = vnet_get_sw_interface (vnm, event_data[i]);
519 send_sw_interface_flags (vam, q, swif);
524 vec_reset_length (event_data);
530 static clib_error_t *
531 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
532 static clib_error_t *
533 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
535 VLIB_REGISTER_NODE (link_state_process_node,static) = {
536 .function = link_state_process,
537 .type = VLIB_NODE_TYPE_PROCESS,
538 .name = "vpe-link-state-process",
541 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
542 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
544 static clib_error_t *
545 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
547 vpe_api_main_t * vam = &vpe_api_main;
548 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
550 if (vam->link_state_process_up)
551 vlib_process_signal_event (vam->vlib_main,
552 link_state_process_node.index,
553 API_LINK_STATE_EVENT,
558 static clib_error_t *
559 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
561 vpe_api_main_t * vam = &vpe_api_main;
564 * Note: it's perfectly fair to set a subif admin up / admin down.
565 * Note the subtle distinction between this routine and the previous
568 if (vam->link_state_process_up)
569 vlib_process_signal_event (vam->vlib_main,
570 link_state_process_node.index,
571 API_ADMIN_UP_DOWN_EVENT,
576 #define pub_sub_handler(lca,UCA) \
577 static void vl_api_want_##lca##_t_handler ( \
578 vl_api_want_##lca##_t *mp) \
580 vpe_api_main_t *vam = &vpe_api_main; \
581 vpe_client_registration_t *rp; \
582 vl_api_want_##lca##_reply_t *rmp; \
586 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
588 if (mp->enable_disable) { \
589 clib_warning ("pid %d: already enabled...", mp->pid); \
590 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
593 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
594 pool_put (vam->lca##_registrations, rp); \
595 hash_unset (vam->lca##_registration_hash, \
600 if (mp->enable_disable == 0) { \
601 clib_warning ("pid %d: already disabled...", mp->pid); \
602 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
605 pool_get (vam->lca##_registrations, rp); \
606 rp->client_index = mp->client_index; \
607 rp->client_pid = mp->pid; \
608 hash_set (vam->lca##_registration_hash, rp->client_index, \
609 rp - vam->lca##_registrations); \
612 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
615 pub_sub_handler (interface_events,INTERFACE_EVENTS)
616 pub_sub_handler (oam_events,OAM_EVENTS)
618 #define RESOLUTION_EVENT 1
619 #define RESOLUTION_PENDING_EVENT 2
620 #define IP4_ARP_EVENT 3
622 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
623 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
624 static int mpls_ethernet_add_del_tunnel_2_t_handler
625 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
627 void handle_ip4_arp_event (u32 pool_index)
629 vpe_api_main_t * vam = &vpe_api_main;
630 vnet_main_t * vnm = vam->vnet_main;
631 vlib_main_t * vm = vam->vlib_main;
632 vl_api_ip4_arp_event_t * event;
633 vl_api_ip4_arp_event_t * mp;
634 unix_shared_memory_queue_t * q;
636 /* Client can cancel, die, etc. */
637 if (pool_is_free_index (vam->arp_events, pool_index))
640 event = pool_elt_at_index (vam->arp_events, pool_index);
642 q = vl_api_client_index_to_input_queue (event->client_index);
644 (void) vnet_add_del_ip4_arp_change_event
645 (vnm, arp_change_delete_callback,
646 event->pid, &event->address,
647 vpe_resolver_process_node.index, IP4_ARP_EVENT,
648 ~0 /* pool index, notused */, 0 /* is_add */);
652 if (q->cursize < q->maxsize) {
653 mp = vl_msg_api_alloc (sizeof (*mp));
654 clib_memcpy (mp, event, sizeof (*mp));
655 vl_msg_api_send_shmem (q, (u8 *)&mp);
657 static f64 last_time;
659 * Throttle syslog msgs.
660 * It's pretty tempting to just revoke the registration...
662 if (vlib_time_now (vm) > last_time + 10.0) {
663 clib_warning ("arp event for %U to pid %d: queue stuffed!",
664 format_ip4_address, &event->address, event->pid);
665 last_time = vlib_time_now(vm);
671 resolver_process (vlib_main_t * vm,
672 vlib_node_runtime_t * rt,
676 uword *event_data = 0;
678 vpe_api_main_t * vam = &vpe_api_main;
679 pending_route_t * pr;
680 vl_api_ip_add_del_route_t * adr;
681 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
682 u32 * resolution_failures = 0;
687 vlib_process_wait_for_event_or_clock (vm, timeout);
689 event_type = vlib_process_get_events (vm, &event_data);
691 switch (event_type) {
692 case RESOLUTION_PENDING_EVENT:
696 case RESOLUTION_EVENT:
697 for (i = 0; i < vec_len(event_data); i++) {
699 * Resolution events can occur long after the
700 * original request has timed out. $$$ add a cancel
703 if (pool_is_free_index (vam->pending_routes, event_data[i]))
706 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
710 switch (pr->resolve_type) {
711 case RESOLVE_IP4_ADD_DEL_ROUTE:
712 rv = ip4_add_del_route_t_handler (adr);
713 clib_warning ("resolver: add %U/%d via %U %s",
715 (ip4_address_t *)&(adr->dst_address),
716 adr->dst_address_length,
718 (ip4_address_t *)&(adr->next_hop_address),
719 (rv >= 0) ? "succeeded" : "failed");
722 case RESOLVE_IP6_ADD_DEL_ROUTE:
723 rv = ip6_add_del_route_t_handler (adr);
724 clib_warning ("resolver: add %U/%d via %U %s",
726 (ip6_address_t *)&(adr->dst_address),
727 adr->dst_address_length,
729 (ip6_address_t *)&(adr->next_hop_address),
730 (rv >= 0) ? "succeeded" : "failed");
733 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
734 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
735 clib_warning ("resolver: add mpls-o-e via %U %s",
737 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
738 (rv >= 0) ? "succeeded" : "failed");
742 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
744 pool_put (vam->pending_routes, pr);
749 for (i = 0; i < vec_len(event_data); i++)
750 handle_ip4_arp_event (event_data[i]);
753 case ~0: /* timeout, retry pending resolutions */
754 pool_foreach (pr, vam->pending_routes,
760 /* May fail, e.g. due to interface down */
761 switch (pr->resolve_type) {
762 case RESOLVE_IP4_ADD_DEL_ROUTE:
763 e = ip4_probe_neighbor
764 (vm, (ip4_address_t *)&(adr->next_hop_address),
765 ntohl(adr->next_hop_sw_if_index));
768 case RESOLVE_IP6_ADD_DEL_ROUTE:
769 e = ip6_probe_neighbor
770 (vm, (ip6_address_t *)&(adr->next_hop_address),
771 ntohl(adr->next_hop_sw_if_index));
774 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
776 e = ip4_probe_neighbor
778 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
779 pme->resolve_opaque);
783 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
787 clib_error_report (e);
789 adr->resolve_attempts = 1;
791 pme->resolve_attempts = 1;
795 adr->resolve_attempts -= 1;
796 if (adr->resolve_attempts == 0)
797 vec_add1 (resolution_failures,
798 pr - vam->pending_routes);
800 pme->resolve_attempts -= 1;
801 if (pme->resolve_attempts == 0)
802 vec_add1 (resolution_failures,
803 pr - vam->pending_routes);
807 for (i = 0; i < vec_len (resolution_failures); i++) {
808 pr = pool_elt_at_index (vam->pending_routes,
809 resolution_failures[i]);
813 switch (pr->resolve_type) {
814 case RESOLVE_IP4_ADD_DEL_ROUTE:
815 clib_warning ("resolver: add %U/%d via %U retry failure",
817 (ip4_address_t *)&(adr->dst_address),
818 adr->dst_address_length,
820 (ip4_address_t *)&(adr->next_hop_address));
823 case RESOLVE_IP6_ADD_DEL_ROUTE:
824 clib_warning ("resolver: add %U/%d via %U retry failure",
826 (ip6_address_t *)&(adr->dst_address),
827 adr->dst_address_length,
829 (ip6_address_t *)&(adr->next_hop_address));
832 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
833 clib_warning ("resolver: add mpls-o-e via %U retry failure",
835 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
839 clib_warning ("BUG");
841 pool_put(vam->pending_routes, pr);
843 vec_reset_length (resolution_failures);
846 if (pool_elts (vam->pending_routes) == 0)
848 vec_reset_length (event_data);
850 return 0; /* or not */
853 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
854 .function = resolver_process,
855 .type = VLIB_NODE_TYPE_PROCESS,
856 .name = "vpe-route-resolver-process",
859 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
861 ip4_main_t * im = &ip4_main;
862 ip_lookup_main_t * lm = &im->lookup_main;
863 vnet_classify_main_t * cm = &vnet_classify_main;
864 stats_main_t * sm = &stats_main;
865 ip4_add_del_route_args_t a;
866 ip4_address_t next_hop_address;
868 vpe_api_main_t * vam = &vpe_api_main;
869 vnet_main_t * vnm = vam->vnet_main;
870 vlib_main_t * vm = vlib_get_main();
871 pending_route_t * pr;
872 vl_api_ip_add_del_route_t * adr;
878 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
880 if (mp->create_vrf_if_needed) {
882 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
884 fib_index = f->index;
886 /* No such VRF, and we weren't asked to create one */
887 return VNET_API_ERROR_NO_SUCH_FIB;
893 if (~0 != mp->next_hop_sw_if_index &&
894 pool_is_free_index (vnm->interface_main.sw_interfaces,
895 ntohl(mp->next_hop_sw_if_index)))
896 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
898 clib_memcpy (next_hop_address.data, mp->next_hop_address,
899 sizeof (next_hop_address.data));
901 /* Arp for the next_hop if necessary */
902 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
904 ip_adjacency_t * adj;
906 lookup_result = ip4_fib_lookup_with_table
907 (im, fib_index, &next_hop_address, 1 /* disable default route */);
909 adj = ip_get_adjacency (lm, lookup_result);
911 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
912 pool_get (vam->pending_routes, pr);
913 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
915 clib_memcpy (adr, mp, sizeof (*adr));
916 /* recursion block, "just in case" */
917 adr->resolve_if_needed = 0;
918 adr->resolve_attempts = ntohl(mp->resolve_attempts);
919 vnet_register_ip4_arp_resolution_event
920 (vnm, &next_hop_address, vpe_resolver_process_node.index,
921 RESOLUTION_EVENT, pr - vam->pending_routes);
923 vlib_process_signal_event
924 (vm, vpe_resolver_process_node.index,
925 RESOLUTION_PENDING_EVENT, 0 /* data */);
927 /* The interface may be down, etc. */
928 e = ip4_probe_neighbor
929 (vm, (ip4_address_t *)&(mp->next_hop_address),
930 ntohl(mp->next_hop_sw_if_index));
933 clib_error_report(e);
935 return VNET_API_ERROR_IN_PROGRESS;
939 if (mp->is_multipath) {
942 dslock (sm, 1 /* release hint */, 10 /* tag */);
945 flags = IP4_ROUTE_FLAG_ADD;
947 flags = IP4_ROUTE_FLAG_DEL;
950 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
952 ip4_add_del_route_next_hop (im, flags,
953 (ip4_address_t *) mp->dst_address,
954 (u32) mp->dst_address_length,
955 (ip4_address_t *) mp->next_hop_address,
956 ntohl(mp->next_hop_sw_if_index),
957 (u32) mp->next_hop_weight,
964 memset (&a, 0, sizeof (a));
965 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
967 a.dst_address_length = mp->dst_address_length;
969 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
970 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
971 a.table_index_or_table_id = fib_index;
976 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
978 dslock (sm, 1 /* release hint */, 2 /* tag */);
982 ai = lm->drop_adj_index;
983 else if (mp->is_local)
984 ai = lm->local_adj_index;
985 else if (mp->is_classify) {
986 if (pool_is_free_index (cm->tables, ntohl(mp->classify_table_index))) {
988 return VNET_API_ERROR_NO_SUCH_TABLE;
990 adj = ip_add_adjacency (lm,
995 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
996 adj->classify.table_index = ntohl(mp->classify_table_index);
998 else if (mp->lookup_in_vrf) {
999 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1001 adj = ip_add_adjacency (lm,
1005 adj->explicit_fib_index = p[0];
1009 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1013 ai = ip4_route_get_next_hop_adj (im,
1016 ntohl(mp->next_hop_sw_if_index),
1019 if (ai == lm->miss_adj_index) {
1021 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1024 ip_adjacency_t * adj;
1025 int disable_default_route = 1;
1027 /* Trying to delete the default route? */
1028 if (a.dst_address.as_u32 == 0 &&
1029 a.dst_address_length == 0)
1030 disable_default_route = 0;
1032 ai = ip4_fib_lookup_with_table
1033 (im, fib_index, &a.dst_address, disable_default_route);
1034 if (ai == lm->miss_adj_index) {
1036 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1039 adj = ip_get_adjacency (lm, ai);
1040 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1042 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1047 ip4_add_del_route (im, &a);
1053 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1055 ip6_main_t * im = &ip6_main;
1056 ip_lookup_main_t * lm = &im->lookup_main;
1057 vnet_main_t * vnm = vnet_get_main();
1058 vlib_main_t * vm = vlib_get_main();
1059 vpe_api_main_t * vam = &vpe_api_main;
1060 stats_main_t * sm = &stats_main;
1061 ip6_add_del_route_args_t a;
1062 ip6_address_t next_hop_address;
1063 pending_route_t * pr;
1064 vl_api_ip_add_del_route_t * adr;
1069 ip_adjacency_t *adj = 0;
1072 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1075 if (mp->create_vrf_if_needed) {
1077 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1079 fib_index = f->index;
1081 /* No such VRF, and we weren't asked to create one */
1082 return VNET_API_ERROR_NO_SUCH_FIB;
1088 if (~0 != mp->next_hop_sw_if_index &&
1089 pool_is_free_index (vnm->interface_main.sw_interfaces,
1090 ntohl(mp->next_hop_sw_if_index)))
1091 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1093 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1094 sizeof (next_hop_address.as_u8));
1096 /* Arp for the next_hop if necessary */
1097 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
1099 ip_adjacency_t * adj;
1101 lookup_result = ip6_fib_lookup_with_table
1102 (im, fib_index, &next_hop_address);
1104 adj = ip_get_adjacency (lm, lookup_result);
1106 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1107 pool_get (vam->pending_routes, pr);
1109 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1110 clib_memcpy (adr, mp, sizeof (*adr));
1111 /* recursion block, "just in case" */
1112 adr->resolve_if_needed = 0;
1113 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1114 vnet_register_ip6_neighbor_resolution_event
1115 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1116 RESOLUTION_EVENT, pr - vam->pending_routes);
1118 vlib_process_signal_event
1119 (vm, vpe_resolver_process_node.index,
1120 RESOLUTION_PENDING_EVENT, 0 /* data */);
1122 /* The interface may be down, etc. */
1123 e = ip6_probe_neighbor
1124 (vm, (ip6_address_t *)&(mp->next_hop_address),
1125 ntohl(mp->next_hop_sw_if_index));
1128 clib_error_report(e);
1130 return VNET_API_ERROR_IN_PROGRESS;
1134 if (mp->is_multipath) {
1137 dslock (sm, 1 /* release hint */, 11 /* tag */);
1140 flags = IP6_ROUTE_FLAG_ADD;
1142 flags = IP6_ROUTE_FLAG_DEL;
1145 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1147 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1148 (u32) mp->dst_address_length,
1149 (ip6_address_t *)mp->next_hop_address,
1150 ntohl(mp->next_hop_sw_if_index),
1151 (u32) mp->next_hop_weight,
1158 memset (&a, 0, sizeof (a));
1159 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1161 a.dst_address_length = mp->dst_address_length;
1163 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1164 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1165 a.table_index_or_table_id = fib_index;
1170 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1172 dslock (sm, 1 /* release hint */, 3 /* tag */);
1176 ai = lm->drop_adj_index;
1177 else if (mp->is_local)
1178 ai = lm->local_adj_index;
1179 else if (mp->lookup_in_vrf) {
1180 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1182 adj = ip_add_adjacency (lm,
1186 adj->explicit_fib_index = p[0];
1190 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1194 ai = ip6_route_get_next_hop_adj (im,
1197 ntohl(mp->next_hop_sw_if_index),
1199 if (ai == lm->miss_adj_index) {
1201 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1204 ip_adjacency_t * adj;
1206 ai = ip6_fib_lookup_with_table
1207 (im, fib_index, &a.dst_address);
1208 if (ai == lm->miss_adj_index) {
1210 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1212 adj = ip_get_adjacency (lm, ai);
1213 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1215 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1220 ip6_add_del_route (im, &a);
1226 void vl_api_ip_add_del_route_t_handler (
1227 vl_api_ip_add_del_route_t *mp)
1229 vl_api_ip_add_del_route_reply_t * rmp;
1231 vnet_main_t * vnm = vnet_get_main();
1236 rv = ip6_add_del_route_t_handler (mp);
1238 rv = ip4_add_del_route_t_handler (mp);
1240 rv = (rv == 0) ? vnm->api_errno : rv;
1242 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1245 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1246 u32 sw_if_index, u8 *next_hop_addr)
1248 vl_api_ip_add_del_route_t mp;
1251 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1254 * Configure default IP route:
1255 * - ip route add 0.0.0.0/1 via <GW IP>
1256 * - ip route add 128.0.0.0/1 via <GW IP>
1258 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1260 mp.resolve_attempts = ~0;
1261 mp.resolve_if_needed = 1;
1263 mp.is_ipv6 = is_ipv6;
1264 mp.next_hop_weight = 1;
1266 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1269 rv = ip6_add_del_route_t_handler (&mp);
1272 mp.dst_address_length = 1;
1274 mp.dst_address[0] = 0;
1275 rv = ip4_add_del_route_t_handler (&mp);
1277 mp.dst_address[0] = 128;
1278 rv |= ip4_add_del_route_t_handler (&mp);
1282 clib_error_return (0, "failed to config default IP route");
1287 vl_api_sw_interface_add_del_address_t_handler
1288 (vl_api_sw_interface_add_del_address_t *mp)
1290 vlib_main_t *vm = vlib_get_main();
1291 vl_api_sw_interface_add_del_address_reply_t * rmp;
1295 VALIDATE_SW_IF_INDEX(mp);
1297 is_del = mp->is_add == 0;
1300 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1301 else if (mp->is_ipv6)
1302 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1303 (void *)mp->address,
1304 mp->address_length, is_del);
1306 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1307 (void *) mp->address,
1308 mp->address_length, is_del);
1310 BAD_SW_IF_INDEX_LABEL;
1312 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1316 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1319 u32 table_id = ntohl(mp->vrf_id);
1320 u32 sw_if_index = ntohl(mp->sw_if_index);
1321 vl_api_sw_interface_set_table_reply_t * rmp;
1322 stats_main_t * sm = &stats_main;
1324 VALIDATE_SW_IF_INDEX(mp);
1326 dslock (sm, 1 /* release hint */, 4 /* tag */);
1329 ip6_main_t * im = &ip6_main;
1331 find_ip6_fib_by_table_index_or_id (im, table_id,
1332 IP6_ROUTE_FLAG_TABLE_ID);
1334 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1335 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1337 rv = VNET_API_ERROR_NO_SUCH_FIB;
1340 ip4_main_t * im = &ip4_main;
1341 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1342 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1344 /* Truthfully this can't fail */
1346 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1347 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1349 rv = VNET_API_ERROR_NO_SUCH_FIB;
1354 BAD_SW_IF_INDEX_LABEL;
1356 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1360 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1362 vlib_main_t *vm = vlib_get_main();
1363 ip4_main_t * im4 = &ip4_main;
1364 ip6_main_t * im6 = &ip6_main;
1365 vl_api_sw_interface_set_vpath_reply_t * rmp;
1368 u32 sw_if_index = ntohl(mp->sw_if_index);
1369 ip4_main_t *ip4m = &ip4_main;
1370 ip6_main_t *ip6m = &ip6_main;
1371 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1372 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1373 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1374 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1375 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1376 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1378 VALIDATE_SW_IF_INDEX(mp);
1380 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1382 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1383 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1385 im4->ip4_unicast_rx_feature_vpath,
1387 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1388 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1389 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1391 im4->ip4_multicast_rx_feature_vpath,
1393 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1394 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1395 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1397 im6->ip6_unicast_rx_feature_vpath,
1399 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1400 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1401 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1403 im6->ip6_multicast_rx_feature_vpath,
1405 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1407 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1408 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1410 im4->ip4_unicast_rx_feature_vpath,
1412 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1413 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1414 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1416 im4->ip4_multicast_rx_feature_vpath,
1418 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1419 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1420 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1422 im6->ip6_unicast_rx_feature_vpath,
1424 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1425 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1426 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1428 im6->ip6_multicast_rx_feature_vpath,
1430 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1433 BAD_SW_IF_INDEX_LABEL;
1435 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1439 vl_api_sw_interface_set_l2_xconnect_t_handler (
1440 vl_api_sw_interface_set_l2_xconnect_t *mp)
1442 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1444 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1445 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1446 vlib_main_t *vm = vlib_get_main();
1447 vnet_main_t *vnm = vnet_get_main();
1449 VALIDATE_RX_SW_IF_INDEX(mp);
1452 VALIDATE_TX_SW_IF_INDEX(mp);
1453 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1454 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1456 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1459 BAD_RX_SW_IF_INDEX_LABEL;
1460 BAD_TX_SW_IF_INDEX_LABEL;
1462 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1466 vl_api_sw_interface_set_l2_bridge_t_handler (
1467 vl_api_sw_interface_set_l2_bridge_t *mp)
1469 bd_main_t * bdm = &bd_main;
1470 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1472 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1473 u32 bd_id = ntohl(mp->bd_id);
1477 vlib_main_t *vm = vlib_get_main();
1478 vnet_main_t *vnm = vnet_get_main();
1480 VALIDATE_RX_SW_IF_INDEX(mp);
1482 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1485 //VALIDATE_TX_SW_IF_INDEX(mp);
1486 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1487 rx_sw_if_index, bd_index, bvi, shg, 0);
1489 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1492 BAD_RX_SW_IF_INDEX_LABEL;
1494 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1498 vl_api_bridge_domain_add_del_t_handler (
1499 vl_api_bridge_domain_add_del_t *mp)
1501 vlib_main_t * vm = vlib_get_main ();
1502 bd_main_t * bdm = &bd_main;
1503 vl_api_bridge_domain_add_del_reply_t * rmp;
1505 u32 enable_flags = 0, disable_flags = 0;
1506 u32 bd_id = ntohl(mp->bd_id);
1510 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1513 enable_flags |= L2_FLOOD;
1515 disable_flags |= L2_FLOOD;
1518 enable_flags |= L2_UU_FLOOD;
1520 disable_flags |= L2_UU_FLOOD;
1523 enable_flags |= L2_FWD;
1525 disable_flags |= L2_FWD;
1528 enable_flags |= L2_ARP_TERM;
1530 disable_flags |= L2_ARP_TERM;
1533 enable_flags |= L2_LEARN;
1535 disable_flags |= L2_LEARN;
1538 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1541 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1544 rv = bd_delete_bd_index(bdm, bd_id);
1546 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1549 static void vl_api_bridge_domain_details_t_handler (
1550 vl_api_bridge_domain_details_t * mp)
1552 clib_warning ("BUG");
1555 static void vl_api_bridge_domain_sw_if_details_t_handler (
1556 vl_api_bridge_domain_sw_if_details_t * mp)
1558 clib_warning ("BUG");
1561 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1562 l2_bridge_domain_t * bd_config,
1566 vl_api_bridge_domain_details_t * mp;
1568 mp = vl_msg_api_alloc (sizeof (*mp));
1569 memset (mp, 0, sizeof (*mp));
1570 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1571 mp->bd_id = ntohl (bd_config->bd_id);
1572 mp->flood = bd_feature_flood (bd_config);
1573 mp->uu_flood = bd_feature_uu_flood (bd_config);
1574 mp->forward = bd_feature_forward (bd_config);
1575 mp->learn = bd_feature_learn (bd_config);
1576 mp->arp_term = bd_feature_arp_term (bd_config);
1577 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1578 mp->n_sw_ifs = ntohl (n_sw_ifs);
1579 mp->context = context;
1581 vl_msg_api_send_shmem (q, (u8 *)&mp);
1584 static void send_bd_sw_if_details (l2input_main_t * l2im,
1585 unix_shared_memory_queue_t *q,
1586 l2_flood_member_t * member, u32 bd_id,
1589 vl_api_bridge_domain_sw_if_details_t * mp;
1590 l2_input_config_t * input_cfg;
1592 mp = vl_msg_api_alloc (sizeof (*mp));
1593 memset (mp, 0, sizeof (*mp));
1594 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1595 mp->bd_id = ntohl (bd_id);
1596 mp->sw_if_index = ntohl (member->sw_if_index);
1597 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1598 mp->shg = input_cfg->shg;
1599 mp->context = context;
1601 vl_msg_api_send_shmem (q, (u8 *)&mp);
1604 static void vl_api_bridge_domain_dump_t_handler (
1605 vl_api_bridge_domain_dump_t *mp)
1607 bd_main_t * bdm = &bd_main;
1608 l2input_main_t * l2im = &l2input_main;
1609 unix_shared_memory_queue_t * q;
1610 l2_bridge_domain_t * bd_config;
1611 u32 bd_id, bd_index;
1614 q = vl_api_client_index_to_input_queue (mp->client_index);
1619 bd_id = ntohl(mp->bd_id);
1621 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1622 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1623 for (; bd_index < end; bd_index++) {
1624 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1625 /* skip dummy bd_id 0 */
1626 if (bd_config && (bd_config->bd_id > 0)) {
1628 l2_flood_member_t * m;
1630 n_sw_ifs = vec_len (bd_config->members);
1631 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1633 vec_foreach (m, bd_config->members) {
1634 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1641 vl_api_l2fib_add_del_t_handler (
1642 vl_api_l2fib_add_del_t *mp)
1644 bd_main_t * bdm = &bd_main;
1645 l2input_main_t * l2im = &l2input_main;
1646 vl_api_l2fib_add_del_reply_t * rmp;
1649 u32 sw_if_index = ntohl(mp->sw_if_index);
1650 u32 bd_id = ntohl(mp->bd_id);
1659 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1661 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1662 goto bad_sw_if_index;
1667 VALIDATE_SW_IF_INDEX(mp);
1668 if (vec_len(l2im->configs) <= sw_if_index) {
1669 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1670 goto bad_sw_if_index;
1672 l2_input_config_t * config;
1673 config = vec_elt_at_index(l2im->configs, sw_if_index);
1674 if (config->bridge == 0) {
1675 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1676 goto bad_sw_if_index;
1679 static_mac = mp->static_mac ? 1 : 0;
1680 filter_mac = mp->filter_mac ? 1 : 0;
1681 bvi_mac = mp->bvi_mac ? 1 : 0;
1682 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1685 l2fib_del_entry(mac, bd_index);
1688 BAD_SW_IF_INDEX_LABEL;
1690 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1694 vl_api_l2_flags_t_handler (
1695 vl_api_l2_flags_t *mp)
1697 vl_api_l2_flags_reply_t * rmp;
1699 u32 sw_if_index = ntohl(mp->sw_if_index);
1700 u32 flags = ntohl(mp->feature_bitmap);
1703 VALIDATE_SW_IF_INDEX(mp);
1706 if (flags & L2INPUT_FEAT_ ## a) \
1707 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1708 foreach_l2input_feat;
1711 BAD_SW_IF_INDEX_LABEL;
1713 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1717 vl_api_bridge_flags_t_handler (
1718 vl_api_bridge_flags_t *mp)
1720 vlib_main_t *vm = vlib_get_main();
1721 bd_main_t * bdm = &bd_main;
1722 vl_api_bridge_flags_reply_t * rmp;
1724 u32 bd_id = ntohl(mp->bd_id);
1726 u32 flags = ntohl(mp->feature_bitmap);
1729 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1731 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1737 bd_set_flags(vm, bd_index, flags, mp->is_set);
1740 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1741 rmp->resulting_feature_bitmap = ntohl(flags));
1745 vl_api_bd_ip_mac_add_del_t_handler (
1746 vl_api_bd_ip_mac_add_del_t *mp)
1748 bd_main_t * bdm = &bd_main;
1749 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1751 u32 bd_id = ntohl(mp->bd_id);
1755 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1757 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1762 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1763 mp->mac_address, mp->is_ipv6, mp->is_add))
1764 rv = VNET_API_ERROR_UNSPECIFIED;
1767 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1771 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1774 vl_api_tap_connect_reply_t * rmp;
1775 unix_shared_memory_queue_t * q;
1776 u32 sw_if_index = (u32)~0;
1778 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1779 mp->use_random_mac ? 0 : mp->mac_address,
1780 &sw_if_index, mp->renumber,
1781 ntohl(mp->custom_dev_instance));
1783 q = vl_api_client_index_to_input_queue (mp->client_index);
1787 rmp = vl_msg_api_alloc (sizeof (*rmp));
1788 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1789 rmp->context = mp->context;
1790 rmp->retval = ntohl(rv);
1791 rmp->sw_if_index = ntohl(sw_if_index);
1793 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1797 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1800 vl_api_tap_modify_reply_t * rmp;
1801 unix_shared_memory_queue_t * q;
1802 u32 sw_if_index = (u32)~0;
1804 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1805 mp->use_random_mac ? 0 : mp->mac_address,
1806 &sw_if_index, mp->renumber,
1807 ntohl(mp->custom_dev_instance));
1809 q = vl_api_client_index_to_input_queue (mp->client_index);
1813 rmp = vl_msg_api_alloc (sizeof (*rmp));
1814 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1815 rmp->context = mp->context;
1816 rmp->retval = ntohl(rv);
1817 rmp->sw_if_index = ntohl(sw_if_index);
1819 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1823 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1826 vpe_api_main_t * vam = &vpe_api_main;
1827 vl_api_tap_delete_reply_t * rmp;
1828 unix_shared_memory_queue_t * q;
1829 u32 sw_if_index = ntohl(mp->sw_if_index);
1831 rv = vnet_tap_delete (vm, sw_if_index);
1833 q = vl_api_client_index_to_input_queue (mp->client_index);
1837 rmp = vl_msg_api_alloc (sizeof (*rmp));
1838 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1839 rmp->context = mp->context;
1840 rmp->retval = ntohl(rv);
1842 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1845 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1849 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1851 vl_api_create_vlan_subif_reply_t * rmp;
1852 vnet_main_t * vnm = vnet_get_main();
1853 u32 hw_if_index, sw_if_index = (u32)~0;
1854 vnet_hw_interface_t * hi;
1857 vnet_sw_interface_t template;
1859 vnet_interface_main_t * im = &vnm->interface_main;
1860 u64 sup_and_sub_key;
1862 unix_shared_memory_queue_t * q;
1863 clib_error_t * error;
1865 VALIDATE_SW_IF_INDEX(mp);
1867 hw_if_index = ntohl(mp->sw_if_index);
1868 hi = vnet_get_hw_interface (vnm, hw_if_index);
1870 id = ntohl(mp->vlan_id);
1871 if (id == 0 || id > 4095) {
1872 rv = VNET_API_ERROR_INVALID_VLAN;
1876 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1878 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1880 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1884 kp = clib_mem_alloc (sizeof (*kp));
1885 *kp = sup_and_sub_key;
1887 memset (&template, 0, sizeof (template));
1888 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1889 template.sup_sw_if_index = hi->sw_if_index;
1890 template.sub.id = id;
1891 template.sub.eth.raw_flags = 0;
1892 template.sub.eth.flags.one_tag = 1;
1893 template.sub.eth.outer_vlan_id = id;
1894 template.sub.eth.flags.exact_match = 1;
1896 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1898 clib_error_report(error);
1899 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1902 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1903 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1905 BAD_SW_IF_INDEX_LABEL;
1908 q = vl_api_client_index_to_input_queue (mp->client_index);
1912 rmp = vl_msg_api_alloc (sizeof (*rmp));
1913 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1914 rmp->context = mp->context;
1915 rmp->retval = ntohl(rv);
1916 rmp->sw_if_index = ntohl(sw_if_index);
1917 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1921 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1923 vl_api_create_subif_reply_t * rmp;
1924 vnet_main_t * vnm = vnet_get_main();
1925 u32 sw_if_index = ~0;
1928 vnet_sw_interface_t *si;
1929 vnet_hw_interface_t *hi;
1930 vnet_sw_interface_t template;
1932 vnet_interface_main_t * im = &vnm->interface_main;
1933 u64 sup_and_sub_key;
1935 clib_error_t * error;
1937 VALIDATE_SW_IF_INDEX(mp);
1939 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1940 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1942 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1943 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1947 sw_if_index = si->sw_if_index;
1948 sub_id = ntohl(mp->sub_id);
1950 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1952 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1955 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1956 sw_if_index, sub_id);
1957 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1961 kp = clib_mem_alloc (sizeof (*kp));
1962 *kp = sup_and_sub_key;
1964 memset (&template, 0, sizeof (template));
1965 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1966 template.sup_sw_if_index = sw_if_index;
1967 template.sub.id = sub_id;
1968 template.sub.eth.flags.no_tags = mp->no_tags;
1969 template.sub.eth.flags.one_tag = mp->one_tag;
1970 template.sub.eth.flags.two_tags = mp->two_tags;
1971 template.sub.eth.flags.dot1ad = mp->dot1ad;
1972 template.sub.eth.flags.exact_match = mp->exact_match;
1973 template.sub.eth.flags.default_sub = mp->default_sub;
1974 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1975 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1976 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1977 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1979 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1981 clib_error_report (error);
1982 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1986 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1987 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1989 BAD_SW_IF_INDEX_LABEL;
1993 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1995 rmp->sw_if_index = ntohl(sw_if_index);
2000 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
2002 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
2004 stats_main_t * sm = &stats_main;
2005 u32 tunnel_sw_if_index = ~0;
2007 dslock (sm, 1 /* release hint */, 5 /* tag */);
2009 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
2010 (ip4_address_t *)(mp->dst_address),
2011 (ip4_address_t *)(mp->intfc_address),
2012 (u32)(mp->intfc_address_length),
2013 ntohl(mp->inner_vrf_id),
2014 ntohl(mp->outer_vrf_id),
2015 &tunnel_sw_if_index,
2020 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2022 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2027 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2028 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
2030 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2032 stats_main_t * sm = &stats_main;
2033 u32 tunnel_sw_if_index;
2035 dslock (sm, 1 /* release hint */, 5 /* tag */);
2037 rv = vnet_mpls_ethernet_add_del_tunnel
2038 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
2039 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
2040 ntohl(mp->tx_sw_if_index),
2041 &tunnel_sw_if_index,
2047 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2049 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2054 * This piece of misery brought to you because the control-plane
2055 * can't figure out the tx interface + dst-mac address all by itself
2057 static int mpls_ethernet_add_del_tunnel_2_t_handler
2058 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2060 pending_route_t * pr;
2061 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2062 vnet_main_t * vnm = vnet_get_main();
2063 vlib_main_t * vm = vlib_get_main();
2064 stats_main_t * sm = &stats_main;
2065 vpe_api_main_t * vam = &vpe_api_main;
2066 u32 inner_fib_index, outer_fib_index;
2067 ip4_main_t * im = &ip4_main;
2068 ip_lookup_main_t * lm = &im->lookup_main;
2069 ip_adjacency_t * adj = 0;
2072 u8 * dst_mac_address;
2076 u32 tunnel_sw_if_index;
2078 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2080 return VNET_API_ERROR_NO_SUCH_FIB;
2082 outer_fib_index = p[0];
2085 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2087 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2089 inner_fib_index = p[0];
2091 if (inner_fib_index == outer_fib_index)
2092 return VNET_API_ERROR_INVALID_VALUE;
2094 lookup_result = ip4_fib_lookup_with_table
2095 (im, outer_fib_index,
2096 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2097 1 /* disable default route */);
2099 adj = ip_get_adjacency (lm, lookup_result);
2100 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2102 if (mp->is_add && mp->resolve_if_needed) {
2103 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2104 pool_get (vam->pending_routes, pr);
2105 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2107 clib_memcpy (pme, mp, sizeof (*pme));
2108 /* recursion block, "just in case" */
2109 pme->resolve_if_needed = 0;
2110 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2111 pme->resolve_opaque = tx_sw_if_index;
2112 vnet_register_ip4_arp_resolution_event
2114 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2115 vpe_resolver_process_node.index,
2116 RESOLUTION_EVENT, pr - vam->pending_routes);
2118 vlib_process_signal_event
2119 (vm, vpe_resolver_process_node.index,
2120 RESOLUTION_PENDING_EVENT, 0 /* data */);
2122 /* The interface may be down, etc. */
2123 e = ip4_probe_neighbor
2124 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2128 clib_error_report(e);
2130 return VNET_API_ERROR_IN_PROGRESS;
2134 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2135 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2138 vnet_rewrite_get_data_internal
2139 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2141 dslock (sm, 1 /* release hint */, 10 /* tag */);
2143 rv = vnet_mpls_ethernet_add_del_tunnel
2144 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2145 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2146 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2154 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2155 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2157 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2160 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2162 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2167 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2169 vl_api_mpls_add_del_encap_reply_t * rmp;
2171 static u32 * labels;
2174 vec_reset_length (labels);
2176 for (i = 0; i < mp->nlabels; i++)
2177 vec_add1 (labels, ntohl(mp->labels[i]));
2180 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2181 ntohl(mp->vrf_id), labels,
2182 ~0 /* policy_tunnel_index */,
2183 0 /* no_dst_hash */,
2187 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2191 vl_api_mpls_add_del_decap_t_handler
2192 (vl_api_mpls_add_del_decap_t *mp)
2194 vl_api_mpls_add_del_decap_reply_t * rmp;
2197 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2198 ntohl(mp->label), ntohl(mp->next_index),
2199 mp->s_bit, mp->is_add);
2201 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2205 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2207 vl_api_proxy_arp_add_del_reply_t * rmp;
2210 ip4_main_t * im = &ip4_main;
2211 stats_main_t * sm = &stats_main;
2212 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2213 ip4_address_t *hi_addr,
2214 u32 fib_index, int is_del);
2217 dslock (sm, 1 /* release hint */, 6 /* tag */);
2219 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2222 rv = VNET_API_ERROR_NO_SUCH_FIB;
2228 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2229 (ip4_address_t *)mp->hi_address,
2230 fib_index, mp->is_add == 0);
2234 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2238 vl_api_proxy_arp_intfc_enable_disable_t_handler
2239 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2242 vnet_main_t * vnm = vnet_get_main();
2243 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2244 vnet_sw_interface_t * si;
2247 VALIDATE_SW_IF_INDEX(mp);
2249 sw_if_index = ntohl(mp->sw_if_index);
2251 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2253 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2257 si = vnet_get_sw_interface (vnm, sw_if_index);
2261 if (mp->enable_disable)
2262 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2264 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2266 BAD_SW_IF_INDEX_LABEL;
2269 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2273 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2275 vl_api_ip_neighbor_add_del_reply_t * rmp;
2276 vnet_main_t * vnm = vnet_get_main();
2279 stats_main_t * sm = &stats_main;
2281 VALIDATE_SW_IF_INDEX(mp);
2283 dslock (sm, 1 /* release hint */, 7 /* tag */);
2287 rv = vnet_set_ip6_ethernet_neighbor
2288 (vm, ntohl(mp->sw_if_index),
2289 (ip6_address_t *)(mp->dst_address),
2290 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2292 rv = vnet_unset_ip6_ethernet_neighbor
2293 (vm, ntohl(mp->sw_if_index),
2294 (ip6_address_t *)(mp->dst_address),
2295 mp->mac_address, sizeof(mp->mac_address));
2297 ip4_main_t * im = &ip4_main;
2298 ip_lookup_main_t * lm = &im->lookup_main;
2299 ethernet_arp_ip4_over_ethernet_address_t a;
2301 ip_adjacency_t *nh_adj;
2303 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2305 rv = VNET_API_ERROR_NO_SUCH_FIB;
2311 * Unfortunately, folks have a penchant for
2312 * adding interface addresses to the ARP cache, and
2313 * wondering why the forwarder eventually ASSERTs...
2315 ai = ip4_fib_lookup_with_table
2316 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2317 1 /* disable default route */);
2320 nh_adj = ip_get_adjacency (lm, ai);
2321 /* Never allow manipulation of a local adj! */
2322 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2323 clib_warning("%U matches local adj",
2325 (ip4_address_t *)(mp->dst_address));
2326 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2331 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2332 clib_memcpy (&a.ip4, mp->dst_address, 4);
2335 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2336 fib_index, &a, mp->is_static);
2338 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2342 BAD_SW_IF_INDEX_LABEL;
2345 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2349 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2352 vpe_main_t *rm = &vpe_main;
2353 ip4_main_t *im4 = &ip4_main;
2354 ip6_main_t *im6 = &ip6_main;
2355 ip_lookup_main_t * lm;
2360 u32 adj_index, sw_if_index;
2361 vl_api_is_address_reachable_t *rmp;
2362 ip_adjacency_t * adj;
2363 unix_shared_memory_queue_t *q;
2365 q = vl_api_client_index_to_input_queue (mp->client_index);
2367 increment_missing_api_client_counter (rm->vlib_main);
2371 rmp = vl_msg_api_alloc (sizeof (*rmp));
2372 clib_memcpy (rmp, mp, sizeof (*rmp));
2374 sw_if_index = mp->next_hop_sw_if_index;
2375 clib_memcpy (&addr, mp->address, sizeof (addr));
2377 lm = &im6->lookup_main;
2379 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2381 lm = &im4->lookup_main;
2383 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2385 if (adj_index == ~0) {
2389 adj = ip_get_adjacency (lm, adj_index);
2391 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2392 && adj->rewrite_header.sw_if_index == sw_if_index) {
2395 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2396 && adj->rewrite_header.sw_if_index == sw_if_index) {
2398 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2400 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2401 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2409 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2413 static void vl_api_sw_interface_details_t_handler (
2414 vl_api_sw_interface_details_t * mp)
2416 clib_warning ("BUG");
2419 static void vl_api_sw_interface_set_flags_t_handler (
2420 vl_api_sw_interface_set_flags_t * mp)
2422 vl_api_sw_interface_set_flags_reply_t *rmp;
2423 vnet_main_t * vnm = vnet_get_main();
2425 clib_error_t * error;
2428 VALIDATE_SW_IF_INDEX(mp);
2430 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2432 error = vnet_sw_interface_set_flags (vnm,
2433 ntohl(mp->sw_if_index),
2437 clib_error_report (error);
2440 BAD_SW_IF_INDEX_LABEL;
2441 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2444 static void vl_api_sw_interface_clear_stats_t_handler (
2445 vl_api_sw_interface_clear_stats_t * mp)
2447 vl_api_sw_interface_clear_stats_reply_t *rmp;
2449 vnet_main_t * vnm = vnet_get_main();
2450 vnet_interface_main_t * im = &vnm->interface_main;
2451 vlib_simple_counter_main_t * sm;
2452 vlib_combined_counter_main_t * cm;
2453 static vnet_main_t ** my_vnet_mains;
2454 int i, j, n_counters;
2458 vec_reset_length (my_vnet_mains);
2460 for (i = 0; i < vec_len (vnet_mains); i++)
2463 vec_add1 (my_vnet_mains, vnet_mains[i]);
2466 if (vec_len (vnet_mains) == 0)
2467 vec_add1 (my_vnet_mains, vnm);
2469 n_counters = vec_len (im->combined_sw_if_counters);
2471 for (j = 0; j < n_counters; j++)
2473 for (i = 0; i < vec_len(my_vnet_mains); i++)
2475 im = &my_vnet_mains[i]->interface_main;
2476 cm = im->combined_sw_if_counters + j;
2477 if (mp->sw_if_index == (u32)~0)
2478 vlib_clear_combined_counters (cm);
2480 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2484 n_counters = vec_len (im->sw_if_counters);
2486 for (j = 0; j < n_counters; j++)
2488 for (i = 0; i < vec_len(my_vnet_mains); i++)
2490 im = &my_vnet_mains[i]->interface_main;
2491 sm = im->sw_if_counters + j;
2492 if (mp->sw_if_index == (u32)~0)
2493 vlib_clear_simple_counters (sm);
2495 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2499 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2502 static void send_sw_interface_details (vpe_api_main_t * am,
2503 unix_shared_memory_queue_t *q,
2504 vnet_sw_interface_t * swif,
2505 u8 * interface_name,
2508 vl_api_sw_interface_details_t * mp;
2509 vnet_hw_interface_t * hi;
2511 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2513 mp = vl_msg_api_alloc (sizeof (*mp));
2514 memset (mp, 0, sizeof (*mp));
2515 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2516 mp->sw_if_index = ntohl(swif->sw_if_index);
2517 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2518 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2520 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2522 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2523 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2524 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2525 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2526 mp->link_mtu = ntohs(hi->max_packet_bytes);
2527 mp->context = context;
2529 strncpy ((char *) mp->interface_name,
2530 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2532 /* Send the L2 address for ethernet physical intfcs */
2533 if (swif->sup_sw_if_index == swif->sw_if_index
2534 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2535 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2536 ethernet_interface_t *ei;
2538 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2539 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2540 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2541 mp->l2_address_length = ntohl(sizeof (ei->address));
2542 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2543 vnet_sub_interface_t *sub = &swif->sub;
2544 mp->sub_id = ntohl(sub->id);
2545 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2546 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2547 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2548 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2549 mp->sub_exact_match = sub->eth.flags.exact_match;
2550 mp->sub_default = sub->eth.flags.default_sub;
2551 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2552 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2554 /* vlan tag rewrite data */
2555 u32 vtr_op = L2_VTR_DISABLED;
2556 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2558 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2559 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2560 // error - default to disabled
2561 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2562 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2565 mp->vtr_op = ntohl(vtr_op);
2566 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2567 mp->vtr_tag1 = ntohl(vtr_tag1);
2568 mp->vtr_tag2 = ntohl(vtr_tag2);
2572 vl_msg_api_send_shmem (q, (u8 *)&mp);
2575 static void send_sw_interface_flags (vpe_api_main_t * am,
2576 unix_shared_memory_queue_t *q,
2577 vnet_sw_interface_t * swif)
2579 vl_api_sw_interface_set_flags_t *mp;
2580 vnet_main_t * vnm = am->vnet_main;
2582 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2584 mp = vl_msg_api_alloc (sizeof (*mp));
2585 memset (mp, 0, sizeof (*mp));
2586 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2587 mp->sw_if_index = ntohl(swif->sw_if_index);
2589 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2591 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2593 vl_msg_api_send_shmem (q, (u8 *)&mp);
2596 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2597 unix_shared_memory_queue_t *q,
2599 __attribute__((unused));
2601 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2602 unix_shared_memory_queue_t *q,
2605 vl_api_sw_interface_set_flags_t *mp;
2607 mp = vl_msg_api_alloc (sizeof (*mp));
2608 memset (mp, 0, sizeof (*mp));
2609 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2610 mp->sw_if_index = ntohl(sw_if_index);
2612 mp->admin_up_down = 0;
2613 mp->link_up_down = 0;
2615 vl_msg_api_send_shmem (q, (u8 *)&mp);
2618 static void vl_api_sw_interface_dump_t_handler (
2619 vl_api_sw_interface_dump_t *mp)
2621 vpe_api_main_t * am = &vpe_api_main;
2622 vnet_sw_interface_t * swif;
2623 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2624 u8 * filter_string = 0, * name_string = 0;
2625 unix_shared_memory_queue_t * q;
2626 char * strcasestr (char *, char *); /* lnx hdr file botch */
2628 q = vl_api_client_index_to_input_queue (mp->client_index);
2633 if (mp->name_filter_valid) {
2634 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2635 filter_string = format (0, "%s%c", mp->name_filter, 0);
2638 pool_foreach (swif, im->sw_interfaces,
2640 name_string = format (name_string, "%U%c",
2641 format_vnet_sw_interface_name,
2642 am->vnet_main, swif, 0);
2644 if (mp->name_filter_valid == 0 ||
2645 strcasestr((char *) name_string, (char *) filter_string)) {
2647 send_sw_interface_details (am, q, swif, name_string, mp->context);
2649 _vec_len (name_string) = 0;
2652 vec_free (name_string);
2653 vec_free (filter_string);
2656 void send_oam_event (oam_target_t * t)
2658 vpe_api_main_t * vam = &vpe_api_main;
2659 unix_shared_memory_queue_t * q;
2660 vpe_client_registration_t *reg;
2661 vl_api_oam_event_t * mp;
2663 pool_foreach(reg, vam->oam_events_registrations,
2665 q = vl_api_client_index_to_input_queue (reg->client_index);
2667 mp = vl_msg_api_alloc (sizeof (*mp));
2668 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2669 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2670 mp->state = t->state;
2671 vl_msg_api_send_shmem (q, (u8 *)&mp);
2677 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2679 vl_api_oam_add_del_reply_t * rmp;
2682 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2683 (ip4_address_t *)mp->dst_address,
2687 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2691 vl_api_vnet_get_summary_stats_t_handler (
2692 vl_api_vnet_get_summary_stats_t *mp)
2694 stats_main_t * sm = &stats_main;
2695 vnet_interface_main_t * im = sm->interface_main;
2696 vl_api_vnet_summary_stats_reply_t *rmp;
2697 vlib_combined_counter_main_t * cm;
2700 u64 total_pkts[VLIB_N_RX_TX];
2701 u64 total_bytes[VLIB_N_RX_TX];
2703 unix_shared_memory_queue_t * q =
2704 vl_api_client_index_to_input_queue (mp->client_index);
2709 rmp = vl_msg_api_alloc (sizeof (*rmp));
2710 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2711 rmp->context = mp->context;
2714 memset (total_pkts, 0, sizeof (total_pkts));
2715 memset (total_bytes, 0, sizeof (total_bytes));
2717 vnet_interface_counter_lock (im);
2719 vec_foreach (cm, im->combined_sw_if_counters) {
2720 which = cm - im->combined_sw_if_counters;
2722 for (i = 0; i < vec_len (cm->maxi); i++) {
2723 vlib_get_combined_counter (cm, i, &v);
2724 total_pkts[which] += v.packets;
2725 total_bytes[which] += v.bytes;
2728 vnet_interface_counter_unlock (im);
2730 /* Note: in HOST byte order! */
2731 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2732 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2733 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2734 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2735 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2737 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2740 typedef CLIB_PACKED (struct {
2741 ip4_address_t address;
2743 u32 address_length : 6;
2748 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2750 vnet_main_t * vnm = vnet_get_main();
2751 vnet_interface_main_t * im = &vnm->interface_main;
2752 ip4_main_t * im4 = &ip4_main;
2753 static ip4_route_t * routes;
2754 static u32 * sw_if_indices_to_shut;
2755 stats_main_t * sm = &stats_main;
2760 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2761 u32 target_fib_id = ntohl(mp->vrf_id);
2763 dslock (sm, 1 /* release hint */, 8 /* tag */);
2765 vec_foreach (fib, im4->fibs) {
2766 vnet_sw_interface_t * si;
2768 if (fib->table_id != target_fib_id)
2771 /* remove any mpls/gre tunnels in this fib */
2772 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2774 /* remove any mpls encap/decap labels */
2775 mpls_fib_reset_labels (fib->table_id);
2777 /* remove any proxy arps in this fib */
2778 vnet_proxy_arp_fib_reset (fib->table_id);
2780 /* Set the flow hash for this fib to the default */
2781 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2783 vec_reset_length (sw_if_indices_to_shut);
2785 /* Shut down interfaces in this FIB / clean out intfc routes */
2786 pool_foreach (si, im->sw_interfaces,
2788 u32 sw_if_index = si->sw_if_index;
2790 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2791 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2793 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2796 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2797 sw_if_index = sw_if_indices_to_shut[i];
2798 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2800 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2801 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2802 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2805 vec_reset_length (routes);
2807 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2808 uword * hash = fib->adj_index_by_dst_address[i];
2812 x.address_length = i;
2814 hash_foreach_pair (p, hash,
2816 x.address.data_u32 = p->key;
2817 vec_add1 (routes, x);
2821 vec_foreach (r, routes) {
2822 ip4_add_del_route_args_t a;
2824 memset (&a, 0, sizeof (a));
2825 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2826 a.table_index_or_table_id = fib - im4->fibs;
2827 a.dst_address = r->address;
2828 a.dst_address_length = r->address_length;
2831 ip4_add_del_route (im4, &a);
2832 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2833 IP4_ROUTE_FLAG_FIB_INDEX);
2837 } /* vec_foreach (fib) */
2844 ip6_address_t address;
2851 ip6_route_t ** routep;
2852 } add_routes_in_fib_arg_t;
2854 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2856 add_routes_in_fib_arg_t * ap = arg;
2858 if (kvp->key[2]>>32 == ap->fib_index)
2860 ip6_address_t *addr;
2862 addr = (ip6_address_t *) kvp;
2863 vec_add2 (*ap->routep, r, 1);
2864 r->address = addr[0];
2865 r->address_length = kvp->key[2] & 0xFF;
2866 r->index = kvp->value;
2870 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2872 vnet_main_t * vnm = vnet_get_main();
2873 vnet_interface_main_t * im = &vnm->interface_main;
2874 ip6_main_t * im6 = &ip6_main;
2875 stats_main_t * sm = &stats_main;
2876 static ip6_route_t * routes;
2877 static u32 * sw_if_indices_to_shut;
2882 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2883 u32 target_fib_id = ntohl(mp->vrf_id);
2884 add_routes_in_fib_arg_t _a, *a=&_a;
2885 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2887 dslock (sm, 1 /* release hint */, 9 /* tag */);
2889 vec_foreach (fib, im6->fibs) {
2890 vnet_sw_interface_t * si;
2892 if (fib->table_id != target_fib_id)
2895 vec_reset_length (sw_if_indices_to_shut);
2897 /* Shut down interfaces in this FIB / clean out intfc routes */
2898 pool_foreach (si, im->sw_interfaces,
2900 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2902 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2905 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2906 sw_if_index = sw_if_indices_to_shut[i];
2907 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2909 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2910 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2911 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2914 vec_reset_length (routes);
2916 a->fib_index = fib - im6->fibs;
2917 a->routep = &routes;
2919 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2921 vec_foreach (r, routes) {
2922 ip6_add_del_route_args_t a;
2924 memset (&a, 0, sizeof (a));
2925 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2926 a.table_index_or_table_id = fib - im6->fibs;
2927 a.dst_address = r->address;
2928 a.dst_address_length = r->address_length;
2931 ip6_add_del_route (im6, &a);
2932 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2933 IP6_ROUTE_FLAG_FIB_INDEX);
2936 /* Reinstall the neighbor / router discovery routes */
2937 vnet_ip6_fib_init (im6, fib - im6->fibs);
2939 } /* vec_foreach (fib) */
2945 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2948 vl_api_reset_fib_reply_t * rmp;
2951 rv = ip6_reset_fib_t_handler (mp);
2953 rv = ip4_reset_fib_t_handler (mp);
2955 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2960 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2962 vl_api_dhcp_proxy_config_reply_t * rmp;
2965 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2966 (ip4_address_t *)(&mp->dhcp_src_address),
2967 (u32) ntohl(mp->vrf_id),
2968 (int) mp->insert_circuit_id,
2969 (int) (mp->is_add == 0));
2971 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2976 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2978 vl_api_dhcp_proxy_config_reply_t * rmp;
2981 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2982 (ip6_address_t *)(&mp->dhcp_src_address),
2983 (u32) ntohl(mp->vrf_id),
2984 (int) mp->insert_circuit_id,
2985 (int) (mp->is_add == 0));
2987 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2991 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2993 vl_api_dhcp_proxy_config_reply_t * rmp;
2996 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2997 (ip4_address_t *)(&mp->dhcp_src_address),
2998 (u32) ntohl(mp->rx_vrf_id),
2999 (u32) ntohl(mp->server_vrf_id),
3000 (int) mp->insert_circuit_id,
3001 (int) (mp->is_add == 0));
3003 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3008 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
3010 vl_api_dhcp_proxy_config_reply_t * rmp;
3014 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
3015 (ip6_address_t *)(&mp->dhcp_src_address),
3016 (u32) ntohl(mp->rx_vrf_id),
3017 (u32) ntohl(mp->server_vrf_id),
3018 (int) mp->insert_circuit_id,
3019 (int) (mp->is_add == 0));
3021 rv = VNET_API_ERROR_UNIMPLEMENTED;
3024 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3029 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
3031 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3034 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
3037 (int)mp->is_add == 0);
3039 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
3042 (int)mp->is_add == 0);
3044 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
3048 static void vl_api_dhcp_proxy_config_t_handler
3049 (vl_api_dhcp_proxy_config_t *mp)
3051 if (mp->is_ipv6 == 0)
3052 dhcpv4_proxy_config (mp);
3054 dhcpv6_proxy_config (mp);
3057 static void vl_api_dhcp_proxy_config_2_t_handler
3058 (vl_api_dhcp_proxy_config_2_t *mp)
3060 if (mp->is_ipv6 == 0)
3061 dhcpv4_proxy_config_2 (mp);
3063 dhcpv6_proxy_config_2 (mp);
3066 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3067 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3069 unix_shared_memory_queue_t * q;
3070 vl_api_dhcp_compl_event_t * mp;
3072 q = vl_api_client_index_to_input_queue (client_index);
3076 mp = vl_msg_api_alloc (sizeof (*mp));
3077 mp->client_index = client_index;
3079 mp->is_ipv6 = is_ipv6;
3080 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3081 mp->hostname[vec_len(hostname) + 1] = '\n';
3082 clib_memcpy (&mp->host_address[0], host_address, 16);
3083 clib_memcpy (&mp->router_address[0], router_address, 16);
3084 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3086 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3088 vl_msg_api_send_shmem (q, (u8 *)&mp);
3091 static void vl_api_dhcp_client_config_t_handler
3092 (vl_api_dhcp_client_config_t *mp)
3094 vlib_main_t *vm = vlib_get_main();
3095 vl_api_dhcp_client_config_reply_t * rmp;
3098 VALIDATE_SW_IF_INDEX(mp);
3100 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3101 mp->hostname, mp->is_add, mp->client_index,
3102 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3105 BAD_SW_IF_INDEX_LABEL;
3107 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3111 vl_api_sw_interface_ip6nd_ra_config_t_handler
3112 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3114 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3116 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, default_router;
3118 is_no = mp->is_no == 1;
3119 suppress = mp->suppress == 1;
3120 managed = mp->managed == 1;
3121 other = mp->other == 1;
3122 ll_option = mp->ll_option == 1;
3123 send_unicast = mp->send_unicast == 1;
3124 cease = mp->cease == 1;
3125 default_router = mp->default_router == 1;
3127 VALIDATE_SW_IF_INDEX(mp);
3129 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3130 suppress, managed, other,
3131 ll_option, send_unicast, cease,
3132 default_router, ntohl (mp->lifetime),
3133 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3134 ntohl(mp->max_interval), ntohl( mp->min_interval),
3137 BAD_SW_IF_INDEX_LABEL;
3139 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3143 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3144 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3146 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3148 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3150 VALIDATE_SW_IF_INDEX(mp);
3152 is_no = mp->is_no == 1;
3153 use_default = mp->use_default == 1;
3154 no_advertise = mp->no_advertise == 1;
3155 off_link = mp->off_link == 1;
3156 no_autoconfig = mp->no_autoconfig == 1;
3157 no_onlink = mp->no_onlink == 1;
3159 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3160 (ip6_address_t *)mp->address, mp->address_length,
3161 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3162 no_advertise, off_link, no_autoconfig, no_onlink,
3165 BAD_SW_IF_INDEX_LABEL;
3166 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3170 vl_api_sw_interface_ip6_enable_disable_t_handler
3171 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3173 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3174 vnet_main_t * vnm = vnet_get_main();
3176 clib_error_t * error;
3180 VALIDATE_SW_IF_INDEX(mp);
3182 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3183 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3186 clib_error_report(error);
3187 rv = VNET_API_ERROR_UNSPECIFIED;
3189 rv = vnm->api_errno;
3192 BAD_SW_IF_INDEX_LABEL;
3194 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3198 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3199 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3201 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3203 clib_error_t * error;
3204 vnet_main_t * vnm = vnet_get_main();
3208 VALIDATE_SW_IF_INDEX(mp);
3210 error = set_ip6_link_local_address(vm,
3211 ntohl(mp->sw_if_index),
3212 (ip6_address_t *)mp->address,
3213 mp->address_length);
3215 clib_error_report(error);
3216 rv = VNET_API_ERROR_UNSPECIFIED;
3218 rv = vnm->api_errno;
3221 BAD_SW_IF_INDEX_LABEL;
3223 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3226 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3228 vl_api_set_ip_flow_hash_reply_t *rmp;
3229 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3231 clib_warning ("unimplemented...");
3233 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3236 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3238 vl_api_set_ip_flow_hash_reply_t *rmp;
3241 u32 flow_hash_config = 0;
3243 table_id = ntohl(mp->vrf_id);
3245 #define _(a,b) if (mp->a) flow_hash_config |= b;
3246 foreach_flow_hash_bit;
3249 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3251 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3255 static void vl_api_set_ip_flow_hash_t_handler
3256 (vl_api_set_ip_flow_hash_t *mp)
3258 if (mp->is_ipv6 == 0)
3259 set_ip4_flow_hash (mp);
3261 set_ip6_flow_hash (mp);
3264 static void vl_api_sw_interface_set_unnumbered_t_handler
3265 (vl_api_sw_interface_set_unnumbered_t *mp)
3267 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3269 vnet_sw_interface_t * si;
3270 vnet_main_t *vnm = vnet_get_main();
3271 u32 sw_if_index, unnumbered_sw_if_index;
3273 sw_if_index = ntohl(mp->sw_if_index);
3274 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3277 * The API message field names are backwards from
3278 * the underlying data structure names.
3279 * It's not worth changing them now.
3281 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3282 unnumbered_sw_if_index)) {
3283 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3287 /* Only check the "use loop0" field when setting the binding */
3289 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3290 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3294 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3297 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3298 si->unnumbered_sw_if_index = sw_if_index;
3300 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3301 si->unnumbered_sw_if_index = (u32)~0;
3305 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3308 static void vl_api_create_loopback_t_handler
3309 (vl_api_create_loopback_t *mp)
3311 vl_api_create_loopback_reply_t * rmp;
3315 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3317 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3319 rmp->sw_if_index = ntohl (sw_if_index);
3323 static void vl_api_delete_loopback_t_handler
3324 (vl_api_delete_loopback_t *mp)
3326 vl_api_delete_loopback_reply_t * rmp;
3330 sw_if_index = ntohl (mp->sw_if_index);
3331 rv = vnet_delete_loopback_interface (sw_if_index);
3333 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3336 static void vl_api_control_ping_t_handler
3337 (vl_api_control_ping_t *mp)
3339 vl_api_control_ping_reply_t * rmp;
3342 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3344 rmp->vpe_pid = ntohl (getpid());
3348 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3350 u8 **shmem_vecp = (u8 **)arg;
3353 api_main_t * am = &api_main;
3356 shmem_vec = *shmem_vecp;
3358 offset = vec_len (shmem_vec);
3360 pthread_mutex_lock (&am->vlib_rp->mutex);
3361 oldheap = svm_push_data_heap (am->vlib_rp);
3363 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3365 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3367 svm_pop_heap (oldheap);
3368 pthread_mutex_unlock (&am->vlib_rp->mutex);
3370 *shmem_vecp = shmem_vec;
3374 static void vl_api_cli_request_t_handler
3375 (vl_api_cli_request_t *mp)
3377 vl_api_cli_reply_t *rp;
3378 unix_shared_memory_queue_t *q;
3379 vlib_main_t * vm = vlib_get_main();
3380 api_main_t * am = &api_main;
3381 unformat_input_t input;
3385 q = vl_api_client_index_to_input_queue (mp->client_index);
3389 rp = vl_msg_api_alloc (sizeof (*rp));
3390 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3391 rp->context = mp->context;
3393 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3395 vlib_cli_input (vm, &input, shmem_cli_output,
3398 pthread_mutex_lock (&am->vlib_rp->mutex);
3399 oldheap = svm_push_data_heap (am->vlib_rp);
3401 vec_add1(shmem_vec, 0);
3403 svm_pop_heap (oldheap);
3404 pthread_mutex_unlock (&am->vlib_rp->mutex);
3406 rp->reply_in_shmem = (uword)shmem_vec;
3408 vl_msg_api_send_shmem (q, (u8 *)&rp);
3411 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3414 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3415 vnet_main_t *vnm = vnet_get_main();
3416 clib_error_t * error;
3421 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3423 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3426 clib_error_report(error);
3427 rv = VNET_API_ERROR_UNSPECIFIED;
3429 rv = vnm->api_errno;
3432 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3435 static void vl_api_sr_tunnel_add_del_t_handler
3436 (vl_api_sr_tunnel_add_del_t *mp)
3439 clib_warning ("unimplemented");
3441 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3443 vl_api_sr_tunnel_add_del_reply_t * rmp;
3444 ip6_address_t * segments = 0, * seg;
3445 ip6_address_t * tags = 0, *tag;
3446 ip6_address_t * this_address;
3449 if (mp->n_segments == 0) {
3454 memset (a, 0, sizeof (*a));
3455 a->src_address = (ip6_address_t *)&mp->src_address;
3456 a->dst_address = (ip6_address_t *)&mp->dst_address;
3457 a->dst_mask_width = mp->dst_mask_width;
3458 a->flags_net_byte_order = mp->flags_net_byte_order;
3459 a->is_del = (mp->is_add == 0);
3460 a->rx_table_id = ntohl(mp->outer_vrf_id);
3461 a->tx_table_id = ntohl(mp->inner_vrf_id);
3463 a->name = format(0, "%s", mp->name);
3464 if (!(vec_len(a->name)))
3467 a->policy_name = format(0, "%s", mp->policy_name);
3468 if (!(vec_len(a->policy_name)))
3471 /* Yank segments and tags out of the API message */
3472 this_address = (ip6_address_t *)mp->segs_and_tags;
3473 for (i = 0; i < mp->n_segments; i++) {
3474 vec_add2 (segments, seg, 1);
3475 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3478 for (i = 0; i < mp->n_tags; i++) {
3479 vec_add2 (tags, tag, 1);
3480 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3484 a->segments = segments;
3487 rv = ip6_sr_add_del_tunnel (a);
3491 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3495 static void vl_api_sr_policy_add_del_t_handler
3496 (vl_api_sr_policy_add_del_t *mp)
3499 clib_warning ("unimplemented");
3501 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3503 vl_api_sr_policy_add_del_reply_t * rmp;
3506 memset (a, 0, sizeof (*a));
3507 a->is_del = (mp->is_add == 0);
3509 a->name = format(0, "%s", mp->name);
3510 if (!(vec_len(a->name)))
3512 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3516 if (!(mp->tunnel_names[0]))
3518 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3522 // start deserializing tunnel_names
3523 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3524 u8 * deser_tun_names = mp->tunnel_names;
3525 deser_tun_names += 1; //moving along
3528 int tun_name_len = 0;
3530 for (i=0; i < num_tunnels; i++)
3532 tun_name_len= *deser_tun_names;
3533 deser_tun_names += 1;
3534 vec_resize (tun_name, tun_name_len);
3535 memcpy(tun_name, deser_tun_names, tun_name_len);
3536 vec_add1 (a->tunnel_names, tun_name);
3537 deser_tun_names += tun_name_len;
3541 rv = ip6_sr_add_del_policy (a);
3545 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3549 static void vl_api_sr_multicast_map_add_del_t_handler
3550 (vl_api_sr_multicast_map_add_del_t *mp)
3553 clib_warning ("unimplemented");
3555 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3557 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3559 memset (a, 0, sizeof (*a));
3560 a->is_del = (mp->is_add == 0);
3562 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3563 a->policy_name = format(0, "%s", mp->policy_name);
3565 if (a->multicast_address == 0)
3571 if (!(a->policy_name))
3577 #if DPDK > 0 /* Cannot call replicate without DPDK */
3578 rv = ip6_sr_add_del_multicastmap (a);
3580 clib_warning ("multicast replication without DPDK not implemented");
3581 rv = VNET_API_ERROR_UNIMPLEMENTED;
3586 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3590 #define foreach_classify_add_del_table_field \
3595 _(match_n_vectors) \
3596 _(next_table_index) \
3599 static void vl_api_classify_add_del_table_t_handler
3600 (vl_api_classify_add_del_table_t * mp)
3602 vl_api_classify_add_del_table_reply_t * rmp;
3603 vnet_classify_main_t * cm = &vnet_classify_main;
3604 vnet_classify_table_t * t;
3608 foreach_classify_add_del_table_field;
3611 #define _(a) a = ntohl(mp->a);
3612 foreach_classify_add_del_table_field;
3615 /* The underlying API fails silently, on purpose, so check here */
3616 if (mp->is_add == 0)
3617 if (pool_is_free_index (cm->tables, table_index)) {
3618 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3622 rv = vnet_classify_add_del_table
3623 (cm, mp->mask, nbuckets, memory_size,
3624 skip_n_vectors, match_n_vectors,
3625 next_table_index, miss_next_index,
3626 &table_index, mp->is_add);
3629 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3631 if (rv == 0 && mp->is_add) {
3632 t = pool_elt_at_index (cm->tables, table_index);
3633 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3634 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3635 rmp->new_table_index = ntohl(table_index);
3637 rmp->skip_n_vectors = ~0;
3638 rmp->match_n_vectors = ~0;
3639 rmp->new_table_index = ~0;
3644 static void vl_api_classify_add_del_session_t_handler
3645 (vl_api_classify_add_del_session_t * mp)
3647 vnet_classify_main_t * cm = &vnet_classify_main;
3648 vl_api_classify_add_del_session_reply_t * rmp;
3650 u32 table_index, hit_next_index, opaque_index;
3653 table_index = ntohl (mp->table_index);
3654 hit_next_index = ntohl (mp->hit_next_index);
3655 opaque_index = ntohl (mp->opaque_index);
3656 advance = ntohl (mp->advance);
3658 rv = vnet_classify_add_del_session
3659 (cm, table_index, mp->match, hit_next_index, opaque_index,
3660 advance, mp->is_add);
3662 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3665 static void vl_api_classify_set_interface_ip_table_t_handler
3666 (vl_api_classify_set_interface_ip_table_t * mp)
3668 vlib_main_t * vm = vlib_get_main();
3669 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3671 u32 table_index, sw_if_index;
3673 table_index = ntohl (mp->table_index);
3674 sw_if_index = ntohl (mp->sw_if_index);
3676 VALIDATE_SW_IF_INDEX(mp);
3679 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3681 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3683 BAD_SW_IF_INDEX_LABEL;
3685 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3688 static void vl_api_classify_set_interface_l2_tables_t_handler
3689 (vl_api_classify_set_interface_l2_tables_t * mp)
3691 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3693 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3696 ip4_table_index = ntohl(mp->ip4_table_index);
3697 ip6_table_index = ntohl(mp->ip6_table_index);
3698 other_table_index = ntohl(mp->other_table_index);
3699 sw_if_index = ntohl(mp->sw_if_index);
3701 VALIDATE_SW_IF_INDEX(mp);
3703 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3704 ip6_table_index, other_table_index);
3707 if (ip4_table_index != ~0 || ip6_table_index != ~0
3708 || other_table_index != ~0)
3713 vnet_l2_classify_enable_disable (sw_if_index, enable);
3716 BAD_SW_IF_INDEX_LABEL;
3718 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3722 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3725 vl_api_l2_fib_clear_table_reply_t * rmp;
3727 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3728 * that is not currently implemented. When that TODO is fixed
3729 * this call should be changed to pass 1 instead of 0.
3731 l2fib_clear_table (0);
3733 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3736 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3741 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3744 vl_api_l2_interface_efp_filter_reply_t * rmp;
3745 vnet_main_t *vnm = vnet_get_main();
3747 // enable/disable the feature
3748 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3749 rv = vnm->api_errno;
3751 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3755 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3758 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3759 vnet_main_t * vnm = vnet_get_main();
3760 vlib_main_t * vm = vlib_get_main();
3763 VALIDATE_SW_IF_INDEX(mp);
3765 vtr_op = ntohl(mp->vtr_op);
3767 /* The L2 code is unsuspicious */
3769 case L2_VTR_DISABLED:
3774 case L2_VTR_TRANSLATE_1_1:
3775 case L2_VTR_TRANSLATE_1_2:
3776 case L2_VTR_TRANSLATE_2_1:
3777 case L2_VTR_TRANSLATE_2_2:
3781 rv = VNET_API_ERROR_INVALID_VALUE;
3782 goto bad_sw_if_index;
3785 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3786 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3789 BAD_SW_IF_INDEX_LABEL;
3791 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3795 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3798 vl_api_create_vhost_user_if_reply_t * rmp;
3799 #if DPDK > 0 && DPDK_VHOST_USER
3800 u32 sw_if_index = (u32)~0;
3802 vnet_main_t * vnm = vnet_get_main();
3803 vlib_main_t * vm = vlib_get_main();
3805 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3806 mp->is_server, &sw_if_index, (u64)~0,
3807 mp->renumber, ntohl(mp->custom_dev_instance),
3808 (mp->use_custom_mac)?mp->mac_address:NULL);
3810 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3812 rmp->sw_if_index = ntohl (sw_if_index);
3815 rv = VNET_API_ERROR_UNIMPLEMENTED;
3816 REPLY_MACRO(VL_API_CREATE_VHOST_USER_IF_REPLY);
3821 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3824 vl_api_modify_vhost_user_if_reply_t * rmp;
3825 #if DPDK > 0 && DPDK_VHOST_USER
3826 u32 sw_if_index = ntohl(mp->sw_if_index);
3828 vnet_main_t * vnm = vnet_get_main();
3829 vlib_main_t * vm = vlib_get_main();
3831 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3832 mp->is_server, sw_if_index, (u64)~0,
3833 mp->renumber, ntohl(mp->custom_dev_instance));
3835 rv = VNET_API_ERROR_UNIMPLEMENTED;
3837 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3841 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3844 vl_api_delete_vhost_user_if_reply_t * rmp;
3845 #if DPDK > 0 && DPDK_VHOST_USER
3846 vpe_api_main_t * vam = &vpe_api_main;
3847 u32 sw_if_index = ntohl(mp->sw_if_index);
3849 vnet_main_t * vnm = vnet_get_main();
3850 vlib_main_t * vm = vlib_get_main();
3852 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3854 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3856 unix_shared_memory_queue_t * q =
3857 vl_api_client_index_to_input_queue (mp->client_index);
3861 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3864 rv = VNET_API_ERROR_UNIMPLEMENTED;
3865 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3869 static void vl_api_sw_interface_vhost_user_details_t_handler (
3870 vl_api_sw_interface_vhost_user_details_t * mp)
3872 clib_warning ("BUG");
3875 #if DPDK > 0 && DPDK_VHOST_USER
3876 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3877 unix_shared_memory_queue_t *q,
3878 vhost_user_intf_details_t * vui,
3881 vl_api_sw_interface_vhost_user_details_t * mp;
3883 mp = vl_msg_api_alloc (sizeof (*mp));
3884 memset (mp, 0, sizeof (*mp));
3885 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3886 mp->sw_if_index = ntohl(vui->sw_if_index);
3887 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3888 mp->features = clib_net_to_host_u64 (vui->features);
3889 mp->is_server = vui->is_server;
3890 mp->num_regions = ntohl(vui->num_regions);
3891 mp->sock_errno = ntohl(vui->sock_errno);
3892 mp->context = context;
3894 strncpy ((char *) mp->sock_filename,
3895 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3896 strncpy ((char *) mp->interface_name,
3897 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3899 vl_msg_api_send_shmem (q, (u8 *)&mp);
3904 vl_api_sw_interface_vhost_user_dump_t_handler (
3905 vl_api_sw_interface_vhost_user_dump_t *mp)
3907 #if DPDK > 0 && DPDK_VHOST_USER
3909 vpe_api_main_t * am = &vpe_api_main;
3910 vnet_main_t * vnm = vnet_get_main();
3911 vlib_main_t * vm = vlib_get_main();
3912 vhost_user_intf_details_t *ifaces = NULL;
3913 vhost_user_intf_details_t *vuid = NULL;
3914 unix_shared_memory_queue_t * q;
3916 q = vl_api_client_index_to_input_queue (mp->client_index);
3920 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3924 vec_foreach (vuid, ifaces) {
3925 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3931 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3932 unix_shared_memory_queue_t *q,
3937 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3938 u8 * if_name = NULL;
3939 vnet_sw_interface_t * si = NULL;
3941 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3943 if_name = format(if_name, "%U",
3944 format_vnet_sw_interface_name, lm->vnet_main, si);
3946 mp = vl_msg_api_alloc (sizeof (*mp));
3947 memset (mp, 0, sizeof (*mp));
3948 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3949 strncpy((char *)mp->interface_name,
3950 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3951 mp->sw_if_index = ntohl(si->sw_if_index);
3952 mp->local_session_id = s->local_session_id;
3953 mp->remote_session_id = s->remote_session_id;
3954 mp->local_cookie[0] = s->local_cookie[0];
3955 mp->local_cookie[1] = s->local_cookie[1];
3956 mp->remote_cookie = s->remote_cookie;
3957 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3958 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3959 mp->l2_sublayer_present = s->l2_sublayer_present;
3960 mp->context = context;
3962 vl_msg_api_send_shmem (q, (u8 *)&mp);
3965 static void send_ip_address_details (vpe_api_main_t * am,
3966 unix_shared_memory_queue_t * q,
3972 vl_api_ip_address_details_t * mp;
3974 mp = vl_msg_api_alloc (sizeof (*mp));
3975 memset (mp, 0, sizeof (*mp));
3976 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3979 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3981 u32 * tp = (u32 *)mp->ip;
3982 *tp = ntohl(*(u32*)ip);
3984 mp->prefix_length = prefix_length;
3985 mp->context = context;
3987 vl_msg_api_send_shmem (q, (u8 *)&mp);
3991 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
3993 vpe_api_main_t * am = &vpe_api_main;
3994 unix_shared_memory_queue_t * q;
3997 ip6_main_t * im6 = &ip6_main;
3998 ip4_main_t * im4 = &ip4_main;
3999 ip_lookup_main_t * lm6 = &im6->lookup_main;
4000 ip_lookup_main_t * lm4 = &im4->lookup_main;
4001 ip_interface_address_t * ia = 0;
4002 u32 sw_if_index = ~0;
4003 int rv __attribute__ ((unused)) = 0;
4005 VALIDATE_SW_IF_INDEX(mp);
4007 sw_if_index = ntohl(mp->sw_if_index);
4009 q = vl_api_client_index_to_input_queue (mp->client_index);
4015 foreach_ip_interface_address (lm6, ia, sw_if_index,
4016 1 /* honor unnumbered */,
4018 r6 = ip_interface_address_get_address (lm6, ia);
4019 u16 prefix_length = ia->address_length;
4020 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4023 foreach_ip_interface_address (lm4, ia, sw_if_index,
4024 1 /* honor unnumbered */,
4026 r4 = ip_interface_address_get_address (lm4, ia);
4027 u16 prefix_length = ia->address_length;
4028 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4031 BAD_SW_IF_INDEX_LABEL;
4034 static void send_ip_details (vpe_api_main_t * am,
4035 unix_shared_memory_queue_t *q,
4039 vl_api_ip_details_t * mp;
4041 mp = vl_msg_api_alloc (sizeof (*mp));
4042 memset (mp, 0, sizeof (*mp));
4043 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
4045 mp->sw_if_index = ntohl(sw_if_index);
4046 mp->context = context;
4048 vl_msg_api_send_shmem (q, (u8 *)&mp);
4052 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
4053 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
4055 vpe_api_main_t * am = &vpe_api_main;
4056 l2t_main_t * lm = &l2t_main;
4057 unix_shared_memory_queue_t * q;
4058 l2t_session_t *session;
4060 q = vl_api_client_index_to_input_queue (mp->client_index);
4064 pool_foreach (session, lm->sessions,
4066 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4071 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4072 unix_shared_memory_queue_t *q,
4073 tapcli_interface_details_t *tap_if,
4076 vl_api_sw_interface_tap_details_t * mp;
4077 mp = vl_msg_api_alloc (sizeof (*mp));
4078 memset (mp, 0, sizeof (*mp));
4079 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4080 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4081 strncpy((char *)mp->dev_name,
4082 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4083 mp->context = context;
4085 vl_msg_api_send_shmem (q, (u8 *)&mp);
4089 vl_api_sw_interface_tap_dump_t_handler (
4090 vl_api_sw_interface_tap_dump_t *mp)
4093 vpe_api_main_t * am = &vpe_api_main;
4094 unix_shared_memory_queue_t * q;
4095 tapcli_interface_details_t *tapifs = NULL;
4096 tapcli_interface_details_t *tap_if = NULL;
4098 q = vl_api_client_index_to_input_queue (mp->client_index);
4102 rv = vnet_tap_dump_ifs(&tapifs);
4106 vec_foreach(tap_if, tapifs) {
4107 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4114 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4116 vpe_api_main_t * am = &vpe_api_main;
4117 vnet_main_t * vnm = vnet_get_main();
4118 vlib_main_t * vm = vlib_get_main();
4119 vnet_interface_main_t * im = &vnm->interface_main;
4120 unix_shared_memory_queue_t * q;
4121 vnet_sw_interface_t * si, * sorted_sis;
4122 u32 sw_if_index = ~0;
4124 q = vl_api_client_index_to_input_queue (mp->client_index);
4129 /* Gather interfaces. */
4130 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4131 _vec_len (sorted_sis) = 0;
4132 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4134 vec_foreach (si, sorted_sis) {
4135 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4136 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4139 sw_if_index = si->sw_if_index;
4140 send_ip_details(am, q, sw_if_index, mp->context);
4145 static void vl_api_l2_fib_table_entry_t_handler (
4146 vl_api_l2_fib_table_entry_t * mp)
4148 clib_warning ("BUG");
4151 static void send_l2fib_table_entry (vpe_api_main_t * am,
4152 unix_shared_memory_queue_t *q,
4153 l2fib_entry_key_t * l2fe_key,
4154 l2fib_entry_result_t * l2fe_res,
4157 vl_api_l2_fib_table_entry_t * mp;
4159 mp = vl_msg_api_alloc (sizeof (*mp));
4160 memset (mp, 0, sizeof (*mp));
4161 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4163 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4165 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4166 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4167 mp->static_mac = l2fe_res->fields.static_mac;
4168 mp->filter_mac = l2fe_res->fields.filter;
4169 mp->bvi_mac = l2fe_res->fields.bvi;
4170 mp->context = context;
4172 vl_msg_api_send_shmem (q, (u8 *)&mp);
4176 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4178 vpe_api_main_t * am = &vpe_api_main;
4179 bd_main_t * bdm = &bd_main;
4180 l2fib_entry_key_t *l2fe_key = NULL;
4181 l2fib_entry_result_t *l2fe_res = NULL;
4182 u32 ni, bd_id = ntohl (mp->bd_id);
4184 unix_shared_memory_queue_t * q;
4187 q = vl_api_client_index_to_input_queue (mp->client_index);
4191 /* see l2fib_table_dump: ~0 means "any" */
4195 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4202 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4204 vec_foreach_index (ni, l2fe_key) {
4205 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4206 vec_elt_at_index(l2fe_res, ni), mp->context);
4213 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4215 vl_api_show_version_reply_t *rmp;
4217 char * vpe_api_get_build_directory(void);
4218 char * vpe_api_get_version(void);
4219 char * vpe_api_get_build_date(void);
4221 unix_shared_memory_queue_t * q =
4222 vl_api_client_index_to_input_queue (mp->client_index);
4227 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4229 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4230 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4231 ARRAY_LEN(rmp->build_directory)-1);
4232 strncpy ((char *) rmp->version, vpe_api_get_version(),
4233 ARRAY_LEN(rmp->version)-1);
4234 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4235 ARRAY_LEN(rmp->build_date)-1);
4239 static void vl_api_get_node_index_t_handler
4240 (vl_api_get_node_index_t * mp)
4242 vlib_main_t * vm = vlib_get_main();
4243 vl_api_get_node_index_reply_t * rmp;
4246 u32 node_index = ~0;
4248 n = vlib_get_node_by_name (vm, mp->node_name);
4251 rv = VNET_API_ERROR_NO_SUCH_NODE;
4253 node_index = n->index;
4255 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4257 rmp->node_index = ntohl(node_index);
4261 static void vl_api_get_next_index_t_handler
4262 (vl_api_get_next_index_t * mp)
4264 vlib_main_t * vm = vlib_get_main();
4265 vl_api_get_next_index_reply_t * rmp;
4266 vlib_node_t * node, * next_node;
4268 u32 next_node_index = ~0, next_index = ~0;
4271 node = vlib_get_node_by_name (vm, mp->node_name);
4274 rv = VNET_API_ERROR_NO_SUCH_NODE;
4278 next_node = vlib_get_node_by_name (vm, mp->next_name);
4280 if (next_node == 0) {
4281 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4285 next_node_index = next_node->index;
4287 p = hash_get (node->next_slot_by_node, next_node_index);
4290 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4297 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4299 rmp->next_index = ntohl(next_index);
4303 static void vl_api_add_node_next_t_handler
4304 (vl_api_add_node_next_t * mp)
4306 vlib_main_t * vm = vlib_get_main();
4307 vl_api_add_node_next_reply_t * rmp;
4308 vlib_node_t * n, * next;
4310 u32 next_index = ~0;
4312 n = vlib_get_node_by_name (vm, mp->node_name);
4315 rv = VNET_API_ERROR_NO_SUCH_NODE;
4319 next = vlib_get_node_by_name (vm, mp->next_name);
4322 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4324 next_index = vlib_node_add_next (vm, n->index, next->index);
4327 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4329 rmp->next_index = ntohl(next_index);
4333 static void vl_api_l2tpv3_create_tunnel_t_handler
4334 (vl_api_l2tpv3_create_tunnel_t *mp)
4336 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4337 l2t_main_t *lm = &l2t_main;
4338 u32 sw_if_index = (u32)~0;
4341 if (mp->is_ipv6 != 1) {
4342 rv = VNET_API_ERROR_UNIMPLEMENTED;
4346 u32 encap_fib_index;
4348 if (mp->encap_vrf_id != ~0) {
4350 ip6_main_t *im = &ip6_main;
4351 if (!(p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id)))) {
4352 rv = VNET_API_ERROR_NO_SUCH_FIB;
4355 encap_fib_index = p[0];
4357 encap_fib_index = ~0;
4360 rv = create_l2tpv3_ipv6_tunnel (lm,
4361 (ip6_address_t *) mp->client_address,
4362 (ip6_address_t *) mp->our_address,
4363 ntohl(mp->local_session_id),
4364 ntohl(mp->remote_session_id),
4365 clib_net_to_host_u64(mp->local_cookie),
4366 clib_net_to_host_u64(mp->remote_cookie),
4367 mp->l2_sublayer_present,
4372 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4374 rmp->sw_if_index = ntohl (sw_if_index);
4378 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4379 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4381 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4382 l2t_main_t *lm = &l2t_main;
4385 VALIDATE_SW_IF_INDEX(mp);
4387 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4388 clib_net_to_host_u64(mp->new_local_cookie),
4389 clib_net_to_host_u64(mp->new_remote_cookie));
4391 BAD_SW_IF_INDEX_LABEL;
4393 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4396 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4397 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4400 vnet_main_t * vnm = vnet_get_main();
4401 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4403 VALIDATE_SW_IF_INDEX(mp);
4405 rv = l2tpv3_interface_enable_disable
4406 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4408 BAD_SW_IF_INDEX_LABEL;
4410 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4413 static void vl_api_l2tpv3_set_lookup_key_t_handler
4414 (vl_api_l2tpv3_set_lookup_key_t * mp)
4417 l2t_main_t *lm = &l2t_main;
4418 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4420 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4421 rv = VNET_API_ERROR_INVALID_VALUE;
4425 lm->lookup_type = mp->key;
4428 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4431 static void vl_api_vxlan_add_del_tunnel_t_handler
4432 (vl_api_vxlan_add_del_tunnel_t * mp)
4434 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4436 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4437 u32 encap_fib_index;
4439 ip4_main_t * im = &ip4_main;
4440 u32 sw_if_index = ~0;
4442 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4444 rv = VNET_API_ERROR_NO_SUCH_FIB;
4447 encap_fib_index = p[0];
4449 /* Check src & dst are different */
4450 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4451 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4452 rv = VNET_API_ERROR_SAME_SRC_DST;
4455 memset (a, 0, sizeof (*a));
4457 a->is_add = mp->is_add;
4458 a->is_ip6 = mp->is_ipv6;
4460 /* ip addresses sent in network byte order */
4462 memcpy(&(a->src.ip6), mp->src_address, 16);
4463 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4465 memcpy(&(a->src.ip4), mp->src_address, 4);
4466 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4469 a->encap_fib_index = encap_fib_index;
4470 a->decap_next_index = ntohl(mp->decap_next_index);
4471 a->vni = ntohl(mp->vni);
4472 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4475 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4477 rmp->sw_if_index = ntohl (sw_if_index);
4481 static void send_vxlan_tunnel_details
4482 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4484 vl_api_vxlan_tunnel_details_t * rmp;
4485 ip4_main_t * im4 = &ip4_main;
4486 ip6_main_t * im6 = &ip6_main;
4487 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4489 rmp = vl_msg_api_alloc (sizeof (*rmp));
4490 memset (rmp, 0, sizeof (*rmp));
4491 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4493 memcpy(rmp->src_address, &(t->src.ip6), 16);
4494 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4495 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4497 memcpy(rmp->src_address, &(t->src.ip4), 4);
4498 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4499 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4501 rmp->vni = htonl(t->vni);
4502 rmp->decap_next_index = htonl(t->decap_next_index);
4503 rmp->sw_if_index = htonl(t->sw_if_index);
4504 rmp->is_ipv6 = is_ipv6;
4505 rmp->context = context;
4507 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4510 static void vl_api_vxlan_tunnel_dump_t_handler
4511 (vl_api_vxlan_tunnel_dump_t * mp)
4513 unix_shared_memory_queue_t * q;
4514 vxlan_main_t * vxm = &vxlan_main;
4518 q = vl_api_client_index_to_input_queue (mp->client_index);
4523 sw_if_index = ntohl(mp->sw_if_index);
4525 if (~0 == sw_if_index) {
4526 pool_foreach (t, vxm->tunnels,
4528 send_vxlan_tunnel_details(t, q, mp->context);
4531 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4532 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4535 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4536 send_vxlan_tunnel_details(t, q, mp->context);
4540 static void vl_api_gre_add_del_tunnel_t_handler
4541 (vl_api_gre_add_del_tunnel_t * mp)
4543 vl_api_gre_add_del_tunnel_reply_t * rmp;
4545 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4548 ip4_main_t * im = &ip4_main;
4549 u32 sw_if_index = ~0;
4551 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_fib_id));
4553 rv = VNET_API_ERROR_NO_SUCH_FIB;
4556 outer_fib_id = p[0];
4558 /* Check src & dst are different */
4559 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4560 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4561 rv = VNET_API_ERROR_SAME_SRC_DST;
4564 memset (a, 0, sizeof (*a));
4566 a->is_add = mp->is_add;
4568 /* ip addresses sent in network byte order */
4569 clib_memcpy(&(a->src), mp->src_address, 4);
4570 clib_memcpy(&(a->dst), mp->dst_address, 4);
4572 a->outer_fib_id = outer_fib_id;
4573 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4576 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4578 rmp->sw_if_index = ntohl (sw_if_index);
4582 static void send_gre_tunnel_details
4583 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4585 vl_api_gre_tunnel_details_t * rmp;
4586 ip4_main_t * im = &ip4_main;
4588 rmp = vl_msg_api_alloc (sizeof (*rmp));
4589 memset (rmp, 0, sizeof (*rmp));
4590 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4591 clib_memcpy(rmp->src_address, &(t->tunnel_src), 4);
4592 clib_memcpy(rmp->dst_address, &(t->tunnel_dst), 4);
4593 rmp->outer_fib_id = htonl(im->fibs[t->outer_fib_index].table_id);
4594 rmp->sw_if_index = htonl(t->sw_if_index);
4595 rmp->context = context;
4597 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4600 static void vl_api_gre_tunnel_dump_t_handler
4601 (vl_api_gre_tunnel_dump_t * mp)
4603 unix_shared_memory_queue_t * q;
4604 gre_main_t * gm = &gre_main;
4608 q = vl_api_client_index_to_input_queue (mp->client_index);
4613 sw_if_index = ntohl(mp->sw_if_index);
4615 if (~0 == sw_if_index) {
4616 pool_foreach (t, gm->tunnels,
4618 send_gre_tunnel_details(t, q, mp->context);
4621 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4622 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4625 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4626 send_gre_tunnel_details(t, q, mp->context);
4631 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4633 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4635 vl_api_l2_patch_add_del_reply_t * rmp;
4636 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4640 VALIDATE_RX_SW_IF_INDEX(mp);
4641 VALIDATE_TX_SW_IF_INDEX(mp);
4643 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4644 ntohl(mp->tx_sw_if_index),
4645 (int)(mp->is_add != 0));
4647 BAD_RX_SW_IF_INDEX_LABEL;
4648 BAD_TX_SW_IF_INDEX_LABEL;
4650 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4654 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4655 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4657 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4659 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4660 u32 encap_fib_index, decap_fib_index;
4663 ip4_main_t * im = &ip4_main;
4664 u32 sw_if_index = ~0;
4667 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4669 rv = VNET_API_ERROR_NO_SUCH_FIB;
4672 encap_fib_index = p[0];
4674 protocol = mp->protocol;
4676 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4677 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4678 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4680 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4683 decap_fib_index = p[0];
4685 decap_fib_index = ntohl(mp->decap_vrf_id);
4688 /* Check src & dst are different */
4689 if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4690 (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4691 rv = VNET_API_ERROR_SAME_SRC_DST;
4694 memset (a, 0, sizeof (*a));
4696 a->is_add = mp->is_add;
4697 a->is_ip6 = mp->is_ipv6;
4698 /* ip addresses sent in network byte order */
4700 clib_memcpy(&(a->local.ip6), mp->local, 16);
4701 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4703 clib_memcpy(&(a->local.ip4), mp->local, 4);
4704 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4706 a->encap_fib_index = encap_fib_index;
4707 a->decap_fib_index = decap_fib_index;
4708 a->protocol = protocol;
4709 a->vni = ntohl(mp->vni);
4710 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4713 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4715 rmp->sw_if_index = ntohl (sw_if_index);
4719 static void send_vxlan_gpe_tunnel_details
4720 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4722 vl_api_vxlan_gpe_tunnel_details_t * rmp;
4723 ip4_main_t * im4 = &ip4_main;
4724 ip6_main_t * im6 = &ip6_main;
4725 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4727 rmp = vl_msg_api_alloc (sizeof (*rmp));
4728 memset (rmp, 0, sizeof (*rmp));
4729 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4731 memcpy(rmp->local, &(t->local.ip6), 16);
4732 memcpy(rmp->remote, &(t->remote.ip6), 16);
4733 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4734 rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
4736 memcpy(rmp->local, &(t->local.ip4), 4);
4737 memcpy(rmp->remote, &(t->remote.ip4), 4);
4738 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4739 rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
4741 rmp->vni = htonl(t->vni);
4742 rmp->protocol = t->protocol;
4743 rmp->sw_if_index = htonl(t->sw_if_index);
4744 rmp->is_ipv6 = is_ipv6;
4745 rmp->context = context;
4747 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4750 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4751 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4753 unix_shared_memory_queue_t * q;
4754 vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
4755 vxlan_gpe_tunnel_t * t;
4758 q = vl_api_client_index_to_input_queue (mp->client_index);
4763 sw_if_index = ntohl(mp->sw_if_index);
4765 if (~0 == sw_if_index) {
4766 pool_foreach (t, vgm->tunnels,
4768 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4771 if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
4772 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
4775 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4776 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4780 /** Used for transferring locators via VPP API */
4781 typedef CLIB_PACKED(struct
4783 u32 sw_if_index; /**< locator sw_if_index */
4784 u8 priority; /**< locator priority */
4785 u8 weight; /**< locator weight */
4789 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4791 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4793 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4795 ls_locator_t *ls_loc;
4797 u8 *locator_name = NULL;
4800 memset(a, 0, sizeof(a[0]));
4802 locator_name = format(0, "%s", mp->locator_set_name);
4804 a->name = locator_name;
4805 a->is_add = mp->is_add;
4808 memset(&locator, 0, sizeof(locator));
4809 for (i = 0; i < mp->locator_num; i++) {
4810 ls_loc = &((ls_locator_t *) mp->locators)[i];
4811 VALIDATE_SW_IF_INDEX(ls_loc);
4813 locator.sw_if_index = htonl(ls_loc->sw_if_index);
4814 locator.priority = ls_loc->priority;
4815 locator.weight = ls_loc->weight;
4817 vec_add1(a->locators, locator);
4820 rv = vnet_lisp_add_del_locator_set(a, &ls_index);
4822 BAD_SW_IF_INDEX_LABEL;
4824 vec_free(locator_name);
4825 vec_free(a->locators);
4827 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4831 vl_api_lisp_add_del_locator_t_handler(
4832 vl_api_lisp_add_del_locator_t *mp)
4834 vl_api_lisp_add_del_locator_reply_t *rmp;
4836 locator_t locator, *locators = NULL;
4837 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4839 u8 *locator_name = NULL;
4841 memset(&locator, 0, sizeof(locator));
4842 memset(a, 0, sizeof(a[0]));
4844 locator.sw_if_index = ntohl(mp->sw_if_index);
4845 locator.priority = mp->priority;
4846 locator.weight = mp->weight;
4848 vec_add1(locators, locator);
4850 locator_name = format(0, "%s", mp->locator_set_name);
4852 a->name = locator_name;
4853 a->locators = locators;
4854 a->is_add = mp->is_add;
4857 rv = vnet_lisp_add_del_locator(a, NULL, &ls_index);
4860 vec_free(locator_name);
4862 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4866 vl_api_lisp_add_del_local_eid_t_handler(
4867 vl_api_lisp_add_del_local_eid_t *mp)
4869 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4870 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4872 ip_prefix_t *prefp = NULL;
4873 ip_address_t *ip_eid = NULL;
4875 u8 * mac = gid_address_mac (&eid);
4877 u32 locator_set_index = ~0, map_index = ~0;
4878 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4880 memset (a, 0, sizeof (a[0]));
4881 memset (&eid, 0, sizeof (eid));
4883 prefp = &gid_address_ippref(&eid);
4884 ip_eid = &ip_prefix_addr(prefp);
4886 switch (mp->eid_type)
4889 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4890 ip_address_set(ip_eid, mp->eid, IP4);
4891 ip_prefix_len(prefp) = mp->prefix_len;
4894 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4895 ip_address_set(ip_eid, mp->eid, IP6);
4896 ip_prefix_len(prefp) = mp->prefix_len;
4898 case 2: /* l2 mac */
4899 gid_address_type (&eid) = GID_ADDR_MAC;
4900 clib_memcpy(mac, mp->eid, 6);
4903 rv = VNET_API_ERROR_INVALID_EID_TYPE;
4907 name = format(0, "%s", mp->locator_set_name);
4908 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4910 rv = VNET_API_ERROR_INVALID_VALUE;
4913 locator_set_index = p[0];
4915 /* XXX treat batch configuration */
4916 a->is_add = mp->is_add;
4917 gid_address_vni (&eid) = clib_net_to_host_u32 (mp->vni);
4918 gid_address_copy (&a->eid, &eid);
4919 a->locator_set_index = locator_set_index;
4921 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4925 gid_address_free (&a->eid);
4927 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4931 vl_api_lisp_eid_table_add_del_map_t_handler(
4932 vl_api_lisp_eid_table_add_del_map_t *mp)
4934 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4936 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4937 clib_net_to_host_u32 (mp->vrf), mp->is_add);
4938 REPLY_MACRO(VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)
4942 lisp_gpe_add_del_fwd_entry_set_address(
4943 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4944 ip_address_t *slocator,
4945 ip_address_t *dlocator,
4948 ip_address_t *ip_eid = NULL;
4949 ip_prefix_t *prefp = NULL;
4951 prefp = &gid_address_ippref(eid);
4952 ip_eid = &ip_prefix_addr(prefp);
4954 if (mp->eid_is_ipv6) {
4955 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4956 sizeof(ip_addr_v6(ip_eid)));
4957 ip_addr_version(ip_eid) = IP6;
4959 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4960 sizeof(ip_addr_v4(ip_eid)));
4961 ip_addr_version(ip_eid) = IP4;
4963 ip_prefix_len(prefp) = mp->eid_prefix_len;
4965 if (mp->address_is_ipv6) {
4966 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4967 sizeof(ip_addr_v6(slocator)));
4968 ip_addr_version(slocator) = IP6;
4969 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4970 sizeof(ip_addr_v6(dlocator)));
4971 ip_addr_version(dlocator) = IP6;
4973 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4974 sizeof(ip_addr_v4(slocator)));
4975 ip_addr_version(slocator) = IP4;
4976 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4977 sizeof(ip_addr_v4(dlocator)));
4978 ip_addr_version(dlocator) = IP4;
4983 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
4984 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
4986 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
4988 ip_address_t slocator, dlocator;
4990 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
4992 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
4994 memset (&a, 0, sizeof(a));
4996 a.is_add = mp->is_add;
4998 a.slocator = slocator;
4999 a.dlocator = dlocator;
5000 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
5002 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5006 vl_api_lisp_add_del_map_resolver_t_handler(
5007 vl_api_lisp_add_del_map_resolver_t *mp)
5009 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5011 ip_address_t *ip_addr = NULL;
5012 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
5014 a->is_add = mp->is_add;
5015 ip_addr = &a->address;
5018 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
5019 sizeof(ip_addr_v6(ip_addr)));
5020 ip_addr_version(ip_addr) = IP6;
5022 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
5023 sizeof(ip_addr_v4(ip_addr)));
5024 ip_addr_version(ip_addr) = IP4;
5027 rv = vnet_lisp_add_del_map_resolver (a);
5029 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5033 vl_api_lisp_gpe_enable_disable_t_handler(
5034 vl_api_lisp_gpe_enable_disable_t *mp)
5036 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5038 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
5040 a->is_en = mp->is_en;
5041 vnet_lisp_gpe_enable_disable (a);
5043 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5047 vl_api_lisp_enable_disable_t_handler(
5048 vl_api_lisp_enable_disable_t *mp)
5050 vl_api_lisp_enable_disable_reply_t *rmp;
5053 vnet_lisp_enable_disable (mp->is_en);
5054 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
5058 vl_api_lisp_gpe_add_del_iface_t_handler(
5059 vl_api_lisp_gpe_add_del_iface_t *mp)
5061 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5063 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
5065 a->is_add = mp->is_add;
5066 a->table_id = mp->table_id;
5068 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5070 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5074 vl_api_lisp_pitr_set_locator_set_t_handler(
5075 vl_api_lisp_pitr_set_locator_set_t *mp)
5077 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5081 ls_name = format (0, "%s", mp->ls_name);
5082 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5085 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5089 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5090 (vl_api_lisp_add_del_map_request_itr_rlocs_t *mp)
5092 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5094 u8 * locator_set_name = NULL;
5095 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, * a = &_a;
5097 locator_set_name = format (0, "%s", mp->locator_set_name);
5099 a->is_add = mp->is_add;
5100 a->locator_set_name = locator_set_name;
5102 rv = vnet_lisp_add_del_mreq_itr_rlocs(a);
5104 vec_free(locator_set_name);
5106 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5109 /** Used for transferring locators via VPP API */
5110 typedef CLIB_PACKED(struct
5112 u8 is_ip4; /**< is locator an IPv4 address */
5113 u8 priority; /**< locator priority */
5114 u8 weight; /**< locator weight */
5115 u8 addr[16]; /**< IPv4/IPv6 address */
5119 send_lisp_locator_set_details_set_address
5120 (vl_api_lisp_locator_set_details_t *rmp,
5121 gid_address_t *gid_address)
5123 ip_prefix_t *ip_addr;
5125 if (gid_address_type(gid_address) != GID_ADDR_IP_PREFIX) {
5129 ip_addr = &gid_address_ippref(gid_address);
5130 rmp->prefix_len = ip_prefix_len(ip_addr);
5131 rmp->is_ipv6 = ip_prefix_version(ip_addr);
5132 ip_address_copy_addr(rmp->ip_address, &ip_prefix_addr(ip_addr));
5136 vl_api_lisp_add_del_remote_mapping_t_handler (
5137 vl_api_lisp_add_del_remote_mapping_t *mp)
5140 locator_t rloc, * rlocs = 0;
5141 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
5143 gid_address_t _seid, * seid = &_seid;
5144 gid_address_t _deid, * deid = &_deid;
5145 ip_prefix_t * seid_pref = &gid_address_ippref(seid);
5146 ip_prefix_t * deid_pref = &gid_address_ippref(deid);
5148 /* TODO remove seid from API */
5149 memset (seid, 0, sizeof (seid[0]));
5150 memset (deid, 0, sizeof (deid[0]));
5151 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5152 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5153 ip_prefix_len(seid_pref) = mp->seid_len;
5154 ip_prefix_len(deid_pref) = mp->deid_len;
5155 u8 * seid_mac = gid_address_mac (seid);
5156 u8 * deid_mac = gid_address_mac (deid);
5157 gid_address_vni (seid) = ntohl (mp->vni);
5158 gid_address_vni (deid) = ntohl (mp->vni);
5160 switch (mp->eid_type)
5163 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
5164 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
5165 ip_address_set (seid_addr, mp->seid, IP4);
5166 ip_address_set (deid_addr, mp->deid, IP4);
5169 gid_address_type(seid) = GID_ADDR_IP_PREFIX;
5170 gid_address_type(deid) = GID_ADDR_IP_PREFIX;
5171 ip_address_set (seid_addr, mp->seid, IP6);
5172 ip_address_set (deid_addr, mp->deid, IP6);
5174 case 2: /* l2 mac */
5175 gid_address_type(seid) = GID_ADDR_MAC;
5176 gid_address_type(deid) = GID_ADDR_MAC;
5177 clib_memcpy (seid_mac, mp->seid, 6);
5178 clib_memcpy (deid_mac, mp->deid, 6);
5181 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5185 for (i = 0; i < mp->rloc_num; i++) {
5186 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
5187 memset(&rloc, 0, sizeof(rloc));
5188 ip_address_set(&gid_address_ip(&rloc.address), &r->addr,
5189 r->is_ip4 ? IP4 : IP6);
5190 gid_address_ippref_len(&rloc.address) = r->is_ip4 ? 32: 128;
5191 gid_address_type(&rloc.address) = GID_ADDR_IP_PREFIX;
5192 rloc.priority = r->priority;
5193 rloc.weight = r->weight;
5194 vec_add1 (rlocs, rloc);
5198 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5199 gid_address_copy(&a->deid, deid);
5201 rv = vnet_lisp_add_del_adjacency (a);
5203 /* NOTE: for now this works as a static remote mapping, i.e.,
5204 * not authoritative and ttl infinite. */
5205 rv = vnet_lisp_add_del_mapping (deid, rlocs, mp->action, 0, ~0,
5208 /* TODO remove once CSIT switched to lisp_add_del_adjacency */
5209 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5210 gid_address_copy(&a->seid, seid);
5211 gid_address_copy(&a->deid, deid);
5213 vnet_lisp_add_del_adjacency (a);
5217 vnet_lisp_clear_all_remote_adjacencies ();
5221 REPLY_MACRO(VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5225 vl_api_lisp_add_del_adjacency_t_handler (
5226 vl_api_lisp_add_del_adjacency_t *mp)
5228 vl_api_lisp_add_del_adjacency_reply_t * rmp;
5229 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5232 memset(a, 0, sizeof(a[0]));
5234 ip_prefix_t * seid_pref = &gid_address_ippref(&a->seid);
5235 ip_prefix_t * deid_pref = &gid_address_ippref(&a->deid);
5237 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5238 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5239 ip_prefix_len(seid_pref) = mp->seid_len;
5240 ip_prefix_len(deid_pref) = mp->deid_len;
5241 u8 * seid_mac = gid_address_mac (&a->seid);
5242 u8 * deid_mac = gid_address_mac (&a->deid);
5243 gid_address_vni(&a->seid) = ntohl (mp->vni);
5244 gid_address_vni(&a->deid) = ntohl (mp->vni);
5246 switch (mp->eid_type)
5249 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5250 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5251 ip_address_set (seid_addr, mp->seid, IP4);
5252 ip_address_set (deid_addr, mp->deid, IP4);
5255 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5256 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5257 ip_address_set (seid_addr, mp->seid, IP6);
5258 ip_address_set (deid_addr, mp->deid, IP6);
5260 case 2: /* l2 mac */
5261 gid_address_type(&a->seid) = GID_ADDR_MAC;
5262 gid_address_type(&a->deid) = GID_ADDR_MAC;
5263 clib_memcpy (seid_mac, mp->seid, 6);
5264 clib_memcpy (deid_mac, mp->deid, 6);
5267 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5271 a->is_add = mp->is_add;
5272 rv = vnet_lisp_add_del_adjacency (a);
5275 REPLY_MACRO(VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5279 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
5280 locator_set_t *lsit,
5281 unix_shared_memory_queue_t *q,
5285 vl_api_lisp_locator_set_details_t *rmp;
5286 locator_t *loc = NULL;
5290 vec_foreach (locit, lsit->locator_indices) {
5291 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5292 rmp = vl_msg_api_alloc (sizeof (*rmp));
5293 memset (rmp, 0, sizeof (*rmp));
5294 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
5295 rmp->local = lsit->local;
5297 ASSERT(lsit->name != NULL);
5298 strncpy((char *) rmp->locator_set_name,
5299 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5300 rmp->sw_if_index = htonl(loc->sw_if_index);
5302 str = format(0, "remote-%d", index);
5303 strncpy((char *) rmp->locator_set_name, (char *) str,
5304 ARRAY_LEN(rmp->locator_set_name) - 1);
5305 send_lisp_locator_set_details_set_address(rmp, &loc->address);
5309 rmp->priority = loc->priority;
5310 rmp->weight = loc->weight;
5311 rmp->context = context;
5313 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5318 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
5320 unix_shared_memory_queue_t * q = NULL;
5321 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5322 locator_set_t * lsit = NULL;
5325 q = vl_api_client_index_to_input_queue (mp->client_index);
5331 pool_foreach (lsit, lcm->locator_set_pool,
5333 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5338 send_lisp_local_eid_table_details (mapping_t *mapit,
5339 unix_shared_memory_queue_t *q,
5342 vl_api_lisp_local_eid_table_details_t *rmp = NULL;
5343 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5344 locator_set_t *ls = NULL;
5345 gid_address_t *gid = NULL;
5347 ip_prefix_t *ip_prefix = NULL;
5350 ls = pool_elt_at_index (lcm->locator_set_pool,
5351 mapit->locator_set_index);
5353 ip_prefix = &gid_address_ippref(gid);
5354 mac = gid_address_mac(gid);
5356 rmp = vl_msg_api_alloc (sizeof (*rmp));
5357 memset (rmp, 0, sizeof (*rmp));
5358 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCAL_EID_TABLE_DETAILS);
5360 ASSERT(ls->name != NULL);
5361 strncpy((char *) rmp->locator_set_name,
5362 (char *) ls->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5364 str = format(0, "remote-%d", mapit->locator_set_index);
5365 strncpy((char *) rmp->locator_set_name, (char *) str,
5366 ARRAY_LEN(rmp->locator_set_name) - 1);
5370 switch (gid_address_type (gid))
5372 case GID_ADDR_IP_PREFIX:
5373 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5374 if (ip_prefix_version(ip_prefix) == IP4)
5376 rmp->eid_type = 0; /* ipv4 type */
5377 clib_memcpy(rmp->eid, &ip_prefix_v4(ip_prefix),
5378 sizeof(ip_prefix_v4(ip_prefix)));
5382 rmp->eid_type = 1; /* ipv6 type */
5383 clib_memcpy(rmp->eid, &ip_prefix_v6(ip_prefix),
5384 sizeof(ip_prefix_v6(ip_prefix)));
5388 rmp->eid_type = 2; /* l2 mac type */
5389 clib_memcpy(rmp->eid, mac, 6);
5394 rmp->context = context;
5395 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5396 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5400 vl_api_lisp_local_eid_table_dump_t_handler (
5401 vl_api_lisp_local_eid_table_dump_t *mp)
5404 unix_shared_memory_queue_t * q = NULL;
5405 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5406 mapping_t * mapit = NULL;
5407 gid_address_t _eid, * eid = &_eid;
5409 q = vl_api_client_index_to_input_queue (mp->client_index);
5415 memset (eid, 0, sizeof (*eid));
5416 gid_address_vni(eid) = ntohl(mp->vni);
5417 switch (mp->eid_type) {
5419 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5420 gid_address_ippref_len(eid) = mp->prefix_length;
5421 gid_address_ip_version(eid) = IP4;
5422 clib_memcpy (&gid_address_ippref(eid), mp->eid, 4);
5425 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5426 gid_address_ippref_len(eid) = mp->prefix_length;
5427 gid_address_ip_version(eid) = IP6;
5428 clib_memcpy (&gid_address_ippref(eid), mp->eid, 16);
5431 gid_address_type(eid) = GID_ADDR_MAC;
5432 clib_memcpy (gid_address_mac(eid), mp->eid, 6);
5435 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5439 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5440 send_lisp_local_eid_table_details(mapit, q, mp->context);
5442 pool_foreach (mapit, lcm->mapping_pool,
5444 send_lisp_local_eid_table_details(mapit, q, mp->context);
5450 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5451 unix_shared_memory_queue_t *q,
5454 vl_api_lisp_gpe_tunnel_details_t *rmp;
5455 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5457 rmp = vl_msg_api_alloc (sizeof (*rmp));
5458 memset (rmp, 0, sizeof (*rmp));
5459 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5461 rmp->tunnels = tunnel - lgm->tunnels;
5463 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5464 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5465 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5467 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5468 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5469 rmp->dcap_next = htonl(tunnel->decap_next_index);
5470 rmp->lisp_ver = tunnel->ver_res;
5471 rmp->next_protocol = tunnel->next_protocol;
5472 rmp->flags = tunnel->flags;
5473 rmp->ver_res = tunnel->ver_res;
5474 rmp->res = tunnel->res;
5475 rmp->iid = htonl(tunnel->vni);
5476 rmp->context = context;
5478 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5482 vl_api_lisp_gpe_tunnel_dump_t_handler (
5483 vl_api_lisp_gpe_tunnel_dump_t *mp)
5485 unix_shared_memory_queue_t * q = NULL;
5486 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5487 lisp_gpe_tunnel_t * tunnel = NULL;
5489 if (pool_elts(lgm->tunnels) == 0) {
5493 q = vl_api_client_index_to_input_queue (mp->client_index);
5498 pool_foreach(tunnel, lgm->tunnels,
5500 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5505 send_lisp_map_resolver_details (ip_address_t *ip,
5506 unix_shared_memory_queue_t *q,
5509 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5511 rmp = vl_msg_api_alloc (sizeof (*rmp));
5512 memset (rmp, 0, sizeof (*rmp));
5513 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5515 switch (ip_addr_version(ip)) {
5518 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5523 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5529 rmp->context = context;
5531 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5535 vl_api_lisp_map_resolver_dump_t_handler (
5536 vl_api_lisp_map_resolver_dump_t *mp)
5538 unix_shared_memory_queue_t * q = NULL;
5539 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5540 ip_address_t *ip = NULL;
5542 q = vl_api_client_index_to_input_queue (mp->client_index);
5547 vec_foreach(ip, lcm->map_resolvers) {
5548 send_lisp_map_resolver_details(ip, q, mp->context);
5554 send_eid_table_map_pair (hash_pair_t * p,
5555 unix_shared_memory_queue_t * q,
5558 vl_api_lisp_eid_table_map_details_t * rmp = NULL;
5560 rmp = vl_msg_api_alloc (sizeof (*rmp));
5561 memset (rmp, 0, sizeof (*rmp));
5562 rmp->_vl_msg_id = ntohs(VL_API_LISP_EID_TABLE_MAP_DETAILS);
5564 rmp->vni = clib_host_to_net_u32 (p->key);
5565 rmp->vrf = clib_host_to_net_u32 (p->value[0]);
5566 rmp->context = context;
5567 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5571 vl_api_lisp_eid_table_map_dump_t_handler (
5572 vl_api_lisp_eid_table_map_dump_t *mp)
5574 unix_shared_memory_queue_t * q = NULL;
5575 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5578 q = vl_api_client_index_to_input_queue (mp->client_index);
5582 hash_foreach_pair (p, lcm->table_id_by_vni, {
5583 send_eid_table_map_pair (p, q, mp->context);
5588 send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
5591 vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
5593 rmp = vl_msg_api_alloc (sizeof (*rmp));
5594 memset (rmp, 0, sizeof (*rmp));
5595 rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
5597 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5598 rmp->feature_status = vnet_lisp_enable_disable_status ();
5599 rmp->context = context;
5601 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5605 vl_api_lisp_enable_disable_status_dump_t_handler
5606 (vl_api_lisp_enable_disable_status_dump_t *mp)
5608 unix_shared_memory_queue_t * q = NULL;
5610 q = vl_api_client_index_to_input_queue (mp->client_index);
5615 send_lisp_enable_disable_details(q, mp->context);
5619 vl_api_lisp_get_map_request_itr_rlocs_t_handler (
5620 vl_api_lisp_get_map_request_itr_rlocs_t *mp)
5622 unix_shared_memory_queue_t * q = NULL;
5623 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5624 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5625 locator_set_t * loc_set = 0;
5629 q = vl_api_client_index_to_input_queue (mp->client_index);
5634 if (~0 == lcm->mreq_itr_rlocs) {
5635 tmp_str = format(0, " ");
5637 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5638 tmp_str = format(0, "%s", loc_set->name);
5641 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5643 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5644 ARRAY_LEN(rmp->locator_set_name) - 1);
5651 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5653 unix_shared_memory_queue_t * q = NULL;
5654 vl_api_show_lisp_pitr_reply_t * rmp = NULL;
5655 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5657 locator_set_t * ls = 0;
5661 q = vl_api_client_index_to_input_queue (mp->client_index);
5666 if (~0 == lcm->pitr_map_index) {
5667 tmp_str = format(0, "N/A");
5669 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5670 if (~0 != m->locator_set_index) {
5671 ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5672 tmp_str = format(0, "%s", ls->name);
5674 tmp_str = format(0, "N/A");
5677 vec_add1(tmp_str, 0);
5679 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5681 rmp->status = lcm->lisp_pitr;
5682 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5683 ARRAY_LEN(rmp->locator_set_name) - 1);
5688 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5690 vl_api_interface_name_renumber_reply_t * rmp;
5693 VALIDATE_SW_IF_INDEX(mp);
5695 rv = vnet_interface_name_renumber
5696 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5698 BAD_SW_IF_INDEX_LABEL;
5700 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5703 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5704 u32 sw_if_index, u32 address)
5706 vpe_api_main_t * am = &vpe_api_main;
5707 vlib_main_t * vm = am->vlib_main;
5708 vl_api_ip4_arp_event_t * event;
5709 static f64 arp_event_last_time;
5710 f64 now = vlib_time_now (vm);
5712 if (pool_is_free_index (am->arp_events, pool_index))
5715 event = pool_elt_at_index (am->arp_events, pool_index);
5716 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5717 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5718 } else { /* same mac */
5719 if ((sw_if_index == event->sw_if_index) &&
5721 /* for BD case, also check IP address with 10 sec timeout */
5722 ((address == event->address) &&
5723 ((now - arp_event_last_time) < 10.0))))
5727 arp_event_last_time = now;
5728 event->sw_if_index = sw_if_index;
5729 if (address) event->address = address;
5733 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5735 vpe_api_main_t * am = &vpe_api_main;
5737 if (pool_is_free_index (am->arp_events, pool_index))
5740 pool_put_index (am->arp_events, pool_index);
5745 vl_api_want_ip4_arp_events_t_handler
5746 (vl_api_want_ip4_arp_events_t * mp)
5748 vpe_api_main_t * am = &vpe_api_main;
5749 vnet_main_t * vnm = vnet_get_main();
5750 vl_api_want_ip4_arp_events_reply_t *rmp;
5751 vl_api_ip4_arp_event_t * event;
5754 if (mp->enable_disable) {
5755 pool_get (am->arp_events, event);
5756 memset (event, 0, sizeof (*event));
5758 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5759 event->client_index = mp->client_index;
5760 event->context = mp->context;
5761 event->address = mp->address;
5762 event->pid = mp->pid;
5764 rv = vnet_add_del_ip4_arp_change_event
5765 (vnm, arp_change_data_callback,
5767 &mp->address /* addr, in net byte order */,
5768 vpe_resolver_process_node.index,
5769 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5771 rv = vnet_add_del_ip4_arp_change_event
5772 (vnm, arp_change_delete_callback,
5774 &mp->address /* addr, in net byte order */,
5775 vpe_resolver_process_node.index,
5776 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5778 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5781 static void vl_api_input_acl_set_interface_t_handler
5782 (vl_api_input_acl_set_interface_t * mp)
5784 vlib_main_t *vm = vlib_get_main();
5785 vl_api_input_acl_set_interface_reply_t * rmp;
5787 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5789 ip4_table_index = ntohl(mp->ip4_table_index);
5790 ip6_table_index = ntohl(mp->ip6_table_index);
5791 l2_table_index = ntohl(mp->l2_table_index);
5792 sw_if_index = ntohl(mp->sw_if_index);
5794 VALIDATE_SW_IF_INDEX(mp);
5796 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5797 ip6_table_index, l2_table_index,
5800 BAD_SW_IF_INDEX_LABEL;
5802 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5805 static void vl_api_ipsec_spd_add_del_t_handler
5806 (vl_api_ipsec_spd_add_del_t * mp)
5809 clib_warning ("unimplemented");
5812 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5813 vl_api_ipsec_spd_add_del_reply_t * rmp;
5817 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5819 rv = VNET_API_ERROR_UNIMPLEMENTED;
5822 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5826 static void vl_api_ipsec_interface_add_del_spd_t_handler
5827 (vl_api_ipsec_interface_add_del_spd_t * mp)
5829 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5830 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5832 u32 sw_if_index __attribute__((unused));
5833 u32 spd_id __attribute__((unused));
5835 sw_if_index = ntohl(mp->sw_if_index);
5836 spd_id = ntohl(mp->spd_id);
5838 VALIDATE_SW_IF_INDEX(mp);
5841 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5843 rv = VNET_API_ERROR_UNIMPLEMENTED;
5846 BAD_SW_IF_INDEX_LABEL;
5848 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5851 static void vl_api_ipsec_spd_add_del_entry_t_handler
5852 (vl_api_ipsec_spd_add_del_entry_t * mp)
5854 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5855 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5861 memset(&p, 0, sizeof(p));
5863 p.id = ntohl(mp->spd_id);
5864 p.priority = ntohl(mp->priority);
5865 p.is_outbound = mp->is_outbound;
5866 p.is_ipv6 = mp->is_ipv6;
5868 if (mp->is_ipv6 || mp->is_ip_any) {
5869 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5870 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5871 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5872 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5874 clib_memcpy(&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5875 clib_memcpy(&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5876 clib_memcpy(&p.laddr.start.ip4.data, mp->local_address_start, 4);
5877 clib_memcpy(&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5879 p.protocol = mp->protocol;
5880 p.rport.start = ntohs(mp->remote_port_start);
5881 p.rport.stop = ntohs(mp->remote_port_stop);
5882 p.lport.start = ntohs(mp->local_port_start);
5883 p.lport.stop = ntohs(mp->local_port_stop);
5884 /* policy action resolve unsupported */
5885 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5886 clib_warning("unsupported action: 'resolve'");
5887 rv = VNET_API_ERROR_UNIMPLEMENTED;
5890 p.policy = mp->policy;
5891 p.sa_id = ntohl(mp->sa_id);
5893 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5897 if (mp->is_ip_any) {
5899 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5902 rv = VNET_API_ERROR_UNIMPLEMENTED;
5907 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5910 static void vl_api_ipsec_sad_add_del_entry_t_handler
5911 (vl_api_ipsec_sad_add_del_entry_t * mp)
5913 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5914 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5919 memset(&sa, 0, sizeof(sa));
5921 sa.id = ntohl(mp->sad_id);
5922 sa.spi = ntohl(mp->spi);
5923 /* security protocol AH unsupported */
5924 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5925 clib_warning("unsupported security protocol 'AH'");
5926 rv = VNET_API_ERROR_UNIMPLEMENTED;
5929 sa.protocol = mp->protocol;
5930 /* check for unsupported crypto-alg */
5931 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5932 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5933 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5934 mp->crypto_algorithm);
5935 rv = VNET_API_ERROR_UNIMPLEMENTED;
5938 sa.crypto_alg = mp->crypto_algorithm;
5939 sa.crypto_key_len = mp->crypto_key_length;
5940 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5941 /* check for unsupported integ-alg */
5942 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5943 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5944 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5945 mp->integrity_algorithm);
5946 rv = VNET_API_ERROR_UNIMPLEMENTED;
5949 sa.integ_alg = mp->integrity_algorithm;
5950 sa.integ_key_len = mp->integrity_key_length;
5951 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
5952 sa.use_esn = mp->use_extended_sequence_number;
5953 sa.is_tunnel = mp->is_tunnel;
5954 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
5955 if (sa.is_tunnel_ip6) {
5956 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
5957 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
5959 clib_memcpy(&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
5960 clib_memcpy(&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
5963 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
5965 rv = VNET_API_ERROR_UNIMPLEMENTED;
5970 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
5974 vl_api_ikev2_profile_add_del_t_handler
5975 (vl_api_ikev2_profile_add_del_t * mp)
5977 vl_api_ikev2_profile_add_del_reply_t * rmp;
5981 vlib_main_t * vm = vlib_get_main();
5982 clib_error_t * error;
5983 u8 * tmp = format(0, "%s", mp->name);
5984 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
5987 rv = VNET_API_ERROR_UNSPECIFIED;
5989 rv = VNET_API_ERROR_UNIMPLEMENTED;
5992 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
5996 vl_api_ikev2_profile_set_auth_t_handler
5997 (vl_api_ikev2_profile_set_auth_t * mp)
5999 vl_api_ikev2_profile_set_auth_reply_t * rmp;
6003 vlib_main_t * vm = vlib_get_main();
6004 clib_error_t * error;
6005 u8 * tmp = format(0, "%s", mp->name);
6006 u8 * data = vec_new (u8, mp->data_len);
6007 clib_memcpy(data, mp->data, mp->data_len);
6008 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
6012 rv = VNET_API_ERROR_UNSPECIFIED;
6014 rv = VNET_API_ERROR_UNIMPLEMENTED;
6017 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6021 vl_api_ikev2_profile_set_id_t_handler
6022 (vl_api_ikev2_profile_set_id_t * mp)
6024 vl_api_ikev2_profile_add_del_reply_t * rmp;
6028 vlib_main_t * vm = vlib_get_main();
6029 clib_error_t * error;
6030 u8 * tmp = format(0, "%s", mp->name);
6031 u8 * data = vec_new (u8, mp->data_len);
6032 clib_memcpy(data, mp->data, mp->data_len);
6033 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
6037 rv = VNET_API_ERROR_UNSPECIFIED;
6039 rv = VNET_API_ERROR_UNIMPLEMENTED;
6042 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6046 vl_api_ikev2_profile_set_ts_t_handler
6047 (vl_api_ikev2_profile_set_ts_t * mp)
6049 vl_api_ikev2_profile_set_ts_reply_t * rmp;
6053 vlib_main_t * vm = vlib_get_main();
6054 clib_error_t * error;
6055 u8 * tmp = format(0, "%s", mp->name);
6056 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
6057 mp->end_port, (ip4_address_t) mp->start_addr,
6058 (ip4_address_t) mp->end_addr, mp->is_local);
6061 rv = VNET_API_ERROR_UNSPECIFIED;
6063 rv = VNET_API_ERROR_UNIMPLEMENTED;
6066 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6070 vl_api_ikev2_set_local_key_t_handler
6071 (vl_api_ikev2_set_local_key_t * mp)
6073 vl_api_ikev2_profile_set_ts_reply_t * rmp;
6077 vlib_main_t * vm = vlib_get_main();
6078 clib_error_t * error;
6080 error = ikev2_set_local_key(vm, mp->key_file);
6082 rv = VNET_API_ERROR_UNSPECIFIED;
6084 rv = VNET_API_ERROR_UNIMPLEMENTED;
6087 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6091 vl_api_map_add_domain_t_handler
6092 (vl_api_map_add_domain_t * mp)
6094 vl_api_map_add_domain_reply_t * rmp;
6097 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6098 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
6099 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
6100 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
6101 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
6103 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6105 rmp->index = ntohl(index);
6110 vl_api_map_del_domain_t_handler
6111 (vl_api_map_del_domain_t * mp)
6113 vl_api_map_del_domain_reply_t * rmp;
6116 rv = map_delete_domain(ntohl(mp->index));
6118 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
6122 vl_api_map_add_del_rule_t_handler
6123 (vl_api_map_add_del_rule_t * mp)
6125 vl_api_map_del_domain_reply_t * rmp;
6128 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
6130 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
6134 vl_api_map_domain_dump_t_handler
6135 (vl_api_map_domain_dump_t * mp)
6137 vl_api_map_domain_details_t * rmp;
6138 map_main_t *mm = &map_main;
6140 unix_shared_memory_queue_t * q;
6142 if (pool_elts (mm->domains) == 0)
6145 q = vl_api_client_index_to_input_queue (mp->client_index);
6150 pool_foreach(d, mm->domains, ({
6151 /* Make sure every field is initiated (or don't skip the memset()) */
6152 rmp = vl_msg_api_alloc (sizeof (*rmp));
6153 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6154 rmp->domain_index = htonl(d - mm->domains);
6155 rmp->ea_bits_len = d->ea_bits_len;
6156 rmp->psid_offset = d->psid_offset;
6157 rmp->psid_length = d->psid_length;
6158 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6159 rmp->ip4_prefix_len = d->ip4_prefix_len;
6160 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6161 rmp->ip6_prefix_len = d->ip6_prefix_len;
6162 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6163 rmp->ip6_src_len = d->ip6_src_len;
6164 rmp->mtu = htons(d->mtu);
6165 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6166 rmp->context = mp->context;
6168 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6173 vl_api_map_rule_dump_t_handler
6174 (vl_api_map_rule_dump_t * mp)
6176 unix_shared_memory_queue_t * q;
6179 vl_api_map_rule_details_t * rmp;
6180 map_main_t *mm = &map_main;
6181 u32 domain_index = ntohl(mp->domain_index);
6184 if (pool_elts (mm->domains) == 0)
6187 d = pool_elt_at_index(mm->domains, domain_index);
6188 if (!d || !d->rules) {
6192 q = vl_api_client_index_to_input_queue (mp->client_index);
6197 for (i = 0; i < (0x1 << d->psid_length); i++) {
6199 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
6202 rmp = vl_msg_api_alloc(sizeof(*rmp));
6203 memset(rmp, 0, sizeof(*rmp));
6204 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
6205 rmp->psid = htons(i);
6206 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
6207 rmp->context = mp->context;
6208 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6213 vl_api_map_summary_stats_t_handler (
6214 vl_api_map_summary_stats_t *mp)
6216 vl_api_map_summary_stats_reply_t *rmp;
6217 vlib_combined_counter_main_t *cm;
6220 u64 total_pkts[VLIB_N_RX_TX];
6221 u64 total_bytes[VLIB_N_RX_TX];
6222 map_main_t *mm = &map_main;
6223 unix_shared_memory_queue_t *q =
6224 vl_api_client_index_to_input_queue(mp->client_index);
6229 rmp = vl_msg_api_alloc (sizeof (*rmp));
6230 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
6231 rmp->context = mp->context;
6234 memset (total_pkts, 0, sizeof (total_pkts));
6235 memset (total_bytes, 0, sizeof (total_bytes));
6237 map_domain_counter_lock (mm);
6238 vec_foreach(cm, mm->domain_counters) {
6239 which = cm - mm->domain_counters;
6241 for (i = 0; i < vec_len(cm->maxi); i++) {
6242 vlib_get_combined_counter (cm, i, &v);
6243 total_pkts[which] += v.packets;
6244 total_bytes[which] += v.bytes;
6248 map_domain_counter_unlock (mm);
6250 /* Note: in network byte order! */
6251 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
6252 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
6253 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
6254 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
6255 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
6256 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6257 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));
6258 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));
6260 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6263 static void vl_api_ipsec_sa_set_key_t_handler
6264 (vl_api_ipsec_sa_set_key_t * mp)
6266 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
6267 vl_api_ipsec_sa_set_key_reply_t *rmp;
6271 sa.id = ntohl(mp->sa_id);
6272 sa.crypto_key_len = mp->crypto_key_length;
6273 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
6274 sa.integ_key_len = mp->integrity_key_length;
6275 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
6277 rv = ipsec_set_sa_key(vm, &sa);
6279 rv = VNET_API_ERROR_UNIMPLEMENTED;
6282 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
6285 static void vl_api_cop_interface_enable_disable_t_handler
6286 (vl_api_cop_interface_enable_disable_t * mp)
6288 vl_api_cop_interface_enable_disable_reply_t * rmp;
6290 u32 sw_if_index = ntohl(mp->sw_if_index);
6293 VALIDATE_SW_IF_INDEX(mp);
6295 enable_disable = (int) mp->enable_disable;
6297 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6299 BAD_SW_IF_INDEX_LABEL;
6301 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6304 static void vl_api_cop_whitelist_enable_disable_t_handler
6305 (vl_api_cop_whitelist_enable_disable_t * mp)
6307 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
6308 cop_whitelist_enable_disable_args_t _a, *a=&_a;
6309 u32 sw_if_index = ntohl(mp->sw_if_index);
6312 VALIDATE_SW_IF_INDEX(mp);
6314 a->sw_if_index = sw_if_index;
6317 a->default_cop = mp->default_cop;
6318 a->fib_id = ntohl(mp->fib_id);
6320 rv = cop_whitelist_enable_disable (a);
6322 BAD_SW_IF_INDEX_LABEL;
6324 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6327 static void vl_api_get_node_graph_t_handler
6328 (vl_api_get_node_graph_t * mp)
6332 api_main_t * am = &api_main;
6333 vlib_main_t * vm = vlib_get_main();
6335 vl_api_get_node_graph_reply_t * rmp;
6337 pthread_mutex_lock (&am->vlib_rp->mutex);
6338 oldheap = svm_push_data_heap (am->vlib_rp);
6341 * Keep the number of memcpy ops to a minimum (e.g. 1).
6343 vec_validate (vector, 16384);
6344 vec_reset_length (vector);
6347 vector = vlib_node_serialize (&vm->node_main, vector,
6348 (u32)~0 /* all threads */,
6349 1 /* include nexts */,
6350 1 /* include stats */);
6352 svm_pop_heap (oldheap);
6353 pthread_mutex_unlock (&am->vlib_rp->mutex);
6355 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6356 rmp->reply_in_shmem = (uword) vector);
6359 static void vl_api_trace_profile_add_t_handler
6360 (vl_api_trace_profile_add_t *mp)
6363 vl_api_trace_profile_add_reply_t * rmp;
6364 clib_error_t *error;
6366 /* Ignoring the profile id as currently a single profile
6368 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
6369 ntohl(mp->node_id), ntohl(mp->trace_app_data),
6370 mp->pow_enable, mp->trace_tsp,
6373 clib_error_report(error);
6374 rv = clib_error_get_code(error);
6377 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
6380 static void vl_api_trace_profile_apply_t_handler
6381 (vl_api_trace_profile_apply_t *mp)
6384 vl_api_trace_profile_apply_reply_t * rmp;
6386 if (mp->enable != 0) {
6387 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
6388 ntohl(mp->prefix_length),
6390 mp->trace_op == IOAM_HBYH_ADD,
6391 mp->trace_op == IOAM_HBYH_POP,
6392 mp->trace_op == IOAM_HBYH_MOD);
6394 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6396 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
6399 static void vl_api_trace_profile_del_t_handler
6400 (vl_api_trace_profile_del_t *mp)
6403 vl_api_trace_profile_del_reply_t * rmp;
6404 clib_error_t *error;
6406 error = clear_ioam_rewrite_fn();
6408 clib_error_report(error);
6409 rv = clib_error_get_code(error);
6412 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
6416 vl_api_af_packet_create_t_handler
6417 (vl_api_af_packet_create_t *mp)
6419 vlib_main_t *vm = vlib_get_main();
6420 vl_api_af_packet_create_reply_t *rmp;
6422 u8 *host_if_name = NULL;
6425 host_if_name = format(0, "%s", mp->host_if_name);
6426 vec_add1 (host_if_name, 0);
6428 rv = af_packet_create_if(vm, host_if_name,
6429 mp->use_random_hw_addr ? 0 : mp->hw_addr, &sw_if_index);
6431 vec_free(host_if_name);
6433 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6434 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index));
6438 vl_api_af_packet_delete_t_handler
6439 (vl_api_af_packet_delete_t *mp)
6441 vlib_main_t * vm = vlib_get_main();
6442 vl_api_af_packet_delete_reply_t *rmp;
6444 u8 *host_if_name = NULL;
6446 host_if_name = format(0, "%s", mp->host_if_name);
6447 vec_add1 (host_if_name, 0);
6449 rv = af_packet_delete_if(vm, host_if_name);
6451 vec_free(host_if_name);
6453 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
6457 vl_api_policer_add_del_t_handler
6458 (vl_api_policer_add_del_t *mp)
6460 vlib_main_t * vm = vlib_get_main();
6461 vl_api_policer_add_del_reply_t *rmp;
6464 sse2_qos_pol_cfg_params_st cfg;
6465 clib_error_t * error;
6468 name = format(0, "%s", mp->name);
6470 memset (&cfg, 0, sizeof (cfg));
6472 cfg.rnd_type = mp->round_type;
6473 cfg.rate_type = mp->rate_type;
6474 cfg.rb.kbps.cir_kbps = mp->cir;
6475 cfg.rb.kbps.eir_kbps = mp->eir;
6476 cfg.rb.kbps.cb_bytes = mp->cb;
6477 cfg.rb.kbps.eb_bytes = mp->eb;
6478 cfg.conform_action.action_type = mp->conform_action_type;
6479 cfg.conform_action.dscp = mp->conform_dscp;
6480 cfg.exceed_action.action_type = mp->exceed_action_type;
6481 cfg.exceed_action.dscp = mp->exceed_dscp;
6482 cfg.violate_action.action_type = mp->violate_action_type;
6483 cfg.violate_action.dscp = mp->violate_dscp;
6484 cfg.color_aware = mp->color_aware;
6486 error = policer_add_del(vm, name, &cfg, &policer_index, mp->is_add);
6489 rv = VNET_API_ERROR_UNSPECIFIED;
6491 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6493 if (rv == 0 && mp->is_add)
6494 rmp->policer_index = ntohl(policer_index);
6496 rmp->policer_index = ~0;
6501 send_policer_details (u8 *name,
6502 sse2_qos_pol_cfg_params_st *config,
6503 policer_read_response_type_st *templ,
6504 unix_shared_memory_queue_t *q,
6507 vl_api_policer_details_t * mp;
6509 mp = vl_msg_api_alloc (sizeof (*mp));
6510 memset (mp, 0, sizeof (*mp));
6511 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6512 mp->context = context;
6513 mp->cir = htonl(config->rb.kbps.cir_kbps);
6514 mp->eir = htonl(config->rb.kbps.eir_kbps);
6515 mp->cb = htonl(config->rb.kbps.cb_bytes);
6516 mp->eb = htonl(config->rb.kbps.eb_bytes);
6517 mp->rate_type = config->rate_type;
6518 mp->round_type = config->rnd_type;
6519 mp->type = config->rfc;
6520 mp->conform_action_type = config->conform_action.action_type;
6521 mp->conform_dscp = config->conform_action.dscp;
6522 mp->exceed_action_type = config->exceed_action.action_type;
6523 mp->exceed_dscp = config->exceed_action.dscp;
6524 mp->violate_action_type = config->violate_action.action_type;
6525 mp->violate_dscp = config->violate_action.dscp;
6526 mp->single_rate = templ->single_rate ? 1 : 0;
6527 mp->color_aware = templ->color_aware ? 1 : 0;
6528 mp->scale = htonl(templ->scale);
6529 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6530 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6531 mp->current_limit = htonl(templ->current_limit);
6532 mp->current_bucket = htonl(templ->current_bucket);
6533 mp->extended_limit = htonl(templ->extended_limit);
6534 mp->extended_bucket = htonl(templ->extended_bucket);
6535 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6537 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6539 vl_msg_api_send_shmem (q, (u8 *)&mp);
6543 vl_api_policer_dump_t_handler
6544 (vl_api_policer_dump_t *mp)
6546 unix_shared_memory_queue_t * q;
6547 vnet_policer_main_t * pm = &vnet_policer_main;
6551 u8 * match_name = 0;
6553 sse2_qos_pol_cfg_params_st *config;
6554 policer_read_response_type_st *templ;
6556 q = vl_api_client_index_to_input_queue (mp->client_index);
6560 if (mp->match_name_valid) {
6561 match_name = format(0, "%s%c", mp->match_name, 0);
6564 if (mp->match_name_valid) {
6565 p = hash_get_mem (pm->policer_config_by_name, match_name);
6568 config = pool_elt_at_index (pm->configs, pool_index);
6569 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6570 send_policer_details(match_name, config, templ, q, mp->context);
6573 hash_foreach_pair (hp, pm->policer_config_by_name,
6575 name = (u8 *) hp->key;
6576 pool_index = hp->value[0];
6577 config = pool_elt_at_index (pm->configs, pool_index);
6578 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6579 send_policer_details(name, config, templ, q, mp->context);
6585 vl_api_policer_classify_set_interface_t_handler
6586 (vl_api_policer_classify_set_interface_t * mp)
6588 vlib_main_t *vm = vlib_get_main();
6589 vl_api_policer_classify_set_interface_reply_t * rmp;
6591 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6593 ip4_table_index = ntohl(mp->ip4_table_index);
6594 ip6_table_index = ntohl(mp->ip6_table_index);
6595 l2_table_index = ntohl(mp->l2_table_index);
6596 sw_if_index = ntohl(mp->sw_if_index);
6598 VALIDATE_SW_IF_INDEX(mp);
6600 rv = vnet_set_policer_classify_intfc(vm, sw_if_index, ip4_table_index,
6601 ip6_table_index, l2_table_index,
6604 BAD_SW_IF_INDEX_LABEL;
6606 REPLY_MACRO(VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
6610 send_policer_classify_details (u32 sw_if_index,
6612 unix_shared_memory_queue_t *q,
6615 vl_api_policer_classify_details_t * mp;
6617 mp = vl_msg_api_alloc (sizeof (*mp));
6618 memset (mp, 0, sizeof (*mp));
6619 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
6620 mp->context = context;
6621 mp->sw_if_index= htonl(sw_if_index);
6622 mp->table_index= htonl(table_index);
6624 vl_msg_api_send_shmem (q, (u8 *)&mp);
6628 vl_api_policer_classify_dump_t_handler
6629 (vl_api_policer_classify_dump_t *mp)
6631 unix_shared_memory_queue_t * q;
6632 policer_classify_main_t * pcm = &policer_classify_main;
6636 q = vl_api_client_index_to_input_queue (mp->client_index);
6640 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6642 if (vec_len(vec_tbl)) {
6643 for (i = 0; i < vec_len (vec_tbl); i++) {
6644 if (vec_elt(vec_tbl, i) == ~0)
6647 send_policer_classify_details(i, vec_elt(vec_tbl, i), q,
6654 vl_api_netmap_create_t_handler
6655 (vl_api_netmap_create_t *mp)
6657 vlib_main_t *vm = vlib_get_main();
6658 vl_api_netmap_create_reply_t *rmp;
6662 if_name = format(0, "%s", mp->netmap_if_name);
6663 vec_add1 (if_name, 0);
6665 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6666 mp->is_pipe, mp->is_master, 0);
6670 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6674 vl_api_netmap_delete_t_handler
6675 (vl_api_netmap_delete_t *mp)
6677 vlib_main_t * vm = vlib_get_main();
6678 vl_api_netmap_delete_reply_t *rmp;
6682 if_name = format(0, "%s", mp->netmap_if_name);
6683 vec_add1 (if_name, 0);
6685 rv = netmap_delete_if(vm, if_name);
6689 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6692 static void vl_api_mpls_gre_tunnel_details_t_handler (
6693 vl_api_mpls_gre_tunnel_details_t * mp)
6695 clib_warning ("BUG");
6698 static void send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
6699 unix_shared_memory_queue_t *q,
6700 mpls_gre_tunnel_t * gt,
6704 vl_api_mpls_gre_tunnel_details_t * mp;
6706 mp = vl_msg_api_alloc (sizeof (*mp));
6707 memset (mp, 0, sizeof (*mp));
6708 mp->_vl_msg_id = ntohs(VL_API_MPLS_GRE_TUNNEL_DETAILS);
6709 mp->context = context;
6712 mp->tunnel_index = htonl(index);
6713 mp->tunnel_src = gt->tunnel_src.as_u32;
6714 mp->tunnel_dst = gt->tunnel_dst.as_u32;
6715 mp->intfc_address = gt->intfc_address.as_u32;
6716 mp->mask_width = htonl(gt->mask_width);
6717 mp->inner_fib_index = htonl(gt->inner_fib_index);
6718 mp->outer_fib_index = htonl(gt->outer_fib_index);
6719 mp->encap_index = htonl(gt->encap_index);
6720 mp->hw_if_index = htonl(gt->hw_if_index);
6721 mp->l2_only = htonl(gt->l2_only);
6724 mpls_main_t * mm = &mpls_main;
6729 e = pool_elt_at_index (mm->encaps, gt->encap_index);
6730 len = vec_len (e->labels);
6731 mp->nlabels = htonl(len);
6733 for (i = 0; i < len; i++) {
6734 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6735 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6738 vl_msg_api_send_shmem (q, (u8 *)&mp);
6742 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t *mp)
6744 vpe_api_main_t * am = &vpe_api_main;
6745 unix_shared_memory_queue_t * q;
6746 vlib_main_t * vm = &vlib_global_main;
6747 mpls_main_t * mm = &mpls_main;
6748 mpls_gre_tunnel_t * gt;
6749 u32 index = ntohl(mp->tunnel_index);
6751 q = vl_api_client_index_to_input_queue (mp->client_index);
6755 if (pool_elts (mm->gre_tunnels)) {
6756 if(mp->tunnel_index >= 0) {
6757 vlib_cli_output (vm, "MPLS-GRE tunnel %u", index);
6758 gt = pool_elt_at_index (mm->gre_tunnels, index);
6759 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6761 vlib_cli_output (vm, "MPLS-GRE tunnels");
6762 pool_foreach (gt, mm->gre_tunnels,
6764 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6768 vlib_cli_output (vm, "No MPLS-GRE tunnels");
6772 static void vl_api_mpls_eth_tunnel_details_t_handler (
6773 vl_api_mpls_eth_tunnel_details_t * mp)
6775 clib_warning ("BUG");
6778 static void send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
6779 unix_shared_memory_queue_t *q,
6780 mpls_eth_tunnel_t * et,
6784 vl_api_mpls_eth_tunnel_details_t * mp;
6786 mp = vl_msg_api_alloc (sizeof (*mp));
6787 memset (mp, 0, sizeof (*mp));
6788 mp->_vl_msg_id = ntohs(VL_API_MPLS_ETH_TUNNEL_DETAILS);
6789 mp->context = context;
6792 mp->tunnel_index = htonl(index);
6793 memcpy(mp->tunnel_dst_mac, et->tunnel_dst, 6);
6794 mp->intfc_address = et->intfc_address.as_u32;
6795 mp->tx_sw_if_index = htonl(et->tx_sw_if_index);
6796 mp->inner_fib_index = htonl(et->inner_fib_index);
6797 mp->mask_width = htonl(et->mask_width);
6798 mp->encap_index = htonl(et->encap_index);
6799 mp->hw_if_index = htonl(et->hw_if_index);
6800 mp->l2_only = htonl(et->l2_only);
6803 mpls_main_t * mm = &mpls_main;
6808 e = pool_elt_at_index (mm->encaps, et->encap_index);
6809 len = vec_len (e->labels);
6810 mp->nlabels = htonl(len);
6812 for (i = 0; i < len; i++) {
6813 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6814 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6817 vl_msg_api_send_shmem (q, (u8 *)&mp);
6821 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t *mp)
6823 vpe_api_main_t * am = &vpe_api_main;
6824 unix_shared_memory_queue_t * q;
6825 vlib_main_t * vm = &vlib_global_main;
6826 mpls_main_t * mm = &mpls_main;
6827 mpls_eth_tunnel_t * et;
6828 u32 index = ntohl(mp->tunnel_index);
6830 q = vl_api_client_index_to_input_queue (mp->client_index);
6834 clib_warning("Received mpls_eth_tunnel_dump");
6835 clib_warning("Received tunnel index: %u from client %u", index, mp->client_index);
6837 if (pool_elts (mm->eth_tunnels)) {
6838 if(mp->tunnel_index >= 0) {
6839 vlib_cli_output (vm, "MPLS-Ethernet tunnel %u", index);
6840 et = pool_elt_at_index (mm->eth_tunnels, index);
6841 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6843 clib_warning("MPLS-Ethernet tunnels");
6844 pool_foreach (et, mm->eth_tunnels,
6846 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6850 clib_warning("No MPLS-Ethernet tunnels");
6854 static void vl_api_mpls_fib_encap_details_t_handler (
6855 vl_api_mpls_fib_encap_details_t * mp)
6857 clib_warning ("BUG");
6860 static void send_mpls_fib_encap_details (vpe_api_main_t * am,
6861 unix_shared_memory_queue_t *q,
6865 vl_api_mpls_fib_encap_details_t * mp;
6867 mp = vl_msg_api_alloc (sizeof (*mp));
6868 memset (mp, 0, sizeof (*mp));
6869 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_ENCAP_DETAILS);
6870 mp->context = context;
6872 mp->fib_index = htonl(s->fib_index);
6873 mp->entry_index = htonl(s->entry_index);
6875 mp->s_bit = htonl(s->s_bit);
6877 mpls_main_t * mm = &mpls_main;
6882 e = pool_elt_at_index (mm->encaps, s->entry_index);
6883 len = vec_len (e->labels);
6884 mp->nlabels = htonl(len);
6886 for (i = 0; i < len; i++) {
6887 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6888 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6891 vl_msg_api_send_shmem (q, (u8 *)&mp);
6895 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t *mp)
6897 vpe_api_main_t * am = &vpe_api_main;
6898 unix_shared_memory_queue_t * q;
6899 vlib_main_t * vm = &vlib_global_main;
6902 show_mpls_fib_t *records = 0;
6904 mpls_main_t * mm = &mpls_main;
6905 ip4_main_t * im = &ip4_main;
6908 q = vl_api_client_index_to_input_queue (mp->client_index);
6912 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
6914 vec_add2 (records, s, 1);
6915 s->fib_index = (u32)(key>>32);
6916 s->dest = (u32)(key & 0xFFFFFFFF);
6917 s->entry_index = (u32) value;
6920 if (0 == vec_len(records)) {
6921 vlib_cli_output(vm, "MPLS encap table empty");
6925 /* sort output by dst address within fib */
6926 vec_sort_with_function(records, mpls_dest_cmp);
6927 vec_sort_with_function(records, mpls_fib_index_cmp);
6928 vlib_cli_output(vm, "MPLS encap table");
6929 vlib_cli_output(vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
6930 vec_foreach (s, records)
6932 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
6933 vlib_cli_output(vm, "%=6d%=16U%=16U", rx_fib->table_id,
6934 format_ip4_address, &s->dest, format_mpls_encap_index, mm,
6936 send_mpls_fib_encap_details (am, q, s, mp->context);
6943 static void vl_api_mpls_fib_decap_details_t_handler (
6944 vl_api_mpls_fib_decap_details_t * mp)
6946 clib_warning ("BUG");
6949 static void send_mpls_fib_decap_details (vpe_api_main_t * am,
6950 unix_shared_memory_queue_t *q,
6957 vl_api_mpls_fib_decap_details_t * mp;
6959 mp = vl_msg_api_alloc (sizeof (*mp));
6960 memset (mp, 0, sizeof (*mp));
6961 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_DECAP_DETAILS);
6962 mp->context = context;
6964 mp->fib_index = htonl(s->fib_index);
6965 mp->entry_index = htonl(s->entry_index);
6967 mp->s_bit = htonl(s->s_bit);
6968 mp->label = htonl(s->label);
6969 mp->rx_table_id = htonl(rx_table_id);
6970 mp->tx_table_id = htonl(tx_table_id);
6971 strncpy ((char *) mp->swif_tag,
6972 (char *) swif_tag, ARRAY_LEN(mp->swif_tag)-1);
6974 vl_msg_api_send_shmem (q, (u8 *)&mp);
6978 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t *mp)
6980 vpe_api_main_t * am = &vpe_api_main;
6981 unix_shared_memory_queue_t * q;
6982 vlib_main_t * vm = &vlib_global_main;
6985 show_mpls_fib_t *records = 0;
6987 mpls_main_t * mm = &mpls_main;
6988 ip4_main_t * im = &ip4_main;
6994 q = vl_api_client_index_to_input_queue (mp->client_index);
6998 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7000 vec_add2 (records, s, 1);
7001 s->fib_index = (u32)(key>>32);
7002 s->entry_index = (u32) value;
7003 s->label = ((u32) key)>>12;
7004 s->s_bit = (key & (1<<8)) != 0;
7007 if (!vec_len(records)) {
7008 vlib_cli_output(vm, "MPLS decap table empty");
7012 vec_sort_with_function(records, mpls_label_cmp);
7013 vlib_cli_output(vm, "MPLS decap table");
7014 vlib_cli_output(vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7016 vec_foreach (s, records)
7019 d = pool_elt_at_index(mm->decaps, s->entry_index);
7020 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT) {
7021 tx_fib = vec_elt_at_index(im->fibs, d->tx_fib_index);
7022 tx_table_id = tx_fib->table_id;
7025 tx_table_id = d->tx_fib_index;
7028 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
7030 vlib_cli_output(vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7031 tx_table_id, swif_tag, s->label, s->s_bit);
7033 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7034 tx_table_id, swif_tag, mp->context);
7041 static void vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t *mp)
7043 unix_shared_memory_queue_t * q;
7045 q = vl_api_client_index_to_input_queue (mp->client_index);
7049 vnet_classify_main_t * cm = &vnet_classify_main;
7050 vnet_classify_table_t * t;
7051 u32 * table_ids = 0;
7054 pool_foreach (t, cm->tables,
7056 vec_add1 (table_ids, ntohl(t - cm->tables));
7058 count = vec_len(table_ids);
7060 vl_api_classify_table_ids_reply_t *rmp;
7061 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + count * sizeof(u32));
7062 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7063 rmp->context = mp->context;
7064 rmp->count = ntohl(count);
7065 clib_memcpy(rmp->ids, table_ids, count * sizeof(u32));
7068 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7070 vec_free (table_ids);
7073 static void vl_api_classify_table_by_interface_t_handler (vl_api_classify_table_by_interface_t *mp)
7075 vl_api_classify_table_by_interface_reply_t *rmp;
7078 u32 sw_if_index = ntohl(mp->sw_if_index);
7081 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7084 VALIDATE_SW_IF_INDEX(mp);
7086 input_acl_main_t * am = &input_acl_main;
7091 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7093 u32 * vec_tbl = am->classify_table_index_by_sw_if_index[type];
7094 if (vec_len(vec_tbl)) {
7095 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7097 if (vec_elt(vec_tbl, if_idx) == ~0 || sw_if_index != if_idx) {
7100 acl[type] = vec_elt(vec_tbl, if_idx);
7105 BAD_SW_IF_INDEX_LABEL;
7107 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7109 rmp->sw_if_index = ntohl(sw_if_index);
7110 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7111 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7112 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7117 static void vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t *mp)
7119 unix_shared_memory_queue_t * q;
7121 q = vl_api_client_index_to_input_queue (mp->client_index);
7125 vl_api_classify_table_info_reply_t *rmp = 0;
7127 vnet_classify_main_t * cm = &vnet_classify_main;
7128 u32 table_id = ntohl(mp->table_id);
7129 vnet_classify_table_t * t;
7131 pool_foreach (t, cm->tables,
7133 if (table_id == t - cm->tables) {
7134 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7135 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7136 rmp->context = mp->context;
7137 rmp->table_id = ntohl(table_id);
7138 rmp->nbuckets = ntohl(t->nbuckets);
7139 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7140 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7141 rmp->active_sessions = ntohl(t->active_elements);
7142 rmp->next_table_index = ntohl(t->next_table_index);
7143 rmp->miss_next_index = ntohl(t->miss_next_index);
7144 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7145 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7152 rmp = vl_msg_api_alloc (sizeof (*rmp));
7153 rmp->_vl_msg_id = ntohs((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7154 rmp->context = mp->context;
7155 rmp->retval = ntohl(VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7158 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7161 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
7163 clib_warning ("BUG");
7166 static void send_classify_session_details (unix_shared_memory_queue_t * q,
7169 vnet_classify_entry_t * e,
7172 vl_api_classify_session_details_t *rmp;
7174 rmp = vl_msg_api_alloc (sizeof (*rmp));
7175 memset (rmp, 0, sizeof (*rmp));
7176 rmp->_vl_msg_id = ntohs(VL_API_CLASSIFY_SESSION_DETAILS);
7177 rmp->context = context;
7178 rmp->table_id = ntohl(table_id);
7179 rmp->hit_next_index = ntohl(e->next_index);
7180 rmp->advance = ntohl(e->advance);
7181 rmp->opaque_index = ntohl(e->opaque_index);
7182 rmp->match_length = ntohl(match_length);
7183 clib_memcpy(rmp->match, e->key, match_length);
7185 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7188 static void vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t *mp)
7190 vnet_classify_main_t * cm = &vnet_classify_main;
7191 unix_shared_memory_queue_t * q;
7193 u32 table_id = ntohl(mp->table_id);
7194 vnet_classify_table_t * t;
7196 q = vl_api_client_index_to_input_queue (mp->client_index);
7198 pool_foreach (t, cm->tables,
7200 if (table_id == t - cm->tables) {
7201 vnet_classify_bucket_t * b;
7202 vnet_classify_entry_t * v, * save_v;
7205 for (i = 0; i < t->nbuckets; i++)
7207 b = &t->buckets [i];
7211 save_v = vnet_classify_get_entry (t, b->offset);
7212 for (j = 0; j < (1<<b->log2_pages); j++)
7214 for (k = 0; k < t->entries_per_page; k++)
7216 v = vnet_classify_entry_at_index (t, save_v, j*t->entries_per_page + k);
7217 if (vnet_classify_entry_is_free (v))
7220 send_classify_session_details(q, table_id,
7221 t->match_n_vectors * sizeof (u32x4), v, mp->context);
7230 static void vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t *mp)
7232 vlib_main_t *vm = vlib_get_main();
7233 flow_report_main_t * frm = &flow_report_main;
7234 vl_api_ipfix_enable_reply_t *rmp;
7235 ip4_address_t collector, src;
7236 u16 collector_port = UDP_DST_PORT_ipfix;
7238 u32 template_interval;
7243 memcpy(collector.data, mp->collector_address, sizeof(collector.data));
7244 collector_port = ntohs(mp->collector_port);
7245 if (collector_port == (u16)~0)
7246 collector_port = UDP_DST_PORT_ipfix;
7247 memcpy(src.data, mp->src_address, sizeof(src.data));
7248 fib_id = ntohl(mp->vrf_id);
7250 ip4_main_t * im = &ip4_main;
7251 uword * p = hash_get (im->fib_index_by_table_id, fib_id);
7253 rv = VNET_API_ERROR_NO_SUCH_FIB;
7258 path_mtu = ntohl(mp->path_mtu);
7260 path_mtu = 512; // RFC 7011 section 10.3.3.
7261 template_interval = ntohl(mp->template_interval);
7262 if (template_interval == ~0)
7263 template_interval = 20;
7265 if (collector.as_u32 == 0) {
7266 rv = VNET_API_ERROR_INVALID_VALUE;
7270 if (src.as_u32 == 0) {
7271 rv = VNET_API_ERROR_INVALID_VALUE;
7275 if (path_mtu > 1450 /* vpp does not support fragmentation */) {
7276 rv = VNET_API_ERROR_INVALID_VALUE;
7280 if (path_mtu < 68) {
7281 rv = VNET_API_ERROR_INVALID_VALUE;
7285 /* Reset report streams if we are reconfiguring IP addresses */
7286 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7287 frm->src_address.as_u32 != src.as_u32 ||
7288 frm->collector_port != collector_port)
7289 vnet_flow_reports_reset(frm);
7291 frm->ipfix_collector.as_u32 = collector.as_u32;
7292 frm->collector_port = collector_port;
7293 frm->src_address.as_u32 = src.as_u32;
7294 frm->fib_index = fib_index;
7295 frm->path_mtu = path_mtu;
7296 frm->template_interval = template_interval;
7298 /* Turn on the flow reporting process */
7299 vlib_process_signal_event (vm, flow_report_process_node.index,
7303 REPLY_MACRO(VL_API_IPFIX_ENABLE_REPLY);
7306 static void vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t *mp)
7308 flow_report_main_t * frm = &flow_report_main;
7309 unix_shared_memory_queue_t * q;
7310 vl_api_ipfix_details_t *rmp;
7312 q = vl_api_client_index_to_input_queue (mp->client_index);
7314 rmp = vl_msg_api_alloc (sizeof (*rmp));
7315 memset (rmp, 0, sizeof (*rmp));
7316 rmp->_vl_msg_id = ntohs(VL_API_IPFIX_DETAILS);
7317 rmp->context = mp->context;
7318 memcpy(rmp->collector_address, frm->ipfix_collector.data,
7319 sizeof(frm->ipfix_collector.data));
7320 rmp->collector_port = htons(frm->collector_port);
7321 memcpy(rmp->src_address, frm->src_address.data,
7322 sizeof(frm->src_address.data));
7323 rmp->fib_index = htonl(frm->fib_index);
7324 rmp->path_mtu = htonl(frm->path_mtu);
7325 rmp->template_interval = htonl(frm->template_interval);
7327 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7330 static void vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t *mp)
7332 vl_api_pg_create_interface_reply_t *rmp;
7335 pg_main_t * pg = &pg_main;
7336 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl(mp->interface_id));
7338 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7340 rmp->sw_if_index = ntohl(sw_if_index);
7344 static void vl_api_pg_capture_t_handler (vl_api_pg_capture_t *mp)
7346 vl_api_pg_capture_reply_t *rmp;
7349 vnet_main_t * vnm = vnet_get_main();
7350 vnet_interface_main_t * im = &vnm->interface_main;
7351 vnet_hw_interface_t * hi = 0;
7353 u8 * intf_name = format (0, "pg%d", ntohl(mp->interface_id), 0);
7354 u32 hw_if_index = ~0;
7355 uword * p = hash_get_mem (im->hw_interface_by_name, intf_name);
7358 vec_free (intf_name);
7360 if (hw_if_index != ~0) {
7361 pg_capture_args_t _a, *a=&_a;
7363 u32 len = ntohl(mp->pcap_name_length);
7364 u8 * pcap_file_name = vec_new(u8, len);
7365 clib_memcpy(pcap_file_name, mp->pcap_file_name, len);
7367 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7368 a->hw_if_index = hw_if_index;
7369 a->dev_instance = hi->dev_instance;
7370 a->is_enabled = mp->is_enabled;
7371 a->pcap_file_name = pcap_file_name;
7372 a->count = ntohl(mp->count);
7374 clib_error_t * e = pg_capture (a);
7376 clib_error_report(e);
7377 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7380 vec_free (pcap_file_name);
7382 REPLY_MACRO(VL_API_PG_CAPTURE_REPLY);
7385 static void vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t *mp)
7387 vl_api_pg_enable_disable_reply_t *rmp;
7390 pg_main_t * pg = &pg_main;
7391 u32 stream_index = ~0;
7393 int is_enable = mp->is_enabled != 0;
7394 u32 len = ntohl(mp->stream_name_length)-1;
7397 u8 * stream_name = vec_new(u8, len);
7398 clib_memcpy(stream_name, mp->stream_name, len);
7399 uword * p = hash_get_mem (pg->stream_index_by_name, stream_name);
7402 vec_free(stream_name);
7405 pg_enable_disable (stream_index, is_enable);
7407 REPLY_MACRO(VL_API_PG_ENABLE_DISABLE_REPLY);
7410 #define BOUNCE_HANDLER(nn) \
7411 static void vl_api_##nn##_t_handler ( \
7412 vl_api_##nn##_t *mp) \
7414 vpe_client_registration_t *reg; \
7415 vpe_api_main_t * vam = &vpe_api_main; \
7416 unix_shared_memory_queue_t * q; \
7418 /* One registration only... */ \
7419 pool_foreach(reg, vam->nn##_registrations, \
7421 q = vl_api_client_index_to_input_queue (reg->client_index); \
7424 * If the queue is stuffed, turf the msg and complain \
7425 * It's unlikely that the intended recipient is \
7426 * alive; avoid deadlock at all costs. \
7428 if (q->cursize == q->maxsize) { \
7429 clib_warning ("ERROR: receiver queue full, drop msg"); \
7430 vl_msg_api_free (mp); \
7433 vl_msg_api_send_shmem (q, (u8 *)&mp); \
7437 vl_msg_api_free (mp); \
7442 * Add vpe's API message handlers to the table.
7443 * vlib has alread mapped shared memory and
7444 * added the client registration handlers.
7445 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
7448 static clib_error_t *
7449 vpe_api_hookup (vlib_main_t *vm)
7451 api_main_t * am = &api_main;
7454 vl_msg_api_set_handlers(VL_API_##N, #n, \
7455 vl_api_##n##_t_handler, \
7457 vl_api_##n##_t_endian, \
7458 vl_api_##n##_t_print, \
7459 sizeof(vl_api_##n##_t), 1);
7460 foreach_vpe_api_msg;
7464 * Manually register the sr tunnel add del msg, so we trace
7465 * enough bytes to capture a typical segment list
7467 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
7468 "sr_tunnel_add_del",
7469 vl_api_sr_tunnel_add_del_t_handler,
7471 vl_api_sr_tunnel_add_del_t_endian,
7472 vl_api_sr_tunnel_add_del_t_print,
7477 * Manually register the sr policy add del msg, so we trace
7478 * enough bytes to capture a typical tunnel name list
7480 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
7481 "sr_policy_add_del",
7482 vl_api_sr_policy_add_del_t_handler,
7484 vl_api_sr_policy_add_del_t_endian,
7485 vl_api_sr_policy_add_del_t_print,
7489 * Trace space for 8 MPLS encap labels, classifier mask+match
7491 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
7492 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
7493 += 5 * sizeof (u32x4);
7494 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
7495 += 5 * sizeof (u32x4);
7496 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
7497 += 16 * sizeof (u32);
7500 * Thread-safe API messages
7502 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
7503 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
7508 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
7510 static clib_error_t *
7511 vpe_api_init (vlib_main_t *vm)
7513 vpe_api_main_t *am = &vpe_api_main;
7516 am->vnet_main = vnet_get_main();
7517 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
7518 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7519 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7520 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7521 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7522 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
7525 vl_set_memory_region_name ("/vpe-api");
7526 vl_enable_disable_memory_api (vm, 1 /* enable it */);
7531 VLIB_INIT_FUNCTION(vpe_api_init);
7534 static clib_error_t *
7535 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
7540 struct passwd _pw, *pw;
7541 struct group _grp, *grp;
7544 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7546 if (unformat (input, "prefix %s", &chroot_path))
7548 vec_add1 (chroot_path, 0);
7549 vl_set_memory_root_path ((char *)chroot_path);
7551 else if (unformat (input, "uid %d", &uid))
7552 vl_set_memory_uid (uid);
7553 else if (unformat (input, "gid %d", &gid))
7554 vl_set_memory_gid (gid);
7555 else if (unformat (input, "uid %s", &s))
7557 /* lookup the username */
7559 rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
7562 e = clib_error_return_code(0, rv,
7563 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7564 "cannot fetch username %s", s);
7570 e = clib_error_return_fatal(0, "username %s does not exist", s);
7575 vl_set_memory_uid (pw->pw_uid);
7577 else if (unformat (input, "gid %s", &s))
7579 /* lookup the group name */
7581 rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
7584 e = clib_error_return_code(0, rv,
7585 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7586 "cannot fetch group %s", s);
7592 e = clib_error_return_fatal(0, "group %s does not exist", s);
7597 vl_set_memory_gid (grp->gr_gid);
7600 return clib_error_return (0, "unknown input `%U'",
7601 format_unformat_error, input);
7605 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
7607 void * get_unformat_vnet_sw_interface (void)
7609 return (void *) &unformat_vnet_sw_interface;
7612 #undef vl_api_version
7613 #define vl_api_version(n,v) static u32 vpe_api_version = v;
7614 #include <vpp-api/vpe.api.h>
7615 #undef vl_api_version
7617 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
7619 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
7620 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
7621 clib_host_to_net_u32 (mp->api_versions[0]),
7628 static u8 * format_arp_event (u8 * s, va_list * args)
7630 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
7632 s = format (s, "pid %d: %U", event->pid,
7633 format_ip4_address, &event->address);
7637 static clib_error_t *
7638 show_ip4_arp_events_fn (vlib_main_t * vm,
7639 unformat_input_t * input,
7640 vlib_cli_command_t * cmd)
7642 vpe_api_main_t * am = &vpe_api_main;
7643 vl_api_ip4_arp_event_t * event;
7645 if (pool_elts (am->arp_events) == 0) {
7646 vlib_cli_output (vm, "No active arp event registrations");
7650 pool_foreach (event, am->arp_events,
7652 vlib_cli_output (vm, "%U", format_arp_event, event);
7658 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
7659 .path = "show arp event registrations",
7660 .function = show_ip4_arp_events_fn,
7661 .short_help = "Show arp event registrations",