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);
3999 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
4000 ip6_table_index, other_table_index);
4004 if (ip4_table_index != ~0 || ip6_table_index != ~0
4005 || other_table_index != ~0)
4010 vnet_l2_classify_enable_disable (sw_if_index, enable);
4013 BAD_SW_IF_INDEX_LABEL;
4015 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
4019 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
4022 vl_api_l2_fib_clear_table_reply_t *rmp;
4024 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
4025 * that is not currently implemented. When that TODO is fixed
4026 * this call should be changed to pass 1 instead of 0.
4028 l2fib_clear_table (0);
4030 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
4033 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
4034 u32 sw_if_index, u32 enable);
4037 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
4041 vl_api_l2_interface_efp_filter_reply_t *rmp;
4042 vnet_main_t *vnm = vnet_get_main ();
4044 // enable/disable the feature
4045 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
4046 rv = vnm->api_errno;
4048 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
4052 vl_api_l2_interface_vlan_tag_rewrite_t_handler
4053 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
4056 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
4057 vnet_main_t *vnm = vnet_get_main ();
4058 vlib_main_t *vm = vlib_get_main ();
4061 VALIDATE_SW_IF_INDEX (mp);
4063 vtr_op = ntohl (mp->vtr_op);
4065 /* The L2 code is unsuspicious */
4068 case L2_VTR_DISABLED:
4073 case L2_VTR_TRANSLATE_1_1:
4074 case L2_VTR_TRANSLATE_1_2:
4075 case L2_VTR_TRANSLATE_2_1:
4076 case L2_VTR_TRANSLATE_2_2:
4080 rv = VNET_API_ERROR_INVALID_VALUE;
4081 goto bad_sw_if_index;
4084 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4085 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4088 BAD_SW_IF_INDEX_LABEL;
4090 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4094 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4097 vl_api_create_vhost_user_if_reply_t *rmp;
4098 u32 sw_if_index = (u32) ~ 0;
4100 vnet_main_t *vnm = vnet_get_main ();
4101 vlib_main_t *vm = vlib_get_main ();
4103 #if DPDK > 0 && DPDK_VHOST_USER
4104 rv = dpdk_vhost_user_create_if (
4106 rv = vhost_user_create_if (
4108 vnm, vm, (char *) mp->sock_filename,
4109 mp->is_server, &sw_if_index, (u64) ~ 0,
4110 mp->renumber, ntohl (mp->custom_dev_instance),
4111 (mp->use_custom_mac) ? mp->mac_address : NULL);
4114 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4116 rmp->sw_if_index = ntohl (sw_if_index);
4122 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4125 vl_api_modify_vhost_user_if_reply_t *rmp;
4126 u32 sw_if_index = ntohl (mp->sw_if_index);
4128 vnet_main_t *vnm = vnet_get_main ();
4129 vlib_main_t *vm = vlib_get_main ();
4131 #if DPDK > 0 && DPDK_VHOST_USER
4132 rv = dpdk_vhost_user_modify_if (
4134 rv = vhost_user_modify_if (
4136 vnm, vm, (char *) mp->sock_filename,
4137 mp->is_server, sw_if_index, (u64) ~ 0,
4138 mp->renumber, ntohl (mp->custom_dev_instance));
4139 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4143 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4146 vl_api_delete_vhost_user_if_reply_t *rmp;
4147 vpe_api_main_t *vam = &vpe_api_main;
4148 u32 sw_if_index = ntohl (mp->sw_if_index);
4150 vnet_main_t *vnm = vnet_get_main ();
4151 vlib_main_t *vm = vlib_get_main ();
4153 #if DPDK > 0 && DPDK_VHOST_USER
4154 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4156 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4159 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4162 unix_shared_memory_queue_t *q =
4163 vl_api_client_index_to_input_queue (mp->client_index);
4167 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4172 vl_api_sw_interface_vhost_user_details_t_handler
4173 (vl_api_sw_interface_vhost_user_details_t * mp)
4175 clib_warning ("BUG");
4179 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4180 unix_shared_memory_queue_t * q,
4181 vhost_user_intf_details_t * vui,
4184 vl_api_sw_interface_vhost_user_details_t *mp;
4186 mp = vl_msg_api_alloc (sizeof (*mp));
4187 memset (mp, 0, sizeof (*mp));
4188 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4189 mp->sw_if_index = ntohl (vui->sw_if_index);
4190 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4191 mp->features = clib_net_to_host_u64 (vui->features);
4192 mp->is_server = vui->is_server;
4193 mp->num_regions = ntohl (vui->num_regions);
4194 mp->sock_errno = ntohl (vui->sock_errno);
4195 mp->context = context;
4197 strncpy ((char *) mp->sock_filename,
4198 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4199 strncpy ((char *) mp->interface_name,
4200 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4202 vl_msg_api_send_shmem (q, (u8 *) & mp);
4206 vl_api_sw_interface_vhost_user_dump_t_handler
4207 (vl_api_sw_interface_vhost_user_dump_t * mp)
4210 vpe_api_main_t *am = &vpe_api_main;
4211 vnet_main_t *vnm = vnet_get_main ();
4212 vlib_main_t *vm = vlib_get_main ();
4213 vhost_user_intf_details_t *ifaces = NULL;
4214 vhost_user_intf_details_t *vuid = NULL;
4215 unix_shared_memory_queue_t *q;
4217 q = vl_api_client_index_to_input_queue (mp->client_index);
4221 #if DPDK > 0 && DPDK_VHOST_USER
4222 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4224 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4229 vec_foreach (vuid, ifaces)
4231 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4237 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4238 unix_shared_memory_queue_t * q,
4240 l2t_main_t * lm, u32 context)
4242 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4244 vnet_sw_interface_t *si = NULL;
4246 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4248 if_name = format (if_name, "%U",
4249 format_vnet_sw_interface_name, lm->vnet_main, si);
4251 mp = vl_msg_api_alloc (sizeof (*mp));
4252 memset (mp, 0, sizeof (*mp));
4253 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4254 strncpy ((char *) mp->interface_name,
4255 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4256 mp->sw_if_index = ntohl (si->sw_if_index);
4257 mp->local_session_id = s->local_session_id;
4258 mp->remote_session_id = s->remote_session_id;
4259 mp->local_cookie[0] = s->local_cookie[0];
4260 mp->local_cookie[1] = s->local_cookie[1];
4261 mp->remote_cookie = s->remote_cookie;
4262 clib_memcpy (mp->client_address, &s->client_address,
4263 sizeof (s->client_address));
4264 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4265 mp->l2_sublayer_present = s->l2_sublayer_present;
4266 mp->context = context;
4268 vl_msg_api_send_shmem (q, (u8 *) & mp);
4272 send_ip_address_details (vpe_api_main_t * am,
4273 unix_shared_memory_queue_t * q,
4274 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4276 vl_api_ip_address_details_t *mp;
4278 mp = vl_msg_api_alloc (sizeof (*mp));
4279 memset (mp, 0, sizeof (*mp));
4280 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4284 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4288 u32 *tp = (u32 *) mp->ip;
4289 *tp = ntohl (*(u32 *) ip);
4291 mp->prefix_length = prefix_length;
4292 mp->context = context;
4294 vl_msg_api_send_shmem (q, (u8 *) & mp);
4298 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4300 vpe_api_main_t *am = &vpe_api_main;
4301 unix_shared_memory_queue_t *q;
4304 ip6_main_t *im6 = &ip6_main;
4305 ip4_main_t *im4 = &ip4_main;
4306 ip_lookup_main_t *lm6 = &im6->lookup_main;
4307 ip_lookup_main_t *lm4 = &im4->lookup_main;
4308 ip_interface_address_t *ia = 0;
4309 u32 sw_if_index = ~0;
4310 int rv __attribute__ ((unused)) = 0;
4312 VALIDATE_SW_IF_INDEX (mp);
4314 sw_if_index = ntohl (mp->sw_if_index);
4316 q = vl_api_client_index_to_input_queue (mp->client_index);
4325 foreach_ip_interface_address (lm6, ia, sw_if_index,
4326 1 /* honor unnumbered */,
4328 r6 = ip_interface_address_get_address (lm6, ia);
4329 u16 prefix_length = ia->address_length;
4330 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4337 foreach_ip_interface_address (lm4, ia, sw_if_index,
4338 1 /* honor unnumbered */,
4340 r4 = ip_interface_address_get_address (lm4, ia);
4341 u16 prefix_length = ia->address_length;
4342 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4346 BAD_SW_IF_INDEX_LABEL;
4350 send_ip_details (vpe_api_main_t * am,
4351 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4353 vl_api_ip_details_t *mp;
4355 mp = vl_msg_api_alloc (sizeof (*mp));
4356 memset (mp, 0, sizeof (*mp));
4357 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4359 mp->sw_if_index = ntohl (sw_if_index);
4360 mp->context = context;
4362 vl_msg_api_send_shmem (q, (u8 *) & mp);
4366 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4369 vpe_api_main_t *am = &vpe_api_main;
4370 l2t_main_t *lm = &l2t_main;
4371 unix_shared_memory_queue_t *q;
4372 l2t_session_t *session;
4374 q = vl_api_client_index_to_input_queue (mp->client_index);
4379 pool_foreach (session, lm->sessions,
4381 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4388 send_sw_interface_tap_details (vpe_api_main_t * am,
4389 unix_shared_memory_queue_t * q,
4390 tapcli_interface_details_t * tap_if,
4393 vl_api_sw_interface_tap_details_t *mp;
4394 mp = vl_msg_api_alloc (sizeof (*mp));
4395 memset (mp, 0, sizeof (*mp));
4396 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4397 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4398 strncpy ((char *) mp->dev_name,
4399 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4400 mp->context = context;
4402 vl_msg_api_send_shmem (q, (u8 *) & mp);
4406 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4409 vpe_api_main_t *am = &vpe_api_main;
4410 unix_shared_memory_queue_t *q;
4411 tapcli_interface_details_t *tapifs = NULL;
4412 tapcli_interface_details_t *tap_if = NULL;
4414 q = vl_api_client_index_to_input_queue (mp->client_index);
4418 rv = vnet_tap_dump_ifs (&tapifs);
4422 vec_foreach (tap_if, tapifs)
4424 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4431 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4433 vpe_api_main_t *am = &vpe_api_main;
4434 vnet_main_t *vnm = vnet_get_main ();
4435 vlib_main_t *vm = vlib_get_main ();
4436 vnet_interface_main_t *im = &vnm->interface_main;
4437 unix_shared_memory_queue_t *q;
4438 vnet_sw_interface_t *si, *sorted_sis;
4439 u32 sw_if_index = ~0;
4441 q = vl_api_client_index_to_input_queue (mp->client_index);
4447 /* Gather interfaces. */
4448 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4449 _vec_len (sorted_sis) = 0;
4451 pool_foreach (si, im->sw_interfaces,
4453 vec_add1 (sorted_sis, si[0]);
4457 vec_foreach (si, sorted_sis)
4459 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4461 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4465 sw_if_index = si->sw_if_index;
4466 send_ip_details (am, q, sw_if_index, mp->context);
4472 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4474 clib_warning ("BUG");
4478 send_l2fib_table_entry (vpe_api_main_t * am,
4479 unix_shared_memory_queue_t * q,
4480 l2fib_entry_key_t * l2fe_key,
4481 l2fib_entry_result_t * l2fe_res, u32 context)
4483 vl_api_l2_fib_table_entry_t *mp;
4485 mp = vl_msg_api_alloc (sizeof (*mp));
4486 memset (mp, 0, sizeof (*mp));
4487 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4490 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4492 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4493 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4494 mp->static_mac = l2fe_res->fields.static_mac;
4495 mp->filter_mac = l2fe_res->fields.filter;
4496 mp->bvi_mac = l2fe_res->fields.bvi;
4497 mp->context = context;
4499 vl_msg_api_send_shmem (q, (u8 *) & mp);
4503 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4505 vpe_api_main_t *am = &vpe_api_main;
4506 bd_main_t *bdm = &bd_main;
4507 l2fib_entry_key_t *l2fe_key = NULL;
4508 l2fib_entry_result_t *l2fe_res = NULL;
4509 u32 ni, bd_id = ntohl (mp->bd_id);
4511 unix_shared_memory_queue_t *q;
4514 q = vl_api_client_index_to_input_queue (mp->client_index);
4518 /* see l2fib_table_dump: ~0 means "any" */
4523 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4530 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4532 vec_foreach_index (ni, l2fe_key)
4534 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4535 vec_elt_at_index (l2fe_res, ni), mp->context);
4537 vec_free (l2fe_key);
4538 vec_free (l2fe_res);
4542 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4544 vl_api_show_version_reply_t *rmp;
4546 char *vpe_api_get_build_directory (void);
4547 char *vpe_api_get_version (void);
4548 char *vpe_api_get_build_date (void);
4550 unix_shared_memory_queue_t *q =
4551 vl_api_client_index_to_input_queue (mp->client_index);
4557 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4559 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4560 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4561 ARRAY_LEN(rmp->build_directory)-1);
4562 strncpy ((char *) rmp->version, vpe_api_get_version(),
4563 ARRAY_LEN(rmp->version)-1);
4564 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4565 ARRAY_LEN(rmp->build_date)-1);
4571 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4573 vlib_main_t *vm = vlib_get_main ();
4574 vl_api_get_node_index_reply_t *rmp;
4577 u32 node_index = ~0;
4579 n = vlib_get_node_by_name (vm, mp->node_name);
4582 rv = VNET_API_ERROR_NO_SUCH_NODE;
4584 node_index = n->index;
4587 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4589 rmp->node_index = ntohl(node_index);
4595 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4597 vlib_main_t *vm = vlib_get_main ();
4598 vl_api_get_next_index_reply_t *rmp;
4599 vlib_node_t *node, *next_node;
4601 u32 next_node_index = ~0, next_index = ~0;
4604 node = vlib_get_node_by_name (vm, mp->node_name);
4608 rv = VNET_API_ERROR_NO_SUCH_NODE;
4612 next_node = vlib_get_node_by_name (vm, mp->next_name);
4616 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4620 next_node_index = next_node->index;
4622 p = hash_get (node->next_slot_by_node, next_node_index);
4626 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4634 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4636 rmp->next_index = ntohl(next_index);
4642 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4644 vlib_main_t *vm = vlib_get_main ();
4645 vl_api_add_node_next_reply_t *rmp;
4646 vlib_node_t *n, *next;
4648 u32 next_index = ~0;
4650 n = vlib_get_node_by_name (vm, mp->node_name);
4654 rv = VNET_API_ERROR_NO_SUCH_NODE;
4658 next = vlib_get_node_by_name (vm, mp->next_name);
4661 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4663 next_index = vlib_node_add_next (vm, n->index, next->index);
4667 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4669 rmp->next_index = ntohl(next_index);
4674 static void vl_api_l2tpv3_create_tunnel_t_handler
4675 (vl_api_l2tpv3_create_tunnel_t * mp)
4677 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4678 l2t_main_t *lm = &l2t_main;
4679 u32 sw_if_index = (u32) ~ 0;
4682 if (mp->is_ipv6 != 1)
4684 rv = VNET_API_ERROR_UNIMPLEMENTED;
4688 u32 encap_fib_index;
4690 if (mp->encap_vrf_id != ~0)
4693 ip6_main_t *im = &ip6_main;
4696 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4698 rv = VNET_API_ERROR_NO_SUCH_FIB;
4701 encap_fib_index = p[0];
4705 encap_fib_index = ~0;
4708 rv = create_l2tpv3_ipv6_tunnel (lm,
4709 (ip6_address_t *) mp->client_address,
4710 (ip6_address_t *) mp->our_address,
4711 ntohl (mp->local_session_id),
4712 ntohl (mp->remote_session_id),
4713 clib_net_to_host_u64 (mp->local_cookie),
4714 clib_net_to_host_u64 (mp->remote_cookie),
4715 mp->l2_sublayer_present,
4716 encap_fib_index, &sw_if_index);
4720 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4722 rmp->sw_if_index = ntohl (sw_if_index);
4727 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4728 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4730 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4731 l2t_main_t *lm = &l2t_main;
4734 VALIDATE_SW_IF_INDEX (mp);
4736 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4737 clib_net_to_host_u64 (mp->new_local_cookie),
4738 clib_net_to_host_u64
4739 (mp->new_remote_cookie));
4741 BAD_SW_IF_INDEX_LABEL;
4743 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4746 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4747 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4750 vnet_main_t *vnm = vnet_get_main ();
4751 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4753 VALIDATE_SW_IF_INDEX (mp);
4755 rv = l2tpv3_interface_enable_disable
4756 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4758 BAD_SW_IF_INDEX_LABEL;
4760 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4763 static void vl_api_l2tpv3_set_lookup_key_t_handler
4764 (vl_api_l2tpv3_set_lookup_key_t * mp)
4767 l2t_main_t *lm = &l2t_main;
4768 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4770 if (mp->key > L2T_LOOKUP_SESSION_ID)
4772 rv = VNET_API_ERROR_INVALID_VALUE;
4776 lm->lookup_type = mp->key;
4779 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4782 static void vl_api_vxlan_add_del_tunnel_t_handler
4783 (vl_api_vxlan_add_del_tunnel_t * mp)
4785 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4787 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4788 u32 encap_fib_index;
4790 ip4_main_t *im = &ip4_main;
4791 u32 sw_if_index = ~0;
4793 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4796 rv = VNET_API_ERROR_NO_SUCH_FIB;
4799 encap_fib_index = p[0];
4801 /* Check src & dst are different */
4802 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4803 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4805 rv = VNET_API_ERROR_SAME_SRC_DST;
4808 memset (a, 0, sizeof (*a));
4810 a->is_add = mp->is_add;
4811 a->is_ip6 = mp->is_ipv6;
4813 /* ip addresses sent in network byte order */
4816 memcpy (&(a->src.ip6), mp->src_address, 16);
4817 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4821 memcpy (&(a->src.ip4), mp->src_address, 4);
4822 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4825 a->encap_fib_index = encap_fib_index;
4826 a->decap_next_index = ntohl (mp->decap_next_index);
4827 a->vni = ntohl (mp->vni);
4828 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4832 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4834 rmp->sw_if_index = ntohl (sw_if_index);
4839 static void send_vxlan_tunnel_details
4840 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4842 vl_api_vxlan_tunnel_details_t *rmp;
4843 ip4_main_t *im4 = &ip4_main;
4844 ip6_main_t *im6 = &ip6_main;
4845 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4847 rmp = vl_msg_api_alloc (sizeof (*rmp));
4848 memset (rmp, 0, sizeof (*rmp));
4849 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4852 memcpy (rmp->src_address, &(t->src.ip6), 16);
4853 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4854 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
4858 memcpy (rmp->src_address, &(t->src.ip4), 4);
4859 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4860 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
4862 rmp->vni = htonl (t->vni);
4863 rmp->decap_next_index = htonl (t->decap_next_index);
4864 rmp->sw_if_index = htonl (t->sw_if_index);
4865 rmp->is_ipv6 = is_ipv6;
4866 rmp->context = context;
4868 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4871 static void vl_api_vxlan_tunnel_dump_t_handler
4872 (vl_api_vxlan_tunnel_dump_t * mp)
4874 unix_shared_memory_queue_t *q;
4875 vxlan_main_t *vxm = &vxlan_main;
4879 q = vl_api_client_index_to_input_queue (mp->client_index);
4885 sw_if_index = ntohl (mp->sw_if_index);
4887 if (~0 == sw_if_index)
4890 pool_foreach (t, vxm->tunnels,
4892 send_vxlan_tunnel_details(t, q, mp->context);
4898 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4899 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4903 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4904 send_vxlan_tunnel_details (t, q, mp->context);
4908 static void vl_api_gre_add_del_tunnel_t_handler
4909 (vl_api_gre_add_del_tunnel_t * mp)
4911 vl_api_gre_add_del_tunnel_reply_t *rmp;
4913 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4916 ip4_main_t *im = &ip4_main;
4917 u32 sw_if_index = ~0;
4919 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4922 rv = VNET_API_ERROR_NO_SUCH_FIB;
4925 outer_fib_id = p[0];
4927 /* Check src & dst are different */
4928 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4929 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4931 rv = VNET_API_ERROR_SAME_SRC_DST;
4934 memset (a, 0, sizeof (*a));
4936 a->is_add = mp->is_add;
4938 /* ip addresses sent in network byte order */
4939 clib_memcpy (&(a->src), mp->src_address, 4);
4940 clib_memcpy (&(a->dst), mp->dst_address, 4);
4942 a->outer_fib_id = outer_fib_id;
4943 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4947 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4949 rmp->sw_if_index = ntohl (sw_if_index);
4954 static void send_gre_tunnel_details
4955 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4957 vl_api_gre_tunnel_details_t *rmp;
4958 ip4_main_t *im = &ip4_main;
4960 rmp = vl_msg_api_alloc (sizeof (*rmp));
4961 memset (rmp, 0, sizeof (*rmp));
4962 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
4963 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
4964 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
4965 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
4966 rmp->sw_if_index = htonl (t->sw_if_index);
4967 rmp->context = context;
4969 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4973 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
4975 unix_shared_memory_queue_t *q;
4976 gre_main_t *gm = &gre_main;
4980 q = vl_api_client_index_to_input_queue (mp->client_index);
4986 sw_if_index = ntohl (mp->sw_if_index);
4988 if (~0 == sw_if_index)
4991 pool_foreach (t, gm->tunnels,
4993 send_gre_tunnel_details(t, q, mp->context);
4999 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
5000 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
5004 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
5005 send_gre_tunnel_details (t, q, mp->context);
5010 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
5012 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5014 vl_api_l2_patch_add_del_reply_t *rmp;
5015 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5019 VALIDATE_RX_SW_IF_INDEX (mp);
5020 VALIDATE_TX_SW_IF_INDEX (mp);
5022 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
5023 ntohl (mp->tx_sw_if_index),
5024 (int) (mp->is_add != 0));
5026 BAD_RX_SW_IF_INDEX_LABEL;
5027 BAD_TX_SW_IF_INDEX_LABEL;
5029 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
5033 vl_api_vxlan_gpe_add_del_tunnel_t_handler
5034 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
5036 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
5038 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
5039 u32 encap_fib_index, decap_fib_index;
5042 ip4_main_t *im = &ip4_main;
5043 u32 sw_if_index = ~0;
5046 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
5049 rv = VNET_API_ERROR_NO_SUCH_FIB;
5052 encap_fib_index = p[0];
5054 protocol = mp->protocol;
5056 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
5057 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
5059 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
5062 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
5065 decap_fib_index = p[0];
5069 decap_fib_index = ntohl (mp->decap_vrf_id);
5072 /* Check src & dst are different */
5073 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5074 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5076 rv = VNET_API_ERROR_SAME_SRC_DST;
5079 memset (a, 0, sizeof (*a));
5081 a->is_add = mp->is_add;
5082 a->is_ip6 = mp->is_ipv6;
5083 /* ip addresses sent in network byte order */
5086 clib_memcpy (&(a->local.ip6), mp->local, 16);
5087 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5091 clib_memcpy (&(a->local.ip4), mp->local, 4);
5092 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5094 a->encap_fib_index = encap_fib_index;
5095 a->decap_fib_index = decap_fib_index;
5096 a->protocol = protocol;
5097 a->vni = ntohl (mp->vni);
5098 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5102 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5104 rmp->sw_if_index = ntohl (sw_if_index);
5109 static void send_vxlan_gpe_tunnel_details
5110 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5112 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5113 ip4_main_t *im4 = &ip4_main;
5114 ip6_main_t *im6 = &ip6_main;
5115 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5117 rmp = vl_msg_api_alloc (sizeof (*rmp));
5118 memset (rmp, 0, sizeof (*rmp));
5119 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5122 memcpy (rmp->local, &(t->local.ip6), 16);
5123 memcpy (rmp->remote, &(t->remote.ip6), 16);
5124 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
5125 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].table_id);
5129 memcpy (rmp->local, &(t->local.ip4), 4);
5130 memcpy (rmp->remote, &(t->remote.ip4), 4);
5131 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
5132 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].table_id);
5134 rmp->vni = htonl (t->vni);
5135 rmp->protocol = t->protocol;
5136 rmp->sw_if_index = htonl (t->sw_if_index);
5137 rmp->is_ipv6 = is_ipv6;
5138 rmp->context = context;
5140 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5143 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5144 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5146 unix_shared_memory_queue_t *q;
5147 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5148 vxlan_gpe_tunnel_t *t;
5151 q = vl_api_client_index_to_input_queue (mp->client_index);
5157 sw_if_index = ntohl (mp->sw_if_index);
5159 if (~0 == sw_if_index)
5162 pool_foreach (t, vgm->tunnels,
5164 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5170 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5171 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5175 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5176 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5180 /** Used for transferring locators via VPP API */
5182 typedef CLIB_PACKED (struct {
5183 u32 sw_if_index; /**< locator sw_if_index */
5184 u8 priority; /**< locator priority */
5185 u8 weight; /**< locator weight */
5190 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5193 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5195 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5197 ls_locator_t *ls_loc;
5198 u32 ls_index = ~0, locator_num;
5199 u8 *locator_name = NULL;
5202 memset (a, 0, sizeof (a[0]));
5204 locator_name = format (0, "%s", mp->locator_set_name);
5206 a->name = locator_name;
5207 a->is_add = mp->is_add;
5209 locator_num = clib_net_to_host_u32 (mp->locator_num);
5211 memset (&locator, 0, sizeof (locator));
5212 for (i = 0; i < locator_num; i++)
5214 ls_loc = &((ls_locator_t *) mp->locators)[i];
5215 VALIDATE_SW_IF_INDEX (ls_loc);
5217 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5218 locator.priority = ls_loc->priority;
5219 locator.weight = ls_loc->weight;
5221 vec_add1 (a->locators, locator);
5224 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5226 BAD_SW_IF_INDEX_LABEL;
5228 vec_free (locator_name);
5229 vec_free (a->locators);
5232 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5234 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5240 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5242 vl_api_lisp_add_del_locator_reply_t *rmp;
5244 locator_t locator, *locators = NULL;
5245 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5247 u8 *locator_name = NULL;
5249 memset (&locator, 0, sizeof (locator));
5250 memset (a, 0, sizeof (a[0]));
5252 locator.sw_if_index = ntohl (mp->sw_if_index);
5253 locator.priority = mp->priority;
5254 locator.weight = mp->weight;
5256 vec_add1 (locators, locator);
5258 locator_name = format (0, "%s", mp->locator_set_name);
5260 a->name = locator_name;
5261 a->locators = locators;
5262 a->is_add = mp->is_add;
5265 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5267 vec_free (locators);
5268 vec_free (locator_name);
5270 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5274 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5280 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5281 gid_address_ip_set (dst, src, IP4);
5282 gid_address_ippref_len (dst) = len;
5283 ip_prefix_normalize (&gid_address_ippref (dst));
5286 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5287 gid_address_ip_set (dst, src, IP6);
5288 gid_address_ippref_len (dst) = len;
5289 ip_prefix_normalize (&gid_address_ippref (dst));
5291 case 2: /* l2 mac */
5292 gid_address_type (dst) = GID_ADDR_MAC;
5293 clib_memcpy (&gid_address_mac (dst), src, 6);
5297 return VNET_API_ERROR_INVALID_VALUE;
5300 gid_address_vni (dst) = vni;
5306 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5308 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5309 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5311 gid_address_t _eid, *eid = &_eid;
5313 u32 locator_set_index = ~0, map_index = ~0;
5314 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5316 memset (a, 0, sizeof (a[0]));
5317 memset (eid, 0, sizeof (eid[0]));
5319 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5320 mp->eid_type, mp->eid, mp->prefix_len);
5324 name = format (0, "%s", mp->locator_set_name);
5325 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5328 rv = VNET_API_ERROR_INVALID_VALUE;
5331 locator_set_index = p[0];
5333 /* XXX treat batch configuration */
5334 a->is_add = mp->is_add;
5335 gid_address_copy (&a->eid, eid);
5336 a->locator_set_index = locator_set_index;
5338 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5342 gid_address_free (&a->eid);
5344 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5348 vl_api_lisp_eid_table_add_del_map_t_handler
5349 (vl_api_lisp_eid_table_add_del_map_t * mp)
5351 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5353 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5354 clib_net_to_host_u32 (mp->dp_table),
5355 mp->is_l2, mp->is_add);
5356 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5358 /** Used for transferring locators via VPP API */
5360 typedef CLIB_PACKED (struct {
5361 u8 is_ip4; /**< is locator an IPv4 address */
5362 u8 priority; /**< locator priority */
5363 u8 weight; /**< locator weight */
5364 u8 addr[16]; /**< IPv4/IPv6 address */
5368 static locator_pair_t *
5369 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5372 locator_pair_t *pairs = 0, pair;
5375 for (i = 0; i < rloc_num; i++)
5378 r = &((rloc_t *) lcl_locs)[i];
5379 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5380 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5382 /* remote locators */
5383 r = &((rloc_t *) rmt_locs)[i];
5384 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5385 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5387 pair.priority = r->priority;
5388 pair.weight = r->weight;
5390 vec_add1 (pairs, pair);
5396 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5399 locator_t *locs = 0, loc;
5402 for (i = 0; i < rloc_num; i++)
5404 /* remote locators */
5405 r = &((rloc_t *) rmt_locs)[i];
5406 memset (&loc, 0, sizeof (loc));
5407 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5409 loc.priority = r->priority;
5410 loc.weight = r->weight;
5412 vec_add1 (locs, loc);
5418 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5419 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5421 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5422 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5423 locator_pair_t *pairs = 0;
5426 memset (a, 0, sizeof (a[0]));
5428 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5429 mp->rmt_eid, mp->rmt_len);
5430 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5431 mp->lcl_eid, mp->lcl_len);
5433 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5435 if (rv || 0 == pairs)
5438 a->is_add = mp->is_add;
5439 a->locator_pairs = pairs;
5440 a->dp_table = mp->dp_table;
5442 a->action = mp->action;
5444 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5447 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5451 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5454 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5456 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5458 memset (a, 0, sizeof (a[0]));
5460 a->is_add = mp->is_add;
5461 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5463 rv = vnet_lisp_add_del_map_resolver (a);
5465 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5469 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5472 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5474 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5476 a->is_en = mp->is_en;
5477 vnet_lisp_gpe_enable_disable (a);
5479 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5483 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5485 vl_api_lisp_enable_disable_reply_t *rmp;
5488 vnet_lisp_enable_disable (mp->is_en);
5489 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5493 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5495 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5497 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5499 a->is_add = mp->is_add;
5500 a->dp_table = mp->dp_table;
5502 a->is_l2 = mp->is_l2;
5503 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5505 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5509 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5512 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5516 ls_name = format (0, "%s", mp->ls_name);
5517 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5520 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5524 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5525 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5527 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5529 u8 *locator_set_name = NULL;
5530 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5532 locator_set_name = format (0, "%s", mp->locator_set_name);
5534 a->is_add = mp->is_add;
5535 a->locator_set_name = locator_set_name;
5537 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5539 vec_free (locator_set_name);
5541 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5545 vl_api_lisp_add_del_remote_mapping_t_handler
5546 (vl_api_lisp_add_del_remote_mapping_t * mp)
5548 locator_t *rlocs = 0;
5549 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5551 gid_address_t _eid, *eid = &_eid;
5552 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5554 memset (eid, 0, sizeof (eid[0]));
5556 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5557 mp->eid_type, mp->eid, mp->eid_len);
5561 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5565 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5566 gid_address_copy (&a->deid, eid);
5568 rv = vnet_lisp_add_del_adjacency (a);
5575 /* NOTE: for now this works as a static remote mapping, i.e.,
5576 * not authoritative and ttl infinite. */
5577 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5578 mp->is_add, 1 /* is_static */ , 0);
5581 vnet_lisp_clear_all_remote_adjacencies ();
5586 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5590 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5592 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5593 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5596 memset (a, 0, sizeof (a[0]));
5598 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5599 mp->eid_type, mp->seid, mp->seid_len);
5600 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5601 mp->eid_type, mp->deid, mp->deid_len);
5606 a->is_add = mp->is_add;
5607 rv = vnet_lisp_add_del_adjacency (a);
5610 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5614 send_lisp_locator_details (lisp_cp_main_t * lcm,
5616 unix_shared_memory_queue_t * q, u32 context)
5618 vl_api_lisp_locator_details_t *rmp;
5620 rmp = vl_msg_api_alloc (sizeof (*rmp));
5621 memset (rmp, 0, sizeof (*rmp));
5622 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5623 rmp->context = context;
5625 rmp->local = loc->local;
5628 rmp->sw_if_index = ntohl (loc->sw_if_index);
5632 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5633 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5635 rmp->priority = loc->priority;
5636 rmp->weight = loc->weight;
5638 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5642 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5644 unix_shared_memory_queue_t *q = 0;
5645 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5646 locator_set_t *lsit = 0;
5648 u32 ls_index = ~0, *locit = 0;
5651 q = vl_api_client_index_to_input_queue (mp->client_index);
5657 ls_index = htonl (mp->locator_set_index);
5659 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5661 filter = mp->filter;
5662 if (filter && !((1 == filter && lsit->local) ||
5663 (2 == filter && !lsit->local)))
5668 vec_foreach (locit, lsit->locator_indices)
5670 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5671 send_lisp_locator_details (lcm, loc, q, mp->context);
5676 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5677 locator_set_t * lsit,
5678 unix_shared_memory_queue_t * q,
5679 u32 context, u32 ls_index)
5681 vl_api_lisp_locator_set_details_t *rmp;
5684 rmp = vl_msg_api_alloc (sizeof (*rmp));
5685 memset (rmp, 0, sizeof (*rmp));
5686 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5687 rmp->context = context;
5689 rmp->local = lsit->local;
5690 rmp->locator_set_index = htonl (ls_index);
5693 ASSERT (lsit->name != NULL);
5694 strncpy ((char *) rmp->locator_set_name,
5695 (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1);
5699 str = format (0, "remote-%d", ls_index);
5700 strncpy ((char *) rmp->locator_set_name, (char *) str,
5701 ARRAY_LEN (rmp->locator_set_name) - 1);
5705 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5709 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5711 unix_shared_memory_queue_t *q = NULL;
5712 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5713 locator_set_t *lsit = NULL;
5717 q = vl_api_client_index_to_input_queue (mp->client_index);
5723 filter = mp->filter;
5726 pool_foreach (lsit, lcm->locator_set_pool,
5728 if (filter && !((1 == filter && lsit->local) ||
5729 (2 == filter && !lsit->local))) {
5733 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5739 send_lisp_eid_table_details (mapping_t * mapit,
5740 unix_shared_memory_queue_t * q,
5741 u32 context, u8 filter)
5743 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5744 locator_set_t *ls = 0;
5745 vl_api_lisp_eid_table_details_t *rmp = NULL;
5746 gid_address_t *gid = NULL;
5748 ip_prefix_t *ip_prefix = NULL;
5752 case 0: /* all mappings */
5755 case 1: /* local only */
5759 case 2: /* remote only */
5764 clib_warning ("Filter error, unknown filter: %d", filter);
5769 ip_prefix = &gid_address_ippref (gid);
5770 mac = gid_address_mac (gid);
5772 rmp = vl_msg_api_alloc (sizeof (*rmp));
5773 memset (rmp, 0, sizeof (*rmp));
5774 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5776 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5777 if (vec_len (ls->locator_indices) == 0)
5778 rmp->locator_set_index = ~0;
5780 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5782 rmp->is_local = mapit->local;
5783 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5784 rmp->action = mapit->action;
5785 rmp->authoritative = mapit->authoritative;
5787 switch (gid_address_type (gid))
5789 case GID_ADDR_IP_PREFIX:
5790 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5791 if (ip_prefix_version (ip_prefix) == IP4)
5793 rmp->eid_type = 0; /* ipv4 type */
5794 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5795 sizeof (ip_prefix_v4 (ip_prefix)));
5799 rmp->eid_type = 1; /* ipv6 type */
5800 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5801 sizeof (ip_prefix_v6 (ip_prefix)));
5805 rmp->eid_type = 2; /* l2 mac type */
5806 clib_memcpy (rmp->eid, mac, 6);
5811 rmp->context = context;
5812 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5813 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5817 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5820 unix_shared_memory_queue_t *q = NULL;
5821 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5822 mapping_t *mapit = NULL;
5823 gid_address_t _eid, *eid = &_eid;
5825 q = vl_api_client_index_to_input_queue (mp->client_index);
5833 memset (eid, 0, sizeof (*eid));
5835 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5836 mp->eid_type, mp->eid, mp->prefix_length);
5838 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5839 if ((u32) ~ 0 == mi)
5842 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5843 send_lisp_eid_table_details (mapit, q, mp->context,
5844 0 /* ignore filter */ );
5849 pool_foreach (mapit, lcm->mapping_pool,
5851 send_lisp_eid_table_details(mapit, q, mp->context,
5859 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5860 unix_shared_memory_queue_t * q, u32 context)
5862 vl_api_lisp_gpe_tunnel_details_t *rmp;
5863 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5865 rmp = vl_msg_api_alloc (sizeof (*rmp));
5866 memset (rmp, 0, sizeof (*rmp));
5867 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5869 rmp->tunnels = tunnel - lgm->tunnels;
5871 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5872 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5873 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5875 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5876 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5877 rmp->dcap_next = htonl (tunnel->decap_next_index);
5878 rmp->lisp_ver = tunnel->ver_res;
5879 rmp->next_protocol = tunnel->next_protocol;
5880 rmp->flags = tunnel->flags;
5881 rmp->ver_res = tunnel->ver_res;
5882 rmp->res = tunnel->res;
5883 rmp->iid = htonl (tunnel->vni);
5884 rmp->context = context;
5886 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5890 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5892 unix_shared_memory_queue_t *q = NULL;
5893 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5894 lisp_gpe_tunnel_t *tunnel = NULL;
5896 if (pool_elts (lgm->tunnels) == 0)
5901 q = vl_api_client_index_to_input_queue (mp->client_index);
5908 pool_foreach(tunnel, lgm->tunnels,
5910 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5916 send_lisp_map_resolver_details (ip_address_t * ip,
5917 unix_shared_memory_queue_t * q, u32 context)
5919 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5921 rmp = vl_msg_api_alloc (sizeof (*rmp));
5922 memset (rmp, 0, sizeof (*rmp));
5923 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5925 switch (ip_addr_version (ip))
5929 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5930 sizeof (ip_addr_v4 (ip)));
5935 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
5936 sizeof (ip_addr_v6 (ip)));
5942 rmp->context = context;
5944 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5948 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
5950 unix_shared_memory_queue_t *q = NULL;
5951 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5954 q = vl_api_client_index_to_input_queue (mp->client_index);
5960 vec_foreach (mr, lcm->map_resolvers)
5962 send_lisp_map_resolver_details (&mr->address, q, mp->context);
5967 send_eid_table_map_pair (hash_pair_t * p,
5968 unix_shared_memory_queue_t * q, u32 context)
5970 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
5972 rmp = vl_msg_api_alloc (sizeof (*rmp));
5973 memset (rmp, 0, sizeof (*rmp));
5974 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
5976 rmp->vni = clib_host_to_net_u32 (p->key);
5977 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
5978 rmp->context = context;
5979 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5983 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
5986 unix_shared_memory_queue_t *q = NULL;
5987 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5989 uword *vni_table = 0;
5991 q = vl_api_client_index_to_input_queue (mp->client_index);
5999 vni_table = lcm->bd_id_by_vni;
6003 vni_table = lcm->table_id_by_vni;
6007 hash_foreach_pair (p, vni_table,
6009 send_eid_table_map_pair (p, q, mp->context);
6015 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6017 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6019 rmp = vl_msg_api_alloc (sizeof (*rmp));
6020 memset (rmp, 0, sizeof (*rmp));
6021 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6022 rmp->context = context;
6023 rmp->vni = clib_host_to_net_u32 (vni);
6024 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6028 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6033 unix_shared_memory_queue_t *q = 0;
6034 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6036 q = vl_api_client_index_to_input_queue (mp->client_index);
6043 hash_foreach_pair (p, lcm->table_id_by_vni,
6045 hash_set (vnis, p->key, 0);
6048 hash_foreach_pair (p, lcm->bd_id_by_vni,
6050 hash_set (vnis, p->key, 0);
6053 hash_foreach_pair (p, vnis,
6055 send_eid_table_vni (p->key, q, mp->context);
6063 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6065 unix_shared_memory_queue_t *q = NULL;
6066 vl_api_show_lisp_status_reply_t *rmp = NULL;
6069 q = vl_api_client_index_to_input_queue (mp->client_index);
6076 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6078 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6079 rmp->feature_status = vnet_lisp_enable_disable_status ();
6085 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6086 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6088 unix_shared_memory_queue_t *q = NULL;
6089 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6090 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6091 locator_set_t *loc_set = 0;
6095 q = vl_api_client_index_to_input_queue (mp->client_index);
6101 if (~0 == lcm->mreq_itr_rlocs)
6103 tmp_str = format (0, " ");
6108 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6109 tmp_str = format (0, "%s", loc_set->name);
6113 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6115 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6116 ARRAY_LEN(rmp->locator_set_name) - 1);
6124 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6126 unix_shared_memory_queue_t *q = NULL;
6127 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6128 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6130 locator_set_t *ls = 0;
6134 q = vl_api_client_index_to_input_queue (mp->client_index);
6140 if (!lcm->lisp_pitr)
6142 tmp_str = format (0, "N/A");
6146 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6147 if (~0 != m->locator_set_index)
6150 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6151 tmp_str = format (0, "%s", ls->name);
6155 tmp_str = format (0, "N/A");
6158 vec_add1 (tmp_str, 0);
6161 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6163 rmp->status = lcm->lisp_pitr;
6164 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6165 ARRAY_LEN(rmp->locator_set_name) - 1);
6171 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6174 vl_api_interface_name_renumber_reply_t *rmp;
6177 VALIDATE_SW_IF_INDEX (mp);
6179 rv = vnet_interface_name_renumber
6180 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6182 BAD_SW_IF_INDEX_LABEL;
6184 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6188 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6189 u32 sw_if_index, u32 address)
6191 vpe_api_main_t *am = &vpe_api_main;
6192 vlib_main_t *vm = am->vlib_main;
6193 vl_api_ip4_arp_event_t *event;
6194 static f64 arp_event_last_time;
6195 f64 now = vlib_time_now (vm);
6197 if (pool_is_free_index (am->arp_events, pool_index))
6200 event = pool_elt_at_index (am->arp_events, pool_index);
6202 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6204 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6208 if (sw_if_index == event->sw_if_index &&
6210 /* for BD case, also check IP address with 10 sec timeout */
6211 (address == event->address &&
6212 (now - arp_event_last_time) < 10.0)))
6217 arp_event_last_time = now;
6218 event->sw_if_index = sw_if_index;
6220 event->address = address;
6225 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6226 u32 sw_if_index, ip6_address_t * address)
6228 vpe_api_main_t *am = &vpe_api_main;
6229 vlib_main_t *vm = am->vlib_main;
6230 vl_api_ip6_nd_event_t *event;
6231 static f64 nd_event_last_time;
6232 f64 now = vlib_time_now (vm);
6234 if (pool_is_free_index (am->nd_events, pool_index))
6237 event = pool_elt_at_index (am->nd_events, pool_index);
6240 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6242 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6246 if (sw_if_index == event->sw_if_index &&
6248 /* for BD case, also check IP address with 10 sec timeout */
6249 (ip6_address_is_equal (address,
6250 (ip6_address_t *) event->address) &&
6251 (now - nd_event_last_time) < 10.0)))
6256 nd_event_last_time = now;
6257 event->sw_if_index = sw_if_index;
6259 clib_memcpy (event->address, address, sizeof (event->address));
6264 arp_change_delete_callback (u32 pool_index, u8 * notused)
6266 vpe_api_main_t *am = &vpe_api_main;
6268 if (pool_is_free_index (am->arp_events, pool_index))
6271 pool_put_index (am->arp_events, pool_index);
6276 nd_change_delete_callback (u32 pool_index, u8 * notused)
6278 vpe_api_main_t *am = &vpe_api_main;
6280 if (pool_is_free_index (am->nd_events, pool_index))
6283 pool_put_index (am->nd_events, pool_index);
6288 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6290 vpe_api_main_t *am = &vpe_api_main;
6291 vnet_main_t *vnm = vnet_get_main ();
6292 vl_api_want_ip4_arp_events_reply_t *rmp;
6293 vl_api_ip4_arp_event_t *event;
6296 if (mp->enable_disable)
6298 pool_get (am->arp_events, event);
6299 memset (event, 0, sizeof (*event));
6301 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6302 event->client_index = mp->client_index;
6303 event->context = mp->context;
6304 event->address = mp->address;
6305 event->pid = mp->pid;
6306 if (mp->address == 0)
6309 rv = vnet_add_del_ip4_arp_change_event
6310 (vnm, arp_change_data_callback,
6311 mp->pid, &mp->address /* addr, in net byte order */ ,
6312 vpe_resolver_process_node.index,
6313 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6317 rv = vnet_add_del_ip4_arp_change_event
6318 (vnm, arp_change_delete_callback,
6319 mp->pid, &mp->address /* addr, in net byte order */ ,
6320 vpe_resolver_process_node.index,
6321 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6323 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6327 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6329 vpe_api_main_t *am = &vpe_api_main;
6330 vnet_main_t *vnm = vnet_get_main ();
6331 vl_api_want_ip6_nd_events_reply_t *rmp;
6332 vl_api_ip6_nd_event_t *event;
6335 if (mp->enable_disable)
6337 pool_get (am->nd_events, event);
6338 memset (event, 0, sizeof (*event));
6340 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6341 event->client_index = mp->client_index;
6342 event->context = mp->context;
6343 clib_memcpy (event->address, mp->address, 16);
6344 event->pid = mp->pid;
6345 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6348 rv = vnet_add_del_ip6_nd_change_event
6349 (vnm, nd_change_data_callback,
6350 mp->pid, mp->address /* addr, in net byte order */ ,
6351 vpe_resolver_process_node.index,
6352 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6356 rv = vnet_add_del_ip6_nd_change_event
6357 (vnm, nd_change_delete_callback,
6358 mp->pid, mp->address /* addr, in net byte order */ ,
6359 vpe_resolver_process_node.index,
6360 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6362 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6365 static void vl_api_input_acl_set_interface_t_handler
6366 (vl_api_input_acl_set_interface_t * mp)
6368 vlib_main_t *vm = vlib_get_main ();
6369 vl_api_input_acl_set_interface_reply_t *rmp;
6371 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6373 ip4_table_index = ntohl (mp->ip4_table_index);
6374 ip6_table_index = ntohl (mp->ip6_table_index);
6375 l2_table_index = ntohl (mp->l2_table_index);
6376 sw_if_index = ntohl (mp->sw_if_index);
6378 VALIDATE_SW_IF_INDEX (mp);
6380 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6381 ip6_table_index, l2_table_index, mp->is_add);
6383 BAD_SW_IF_INDEX_LABEL;
6385 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6388 static void vl_api_ipsec_spd_add_del_t_handler
6389 (vl_api_ipsec_spd_add_del_t * mp)
6392 clib_warning ("unimplemented");
6395 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6396 vl_api_ipsec_spd_add_del_reply_t *rmp;
6400 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6402 rv = VNET_API_ERROR_UNIMPLEMENTED;
6405 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6409 static void vl_api_ipsec_interface_add_del_spd_t_handler
6410 (vl_api_ipsec_interface_add_del_spd_t * mp)
6412 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6413 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6415 u32 sw_if_index __attribute__ ((unused));
6416 u32 spd_id __attribute__ ((unused));
6418 sw_if_index = ntohl (mp->sw_if_index);
6419 spd_id = ntohl (mp->spd_id);
6421 VALIDATE_SW_IF_INDEX (mp);
6424 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6426 rv = VNET_API_ERROR_UNIMPLEMENTED;
6429 BAD_SW_IF_INDEX_LABEL;
6431 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6434 static void vl_api_ipsec_spd_add_del_entry_t_handler
6435 (vl_api_ipsec_spd_add_del_entry_t * mp)
6437 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6438 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6444 memset (&p, 0, sizeof (p));
6446 p.id = ntohl (mp->spd_id);
6447 p.priority = ntohl (mp->priority);
6448 p.is_outbound = mp->is_outbound;
6449 p.is_ipv6 = mp->is_ipv6;
6451 if (mp->is_ipv6 || mp->is_ip_any)
6453 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6454 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6455 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6456 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6460 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6461 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6462 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6463 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6465 p.protocol = mp->protocol;
6466 p.rport.start = ntohs (mp->remote_port_start);
6467 p.rport.stop = ntohs (mp->remote_port_stop);
6468 p.lport.start = ntohs (mp->local_port_start);
6469 p.lport.stop = ntohs (mp->local_port_stop);
6470 /* policy action resolve unsupported */
6471 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6473 clib_warning ("unsupported action: 'resolve'");
6474 rv = VNET_API_ERROR_UNIMPLEMENTED;
6477 p.policy = mp->policy;
6478 p.sa_id = ntohl (mp->sa_id);
6480 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6487 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6490 rv = VNET_API_ERROR_UNIMPLEMENTED;
6495 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6498 static void vl_api_ipsec_sad_add_del_entry_t_handler
6499 (vl_api_ipsec_sad_add_del_entry_t * mp)
6501 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6502 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6507 memset (&sa, 0, sizeof (sa));
6509 sa.id = ntohl (mp->sad_id);
6510 sa.spi = ntohl (mp->spi);
6511 /* security protocol AH unsupported */
6512 if (mp->protocol == IPSEC_PROTOCOL_AH)
6514 clib_warning ("unsupported security protocol 'AH'");
6515 rv = VNET_API_ERROR_UNIMPLEMENTED;
6518 sa.protocol = mp->protocol;
6519 /* check for unsupported crypto-alg */
6520 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6521 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6523 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6524 mp->crypto_algorithm);
6525 rv = VNET_API_ERROR_UNIMPLEMENTED;
6528 sa.crypto_alg = mp->crypto_algorithm;
6529 sa.crypto_key_len = mp->crypto_key_length;
6530 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6531 /* check for unsupported integ-alg */
6532 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6533 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6535 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6536 mp->integrity_algorithm);
6537 rv = VNET_API_ERROR_UNIMPLEMENTED;
6540 sa.integ_alg = mp->integrity_algorithm;
6541 sa.integ_key_len = mp->integrity_key_length;
6542 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6543 sa.use_esn = mp->use_extended_sequence_number;
6544 sa.is_tunnel = mp->is_tunnel;
6545 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6546 if (sa.is_tunnel_ip6)
6548 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6549 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6553 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6554 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6557 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6559 rv = VNET_API_ERROR_UNIMPLEMENTED;
6564 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6568 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6570 vl_api_ikev2_profile_add_del_reply_t *rmp;
6574 vlib_main_t *vm = vlib_get_main ();
6575 clib_error_t *error;
6576 u8 *tmp = format (0, "%s", mp->name);
6577 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6580 rv = VNET_API_ERROR_UNSPECIFIED;
6582 rv = VNET_API_ERROR_UNIMPLEMENTED;
6585 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6589 vl_api_ikev2_profile_set_auth_t_handler
6590 (vl_api_ikev2_profile_set_auth_t * mp)
6592 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6596 vlib_main_t *vm = vlib_get_main ();
6597 clib_error_t *error;
6598 u8 *tmp = format (0, "%s", mp->name);
6599 u8 *data = vec_new (u8, mp->data_len);
6600 clib_memcpy (data, mp->data, mp->data_len);
6601 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6605 rv = VNET_API_ERROR_UNSPECIFIED;
6607 rv = VNET_API_ERROR_UNIMPLEMENTED;
6610 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6614 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6616 vl_api_ikev2_profile_add_del_reply_t *rmp;
6620 vlib_main_t *vm = vlib_get_main ();
6621 clib_error_t *error;
6622 u8 *tmp = format (0, "%s", mp->name);
6623 u8 *data = vec_new (u8, mp->data_len);
6624 clib_memcpy (data, mp->data, mp->data_len);
6625 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6629 rv = VNET_API_ERROR_UNSPECIFIED;
6631 rv = VNET_API_ERROR_UNIMPLEMENTED;
6634 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6638 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6640 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6644 vlib_main_t *vm = vlib_get_main ();
6645 clib_error_t *error;
6646 u8 *tmp = format (0, "%s", mp->name);
6647 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6648 mp->end_port, (ip4_address_t) mp->start_addr,
6649 (ip4_address_t) mp->end_addr, mp->is_local);
6652 rv = VNET_API_ERROR_UNSPECIFIED;
6654 rv = VNET_API_ERROR_UNIMPLEMENTED;
6657 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6661 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6663 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6667 vlib_main_t *vm = vlib_get_main ();
6668 clib_error_t *error;
6670 error = ikev2_set_local_key (vm, mp->key_file);
6672 rv = VNET_API_ERROR_UNSPECIFIED;
6674 rv = VNET_API_ERROR_UNIMPLEMENTED;
6677 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6681 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6683 vl_api_map_add_domain_reply_t *rmp;
6686 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6688 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6689 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6690 (ip6_address_t *) & mp->ip6_src,
6691 mp->ip6_src_prefix_len, mp->ea_bits_len,
6692 mp->psid_offset, mp->psid_length, &index,
6693 ntohs (mp->mtu), flags);
6696 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6698 rmp->index = ntohl(index);
6704 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6706 vl_api_map_del_domain_reply_t *rmp;
6709 rv = map_delete_domain (ntohl (mp->index));
6711 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6715 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6717 vl_api_map_del_domain_reply_t *rmp;
6721 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6722 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6724 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6728 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6730 vl_api_map_domain_details_t *rmp;
6731 map_main_t *mm = &map_main;
6733 unix_shared_memory_queue_t *q;
6735 if (pool_elts (mm->domains) == 0)
6738 q = vl_api_client_index_to_input_queue (mp->client_index);
6745 pool_foreach(d, mm->domains,
6747 /* Make sure every field is initiated (or don't skip the memset()) */
6748 rmp = vl_msg_api_alloc (sizeof (*rmp));
6749 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6750 rmp->domain_index = htonl(d - mm->domains);
6751 rmp->ea_bits_len = d->ea_bits_len;
6752 rmp->psid_offset = d->psid_offset;
6753 rmp->psid_length = d->psid_length;
6754 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6755 rmp->ip4_prefix_len = d->ip4_prefix_len;
6756 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6757 rmp->ip6_prefix_len = d->ip6_prefix_len;
6758 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6759 rmp->ip6_src_len = d->ip6_src_len;
6760 rmp->mtu = htons(d->mtu);
6761 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6762 rmp->context = mp->context;
6764 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6770 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6772 unix_shared_memory_queue_t *q;
6775 vl_api_map_rule_details_t *rmp;
6776 map_main_t *mm = &map_main;
6777 u32 domain_index = ntohl (mp->domain_index);
6780 if (pool_elts (mm->domains) == 0)
6783 d = pool_elt_at_index (mm->domains, domain_index);
6784 if (!d || !d->rules)
6789 q = vl_api_client_index_to_input_queue (mp->client_index);
6795 for (i = 0; i < (0x1 << d->psid_length); i++)
6798 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6802 rmp = vl_msg_api_alloc (sizeof (*rmp));
6803 memset (rmp, 0, sizeof (*rmp));
6804 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6805 rmp->psid = htons (i);
6806 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6807 rmp->context = mp->context;
6808 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6813 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6815 vl_api_map_summary_stats_reply_t *rmp;
6816 vlib_combined_counter_main_t *cm;
6819 u64 total_pkts[VLIB_N_RX_TX];
6820 u64 total_bytes[VLIB_N_RX_TX];
6821 map_main_t *mm = &map_main;
6822 unix_shared_memory_queue_t *q =
6823 vl_api_client_index_to_input_queue (mp->client_index);
6828 rmp = vl_msg_api_alloc (sizeof (*rmp));
6829 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6830 rmp->context = mp->context;
6833 memset (total_pkts, 0, sizeof (total_pkts));
6834 memset (total_bytes, 0, sizeof (total_bytes));
6836 map_domain_counter_lock (mm);
6837 vec_foreach (cm, mm->domain_counters)
6839 which = cm - mm->domain_counters;
6841 for (i = 0; i < vec_len (cm->maxi); i++)
6843 vlib_get_combined_counter (cm, i, &v);
6844 total_pkts[which] += v.packets;
6845 total_bytes[which] += v.bytes;
6849 map_domain_counter_unlock (mm);
6851 /* Note: in network byte order! */
6852 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6853 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6854 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6855 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6856 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6857 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6858 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6859 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6860 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6861 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6862 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6863 clib_host_to_net_u64 (map_error_counter_get
6864 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6865 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6866 clib_host_to_net_u64 (map_error_counter_get
6867 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6869 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6873 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6875 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6876 vl_api_ipsec_sa_set_key_reply_t *rmp;
6880 sa.id = ntohl (mp->sa_id);
6881 sa.crypto_key_len = mp->crypto_key_length;
6882 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6883 sa.integ_key_len = mp->integrity_key_length;
6884 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6886 rv = ipsec_set_sa_key (vm, &sa);
6888 rv = VNET_API_ERROR_UNIMPLEMENTED;
6891 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6894 static void vl_api_cop_interface_enable_disable_t_handler
6895 (vl_api_cop_interface_enable_disable_t * mp)
6897 vl_api_cop_interface_enable_disable_reply_t *rmp;
6899 u32 sw_if_index = ntohl (mp->sw_if_index);
6902 VALIDATE_SW_IF_INDEX (mp);
6904 enable_disable = (int) mp->enable_disable;
6906 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6908 BAD_SW_IF_INDEX_LABEL;
6910 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6913 static void vl_api_cop_whitelist_enable_disable_t_handler
6914 (vl_api_cop_whitelist_enable_disable_t * mp)
6916 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6917 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6918 u32 sw_if_index = ntohl (mp->sw_if_index);
6921 VALIDATE_SW_IF_INDEX (mp);
6923 a->sw_if_index = sw_if_index;
6926 a->default_cop = mp->default_cop;
6927 a->fib_id = ntohl (mp->fib_id);
6929 rv = cop_whitelist_enable_disable (a);
6931 BAD_SW_IF_INDEX_LABEL;
6933 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6937 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
6941 api_main_t *am = &api_main;
6942 vlib_main_t *vm = vlib_get_main ();
6944 vl_api_get_node_graph_reply_t *rmp;
6946 pthread_mutex_lock (&am->vlib_rp->mutex);
6947 oldheap = svm_push_data_heap (am->vlib_rp);
6950 * Keep the number of memcpy ops to a minimum (e.g. 1).
6952 vec_validate (vector, 16384);
6953 vec_reset_length (vector);
6956 vector = vlib_node_serialize (&vm->node_main, vector,
6957 (u32) ~ 0 /* all threads */ ,
6958 1 /* include nexts */ ,
6959 1 /* include stats */ );
6961 svm_pop_heap (oldheap);
6962 pthread_mutex_unlock (&am->vlib_rp->mutex);
6965 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6967 rmp->reply_in_shmem = (uword) vector;
6972 static void vl_api_trace_profile_add_t_handler
6973 (vl_api_trace_profile_add_t * mp)
6976 vl_api_trace_profile_add_reply_t *rmp;
6977 clib_error_t *error;
6979 /* Ignoring the profile id as currently a single profile
6981 error = ip6_ioam_trace_profile_set (mp->trace_num_elt, mp->trace_type,
6982 ntohl (mp->node_id),
6983 ntohl (mp->trace_app_data),
6984 mp->pow_enable, mp->trace_tsp,
6988 clib_error_report (error);
6989 rv = clib_error_get_code (error);
6992 REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
6995 static void vl_api_trace_profile_apply_t_handler
6996 (vl_api_trace_profile_apply_t * mp)
6999 vl_api_trace_profile_apply_reply_t *rmp;
7001 if (mp->enable != 0)
7003 rv = ip6_ioam_set_destination ((ip6_address_t *) (&mp->dest_ipv6),
7004 ntohl (mp->prefix_length),
7006 mp->trace_op == IOAM_HBYH_ADD,
7007 mp->trace_op == IOAM_HBYH_POP,
7008 mp->trace_op == IOAM_HBYH_MOD);
7012 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
7014 REPLY_MACRO (VL_API_TRACE_PROFILE_APPLY_REPLY);
7017 static void vl_api_trace_profile_del_t_handler
7018 (vl_api_trace_profile_del_t * mp)
7021 vl_api_trace_profile_del_reply_t *rmp;
7022 clib_error_t *error;
7024 error = clear_ioam_rewrite_fn ();
7027 clib_error_report (error);
7028 rv = clib_error_get_code (error);
7031 REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
7035 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7037 vlib_main_t *vm = vlib_get_main ();
7038 vl_api_af_packet_create_reply_t *rmp;
7040 u8 *host_if_name = NULL;
7043 host_if_name = format (0, "%s", mp->host_if_name);
7044 vec_add1 (host_if_name, 0);
7046 rv = af_packet_create_if (vm, host_if_name,
7047 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7050 vec_free (host_if_name);
7053 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7055 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7061 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7063 vlib_main_t *vm = vlib_get_main ();
7064 vl_api_af_packet_delete_reply_t *rmp;
7066 u8 *host_if_name = NULL;
7068 host_if_name = format (0, "%s", mp->host_if_name);
7069 vec_add1 (host_if_name, 0);
7071 rv = af_packet_delete_if (vm, host_if_name);
7073 vec_free (host_if_name);
7075 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7079 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7081 vlib_main_t *vm = vlib_get_main ();
7082 vl_api_policer_add_del_reply_t *rmp;
7085 sse2_qos_pol_cfg_params_st cfg;
7086 clib_error_t *error;
7089 name = format (0, "%s", mp->name);
7091 memset (&cfg, 0, sizeof (cfg));
7093 cfg.rnd_type = mp->round_type;
7094 cfg.rate_type = mp->rate_type;
7095 cfg.rb.kbps.cir_kbps = mp->cir;
7096 cfg.rb.kbps.eir_kbps = mp->eir;
7097 cfg.rb.kbps.cb_bytes = mp->cb;
7098 cfg.rb.kbps.eb_bytes = mp->eb;
7099 cfg.conform_action.action_type = mp->conform_action_type;
7100 cfg.conform_action.dscp = mp->conform_dscp;
7101 cfg.exceed_action.action_type = mp->exceed_action_type;
7102 cfg.exceed_action.dscp = mp->exceed_dscp;
7103 cfg.violate_action.action_type = mp->violate_action_type;
7104 cfg.violate_action.dscp = mp->violate_dscp;
7105 cfg.color_aware = mp->color_aware;
7107 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7110 rv = VNET_API_ERROR_UNSPECIFIED;
7113 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7115 if (rv == 0 && mp->is_add)
7116 rmp->policer_index = ntohl(policer_index);
7118 rmp->policer_index = ~0;
7124 send_policer_details (u8 * name,
7125 sse2_qos_pol_cfg_params_st * config,
7126 policer_read_response_type_st * templ,
7127 unix_shared_memory_queue_t * q, u32 context)
7129 vl_api_policer_details_t *mp;
7131 mp = vl_msg_api_alloc (sizeof (*mp));
7132 memset (mp, 0, sizeof (*mp));
7133 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7134 mp->context = context;
7135 mp->cir = htonl (config->rb.kbps.cir_kbps);
7136 mp->eir = htonl (config->rb.kbps.eir_kbps);
7137 mp->cb = htonl (config->rb.kbps.cb_bytes);
7138 mp->eb = htonl (config->rb.kbps.eb_bytes);
7139 mp->rate_type = config->rate_type;
7140 mp->round_type = config->rnd_type;
7141 mp->type = config->rfc;
7142 mp->conform_action_type = config->conform_action.action_type;
7143 mp->conform_dscp = config->conform_action.dscp;
7144 mp->exceed_action_type = config->exceed_action.action_type;
7145 mp->exceed_dscp = config->exceed_action.dscp;
7146 mp->violate_action_type = config->violate_action.action_type;
7147 mp->violate_dscp = config->violate_action.dscp;
7148 mp->single_rate = templ->single_rate ? 1 : 0;
7149 mp->color_aware = templ->color_aware ? 1 : 0;
7150 mp->scale = htonl (templ->scale);
7151 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7152 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7153 mp->current_limit = htonl (templ->current_limit);
7154 mp->current_bucket = htonl (templ->current_bucket);
7155 mp->extended_limit = htonl (templ->extended_limit);
7156 mp->extended_bucket = htonl (templ->extended_bucket);
7157 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7159 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7161 vl_msg_api_send_shmem (q, (u8 *) & mp);
7165 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7167 unix_shared_memory_queue_t *q;
7168 vnet_policer_main_t *pm = &vnet_policer_main;
7174 sse2_qos_pol_cfg_params_st *config;
7175 policer_read_response_type_st *templ;
7177 q = vl_api_client_index_to_input_queue (mp->client_index);
7181 if (mp->match_name_valid)
7183 match_name = format (0, "%s%c", mp->match_name, 0);
7186 if (mp->match_name_valid)
7188 p = hash_get_mem (pm->policer_config_by_name, match_name);
7192 config = pool_elt_at_index (pm->configs, pool_index);
7193 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7194 send_policer_details (match_name, config, templ, q, mp->context);
7200 hash_foreach_pair (hp, pm->policer_config_by_name,
7202 name = (u8 *) hp->key;
7203 pool_index = hp->value[0];
7204 config = pool_elt_at_index (pm->configs, pool_index);
7205 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7206 send_policer_details(name, config, templ, q, mp->context);
7213 vl_api_policer_classify_set_interface_t_handler
7214 (vl_api_policer_classify_set_interface_t * mp)
7216 vlib_main_t *vm = vlib_get_main ();
7217 vl_api_policer_classify_set_interface_reply_t *rmp;
7219 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7221 ip4_table_index = ntohl (mp->ip4_table_index);
7222 ip6_table_index = ntohl (mp->ip6_table_index);
7223 l2_table_index = ntohl (mp->l2_table_index);
7224 sw_if_index = ntohl (mp->sw_if_index);
7226 VALIDATE_SW_IF_INDEX (mp);
7228 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7229 ip6_table_index, l2_table_index,
7232 BAD_SW_IF_INDEX_LABEL;
7234 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7238 send_policer_classify_details (u32 sw_if_index,
7240 unix_shared_memory_queue_t * q, u32 context)
7242 vl_api_policer_classify_details_t *mp;
7244 mp = vl_msg_api_alloc (sizeof (*mp));
7245 memset (mp, 0, sizeof (*mp));
7246 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7247 mp->context = context;
7248 mp->sw_if_index = htonl (sw_if_index);
7249 mp->table_index = htonl (table_index);
7251 vl_msg_api_send_shmem (q, (u8 *) & mp);
7255 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7257 unix_shared_memory_queue_t *q;
7258 policer_classify_main_t *pcm = &policer_classify_main;
7262 q = vl_api_client_index_to_input_queue (mp->client_index);
7266 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7268 if (vec_len (vec_tbl))
7270 for (i = 0; i < vec_len (vec_tbl); i++)
7272 if (vec_elt (vec_tbl, i) == ~0)
7275 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7282 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7284 vlib_main_t *vm = vlib_get_main ();
7285 vl_api_netmap_create_reply_t *rmp;
7289 if_name = format (0, "%s", mp->netmap_if_name);
7290 vec_add1 (if_name, 0);
7293 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7294 mp->is_pipe, mp->is_master, 0);
7298 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7302 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7304 vlib_main_t *vm = vlib_get_main ();
7305 vl_api_netmap_delete_reply_t *rmp;
7309 if_name = format (0, "%s", mp->netmap_if_name);
7310 vec_add1 (if_name, 0);
7312 rv = netmap_delete_if (vm, if_name);
7316 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7320 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7323 clib_warning ("BUG");
7327 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7328 unix_shared_memory_queue_t * q,
7329 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7331 vl_api_mpls_gre_tunnel_details_t *mp;
7332 mpls_main_t *mm = &mpls_main;
7337 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7338 nlabels = vec_len (e->labels);
7340 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7341 memset (mp, 0, sizeof (*mp));
7342 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7343 mp->context = context;
7345 mp->tunnel_index = htonl (index);
7346 mp->tunnel_src = gt->tunnel_src.as_u32;
7347 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7348 mp->intfc_address = gt->intfc_address.as_u32;
7349 mp->mask_width = htonl (gt->mask_width);
7350 mp->inner_fib_index = htonl (gt->inner_fib_index);
7351 mp->outer_fib_index = htonl (gt->outer_fib_index);
7352 mp->encap_index = htonl (gt->encap_index);
7353 mp->hw_if_index = htonl (gt->hw_if_index);
7354 mp->l2_only = htonl (gt->l2_only);
7355 mp->nlabels = htonl (nlabels);
7357 for (i = 0; i < nlabels; i++)
7360 htonl (vnet_mpls_uc_get_label
7361 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7364 vl_msg_api_send_shmem (q, (u8 *) & mp);
7368 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7370 vpe_api_main_t *am = &vpe_api_main;
7371 unix_shared_memory_queue_t *q;
7372 mpls_main_t *mm = &mpls_main;
7373 mpls_gre_tunnel_t *gt;
7374 u32 index = ntohl (mp->tunnel_index);
7376 q = vl_api_client_index_to_input_queue (mp->client_index);
7382 if (!pool_is_free_index (mm->gre_tunnels, index))
7384 gt = pool_elt_at_index (mm->gre_tunnels, index);
7385 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7392 pool_foreach (gt, mm->gre_tunnels,
7394 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7402 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7405 clib_warning ("BUG");
7409 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7410 unix_shared_memory_queue_t * q,
7411 mpls_eth_tunnel_t * et, u32 index, u32 context)
7413 mpls_main_t *mm = &mpls_main;
7417 vl_api_mpls_eth_tunnel_details_t *mp;
7419 e = pool_elt_at_index (mm->encaps, et->encap_index);
7420 nlabels = vec_len (e->labels);
7422 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7423 memset (mp, 0, sizeof (*mp));
7424 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7425 mp->context = context;
7427 mp->tunnel_index = htonl (index);
7428 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7429 mp->intfc_address = et->intfc_address.as_u32;
7430 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7431 mp->inner_fib_index = htonl (et->inner_fib_index);
7432 mp->mask_width = htonl (et->mask_width);
7433 mp->encap_index = htonl (et->encap_index);
7434 mp->hw_if_index = htonl (et->hw_if_index);
7435 mp->l2_only = htonl (et->l2_only);
7436 mp->nlabels = htonl (nlabels);
7438 for (i = 0; i < nlabels; i++)
7441 htonl (vnet_mpls_uc_get_label
7442 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7445 vl_msg_api_send_shmem (q, (u8 *) & mp);
7449 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7451 vpe_api_main_t *am = &vpe_api_main;
7452 unix_shared_memory_queue_t *q;
7453 mpls_main_t *mm = &mpls_main;
7454 mpls_eth_tunnel_t *et;
7455 u32 index = ntohl (mp->tunnel_index);
7457 q = vl_api_client_index_to_input_queue (mp->client_index);
7463 if (!pool_is_free_index (mm->eth_tunnels, index))
7465 et = pool_elt_at_index (mm->eth_tunnels, index);
7466 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7473 pool_foreach (et, mm->eth_tunnels,
7475 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7483 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7485 clib_warning ("BUG");
7489 send_mpls_fib_encap_details (vpe_api_main_t * am,
7490 unix_shared_memory_queue_t * q,
7491 show_mpls_fib_t * s, u32 context)
7493 vl_api_mpls_fib_encap_details_t *mp;
7494 mpls_main_t *mm = &mpls_main;
7499 e = pool_elt_at_index (mm->encaps, s->entry_index);
7500 nlabels = vec_len (e->labels);
7502 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7503 memset (mp, 0, sizeof (*mp));
7504 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7505 mp->context = context;
7507 mp->fib_index = htonl (s->fib_index);
7508 mp->entry_index = htonl (s->entry_index);
7510 mp->s_bit = htonl (s->s_bit);
7512 mp->nlabels = htonl (nlabels);
7514 for (i = 0; i < nlabels; i++)
7517 htonl (vnet_mpls_uc_get_label
7518 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7521 vl_msg_api_send_shmem (q, (u8 *) & mp);
7525 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7527 vpe_api_main_t *am = &vpe_api_main;
7528 unix_shared_memory_queue_t *q;
7529 vlib_main_t *vm = &vlib_global_main;
7532 show_mpls_fib_t *records = 0;
7534 mpls_main_t *mm = &mpls_main;
7535 ip4_main_t *im = &ip4_main;
7538 q = vl_api_client_index_to_input_queue (mp->client_index);
7543 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7545 vec_add2 (records, s, 1);
7546 s->fib_index = (u32)(key>>32);
7547 s->dest = (u32)(key & 0xFFFFFFFF);
7548 s->entry_index = (u32) value;
7552 if (0 == vec_len (records))
7554 vlib_cli_output (vm, "MPLS encap table empty");
7558 /* sort output by dst address within fib */
7559 vec_sort_with_function (records, mpls_dest_cmp);
7560 vec_sort_with_function (records, mpls_fib_index_cmp);
7561 vlib_cli_output (vm, "MPLS encap table");
7562 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7563 vec_foreach (s, records)
7565 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7566 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7567 format_ip4_address, &s->dest, format_mpls_encap_index,
7568 mm, s->entry_index);
7569 send_mpls_fib_encap_details (am, q, s, mp->context);
7577 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7579 clib_warning ("BUG");
7583 send_mpls_fib_decap_details (vpe_api_main_t * am,
7584 unix_shared_memory_queue_t * q,
7585 show_mpls_fib_t * s,
7587 u32 tx_table_id, char *swif_tag, u32 context)
7589 vl_api_mpls_fib_decap_details_t *mp;
7591 mp = vl_msg_api_alloc (sizeof (*mp));
7592 memset (mp, 0, sizeof (*mp));
7593 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7594 mp->context = context;
7596 mp->fib_index = htonl (s->fib_index);
7597 mp->entry_index = htonl (s->entry_index);
7599 mp->s_bit = htonl (s->s_bit);
7600 mp->label = htonl (s->label);
7601 mp->rx_table_id = htonl (rx_table_id);
7602 mp->tx_table_id = htonl (tx_table_id);
7603 strncpy ((char *) mp->swif_tag,
7604 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7606 vl_msg_api_send_shmem (q, (u8 *) & mp);
7610 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7612 vpe_api_main_t *am = &vpe_api_main;
7613 unix_shared_memory_queue_t *q;
7614 vlib_main_t *vm = &vlib_global_main;
7617 show_mpls_fib_t *records = 0;
7619 mpls_main_t *mm = &mpls_main;
7620 ip4_main_t *im = &ip4_main;
7626 q = vl_api_client_index_to_input_queue (mp->client_index);
7631 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7633 vec_add2 (records, s, 1);
7634 s->fib_index = (u32)(key>>32);
7635 s->entry_index = (u32) value;
7636 s->label = ((u32) key)>>12;
7637 s->s_bit = (key & (1<<8)) != 0;
7641 if (!vec_len (records))
7643 vlib_cli_output (vm, "MPLS decap table empty");
7647 vec_sort_with_function (records, mpls_label_cmp);
7648 vlib_cli_output (vm, "MPLS decap table");
7649 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7651 vec_foreach (s, records)
7654 d = pool_elt_at_index (mm->decaps, s->entry_index);
7655 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT)
7657 tx_fib = vec_elt_at_index (im->fibs, d->tx_fib_index);
7658 tx_table_id = tx_fib->table_id;
7663 tx_table_id = d->tx_fib_index;
7666 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7668 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7669 tx_table_id, swif_tag, s->label, s->s_bit);
7671 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7672 tx_table_id, swif_tag, mp->context);
7680 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7682 unix_shared_memory_queue_t *q;
7684 q = vl_api_client_index_to_input_queue (mp->client_index);
7688 vnet_classify_main_t *cm = &vnet_classify_main;
7689 vnet_classify_table_t *t;
7694 pool_foreach (t, cm->tables,
7696 vec_add1 (table_ids, ntohl(t - cm->tables));
7699 count = vec_len (table_ids);
7701 vl_api_classify_table_ids_reply_t *rmp;
7702 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7703 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7704 rmp->context = mp->context;
7705 rmp->count = ntohl (count);
7706 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7709 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7711 vec_free (table_ids);
7715 vl_api_classify_table_by_interface_t_handler
7716 (vl_api_classify_table_by_interface_t * mp)
7718 vl_api_classify_table_by_interface_reply_t *rmp;
7721 u32 sw_if_index = ntohl (mp->sw_if_index);
7724 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7727 VALIDATE_SW_IF_INDEX (mp);
7729 input_acl_main_t *am = &input_acl_main;
7734 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7736 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7737 if (vec_len (vec_tbl))
7739 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7741 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7745 acl[type] = vec_elt (vec_tbl, if_idx);
7750 BAD_SW_IF_INDEX_LABEL;
7753 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7755 rmp->sw_if_index = ntohl(sw_if_index);
7756 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7757 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7758 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7765 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7767 unix_shared_memory_queue_t *q;
7769 q = vl_api_client_index_to_input_queue (mp->client_index);
7773 vl_api_classify_table_info_reply_t *rmp = 0;
7775 vnet_classify_main_t *cm = &vnet_classify_main;
7776 u32 table_id = ntohl (mp->table_id);
7777 vnet_classify_table_t *t;
7780 pool_foreach (t, cm->tables,
7782 if (table_id == t - cm->tables)
7784 rmp = vl_msg_api_alloc_as_if_client
7785 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7786 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7787 rmp->context = mp->context;
7788 rmp->table_id = ntohl(table_id);
7789 rmp->nbuckets = ntohl(t->nbuckets);
7790 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7791 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7792 rmp->active_sessions = ntohl(t->active_elements);
7793 rmp->next_table_index = ntohl(t->next_table_index);
7794 rmp->miss_next_index = ntohl(t->miss_next_index);
7795 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7796 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7805 rmp = vl_msg_api_alloc (sizeof (*rmp));
7806 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7807 rmp->context = mp->context;
7808 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7811 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7815 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7818 clib_warning ("BUG");
7822 send_classify_session_details (unix_shared_memory_queue_t * q,
7825 vnet_classify_entry_t * e, u32 context)
7827 vl_api_classify_session_details_t *rmp;
7829 rmp = vl_msg_api_alloc (sizeof (*rmp));
7830 memset (rmp, 0, sizeof (*rmp));
7831 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7832 rmp->context = context;
7833 rmp->table_id = ntohl (table_id);
7834 rmp->hit_next_index = ntohl (e->next_index);
7835 rmp->advance = ntohl (e->advance);
7836 rmp->opaque_index = ntohl (e->opaque_index);
7837 rmp->match_length = ntohl (match_length);
7838 clib_memcpy (rmp->match, e->key, match_length);
7840 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7844 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7846 vnet_classify_main_t *cm = &vnet_classify_main;
7847 unix_shared_memory_queue_t *q;
7849 u32 table_id = ntohl (mp->table_id);
7850 vnet_classify_table_t *t;
7852 q = vl_api_client_index_to_input_queue (mp->client_index);
7855 pool_foreach (t, cm->tables,
7857 if (table_id == t - cm->tables)
7859 vnet_classify_bucket_t * b;
7860 vnet_classify_entry_t * v, * save_v;
7863 for (i = 0; i < t->nbuckets; i++)
7865 b = &t->buckets [i];
7869 save_v = vnet_classify_get_entry (t, b->offset);
7870 for (j = 0; j < (1<<b->log2_pages); j++)
7872 for (k = 0; k < t->entries_per_page; k++)
7874 v = vnet_classify_entry_at_index
7875 (t, save_v, j*t->entries_per_page + k);
7876 if (vnet_classify_entry_is_free (v))
7879 send_classify_session_details
7880 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7892 vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t * mp)
7894 vlib_main_t *vm = vlib_get_main ();
7895 flow_report_main_t *frm = &flow_report_main;
7896 vl_api_ipfix_enable_reply_t *rmp;
7897 ip4_address_t collector, src;
7898 u16 collector_port = UDP_DST_PORT_ipfix;
7900 u32 template_interval;
7905 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7906 collector_port = ntohs (mp->collector_port);
7907 if (collector_port == (u16) ~ 0)
7908 collector_port = UDP_DST_PORT_ipfix;
7909 memcpy (src.data, mp->src_address, sizeof (src.data));
7910 fib_id = ntohl (mp->vrf_id);
7912 ip4_main_t *im = &ip4_main;
7913 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7916 rv = VNET_API_ERROR_NO_SUCH_FIB;
7921 path_mtu = ntohl (mp->path_mtu);
7923 path_mtu = 512; // RFC 7011 section 10.3.3.
7924 template_interval = ntohl (mp->template_interval);
7925 if (template_interval == ~0)
7926 template_interval = 20;
7928 if (collector.as_u32 == 0)
7930 rv = VNET_API_ERROR_INVALID_VALUE;
7934 if (src.as_u32 == 0)
7936 rv = VNET_API_ERROR_INVALID_VALUE;
7940 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7942 rv = VNET_API_ERROR_INVALID_VALUE;
7948 rv = VNET_API_ERROR_INVALID_VALUE;
7952 /* Reset report streams if we are reconfiguring IP addresses */
7953 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7954 frm->src_address.as_u32 != src.as_u32 ||
7955 frm->collector_port != collector_port)
7956 vnet_flow_reports_reset (frm);
7958 frm->ipfix_collector.as_u32 = collector.as_u32;
7959 frm->collector_port = collector_port;
7960 frm->src_address.as_u32 = src.as_u32;
7961 frm->fib_index = fib_index;
7962 frm->path_mtu = path_mtu;
7963 frm->template_interval = template_interval;
7965 /* Turn on the flow reporting process */
7966 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
7969 REPLY_MACRO (VL_API_IPFIX_ENABLE_REPLY);
7973 vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t * mp)
7975 flow_report_main_t *frm = &flow_report_main;
7976 unix_shared_memory_queue_t *q;
7977 vl_api_ipfix_details_t *rmp;
7979 q = vl_api_client_index_to_input_queue (mp->client_index);
7983 rmp = vl_msg_api_alloc (sizeof (*rmp));
7984 memset (rmp, 0, sizeof (*rmp));
7985 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_DETAILS);
7986 rmp->context = mp->context;
7987 memcpy (rmp->collector_address, frm->ipfix_collector.data,
7988 sizeof (frm->ipfix_collector.data));
7989 rmp->collector_port = htons (frm->collector_port);
7990 memcpy (rmp->src_address, frm->src_address.data,
7991 sizeof (frm->src_address.data));
7992 rmp->fib_index = htonl (frm->fib_index);
7993 rmp->path_mtu = htonl (frm->path_mtu);
7994 rmp->template_interval = htonl (frm->template_interval);
7996 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8000 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8002 vl_api_pg_create_interface_reply_t *rmp;
8005 pg_main_t *pg = &pg_main;
8006 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8009 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8011 rmp->sw_if_index = ntohl(sw_if_index);
8017 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8019 vl_api_pg_capture_reply_t *rmp;
8022 vnet_main_t *vnm = vnet_get_main ();
8023 vnet_interface_main_t *im = &vnm->interface_main;
8024 vnet_hw_interface_t *hi = 0;
8026 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8027 u32 hw_if_index = ~0;
8028 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8031 vec_free (intf_name);
8033 if (hw_if_index != ~0)
8035 pg_capture_args_t _a, *a = &_a;
8037 u32 len = ntohl (mp->pcap_name_length);
8038 u8 *pcap_file_name = vec_new (u8, len);
8039 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8041 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8042 a->hw_if_index = hw_if_index;
8043 a->dev_instance = hi->dev_instance;
8044 a->is_enabled = mp->is_enabled;
8045 a->pcap_file_name = pcap_file_name;
8046 a->count = ntohl (mp->count);
8048 clib_error_t *e = pg_capture (a);
8051 clib_error_report (e);
8052 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8055 vec_free (pcap_file_name);
8057 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8061 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8063 vl_api_pg_enable_disable_reply_t *rmp;
8066 pg_main_t *pg = &pg_main;
8067 u32 stream_index = ~0;
8069 int is_enable = mp->is_enabled != 0;
8070 u32 len = ntohl (mp->stream_name_length) - 1;
8074 u8 *stream_name = vec_new (u8, len);
8075 clib_memcpy (stream_name, mp->stream_name, len);
8076 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8079 vec_free (stream_name);
8082 pg_enable_disable (stream_index, is_enable);
8084 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8088 vl_api_ip_source_and_port_range_check_add_del_t_handler
8089 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8091 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8094 u8 is_ipv6 = mp->is_ipv6;
8095 u8 is_add = mp->is_add;
8096 u8 mask_length = mp->mask_length;
8097 ip4_address_t ip4_addr;
8098 ip6_address_t ip6_addr;
8100 u16 *high_ports = 0;
8102 u16 tmp_low, tmp_high;
8106 // Validate port range
8107 num_ranges = mp->number_of_ranges;
8108 if (num_ranges > 32)
8109 { // This is size of array in VPE.API
8110 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8114 vec_reset_length (low_ports);
8115 vec_reset_length (high_ports);
8117 for (i = 0; i < num_ranges; i++)
8119 tmp_low = mp->low_ports[i];
8120 tmp_high = mp->high_ports[i];
8121 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8122 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8123 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8125 rv = VNET_API_ERROR_INVALID_VALUE;
8128 vec_add1 (low_ports, tmp_low);
8129 vec_add1 (high_ports, tmp_high + 1);
8132 // Validate mask_length
8133 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8135 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8139 vrf_id = ntohl (mp->vrf_id);
8143 rv = VNET_API_ERROR_INVALID_VALUE;
8150 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8151 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8155 high_ports, is_add);
8159 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8160 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8164 high_ports, is_add);
8168 vec_free (low_ports);
8169 vec_free (high_ports);
8170 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8174 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8175 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8177 vlib_main_t *vm = vlib_get_main ();
8178 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8179 ip4_main_t *im = &ip4_main;
8182 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8183 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8187 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8188 ntohl (mp->tcp_out_vrf_id);
8189 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8190 ntohl (mp->udp_out_vrf_id);
8191 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8192 ntohl (mp->tcp_in_vrf_id);
8193 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8194 ntohl (mp->udp_in_vrf_id);
8197 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8199 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8201 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8205 rv = VNET_API_ERROR_INVALID_VALUE;
8209 fib_index[i] = p[0];
8214 sw_if_index = ntohl (mp->sw_if_index);
8216 VALIDATE_SW_IF_INDEX (mp);
8219 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8222 BAD_SW_IF_INDEX_LABEL;
8225 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8229 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8232 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8234 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8235 u32 sw_if_index = ~0;
8237 /* Check src & dst are different */
8238 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8240 rv = VNET_API_ERROR_SAME_SRC_DST;
8244 memset (a, 0, sizeof (*a));
8246 /* ip addresses sent in network byte order */
8247 clib_memcpy (&(a->src), mp->src_address, 4);
8248 clib_memcpy (&(a->dst), mp->dst_address, 4);
8249 a->is_add = mp->is_add;
8250 a->lsa = ntohl (mp->local_sa_id);
8251 a->rsa = ntohl (mp->remote_sa_id);
8253 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8257 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8259 rmp->sw_if_index = ntohl (sw_if_index);
8264 static void send_ipsec_gre_tunnel_details
8265 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8267 vl_api_ipsec_gre_tunnel_details_t *rmp;
8269 rmp = vl_msg_api_alloc (sizeof (*rmp));
8270 memset (rmp, 0, sizeof (*rmp));
8271 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8272 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8273 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8274 rmp->sw_if_index = htonl (t->sw_if_index);
8275 rmp->local_sa_id = htonl (t->local_sa_id);
8276 rmp->remote_sa_id = htonl (t->remote_sa_id);
8277 rmp->context = context;
8279 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8282 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8283 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8285 unix_shared_memory_queue_t *q;
8286 ipsec_gre_main_t *igm = &ipsec_gre_main;
8287 ipsec_gre_tunnel_t *t;
8290 q = vl_api_client_index_to_input_queue (mp->client_index);
8296 sw_if_index = ntohl (mp->sw_if_index);
8298 if (~0 == sw_if_index)
8301 pool_foreach (t, igm->tunnels,
8303 send_ipsec_gre_tunnel_details(t, q, mp->context);
8309 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8310 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8314 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8315 send_ipsec_gre_tunnel_details (t, q, mp->context);
8320 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8322 vl_api_delete_subif_reply_t *rmp;
8325 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8327 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8330 #define BOUNCE_HANDLER(nn) \
8331 static void vl_api_##nn##_t_handler ( \
8332 vl_api_##nn##_t *mp) \
8334 vpe_client_registration_t *reg; \
8335 vpe_api_main_t * vam = &vpe_api_main; \
8336 unix_shared_memory_queue_t * q; \
8338 /* One registration only... */ \
8339 pool_foreach(reg, vam->nn##_registrations, \
8341 q = vl_api_client_index_to_input_queue (reg->client_index); \
8344 * If the queue is stuffed, turf the msg and complain \
8345 * It's unlikely that the intended recipient is \
8346 * alive; avoid deadlock at all costs. \
8348 if (q->cursize == q->maxsize) { \
8349 clib_warning ("ERROR: receiver queue full, drop msg"); \
8350 vl_msg_api_free (mp); \
8353 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8357 vl_msg_api_free (mp); \
8362 * Add vpe's API message handlers to the table.
8363 * vlib has alread mapped shared memory and
8364 * added the client registration handlers.
8365 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8368 static clib_error_t *
8369 vpe_api_hookup (vlib_main_t * vm)
8371 api_main_t *am = &api_main;
8374 vl_msg_api_set_handlers(VL_API_##N, #n, \
8375 vl_api_##n##_t_handler, \
8377 vl_api_##n##_t_endian, \
8378 vl_api_##n##_t_print, \
8379 sizeof(vl_api_##n##_t), 1);
8380 foreach_vpe_api_msg;
8384 * Manually register the sr tunnel add del msg, so we trace
8385 * enough bytes to capture a typical segment list
8387 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8388 "sr_tunnel_add_del",
8389 vl_api_sr_tunnel_add_del_t_handler,
8391 vl_api_sr_tunnel_add_del_t_endian,
8392 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8396 * Manually register the sr policy add del msg, so we trace
8397 * enough bytes to capture a typical tunnel name list
8399 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8400 "sr_policy_add_del",
8401 vl_api_sr_policy_add_del_t_handler,
8403 vl_api_sr_policy_add_del_t_endian,
8404 vl_api_sr_policy_add_del_t_print, 256, 1);
8407 * Trace space for 8 MPLS encap labels, classifier mask+match
8409 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8410 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8411 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8412 += 5 * sizeof (u32x4);
8413 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8416 * Thread-safe API messages
8418 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8419 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8424 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8426 static clib_error_t *
8427 vpe_api_init (vlib_main_t * vm)
8429 vpe_api_main_t *am = &vpe_api_main;
8432 am->vnet_main = vnet_get_main ();
8433 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8434 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8435 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8436 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8437 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8438 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8441 vl_set_memory_region_name ("/vpe-api");
8442 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8447 VLIB_INIT_FUNCTION (vpe_api_init);
8450 static clib_error_t *
8451 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8454 u64 baseva, size, pvt_heap_size;
8456 const int max_buf_size = 4096;
8458 struct passwd _pw, *pw;
8459 struct group _grp, *grp;
8461 buf = vec_new (char, 128);
8462 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8464 if (unformat (input, "prefix %s", &chroot_path))
8466 vec_add1 (chroot_path, 0);
8467 vl_set_memory_root_path ((char *) chroot_path);
8469 else if (unformat (input, "uid %d", &uid))
8470 vl_set_memory_uid (uid);
8471 else if (unformat (input, "gid %d", &gid))
8472 vl_set_memory_gid (gid);
8473 else if (unformat (input, "baseva %llx", &baseva))
8474 vl_set_global_memory_baseva (baseva);
8475 else if (unformat (input, "global-size %lldM", &size))
8476 vl_set_global_memory_size (size * (1ULL << 20));
8477 else if (unformat (input, "global-size %lldG", &size))
8478 vl_set_global_memory_size (size * (1ULL << 30));
8479 else if (unformat (input, "global-size %lld", &size))
8480 vl_set_global_memory_size (size);
8481 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8482 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8483 else if (unformat (input, "global-pvt-heap-size size %lld",
8485 vl_set_global_pvt_heap_size (pvt_heap_size);
8486 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8487 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8488 else if (unformat (input, "api-pvt-heap-size size %lld",
8490 vl_set_api_pvt_heap_size (pvt_heap_size);
8491 else if (unformat (input, "api-size %lldM", &size))
8492 vl_set_api_memory_size (size * (1ULL << 20));
8493 else if (unformat (input, "api-size %lldG", &size))
8494 vl_set_api_memory_size (size * (1ULL << 30));
8495 else if (unformat (input, "api-size %lld", &size))
8496 vl_set_api_memory_size (size);
8497 else if (unformat (input, "uid %s", &s))
8499 /* lookup the username */
8502 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8503 && (vec_len (buf) <= max_buf_size))
8505 vec_resize (buf, vec_len (buf) * 2);
8509 e = clib_error_return_code (0, rv,
8510 CLIB_ERROR_ERRNO_VALID |
8512 "cannot fetch username %s", s);
8520 clib_error_return_fatal (0, "username %s does not exist", s);
8526 vl_set_memory_uid (pw->pw_uid);
8528 else if (unformat (input, "gid %s", &s))
8530 /* lookup the group name */
8533 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8534 && (vec_len (buf) <= max_buf_size))
8536 vec_resize (buf, vec_len (buf) * 2);
8540 e = clib_error_return_code (0, rv,
8541 CLIB_ERROR_ERRNO_VALID |
8543 "cannot fetch group %s", s);
8550 e = clib_error_return_fatal (0, "group %s does not exist", s);
8557 vl_set_memory_gid (grp->gr_gid);
8560 return clib_error_return (0, "unknown input `%U'",
8561 format_unformat_error, input);
8566 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8569 get_unformat_vnet_sw_interface (void)
8571 return (void *) &unformat_vnet_sw_interface;
8574 #undef vl_api_version
8575 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8576 #include <vpp-api/vpe.api.h>
8577 #undef vl_api_version
8580 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8582 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8584 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8585 clib_host_to_net_u32 (mp->api_versions[0]),
8593 format_arp_event (u8 * s, va_list * args)
8595 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8597 s = format (s, "pid %d: ", event->pid);
8599 s = format (s, "bd mac/ip4 binding events");
8601 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8606 format_nd_event (u8 * s, va_list * args)
8608 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8610 s = format (s, "pid %d: ", event->pid);
8612 s = format (s, "bd mac/ip6 binding events");
8614 s = format (s, "resolution for %U", format_ip6_address, event->address);
8618 static clib_error_t *
8619 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8620 unformat_input_t * input, vlib_cli_command_t * cmd)
8622 vpe_api_main_t *am = &vpe_api_main;
8623 vl_api_ip4_arp_event_t *arp_event;
8624 vl_api_ip6_nd_event_t *nd_event;
8626 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8628 vlib_cli_output (vm, "No active arp or nd event registrations");
8633 pool_foreach (arp_event, am->arp_events,
8635 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8638 pool_foreach (nd_event, am->nd_events,
8640 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8648 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8649 .path = "show arp-nd-event registrations",
8650 .function = show_ip_arp_nd_events_fn,
8651 .short_help = "Show ip4 arp and ip6 nd event registrations",
8656 * fd.io coding-style-patch-verification: ON
8659 * eval: (c-set-style "gnu")