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 _(NOPRINT_CONTROL_PING, noprint_control_ping) \
269 _(CLI_REQUEST, cli_request) \
270 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
271 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
272 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
273 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
274 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
275 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
276 _(GET_NODE_INDEX, get_node_index) \
277 _(ADD_NODE_NEXT, add_node_next) \
278 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
279 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
280 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
281 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
282 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
283 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
284 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
285 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
286 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
287 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
288 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
289 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
290 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
291 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
292 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
293 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
294 _(IP_ADDRESS_DUMP, ip_address_dump) \
295 _(IP_DUMP, ip_dump) \
296 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
297 _(SHOW_VERSION, show_version) \
298 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
299 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
300 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
301 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
302 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
303 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
304 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
305 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
306 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
307 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
308 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
309 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
310 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
311 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
312 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
313 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
314 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
315 _(DELETE_LOOPBACK, delete_loopback) \
316 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
317 _(MAP_ADD_DOMAIN, map_add_domain) \
318 _(MAP_DEL_DOMAIN, map_del_domain) \
319 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
320 _(MAP_DOMAIN_DUMP, map_domain_dump) \
321 _(MAP_RULE_DUMP, map_rule_dump) \
322 _(MAP_SUMMARY_STATS, map_summary_stats) \
323 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
324 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
325 _(GET_NODE_GRAPH, get_node_graph) \
326 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
327 _(TRACE_PROFILE_ADD, trace_profile_add) \
328 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
329 _(TRACE_PROFILE_DEL, trace_profile_del) \
330 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
331 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
332 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
333 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
334 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
335 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
336 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
337 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
338 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
339 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
340 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
341 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
342 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
343 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
344 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
345 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
346 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
347 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
348 _(SHOW_LISP_STATUS, show_lisp_status) \
349 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
350 lisp_add_del_map_request_itr_rlocs) \
351 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
352 _(SHOW_LISP_PITR, show_lisp_pitr) \
353 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
354 _(AF_PACKET_CREATE, af_packet_create) \
355 _(AF_PACKET_DELETE, af_packet_delete) \
356 _(POLICER_ADD_DEL, policer_add_del) \
357 _(POLICER_DUMP, policer_dump) \
358 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
359 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
360 _(NETMAP_CREATE, netmap_create) \
361 _(NETMAP_DELETE, netmap_delete) \
362 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
363 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
364 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
365 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
366 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
367 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
368 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
369 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
370 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
371 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
372 _(CLASSIFY_TABLE_INFO,classify_table_info) \
373 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
374 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
375 _(IPFIX_ENABLE,ipfix_enable) \
376 _(IPFIX_DUMP,ipfix_dump) \
377 _(GET_NEXT_INDEX, get_next_index) \
378 _(PG_CREATE_INTERFACE, pg_create_interface) \
379 _(PG_CAPTURE, pg_capture) \
380 _(PG_ENABLE_DISABLE, pg_enable_disable)
383 #define QUOTE(x) QUOTE_(x)
385 #define foreach_registration_hash \
386 _(interface_events) \
387 _(to_netconf_server) \
388 _(from_netconf_server) \
389 _(to_netconf_client) \
390 _(from_netconf_client) \
394 RESOLVE_IP4_ADD_DEL_ROUTE=1,
395 RESOLVE_IP6_ADD_DEL_ROUTE,
396 RESOLVE_MPLS_ETHERNET_ADD_DEL,
402 vl_api_ip_add_del_route_t r;
403 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
409 #define _(a) uword *a##_registration_hash; \
410 vpe_client_registration_t * a##_registrations;
411 foreach_registration_hash
414 /* notifications happen really early in the game */
415 u8 link_state_process_up;
417 /* ip4 pending route adds */
418 pending_route_t * pending_routes;
420 /* ip4 arp event registration pool */
421 vl_api_ip4_arp_event_t * arp_events;
424 vlib_main_t * vlib_main;
425 vnet_main_t * vnet_main;
428 static vlib_node_registration_t vpe_resolver_process_node;
429 static vpe_api_main_t vpe_api_main;
431 static void send_sw_interface_flags (vpe_api_main_t * am,
432 unix_shared_memory_queue_t *q,
433 vnet_sw_interface_t * swif);
434 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
435 unix_shared_memory_queue_t *q,
438 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
441 /* Clean up all registrations belonging to the indicated client */
442 int vl_api_memclnt_delete_callback (u32 client_index)
444 vpe_api_main_t * vam = &vpe_api_main;
445 vpe_client_registration_t *rp;
447 int stats_memclnt_delete_callback (u32 client_index);
449 stats_memclnt_delete_callback (client_index);
452 p = hash_get (vam->a##_registration_hash, client_index); \
454 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
455 pool_put (vam->a##_registrations, rp); \
456 hash_unset (vam->a##_registration_hash, client_index); \
458 foreach_registration_hash;
463 #define API_LINK_STATE_EVENT 1
464 #define API_ADMIN_UP_DOWN_EVENT 2
467 event_data_cmp (void * a1, void * a2)
472 return (word) e1[0] - (word) e2[0];
476 link_state_process (vlib_main_t * vm,
477 vlib_node_runtime_t * rt,
480 vpe_api_main_t * vam = &vpe_api_main;
481 vnet_main_t * vnm = vam->vnet_main;
482 vnet_sw_interface_t * swif;
483 uword * event_data = 0;
484 vpe_client_registration_t *reg;
486 u32 prev_sw_if_index;
487 unix_shared_memory_queue_t * q;
489 vam->link_state_process_up = 1;
492 vlib_process_wait_for_event (vm);
494 /* Unified list of changed link or admin state sw_if_indices */
495 vlib_process_get_events_with_type
496 (vm, &event_data, API_LINK_STATE_EVENT);
497 vlib_process_get_events_with_type
498 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
500 /* Sort, so we can eliminate duplicates */
501 vec_sort_with_function (event_data, event_data_cmp);
503 prev_sw_if_index = ~0;
505 for (i = 0; i < vec_len(event_data); i++) {
506 /* Only one message per swif */
507 if (prev_sw_if_index == event_data[i])
509 prev_sw_if_index = event_data[i];
511 pool_foreach(reg, vam->interface_events_registrations,
513 q = vl_api_client_index_to_input_queue (reg->client_index);
515 // sw_interface may be deleted already
516 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
519 swif = vnet_get_sw_interface (vnm, event_data[i]);
520 send_sw_interface_flags (vam, q, swif);
525 vec_reset_length (event_data);
531 static clib_error_t *
532 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
533 static clib_error_t *
534 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
536 VLIB_REGISTER_NODE (link_state_process_node,static) = {
537 .function = link_state_process,
538 .type = VLIB_NODE_TYPE_PROCESS,
539 .name = "vpe-link-state-process",
542 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
543 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
545 static clib_error_t *
546 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
548 vpe_api_main_t * vam = &vpe_api_main;
549 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
551 if (vam->link_state_process_up)
552 vlib_process_signal_event (vam->vlib_main,
553 link_state_process_node.index,
554 API_LINK_STATE_EVENT,
559 static clib_error_t *
560 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
562 vpe_api_main_t * vam = &vpe_api_main;
565 * Note: it's perfectly fair to set a subif admin up / admin down.
566 * Note the subtle distinction between this routine and the previous
569 if (vam->link_state_process_up)
570 vlib_process_signal_event (vam->vlib_main,
571 link_state_process_node.index,
572 API_ADMIN_UP_DOWN_EVENT,
577 #define pub_sub_handler(lca,UCA) \
578 static void vl_api_want_##lca##_t_handler ( \
579 vl_api_want_##lca##_t *mp) \
581 vpe_api_main_t *vam = &vpe_api_main; \
582 vpe_client_registration_t *rp; \
583 vl_api_want_##lca##_reply_t *rmp; \
587 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
589 if (mp->enable_disable) { \
590 clib_warning ("pid %d: already enabled...", mp->pid); \
591 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
594 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
595 pool_put (vam->lca##_registrations, rp); \
596 hash_unset (vam->lca##_registration_hash, \
601 if (mp->enable_disable == 0) { \
602 clib_warning ("pid %d: already disabled...", mp->pid); \
603 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
606 pool_get (vam->lca##_registrations, rp); \
607 rp->client_index = mp->client_index; \
608 rp->client_pid = mp->pid; \
609 hash_set (vam->lca##_registration_hash, rp->client_index, \
610 rp - vam->lca##_registrations); \
613 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
616 pub_sub_handler (interface_events,INTERFACE_EVENTS)
617 pub_sub_handler (oam_events,OAM_EVENTS)
619 #define RESOLUTION_EVENT 1
620 #define RESOLUTION_PENDING_EVENT 2
621 #define IP4_ARP_EVENT 3
623 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
624 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
625 static int mpls_ethernet_add_del_tunnel_2_t_handler
626 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
628 void handle_ip4_arp_event (u32 pool_index)
630 vpe_api_main_t * vam = &vpe_api_main;
631 vnet_main_t * vnm = vam->vnet_main;
632 vlib_main_t * vm = vam->vlib_main;
633 vl_api_ip4_arp_event_t * event;
634 vl_api_ip4_arp_event_t * mp;
635 unix_shared_memory_queue_t * q;
637 /* Client can cancel, die, etc. */
638 if (pool_is_free_index (vam->arp_events, pool_index))
641 event = pool_elt_at_index (vam->arp_events, pool_index);
643 q = vl_api_client_index_to_input_queue (event->client_index);
645 (void) vnet_add_del_ip4_arp_change_event
646 (vnm, arp_change_delete_callback,
647 event->pid, &event->address,
648 vpe_resolver_process_node.index, IP4_ARP_EVENT,
649 ~0 /* pool index, notused */, 0 /* is_add */);
653 if (q->cursize < q->maxsize) {
654 mp = vl_msg_api_alloc (sizeof (*mp));
655 clib_memcpy (mp, event, sizeof (*mp));
656 vl_msg_api_send_shmem (q, (u8 *)&mp);
658 static f64 last_time;
660 * Throttle syslog msgs.
661 * It's pretty tempting to just revoke the registration...
663 if (vlib_time_now (vm) > last_time + 10.0) {
664 clib_warning ("arp event for %U to pid %d: queue stuffed!",
665 format_ip4_address, &event->address, event->pid);
666 last_time = vlib_time_now(vm);
672 resolver_process (vlib_main_t * vm,
673 vlib_node_runtime_t * rt,
677 uword *event_data = 0;
679 vpe_api_main_t * vam = &vpe_api_main;
680 pending_route_t * pr;
681 vl_api_ip_add_del_route_t * adr;
682 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
683 u32 * resolution_failures = 0;
688 vlib_process_wait_for_event_or_clock (vm, timeout);
690 event_type = vlib_process_get_events (vm, &event_data);
692 switch (event_type) {
693 case RESOLUTION_PENDING_EVENT:
697 case RESOLUTION_EVENT:
698 for (i = 0; i < vec_len(event_data); i++) {
700 * Resolution events can occur long after the
701 * original request has timed out. $$$ add a cancel
704 if (pool_is_free_index (vam->pending_routes, event_data[i]))
707 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
711 switch (pr->resolve_type) {
712 case RESOLVE_IP4_ADD_DEL_ROUTE:
713 rv = ip4_add_del_route_t_handler (adr);
714 clib_warning ("resolver: add %U/%d via %U %s",
716 (ip4_address_t *)&(adr->dst_address),
717 adr->dst_address_length,
719 (ip4_address_t *)&(adr->next_hop_address),
720 (rv >= 0) ? "succeeded" : "failed");
723 case RESOLVE_IP6_ADD_DEL_ROUTE:
724 rv = ip6_add_del_route_t_handler (adr);
725 clib_warning ("resolver: add %U/%d via %U %s",
727 (ip6_address_t *)&(adr->dst_address),
728 adr->dst_address_length,
730 (ip6_address_t *)&(adr->next_hop_address),
731 (rv >= 0) ? "succeeded" : "failed");
734 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
735 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
736 clib_warning ("resolver: add mpls-o-e via %U %s",
738 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
739 (rv >= 0) ? "succeeded" : "failed");
743 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
745 pool_put (vam->pending_routes, pr);
750 for (i = 0; i < vec_len(event_data); i++)
751 handle_ip4_arp_event (event_data[i]);
754 case ~0: /* timeout, retry pending resolutions */
755 pool_foreach (pr, vam->pending_routes,
761 /* May fail, e.g. due to interface down */
762 switch (pr->resolve_type) {
763 case RESOLVE_IP4_ADD_DEL_ROUTE:
764 e = ip4_probe_neighbor
765 (vm, (ip4_address_t *)&(adr->next_hop_address),
766 ntohl(adr->next_hop_sw_if_index));
769 case RESOLVE_IP6_ADD_DEL_ROUTE:
770 e = ip6_probe_neighbor
771 (vm, (ip6_address_t *)&(adr->next_hop_address),
772 ntohl(adr->next_hop_sw_if_index));
775 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
777 e = ip4_probe_neighbor
779 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
780 pme->resolve_opaque);
784 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
788 clib_error_report (e);
790 adr->resolve_attempts = 1;
792 pme->resolve_attempts = 1;
796 adr->resolve_attempts -= 1;
797 if (adr->resolve_attempts == 0)
798 vec_add1 (resolution_failures,
799 pr - vam->pending_routes);
801 pme->resolve_attempts -= 1;
802 if (pme->resolve_attempts == 0)
803 vec_add1 (resolution_failures,
804 pr - vam->pending_routes);
808 for (i = 0; i < vec_len (resolution_failures); i++) {
809 pr = pool_elt_at_index (vam->pending_routes,
810 resolution_failures[i]);
814 switch (pr->resolve_type) {
815 case RESOLVE_IP4_ADD_DEL_ROUTE:
816 clib_warning ("resolver: add %U/%d via %U retry failure",
818 (ip4_address_t *)&(adr->dst_address),
819 adr->dst_address_length,
821 (ip4_address_t *)&(adr->next_hop_address));
824 case RESOLVE_IP6_ADD_DEL_ROUTE:
825 clib_warning ("resolver: add %U/%d via %U retry failure",
827 (ip6_address_t *)&(adr->dst_address),
828 adr->dst_address_length,
830 (ip6_address_t *)&(adr->next_hop_address));
833 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
834 clib_warning ("resolver: add mpls-o-e via %U retry failure",
836 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
840 clib_warning ("BUG");
842 pool_put(vam->pending_routes, pr);
844 vec_reset_length (resolution_failures);
847 if (pool_elts (vam->pending_routes) == 0)
849 vec_reset_length (event_data);
851 return 0; /* or not */
854 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
855 .function = resolver_process,
856 .type = VLIB_NODE_TYPE_PROCESS,
857 .name = "vpe-route-resolver-process",
860 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
862 ip4_main_t * im = &ip4_main;
863 ip_lookup_main_t * lm = &im->lookup_main;
864 vnet_classify_main_t * cm = &vnet_classify_main;
865 stats_main_t * sm = &stats_main;
866 ip4_add_del_route_args_t a;
867 ip4_address_t next_hop_address;
869 vpe_api_main_t * vam = &vpe_api_main;
870 vnet_main_t * vnm = vam->vnet_main;
871 vlib_main_t * vm = vlib_get_main();
872 pending_route_t * pr;
873 vl_api_ip_add_del_route_t * adr;
879 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
881 if (mp->create_vrf_if_needed) {
883 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
885 fib_index = f->index;
887 /* No such VRF, and we weren't asked to create one */
888 return VNET_API_ERROR_NO_SUCH_FIB;
894 if (~0 != mp->next_hop_sw_if_index &&
895 pool_is_free_index (vnm->interface_main.sw_interfaces,
896 ntohl(mp->next_hop_sw_if_index)))
897 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
899 clib_memcpy (next_hop_address.data, mp->next_hop_address,
900 sizeof (next_hop_address.data));
902 /* Arp for the next_hop if necessary */
903 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
905 ip_adjacency_t * adj;
907 lookup_result = ip4_fib_lookup_with_table
908 (im, fib_index, &next_hop_address, 1 /* disable default route */);
910 adj = ip_get_adjacency (lm, lookup_result);
912 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
913 pool_get (vam->pending_routes, pr);
914 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
916 clib_memcpy (adr, mp, sizeof (*adr));
917 /* recursion block, "just in case" */
918 adr->resolve_if_needed = 0;
919 adr->resolve_attempts = ntohl(mp->resolve_attempts);
920 vnet_register_ip4_arp_resolution_event
921 (vnm, &next_hop_address, vpe_resolver_process_node.index,
922 RESOLUTION_EVENT, pr - vam->pending_routes);
924 vlib_process_signal_event
925 (vm, vpe_resolver_process_node.index,
926 RESOLUTION_PENDING_EVENT, 0 /* data */);
928 /* The interface may be down, etc. */
929 e = ip4_probe_neighbor
930 (vm, (ip4_address_t *)&(mp->next_hop_address),
931 ntohl(mp->next_hop_sw_if_index));
934 clib_error_report(e);
936 return VNET_API_ERROR_IN_PROGRESS;
940 if (mp->is_multipath) {
943 dslock (sm, 1 /* release hint */, 10 /* tag */);
946 flags = IP4_ROUTE_FLAG_ADD;
948 flags = IP4_ROUTE_FLAG_DEL;
951 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
953 ip4_add_del_route_next_hop (im, flags,
954 (ip4_address_t *) mp->dst_address,
955 (u32) mp->dst_address_length,
956 (ip4_address_t *) mp->next_hop_address,
957 ntohl(mp->next_hop_sw_if_index),
958 (u32) mp->next_hop_weight,
965 memset (&a, 0, sizeof (a));
966 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
968 a.dst_address_length = mp->dst_address_length;
970 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
971 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
972 a.table_index_or_table_id = fib_index;
977 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
979 dslock (sm, 1 /* release hint */, 2 /* tag */);
983 ai = lm->drop_adj_index;
984 else if (mp->is_local)
985 ai = lm->local_adj_index;
986 else if (mp->is_classify) {
987 if (pool_is_free_index (cm->tables, ntohl(mp->classify_table_index))) {
989 return VNET_API_ERROR_NO_SUCH_TABLE;
991 adj = ip_add_adjacency (lm,
996 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
997 adj->classify.table_index = ntohl(mp->classify_table_index);
999 else if (mp->lookup_in_vrf) {
1000 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1002 adj = ip_add_adjacency (lm,
1006 adj->explicit_fib_index = p[0];
1010 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1014 ai = ip4_route_get_next_hop_adj (im,
1017 ntohl(mp->next_hop_sw_if_index),
1020 if (ai == lm->miss_adj_index) {
1022 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1025 ip_adjacency_t * adj;
1026 int disable_default_route = 1;
1028 /* Trying to delete the default route? */
1029 if (a.dst_address.as_u32 == 0 &&
1030 a.dst_address_length == 0)
1031 disable_default_route = 0;
1033 ai = ip4_fib_lookup_with_table
1034 (im, fib_index, &a.dst_address, disable_default_route);
1035 if (ai == lm->miss_adj_index) {
1037 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1040 adj = ip_get_adjacency (lm, ai);
1041 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1043 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1048 ip4_add_del_route (im, &a);
1054 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1056 ip6_main_t * im = &ip6_main;
1057 ip_lookup_main_t * lm = &im->lookup_main;
1058 vnet_main_t * vnm = vnet_get_main();
1059 vlib_main_t * vm = vlib_get_main();
1060 vpe_api_main_t * vam = &vpe_api_main;
1061 stats_main_t * sm = &stats_main;
1062 ip6_add_del_route_args_t a;
1063 ip6_address_t next_hop_address;
1064 pending_route_t * pr;
1065 vl_api_ip_add_del_route_t * adr;
1070 ip_adjacency_t *adj = 0;
1073 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1076 if (mp->create_vrf_if_needed) {
1078 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1080 fib_index = f->index;
1082 /* No such VRF, and we weren't asked to create one */
1083 return VNET_API_ERROR_NO_SUCH_FIB;
1089 if (~0 != mp->next_hop_sw_if_index &&
1090 pool_is_free_index (vnm->interface_main.sw_interfaces,
1091 ntohl(mp->next_hop_sw_if_index)))
1092 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1094 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1095 sizeof (next_hop_address.as_u8));
1097 /* Arp for the next_hop if necessary */
1098 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
1100 ip_adjacency_t * adj;
1102 lookup_result = ip6_fib_lookup_with_table
1103 (im, fib_index, &next_hop_address);
1105 adj = ip_get_adjacency (lm, lookup_result);
1107 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1108 pool_get (vam->pending_routes, pr);
1110 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1111 clib_memcpy (adr, mp, sizeof (*adr));
1112 /* recursion block, "just in case" */
1113 adr->resolve_if_needed = 0;
1114 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1115 vnet_register_ip6_neighbor_resolution_event
1116 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1117 RESOLUTION_EVENT, pr - vam->pending_routes);
1119 vlib_process_signal_event
1120 (vm, vpe_resolver_process_node.index,
1121 RESOLUTION_PENDING_EVENT, 0 /* data */);
1123 /* The interface may be down, etc. */
1124 e = ip6_probe_neighbor
1125 (vm, (ip6_address_t *)&(mp->next_hop_address),
1126 ntohl(mp->next_hop_sw_if_index));
1129 clib_error_report(e);
1131 return VNET_API_ERROR_IN_PROGRESS;
1135 if (mp->is_multipath) {
1138 dslock (sm, 1 /* release hint */, 11 /* tag */);
1141 flags = IP6_ROUTE_FLAG_ADD;
1143 flags = IP6_ROUTE_FLAG_DEL;
1146 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1148 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1149 (u32) mp->dst_address_length,
1150 (ip6_address_t *)mp->next_hop_address,
1151 ntohl(mp->next_hop_sw_if_index),
1152 (u32) mp->next_hop_weight,
1159 memset (&a, 0, sizeof (a));
1160 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1162 a.dst_address_length = mp->dst_address_length;
1164 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1165 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1166 a.table_index_or_table_id = fib_index;
1171 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1173 dslock (sm, 1 /* release hint */, 3 /* tag */);
1177 ai = lm->drop_adj_index;
1178 else if (mp->is_local)
1179 ai = lm->local_adj_index;
1180 else if (mp->lookup_in_vrf) {
1181 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1183 adj = ip_add_adjacency (lm,
1187 adj->explicit_fib_index = p[0];
1191 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1195 ai = ip6_route_get_next_hop_adj (im,
1198 ntohl(mp->next_hop_sw_if_index),
1200 if (ai == lm->miss_adj_index) {
1202 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1205 ip_adjacency_t * adj;
1207 ai = ip6_fib_lookup_with_table
1208 (im, fib_index, &a.dst_address);
1209 if (ai == lm->miss_adj_index) {
1211 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1213 adj = ip_get_adjacency (lm, ai);
1214 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1216 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1221 ip6_add_del_route (im, &a);
1227 void vl_api_ip_add_del_route_t_handler (
1228 vl_api_ip_add_del_route_t *mp)
1230 vl_api_ip_add_del_route_reply_t * rmp;
1232 vnet_main_t * vnm = vnet_get_main();
1237 rv = ip6_add_del_route_t_handler (mp);
1239 rv = ip4_add_del_route_t_handler (mp);
1241 rv = (rv == 0) ? vnm->api_errno : rv;
1243 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1246 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1247 u32 sw_if_index, u8 *next_hop_addr)
1249 vl_api_ip_add_del_route_t mp;
1252 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1255 * Configure default IP route:
1256 * - ip route add 0.0.0.0/1 via <GW IP>
1257 * - ip route add 128.0.0.0/1 via <GW IP>
1259 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1261 mp.resolve_attempts = ~0;
1262 mp.resolve_if_needed = 1;
1264 mp.is_ipv6 = is_ipv6;
1265 mp.next_hop_weight = 1;
1267 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1270 rv = ip6_add_del_route_t_handler (&mp);
1273 mp.dst_address_length = 1;
1275 mp.dst_address[0] = 0;
1276 rv = ip4_add_del_route_t_handler (&mp);
1278 mp.dst_address[0] = 128;
1279 rv |= ip4_add_del_route_t_handler (&mp);
1283 clib_error_return (0, "failed to config default IP route");
1288 vl_api_sw_interface_add_del_address_t_handler
1289 (vl_api_sw_interface_add_del_address_t *mp)
1291 vlib_main_t *vm = vlib_get_main();
1292 vl_api_sw_interface_add_del_address_reply_t * rmp;
1296 VALIDATE_SW_IF_INDEX(mp);
1298 is_del = mp->is_add == 0;
1301 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1302 else if (mp->is_ipv6)
1303 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1304 (void *)mp->address,
1305 mp->address_length, is_del);
1307 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1308 (void *) mp->address,
1309 mp->address_length, is_del);
1311 BAD_SW_IF_INDEX_LABEL;
1313 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1317 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1320 u32 table_id = ntohl(mp->vrf_id);
1321 u32 sw_if_index = ntohl(mp->sw_if_index);
1322 vl_api_sw_interface_set_table_reply_t * rmp;
1323 stats_main_t * sm = &stats_main;
1325 VALIDATE_SW_IF_INDEX(mp);
1327 dslock (sm, 1 /* release hint */, 4 /* tag */);
1330 ip6_main_t * im = &ip6_main;
1332 find_ip6_fib_by_table_index_or_id (im, table_id,
1333 IP6_ROUTE_FLAG_TABLE_ID);
1335 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1336 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1338 rv = VNET_API_ERROR_NO_SUCH_FIB;
1341 ip4_main_t * im = &ip4_main;
1342 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1343 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1345 /* Truthfully this can't fail */
1347 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1348 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1350 rv = VNET_API_ERROR_NO_SUCH_FIB;
1355 BAD_SW_IF_INDEX_LABEL;
1357 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1361 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1363 vlib_main_t *vm = vlib_get_main();
1364 ip4_main_t * im4 = &ip4_main;
1365 ip6_main_t * im6 = &ip6_main;
1366 vl_api_sw_interface_set_vpath_reply_t * rmp;
1369 u32 sw_if_index = ntohl(mp->sw_if_index);
1370 ip4_main_t *ip4m = &ip4_main;
1371 ip6_main_t *ip6m = &ip6_main;
1372 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1373 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1374 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1375 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1376 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1377 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1379 VALIDATE_SW_IF_INDEX(mp);
1381 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1383 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1384 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1386 im4->ip4_unicast_rx_feature_vpath,
1388 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1389 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1390 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1392 im4->ip4_multicast_rx_feature_vpath,
1394 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1395 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1396 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1398 im6->ip6_unicast_rx_feature_vpath,
1400 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1401 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1402 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1404 im6->ip6_multicast_rx_feature_vpath,
1406 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1408 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1409 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1411 im4->ip4_unicast_rx_feature_vpath,
1413 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1414 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1415 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1417 im4->ip4_multicast_rx_feature_vpath,
1419 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1420 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1421 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1423 im6->ip6_unicast_rx_feature_vpath,
1425 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1426 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1427 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1429 im6->ip6_multicast_rx_feature_vpath,
1431 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1434 BAD_SW_IF_INDEX_LABEL;
1436 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1440 vl_api_sw_interface_set_l2_xconnect_t_handler (
1441 vl_api_sw_interface_set_l2_xconnect_t *mp)
1443 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1445 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1446 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1447 vlib_main_t *vm = vlib_get_main();
1448 vnet_main_t *vnm = vnet_get_main();
1450 VALIDATE_RX_SW_IF_INDEX(mp);
1453 VALIDATE_TX_SW_IF_INDEX(mp);
1454 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1455 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1457 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1460 BAD_RX_SW_IF_INDEX_LABEL;
1461 BAD_TX_SW_IF_INDEX_LABEL;
1463 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1467 vl_api_sw_interface_set_l2_bridge_t_handler (
1468 vl_api_sw_interface_set_l2_bridge_t *mp)
1470 bd_main_t * bdm = &bd_main;
1471 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1473 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1474 u32 bd_id = ntohl(mp->bd_id);
1478 vlib_main_t *vm = vlib_get_main();
1479 vnet_main_t *vnm = vnet_get_main();
1481 VALIDATE_RX_SW_IF_INDEX(mp);
1483 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1486 //VALIDATE_TX_SW_IF_INDEX(mp);
1487 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1488 rx_sw_if_index, bd_index, bvi, shg, 0);
1490 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1493 BAD_RX_SW_IF_INDEX_LABEL;
1495 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1499 vl_api_bridge_domain_add_del_t_handler (
1500 vl_api_bridge_domain_add_del_t *mp)
1502 vlib_main_t * vm = vlib_get_main ();
1503 bd_main_t * bdm = &bd_main;
1504 vl_api_bridge_domain_add_del_reply_t * rmp;
1506 u32 enable_flags = 0, disable_flags = 0;
1507 u32 bd_id = ntohl(mp->bd_id);
1511 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1514 enable_flags |= L2_FLOOD;
1516 disable_flags |= L2_FLOOD;
1519 enable_flags |= L2_UU_FLOOD;
1521 disable_flags |= L2_UU_FLOOD;
1524 enable_flags |= L2_FWD;
1526 disable_flags |= L2_FWD;
1529 enable_flags |= L2_ARP_TERM;
1531 disable_flags |= L2_ARP_TERM;
1534 enable_flags |= L2_LEARN;
1536 disable_flags |= L2_LEARN;
1539 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1542 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1545 rv = bd_delete_bd_index(bdm, bd_id);
1547 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1550 static void vl_api_bridge_domain_details_t_handler (
1551 vl_api_bridge_domain_details_t * mp)
1553 clib_warning ("BUG");
1556 static void vl_api_bridge_domain_sw_if_details_t_handler (
1557 vl_api_bridge_domain_sw_if_details_t * mp)
1559 clib_warning ("BUG");
1562 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1563 l2_bridge_domain_t * bd_config,
1567 vl_api_bridge_domain_details_t * mp;
1569 mp = vl_msg_api_alloc (sizeof (*mp));
1570 memset (mp, 0, sizeof (*mp));
1571 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1572 mp->bd_id = ntohl (bd_config->bd_id);
1573 mp->flood = bd_feature_flood (bd_config);
1574 mp->uu_flood = bd_feature_uu_flood (bd_config);
1575 mp->forward = bd_feature_forward (bd_config);
1576 mp->learn = bd_feature_learn (bd_config);
1577 mp->arp_term = bd_feature_arp_term (bd_config);
1578 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1579 mp->n_sw_ifs = ntohl (n_sw_ifs);
1580 mp->context = context;
1582 vl_msg_api_send_shmem (q, (u8 *)&mp);
1585 static void send_bd_sw_if_details (l2input_main_t * l2im,
1586 unix_shared_memory_queue_t *q,
1587 l2_flood_member_t * member, u32 bd_id,
1590 vl_api_bridge_domain_sw_if_details_t * mp;
1591 l2_input_config_t * input_cfg;
1593 mp = vl_msg_api_alloc (sizeof (*mp));
1594 memset (mp, 0, sizeof (*mp));
1595 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1596 mp->bd_id = ntohl (bd_id);
1597 mp->sw_if_index = ntohl (member->sw_if_index);
1598 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1599 mp->shg = input_cfg->shg;
1600 mp->context = context;
1602 vl_msg_api_send_shmem (q, (u8 *)&mp);
1605 static void vl_api_bridge_domain_dump_t_handler (
1606 vl_api_bridge_domain_dump_t *mp)
1608 bd_main_t * bdm = &bd_main;
1609 l2input_main_t * l2im = &l2input_main;
1610 unix_shared_memory_queue_t * q;
1611 l2_bridge_domain_t * bd_config;
1612 u32 bd_id, bd_index;
1615 q = vl_api_client_index_to_input_queue (mp->client_index);
1620 bd_id = ntohl(mp->bd_id);
1622 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1623 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1624 for (; bd_index < end; bd_index++) {
1625 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1626 /* skip dummy bd_id 0 */
1627 if (bd_config && (bd_config->bd_id > 0)) {
1629 l2_flood_member_t * m;
1631 n_sw_ifs = vec_len (bd_config->members);
1632 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1634 vec_foreach (m, bd_config->members) {
1635 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1642 vl_api_l2fib_add_del_t_handler (
1643 vl_api_l2fib_add_del_t *mp)
1645 bd_main_t * bdm = &bd_main;
1646 l2input_main_t * l2im = &l2input_main;
1647 vl_api_l2fib_add_del_reply_t * rmp;
1650 u32 sw_if_index = ntohl(mp->sw_if_index);
1651 u32 bd_id = ntohl(mp->bd_id);
1660 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1662 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1663 goto bad_sw_if_index;
1668 VALIDATE_SW_IF_INDEX(mp);
1669 if (vec_len(l2im->configs) <= sw_if_index) {
1670 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1671 goto bad_sw_if_index;
1673 l2_input_config_t * config;
1674 config = vec_elt_at_index(l2im->configs, sw_if_index);
1675 if (config->bridge == 0) {
1676 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1677 goto bad_sw_if_index;
1680 static_mac = mp->static_mac ? 1 : 0;
1681 filter_mac = mp->filter_mac ? 1 : 0;
1682 bvi_mac = mp->bvi_mac ? 1 : 0;
1683 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1686 l2fib_del_entry(mac, bd_index);
1689 BAD_SW_IF_INDEX_LABEL;
1691 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1695 vl_api_l2_flags_t_handler (
1696 vl_api_l2_flags_t *mp)
1698 vl_api_l2_flags_reply_t * rmp;
1700 u32 sw_if_index = ntohl(mp->sw_if_index);
1701 u32 flags = ntohl(mp->feature_bitmap);
1704 VALIDATE_SW_IF_INDEX(mp);
1707 if (flags & L2INPUT_FEAT_ ## a) \
1708 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1709 foreach_l2input_feat;
1712 BAD_SW_IF_INDEX_LABEL;
1714 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1718 vl_api_bridge_flags_t_handler (
1719 vl_api_bridge_flags_t *mp)
1721 vlib_main_t *vm = vlib_get_main();
1722 bd_main_t * bdm = &bd_main;
1723 vl_api_bridge_flags_reply_t * rmp;
1725 u32 bd_id = ntohl(mp->bd_id);
1727 u32 flags = ntohl(mp->feature_bitmap);
1730 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1732 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1738 bd_set_flags(vm, bd_index, flags, mp->is_set);
1741 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1742 rmp->resulting_feature_bitmap = ntohl(flags));
1746 vl_api_bd_ip_mac_add_del_t_handler (
1747 vl_api_bd_ip_mac_add_del_t *mp)
1749 bd_main_t * bdm = &bd_main;
1750 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1752 u32 bd_id = ntohl(mp->bd_id);
1756 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1758 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1763 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1764 mp->mac_address, mp->is_ipv6, mp->is_add))
1765 rv = VNET_API_ERROR_UNSPECIFIED;
1768 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1772 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1775 vl_api_tap_connect_reply_t * rmp;
1776 unix_shared_memory_queue_t * q;
1777 u32 sw_if_index = (u32)~0;
1779 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1780 mp->use_random_mac ? 0 : mp->mac_address,
1781 &sw_if_index, mp->renumber,
1782 ntohl(mp->custom_dev_instance));
1784 q = vl_api_client_index_to_input_queue (mp->client_index);
1788 rmp = vl_msg_api_alloc (sizeof (*rmp));
1789 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1790 rmp->context = mp->context;
1791 rmp->retval = ntohl(rv);
1792 rmp->sw_if_index = ntohl(sw_if_index);
1794 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1798 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1801 vl_api_tap_modify_reply_t * rmp;
1802 unix_shared_memory_queue_t * q;
1803 u32 sw_if_index = (u32)~0;
1805 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1806 mp->use_random_mac ? 0 : mp->mac_address,
1807 &sw_if_index, mp->renumber,
1808 ntohl(mp->custom_dev_instance));
1810 q = vl_api_client_index_to_input_queue (mp->client_index);
1814 rmp = vl_msg_api_alloc (sizeof (*rmp));
1815 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1816 rmp->context = mp->context;
1817 rmp->retval = ntohl(rv);
1818 rmp->sw_if_index = ntohl(sw_if_index);
1820 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1824 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1827 vpe_api_main_t * vam = &vpe_api_main;
1828 vl_api_tap_delete_reply_t * rmp;
1829 unix_shared_memory_queue_t * q;
1830 u32 sw_if_index = ntohl(mp->sw_if_index);
1832 rv = vnet_tap_delete (vm, sw_if_index);
1834 q = vl_api_client_index_to_input_queue (mp->client_index);
1838 rmp = vl_msg_api_alloc (sizeof (*rmp));
1839 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1840 rmp->context = mp->context;
1841 rmp->retval = ntohl(rv);
1843 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1846 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1850 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1852 vl_api_create_vlan_subif_reply_t * rmp;
1853 vnet_main_t * vnm = vnet_get_main();
1854 u32 hw_if_index, sw_if_index = (u32)~0;
1855 vnet_hw_interface_t * hi;
1858 vnet_sw_interface_t template;
1860 vnet_interface_main_t * im = &vnm->interface_main;
1861 u64 sup_and_sub_key;
1863 unix_shared_memory_queue_t * q;
1864 clib_error_t * error;
1866 VALIDATE_SW_IF_INDEX(mp);
1868 hw_if_index = ntohl(mp->sw_if_index);
1869 hi = vnet_get_hw_interface (vnm, hw_if_index);
1871 id = ntohl(mp->vlan_id);
1872 if (id == 0 || id > 4095) {
1873 rv = VNET_API_ERROR_INVALID_VLAN;
1877 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1879 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1881 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1885 kp = clib_mem_alloc (sizeof (*kp));
1886 *kp = sup_and_sub_key;
1888 memset (&template, 0, sizeof (template));
1889 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1890 template.sup_sw_if_index = hi->sw_if_index;
1891 template.sub.id = id;
1892 template.sub.eth.raw_flags = 0;
1893 template.sub.eth.flags.one_tag = 1;
1894 template.sub.eth.outer_vlan_id = id;
1895 template.sub.eth.flags.exact_match = 1;
1897 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1899 clib_error_report(error);
1900 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1903 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1904 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1906 BAD_SW_IF_INDEX_LABEL;
1909 q = vl_api_client_index_to_input_queue (mp->client_index);
1913 rmp = vl_msg_api_alloc (sizeof (*rmp));
1914 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1915 rmp->context = mp->context;
1916 rmp->retval = ntohl(rv);
1917 rmp->sw_if_index = ntohl(sw_if_index);
1918 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1922 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1924 vl_api_create_subif_reply_t * rmp;
1925 vnet_main_t * vnm = vnet_get_main();
1926 u32 sw_if_index = ~0;
1929 vnet_sw_interface_t *si;
1930 vnet_hw_interface_t *hi;
1931 vnet_sw_interface_t template;
1933 vnet_interface_main_t * im = &vnm->interface_main;
1934 u64 sup_and_sub_key;
1936 clib_error_t * error;
1938 VALIDATE_SW_IF_INDEX(mp);
1940 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1941 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1943 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1944 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1948 sw_if_index = si->sw_if_index;
1949 sub_id = ntohl(mp->sub_id);
1951 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1953 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1956 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1957 sw_if_index, sub_id);
1958 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1962 kp = clib_mem_alloc (sizeof (*kp));
1963 *kp = sup_and_sub_key;
1965 memset (&template, 0, sizeof (template));
1966 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1967 template.sup_sw_if_index = sw_if_index;
1968 template.sub.id = sub_id;
1969 template.sub.eth.flags.no_tags = mp->no_tags;
1970 template.sub.eth.flags.one_tag = mp->one_tag;
1971 template.sub.eth.flags.two_tags = mp->two_tags;
1972 template.sub.eth.flags.dot1ad = mp->dot1ad;
1973 template.sub.eth.flags.exact_match = mp->exact_match;
1974 template.sub.eth.flags.default_sub = mp->default_sub;
1975 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1976 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1977 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1978 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1980 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1982 clib_error_report (error);
1983 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1987 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1988 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1990 BAD_SW_IF_INDEX_LABEL;
1994 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1996 rmp->sw_if_index = ntohl(sw_if_index);
2001 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
2003 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
2005 stats_main_t * sm = &stats_main;
2006 u32 tunnel_sw_if_index = ~0;
2008 dslock (sm, 1 /* release hint */, 5 /* tag */);
2010 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
2011 (ip4_address_t *)(mp->dst_address),
2012 (ip4_address_t *)(mp->intfc_address),
2013 (u32)(mp->intfc_address_length),
2014 ntohl(mp->inner_vrf_id),
2015 ntohl(mp->outer_vrf_id),
2016 &tunnel_sw_if_index,
2021 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2023 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2028 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2029 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
2031 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2033 stats_main_t * sm = &stats_main;
2034 u32 tunnel_sw_if_index;
2036 dslock (sm, 1 /* release hint */, 5 /* tag */);
2038 rv = vnet_mpls_ethernet_add_del_tunnel
2039 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
2040 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
2041 ntohl(mp->tx_sw_if_index),
2042 &tunnel_sw_if_index,
2048 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2050 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2055 * This piece of misery brought to you because the control-plane
2056 * can't figure out the tx interface + dst-mac address all by itself
2058 static int mpls_ethernet_add_del_tunnel_2_t_handler
2059 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2061 pending_route_t * pr;
2062 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2063 vnet_main_t * vnm = vnet_get_main();
2064 vlib_main_t * vm = vlib_get_main();
2065 stats_main_t * sm = &stats_main;
2066 vpe_api_main_t * vam = &vpe_api_main;
2067 u32 inner_fib_index, outer_fib_index;
2068 ip4_main_t * im = &ip4_main;
2069 ip_lookup_main_t * lm = &im->lookup_main;
2070 ip_adjacency_t * adj = 0;
2073 u8 * dst_mac_address;
2077 u32 tunnel_sw_if_index;
2079 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2081 return VNET_API_ERROR_NO_SUCH_FIB;
2083 outer_fib_index = p[0];
2086 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2088 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2090 inner_fib_index = p[0];
2092 if (inner_fib_index == outer_fib_index)
2093 return VNET_API_ERROR_INVALID_VALUE;
2095 lookup_result = ip4_fib_lookup_with_table
2096 (im, outer_fib_index,
2097 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2098 1 /* disable default route */);
2100 adj = ip_get_adjacency (lm, lookup_result);
2101 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2103 if (mp->is_add && mp->resolve_if_needed) {
2104 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2105 pool_get (vam->pending_routes, pr);
2106 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2108 clib_memcpy (pme, mp, sizeof (*pme));
2109 /* recursion block, "just in case" */
2110 pme->resolve_if_needed = 0;
2111 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2112 pme->resolve_opaque = tx_sw_if_index;
2113 vnet_register_ip4_arp_resolution_event
2115 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2116 vpe_resolver_process_node.index,
2117 RESOLUTION_EVENT, pr - vam->pending_routes);
2119 vlib_process_signal_event
2120 (vm, vpe_resolver_process_node.index,
2121 RESOLUTION_PENDING_EVENT, 0 /* data */);
2123 /* The interface may be down, etc. */
2124 e = ip4_probe_neighbor
2125 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2129 clib_error_report(e);
2131 return VNET_API_ERROR_IN_PROGRESS;
2135 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2136 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2139 vnet_rewrite_get_data_internal
2140 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2142 dslock (sm, 1 /* release hint */, 10 /* tag */);
2144 rv = vnet_mpls_ethernet_add_del_tunnel
2145 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2146 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2147 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2155 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2156 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2158 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2161 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2163 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2168 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2170 vl_api_mpls_add_del_encap_reply_t * rmp;
2172 static u32 * labels;
2175 vec_reset_length (labels);
2177 for (i = 0; i < mp->nlabels; i++)
2178 vec_add1 (labels, ntohl(mp->labels[i]));
2181 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2182 ntohl(mp->vrf_id), labels,
2183 ~0 /* policy_tunnel_index */,
2184 0 /* no_dst_hash */,
2188 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2192 vl_api_mpls_add_del_decap_t_handler
2193 (vl_api_mpls_add_del_decap_t *mp)
2195 vl_api_mpls_add_del_decap_reply_t * rmp;
2198 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2199 ntohl(mp->label), ntohl(mp->next_index),
2200 mp->s_bit, mp->is_add);
2202 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2206 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2208 vl_api_proxy_arp_add_del_reply_t * rmp;
2211 ip4_main_t * im = &ip4_main;
2212 stats_main_t * sm = &stats_main;
2213 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2214 ip4_address_t *hi_addr,
2215 u32 fib_index, int is_del);
2218 dslock (sm, 1 /* release hint */, 6 /* tag */);
2220 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2223 rv = VNET_API_ERROR_NO_SUCH_FIB;
2229 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2230 (ip4_address_t *)mp->hi_address,
2231 fib_index, mp->is_add == 0);
2235 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2239 vl_api_proxy_arp_intfc_enable_disable_t_handler
2240 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2243 vnet_main_t * vnm = vnet_get_main();
2244 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2245 vnet_sw_interface_t * si;
2248 VALIDATE_SW_IF_INDEX(mp);
2250 sw_if_index = ntohl(mp->sw_if_index);
2252 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2254 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2258 si = vnet_get_sw_interface (vnm, sw_if_index);
2262 if (mp->enable_disable)
2263 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2265 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2267 BAD_SW_IF_INDEX_LABEL;
2270 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2274 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2276 vl_api_ip_neighbor_add_del_reply_t * rmp;
2277 vnet_main_t * vnm = vnet_get_main();
2280 stats_main_t * sm = &stats_main;
2282 VALIDATE_SW_IF_INDEX(mp);
2284 dslock (sm, 1 /* release hint */, 7 /* tag */);
2288 rv = vnet_set_ip6_ethernet_neighbor
2289 (vm, ntohl(mp->sw_if_index),
2290 (ip6_address_t *)(mp->dst_address),
2291 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2293 rv = vnet_unset_ip6_ethernet_neighbor
2294 (vm, ntohl(mp->sw_if_index),
2295 (ip6_address_t *)(mp->dst_address),
2296 mp->mac_address, sizeof(mp->mac_address));
2298 ip4_main_t * im = &ip4_main;
2299 ip_lookup_main_t * lm = &im->lookup_main;
2300 ethernet_arp_ip4_over_ethernet_address_t a;
2302 ip_adjacency_t *nh_adj;
2304 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2306 rv = VNET_API_ERROR_NO_SUCH_FIB;
2312 * Unfortunately, folks have a penchant for
2313 * adding interface addresses to the ARP cache, and
2314 * wondering why the forwarder eventually ASSERTs...
2316 ai = ip4_fib_lookup_with_table
2317 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2318 1 /* disable default route */);
2321 nh_adj = ip_get_adjacency (lm, ai);
2322 /* Never allow manipulation of a local adj! */
2323 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2324 clib_warning("%U matches local adj",
2326 (ip4_address_t *)(mp->dst_address));
2327 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2332 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2333 clib_memcpy (&a.ip4, mp->dst_address, 4);
2336 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2337 fib_index, &a, mp->is_static);
2339 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2343 BAD_SW_IF_INDEX_LABEL;
2346 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2350 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2353 vpe_main_t *rm = &vpe_main;
2354 ip4_main_t *im4 = &ip4_main;
2355 ip6_main_t *im6 = &ip6_main;
2356 ip_lookup_main_t * lm;
2361 u32 adj_index, sw_if_index;
2362 vl_api_is_address_reachable_t *rmp;
2363 ip_adjacency_t * adj;
2364 unix_shared_memory_queue_t *q;
2366 q = vl_api_client_index_to_input_queue (mp->client_index);
2368 increment_missing_api_client_counter (rm->vlib_main);
2372 rmp = vl_msg_api_alloc (sizeof (*rmp));
2373 clib_memcpy (rmp, mp, sizeof (*rmp));
2375 sw_if_index = mp->next_hop_sw_if_index;
2376 clib_memcpy (&addr, mp->address, sizeof (addr));
2378 lm = &im6->lookup_main;
2380 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2382 lm = &im4->lookup_main;
2384 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2386 if (adj_index == ~0) {
2390 adj = ip_get_adjacency (lm, adj_index);
2392 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2393 && adj->rewrite_header.sw_if_index == sw_if_index) {
2396 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2397 && adj->rewrite_header.sw_if_index == sw_if_index) {
2399 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2401 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2402 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2410 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2414 static void vl_api_sw_interface_details_t_handler (
2415 vl_api_sw_interface_details_t * mp)
2417 clib_warning ("BUG");
2420 static void vl_api_sw_interface_set_flags_t_handler (
2421 vl_api_sw_interface_set_flags_t * mp)
2423 vl_api_sw_interface_set_flags_reply_t *rmp;
2424 vnet_main_t * vnm = vnet_get_main();
2426 clib_error_t * error;
2429 VALIDATE_SW_IF_INDEX(mp);
2431 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2433 error = vnet_sw_interface_set_flags (vnm,
2434 ntohl(mp->sw_if_index),
2438 clib_error_report (error);
2441 BAD_SW_IF_INDEX_LABEL;
2442 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2445 static void vl_api_sw_interface_clear_stats_t_handler (
2446 vl_api_sw_interface_clear_stats_t * mp)
2448 vl_api_sw_interface_clear_stats_reply_t *rmp;
2450 vnet_main_t * vnm = vnet_get_main();
2451 vnet_interface_main_t * im = &vnm->interface_main;
2452 vlib_simple_counter_main_t * sm;
2453 vlib_combined_counter_main_t * cm;
2454 static vnet_main_t ** my_vnet_mains;
2455 int i, j, n_counters;
2459 vec_reset_length (my_vnet_mains);
2461 for (i = 0; i < vec_len (vnet_mains); i++)
2464 vec_add1 (my_vnet_mains, vnet_mains[i]);
2467 if (vec_len (vnet_mains) == 0)
2468 vec_add1 (my_vnet_mains, vnm);
2470 n_counters = vec_len (im->combined_sw_if_counters);
2472 for (j = 0; j < n_counters; j++)
2474 for (i = 0; i < vec_len(my_vnet_mains); i++)
2476 im = &my_vnet_mains[i]->interface_main;
2477 cm = im->combined_sw_if_counters + j;
2478 if (mp->sw_if_index == (u32)~0)
2479 vlib_clear_combined_counters (cm);
2481 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2485 n_counters = vec_len (im->sw_if_counters);
2487 for (j = 0; j < n_counters; j++)
2489 for (i = 0; i < vec_len(my_vnet_mains); i++)
2491 im = &my_vnet_mains[i]->interface_main;
2492 sm = im->sw_if_counters + j;
2493 if (mp->sw_if_index == (u32)~0)
2494 vlib_clear_simple_counters (sm);
2496 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2500 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2503 static void send_sw_interface_details (vpe_api_main_t * am,
2504 unix_shared_memory_queue_t *q,
2505 vnet_sw_interface_t * swif,
2506 u8 * interface_name,
2509 vl_api_sw_interface_details_t * mp;
2510 vnet_hw_interface_t * hi;
2512 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2514 mp = vl_msg_api_alloc (sizeof (*mp));
2515 memset (mp, 0, sizeof (*mp));
2516 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2517 mp->sw_if_index = ntohl(swif->sw_if_index);
2518 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2519 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2521 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2523 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2524 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2525 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2526 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2527 mp->link_mtu = ntohs(hi->max_packet_bytes);
2528 mp->context = context;
2530 strncpy ((char *) mp->interface_name,
2531 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2533 /* Send the L2 address for ethernet physical intfcs */
2534 if (swif->sup_sw_if_index == swif->sw_if_index
2535 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2536 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2537 ethernet_interface_t *ei;
2539 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2540 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2541 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2542 mp->l2_address_length = ntohl(sizeof (ei->address));
2543 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2544 vnet_sub_interface_t *sub = &swif->sub;
2545 mp->sub_id = ntohl(sub->id);
2546 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2547 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2548 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2549 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2550 mp->sub_exact_match = sub->eth.flags.exact_match;
2551 mp->sub_default = sub->eth.flags.default_sub;
2552 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2553 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2555 /* vlan tag rewrite data */
2556 u32 vtr_op = L2_VTR_DISABLED;
2557 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2559 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2560 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2561 // error - default to disabled
2562 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2563 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2566 mp->vtr_op = ntohl(vtr_op);
2567 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2568 mp->vtr_tag1 = ntohl(vtr_tag1);
2569 mp->vtr_tag2 = ntohl(vtr_tag2);
2573 vl_msg_api_send_shmem (q, (u8 *)&mp);
2576 static void send_sw_interface_flags (vpe_api_main_t * am,
2577 unix_shared_memory_queue_t *q,
2578 vnet_sw_interface_t * swif)
2580 vl_api_sw_interface_set_flags_t *mp;
2581 vnet_main_t * vnm = am->vnet_main;
2583 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2585 mp = vl_msg_api_alloc (sizeof (*mp));
2586 memset (mp, 0, sizeof (*mp));
2587 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2588 mp->sw_if_index = ntohl(swif->sw_if_index);
2590 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2592 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2594 vl_msg_api_send_shmem (q, (u8 *)&mp);
2597 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2598 unix_shared_memory_queue_t *q,
2600 __attribute__((unused));
2602 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2603 unix_shared_memory_queue_t *q,
2606 vl_api_sw_interface_set_flags_t *mp;
2608 mp = vl_msg_api_alloc (sizeof (*mp));
2609 memset (mp, 0, sizeof (*mp));
2610 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2611 mp->sw_if_index = ntohl(sw_if_index);
2613 mp->admin_up_down = 0;
2614 mp->link_up_down = 0;
2616 vl_msg_api_send_shmem (q, (u8 *)&mp);
2619 static void vl_api_sw_interface_dump_t_handler (
2620 vl_api_sw_interface_dump_t *mp)
2622 vpe_api_main_t * am = &vpe_api_main;
2623 vnet_sw_interface_t * swif;
2624 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2625 u8 * filter_string = 0, * name_string = 0;
2626 unix_shared_memory_queue_t * q;
2627 char * strcasestr (char *, char *); /* lnx hdr file botch */
2629 q = vl_api_client_index_to_input_queue (mp->client_index);
2634 if (mp->name_filter_valid) {
2635 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2636 filter_string = format (0, "%s%c", mp->name_filter, 0);
2639 pool_foreach (swif, im->sw_interfaces,
2641 name_string = format (name_string, "%U%c",
2642 format_vnet_sw_interface_name,
2643 am->vnet_main, swif, 0);
2645 if (mp->name_filter_valid == 0 ||
2646 strcasestr((char *) name_string, (char *) filter_string)) {
2648 send_sw_interface_details (am, q, swif, name_string, mp->context);
2650 _vec_len (name_string) = 0;
2653 vec_free (name_string);
2654 vec_free (filter_string);
2657 void send_oam_event (oam_target_t * t)
2659 vpe_api_main_t * vam = &vpe_api_main;
2660 unix_shared_memory_queue_t * q;
2661 vpe_client_registration_t *reg;
2662 vl_api_oam_event_t * mp;
2664 pool_foreach(reg, vam->oam_events_registrations,
2666 q = vl_api_client_index_to_input_queue (reg->client_index);
2668 mp = vl_msg_api_alloc (sizeof (*mp));
2669 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2670 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2671 mp->state = t->state;
2672 vl_msg_api_send_shmem (q, (u8 *)&mp);
2678 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2680 vl_api_oam_add_del_reply_t * rmp;
2683 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2684 (ip4_address_t *)mp->dst_address,
2688 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2692 vl_api_vnet_get_summary_stats_t_handler (
2693 vl_api_vnet_get_summary_stats_t *mp)
2695 stats_main_t * sm = &stats_main;
2696 vnet_interface_main_t * im = sm->interface_main;
2697 vl_api_vnet_summary_stats_reply_t *rmp;
2698 vlib_combined_counter_main_t * cm;
2701 u64 total_pkts[VLIB_N_RX_TX];
2702 u64 total_bytes[VLIB_N_RX_TX];
2704 unix_shared_memory_queue_t * q =
2705 vl_api_client_index_to_input_queue (mp->client_index);
2710 rmp = vl_msg_api_alloc (sizeof (*rmp));
2711 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2712 rmp->context = mp->context;
2715 memset (total_pkts, 0, sizeof (total_pkts));
2716 memset (total_bytes, 0, sizeof (total_bytes));
2718 vnet_interface_counter_lock (im);
2720 vec_foreach (cm, im->combined_sw_if_counters) {
2721 which = cm - im->combined_sw_if_counters;
2723 for (i = 0; i < vec_len (cm->maxi); i++) {
2724 vlib_get_combined_counter (cm, i, &v);
2725 total_pkts[which] += v.packets;
2726 total_bytes[which] += v.bytes;
2729 vnet_interface_counter_unlock (im);
2731 /* Note: in HOST byte order! */
2732 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2733 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2734 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2735 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2736 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2738 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2741 typedef CLIB_PACKED (struct {
2742 ip4_address_t address;
2744 u32 address_length : 6;
2749 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2751 vnet_main_t * vnm = vnet_get_main();
2752 vnet_interface_main_t * im = &vnm->interface_main;
2753 ip4_main_t * im4 = &ip4_main;
2754 static ip4_route_t * routes;
2755 static u32 * sw_if_indices_to_shut;
2756 stats_main_t * sm = &stats_main;
2761 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2762 u32 target_fib_id = ntohl(mp->vrf_id);
2764 dslock (sm, 1 /* release hint */, 8 /* tag */);
2766 vec_foreach (fib, im4->fibs) {
2767 vnet_sw_interface_t * si;
2769 if (fib->table_id != target_fib_id)
2772 /* remove any mpls/gre tunnels in this fib */
2773 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2775 /* remove any mpls encap/decap labels */
2776 mpls_fib_reset_labels (fib->table_id);
2778 /* remove any proxy arps in this fib */
2779 vnet_proxy_arp_fib_reset (fib->table_id);
2781 /* Set the flow hash for this fib to the default */
2782 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2784 vec_reset_length (sw_if_indices_to_shut);
2786 /* Shut down interfaces in this FIB / clean out intfc routes */
2787 pool_foreach (si, im->sw_interfaces,
2789 u32 sw_if_index = si->sw_if_index;
2791 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2792 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2794 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2797 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2798 sw_if_index = sw_if_indices_to_shut[i];
2799 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2801 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2802 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2803 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2806 vec_reset_length (routes);
2808 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2809 uword * hash = fib->adj_index_by_dst_address[i];
2813 x.address_length = i;
2815 hash_foreach_pair (p, hash,
2817 x.address.data_u32 = p->key;
2818 vec_add1 (routes, x);
2822 vec_foreach (r, routes) {
2823 ip4_add_del_route_args_t a;
2825 memset (&a, 0, sizeof (a));
2826 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2827 a.table_index_or_table_id = fib - im4->fibs;
2828 a.dst_address = r->address;
2829 a.dst_address_length = r->address_length;
2832 ip4_add_del_route (im4, &a);
2833 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2834 IP4_ROUTE_FLAG_FIB_INDEX);
2838 } /* vec_foreach (fib) */
2845 ip6_address_t address;
2852 ip6_route_t ** routep;
2853 } add_routes_in_fib_arg_t;
2855 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2857 add_routes_in_fib_arg_t * ap = arg;
2859 if (kvp->key[2]>>32 == ap->fib_index)
2861 ip6_address_t *addr;
2863 addr = (ip6_address_t *) kvp;
2864 vec_add2 (*ap->routep, r, 1);
2865 r->address = addr[0];
2866 r->address_length = kvp->key[2] & 0xFF;
2867 r->index = kvp->value;
2871 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2873 vnet_main_t * vnm = vnet_get_main();
2874 vnet_interface_main_t * im = &vnm->interface_main;
2875 ip6_main_t * im6 = &ip6_main;
2876 stats_main_t * sm = &stats_main;
2877 static ip6_route_t * routes;
2878 static u32 * sw_if_indices_to_shut;
2883 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2884 u32 target_fib_id = ntohl(mp->vrf_id);
2885 add_routes_in_fib_arg_t _a, *a=&_a;
2886 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2888 dslock (sm, 1 /* release hint */, 9 /* tag */);
2890 vec_foreach (fib, im6->fibs) {
2891 vnet_sw_interface_t * si;
2893 if (fib->table_id != target_fib_id)
2896 vec_reset_length (sw_if_indices_to_shut);
2898 /* Shut down interfaces in this FIB / clean out intfc routes */
2899 pool_foreach (si, im->sw_interfaces,
2901 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2903 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2906 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2907 sw_if_index = sw_if_indices_to_shut[i];
2908 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2910 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2911 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2912 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2915 vec_reset_length (routes);
2917 a->fib_index = fib - im6->fibs;
2918 a->routep = &routes;
2920 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2922 vec_foreach (r, routes) {
2923 ip6_add_del_route_args_t a;
2925 memset (&a, 0, sizeof (a));
2926 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2927 a.table_index_or_table_id = fib - im6->fibs;
2928 a.dst_address = r->address;
2929 a.dst_address_length = r->address_length;
2932 ip6_add_del_route (im6, &a);
2933 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2934 IP6_ROUTE_FLAG_FIB_INDEX);
2937 /* Reinstall the neighbor / router discovery routes */
2938 vnet_ip6_fib_init (im6, fib - im6->fibs);
2940 } /* vec_foreach (fib) */
2946 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2949 vl_api_reset_fib_reply_t * rmp;
2952 rv = ip6_reset_fib_t_handler (mp);
2954 rv = ip4_reset_fib_t_handler (mp);
2956 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2961 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2963 vl_api_dhcp_proxy_config_reply_t * rmp;
2966 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2967 (ip4_address_t *)(&mp->dhcp_src_address),
2968 (u32) ntohl(mp->vrf_id),
2969 (int) mp->insert_circuit_id,
2970 (int) (mp->is_add == 0));
2972 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2977 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2979 vl_api_dhcp_proxy_config_reply_t * rmp;
2982 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2983 (ip6_address_t *)(&mp->dhcp_src_address),
2984 (u32) ntohl(mp->vrf_id),
2985 (int) mp->insert_circuit_id,
2986 (int) (mp->is_add == 0));
2988 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2992 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2994 vl_api_dhcp_proxy_config_reply_t * rmp;
2997 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
2998 (ip4_address_t *)(&mp->dhcp_src_address),
2999 (u32) ntohl(mp->rx_vrf_id),
3000 (u32) ntohl(mp->server_vrf_id),
3001 (int) mp->insert_circuit_id,
3002 (int) (mp->is_add == 0));
3004 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3009 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
3011 vl_api_dhcp_proxy_config_reply_t * rmp;
3015 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
3016 (ip6_address_t *)(&mp->dhcp_src_address),
3017 (u32) ntohl(mp->rx_vrf_id),
3018 (u32) ntohl(mp->server_vrf_id),
3019 (int) mp->insert_circuit_id,
3020 (int) (mp->is_add == 0));
3022 rv = VNET_API_ERROR_UNIMPLEMENTED;
3025 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3030 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
3032 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3035 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
3038 (int)mp->is_add == 0);
3040 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
3043 (int)mp->is_add == 0);
3045 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
3049 static void vl_api_dhcp_proxy_config_t_handler
3050 (vl_api_dhcp_proxy_config_t *mp)
3052 if (mp->is_ipv6 == 0)
3053 dhcpv4_proxy_config (mp);
3055 dhcpv6_proxy_config (mp);
3058 static void vl_api_dhcp_proxy_config_2_t_handler
3059 (vl_api_dhcp_proxy_config_2_t *mp)
3061 if (mp->is_ipv6 == 0)
3062 dhcpv4_proxy_config_2 (mp);
3064 dhcpv6_proxy_config_2 (mp);
3067 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3068 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3070 unix_shared_memory_queue_t * q;
3071 vl_api_dhcp_compl_event_t * mp;
3073 q = vl_api_client_index_to_input_queue (client_index);
3077 mp = vl_msg_api_alloc (sizeof (*mp));
3078 mp->client_index = client_index;
3080 mp->is_ipv6 = is_ipv6;
3081 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3082 mp->hostname[vec_len(hostname) + 1] = '\n';
3083 clib_memcpy (&mp->host_address[0], host_address, 16);
3084 clib_memcpy (&mp->router_address[0], router_address, 16);
3085 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3087 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3089 vl_msg_api_send_shmem (q, (u8 *)&mp);
3092 static void vl_api_dhcp_client_config_t_handler
3093 (vl_api_dhcp_client_config_t *mp)
3095 vlib_main_t *vm = vlib_get_main();
3096 vl_api_dhcp_client_config_reply_t * rmp;
3099 VALIDATE_SW_IF_INDEX(mp);
3101 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3102 mp->hostname, mp->is_add, mp->client_index,
3103 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3106 BAD_SW_IF_INDEX_LABEL;
3108 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3112 vl_api_sw_interface_ip6nd_ra_config_t_handler
3113 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3115 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3117 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, default_router;
3119 is_no = mp->is_no == 1;
3120 suppress = mp->suppress == 1;
3121 managed = mp->managed == 1;
3122 other = mp->other == 1;
3123 ll_option = mp->ll_option == 1;
3124 send_unicast = mp->send_unicast == 1;
3125 cease = mp->cease == 1;
3126 default_router = mp->default_router == 1;
3128 VALIDATE_SW_IF_INDEX(mp);
3130 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3131 suppress, managed, other,
3132 ll_option, send_unicast, cease,
3133 default_router, ntohl (mp->lifetime),
3134 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3135 ntohl(mp->max_interval), ntohl( mp->min_interval),
3138 BAD_SW_IF_INDEX_LABEL;
3140 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3144 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3145 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3147 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3149 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3151 VALIDATE_SW_IF_INDEX(mp);
3153 is_no = mp->is_no == 1;
3154 use_default = mp->use_default == 1;
3155 no_advertise = mp->no_advertise == 1;
3156 off_link = mp->off_link == 1;
3157 no_autoconfig = mp->no_autoconfig == 1;
3158 no_onlink = mp->no_onlink == 1;
3160 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3161 (ip6_address_t *)mp->address, mp->address_length,
3162 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3163 no_advertise, off_link, no_autoconfig, no_onlink,
3166 BAD_SW_IF_INDEX_LABEL;
3167 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3171 vl_api_sw_interface_ip6_enable_disable_t_handler
3172 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3174 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3175 vnet_main_t * vnm = vnet_get_main();
3177 clib_error_t * error;
3181 VALIDATE_SW_IF_INDEX(mp);
3183 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3184 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3187 clib_error_report(error);
3188 rv = VNET_API_ERROR_UNSPECIFIED;
3190 rv = vnm->api_errno;
3193 BAD_SW_IF_INDEX_LABEL;
3195 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3199 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3200 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3202 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3204 clib_error_t * error;
3205 vnet_main_t * vnm = vnet_get_main();
3209 VALIDATE_SW_IF_INDEX(mp);
3211 error = set_ip6_link_local_address(vm,
3212 ntohl(mp->sw_if_index),
3213 (ip6_address_t *)mp->address,
3214 mp->address_length);
3216 clib_error_report(error);
3217 rv = VNET_API_ERROR_UNSPECIFIED;
3219 rv = vnm->api_errno;
3222 BAD_SW_IF_INDEX_LABEL;
3224 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3227 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3229 vl_api_set_ip_flow_hash_reply_t *rmp;
3230 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3232 clib_warning ("unimplemented...");
3234 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3237 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3239 vl_api_set_ip_flow_hash_reply_t *rmp;
3242 u32 flow_hash_config = 0;
3244 table_id = ntohl(mp->vrf_id);
3246 #define _(a,b) if (mp->a) flow_hash_config |= b;
3247 foreach_flow_hash_bit;
3250 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3252 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3256 static void vl_api_set_ip_flow_hash_t_handler
3257 (vl_api_set_ip_flow_hash_t *mp)
3259 if (mp->is_ipv6 == 0)
3260 set_ip4_flow_hash (mp);
3262 set_ip6_flow_hash (mp);
3265 static void vl_api_sw_interface_set_unnumbered_t_handler
3266 (vl_api_sw_interface_set_unnumbered_t *mp)
3268 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3270 vnet_sw_interface_t * si;
3271 vnet_main_t *vnm = vnet_get_main();
3272 u32 sw_if_index, unnumbered_sw_if_index;
3274 sw_if_index = ntohl(mp->sw_if_index);
3275 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3278 * The API message field names are backwards from
3279 * the underlying data structure names.
3280 * It's not worth changing them now.
3282 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3283 unnumbered_sw_if_index)) {
3284 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3288 /* Only check the "use loop0" field when setting the binding */
3290 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3291 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3295 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3298 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3299 si->unnumbered_sw_if_index = sw_if_index;
3301 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3302 si->unnumbered_sw_if_index = (u32)~0;
3306 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3309 static void vl_api_create_loopback_t_handler
3310 (vl_api_create_loopback_t *mp)
3312 vl_api_create_loopback_reply_t * rmp;
3316 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3318 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3320 rmp->sw_if_index = ntohl (sw_if_index);
3324 static void vl_api_delete_loopback_t_handler
3325 (vl_api_delete_loopback_t *mp)
3327 vl_api_delete_loopback_reply_t * rmp;
3331 sw_if_index = ntohl (mp->sw_if_index);
3332 rv = vnet_delete_loopback_interface (sw_if_index);
3334 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3337 static void vl_api_control_ping_t_handler
3338 (vl_api_control_ping_t *mp)
3340 vl_api_control_ping_reply_t * rmp;
3343 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3345 rmp->vpe_pid = ntohl (getpid());
3349 static void vl_api_noprint_control_ping_t_handler
3350 (vl_api_noprint_control_ping_t *mp)
3352 vl_api_noprint_control_ping_reply_t * rmp;
3355 REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY,
3357 rmp->vpe_pid = ntohl (getpid());
3361 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3363 u8 **shmem_vecp = (u8 **)arg;
3366 api_main_t * am = &api_main;
3369 shmem_vec = *shmem_vecp;
3371 offset = vec_len (shmem_vec);
3373 pthread_mutex_lock (&am->vlib_rp->mutex);
3374 oldheap = svm_push_data_heap (am->vlib_rp);
3376 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3378 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3380 svm_pop_heap (oldheap);
3381 pthread_mutex_unlock (&am->vlib_rp->mutex);
3383 *shmem_vecp = shmem_vec;
3387 static void vl_api_cli_request_t_handler
3388 (vl_api_cli_request_t *mp)
3390 vl_api_cli_reply_t *rp;
3391 unix_shared_memory_queue_t *q;
3392 vlib_main_t * vm = vlib_get_main();
3393 api_main_t * am = &api_main;
3394 unformat_input_t input;
3398 q = vl_api_client_index_to_input_queue (mp->client_index);
3402 rp = vl_msg_api_alloc (sizeof (*rp));
3403 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3404 rp->context = mp->context;
3406 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3408 vlib_cli_input (vm, &input, shmem_cli_output,
3411 pthread_mutex_lock (&am->vlib_rp->mutex);
3412 oldheap = svm_push_data_heap (am->vlib_rp);
3414 vec_add1(shmem_vec, 0);
3416 svm_pop_heap (oldheap);
3417 pthread_mutex_unlock (&am->vlib_rp->mutex);
3419 rp->reply_in_shmem = (uword)shmem_vec;
3421 vl_msg_api_send_shmem (q, (u8 *)&rp);
3424 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3427 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3428 vnet_main_t *vnm = vnet_get_main();
3429 clib_error_t * error;
3434 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3436 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3439 clib_error_report(error);
3440 rv = VNET_API_ERROR_UNSPECIFIED;
3442 rv = vnm->api_errno;
3445 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3448 static void vl_api_sr_tunnel_add_del_t_handler
3449 (vl_api_sr_tunnel_add_del_t *mp)
3452 clib_warning ("unimplemented");
3454 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3456 vl_api_sr_tunnel_add_del_reply_t * rmp;
3457 ip6_address_t * segments = 0, * seg;
3458 ip6_address_t * tags = 0, *tag;
3459 ip6_address_t * this_address;
3462 if (mp->n_segments == 0) {
3467 memset (a, 0, sizeof (*a));
3468 a->src_address = (ip6_address_t *)&mp->src_address;
3469 a->dst_address = (ip6_address_t *)&mp->dst_address;
3470 a->dst_mask_width = mp->dst_mask_width;
3471 a->flags_net_byte_order = mp->flags_net_byte_order;
3472 a->is_del = (mp->is_add == 0);
3473 a->rx_table_id = ntohl(mp->outer_vrf_id);
3474 a->tx_table_id = ntohl(mp->inner_vrf_id);
3476 a->name = format(0, "%s", mp->name);
3477 if (!(vec_len(a->name)))
3480 a->policy_name = format(0, "%s", mp->policy_name);
3481 if (!(vec_len(a->policy_name)))
3484 /* Yank segments and tags out of the API message */
3485 this_address = (ip6_address_t *)mp->segs_and_tags;
3486 for (i = 0; i < mp->n_segments; i++) {
3487 vec_add2 (segments, seg, 1);
3488 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3491 for (i = 0; i < mp->n_tags; i++) {
3492 vec_add2 (tags, tag, 1);
3493 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3497 a->segments = segments;
3500 rv = ip6_sr_add_del_tunnel (a);
3504 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3508 static void vl_api_sr_policy_add_del_t_handler
3509 (vl_api_sr_policy_add_del_t *mp)
3512 clib_warning ("unimplemented");
3514 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3516 vl_api_sr_policy_add_del_reply_t * rmp;
3519 memset (a, 0, sizeof (*a));
3520 a->is_del = (mp->is_add == 0);
3522 a->name = format(0, "%s", mp->name);
3523 if (!(vec_len(a->name)))
3525 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3529 if (!(mp->tunnel_names[0]))
3531 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3535 // start deserializing tunnel_names
3536 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3537 u8 * deser_tun_names = mp->tunnel_names;
3538 deser_tun_names += 1; //moving along
3541 int tun_name_len = 0;
3543 for (i=0; i < num_tunnels; i++)
3545 tun_name_len= *deser_tun_names;
3546 deser_tun_names += 1;
3547 vec_resize (tun_name, tun_name_len);
3548 memcpy(tun_name, deser_tun_names, tun_name_len);
3549 vec_add1 (a->tunnel_names, tun_name);
3550 deser_tun_names += tun_name_len;
3554 rv = ip6_sr_add_del_policy (a);
3558 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3562 static void vl_api_sr_multicast_map_add_del_t_handler
3563 (vl_api_sr_multicast_map_add_del_t *mp)
3566 clib_warning ("unimplemented");
3568 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3570 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3572 memset (a, 0, sizeof (*a));
3573 a->is_del = (mp->is_add == 0);
3575 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3576 a->policy_name = format(0, "%s", mp->policy_name);
3578 if (a->multicast_address == 0)
3584 if (!(a->policy_name))
3590 #if DPDK > 0 /* Cannot call replicate without DPDK */
3591 rv = ip6_sr_add_del_multicastmap (a);
3593 clib_warning ("multicast replication without DPDK not implemented");
3594 rv = VNET_API_ERROR_UNIMPLEMENTED;
3599 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3603 #define foreach_classify_add_del_table_field \
3608 _(match_n_vectors) \
3609 _(next_table_index) \
3612 static void vl_api_classify_add_del_table_t_handler
3613 (vl_api_classify_add_del_table_t * mp)
3615 vl_api_classify_add_del_table_reply_t * rmp;
3616 vnet_classify_main_t * cm = &vnet_classify_main;
3617 vnet_classify_table_t * t;
3621 foreach_classify_add_del_table_field;
3624 #define _(a) a = ntohl(mp->a);
3625 foreach_classify_add_del_table_field;
3628 /* The underlying API fails silently, on purpose, so check here */
3629 if (mp->is_add == 0)
3630 if (pool_is_free_index (cm->tables, table_index)) {
3631 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3635 rv = vnet_classify_add_del_table
3636 (cm, mp->mask, nbuckets, memory_size,
3637 skip_n_vectors, match_n_vectors,
3638 next_table_index, miss_next_index,
3639 &table_index, mp->is_add);
3642 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3644 if (rv == 0 && mp->is_add) {
3645 t = pool_elt_at_index (cm->tables, table_index);
3646 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3647 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3648 rmp->new_table_index = ntohl(table_index);
3650 rmp->skip_n_vectors = ~0;
3651 rmp->match_n_vectors = ~0;
3652 rmp->new_table_index = ~0;
3657 static void vl_api_classify_add_del_session_t_handler
3658 (vl_api_classify_add_del_session_t * mp)
3660 vnet_classify_main_t * cm = &vnet_classify_main;
3661 vl_api_classify_add_del_session_reply_t * rmp;
3663 u32 table_index, hit_next_index, opaque_index;
3666 table_index = ntohl (mp->table_index);
3667 hit_next_index = ntohl (mp->hit_next_index);
3668 opaque_index = ntohl (mp->opaque_index);
3669 advance = ntohl (mp->advance);
3671 rv = vnet_classify_add_del_session
3672 (cm, table_index, mp->match, hit_next_index, opaque_index,
3673 advance, mp->is_add);
3675 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3678 static void vl_api_classify_set_interface_ip_table_t_handler
3679 (vl_api_classify_set_interface_ip_table_t * mp)
3681 vlib_main_t * vm = vlib_get_main();
3682 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3684 u32 table_index, sw_if_index;
3686 table_index = ntohl (mp->table_index);
3687 sw_if_index = ntohl (mp->sw_if_index);
3689 VALIDATE_SW_IF_INDEX(mp);
3692 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3694 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3696 BAD_SW_IF_INDEX_LABEL;
3698 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3701 static void vl_api_classify_set_interface_l2_tables_t_handler
3702 (vl_api_classify_set_interface_l2_tables_t * mp)
3704 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3706 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3709 ip4_table_index = ntohl(mp->ip4_table_index);
3710 ip6_table_index = ntohl(mp->ip6_table_index);
3711 other_table_index = ntohl(mp->other_table_index);
3712 sw_if_index = ntohl(mp->sw_if_index);
3714 VALIDATE_SW_IF_INDEX(mp);
3716 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3717 ip6_table_index, other_table_index);
3720 if (ip4_table_index != ~0 || ip6_table_index != ~0
3721 || other_table_index != ~0)
3726 vnet_l2_classify_enable_disable (sw_if_index, enable);
3729 BAD_SW_IF_INDEX_LABEL;
3731 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3735 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3738 vl_api_l2_fib_clear_table_reply_t * rmp;
3740 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3741 * that is not currently implemented. When that TODO is fixed
3742 * this call should be changed to pass 1 instead of 0.
3744 l2fib_clear_table (0);
3746 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3749 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3754 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3757 vl_api_l2_interface_efp_filter_reply_t * rmp;
3758 vnet_main_t *vnm = vnet_get_main();
3760 // enable/disable the feature
3761 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3762 rv = vnm->api_errno;
3764 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3768 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3771 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3772 vnet_main_t * vnm = vnet_get_main();
3773 vlib_main_t * vm = vlib_get_main();
3776 VALIDATE_SW_IF_INDEX(mp);
3778 vtr_op = ntohl(mp->vtr_op);
3780 /* The L2 code is unsuspicious */
3782 case L2_VTR_DISABLED:
3787 case L2_VTR_TRANSLATE_1_1:
3788 case L2_VTR_TRANSLATE_1_2:
3789 case L2_VTR_TRANSLATE_2_1:
3790 case L2_VTR_TRANSLATE_2_2:
3794 rv = VNET_API_ERROR_INVALID_VALUE;
3795 goto bad_sw_if_index;
3798 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3799 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3802 BAD_SW_IF_INDEX_LABEL;
3804 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3808 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3811 vl_api_create_vhost_user_if_reply_t * rmp;
3812 #if DPDK > 0 && DPDK_VHOST_USER
3813 u32 sw_if_index = (u32)~0;
3815 vnet_main_t * vnm = vnet_get_main();
3816 vlib_main_t * vm = vlib_get_main();
3818 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3819 mp->is_server, &sw_if_index, (u64)~0,
3820 mp->renumber, ntohl(mp->custom_dev_instance),
3821 (mp->use_custom_mac)?mp->mac_address:NULL);
3823 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3825 rmp->sw_if_index = ntohl (sw_if_index);
3828 rv = VNET_API_ERROR_UNIMPLEMENTED;
3829 REPLY_MACRO(VL_API_CREATE_VHOST_USER_IF_REPLY);
3834 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3837 vl_api_modify_vhost_user_if_reply_t * rmp;
3838 #if DPDK > 0 && DPDK_VHOST_USER
3839 u32 sw_if_index = ntohl(mp->sw_if_index);
3841 vnet_main_t * vnm = vnet_get_main();
3842 vlib_main_t * vm = vlib_get_main();
3844 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3845 mp->is_server, sw_if_index, (u64)~0,
3846 mp->renumber, ntohl(mp->custom_dev_instance));
3848 rv = VNET_API_ERROR_UNIMPLEMENTED;
3850 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3854 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3857 vl_api_delete_vhost_user_if_reply_t * rmp;
3858 #if DPDK > 0 && DPDK_VHOST_USER
3859 vpe_api_main_t * vam = &vpe_api_main;
3860 u32 sw_if_index = ntohl(mp->sw_if_index);
3862 vnet_main_t * vnm = vnet_get_main();
3863 vlib_main_t * vm = vlib_get_main();
3865 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3867 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3869 unix_shared_memory_queue_t * q =
3870 vl_api_client_index_to_input_queue (mp->client_index);
3874 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3877 rv = VNET_API_ERROR_UNIMPLEMENTED;
3878 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3882 static void vl_api_sw_interface_vhost_user_details_t_handler (
3883 vl_api_sw_interface_vhost_user_details_t * mp)
3885 clib_warning ("BUG");
3888 #if DPDK > 0 && DPDK_VHOST_USER
3889 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3890 unix_shared_memory_queue_t *q,
3891 vhost_user_intf_details_t * vui,
3894 vl_api_sw_interface_vhost_user_details_t * mp;
3896 mp = vl_msg_api_alloc (sizeof (*mp));
3897 memset (mp, 0, sizeof (*mp));
3898 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3899 mp->sw_if_index = ntohl(vui->sw_if_index);
3900 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3901 mp->features = clib_net_to_host_u64 (vui->features);
3902 mp->is_server = vui->is_server;
3903 mp->num_regions = ntohl(vui->num_regions);
3904 mp->sock_errno = ntohl(vui->sock_errno);
3905 mp->context = context;
3907 strncpy ((char *) mp->sock_filename,
3908 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3909 strncpy ((char *) mp->interface_name,
3910 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3912 vl_msg_api_send_shmem (q, (u8 *)&mp);
3917 vl_api_sw_interface_vhost_user_dump_t_handler (
3918 vl_api_sw_interface_vhost_user_dump_t *mp)
3920 #if DPDK > 0 && DPDK_VHOST_USER
3922 vpe_api_main_t * am = &vpe_api_main;
3923 vnet_main_t * vnm = vnet_get_main();
3924 vlib_main_t * vm = vlib_get_main();
3925 vhost_user_intf_details_t *ifaces = NULL;
3926 vhost_user_intf_details_t *vuid = NULL;
3927 unix_shared_memory_queue_t * q;
3929 q = vl_api_client_index_to_input_queue (mp->client_index);
3933 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3937 vec_foreach (vuid, ifaces) {
3938 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3944 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3945 unix_shared_memory_queue_t *q,
3950 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3951 u8 * if_name = NULL;
3952 vnet_sw_interface_t * si = NULL;
3954 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3956 if_name = format(if_name, "%U",
3957 format_vnet_sw_interface_name, lm->vnet_main, si);
3959 mp = vl_msg_api_alloc (sizeof (*mp));
3960 memset (mp, 0, sizeof (*mp));
3961 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3962 strncpy((char *)mp->interface_name,
3963 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3964 mp->sw_if_index = ntohl(si->sw_if_index);
3965 mp->local_session_id = s->local_session_id;
3966 mp->remote_session_id = s->remote_session_id;
3967 mp->local_cookie[0] = s->local_cookie[0];
3968 mp->local_cookie[1] = s->local_cookie[1];
3969 mp->remote_cookie = s->remote_cookie;
3970 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3971 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3972 mp->l2_sublayer_present = s->l2_sublayer_present;
3973 mp->context = context;
3975 vl_msg_api_send_shmem (q, (u8 *)&mp);
3978 static void send_ip_address_details (vpe_api_main_t * am,
3979 unix_shared_memory_queue_t * q,
3985 vl_api_ip_address_details_t * mp;
3987 mp = vl_msg_api_alloc (sizeof (*mp));
3988 memset (mp, 0, sizeof (*mp));
3989 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3992 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3994 u32 * tp = (u32 *)mp->ip;
3995 *tp = ntohl(*(u32*)ip);
3997 mp->prefix_length = prefix_length;
3998 mp->context = context;
4000 vl_msg_api_send_shmem (q, (u8 *)&mp);
4004 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
4006 vpe_api_main_t * am = &vpe_api_main;
4007 unix_shared_memory_queue_t * q;
4010 ip6_main_t * im6 = &ip6_main;
4011 ip4_main_t * im4 = &ip4_main;
4012 ip_lookup_main_t * lm6 = &im6->lookup_main;
4013 ip_lookup_main_t * lm4 = &im4->lookup_main;
4014 ip_interface_address_t * ia = 0;
4015 u32 sw_if_index = ~0;
4016 int rv __attribute__ ((unused)) = 0;
4018 VALIDATE_SW_IF_INDEX(mp);
4020 sw_if_index = ntohl(mp->sw_if_index);
4022 q = vl_api_client_index_to_input_queue (mp->client_index);
4028 foreach_ip_interface_address (lm6, ia, sw_if_index,
4029 1 /* honor unnumbered */,
4031 r6 = ip_interface_address_get_address (lm6, ia);
4032 u16 prefix_length = ia->address_length;
4033 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4036 foreach_ip_interface_address (lm4, ia, sw_if_index,
4037 1 /* honor unnumbered */,
4039 r4 = ip_interface_address_get_address (lm4, ia);
4040 u16 prefix_length = ia->address_length;
4041 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4044 BAD_SW_IF_INDEX_LABEL;
4047 static void send_ip_details (vpe_api_main_t * am,
4048 unix_shared_memory_queue_t *q,
4052 vl_api_ip_details_t * mp;
4054 mp = vl_msg_api_alloc (sizeof (*mp));
4055 memset (mp, 0, sizeof (*mp));
4056 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
4058 mp->sw_if_index = ntohl(sw_if_index);
4059 mp->context = context;
4061 vl_msg_api_send_shmem (q, (u8 *)&mp);
4065 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
4066 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
4068 vpe_api_main_t * am = &vpe_api_main;
4069 l2t_main_t * lm = &l2t_main;
4070 unix_shared_memory_queue_t * q;
4071 l2t_session_t *session;
4073 q = vl_api_client_index_to_input_queue (mp->client_index);
4077 pool_foreach (session, lm->sessions,
4079 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4084 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4085 unix_shared_memory_queue_t *q,
4086 tapcli_interface_details_t *tap_if,
4089 vl_api_sw_interface_tap_details_t * mp;
4090 mp = vl_msg_api_alloc (sizeof (*mp));
4091 memset (mp, 0, sizeof (*mp));
4092 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4093 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4094 strncpy((char *)mp->dev_name,
4095 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4096 mp->context = context;
4098 vl_msg_api_send_shmem (q, (u8 *)&mp);
4102 vl_api_sw_interface_tap_dump_t_handler (
4103 vl_api_sw_interface_tap_dump_t *mp)
4106 vpe_api_main_t * am = &vpe_api_main;
4107 unix_shared_memory_queue_t * q;
4108 tapcli_interface_details_t *tapifs = NULL;
4109 tapcli_interface_details_t *tap_if = NULL;
4111 q = vl_api_client_index_to_input_queue (mp->client_index);
4115 rv = vnet_tap_dump_ifs(&tapifs);
4119 vec_foreach(tap_if, tapifs) {
4120 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4127 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4129 vpe_api_main_t * am = &vpe_api_main;
4130 vnet_main_t * vnm = vnet_get_main();
4131 vlib_main_t * vm = vlib_get_main();
4132 vnet_interface_main_t * im = &vnm->interface_main;
4133 unix_shared_memory_queue_t * q;
4134 vnet_sw_interface_t * si, * sorted_sis;
4135 u32 sw_if_index = ~0;
4137 q = vl_api_client_index_to_input_queue (mp->client_index);
4142 /* Gather interfaces. */
4143 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4144 _vec_len (sorted_sis) = 0;
4145 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4147 vec_foreach (si, sorted_sis) {
4148 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4149 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4152 sw_if_index = si->sw_if_index;
4153 send_ip_details(am, q, sw_if_index, mp->context);
4158 static void vl_api_l2_fib_table_entry_t_handler (
4159 vl_api_l2_fib_table_entry_t * mp)
4161 clib_warning ("BUG");
4164 static void send_l2fib_table_entry (vpe_api_main_t * am,
4165 unix_shared_memory_queue_t *q,
4166 l2fib_entry_key_t * l2fe_key,
4167 l2fib_entry_result_t * l2fe_res,
4170 vl_api_l2_fib_table_entry_t * mp;
4172 mp = vl_msg_api_alloc (sizeof (*mp));
4173 memset (mp, 0, sizeof (*mp));
4174 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4176 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4178 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4179 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4180 mp->static_mac = l2fe_res->fields.static_mac;
4181 mp->filter_mac = l2fe_res->fields.filter;
4182 mp->bvi_mac = l2fe_res->fields.bvi;
4183 mp->context = context;
4185 vl_msg_api_send_shmem (q, (u8 *)&mp);
4189 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4191 vpe_api_main_t * am = &vpe_api_main;
4192 bd_main_t * bdm = &bd_main;
4193 l2fib_entry_key_t *l2fe_key = NULL;
4194 l2fib_entry_result_t *l2fe_res = NULL;
4195 u32 ni, bd_id = ntohl (mp->bd_id);
4197 unix_shared_memory_queue_t * q;
4200 q = vl_api_client_index_to_input_queue (mp->client_index);
4204 /* see l2fib_table_dump: ~0 means "any" */
4208 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4215 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4217 vec_foreach_index (ni, l2fe_key) {
4218 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4219 vec_elt_at_index(l2fe_res, ni), mp->context);
4226 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4228 vl_api_show_version_reply_t *rmp;
4230 char * vpe_api_get_build_directory(void);
4231 char * vpe_api_get_version(void);
4232 char * vpe_api_get_build_date(void);
4234 unix_shared_memory_queue_t * q =
4235 vl_api_client_index_to_input_queue (mp->client_index);
4240 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4242 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4243 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4244 ARRAY_LEN(rmp->build_directory)-1);
4245 strncpy ((char *) rmp->version, vpe_api_get_version(),
4246 ARRAY_LEN(rmp->version)-1);
4247 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4248 ARRAY_LEN(rmp->build_date)-1);
4252 static void vl_api_get_node_index_t_handler
4253 (vl_api_get_node_index_t * mp)
4255 vlib_main_t * vm = vlib_get_main();
4256 vl_api_get_node_index_reply_t * rmp;
4259 u32 node_index = ~0;
4261 n = vlib_get_node_by_name (vm, mp->node_name);
4264 rv = VNET_API_ERROR_NO_SUCH_NODE;
4266 node_index = n->index;
4268 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4270 rmp->node_index = ntohl(node_index);
4274 static void vl_api_get_next_index_t_handler
4275 (vl_api_get_next_index_t * mp)
4277 vlib_main_t * vm = vlib_get_main();
4278 vl_api_get_next_index_reply_t * rmp;
4279 vlib_node_t * node, * next_node;
4281 u32 next_node_index = ~0, next_index = ~0;
4284 node = vlib_get_node_by_name (vm, mp->node_name);
4287 rv = VNET_API_ERROR_NO_SUCH_NODE;
4291 next_node = vlib_get_node_by_name (vm, mp->next_name);
4293 if (next_node == 0) {
4294 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4298 next_node_index = next_node->index;
4300 p = hash_get (node->next_slot_by_node, next_node_index);
4303 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4310 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4312 rmp->next_index = ntohl(next_index);
4316 static void vl_api_add_node_next_t_handler
4317 (vl_api_add_node_next_t * mp)
4319 vlib_main_t * vm = vlib_get_main();
4320 vl_api_add_node_next_reply_t * rmp;
4321 vlib_node_t * n, * next;
4323 u32 next_index = ~0;
4325 n = vlib_get_node_by_name (vm, mp->node_name);
4328 rv = VNET_API_ERROR_NO_SUCH_NODE;
4332 next = vlib_get_node_by_name (vm, mp->next_name);
4335 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4337 next_index = vlib_node_add_next (vm, n->index, next->index);
4340 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4342 rmp->next_index = ntohl(next_index);
4346 static void vl_api_l2tpv3_create_tunnel_t_handler
4347 (vl_api_l2tpv3_create_tunnel_t *mp)
4349 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4350 l2t_main_t *lm = &l2t_main;
4351 u32 sw_if_index = (u32)~0;
4354 if (mp->is_ipv6 != 1) {
4355 rv = VNET_API_ERROR_UNIMPLEMENTED;
4359 u32 encap_fib_index;
4361 if (mp->encap_vrf_id != ~0) {
4363 ip6_main_t *im = &ip6_main;
4364 if (!(p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id)))) {
4365 rv = VNET_API_ERROR_NO_SUCH_FIB;
4368 encap_fib_index = p[0];
4370 encap_fib_index = ~0;
4373 rv = create_l2tpv3_ipv6_tunnel (lm,
4374 (ip6_address_t *) mp->client_address,
4375 (ip6_address_t *) mp->our_address,
4376 ntohl(mp->local_session_id),
4377 ntohl(mp->remote_session_id),
4378 clib_net_to_host_u64(mp->local_cookie),
4379 clib_net_to_host_u64(mp->remote_cookie),
4380 mp->l2_sublayer_present,
4385 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4387 rmp->sw_if_index = ntohl (sw_if_index);
4391 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4392 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4394 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4395 l2t_main_t *lm = &l2t_main;
4398 VALIDATE_SW_IF_INDEX(mp);
4400 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4401 clib_net_to_host_u64(mp->new_local_cookie),
4402 clib_net_to_host_u64(mp->new_remote_cookie));
4404 BAD_SW_IF_INDEX_LABEL;
4406 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4409 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4410 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4413 vnet_main_t * vnm = vnet_get_main();
4414 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4416 VALIDATE_SW_IF_INDEX(mp);
4418 rv = l2tpv3_interface_enable_disable
4419 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4421 BAD_SW_IF_INDEX_LABEL;
4423 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4426 static void vl_api_l2tpv3_set_lookup_key_t_handler
4427 (vl_api_l2tpv3_set_lookup_key_t * mp)
4430 l2t_main_t *lm = &l2t_main;
4431 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4433 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4434 rv = VNET_API_ERROR_INVALID_VALUE;
4438 lm->lookup_type = mp->key;
4441 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4444 static void vl_api_vxlan_add_del_tunnel_t_handler
4445 (vl_api_vxlan_add_del_tunnel_t * mp)
4447 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4449 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4450 u32 encap_fib_index;
4452 ip4_main_t * im = &ip4_main;
4453 u32 sw_if_index = ~0;
4455 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4457 rv = VNET_API_ERROR_NO_SUCH_FIB;
4460 encap_fib_index = p[0];
4462 /* Check src & dst are different */
4463 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4464 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4465 rv = VNET_API_ERROR_SAME_SRC_DST;
4468 memset (a, 0, sizeof (*a));
4470 a->is_add = mp->is_add;
4471 a->is_ip6 = mp->is_ipv6;
4473 /* ip addresses sent in network byte order */
4475 memcpy(&(a->src.ip6), mp->src_address, 16);
4476 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4478 memcpy(&(a->src.ip4), mp->src_address, 4);
4479 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4482 a->encap_fib_index = encap_fib_index;
4483 a->decap_next_index = ntohl(mp->decap_next_index);
4484 a->vni = ntohl(mp->vni);
4485 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4488 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4490 rmp->sw_if_index = ntohl (sw_if_index);
4494 static void send_vxlan_tunnel_details
4495 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4497 vl_api_vxlan_tunnel_details_t * rmp;
4498 ip4_main_t * im4 = &ip4_main;
4499 ip6_main_t * im6 = &ip6_main;
4500 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4502 rmp = vl_msg_api_alloc (sizeof (*rmp));
4503 memset (rmp, 0, sizeof (*rmp));
4504 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4506 memcpy(rmp->src_address, &(t->src.ip6), 16);
4507 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4508 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4510 memcpy(rmp->src_address, &(t->src.ip4), 4);
4511 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4512 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4514 rmp->vni = htonl(t->vni);
4515 rmp->decap_next_index = htonl(t->decap_next_index);
4516 rmp->sw_if_index = htonl(t->sw_if_index);
4517 rmp->is_ipv6 = is_ipv6;
4518 rmp->context = context;
4520 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4523 static void vl_api_vxlan_tunnel_dump_t_handler
4524 (vl_api_vxlan_tunnel_dump_t * mp)
4526 unix_shared_memory_queue_t * q;
4527 vxlan_main_t * vxm = &vxlan_main;
4531 q = vl_api_client_index_to_input_queue (mp->client_index);
4536 sw_if_index = ntohl(mp->sw_if_index);
4538 if (~0 == sw_if_index) {
4539 pool_foreach (t, vxm->tunnels,
4541 send_vxlan_tunnel_details(t, q, mp->context);
4544 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4545 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4548 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4549 send_vxlan_tunnel_details(t, q, mp->context);
4553 static void vl_api_gre_add_del_tunnel_t_handler
4554 (vl_api_gre_add_del_tunnel_t * mp)
4556 vl_api_gre_add_del_tunnel_reply_t * rmp;
4558 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4561 ip4_main_t * im = &ip4_main;
4562 u32 sw_if_index = ~0;
4564 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_fib_id));
4566 rv = VNET_API_ERROR_NO_SUCH_FIB;
4569 outer_fib_id = p[0];
4571 /* Check src & dst are different */
4572 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4573 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4574 rv = VNET_API_ERROR_SAME_SRC_DST;
4577 memset (a, 0, sizeof (*a));
4579 a->is_add = mp->is_add;
4581 /* ip addresses sent in network byte order */
4582 clib_memcpy(&(a->src), mp->src_address, 4);
4583 clib_memcpy(&(a->dst), mp->dst_address, 4);
4585 a->outer_fib_id = outer_fib_id;
4586 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4589 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4591 rmp->sw_if_index = ntohl (sw_if_index);
4595 static void send_gre_tunnel_details
4596 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4598 vl_api_gre_tunnel_details_t * rmp;
4599 ip4_main_t * im = &ip4_main;
4601 rmp = vl_msg_api_alloc (sizeof (*rmp));
4602 memset (rmp, 0, sizeof (*rmp));
4603 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4604 clib_memcpy(rmp->src_address, &(t->tunnel_src), 4);
4605 clib_memcpy(rmp->dst_address, &(t->tunnel_dst), 4);
4606 rmp->outer_fib_id = htonl(im->fibs[t->outer_fib_index].table_id);
4607 rmp->sw_if_index = htonl(t->sw_if_index);
4608 rmp->context = context;
4610 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4613 static void vl_api_gre_tunnel_dump_t_handler
4614 (vl_api_gre_tunnel_dump_t * mp)
4616 unix_shared_memory_queue_t * q;
4617 gre_main_t * gm = &gre_main;
4621 q = vl_api_client_index_to_input_queue (mp->client_index);
4626 sw_if_index = ntohl(mp->sw_if_index);
4628 if (~0 == sw_if_index) {
4629 pool_foreach (t, gm->tunnels,
4631 send_gre_tunnel_details(t, q, mp->context);
4634 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4635 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4638 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4639 send_gre_tunnel_details(t, q, mp->context);
4644 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4646 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4648 vl_api_l2_patch_add_del_reply_t * rmp;
4649 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4653 VALIDATE_RX_SW_IF_INDEX(mp);
4654 VALIDATE_TX_SW_IF_INDEX(mp);
4656 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4657 ntohl(mp->tx_sw_if_index),
4658 (int)(mp->is_add != 0));
4660 BAD_RX_SW_IF_INDEX_LABEL;
4661 BAD_TX_SW_IF_INDEX_LABEL;
4663 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4667 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4668 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4670 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4672 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4673 u32 encap_fib_index, decap_fib_index;
4676 ip4_main_t * im = &ip4_main;
4677 u32 sw_if_index = ~0;
4680 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4682 rv = VNET_API_ERROR_NO_SUCH_FIB;
4685 encap_fib_index = p[0];
4687 protocol = mp->protocol;
4689 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4690 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4691 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4693 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4696 decap_fib_index = p[0];
4698 decap_fib_index = ntohl(mp->decap_vrf_id);
4701 /* Check src & dst are different */
4702 if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4703 (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4704 rv = VNET_API_ERROR_SAME_SRC_DST;
4707 memset (a, 0, sizeof (*a));
4709 a->is_add = mp->is_add;
4710 a->is_ip6 = mp->is_ipv6;
4711 /* ip addresses sent in network byte order */
4713 clib_memcpy(&(a->local.ip6), mp->local, 16);
4714 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4716 clib_memcpy(&(a->local.ip4), mp->local, 4);
4717 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4719 a->encap_fib_index = encap_fib_index;
4720 a->decap_fib_index = decap_fib_index;
4721 a->protocol = protocol;
4722 a->vni = ntohl(mp->vni);
4723 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4726 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4728 rmp->sw_if_index = ntohl (sw_if_index);
4732 static void send_vxlan_gpe_tunnel_details
4733 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4735 vl_api_vxlan_gpe_tunnel_details_t * rmp;
4736 ip4_main_t * im4 = &ip4_main;
4737 ip6_main_t * im6 = &ip6_main;
4738 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4740 rmp = vl_msg_api_alloc (sizeof (*rmp));
4741 memset (rmp, 0, sizeof (*rmp));
4742 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4744 memcpy(rmp->local, &(t->local.ip6), 16);
4745 memcpy(rmp->remote, &(t->remote.ip6), 16);
4746 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4747 rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
4749 memcpy(rmp->local, &(t->local.ip4), 4);
4750 memcpy(rmp->remote, &(t->remote.ip4), 4);
4751 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4752 rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
4754 rmp->vni = htonl(t->vni);
4755 rmp->protocol = t->protocol;
4756 rmp->sw_if_index = htonl(t->sw_if_index);
4757 rmp->is_ipv6 = is_ipv6;
4758 rmp->context = context;
4760 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4763 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4764 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4766 unix_shared_memory_queue_t * q;
4767 vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
4768 vxlan_gpe_tunnel_t * t;
4771 q = vl_api_client_index_to_input_queue (mp->client_index);
4776 sw_if_index = ntohl(mp->sw_if_index);
4778 if (~0 == sw_if_index) {
4779 pool_foreach (t, vgm->tunnels,
4781 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4784 if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
4785 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
4788 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4789 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4793 /** Used for transferring locators via VPP API */
4794 typedef CLIB_PACKED(struct
4796 u32 sw_if_index; /**< locator sw_if_index */
4797 u8 priority; /**< locator priority */
4798 u8 weight; /**< locator weight */
4802 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4804 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4806 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4808 ls_locator_t *ls_loc;
4810 u8 *locator_name = NULL;
4813 memset(a, 0, sizeof(a[0]));
4815 locator_name = format(0, "%s", mp->locator_set_name);
4817 a->name = locator_name;
4818 a->is_add = mp->is_add;
4821 memset(&locator, 0, sizeof(locator));
4822 for (i = 0; i < mp->locator_num; i++) {
4823 ls_loc = &((ls_locator_t *) mp->locators)[i];
4824 VALIDATE_SW_IF_INDEX(ls_loc);
4826 locator.sw_if_index = htonl(ls_loc->sw_if_index);
4827 locator.priority = ls_loc->priority;
4828 locator.weight = ls_loc->weight;
4830 vec_add1(a->locators, locator);
4833 rv = vnet_lisp_add_del_locator_set(a, &ls_index);
4835 BAD_SW_IF_INDEX_LABEL;
4837 vec_free(locator_name);
4838 vec_free(a->locators);
4840 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4844 vl_api_lisp_add_del_locator_t_handler(
4845 vl_api_lisp_add_del_locator_t *mp)
4847 vl_api_lisp_add_del_locator_reply_t *rmp;
4849 locator_t locator, *locators = NULL;
4850 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4852 u8 *locator_name = NULL;
4854 memset(&locator, 0, sizeof(locator));
4855 memset(a, 0, sizeof(a[0]));
4857 locator.sw_if_index = ntohl(mp->sw_if_index);
4858 locator.priority = mp->priority;
4859 locator.weight = mp->weight;
4861 vec_add1(locators, locator);
4863 locator_name = format(0, "%s", mp->locator_set_name);
4865 a->name = locator_name;
4866 a->locators = locators;
4867 a->is_add = mp->is_add;
4870 rv = vnet_lisp_add_del_locator(a, NULL, &ls_index);
4873 vec_free(locator_name);
4875 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4879 vl_api_lisp_add_del_local_eid_t_handler(
4880 vl_api_lisp_add_del_local_eid_t *mp)
4882 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4883 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4885 ip_prefix_t *prefp = NULL;
4886 ip_address_t *ip_eid = NULL;
4888 u8 * mac = gid_address_mac (&eid);
4890 u32 locator_set_index = ~0, map_index = ~0;
4891 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4893 memset (a, 0, sizeof (a[0]));
4894 memset (&eid, 0, sizeof (eid));
4896 prefp = &gid_address_ippref(&eid);
4897 ip_eid = &ip_prefix_addr(prefp);
4899 switch (mp->eid_type)
4902 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4903 ip_address_set(ip_eid, mp->eid, IP4);
4904 ip_prefix_len(prefp) = mp->prefix_len;
4905 ip_prefix_normalize(prefp);
4908 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4909 ip_address_set(ip_eid, mp->eid, IP6);
4910 ip_prefix_len(prefp) = mp->prefix_len;
4911 ip_prefix_normalize(prefp);
4913 case 2: /* l2 mac */
4914 gid_address_type (&eid) = GID_ADDR_MAC;
4915 clib_memcpy(mac, mp->eid, 6);
4918 rv = VNET_API_ERROR_INVALID_EID_TYPE;
4922 name = format(0, "%s", mp->locator_set_name);
4923 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4925 rv = VNET_API_ERROR_INVALID_VALUE;
4928 locator_set_index = p[0];
4930 /* XXX treat batch configuration */
4931 a->is_add = mp->is_add;
4932 gid_address_vni (&eid) = clib_net_to_host_u32 (mp->vni);
4933 gid_address_copy (&a->eid, &eid);
4934 a->locator_set_index = locator_set_index;
4936 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4940 gid_address_free (&a->eid);
4942 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4946 vl_api_lisp_eid_table_add_del_map_t_handler(
4947 vl_api_lisp_eid_table_add_del_map_t *mp)
4949 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4951 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4952 clib_net_to_host_u32 (mp->dp_table),
4953 mp->is_l2, mp->is_add);
4954 REPLY_MACRO(VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)
4958 lisp_gpe_add_del_fwd_entry_set_address(
4959 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4960 ip_address_t *slocator,
4961 ip_address_t *dlocator,
4964 ip_address_t *ip_eid = NULL;
4965 ip_prefix_t *prefp = NULL;
4967 prefp = &gid_address_ippref(eid);
4968 ip_eid = &ip_prefix_addr(prefp);
4970 if (mp->eid_is_ipv6) {
4971 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4972 sizeof(ip_addr_v6(ip_eid)));
4973 ip_addr_version(ip_eid) = IP6;
4975 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4976 sizeof(ip_addr_v4(ip_eid)));
4977 ip_addr_version(ip_eid) = IP4;
4979 ip_prefix_len(prefp) = mp->eid_prefix_len;
4980 ip_prefix_normalize(prefp);
4982 if (mp->address_is_ipv6) {
4983 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4984 sizeof(ip_addr_v6(slocator)));
4985 ip_addr_version(slocator) = IP6;
4986 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4987 sizeof(ip_addr_v6(dlocator)));
4988 ip_addr_version(dlocator) = IP6;
4990 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4991 sizeof(ip_addr_v4(slocator)));
4992 ip_addr_version(slocator) = IP4;
4993 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4994 sizeof(ip_addr_v4(dlocator)));
4995 ip_addr_version(dlocator) = IP4;
5000 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
5001 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
5003 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5005 ip_address_t slocator, dlocator;
5007 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
5009 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
5011 memset (&a, 0, sizeof(a));
5013 a.is_add = mp->is_add;
5015 a.lcl_loc = slocator;
5016 a.rmt_loc = dlocator;
5017 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
5019 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5023 vl_api_lisp_add_del_map_resolver_t_handler(
5024 vl_api_lisp_add_del_map_resolver_t *mp)
5026 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5028 ip_address_t *ip_addr = NULL;
5029 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
5031 a->is_add = mp->is_add;
5032 ip_addr = &a->address;
5035 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
5036 sizeof(ip_addr_v6(ip_addr)));
5037 ip_addr_version(ip_addr) = IP6;
5039 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
5040 sizeof(ip_addr_v4(ip_addr)));
5041 ip_addr_version(ip_addr) = IP4;
5044 rv = vnet_lisp_add_del_map_resolver (a);
5046 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5050 vl_api_lisp_gpe_enable_disable_t_handler(
5051 vl_api_lisp_gpe_enable_disable_t *mp)
5053 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5055 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
5057 a->is_en = mp->is_en;
5058 vnet_lisp_gpe_enable_disable (a);
5060 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5064 vl_api_lisp_enable_disable_t_handler(
5065 vl_api_lisp_enable_disable_t *mp)
5067 vl_api_lisp_enable_disable_reply_t *rmp;
5070 vnet_lisp_enable_disable (mp->is_en);
5071 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
5075 vl_api_lisp_gpe_add_del_iface_t_handler(
5076 vl_api_lisp_gpe_add_del_iface_t *mp)
5078 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5080 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
5082 a->is_add = mp->is_add;
5083 a->table_id = mp->table_id;
5085 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5087 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5091 vl_api_lisp_pitr_set_locator_set_t_handler(
5092 vl_api_lisp_pitr_set_locator_set_t *mp)
5094 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5098 ls_name = format (0, "%s", mp->ls_name);
5099 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5102 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5106 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5107 (vl_api_lisp_add_del_map_request_itr_rlocs_t *mp)
5109 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5111 u8 * locator_set_name = NULL;
5112 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, * a = &_a;
5114 locator_set_name = format (0, "%s", mp->locator_set_name);
5116 a->is_add = mp->is_add;
5117 a->locator_set_name = locator_set_name;
5119 rv = vnet_lisp_add_del_mreq_itr_rlocs(a);
5121 vec_free(locator_set_name);
5123 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5126 /** Used for transferring locators via VPP API */
5127 typedef CLIB_PACKED(struct
5129 u8 is_ip4; /**< is locator an IPv4 address */
5130 u8 priority; /**< locator priority */
5131 u8 weight; /**< locator weight */
5132 u8 addr[16]; /**< IPv4/IPv6 address */
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 _eid, * eid = &_eid;
5144 ip_prefix_t * eid_pref = &gid_address_ippref(eid);
5146 memset (eid, 0, sizeof (eid[0]));
5147 ip_address_t * eid_addr = &ip_prefix_addr(eid_pref);
5148 ip_prefix_len(eid_pref) = mp->eid_len;
5149 u8 * eid_mac = gid_address_mac (eid);
5150 gid_address_vni (eid) = ntohl (mp->vni);
5152 switch (mp->eid_type)
5155 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5156 ip_address_set (eid_addr, mp->eid, IP4);
5157 ip_prefix_normalize (eid_pref);
5160 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5161 ip_address_set (eid_addr, mp->eid, IP6);
5162 ip_prefix_normalize (eid_pref);
5164 case 2: /* l2 mac */
5165 gid_address_type(eid) = GID_ADDR_MAC;
5166 clib_memcpy (eid_mac, mp->eid, 6);
5169 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5173 for (i = 0; i < mp->rloc_num; i++) {
5174 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
5175 memset(&rloc, 0, sizeof(rloc));
5176 ip_address_set(&gid_address_ip(&rloc.address), &r->addr,
5177 r->is_ip4 ? IP4 : IP6);
5178 gid_address_ippref_len(&rloc.address) = r->is_ip4 ? 32: 128;
5179 gid_address_type(&rloc.address) = GID_ADDR_IP_PREFIX;
5180 rloc.priority = r->priority;
5181 rloc.weight = r->weight;
5182 vec_add1 (rlocs, rloc);
5186 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5187 gid_address_copy(&a->deid, eid);
5189 rv = vnet_lisp_add_del_adjacency (a);
5195 /* NOTE: for now this works as a static remote mapping, i.e.,
5196 * not authoritative and ttl infinite. */
5197 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5201 vnet_lisp_clear_all_remote_adjacencies ();
5206 REPLY_MACRO(VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5210 vl_api_lisp_add_del_adjacency_t_handler (
5211 vl_api_lisp_add_del_adjacency_t *mp)
5213 vl_api_lisp_add_del_adjacency_reply_t * rmp;
5214 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5217 memset(a, 0, sizeof(a[0]));
5219 ip_prefix_t * seid_pref = &gid_address_ippref(&a->seid);
5220 ip_prefix_t * deid_pref = &gid_address_ippref(&a->deid);
5222 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5223 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5224 ip_prefix_len(seid_pref) = mp->seid_len;
5225 ip_prefix_len(deid_pref) = mp->deid_len;
5226 u8 * seid_mac = gid_address_mac (&a->seid);
5227 u8 * deid_mac = gid_address_mac (&a->deid);
5228 gid_address_vni(&a->seid) = ntohl (mp->vni);
5229 gid_address_vni(&a->deid) = ntohl (mp->vni);
5231 switch (mp->eid_type)
5234 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5235 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5236 ip_address_set (seid_addr, mp->seid, IP4);
5237 ip_address_set (deid_addr, mp->deid, IP4);
5238 ip_prefix_normalize (seid_pref);
5239 ip_prefix_normalize (deid_pref);
5242 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5243 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5244 ip_address_set (seid_addr, mp->seid, IP6);
5245 ip_address_set (deid_addr, mp->deid, IP6);
5246 ip_prefix_normalize (seid_pref);
5247 ip_prefix_normalize (deid_pref);
5249 case 2: /* l2 mac */
5250 gid_address_type(&a->seid) = GID_ADDR_MAC;
5251 gid_address_type(&a->deid) = GID_ADDR_MAC;
5252 clib_memcpy (seid_mac, mp->seid, 6);
5253 clib_memcpy (deid_mac, mp->deid, 6);
5256 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5260 a->is_add = mp->is_add;
5261 rv = vnet_lisp_add_del_adjacency (a);
5264 REPLY_MACRO(VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5268 send_lisp_locator_details (lisp_cp_main_t *lcm,
5270 unix_shared_memory_queue_t *q,
5273 vl_api_lisp_locator_details_t *rmp;
5275 rmp = vl_msg_api_alloc (sizeof (*rmp));
5276 memset (rmp, 0, sizeof (*rmp));
5277 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_DETAILS);
5278 rmp->context = context;
5280 rmp->local = loc->local;
5282 rmp->sw_if_index = ntohl(loc->sw_if_index);
5284 rmp->is_ipv6 = gid_address_ip_version(&loc->address);
5285 ip_address_copy_addr(rmp->ip_address, &gid_address_ip(&loc->address));
5287 rmp->priority = loc->priority;
5288 rmp->weight = loc->weight;
5290 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5294 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t *mp)
5296 unix_shared_memory_queue_t * q = 0;
5297 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5298 locator_set_t * lsit = 0;
5299 locator_t * loc = 0;
5300 u32 ls_index = ~0, * locit = 0;
5303 q = vl_api_client_index_to_input_queue (mp->client_index);
5308 ls_index = htonl(mp->locator_set_index);
5310 lsit = pool_elt_at_index(lcm->locator_set_pool, ls_index);
5312 filter = mp->filter;
5313 if (filter && !((1 == filter && lsit->local) ||
5314 (2 == filter && !lsit->local))) {
5318 vec_foreach(locit, lsit->locator_indices) {
5319 loc = pool_elt_at_index(lcm->locator_pool, locit[0]);
5320 send_lisp_locator_details(lcm, loc, q, mp->context);
5325 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
5326 locator_set_t *lsit,
5327 unix_shared_memory_queue_t *q,
5331 vl_api_lisp_locator_set_details_t *rmp;
5334 rmp = vl_msg_api_alloc (sizeof (*rmp));
5335 memset (rmp, 0, sizeof (*rmp));
5336 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
5337 rmp->context = context;
5339 rmp->local = lsit->local;
5340 rmp->locator_set_index= htonl(ls_index);
5342 ASSERT(lsit->name != NULL);
5343 strncpy((char *) rmp->locator_set_name,
5344 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5346 str = format(0, "remote-%d", ls_index);
5347 strncpy((char *) rmp->locator_set_name, (char *) str,
5348 ARRAY_LEN(rmp->locator_set_name) - 1);
5352 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5356 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
5358 unix_shared_memory_queue_t * q = NULL;
5359 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5360 locator_set_t * lsit = NULL;
5364 q = vl_api_client_index_to_input_queue (mp->client_index);
5369 filter = mp->filter;
5371 pool_foreach (lsit, lcm->locator_set_pool,
5373 if (filter && !((1 == filter && lsit->local) ||
5374 (2 == filter && !lsit->local))) {
5379 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5384 send_lisp_eid_table_details (mapping_t *mapit,
5385 unix_shared_memory_queue_t *q,
5386 u32 context, u8 filter)
5388 vl_api_lisp_eid_table_details_t *rmp = NULL;
5389 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5390 locator_set_t *ls = NULL;
5391 gid_address_t *gid = NULL;
5393 ip_prefix_t *ip_prefix = NULL;
5395 ls = pool_elt_at_index (lcm->locator_set_pool,
5396 mapit->locator_set_index);
5412 clib_warning("Filter error, unknown filter: %d\n", filter);
5417 ip_prefix = &gid_address_ippref(gid);
5418 mac = gid_address_mac(gid);
5420 rmp = vl_msg_api_alloc (sizeof (*rmp));
5421 memset (rmp, 0, sizeof (*rmp));
5422 rmp->_vl_msg_id = ntohs(VL_API_LISP_EID_TABLE_DETAILS);
5423 rmp->locator_set_index = mapit->locator_set_index;
5424 rmp->is_local = ls->local;
5425 rmp->ttl = mapit->ttl;
5426 rmp->authoritative = mapit->authoritative;
5428 switch (gid_address_type (gid))
5430 case GID_ADDR_IP_PREFIX:
5431 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5432 if (ip_prefix_version(ip_prefix) == IP4)
5434 rmp->eid_type = 0; /* ipv4 type */
5435 clib_memcpy(rmp->eid, &ip_prefix_v4(ip_prefix),
5436 sizeof(ip_prefix_v4(ip_prefix)));
5440 rmp->eid_type = 1; /* ipv6 type */
5441 clib_memcpy(rmp->eid, &ip_prefix_v6(ip_prefix),
5442 sizeof(ip_prefix_v6(ip_prefix)));
5446 rmp->eid_type = 2; /* l2 mac type */
5447 clib_memcpy(rmp->eid, mac, 6);
5452 rmp->context = context;
5453 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5454 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5458 vl_api_lisp_eid_table_dump_t_handler (
5459 vl_api_lisp_eid_table_dump_t *mp)
5462 unix_shared_memory_queue_t * q = NULL;
5463 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5464 mapping_t * mapit = NULL;
5465 gid_address_t _eid, * eid = &_eid;
5467 q = vl_api_client_index_to_input_queue (mp->client_index);
5473 memset (eid, 0, sizeof (*eid));
5474 gid_address_vni(eid) = ntohl(mp->vni);
5475 switch (mp->eid_type) {
5477 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5478 gid_address_ippref_len(eid) = mp->prefix_length;
5479 gid_address_ip_version(eid) = IP4;
5480 clib_memcpy (&gid_address_ippref(eid), mp->eid, 4);
5483 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5484 gid_address_ippref_len(eid) = mp->prefix_length;
5485 gid_address_ip_version(eid) = IP6;
5486 clib_memcpy (&gid_address_ippref(eid), mp->eid, 16);
5489 gid_address_type(eid) = GID_ADDR_MAC;
5490 clib_memcpy (gid_address_mac(eid), mp->eid, 6);
5493 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5497 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5498 send_lisp_eid_table_details(mapit, q, mp->context, mp->filter);
5500 pool_foreach (mapit, lcm->mapping_pool,
5502 send_lisp_eid_table_details(mapit, q, mp->context,
5509 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5510 unix_shared_memory_queue_t *q,
5513 vl_api_lisp_gpe_tunnel_details_t *rmp;
5514 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5516 rmp = vl_msg_api_alloc (sizeof (*rmp));
5517 memset (rmp, 0, sizeof (*rmp));
5518 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5520 rmp->tunnels = tunnel - lgm->tunnels;
5522 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5523 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5524 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5526 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5527 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5528 rmp->dcap_next = htonl(tunnel->decap_next_index);
5529 rmp->lisp_ver = tunnel->ver_res;
5530 rmp->next_protocol = tunnel->next_protocol;
5531 rmp->flags = tunnel->flags;
5532 rmp->ver_res = tunnel->ver_res;
5533 rmp->res = tunnel->res;
5534 rmp->iid = htonl(tunnel->vni);
5535 rmp->context = context;
5537 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5541 vl_api_lisp_gpe_tunnel_dump_t_handler (
5542 vl_api_lisp_gpe_tunnel_dump_t *mp)
5544 unix_shared_memory_queue_t * q = NULL;
5545 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5546 lisp_gpe_tunnel_t * tunnel = NULL;
5548 if (pool_elts(lgm->tunnels) == 0) {
5552 q = vl_api_client_index_to_input_queue (mp->client_index);
5557 pool_foreach(tunnel, lgm->tunnels,
5559 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5564 send_lisp_map_resolver_details (ip_address_t *ip,
5565 unix_shared_memory_queue_t *q,
5568 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5570 rmp = vl_msg_api_alloc (sizeof (*rmp));
5571 memset (rmp, 0, sizeof (*rmp));
5572 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5574 switch (ip_addr_version(ip)) {
5577 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5582 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5588 rmp->context = context;
5590 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5594 vl_api_lisp_map_resolver_dump_t_handler (
5595 vl_api_lisp_map_resolver_dump_t *mp)
5597 unix_shared_memory_queue_t * q = NULL;
5598 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5599 ip_address_t *ip = NULL;
5601 q = vl_api_client_index_to_input_queue (mp->client_index);
5606 vec_foreach(ip, lcm->map_resolvers) {
5607 send_lisp_map_resolver_details(ip, q, mp->context);
5613 send_eid_table_map_pair (hash_pair_t * p,
5614 unix_shared_memory_queue_t * q,
5617 vl_api_lisp_eid_table_map_details_t * rmp = NULL;
5619 rmp = vl_msg_api_alloc (sizeof (*rmp));
5620 memset (rmp, 0, sizeof (*rmp));
5621 rmp->_vl_msg_id = ntohs(VL_API_LISP_EID_TABLE_MAP_DETAILS);
5623 rmp->vni = clib_host_to_net_u32 (p->key);
5624 rmp->vrf = clib_host_to_net_u32 (p->value[0]);
5625 rmp->context = context;
5626 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5630 vl_api_lisp_eid_table_map_dump_t_handler (
5631 vl_api_lisp_eid_table_map_dump_t *mp)
5633 unix_shared_memory_queue_t * q = NULL;
5634 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5637 q = vl_api_client_index_to_input_queue (mp->client_index);
5641 hash_foreach_pair (p, lcm->table_id_by_vni, {
5642 send_eid_table_map_pair (p, q, mp->context);
5647 vl_api_show_lisp_status_t_handler
5648 (vl_api_show_lisp_status_t *mp)
5650 unix_shared_memory_queue_t * q = NULL;
5651 vl_api_show_lisp_status_reply_t *rmp = NULL;
5654 q = vl_api_client_index_to_input_queue (mp->client_index);
5659 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5661 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5662 rmp->feature_status = vnet_lisp_enable_disable_status ();
5667 vl_api_lisp_get_map_request_itr_rlocs_t_handler (
5668 vl_api_lisp_get_map_request_itr_rlocs_t *mp)
5670 unix_shared_memory_queue_t * q = NULL;
5671 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5672 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5673 locator_set_t * loc_set = 0;
5677 q = vl_api_client_index_to_input_queue (mp->client_index);
5682 if (~0 == lcm->mreq_itr_rlocs) {
5683 tmp_str = format(0, " ");
5685 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5686 tmp_str = format(0, "%s", loc_set->name);
5689 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5691 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5692 ARRAY_LEN(rmp->locator_set_name) - 1);
5699 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5701 unix_shared_memory_queue_t * q = NULL;
5702 vl_api_show_lisp_pitr_reply_t * rmp = NULL;
5703 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5705 locator_set_t * ls = 0;
5709 q = vl_api_client_index_to_input_queue (mp->client_index);
5714 if (~0 == lcm->pitr_map_index) {
5715 tmp_str = format(0, "N/A");
5717 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5718 if (~0 != m->locator_set_index) {
5719 ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5720 tmp_str = format(0, "%s", ls->name);
5722 tmp_str = format(0, "N/A");
5725 vec_add1(tmp_str, 0);
5727 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5729 rmp->status = lcm->lisp_pitr;
5730 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5731 ARRAY_LEN(rmp->locator_set_name) - 1);
5736 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5738 vl_api_interface_name_renumber_reply_t * rmp;
5741 VALIDATE_SW_IF_INDEX(mp);
5743 rv = vnet_interface_name_renumber
5744 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5746 BAD_SW_IF_INDEX_LABEL;
5748 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5751 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5752 u32 sw_if_index, u32 address)
5754 vpe_api_main_t * am = &vpe_api_main;
5755 vlib_main_t * vm = am->vlib_main;
5756 vl_api_ip4_arp_event_t * event;
5757 static f64 arp_event_last_time;
5758 f64 now = vlib_time_now (vm);
5760 if (pool_is_free_index (am->arp_events, pool_index))
5763 event = pool_elt_at_index (am->arp_events, pool_index);
5764 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5765 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5766 } else { /* same mac */
5767 if ((sw_if_index == event->sw_if_index) &&
5769 /* for BD case, also check IP address with 10 sec timeout */
5770 ((address == event->address) &&
5771 ((now - arp_event_last_time) < 10.0))))
5775 arp_event_last_time = now;
5776 event->sw_if_index = sw_if_index;
5777 if (address) event->address = address;
5781 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5783 vpe_api_main_t * am = &vpe_api_main;
5785 if (pool_is_free_index (am->arp_events, pool_index))
5788 pool_put_index (am->arp_events, pool_index);
5793 vl_api_want_ip4_arp_events_t_handler
5794 (vl_api_want_ip4_arp_events_t * mp)
5796 vpe_api_main_t * am = &vpe_api_main;
5797 vnet_main_t * vnm = vnet_get_main();
5798 vl_api_want_ip4_arp_events_reply_t *rmp;
5799 vl_api_ip4_arp_event_t * event;
5802 if (mp->enable_disable) {
5803 pool_get (am->arp_events, event);
5804 memset (event, 0, sizeof (*event));
5806 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5807 event->client_index = mp->client_index;
5808 event->context = mp->context;
5809 event->address = mp->address;
5810 event->pid = mp->pid;
5812 rv = vnet_add_del_ip4_arp_change_event
5813 (vnm, arp_change_data_callback,
5815 &mp->address /* addr, in net byte order */,
5816 vpe_resolver_process_node.index,
5817 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5819 rv = vnet_add_del_ip4_arp_change_event
5820 (vnm, arp_change_delete_callback,
5822 &mp->address /* addr, in net byte order */,
5823 vpe_resolver_process_node.index,
5824 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5826 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5829 static void vl_api_input_acl_set_interface_t_handler
5830 (vl_api_input_acl_set_interface_t * mp)
5832 vlib_main_t *vm = vlib_get_main();
5833 vl_api_input_acl_set_interface_reply_t * rmp;
5835 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5837 ip4_table_index = ntohl(mp->ip4_table_index);
5838 ip6_table_index = ntohl(mp->ip6_table_index);
5839 l2_table_index = ntohl(mp->l2_table_index);
5840 sw_if_index = ntohl(mp->sw_if_index);
5842 VALIDATE_SW_IF_INDEX(mp);
5844 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5845 ip6_table_index, l2_table_index,
5848 BAD_SW_IF_INDEX_LABEL;
5850 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5853 static void vl_api_ipsec_spd_add_del_t_handler
5854 (vl_api_ipsec_spd_add_del_t * mp)
5857 clib_warning ("unimplemented");
5860 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5861 vl_api_ipsec_spd_add_del_reply_t * rmp;
5865 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5867 rv = VNET_API_ERROR_UNIMPLEMENTED;
5870 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5874 static void vl_api_ipsec_interface_add_del_spd_t_handler
5875 (vl_api_ipsec_interface_add_del_spd_t * mp)
5877 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5878 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5880 u32 sw_if_index __attribute__((unused));
5881 u32 spd_id __attribute__((unused));
5883 sw_if_index = ntohl(mp->sw_if_index);
5884 spd_id = ntohl(mp->spd_id);
5886 VALIDATE_SW_IF_INDEX(mp);
5889 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5891 rv = VNET_API_ERROR_UNIMPLEMENTED;
5894 BAD_SW_IF_INDEX_LABEL;
5896 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5899 static void vl_api_ipsec_spd_add_del_entry_t_handler
5900 (vl_api_ipsec_spd_add_del_entry_t * mp)
5902 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5903 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5909 memset(&p, 0, sizeof(p));
5911 p.id = ntohl(mp->spd_id);
5912 p.priority = ntohl(mp->priority);
5913 p.is_outbound = mp->is_outbound;
5914 p.is_ipv6 = mp->is_ipv6;
5916 if (mp->is_ipv6 || mp->is_ip_any) {
5917 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5918 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5919 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5920 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5922 clib_memcpy(&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5923 clib_memcpy(&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5924 clib_memcpy(&p.laddr.start.ip4.data, mp->local_address_start, 4);
5925 clib_memcpy(&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5927 p.protocol = mp->protocol;
5928 p.rport.start = ntohs(mp->remote_port_start);
5929 p.rport.stop = ntohs(mp->remote_port_stop);
5930 p.lport.start = ntohs(mp->local_port_start);
5931 p.lport.stop = ntohs(mp->local_port_stop);
5932 /* policy action resolve unsupported */
5933 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5934 clib_warning("unsupported action: 'resolve'");
5935 rv = VNET_API_ERROR_UNIMPLEMENTED;
5938 p.policy = mp->policy;
5939 p.sa_id = ntohl(mp->sa_id);
5941 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5945 if (mp->is_ip_any) {
5947 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5950 rv = VNET_API_ERROR_UNIMPLEMENTED;
5955 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5958 static void vl_api_ipsec_sad_add_del_entry_t_handler
5959 (vl_api_ipsec_sad_add_del_entry_t * mp)
5961 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5962 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5967 memset(&sa, 0, sizeof(sa));
5969 sa.id = ntohl(mp->sad_id);
5970 sa.spi = ntohl(mp->spi);
5971 /* security protocol AH unsupported */
5972 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5973 clib_warning("unsupported security protocol 'AH'");
5974 rv = VNET_API_ERROR_UNIMPLEMENTED;
5977 sa.protocol = mp->protocol;
5978 /* check for unsupported crypto-alg */
5979 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5980 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5981 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5982 mp->crypto_algorithm);
5983 rv = VNET_API_ERROR_UNIMPLEMENTED;
5986 sa.crypto_alg = mp->crypto_algorithm;
5987 sa.crypto_key_len = mp->crypto_key_length;
5988 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5989 /* check for unsupported integ-alg */
5990 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5991 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5992 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5993 mp->integrity_algorithm);
5994 rv = VNET_API_ERROR_UNIMPLEMENTED;
5997 sa.integ_alg = mp->integrity_algorithm;
5998 sa.integ_key_len = mp->integrity_key_length;
5999 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
6000 sa.use_esn = mp->use_extended_sequence_number;
6001 sa.is_tunnel = mp->is_tunnel;
6002 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6003 if (sa.is_tunnel_ip6) {
6004 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6005 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6007 clib_memcpy(&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6008 clib_memcpy(&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6011 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
6013 rv = VNET_API_ERROR_UNIMPLEMENTED;
6018 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6022 vl_api_ikev2_profile_add_del_t_handler
6023 (vl_api_ikev2_profile_add_del_t * mp)
6025 vl_api_ikev2_profile_add_del_reply_t * rmp;
6029 vlib_main_t * vm = vlib_get_main();
6030 clib_error_t * error;
6031 u8 * tmp = format(0, "%s", mp->name);
6032 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
6035 rv = VNET_API_ERROR_UNSPECIFIED;
6037 rv = VNET_API_ERROR_UNIMPLEMENTED;
6040 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6044 vl_api_ikev2_profile_set_auth_t_handler
6045 (vl_api_ikev2_profile_set_auth_t * mp)
6047 vl_api_ikev2_profile_set_auth_reply_t * rmp;
6051 vlib_main_t * vm = vlib_get_main();
6052 clib_error_t * error;
6053 u8 * tmp = format(0, "%s", mp->name);
6054 u8 * data = vec_new (u8, mp->data_len);
6055 clib_memcpy(data, mp->data, mp->data_len);
6056 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
6060 rv = VNET_API_ERROR_UNSPECIFIED;
6062 rv = VNET_API_ERROR_UNIMPLEMENTED;
6065 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6069 vl_api_ikev2_profile_set_id_t_handler
6070 (vl_api_ikev2_profile_set_id_t * mp)
6072 vl_api_ikev2_profile_add_del_reply_t * rmp;
6076 vlib_main_t * vm = vlib_get_main();
6077 clib_error_t * error;
6078 u8 * tmp = format(0, "%s", mp->name);
6079 u8 * data = vec_new (u8, mp->data_len);
6080 clib_memcpy(data, mp->data, mp->data_len);
6081 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
6085 rv = VNET_API_ERROR_UNSPECIFIED;
6087 rv = VNET_API_ERROR_UNIMPLEMENTED;
6090 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6094 vl_api_ikev2_profile_set_ts_t_handler
6095 (vl_api_ikev2_profile_set_ts_t * mp)
6097 vl_api_ikev2_profile_set_ts_reply_t * rmp;
6101 vlib_main_t * vm = vlib_get_main();
6102 clib_error_t * error;
6103 u8 * tmp = format(0, "%s", mp->name);
6104 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
6105 mp->end_port, (ip4_address_t) mp->start_addr,
6106 (ip4_address_t) mp->end_addr, mp->is_local);
6109 rv = VNET_API_ERROR_UNSPECIFIED;
6111 rv = VNET_API_ERROR_UNIMPLEMENTED;
6114 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6118 vl_api_ikev2_set_local_key_t_handler
6119 (vl_api_ikev2_set_local_key_t * mp)
6121 vl_api_ikev2_profile_set_ts_reply_t * rmp;
6125 vlib_main_t * vm = vlib_get_main();
6126 clib_error_t * error;
6128 error = ikev2_set_local_key(vm, mp->key_file);
6130 rv = VNET_API_ERROR_UNSPECIFIED;
6132 rv = VNET_API_ERROR_UNIMPLEMENTED;
6135 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6139 vl_api_map_add_domain_t_handler
6140 (vl_api_map_add_domain_t * mp)
6142 vl_api_map_add_domain_reply_t * rmp;
6145 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6146 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
6147 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
6148 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
6149 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
6151 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6153 rmp->index = ntohl(index);
6158 vl_api_map_del_domain_t_handler
6159 (vl_api_map_del_domain_t * mp)
6161 vl_api_map_del_domain_reply_t * rmp;
6164 rv = map_delete_domain(ntohl(mp->index));
6166 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
6170 vl_api_map_add_del_rule_t_handler
6171 (vl_api_map_add_del_rule_t * mp)
6173 vl_api_map_del_domain_reply_t * rmp;
6176 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
6178 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
6182 vl_api_map_domain_dump_t_handler
6183 (vl_api_map_domain_dump_t * mp)
6185 vl_api_map_domain_details_t * rmp;
6186 map_main_t *mm = &map_main;
6188 unix_shared_memory_queue_t * q;
6190 if (pool_elts (mm->domains) == 0)
6193 q = vl_api_client_index_to_input_queue (mp->client_index);
6198 pool_foreach(d, mm->domains, ({
6199 /* Make sure every field is initiated (or don't skip the memset()) */
6200 rmp = vl_msg_api_alloc (sizeof (*rmp));
6201 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6202 rmp->domain_index = htonl(d - mm->domains);
6203 rmp->ea_bits_len = d->ea_bits_len;
6204 rmp->psid_offset = d->psid_offset;
6205 rmp->psid_length = d->psid_length;
6206 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6207 rmp->ip4_prefix_len = d->ip4_prefix_len;
6208 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6209 rmp->ip6_prefix_len = d->ip6_prefix_len;
6210 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6211 rmp->ip6_src_len = d->ip6_src_len;
6212 rmp->mtu = htons(d->mtu);
6213 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6214 rmp->context = mp->context;
6216 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6221 vl_api_map_rule_dump_t_handler
6222 (vl_api_map_rule_dump_t * mp)
6224 unix_shared_memory_queue_t * q;
6227 vl_api_map_rule_details_t * rmp;
6228 map_main_t *mm = &map_main;
6229 u32 domain_index = ntohl(mp->domain_index);
6232 if (pool_elts (mm->domains) == 0)
6235 d = pool_elt_at_index(mm->domains, domain_index);
6236 if (!d || !d->rules) {
6240 q = vl_api_client_index_to_input_queue (mp->client_index);
6245 for (i = 0; i < (0x1 << d->psid_length); i++) {
6247 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
6250 rmp = vl_msg_api_alloc(sizeof(*rmp));
6251 memset(rmp, 0, sizeof(*rmp));
6252 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
6253 rmp->psid = htons(i);
6254 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
6255 rmp->context = mp->context;
6256 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6261 vl_api_map_summary_stats_t_handler (
6262 vl_api_map_summary_stats_t *mp)
6264 vl_api_map_summary_stats_reply_t *rmp;
6265 vlib_combined_counter_main_t *cm;
6268 u64 total_pkts[VLIB_N_RX_TX];
6269 u64 total_bytes[VLIB_N_RX_TX];
6270 map_main_t *mm = &map_main;
6271 unix_shared_memory_queue_t *q =
6272 vl_api_client_index_to_input_queue(mp->client_index);
6277 rmp = vl_msg_api_alloc (sizeof (*rmp));
6278 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
6279 rmp->context = mp->context;
6282 memset (total_pkts, 0, sizeof (total_pkts));
6283 memset (total_bytes, 0, sizeof (total_bytes));
6285 map_domain_counter_lock (mm);
6286 vec_foreach(cm, mm->domain_counters) {
6287 which = cm - mm->domain_counters;
6289 for (i = 0; i < vec_len(cm->maxi); i++) {
6290 vlib_get_combined_counter (cm, i, &v);
6291 total_pkts[which] += v.packets;
6292 total_bytes[which] += v.bytes;
6296 map_domain_counter_unlock (mm);
6298 /* Note: in network byte order! */
6299 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
6300 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
6301 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
6302 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
6303 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
6304 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6305 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));
6306 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));
6308 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6311 static void vl_api_ipsec_sa_set_key_t_handler
6312 (vl_api_ipsec_sa_set_key_t * mp)
6314 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
6315 vl_api_ipsec_sa_set_key_reply_t *rmp;
6319 sa.id = ntohl(mp->sa_id);
6320 sa.crypto_key_len = mp->crypto_key_length;
6321 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
6322 sa.integ_key_len = mp->integrity_key_length;
6323 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
6325 rv = ipsec_set_sa_key(vm, &sa);
6327 rv = VNET_API_ERROR_UNIMPLEMENTED;
6330 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
6333 static void vl_api_cop_interface_enable_disable_t_handler
6334 (vl_api_cop_interface_enable_disable_t * mp)
6336 vl_api_cop_interface_enable_disable_reply_t * rmp;
6338 u32 sw_if_index = ntohl(mp->sw_if_index);
6341 VALIDATE_SW_IF_INDEX(mp);
6343 enable_disable = (int) mp->enable_disable;
6345 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6347 BAD_SW_IF_INDEX_LABEL;
6349 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6352 static void vl_api_cop_whitelist_enable_disable_t_handler
6353 (vl_api_cop_whitelist_enable_disable_t * mp)
6355 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
6356 cop_whitelist_enable_disable_args_t _a, *a=&_a;
6357 u32 sw_if_index = ntohl(mp->sw_if_index);
6360 VALIDATE_SW_IF_INDEX(mp);
6362 a->sw_if_index = sw_if_index;
6365 a->default_cop = mp->default_cop;
6366 a->fib_id = ntohl(mp->fib_id);
6368 rv = cop_whitelist_enable_disable (a);
6370 BAD_SW_IF_INDEX_LABEL;
6372 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6375 static void vl_api_get_node_graph_t_handler
6376 (vl_api_get_node_graph_t * mp)
6380 api_main_t * am = &api_main;
6381 vlib_main_t * vm = vlib_get_main();
6383 vl_api_get_node_graph_reply_t * rmp;
6385 pthread_mutex_lock (&am->vlib_rp->mutex);
6386 oldheap = svm_push_data_heap (am->vlib_rp);
6389 * Keep the number of memcpy ops to a minimum (e.g. 1).
6391 vec_validate (vector, 16384);
6392 vec_reset_length (vector);
6395 vector = vlib_node_serialize (&vm->node_main, vector,
6396 (u32)~0 /* all threads */,
6397 1 /* include nexts */,
6398 1 /* include stats */);
6400 svm_pop_heap (oldheap);
6401 pthread_mutex_unlock (&am->vlib_rp->mutex);
6403 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6404 rmp->reply_in_shmem = (uword) vector);
6407 static void vl_api_trace_profile_add_t_handler
6408 (vl_api_trace_profile_add_t *mp)
6411 vl_api_trace_profile_add_reply_t * rmp;
6412 clib_error_t *error;
6414 /* Ignoring the profile id as currently a single profile
6416 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
6417 ntohl(mp->node_id), ntohl(mp->trace_app_data),
6418 mp->pow_enable, mp->trace_tsp,
6421 clib_error_report(error);
6422 rv = clib_error_get_code(error);
6425 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
6428 static void vl_api_trace_profile_apply_t_handler
6429 (vl_api_trace_profile_apply_t *mp)
6432 vl_api_trace_profile_apply_reply_t * rmp;
6434 if (mp->enable != 0) {
6435 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
6436 ntohl(mp->prefix_length),
6438 mp->trace_op == IOAM_HBYH_ADD,
6439 mp->trace_op == IOAM_HBYH_POP,
6440 mp->trace_op == IOAM_HBYH_MOD);
6442 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6444 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
6447 static void vl_api_trace_profile_del_t_handler
6448 (vl_api_trace_profile_del_t *mp)
6451 vl_api_trace_profile_del_reply_t * rmp;
6452 clib_error_t *error;
6454 error = clear_ioam_rewrite_fn();
6456 clib_error_report(error);
6457 rv = clib_error_get_code(error);
6460 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
6464 vl_api_af_packet_create_t_handler
6465 (vl_api_af_packet_create_t *mp)
6467 vlib_main_t *vm = vlib_get_main();
6468 vl_api_af_packet_create_reply_t *rmp;
6470 u8 *host_if_name = NULL;
6473 host_if_name = format(0, "%s", mp->host_if_name);
6474 vec_add1 (host_if_name, 0);
6476 rv = af_packet_create_if(vm, host_if_name,
6477 mp->use_random_hw_addr ? 0 : mp->hw_addr, &sw_if_index);
6479 vec_free(host_if_name);
6481 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6482 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index));
6486 vl_api_af_packet_delete_t_handler
6487 (vl_api_af_packet_delete_t *mp)
6489 vlib_main_t * vm = vlib_get_main();
6490 vl_api_af_packet_delete_reply_t *rmp;
6492 u8 *host_if_name = NULL;
6494 host_if_name = format(0, "%s", mp->host_if_name);
6495 vec_add1 (host_if_name, 0);
6497 rv = af_packet_delete_if(vm, host_if_name);
6499 vec_free(host_if_name);
6501 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
6505 vl_api_policer_add_del_t_handler
6506 (vl_api_policer_add_del_t *mp)
6508 vlib_main_t * vm = vlib_get_main();
6509 vl_api_policer_add_del_reply_t *rmp;
6512 sse2_qos_pol_cfg_params_st cfg;
6513 clib_error_t * error;
6516 name = format(0, "%s", mp->name);
6518 memset (&cfg, 0, sizeof (cfg));
6520 cfg.rnd_type = mp->round_type;
6521 cfg.rate_type = mp->rate_type;
6522 cfg.rb.kbps.cir_kbps = mp->cir;
6523 cfg.rb.kbps.eir_kbps = mp->eir;
6524 cfg.rb.kbps.cb_bytes = mp->cb;
6525 cfg.rb.kbps.eb_bytes = mp->eb;
6526 cfg.conform_action.action_type = mp->conform_action_type;
6527 cfg.conform_action.dscp = mp->conform_dscp;
6528 cfg.exceed_action.action_type = mp->exceed_action_type;
6529 cfg.exceed_action.dscp = mp->exceed_dscp;
6530 cfg.violate_action.action_type = mp->violate_action_type;
6531 cfg.violate_action.dscp = mp->violate_dscp;
6532 cfg.color_aware = mp->color_aware;
6534 error = policer_add_del(vm, name, &cfg, &policer_index, mp->is_add);
6537 rv = VNET_API_ERROR_UNSPECIFIED;
6539 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6541 if (rv == 0 && mp->is_add)
6542 rmp->policer_index = ntohl(policer_index);
6544 rmp->policer_index = ~0;
6549 send_policer_details (u8 *name,
6550 sse2_qos_pol_cfg_params_st *config,
6551 policer_read_response_type_st *templ,
6552 unix_shared_memory_queue_t *q,
6555 vl_api_policer_details_t * mp;
6557 mp = vl_msg_api_alloc (sizeof (*mp));
6558 memset (mp, 0, sizeof (*mp));
6559 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6560 mp->context = context;
6561 mp->cir = htonl(config->rb.kbps.cir_kbps);
6562 mp->eir = htonl(config->rb.kbps.eir_kbps);
6563 mp->cb = htonl(config->rb.kbps.cb_bytes);
6564 mp->eb = htonl(config->rb.kbps.eb_bytes);
6565 mp->rate_type = config->rate_type;
6566 mp->round_type = config->rnd_type;
6567 mp->type = config->rfc;
6568 mp->conform_action_type = config->conform_action.action_type;
6569 mp->conform_dscp = config->conform_action.dscp;
6570 mp->exceed_action_type = config->exceed_action.action_type;
6571 mp->exceed_dscp = config->exceed_action.dscp;
6572 mp->violate_action_type = config->violate_action.action_type;
6573 mp->violate_dscp = config->violate_action.dscp;
6574 mp->single_rate = templ->single_rate ? 1 : 0;
6575 mp->color_aware = templ->color_aware ? 1 : 0;
6576 mp->scale = htonl(templ->scale);
6577 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6578 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6579 mp->current_limit = htonl(templ->current_limit);
6580 mp->current_bucket = htonl(templ->current_bucket);
6581 mp->extended_limit = htonl(templ->extended_limit);
6582 mp->extended_bucket = htonl(templ->extended_bucket);
6583 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6585 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6587 vl_msg_api_send_shmem (q, (u8 *)&mp);
6591 vl_api_policer_dump_t_handler
6592 (vl_api_policer_dump_t *mp)
6594 unix_shared_memory_queue_t * q;
6595 vnet_policer_main_t * pm = &vnet_policer_main;
6599 u8 * match_name = 0;
6601 sse2_qos_pol_cfg_params_st *config;
6602 policer_read_response_type_st *templ;
6604 q = vl_api_client_index_to_input_queue (mp->client_index);
6608 if (mp->match_name_valid) {
6609 match_name = format(0, "%s%c", mp->match_name, 0);
6612 if (mp->match_name_valid) {
6613 p = hash_get_mem (pm->policer_config_by_name, match_name);
6616 config = pool_elt_at_index (pm->configs, pool_index);
6617 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6618 send_policer_details(match_name, config, templ, q, mp->context);
6621 hash_foreach_pair (hp, pm->policer_config_by_name,
6623 name = (u8 *) hp->key;
6624 pool_index = hp->value[0];
6625 config = pool_elt_at_index (pm->configs, pool_index);
6626 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6627 send_policer_details(name, config, templ, q, mp->context);
6633 vl_api_policer_classify_set_interface_t_handler
6634 (vl_api_policer_classify_set_interface_t * mp)
6636 vlib_main_t *vm = vlib_get_main();
6637 vl_api_policer_classify_set_interface_reply_t * rmp;
6639 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6641 ip4_table_index = ntohl(mp->ip4_table_index);
6642 ip6_table_index = ntohl(mp->ip6_table_index);
6643 l2_table_index = ntohl(mp->l2_table_index);
6644 sw_if_index = ntohl(mp->sw_if_index);
6646 VALIDATE_SW_IF_INDEX(mp);
6648 rv = vnet_set_policer_classify_intfc(vm, sw_if_index, ip4_table_index,
6649 ip6_table_index, l2_table_index,
6652 BAD_SW_IF_INDEX_LABEL;
6654 REPLY_MACRO(VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
6658 send_policer_classify_details (u32 sw_if_index,
6660 unix_shared_memory_queue_t *q,
6663 vl_api_policer_classify_details_t * mp;
6665 mp = vl_msg_api_alloc (sizeof (*mp));
6666 memset (mp, 0, sizeof (*mp));
6667 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
6668 mp->context = context;
6669 mp->sw_if_index= htonl(sw_if_index);
6670 mp->table_index= htonl(table_index);
6672 vl_msg_api_send_shmem (q, (u8 *)&mp);
6676 vl_api_policer_classify_dump_t_handler
6677 (vl_api_policer_classify_dump_t *mp)
6679 unix_shared_memory_queue_t * q;
6680 policer_classify_main_t * pcm = &policer_classify_main;
6684 q = vl_api_client_index_to_input_queue (mp->client_index);
6688 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6690 if (vec_len(vec_tbl)) {
6691 for (i = 0; i < vec_len (vec_tbl); i++) {
6692 if (vec_elt(vec_tbl, i) == ~0)
6695 send_policer_classify_details(i, vec_elt(vec_tbl, i), q,
6702 vl_api_netmap_create_t_handler
6703 (vl_api_netmap_create_t *mp)
6705 vlib_main_t *vm = vlib_get_main();
6706 vl_api_netmap_create_reply_t *rmp;
6710 if_name = format(0, "%s", mp->netmap_if_name);
6711 vec_add1 (if_name, 0);
6713 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6714 mp->is_pipe, mp->is_master, 0);
6718 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6722 vl_api_netmap_delete_t_handler
6723 (vl_api_netmap_delete_t *mp)
6725 vlib_main_t * vm = vlib_get_main();
6726 vl_api_netmap_delete_reply_t *rmp;
6730 if_name = format(0, "%s", mp->netmap_if_name);
6731 vec_add1 (if_name, 0);
6733 rv = netmap_delete_if(vm, if_name);
6737 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6740 static void vl_api_mpls_gre_tunnel_details_t_handler (
6741 vl_api_mpls_gre_tunnel_details_t * mp)
6743 clib_warning ("BUG");
6746 static void send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
6747 unix_shared_memory_queue_t *q,
6748 mpls_gre_tunnel_t * gt,
6752 vl_api_mpls_gre_tunnel_details_t * mp;
6754 mp = vl_msg_api_alloc (sizeof (*mp));
6755 memset (mp, 0, sizeof (*mp));
6756 mp->_vl_msg_id = ntohs(VL_API_MPLS_GRE_TUNNEL_DETAILS);
6757 mp->context = context;
6760 mp->tunnel_index = htonl(index);
6761 mp->tunnel_src = gt->tunnel_src.as_u32;
6762 mp->tunnel_dst = gt->tunnel_dst.as_u32;
6763 mp->intfc_address = gt->intfc_address.as_u32;
6764 mp->mask_width = htonl(gt->mask_width);
6765 mp->inner_fib_index = htonl(gt->inner_fib_index);
6766 mp->outer_fib_index = htonl(gt->outer_fib_index);
6767 mp->encap_index = htonl(gt->encap_index);
6768 mp->hw_if_index = htonl(gt->hw_if_index);
6769 mp->l2_only = htonl(gt->l2_only);
6772 mpls_main_t * mm = &mpls_main;
6777 e = pool_elt_at_index (mm->encaps, gt->encap_index);
6778 len = vec_len (e->labels);
6779 mp->nlabels = htonl(len);
6781 for (i = 0; i < len; i++) {
6782 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6783 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6786 vl_msg_api_send_shmem (q, (u8 *)&mp);
6790 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t *mp)
6792 vpe_api_main_t * am = &vpe_api_main;
6793 unix_shared_memory_queue_t * q;
6794 vlib_main_t * vm = &vlib_global_main;
6795 mpls_main_t * mm = &mpls_main;
6796 mpls_gre_tunnel_t * gt;
6797 u32 index = ntohl(mp->tunnel_index);
6799 q = vl_api_client_index_to_input_queue (mp->client_index);
6803 if (pool_elts (mm->gre_tunnels)) {
6804 if(mp->tunnel_index >= 0) {
6805 vlib_cli_output (vm, "MPLS-GRE tunnel %u", index);
6806 gt = pool_elt_at_index (mm->gre_tunnels, index);
6807 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6809 vlib_cli_output (vm, "MPLS-GRE tunnels");
6810 pool_foreach (gt, mm->gre_tunnels,
6812 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6816 vlib_cli_output (vm, "No MPLS-GRE tunnels");
6820 static void vl_api_mpls_eth_tunnel_details_t_handler (
6821 vl_api_mpls_eth_tunnel_details_t * mp)
6823 clib_warning ("BUG");
6826 static void send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
6827 unix_shared_memory_queue_t *q,
6828 mpls_eth_tunnel_t * et,
6832 vl_api_mpls_eth_tunnel_details_t * mp;
6834 mp = vl_msg_api_alloc (sizeof (*mp));
6835 memset (mp, 0, sizeof (*mp));
6836 mp->_vl_msg_id = ntohs(VL_API_MPLS_ETH_TUNNEL_DETAILS);
6837 mp->context = context;
6840 mp->tunnel_index = htonl(index);
6841 memcpy(mp->tunnel_dst_mac, et->tunnel_dst, 6);
6842 mp->intfc_address = et->intfc_address.as_u32;
6843 mp->tx_sw_if_index = htonl(et->tx_sw_if_index);
6844 mp->inner_fib_index = htonl(et->inner_fib_index);
6845 mp->mask_width = htonl(et->mask_width);
6846 mp->encap_index = htonl(et->encap_index);
6847 mp->hw_if_index = htonl(et->hw_if_index);
6848 mp->l2_only = htonl(et->l2_only);
6851 mpls_main_t * mm = &mpls_main;
6856 e = pool_elt_at_index (mm->encaps, et->encap_index);
6857 len = vec_len (e->labels);
6858 mp->nlabels = htonl(len);
6860 for (i = 0; i < len; i++) {
6861 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6862 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6865 vl_msg_api_send_shmem (q, (u8 *)&mp);
6869 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t *mp)
6871 vpe_api_main_t * am = &vpe_api_main;
6872 unix_shared_memory_queue_t * q;
6873 vlib_main_t * vm = &vlib_global_main;
6874 mpls_main_t * mm = &mpls_main;
6875 mpls_eth_tunnel_t * et;
6876 u32 index = ntohl(mp->tunnel_index);
6878 q = vl_api_client_index_to_input_queue (mp->client_index);
6882 clib_warning("Received mpls_eth_tunnel_dump");
6883 clib_warning("Received tunnel index: %u from client %u", index, mp->client_index);
6885 if (pool_elts (mm->eth_tunnels)) {
6886 if(mp->tunnel_index >= 0) {
6887 vlib_cli_output (vm, "MPLS-Ethernet tunnel %u", index);
6888 et = pool_elt_at_index (mm->eth_tunnels, index);
6889 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6891 clib_warning("MPLS-Ethernet tunnels");
6892 pool_foreach (et, mm->eth_tunnels,
6894 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6898 clib_warning("No MPLS-Ethernet tunnels");
6902 static void vl_api_mpls_fib_encap_details_t_handler (
6903 vl_api_mpls_fib_encap_details_t * mp)
6905 clib_warning ("BUG");
6908 static void send_mpls_fib_encap_details (vpe_api_main_t * am,
6909 unix_shared_memory_queue_t *q,
6913 vl_api_mpls_fib_encap_details_t * mp;
6915 mp = vl_msg_api_alloc (sizeof (*mp));
6916 memset (mp, 0, sizeof (*mp));
6917 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_ENCAP_DETAILS);
6918 mp->context = context;
6920 mp->fib_index = htonl(s->fib_index);
6921 mp->entry_index = htonl(s->entry_index);
6923 mp->s_bit = htonl(s->s_bit);
6925 mpls_main_t * mm = &mpls_main;
6930 e = pool_elt_at_index (mm->encaps, s->entry_index);
6931 len = vec_len (e->labels);
6932 mp->nlabels = htonl(len);
6934 for (i = 0; i < len; i++) {
6935 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6936 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6939 vl_msg_api_send_shmem (q, (u8 *)&mp);
6943 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t *mp)
6945 vpe_api_main_t * am = &vpe_api_main;
6946 unix_shared_memory_queue_t * q;
6947 vlib_main_t * vm = &vlib_global_main;
6950 show_mpls_fib_t *records = 0;
6952 mpls_main_t * mm = &mpls_main;
6953 ip4_main_t * im = &ip4_main;
6956 q = vl_api_client_index_to_input_queue (mp->client_index);
6960 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
6962 vec_add2 (records, s, 1);
6963 s->fib_index = (u32)(key>>32);
6964 s->dest = (u32)(key & 0xFFFFFFFF);
6965 s->entry_index = (u32) value;
6968 if (0 == vec_len(records)) {
6969 vlib_cli_output(vm, "MPLS encap table empty");
6973 /* sort output by dst address within fib */
6974 vec_sort_with_function(records, mpls_dest_cmp);
6975 vec_sort_with_function(records, mpls_fib_index_cmp);
6976 vlib_cli_output(vm, "MPLS encap table");
6977 vlib_cli_output(vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
6978 vec_foreach (s, records)
6980 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
6981 vlib_cli_output(vm, "%=6d%=16U%=16U", rx_fib->table_id,
6982 format_ip4_address, &s->dest, format_mpls_encap_index, mm,
6984 send_mpls_fib_encap_details (am, q, s, mp->context);
6991 static void vl_api_mpls_fib_decap_details_t_handler (
6992 vl_api_mpls_fib_decap_details_t * mp)
6994 clib_warning ("BUG");
6997 static void send_mpls_fib_decap_details (vpe_api_main_t * am,
6998 unix_shared_memory_queue_t *q,
7005 vl_api_mpls_fib_decap_details_t * mp;
7007 mp = vl_msg_api_alloc (sizeof (*mp));
7008 memset (mp, 0, sizeof (*mp));
7009 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_DECAP_DETAILS);
7010 mp->context = context;
7012 mp->fib_index = htonl(s->fib_index);
7013 mp->entry_index = htonl(s->entry_index);
7015 mp->s_bit = htonl(s->s_bit);
7016 mp->label = htonl(s->label);
7017 mp->rx_table_id = htonl(rx_table_id);
7018 mp->tx_table_id = htonl(tx_table_id);
7019 strncpy ((char *) mp->swif_tag,
7020 (char *) swif_tag, ARRAY_LEN(mp->swif_tag)-1);
7022 vl_msg_api_send_shmem (q, (u8 *)&mp);
7026 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t *mp)
7028 vpe_api_main_t * am = &vpe_api_main;
7029 unix_shared_memory_queue_t * q;
7030 vlib_main_t * vm = &vlib_global_main;
7033 show_mpls_fib_t *records = 0;
7035 mpls_main_t * mm = &mpls_main;
7036 ip4_main_t * im = &ip4_main;
7042 q = vl_api_client_index_to_input_queue (mp->client_index);
7046 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7048 vec_add2 (records, s, 1);
7049 s->fib_index = (u32)(key>>32);
7050 s->entry_index = (u32) value;
7051 s->label = ((u32) key)>>12;
7052 s->s_bit = (key & (1<<8)) != 0;
7055 if (!vec_len(records)) {
7056 vlib_cli_output(vm, "MPLS decap table empty");
7060 vec_sort_with_function(records, mpls_label_cmp);
7061 vlib_cli_output(vm, "MPLS decap table");
7062 vlib_cli_output(vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7064 vec_foreach (s, records)
7067 d = pool_elt_at_index(mm->decaps, s->entry_index);
7068 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT) {
7069 tx_fib = vec_elt_at_index(im->fibs, d->tx_fib_index);
7070 tx_table_id = tx_fib->table_id;
7073 tx_table_id = d->tx_fib_index;
7076 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
7078 vlib_cli_output(vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7079 tx_table_id, swif_tag, s->label, s->s_bit);
7081 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7082 tx_table_id, swif_tag, mp->context);
7089 static void vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t *mp)
7091 unix_shared_memory_queue_t * q;
7093 q = vl_api_client_index_to_input_queue (mp->client_index);
7097 vnet_classify_main_t * cm = &vnet_classify_main;
7098 vnet_classify_table_t * t;
7099 u32 * table_ids = 0;
7102 pool_foreach (t, cm->tables,
7104 vec_add1 (table_ids, ntohl(t - cm->tables));
7106 count = vec_len(table_ids);
7108 vl_api_classify_table_ids_reply_t *rmp;
7109 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + count * sizeof(u32));
7110 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7111 rmp->context = mp->context;
7112 rmp->count = ntohl(count);
7113 clib_memcpy(rmp->ids, table_ids, count * sizeof(u32));
7116 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7118 vec_free (table_ids);
7121 static void vl_api_classify_table_by_interface_t_handler (vl_api_classify_table_by_interface_t *mp)
7123 vl_api_classify_table_by_interface_reply_t *rmp;
7126 u32 sw_if_index = ntohl(mp->sw_if_index);
7129 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7132 VALIDATE_SW_IF_INDEX(mp);
7134 input_acl_main_t * am = &input_acl_main;
7139 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7141 u32 * vec_tbl = am->classify_table_index_by_sw_if_index[type];
7142 if (vec_len(vec_tbl)) {
7143 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7145 if (vec_elt(vec_tbl, if_idx) == ~0 || sw_if_index != if_idx) {
7148 acl[type] = vec_elt(vec_tbl, if_idx);
7153 BAD_SW_IF_INDEX_LABEL;
7155 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7157 rmp->sw_if_index = ntohl(sw_if_index);
7158 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7159 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7160 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7165 static void vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t *mp)
7167 unix_shared_memory_queue_t * q;
7169 q = vl_api_client_index_to_input_queue (mp->client_index);
7173 vl_api_classify_table_info_reply_t *rmp = 0;
7175 vnet_classify_main_t * cm = &vnet_classify_main;
7176 u32 table_id = ntohl(mp->table_id);
7177 vnet_classify_table_t * t;
7179 pool_foreach (t, cm->tables,
7181 if (table_id == t - cm->tables) {
7182 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7183 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7184 rmp->context = mp->context;
7185 rmp->table_id = ntohl(table_id);
7186 rmp->nbuckets = ntohl(t->nbuckets);
7187 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7188 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7189 rmp->active_sessions = ntohl(t->active_elements);
7190 rmp->next_table_index = ntohl(t->next_table_index);
7191 rmp->miss_next_index = ntohl(t->miss_next_index);
7192 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7193 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7200 rmp = vl_msg_api_alloc (sizeof (*rmp));
7201 rmp->_vl_msg_id = ntohs((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7202 rmp->context = mp->context;
7203 rmp->retval = ntohl(VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7206 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7209 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
7211 clib_warning ("BUG");
7214 static void send_classify_session_details (unix_shared_memory_queue_t * q,
7217 vnet_classify_entry_t * e,
7220 vl_api_classify_session_details_t *rmp;
7222 rmp = vl_msg_api_alloc (sizeof (*rmp));
7223 memset (rmp, 0, sizeof (*rmp));
7224 rmp->_vl_msg_id = ntohs(VL_API_CLASSIFY_SESSION_DETAILS);
7225 rmp->context = context;
7226 rmp->table_id = ntohl(table_id);
7227 rmp->hit_next_index = ntohl(e->next_index);
7228 rmp->advance = ntohl(e->advance);
7229 rmp->opaque_index = ntohl(e->opaque_index);
7230 rmp->match_length = ntohl(match_length);
7231 clib_memcpy(rmp->match, e->key, match_length);
7233 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7236 static void vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t *mp)
7238 vnet_classify_main_t * cm = &vnet_classify_main;
7239 unix_shared_memory_queue_t * q;
7241 u32 table_id = ntohl(mp->table_id);
7242 vnet_classify_table_t * t;
7244 q = vl_api_client_index_to_input_queue (mp->client_index);
7246 pool_foreach (t, cm->tables,
7248 if (table_id == t - cm->tables) {
7249 vnet_classify_bucket_t * b;
7250 vnet_classify_entry_t * v, * save_v;
7253 for (i = 0; i < t->nbuckets; i++)
7255 b = &t->buckets [i];
7259 save_v = vnet_classify_get_entry (t, b->offset);
7260 for (j = 0; j < (1<<b->log2_pages); j++)
7262 for (k = 0; k < t->entries_per_page; k++)
7264 v = vnet_classify_entry_at_index (t, save_v, j*t->entries_per_page + k);
7265 if (vnet_classify_entry_is_free (v))
7268 send_classify_session_details(q, table_id,
7269 t->match_n_vectors * sizeof (u32x4), v, mp->context);
7278 static void vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t *mp)
7280 vlib_main_t *vm = vlib_get_main();
7281 flow_report_main_t * frm = &flow_report_main;
7282 vl_api_ipfix_enable_reply_t *rmp;
7283 ip4_address_t collector, src;
7284 u16 collector_port = UDP_DST_PORT_ipfix;
7286 u32 template_interval;
7291 memcpy(collector.data, mp->collector_address, sizeof(collector.data));
7292 collector_port = ntohs(mp->collector_port);
7293 if (collector_port == (u16)~0)
7294 collector_port = UDP_DST_PORT_ipfix;
7295 memcpy(src.data, mp->src_address, sizeof(src.data));
7296 fib_id = ntohl(mp->vrf_id);
7298 ip4_main_t * im = &ip4_main;
7299 uword * p = hash_get (im->fib_index_by_table_id, fib_id);
7301 rv = VNET_API_ERROR_NO_SUCH_FIB;
7306 path_mtu = ntohl(mp->path_mtu);
7308 path_mtu = 512; // RFC 7011 section 10.3.3.
7309 template_interval = ntohl(mp->template_interval);
7310 if (template_interval == ~0)
7311 template_interval = 20;
7313 if (collector.as_u32 == 0) {
7314 rv = VNET_API_ERROR_INVALID_VALUE;
7318 if (src.as_u32 == 0) {
7319 rv = VNET_API_ERROR_INVALID_VALUE;
7323 if (path_mtu > 1450 /* vpp does not support fragmentation */) {
7324 rv = VNET_API_ERROR_INVALID_VALUE;
7328 if (path_mtu < 68) {
7329 rv = VNET_API_ERROR_INVALID_VALUE;
7333 /* Reset report streams if we are reconfiguring IP addresses */
7334 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7335 frm->src_address.as_u32 != src.as_u32 ||
7336 frm->collector_port != collector_port)
7337 vnet_flow_reports_reset(frm);
7339 frm->ipfix_collector.as_u32 = collector.as_u32;
7340 frm->collector_port = collector_port;
7341 frm->src_address.as_u32 = src.as_u32;
7342 frm->fib_index = fib_index;
7343 frm->path_mtu = path_mtu;
7344 frm->template_interval = template_interval;
7346 /* Turn on the flow reporting process */
7347 vlib_process_signal_event (vm, flow_report_process_node.index,
7351 REPLY_MACRO(VL_API_IPFIX_ENABLE_REPLY);
7354 static void vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t *mp)
7356 flow_report_main_t * frm = &flow_report_main;
7357 unix_shared_memory_queue_t * q;
7358 vl_api_ipfix_details_t *rmp;
7360 q = vl_api_client_index_to_input_queue (mp->client_index);
7362 rmp = vl_msg_api_alloc (sizeof (*rmp));
7363 memset (rmp, 0, sizeof (*rmp));
7364 rmp->_vl_msg_id = ntohs(VL_API_IPFIX_DETAILS);
7365 rmp->context = mp->context;
7366 memcpy(rmp->collector_address, frm->ipfix_collector.data,
7367 sizeof(frm->ipfix_collector.data));
7368 rmp->collector_port = htons(frm->collector_port);
7369 memcpy(rmp->src_address, frm->src_address.data,
7370 sizeof(frm->src_address.data));
7371 rmp->fib_index = htonl(frm->fib_index);
7372 rmp->path_mtu = htonl(frm->path_mtu);
7373 rmp->template_interval = htonl(frm->template_interval);
7375 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7378 static void vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t *mp)
7380 vl_api_pg_create_interface_reply_t *rmp;
7383 pg_main_t * pg = &pg_main;
7384 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl(mp->interface_id));
7386 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7388 rmp->sw_if_index = ntohl(sw_if_index);
7392 static void vl_api_pg_capture_t_handler (vl_api_pg_capture_t *mp)
7394 vl_api_pg_capture_reply_t *rmp;
7397 vnet_main_t * vnm = vnet_get_main();
7398 vnet_interface_main_t * im = &vnm->interface_main;
7399 vnet_hw_interface_t * hi = 0;
7401 u8 * intf_name = format (0, "pg%d", ntohl(mp->interface_id), 0);
7402 u32 hw_if_index = ~0;
7403 uword * p = hash_get_mem (im->hw_interface_by_name, intf_name);
7406 vec_free (intf_name);
7408 if (hw_if_index != ~0) {
7409 pg_capture_args_t _a, *a=&_a;
7411 u32 len = ntohl(mp->pcap_name_length);
7412 u8 * pcap_file_name = vec_new(u8, len);
7413 clib_memcpy(pcap_file_name, mp->pcap_file_name, len);
7415 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7416 a->hw_if_index = hw_if_index;
7417 a->dev_instance = hi->dev_instance;
7418 a->is_enabled = mp->is_enabled;
7419 a->pcap_file_name = pcap_file_name;
7420 a->count = ntohl(mp->count);
7422 clib_error_t * e = pg_capture (a);
7424 clib_error_report(e);
7425 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7428 vec_free (pcap_file_name);
7430 REPLY_MACRO(VL_API_PG_CAPTURE_REPLY);
7433 static void vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t *mp)
7435 vl_api_pg_enable_disable_reply_t *rmp;
7438 pg_main_t * pg = &pg_main;
7439 u32 stream_index = ~0;
7441 int is_enable = mp->is_enabled != 0;
7442 u32 len = ntohl(mp->stream_name_length)-1;
7445 u8 * stream_name = vec_new(u8, len);
7446 clib_memcpy(stream_name, mp->stream_name, len);
7447 uword * p = hash_get_mem (pg->stream_index_by_name, stream_name);
7450 vec_free(stream_name);
7453 pg_enable_disable (stream_index, is_enable);
7455 REPLY_MACRO(VL_API_PG_ENABLE_DISABLE_REPLY);
7458 #define BOUNCE_HANDLER(nn) \
7459 static void vl_api_##nn##_t_handler ( \
7460 vl_api_##nn##_t *mp) \
7462 vpe_client_registration_t *reg; \
7463 vpe_api_main_t * vam = &vpe_api_main; \
7464 unix_shared_memory_queue_t * q; \
7466 /* One registration only... */ \
7467 pool_foreach(reg, vam->nn##_registrations, \
7469 q = vl_api_client_index_to_input_queue (reg->client_index); \
7472 * If the queue is stuffed, turf the msg and complain \
7473 * It's unlikely that the intended recipient is \
7474 * alive; avoid deadlock at all costs. \
7476 if (q->cursize == q->maxsize) { \
7477 clib_warning ("ERROR: receiver queue full, drop msg"); \
7478 vl_msg_api_free (mp); \
7481 vl_msg_api_send_shmem (q, (u8 *)&mp); \
7485 vl_msg_api_free (mp); \
7490 * Add vpe's API message handlers to the table.
7491 * vlib has alread mapped shared memory and
7492 * added the client registration handlers.
7493 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
7496 static clib_error_t *
7497 vpe_api_hookup (vlib_main_t *vm)
7499 api_main_t * am = &api_main;
7502 vl_msg_api_set_handlers(VL_API_##N, #n, \
7503 vl_api_##n##_t_handler, \
7505 vl_api_##n##_t_endian, \
7506 vl_api_##n##_t_print, \
7507 sizeof(vl_api_##n##_t), 1);
7508 foreach_vpe_api_msg;
7512 * Manually register the sr tunnel add del msg, so we trace
7513 * enough bytes to capture a typical segment list
7515 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
7516 "sr_tunnel_add_del",
7517 vl_api_sr_tunnel_add_del_t_handler,
7519 vl_api_sr_tunnel_add_del_t_endian,
7520 vl_api_sr_tunnel_add_del_t_print,
7525 * Manually register the sr policy add del msg, so we trace
7526 * enough bytes to capture a typical tunnel name list
7528 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
7529 "sr_policy_add_del",
7530 vl_api_sr_policy_add_del_t_handler,
7532 vl_api_sr_policy_add_del_t_endian,
7533 vl_api_sr_policy_add_del_t_print,
7537 * Trace space for 8 MPLS encap labels, classifier mask+match
7539 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
7540 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
7541 += 5 * sizeof (u32x4);
7542 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
7543 += 5 * sizeof (u32x4);
7544 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
7545 += 16 * sizeof (u32);
7548 * Thread-safe API messages
7550 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
7551 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
7556 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
7558 static clib_error_t *
7559 vpe_api_init (vlib_main_t *vm)
7561 vpe_api_main_t *am = &vpe_api_main;
7564 am->vnet_main = vnet_get_main();
7565 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
7566 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7567 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7568 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7569 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7570 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
7573 vl_set_memory_region_name ("/vpe-api");
7574 vl_enable_disable_memory_api (vm, 1 /* enable it */);
7579 VLIB_INIT_FUNCTION(vpe_api_init);
7582 static clib_error_t *
7583 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
7588 struct passwd _pw, *pw;
7589 struct group _grp, *grp;
7592 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7594 if (unformat (input, "prefix %s", &chroot_path))
7596 vec_add1 (chroot_path, 0);
7597 vl_set_memory_root_path ((char *)chroot_path);
7599 else if (unformat (input, "uid %d", &uid))
7600 vl_set_memory_uid (uid);
7601 else if (unformat (input, "gid %d", &gid))
7602 vl_set_memory_gid (gid);
7603 else if (unformat (input, "uid %s", &s))
7605 /* lookup the username */
7607 rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
7610 e = clib_error_return_code(0, rv,
7611 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7612 "cannot fetch username %s", s);
7618 e = clib_error_return_fatal(0, "username %s does not exist", s);
7623 vl_set_memory_uid (pw->pw_uid);
7625 else if (unformat (input, "gid %s", &s))
7627 /* lookup the group name */
7629 rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
7632 e = clib_error_return_code(0, rv,
7633 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7634 "cannot fetch group %s", s);
7640 e = clib_error_return_fatal(0, "group %s does not exist", s);
7645 vl_set_memory_gid (grp->gr_gid);
7648 return clib_error_return (0, "unknown input `%U'",
7649 format_unformat_error, input);
7653 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
7655 void * get_unformat_vnet_sw_interface (void)
7657 return (void *) &unformat_vnet_sw_interface;
7660 #undef vl_api_version
7661 #define vl_api_version(n,v) static u32 vpe_api_version = v;
7662 #include <vpp-api/vpe.api.h>
7663 #undef vl_api_version
7665 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
7667 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
7668 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
7669 clib_host_to_net_u32 (mp->api_versions[0]),
7676 static u8 * format_arp_event (u8 * s, va_list * args)
7678 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
7680 s = format (s, "pid %d: %U", event->pid,
7681 format_ip4_address, &event->address);
7685 static clib_error_t *
7686 show_ip4_arp_events_fn (vlib_main_t * vm,
7687 unformat_input_t * input,
7688 vlib_cli_command_t * cmd)
7690 vpe_api_main_t * am = &vpe_api_main;
7691 vl_api_ip4_arp_event_t * event;
7693 if (pool_elts (am->arp_events) == 0) {
7694 vlib_cli_output (vm, "No active arp event registrations");
7698 pool_foreach (event, am->arp_events,
7700 vlib_cli_output (vm, "%U", format_arp_event, event);
7706 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
7707 .path = "show arp event registrations",
7708 .function = show_ip4_arp_events_fn,
7709 .short_help = "Show arp event registrations",