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>
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/ip/ip_source_and_port_range_check.h>
81 #include <vnet/devices/af_packet/af_packet.h>
82 #include <vnet/policer/policer.h>
83 #include <vnet/devices/netmap/netmap.h>
84 #include <vnet/flow/flow_report.h>
85 #include <vnet/ipsec-gre/ipsec_gre.h>
88 #undef __included_bihash_template_h__
89 #include <vnet/l2/l2_fib.h>
92 #include <vnet/ipsec/ipsec.h>
93 #include <vnet/ipsec/ikev2.h>
96 #include <vnet/devices/virtio/vhost-user.h>
99 #include <stats/stats.h>
102 #include <vnet/ethernet/ethernet.h>
103 #include <vnet/ethernet/arp_packet.h>
104 #include <vnet/interface.h>
106 #include <vnet/l2/l2_fib.h>
107 #include <vnet/l2/l2_bd.h>
108 #include <vpp-api/vpe_msg_enum.h>
110 #define f64_endian(a)
111 #define f64_print(a,b)
113 #define vl_typedefs /* define message structures */
114 #include <vpp-api/vpe_all_api_h.h>
117 #define vl_endianfun /* define message structures */
118 #include <vpp-api/vpe_all_api_h.h>
121 /* instantiate all the print functions we know about */
122 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
124 #include <vpp-api/vpe_all_api_h.h>
127 #define REPLY_MACRO(t) \
129 unix_shared_memory_queue_t * q; \
130 rv = vl_msg_api_pd_handler (mp, rv); \
131 q = vl_api_client_index_to_input_queue (mp->client_index); \
135 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
136 rmp->_vl_msg_id = ntohs((t)); \
137 rmp->context = mp->context; \
138 rmp->retval = ntohl(rv); \
140 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
143 #define REPLY_MACRO2(t, body) \
145 unix_shared_memory_queue_t * q; \
146 rv = vl_msg_api_pd_handler (mp, rv); \
147 q = vl_api_client_index_to_input_queue (mp->client_index); \
151 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
152 rmp->_vl_msg_id = ntohs((t)); \
153 rmp->context = mp->context; \
154 rmp->retval = ntohl(rv); \
155 do {body;} while (0); \
156 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
159 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
161 #define VALIDATE_SW_IF_INDEX(mp) \
162 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
163 vnet_main_t *__vnm = vnet_get_main(); \
164 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
166 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
167 goto bad_sw_if_index; \
171 #define BAD_SW_IF_INDEX_LABEL \
177 #define VALIDATE_RX_SW_IF_INDEX(mp) \
178 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
179 vnet_main_t *__vnm = vnet_get_main(); \
180 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
181 __rx_sw_if_index)) { \
182 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
183 goto bad_rx_sw_if_index; \
187 #define BAD_RX_SW_IF_INDEX_LABEL \
189 bad_rx_sw_if_index: \
193 #define VALIDATE_TX_SW_IF_INDEX(mp) \
194 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
195 vnet_main_t *__vnm = vnet_get_main(); \
196 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
197 __tx_sw_if_index)) { \
198 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
199 goto bad_tx_sw_if_index; \
203 #define BAD_TX_SW_IF_INDEX_LABEL \
205 bad_tx_sw_if_index: \
211 #define VALIDATE_SW_IF_INDEX(mp)
212 #define BAD_SW_IF_INDEX_LABEL
213 #define VALIDATE_RX_SW_IF_INDEX(mp)
214 #define BAD_RX_SW_IF_INDEX_LABEL
215 #define VALIDATE_TX_SW_IF_INDEX(mp)
216 #define BAD_TX_SW_IF_INDEX_LABEL
218 #endif /* CLIB_DEBUG > 0 */
220 #define foreach_vpe_api_msg \
221 _(WANT_INTERFACE_EVENTS, want_interface_events) \
222 _(WANT_OAM_EVENTS, want_oam_events) \
223 _(OAM_ADD_DEL, oam_add_del) \
224 _(SW_INTERFACE_DUMP, sw_interface_dump) \
225 _(SW_INTERFACE_DETAILS, sw_interface_details) \
226 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
227 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
228 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
229 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
230 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
231 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
232 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
233 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
234 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
235 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
236 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
237 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
238 _(L2FIB_ADD_DEL, l2fib_add_del) \
239 _(L2_FLAGS, l2_flags) \
240 _(BRIDGE_FLAGS, bridge_flags) \
241 _(TAP_CONNECT, tap_connect) \
242 _(TAP_MODIFY, tap_modify) \
243 _(TAP_DELETE, tap_delete) \
244 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
245 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
246 _(CREATE_SUBIF, create_subif) \
247 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
248 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
249 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
250 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
251 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
252 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
253 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
254 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
255 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
256 _(RESET_FIB, reset_fib) \
257 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
258 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
259 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
260 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
261 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
262 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
263 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
264 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
265 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
266 sw_interface_ip6_set_link_local_address) \
267 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
268 _(CREATE_LOOPBACK, create_loopback) \
269 _(CONTROL_PING, control_ping) \
270 _(NOPRINT_CONTROL_PING, noprint_control_ping) \
271 _(CLI_REQUEST, cli_request) \
272 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
273 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
274 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
275 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
276 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
277 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
278 _(GET_NODE_INDEX, get_node_index) \
279 _(ADD_NODE_NEXT, add_node_next) \
280 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
281 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
282 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
283 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
284 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
285 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
286 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
287 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
288 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
289 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
290 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
291 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
292 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
293 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
294 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
295 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
296 _(IP_ADDRESS_DUMP, ip_address_dump) \
297 _(IP_DUMP, ip_dump) \
298 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
299 _(SHOW_VERSION, show_version) \
300 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
301 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
302 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
303 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
304 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
305 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
306 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
307 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
308 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
309 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
310 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
311 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
312 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
313 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
314 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
315 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
316 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
317 _(DELETE_LOOPBACK, delete_loopback) \
318 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
319 _(MAP_ADD_DOMAIN, map_add_domain) \
320 _(MAP_DEL_DOMAIN, map_del_domain) \
321 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
322 _(MAP_DOMAIN_DUMP, map_domain_dump) \
323 _(MAP_RULE_DUMP, map_rule_dump) \
324 _(MAP_SUMMARY_STATS, map_summary_stats) \
325 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
326 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
327 _(GET_NODE_GRAPH, get_node_graph) \
328 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
329 _(TRACE_PROFILE_ADD, trace_profile_add) \
330 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
331 _(TRACE_PROFILE_DEL, trace_profile_del) \
332 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
333 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
334 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
335 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
336 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
337 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
338 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
339 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
340 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
341 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
342 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
343 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
344 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
345 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
346 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
347 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
348 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
349 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
350 _(SHOW_LISP_STATUS, show_lisp_status) \
351 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
352 lisp_add_del_map_request_itr_rlocs) \
353 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
354 _(SHOW_LISP_PITR, show_lisp_pitr) \
355 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
356 _(AF_PACKET_CREATE, af_packet_create) \
357 _(AF_PACKET_DELETE, af_packet_delete) \
358 _(POLICER_ADD_DEL, policer_add_del) \
359 _(POLICER_DUMP, policer_dump) \
360 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
361 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
362 _(NETMAP_CREATE, netmap_create) \
363 _(NETMAP_DELETE, netmap_delete) \
364 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
365 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
366 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
367 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
368 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
369 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
370 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
371 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
372 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
373 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
374 _(CLASSIFY_TABLE_INFO,classify_table_info) \
375 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
376 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
377 _(IPFIX_ENABLE,ipfix_enable) \
378 _(IPFIX_DUMP,ipfix_dump) \
379 _(GET_NEXT_INDEX, get_next_index) \
380 _(PG_CREATE_INTERFACE, pg_create_interface) \
381 _(PG_CAPTURE, pg_capture) \
382 _(PG_ENABLE_DISABLE, pg_enable_disable) \
383 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
384 ip_source_and_port_range_check_add_del) \
385 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
386 ip_source_and_port_range_check_interface_add_del) \
387 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
388 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump)
391 #define QUOTE(x) QUOTE_(x)
393 #define foreach_registration_hash \
394 _(interface_events) \
395 _(to_netconf_server) \
396 _(from_netconf_server) \
397 _(to_netconf_client) \
398 _(from_netconf_client) \
403 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
404 RESOLVE_IP6_ADD_DEL_ROUTE,
405 RESOLVE_MPLS_ETHERNET_ADD_DEL,
413 vl_api_ip_add_del_route_t r;
414 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
421 #define _(a) uword *a##_registration_hash; \
422 vpe_client_registration_t * a##_registrations;
423 foreach_registration_hash
425 /* notifications happen really early in the game */
426 u8 link_state_process_up;
428 /* ip4 pending route adds */
429 pending_route_t *pending_routes;
431 /* ip4 arp event registration pool */
432 vl_api_ip4_arp_event_t *arp_events;
435 vlib_main_t *vlib_main;
436 vnet_main_t *vnet_main;
439 static vlib_node_registration_t vpe_resolver_process_node;
440 static vpe_api_main_t vpe_api_main;
442 static void send_sw_interface_flags (vpe_api_main_t * am,
443 unix_shared_memory_queue_t * q,
444 vnet_sw_interface_t * swif);
445 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
446 unix_shared_memory_queue_t * q,
449 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
452 /* Clean up all registrations belonging to the indicated client */
454 vl_api_memclnt_delete_callback (u32 client_index)
456 vpe_api_main_t *vam = &vpe_api_main;
457 vpe_client_registration_t *rp;
459 int stats_memclnt_delete_callback (u32 client_index);
461 stats_memclnt_delete_callback (client_index);
464 p = hash_get (vam->a##_registration_hash, client_index); \
466 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
467 pool_put (vam->a##_registrations, rp); \
468 hash_unset (vam->a##_registration_hash, client_index); \
470 foreach_registration_hash;
475 #define API_LINK_STATE_EVENT 1
476 #define API_ADMIN_UP_DOWN_EVENT 2
479 event_data_cmp (void *a1, void *a2)
484 return (word) e1[0] - (word) e2[0];
488 link_state_process (vlib_main_t * vm,
489 vlib_node_runtime_t * rt, vlib_frame_t * f)
491 vpe_api_main_t *vam = &vpe_api_main;
492 vnet_main_t *vnm = vam->vnet_main;
493 vnet_sw_interface_t *swif;
494 uword *event_data = 0;
495 vpe_client_registration_t *reg;
497 u32 prev_sw_if_index;
498 unix_shared_memory_queue_t *q;
500 vam->link_state_process_up = 1;
504 vlib_process_wait_for_event (vm);
506 /* Unified list of changed link or admin state sw_if_indices */
507 vlib_process_get_events_with_type
508 (vm, &event_data, API_LINK_STATE_EVENT);
509 vlib_process_get_events_with_type
510 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
512 /* Sort, so we can eliminate duplicates */
513 vec_sort_with_function (event_data, event_data_cmp);
515 prev_sw_if_index = ~0;
517 for (i = 0; i < vec_len (event_data); i++)
519 /* Only one message per swif */
520 if (prev_sw_if_index == event_data[i])
522 prev_sw_if_index = event_data[i];
525 pool_foreach(reg, vam->interface_events_registrations,
527 q = vl_api_client_index_to_input_queue (reg->client_index);
530 /* sw_interface may be deleted already */
531 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
534 swif = vnet_get_sw_interface (vnm, event_data[i]);
535 send_sw_interface_flags (vam, q, swif);
541 vec_reset_length (event_data);
547 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
549 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
550 u32 hw_if_index, u32 flags);
553 VLIB_REGISTER_NODE (link_state_process_node,static) = {
554 .function = link_state_process,
555 .type = VLIB_NODE_TYPE_PROCESS,
556 .name = "vpe-link-state-process",
560 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
561 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
563 static clib_error_t *
564 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
566 vpe_api_main_t *vam = &vpe_api_main;
567 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
569 if (vam->link_state_process_up)
570 vlib_process_signal_event (vam->vlib_main,
571 link_state_process_node.index,
572 API_LINK_STATE_EVENT, hi->sw_if_index);
576 static clib_error_t *
577 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
579 vpe_api_main_t *vam = &vpe_api_main;
582 * Note: it's perfectly fair to set a subif admin up / admin down.
583 * Note the subtle distinction between this routine and the previous
586 if (vam->link_state_process_up)
587 vlib_process_signal_event (vam->vlib_main,
588 link_state_process_node.index,
589 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
593 #define pub_sub_handler(lca,UCA) \
594 static void vl_api_want_##lca##_t_handler ( \
595 vl_api_want_##lca##_t *mp) \
597 vpe_api_main_t *vam = &vpe_api_main; \
598 vpe_client_registration_t *rp; \
599 vl_api_want_##lca##_reply_t *rmp; \
603 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
605 if (mp->enable_disable) { \
606 clib_warning ("pid %d: already enabled...", mp->pid); \
607 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
610 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
611 pool_put (vam->lca##_registrations, rp); \
612 hash_unset (vam->lca##_registration_hash, \
617 if (mp->enable_disable == 0) { \
618 clib_warning ("pid %d: already disabled...", mp->pid); \
619 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
622 pool_get (vam->lca##_registrations, rp); \
623 rp->client_index = mp->client_index; \
624 rp->client_pid = mp->pid; \
625 hash_set (vam->lca##_registration_hash, rp->client_index, \
626 rp - vam->lca##_registrations); \
629 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
632 pub_sub_handler (interface_events, INTERFACE_EVENTS)
633 pub_sub_handler (oam_events, OAM_EVENTS)
634 #define RESOLUTION_EVENT 1
635 #define RESOLUTION_PENDING_EVENT 2
636 #define IP4_ARP_EVENT 3
637 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
638 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
639 static int mpls_ethernet_add_del_tunnel_2_t_handler
640 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
642 void handle_ip4_arp_event (u32 pool_index)
644 vpe_api_main_t *vam = &vpe_api_main;
645 vnet_main_t *vnm = vam->vnet_main;
646 vlib_main_t *vm = vam->vlib_main;
647 vl_api_ip4_arp_event_t *event;
648 vl_api_ip4_arp_event_t *mp;
649 unix_shared_memory_queue_t *q;
651 /* Client can cancel, die, etc. */
652 if (pool_is_free_index (vam->arp_events, pool_index))
655 event = pool_elt_at_index (vam->arp_events, pool_index);
657 q = vl_api_client_index_to_input_queue (event->client_index);
660 (void) vnet_add_del_ip4_arp_change_event
661 (vnm, arp_change_delete_callback,
662 event->pid, &event->address,
663 vpe_resolver_process_node.index, IP4_ARP_EVENT,
664 ~0 /* pool index, notused */ , 0 /* is_add */ );
668 if (q->cursize < q->maxsize)
670 mp = vl_msg_api_alloc (sizeof (*mp));
671 clib_memcpy (mp, event, sizeof (*mp));
672 vl_msg_api_send_shmem (q, (u8 *) & mp);
676 static f64 last_time;
678 * Throttle syslog msgs.
679 * It's pretty tempting to just revoke the registration...
681 if (vlib_time_now (vm) > last_time + 10.0)
683 clib_warning ("arp event for %U to pid %d: queue stuffed!",
684 format_ip4_address, &event->address, event->pid);
685 last_time = vlib_time_now (vm);
691 resolver_process (vlib_main_t * vm,
692 vlib_node_runtime_t * rt, vlib_frame_t * f)
695 uword *event_data = 0;
697 vpe_api_main_t *vam = &vpe_api_main;
699 vl_api_ip_add_del_route_t *adr;
700 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
701 u32 *resolution_failures = 0;
707 vlib_process_wait_for_event_or_clock (vm, timeout);
709 event_type = vlib_process_get_events (vm, &event_data);
713 case RESOLUTION_PENDING_EVENT:
717 case RESOLUTION_EVENT:
718 for (i = 0; i < vec_len (event_data); i++)
721 * Resolution events can occur long after the
722 * original request has timed out. $$$ add a cancel
725 if (pool_is_free_index (vam->pending_routes, event_data[i]))
728 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
732 switch (pr->resolve_type)
734 case RESOLVE_IP4_ADD_DEL_ROUTE:
735 rv = ip4_add_del_route_t_handler (adr);
736 clib_warning ("resolver: add %U/%d via %U %s",
738 (ip4_address_t *) & (adr->dst_address),
739 adr->dst_address_length,
741 (ip4_address_t *) & (adr->next_hop_address),
742 (rv >= 0) ? "succeeded" : "failed");
745 case RESOLVE_IP6_ADD_DEL_ROUTE:
746 rv = ip6_add_del_route_t_handler (adr);
747 clib_warning ("resolver: add %U/%d via %U %s",
749 (ip6_address_t *) & (adr->dst_address),
750 adr->dst_address_length,
752 (ip6_address_t *) & (adr->next_hop_address),
753 (rv >= 0) ? "succeeded" : "failed");
756 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
757 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
758 clib_warning ("resolver: add mpls-o-e via %U %s",
761 (pme->next_hop_ip4_address_in_outer_vrf),
762 (rv >= 0) ? "succeeded" : "failed");
766 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
768 pool_put (vam->pending_routes, pr);
773 for (i = 0; i < vec_len (event_data); i++)
774 handle_ip4_arp_event (event_data[i]);
777 case ~0: /* timeout, retry pending resolutions */
779 pool_foreach (pr, vam->pending_routes,
785 /* May fail, e.g. due to interface down */
786 switch (pr->resolve_type)
788 case RESOLVE_IP4_ADD_DEL_ROUTE:
789 e = ip4_probe_neighbor
790 (vm, (ip4_address_t *)&(adr->next_hop_address),
791 ntohl(adr->next_hop_sw_if_index));
794 case RESOLVE_IP6_ADD_DEL_ROUTE:
795 e = ip6_probe_neighbor
796 (vm, (ip6_address_t *)&(adr->next_hop_address),
797 ntohl(adr->next_hop_sw_if_index));
800 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
802 e = ip4_probe_neighbor
804 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
805 pme->resolve_opaque);
809 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
814 clib_error_report (e);
816 adr->resolve_attempts = 1;
818 pme->resolve_attempts = 1;
822 adr->resolve_attempts -= 1;
823 if (adr->resolve_attempts == 0)
824 vec_add1 (resolution_failures,
825 pr - vam->pending_routes);
829 pme->resolve_attempts -= 1;
830 if (pme->resolve_attempts == 0)
831 vec_add1 (resolution_failures,
832 pr - vam->pending_routes);
836 for (i = 0; i < vec_len (resolution_failures); i++)
838 pr = pool_elt_at_index (vam->pending_routes,
839 resolution_failures[i]);
843 switch (pr->resolve_type)
845 case RESOLVE_IP4_ADD_DEL_ROUTE:
846 clib_warning ("resolver: add %U/%d via %U retry failure",
848 (ip4_address_t *) & (adr->dst_address),
849 adr->dst_address_length,
851 (ip4_address_t *) & (adr->next_hop_address));
854 case RESOLVE_IP6_ADD_DEL_ROUTE:
855 clib_warning ("resolver: add %U/%d via %U retry failure",
857 (ip6_address_t *) & (adr->dst_address),
858 adr->dst_address_length,
860 (ip6_address_t *) & (adr->next_hop_address));
863 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
864 clib_warning ("resolver: add mpls-o-e via %U retry failure",
867 (pme->next_hop_ip4_address_in_outer_vrf));
871 clib_warning ("BUG");
873 pool_put (vam->pending_routes, pr);
875 vec_reset_length (resolution_failures);
878 if (pool_elts (vam->pending_routes) == 0)
880 vec_reset_length (event_data);
882 return 0; /* or not */
886 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
887 .function = resolver_process,
888 .type = VLIB_NODE_TYPE_PROCESS,
889 .name = "vpe-route-resolver-process",
894 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
896 ip4_main_t *im = &ip4_main;
897 ip_lookup_main_t *lm = &im->lookup_main;
898 vnet_classify_main_t *cm = &vnet_classify_main;
899 stats_main_t *sm = &stats_main;
900 ip4_add_del_route_args_t a;
901 ip4_address_t next_hop_address;
903 vpe_api_main_t *vam = &vpe_api_main;
904 vnet_main_t *vnm = vam->vnet_main;
905 vlib_main_t *vm = vlib_get_main ();
907 vl_api_ip_add_del_route_t *adr;
913 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
916 if (mp->create_vrf_if_needed)
919 f = find_ip4_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
921 fib_index = f->index;
925 /* No such VRF, and we weren't asked to create one */
926 return VNET_API_ERROR_NO_SUCH_FIB;
934 if (~0 != mp->next_hop_sw_if_index &&
935 pool_is_free_index (vnm->interface_main.sw_interfaces,
936 ntohl (mp->next_hop_sw_if_index)))
937 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
939 clib_memcpy (next_hop_address.data, mp->next_hop_address,
940 sizeof (next_hop_address.data));
942 /* Arp for the next_hop if necessary */
943 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
948 lookup_result = ip4_fib_lookup_with_table
949 (im, fib_index, &next_hop_address, 1 /* disable default route */ );
951 adj = ip_get_adjacency (lm, lookup_result);
953 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
955 pool_get (vam->pending_routes, pr);
956 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
958 clib_memcpy (adr, mp, sizeof (*adr));
959 /* recursion block, "just in case" */
960 adr->resolve_if_needed = 0;
961 adr->resolve_attempts = ntohl (mp->resolve_attempts);
962 vnet_register_ip4_arp_resolution_event
963 (vnm, &next_hop_address, vpe_resolver_process_node.index,
964 RESOLUTION_EVENT, pr - vam->pending_routes);
966 vlib_process_signal_event
967 (vm, vpe_resolver_process_node.index,
968 RESOLUTION_PENDING_EVENT, 0 /* data */ );
970 /* The interface may be down, etc. */
971 e = ip4_probe_neighbor
972 (vm, (ip4_address_t *) & (mp->next_hop_address),
973 ntohl (mp->next_hop_sw_if_index));
976 clib_error_report (e);
978 return VNET_API_ERROR_IN_PROGRESS;
982 if (mp->is_multipath)
986 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
989 flags = IP4_ROUTE_FLAG_ADD;
991 flags = IP4_ROUTE_FLAG_DEL;
994 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
996 ip4_add_del_route_next_hop (im, flags,
997 (ip4_address_t *) mp->dst_address,
998 (u32) mp->dst_address_length,
999 (ip4_address_t *) mp->next_hop_address,
1000 ntohl (mp->next_hop_sw_if_index),
1001 (u32) mp->next_hop_weight,
1002 ~0 /* adj_index */ ,
1008 memset (&a, 0, sizeof (a));
1009 clib_memcpy (a.dst_address.data, mp->dst_address,
1010 sizeof (a.dst_address.data));
1012 a.dst_address_length = mp->dst_address_length;
1014 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
1015 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
1016 a.table_index_or_table_id = fib_index;
1021 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1023 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1028 ai = lm->drop_adj_index;
1029 else if (mp->is_local)
1030 ai = lm->local_adj_index;
1031 else if (mp->is_classify)
1033 if (pool_is_free_index
1034 (cm->tables, ntohl (mp->classify_table_index)))
1037 return VNET_API_ERROR_NO_SUCH_TABLE;
1039 adj = ip_add_adjacency (lm,
1044 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
1045 adj->classify.table_index = ntohl (mp->classify_table_index);
1047 else if (mp->lookup_in_vrf)
1049 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1052 adj = ip_add_adjacency (lm,
1056 adj->explicit_fib_index = p[0];
1061 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1065 ai = ip4_route_get_next_hop_adj (im,
1068 ntohl (mp->next_hop_sw_if_index),
1071 if (ai == lm->miss_adj_index)
1074 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1079 ip_adjacency_t *adj;
1080 int disable_default_route = 1;
1082 /* Trying to delete the default route? */
1083 if (a.dst_address.as_u32 == 0 && a.dst_address_length == 0)
1084 disable_default_route = 0;
1086 ai = ip4_fib_lookup_with_table
1087 (im, fib_index, &a.dst_address, disable_default_route);
1088 if (ai == lm->miss_adj_index)
1091 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1094 adj = ip_get_adjacency (lm, ai);
1095 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1098 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1103 ip4_add_del_route (im, &a);
1110 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1112 ip6_main_t *im = &ip6_main;
1113 ip_lookup_main_t *lm = &im->lookup_main;
1114 vnet_main_t *vnm = vnet_get_main ();
1115 vlib_main_t *vm = vlib_get_main ();
1116 vpe_api_main_t *vam = &vpe_api_main;
1117 stats_main_t *sm = &stats_main;
1118 ip6_add_del_route_args_t a;
1119 ip6_address_t next_hop_address;
1120 pending_route_t *pr;
1121 vl_api_ip_add_del_route_t *adr;
1126 ip_adjacency_t *adj = 0;
1129 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1133 if (mp->create_vrf_if_needed)
1136 f = find_ip6_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1138 fib_index = f->index;
1142 /* No such VRF, and we weren't asked to create one */
1143 return VNET_API_ERROR_NO_SUCH_FIB;
1151 if (~0 != mp->next_hop_sw_if_index &&
1152 pool_is_free_index (vnm->interface_main.sw_interfaces,
1153 ntohl (mp->next_hop_sw_if_index)))
1154 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1156 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1157 sizeof (next_hop_address.as_u8));
1159 /* Arp for the next_hop if necessary */
1160 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1163 ip_adjacency_t *adj;
1165 lookup_result = ip6_fib_lookup_with_table
1166 (im, fib_index, &next_hop_address);
1168 adj = ip_get_adjacency (lm, lookup_result);
1170 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1172 pool_get (vam->pending_routes, pr);
1174 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1175 clib_memcpy (adr, mp, sizeof (*adr));
1176 /* recursion block, "just in case" */
1177 adr->resolve_if_needed = 0;
1178 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1179 vnet_register_ip6_neighbor_resolution_event
1180 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1181 RESOLUTION_EVENT, pr - vam->pending_routes);
1183 vlib_process_signal_event
1184 (vm, vpe_resolver_process_node.index,
1185 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1187 /* The interface may be down, etc. */
1188 e = ip6_probe_neighbor
1189 (vm, (ip6_address_t *) & (mp->next_hop_address),
1190 ntohl (mp->next_hop_sw_if_index));
1193 clib_error_report (e);
1195 return VNET_API_ERROR_IN_PROGRESS;
1199 if (mp->is_multipath)
1203 dslock (sm, 1 /* release hint */ , 11 /* tag */ );
1206 flags = IP6_ROUTE_FLAG_ADD;
1208 flags = IP6_ROUTE_FLAG_DEL;
1211 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1213 ip6_add_del_route_next_hop (im, flags,
1214 (ip6_address_t *) mp->dst_address,
1215 (u32) mp->dst_address_length,
1216 (ip6_address_t *) mp->next_hop_address,
1217 ntohl (mp->next_hop_sw_if_index),
1218 (u32) mp->next_hop_weight,
1219 ~0 /* adj_index */ ,
1225 memset (&a, 0, sizeof (a));
1226 clib_memcpy (a.dst_address.as_u8, mp->dst_address,
1227 sizeof (a.dst_address.as_u8));
1229 a.dst_address_length = mp->dst_address_length;
1231 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1232 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1233 a.table_index_or_table_id = fib_index;
1238 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1240 dslock (sm, 1 /* release hint */ , 3 /* tag */ );
1245 ai = lm->drop_adj_index;
1246 else if (mp->is_local)
1247 ai = lm->local_adj_index;
1248 else if (mp->lookup_in_vrf)
1250 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1253 adj = ip_add_adjacency (lm,
1257 adj->explicit_fib_index = p[0];
1262 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1266 ai = ip6_route_get_next_hop_adj (im,
1269 ntohl (mp->next_hop_sw_if_index),
1271 if (ai == lm->miss_adj_index)
1274 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1279 ip_adjacency_t *adj;
1281 ai = ip6_fib_lookup_with_table (im, fib_index, &a.dst_address);
1282 if (ai == lm->miss_adj_index)
1285 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1287 adj = ip_get_adjacency (lm, ai);
1288 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1291 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1296 ip6_add_del_route (im, &a);
1303 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1305 vl_api_ip_add_del_route_reply_t *rmp;
1307 vnet_main_t *vnm = vnet_get_main ();
1312 rv = ip6_add_del_route_t_handler (mp);
1314 rv = ip4_add_del_route_t_handler (mp);
1316 rv = (rv == 0) ? vnm->api_errno : rv;
1318 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1322 api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1323 u32 sw_if_index, u8 * next_hop_addr)
1325 vl_api_ip_add_del_route_t mp;
1328 memset (&mp, 0, sizeof (vl_api_ip_add_del_route_t));
1331 * Configure default IP route:
1332 * - ip route add 0.0.0.0/1 via <GW IP>
1333 * - ip route add 128.0.0.0/1 via <GW IP>
1335 mp.next_hop_sw_if_index = ntohl (sw_if_index);
1337 mp.resolve_attempts = ~0;
1338 mp.resolve_if_needed = 1;
1340 mp.is_ipv6 = is_ipv6;
1341 mp.next_hop_weight = 1;
1343 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1346 rv = ip6_add_del_route_t_handler (&mp);
1349 mp.dst_address_length = 1;
1351 mp.dst_address[0] = 0;
1352 rv = ip4_add_del_route_t_handler (&mp);
1354 mp.dst_address[0] = 128;
1355 rv |= ip4_add_del_route_t_handler (&mp);
1359 clib_error_return (0, "failed to config default IP route");
1364 vl_api_sw_interface_add_del_address_t_handler
1365 (vl_api_sw_interface_add_del_address_t * mp)
1367 vlib_main_t *vm = vlib_get_main ();
1368 vl_api_sw_interface_add_del_address_reply_t *rmp;
1372 VALIDATE_SW_IF_INDEX (mp);
1374 is_del = mp->is_add == 0;
1377 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1378 else if (mp->is_ipv6)
1379 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1380 (void *) mp->address,
1381 mp->address_length, is_del);
1383 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1384 (void *) mp->address,
1385 mp->address_length, is_del);
1387 BAD_SW_IF_INDEX_LABEL;
1389 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1393 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1396 u32 table_id = ntohl (mp->vrf_id);
1397 u32 sw_if_index = ntohl (mp->sw_if_index);
1398 vl_api_sw_interface_set_table_reply_t *rmp;
1399 stats_main_t *sm = &stats_main;
1401 VALIDATE_SW_IF_INDEX (mp);
1403 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1407 ip6_main_t *im = &ip6_main;
1408 ip6_fib_t *fib = find_ip6_fib_by_table_index_or_id (im, table_id,
1409 IP6_ROUTE_FLAG_TABLE_ID);
1412 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1413 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1417 rv = VNET_API_ERROR_NO_SUCH_FIB;
1422 ip4_main_t *im = &ip4_main;
1423 ip4_fib_t *fib = find_ip4_fib_by_table_index_or_id
1424 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1426 /* Truthfully this can't fail */
1429 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1430 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1434 rv = VNET_API_ERROR_NO_SUCH_FIB;
1439 BAD_SW_IF_INDEX_LABEL;
1441 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1445 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1447 vlib_main_t *vm = vlib_get_main ();
1448 ip4_main_t *im4 = &ip4_main;
1449 ip6_main_t *im6 = &ip6_main;
1450 vl_api_sw_interface_set_vpath_reply_t *rmp;
1453 u32 sw_if_index = ntohl (mp->sw_if_index);
1454 ip4_main_t *ip4m = &ip4_main;
1455 ip6_main_t *ip6m = &ip6_main;
1456 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1457 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1458 ip_config_main_t *rx_cm4u =
1459 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1460 ip_config_main_t *rx_cm4m =
1461 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1462 ip_config_main_t *rx_cm6u =
1463 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1464 ip_config_main_t *rx_cm6m =
1465 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1467 VALIDATE_SW_IF_INDEX (mp);
1469 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1472 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1473 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1475 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1476 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1477 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1478 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1480 im4->ip4_multicast_rx_feature_vpath,
1482 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1483 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1484 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1486 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1487 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1488 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1489 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1491 im6->ip6_multicast_rx_feature_vpath,
1493 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1497 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1498 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1500 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1501 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1502 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1503 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1505 im4->ip4_multicast_rx_feature_vpath,
1507 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1508 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1509 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1511 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1512 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1513 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1514 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1516 im6->ip6_multicast_rx_feature_vpath,
1518 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1521 BAD_SW_IF_INDEX_LABEL;
1523 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1527 vl_api_sw_interface_set_l2_xconnect_t_handler
1528 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1530 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1532 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1533 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1534 vlib_main_t *vm = vlib_get_main ();
1535 vnet_main_t *vnm = vnet_get_main ();
1537 VALIDATE_RX_SW_IF_INDEX (mp);
1541 VALIDATE_TX_SW_IF_INDEX (mp);
1542 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1543 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1547 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1550 BAD_RX_SW_IF_INDEX_LABEL;
1551 BAD_TX_SW_IF_INDEX_LABEL;
1553 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1557 vl_api_sw_interface_set_l2_bridge_t_handler
1558 (vl_api_sw_interface_set_l2_bridge_t * mp)
1560 bd_main_t *bdm = &bd_main;
1561 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1563 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1564 u32 bd_id = ntohl (mp->bd_id);
1568 vlib_main_t *vm = vlib_get_main ();
1569 vnet_main_t *vnm = vnet_get_main ();
1571 VALIDATE_RX_SW_IF_INDEX (mp);
1573 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1577 //VALIDATE_TX_SW_IF_INDEX(mp);
1578 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1579 rx_sw_if_index, bd_index, bvi, shg, 0);
1583 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1586 BAD_RX_SW_IF_INDEX_LABEL;
1588 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1592 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1594 vlib_main_t *vm = vlib_get_main ();
1595 bd_main_t *bdm = &bd_main;
1596 vl_api_bridge_domain_add_del_reply_t *rmp;
1598 u32 enable_flags = 0, disable_flags = 0;
1599 u32 bd_id = ntohl (mp->bd_id);
1604 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1607 enable_flags |= L2_FLOOD;
1609 disable_flags |= L2_FLOOD;
1612 enable_flags |= L2_UU_FLOOD;
1614 disable_flags |= L2_UU_FLOOD;
1617 enable_flags |= L2_FWD;
1619 disable_flags |= L2_FWD;
1622 enable_flags |= L2_ARP_TERM;
1624 disable_flags |= L2_ARP_TERM;
1627 enable_flags |= L2_LEARN;
1629 disable_flags |= L2_LEARN;
1632 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1635 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1639 rv = bd_delete_bd_index (bdm, bd_id);
1641 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1645 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1647 clib_warning ("BUG");
1651 vl_api_bridge_domain_sw_if_details_t_handler
1652 (vl_api_bridge_domain_sw_if_details_t * mp)
1654 clib_warning ("BUG");
1658 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1659 l2_bridge_domain_t * bd_config,
1660 u32 n_sw_ifs, u32 context)
1662 vl_api_bridge_domain_details_t *mp;
1664 mp = vl_msg_api_alloc (sizeof (*mp));
1665 memset (mp, 0, sizeof (*mp));
1666 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1667 mp->bd_id = ntohl (bd_config->bd_id);
1668 mp->flood = bd_feature_flood (bd_config);
1669 mp->uu_flood = bd_feature_uu_flood (bd_config);
1670 mp->forward = bd_feature_forward (bd_config);
1671 mp->learn = bd_feature_learn (bd_config);
1672 mp->arp_term = bd_feature_arp_term (bd_config);
1673 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1674 mp->n_sw_ifs = ntohl (n_sw_ifs);
1675 mp->context = context;
1677 vl_msg_api_send_shmem (q, (u8 *) & mp);
1681 send_bd_sw_if_details (l2input_main_t * l2im,
1682 unix_shared_memory_queue_t * q,
1683 l2_flood_member_t * member, u32 bd_id, u32 context)
1685 vl_api_bridge_domain_sw_if_details_t *mp;
1686 l2_input_config_t *input_cfg;
1688 mp = vl_msg_api_alloc (sizeof (*mp));
1689 memset (mp, 0, sizeof (*mp));
1690 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1691 mp->bd_id = ntohl (bd_id);
1692 mp->sw_if_index = ntohl (member->sw_if_index);
1693 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1694 mp->shg = input_cfg->shg;
1695 mp->context = context;
1697 vl_msg_api_send_shmem (q, (u8 *) & mp);
1701 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1703 bd_main_t *bdm = &bd_main;
1704 l2input_main_t *l2im = &l2input_main;
1705 unix_shared_memory_queue_t *q;
1706 l2_bridge_domain_t *bd_config;
1707 u32 bd_id, bd_index;
1710 q = vl_api_client_index_to_input_queue (mp->client_index);
1715 bd_id = ntohl (mp->bd_id);
1717 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1718 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1719 for (; bd_index < end; bd_index++)
1721 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1722 /* skip dummy bd_id 0 */
1723 if (bd_config && (bd_config->bd_id > 0))
1726 l2_flood_member_t *m;
1728 n_sw_ifs = vec_len (bd_config->members);
1729 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1731 vec_foreach (m, bd_config->members)
1733 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1740 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1742 bd_main_t *bdm = &bd_main;
1743 l2input_main_t *l2im = &l2input_main;
1744 vl_api_l2fib_add_del_reply_t *rmp;
1747 u32 sw_if_index = ntohl (mp->sw_if_index);
1748 u32 bd_id = ntohl (mp->bd_id);
1757 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1760 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1761 goto bad_sw_if_index;
1767 VALIDATE_SW_IF_INDEX (mp);
1768 if (vec_len (l2im->configs) <= sw_if_index)
1770 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1771 goto bad_sw_if_index;
1775 l2_input_config_t *config;
1776 config = vec_elt_at_index (l2im->configs, sw_if_index);
1777 if (config->bridge == 0)
1779 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1780 goto bad_sw_if_index;
1783 static_mac = mp->static_mac ? 1 : 0;
1784 filter_mac = mp->filter_mac ? 1 : 0;
1785 bvi_mac = mp->bvi_mac ? 1 : 0;
1786 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1791 l2fib_del_entry (mac, bd_index);
1794 BAD_SW_IF_INDEX_LABEL;
1796 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1800 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1802 vl_api_l2_flags_reply_t *rmp;
1804 u32 sw_if_index = ntohl (mp->sw_if_index);
1805 u32 flags = ntohl (mp->feature_bitmap);
1808 VALIDATE_SW_IF_INDEX (mp);
1811 if (flags & L2INPUT_FEAT_ ## a) \
1812 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1813 foreach_l2input_feat;
1816 BAD_SW_IF_INDEX_LABEL;
1819 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1821 rmp->resulting_feature_bitmap = ntohl(rbm);
1827 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1829 vlib_main_t *vm = vlib_get_main ();
1830 bd_main_t *bdm = &bd_main;
1831 vl_api_bridge_flags_reply_t *rmp;
1833 u32 bd_id = ntohl (mp->bd_id);
1835 u32 flags = ntohl (mp->feature_bitmap);
1838 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1841 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1847 bd_set_flags (vm, bd_index, flags, mp->is_set);
1851 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1853 rmp->resulting_feature_bitmap = ntohl(flags);
1859 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1861 bd_main_t *bdm = &bd_main;
1862 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1864 u32 bd_id = ntohl (mp->bd_id);
1868 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1871 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1876 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1877 mp->mac_address, mp->is_ipv6, mp->is_add))
1878 rv = VNET_API_ERROR_UNSPECIFIED;
1881 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1885 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1888 vl_api_tap_connect_reply_t *rmp;
1889 unix_shared_memory_queue_t *q;
1890 u32 sw_if_index = (u32) ~ 0;
1892 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1893 mp->use_random_mac ? 0 : mp->mac_address,
1894 &sw_if_index, mp->renumber,
1895 ntohl (mp->custom_dev_instance));
1897 q = vl_api_client_index_to_input_queue (mp->client_index);
1901 rmp = vl_msg_api_alloc (sizeof (*rmp));
1902 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1903 rmp->context = mp->context;
1904 rmp->retval = ntohl (rv);
1905 rmp->sw_if_index = ntohl (sw_if_index);
1907 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1911 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
1914 vl_api_tap_modify_reply_t *rmp;
1915 unix_shared_memory_queue_t *q;
1916 u32 sw_if_index = (u32) ~ 0;
1918 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1919 mp->use_random_mac ? 0 : mp->mac_address,
1920 &sw_if_index, mp->renumber,
1921 ntohl (mp->custom_dev_instance));
1923 q = vl_api_client_index_to_input_queue (mp->client_index);
1927 rmp = vl_msg_api_alloc (sizeof (*rmp));
1928 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1929 rmp->context = mp->context;
1930 rmp->retval = ntohl (rv);
1931 rmp->sw_if_index = ntohl (sw_if_index);
1933 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1937 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
1940 vpe_api_main_t *vam = &vpe_api_main;
1941 vl_api_tap_delete_reply_t *rmp;
1942 unix_shared_memory_queue_t *q;
1943 u32 sw_if_index = ntohl (mp->sw_if_index);
1945 rv = vnet_tap_delete (vm, sw_if_index);
1947 q = vl_api_client_index_to_input_queue (mp->client_index);
1951 rmp = vl_msg_api_alloc (sizeof (*rmp));
1952 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
1953 rmp->context = mp->context;
1954 rmp->retval = ntohl (rv);
1956 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1959 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1963 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1965 vl_api_create_vlan_subif_reply_t *rmp;
1966 vnet_main_t *vnm = vnet_get_main ();
1967 u32 hw_if_index, sw_if_index = (u32) ~ 0;
1968 vnet_hw_interface_t *hi;
1971 vnet_sw_interface_t template;
1973 vnet_interface_main_t *im = &vnm->interface_main;
1974 u64 sup_and_sub_key;
1976 unix_shared_memory_queue_t *q;
1977 clib_error_t *error;
1979 VALIDATE_SW_IF_INDEX (mp);
1981 hw_if_index = ntohl (mp->sw_if_index);
1982 hi = vnet_get_hw_interface (vnm, hw_if_index);
1984 id = ntohl (mp->vlan_id);
1985 if (id == 0 || id > 4095)
1987 rv = VNET_API_ERROR_INVALID_VLAN;
1991 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1993 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1996 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2000 kp = clib_mem_alloc (sizeof (*kp));
2001 *kp = sup_and_sub_key;
2003 memset (&template, 0, sizeof (template));
2004 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2005 template.sup_sw_if_index = hi->sw_if_index;
2006 template.sub.id = id;
2007 template.sub.eth.raw_flags = 0;
2008 template.sub.eth.flags.one_tag = 1;
2009 template.sub.eth.outer_vlan_id = id;
2010 template.sub.eth.flags.exact_match = 1;
2012 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2015 clib_error_report (error);
2016 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2019 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2020 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2022 BAD_SW_IF_INDEX_LABEL;
2025 q = vl_api_client_index_to_input_queue (mp->client_index);
2029 rmp = vl_msg_api_alloc (sizeof (*rmp));
2030 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2031 rmp->context = mp->context;
2032 rmp->retval = ntohl (rv);
2033 rmp->sw_if_index = ntohl (sw_if_index);
2034 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2038 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2040 vl_api_create_subif_reply_t *rmp;
2041 vnet_main_t *vnm = vnet_get_main ();
2042 u32 sw_if_index = ~0;
2045 vnet_sw_interface_t *si;
2046 vnet_hw_interface_t *hi;
2047 vnet_sw_interface_t template;
2049 vnet_interface_main_t *im = &vnm->interface_main;
2050 u64 sup_and_sub_key;
2052 clib_error_t *error;
2054 VALIDATE_SW_IF_INDEX (mp);
2056 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2057 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2059 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2061 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2065 sw_if_index = si->sw_if_index;
2066 sub_id = ntohl (mp->sub_id);
2068 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2070 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2074 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2075 sw_if_index, sub_id);
2076 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2080 kp = clib_mem_alloc (sizeof (*kp));
2081 *kp = sup_and_sub_key;
2083 memset (&template, 0, sizeof (template));
2084 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2085 template.sup_sw_if_index = sw_if_index;
2086 template.sub.id = sub_id;
2087 template.sub.eth.flags.no_tags = mp->no_tags;
2088 template.sub.eth.flags.one_tag = mp->one_tag;
2089 template.sub.eth.flags.two_tags = mp->two_tags;
2090 template.sub.eth.flags.dot1ad = mp->dot1ad;
2091 template.sub.eth.flags.exact_match = mp->exact_match;
2092 template.sub.eth.flags.default_sub = mp->default_sub;
2093 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2094 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2095 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2096 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2098 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2101 clib_error_report (error);
2102 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2106 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2107 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2109 BAD_SW_IF_INDEX_LABEL;
2114 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2116 rmp->sw_if_index = ntohl(sw_if_index);
2122 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2125 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2127 stats_main_t *sm = &stats_main;
2128 u32 tunnel_sw_if_index = ~0;
2130 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2132 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2133 (ip4_address_t *) (mp->dst_address),
2134 (ip4_address_t *) (mp->intfc_address),
2135 (u32) (mp->intfc_address_length),
2136 ntohl (mp->inner_vrf_id),
2137 ntohl (mp->outer_vrf_id),
2138 &tunnel_sw_if_index,
2139 mp->l2_only, mp->is_add);
2143 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2145 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2151 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2152 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2154 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2156 stats_main_t *sm = &stats_main;
2157 u32 tunnel_sw_if_index;
2159 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2161 rv = vnet_mpls_ethernet_add_del_tunnel
2162 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2163 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2164 ntohl (mp->tx_sw_if_index),
2165 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2170 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2172 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2178 * This piece of misery brought to you because the control-plane
2179 * can't figure out the tx interface + dst-mac address all by itself
2181 static int mpls_ethernet_add_del_tunnel_2_t_handler
2182 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2184 pending_route_t *pr;
2185 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2186 vnet_main_t *vnm = vnet_get_main ();
2187 vlib_main_t *vm = vlib_get_main ();
2188 stats_main_t *sm = &stats_main;
2189 vpe_api_main_t *vam = &vpe_api_main;
2190 u32 inner_fib_index, outer_fib_index;
2191 ip4_main_t *im = &ip4_main;
2192 ip_lookup_main_t *lm = &im->lookup_main;
2193 ip_adjacency_t *adj = 0;
2196 u8 *dst_mac_address;
2200 u32 tunnel_sw_if_index;
2202 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2204 return VNET_API_ERROR_NO_SUCH_FIB;
2206 outer_fib_index = p[0];
2209 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2211 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2213 inner_fib_index = p[0];
2215 if (inner_fib_index == outer_fib_index)
2216 return VNET_API_ERROR_INVALID_VALUE;
2218 lookup_result = ip4_fib_lookup_with_table
2219 (im, outer_fib_index,
2220 (ip4_address_t *) mp->next_hop_ip4_address_in_outer_vrf,
2221 1 /* disable default route */ );
2223 adj = ip_get_adjacency (lm, lookup_result);
2224 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2226 if (mp->is_add && mp->resolve_if_needed)
2228 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2230 pool_get (vam->pending_routes, pr);
2231 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2233 clib_memcpy (pme, mp, sizeof (*pme));
2234 /* recursion block, "just in case" */
2235 pme->resolve_if_needed = 0;
2236 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2237 pme->resolve_opaque = tx_sw_if_index;
2238 vnet_register_ip4_arp_resolution_event
2240 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2241 vpe_resolver_process_node.index,
2242 RESOLUTION_EVENT, pr - vam->pending_routes);
2244 vlib_process_signal_event
2245 (vm, vpe_resolver_process_node.index,
2246 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2248 /* The interface may be down, etc. */
2249 e = ip4_probe_neighbor
2250 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2254 clib_error_report (e);
2256 return VNET_API_ERROR_IN_PROGRESS;
2260 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2261 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2264 vnet_rewrite_get_data_internal
2265 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2267 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2269 rv = vnet_mpls_ethernet_add_del_tunnel
2270 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2271 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2272 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2280 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2281 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2283 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2286 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2288 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2293 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2295 vl_api_mpls_add_del_encap_reply_t *rmp;
2300 vec_reset_length (labels);
2302 for (i = 0; i < mp->nlabels; i++)
2303 vec_add1 (labels, ntohl (mp->labels[i]));
2306 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2307 ntohl (mp->vrf_id), labels,
2308 ~0 /* policy_tunnel_index */ ,
2309 0 /* no_dst_hash */ ,
2313 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2317 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2319 vl_api_mpls_add_del_decap_reply_t *rmp;
2322 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2323 ntohl (mp->label), ntohl (mp->next_index),
2324 mp->s_bit, mp->is_add);
2326 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2330 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2332 vl_api_proxy_arp_add_del_reply_t *rmp;
2335 ip4_main_t *im = &ip4_main;
2336 stats_main_t *sm = &stats_main;
2337 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2338 ip4_address_t * hi_addr,
2339 u32 fib_index, int is_del);
2342 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2344 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2348 rv = VNET_API_ERROR_NO_SUCH_FIB;
2354 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2355 (ip4_address_t *) mp->hi_address,
2356 fib_index, mp->is_add == 0);
2360 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2364 vl_api_proxy_arp_intfc_enable_disable_t_handler
2365 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2368 vnet_main_t *vnm = vnet_get_main ();
2369 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2370 vnet_sw_interface_t *si;
2373 VALIDATE_SW_IF_INDEX (mp);
2375 sw_if_index = ntohl (mp->sw_if_index);
2377 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2379 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2383 si = vnet_get_sw_interface (vnm, sw_if_index);
2387 if (mp->enable_disable)
2388 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2390 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2392 BAD_SW_IF_INDEX_LABEL;
2395 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2399 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2402 vl_api_ip_neighbor_add_del_reply_t *rmp;
2403 vnet_main_t *vnm = vnet_get_main ();
2406 stats_main_t *sm = &stats_main;
2408 VALIDATE_SW_IF_INDEX (mp);
2410 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2415 rv = vnet_set_ip6_ethernet_neighbor
2416 (vm, ntohl (mp->sw_if_index),
2417 (ip6_address_t *) (mp->dst_address),
2418 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2420 rv = vnet_unset_ip6_ethernet_neighbor
2421 (vm, ntohl (mp->sw_if_index),
2422 (ip6_address_t *) (mp->dst_address),
2423 mp->mac_address, sizeof (mp->mac_address));
2427 ip4_main_t *im = &ip4_main;
2428 ip_lookup_main_t *lm = &im->lookup_main;
2429 ethernet_arp_ip4_over_ethernet_address_t a;
2431 ip_adjacency_t *nh_adj;
2433 uword *p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2436 rv = VNET_API_ERROR_NO_SUCH_FIB;
2442 * Unfortunately, folks have a penchant for
2443 * adding interface addresses to the ARP cache, and
2444 * wondering why the forwarder eventually ASSERTs...
2446 ai = ip4_fib_lookup_with_table
2447 (im, fib_index, (ip4_address_t *) (mp->dst_address),
2448 1 /* disable default route */ );
2452 nh_adj = ip_get_adjacency (lm, ai);
2453 /* Never allow manipulation of a local adj! */
2454 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL)
2456 clib_warning ("%U matches local adj",
2458 (ip4_address_t *) (mp->dst_address));
2459 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2464 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2465 clib_memcpy (&a.ip4, mp->dst_address, 4);
2468 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2469 fib_index, &a, mp->is_static);
2471 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2475 BAD_SW_IF_INDEX_LABEL;
2478 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2482 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2485 vpe_main_t *rm = &vpe_main;
2486 ip4_main_t *im4 = &ip4_main;
2487 ip6_main_t *im6 = &ip6_main;
2488 ip_lookup_main_t *lm;
2494 u32 adj_index, sw_if_index;
2495 vl_api_is_address_reachable_t *rmp;
2496 ip_adjacency_t *adj;
2497 unix_shared_memory_queue_t *q;
2499 q = vl_api_client_index_to_input_queue (mp->client_index);
2502 increment_missing_api_client_counter (rm->vlib_main);
2506 rmp = vl_msg_api_alloc (sizeof (*rmp));
2507 clib_memcpy (rmp, mp, sizeof (*rmp));
2509 sw_if_index = mp->next_hop_sw_if_index;
2510 clib_memcpy (&addr, mp->address, sizeof (addr));
2513 lm = &im6->lookup_main;
2514 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2518 lm = &im4->lookup_main;
2519 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2521 if (adj_index == ~0)
2526 adj = ip_get_adjacency (lm, adj_index);
2528 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2529 && adj->rewrite_header.sw_if_index == sw_if_index)
2535 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2536 && adj->rewrite_header.sw_if_index == sw_if_index)
2539 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2541 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2543 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2552 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2557 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2559 clib_warning ("BUG");
2563 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2565 vl_api_sw_interface_set_flags_reply_t *rmp;
2566 vnet_main_t *vnm = vnet_get_main ();
2568 clib_error_t *error;
2571 VALIDATE_SW_IF_INDEX (mp);
2573 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2575 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2579 clib_error_report (error);
2582 BAD_SW_IF_INDEX_LABEL;
2583 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2587 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2590 vl_api_sw_interface_clear_stats_reply_t *rmp;
2592 vnet_main_t *vnm = vnet_get_main ();
2593 vnet_interface_main_t *im = &vnm->interface_main;
2594 vlib_simple_counter_main_t *sm;
2595 vlib_combined_counter_main_t *cm;
2596 static vnet_main_t **my_vnet_mains;
2597 int i, j, n_counters;
2600 if (mp->sw_if_index != ~0)
2601 VALIDATE_SW_IF_INDEX (mp);
2603 vec_reset_length (my_vnet_mains);
2605 for (i = 0; i < vec_len (vnet_mains); i++)
2608 vec_add1 (my_vnet_mains, vnet_mains[i]);
2611 if (vec_len (vnet_mains) == 0)
2612 vec_add1 (my_vnet_mains, vnm);
2614 n_counters = vec_len (im->combined_sw_if_counters);
2616 for (j = 0; j < n_counters; j++)
2618 for (i = 0; i < vec_len (my_vnet_mains); i++)
2620 im = &my_vnet_mains[i]->interface_main;
2621 cm = im->combined_sw_if_counters + j;
2622 if (mp->sw_if_index == (u32) ~ 0)
2623 vlib_clear_combined_counters (cm);
2625 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2629 n_counters = vec_len (im->sw_if_counters);
2631 for (j = 0; j < n_counters; j++)
2633 for (i = 0; i < vec_len (my_vnet_mains); i++)
2635 im = &my_vnet_mains[i]->interface_main;
2636 sm = im->sw_if_counters + j;
2637 if (mp->sw_if_index == (u32) ~ 0)
2638 vlib_clear_simple_counters (sm);
2640 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2644 BAD_SW_IF_INDEX_LABEL;
2646 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2650 send_sw_interface_details (vpe_api_main_t * am,
2651 unix_shared_memory_queue_t * q,
2652 vnet_sw_interface_t * swif,
2653 u8 * interface_name, u32 context)
2655 vl_api_sw_interface_details_t *mp;
2656 vnet_hw_interface_t *hi;
2658 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2660 mp = vl_msg_api_alloc (sizeof (*mp));
2661 memset (mp, 0, sizeof (*mp));
2662 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2663 mp->sw_if_index = ntohl (swif->sw_if_index);
2664 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2665 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2666 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2667 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2668 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2669 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2670 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2671 mp->link_mtu = ntohs (hi->max_packet_bytes);
2672 mp->context = context;
2674 strncpy ((char *) mp->interface_name,
2675 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2677 /* Send the L2 address for ethernet physical intfcs */
2678 if (swif->sup_sw_if_index == swif->sw_if_index
2679 && hi->hw_class_index == ethernet_hw_interface_class.index)
2681 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2682 ethernet_interface_t *ei;
2684 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2685 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2686 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2687 mp->l2_address_length = ntohl (sizeof (ei->address));
2689 else if (swif->sup_sw_if_index != swif->sw_if_index)
2691 vnet_sub_interface_t *sub = &swif->sub;
2692 mp->sub_id = ntohl (sub->id);
2693 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2694 mp->sub_number_of_tags =
2695 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2696 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2697 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2698 mp->sub_exact_match = sub->eth.flags.exact_match;
2699 mp->sub_default = sub->eth.flags.default_sub;
2700 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2701 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2703 /* vlan tag rewrite data */
2704 u32 vtr_op = L2_VTR_DISABLED;
2705 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2707 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2708 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2710 // error - default to disabled
2711 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2712 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2717 mp->vtr_op = ntohl (vtr_op);
2718 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2719 mp->vtr_tag1 = ntohl (vtr_tag1);
2720 mp->vtr_tag2 = ntohl (vtr_tag2);
2724 vl_msg_api_send_shmem (q, (u8 *) & mp);
2728 send_sw_interface_flags (vpe_api_main_t * am,
2729 unix_shared_memory_queue_t * q,
2730 vnet_sw_interface_t * swif)
2732 vl_api_sw_interface_set_flags_t *mp;
2733 vnet_main_t *vnm = am->vnet_main;
2735 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2737 mp = vl_msg_api_alloc (sizeof (*mp));
2738 memset (mp, 0, sizeof (*mp));
2739 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2740 mp->sw_if_index = ntohl (swif->sw_if_index);
2742 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2743 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2744 vl_msg_api_send_shmem (q, (u8 *) & mp);
2747 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2748 unix_shared_memory_queue_t * q,
2750 __attribute__ ((unused));
2753 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2754 unix_shared_memory_queue_t * q,
2757 vl_api_sw_interface_set_flags_t *mp;
2759 mp = vl_msg_api_alloc (sizeof (*mp));
2760 memset (mp, 0, sizeof (*mp));
2761 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2762 mp->sw_if_index = ntohl (sw_if_index);
2764 mp->admin_up_down = 0;
2765 mp->link_up_down = 0;
2767 vl_msg_api_send_shmem (q, (u8 *) & mp);
2771 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2773 vpe_api_main_t *am = &vpe_api_main;
2774 vnet_sw_interface_t *swif;
2775 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2776 u8 *filter_string = 0, *name_string = 0;
2777 unix_shared_memory_queue_t *q;
2778 char *strcasestr (char *, char *); /* lnx hdr file botch */
2780 q = vl_api_client_index_to_input_queue (mp->client_index);
2785 if (mp->name_filter_valid)
2787 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2788 filter_string = format (0, "%s%c", mp->name_filter, 0);
2792 pool_foreach (swif, im->sw_interfaces,
2794 name_string = format (name_string, "%U%c",
2795 format_vnet_sw_interface_name,
2796 am->vnet_main, swif, 0);
2798 if (mp->name_filter_valid == 0 ||
2799 strcasestr((char *) name_string, (char *) filter_string)) {
2801 send_sw_interface_details (am, q, swif, name_string, mp->context);
2803 _vec_len (name_string) = 0;
2807 vec_free (name_string);
2808 vec_free (filter_string);
2812 send_oam_event (oam_target_t * t)
2814 vpe_api_main_t *vam = &vpe_api_main;
2815 unix_shared_memory_queue_t *q;
2816 vpe_client_registration_t *reg;
2817 vl_api_oam_event_t *mp;
2820 pool_foreach(reg, vam->oam_events_registrations,
2822 q = vl_api_client_index_to_input_queue (reg->client_index);
2825 mp = vl_msg_api_alloc (sizeof (*mp));
2826 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2827 clib_memcpy (mp->dst_address, &t->dst_address,
2828 sizeof (mp->dst_address));
2829 mp->state = t->state;
2830 vl_msg_api_send_shmem (q, (u8 *)&mp);
2837 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2839 vl_api_oam_add_del_reply_t *rmp;
2842 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2843 (ip4_address_t *) mp->dst_address,
2844 ntohl (mp->vrf_id), (int) (mp->is_add));
2846 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2850 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2852 stats_main_t *sm = &stats_main;
2853 vnet_interface_main_t *im = sm->interface_main;
2854 vl_api_vnet_summary_stats_reply_t *rmp;
2855 vlib_combined_counter_main_t *cm;
2858 u64 total_pkts[VLIB_N_RX_TX];
2859 u64 total_bytes[VLIB_N_RX_TX];
2861 unix_shared_memory_queue_t *q =
2862 vl_api_client_index_to_input_queue (mp->client_index);
2867 rmp = vl_msg_api_alloc (sizeof (*rmp));
2868 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2869 rmp->context = mp->context;
2872 memset (total_pkts, 0, sizeof (total_pkts));
2873 memset (total_bytes, 0, sizeof (total_bytes));
2875 vnet_interface_counter_lock (im);
2877 vec_foreach (cm, im->combined_sw_if_counters)
2879 which = cm - im->combined_sw_if_counters;
2881 for (i = 0; i < vec_len (cm->maxi); i++)
2883 vlib_get_combined_counter (cm, i, &v);
2884 total_pkts[which] += v.packets;
2885 total_bytes[which] += v.bytes;
2888 vnet_interface_counter_unlock (im);
2890 /* Note: in HOST byte order! */
2891 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2892 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2893 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2894 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2895 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2897 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2901 typedef CLIB_PACKED (struct {
2902 ip4_address_t address;
2903 u32 address_length: 6;
2909 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2911 vnet_main_t *vnm = vnet_get_main ();
2912 vnet_interface_main_t *im = &vnm->interface_main;
2913 ip4_main_t *im4 = &ip4_main;
2914 static ip4_route_t *routes;
2915 static u32 *sw_if_indices_to_shut;
2916 stats_main_t *sm = &stats_main;
2921 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2922 u32 target_fib_id = ntohl (mp->vrf_id);
2924 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2926 vec_foreach (fib, im4->fibs)
2928 vnet_sw_interface_t *si;
2930 if (fib->table_id != target_fib_id)
2933 /* remove any mpls/gre tunnels in this fib */
2934 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2936 /* remove any mpls encap/decap labels */
2937 mpls_fib_reset_labels (fib->table_id);
2939 /* remove any proxy arps in this fib */
2940 vnet_proxy_arp_fib_reset (fib->table_id);
2942 /* Set the flow hash for this fib to the default */
2943 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2945 vec_reset_length (sw_if_indices_to_shut);
2947 /* Shut down interfaces in this FIB / clean out intfc routes */
2949 pool_foreach (si, im->sw_interfaces,
2951 u32 sw_if_index = si->sw_if_index;
2953 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2954 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2956 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2960 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
2962 sw_if_index = sw_if_indices_to_shut[i];
2963 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2965 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2966 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2967 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2970 vec_reset_length (routes);
2972 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++)
2974 uword *hash = fib->adj_index_by_dst_address[i];
2978 x.address_length = i;
2981 hash_foreach_pair (p, hash,
2983 x.address.data_u32 = p->key;
2984 vec_add1 (routes, x);
2989 vec_foreach (r, routes)
2991 ip4_add_del_route_args_t a;
2993 memset (&a, 0, sizeof (a));
2994 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2995 a.table_index_or_table_id = fib - im4->fibs;
2996 a.dst_address = r->address;
2997 a.dst_address_length = r->address_length;
3000 ip4_add_del_route (im4, &a);
3001 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
3002 IP4_ROUTE_FLAG_FIB_INDEX);
3006 } /* vec_foreach (fib) */
3014 ip6_address_t address;
3022 ip6_route_t **routep;
3023 } add_routes_in_fib_arg_t;
3026 add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
3028 add_routes_in_fib_arg_t *ap = arg;
3030 if (kvp->key[2] >> 32 == ap->fib_index)
3032 ip6_address_t *addr;
3034 addr = (ip6_address_t *) kvp;
3035 vec_add2 (*ap->routep, r, 1);
3036 r->address = addr[0];
3037 r->address_length = kvp->key[2] & 0xFF;
3038 r->index = kvp->value;
3043 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3045 vnet_main_t *vnm = vnet_get_main ();
3046 vnet_interface_main_t *im = &vnm->interface_main;
3047 ip6_main_t *im6 = &ip6_main;
3048 stats_main_t *sm = &stats_main;
3049 static ip6_route_t *routes;
3050 static u32 *sw_if_indices_to_shut;
3055 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3056 u32 target_fib_id = ntohl (mp->vrf_id);
3057 add_routes_in_fib_arg_t _a, *a = &_a;
3058 clib_bihash_24_8_t *h = &im6->ip6_lookup_table;
3060 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3062 vec_foreach (fib, im6->fibs)
3064 vnet_sw_interface_t *si;
3066 if (fib->table_id != target_fib_id)
3069 vec_reset_length (sw_if_indices_to_shut);
3071 /* Shut down interfaces in this FIB / clean out intfc routes */
3073 pool_foreach (si, im->sw_interfaces,
3075 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3077 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3081 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3083 sw_if_index = sw_if_indices_to_shut[i];
3084 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3086 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3087 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3088 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3091 vec_reset_length (routes);
3093 a->fib_index = fib - im6->fibs;
3094 a->routep = &routes;
3096 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
3098 vec_foreach (r, routes)
3100 ip6_add_del_route_args_t a;
3102 memset (&a, 0, sizeof (a));
3103 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
3104 a.table_index_or_table_id = fib - im6->fibs;
3105 a.dst_address = r->address;
3106 a.dst_address_length = r->address_length;
3109 ip6_add_del_route (im6, &a);
3110 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
3111 IP6_ROUTE_FLAG_FIB_INDEX);
3114 /* Reinstall the neighbor / router discovery routes */
3115 vnet_ip6_fib_init (im6, fib - im6->fibs);
3117 } /* vec_foreach (fib) */
3124 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3127 vl_api_reset_fib_reply_t *rmp;
3130 rv = ip6_reset_fib_t_handler (mp);
3132 rv = ip4_reset_fib_t_handler (mp);
3134 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3139 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3141 vl_api_dhcp_proxy_config_reply_t *rmp;
3144 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3145 (ip4_address_t *) (&mp->dhcp_src_address),
3146 (u32) ntohl (mp->vrf_id),
3147 (int) mp->insert_circuit_id,
3148 (int) (mp->is_add == 0));
3150 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3155 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3157 vl_api_dhcp_proxy_config_reply_t *rmp;
3160 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3161 (ip6_address_t *) (&mp->dhcp_src_address),
3162 (u32) ntohl (mp->vrf_id),
3163 (int) mp->insert_circuit_id,
3164 (int) (mp->is_add == 0));
3166 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3170 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3172 vl_api_dhcp_proxy_config_reply_t *rmp;
3175 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3176 (ip4_address_t *) (&mp->dhcp_src_address),
3177 (u32) ntohl (mp->rx_vrf_id),
3178 (u32) ntohl (mp->server_vrf_id),
3179 (int) mp->insert_circuit_id,
3180 (int) (mp->is_add == 0));
3182 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3187 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3189 vl_api_dhcp_proxy_config_reply_t *rmp;
3193 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3194 (ip6_address_t *) (&mp->dhcp_src_address),
3195 (u32) ntohl (mp->rx_vrf_id),
3196 (u32) ntohl (mp->server_vrf_id),
3197 (int) mp->insert_circuit_id,
3198 (int) (mp->is_add == 0));
3200 rv = VNET_API_ERROR_UNIMPLEMENTED;
3203 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3208 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3210 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3213 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3216 (int) mp->is_add == 0);
3218 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3220 ntohl (mp->fib_id), (int) mp->is_add == 0);
3222 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3226 static void vl_api_dhcp_proxy_config_t_handler
3227 (vl_api_dhcp_proxy_config_t * mp)
3229 if (mp->is_ipv6 == 0)
3230 dhcpv4_proxy_config (mp);
3232 dhcpv6_proxy_config (mp);
3235 static void vl_api_dhcp_proxy_config_2_t_handler
3236 (vl_api_dhcp_proxy_config_2_t * mp)
3238 if (mp->is_ipv6 == 0)
3239 dhcpv4_proxy_config_2 (mp);
3241 dhcpv6_proxy_config_2 (mp);
3245 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3246 u8 is_ipv6, u8 * host_address, u8 * router_address,
3249 unix_shared_memory_queue_t *q;
3250 vl_api_dhcp_compl_event_t *mp;
3252 q = vl_api_client_index_to_input_queue (client_index);
3256 mp = vl_msg_api_alloc (sizeof (*mp));
3257 mp->client_index = client_index;
3259 mp->is_ipv6 = is_ipv6;
3260 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3261 mp->hostname[vec_len (hostname) + 1] = '\n';
3262 clib_memcpy (&mp->host_address[0], host_address, 16);
3263 clib_memcpy (&mp->router_address[0], router_address, 16);
3264 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3266 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3268 vl_msg_api_send_shmem (q, (u8 *) & mp);
3271 static void vl_api_dhcp_client_config_t_handler
3272 (vl_api_dhcp_client_config_t * mp)
3274 vlib_main_t *vm = vlib_get_main ();
3275 vl_api_dhcp_client_config_reply_t *rmp;
3278 VALIDATE_SW_IF_INDEX (mp);
3280 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3281 mp->hostname, mp->is_add, mp->client_index,
3282 mp->want_dhcp_event ? dhcp_compl_event_callback :
3285 BAD_SW_IF_INDEX_LABEL;
3287 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3291 vl_api_sw_interface_ip6nd_ra_config_t_handler
3292 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3294 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3296 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3299 is_no = mp->is_no == 1;
3300 suppress = mp->suppress == 1;
3301 managed = mp->managed == 1;
3302 other = mp->other == 1;
3303 ll_option = mp->ll_option == 1;
3304 send_unicast = mp->send_unicast == 1;
3305 cease = mp->cease == 1;
3306 default_router = mp->default_router == 1;
3308 VALIDATE_SW_IF_INDEX (mp);
3310 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3311 suppress, managed, other,
3312 ll_option, send_unicast, cease,
3313 default_router, ntohl (mp->lifetime),
3314 ntohl (mp->initial_count),
3315 ntohl (mp->initial_interval),
3316 ntohl (mp->max_interval),
3317 ntohl (mp->min_interval), is_no);
3319 BAD_SW_IF_INDEX_LABEL;
3321 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3325 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3326 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3328 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3330 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3332 VALIDATE_SW_IF_INDEX (mp);
3334 is_no = mp->is_no == 1;
3335 use_default = mp->use_default == 1;
3336 no_advertise = mp->no_advertise == 1;
3337 off_link = mp->off_link == 1;
3338 no_autoconfig = mp->no_autoconfig == 1;
3339 no_onlink = mp->no_onlink == 1;
3341 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3342 (ip6_address_t *) mp->address,
3343 mp->address_length, use_default,
3344 ntohl (mp->val_lifetime),
3345 ntohl (mp->pref_lifetime), no_advertise,
3346 off_link, no_autoconfig, no_onlink, is_no);
3348 BAD_SW_IF_INDEX_LABEL;
3349 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3353 vl_api_sw_interface_ip6_enable_disable_t_handler
3354 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3356 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3357 vnet_main_t *vnm = vnet_get_main ();
3359 clib_error_t *error;
3363 VALIDATE_SW_IF_INDEX (mp);
3366 (mp->enable == 1) ? enable_ip6_interface (vm,
3367 ntohl (mp->sw_if_index)) :
3368 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3372 clib_error_report (error);
3373 rv = VNET_API_ERROR_UNSPECIFIED;
3377 rv = vnm->api_errno;
3380 BAD_SW_IF_INDEX_LABEL;
3382 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3386 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3387 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3389 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3391 clib_error_t *error;
3392 vnet_main_t *vnm = vnet_get_main ();
3396 VALIDATE_SW_IF_INDEX (mp);
3398 error = set_ip6_link_local_address (vm,
3399 ntohl (mp->sw_if_index),
3400 (ip6_address_t *) mp->address,
3401 mp->address_length);
3404 clib_error_report (error);
3405 rv = VNET_API_ERROR_UNSPECIFIED;
3409 rv = vnm->api_errno;
3412 BAD_SW_IF_INDEX_LABEL;
3414 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3418 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3420 vl_api_set_ip_flow_hash_reply_t *rmp;
3421 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3423 clib_warning ("unimplemented...");
3425 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3429 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3431 vl_api_set_ip_flow_hash_reply_t *rmp;
3434 u32 flow_hash_config = 0;
3436 table_id = ntohl (mp->vrf_id);
3438 #define _(a,b) if (mp->a) flow_hash_config |= b;
3439 foreach_flow_hash_bit;
3442 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3444 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3449 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3451 if (mp->is_ipv6 == 0)
3452 set_ip4_flow_hash (mp);
3454 set_ip6_flow_hash (mp);
3457 static void vl_api_sw_interface_set_unnumbered_t_handler
3458 (vl_api_sw_interface_set_unnumbered_t * mp)
3460 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3462 vnet_sw_interface_t *si;
3463 vnet_main_t *vnm = vnet_get_main ();
3464 u32 sw_if_index, unnumbered_sw_if_index;
3466 sw_if_index = ntohl (mp->sw_if_index);
3467 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3470 * The API message field names are backwards from
3471 * the underlying data structure names.
3472 * It's not worth changing them now.
3474 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3475 unnumbered_sw_if_index))
3477 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3481 /* Only check the "use loop0" field when setting the binding */
3483 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3485 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3489 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3493 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3494 si->unnumbered_sw_if_index = sw_if_index;
3498 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3499 si->unnumbered_sw_if_index = (u32) ~ 0;
3503 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3507 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3509 vl_api_create_loopback_reply_t *rmp;
3513 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3516 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3518 rmp->sw_if_index = ntohl (sw_if_index);
3524 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3526 vl_api_delete_loopback_reply_t *rmp;
3530 sw_if_index = ntohl (mp->sw_if_index);
3531 rv = vnet_delete_loopback_interface (sw_if_index);
3533 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3537 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3539 vl_api_control_ping_reply_t *rmp;
3543 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3545 rmp->vpe_pid = ntohl (getpid());
3550 static void vl_api_noprint_control_ping_t_handler
3551 (vl_api_noprint_control_ping_t * mp)
3553 vl_api_noprint_control_ping_reply_t *rmp;
3557 REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY,
3559 rmp->vpe_pid = ntohl (getpid());
3565 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3567 u8 **shmem_vecp = (u8 **) arg;
3570 api_main_t *am = &api_main;
3573 shmem_vec = *shmem_vecp;
3575 offset = vec_len (shmem_vec);
3577 pthread_mutex_lock (&am->vlib_rp->mutex);
3578 oldheap = svm_push_data_heap (am->vlib_rp);
3580 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3582 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3584 svm_pop_heap (oldheap);
3585 pthread_mutex_unlock (&am->vlib_rp->mutex);
3587 *shmem_vecp = shmem_vec;
3592 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3594 vl_api_cli_reply_t *rp;
3595 unix_shared_memory_queue_t *q;
3596 vlib_main_t *vm = vlib_get_main ();
3597 api_main_t *am = &api_main;
3598 unformat_input_t input;
3602 q = vl_api_client_index_to_input_queue (mp->client_index);
3606 rp = vl_msg_api_alloc (sizeof (*rp));
3607 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3608 rp->context = mp->context;
3610 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3612 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3614 pthread_mutex_lock (&am->vlib_rp->mutex);
3615 oldheap = svm_push_data_heap (am->vlib_rp);
3617 vec_add1 (shmem_vec, 0);
3619 svm_pop_heap (oldheap);
3620 pthread_mutex_unlock (&am->vlib_rp->mutex);
3622 rp->reply_in_shmem = (uword) shmem_vec;
3624 vl_msg_api_send_shmem (q, (u8 *) & rp);
3628 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3631 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3632 vnet_main_t *vnm = vnet_get_main ();
3633 clib_error_t *error;
3638 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3640 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3644 clib_error_report (error);
3645 rv = VNET_API_ERROR_UNSPECIFIED;
3649 rv = vnm->api_errno;
3652 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3655 static void vl_api_sr_tunnel_add_del_t_handler
3656 (vl_api_sr_tunnel_add_del_t * mp)
3659 clib_warning ("unimplemented");
3661 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3663 vl_api_sr_tunnel_add_del_reply_t *rmp;
3664 ip6_address_t *segments = 0, *seg;
3665 ip6_address_t *tags = 0, *tag;
3666 ip6_address_t *this_address;
3669 if (mp->n_segments == 0)
3675 memset (a, 0, sizeof (*a));
3676 a->src_address = (ip6_address_t *) & mp->src_address;
3677 a->dst_address = (ip6_address_t *) & mp->dst_address;
3678 a->dst_mask_width = mp->dst_mask_width;
3679 a->flags_net_byte_order = mp->flags_net_byte_order;
3680 a->is_del = (mp->is_add == 0);
3681 a->rx_table_id = ntohl (mp->outer_vrf_id);
3682 a->tx_table_id = ntohl (mp->inner_vrf_id);
3684 a->name = format (0, "%s", mp->name);
3685 if (!(vec_len (a->name)))
3688 a->policy_name = format (0, "%s", mp->policy_name);
3689 if (!(vec_len (a->policy_name)))
3692 /* Yank segments and tags out of the API message */
3693 this_address = (ip6_address_t *) mp->segs_and_tags;
3694 for (i = 0; i < mp->n_segments; i++)
3696 vec_add2 (segments, seg, 1);
3697 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3700 for (i = 0; i < mp->n_tags; i++)
3702 vec_add2 (tags, tag, 1);
3703 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3707 a->segments = segments;
3710 rv = ip6_sr_add_del_tunnel (a);
3714 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3718 static void vl_api_sr_policy_add_del_t_handler
3719 (vl_api_sr_policy_add_del_t * mp)
3722 clib_warning ("unimplemented");
3724 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3726 vl_api_sr_policy_add_del_reply_t *rmp;
3729 memset (a, 0, sizeof (*a));
3730 a->is_del = (mp->is_add == 0);
3732 a->name = format (0, "%s", mp->name);
3733 if (!(vec_len (a->name)))
3735 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3739 if (!(mp->tunnel_names[0]))
3741 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3745 // start deserializing tunnel_names
3746 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3747 u8 *deser_tun_names = mp->tunnel_names;
3748 deser_tun_names += 1; //moving along
3751 int tun_name_len = 0;
3753 for (i = 0; i < num_tunnels; i++)
3755 tun_name_len = *deser_tun_names;
3756 deser_tun_names += 1;
3757 vec_resize (tun_name, tun_name_len);
3758 memcpy (tun_name, deser_tun_names, tun_name_len);
3759 vec_add1 (a->tunnel_names, tun_name);
3760 deser_tun_names += tun_name_len;
3764 rv = ip6_sr_add_del_policy (a);
3768 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3772 static void vl_api_sr_multicast_map_add_del_t_handler
3773 (vl_api_sr_multicast_map_add_del_t * mp)
3776 clib_warning ("unimplemented");
3778 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3780 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3782 memset (a, 0, sizeof (*a));
3783 a->is_del = (mp->is_add == 0);
3785 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3786 a->policy_name = format (0, "%s", mp->policy_name);
3788 if (a->multicast_address == 0)
3794 if (!(a->policy_name))
3800 #if DPDK > 0 /* Cannot call replicate without DPDK */
3801 rv = ip6_sr_add_del_multicastmap (a);
3803 clib_warning ("multicast replication without DPDK not implemented");
3804 rv = VNET_API_ERROR_UNIMPLEMENTED;
3809 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3813 #define foreach_classify_add_del_table_field \
3818 _(match_n_vectors) \
3819 _(next_table_index) \
3822 static void vl_api_classify_add_del_table_t_handler
3823 (vl_api_classify_add_del_table_t * mp)
3825 vl_api_classify_add_del_table_reply_t *rmp;
3826 vnet_classify_main_t *cm = &vnet_classify_main;
3827 vnet_classify_table_t *t;
3831 foreach_classify_add_del_table_field;
3834 #define _(a) a = ntohl(mp->a);
3835 foreach_classify_add_del_table_field;
3838 /* The underlying API fails silently, on purpose, so check here */
3839 if (mp->is_add == 0)
3840 if (pool_is_free_index (cm->tables, table_index))
3842 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3846 rv = vnet_classify_add_del_table
3847 (cm, mp->mask, nbuckets, memory_size,
3848 skip_n_vectors, match_n_vectors,
3849 next_table_index, miss_next_index, &table_index, mp->is_add);
3853 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3855 if (rv == 0 && mp->is_add)
3857 t = pool_elt_at_index (cm->tables, table_index);
3858 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3859 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3860 rmp->new_table_index = ntohl(table_index);
3864 rmp->skip_n_vectors = ~0;
3865 rmp->match_n_vectors = ~0;
3866 rmp->new_table_index = ~0;
3872 static void vl_api_classify_add_del_session_t_handler
3873 (vl_api_classify_add_del_session_t * mp)
3875 vnet_classify_main_t *cm = &vnet_classify_main;
3876 vl_api_classify_add_del_session_reply_t *rmp;
3878 u32 table_index, hit_next_index, opaque_index;
3881 table_index = ntohl (mp->table_index);
3882 hit_next_index = ntohl (mp->hit_next_index);
3883 opaque_index = ntohl (mp->opaque_index);
3884 advance = ntohl (mp->advance);
3886 rv = vnet_classify_add_del_session
3887 (cm, table_index, mp->match, hit_next_index, opaque_index,
3888 advance, mp->is_add);
3890 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3893 static void vl_api_classify_set_interface_ip_table_t_handler
3894 (vl_api_classify_set_interface_ip_table_t * mp)
3896 vlib_main_t *vm = vlib_get_main ();
3897 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3899 u32 table_index, sw_if_index;
3901 table_index = ntohl (mp->table_index);
3902 sw_if_index = ntohl (mp->sw_if_index);
3904 VALIDATE_SW_IF_INDEX (mp);
3907 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3909 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3911 BAD_SW_IF_INDEX_LABEL;
3913 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3916 static void vl_api_classify_set_interface_l2_tables_t_handler
3917 (vl_api_classify_set_interface_l2_tables_t * mp)
3919 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3921 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3924 ip4_table_index = ntohl (mp->ip4_table_index);
3925 ip6_table_index = ntohl (mp->ip6_table_index);
3926 other_table_index = ntohl (mp->other_table_index);
3927 sw_if_index = ntohl (mp->sw_if_index);
3929 VALIDATE_SW_IF_INDEX (mp);
3931 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3932 ip6_table_index, other_table_index);
3936 if (ip4_table_index != ~0 || ip6_table_index != ~0
3937 || other_table_index != ~0)
3942 vnet_l2_classify_enable_disable (sw_if_index, enable);
3945 BAD_SW_IF_INDEX_LABEL;
3947 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3951 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
3954 vl_api_l2_fib_clear_table_reply_t *rmp;
3956 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3957 * that is not currently implemented. When that TODO is fixed
3958 * this call should be changed to pass 1 instead of 0.
3960 l2fib_clear_table (0);
3962 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3965 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
3966 u32 sw_if_index, u32 enable);
3969 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
3973 vl_api_l2_interface_efp_filter_reply_t *rmp;
3974 vnet_main_t *vnm = vnet_get_main ();
3976 // enable/disable the feature
3977 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3978 rv = vnm->api_errno;
3980 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3984 vl_api_l2_interface_vlan_tag_rewrite_t_handler
3985 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
3988 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
3989 vnet_main_t *vnm = vnet_get_main ();
3990 vlib_main_t *vm = vlib_get_main ();
3993 VALIDATE_SW_IF_INDEX (mp);
3995 vtr_op = ntohl (mp->vtr_op);
3997 /* The L2 code is unsuspicious */
4000 case L2_VTR_DISABLED:
4005 case L2_VTR_TRANSLATE_1_1:
4006 case L2_VTR_TRANSLATE_1_2:
4007 case L2_VTR_TRANSLATE_2_1:
4008 case L2_VTR_TRANSLATE_2_2:
4012 rv = VNET_API_ERROR_INVALID_VALUE;
4013 goto bad_sw_if_index;
4016 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4017 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4020 BAD_SW_IF_INDEX_LABEL;
4022 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4026 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4029 vl_api_create_vhost_user_if_reply_t *rmp;
4031 u32 sw_if_index = (u32) ~ 0;
4033 vnet_main_t *vnm = vnet_get_main ();
4034 vlib_main_t *vm = vlib_get_main ();
4036 rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
4037 mp->is_server, &sw_if_index, (u64) ~ 0,
4038 mp->renumber, ntohl (mp->custom_dev_instance),
4039 (mp->use_custom_mac) ? mp->mac_address : NULL);
4042 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4044 rmp->sw_if_index = ntohl (sw_if_index);
4048 rv = VNET_API_ERROR_UNIMPLEMENTED;
4049 REPLY_MACRO (VL_API_CREATE_VHOST_USER_IF_REPLY);
4054 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4057 vl_api_modify_vhost_user_if_reply_t *rmp;
4058 #if DPDK > 0 && DPDK_VHOST_USER
4059 u32 sw_if_index = ntohl (mp->sw_if_index);
4061 vnet_main_t *vnm = vnet_get_main ();
4062 vlib_main_t *vm = vlib_get_main ();
4064 rv = dpdk_vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
4065 mp->is_server, sw_if_index, (u64) ~ 0,
4067 ntohl (mp->custom_dev_instance));
4069 rv = VNET_API_ERROR_UNIMPLEMENTED;
4071 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4075 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4078 vl_api_delete_vhost_user_if_reply_t *rmp;
4079 #if DPDK > 0 && DPDK_VHOST_USER
4080 vpe_api_main_t *vam = &vpe_api_main;
4081 u32 sw_if_index = ntohl (mp->sw_if_index);
4083 vnet_main_t *vnm = vnet_get_main ();
4084 vlib_main_t *vm = vlib_get_main ();
4086 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4088 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4091 unix_shared_memory_queue_t *q =
4092 vl_api_client_index_to_input_queue (mp->client_index);
4096 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4099 rv = VNET_API_ERROR_UNIMPLEMENTED;
4100 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4105 vl_api_sw_interface_vhost_user_details_t_handler
4106 (vl_api_sw_interface_vhost_user_details_t * mp)
4108 clib_warning ("BUG");
4111 #if DPDK > 0 && DPDK_VHOST_USER
4113 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4114 unix_shared_memory_queue_t * q,
4115 vhost_user_intf_details_t * vui,
4118 vl_api_sw_interface_vhost_user_details_t *mp;
4120 mp = vl_msg_api_alloc (sizeof (*mp));
4121 memset (mp, 0, sizeof (*mp));
4122 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4123 mp->sw_if_index = ntohl (vui->sw_if_index);
4124 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4125 mp->features = clib_net_to_host_u64 (vui->features);
4126 mp->is_server = vui->is_server;
4127 mp->num_regions = ntohl (vui->num_regions);
4128 mp->sock_errno = ntohl (vui->sock_errno);
4129 mp->context = context;
4131 strncpy ((char *) mp->sock_filename,
4132 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4133 strncpy ((char *) mp->interface_name,
4134 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4136 vl_msg_api_send_shmem (q, (u8 *) & mp);
4141 vl_api_sw_interface_vhost_user_dump_t_handler
4142 (vl_api_sw_interface_vhost_user_dump_t * mp)
4144 #if DPDK > 0 && DPDK_VHOST_USER
4146 vpe_api_main_t *am = &vpe_api_main;
4147 vnet_main_t *vnm = vnet_get_main ();
4148 vlib_main_t *vm = vlib_get_main ();
4149 vhost_user_intf_details_t *ifaces = NULL;
4150 vhost_user_intf_details_t *vuid = NULL;
4151 unix_shared_memory_queue_t *q;
4153 q = vl_api_client_index_to_input_queue (mp->client_index);
4157 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4161 vec_foreach (vuid, ifaces)
4163 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4170 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4171 unix_shared_memory_queue_t * q,
4173 l2t_main_t * lm, u32 context)
4175 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4177 vnet_sw_interface_t *si = NULL;
4179 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4181 if_name = format (if_name, "%U",
4182 format_vnet_sw_interface_name, lm->vnet_main, si);
4184 mp = vl_msg_api_alloc (sizeof (*mp));
4185 memset (mp, 0, sizeof (*mp));
4186 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4187 strncpy ((char *) mp->interface_name,
4188 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4189 mp->sw_if_index = ntohl (si->sw_if_index);
4190 mp->local_session_id = s->local_session_id;
4191 mp->remote_session_id = s->remote_session_id;
4192 mp->local_cookie[0] = s->local_cookie[0];
4193 mp->local_cookie[1] = s->local_cookie[1];
4194 mp->remote_cookie = s->remote_cookie;
4195 clib_memcpy (mp->client_address, &s->client_address,
4196 sizeof (s->client_address));
4197 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4198 mp->l2_sublayer_present = s->l2_sublayer_present;
4199 mp->context = context;
4201 vl_msg_api_send_shmem (q, (u8 *) & mp);
4205 send_ip_address_details (vpe_api_main_t * am,
4206 unix_shared_memory_queue_t * q,
4207 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4209 vl_api_ip_address_details_t *mp;
4211 mp = vl_msg_api_alloc (sizeof (*mp));
4212 memset (mp, 0, sizeof (*mp));
4213 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4217 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4221 u32 *tp = (u32 *) mp->ip;
4222 *tp = ntohl (*(u32 *) ip);
4224 mp->prefix_length = prefix_length;
4225 mp->context = context;
4227 vl_msg_api_send_shmem (q, (u8 *) & mp);
4231 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4233 vpe_api_main_t *am = &vpe_api_main;
4234 unix_shared_memory_queue_t *q;
4237 ip6_main_t *im6 = &ip6_main;
4238 ip4_main_t *im4 = &ip4_main;
4239 ip_lookup_main_t *lm6 = &im6->lookup_main;
4240 ip_lookup_main_t *lm4 = &im4->lookup_main;
4241 ip_interface_address_t *ia = 0;
4242 u32 sw_if_index = ~0;
4243 int rv __attribute__ ((unused)) = 0;
4245 VALIDATE_SW_IF_INDEX (mp);
4247 sw_if_index = ntohl (mp->sw_if_index);
4249 q = vl_api_client_index_to_input_queue (mp->client_index);
4258 foreach_ip_interface_address (lm6, ia, sw_if_index,
4259 1 /* honor unnumbered */,
4261 r6 = ip_interface_address_get_address (lm6, ia);
4262 u16 prefix_length = ia->address_length;
4263 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4270 foreach_ip_interface_address (lm4, ia, sw_if_index,
4271 1 /* honor unnumbered */,
4273 r4 = ip_interface_address_get_address (lm4, ia);
4274 u16 prefix_length = ia->address_length;
4275 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4279 BAD_SW_IF_INDEX_LABEL;
4283 send_ip_details (vpe_api_main_t * am,
4284 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4286 vl_api_ip_details_t *mp;
4288 mp = vl_msg_api_alloc (sizeof (*mp));
4289 memset (mp, 0, sizeof (*mp));
4290 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4292 mp->sw_if_index = ntohl (sw_if_index);
4293 mp->context = context;
4295 vl_msg_api_send_shmem (q, (u8 *) & mp);
4299 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4302 vpe_api_main_t *am = &vpe_api_main;
4303 l2t_main_t *lm = &l2t_main;
4304 unix_shared_memory_queue_t *q;
4305 l2t_session_t *session;
4307 q = vl_api_client_index_to_input_queue (mp->client_index);
4312 pool_foreach (session, lm->sessions,
4314 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4321 send_sw_interface_tap_details (vpe_api_main_t * am,
4322 unix_shared_memory_queue_t * q,
4323 tapcli_interface_details_t * tap_if,
4326 vl_api_sw_interface_tap_details_t *mp;
4327 mp = vl_msg_api_alloc (sizeof (*mp));
4328 memset (mp, 0, sizeof (*mp));
4329 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4330 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4331 strncpy ((char *) mp->dev_name,
4332 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4333 mp->context = context;
4335 vl_msg_api_send_shmem (q, (u8 *) & mp);
4339 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4342 vpe_api_main_t *am = &vpe_api_main;
4343 unix_shared_memory_queue_t *q;
4344 tapcli_interface_details_t *tapifs = NULL;
4345 tapcli_interface_details_t *tap_if = NULL;
4347 q = vl_api_client_index_to_input_queue (mp->client_index);
4351 rv = vnet_tap_dump_ifs (&tapifs);
4355 vec_foreach (tap_if, tapifs)
4357 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4364 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4366 vpe_api_main_t *am = &vpe_api_main;
4367 vnet_main_t *vnm = vnet_get_main ();
4368 vlib_main_t *vm = vlib_get_main ();
4369 vnet_interface_main_t *im = &vnm->interface_main;
4370 unix_shared_memory_queue_t *q;
4371 vnet_sw_interface_t *si, *sorted_sis;
4372 u32 sw_if_index = ~0;
4374 q = vl_api_client_index_to_input_queue (mp->client_index);
4380 /* Gather interfaces. */
4381 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4382 _vec_len (sorted_sis) = 0;
4384 pool_foreach (si, im->sw_interfaces,
4386 vec_add1 (sorted_sis, si[0]);
4390 vec_foreach (si, sorted_sis)
4392 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4394 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4398 sw_if_index = si->sw_if_index;
4399 send_ip_details (am, q, sw_if_index, mp->context);
4405 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4407 clib_warning ("BUG");
4411 send_l2fib_table_entry (vpe_api_main_t * am,
4412 unix_shared_memory_queue_t * q,
4413 l2fib_entry_key_t * l2fe_key,
4414 l2fib_entry_result_t * l2fe_res, u32 context)
4416 vl_api_l2_fib_table_entry_t *mp;
4418 mp = vl_msg_api_alloc (sizeof (*mp));
4419 memset (mp, 0, sizeof (*mp));
4420 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4423 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4425 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4426 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4427 mp->static_mac = l2fe_res->fields.static_mac;
4428 mp->filter_mac = l2fe_res->fields.filter;
4429 mp->bvi_mac = l2fe_res->fields.bvi;
4430 mp->context = context;
4432 vl_msg_api_send_shmem (q, (u8 *) & mp);
4436 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4438 vpe_api_main_t *am = &vpe_api_main;
4439 bd_main_t *bdm = &bd_main;
4440 l2fib_entry_key_t *l2fe_key = NULL;
4441 l2fib_entry_result_t *l2fe_res = NULL;
4442 u32 ni, bd_id = ntohl (mp->bd_id);
4444 unix_shared_memory_queue_t *q;
4447 q = vl_api_client_index_to_input_queue (mp->client_index);
4451 /* see l2fib_table_dump: ~0 means "any" */
4456 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4463 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4465 vec_foreach_index (ni, l2fe_key)
4467 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4468 vec_elt_at_index (l2fe_res, ni), mp->context);
4470 vec_free (l2fe_key);
4471 vec_free (l2fe_res);
4475 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4477 vl_api_show_version_reply_t *rmp;
4479 char *vpe_api_get_build_directory (void);
4480 char *vpe_api_get_version (void);
4481 char *vpe_api_get_build_date (void);
4483 unix_shared_memory_queue_t *q =
4484 vl_api_client_index_to_input_queue (mp->client_index);
4490 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4492 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4493 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4494 ARRAY_LEN(rmp->build_directory)-1);
4495 strncpy ((char *) rmp->version, vpe_api_get_version(),
4496 ARRAY_LEN(rmp->version)-1);
4497 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4498 ARRAY_LEN(rmp->build_date)-1);
4504 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4506 vlib_main_t *vm = vlib_get_main ();
4507 vl_api_get_node_index_reply_t *rmp;
4510 u32 node_index = ~0;
4512 n = vlib_get_node_by_name (vm, mp->node_name);
4515 rv = VNET_API_ERROR_NO_SUCH_NODE;
4517 node_index = n->index;
4520 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4522 rmp->node_index = ntohl(node_index);
4528 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4530 vlib_main_t *vm = vlib_get_main ();
4531 vl_api_get_next_index_reply_t *rmp;
4532 vlib_node_t *node, *next_node;
4534 u32 next_node_index = ~0, next_index = ~0;
4537 node = vlib_get_node_by_name (vm, mp->node_name);
4541 rv = VNET_API_ERROR_NO_SUCH_NODE;
4545 next_node = vlib_get_node_by_name (vm, mp->next_name);
4549 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4553 next_node_index = next_node->index;
4555 p = hash_get (node->next_slot_by_node, next_node_index);
4559 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4567 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4569 rmp->next_index = ntohl(next_index);
4575 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4577 vlib_main_t *vm = vlib_get_main ();
4578 vl_api_add_node_next_reply_t *rmp;
4579 vlib_node_t *n, *next;
4581 u32 next_index = ~0;
4583 n = vlib_get_node_by_name (vm, mp->node_name);
4587 rv = VNET_API_ERROR_NO_SUCH_NODE;
4591 next = vlib_get_node_by_name (vm, mp->next_name);
4594 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4596 next_index = vlib_node_add_next (vm, n->index, next->index);
4600 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4602 rmp->next_index = ntohl(next_index);
4607 static void vl_api_l2tpv3_create_tunnel_t_handler
4608 (vl_api_l2tpv3_create_tunnel_t * mp)
4610 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4611 l2t_main_t *lm = &l2t_main;
4612 u32 sw_if_index = (u32) ~ 0;
4615 if (mp->is_ipv6 != 1)
4617 rv = VNET_API_ERROR_UNIMPLEMENTED;
4621 u32 encap_fib_index;
4623 if (mp->encap_vrf_id != ~0)
4626 ip6_main_t *im = &ip6_main;
4629 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4631 rv = VNET_API_ERROR_NO_SUCH_FIB;
4634 encap_fib_index = p[0];
4638 encap_fib_index = ~0;
4641 rv = create_l2tpv3_ipv6_tunnel (lm,
4642 (ip6_address_t *) mp->client_address,
4643 (ip6_address_t *) mp->our_address,
4644 ntohl (mp->local_session_id),
4645 ntohl (mp->remote_session_id),
4646 clib_net_to_host_u64 (mp->local_cookie),
4647 clib_net_to_host_u64 (mp->remote_cookie),
4648 mp->l2_sublayer_present,
4649 encap_fib_index, &sw_if_index);
4653 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4655 rmp->sw_if_index = ntohl (sw_if_index);
4660 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4661 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4663 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4664 l2t_main_t *lm = &l2t_main;
4667 VALIDATE_SW_IF_INDEX (mp);
4669 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4670 clib_net_to_host_u64 (mp->new_local_cookie),
4671 clib_net_to_host_u64
4672 (mp->new_remote_cookie));
4674 BAD_SW_IF_INDEX_LABEL;
4676 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4679 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4680 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4683 vnet_main_t *vnm = vnet_get_main ();
4684 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4686 VALIDATE_SW_IF_INDEX (mp);
4688 rv = l2tpv3_interface_enable_disable
4689 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4691 BAD_SW_IF_INDEX_LABEL;
4693 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4696 static void vl_api_l2tpv3_set_lookup_key_t_handler
4697 (vl_api_l2tpv3_set_lookup_key_t * mp)
4700 l2t_main_t *lm = &l2t_main;
4701 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4703 if (mp->key > L2T_LOOKUP_SESSION_ID)
4705 rv = VNET_API_ERROR_INVALID_VALUE;
4709 lm->lookup_type = mp->key;
4712 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4715 static void vl_api_vxlan_add_del_tunnel_t_handler
4716 (vl_api_vxlan_add_del_tunnel_t * mp)
4718 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4720 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4721 u32 encap_fib_index;
4723 ip4_main_t *im = &ip4_main;
4724 u32 sw_if_index = ~0;
4726 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4729 rv = VNET_API_ERROR_NO_SUCH_FIB;
4732 encap_fib_index = p[0];
4734 /* Check src & dst are different */
4735 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4736 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4738 rv = VNET_API_ERROR_SAME_SRC_DST;
4741 memset (a, 0, sizeof (*a));
4743 a->is_add = mp->is_add;
4744 a->is_ip6 = mp->is_ipv6;
4746 /* ip addresses sent in network byte order */
4749 memcpy (&(a->src.ip6), mp->src_address, 16);
4750 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4754 memcpy (&(a->src.ip4), mp->src_address, 4);
4755 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4758 a->encap_fib_index = encap_fib_index;
4759 a->decap_next_index = ntohl (mp->decap_next_index);
4760 a->vni = ntohl (mp->vni);
4761 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4765 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4767 rmp->sw_if_index = ntohl (sw_if_index);
4772 static void send_vxlan_tunnel_details
4773 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4775 vl_api_vxlan_tunnel_details_t *rmp;
4776 ip4_main_t *im4 = &ip4_main;
4777 ip6_main_t *im6 = &ip6_main;
4778 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4780 rmp = vl_msg_api_alloc (sizeof (*rmp));
4781 memset (rmp, 0, sizeof (*rmp));
4782 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4785 memcpy (rmp->src_address, &(t->src.ip6), 16);
4786 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4787 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
4791 memcpy (rmp->src_address, &(t->src.ip4), 4);
4792 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4793 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
4795 rmp->vni = htonl (t->vni);
4796 rmp->decap_next_index = htonl (t->decap_next_index);
4797 rmp->sw_if_index = htonl (t->sw_if_index);
4798 rmp->is_ipv6 = is_ipv6;
4799 rmp->context = context;
4801 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4804 static void vl_api_vxlan_tunnel_dump_t_handler
4805 (vl_api_vxlan_tunnel_dump_t * mp)
4807 unix_shared_memory_queue_t *q;
4808 vxlan_main_t *vxm = &vxlan_main;
4812 q = vl_api_client_index_to_input_queue (mp->client_index);
4818 sw_if_index = ntohl (mp->sw_if_index);
4820 if (~0 == sw_if_index)
4823 pool_foreach (t, vxm->tunnels,
4825 send_vxlan_tunnel_details(t, q, mp->context);
4831 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4832 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4836 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4837 send_vxlan_tunnel_details (t, q, mp->context);
4841 static void vl_api_gre_add_del_tunnel_t_handler
4842 (vl_api_gre_add_del_tunnel_t * mp)
4844 vl_api_gre_add_del_tunnel_reply_t *rmp;
4846 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4849 ip4_main_t *im = &ip4_main;
4850 u32 sw_if_index = ~0;
4852 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4855 rv = VNET_API_ERROR_NO_SUCH_FIB;
4858 outer_fib_id = p[0];
4860 /* Check src & dst are different */
4861 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4862 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4864 rv = VNET_API_ERROR_SAME_SRC_DST;
4867 memset (a, 0, sizeof (*a));
4869 a->is_add = mp->is_add;
4871 /* ip addresses sent in network byte order */
4872 clib_memcpy (&(a->src), mp->src_address, 4);
4873 clib_memcpy (&(a->dst), mp->dst_address, 4);
4875 a->outer_fib_id = outer_fib_id;
4876 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4880 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4882 rmp->sw_if_index = ntohl (sw_if_index);
4887 static void send_gre_tunnel_details
4888 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4890 vl_api_gre_tunnel_details_t *rmp;
4891 ip4_main_t *im = &ip4_main;
4893 rmp = vl_msg_api_alloc (sizeof (*rmp));
4894 memset (rmp, 0, sizeof (*rmp));
4895 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4896 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4897 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4898 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
4899 rmp->sw_if_index = htonl (t->sw_if_index);
4900 rmp->context = context;
4902 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4906 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4908 unix_shared_memory_queue_t *q;
4909 gre_main_t *gm = &gre_main;
4913 q = vl_api_client_index_to_input_queue (mp->client_index);
4919 sw_if_index = ntohl (mp->sw_if_index);
4921 if (~0 == sw_if_index)
4924 pool_foreach (t, gm->tunnels,
4926 send_gre_tunnel_details(t, q, mp->context);
4932 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
4933 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
4937 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4938 send_gre_tunnel_details (t, q, mp->context);
4943 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
4945 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4947 vl_api_l2_patch_add_del_reply_t *rmp;
4948 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4952 VALIDATE_RX_SW_IF_INDEX (mp);
4953 VALIDATE_TX_SW_IF_INDEX (mp);
4955 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
4956 ntohl (mp->tx_sw_if_index),
4957 (int) (mp->is_add != 0));
4959 BAD_RX_SW_IF_INDEX_LABEL;
4960 BAD_TX_SW_IF_INDEX_LABEL;
4962 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
4966 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4967 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4969 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
4971 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4972 u32 encap_fib_index, decap_fib_index;
4975 ip4_main_t *im = &ip4_main;
4976 u32 sw_if_index = ~0;
4979 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4982 rv = VNET_API_ERROR_NO_SUCH_FIB;
4985 encap_fib_index = p[0];
4987 protocol = mp->protocol;
4989 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4990 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
4992 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
4995 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4998 decap_fib_index = p[0];
5002 decap_fib_index = ntohl (mp->decap_vrf_id);
5005 /* Check src & dst are different */
5006 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5007 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5009 rv = VNET_API_ERROR_SAME_SRC_DST;
5012 memset (a, 0, sizeof (*a));
5014 a->is_add = mp->is_add;
5015 a->is_ip6 = mp->is_ipv6;
5016 /* ip addresses sent in network byte order */
5019 clib_memcpy (&(a->local.ip6), mp->local, 16);
5020 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5024 clib_memcpy (&(a->local.ip4), mp->local, 4);
5025 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5027 a->encap_fib_index = encap_fib_index;
5028 a->decap_fib_index = decap_fib_index;
5029 a->protocol = protocol;
5030 a->vni = ntohl (mp->vni);
5031 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5035 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5037 rmp->sw_if_index = ntohl (sw_if_index);
5042 static void send_vxlan_gpe_tunnel_details
5043 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5045 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5046 ip4_main_t *im4 = &ip4_main;
5047 ip6_main_t *im6 = &ip6_main;
5048 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5050 rmp = vl_msg_api_alloc (sizeof (*rmp));
5051 memset (rmp, 0, sizeof (*rmp));
5052 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5055 memcpy (rmp->local, &(t->local.ip6), 16);
5056 memcpy (rmp->remote, &(t->remote.ip6), 16);
5057 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
5058 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].table_id);
5062 memcpy (rmp->local, &(t->local.ip4), 4);
5063 memcpy (rmp->remote, &(t->remote.ip4), 4);
5064 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
5065 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].table_id);
5067 rmp->vni = htonl (t->vni);
5068 rmp->protocol = t->protocol;
5069 rmp->sw_if_index = htonl (t->sw_if_index);
5070 rmp->is_ipv6 = is_ipv6;
5071 rmp->context = context;
5073 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5076 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5077 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5079 unix_shared_memory_queue_t *q;
5080 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5081 vxlan_gpe_tunnel_t *t;
5084 q = vl_api_client_index_to_input_queue (mp->client_index);
5090 sw_if_index = ntohl (mp->sw_if_index);
5092 if (~0 == sw_if_index)
5095 pool_foreach (t, vgm->tunnels,
5097 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5103 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5104 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5108 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5109 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5113 /** Used for transferring locators via VPP API */
5115 typedef CLIB_PACKED (struct {
5116 u32 sw_if_index; /**< locator sw_if_index */
5117 u8 priority; /**< locator priority */
5118 u8 weight; /**< locator weight */
5123 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5126 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5128 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5130 ls_locator_t *ls_loc;
5132 u8 *locator_name = NULL;
5135 memset (a, 0, sizeof (a[0]));
5137 locator_name = format (0, "%s", mp->locator_set_name);
5139 a->name = locator_name;
5140 a->is_add = mp->is_add;
5143 memset (&locator, 0, sizeof (locator));
5144 for (i = 0; i < mp->locator_num; i++)
5146 ls_loc = &((ls_locator_t *) mp->locators)[i];
5147 VALIDATE_SW_IF_INDEX (ls_loc);
5149 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5150 locator.priority = ls_loc->priority;
5151 locator.weight = ls_loc->weight;
5153 vec_add1 (a->locators, locator);
5156 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5158 BAD_SW_IF_INDEX_LABEL;
5160 vec_free (locator_name);
5161 vec_free (a->locators);
5164 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5166 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5172 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5174 vl_api_lisp_add_del_locator_reply_t *rmp;
5176 locator_t locator, *locators = NULL;
5177 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5179 u8 *locator_name = NULL;
5181 memset (&locator, 0, sizeof (locator));
5182 memset (a, 0, sizeof (a[0]));
5184 locator.sw_if_index = ntohl (mp->sw_if_index);
5185 locator.priority = mp->priority;
5186 locator.weight = mp->weight;
5188 vec_add1 (locators, locator);
5190 locator_name = format (0, "%s", mp->locator_set_name);
5192 a->name = locator_name;
5193 a->locators = locators;
5194 a->is_add = mp->is_add;
5197 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5199 vec_free (locators);
5200 vec_free (locator_name);
5202 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5206 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5212 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5213 gid_address_ip_set (dst, src, IP4);
5214 gid_address_ippref_len (dst) = len;
5215 ip_prefix_normalize (&gid_address_ippref (dst));
5218 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5219 gid_address_ip_set (dst, src, IP6);
5220 gid_address_ippref_len (dst) = len;
5221 ip_prefix_normalize (&gid_address_ippref (dst));
5223 case 2: /* l2 mac */
5224 gid_address_type (dst) = GID_ADDR_MAC;
5225 clib_memcpy (&gid_address_mac (dst), src, 6);
5229 return VNET_API_ERROR_INVALID_VALUE;
5232 gid_address_vni (dst) = vni;
5238 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5240 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5241 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5243 gid_address_t _eid, *eid = &_eid;
5245 u32 locator_set_index = ~0, map_index = ~0;
5246 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5248 memset (a, 0, sizeof (a[0]));
5249 memset (eid, 0, sizeof (eid[0]));
5251 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5252 mp->eid_type, mp->eid, mp->prefix_len);
5256 name = format (0, "%s", mp->locator_set_name);
5257 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5260 rv = VNET_API_ERROR_INVALID_VALUE;
5263 locator_set_index = p[0];
5265 /* XXX treat batch configuration */
5266 a->is_add = mp->is_add;
5267 gid_address_copy (&a->eid, eid);
5268 a->locator_set_index = locator_set_index;
5270 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5274 gid_address_free (&a->eid);
5276 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5280 vl_api_lisp_eid_table_add_del_map_t_handler
5281 (vl_api_lisp_eid_table_add_del_map_t * mp)
5283 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5285 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5286 clib_net_to_host_u32 (mp->dp_table),
5287 mp->is_l2, mp->is_add);
5288 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5290 /** Used for transferring locators via VPP API */
5292 typedef CLIB_PACKED (struct {
5293 u8 is_ip4; /**< is locator an IPv4 address */
5294 u8 priority; /**< locator priority */
5295 u8 weight; /**< locator weight */
5296 u8 addr[16]; /**< IPv4/IPv6 address */
5300 static locator_pair_t *
5301 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5304 locator_pair_t *pairs = 0, pair;
5307 for (i = 0; i < rloc_num; i++)
5310 r = &((rloc_t *) lcl_locs)[i];
5311 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5312 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5314 /* remote locators */
5315 r = &((rloc_t *) rmt_locs)[i];
5316 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5317 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5319 pair.priority = r->priority;
5320 pair.weight = r->weight;
5322 vec_add1 (pairs, pair);
5328 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5331 locator_t *locs = 0, loc;
5334 for (i = 0; i < rloc_num; i++)
5336 /* remote locators */
5337 r = &((rloc_t *) rmt_locs)[i];
5338 memset (&loc, 0, sizeof (loc));
5339 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5341 loc.priority = r->priority;
5342 loc.weight = r->weight;
5344 vec_add1 (locs, loc);
5350 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5351 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5353 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5354 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5355 locator_pair_t *pairs = 0;
5358 memset (a, 0, sizeof (a[0]));
5360 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5361 mp->rmt_eid, mp->rmt_len);
5362 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5363 mp->lcl_eid, mp->lcl_len);
5365 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5367 if (rv || 0 == pairs)
5370 a->is_add = mp->is_add;
5371 a->locator_pairs = pairs;
5372 a->dp_table = mp->dp_table;
5374 a->action = mp->action;
5376 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5379 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5383 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5386 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5388 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5390 memset (a, 0, sizeof (a[0]));
5392 a->is_add = mp->is_add;
5393 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5395 rv = vnet_lisp_add_del_map_resolver (a);
5397 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5401 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5404 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5406 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5408 a->is_en = mp->is_en;
5409 vnet_lisp_gpe_enable_disable (a);
5411 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5415 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5417 vl_api_lisp_enable_disable_reply_t *rmp;
5420 vnet_lisp_enable_disable (mp->is_en);
5421 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5425 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5427 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5429 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5431 a->is_add = mp->is_add;
5432 a->dp_table = mp->dp_table;
5434 a->is_l2 = mp->is_l2;
5435 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5437 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5441 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5444 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5448 ls_name = format (0, "%s", mp->ls_name);
5449 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5452 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5456 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5457 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5459 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5461 u8 *locator_set_name = NULL;
5462 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5464 locator_set_name = format (0, "%s", mp->locator_set_name);
5466 a->is_add = mp->is_add;
5467 a->locator_set_name = locator_set_name;
5469 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5471 vec_free (locator_set_name);
5473 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5477 vl_api_lisp_add_del_remote_mapping_t_handler
5478 (vl_api_lisp_add_del_remote_mapping_t * mp)
5480 locator_t *rlocs = 0;
5481 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5483 gid_address_t _eid, *eid = &_eid;
5485 memset (eid, 0, sizeof (eid[0]));
5487 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5488 mp->eid_type, mp->eid, mp->eid_len);
5492 rlocs = unformat_lisp_locs (mp->rlocs, mp->rloc_num);
5498 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5499 gid_address_copy (&a->deid, eid);
5501 rv = vnet_lisp_add_del_adjacency (a);
5508 /* NOTE: for now this works as a static remote mapping, i.e.,
5509 * not authoritative and ttl infinite. */
5510 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5511 mp->is_add, 1 /* is_static */ , 0);
5514 vnet_lisp_clear_all_remote_adjacencies ();
5519 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5523 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5525 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5526 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5529 memset (a, 0, sizeof (a[0]));
5531 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5532 mp->eid_type, mp->seid, mp->seid_len);
5533 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5534 mp->eid_type, mp->deid, mp->deid_len);
5539 a->is_add = mp->is_add;
5540 rv = vnet_lisp_add_del_adjacency (a);
5543 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5547 send_lisp_locator_details (lisp_cp_main_t * lcm,
5549 unix_shared_memory_queue_t * q, u32 context)
5551 vl_api_lisp_locator_details_t *rmp;
5553 rmp = vl_msg_api_alloc (sizeof (*rmp));
5554 memset (rmp, 0, sizeof (*rmp));
5555 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5556 rmp->context = context;
5558 rmp->local = loc->local;
5561 rmp->sw_if_index = ntohl (loc->sw_if_index);
5565 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5566 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5568 rmp->priority = loc->priority;
5569 rmp->weight = loc->weight;
5571 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5575 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5577 unix_shared_memory_queue_t *q = 0;
5578 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5579 locator_set_t *lsit = 0;
5581 u32 ls_index = ~0, *locit = 0;
5584 q = vl_api_client_index_to_input_queue (mp->client_index);
5590 ls_index = htonl (mp->locator_set_index);
5592 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5594 filter = mp->filter;
5595 if (filter && !((1 == filter && lsit->local) ||
5596 (2 == filter && !lsit->local)))
5601 vec_foreach (locit, lsit->locator_indices)
5603 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5604 send_lisp_locator_details (lcm, loc, q, mp->context);
5609 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5610 locator_set_t * lsit,
5611 unix_shared_memory_queue_t * q,
5612 u32 context, u32 ls_index)
5614 vl_api_lisp_locator_set_details_t *rmp;
5617 rmp = vl_msg_api_alloc (sizeof (*rmp));
5618 memset (rmp, 0, sizeof (*rmp));
5619 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5620 rmp->context = context;
5622 rmp->local = lsit->local;
5623 rmp->locator_set_index = htonl (ls_index);
5626 ASSERT (lsit->name != NULL);
5627 strncpy ((char *) rmp->locator_set_name,
5628 (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1);
5632 str = format (0, "remote-%d", ls_index);
5633 strncpy ((char *) rmp->locator_set_name, (char *) str,
5634 ARRAY_LEN (rmp->locator_set_name) - 1);
5638 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5642 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5644 unix_shared_memory_queue_t *q = NULL;
5645 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5646 locator_set_t *lsit = NULL;
5650 q = vl_api_client_index_to_input_queue (mp->client_index);
5656 filter = mp->filter;
5659 pool_foreach (lsit, lcm->locator_set_pool,
5661 if (filter && !((1 == filter && lsit->local) ||
5662 (2 == filter && !lsit->local))) {
5666 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5672 send_lisp_eid_table_details (mapping_t * mapit,
5673 unix_shared_memory_queue_t * q,
5674 u32 context, u8 filter)
5676 vl_api_lisp_eid_table_details_t *rmp = NULL;
5677 gid_address_t *gid = NULL;
5679 ip_prefix_t *ip_prefix = NULL;
5683 case 0: /* all mappings */
5686 case 1: /* local only */
5690 case 2: /* remote only */
5695 clib_warning ("Filter error, unknown filter: %d", filter);
5700 ip_prefix = &gid_address_ippref (gid);
5701 mac = gid_address_mac (gid);
5703 rmp = vl_msg_api_alloc (sizeof (*rmp));
5704 memset (rmp, 0, sizeof (*rmp));
5705 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5706 rmp->locator_set_index = mapit->locator_set_index;
5707 rmp->is_local = mapit->local;
5708 rmp->ttl = mapit->ttl;
5709 rmp->authoritative = mapit->authoritative;
5711 switch (gid_address_type (gid))
5713 case GID_ADDR_IP_PREFIX:
5714 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5715 if (ip_prefix_version (ip_prefix) == IP4)
5717 rmp->eid_type = 0; /* ipv4 type */
5718 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5719 sizeof (ip_prefix_v4 (ip_prefix)));
5723 rmp->eid_type = 1; /* ipv6 type */
5724 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5725 sizeof (ip_prefix_v6 (ip_prefix)));
5729 rmp->eid_type = 2; /* l2 mac type */
5730 clib_memcpy (rmp->eid, mac, 6);
5735 rmp->context = context;
5736 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5737 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5741 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5744 unix_shared_memory_queue_t *q = NULL;
5745 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5746 mapping_t *mapit = NULL;
5747 gid_address_t _eid, *eid = &_eid;
5749 q = vl_api_client_index_to_input_queue (mp->client_index);
5757 memset (eid, 0, sizeof (*eid));
5759 unformat_lisp_eid_api (eid, mp->eid_type,
5760 clib_net_to_host_u32 (mp->vni), mp->eid,
5763 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5764 if ((u32) ~ 0 == mi)
5767 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5768 send_lisp_eid_table_details (mapit, q, mp->context,
5769 0 /* ignore filter */ );
5774 pool_foreach (mapit, lcm->mapping_pool,
5776 send_lisp_eid_table_details(mapit, q, mp->context,
5784 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5785 unix_shared_memory_queue_t * q, u32 context)
5787 vl_api_lisp_gpe_tunnel_details_t *rmp;
5788 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5790 rmp = vl_msg_api_alloc (sizeof (*rmp));
5791 memset (rmp, 0, sizeof (*rmp));
5792 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5794 rmp->tunnels = tunnel - lgm->tunnels;
5796 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5797 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5798 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5800 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5801 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5802 rmp->dcap_next = htonl (tunnel->decap_next_index);
5803 rmp->lisp_ver = tunnel->ver_res;
5804 rmp->next_protocol = tunnel->next_protocol;
5805 rmp->flags = tunnel->flags;
5806 rmp->ver_res = tunnel->ver_res;
5807 rmp->res = tunnel->res;
5808 rmp->iid = htonl (tunnel->vni);
5809 rmp->context = context;
5811 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5815 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5817 unix_shared_memory_queue_t *q = NULL;
5818 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5819 lisp_gpe_tunnel_t *tunnel = NULL;
5821 if (pool_elts (lgm->tunnels) == 0)
5826 q = vl_api_client_index_to_input_queue (mp->client_index);
5833 pool_foreach(tunnel, lgm->tunnels,
5835 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5841 send_lisp_map_resolver_details (ip_address_t * ip,
5842 unix_shared_memory_queue_t * q, u32 context)
5844 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5846 rmp = vl_msg_api_alloc (sizeof (*rmp));
5847 memset (rmp, 0, sizeof (*rmp));
5848 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5850 switch (ip_addr_version (ip))
5854 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5855 sizeof (ip_addr_v4 (ip)));
5860 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5861 sizeof (ip_addr_v6 (ip)));
5867 rmp->context = context;
5869 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5873 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5875 unix_shared_memory_queue_t *q = NULL;
5876 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5879 q = vl_api_client_index_to_input_queue (mp->client_index);
5885 vec_foreach (mr, lcm->map_resolvers)
5887 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5892 send_eid_table_map_pair (hash_pair_t * p,
5893 unix_shared_memory_queue_t * q, u32 context)
5895 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5897 rmp = vl_msg_api_alloc (sizeof (*rmp));
5898 memset (rmp, 0, sizeof (*rmp));
5899 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5901 rmp->vni = clib_host_to_net_u32 (p->key);
5902 rmp->vrf = clib_host_to_net_u32 (p->value[0]);
5903 rmp->context = context;
5904 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5908 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5911 unix_shared_memory_queue_t *q = NULL;
5912 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5915 q = vl_api_client_index_to_input_queue (mp->client_index);
5921 hash_foreach_pair (p, lcm->table_id_by_vni,
5923 send_eid_table_map_pair (p, q, mp->context);
5929 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
5931 unix_shared_memory_queue_t *q = NULL;
5932 vl_api_show_lisp_status_reply_t *rmp = NULL;
5935 q = vl_api_client_index_to_input_queue (mp->client_index);
5942 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5944 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5945 rmp->feature_status = vnet_lisp_enable_disable_status ();
5951 vl_api_lisp_get_map_request_itr_rlocs_t_handler
5952 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
5954 unix_shared_memory_queue_t *q = NULL;
5955 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5956 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5957 locator_set_t *loc_set = 0;
5961 q = vl_api_client_index_to_input_queue (mp->client_index);
5967 if (~0 == lcm->mreq_itr_rlocs)
5969 tmp_str = format (0, " ");
5974 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5975 tmp_str = format (0, "%s", loc_set->name);
5979 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5981 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5982 ARRAY_LEN(rmp->locator_set_name) - 1);
5990 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5992 unix_shared_memory_queue_t *q = NULL;
5993 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
5994 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5996 locator_set_t *ls = 0;
6000 q = vl_api_client_index_to_input_queue (mp->client_index);
6006 if (!lcm->lisp_pitr)
6008 tmp_str = format (0, "N/A");
6012 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6013 if (~0 != m->locator_set_index)
6016 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6017 tmp_str = format (0, "%s", ls->name);
6021 tmp_str = format (0, "N/A");
6024 vec_add1 (tmp_str, 0);
6027 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6029 rmp->status = lcm->lisp_pitr;
6030 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6031 ARRAY_LEN(rmp->locator_set_name) - 1);
6037 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6040 vl_api_interface_name_renumber_reply_t *rmp;
6043 VALIDATE_SW_IF_INDEX (mp);
6045 rv = vnet_interface_name_renumber
6046 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6048 BAD_SW_IF_INDEX_LABEL;
6050 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6054 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6055 u32 sw_if_index, u32 address)
6057 vpe_api_main_t *am = &vpe_api_main;
6058 vlib_main_t *vm = am->vlib_main;
6059 vl_api_ip4_arp_event_t *event;
6060 static f64 arp_event_last_time;
6061 f64 now = vlib_time_now (vm);
6063 if (pool_is_free_index (am->arp_events, pool_index))
6066 event = pool_elt_at_index (am->arp_events, pool_index);
6067 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6069 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6073 if ((sw_if_index == event->sw_if_index) && ((address == 0) ||
6074 /* for BD case, also check IP address with 10 sec timeout */
6075 ((address == event->address)
6078 arp_event_last_time) <
6083 arp_event_last_time = now;
6084 event->sw_if_index = sw_if_index;
6086 event->address = address;
6091 arp_change_delete_callback (u32 pool_index, u8 * notused)
6093 vpe_api_main_t *am = &vpe_api_main;
6095 if (pool_is_free_index (am->arp_events, pool_index))
6098 pool_put_index (am->arp_events, pool_index);
6103 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6105 vpe_api_main_t *am = &vpe_api_main;
6106 vnet_main_t *vnm = vnet_get_main ();
6107 vl_api_want_ip4_arp_events_reply_t *rmp;
6108 vl_api_ip4_arp_event_t *event;
6111 if (mp->enable_disable)
6113 pool_get (am->arp_events, event);
6114 memset (event, 0, sizeof (*event));
6116 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6117 event->client_index = mp->client_index;
6118 event->context = mp->context;
6119 event->address = mp->address;
6120 event->pid = mp->pid;
6122 rv = vnet_add_del_ip4_arp_change_event
6123 (vnm, arp_change_data_callback,
6124 mp->pid, &mp->address /* addr, in net byte order */ ,
6125 vpe_resolver_process_node.index,
6126 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6130 rv = vnet_add_del_ip4_arp_change_event
6131 (vnm, arp_change_delete_callback,
6132 mp->pid, &mp->address /* addr, in net byte order */ ,
6133 vpe_resolver_process_node.index,
6134 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6136 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6139 static void vl_api_input_acl_set_interface_t_handler
6140 (vl_api_input_acl_set_interface_t * mp)
6142 vlib_main_t *vm = vlib_get_main ();
6143 vl_api_input_acl_set_interface_reply_t *rmp;
6145 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6147 ip4_table_index = ntohl (mp->ip4_table_index);
6148 ip6_table_index = ntohl (mp->ip6_table_index);
6149 l2_table_index = ntohl (mp->l2_table_index);
6150 sw_if_index = ntohl (mp->sw_if_index);
6152 VALIDATE_SW_IF_INDEX (mp);
6154 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6155 ip6_table_index, l2_table_index, mp->is_add);
6157 BAD_SW_IF_INDEX_LABEL;
6159 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6162 static void vl_api_ipsec_spd_add_del_t_handler
6163 (vl_api_ipsec_spd_add_del_t * mp)
6166 clib_warning ("unimplemented");
6169 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6170 vl_api_ipsec_spd_add_del_reply_t *rmp;
6174 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6176 rv = VNET_API_ERROR_UNIMPLEMENTED;
6179 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6183 static void vl_api_ipsec_interface_add_del_spd_t_handler
6184 (vl_api_ipsec_interface_add_del_spd_t * mp)
6186 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6187 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6189 u32 sw_if_index __attribute__ ((unused));
6190 u32 spd_id __attribute__ ((unused));
6192 sw_if_index = ntohl (mp->sw_if_index);
6193 spd_id = ntohl (mp->spd_id);
6195 VALIDATE_SW_IF_INDEX (mp);
6198 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6200 rv = VNET_API_ERROR_UNIMPLEMENTED;
6203 BAD_SW_IF_INDEX_LABEL;
6205 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6208 static void vl_api_ipsec_spd_add_del_entry_t_handler
6209 (vl_api_ipsec_spd_add_del_entry_t * mp)
6211 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6212 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6218 memset (&p, 0, sizeof (p));
6220 p.id = ntohl (mp->spd_id);
6221 p.priority = ntohl (mp->priority);
6222 p.is_outbound = mp->is_outbound;
6223 p.is_ipv6 = mp->is_ipv6;
6225 if (mp->is_ipv6 || mp->is_ip_any)
6227 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6228 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6229 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6230 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6234 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6235 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6236 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6237 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6239 p.protocol = mp->protocol;
6240 p.rport.start = ntohs (mp->remote_port_start);
6241 p.rport.stop = ntohs (mp->remote_port_stop);
6242 p.lport.start = ntohs (mp->local_port_start);
6243 p.lport.stop = ntohs (mp->local_port_stop);
6244 /* policy action resolve unsupported */
6245 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6247 clib_warning ("unsupported action: 'resolve'");
6248 rv = VNET_API_ERROR_UNIMPLEMENTED;
6251 p.policy = mp->policy;
6252 p.sa_id = ntohl (mp->sa_id);
6254 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6261 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6264 rv = VNET_API_ERROR_UNIMPLEMENTED;
6269 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6272 static void vl_api_ipsec_sad_add_del_entry_t_handler
6273 (vl_api_ipsec_sad_add_del_entry_t * mp)
6275 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6276 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6281 memset (&sa, 0, sizeof (sa));
6283 sa.id = ntohl (mp->sad_id);
6284 sa.spi = ntohl (mp->spi);
6285 /* security protocol AH unsupported */
6286 if (mp->protocol == IPSEC_PROTOCOL_AH)
6288 clib_warning ("unsupported security protocol 'AH'");
6289 rv = VNET_API_ERROR_UNIMPLEMENTED;
6292 sa.protocol = mp->protocol;
6293 /* check for unsupported crypto-alg */
6294 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6295 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6297 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6298 mp->crypto_algorithm);
6299 rv = VNET_API_ERROR_UNIMPLEMENTED;
6302 sa.crypto_alg = mp->crypto_algorithm;
6303 sa.crypto_key_len = mp->crypto_key_length;
6304 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6305 /* check for unsupported integ-alg */
6306 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6307 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6309 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6310 mp->integrity_algorithm);
6311 rv = VNET_API_ERROR_UNIMPLEMENTED;
6314 sa.integ_alg = mp->integrity_algorithm;
6315 sa.integ_key_len = mp->integrity_key_length;
6316 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6317 sa.use_esn = mp->use_extended_sequence_number;
6318 sa.is_tunnel = mp->is_tunnel;
6319 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6320 if (sa.is_tunnel_ip6)
6322 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6323 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6327 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6328 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6331 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6333 rv = VNET_API_ERROR_UNIMPLEMENTED;
6338 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6342 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6344 vl_api_ikev2_profile_add_del_reply_t *rmp;
6348 vlib_main_t *vm = vlib_get_main ();
6349 clib_error_t *error;
6350 u8 *tmp = format (0, "%s", mp->name);
6351 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6354 rv = VNET_API_ERROR_UNSPECIFIED;
6356 rv = VNET_API_ERROR_UNIMPLEMENTED;
6359 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6363 vl_api_ikev2_profile_set_auth_t_handler
6364 (vl_api_ikev2_profile_set_auth_t * mp)
6366 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6370 vlib_main_t *vm = vlib_get_main ();
6371 clib_error_t *error;
6372 u8 *tmp = format (0, "%s", mp->name);
6373 u8 *data = vec_new (u8, mp->data_len);
6374 clib_memcpy (data, mp->data, mp->data_len);
6375 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6379 rv = VNET_API_ERROR_UNSPECIFIED;
6381 rv = VNET_API_ERROR_UNIMPLEMENTED;
6384 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6388 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6390 vl_api_ikev2_profile_add_del_reply_t *rmp;
6394 vlib_main_t *vm = vlib_get_main ();
6395 clib_error_t *error;
6396 u8 *tmp = format (0, "%s", mp->name);
6397 u8 *data = vec_new (u8, mp->data_len);
6398 clib_memcpy (data, mp->data, mp->data_len);
6399 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6403 rv = VNET_API_ERROR_UNSPECIFIED;
6405 rv = VNET_API_ERROR_UNIMPLEMENTED;
6408 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6412 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6414 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6418 vlib_main_t *vm = vlib_get_main ();
6419 clib_error_t *error;
6420 u8 *tmp = format (0, "%s", mp->name);
6421 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6422 mp->end_port, (ip4_address_t) mp->start_addr,
6423 (ip4_address_t) mp->end_addr, mp->is_local);
6426 rv = VNET_API_ERROR_UNSPECIFIED;
6428 rv = VNET_API_ERROR_UNIMPLEMENTED;
6431 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6435 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6437 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6441 vlib_main_t *vm = vlib_get_main ();
6442 clib_error_t *error;
6444 error = ikev2_set_local_key (vm, mp->key_file);
6446 rv = VNET_API_ERROR_UNSPECIFIED;
6448 rv = VNET_API_ERROR_UNIMPLEMENTED;
6451 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6455 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6457 vl_api_map_add_domain_reply_t *rmp;
6460 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6462 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6463 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6464 (ip6_address_t *) & mp->ip6_src,
6465 mp->ip6_src_prefix_len, mp->ea_bits_len,
6466 mp->psid_offset, mp->psid_length, &index,
6467 ntohs (mp->mtu), flags);
6470 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6472 rmp->index = ntohl(index);
6478 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6480 vl_api_map_del_domain_reply_t *rmp;
6483 rv = map_delete_domain (ntohl (mp->index));
6485 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6489 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6491 vl_api_map_del_domain_reply_t *rmp;
6495 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6496 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6498 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6502 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6504 vl_api_map_domain_details_t *rmp;
6505 map_main_t *mm = &map_main;
6507 unix_shared_memory_queue_t *q;
6509 if (pool_elts (mm->domains) == 0)
6512 q = vl_api_client_index_to_input_queue (mp->client_index);
6519 pool_foreach(d, mm->domains,
6521 /* Make sure every field is initiated (or don't skip the memset()) */
6522 rmp = vl_msg_api_alloc (sizeof (*rmp));
6523 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6524 rmp->domain_index = htonl(d - mm->domains);
6525 rmp->ea_bits_len = d->ea_bits_len;
6526 rmp->psid_offset = d->psid_offset;
6527 rmp->psid_length = d->psid_length;
6528 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6529 rmp->ip4_prefix_len = d->ip4_prefix_len;
6530 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6531 rmp->ip6_prefix_len = d->ip6_prefix_len;
6532 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6533 rmp->ip6_src_len = d->ip6_src_len;
6534 rmp->mtu = htons(d->mtu);
6535 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6536 rmp->context = mp->context;
6538 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6544 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6546 unix_shared_memory_queue_t *q;
6549 vl_api_map_rule_details_t *rmp;
6550 map_main_t *mm = &map_main;
6551 u32 domain_index = ntohl (mp->domain_index);
6554 if (pool_elts (mm->domains) == 0)
6557 d = pool_elt_at_index (mm->domains, domain_index);
6558 if (!d || !d->rules)
6563 q = vl_api_client_index_to_input_queue (mp->client_index);
6569 for (i = 0; i < (0x1 << d->psid_length); i++)
6572 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6576 rmp = vl_msg_api_alloc (sizeof (*rmp));
6577 memset (rmp, 0, sizeof (*rmp));
6578 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6579 rmp->psid = htons (i);
6580 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6581 rmp->context = mp->context;
6582 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6587 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6589 vl_api_map_summary_stats_reply_t *rmp;
6590 vlib_combined_counter_main_t *cm;
6593 u64 total_pkts[VLIB_N_RX_TX];
6594 u64 total_bytes[VLIB_N_RX_TX];
6595 map_main_t *mm = &map_main;
6596 unix_shared_memory_queue_t *q =
6597 vl_api_client_index_to_input_queue (mp->client_index);
6602 rmp = vl_msg_api_alloc (sizeof (*rmp));
6603 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6604 rmp->context = mp->context;
6607 memset (total_pkts, 0, sizeof (total_pkts));
6608 memset (total_bytes, 0, sizeof (total_bytes));
6610 map_domain_counter_lock (mm);
6611 vec_foreach (cm, mm->domain_counters)
6613 which = cm - mm->domain_counters;
6615 for (i = 0; i < vec_len (cm->maxi); i++)
6617 vlib_get_combined_counter (cm, i, &v);
6618 total_pkts[which] += v.packets;
6619 total_bytes[which] += v.bytes;
6623 map_domain_counter_unlock (mm);
6625 /* Note: in network byte order! */
6626 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6627 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6628 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6629 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6630 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6631 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6632 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6633 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6634 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6635 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6636 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6637 clib_host_to_net_u64 (map_error_counter_get
6638 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6639 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6640 clib_host_to_net_u64 (map_error_counter_get
6641 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6643 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6647 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6649 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6650 vl_api_ipsec_sa_set_key_reply_t *rmp;
6654 sa.id = ntohl (mp->sa_id);
6655 sa.crypto_key_len = mp->crypto_key_length;
6656 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6657 sa.integ_key_len = mp->integrity_key_length;
6658 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6660 rv = ipsec_set_sa_key (vm, &sa);
6662 rv = VNET_API_ERROR_UNIMPLEMENTED;
6665 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6668 static void vl_api_cop_interface_enable_disable_t_handler
6669 (vl_api_cop_interface_enable_disable_t * mp)
6671 vl_api_cop_interface_enable_disable_reply_t *rmp;
6673 u32 sw_if_index = ntohl (mp->sw_if_index);
6676 VALIDATE_SW_IF_INDEX (mp);
6678 enable_disable = (int) mp->enable_disable;
6680 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6682 BAD_SW_IF_INDEX_LABEL;
6684 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6687 static void vl_api_cop_whitelist_enable_disable_t_handler
6688 (vl_api_cop_whitelist_enable_disable_t * mp)
6690 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6691 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6692 u32 sw_if_index = ntohl (mp->sw_if_index);
6695 VALIDATE_SW_IF_INDEX (mp);
6697 a->sw_if_index = sw_if_index;
6700 a->default_cop = mp->default_cop;
6701 a->fib_id = ntohl (mp->fib_id);
6703 rv = cop_whitelist_enable_disable (a);
6705 BAD_SW_IF_INDEX_LABEL;
6707 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6711 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6715 api_main_t *am = &api_main;
6716 vlib_main_t *vm = vlib_get_main ();
6718 vl_api_get_node_graph_reply_t *rmp;
6720 pthread_mutex_lock (&am->vlib_rp->mutex);
6721 oldheap = svm_push_data_heap (am->vlib_rp);
6724 * Keep the number of memcpy ops to a minimum (e.g. 1).
6726 vec_validate (vector, 16384);
6727 vec_reset_length (vector);
6730 vector = vlib_node_serialize (&vm->node_main, vector,
6731 (u32) ~ 0 /* all threads */ ,
6732 1 /* include nexts */ ,
6733 1 /* include stats */ );
6735 svm_pop_heap (oldheap);
6736 pthread_mutex_unlock (&am->vlib_rp->mutex);
6739 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6741 rmp->reply_in_shmem = (uword) vector;
6746 static void vl_api_trace_profile_add_t_handler
6747 (vl_api_trace_profile_add_t * mp)
6750 vl_api_trace_profile_add_reply_t *rmp;
6751 clib_error_t *error;
6753 /* Ignoring the profile id as currently a single profile
6755 error = ip6_ioam_trace_profile_set (mp->trace_num_elt, mp->trace_type,
6756 ntohl (mp->node_id),
6757 ntohl (mp->trace_app_data),
6758 mp->pow_enable, mp->trace_tsp,
6762 clib_error_report (error);
6763 rv = clib_error_get_code (error);
6766 REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
6769 static void vl_api_trace_profile_apply_t_handler
6770 (vl_api_trace_profile_apply_t * mp)
6773 vl_api_trace_profile_apply_reply_t *rmp;
6775 if (mp->enable != 0)
6777 rv = ip6_ioam_set_destination ((ip6_address_t *) (&mp->dest_ipv6),
6778 ntohl (mp->prefix_length),
6780 mp->trace_op == IOAM_HBYH_ADD,
6781 mp->trace_op == IOAM_HBYH_POP,
6782 mp->trace_op == IOAM_HBYH_MOD);
6786 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6788 REPLY_MACRO (VL_API_TRACE_PROFILE_APPLY_REPLY);
6791 static void vl_api_trace_profile_del_t_handler
6792 (vl_api_trace_profile_del_t * mp)
6795 vl_api_trace_profile_del_reply_t *rmp;
6796 clib_error_t *error;
6798 error = clear_ioam_rewrite_fn ();
6801 clib_error_report (error);
6802 rv = clib_error_get_code (error);
6805 REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
6809 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
6811 vlib_main_t *vm = vlib_get_main ();
6812 vl_api_af_packet_create_reply_t *rmp;
6814 u8 *host_if_name = NULL;
6817 host_if_name = format (0, "%s", mp->host_if_name);
6818 vec_add1 (host_if_name, 0);
6820 rv = af_packet_create_if (vm, host_if_name,
6821 mp->use_random_hw_addr ? 0 : mp->hw_addr,
6824 vec_free (host_if_name);
6827 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6829 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
6835 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
6837 vlib_main_t *vm = vlib_get_main ();
6838 vl_api_af_packet_delete_reply_t *rmp;
6840 u8 *host_if_name = NULL;
6842 host_if_name = format (0, "%s", mp->host_if_name);
6843 vec_add1 (host_if_name, 0);
6845 rv = af_packet_delete_if (vm, host_if_name);
6847 vec_free (host_if_name);
6849 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
6853 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
6855 vlib_main_t *vm = vlib_get_main ();
6856 vl_api_policer_add_del_reply_t *rmp;
6859 sse2_qos_pol_cfg_params_st cfg;
6860 clib_error_t *error;
6863 name = format (0, "%s", mp->name);
6865 memset (&cfg, 0, sizeof (cfg));
6867 cfg.rnd_type = mp->round_type;
6868 cfg.rate_type = mp->rate_type;
6869 cfg.rb.kbps.cir_kbps = mp->cir;
6870 cfg.rb.kbps.eir_kbps = mp->eir;
6871 cfg.rb.kbps.cb_bytes = mp->cb;
6872 cfg.rb.kbps.eb_bytes = mp->eb;
6873 cfg.conform_action.action_type = mp->conform_action_type;
6874 cfg.conform_action.dscp = mp->conform_dscp;
6875 cfg.exceed_action.action_type = mp->exceed_action_type;
6876 cfg.exceed_action.dscp = mp->exceed_dscp;
6877 cfg.violate_action.action_type = mp->violate_action_type;
6878 cfg.violate_action.dscp = mp->violate_dscp;
6879 cfg.color_aware = mp->color_aware;
6881 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
6884 rv = VNET_API_ERROR_UNSPECIFIED;
6887 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6889 if (rv == 0 && mp->is_add)
6890 rmp->policer_index = ntohl(policer_index);
6892 rmp->policer_index = ~0;
6898 send_policer_details (u8 * name,
6899 sse2_qos_pol_cfg_params_st * config,
6900 policer_read_response_type_st * templ,
6901 unix_shared_memory_queue_t * q, u32 context)
6903 vl_api_policer_details_t *mp;
6905 mp = vl_msg_api_alloc (sizeof (*mp));
6906 memset (mp, 0, sizeof (*mp));
6907 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6908 mp->context = context;
6909 mp->cir = htonl (config->rb.kbps.cir_kbps);
6910 mp->eir = htonl (config->rb.kbps.eir_kbps);
6911 mp->cb = htonl (config->rb.kbps.cb_bytes);
6912 mp->eb = htonl (config->rb.kbps.eb_bytes);
6913 mp->rate_type = config->rate_type;
6914 mp->round_type = config->rnd_type;
6915 mp->type = config->rfc;
6916 mp->conform_action_type = config->conform_action.action_type;
6917 mp->conform_dscp = config->conform_action.dscp;
6918 mp->exceed_action_type = config->exceed_action.action_type;
6919 mp->exceed_dscp = config->exceed_action.dscp;
6920 mp->violate_action_type = config->violate_action.action_type;
6921 mp->violate_dscp = config->violate_action.dscp;
6922 mp->single_rate = templ->single_rate ? 1 : 0;
6923 mp->color_aware = templ->color_aware ? 1 : 0;
6924 mp->scale = htonl (templ->scale);
6925 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
6926 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
6927 mp->current_limit = htonl (templ->current_limit);
6928 mp->current_bucket = htonl (templ->current_bucket);
6929 mp->extended_limit = htonl (templ->extended_limit);
6930 mp->extended_bucket = htonl (templ->extended_bucket);
6931 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
6933 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
6935 vl_msg_api_send_shmem (q, (u8 *) & mp);
6939 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
6941 unix_shared_memory_queue_t *q;
6942 vnet_policer_main_t *pm = &vnet_policer_main;
6948 sse2_qos_pol_cfg_params_st *config;
6949 policer_read_response_type_st *templ;
6951 q = vl_api_client_index_to_input_queue (mp->client_index);
6955 if (mp->match_name_valid)
6957 match_name = format (0, "%s%c", mp->match_name, 0);
6960 if (mp->match_name_valid)
6962 p = hash_get_mem (pm->policer_config_by_name, match_name);
6966 config = pool_elt_at_index (pm->configs, pool_index);
6967 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6968 send_policer_details (match_name, config, templ, q, mp->context);
6974 hash_foreach_pair (hp, pm->policer_config_by_name,
6976 name = (u8 *) hp->key;
6977 pool_index = hp->value[0];
6978 config = pool_elt_at_index (pm->configs, pool_index);
6979 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6980 send_policer_details(name, config, templ, q, mp->context);
6987 vl_api_policer_classify_set_interface_t_handler
6988 (vl_api_policer_classify_set_interface_t * mp)
6990 vlib_main_t *vm = vlib_get_main ();
6991 vl_api_policer_classify_set_interface_reply_t *rmp;
6993 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6995 ip4_table_index = ntohl (mp->ip4_table_index);
6996 ip6_table_index = ntohl (mp->ip6_table_index);
6997 l2_table_index = ntohl (mp->l2_table_index);
6998 sw_if_index = ntohl (mp->sw_if_index);
7000 VALIDATE_SW_IF_INDEX (mp);
7002 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7003 ip6_table_index, l2_table_index,
7006 BAD_SW_IF_INDEX_LABEL;
7008 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7012 send_policer_classify_details (u32 sw_if_index,
7014 unix_shared_memory_queue_t * q, u32 context)
7016 vl_api_policer_classify_details_t *mp;
7018 mp = vl_msg_api_alloc (sizeof (*mp));
7019 memset (mp, 0, sizeof (*mp));
7020 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7021 mp->context = context;
7022 mp->sw_if_index = htonl (sw_if_index);
7023 mp->table_index = htonl (table_index);
7025 vl_msg_api_send_shmem (q, (u8 *) & mp);
7029 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7031 unix_shared_memory_queue_t *q;
7032 policer_classify_main_t *pcm = &policer_classify_main;
7036 q = vl_api_client_index_to_input_queue (mp->client_index);
7040 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7042 if (vec_len (vec_tbl))
7044 for (i = 0; i < vec_len (vec_tbl); i++)
7046 if (vec_elt (vec_tbl, i) == ~0)
7049 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7056 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7058 vlib_main_t *vm = vlib_get_main ();
7059 vl_api_netmap_create_reply_t *rmp;
7063 if_name = format (0, "%s", mp->netmap_if_name);
7064 vec_add1 (if_name, 0);
7067 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7068 mp->is_pipe, mp->is_master, 0);
7072 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7076 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7078 vlib_main_t *vm = vlib_get_main ();
7079 vl_api_netmap_delete_reply_t *rmp;
7083 if_name = format (0, "%s", mp->netmap_if_name);
7084 vec_add1 (if_name, 0);
7086 rv = netmap_delete_if (vm, if_name);
7090 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7094 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7097 clib_warning ("BUG");
7101 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7102 unix_shared_memory_queue_t * q,
7103 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7105 vl_api_mpls_gre_tunnel_details_t *mp;
7106 mpls_main_t *mm = &mpls_main;
7111 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7112 nlabels = vec_len (e->labels);
7114 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7115 memset (mp, 0, sizeof (*mp));
7116 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7117 mp->context = context;
7119 mp->tunnel_index = htonl (index);
7120 mp->tunnel_src = gt->tunnel_src.as_u32;
7121 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7122 mp->intfc_address = gt->intfc_address.as_u32;
7123 mp->mask_width = htonl (gt->mask_width);
7124 mp->inner_fib_index = htonl (gt->inner_fib_index);
7125 mp->outer_fib_index = htonl (gt->outer_fib_index);
7126 mp->encap_index = htonl (gt->encap_index);
7127 mp->hw_if_index = htonl (gt->hw_if_index);
7128 mp->l2_only = htonl (gt->l2_only);
7129 mp->nlabels = htonl (nlabels);
7131 for (i = 0; i < nlabels; i++)
7134 htonl (vnet_mpls_uc_get_label
7135 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7138 vl_msg_api_send_shmem (q, (u8 *) & mp);
7142 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7144 vpe_api_main_t *am = &vpe_api_main;
7145 unix_shared_memory_queue_t *q;
7146 mpls_main_t *mm = &mpls_main;
7147 mpls_gre_tunnel_t *gt;
7148 u32 index = ntohl (mp->tunnel_index);
7150 q = vl_api_client_index_to_input_queue (mp->client_index);
7156 if (!pool_is_free_index (mm->gre_tunnels, index))
7158 gt = pool_elt_at_index (mm->gre_tunnels, index);
7159 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7166 pool_foreach (gt, mm->gre_tunnels,
7168 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7176 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7179 clib_warning ("BUG");
7183 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7184 unix_shared_memory_queue_t * q,
7185 mpls_eth_tunnel_t * et, u32 index, u32 context)
7187 mpls_main_t *mm = &mpls_main;
7191 vl_api_mpls_eth_tunnel_details_t *mp;
7193 e = pool_elt_at_index (mm->encaps, et->encap_index);
7194 nlabels = vec_len (e->labels);
7196 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7197 memset (mp, 0, sizeof (*mp));
7198 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7199 mp->context = context;
7201 mp->tunnel_index = htonl (index);
7202 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7203 mp->intfc_address = et->intfc_address.as_u32;
7204 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7205 mp->inner_fib_index = htonl (et->inner_fib_index);
7206 mp->mask_width = htonl (et->mask_width);
7207 mp->encap_index = htonl (et->encap_index);
7208 mp->hw_if_index = htonl (et->hw_if_index);
7209 mp->l2_only = htonl (et->l2_only);
7210 mp->nlabels = htonl (nlabels);
7212 for (i = 0; i < nlabels; i++)
7215 htonl (vnet_mpls_uc_get_label
7216 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7219 vl_msg_api_send_shmem (q, (u8 *) & mp);
7223 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7225 vpe_api_main_t *am = &vpe_api_main;
7226 unix_shared_memory_queue_t *q;
7227 mpls_main_t *mm = &mpls_main;
7228 mpls_eth_tunnel_t *et;
7229 u32 index = ntohl (mp->tunnel_index);
7231 q = vl_api_client_index_to_input_queue (mp->client_index);
7237 if (!pool_is_free_index (mm->eth_tunnels, index))
7239 et = pool_elt_at_index (mm->eth_tunnels, index);
7240 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7247 pool_foreach (et, mm->eth_tunnels,
7249 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7257 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7259 clib_warning ("BUG");
7263 send_mpls_fib_encap_details (vpe_api_main_t * am,
7264 unix_shared_memory_queue_t * q,
7265 show_mpls_fib_t * s, u32 context)
7267 vl_api_mpls_fib_encap_details_t *mp;
7268 mpls_main_t *mm = &mpls_main;
7273 e = pool_elt_at_index (mm->encaps, s->entry_index);
7274 nlabels = vec_len (e->labels);
7276 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7277 memset (mp, 0, sizeof (*mp));
7278 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7279 mp->context = context;
7281 mp->fib_index = htonl (s->fib_index);
7282 mp->entry_index = htonl (s->entry_index);
7284 mp->s_bit = htonl (s->s_bit);
7286 mp->nlabels = htonl (nlabels);
7288 for (i = 0; i < nlabels; i++)
7291 htonl (vnet_mpls_uc_get_label
7292 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7295 vl_msg_api_send_shmem (q, (u8 *) & mp);
7299 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7301 vpe_api_main_t *am = &vpe_api_main;
7302 unix_shared_memory_queue_t *q;
7303 vlib_main_t *vm = &vlib_global_main;
7306 show_mpls_fib_t *records = 0;
7308 mpls_main_t *mm = &mpls_main;
7309 ip4_main_t *im = &ip4_main;
7312 q = vl_api_client_index_to_input_queue (mp->client_index);
7317 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7319 vec_add2 (records, s, 1);
7320 s->fib_index = (u32)(key>>32);
7321 s->dest = (u32)(key & 0xFFFFFFFF);
7322 s->entry_index = (u32) value;
7326 if (0 == vec_len (records))
7328 vlib_cli_output (vm, "MPLS encap table empty");
7332 /* sort output by dst address within fib */
7333 vec_sort_with_function (records, mpls_dest_cmp);
7334 vec_sort_with_function (records, mpls_fib_index_cmp);
7335 vlib_cli_output (vm, "MPLS encap table");
7336 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7337 vec_foreach (s, records)
7339 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7340 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7341 format_ip4_address, &s->dest, format_mpls_encap_index,
7342 mm, s->entry_index);
7343 send_mpls_fib_encap_details (am, q, s, mp->context);
7351 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7353 clib_warning ("BUG");
7357 send_mpls_fib_decap_details (vpe_api_main_t * am,
7358 unix_shared_memory_queue_t * q,
7359 show_mpls_fib_t * s,
7361 u32 tx_table_id, char *swif_tag, u32 context)
7363 vl_api_mpls_fib_decap_details_t *mp;
7365 mp = vl_msg_api_alloc (sizeof (*mp));
7366 memset (mp, 0, sizeof (*mp));
7367 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7368 mp->context = context;
7370 mp->fib_index = htonl (s->fib_index);
7371 mp->entry_index = htonl (s->entry_index);
7373 mp->s_bit = htonl (s->s_bit);
7374 mp->label = htonl (s->label);
7375 mp->rx_table_id = htonl (rx_table_id);
7376 mp->tx_table_id = htonl (tx_table_id);
7377 strncpy ((char *) mp->swif_tag,
7378 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7380 vl_msg_api_send_shmem (q, (u8 *) & mp);
7384 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7386 vpe_api_main_t *am = &vpe_api_main;
7387 unix_shared_memory_queue_t *q;
7388 vlib_main_t *vm = &vlib_global_main;
7391 show_mpls_fib_t *records = 0;
7393 mpls_main_t *mm = &mpls_main;
7394 ip4_main_t *im = &ip4_main;
7400 q = vl_api_client_index_to_input_queue (mp->client_index);
7405 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7407 vec_add2 (records, s, 1);
7408 s->fib_index = (u32)(key>>32);
7409 s->entry_index = (u32) value;
7410 s->label = ((u32) key)>>12;
7411 s->s_bit = (key & (1<<8)) != 0;
7415 if (!vec_len (records))
7417 vlib_cli_output (vm, "MPLS decap table empty");
7421 vec_sort_with_function (records, mpls_label_cmp);
7422 vlib_cli_output (vm, "MPLS decap table");
7423 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7425 vec_foreach (s, records)
7428 d = pool_elt_at_index (mm->decaps, s->entry_index);
7429 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT)
7431 tx_fib = vec_elt_at_index (im->fibs, d->tx_fib_index);
7432 tx_table_id = tx_fib->table_id;
7437 tx_table_id = d->tx_fib_index;
7440 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7442 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7443 tx_table_id, swif_tag, s->label, s->s_bit);
7445 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7446 tx_table_id, swif_tag, mp->context);
7454 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7456 unix_shared_memory_queue_t *q;
7458 q = vl_api_client_index_to_input_queue (mp->client_index);
7462 vnet_classify_main_t *cm = &vnet_classify_main;
7463 vnet_classify_table_t *t;
7468 pool_foreach (t, cm->tables,
7470 vec_add1 (table_ids, ntohl(t - cm->tables));
7473 count = vec_len (table_ids);
7475 vl_api_classify_table_ids_reply_t *rmp;
7476 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7477 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7478 rmp->context = mp->context;
7479 rmp->count = ntohl (count);
7480 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7483 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7485 vec_free (table_ids);
7489 vl_api_classify_table_by_interface_t_handler
7490 (vl_api_classify_table_by_interface_t * mp)
7492 vl_api_classify_table_by_interface_reply_t *rmp;
7495 u32 sw_if_index = ntohl (mp->sw_if_index);
7498 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7501 VALIDATE_SW_IF_INDEX (mp);
7503 input_acl_main_t *am = &input_acl_main;
7508 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7510 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7511 if (vec_len (vec_tbl))
7513 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7515 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7519 acl[type] = vec_elt (vec_tbl, if_idx);
7524 BAD_SW_IF_INDEX_LABEL;
7527 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7529 rmp->sw_if_index = ntohl(sw_if_index);
7530 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7531 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7532 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7539 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7541 unix_shared_memory_queue_t *q;
7543 q = vl_api_client_index_to_input_queue (mp->client_index);
7547 vl_api_classify_table_info_reply_t *rmp = 0;
7549 vnet_classify_main_t *cm = &vnet_classify_main;
7550 u32 table_id = ntohl (mp->table_id);
7551 vnet_classify_table_t *t;
7554 pool_foreach (t, cm->tables,
7556 if (table_id == t - cm->tables)
7558 rmp = vl_msg_api_alloc_as_if_client
7559 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7560 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7561 rmp->context = mp->context;
7562 rmp->table_id = ntohl(table_id);
7563 rmp->nbuckets = ntohl(t->nbuckets);
7564 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7565 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7566 rmp->active_sessions = ntohl(t->active_elements);
7567 rmp->next_table_index = ntohl(t->next_table_index);
7568 rmp->miss_next_index = ntohl(t->miss_next_index);
7569 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7570 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7579 rmp = vl_msg_api_alloc (sizeof (*rmp));
7580 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7581 rmp->context = mp->context;
7582 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7585 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7589 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7592 clib_warning ("BUG");
7596 send_classify_session_details (unix_shared_memory_queue_t * q,
7599 vnet_classify_entry_t * e, u32 context)
7601 vl_api_classify_session_details_t *rmp;
7603 rmp = vl_msg_api_alloc (sizeof (*rmp));
7604 memset (rmp, 0, sizeof (*rmp));
7605 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7606 rmp->context = context;
7607 rmp->table_id = ntohl (table_id);
7608 rmp->hit_next_index = ntohl (e->next_index);
7609 rmp->advance = ntohl (e->advance);
7610 rmp->opaque_index = ntohl (e->opaque_index);
7611 rmp->match_length = ntohl (match_length);
7612 clib_memcpy (rmp->match, e->key, match_length);
7614 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7618 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7620 vnet_classify_main_t *cm = &vnet_classify_main;
7621 unix_shared_memory_queue_t *q;
7623 u32 table_id = ntohl (mp->table_id);
7624 vnet_classify_table_t *t;
7626 q = vl_api_client_index_to_input_queue (mp->client_index);
7629 pool_foreach (t, cm->tables,
7631 if (table_id == t - cm->tables)
7633 vnet_classify_bucket_t * b;
7634 vnet_classify_entry_t * v, * save_v;
7637 for (i = 0; i < t->nbuckets; i++)
7639 b = &t->buckets [i];
7643 save_v = vnet_classify_get_entry (t, b->offset);
7644 for (j = 0; j < (1<<b->log2_pages); j++)
7646 for (k = 0; k < t->entries_per_page; k++)
7648 v = vnet_classify_entry_at_index
7649 (t, save_v, j*t->entries_per_page + k);
7650 if (vnet_classify_entry_is_free (v))
7653 send_classify_session_details
7654 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7666 vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t * mp)
7668 vlib_main_t *vm = vlib_get_main ();
7669 flow_report_main_t *frm = &flow_report_main;
7670 vl_api_ipfix_enable_reply_t *rmp;
7671 ip4_address_t collector, src;
7672 u16 collector_port = UDP_DST_PORT_ipfix;
7674 u32 template_interval;
7679 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7680 collector_port = ntohs (mp->collector_port);
7681 if (collector_port == (u16) ~ 0)
7682 collector_port = UDP_DST_PORT_ipfix;
7683 memcpy (src.data, mp->src_address, sizeof (src.data));
7684 fib_id = ntohl (mp->vrf_id);
7686 ip4_main_t *im = &ip4_main;
7687 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7690 rv = VNET_API_ERROR_NO_SUCH_FIB;
7695 path_mtu = ntohl (mp->path_mtu);
7697 path_mtu = 512; // RFC 7011 section 10.3.3.
7698 template_interval = ntohl (mp->template_interval);
7699 if (template_interval == ~0)
7700 template_interval = 20;
7702 if (collector.as_u32 == 0)
7704 rv = VNET_API_ERROR_INVALID_VALUE;
7708 if (src.as_u32 == 0)
7710 rv = VNET_API_ERROR_INVALID_VALUE;
7714 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7716 rv = VNET_API_ERROR_INVALID_VALUE;
7722 rv = VNET_API_ERROR_INVALID_VALUE;
7726 /* Reset report streams if we are reconfiguring IP addresses */
7727 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7728 frm->src_address.as_u32 != src.as_u32 ||
7729 frm->collector_port != collector_port)
7730 vnet_flow_reports_reset (frm);
7732 frm->ipfix_collector.as_u32 = collector.as_u32;
7733 frm->collector_port = collector_port;
7734 frm->src_address.as_u32 = src.as_u32;
7735 frm->fib_index = fib_index;
7736 frm->path_mtu = path_mtu;
7737 frm->template_interval = template_interval;
7739 /* Turn on the flow reporting process */
7740 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7743 REPLY_MACRO (VL_API_IPFIX_ENABLE_REPLY);
7747 vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t * mp)
7749 flow_report_main_t *frm = &flow_report_main;
7750 unix_shared_memory_queue_t *q;
7751 vl_api_ipfix_details_t *rmp;
7753 q = vl_api_client_index_to_input_queue (mp->client_index);
7757 rmp = vl_msg_api_alloc (sizeof (*rmp));
7758 memset (rmp, 0, sizeof (*rmp));
7759 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_DETAILS);
7760 rmp->context = mp->context;
7761 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7762 sizeof (frm->ipfix_collector.data));
7763 rmp->collector_port = htons (frm->collector_port);
7764 memcpy (rmp->src_address, frm->src_address.data,
7765 sizeof (frm->src_address.data));
7766 rmp->fib_index = htonl (frm->fib_index);
7767 rmp->path_mtu = htonl (frm->path_mtu);
7768 rmp->template_interval = htonl (frm->template_interval);
7770 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7774 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
7776 vl_api_pg_create_interface_reply_t *rmp;
7779 pg_main_t *pg = &pg_main;
7780 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
7783 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7785 rmp->sw_if_index = ntohl(sw_if_index);
7791 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
7793 vl_api_pg_capture_reply_t *rmp;
7796 vnet_main_t *vnm = vnet_get_main ();
7797 vnet_interface_main_t *im = &vnm->interface_main;
7798 vnet_hw_interface_t *hi = 0;
7800 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
7801 u32 hw_if_index = ~0;
7802 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
7805 vec_free (intf_name);
7807 if (hw_if_index != ~0)
7809 pg_capture_args_t _a, *a = &_a;
7811 u32 len = ntohl (mp->pcap_name_length);
7812 u8 *pcap_file_name = vec_new (u8, len);
7813 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
7815 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7816 a->hw_if_index = hw_if_index;
7817 a->dev_instance = hi->dev_instance;
7818 a->is_enabled = mp->is_enabled;
7819 a->pcap_file_name = pcap_file_name;
7820 a->count = ntohl (mp->count);
7822 clib_error_t *e = pg_capture (a);
7825 clib_error_report (e);
7826 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7829 vec_free (pcap_file_name);
7831 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
7835 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
7837 vl_api_pg_enable_disable_reply_t *rmp;
7840 pg_main_t *pg = &pg_main;
7841 u32 stream_index = ~0;
7843 int is_enable = mp->is_enabled != 0;
7844 u32 len = ntohl (mp->stream_name_length) - 1;
7848 u8 *stream_name = vec_new (u8, len);
7849 clib_memcpy (stream_name, mp->stream_name, len);
7850 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
7853 vec_free (stream_name);
7856 pg_enable_disable (stream_index, is_enable);
7858 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
7862 vl_api_ip_source_and_port_range_check_add_del_t_handler
7863 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
7865 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
7868 u8 is_ipv6 = mp->is_ipv6;
7869 u8 is_add = mp->is_add;
7870 u8 mask_length = mp->mask_length;
7871 ip4_address_t ip4_addr;
7872 ip6_address_t ip6_addr;
7874 u16 *high_ports = 0;
7876 u16 tmp_low, tmp_high;
7880 // Validate port range
7881 num_ranges = mp->number_of_ranges;
7882 if (num_ranges > 32)
7883 { // This is size of array in VPE.API
7884 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
7888 vec_reset_length (low_ports);
7889 vec_reset_length (high_ports);
7891 for (i = 0; i < num_ranges; i++)
7893 tmp_low = mp->low_ports[i];
7894 tmp_high = mp->high_ports[i];
7895 // If tmp_low <= tmp_high then only need to check tmp_low = 0
7896 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
7897 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
7899 rv = VNET_API_ERROR_INVALID_VALUE;
7902 vec_add1 (low_ports, tmp_low);
7903 vec_add1 (high_ports, tmp_high + 1);
7906 // Validate mask_length
7907 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
7909 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
7913 vrf_id = ntohl (mp->vrf_id);
7917 rv = VNET_API_ERROR_INVALID_VALUE;
7924 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
7925 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
7929 high_ports, is_add);
7933 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
7934 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
7938 high_ports, is_add);
7942 vec_free (low_ports);
7943 vec_free (high_ports);
7944 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
7948 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
7949 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
7951 vlib_main_t *vm = vlib_get_main ();
7952 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
7953 ip4_main_t *im = &ip4_main;
7956 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7957 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
7961 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
7962 ntohl (mp->tcp_out_vrf_id);
7963 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
7964 ntohl (mp->udp_out_vrf_id);
7965 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
7966 ntohl (mp->tcp_in_vrf_id);
7967 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
7968 ntohl (mp->udp_in_vrf_id);
7971 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
7973 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
7975 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
7979 rv = VNET_API_ERROR_INVALID_VALUE;
7983 fib_index[i] = p[0];
7988 sw_if_index = ntohl (mp->sw_if_index);
7990 VALIDATE_SW_IF_INDEX (mp);
7993 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
7996 BAD_SW_IF_INDEX_LABEL;
7999 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8003 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8006 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8008 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8009 u32 sw_if_index = ~0;
8011 /* Check src & dst are different */
8012 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8014 rv = VNET_API_ERROR_SAME_SRC_DST;
8018 memset (a, 0, sizeof (*a));
8020 /* ip addresses sent in network byte order */
8021 clib_memcpy (&(a->src), mp->src_address, 4);
8022 clib_memcpy (&(a->dst), mp->dst_address, 4);
8023 a->is_add = mp->is_add;
8024 a->lsa = ntohl (mp->local_sa_id);
8025 a->rsa = ntohl (mp->remote_sa_id);
8027 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8031 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8033 rmp->sw_if_index = ntohl (sw_if_index);
8038 static void send_ipsec_gre_tunnel_details
8039 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8041 vl_api_ipsec_gre_tunnel_details_t *rmp;
8043 rmp = vl_msg_api_alloc (sizeof (*rmp));
8044 memset (rmp, 0, sizeof (*rmp));
8045 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8046 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8047 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8048 rmp->sw_if_index = htonl (t->sw_if_index);
8049 rmp->local_sa_id = htonl (t->local_sa_id);
8050 rmp->remote_sa_id = htonl (t->remote_sa_id);
8051 rmp->context = context;
8053 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8056 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8057 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8059 unix_shared_memory_queue_t *q;
8060 ipsec_gre_main_t *igm = &ipsec_gre_main;
8061 ipsec_gre_tunnel_t *t;
8064 q = vl_api_client_index_to_input_queue (mp->client_index);
8070 sw_if_index = ntohl (mp->sw_if_index);
8072 if (~0 == sw_if_index)
8075 pool_foreach (t, igm->tunnels,
8077 send_ipsec_gre_tunnel_details(t, q, mp->context);
8083 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8084 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8088 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8089 send_ipsec_gre_tunnel_details (t, q, mp->context);
8093 #define BOUNCE_HANDLER(nn) \
8094 static void vl_api_##nn##_t_handler ( \
8095 vl_api_##nn##_t *mp) \
8097 vpe_client_registration_t *reg; \
8098 vpe_api_main_t * vam = &vpe_api_main; \
8099 unix_shared_memory_queue_t * q; \
8101 /* One registration only... */ \
8102 pool_foreach(reg, vam->nn##_registrations, \
8104 q = vl_api_client_index_to_input_queue (reg->client_index); \
8107 * If the queue is stuffed, turf the msg and complain \
8108 * It's unlikely that the intended recipient is \
8109 * alive; avoid deadlock at all costs. \
8111 if (q->cursize == q->maxsize) { \
8112 clib_warning ("ERROR: receiver queue full, drop msg"); \
8113 vl_msg_api_free (mp); \
8116 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8120 vl_msg_api_free (mp); \
8125 * Add vpe's API message handlers to the table.
8126 * vlib has alread mapped shared memory and
8127 * added the client registration handlers.
8128 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8131 static clib_error_t *
8132 vpe_api_hookup (vlib_main_t * vm)
8134 api_main_t *am = &api_main;
8137 vl_msg_api_set_handlers(VL_API_##N, #n, \
8138 vl_api_##n##_t_handler, \
8140 vl_api_##n##_t_endian, \
8141 vl_api_##n##_t_print, \
8142 sizeof(vl_api_##n##_t), 1);
8143 foreach_vpe_api_msg;
8147 * Manually register the sr tunnel add del msg, so we trace
8148 * enough bytes to capture a typical segment list
8150 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8151 "sr_tunnel_add_del",
8152 vl_api_sr_tunnel_add_del_t_handler,
8154 vl_api_sr_tunnel_add_del_t_endian,
8155 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8159 * Manually register the sr policy add del msg, so we trace
8160 * enough bytes to capture a typical tunnel name list
8162 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8163 "sr_policy_add_del",
8164 vl_api_sr_policy_add_del_t_handler,
8166 vl_api_sr_policy_add_del_t_endian,
8167 vl_api_sr_policy_add_del_t_print, 256, 1);
8170 * Trace space for 8 MPLS encap labels, classifier mask+match
8172 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8173 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8174 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8175 += 5 * sizeof (u32x4);
8176 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8179 * Thread-safe API messages
8181 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8182 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8187 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8189 static clib_error_t *
8190 vpe_api_init (vlib_main_t * vm)
8192 vpe_api_main_t *am = &vpe_api_main;
8195 am->vnet_main = vnet_get_main ();
8196 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8197 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8198 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8199 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8200 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8201 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8204 vl_set_memory_region_name ("/vpe-api");
8205 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8210 VLIB_INIT_FUNCTION (vpe_api_init);
8213 static clib_error_t *
8214 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8217 u64 baseva, size, pvt_heap_size;
8219 const int max_buf_size = 4096;
8221 struct passwd _pw, *pw;
8222 struct group _grp, *grp;
8224 buf = vec_new (char, 128);
8225 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8227 if (unformat (input, "prefix %s", &chroot_path))
8229 vec_add1 (chroot_path, 0);
8230 vl_set_memory_root_path ((char *) chroot_path);
8232 else if (unformat (input, "uid %d", &uid))
8233 vl_set_memory_uid (uid);
8234 else if (unformat (input, "gid %d", &gid))
8235 vl_set_memory_gid (gid);
8236 else if (unformat (input, "baseva %llx", &baseva))
8237 vl_set_global_memory_baseva (baseva);
8238 else if (unformat (input, "global-size %lldM", &size))
8239 vl_set_global_memory_size (size * (1ULL << 20));
8240 else if (unformat (input, "global-size %lldG", &size))
8241 vl_set_global_memory_size (size * (1ULL << 30));
8242 else if (unformat (input, "global-size %lld", &size))
8243 vl_set_global_memory_size (size);
8244 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8245 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8246 else if (unformat (input, "global-pvt-heap-size size %lld",
8248 vl_set_global_pvt_heap_size (pvt_heap_size);
8249 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8250 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8251 else if (unformat (input, "api-pvt-heap-size size %lld",
8253 vl_set_api_pvt_heap_size (pvt_heap_size);
8254 else if (unformat (input, "api-size %lldM", &size))
8255 vl_set_api_memory_size (size * (1ULL << 20));
8256 else if (unformat (input, "api-size %lldG", &size))
8257 vl_set_api_memory_size (size * (1ULL << 30));
8258 else if (unformat (input, "api-size %lld", &size))
8259 vl_set_api_memory_size (size);
8260 else if (unformat (input, "uid %s", &s))
8262 /* lookup the username */
8265 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8266 && (vec_len (buf) <= max_buf_size))
8268 vec_resize (buf, vec_len (buf) * 2);
8272 e = clib_error_return_code (0, rv,
8273 CLIB_ERROR_ERRNO_VALID |
8275 "cannot fetch username %s", s);
8283 clib_error_return_fatal (0, "username %s does not exist", s);
8289 vl_set_memory_uid (pw->pw_uid);
8291 else if (unformat (input, "gid %s", &s))
8293 /* lookup the group name */
8296 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8297 && (vec_len (buf) <= max_buf_size))
8299 vec_resize (buf, vec_len (buf) * 2);
8303 e = clib_error_return_code (0, rv,
8304 CLIB_ERROR_ERRNO_VALID |
8306 "cannot fetch group %s", s);
8313 e = clib_error_return_fatal (0, "group %s does not exist", s);
8320 vl_set_memory_gid (grp->gr_gid);
8323 return clib_error_return (0, "unknown input `%U'",
8324 format_unformat_error, input);
8329 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8332 get_unformat_vnet_sw_interface (void)
8334 return (void *) &unformat_vnet_sw_interface;
8337 #undef vl_api_version
8338 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8339 #include <vpp-api/vpe.api.h>
8340 #undef vl_api_version
8343 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8345 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8347 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8348 clib_host_to_net_u32 (mp->api_versions[0]),
8356 format_arp_event (u8 * s, va_list * args)
8358 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8360 s = format (s, "pid %d: %U", event->pid,
8361 format_ip4_address, &event->address);
8365 static clib_error_t *
8366 show_ip4_arp_events_fn (vlib_main_t * vm,
8367 unformat_input_t * input, vlib_cli_command_t * cmd)
8369 vpe_api_main_t *am = &vpe_api_main;
8370 vl_api_ip4_arp_event_t *event;
8372 if (pool_elts (am->arp_events) == 0)
8374 vlib_cli_output (vm, "No active arp event registrations");
8379 pool_foreach (event, am->arp_events,
8381 vlib_cli_output (vm, "%U", format_arp_event, event);
8389 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
8390 .path = "show arp event registrations",
8391 .function = show_ip4_arp_events_fn,
8392 .short_help = "Show arp event registrations",
8397 * fd.io coding-style-patch-verification: ON
8400 * eval: (c-set-style "gnu")