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/ip/ip6.h>
55 #include <vnet/unix/tuntap.h>
56 #include <vnet/unix/tapcli.h>
57 #include <vnet/mpls-gre/mpls.h>
58 #include <vnet/dhcp/proxy.h>
59 #include <vnet/dhcp/client.h>
61 #include <vnet/sr/sr.h>
63 #include <vnet/dhcpv6/proxy.h>
64 #include <vlib/vlib.h>
65 #include <vlib/unix/unix.h>
66 #include <vlibapi/api.h>
67 #include <vlibmemory/api.h>
68 #include <vnet/classify/vnet_classify.h>
69 #include <vnet/classify/input_acl.h>
70 #include <vnet/classify/policer_classify.h>
71 #include <vnet/l2/l2_classify.h>
72 #include <vnet/vxlan/vxlan.h>
73 #include <vnet/gre/gre.h>
74 #include <vnet/l2/l2_vtr.h>
75 #include <vnet/vxlan-gpe/vxlan_gpe.h>
76 #include <vnet/lisp-gpe/lisp_gpe.h>
77 #include <vnet/lisp-cp/control.h>
78 #include <vnet/map/map.h>
79 #include <vnet/cop/cop.h>
80 #include <vnet/ip/ip6_hop_by_hop.h>
81 #include <vnet/ip/ip_source_and_port_range_check.h>
82 #include <vnet/devices/af_packet/af_packet.h>
83 #include <vnet/policer/policer.h>
84 #include <vnet/devices/netmap/netmap.h>
85 #include <vnet/flow/flow_report.h>
86 #include <vnet/ipsec-gre/ipsec_gre.h>
89 #undef __included_bihash_template_h__
90 #include <vnet/l2/l2_fib.h>
93 #include <vnet/ipsec/ipsec.h>
94 #include <vnet/ipsec/ikev2.h>
96 #include <vnet/devices/virtio/vhost-user.h>
98 #include <stats/stats.h>
101 #include <vnet/ethernet/ethernet.h>
102 #include <vnet/ethernet/arp_packet.h>
103 #include <vnet/interface.h>
105 #include <vnet/l2/l2_fib.h>
106 #include <vnet/l2/l2_bd.h>
107 #include <vpp-api/vpe_msg_enum.h>
109 #define f64_endian(a)
110 #define f64_print(a,b)
112 #define vl_typedefs /* define message structures */
113 #include <vpp-api/vpe_all_api_h.h>
116 #define vl_endianfun /* define message structures */
117 #include <vpp-api/vpe_all_api_h.h>
120 /* instantiate all the print functions we know about */
121 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
123 #include <vpp-api/vpe_all_api_h.h>
126 #define REPLY_MACRO(t) \
128 unix_shared_memory_queue_t * q; \
129 rv = vl_msg_api_pd_handler (mp, rv); \
130 q = vl_api_client_index_to_input_queue (mp->client_index); \
134 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
135 rmp->_vl_msg_id = ntohs((t)); \
136 rmp->context = mp->context; \
137 rmp->retval = ntohl(rv); \
139 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
142 #define REPLY_MACRO2(t, body) \
144 unix_shared_memory_queue_t * q; \
145 rv = vl_msg_api_pd_handler (mp, rv); \
146 q = vl_api_client_index_to_input_queue (mp->client_index); \
150 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
151 rmp->_vl_msg_id = ntohs((t)); \
152 rmp->context = mp->context; \
153 rmp->retval = ntohl(rv); \
154 do {body;} while (0); \
155 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
158 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
160 #define VALIDATE_SW_IF_INDEX(mp) \
161 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
162 vnet_main_t *__vnm = vnet_get_main(); \
163 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
165 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
166 goto bad_sw_if_index; \
170 #define BAD_SW_IF_INDEX_LABEL \
176 #define VALIDATE_RX_SW_IF_INDEX(mp) \
177 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
178 vnet_main_t *__vnm = vnet_get_main(); \
179 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
180 __rx_sw_if_index)) { \
181 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
182 goto bad_rx_sw_if_index; \
186 #define BAD_RX_SW_IF_INDEX_LABEL \
188 bad_rx_sw_if_index: \
192 #define VALIDATE_TX_SW_IF_INDEX(mp) \
193 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
194 vnet_main_t *__vnm = vnet_get_main(); \
195 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
196 __tx_sw_if_index)) { \
197 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
198 goto bad_tx_sw_if_index; \
202 #define BAD_TX_SW_IF_INDEX_LABEL \
204 bad_tx_sw_if_index: \
210 #define VALIDATE_SW_IF_INDEX(mp)
211 #define BAD_SW_IF_INDEX_LABEL
212 #define VALIDATE_RX_SW_IF_INDEX(mp)
213 #define BAD_RX_SW_IF_INDEX_LABEL
214 #define VALIDATE_TX_SW_IF_INDEX(mp)
215 #define BAD_TX_SW_IF_INDEX_LABEL
217 #endif /* CLIB_DEBUG > 0 */
219 #define foreach_vpe_api_msg \
220 _(WANT_INTERFACE_EVENTS, want_interface_events) \
221 _(WANT_OAM_EVENTS, want_oam_events) \
222 _(OAM_ADD_DEL, oam_add_del) \
223 _(SW_INTERFACE_DUMP, sw_interface_dump) \
224 _(SW_INTERFACE_DETAILS, sw_interface_details) \
225 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
226 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
227 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
228 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
229 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
230 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
231 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
232 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
233 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
234 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
235 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
236 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
237 _(L2FIB_ADD_DEL, l2fib_add_del) \
238 _(L2_FLAGS, l2_flags) \
239 _(BRIDGE_FLAGS, bridge_flags) \
240 _(TAP_CONNECT, tap_connect) \
241 _(TAP_MODIFY, tap_modify) \
242 _(TAP_DELETE, tap_delete) \
243 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
244 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
245 _(CREATE_SUBIF, create_subif) \
246 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
247 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
248 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
249 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
250 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
251 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
252 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
253 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
254 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
255 _(RESET_FIB, reset_fib) \
256 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
257 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
258 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
259 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
260 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
261 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
262 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
263 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
264 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
265 sw_interface_ip6_set_link_local_address) \
266 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
267 _(CREATE_LOOPBACK, create_loopback) \
268 _(CONTROL_PING, control_ping) \
269 _(NOPRINT_CONTROL_PING, noprint_control_ping) \
270 _(CLI_REQUEST, cli_request) \
271 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
272 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
273 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
274 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
275 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
276 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
277 _(GET_NODE_INDEX, get_node_index) \
278 _(ADD_NODE_NEXT, add_node_next) \
279 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
280 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
281 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
282 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
283 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
284 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
285 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
286 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
287 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
288 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
289 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
290 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
291 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
292 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
293 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
294 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
295 _(IP_ADDRESS_DUMP, ip_address_dump) \
296 _(IP_DUMP, ip_dump) \
297 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
298 _(SHOW_VERSION, show_version) \
299 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
300 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
301 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
302 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
303 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
304 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
305 _(WANT_IP6_ND_EVENTS, want_ip6_nd_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 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
351 _(SHOW_LISP_STATUS, show_lisp_status) \
352 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
353 lisp_add_del_map_request_itr_rlocs) \
354 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
355 _(SHOW_LISP_PITR, show_lisp_pitr) \
356 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
357 _(AF_PACKET_CREATE, af_packet_create) \
358 _(AF_PACKET_DELETE, af_packet_delete) \
359 _(POLICER_ADD_DEL, policer_add_del) \
360 _(POLICER_DUMP, policer_dump) \
361 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
362 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
363 _(NETMAP_CREATE, netmap_create) \
364 _(NETMAP_DELETE, netmap_delete) \
365 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
366 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
367 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
368 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
369 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
370 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
371 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
372 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
373 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
374 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
375 _(CLASSIFY_TABLE_INFO,classify_table_info) \
376 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
377 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
378 _(IPFIX_ENABLE,ipfix_enable) \
379 _(IPFIX_DUMP,ipfix_dump) \
380 _(GET_NEXT_INDEX, get_next_index) \
381 _(PG_CREATE_INTERFACE, pg_create_interface) \
382 _(PG_CAPTURE, pg_capture) \
383 _(PG_ENABLE_DISABLE, pg_enable_disable) \
384 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
385 ip_source_and_port_range_check_add_del) \
386 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
387 ip_source_and_port_range_check_interface_add_del) \
388 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
389 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
390 _(DELETE_SUBIF, delete_subif)
393 #define QUOTE(x) QUOTE_(x)
395 #define foreach_registration_hash \
396 _(interface_events) \
397 _(to_netconf_server) \
398 _(from_netconf_server) \
399 _(to_netconf_client) \
400 _(from_netconf_client) \
405 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
406 RESOLVE_IP6_ADD_DEL_ROUTE,
407 RESOLVE_MPLS_ETHERNET_ADD_DEL,
415 vl_api_ip_add_del_route_t r;
416 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
423 #define _(a) uword *a##_registration_hash; \
424 vpe_client_registration_t * a##_registrations;
425 foreach_registration_hash
427 /* notifications happen really early in the game */
428 u8 link_state_process_up;
430 /* ip4 and ip6 pending route adds */
431 pending_route_t *pending_routes;
433 /* ip4 arp event registration pool */
434 vl_api_ip4_arp_event_t *arp_events;
436 /* ip6 nd event registration pool */
437 vl_api_ip6_nd_event_t *nd_events;
440 vlib_main_t *vlib_main;
441 vnet_main_t *vnet_main;
444 static vlib_node_registration_t vpe_resolver_process_node;
445 static vpe_api_main_t vpe_api_main;
447 static void send_sw_interface_flags (vpe_api_main_t * am,
448 unix_shared_memory_queue_t * q,
449 vnet_sw_interface_t * swif);
450 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
451 unix_shared_memory_queue_t * q,
454 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
455 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
458 /* Clean up all registrations belonging to the indicated client */
460 vl_api_memclnt_delete_callback (u32 client_index)
462 vpe_api_main_t *vam = &vpe_api_main;
463 vpe_client_registration_t *rp;
465 int stats_memclnt_delete_callback (u32 client_index);
467 stats_memclnt_delete_callback (client_index);
470 p = hash_get (vam->a##_registration_hash, client_index); \
472 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
473 pool_put (vam->a##_registrations, rp); \
474 hash_unset (vam->a##_registration_hash, client_index); \
476 foreach_registration_hash;
481 #define API_LINK_STATE_EVENT 1
482 #define API_ADMIN_UP_DOWN_EVENT 2
485 event_data_cmp (void *a1, void *a2)
490 return (word) e1[0] - (word) e2[0];
494 link_state_process (vlib_main_t * vm,
495 vlib_node_runtime_t * rt, vlib_frame_t * f)
497 vpe_api_main_t *vam = &vpe_api_main;
498 vnet_main_t *vnm = vam->vnet_main;
499 vnet_sw_interface_t *swif;
500 uword *event_data = 0;
501 vpe_client_registration_t *reg;
503 u32 prev_sw_if_index;
504 unix_shared_memory_queue_t *q;
506 vam->link_state_process_up = 1;
510 vlib_process_wait_for_event (vm);
512 /* Unified list of changed link or admin state sw_if_indices */
513 vlib_process_get_events_with_type
514 (vm, &event_data, API_LINK_STATE_EVENT);
515 vlib_process_get_events_with_type
516 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
518 /* Sort, so we can eliminate duplicates */
519 vec_sort_with_function (event_data, event_data_cmp);
521 prev_sw_if_index = ~0;
523 for (i = 0; i < vec_len (event_data); i++)
525 /* Only one message per swif */
526 if (prev_sw_if_index == event_data[i])
528 prev_sw_if_index = event_data[i];
531 pool_foreach(reg, vam->interface_events_registrations,
533 q = vl_api_client_index_to_input_queue (reg->client_index);
536 /* sw_interface may be deleted already */
537 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
540 swif = vnet_get_sw_interface (vnm, event_data[i]);
541 send_sw_interface_flags (vam, q, swif);
547 vec_reset_length (event_data);
553 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
555 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
556 u32 hw_if_index, u32 flags);
559 VLIB_REGISTER_NODE (link_state_process_node,static) = {
560 .function = link_state_process,
561 .type = VLIB_NODE_TYPE_PROCESS,
562 .name = "vpe-link-state-process",
566 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
567 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
569 static clib_error_t *
570 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
572 vpe_api_main_t *vam = &vpe_api_main;
573 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
575 if (vam->link_state_process_up)
576 vlib_process_signal_event (vam->vlib_main,
577 link_state_process_node.index,
578 API_LINK_STATE_EVENT, hi->sw_if_index);
582 static clib_error_t *
583 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
585 vpe_api_main_t *vam = &vpe_api_main;
588 * Note: it's perfectly fair to set a subif admin up / admin down.
589 * Note the subtle distinction between this routine and the previous
592 if (vam->link_state_process_up)
593 vlib_process_signal_event (vam->vlib_main,
594 link_state_process_node.index,
595 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
599 #define pub_sub_handler(lca,UCA) \
600 static void vl_api_want_##lca##_t_handler ( \
601 vl_api_want_##lca##_t *mp) \
603 vpe_api_main_t *vam = &vpe_api_main; \
604 vpe_client_registration_t *rp; \
605 vl_api_want_##lca##_reply_t *rmp; \
609 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
611 if (mp->enable_disable) { \
612 clib_warning ("pid %d: already enabled...", mp->pid); \
613 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
616 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
617 pool_put (vam->lca##_registrations, rp); \
618 hash_unset (vam->lca##_registration_hash, \
623 if (mp->enable_disable == 0) { \
624 clib_warning ("pid %d: already disabled...", mp->pid); \
625 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
628 pool_get (vam->lca##_registrations, rp); \
629 rp->client_index = mp->client_index; \
630 rp->client_pid = mp->pid; \
631 hash_set (vam->lca##_registration_hash, rp->client_index, \
632 rp - vam->lca##_registrations); \
635 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
639 pub_sub_handler (interface_events, INTERFACE_EVENTS)
640 pub_sub_handler (oam_events, OAM_EVENTS)
643 #define RESOLUTION_EVENT 1
644 #define RESOLUTION_PENDING_EVENT 2
645 #define IP4_ARP_EVENT 3
646 #define IP6_ND_EVENT 4
648 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
650 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
652 static int mpls_ethernet_add_del_tunnel_2_t_handler
653 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
656 handle_ip4_arp_event (u32 pool_index)
658 vpe_api_main_t *vam = &vpe_api_main;
659 vnet_main_t *vnm = vam->vnet_main;
660 vlib_main_t *vm = vam->vlib_main;
661 vl_api_ip4_arp_event_t *event;
662 vl_api_ip4_arp_event_t *mp;
663 unix_shared_memory_queue_t *q;
665 /* Client can cancel, die, etc. */
666 if (pool_is_free_index (vam->arp_events, pool_index))
669 event = pool_elt_at_index (vam->arp_events, pool_index);
671 q = vl_api_client_index_to_input_queue (event->client_index);
674 (void) vnet_add_del_ip4_arp_change_event
675 (vnm, arp_change_delete_callback,
676 event->pid, &event->address,
677 vpe_resolver_process_node.index, IP4_ARP_EVENT,
678 ~0 /* pool index, notused */ , 0 /* is_add */ );
682 if (q->cursize < q->maxsize)
684 mp = vl_msg_api_alloc (sizeof (*mp));
685 clib_memcpy (mp, event, sizeof (*mp));
686 vl_msg_api_send_shmem (q, (u8 *) & mp);
690 static f64 last_time;
692 * Throttle syslog msgs.
693 * It's pretty tempting to just revoke the registration...
695 if (vlib_time_now (vm) > last_time + 10.0)
697 clib_warning ("arp event for %U to pid %d: queue stuffed!",
698 format_ip4_address, &event->address, event->pid);
699 last_time = vlib_time_now (vm);
705 handle_ip6_nd_event (u32 pool_index)
707 vpe_api_main_t *vam = &vpe_api_main;
708 vnet_main_t *vnm = vam->vnet_main;
709 vlib_main_t *vm = vam->vlib_main;
710 vl_api_ip6_nd_event_t *event;
711 vl_api_ip6_nd_event_t *mp;
712 unix_shared_memory_queue_t *q;
714 /* Client can cancel, die, etc. */
715 if (pool_is_free_index (vam->nd_events, pool_index))
718 event = pool_elt_at_index (vam->nd_events, pool_index);
720 q = vl_api_client_index_to_input_queue (event->client_index);
723 (void) vnet_add_del_ip6_nd_change_event
724 (vnm, nd_change_delete_callback,
725 event->pid, &event->address,
726 vpe_resolver_process_node.index, IP6_ND_EVENT,
727 ~0 /* pool index, notused */ , 0 /* is_add */ );
731 if (q->cursize < q->maxsize)
733 mp = vl_msg_api_alloc (sizeof (*mp));
734 clib_memcpy (mp, event, sizeof (*mp));
735 vl_msg_api_send_shmem (q, (u8 *) & mp);
739 static f64 last_time;
741 * Throttle syslog msgs.
742 * It's pretty tempting to just revoke the registration...
744 if (vlib_time_now (vm) > last_time + 10.0)
746 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
747 format_ip6_address, &event->address, event->pid);
748 last_time = vlib_time_now (vm);
754 resolver_process (vlib_main_t * vm,
755 vlib_node_runtime_t * rt, vlib_frame_t * f)
758 uword *event_data = 0;
760 vpe_api_main_t *vam = &vpe_api_main;
762 vl_api_ip_add_del_route_t *adr;
763 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
764 u32 *resolution_failures = 0;
770 vlib_process_wait_for_event_or_clock (vm, timeout);
772 event_type = vlib_process_get_events (vm, &event_data);
776 case RESOLUTION_PENDING_EVENT:
780 case RESOLUTION_EVENT:
781 for (i = 0; i < vec_len (event_data); i++)
784 * Resolution events can occur long after the
785 * original request has timed out. $$$ add a cancel
788 if (pool_is_free_index (vam->pending_routes, event_data[i]))
791 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
795 switch (pr->resolve_type)
797 case RESOLVE_IP4_ADD_DEL_ROUTE:
798 rv = ip4_add_del_route_t_handler (adr);
799 clib_warning ("resolver: add %U/%d via %U %s",
801 (ip4_address_t *) & (adr->dst_address),
802 adr->dst_address_length,
804 (ip4_address_t *) & (adr->next_hop_address),
805 (rv >= 0) ? "succeeded" : "failed");
808 case RESOLVE_IP6_ADD_DEL_ROUTE:
809 rv = ip6_add_del_route_t_handler (adr);
810 clib_warning ("resolver: add %U/%d via %U %s",
812 (ip6_address_t *) & (adr->dst_address),
813 adr->dst_address_length,
815 (ip6_address_t *) & (adr->next_hop_address),
816 (rv >= 0) ? "succeeded" : "failed");
819 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
820 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
821 clib_warning ("resolver: add mpls-o-e via %U %s",
824 (pme->next_hop_ip4_address_in_outer_vrf),
825 (rv >= 0) ? "succeeded" : "failed");
829 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
831 pool_put (vam->pending_routes, pr);
836 for (i = 0; i < vec_len (event_data); i++)
837 handle_ip4_arp_event (event_data[i]);
841 for (i = 0; i < vec_len (event_data); i++)
842 handle_ip6_nd_event (event_data[i]);
845 case ~0: /* timeout, retry pending resolutions */
847 pool_foreach (pr, vam->pending_routes,
853 /* May fail, e.g. due to interface down */
854 switch (pr->resolve_type)
856 case RESOLVE_IP4_ADD_DEL_ROUTE:
857 e = ip4_probe_neighbor
858 (vm, (ip4_address_t *)&(adr->next_hop_address),
859 ntohl(adr->next_hop_sw_if_index));
862 case RESOLVE_IP6_ADD_DEL_ROUTE:
863 e = ip6_probe_neighbor
864 (vm, (ip6_address_t *)&(adr->next_hop_address),
865 ntohl(adr->next_hop_sw_if_index));
868 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
870 e = ip4_probe_neighbor
872 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
873 pme->resolve_opaque);
877 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
882 clib_error_report (e);
884 adr->resolve_attempts = 1;
886 pme->resolve_attempts = 1;
890 adr->resolve_attempts -= 1;
891 if (adr->resolve_attempts == 0)
892 vec_add1 (resolution_failures,
893 pr - vam->pending_routes);
897 pme->resolve_attempts -= 1;
898 if (pme->resolve_attempts == 0)
899 vec_add1 (resolution_failures,
900 pr - vam->pending_routes);
904 for (i = 0; i < vec_len (resolution_failures); i++)
906 pr = pool_elt_at_index (vam->pending_routes,
907 resolution_failures[i]);
911 switch (pr->resolve_type)
913 case RESOLVE_IP4_ADD_DEL_ROUTE:
914 clib_warning ("resolver: add %U/%d via %U retry failure",
916 (ip4_address_t *) & (adr->dst_address),
917 adr->dst_address_length,
919 (ip4_address_t *) & (adr->next_hop_address));
922 case RESOLVE_IP6_ADD_DEL_ROUTE:
923 clib_warning ("resolver: add %U/%d via %U retry failure",
925 (ip6_address_t *) & (adr->dst_address),
926 adr->dst_address_length,
928 (ip6_address_t *) & (adr->next_hop_address));
931 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
932 clib_warning ("resolver: add mpls-o-e via %U retry failure",
935 (pme->next_hop_ip4_address_in_outer_vrf));
939 clib_warning ("BUG");
941 pool_put (vam->pending_routes, pr);
943 vec_reset_length (resolution_failures);
946 if (pool_elts (vam->pending_routes) == 0)
948 vec_reset_length (event_data);
950 return 0; /* or not */
954 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
955 .function = resolver_process,
956 .type = VLIB_NODE_TYPE_PROCESS,
957 .name = "vpe-route-resolver-process",
962 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
964 ip4_main_t *im = &ip4_main;
965 ip_lookup_main_t *lm = &im->lookup_main;
966 vnet_classify_main_t *cm = &vnet_classify_main;
967 stats_main_t *sm = &stats_main;
968 ip4_add_del_route_args_t a;
969 ip4_address_t next_hop_address;
971 vpe_api_main_t *vam = &vpe_api_main;
972 vnet_main_t *vnm = vam->vnet_main;
973 vlib_main_t *vm = vlib_get_main ();
975 vl_api_ip_add_del_route_t *adr;
981 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
984 if (mp->create_vrf_if_needed)
987 f = find_ip4_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
989 fib_index = f->index;
993 /* No such VRF, and we weren't asked to create one */
994 return VNET_API_ERROR_NO_SUCH_FIB;
1002 if (~0 != mp->next_hop_sw_if_index &&
1003 pool_is_free_index (vnm->interface_main.sw_interfaces,
1004 ntohl (mp->next_hop_sw_if_index)))
1005 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1007 clib_memcpy (next_hop_address.data, mp->next_hop_address,
1008 sizeof (next_hop_address.data));
1010 /* Arp for the next_hop if necessary */
1011 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1014 ip_adjacency_t *adj;
1016 lookup_result = ip4_fib_lookup_with_table
1017 (im, fib_index, &next_hop_address, 1 /* disable default route */ );
1019 adj = ip_get_adjacency (lm, lookup_result);
1021 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1023 pool_get (vam->pending_routes, pr);
1024 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
1026 clib_memcpy (adr, mp, sizeof (*adr));
1027 /* recursion block, "just in case" */
1028 adr->resolve_if_needed = 0;
1029 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1030 vnet_register_ip4_arp_resolution_event
1031 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1032 RESOLUTION_EVENT, pr - vam->pending_routes);
1034 vlib_process_signal_event
1035 (vm, vpe_resolver_process_node.index,
1036 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1038 /* The interface may be down, etc. */
1039 e = ip4_probe_neighbor
1040 (vm, (ip4_address_t *) & (mp->next_hop_address),
1041 ntohl (mp->next_hop_sw_if_index));
1044 clib_error_report (e);
1046 return VNET_API_ERROR_IN_PROGRESS;
1050 if (mp->is_multipath)
1054 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1057 flags = IP4_ROUTE_FLAG_ADD;
1059 flags = IP4_ROUTE_FLAG_DEL;
1062 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1064 ip4_add_del_route_next_hop (im, flags,
1065 (ip4_address_t *) mp->dst_address,
1066 (u32) mp->dst_address_length,
1067 (ip4_address_t *) mp->next_hop_address,
1068 ntohl (mp->next_hop_sw_if_index),
1069 (u32) mp->next_hop_weight,
1070 ~0 /* adj_index */ ,
1076 memset (&a, 0, sizeof (a));
1077 clib_memcpy (a.dst_address.data, mp->dst_address,
1078 sizeof (a.dst_address.data));
1080 a.dst_address_length = mp->dst_address_length;
1082 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
1083 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
1084 a.table_index_or_table_id = fib_index;
1089 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1091 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1096 ai = lm->drop_adj_index;
1097 else if (mp->is_local)
1098 ai = lm->local_adj_index;
1099 else if (mp->is_classify)
1101 if (pool_is_free_index
1102 (cm->tables, ntohl (mp->classify_table_index)))
1105 return VNET_API_ERROR_NO_SUCH_TABLE;
1107 adj = ip_add_adjacency (lm,
1112 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
1113 adj->classify.table_index = ntohl (mp->classify_table_index);
1115 else if (mp->lookup_in_vrf)
1117 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1120 adj = ip_add_adjacency (lm,
1124 adj->explicit_fib_index = p[0];
1129 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1133 ai = ip4_route_get_next_hop_adj (im,
1136 ntohl (mp->next_hop_sw_if_index),
1139 if (ai == lm->miss_adj_index)
1142 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1147 ip_adjacency_t *adj;
1148 int disable_default_route = 1;
1150 /* Trying to delete the default route? */
1151 if (a.dst_address.as_u32 == 0 && a.dst_address_length == 0)
1152 disable_default_route = 0;
1154 ai = ip4_fib_lookup_with_table
1155 (im, fib_index, &a.dst_address, disable_default_route);
1156 if (ai == lm->miss_adj_index)
1159 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1162 adj = ip_get_adjacency (lm, ai);
1163 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1166 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1171 ip4_add_del_route (im, &a);
1178 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1180 ip6_main_t *im = &ip6_main;
1181 ip_lookup_main_t *lm = &im->lookup_main;
1182 vnet_main_t *vnm = vnet_get_main ();
1183 vlib_main_t *vm = vlib_get_main ();
1184 vpe_api_main_t *vam = &vpe_api_main;
1185 stats_main_t *sm = &stats_main;
1186 ip6_add_del_route_args_t a;
1187 ip6_address_t next_hop_address;
1188 pending_route_t *pr;
1189 vl_api_ip_add_del_route_t *adr;
1194 ip_adjacency_t *adj = 0;
1197 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1201 if (mp->create_vrf_if_needed)
1204 f = find_ip6_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1206 fib_index = f->index;
1210 /* No such VRF, and we weren't asked to create one */
1211 return VNET_API_ERROR_NO_SUCH_FIB;
1219 if (~0 != mp->next_hop_sw_if_index &&
1220 pool_is_free_index (vnm->interface_main.sw_interfaces,
1221 ntohl (mp->next_hop_sw_if_index)))
1222 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1224 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1225 sizeof (next_hop_address.as_u8));
1227 /* Arp for the next_hop if necessary */
1228 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1231 ip_adjacency_t *adj;
1233 lookup_result = ip6_fib_lookup_with_table
1234 (im, fib_index, &next_hop_address);
1236 adj = ip_get_adjacency (lm, lookup_result);
1238 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1240 pool_get (vam->pending_routes, pr);
1242 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1243 clib_memcpy (adr, mp, sizeof (*adr));
1244 /* recursion block, "just in case" */
1245 adr->resolve_if_needed = 0;
1246 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1247 vnet_register_ip6_neighbor_resolution_event
1248 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1249 RESOLUTION_EVENT, pr - vam->pending_routes);
1251 vlib_process_signal_event
1252 (vm, vpe_resolver_process_node.index,
1253 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1255 /* The interface may be down, etc. */
1256 e = ip6_probe_neighbor
1257 (vm, (ip6_address_t *) & (mp->next_hop_address),
1258 ntohl (mp->next_hop_sw_if_index));
1261 clib_error_report (e);
1263 return VNET_API_ERROR_IN_PROGRESS;
1267 if (mp->is_multipath)
1271 dslock (sm, 1 /* release hint */ , 11 /* tag */ );
1274 flags = IP6_ROUTE_FLAG_ADD;
1276 flags = IP6_ROUTE_FLAG_DEL;
1279 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1281 ip6_add_del_route_next_hop (im, flags,
1282 (ip6_address_t *) mp->dst_address,
1283 (u32) mp->dst_address_length,
1284 (ip6_address_t *) mp->next_hop_address,
1285 ntohl (mp->next_hop_sw_if_index),
1286 (u32) mp->next_hop_weight,
1287 ~0 /* adj_index */ ,
1293 memset (&a, 0, sizeof (a));
1294 clib_memcpy (a.dst_address.as_u8, mp->dst_address,
1295 sizeof (a.dst_address.as_u8));
1297 a.dst_address_length = mp->dst_address_length;
1299 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1300 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1301 a.table_index_or_table_id = fib_index;
1306 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1308 dslock (sm, 1 /* release hint */ , 3 /* tag */ );
1313 ai = lm->drop_adj_index;
1314 else if (mp->is_local)
1315 ai = lm->local_adj_index;
1316 else if (mp->lookup_in_vrf)
1318 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1321 adj = ip_add_adjacency (lm,
1325 adj->explicit_fib_index = p[0];
1330 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1334 ai = ip6_route_get_next_hop_adj (im,
1337 ntohl (mp->next_hop_sw_if_index),
1339 if (ai == lm->miss_adj_index)
1342 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1347 ip_adjacency_t *adj;
1349 ai = ip6_fib_lookup_with_table (im, fib_index, &a.dst_address);
1350 if (ai == lm->miss_adj_index)
1353 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1355 adj = ip_get_adjacency (lm, ai);
1356 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1359 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1364 ip6_add_del_route (im, &a);
1371 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1373 vl_api_ip_add_del_route_reply_t *rmp;
1375 vnet_main_t *vnm = vnet_get_main ();
1380 rv = ip6_add_del_route_t_handler (mp);
1382 rv = ip4_add_del_route_t_handler (mp);
1384 rv = (rv == 0) ? vnm->api_errno : rv;
1386 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1390 api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1391 u32 sw_if_index, u8 * next_hop_addr)
1393 vl_api_ip_add_del_route_t mp;
1396 memset (&mp, 0, sizeof (vl_api_ip_add_del_route_t));
1399 * Configure default IP route:
1400 * - ip route add 0.0.0.0/1 via <GW IP>
1401 * - ip route add 128.0.0.0/1 via <GW IP>
1403 mp.next_hop_sw_if_index = ntohl (sw_if_index);
1405 mp.resolve_attempts = ~0;
1406 mp.resolve_if_needed = 1;
1408 mp.is_ipv6 = is_ipv6;
1409 mp.next_hop_weight = 1;
1411 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1414 rv = ip6_add_del_route_t_handler (&mp);
1417 mp.dst_address_length = 1;
1419 mp.dst_address[0] = 0;
1420 rv = ip4_add_del_route_t_handler (&mp);
1422 mp.dst_address[0] = 128;
1423 rv |= ip4_add_del_route_t_handler (&mp);
1427 clib_error_return (0, "failed to config default IP route");
1432 vl_api_sw_interface_add_del_address_t_handler
1433 (vl_api_sw_interface_add_del_address_t * mp)
1435 vlib_main_t *vm = vlib_get_main ();
1436 vl_api_sw_interface_add_del_address_reply_t *rmp;
1440 VALIDATE_SW_IF_INDEX (mp);
1442 is_del = mp->is_add == 0;
1445 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1446 else if (mp->is_ipv6)
1447 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1448 (void *) mp->address,
1449 mp->address_length, is_del);
1451 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1452 (void *) mp->address,
1453 mp->address_length, is_del);
1455 BAD_SW_IF_INDEX_LABEL;
1457 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1461 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1464 u32 table_id = ntohl (mp->vrf_id);
1465 u32 sw_if_index = ntohl (mp->sw_if_index);
1466 vl_api_sw_interface_set_table_reply_t *rmp;
1467 stats_main_t *sm = &stats_main;
1469 VALIDATE_SW_IF_INDEX (mp);
1471 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1475 ip6_main_t *im = &ip6_main;
1476 ip6_fib_t *fib = find_ip6_fib_by_table_index_or_id (im, table_id,
1477 IP6_ROUTE_FLAG_TABLE_ID);
1480 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1481 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1485 rv = VNET_API_ERROR_NO_SUCH_FIB;
1490 ip4_main_t *im = &ip4_main;
1491 ip4_fib_t *fib = find_ip4_fib_by_table_index_or_id
1492 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1494 /* Truthfully this can't fail */
1497 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1498 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1502 rv = VNET_API_ERROR_NO_SUCH_FIB;
1507 BAD_SW_IF_INDEX_LABEL;
1509 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1513 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1515 vlib_main_t *vm = vlib_get_main ();
1516 ip4_main_t *im4 = &ip4_main;
1517 ip6_main_t *im6 = &ip6_main;
1518 vl_api_sw_interface_set_vpath_reply_t *rmp;
1521 u32 sw_if_index = ntohl (mp->sw_if_index);
1522 ip4_main_t *ip4m = &ip4_main;
1523 ip6_main_t *ip6m = &ip6_main;
1524 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1525 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1526 ip_config_main_t *rx_cm4u =
1527 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1528 ip_config_main_t *rx_cm4m =
1529 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1530 ip_config_main_t *rx_cm6u =
1531 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1532 ip_config_main_t *rx_cm6m =
1533 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1535 VALIDATE_SW_IF_INDEX (mp);
1537 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1540 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1541 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1543 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1544 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1545 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1546 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1548 im4->ip4_multicast_rx_feature_vpath,
1550 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1551 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1552 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1554 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1555 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1556 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1557 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1559 im6->ip6_multicast_rx_feature_vpath,
1561 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1565 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1566 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1568 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1569 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1570 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1571 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1573 im4->ip4_multicast_rx_feature_vpath,
1575 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1576 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1577 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1579 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1580 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1581 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1582 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1584 im6->ip6_multicast_rx_feature_vpath,
1586 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1589 BAD_SW_IF_INDEX_LABEL;
1591 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1595 vl_api_sw_interface_set_l2_xconnect_t_handler
1596 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1598 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1600 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1601 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1602 vlib_main_t *vm = vlib_get_main ();
1603 vnet_main_t *vnm = vnet_get_main ();
1605 VALIDATE_RX_SW_IF_INDEX (mp);
1609 VALIDATE_TX_SW_IF_INDEX (mp);
1610 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1611 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1615 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1618 BAD_RX_SW_IF_INDEX_LABEL;
1619 BAD_TX_SW_IF_INDEX_LABEL;
1621 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1625 vl_api_sw_interface_set_l2_bridge_t_handler
1626 (vl_api_sw_interface_set_l2_bridge_t * mp)
1628 bd_main_t *bdm = &bd_main;
1629 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1631 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1632 u32 bd_id = ntohl (mp->bd_id);
1636 vlib_main_t *vm = vlib_get_main ();
1637 vnet_main_t *vnm = vnet_get_main ();
1639 VALIDATE_RX_SW_IF_INDEX (mp);
1641 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1645 //VALIDATE_TX_SW_IF_INDEX(mp);
1646 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1647 rx_sw_if_index, bd_index, bvi, shg, 0);
1651 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1654 BAD_RX_SW_IF_INDEX_LABEL;
1656 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1660 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1662 vlib_main_t *vm = vlib_get_main ();
1663 bd_main_t *bdm = &bd_main;
1664 vl_api_bridge_domain_add_del_reply_t *rmp;
1666 u32 enable_flags = 0, disable_flags = 0;
1667 u32 bd_id = ntohl (mp->bd_id);
1672 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1675 enable_flags |= L2_FLOOD;
1677 disable_flags |= L2_FLOOD;
1680 enable_flags |= L2_UU_FLOOD;
1682 disable_flags |= L2_UU_FLOOD;
1685 enable_flags |= L2_FWD;
1687 disable_flags |= L2_FWD;
1690 enable_flags |= L2_ARP_TERM;
1692 disable_flags |= L2_ARP_TERM;
1695 enable_flags |= L2_LEARN;
1697 disable_flags |= L2_LEARN;
1700 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1703 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1707 rv = bd_delete_bd_index (bdm, bd_id);
1709 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1713 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1715 clib_warning ("BUG");
1719 vl_api_bridge_domain_sw_if_details_t_handler
1720 (vl_api_bridge_domain_sw_if_details_t * mp)
1722 clib_warning ("BUG");
1726 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1727 l2_bridge_domain_t * bd_config,
1728 u32 n_sw_ifs, u32 context)
1730 vl_api_bridge_domain_details_t *mp;
1732 mp = vl_msg_api_alloc (sizeof (*mp));
1733 memset (mp, 0, sizeof (*mp));
1734 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1735 mp->bd_id = ntohl (bd_config->bd_id);
1736 mp->flood = bd_feature_flood (bd_config);
1737 mp->uu_flood = bd_feature_uu_flood (bd_config);
1738 mp->forward = bd_feature_forward (bd_config);
1739 mp->learn = bd_feature_learn (bd_config);
1740 mp->arp_term = bd_feature_arp_term (bd_config);
1741 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1742 mp->n_sw_ifs = ntohl (n_sw_ifs);
1743 mp->context = context;
1745 vl_msg_api_send_shmem (q, (u8 *) & mp);
1749 send_bd_sw_if_details (l2input_main_t * l2im,
1750 unix_shared_memory_queue_t * q,
1751 l2_flood_member_t * member, u32 bd_id, u32 context)
1753 vl_api_bridge_domain_sw_if_details_t *mp;
1754 l2_input_config_t *input_cfg;
1756 mp = vl_msg_api_alloc (sizeof (*mp));
1757 memset (mp, 0, sizeof (*mp));
1758 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1759 mp->bd_id = ntohl (bd_id);
1760 mp->sw_if_index = ntohl (member->sw_if_index);
1761 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1762 mp->shg = input_cfg->shg;
1763 mp->context = context;
1765 vl_msg_api_send_shmem (q, (u8 *) & mp);
1769 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1771 bd_main_t *bdm = &bd_main;
1772 l2input_main_t *l2im = &l2input_main;
1773 unix_shared_memory_queue_t *q;
1774 l2_bridge_domain_t *bd_config;
1775 u32 bd_id, bd_index;
1778 q = vl_api_client_index_to_input_queue (mp->client_index);
1783 bd_id = ntohl (mp->bd_id);
1785 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1786 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1787 for (; bd_index < end; bd_index++)
1789 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1790 /* skip dummy bd_id 0 */
1791 if (bd_config && (bd_config->bd_id > 0))
1794 l2_flood_member_t *m;
1796 n_sw_ifs = vec_len (bd_config->members);
1797 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1799 vec_foreach (m, bd_config->members)
1801 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1808 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1810 bd_main_t *bdm = &bd_main;
1811 l2input_main_t *l2im = &l2input_main;
1812 vl_api_l2fib_add_del_reply_t *rmp;
1815 u32 sw_if_index = ntohl (mp->sw_if_index);
1816 u32 bd_id = ntohl (mp->bd_id);
1825 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1828 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1829 goto bad_sw_if_index;
1835 VALIDATE_SW_IF_INDEX (mp);
1836 if (vec_len (l2im->configs) <= sw_if_index)
1838 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1839 goto bad_sw_if_index;
1843 l2_input_config_t *config;
1844 config = vec_elt_at_index (l2im->configs, sw_if_index);
1845 if (config->bridge == 0)
1847 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1848 goto bad_sw_if_index;
1851 static_mac = mp->static_mac ? 1 : 0;
1852 filter_mac = mp->filter_mac ? 1 : 0;
1853 bvi_mac = mp->bvi_mac ? 1 : 0;
1854 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1859 l2fib_del_entry (mac, bd_index);
1862 BAD_SW_IF_INDEX_LABEL;
1864 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1868 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1870 vl_api_l2_flags_reply_t *rmp;
1872 u32 sw_if_index = ntohl (mp->sw_if_index);
1873 u32 flags = ntohl (mp->feature_bitmap);
1876 VALIDATE_SW_IF_INDEX (mp);
1879 if (flags & L2INPUT_FEAT_ ## a) \
1880 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1881 foreach_l2input_feat;
1884 BAD_SW_IF_INDEX_LABEL;
1887 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1889 rmp->resulting_feature_bitmap = ntohl(rbm);
1895 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1897 vlib_main_t *vm = vlib_get_main ();
1898 bd_main_t *bdm = &bd_main;
1899 vl_api_bridge_flags_reply_t *rmp;
1901 u32 bd_id = ntohl (mp->bd_id);
1903 u32 flags = ntohl (mp->feature_bitmap);
1906 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1909 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1915 bd_set_flags (vm, bd_index, flags, mp->is_set);
1919 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1921 rmp->resulting_feature_bitmap = ntohl(flags);
1927 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1929 bd_main_t *bdm = &bd_main;
1930 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1932 u32 bd_id = ntohl (mp->bd_id);
1936 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1939 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1944 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1945 mp->mac_address, mp->is_ipv6, mp->is_add))
1946 rv = VNET_API_ERROR_UNSPECIFIED;
1949 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1953 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1956 vl_api_tap_connect_reply_t *rmp;
1957 unix_shared_memory_queue_t *q;
1958 u32 sw_if_index = (u32) ~ 0;
1960 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1961 mp->use_random_mac ? 0 : mp->mac_address,
1962 &sw_if_index, mp->renumber,
1963 ntohl (mp->custom_dev_instance));
1965 q = vl_api_client_index_to_input_queue (mp->client_index);
1969 rmp = vl_msg_api_alloc (sizeof (*rmp));
1970 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1971 rmp->context = mp->context;
1972 rmp->retval = ntohl (rv);
1973 rmp->sw_if_index = ntohl (sw_if_index);
1975 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1979 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
1982 vl_api_tap_modify_reply_t *rmp;
1983 unix_shared_memory_queue_t *q;
1984 u32 sw_if_index = (u32) ~ 0;
1986 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
1987 mp->use_random_mac ? 0 : mp->mac_address,
1988 &sw_if_index, mp->renumber,
1989 ntohl (mp->custom_dev_instance));
1991 q = vl_api_client_index_to_input_queue (mp->client_index);
1995 rmp = vl_msg_api_alloc (sizeof (*rmp));
1996 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
1997 rmp->context = mp->context;
1998 rmp->retval = ntohl (rv);
1999 rmp->sw_if_index = ntohl (sw_if_index);
2001 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2005 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
2008 vpe_api_main_t *vam = &vpe_api_main;
2009 vl_api_tap_delete_reply_t *rmp;
2010 unix_shared_memory_queue_t *q;
2011 u32 sw_if_index = ntohl (mp->sw_if_index);
2013 rv = vnet_tap_delete (vm, sw_if_index);
2015 q = vl_api_client_index_to_input_queue (mp->client_index);
2019 rmp = vl_msg_api_alloc (sizeof (*rmp));
2020 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
2021 rmp->context = mp->context;
2022 rmp->retval = ntohl (rv);
2024 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2027 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2031 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
2033 vl_api_create_vlan_subif_reply_t *rmp;
2034 vnet_main_t *vnm = vnet_get_main ();
2035 u32 hw_if_index, sw_if_index = (u32) ~ 0;
2036 vnet_hw_interface_t *hi;
2039 vnet_sw_interface_t template;
2041 vnet_interface_main_t *im = &vnm->interface_main;
2042 u64 sup_and_sub_key;
2044 unix_shared_memory_queue_t *q;
2045 clib_error_t *error;
2047 VALIDATE_SW_IF_INDEX (mp);
2049 hw_if_index = ntohl (mp->sw_if_index);
2050 hi = vnet_get_hw_interface (vnm, hw_if_index);
2052 id = ntohl (mp->vlan_id);
2053 if (id == 0 || id > 4095)
2055 rv = VNET_API_ERROR_INVALID_VLAN;
2059 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2061 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2064 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2068 kp = clib_mem_alloc (sizeof (*kp));
2069 *kp = sup_and_sub_key;
2071 memset (&template, 0, sizeof (template));
2072 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2073 template.sup_sw_if_index = hi->sw_if_index;
2074 template.sub.id = id;
2075 template.sub.eth.raw_flags = 0;
2076 template.sub.eth.flags.one_tag = 1;
2077 template.sub.eth.outer_vlan_id = id;
2078 template.sub.eth.flags.exact_match = 1;
2080 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2083 clib_error_report (error);
2084 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2087 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2088 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2090 BAD_SW_IF_INDEX_LABEL;
2093 q = vl_api_client_index_to_input_queue (mp->client_index);
2097 rmp = vl_msg_api_alloc (sizeof (*rmp));
2098 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2099 rmp->context = mp->context;
2100 rmp->retval = ntohl (rv);
2101 rmp->sw_if_index = ntohl (sw_if_index);
2102 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2106 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2108 vl_api_create_subif_reply_t *rmp;
2109 vnet_main_t *vnm = vnet_get_main ();
2110 u32 sw_if_index = ~0;
2113 vnet_sw_interface_t *si;
2114 vnet_hw_interface_t *hi;
2115 vnet_sw_interface_t template;
2117 vnet_interface_main_t *im = &vnm->interface_main;
2118 u64 sup_and_sub_key;
2120 clib_error_t *error;
2122 VALIDATE_SW_IF_INDEX (mp);
2124 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2125 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2127 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2129 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2133 sw_if_index = si->sw_if_index;
2134 sub_id = ntohl (mp->sub_id);
2136 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2138 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2142 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2143 sw_if_index, sub_id);
2144 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2148 kp = clib_mem_alloc (sizeof (*kp));
2149 *kp = sup_and_sub_key;
2151 memset (&template, 0, sizeof (template));
2152 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2153 template.sup_sw_if_index = sw_if_index;
2154 template.sub.id = sub_id;
2155 template.sub.eth.flags.no_tags = mp->no_tags;
2156 template.sub.eth.flags.one_tag = mp->one_tag;
2157 template.sub.eth.flags.two_tags = mp->two_tags;
2158 template.sub.eth.flags.dot1ad = mp->dot1ad;
2159 template.sub.eth.flags.exact_match = mp->exact_match;
2160 template.sub.eth.flags.default_sub = mp->default_sub;
2161 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2162 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2163 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2164 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2166 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2169 clib_error_report (error);
2170 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2174 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2175 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2177 BAD_SW_IF_INDEX_LABEL;
2182 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2184 rmp->sw_if_index = ntohl(sw_if_index);
2190 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2193 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2195 stats_main_t *sm = &stats_main;
2196 u32 tunnel_sw_if_index = ~0;
2198 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2200 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2201 (ip4_address_t *) (mp->dst_address),
2202 (ip4_address_t *) (mp->intfc_address),
2203 (u32) (mp->intfc_address_length),
2204 ntohl (mp->inner_vrf_id),
2205 ntohl (mp->outer_vrf_id),
2206 &tunnel_sw_if_index,
2207 mp->l2_only, mp->is_add);
2211 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2213 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2219 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2220 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2222 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2224 stats_main_t *sm = &stats_main;
2225 u32 tunnel_sw_if_index;
2227 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2229 rv = vnet_mpls_ethernet_add_del_tunnel
2230 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2231 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2232 ntohl (mp->tx_sw_if_index),
2233 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2238 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2240 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2246 * This piece of misery brought to you because the control-plane
2247 * can't figure out the tx interface + dst-mac address all by itself
2249 static int mpls_ethernet_add_del_tunnel_2_t_handler
2250 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2252 pending_route_t *pr;
2253 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2254 vnet_main_t *vnm = vnet_get_main ();
2255 vlib_main_t *vm = vlib_get_main ();
2256 stats_main_t *sm = &stats_main;
2257 vpe_api_main_t *vam = &vpe_api_main;
2258 u32 inner_fib_index, outer_fib_index;
2259 ip4_main_t *im = &ip4_main;
2260 ip_lookup_main_t *lm = &im->lookup_main;
2261 ip_adjacency_t *adj = 0;
2264 u8 *dst_mac_address;
2268 u32 tunnel_sw_if_index;
2270 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2272 return VNET_API_ERROR_NO_SUCH_FIB;
2274 outer_fib_index = p[0];
2277 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2279 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2281 inner_fib_index = p[0];
2283 if (inner_fib_index == outer_fib_index)
2284 return VNET_API_ERROR_INVALID_VALUE;
2286 lookup_result = ip4_fib_lookup_with_table
2287 (im, outer_fib_index,
2288 (ip4_address_t *) mp->next_hop_ip4_address_in_outer_vrf,
2289 1 /* disable default route */ );
2291 adj = ip_get_adjacency (lm, lookup_result);
2292 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2294 if (mp->is_add && mp->resolve_if_needed)
2296 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2298 pool_get (vam->pending_routes, pr);
2299 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2301 clib_memcpy (pme, mp, sizeof (*pme));
2302 /* recursion block, "just in case" */
2303 pme->resolve_if_needed = 0;
2304 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2305 pme->resolve_opaque = tx_sw_if_index;
2306 vnet_register_ip4_arp_resolution_event
2308 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2309 vpe_resolver_process_node.index,
2310 RESOLUTION_EVENT, pr - vam->pending_routes);
2312 vlib_process_signal_event
2313 (vm, vpe_resolver_process_node.index,
2314 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2316 /* The interface may be down, etc. */
2317 e = ip4_probe_neighbor
2318 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2322 clib_error_report (e);
2324 return VNET_API_ERROR_IN_PROGRESS;
2328 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2329 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2332 vnet_rewrite_get_data_internal
2333 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2335 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2337 rv = vnet_mpls_ethernet_add_del_tunnel
2338 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2339 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2340 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2348 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2349 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2351 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2354 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2356 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2361 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2363 vl_api_mpls_add_del_encap_reply_t *rmp;
2368 vec_reset_length (labels);
2370 for (i = 0; i < mp->nlabels; i++)
2371 vec_add1 (labels, ntohl (mp->labels[i]));
2374 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2375 ntohl (mp->vrf_id), labels,
2376 ~0 /* policy_tunnel_index */ ,
2377 0 /* no_dst_hash */ ,
2381 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2385 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2387 vl_api_mpls_add_del_decap_reply_t *rmp;
2390 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2391 ntohl (mp->label), ntohl (mp->next_index),
2392 mp->s_bit, mp->is_add);
2394 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2398 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2400 vl_api_proxy_arp_add_del_reply_t *rmp;
2403 ip4_main_t *im = &ip4_main;
2404 stats_main_t *sm = &stats_main;
2405 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2406 ip4_address_t * hi_addr,
2407 u32 fib_index, int is_del);
2410 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2412 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2416 rv = VNET_API_ERROR_NO_SUCH_FIB;
2422 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2423 (ip4_address_t *) mp->hi_address,
2424 fib_index, mp->is_add == 0);
2428 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2432 vl_api_proxy_arp_intfc_enable_disable_t_handler
2433 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2436 vnet_main_t *vnm = vnet_get_main ();
2437 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2438 vnet_sw_interface_t *si;
2441 VALIDATE_SW_IF_INDEX (mp);
2443 sw_if_index = ntohl (mp->sw_if_index);
2445 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2447 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2451 si = vnet_get_sw_interface (vnm, sw_if_index);
2455 if (mp->enable_disable)
2456 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2458 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2460 BAD_SW_IF_INDEX_LABEL;
2463 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2467 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2470 vl_api_ip_neighbor_add_del_reply_t *rmp;
2471 vnet_main_t *vnm = vnet_get_main ();
2474 stats_main_t *sm = &stats_main;
2476 VALIDATE_SW_IF_INDEX (mp);
2478 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2483 rv = vnet_set_ip6_ethernet_neighbor
2484 (vm, ntohl (mp->sw_if_index),
2485 (ip6_address_t *) (mp->dst_address),
2486 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2488 rv = vnet_unset_ip6_ethernet_neighbor
2489 (vm, ntohl (mp->sw_if_index),
2490 (ip6_address_t *) (mp->dst_address),
2491 mp->mac_address, sizeof (mp->mac_address));
2495 ip4_main_t *im = &ip4_main;
2496 ip_lookup_main_t *lm = &im->lookup_main;
2497 ethernet_arp_ip4_over_ethernet_address_t a;
2499 ip_adjacency_t *nh_adj;
2501 uword *p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2504 rv = VNET_API_ERROR_NO_SUCH_FIB;
2510 * Unfortunately, folks have a penchant for
2511 * adding interface addresses to the ARP cache, and
2512 * wondering why the forwarder eventually ASSERTs...
2514 ai = ip4_fib_lookup_with_table
2515 (im, fib_index, (ip4_address_t *) (mp->dst_address),
2516 1 /* disable default route */ );
2520 nh_adj = ip_get_adjacency (lm, ai);
2521 /* Never allow manipulation of a local adj! */
2522 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL)
2524 clib_warning ("%U matches local adj",
2526 (ip4_address_t *) (mp->dst_address));
2527 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2532 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2533 clib_memcpy (&a.ip4, mp->dst_address, 4);
2536 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2537 fib_index, &a, mp->is_static);
2539 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2543 BAD_SW_IF_INDEX_LABEL;
2546 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2550 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2553 vpe_main_t *rm = &vpe_main;
2554 ip4_main_t *im4 = &ip4_main;
2555 ip6_main_t *im6 = &ip6_main;
2556 ip_lookup_main_t *lm;
2562 u32 adj_index, sw_if_index;
2563 vl_api_is_address_reachable_t *rmp;
2564 ip_adjacency_t *adj;
2565 unix_shared_memory_queue_t *q;
2567 q = vl_api_client_index_to_input_queue (mp->client_index);
2570 increment_missing_api_client_counter (rm->vlib_main);
2574 rmp = vl_msg_api_alloc (sizeof (*rmp));
2575 clib_memcpy (rmp, mp, sizeof (*rmp));
2577 sw_if_index = mp->next_hop_sw_if_index;
2578 clib_memcpy (&addr, mp->address, sizeof (addr));
2581 lm = &im6->lookup_main;
2582 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2586 lm = &im4->lookup_main;
2587 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2589 if (adj_index == ~0)
2594 adj = ip_get_adjacency (lm, adj_index);
2596 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2597 && adj->rewrite_header.sw_if_index == sw_if_index)
2603 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2604 && adj->rewrite_header.sw_if_index == sw_if_index)
2607 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2609 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2611 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2620 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2625 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2627 clib_warning ("BUG");
2631 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2633 vl_api_sw_interface_set_flags_reply_t *rmp;
2634 vnet_main_t *vnm = vnet_get_main ();
2636 clib_error_t *error;
2639 VALIDATE_SW_IF_INDEX (mp);
2641 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2643 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2647 clib_error_report (error);
2650 BAD_SW_IF_INDEX_LABEL;
2651 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2655 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2658 vl_api_sw_interface_clear_stats_reply_t *rmp;
2660 vnet_main_t *vnm = vnet_get_main ();
2661 vnet_interface_main_t *im = &vnm->interface_main;
2662 vlib_simple_counter_main_t *sm;
2663 vlib_combined_counter_main_t *cm;
2664 static vnet_main_t **my_vnet_mains;
2665 int i, j, n_counters;
2668 if (mp->sw_if_index != ~0)
2669 VALIDATE_SW_IF_INDEX (mp);
2671 vec_reset_length (my_vnet_mains);
2673 for (i = 0; i < vec_len (vnet_mains); i++)
2676 vec_add1 (my_vnet_mains, vnet_mains[i]);
2679 if (vec_len (vnet_mains) == 0)
2680 vec_add1 (my_vnet_mains, vnm);
2682 n_counters = vec_len (im->combined_sw_if_counters);
2684 for (j = 0; j < n_counters; j++)
2686 for (i = 0; i < vec_len (my_vnet_mains); i++)
2688 im = &my_vnet_mains[i]->interface_main;
2689 cm = im->combined_sw_if_counters + j;
2690 if (mp->sw_if_index == (u32) ~ 0)
2691 vlib_clear_combined_counters (cm);
2693 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2697 n_counters = vec_len (im->sw_if_counters);
2699 for (j = 0; j < n_counters; j++)
2701 for (i = 0; i < vec_len (my_vnet_mains); i++)
2703 im = &my_vnet_mains[i]->interface_main;
2704 sm = im->sw_if_counters + j;
2705 if (mp->sw_if_index == (u32) ~ 0)
2706 vlib_clear_simple_counters (sm);
2708 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2712 BAD_SW_IF_INDEX_LABEL;
2714 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2718 send_sw_interface_details (vpe_api_main_t * am,
2719 unix_shared_memory_queue_t * q,
2720 vnet_sw_interface_t * swif,
2721 u8 * interface_name, u32 context)
2723 vl_api_sw_interface_details_t *mp;
2724 vnet_hw_interface_t *hi;
2726 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2728 mp = vl_msg_api_alloc (sizeof (*mp));
2729 memset (mp, 0, sizeof (*mp));
2730 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2731 mp->sw_if_index = ntohl (swif->sw_if_index);
2732 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2733 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2734 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2735 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2736 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2737 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2738 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2739 mp->link_mtu = ntohs (hi->max_packet_bytes);
2740 mp->context = context;
2742 strncpy ((char *) mp->interface_name,
2743 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2745 /* Send the L2 address for ethernet physical intfcs */
2746 if (swif->sup_sw_if_index == swif->sw_if_index
2747 && hi->hw_class_index == ethernet_hw_interface_class.index)
2749 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2750 ethernet_interface_t *ei;
2752 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2753 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2754 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2755 mp->l2_address_length = ntohl (sizeof (ei->address));
2757 else if (swif->sup_sw_if_index != swif->sw_if_index)
2759 vnet_sub_interface_t *sub = &swif->sub;
2760 mp->sub_id = ntohl (sub->id);
2761 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2762 mp->sub_number_of_tags =
2763 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2764 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2765 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2766 mp->sub_exact_match = sub->eth.flags.exact_match;
2767 mp->sub_default = sub->eth.flags.default_sub;
2768 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2769 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2771 /* vlan tag rewrite data */
2772 u32 vtr_op = L2_VTR_DISABLED;
2773 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2775 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2776 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2778 // error - default to disabled
2779 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2780 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2785 mp->vtr_op = ntohl (vtr_op);
2786 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2787 mp->vtr_tag1 = ntohl (vtr_tag1);
2788 mp->vtr_tag2 = ntohl (vtr_tag2);
2792 vl_msg_api_send_shmem (q, (u8 *) & mp);
2796 send_sw_interface_flags (vpe_api_main_t * am,
2797 unix_shared_memory_queue_t * q,
2798 vnet_sw_interface_t * swif)
2800 vl_api_sw_interface_set_flags_t *mp;
2801 vnet_main_t *vnm = am->vnet_main;
2803 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2805 mp = vl_msg_api_alloc (sizeof (*mp));
2806 memset (mp, 0, sizeof (*mp));
2807 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2808 mp->sw_if_index = ntohl (swif->sw_if_index);
2810 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2811 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2812 vl_msg_api_send_shmem (q, (u8 *) & mp);
2815 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2816 unix_shared_memory_queue_t * q,
2818 __attribute__ ((unused));
2821 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2822 unix_shared_memory_queue_t * q,
2825 vl_api_sw_interface_set_flags_t *mp;
2827 mp = vl_msg_api_alloc (sizeof (*mp));
2828 memset (mp, 0, sizeof (*mp));
2829 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2830 mp->sw_if_index = ntohl (sw_if_index);
2832 mp->admin_up_down = 0;
2833 mp->link_up_down = 0;
2835 vl_msg_api_send_shmem (q, (u8 *) & mp);
2839 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2841 vpe_api_main_t *am = &vpe_api_main;
2842 vnet_sw_interface_t *swif;
2843 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2844 u8 *filter_string = 0, *name_string = 0;
2845 unix_shared_memory_queue_t *q;
2846 char *strcasestr (char *, char *); /* lnx hdr file botch */
2848 q = vl_api_client_index_to_input_queue (mp->client_index);
2853 if (mp->name_filter_valid)
2855 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2856 filter_string = format (0, "%s%c", mp->name_filter, 0);
2860 pool_foreach (swif, im->sw_interfaces,
2862 name_string = format (name_string, "%U%c",
2863 format_vnet_sw_interface_name,
2864 am->vnet_main, swif, 0);
2866 if (mp->name_filter_valid == 0 ||
2867 strcasestr((char *) name_string, (char *) filter_string)) {
2869 send_sw_interface_details (am, q, swif, name_string, mp->context);
2871 _vec_len (name_string) = 0;
2875 vec_free (name_string);
2876 vec_free (filter_string);
2880 send_oam_event (oam_target_t * t)
2882 vpe_api_main_t *vam = &vpe_api_main;
2883 unix_shared_memory_queue_t *q;
2884 vpe_client_registration_t *reg;
2885 vl_api_oam_event_t *mp;
2888 pool_foreach(reg, vam->oam_events_registrations,
2890 q = vl_api_client_index_to_input_queue (reg->client_index);
2893 mp = vl_msg_api_alloc (sizeof (*mp));
2894 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2895 clib_memcpy (mp->dst_address, &t->dst_address,
2896 sizeof (mp->dst_address));
2897 mp->state = t->state;
2898 vl_msg_api_send_shmem (q, (u8 *)&mp);
2905 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2907 vl_api_oam_add_del_reply_t *rmp;
2910 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2911 (ip4_address_t *) mp->dst_address,
2912 ntohl (mp->vrf_id), (int) (mp->is_add));
2914 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2918 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2920 stats_main_t *sm = &stats_main;
2921 vnet_interface_main_t *im = sm->interface_main;
2922 vl_api_vnet_summary_stats_reply_t *rmp;
2923 vlib_combined_counter_main_t *cm;
2926 u64 total_pkts[VLIB_N_RX_TX];
2927 u64 total_bytes[VLIB_N_RX_TX];
2929 unix_shared_memory_queue_t *q =
2930 vl_api_client_index_to_input_queue (mp->client_index);
2935 rmp = vl_msg_api_alloc (sizeof (*rmp));
2936 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2937 rmp->context = mp->context;
2940 memset (total_pkts, 0, sizeof (total_pkts));
2941 memset (total_bytes, 0, sizeof (total_bytes));
2943 vnet_interface_counter_lock (im);
2945 vec_foreach (cm, im->combined_sw_if_counters)
2947 which = cm - im->combined_sw_if_counters;
2949 for (i = 0; i < vec_len (cm->maxi); i++)
2951 vlib_get_combined_counter (cm, i, &v);
2952 total_pkts[which] += v.packets;
2953 total_bytes[which] += v.bytes;
2956 vnet_interface_counter_unlock (im);
2958 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2959 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2960 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2961 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2963 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2965 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2969 typedef CLIB_PACKED (struct {
2970 ip4_address_t address;
2971 u32 address_length: 6;
2977 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2979 vnet_main_t *vnm = vnet_get_main ();
2980 vnet_interface_main_t *im = &vnm->interface_main;
2981 ip4_main_t *im4 = &ip4_main;
2982 static ip4_route_t *routes;
2983 static u32 *sw_if_indices_to_shut;
2984 stats_main_t *sm = &stats_main;
2989 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2990 u32 target_fib_id = ntohl (mp->vrf_id);
2992 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
2994 vec_foreach (fib, im4->fibs)
2996 vnet_sw_interface_t *si;
2998 if (fib->table_id != target_fib_id)
3001 /* remove any mpls/gre tunnels in this fib */
3002 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
3004 /* remove any mpls encap/decap labels */
3005 mpls_fib_reset_labels (fib->table_id);
3007 /* remove any proxy arps in this fib */
3008 vnet_proxy_arp_fib_reset (fib->table_id);
3010 /* Set the flow hash for this fib to the default */
3011 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3013 vec_reset_length (sw_if_indices_to_shut);
3015 /* Shut down interfaces in this FIB / clean out intfc routes */
3017 pool_foreach (si, im->sw_interfaces,
3019 u32 sw_if_index = si->sw_if_index;
3021 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
3022 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
3024 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3028 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3030 sw_if_index = sw_if_indices_to_shut[i];
3031 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3033 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3034 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3035 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3038 vec_reset_length (routes);
3040 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++)
3042 uword *hash = fib->adj_index_by_dst_address[i];
3046 x.address_length = i;
3049 hash_foreach_pair (p, hash,
3051 x.address.data_u32 = p->key;
3052 vec_add1 (routes, x);
3057 vec_foreach (r, routes)
3059 ip4_add_del_route_args_t a;
3061 memset (&a, 0, sizeof (a));
3062 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
3063 a.table_index_or_table_id = fib - im4->fibs;
3064 a.dst_address = r->address;
3065 a.dst_address_length = r->address_length;
3068 ip4_add_del_route (im4, &a);
3069 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
3070 IP4_ROUTE_FLAG_FIB_INDEX);
3074 } /* vec_foreach (fib) */
3082 ip6_address_t address;
3090 ip6_route_t **routep;
3091 } add_routes_in_fib_arg_t;
3094 add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
3096 add_routes_in_fib_arg_t *ap = arg;
3098 if (kvp->key[2] >> 32 == ap->fib_index)
3100 ip6_address_t *addr;
3102 addr = (ip6_address_t *) kvp;
3103 vec_add2 (*ap->routep, r, 1);
3104 r->address = addr[0];
3105 r->address_length = kvp->key[2] & 0xFF;
3106 r->index = kvp->value;
3111 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3113 vnet_main_t *vnm = vnet_get_main ();
3114 vnet_interface_main_t *im = &vnm->interface_main;
3115 ip6_main_t *im6 = &ip6_main;
3116 stats_main_t *sm = &stats_main;
3117 static ip6_route_t *routes;
3118 static u32 *sw_if_indices_to_shut;
3123 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3124 u32 target_fib_id = ntohl (mp->vrf_id);
3125 add_routes_in_fib_arg_t _a, *a = &_a;
3126 clib_bihash_24_8_t *h = &im6->ip6_lookup_table;
3128 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3130 vec_foreach (fib, im6->fibs)
3132 vnet_sw_interface_t *si;
3134 if (fib->table_id != target_fib_id)
3137 vec_reset_length (sw_if_indices_to_shut);
3139 /* Shut down interfaces in this FIB / clean out intfc routes */
3141 pool_foreach (si, im->sw_interfaces,
3143 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3145 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3149 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3151 sw_if_index = sw_if_indices_to_shut[i];
3152 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3154 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3155 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3156 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3159 vec_reset_length (routes);
3161 a->fib_index = fib - im6->fibs;
3162 a->routep = &routes;
3164 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
3166 vec_foreach (r, routes)
3168 ip6_add_del_route_args_t a;
3170 memset (&a, 0, sizeof (a));
3171 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
3172 a.table_index_or_table_id = fib - im6->fibs;
3173 a.dst_address = r->address;
3174 a.dst_address_length = r->address_length;
3177 ip6_add_del_route (im6, &a);
3178 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
3179 IP6_ROUTE_FLAG_FIB_INDEX);
3182 /* Reinstall the neighbor / router discovery routes */
3183 vnet_ip6_fib_init (im6, fib - im6->fibs);
3185 } /* vec_foreach (fib) */
3192 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3195 vl_api_reset_fib_reply_t *rmp;
3198 rv = ip6_reset_fib_t_handler (mp);
3200 rv = ip4_reset_fib_t_handler (mp);
3202 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3207 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3209 vl_api_dhcp_proxy_config_reply_t *rmp;
3212 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3213 (ip4_address_t *) (&mp->dhcp_src_address),
3214 (u32) ntohl (mp->vrf_id),
3215 (int) mp->insert_circuit_id,
3216 (int) (mp->is_add == 0));
3218 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3223 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3225 vl_api_dhcp_proxy_config_reply_t *rmp;
3228 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3229 (ip6_address_t *) (&mp->dhcp_src_address),
3230 (u32) ntohl (mp->vrf_id),
3231 (int) mp->insert_circuit_id,
3232 (int) (mp->is_add == 0));
3234 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3238 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3240 vl_api_dhcp_proxy_config_reply_t *rmp;
3243 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3244 (ip4_address_t *) (&mp->dhcp_src_address),
3245 (u32) ntohl (mp->rx_vrf_id),
3246 (u32) ntohl (mp->server_vrf_id),
3247 (int) mp->insert_circuit_id,
3248 (int) (mp->is_add == 0));
3250 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3255 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3257 vl_api_dhcp_proxy_config_reply_t *rmp;
3261 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3262 (ip6_address_t *) (&mp->dhcp_src_address),
3263 (u32) ntohl (mp->rx_vrf_id),
3264 (u32) ntohl (mp->server_vrf_id),
3265 (int) mp->insert_circuit_id,
3266 (int) (mp->is_add == 0));
3268 rv = VNET_API_ERROR_UNIMPLEMENTED;
3271 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3276 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3278 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3281 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3284 (int) mp->is_add == 0);
3286 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3288 ntohl (mp->fib_id), (int) mp->is_add == 0);
3290 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3294 static void vl_api_dhcp_proxy_config_t_handler
3295 (vl_api_dhcp_proxy_config_t * mp)
3297 if (mp->is_ipv6 == 0)
3298 dhcpv4_proxy_config (mp);
3300 dhcpv6_proxy_config (mp);
3303 static void vl_api_dhcp_proxy_config_2_t_handler
3304 (vl_api_dhcp_proxy_config_2_t * mp)
3306 if (mp->is_ipv6 == 0)
3307 dhcpv4_proxy_config_2 (mp);
3309 dhcpv6_proxy_config_2 (mp);
3313 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3314 u8 is_ipv6, u8 * host_address, u8 * router_address,
3317 unix_shared_memory_queue_t *q;
3318 vl_api_dhcp_compl_event_t *mp;
3320 q = vl_api_client_index_to_input_queue (client_index);
3324 mp = vl_msg_api_alloc (sizeof (*mp));
3325 mp->client_index = client_index;
3327 mp->is_ipv6 = is_ipv6;
3328 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3329 mp->hostname[vec_len (hostname) + 1] = '\n';
3330 clib_memcpy (&mp->host_address[0], host_address, 16);
3331 clib_memcpy (&mp->router_address[0], router_address, 16);
3332 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3334 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3336 vl_msg_api_send_shmem (q, (u8 *) & mp);
3339 static void vl_api_dhcp_client_config_t_handler
3340 (vl_api_dhcp_client_config_t * mp)
3342 vlib_main_t *vm = vlib_get_main ();
3343 vl_api_dhcp_client_config_reply_t *rmp;
3346 VALIDATE_SW_IF_INDEX (mp);
3348 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3349 mp->hostname, mp->is_add, mp->client_index,
3350 mp->want_dhcp_event ? dhcp_compl_event_callback :
3353 BAD_SW_IF_INDEX_LABEL;
3355 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3359 vl_api_sw_interface_ip6nd_ra_config_t_handler
3360 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3362 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3364 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3367 is_no = mp->is_no == 1;
3368 suppress = mp->suppress == 1;
3369 managed = mp->managed == 1;
3370 other = mp->other == 1;
3371 ll_option = mp->ll_option == 1;
3372 send_unicast = mp->send_unicast == 1;
3373 cease = mp->cease == 1;
3374 default_router = mp->default_router == 1;
3376 VALIDATE_SW_IF_INDEX (mp);
3378 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3379 suppress, managed, other,
3380 ll_option, send_unicast, cease,
3381 default_router, ntohl (mp->lifetime),
3382 ntohl (mp->initial_count),
3383 ntohl (mp->initial_interval),
3384 ntohl (mp->max_interval),
3385 ntohl (mp->min_interval), is_no);
3387 BAD_SW_IF_INDEX_LABEL;
3389 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3393 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3394 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3396 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3398 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3400 VALIDATE_SW_IF_INDEX (mp);
3402 is_no = mp->is_no == 1;
3403 use_default = mp->use_default == 1;
3404 no_advertise = mp->no_advertise == 1;
3405 off_link = mp->off_link == 1;
3406 no_autoconfig = mp->no_autoconfig == 1;
3407 no_onlink = mp->no_onlink == 1;
3409 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3410 (ip6_address_t *) mp->address,
3411 mp->address_length, use_default,
3412 ntohl (mp->val_lifetime),
3413 ntohl (mp->pref_lifetime), no_advertise,
3414 off_link, no_autoconfig, no_onlink, is_no);
3416 BAD_SW_IF_INDEX_LABEL;
3417 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3421 vl_api_sw_interface_ip6_enable_disable_t_handler
3422 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3424 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3425 vnet_main_t *vnm = vnet_get_main ();
3427 clib_error_t *error;
3431 VALIDATE_SW_IF_INDEX (mp);
3434 (mp->enable == 1) ? enable_ip6_interface (vm,
3435 ntohl (mp->sw_if_index)) :
3436 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3440 clib_error_report (error);
3441 rv = VNET_API_ERROR_UNSPECIFIED;
3445 rv = vnm->api_errno;
3448 BAD_SW_IF_INDEX_LABEL;
3450 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3454 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3455 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3457 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3459 clib_error_t *error;
3460 vnet_main_t *vnm = vnet_get_main ();
3464 VALIDATE_SW_IF_INDEX (mp);
3466 error = set_ip6_link_local_address (vm,
3467 ntohl (mp->sw_if_index),
3468 (ip6_address_t *) mp->address,
3469 mp->address_length);
3472 clib_error_report (error);
3473 rv = VNET_API_ERROR_UNSPECIFIED;
3477 rv = vnm->api_errno;
3480 BAD_SW_IF_INDEX_LABEL;
3482 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3486 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3488 vl_api_set_ip_flow_hash_reply_t *rmp;
3489 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3491 clib_warning ("unimplemented...");
3493 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3497 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3499 vl_api_set_ip_flow_hash_reply_t *rmp;
3502 u32 flow_hash_config = 0;
3504 table_id = ntohl (mp->vrf_id);
3506 #define _(a,b) if (mp->a) flow_hash_config |= b;
3507 foreach_flow_hash_bit;
3510 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3512 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3517 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3519 if (mp->is_ipv6 == 0)
3520 set_ip4_flow_hash (mp);
3522 set_ip6_flow_hash (mp);
3525 static void vl_api_sw_interface_set_unnumbered_t_handler
3526 (vl_api_sw_interface_set_unnumbered_t * mp)
3528 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3530 vnet_sw_interface_t *si;
3531 vnet_main_t *vnm = vnet_get_main ();
3532 u32 sw_if_index, unnumbered_sw_if_index;
3534 sw_if_index = ntohl (mp->sw_if_index);
3535 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3538 * The API message field names are backwards from
3539 * the underlying data structure names.
3540 * It's not worth changing them now.
3542 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3543 unnumbered_sw_if_index))
3545 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3549 /* Only check the "use loop0" field when setting the binding */
3551 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3553 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3557 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3561 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3562 si->unnumbered_sw_if_index = sw_if_index;
3566 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3567 si->unnumbered_sw_if_index = (u32) ~ 0;
3571 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3575 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3577 vl_api_create_loopback_reply_t *rmp;
3581 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3584 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3586 rmp->sw_if_index = ntohl (sw_if_index);
3592 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3594 vl_api_delete_loopback_reply_t *rmp;
3598 sw_if_index = ntohl (mp->sw_if_index);
3599 rv = vnet_delete_loopback_interface (sw_if_index);
3601 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3605 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3607 vl_api_control_ping_reply_t *rmp;
3611 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3613 rmp->vpe_pid = ntohl (getpid());
3618 static void vl_api_noprint_control_ping_t_handler
3619 (vl_api_noprint_control_ping_t * mp)
3621 vl_api_noprint_control_ping_reply_t *rmp;
3625 REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY,
3627 rmp->vpe_pid = ntohl (getpid());
3633 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3635 u8 **shmem_vecp = (u8 **) arg;
3638 api_main_t *am = &api_main;
3641 shmem_vec = *shmem_vecp;
3643 offset = vec_len (shmem_vec);
3645 pthread_mutex_lock (&am->vlib_rp->mutex);
3646 oldheap = svm_push_data_heap (am->vlib_rp);
3648 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3650 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3652 svm_pop_heap (oldheap);
3653 pthread_mutex_unlock (&am->vlib_rp->mutex);
3655 *shmem_vecp = shmem_vec;
3660 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3662 vl_api_cli_reply_t *rp;
3663 unix_shared_memory_queue_t *q;
3664 vlib_main_t *vm = vlib_get_main ();
3665 api_main_t *am = &api_main;
3666 unformat_input_t input;
3670 q = vl_api_client_index_to_input_queue (mp->client_index);
3674 rp = vl_msg_api_alloc (sizeof (*rp));
3675 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3676 rp->context = mp->context;
3678 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3680 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3682 pthread_mutex_lock (&am->vlib_rp->mutex);
3683 oldheap = svm_push_data_heap (am->vlib_rp);
3685 vec_add1 (shmem_vec, 0);
3687 svm_pop_heap (oldheap);
3688 pthread_mutex_unlock (&am->vlib_rp->mutex);
3690 rp->reply_in_shmem = (uword) shmem_vec;
3692 vl_msg_api_send_shmem (q, (u8 *) & rp);
3696 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3699 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3700 vnet_main_t *vnm = vnet_get_main ();
3701 clib_error_t *error;
3706 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3708 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3712 clib_error_report (error);
3713 rv = VNET_API_ERROR_UNSPECIFIED;
3717 rv = vnm->api_errno;
3720 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3723 static void vl_api_sr_tunnel_add_del_t_handler
3724 (vl_api_sr_tunnel_add_del_t * mp)
3727 clib_warning ("unimplemented");
3729 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3731 vl_api_sr_tunnel_add_del_reply_t *rmp;
3732 ip6_address_t *segments = 0, *seg;
3733 ip6_address_t *tags = 0, *tag;
3734 ip6_address_t *this_address;
3737 if (mp->n_segments == 0)
3743 memset (a, 0, sizeof (*a));
3744 a->src_address = (ip6_address_t *) & mp->src_address;
3745 a->dst_address = (ip6_address_t *) & mp->dst_address;
3746 a->dst_mask_width = mp->dst_mask_width;
3747 a->flags_net_byte_order = mp->flags_net_byte_order;
3748 a->is_del = (mp->is_add == 0);
3749 a->rx_table_id = ntohl (mp->outer_vrf_id);
3750 a->tx_table_id = ntohl (mp->inner_vrf_id);
3752 a->name = format (0, "%s", mp->name);
3753 if (!(vec_len (a->name)))
3756 a->policy_name = format (0, "%s", mp->policy_name);
3757 if (!(vec_len (a->policy_name)))
3760 /* Yank segments and tags out of the API message */
3761 this_address = (ip6_address_t *) mp->segs_and_tags;
3762 for (i = 0; i < mp->n_segments; i++)
3764 vec_add2 (segments, seg, 1);
3765 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3768 for (i = 0; i < mp->n_tags; i++)
3770 vec_add2 (tags, tag, 1);
3771 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3775 a->segments = segments;
3778 rv = ip6_sr_add_del_tunnel (a);
3782 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3786 static void vl_api_sr_policy_add_del_t_handler
3787 (vl_api_sr_policy_add_del_t * mp)
3790 clib_warning ("unimplemented");
3792 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3794 vl_api_sr_policy_add_del_reply_t *rmp;
3797 memset (a, 0, sizeof (*a));
3798 a->is_del = (mp->is_add == 0);
3800 a->name = format (0, "%s", mp->name);
3801 if (!(vec_len (a->name)))
3803 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3807 if (!(mp->tunnel_names[0]))
3809 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3813 // start deserializing tunnel_names
3814 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3815 u8 *deser_tun_names = mp->tunnel_names;
3816 deser_tun_names += 1; //moving along
3819 int tun_name_len = 0;
3821 for (i = 0; i < num_tunnels; i++)
3823 tun_name_len = *deser_tun_names;
3824 deser_tun_names += 1;
3825 vec_resize (tun_name, tun_name_len);
3826 memcpy (tun_name, deser_tun_names, tun_name_len);
3827 vec_add1 (a->tunnel_names, tun_name);
3828 deser_tun_names += tun_name_len;
3832 rv = ip6_sr_add_del_policy (a);
3836 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3840 static void vl_api_sr_multicast_map_add_del_t_handler
3841 (vl_api_sr_multicast_map_add_del_t * mp)
3844 clib_warning ("unimplemented");
3846 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3848 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3850 memset (a, 0, sizeof (*a));
3851 a->is_del = (mp->is_add == 0);
3853 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3854 a->policy_name = format (0, "%s", mp->policy_name);
3856 if (a->multicast_address == 0)
3862 if (!(a->policy_name))
3868 #if DPDK > 0 /* Cannot call replicate without DPDK */
3869 rv = ip6_sr_add_del_multicastmap (a);
3871 clib_warning ("multicast replication without DPDK not implemented");
3872 rv = VNET_API_ERROR_UNIMPLEMENTED;
3877 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3881 #define foreach_classify_add_del_table_field \
3886 _(match_n_vectors) \
3887 _(next_table_index) \
3890 static void vl_api_classify_add_del_table_t_handler
3891 (vl_api_classify_add_del_table_t * mp)
3893 vl_api_classify_add_del_table_reply_t *rmp;
3894 vnet_classify_main_t *cm = &vnet_classify_main;
3895 vnet_classify_table_t *t;
3899 foreach_classify_add_del_table_field;
3902 #define _(a) a = ntohl(mp->a);
3903 foreach_classify_add_del_table_field;
3906 /* The underlying API fails silently, on purpose, so check here */
3907 if (mp->is_add == 0)
3908 if (pool_is_free_index (cm->tables, table_index))
3910 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3914 rv = vnet_classify_add_del_table
3915 (cm, mp->mask, nbuckets, memory_size,
3916 skip_n_vectors, match_n_vectors,
3917 next_table_index, miss_next_index, &table_index, mp->is_add);
3921 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3923 if (rv == 0 && mp->is_add)
3925 t = pool_elt_at_index (cm->tables, table_index);
3926 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3927 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3928 rmp->new_table_index = ntohl(table_index);
3932 rmp->skip_n_vectors = ~0;
3933 rmp->match_n_vectors = ~0;
3934 rmp->new_table_index = ~0;
3940 static void vl_api_classify_add_del_session_t_handler
3941 (vl_api_classify_add_del_session_t * mp)
3943 vnet_classify_main_t *cm = &vnet_classify_main;
3944 vl_api_classify_add_del_session_reply_t *rmp;
3946 u32 table_index, hit_next_index, opaque_index;
3949 table_index = ntohl (mp->table_index);
3950 hit_next_index = ntohl (mp->hit_next_index);
3951 opaque_index = ntohl (mp->opaque_index);
3952 advance = ntohl (mp->advance);
3954 rv = vnet_classify_add_del_session
3955 (cm, table_index, mp->match, hit_next_index, opaque_index,
3956 advance, mp->is_add);
3958 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3961 static void vl_api_classify_set_interface_ip_table_t_handler
3962 (vl_api_classify_set_interface_ip_table_t * mp)
3964 vlib_main_t *vm = vlib_get_main ();
3965 vl_api_classify_set_interface_ip_table_reply_t *rmp;
3967 u32 table_index, sw_if_index;
3969 table_index = ntohl (mp->table_index);
3970 sw_if_index = ntohl (mp->sw_if_index);
3972 VALIDATE_SW_IF_INDEX (mp);
3975 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3977 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3979 BAD_SW_IF_INDEX_LABEL;
3981 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3984 static void vl_api_classify_set_interface_l2_tables_t_handler
3985 (vl_api_classify_set_interface_l2_tables_t * mp)
3987 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
3989 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3992 ip4_table_index = ntohl (mp->ip4_table_index);
3993 ip6_table_index = ntohl (mp->ip6_table_index);
3994 other_table_index = ntohl (mp->other_table_index);
3995 sw_if_index = ntohl (mp->sw_if_index);
3997 VALIDATE_SW_IF_INDEX (mp);
4000 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
4004 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
4010 if (ip4_table_index != ~0 || ip6_table_index != ~0
4011 || other_table_index != ~0)
4017 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
4019 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
4022 BAD_SW_IF_INDEX_LABEL;
4024 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
4028 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
4031 vl_api_l2_fib_clear_table_reply_t *rmp;
4033 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
4034 * that is not currently implemented. When that TODO is fixed
4035 * this call should be changed to pass 1 instead of 0.
4037 l2fib_clear_table (0);
4039 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
4042 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
4043 u32 sw_if_index, u32 enable);
4046 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
4050 vl_api_l2_interface_efp_filter_reply_t *rmp;
4051 vnet_main_t *vnm = vnet_get_main ();
4053 // enable/disable the feature
4054 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
4055 rv = vnm->api_errno;
4057 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
4061 vl_api_l2_interface_vlan_tag_rewrite_t_handler
4062 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
4065 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
4066 vnet_main_t *vnm = vnet_get_main ();
4067 vlib_main_t *vm = vlib_get_main ();
4070 VALIDATE_SW_IF_INDEX (mp);
4072 vtr_op = ntohl (mp->vtr_op);
4074 /* The L2 code is unsuspicious */
4077 case L2_VTR_DISABLED:
4082 case L2_VTR_TRANSLATE_1_1:
4083 case L2_VTR_TRANSLATE_1_2:
4084 case L2_VTR_TRANSLATE_2_1:
4085 case L2_VTR_TRANSLATE_2_2:
4089 rv = VNET_API_ERROR_INVALID_VALUE;
4090 goto bad_sw_if_index;
4093 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4094 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4097 BAD_SW_IF_INDEX_LABEL;
4099 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4103 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4106 vl_api_create_vhost_user_if_reply_t *rmp;
4107 u32 sw_if_index = (u32) ~ 0;
4109 vnet_main_t *vnm = vnet_get_main ();
4110 vlib_main_t *vm = vlib_get_main ();
4112 #if DPDK > 0 && DPDK_VHOST_USER
4113 rv = dpdk_vhost_user_create_if (
4115 rv = vhost_user_create_if (
4117 vnm, vm, (char *) mp->sock_filename,
4118 mp->is_server, &sw_if_index, (u64) ~ 0,
4119 mp->renumber, ntohl (mp->custom_dev_instance),
4120 (mp->use_custom_mac) ? mp->mac_address : NULL);
4123 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4125 rmp->sw_if_index = ntohl (sw_if_index);
4131 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4134 vl_api_modify_vhost_user_if_reply_t *rmp;
4135 u32 sw_if_index = ntohl (mp->sw_if_index);
4137 vnet_main_t *vnm = vnet_get_main ();
4138 vlib_main_t *vm = vlib_get_main ();
4140 #if DPDK > 0 && DPDK_VHOST_USER
4141 rv = dpdk_vhost_user_modify_if (
4143 rv = vhost_user_modify_if (
4145 vnm, vm, (char *) mp->sock_filename,
4146 mp->is_server, sw_if_index, (u64) ~ 0,
4147 mp->renumber, ntohl (mp->custom_dev_instance));
4148 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4152 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4155 vl_api_delete_vhost_user_if_reply_t *rmp;
4156 vpe_api_main_t *vam = &vpe_api_main;
4157 u32 sw_if_index = ntohl (mp->sw_if_index);
4159 vnet_main_t *vnm = vnet_get_main ();
4160 vlib_main_t *vm = vlib_get_main ();
4162 #if DPDK > 0 && DPDK_VHOST_USER
4163 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4165 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4168 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4171 unix_shared_memory_queue_t *q =
4172 vl_api_client_index_to_input_queue (mp->client_index);
4176 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4181 vl_api_sw_interface_vhost_user_details_t_handler
4182 (vl_api_sw_interface_vhost_user_details_t * mp)
4184 clib_warning ("BUG");
4188 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4189 unix_shared_memory_queue_t * q,
4190 vhost_user_intf_details_t * vui,
4193 vl_api_sw_interface_vhost_user_details_t *mp;
4195 mp = vl_msg_api_alloc (sizeof (*mp));
4196 memset (mp, 0, sizeof (*mp));
4197 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4198 mp->sw_if_index = ntohl (vui->sw_if_index);
4199 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4200 mp->features = clib_net_to_host_u64 (vui->features);
4201 mp->is_server = vui->is_server;
4202 mp->num_regions = ntohl (vui->num_regions);
4203 mp->sock_errno = ntohl (vui->sock_errno);
4204 mp->context = context;
4206 strncpy ((char *) mp->sock_filename,
4207 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4208 strncpy ((char *) mp->interface_name,
4209 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4211 vl_msg_api_send_shmem (q, (u8 *) & mp);
4215 vl_api_sw_interface_vhost_user_dump_t_handler
4216 (vl_api_sw_interface_vhost_user_dump_t * mp)
4219 vpe_api_main_t *am = &vpe_api_main;
4220 vnet_main_t *vnm = vnet_get_main ();
4221 vlib_main_t *vm = vlib_get_main ();
4222 vhost_user_intf_details_t *ifaces = NULL;
4223 vhost_user_intf_details_t *vuid = NULL;
4224 unix_shared_memory_queue_t *q;
4226 q = vl_api_client_index_to_input_queue (mp->client_index);
4230 #if DPDK > 0 && DPDK_VHOST_USER
4231 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4233 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4238 vec_foreach (vuid, ifaces)
4240 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4246 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4247 unix_shared_memory_queue_t * q,
4249 l2t_main_t * lm, u32 context)
4251 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4253 vnet_sw_interface_t *si = NULL;
4255 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4257 if_name = format (if_name, "%U",
4258 format_vnet_sw_interface_name, lm->vnet_main, si);
4260 mp = vl_msg_api_alloc (sizeof (*mp));
4261 memset (mp, 0, sizeof (*mp));
4262 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4263 strncpy ((char *) mp->interface_name,
4264 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4265 mp->sw_if_index = ntohl (si->sw_if_index);
4266 mp->local_session_id = s->local_session_id;
4267 mp->remote_session_id = s->remote_session_id;
4268 mp->local_cookie[0] = s->local_cookie[0];
4269 mp->local_cookie[1] = s->local_cookie[1];
4270 mp->remote_cookie = s->remote_cookie;
4271 clib_memcpy (mp->client_address, &s->client_address,
4272 sizeof (s->client_address));
4273 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4274 mp->l2_sublayer_present = s->l2_sublayer_present;
4275 mp->context = context;
4277 vl_msg_api_send_shmem (q, (u8 *) & mp);
4281 send_ip_address_details (vpe_api_main_t * am,
4282 unix_shared_memory_queue_t * q,
4283 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4285 vl_api_ip_address_details_t *mp;
4287 mp = vl_msg_api_alloc (sizeof (*mp));
4288 memset (mp, 0, sizeof (*mp));
4289 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4293 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4297 u32 *tp = (u32 *) mp->ip;
4298 *tp = ntohl (*(u32 *) ip);
4300 mp->prefix_length = prefix_length;
4301 mp->context = context;
4303 vl_msg_api_send_shmem (q, (u8 *) & mp);
4307 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4309 vpe_api_main_t *am = &vpe_api_main;
4310 unix_shared_memory_queue_t *q;
4313 ip6_main_t *im6 = &ip6_main;
4314 ip4_main_t *im4 = &ip4_main;
4315 ip_lookup_main_t *lm6 = &im6->lookup_main;
4316 ip_lookup_main_t *lm4 = &im4->lookup_main;
4317 ip_interface_address_t *ia = 0;
4318 u32 sw_if_index = ~0;
4319 int rv __attribute__ ((unused)) = 0;
4321 VALIDATE_SW_IF_INDEX (mp);
4323 sw_if_index = ntohl (mp->sw_if_index);
4325 q = vl_api_client_index_to_input_queue (mp->client_index);
4334 foreach_ip_interface_address (lm6, ia, sw_if_index,
4335 1 /* honor unnumbered */,
4337 r6 = ip_interface_address_get_address (lm6, ia);
4338 u16 prefix_length = ia->address_length;
4339 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4346 foreach_ip_interface_address (lm4, ia, sw_if_index,
4347 1 /* honor unnumbered */,
4349 r4 = ip_interface_address_get_address (lm4, ia);
4350 u16 prefix_length = ia->address_length;
4351 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4355 BAD_SW_IF_INDEX_LABEL;
4359 send_ip_details (vpe_api_main_t * am,
4360 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4362 vl_api_ip_details_t *mp;
4364 mp = vl_msg_api_alloc (sizeof (*mp));
4365 memset (mp, 0, sizeof (*mp));
4366 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4368 mp->sw_if_index = ntohl (sw_if_index);
4369 mp->context = context;
4371 vl_msg_api_send_shmem (q, (u8 *) & mp);
4375 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4378 vpe_api_main_t *am = &vpe_api_main;
4379 l2t_main_t *lm = &l2t_main;
4380 unix_shared_memory_queue_t *q;
4381 l2t_session_t *session;
4383 q = vl_api_client_index_to_input_queue (mp->client_index);
4388 pool_foreach (session, lm->sessions,
4390 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4397 send_sw_interface_tap_details (vpe_api_main_t * am,
4398 unix_shared_memory_queue_t * q,
4399 tapcli_interface_details_t * tap_if,
4402 vl_api_sw_interface_tap_details_t *mp;
4403 mp = vl_msg_api_alloc (sizeof (*mp));
4404 memset (mp, 0, sizeof (*mp));
4405 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4406 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4407 strncpy ((char *) mp->dev_name,
4408 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4409 mp->context = context;
4411 vl_msg_api_send_shmem (q, (u8 *) & mp);
4415 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4418 vpe_api_main_t *am = &vpe_api_main;
4419 unix_shared_memory_queue_t *q;
4420 tapcli_interface_details_t *tapifs = NULL;
4421 tapcli_interface_details_t *tap_if = NULL;
4423 q = vl_api_client_index_to_input_queue (mp->client_index);
4427 rv = vnet_tap_dump_ifs (&tapifs);
4431 vec_foreach (tap_if, tapifs)
4433 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4440 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4442 vpe_api_main_t *am = &vpe_api_main;
4443 vnet_main_t *vnm = vnet_get_main ();
4444 vlib_main_t *vm = vlib_get_main ();
4445 vnet_interface_main_t *im = &vnm->interface_main;
4446 unix_shared_memory_queue_t *q;
4447 vnet_sw_interface_t *si, *sorted_sis;
4448 u32 sw_if_index = ~0;
4450 q = vl_api_client_index_to_input_queue (mp->client_index);
4456 /* Gather interfaces. */
4457 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4458 _vec_len (sorted_sis) = 0;
4460 pool_foreach (si, im->sw_interfaces,
4462 vec_add1 (sorted_sis, si[0]);
4466 vec_foreach (si, sorted_sis)
4468 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4470 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4474 sw_if_index = si->sw_if_index;
4475 send_ip_details (am, q, sw_if_index, mp->context);
4481 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4483 clib_warning ("BUG");
4487 send_l2fib_table_entry (vpe_api_main_t * am,
4488 unix_shared_memory_queue_t * q,
4489 l2fib_entry_key_t * l2fe_key,
4490 l2fib_entry_result_t * l2fe_res, u32 context)
4492 vl_api_l2_fib_table_entry_t *mp;
4494 mp = vl_msg_api_alloc (sizeof (*mp));
4495 memset (mp, 0, sizeof (*mp));
4496 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4499 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4501 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4502 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4503 mp->static_mac = l2fe_res->fields.static_mac;
4504 mp->filter_mac = l2fe_res->fields.filter;
4505 mp->bvi_mac = l2fe_res->fields.bvi;
4506 mp->context = context;
4508 vl_msg_api_send_shmem (q, (u8 *) & mp);
4512 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4514 vpe_api_main_t *am = &vpe_api_main;
4515 bd_main_t *bdm = &bd_main;
4516 l2fib_entry_key_t *l2fe_key = NULL;
4517 l2fib_entry_result_t *l2fe_res = NULL;
4518 u32 ni, bd_id = ntohl (mp->bd_id);
4520 unix_shared_memory_queue_t *q;
4523 q = vl_api_client_index_to_input_queue (mp->client_index);
4527 /* see l2fib_table_dump: ~0 means "any" */
4532 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4539 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4541 vec_foreach_index (ni, l2fe_key)
4543 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4544 vec_elt_at_index (l2fe_res, ni), mp->context);
4546 vec_free (l2fe_key);
4547 vec_free (l2fe_res);
4551 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4553 vl_api_show_version_reply_t *rmp;
4555 char *vpe_api_get_build_directory (void);
4556 char *vpe_api_get_version (void);
4557 char *vpe_api_get_build_date (void);
4559 unix_shared_memory_queue_t *q =
4560 vl_api_client_index_to_input_queue (mp->client_index);
4566 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4568 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4569 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4570 ARRAY_LEN(rmp->build_directory)-1);
4571 strncpy ((char *) rmp->version, vpe_api_get_version(),
4572 ARRAY_LEN(rmp->version)-1);
4573 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4574 ARRAY_LEN(rmp->build_date)-1);
4580 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4582 vlib_main_t *vm = vlib_get_main ();
4583 vl_api_get_node_index_reply_t *rmp;
4586 u32 node_index = ~0;
4588 n = vlib_get_node_by_name (vm, mp->node_name);
4591 rv = VNET_API_ERROR_NO_SUCH_NODE;
4593 node_index = n->index;
4596 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4598 rmp->node_index = ntohl(node_index);
4604 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4606 vlib_main_t *vm = vlib_get_main ();
4607 vl_api_get_next_index_reply_t *rmp;
4608 vlib_node_t *node, *next_node;
4610 u32 next_node_index = ~0, next_index = ~0;
4613 node = vlib_get_node_by_name (vm, mp->node_name);
4617 rv = VNET_API_ERROR_NO_SUCH_NODE;
4621 next_node = vlib_get_node_by_name (vm, mp->next_name);
4625 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4629 next_node_index = next_node->index;
4631 p = hash_get (node->next_slot_by_node, next_node_index);
4635 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4643 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4645 rmp->next_index = ntohl(next_index);
4651 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4653 vlib_main_t *vm = vlib_get_main ();
4654 vl_api_add_node_next_reply_t *rmp;
4655 vlib_node_t *n, *next;
4657 u32 next_index = ~0;
4659 n = vlib_get_node_by_name (vm, mp->node_name);
4663 rv = VNET_API_ERROR_NO_SUCH_NODE;
4667 next = vlib_get_node_by_name (vm, mp->next_name);
4670 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4672 next_index = vlib_node_add_next (vm, n->index, next->index);
4676 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4678 rmp->next_index = ntohl(next_index);
4683 static void vl_api_l2tpv3_create_tunnel_t_handler
4684 (vl_api_l2tpv3_create_tunnel_t * mp)
4686 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4687 l2t_main_t *lm = &l2t_main;
4688 u32 sw_if_index = (u32) ~ 0;
4691 if (mp->is_ipv6 != 1)
4693 rv = VNET_API_ERROR_UNIMPLEMENTED;
4697 u32 encap_fib_index;
4699 if (mp->encap_vrf_id != ~0)
4702 ip6_main_t *im = &ip6_main;
4705 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4707 rv = VNET_API_ERROR_NO_SUCH_FIB;
4710 encap_fib_index = p[0];
4714 encap_fib_index = ~0;
4717 rv = create_l2tpv3_ipv6_tunnel (lm,
4718 (ip6_address_t *) mp->client_address,
4719 (ip6_address_t *) mp->our_address,
4720 ntohl (mp->local_session_id),
4721 ntohl (mp->remote_session_id),
4722 clib_net_to_host_u64 (mp->local_cookie),
4723 clib_net_to_host_u64 (mp->remote_cookie),
4724 mp->l2_sublayer_present,
4725 encap_fib_index, &sw_if_index);
4729 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4731 rmp->sw_if_index = ntohl (sw_if_index);
4736 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4737 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4739 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4740 l2t_main_t *lm = &l2t_main;
4743 VALIDATE_SW_IF_INDEX (mp);
4745 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4746 clib_net_to_host_u64 (mp->new_local_cookie),
4747 clib_net_to_host_u64
4748 (mp->new_remote_cookie));
4750 BAD_SW_IF_INDEX_LABEL;
4752 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4755 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4756 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4759 vnet_main_t *vnm = vnet_get_main ();
4760 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4762 VALIDATE_SW_IF_INDEX (mp);
4764 rv = l2tpv3_interface_enable_disable
4765 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4767 BAD_SW_IF_INDEX_LABEL;
4769 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4772 static void vl_api_l2tpv3_set_lookup_key_t_handler
4773 (vl_api_l2tpv3_set_lookup_key_t * mp)
4776 l2t_main_t *lm = &l2t_main;
4777 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4779 if (mp->key > L2T_LOOKUP_SESSION_ID)
4781 rv = VNET_API_ERROR_INVALID_VALUE;
4785 lm->lookup_type = mp->key;
4788 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4791 static void vl_api_vxlan_add_del_tunnel_t_handler
4792 (vl_api_vxlan_add_del_tunnel_t * mp)
4794 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4796 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4797 u32 encap_fib_index;
4799 ip4_main_t *im = &ip4_main;
4800 u32 sw_if_index = ~0;
4802 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4805 rv = VNET_API_ERROR_NO_SUCH_FIB;
4808 encap_fib_index = p[0];
4810 /* Check src & dst are different */
4811 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4812 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4814 rv = VNET_API_ERROR_SAME_SRC_DST;
4817 memset (a, 0, sizeof (*a));
4819 a->is_add = mp->is_add;
4820 a->is_ip6 = mp->is_ipv6;
4822 /* ip addresses sent in network byte order */
4825 memcpy (&(a->src.ip6), mp->src_address, 16);
4826 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4830 memcpy (&(a->src.ip4), mp->src_address, 4);
4831 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4834 a->encap_fib_index = encap_fib_index;
4835 a->decap_next_index = ntohl (mp->decap_next_index);
4836 a->vni = ntohl (mp->vni);
4837 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4841 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4843 rmp->sw_if_index = ntohl (sw_if_index);
4848 static void send_vxlan_tunnel_details
4849 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4851 vl_api_vxlan_tunnel_details_t *rmp;
4852 ip4_main_t *im4 = &ip4_main;
4853 ip6_main_t *im6 = &ip6_main;
4854 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4856 rmp = vl_msg_api_alloc (sizeof (*rmp));
4857 memset (rmp, 0, sizeof (*rmp));
4858 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4861 memcpy (rmp->src_address, &(t->src.ip6), 16);
4862 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4863 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
4867 memcpy (rmp->src_address, &(t->src.ip4), 4);
4868 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4869 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
4871 rmp->vni = htonl (t->vni);
4872 rmp->decap_next_index = htonl (t->decap_next_index);
4873 rmp->sw_if_index = htonl (t->sw_if_index);
4874 rmp->is_ipv6 = is_ipv6;
4875 rmp->context = context;
4877 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4880 static void vl_api_vxlan_tunnel_dump_t_handler
4881 (vl_api_vxlan_tunnel_dump_t * mp)
4883 unix_shared_memory_queue_t *q;
4884 vxlan_main_t *vxm = &vxlan_main;
4888 q = vl_api_client_index_to_input_queue (mp->client_index);
4894 sw_if_index = ntohl (mp->sw_if_index);
4896 if (~0 == sw_if_index)
4899 pool_foreach (t, vxm->tunnels,
4901 send_vxlan_tunnel_details(t, q, mp->context);
4907 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4908 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4912 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4913 send_vxlan_tunnel_details (t, q, mp->context);
4917 static void vl_api_gre_add_del_tunnel_t_handler
4918 (vl_api_gre_add_del_tunnel_t * mp)
4920 vl_api_gre_add_del_tunnel_reply_t *rmp;
4922 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4925 ip4_main_t *im = &ip4_main;
4926 u32 sw_if_index = ~0;
4928 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4931 rv = VNET_API_ERROR_NO_SUCH_FIB;
4934 outer_fib_id = p[0];
4936 /* Check src & dst are different */
4937 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4938 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4940 rv = VNET_API_ERROR_SAME_SRC_DST;
4943 memset (a, 0, sizeof (*a));
4945 a->is_add = mp->is_add;
4947 /* ip addresses sent in network byte order */
4948 clib_memcpy (&(a->src), mp->src_address, 4);
4949 clib_memcpy (&(a->dst), mp->dst_address, 4);
4951 a->outer_fib_id = outer_fib_id;
4952 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4956 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4958 rmp->sw_if_index = ntohl (sw_if_index);
4963 static void send_gre_tunnel_details
4964 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4966 vl_api_gre_tunnel_details_t *rmp;
4967 ip4_main_t *im = &ip4_main;
4969 rmp = vl_msg_api_alloc (sizeof (*rmp));
4970 memset (rmp, 0, sizeof (*rmp));
4971 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4972 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4973 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4974 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
4975 rmp->sw_if_index = htonl (t->sw_if_index);
4976 rmp->context = context;
4978 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4982 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4984 unix_shared_memory_queue_t *q;
4985 gre_main_t *gm = &gre_main;
4989 q = vl_api_client_index_to_input_queue (mp->client_index);
4995 sw_if_index = ntohl (mp->sw_if_index);
4997 if (~0 == sw_if_index)
5000 pool_foreach (t, gm->tunnels,
5002 send_gre_tunnel_details(t, q, mp->context);
5008 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
5009 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
5013 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
5014 send_gre_tunnel_details (t, q, mp->context);
5019 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
5021 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5023 vl_api_l2_patch_add_del_reply_t *rmp;
5024 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5028 VALIDATE_RX_SW_IF_INDEX (mp);
5029 VALIDATE_TX_SW_IF_INDEX (mp);
5031 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
5032 ntohl (mp->tx_sw_if_index),
5033 (int) (mp->is_add != 0));
5035 BAD_RX_SW_IF_INDEX_LABEL;
5036 BAD_TX_SW_IF_INDEX_LABEL;
5038 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
5042 vl_api_vxlan_gpe_add_del_tunnel_t_handler
5043 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
5045 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
5047 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
5048 u32 encap_fib_index, decap_fib_index;
5051 ip4_main_t *im = &ip4_main;
5052 u32 sw_if_index = ~0;
5055 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
5058 rv = VNET_API_ERROR_NO_SUCH_FIB;
5061 encap_fib_index = p[0];
5063 protocol = mp->protocol;
5065 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
5066 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
5068 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
5071 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
5074 decap_fib_index = p[0];
5078 decap_fib_index = ntohl (mp->decap_vrf_id);
5081 /* Check src & dst are different */
5082 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5083 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5085 rv = VNET_API_ERROR_SAME_SRC_DST;
5088 memset (a, 0, sizeof (*a));
5090 a->is_add = mp->is_add;
5091 a->is_ip6 = mp->is_ipv6;
5092 /* ip addresses sent in network byte order */
5095 clib_memcpy (&(a->local.ip6), mp->local, 16);
5096 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5100 clib_memcpy (&(a->local.ip4), mp->local, 4);
5101 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5103 a->encap_fib_index = encap_fib_index;
5104 a->decap_fib_index = decap_fib_index;
5105 a->protocol = protocol;
5106 a->vni = ntohl (mp->vni);
5107 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5111 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5113 rmp->sw_if_index = ntohl (sw_if_index);
5118 static void send_vxlan_gpe_tunnel_details
5119 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5121 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5122 ip4_main_t *im4 = &ip4_main;
5123 ip6_main_t *im6 = &ip6_main;
5124 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5126 rmp = vl_msg_api_alloc (sizeof (*rmp));
5127 memset (rmp, 0, sizeof (*rmp));
5128 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5131 memcpy (rmp->local, &(t->local.ip6), 16);
5132 memcpy (rmp->remote, &(t->remote.ip6), 16);
5133 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
5134 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].table_id);
5138 memcpy (rmp->local, &(t->local.ip4), 4);
5139 memcpy (rmp->remote, &(t->remote.ip4), 4);
5140 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
5141 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].table_id);
5143 rmp->vni = htonl (t->vni);
5144 rmp->protocol = t->protocol;
5145 rmp->sw_if_index = htonl (t->sw_if_index);
5146 rmp->is_ipv6 = is_ipv6;
5147 rmp->context = context;
5149 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5152 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5153 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5155 unix_shared_memory_queue_t *q;
5156 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5157 vxlan_gpe_tunnel_t *t;
5160 q = vl_api_client_index_to_input_queue (mp->client_index);
5166 sw_if_index = ntohl (mp->sw_if_index);
5168 if (~0 == sw_if_index)
5171 pool_foreach (t, vgm->tunnels,
5173 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5179 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5180 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5184 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5185 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5189 /** Used for transferring locators via VPP API */
5191 typedef CLIB_PACKED (struct {
5192 u32 sw_if_index; /**< locator sw_if_index */
5193 u8 priority; /**< locator priority */
5194 u8 weight; /**< locator weight */
5199 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5202 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5204 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5206 ls_locator_t *ls_loc;
5207 u32 ls_index = ~0, locator_num;
5208 u8 *locator_name = NULL;
5211 memset (a, 0, sizeof (a[0]));
5213 locator_name = format (0, "%s", mp->locator_set_name);
5215 a->name = locator_name;
5216 a->is_add = mp->is_add;
5218 locator_num = clib_net_to_host_u32 (mp->locator_num);
5220 memset (&locator, 0, sizeof (locator));
5221 for (i = 0; i < locator_num; i++)
5223 ls_loc = &((ls_locator_t *) mp->locators)[i];
5224 VALIDATE_SW_IF_INDEX (ls_loc);
5226 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5227 locator.priority = ls_loc->priority;
5228 locator.weight = ls_loc->weight;
5230 vec_add1 (a->locators, locator);
5233 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5235 BAD_SW_IF_INDEX_LABEL;
5237 vec_free (locator_name);
5238 vec_free (a->locators);
5241 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5243 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5249 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5251 vl_api_lisp_add_del_locator_reply_t *rmp;
5253 locator_t locator, *locators = NULL;
5254 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5256 u8 *locator_name = NULL;
5258 memset (&locator, 0, sizeof (locator));
5259 memset (a, 0, sizeof (a[0]));
5261 locator.sw_if_index = ntohl (mp->sw_if_index);
5262 locator.priority = mp->priority;
5263 locator.weight = mp->weight;
5265 vec_add1 (locators, locator);
5267 locator_name = format (0, "%s", mp->locator_set_name);
5269 a->name = locator_name;
5270 a->locators = locators;
5271 a->is_add = mp->is_add;
5274 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5276 vec_free (locators);
5277 vec_free (locator_name);
5279 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5283 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5289 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5290 gid_address_ip_set (dst, src, IP4);
5291 gid_address_ippref_len (dst) = len;
5292 ip_prefix_normalize (&gid_address_ippref (dst));
5295 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5296 gid_address_ip_set (dst, src, IP6);
5297 gid_address_ippref_len (dst) = len;
5298 ip_prefix_normalize (&gid_address_ippref (dst));
5300 case 2: /* l2 mac */
5301 gid_address_type (dst) = GID_ADDR_MAC;
5302 clib_memcpy (&gid_address_mac (dst), src, 6);
5306 return VNET_API_ERROR_INVALID_VALUE;
5309 gid_address_vni (dst) = vni;
5315 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5317 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5318 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5320 gid_address_t _eid, *eid = &_eid;
5322 u32 locator_set_index = ~0, map_index = ~0;
5323 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5325 memset (a, 0, sizeof (a[0]));
5326 memset (eid, 0, sizeof (eid[0]));
5328 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5329 mp->eid_type, mp->eid, mp->prefix_len);
5333 name = format (0, "%s", mp->locator_set_name);
5334 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5337 rv = VNET_API_ERROR_INVALID_VALUE;
5340 locator_set_index = p[0];
5342 /* XXX treat batch configuration */
5343 a->is_add = mp->is_add;
5344 gid_address_copy (&a->eid, eid);
5345 a->locator_set_index = locator_set_index;
5347 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5351 gid_address_free (&a->eid);
5353 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5357 vl_api_lisp_eid_table_add_del_map_t_handler
5358 (vl_api_lisp_eid_table_add_del_map_t * mp)
5360 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5362 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5363 clib_net_to_host_u32 (mp->dp_table),
5364 mp->is_l2, mp->is_add);
5365 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5367 /** Used for transferring locators via VPP API */
5369 typedef CLIB_PACKED (struct {
5370 u8 is_ip4; /**< is locator an IPv4 address */
5371 u8 priority; /**< locator priority */
5372 u8 weight; /**< locator weight */
5373 u8 addr[16]; /**< IPv4/IPv6 address */
5377 static locator_pair_t *
5378 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5381 locator_pair_t *pairs = 0, pair;
5384 for (i = 0; i < rloc_num; i++)
5387 r = &((rloc_t *) lcl_locs)[i];
5388 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5389 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5391 /* remote locators */
5392 r = &((rloc_t *) rmt_locs)[i];
5393 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5394 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5396 pair.priority = r->priority;
5397 pair.weight = r->weight;
5399 vec_add1 (pairs, pair);
5405 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5408 locator_t *locs = 0, loc;
5411 for (i = 0; i < rloc_num; i++)
5413 /* remote locators */
5414 r = &((rloc_t *) rmt_locs)[i];
5415 memset (&loc, 0, sizeof (loc));
5416 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5418 loc.priority = r->priority;
5419 loc.weight = r->weight;
5421 vec_add1 (locs, loc);
5427 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5428 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5430 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5431 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5432 locator_pair_t *pairs = 0;
5435 memset (a, 0, sizeof (a[0]));
5437 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5438 mp->rmt_eid, mp->rmt_len);
5439 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5440 mp->lcl_eid, mp->lcl_len);
5442 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5444 if (rv || 0 == pairs)
5447 a->is_add = mp->is_add;
5448 a->locator_pairs = pairs;
5449 a->dp_table = mp->dp_table;
5451 a->action = mp->action;
5453 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5456 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5460 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5463 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5465 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5467 memset (a, 0, sizeof (a[0]));
5469 a->is_add = mp->is_add;
5470 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5472 rv = vnet_lisp_add_del_map_resolver (a);
5474 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5478 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5481 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5483 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5485 a->is_en = mp->is_en;
5486 vnet_lisp_gpe_enable_disable (a);
5488 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5492 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5494 vl_api_lisp_enable_disable_reply_t *rmp;
5497 vnet_lisp_enable_disable (mp->is_en);
5498 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5502 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5504 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5506 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5508 a->is_add = mp->is_add;
5509 a->dp_table = mp->dp_table;
5511 a->is_l2 = mp->is_l2;
5512 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5514 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5518 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5521 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5525 ls_name = format (0, "%s", mp->ls_name);
5526 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5529 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5533 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5534 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5536 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5538 u8 *locator_set_name = NULL;
5539 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5541 locator_set_name = format (0, "%s", mp->locator_set_name);
5543 a->is_add = mp->is_add;
5544 a->locator_set_name = locator_set_name;
5546 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5548 vec_free (locator_set_name);
5550 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5554 vl_api_lisp_add_del_remote_mapping_t_handler
5555 (vl_api_lisp_add_del_remote_mapping_t * mp)
5557 locator_t *rlocs = 0;
5558 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5560 gid_address_t _eid, *eid = &_eid;
5561 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5563 memset (eid, 0, sizeof (eid[0]));
5565 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5566 mp->eid_type, mp->eid, mp->eid_len);
5570 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5574 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5575 gid_address_copy (&a->deid, eid);
5577 rv = vnet_lisp_add_del_adjacency (a);
5584 /* NOTE: for now this works as a static remote mapping, i.e.,
5585 * not authoritative and ttl infinite. */
5586 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5587 mp->is_add, 1 /* is_static */ , 0);
5590 vnet_lisp_clear_all_remote_adjacencies ();
5595 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5599 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5601 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5602 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5605 memset (a, 0, sizeof (a[0]));
5607 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5608 mp->eid_type, mp->seid, mp->seid_len);
5609 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5610 mp->eid_type, mp->deid, mp->deid_len);
5615 a->is_add = mp->is_add;
5616 rv = vnet_lisp_add_del_adjacency (a);
5619 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5623 send_lisp_locator_details (lisp_cp_main_t * lcm,
5625 unix_shared_memory_queue_t * q, u32 context)
5627 vl_api_lisp_locator_details_t *rmp;
5629 rmp = vl_msg_api_alloc (sizeof (*rmp));
5630 memset (rmp, 0, sizeof (*rmp));
5631 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5632 rmp->context = context;
5634 rmp->local = loc->local;
5637 rmp->sw_if_index = ntohl (loc->sw_if_index);
5641 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5642 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5644 rmp->priority = loc->priority;
5645 rmp->weight = loc->weight;
5647 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5651 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5653 unix_shared_memory_queue_t *q = 0;
5654 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5655 locator_set_t *lsit = 0;
5657 u32 ls_index = ~0, *locit = 0;
5660 q = vl_api_client_index_to_input_queue (mp->client_index);
5666 ls_index = htonl (mp->locator_set_index);
5668 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5670 filter = mp->filter;
5671 if (filter && !((1 == filter && lsit->local) ||
5672 (2 == filter && !lsit->local)))
5677 vec_foreach (locit, lsit->locator_indices)
5679 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5680 send_lisp_locator_details (lcm, loc, q, mp->context);
5685 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5686 locator_set_t * lsit,
5687 unix_shared_memory_queue_t * q,
5688 u32 context, u32 ls_index)
5690 vl_api_lisp_locator_set_details_t *rmp;
5693 rmp = vl_msg_api_alloc (sizeof (*rmp));
5694 memset (rmp, 0, sizeof (*rmp));
5695 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5696 rmp->context = context;
5698 rmp->local = lsit->local;
5699 rmp->locator_set_index = htonl (ls_index);
5702 ASSERT (lsit->name != NULL);
5703 strncpy ((char *) rmp->locator_set_name,
5704 (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1);
5708 str = format (0, "remote-%d", ls_index);
5709 strncpy ((char *) rmp->locator_set_name, (char *) str,
5710 ARRAY_LEN (rmp->locator_set_name) - 1);
5714 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5718 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5720 unix_shared_memory_queue_t *q = NULL;
5721 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5722 locator_set_t *lsit = NULL;
5726 q = vl_api_client_index_to_input_queue (mp->client_index);
5732 filter = mp->filter;
5735 pool_foreach (lsit, lcm->locator_set_pool,
5737 if (filter && !((1 == filter && lsit->local) ||
5738 (2 == filter && !lsit->local))) {
5742 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5748 send_lisp_eid_table_details (mapping_t * mapit,
5749 unix_shared_memory_queue_t * q,
5750 u32 context, u8 filter)
5752 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5753 locator_set_t *ls = 0;
5754 vl_api_lisp_eid_table_details_t *rmp = NULL;
5755 gid_address_t *gid = NULL;
5757 ip_prefix_t *ip_prefix = NULL;
5761 case 0: /* all mappings */
5764 case 1: /* local only */
5768 case 2: /* remote only */
5773 clib_warning ("Filter error, unknown filter: %d", filter);
5778 ip_prefix = &gid_address_ippref (gid);
5779 mac = gid_address_mac (gid);
5781 rmp = vl_msg_api_alloc (sizeof (*rmp));
5782 memset (rmp, 0, sizeof (*rmp));
5783 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5785 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5786 if (vec_len (ls->locator_indices) == 0)
5787 rmp->locator_set_index = ~0;
5789 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5791 rmp->is_local = mapit->local;
5792 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5793 rmp->action = mapit->action;
5794 rmp->authoritative = mapit->authoritative;
5796 switch (gid_address_type (gid))
5798 case GID_ADDR_IP_PREFIX:
5799 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5800 if (ip_prefix_version (ip_prefix) == IP4)
5802 rmp->eid_type = 0; /* ipv4 type */
5803 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5804 sizeof (ip_prefix_v4 (ip_prefix)));
5808 rmp->eid_type = 1; /* ipv6 type */
5809 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5810 sizeof (ip_prefix_v6 (ip_prefix)));
5814 rmp->eid_type = 2; /* l2 mac type */
5815 clib_memcpy (rmp->eid, mac, 6);
5820 rmp->context = context;
5821 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5822 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5826 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5829 unix_shared_memory_queue_t *q = NULL;
5830 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5831 mapping_t *mapit = NULL;
5832 gid_address_t _eid, *eid = &_eid;
5834 q = vl_api_client_index_to_input_queue (mp->client_index);
5842 memset (eid, 0, sizeof (*eid));
5844 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5845 mp->eid_type, mp->eid, mp->prefix_length);
5847 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5848 if ((u32) ~ 0 == mi)
5851 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5852 send_lisp_eid_table_details (mapit, q, mp->context,
5853 0 /* ignore filter */ );
5858 pool_foreach (mapit, lcm->mapping_pool,
5860 send_lisp_eid_table_details(mapit, q, mp->context,
5868 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5869 unix_shared_memory_queue_t * q, u32 context)
5871 vl_api_lisp_gpe_tunnel_details_t *rmp;
5872 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5874 rmp = vl_msg_api_alloc (sizeof (*rmp));
5875 memset (rmp, 0, sizeof (*rmp));
5876 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5878 rmp->tunnels = tunnel - lgm->tunnels;
5880 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5881 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5882 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5884 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5885 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5886 rmp->dcap_next = htonl (tunnel->decap_next_index);
5887 rmp->lisp_ver = tunnel->ver_res;
5888 rmp->next_protocol = tunnel->next_protocol;
5889 rmp->flags = tunnel->flags;
5890 rmp->ver_res = tunnel->ver_res;
5891 rmp->res = tunnel->res;
5892 rmp->iid = htonl (tunnel->vni);
5893 rmp->context = context;
5895 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5899 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5901 unix_shared_memory_queue_t *q = NULL;
5902 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5903 lisp_gpe_tunnel_t *tunnel = NULL;
5905 if (pool_elts (lgm->tunnels) == 0)
5910 q = vl_api_client_index_to_input_queue (mp->client_index);
5917 pool_foreach(tunnel, lgm->tunnels,
5919 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5925 send_lisp_map_resolver_details (ip_address_t * ip,
5926 unix_shared_memory_queue_t * q, u32 context)
5928 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5930 rmp = vl_msg_api_alloc (sizeof (*rmp));
5931 memset (rmp, 0, sizeof (*rmp));
5932 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5934 switch (ip_addr_version (ip))
5938 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5939 sizeof (ip_addr_v4 (ip)));
5944 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5945 sizeof (ip_addr_v6 (ip)));
5951 rmp->context = context;
5953 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5957 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5959 unix_shared_memory_queue_t *q = NULL;
5960 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5963 q = vl_api_client_index_to_input_queue (mp->client_index);
5969 vec_foreach (mr, lcm->map_resolvers)
5971 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5976 send_eid_table_map_pair (hash_pair_t * p,
5977 unix_shared_memory_queue_t * q, u32 context)
5979 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5981 rmp = vl_msg_api_alloc (sizeof (*rmp));
5982 memset (rmp, 0, sizeof (*rmp));
5983 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5985 rmp->vni = clib_host_to_net_u32 (p->key);
5986 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5987 rmp->context = context;
5988 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5992 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5995 unix_shared_memory_queue_t *q = NULL;
5996 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5998 uword *vni_table = 0;
6000 q = vl_api_client_index_to_input_queue (mp->client_index);
6008 vni_table = lcm->bd_id_by_vni;
6012 vni_table = lcm->table_id_by_vni;
6016 hash_foreach_pair (p, vni_table,
6018 send_eid_table_map_pair (p, q, mp->context);
6024 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6026 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6028 rmp = vl_msg_api_alloc (sizeof (*rmp));
6029 memset (rmp, 0, sizeof (*rmp));
6030 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6031 rmp->context = context;
6032 rmp->vni = clib_host_to_net_u32 (vni);
6033 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6037 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6042 unix_shared_memory_queue_t *q = 0;
6043 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6045 q = vl_api_client_index_to_input_queue (mp->client_index);
6052 hash_foreach_pair (p, lcm->table_id_by_vni,
6054 hash_set (vnis, p->key, 0);
6057 hash_foreach_pair (p, lcm->bd_id_by_vni,
6059 hash_set (vnis, p->key, 0);
6062 hash_foreach_pair (p, vnis,
6064 send_eid_table_vni (p->key, q, mp->context);
6072 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6074 unix_shared_memory_queue_t *q = NULL;
6075 vl_api_show_lisp_status_reply_t *rmp = NULL;
6078 q = vl_api_client_index_to_input_queue (mp->client_index);
6085 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6087 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6088 rmp->feature_status = vnet_lisp_enable_disable_status ();
6094 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6095 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6097 unix_shared_memory_queue_t *q = NULL;
6098 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6099 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6100 locator_set_t *loc_set = 0;
6104 q = vl_api_client_index_to_input_queue (mp->client_index);
6110 if (~0 == lcm->mreq_itr_rlocs)
6112 tmp_str = format (0, " ");
6117 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6118 tmp_str = format (0, "%s", loc_set->name);
6122 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6124 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6125 ARRAY_LEN(rmp->locator_set_name) - 1);
6133 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6135 unix_shared_memory_queue_t *q = NULL;
6136 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6137 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6139 locator_set_t *ls = 0;
6143 q = vl_api_client_index_to_input_queue (mp->client_index);
6149 if (!lcm->lisp_pitr)
6151 tmp_str = format (0, "N/A");
6155 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6156 if (~0 != m->locator_set_index)
6159 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6160 tmp_str = format (0, "%s", ls->name);
6164 tmp_str = format (0, "N/A");
6167 vec_add1 (tmp_str, 0);
6170 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6172 rmp->status = lcm->lisp_pitr;
6173 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6174 ARRAY_LEN(rmp->locator_set_name) - 1);
6180 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6183 vl_api_interface_name_renumber_reply_t *rmp;
6186 VALIDATE_SW_IF_INDEX (mp);
6188 rv = vnet_interface_name_renumber
6189 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6191 BAD_SW_IF_INDEX_LABEL;
6193 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6197 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6198 u32 sw_if_index, u32 address)
6200 vpe_api_main_t *am = &vpe_api_main;
6201 vlib_main_t *vm = am->vlib_main;
6202 vl_api_ip4_arp_event_t *event;
6203 static f64 arp_event_last_time;
6204 f64 now = vlib_time_now (vm);
6206 if (pool_is_free_index (am->arp_events, pool_index))
6209 event = pool_elt_at_index (am->arp_events, pool_index);
6211 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6213 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6217 if (sw_if_index == event->sw_if_index &&
6219 /* for BD case, also check IP address with 10 sec timeout */
6220 (address == event->address &&
6221 (now - arp_event_last_time) < 10.0)))
6226 arp_event_last_time = now;
6227 event->sw_if_index = sw_if_index;
6229 event->address = address;
6234 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6235 u32 sw_if_index, ip6_address_t * address)
6237 vpe_api_main_t *am = &vpe_api_main;
6238 vlib_main_t *vm = am->vlib_main;
6239 vl_api_ip6_nd_event_t *event;
6240 static f64 nd_event_last_time;
6241 f64 now = vlib_time_now (vm);
6243 if (pool_is_free_index (am->nd_events, pool_index))
6246 event = pool_elt_at_index (am->nd_events, pool_index);
6249 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6251 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6255 if (sw_if_index == event->sw_if_index &&
6257 /* for BD case, also check IP address with 10 sec timeout */
6258 (ip6_address_is_equal (address,
6259 (ip6_address_t *) event->address) &&
6260 (now - nd_event_last_time) < 10.0)))
6265 nd_event_last_time = now;
6266 event->sw_if_index = sw_if_index;
6268 clib_memcpy (event->address, address, sizeof (event->address));
6273 arp_change_delete_callback (u32 pool_index, u8 * notused)
6275 vpe_api_main_t *am = &vpe_api_main;
6277 if (pool_is_free_index (am->arp_events, pool_index))
6280 pool_put_index (am->arp_events, pool_index);
6285 nd_change_delete_callback (u32 pool_index, u8 * notused)
6287 vpe_api_main_t *am = &vpe_api_main;
6289 if (pool_is_free_index (am->nd_events, pool_index))
6292 pool_put_index (am->nd_events, pool_index);
6297 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6299 vpe_api_main_t *am = &vpe_api_main;
6300 vnet_main_t *vnm = vnet_get_main ();
6301 vl_api_want_ip4_arp_events_reply_t *rmp;
6302 vl_api_ip4_arp_event_t *event;
6305 if (mp->enable_disable)
6307 pool_get (am->arp_events, event);
6308 memset (event, 0, sizeof (*event));
6310 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6311 event->client_index = mp->client_index;
6312 event->context = mp->context;
6313 event->address = mp->address;
6314 event->pid = mp->pid;
6315 if (mp->address == 0)
6318 rv = vnet_add_del_ip4_arp_change_event
6319 (vnm, arp_change_data_callback,
6320 mp->pid, &mp->address /* addr, in net byte order */ ,
6321 vpe_resolver_process_node.index,
6322 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6326 rv = vnet_add_del_ip4_arp_change_event
6327 (vnm, arp_change_delete_callback,
6328 mp->pid, &mp->address /* addr, in net byte order */ ,
6329 vpe_resolver_process_node.index,
6330 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6332 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6336 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6338 vpe_api_main_t *am = &vpe_api_main;
6339 vnet_main_t *vnm = vnet_get_main ();
6340 vl_api_want_ip6_nd_events_reply_t *rmp;
6341 vl_api_ip6_nd_event_t *event;
6344 if (mp->enable_disable)
6346 pool_get (am->nd_events, event);
6347 memset (event, 0, sizeof (*event));
6349 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6350 event->client_index = mp->client_index;
6351 event->context = mp->context;
6352 clib_memcpy (event->address, mp->address, 16);
6353 event->pid = mp->pid;
6354 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6357 rv = vnet_add_del_ip6_nd_change_event
6358 (vnm, nd_change_data_callback,
6359 mp->pid, mp->address /* addr, in net byte order */ ,
6360 vpe_resolver_process_node.index,
6361 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6365 rv = vnet_add_del_ip6_nd_change_event
6366 (vnm, nd_change_delete_callback,
6367 mp->pid, mp->address /* addr, in net byte order */ ,
6368 vpe_resolver_process_node.index,
6369 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6371 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6374 static void vl_api_input_acl_set_interface_t_handler
6375 (vl_api_input_acl_set_interface_t * mp)
6377 vlib_main_t *vm = vlib_get_main ();
6378 vl_api_input_acl_set_interface_reply_t *rmp;
6380 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6382 ip4_table_index = ntohl (mp->ip4_table_index);
6383 ip6_table_index = ntohl (mp->ip6_table_index);
6384 l2_table_index = ntohl (mp->l2_table_index);
6385 sw_if_index = ntohl (mp->sw_if_index);
6387 VALIDATE_SW_IF_INDEX (mp);
6389 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6390 ip6_table_index, l2_table_index, mp->is_add);
6392 BAD_SW_IF_INDEX_LABEL;
6394 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6397 static void vl_api_ipsec_spd_add_del_t_handler
6398 (vl_api_ipsec_spd_add_del_t * mp)
6401 clib_warning ("unimplemented");
6404 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6405 vl_api_ipsec_spd_add_del_reply_t *rmp;
6409 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6411 rv = VNET_API_ERROR_UNIMPLEMENTED;
6414 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6418 static void vl_api_ipsec_interface_add_del_spd_t_handler
6419 (vl_api_ipsec_interface_add_del_spd_t * mp)
6421 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6422 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6424 u32 sw_if_index __attribute__ ((unused));
6425 u32 spd_id __attribute__ ((unused));
6427 sw_if_index = ntohl (mp->sw_if_index);
6428 spd_id = ntohl (mp->spd_id);
6430 VALIDATE_SW_IF_INDEX (mp);
6433 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6435 rv = VNET_API_ERROR_UNIMPLEMENTED;
6438 BAD_SW_IF_INDEX_LABEL;
6440 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6443 static void vl_api_ipsec_spd_add_del_entry_t_handler
6444 (vl_api_ipsec_spd_add_del_entry_t * mp)
6446 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6447 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6453 memset (&p, 0, sizeof (p));
6455 p.id = ntohl (mp->spd_id);
6456 p.priority = ntohl (mp->priority);
6457 p.is_outbound = mp->is_outbound;
6458 p.is_ipv6 = mp->is_ipv6;
6460 if (mp->is_ipv6 || mp->is_ip_any)
6462 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6463 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6464 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6465 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6469 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6470 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6471 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6472 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6474 p.protocol = mp->protocol;
6475 p.rport.start = ntohs (mp->remote_port_start);
6476 p.rport.stop = ntohs (mp->remote_port_stop);
6477 p.lport.start = ntohs (mp->local_port_start);
6478 p.lport.stop = ntohs (mp->local_port_stop);
6479 /* policy action resolve unsupported */
6480 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6482 clib_warning ("unsupported action: 'resolve'");
6483 rv = VNET_API_ERROR_UNIMPLEMENTED;
6486 p.policy = mp->policy;
6487 p.sa_id = ntohl (mp->sa_id);
6489 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6496 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6499 rv = VNET_API_ERROR_UNIMPLEMENTED;
6504 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6507 static void vl_api_ipsec_sad_add_del_entry_t_handler
6508 (vl_api_ipsec_sad_add_del_entry_t * mp)
6510 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6511 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6516 memset (&sa, 0, sizeof (sa));
6518 sa.id = ntohl (mp->sad_id);
6519 sa.spi = ntohl (mp->spi);
6520 /* security protocol AH unsupported */
6521 if (mp->protocol == IPSEC_PROTOCOL_AH)
6523 clib_warning ("unsupported security protocol 'AH'");
6524 rv = VNET_API_ERROR_UNIMPLEMENTED;
6527 sa.protocol = mp->protocol;
6528 /* check for unsupported crypto-alg */
6529 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6530 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6532 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6533 mp->crypto_algorithm);
6534 rv = VNET_API_ERROR_UNIMPLEMENTED;
6537 sa.crypto_alg = mp->crypto_algorithm;
6538 sa.crypto_key_len = mp->crypto_key_length;
6539 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6540 /* check for unsupported integ-alg */
6541 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6542 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6544 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6545 mp->integrity_algorithm);
6546 rv = VNET_API_ERROR_UNIMPLEMENTED;
6549 sa.integ_alg = mp->integrity_algorithm;
6550 sa.integ_key_len = mp->integrity_key_length;
6551 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6552 sa.use_esn = mp->use_extended_sequence_number;
6553 sa.is_tunnel = mp->is_tunnel;
6554 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6555 if (sa.is_tunnel_ip6)
6557 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6558 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6562 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6563 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6566 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6568 rv = VNET_API_ERROR_UNIMPLEMENTED;
6573 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6577 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6579 vl_api_ikev2_profile_add_del_reply_t *rmp;
6583 vlib_main_t *vm = vlib_get_main ();
6584 clib_error_t *error;
6585 u8 *tmp = format (0, "%s", mp->name);
6586 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6589 rv = VNET_API_ERROR_UNSPECIFIED;
6591 rv = VNET_API_ERROR_UNIMPLEMENTED;
6594 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6598 vl_api_ikev2_profile_set_auth_t_handler
6599 (vl_api_ikev2_profile_set_auth_t * mp)
6601 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6605 vlib_main_t *vm = vlib_get_main ();
6606 clib_error_t *error;
6607 u8 *tmp = format (0, "%s", mp->name);
6608 u8 *data = vec_new (u8, mp->data_len);
6609 clib_memcpy (data, mp->data, mp->data_len);
6610 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6614 rv = VNET_API_ERROR_UNSPECIFIED;
6616 rv = VNET_API_ERROR_UNIMPLEMENTED;
6619 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6623 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6625 vl_api_ikev2_profile_add_del_reply_t *rmp;
6629 vlib_main_t *vm = vlib_get_main ();
6630 clib_error_t *error;
6631 u8 *tmp = format (0, "%s", mp->name);
6632 u8 *data = vec_new (u8, mp->data_len);
6633 clib_memcpy (data, mp->data, mp->data_len);
6634 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6638 rv = VNET_API_ERROR_UNSPECIFIED;
6640 rv = VNET_API_ERROR_UNIMPLEMENTED;
6643 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6647 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6649 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6653 vlib_main_t *vm = vlib_get_main ();
6654 clib_error_t *error;
6655 u8 *tmp = format (0, "%s", mp->name);
6656 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6657 mp->end_port, (ip4_address_t) mp->start_addr,
6658 (ip4_address_t) mp->end_addr, mp->is_local);
6661 rv = VNET_API_ERROR_UNSPECIFIED;
6663 rv = VNET_API_ERROR_UNIMPLEMENTED;
6666 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6670 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6672 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6676 vlib_main_t *vm = vlib_get_main ();
6677 clib_error_t *error;
6679 error = ikev2_set_local_key (vm, mp->key_file);
6681 rv = VNET_API_ERROR_UNSPECIFIED;
6683 rv = VNET_API_ERROR_UNIMPLEMENTED;
6686 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6690 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6692 vl_api_map_add_domain_reply_t *rmp;
6695 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6697 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6698 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6699 (ip6_address_t *) & mp->ip6_src,
6700 mp->ip6_src_prefix_len, mp->ea_bits_len,
6701 mp->psid_offset, mp->psid_length, &index,
6702 ntohs (mp->mtu), flags);
6705 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6707 rmp->index = ntohl(index);
6713 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6715 vl_api_map_del_domain_reply_t *rmp;
6718 rv = map_delete_domain (ntohl (mp->index));
6720 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6724 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6726 vl_api_map_del_domain_reply_t *rmp;
6730 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6731 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6733 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6737 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6739 vl_api_map_domain_details_t *rmp;
6740 map_main_t *mm = &map_main;
6742 unix_shared_memory_queue_t *q;
6744 if (pool_elts (mm->domains) == 0)
6747 q = vl_api_client_index_to_input_queue (mp->client_index);
6754 pool_foreach(d, mm->domains,
6756 /* Make sure every field is initiated (or don't skip the memset()) */
6757 rmp = vl_msg_api_alloc (sizeof (*rmp));
6758 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6759 rmp->domain_index = htonl(d - mm->domains);
6760 rmp->ea_bits_len = d->ea_bits_len;
6761 rmp->psid_offset = d->psid_offset;
6762 rmp->psid_length = d->psid_length;
6763 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6764 rmp->ip4_prefix_len = d->ip4_prefix_len;
6765 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6766 rmp->ip6_prefix_len = d->ip6_prefix_len;
6767 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6768 rmp->ip6_src_len = d->ip6_src_len;
6769 rmp->mtu = htons(d->mtu);
6770 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6771 rmp->context = mp->context;
6773 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6779 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6781 unix_shared_memory_queue_t *q;
6784 vl_api_map_rule_details_t *rmp;
6785 map_main_t *mm = &map_main;
6786 u32 domain_index = ntohl (mp->domain_index);
6789 if (pool_elts (mm->domains) == 0)
6792 d = pool_elt_at_index (mm->domains, domain_index);
6793 if (!d || !d->rules)
6798 q = vl_api_client_index_to_input_queue (mp->client_index);
6804 for (i = 0; i < (0x1 << d->psid_length); i++)
6807 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6811 rmp = vl_msg_api_alloc (sizeof (*rmp));
6812 memset (rmp, 0, sizeof (*rmp));
6813 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6814 rmp->psid = htons (i);
6815 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6816 rmp->context = mp->context;
6817 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6822 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6824 vl_api_map_summary_stats_reply_t *rmp;
6825 vlib_combined_counter_main_t *cm;
6828 u64 total_pkts[VLIB_N_RX_TX];
6829 u64 total_bytes[VLIB_N_RX_TX];
6830 map_main_t *mm = &map_main;
6831 unix_shared_memory_queue_t *q =
6832 vl_api_client_index_to_input_queue (mp->client_index);
6837 rmp = vl_msg_api_alloc (sizeof (*rmp));
6838 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6839 rmp->context = mp->context;
6842 memset (total_pkts, 0, sizeof (total_pkts));
6843 memset (total_bytes, 0, sizeof (total_bytes));
6845 map_domain_counter_lock (mm);
6846 vec_foreach (cm, mm->domain_counters)
6848 which = cm - mm->domain_counters;
6850 for (i = 0; i < vec_len (cm->maxi); i++)
6852 vlib_get_combined_counter (cm, i, &v);
6853 total_pkts[which] += v.packets;
6854 total_bytes[which] += v.bytes;
6858 map_domain_counter_unlock (mm);
6860 /* Note: in network byte order! */
6861 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6862 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6863 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6864 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6865 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6866 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6867 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6868 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6869 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6870 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6871 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6872 clib_host_to_net_u64 (map_error_counter_get
6873 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6874 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6875 clib_host_to_net_u64 (map_error_counter_get
6876 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6878 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6882 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6884 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6885 vl_api_ipsec_sa_set_key_reply_t *rmp;
6889 sa.id = ntohl (mp->sa_id);
6890 sa.crypto_key_len = mp->crypto_key_length;
6891 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6892 sa.integ_key_len = mp->integrity_key_length;
6893 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6895 rv = ipsec_set_sa_key (vm, &sa);
6897 rv = VNET_API_ERROR_UNIMPLEMENTED;
6900 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6903 static void vl_api_cop_interface_enable_disable_t_handler
6904 (vl_api_cop_interface_enable_disable_t * mp)
6906 vl_api_cop_interface_enable_disable_reply_t *rmp;
6908 u32 sw_if_index = ntohl (mp->sw_if_index);
6911 VALIDATE_SW_IF_INDEX (mp);
6913 enable_disable = (int) mp->enable_disable;
6915 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6917 BAD_SW_IF_INDEX_LABEL;
6919 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6922 static void vl_api_cop_whitelist_enable_disable_t_handler
6923 (vl_api_cop_whitelist_enable_disable_t * mp)
6925 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6926 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6927 u32 sw_if_index = ntohl (mp->sw_if_index);
6930 VALIDATE_SW_IF_INDEX (mp);
6932 a->sw_if_index = sw_if_index;
6935 a->default_cop = mp->default_cop;
6936 a->fib_id = ntohl (mp->fib_id);
6938 rv = cop_whitelist_enable_disable (a);
6940 BAD_SW_IF_INDEX_LABEL;
6942 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6946 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6950 api_main_t *am = &api_main;
6951 vlib_main_t *vm = vlib_get_main ();
6953 vl_api_get_node_graph_reply_t *rmp;
6955 pthread_mutex_lock (&am->vlib_rp->mutex);
6956 oldheap = svm_push_data_heap (am->vlib_rp);
6959 * Keep the number of memcpy ops to a minimum (e.g. 1).
6961 vec_validate (vector, 16384);
6962 vec_reset_length (vector);
6965 vector = vlib_node_serialize (&vm->node_main, vector,
6966 (u32) ~ 0 /* all threads */ ,
6967 1 /* include nexts */ ,
6968 1 /* include stats */ );
6970 svm_pop_heap (oldheap);
6971 pthread_mutex_unlock (&am->vlib_rp->mutex);
6974 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6976 rmp->reply_in_shmem = (uword) vector;
6981 static void vl_api_trace_profile_add_t_handler
6982 (vl_api_trace_profile_add_t * mp)
6985 vl_api_trace_profile_add_reply_t *rmp;
6986 clib_error_t *error;
6988 /* Ignoring the profile id as currently a single profile
6990 error = ip6_ioam_trace_profile_set (mp->trace_num_elt, mp->trace_type,
6991 ntohl (mp->node_id),
6992 ntohl (mp->trace_app_data),
6993 mp->pow_enable, mp->trace_tsp,
6997 clib_error_report (error);
6998 rv = clib_error_get_code (error);
7001 REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
7004 static void vl_api_trace_profile_apply_t_handler
7005 (vl_api_trace_profile_apply_t * mp)
7008 vl_api_trace_profile_apply_reply_t *rmp;
7010 if (mp->enable != 0)
7012 rv = ip6_ioam_set_destination ((ip6_address_t *) (&mp->dest_ipv6),
7013 ntohl (mp->prefix_length),
7015 mp->trace_op == IOAM_HBYH_ADD,
7016 mp->trace_op == IOAM_HBYH_POP,
7017 mp->trace_op == IOAM_HBYH_MOD);
7021 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
7023 REPLY_MACRO (VL_API_TRACE_PROFILE_APPLY_REPLY);
7026 static void vl_api_trace_profile_del_t_handler
7027 (vl_api_trace_profile_del_t * mp)
7030 vl_api_trace_profile_del_reply_t *rmp;
7031 clib_error_t *error;
7033 error = clear_ioam_rewrite_fn ();
7036 clib_error_report (error);
7037 rv = clib_error_get_code (error);
7040 REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
7044 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7046 vlib_main_t *vm = vlib_get_main ();
7047 vl_api_af_packet_create_reply_t *rmp;
7049 u8 *host_if_name = NULL;
7052 host_if_name = format (0, "%s", mp->host_if_name);
7053 vec_add1 (host_if_name, 0);
7055 rv = af_packet_create_if (vm, host_if_name,
7056 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7059 vec_free (host_if_name);
7062 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7064 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7070 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7072 vlib_main_t *vm = vlib_get_main ();
7073 vl_api_af_packet_delete_reply_t *rmp;
7075 u8 *host_if_name = NULL;
7077 host_if_name = format (0, "%s", mp->host_if_name);
7078 vec_add1 (host_if_name, 0);
7080 rv = af_packet_delete_if (vm, host_if_name);
7082 vec_free (host_if_name);
7084 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7088 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7090 vlib_main_t *vm = vlib_get_main ();
7091 vl_api_policer_add_del_reply_t *rmp;
7094 sse2_qos_pol_cfg_params_st cfg;
7095 clib_error_t *error;
7098 name = format (0, "%s", mp->name);
7100 memset (&cfg, 0, sizeof (cfg));
7102 cfg.rnd_type = mp->round_type;
7103 cfg.rate_type = mp->rate_type;
7104 cfg.rb.kbps.cir_kbps = mp->cir;
7105 cfg.rb.kbps.eir_kbps = mp->eir;
7106 cfg.rb.kbps.cb_bytes = mp->cb;
7107 cfg.rb.kbps.eb_bytes = mp->eb;
7108 cfg.conform_action.action_type = mp->conform_action_type;
7109 cfg.conform_action.dscp = mp->conform_dscp;
7110 cfg.exceed_action.action_type = mp->exceed_action_type;
7111 cfg.exceed_action.dscp = mp->exceed_dscp;
7112 cfg.violate_action.action_type = mp->violate_action_type;
7113 cfg.violate_action.dscp = mp->violate_dscp;
7114 cfg.color_aware = mp->color_aware;
7116 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7119 rv = VNET_API_ERROR_UNSPECIFIED;
7122 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7124 if (rv == 0 && mp->is_add)
7125 rmp->policer_index = ntohl(policer_index);
7127 rmp->policer_index = ~0;
7133 send_policer_details (u8 * name,
7134 sse2_qos_pol_cfg_params_st * config,
7135 policer_read_response_type_st * templ,
7136 unix_shared_memory_queue_t * q, u32 context)
7138 vl_api_policer_details_t *mp;
7140 mp = vl_msg_api_alloc (sizeof (*mp));
7141 memset (mp, 0, sizeof (*mp));
7142 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7143 mp->context = context;
7144 mp->cir = htonl (config->rb.kbps.cir_kbps);
7145 mp->eir = htonl (config->rb.kbps.eir_kbps);
7146 mp->cb = htonl (config->rb.kbps.cb_bytes);
7147 mp->eb = htonl (config->rb.kbps.eb_bytes);
7148 mp->rate_type = config->rate_type;
7149 mp->round_type = config->rnd_type;
7150 mp->type = config->rfc;
7151 mp->conform_action_type = config->conform_action.action_type;
7152 mp->conform_dscp = config->conform_action.dscp;
7153 mp->exceed_action_type = config->exceed_action.action_type;
7154 mp->exceed_dscp = config->exceed_action.dscp;
7155 mp->violate_action_type = config->violate_action.action_type;
7156 mp->violate_dscp = config->violate_action.dscp;
7157 mp->single_rate = templ->single_rate ? 1 : 0;
7158 mp->color_aware = templ->color_aware ? 1 : 0;
7159 mp->scale = htonl (templ->scale);
7160 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7161 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7162 mp->current_limit = htonl (templ->current_limit);
7163 mp->current_bucket = htonl (templ->current_bucket);
7164 mp->extended_limit = htonl (templ->extended_limit);
7165 mp->extended_bucket = htonl (templ->extended_bucket);
7166 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7168 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7170 vl_msg_api_send_shmem (q, (u8 *) & mp);
7174 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7176 unix_shared_memory_queue_t *q;
7177 vnet_policer_main_t *pm = &vnet_policer_main;
7183 sse2_qos_pol_cfg_params_st *config;
7184 policer_read_response_type_st *templ;
7186 q = vl_api_client_index_to_input_queue (mp->client_index);
7190 if (mp->match_name_valid)
7192 match_name = format (0, "%s%c", mp->match_name, 0);
7195 if (mp->match_name_valid)
7197 p = hash_get_mem (pm->policer_config_by_name, match_name);
7201 config = pool_elt_at_index (pm->configs, pool_index);
7202 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7203 send_policer_details (match_name, config, templ, q, mp->context);
7209 hash_foreach_pair (hp, pm->policer_config_by_name,
7211 name = (u8 *) hp->key;
7212 pool_index = hp->value[0];
7213 config = pool_elt_at_index (pm->configs, pool_index);
7214 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7215 send_policer_details(name, config, templ, q, mp->context);
7222 vl_api_policer_classify_set_interface_t_handler
7223 (vl_api_policer_classify_set_interface_t * mp)
7225 vlib_main_t *vm = vlib_get_main ();
7226 vl_api_policer_classify_set_interface_reply_t *rmp;
7228 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7230 ip4_table_index = ntohl (mp->ip4_table_index);
7231 ip6_table_index = ntohl (mp->ip6_table_index);
7232 l2_table_index = ntohl (mp->l2_table_index);
7233 sw_if_index = ntohl (mp->sw_if_index);
7235 VALIDATE_SW_IF_INDEX (mp);
7237 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7238 ip6_table_index, l2_table_index,
7241 BAD_SW_IF_INDEX_LABEL;
7243 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7247 send_policer_classify_details (u32 sw_if_index,
7249 unix_shared_memory_queue_t * q, u32 context)
7251 vl_api_policer_classify_details_t *mp;
7253 mp = vl_msg_api_alloc (sizeof (*mp));
7254 memset (mp, 0, sizeof (*mp));
7255 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7256 mp->context = context;
7257 mp->sw_if_index = htonl (sw_if_index);
7258 mp->table_index = htonl (table_index);
7260 vl_msg_api_send_shmem (q, (u8 *) & mp);
7264 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7266 unix_shared_memory_queue_t *q;
7267 policer_classify_main_t *pcm = &policer_classify_main;
7271 q = vl_api_client_index_to_input_queue (mp->client_index);
7275 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7277 if (vec_len (vec_tbl))
7279 for (i = 0; i < vec_len (vec_tbl); i++)
7281 if (vec_elt (vec_tbl, i) == ~0)
7284 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7291 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7293 vlib_main_t *vm = vlib_get_main ();
7294 vl_api_netmap_create_reply_t *rmp;
7298 if_name = format (0, "%s", mp->netmap_if_name);
7299 vec_add1 (if_name, 0);
7302 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7303 mp->is_pipe, mp->is_master, 0);
7307 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7311 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7313 vlib_main_t *vm = vlib_get_main ();
7314 vl_api_netmap_delete_reply_t *rmp;
7318 if_name = format (0, "%s", mp->netmap_if_name);
7319 vec_add1 (if_name, 0);
7321 rv = netmap_delete_if (vm, if_name);
7325 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7329 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7332 clib_warning ("BUG");
7336 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7337 unix_shared_memory_queue_t * q,
7338 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7340 vl_api_mpls_gre_tunnel_details_t *mp;
7341 mpls_main_t *mm = &mpls_main;
7346 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7347 nlabels = vec_len (e->labels);
7349 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7350 memset (mp, 0, sizeof (*mp));
7351 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7352 mp->context = context;
7354 mp->tunnel_index = htonl (index);
7355 mp->tunnel_src = gt->tunnel_src.as_u32;
7356 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7357 mp->intfc_address = gt->intfc_address.as_u32;
7358 mp->mask_width = htonl (gt->mask_width);
7359 mp->inner_fib_index = htonl (gt->inner_fib_index);
7360 mp->outer_fib_index = htonl (gt->outer_fib_index);
7361 mp->encap_index = htonl (gt->encap_index);
7362 mp->hw_if_index = htonl (gt->hw_if_index);
7363 mp->l2_only = htonl (gt->l2_only);
7364 mp->nlabels = htonl (nlabels);
7366 for (i = 0; i < nlabels; i++)
7369 htonl (vnet_mpls_uc_get_label
7370 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7373 vl_msg_api_send_shmem (q, (u8 *) & mp);
7377 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7379 vpe_api_main_t *am = &vpe_api_main;
7380 unix_shared_memory_queue_t *q;
7381 mpls_main_t *mm = &mpls_main;
7382 mpls_gre_tunnel_t *gt;
7383 u32 index = ntohl (mp->tunnel_index);
7385 q = vl_api_client_index_to_input_queue (mp->client_index);
7391 if (!pool_is_free_index (mm->gre_tunnels, index))
7393 gt = pool_elt_at_index (mm->gre_tunnels, index);
7394 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7401 pool_foreach (gt, mm->gre_tunnels,
7403 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7411 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7414 clib_warning ("BUG");
7418 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7419 unix_shared_memory_queue_t * q,
7420 mpls_eth_tunnel_t * et, u32 index, u32 context)
7422 mpls_main_t *mm = &mpls_main;
7426 vl_api_mpls_eth_tunnel_details_t *mp;
7428 e = pool_elt_at_index (mm->encaps, et->encap_index);
7429 nlabels = vec_len (e->labels);
7431 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7432 memset (mp, 0, sizeof (*mp));
7433 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7434 mp->context = context;
7436 mp->tunnel_index = htonl (index);
7437 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7438 mp->intfc_address = et->intfc_address.as_u32;
7439 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7440 mp->inner_fib_index = htonl (et->inner_fib_index);
7441 mp->mask_width = htonl (et->mask_width);
7442 mp->encap_index = htonl (et->encap_index);
7443 mp->hw_if_index = htonl (et->hw_if_index);
7444 mp->l2_only = htonl (et->l2_only);
7445 mp->nlabels = htonl (nlabels);
7447 for (i = 0; i < nlabels; i++)
7450 htonl (vnet_mpls_uc_get_label
7451 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7454 vl_msg_api_send_shmem (q, (u8 *) & mp);
7458 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7460 vpe_api_main_t *am = &vpe_api_main;
7461 unix_shared_memory_queue_t *q;
7462 mpls_main_t *mm = &mpls_main;
7463 mpls_eth_tunnel_t *et;
7464 u32 index = ntohl (mp->tunnel_index);
7466 q = vl_api_client_index_to_input_queue (mp->client_index);
7472 if (!pool_is_free_index (mm->eth_tunnels, index))
7474 et = pool_elt_at_index (mm->eth_tunnels, index);
7475 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7482 pool_foreach (et, mm->eth_tunnels,
7484 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7492 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7494 clib_warning ("BUG");
7498 send_mpls_fib_encap_details (vpe_api_main_t * am,
7499 unix_shared_memory_queue_t * q,
7500 show_mpls_fib_t * s, u32 context)
7502 vl_api_mpls_fib_encap_details_t *mp;
7503 mpls_main_t *mm = &mpls_main;
7508 e = pool_elt_at_index (mm->encaps, s->entry_index);
7509 nlabels = vec_len (e->labels);
7511 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7512 memset (mp, 0, sizeof (*mp));
7513 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7514 mp->context = context;
7516 mp->fib_index = htonl (s->fib_index);
7517 mp->entry_index = htonl (s->entry_index);
7519 mp->s_bit = htonl (s->s_bit);
7521 mp->nlabels = htonl (nlabels);
7523 for (i = 0; i < nlabels; i++)
7526 htonl (vnet_mpls_uc_get_label
7527 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7530 vl_msg_api_send_shmem (q, (u8 *) & mp);
7534 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7536 vpe_api_main_t *am = &vpe_api_main;
7537 unix_shared_memory_queue_t *q;
7538 vlib_main_t *vm = &vlib_global_main;
7541 show_mpls_fib_t *records = 0;
7543 mpls_main_t *mm = &mpls_main;
7544 ip4_main_t *im = &ip4_main;
7547 q = vl_api_client_index_to_input_queue (mp->client_index);
7552 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7554 vec_add2 (records, s, 1);
7555 s->fib_index = (u32)(key>>32);
7556 s->dest = (u32)(key & 0xFFFFFFFF);
7557 s->entry_index = (u32) value;
7561 if (0 == vec_len (records))
7563 vlib_cli_output (vm, "MPLS encap table empty");
7567 /* sort output by dst address within fib */
7568 vec_sort_with_function (records, mpls_dest_cmp);
7569 vec_sort_with_function (records, mpls_fib_index_cmp);
7570 vlib_cli_output (vm, "MPLS encap table");
7571 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7572 vec_foreach (s, records)
7574 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7575 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7576 format_ip4_address, &s->dest, format_mpls_encap_index,
7577 mm, s->entry_index);
7578 send_mpls_fib_encap_details (am, q, s, mp->context);
7586 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7588 clib_warning ("BUG");
7592 send_mpls_fib_decap_details (vpe_api_main_t * am,
7593 unix_shared_memory_queue_t * q,
7594 show_mpls_fib_t * s,
7596 u32 tx_table_id, char *swif_tag, u32 context)
7598 vl_api_mpls_fib_decap_details_t *mp;
7600 mp = vl_msg_api_alloc (sizeof (*mp));
7601 memset (mp, 0, sizeof (*mp));
7602 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7603 mp->context = context;
7605 mp->fib_index = htonl (s->fib_index);
7606 mp->entry_index = htonl (s->entry_index);
7608 mp->s_bit = htonl (s->s_bit);
7609 mp->label = htonl (s->label);
7610 mp->rx_table_id = htonl (rx_table_id);
7611 mp->tx_table_id = htonl (tx_table_id);
7612 strncpy ((char *) mp->swif_tag,
7613 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7615 vl_msg_api_send_shmem (q, (u8 *) & mp);
7619 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7621 vpe_api_main_t *am = &vpe_api_main;
7622 unix_shared_memory_queue_t *q;
7623 vlib_main_t *vm = &vlib_global_main;
7626 show_mpls_fib_t *records = 0;
7628 mpls_main_t *mm = &mpls_main;
7629 ip4_main_t *im = &ip4_main;
7635 q = vl_api_client_index_to_input_queue (mp->client_index);
7640 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7642 vec_add2 (records, s, 1);
7643 s->fib_index = (u32)(key>>32);
7644 s->entry_index = (u32) value;
7645 s->label = ((u32) key)>>12;
7646 s->s_bit = (key & (1<<8)) != 0;
7650 if (!vec_len (records))
7652 vlib_cli_output (vm, "MPLS decap table empty");
7656 vec_sort_with_function (records, mpls_label_cmp);
7657 vlib_cli_output (vm, "MPLS decap table");
7658 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7660 vec_foreach (s, records)
7663 d = pool_elt_at_index (mm->decaps, s->entry_index);
7664 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT)
7666 tx_fib = vec_elt_at_index (im->fibs, d->tx_fib_index);
7667 tx_table_id = tx_fib->table_id;
7672 tx_table_id = d->tx_fib_index;
7675 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7677 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7678 tx_table_id, swif_tag, s->label, s->s_bit);
7680 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7681 tx_table_id, swif_tag, mp->context);
7689 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7691 unix_shared_memory_queue_t *q;
7693 q = vl_api_client_index_to_input_queue (mp->client_index);
7697 vnet_classify_main_t *cm = &vnet_classify_main;
7698 vnet_classify_table_t *t;
7703 pool_foreach (t, cm->tables,
7705 vec_add1 (table_ids, ntohl(t - cm->tables));
7708 count = vec_len (table_ids);
7710 vl_api_classify_table_ids_reply_t *rmp;
7711 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7712 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7713 rmp->context = mp->context;
7714 rmp->count = ntohl (count);
7715 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7718 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7720 vec_free (table_ids);
7724 vl_api_classify_table_by_interface_t_handler
7725 (vl_api_classify_table_by_interface_t * mp)
7727 vl_api_classify_table_by_interface_reply_t *rmp;
7730 u32 sw_if_index = ntohl (mp->sw_if_index);
7733 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7736 VALIDATE_SW_IF_INDEX (mp);
7738 input_acl_main_t *am = &input_acl_main;
7743 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7745 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7746 if (vec_len (vec_tbl))
7748 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7750 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7754 acl[type] = vec_elt (vec_tbl, if_idx);
7759 BAD_SW_IF_INDEX_LABEL;
7762 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7764 rmp->sw_if_index = ntohl(sw_if_index);
7765 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7766 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7767 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7774 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7776 unix_shared_memory_queue_t *q;
7778 q = vl_api_client_index_to_input_queue (mp->client_index);
7782 vl_api_classify_table_info_reply_t *rmp = 0;
7784 vnet_classify_main_t *cm = &vnet_classify_main;
7785 u32 table_id = ntohl (mp->table_id);
7786 vnet_classify_table_t *t;
7789 pool_foreach (t, cm->tables,
7791 if (table_id == t - cm->tables)
7793 rmp = vl_msg_api_alloc_as_if_client
7794 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7795 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7796 rmp->context = mp->context;
7797 rmp->table_id = ntohl(table_id);
7798 rmp->nbuckets = ntohl(t->nbuckets);
7799 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7800 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7801 rmp->active_sessions = ntohl(t->active_elements);
7802 rmp->next_table_index = ntohl(t->next_table_index);
7803 rmp->miss_next_index = ntohl(t->miss_next_index);
7804 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7805 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7814 rmp = vl_msg_api_alloc (sizeof (*rmp));
7815 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7816 rmp->context = mp->context;
7817 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7820 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7824 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7827 clib_warning ("BUG");
7831 send_classify_session_details (unix_shared_memory_queue_t * q,
7834 vnet_classify_entry_t * e, u32 context)
7836 vl_api_classify_session_details_t *rmp;
7838 rmp = vl_msg_api_alloc (sizeof (*rmp));
7839 memset (rmp, 0, sizeof (*rmp));
7840 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7841 rmp->context = context;
7842 rmp->table_id = ntohl (table_id);
7843 rmp->hit_next_index = ntohl (e->next_index);
7844 rmp->advance = ntohl (e->advance);
7845 rmp->opaque_index = ntohl (e->opaque_index);
7846 rmp->match_length = ntohl (match_length);
7847 clib_memcpy (rmp->match, e->key, match_length);
7849 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7853 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7855 vnet_classify_main_t *cm = &vnet_classify_main;
7856 unix_shared_memory_queue_t *q;
7858 u32 table_id = ntohl (mp->table_id);
7859 vnet_classify_table_t *t;
7861 q = vl_api_client_index_to_input_queue (mp->client_index);
7864 pool_foreach (t, cm->tables,
7866 if (table_id == t - cm->tables)
7868 vnet_classify_bucket_t * b;
7869 vnet_classify_entry_t * v, * save_v;
7872 for (i = 0; i < t->nbuckets; i++)
7874 b = &t->buckets [i];
7878 save_v = vnet_classify_get_entry (t, b->offset);
7879 for (j = 0; j < (1<<b->log2_pages); j++)
7881 for (k = 0; k < t->entries_per_page; k++)
7883 v = vnet_classify_entry_at_index
7884 (t, save_v, j*t->entries_per_page + k);
7885 if (vnet_classify_entry_is_free (v))
7888 send_classify_session_details
7889 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7901 vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t * mp)
7903 vlib_main_t *vm = vlib_get_main ();
7904 flow_report_main_t *frm = &flow_report_main;
7905 vl_api_ipfix_enable_reply_t *rmp;
7906 ip4_address_t collector, src;
7907 u16 collector_port = UDP_DST_PORT_ipfix;
7909 u32 template_interval;
7914 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7915 collector_port = ntohs (mp->collector_port);
7916 if (collector_port == (u16) ~ 0)
7917 collector_port = UDP_DST_PORT_ipfix;
7918 memcpy (src.data, mp->src_address, sizeof (src.data));
7919 fib_id = ntohl (mp->vrf_id);
7921 ip4_main_t *im = &ip4_main;
7922 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7925 rv = VNET_API_ERROR_NO_SUCH_FIB;
7930 path_mtu = ntohl (mp->path_mtu);
7932 path_mtu = 512; // RFC 7011 section 10.3.3.
7933 template_interval = ntohl (mp->template_interval);
7934 if (template_interval == ~0)
7935 template_interval = 20;
7937 if (collector.as_u32 == 0)
7939 rv = VNET_API_ERROR_INVALID_VALUE;
7943 if (src.as_u32 == 0)
7945 rv = VNET_API_ERROR_INVALID_VALUE;
7949 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7951 rv = VNET_API_ERROR_INVALID_VALUE;
7957 rv = VNET_API_ERROR_INVALID_VALUE;
7961 /* Reset report streams if we are reconfiguring IP addresses */
7962 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7963 frm->src_address.as_u32 != src.as_u32 ||
7964 frm->collector_port != collector_port)
7965 vnet_flow_reports_reset (frm);
7967 frm->ipfix_collector.as_u32 = collector.as_u32;
7968 frm->collector_port = collector_port;
7969 frm->src_address.as_u32 = src.as_u32;
7970 frm->fib_index = fib_index;
7971 frm->path_mtu = path_mtu;
7972 frm->template_interval = template_interval;
7974 /* Turn on the flow reporting process */
7975 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7978 REPLY_MACRO (VL_API_IPFIX_ENABLE_REPLY);
7982 vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t * mp)
7984 flow_report_main_t *frm = &flow_report_main;
7985 unix_shared_memory_queue_t *q;
7986 vl_api_ipfix_details_t *rmp;
7988 q = vl_api_client_index_to_input_queue (mp->client_index);
7992 rmp = vl_msg_api_alloc (sizeof (*rmp));
7993 memset (rmp, 0, sizeof (*rmp));
7994 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_DETAILS);
7995 rmp->context = mp->context;
7996 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7997 sizeof (frm->ipfix_collector.data));
7998 rmp->collector_port = htons (frm->collector_port);
7999 memcpy (rmp->src_address, frm->src_address.data,
8000 sizeof (frm->src_address.data));
8001 rmp->fib_index = htonl (frm->fib_index);
8002 rmp->path_mtu = htonl (frm->path_mtu);
8003 rmp->template_interval = htonl (frm->template_interval);
8005 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8009 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8011 vl_api_pg_create_interface_reply_t *rmp;
8014 pg_main_t *pg = &pg_main;
8015 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8018 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8020 rmp->sw_if_index = ntohl(sw_if_index);
8026 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8028 vl_api_pg_capture_reply_t *rmp;
8031 vnet_main_t *vnm = vnet_get_main ();
8032 vnet_interface_main_t *im = &vnm->interface_main;
8033 vnet_hw_interface_t *hi = 0;
8035 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8036 u32 hw_if_index = ~0;
8037 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8040 vec_free (intf_name);
8042 if (hw_if_index != ~0)
8044 pg_capture_args_t _a, *a = &_a;
8046 u32 len = ntohl (mp->pcap_name_length);
8047 u8 *pcap_file_name = vec_new (u8, len);
8048 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8050 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8051 a->hw_if_index = hw_if_index;
8052 a->dev_instance = hi->dev_instance;
8053 a->is_enabled = mp->is_enabled;
8054 a->pcap_file_name = pcap_file_name;
8055 a->count = ntohl (mp->count);
8057 clib_error_t *e = pg_capture (a);
8060 clib_error_report (e);
8061 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8064 vec_free (pcap_file_name);
8066 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8070 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8072 vl_api_pg_enable_disable_reply_t *rmp;
8075 pg_main_t *pg = &pg_main;
8076 u32 stream_index = ~0;
8078 int is_enable = mp->is_enabled != 0;
8079 u32 len = ntohl (mp->stream_name_length) - 1;
8083 u8 *stream_name = vec_new (u8, len);
8084 clib_memcpy (stream_name, mp->stream_name, len);
8085 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8088 vec_free (stream_name);
8091 pg_enable_disable (stream_index, is_enable);
8093 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8097 vl_api_ip_source_and_port_range_check_add_del_t_handler
8098 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8100 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8103 u8 is_ipv6 = mp->is_ipv6;
8104 u8 is_add = mp->is_add;
8105 u8 mask_length = mp->mask_length;
8106 ip4_address_t ip4_addr;
8107 ip6_address_t ip6_addr;
8109 u16 *high_ports = 0;
8111 u16 tmp_low, tmp_high;
8115 // Validate port range
8116 num_ranges = mp->number_of_ranges;
8117 if (num_ranges > 32)
8118 { // This is size of array in VPE.API
8119 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8123 vec_reset_length (low_ports);
8124 vec_reset_length (high_ports);
8126 for (i = 0; i < num_ranges; i++)
8128 tmp_low = mp->low_ports[i];
8129 tmp_high = mp->high_ports[i];
8130 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8131 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8132 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8134 rv = VNET_API_ERROR_INVALID_VALUE;
8137 vec_add1 (low_ports, tmp_low);
8138 vec_add1 (high_ports, tmp_high + 1);
8141 // Validate mask_length
8142 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8144 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8148 vrf_id = ntohl (mp->vrf_id);
8152 rv = VNET_API_ERROR_INVALID_VALUE;
8159 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8160 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8164 high_ports, is_add);
8168 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8169 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8173 high_ports, is_add);
8177 vec_free (low_ports);
8178 vec_free (high_ports);
8179 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8183 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8184 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8186 vlib_main_t *vm = vlib_get_main ();
8187 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8188 ip4_main_t *im = &ip4_main;
8191 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8192 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8196 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8197 ntohl (mp->tcp_out_vrf_id);
8198 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8199 ntohl (mp->udp_out_vrf_id);
8200 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8201 ntohl (mp->tcp_in_vrf_id);
8202 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8203 ntohl (mp->udp_in_vrf_id);
8206 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8208 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8210 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8214 rv = VNET_API_ERROR_INVALID_VALUE;
8218 fib_index[i] = p[0];
8223 sw_if_index = ntohl (mp->sw_if_index);
8225 VALIDATE_SW_IF_INDEX (mp);
8228 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8231 BAD_SW_IF_INDEX_LABEL;
8234 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8238 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8241 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8243 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8244 u32 sw_if_index = ~0;
8246 /* Check src & dst are different */
8247 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8249 rv = VNET_API_ERROR_SAME_SRC_DST;
8253 memset (a, 0, sizeof (*a));
8255 /* ip addresses sent in network byte order */
8256 clib_memcpy (&(a->src), mp->src_address, 4);
8257 clib_memcpy (&(a->dst), mp->dst_address, 4);
8258 a->is_add = mp->is_add;
8259 a->lsa = ntohl (mp->local_sa_id);
8260 a->rsa = ntohl (mp->remote_sa_id);
8262 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8266 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8268 rmp->sw_if_index = ntohl (sw_if_index);
8273 static void send_ipsec_gre_tunnel_details
8274 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8276 vl_api_ipsec_gre_tunnel_details_t *rmp;
8278 rmp = vl_msg_api_alloc (sizeof (*rmp));
8279 memset (rmp, 0, sizeof (*rmp));
8280 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8281 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8282 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8283 rmp->sw_if_index = htonl (t->sw_if_index);
8284 rmp->local_sa_id = htonl (t->local_sa_id);
8285 rmp->remote_sa_id = htonl (t->remote_sa_id);
8286 rmp->context = context;
8288 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8291 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8292 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8294 unix_shared_memory_queue_t *q;
8295 ipsec_gre_main_t *igm = &ipsec_gre_main;
8296 ipsec_gre_tunnel_t *t;
8299 q = vl_api_client_index_to_input_queue (mp->client_index);
8305 sw_if_index = ntohl (mp->sw_if_index);
8307 if (~0 == sw_if_index)
8310 pool_foreach (t, igm->tunnels,
8312 send_ipsec_gre_tunnel_details(t, q, mp->context);
8318 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8319 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8323 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8324 send_ipsec_gre_tunnel_details (t, q, mp->context);
8329 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8331 vl_api_delete_subif_reply_t *rmp;
8334 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8336 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8339 #define BOUNCE_HANDLER(nn) \
8340 static void vl_api_##nn##_t_handler ( \
8341 vl_api_##nn##_t *mp) \
8343 vpe_client_registration_t *reg; \
8344 vpe_api_main_t * vam = &vpe_api_main; \
8345 unix_shared_memory_queue_t * q; \
8347 /* One registration only... */ \
8348 pool_foreach(reg, vam->nn##_registrations, \
8350 q = vl_api_client_index_to_input_queue (reg->client_index); \
8353 * If the queue is stuffed, turf the msg and complain \
8354 * It's unlikely that the intended recipient is \
8355 * alive; avoid deadlock at all costs. \
8357 if (q->cursize == q->maxsize) { \
8358 clib_warning ("ERROR: receiver queue full, drop msg"); \
8359 vl_msg_api_free (mp); \
8362 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8366 vl_msg_api_free (mp); \
8371 * Add vpe's API message handlers to the table.
8372 * vlib has alread mapped shared memory and
8373 * added the client registration handlers.
8374 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8377 static clib_error_t *
8378 vpe_api_hookup (vlib_main_t * vm)
8380 api_main_t *am = &api_main;
8383 vl_msg_api_set_handlers(VL_API_##N, #n, \
8384 vl_api_##n##_t_handler, \
8386 vl_api_##n##_t_endian, \
8387 vl_api_##n##_t_print, \
8388 sizeof(vl_api_##n##_t), 1);
8389 foreach_vpe_api_msg;
8393 * Manually register the sr tunnel add del msg, so we trace
8394 * enough bytes to capture a typical segment list
8396 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8397 "sr_tunnel_add_del",
8398 vl_api_sr_tunnel_add_del_t_handler,
8400 vl_api_sr_tunnel_add_del_t_endian,
8401 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8405 * Manually register the sr policy add del msg, so we trace
8406 * enough bytes to capture a typical tunnel name list
8408 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8409 "sr_policy_add_del",
8410 vl_api_sr_policy_add_del_t_handler,
8412 vl_api_sr_policy_add_del_t_endian,
8413 vl_api_sr_policy_add_del_t_print, 256, 1);
8416 * Trace space for 8 MPLS encap labels, classifier mask+match
8418 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8419 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8420 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8421 += 5 * sizeof (u32x4);
8422 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8425 * Thread-safe API messages
8427 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8428 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8433 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8435 static clib_error_t *
8436 vpe_api_init (vlib_main_t * vm)
8438 vpe_api_main_t *am = &vpe_api_main;
8441 am->vnet_main = vnet_get_main ();
8442 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8443 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8444 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8445 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8446 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8447 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8450 vl_set_memory_region_name ("/vpe-api");
8451 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8456 VLIB_INIT_FUNCTION (vpe_api_init);
8459 static clib_error_t *
8460 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8463 u64 baseva, size, pvt_heap_size;
8465 const int max_buf_size = 4096;
8467 struct passwd _pw, *pw;
8468 struct group _grp, *grp;
8470 buf = vec_new (char, 128);
8471 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8473 if (unformat (input, "prefix %s", &chroot_path))
8475 vec_add1 (chroot_path, 0);
8476 vl_set_memory_root_path ((char *) chroot_path);
8478 else if (unformat (input, "uid %d", &uid))
8479 vl_set_memory_uid (uid);
8480 else if (unformat (input, "gid %d", &gid))
8481 vl_set_memory_gid (gid);
8482 else if (unformat (input, "baseva %llx", &baseva))
8483 vl_set_global_memory_baseva (baseva);
8484 else if (unformat (input, "global-size %lldM", &size))
8485 vl_set_global_memory_size (size * (1ULL << 20));
8486 else if (unformat (input, "global-size %lldG", &size))
8487 vl_set_global_memory_size (size * (1ULL << 30));
8488 else if (unformat (input, "global-size %lld", &size))
8489 vl_set_global_memory_size (size);
8490 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8491 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8492 else if (unformat (input, "global-pvt-heap-size size %lld",
8494 vl_set_global_pvt_heap_size (pvt_heap_size);
8495 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8496 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8497 else if (unformat (input, "api-pvt-heap-size size %lld",
8499 vl_set_api_pvt_heap_size (pvt_heap_size);
8500 else if (unformat (input, "api-size %lldM", &size))
8501 vl_set_api_memory_size (size * (1ULL << 20));
8502 else if (unformat (input, "api-size %lldG", &size))
8503 vl_set_api_memory_size (size * (1ULL << 30));
8504 else if (unformat (input, "api-size %lld", &size))
8505 vl_set_api_memory_size (size);
8506 else if (unformat (input, "uid %s", &s))
8508 /* lookup the username */
8511 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8512 && (vec_len (buf) <= max_buf_size))
8514 vec_resize (buf, vec_len (buf) * 2);
8518 e = clib_error_return_code (0, rv,
8519 CLIB_ERROR_ERRNO_VALID |
8521 "cannot fetch username %s", s);
8529 clib_error_return_fatal (0, "username %s does not exist", s);
8535 vl_set_memory_uid (pw->pw_uid);
8537 else if (unformat (input, "gid %s", &s))
8539 /* lookup the group name */
8542 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8543 && (vec_len (buf) <= max_buf_size))
8545 vec_resize (buf, vec_len (buf) * 2);
8549 e = clib_error_return_code (0, rv,
8550 CLIB_ERROR_ERRNO_VALID |
8552 "cannot fetch group %s", s);
8559 e = clib_error_return_fatal (0, "group %s does not exist", s);
8566 vl_set_memory_gid (grp->gr_gid);
8569 return clib_error_return (0, "unknown input `%U'",
8570 format_unformat_error, input);
8575 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8578 get_unformat_vnet_sw_interface (void)
8580 return (void *) &unformat_vnet_sw_interface;
8583 #undef vl_api_version
8584 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8585 #include <vpp-api/vpe.api.h>
8586 #undef vl_api_version
8589 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8591 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8593 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8594 clib_host_to_net_u32 (mp->api_versions[0]),
8602 format_arp_event (u8 * s, va_list * args)
8604 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8606 s = format (s, "pid %d: ", event->pid);
8608 s = format (s, "bd mac/ip4 binding events");
8610 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8615 format_nd_event (u8 * s, va_list * args)
8617 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8619 s = format (s, "pid %d: ", event->pid);
8621 s = format (s, "bd mac/ip6 binding events");
8623 s = format (s, "resolution for %U", format_ip6_address, event->address);
8627 static clib_error_t *
8628 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8629 unformat_input_t * input, vlib_cli_command_t * cmd)
8631 vpe_api_main_t *am = &vpe_api_main;
8632 vl_api_ip4_arp_event_t *arp_event;
8633 vl_api_ip6_nd_event_t *nd_event;
8635 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8637 vlib_cli_output (vm, "No active arp or nd event registrations");
8642 pool_foreach (arp_event, am->arp_events,
8644 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8647 pool_foreach (nd_event, am->nd_events,
8649 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8657 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8658 .path = "show arp-nd-event registrations",
8659 .function = show_ip_arp_nd_events_fn,
8660 .short_help = "Show ip4 arp and ip6 nd event registrations",
8665 * fd.io coding-style-patch-verification: ON
8668 * eval: (c-set-style "gnu")