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 #define REPLY_MACRO3(t, n, body) \
160 unix_shared_memory_queue_t * q; \
161 rv = vl_msg_api_pd_handler (mp, rv); \
162 q = vl_api_client_index_to_input_queue (mp->client_index); \
166 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
167 rmp->_vl_msg_id = ntohs((t)); \
168 rmp->context = mp->context; \
169 rmp->retval = ntohl(rv); \
170 do {body;} while (0); \
171 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
174 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
176 #define VALIDATE_SW_IF_INDEX(mp) \
177 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
178 vnet_main_t *__vnm = vnet_get_main(); \
179 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
181 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
182 goto bad_sw_if_index; \
186 #define BAD_SW_IF_INDEX_LABEL \
192 #define VALIDATE_RX_SW_IF_INDEX(mp) \
193 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
194 vnet_main_t *__vnm = vnet_get_main(); \
195 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
196 __rx_sw_if_index)) { \
197 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
198 goto bad_rx_sw_if_index; \
202 #define BAD_RX_SW_IF_INDEX_LABEL \
204 bad_rx_sw_if_index: \
208 #define VALIDATE_TX_SW_IF_INDEX(mp) \
209 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
210 vnet_main_t *__vnm = vnet_get_main(); \
211 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
212 __tx_sw_if_index)) { \
213 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
214 goto bad_tx_sw_if_index; \
218 #define BAD_TX_SW_IF_INDEX_LABEL \
220 bad_tx_sw_if_index: \
226 #define VALIDATE_SW_IF_INDEX(mp)
227 #define BAD_SW_IF_INDEX_LABEL
228 #define VALIDATE_RX_SW_IF_INDEX(mp)
229 #define BAD_RX_SW_IF_INDEX_LABEL
230 #define VALIDATE_TX_SW_IF_INDEX(mp)
231 #define BAD_TX_SW_IF_INDEX_LABEL
233 #endif /* CLIB_DEBUG > 0 */
235 #define foreach_vpe_api_msg \
236 _(WANT_INTERFACE_EVENTS, want_interface_events) \
237 _(WANT_OAM_EVENTS, want_oam_events) \
238 _(OAM_ADD_DEL, oam_add_del) \
239 _(SW_INTERFACE_DUMP, sw_interface_dump) \
240 _(SW_INTERFACE_DETAILS, sw_interface_details) \
241 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
242 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
243 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
244 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
245 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
246 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
247 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
248 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
249 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
250 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
251 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
252 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
253 _(L2FIB_ADD_DEL, l2fib_add_del) \
254 _(L2_FLAGS, l2_flags) \
255 _(BRIDGE_FLAGS, bridge_flags) \
256 _(TAP_CONNECT, tap_connect) \
257 _(TAP_MODIFY, tap_modify) \
258 _(TAP_DELETE, tap_delete) \
259 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
260 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
261 _(CREATE_SUBIF, create_subif) \
262 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
263 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
264 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
265 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
266 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
267 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
268 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
269 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
270 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
271 _(RESET_FIB, reset_fib) \
272 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
273 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
274 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
275 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
276 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
277 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
278 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
279 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
280 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
281 sw_interface_ip6_set_link_local_address) \
282 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
283 _(CREATE_LOOPBACK, create_loopback) \
284 _(CONTROL_PING, control_ping) \
285 _(NOPRINT_CONTROL_PING, noprint_control_ping) \
286 _(CLI_REQUEST, cli_request) \
287 _(CLI_INBAND, cli_inband) \
288 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
289 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
290 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
291 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
292 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
293 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
294 _(GET_NODE_INDEX, get_node_index) \
295 _(ADD_NODE_NEXT, add_node_next) \
296 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
297 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
298 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
299 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
300 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
301 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
302 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
303 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
304 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
305 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
306 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
307 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
308 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
309 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
310 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
311 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
312 _(IP_ADDRESS_DUMP, ip_address_dump) \
313 _(IP_DUMP, ip_dump) \
314 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
315 _(SHOW_VERSION, show_version) \
316 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
317 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
318 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
319 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
320 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
321 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
322 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
323 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
324 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
325 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
326 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
327 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
328 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
329 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
330 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
331 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
332 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
333 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
334 _(DELETE_LOOPBACK, delete_loopback) \
335 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
336 _(MAP_ADD_DOMAIN, map_add_domain) \
337 _(MAP_DEL_DOMAIN, map_del_domain) \
338 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
339 _(MAP_DOMAIN_DUMP, map_domain_dump) \
340 _(MAP_RULE_DUMP, map_rule_dump) \
341 _(MAP_SUMMARY_STATS, map_summary_stats) \
342 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
343 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
344 _(GET_NODE_GRAPH, get_node_graph) \
345 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
346 _(TRACE_PROFILE_ADD, trace_profile_add) \
347 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
348 _(TRACE_PROFILE_DEL, trace_profile_del) \
349 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
350 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
351 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
352 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
353 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
354 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
355 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
356 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
357 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
358 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
359 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
360 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
361 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
362 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
363 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
364 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
365 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
366 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
367 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
368 _(SHOW_LISP_STATUS, show_lisp_status) \
369 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
370 lisp_add_del_map_request_itr_rlocs) \
371 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
372 _(SHOW_LISP_PITR, show_lisp_pitr) \
373 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
374 _(AF_PACKET_CREATE, af_packet_create) \
375 _(AF_PACKET_DELETE, af_packet_delete) \
376 _(POLICER_ADD_DEL, policer_add_del) \
377 _(POLICER_DUMP, policer_dump) \
378 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
379 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
380 _(NETMAP_CREATE, netmap_create) \
381 _(NETMAP_DELETE, netmap_delete) \
382 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
383 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
384 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
385 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
386 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
387 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
388 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
389 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
390 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
391 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
392 _(CLASSIFY_TABLE_INFO,classify_table_info) \
393 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
394 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
395 _(IPFIX_ENABLE,ipfix_enable) \
396 _(IPFIX_DUMP,ipfix_dump) \
397 _(GET_NEXT_INDEX, get_next_index) \
398 _(PG_CREATE_INTERFACE, pg_create_interface) \
399 _(PG_CAPTURE, pg_capture) \
400 _(PG_ENABLE_DISABLE, pg_enable_disable) \
401 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
402 ip_source_and_port_range_check_add_del) \
403 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
404 ip_source_and_port_range_check_interface_add_del) \
405 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
406 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
407 _(DELETE_SUBIF, delete_subif)
410 #define QUOTE(x) QUOTE_(x)
412 #define foreach_registration_hash \
413 _(interface_events) \
414 _(to_netconf_server) \
415 _(from_netconf_server) \
416 _(to_netconf_client) \
417 _(from_netconf_client) \
422 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
423 RESOLVE_IP6_ADD_DEL_ROUTE,
424 RESOLVE_MPLS_ETHERNET_ADD_DEL,
432 vl_api_ip_add_del_route_t r;
433 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
440 #define _(a) uword *a##_registration_hash; \
441 vpe_client_registration_t * a##_registrations;
442 foreach_registration_hash
444 /* notifications happen really early in the game */
445 u8 link_state_process_up;
447 /* ip4 and ip6 pending route adds */
448 pending_route_t *pending_routes;
450 /* ip4 arp event registration pool */
451 vl_api_ip4_arp_event_t *arp_events;
453 /* ip6 nd event registration pool */
454 vl_api_ip6_nd_event_t *nd_events;
457 vlib_main_t *vlib_main;
458 vnet_main_t *vnet_main;
461 static vlib_node_registration_t vpe_resolver_process_node;
462 static vpe_api_main_t vpe_api_main;
464 static void send_sw_interface_flags (vpe_api_main_t * am,
465 unix_shared_memory_queue_t * q,
466 vnet_sw_interface_t * swif);
467 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
468 unix_shared_memory_queue_t * q,
471 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
472 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
475 /* Clean up all registrations belonging to the indicated client */
477 vl_api_memclnt_delete_callback (u32 client_index)
479 vpe_api_main_t *vam = &vpe_api_main;
480 vpe_client_registration_t *rp;
482 int stats_memclnt_delete_callback (u32 client_index);
484 stats_memclnt_delete_callback (client_index);
487 p = hash_get (vam->a##_registration_hash, client_index); \
489 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
490 pool_put (vam->a##_registrations, rp); \
491 hash_unset (vam->a##_registration_hash, client_index); \
493 foreach_registration_hash;
498 #define API_LINK_STATE_EVENT 1
499 #define API_ADMIN_UP_DOWN_EVENT 2
502 event_data_cmp (void *a1, void *a2)
507 return (word) e1[0] - (word) e2[0];
511 link_state_process (vlib_main_t * vm,
512 vlib_node_runtime_t * rt, vlib_frame_t * f)
514 vpe_api_main_t *vam = &vpe_api_main;
515 vnet_main_t *vnm = vam->vnet_main;
516 vnet_sw_interface_t *swif;
517 uword *event_data = 0;
518 vpe_client_registration_t *reg;
520 u32 prev_sw_if_index;
521 unix_shared_memory_queue_t *q;
523 vam->link_state_process_up = 1;
527 vlib_process_wait_for_event (vm);
529 /* Unified list of changed link or admin state sw_if_indices */
530 vlib_process_get_events_with_type
531 (vm, &event_data, API_LINK_STATE_EVENT);
532 vlib_process_get_events_with_type
533 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
535 /* Sort, so we can eliminate duplicates */
536 vec_sort_with_function (event_data, event_data_cmp);
538 prev_sw_if_index = ~0;
540 for (i = 0; i < vec_len (event_data); i++)
542 /* Only one message per swif */
543 if (prev_sw_if_index == event_data[i])
545 prev_sw_if_index = event_data[i];
548 pool_foreach(reg, vam->interface_events_registrations,
550 q = vl_api_client_index_to_input_queue (reg->client_index);
553 /* sw_interface may be deleted already */
554 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
557 swif = vnet_get_sw_interface (vnm, event_data[i]);
558 send_sw_interface_flags (vam, q, swif);
564 vec_reset_length (event_data);
570 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
572 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
573 u32 hw_if_index, u32 flags);
576 VLIB_REGISTER_NODE (link_state_process_node,static) = {
577 .function = link_state_process,
578 .type = VLIB_NODE_TYPE_PROCESS,
579 .name = "vpe-link-state-process",
583 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
584 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
586 static clib_error_t *
587 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
589 vpe_api_main_t *vam = &vpe_api_main;
590 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
592 if (vam->link_state_process_up)
593 vlib_process_signal_event (vam->vlib_main,
594 link_state_process_node.index,
595 API_LINK_STATE_EVENT, hi->sw_if_index);
599 static clib_error_t *
600 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
602 vpe_api_main_t *vam = &vpe_api_main;
605 * Note: it's perfectly fair to set a subif admin up / admin down.
606 * Note the subtle distinction between this routine and the previous
609 if (vam->link_state_process_up)
610 vlib_process_signal_event (vam->vlib_main,
611 link_state_process_node.index,
612 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
616 #define pub_sub_handler(lca,UCA) \
617 static void vl_api_want_##lca##_t_handler ( \
618 vl_api_want_##lca##_t *mp) \
620 vpe_api_main_t *vam = &vpe_api_main; \
621 vpe_client_registration_t *rp; \
622 vl_api_want_##lca##_reply_t *rmp; \
626 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
628 if (mp->enable_disable) { \
629 clib_warning ("pid %d: already enabled...", mp->pid); \
630 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
633 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
634 pool_put (vam->lca##_registrations, rp); \
635 hash_unset (vam->lca##_registration_hash, \
640 if (mp->enable_disable == 0) { \
641 clib_warning ("pid %d: already disabled...", mp->pid); \
642 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
645 pool_get (vam->lca##_registrations, rp); \
646 rp->client_index = mp->client_index; \
647 rp->client_pid = mp->pid; \
648 hash_set (vam->lca##_registration_hash, rp->client_index, \
649 rp - vam->lca##_registrations); \
652 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
656 pub_sub_handler (interface_events, INTERFACE_EVENTS)
657 pub_sub_handler (oam_events, OAM_EVENTS)
660 #define RESOLUTION_EVENT 1
661 #define RESOLUTION_PENDING_EVENT 2
662 #define IP4_ARP_EVENT 3
663 #define IP6_ND_EVENT 4
665 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
667 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
669 static int mpls_ethernet_add_del_tunnel_2_t_handler
670 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
673 handle_ip4_arp_event (u32 pool_index)
675 vpe_api_main_t *vam = &vpe_api_main;
676 vnet_main_t *vnm = vam->vnet_main;
677 vlib_main_t *vm = vam->vlib_main;
678 vl_api_ip4_arp_event_t *event;
679 vl_api_ip4_arp_event_t *mp;
680 unix_shared_memory_queue_t *q;
682 /* Client can cancel, die, etc. */
683 if (pool_is_free_index (vam->arp_events, pool_index))
686 event = pool_elt_at_index (vam->arp_events, pool_index);
688 q = vl_api_client_index_to_input_queue (event->client_index);
691 (void) vnet_add_del_ip4_arp_change_event
692 (vnm, arp_change_delete_callback,
693 event->pid, &event->address,
694 vpe_resolver_process_node.index, IP4_ARP_EVENT,
695 ~0 /* pool index, notused */ , 0 /* is_add */ );
699 if (q->cursize < q->maxsize)
701 mp = vl_msg_api_alloc (sizeof (*mp));
702 clib_memcpy (mp, event, sizeof (*mp));
703 vl_msg_api_send_shmem (q, (u8 *) & mp);
707 static f64 last_time;
709 * Throttle syslog msgs.
710 * It's pretty tempting to just revoke the registration...
712 if (vlib_time_now (vm) > last_time + 10.0)
714 clib_warning ("arp event for %U to pid %d: queue stuffed!",
715 format_ip4_address, &event->address, event->pid);
716 last_time = vlib_time_now (vm);
722 handle_ip6_nd_event (u32 pool_index)
724 vpe_api_main_t *vam = &vpe_api_main;
725 vnet_main_t *vnm = vam->vnet_main;
726 vlib_main_t *vm = vam->vlib_main;
727 vl_api_ip6_nd_event_t *event;
728 vl_api_ip6_nd_event_t *mp;
729 unix_shared_memory_queue_t *q;
731 /* Client can cancel, die, etc. */
732 if (pool_is_free_index (vam->nd_events, pool_index))
735 event = pool_elt_at_index (vam->nd_events, pool_index);
737 q = vl_api_client_index_to_input_queue (event->client_index);
740 (void) vnet_add_del_ip6_nd_change_event
741 (vnm, nd_change_delete_callback,
742 event->pid, &event->address,
743 vpe_resolver_process_node.index, IP6_ND_EVENT,
744 ~0 /* pool index, notused */ , 0 /* is_add */ );
748 if (q->cursize < q->maxsize)
750 mp = vl_msg_api_alloc (sizeof (*mp));
751 clib_memcpy (mp, event, sizeof (*mp));
752 vl_msg_api_send_shmem (q, (u8 *) & mp);
756 static f64 last_time;
758 * Throttle syslog msgs.
759 * It's pretty tempting to just revoke the registration...
761 if (vlib_time_now (vm) > last_time + 10.0)
763 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
764 format_ip6_address, &event->address, event->pid);
765 last_time = vlib_time_now (vm);
771 resolver_process (vlib_main_t * vm,
772 vlib_node_runtime_t * rt, vlib_frame_t * f)
775 uword *event_data = 0;
777 vpe_api_main_t *vam = &vpe_api_main;
779 vl_api_ip_add_del_route_t *adr;
780 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
781 u32 *resolution_failures = 0;
787 vlib_process_wait_for_event_or_clock (vm, timeout);
789 event_type = vlib_process_get_events (vm, &event_data);
793 case RESOLUTION_PENDING_EVENT:
797 case RESOLUTION_EVENT:
798 for (i = 0; i < vec_len (event_data); i++)
801 * Resolution events can occur long after the
802 * original request has timed out. $$$ add a cancel
805 if (pool_is_free_index (vam->pending_routes, event_data[i]))
808 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
812 switch (pr->resolve_type)
814 case RESOLVE_IP4_ADD_DEL_ROUTE:
815 rv = ip4_add_del_route_t_handler (adr);
816 clib_warning ("resolver: add %U/%d via %U %s",
818 (ip4_address_t *) & (adr->dst_address),
819 adr->dst_address_length,
821 (ip4_address_t *) & (adr->next_hop_address),
822 (rv >= 0) ? "succeeded" : "failed");
825 case RESOLVE_IP6_ADD_DEL_ROUTE:
826 rv = ip6_add_del_route_t_handler (adr);
827 clib_warning ("resolver: add %U/%d via %U %s",
829 (ip6_address_t *) & (adr->dst_address),
830 adr->dst_address_length,
832 (ip6_address_t *) & (adr->next_hop_address),
833 (rv >= 0) ? "succeeded" : "failed");
836 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
837 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
838 clib_warning ("resolver: add mpls-o-e via %U %s",
841 (pme->next_hop_ip4_address_in_outer_vrf),
842 (rv >= 0) ? "succeeded" : "failed");
846 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
848 pool_put (vam->pending_routes, pr);
853 for (i = 0; i < vec_len (event_data); i++)
854 handle_ip4_arp_event (event_data[i]);
858 for (i = 0; i < vec_len (event_data); i++)
859 handle_ip6_nd_event (event_data[i]);
862 case ~0: /* timeout, retry pending resolutions */
864 pool_foreach (pr, vam->pending_routes,
870 /* May fail, e.g. due to interface down */
871 switch (pr->resolve_type)
873 case RESOLVE_IP4_ADD_DEL_ROUTE:
874 e = ip4_probe_neighbor
875 (vm, (ip4_address_t *)&(adr->next_hop_address),
876 ntohl(adr->next_hop_sw_if_index));
879 case RESOLVE_IP6_ADD_DEL_ROUTE:
880 e = ip6_probe_neighbor
881 (vm, (ip6_address_t *)&(adr->next_hop_address),
882 ntohl(adr->next_hop_sw_if_index));
885 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
887 e = ip4_probe_neighbor
889 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
890 pme->resolve_opaque);
894 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
899 clib_error_report (e);
901 adr->resolve_attempts = 1;
903 pme->resolve_attempts = 1;
907 adr->resolve_attempts -= 1;
908 if (adr->resolve_attempts == 0)
909 vec_add1 (resolution_failures,
910 pr - vam->pending_routes);
914 pme->resolve_attempts -= 1;
915 if (pme->resolve_attempts == 0)
916 vec_add1 (resolution_failures,
917 pr - vam->pending_routes);
921 for (i = 0; i < vec_len (resolution_failures); i++)
923 pr = pool_elt_at_index (vam->pending_routes,
924 resolution_failures[i]);
928 switch (pr->resolve_type)
930 case RESOLVE_IP4_ADD_DEL_ROUTE:
931 clib_warning ("resolver: add %U/%d via %U retry failure",
933 (ip4_address_t *) & (adr->dst_address),
934 adr->dst_address_length,
936 (ip4_address_t *) & (adr->next_hop_address));
939 case RESOLVE_IP6_ADD_DEL_ROUTE:
940 clib_warning ("resolver: add %U/%d via %U retry failure",
942 (ip6_address_t *) & (adr->dst_address),
943 adr->dst_address_length,
945 (ip6_address_t *) & (adr->next_hop_address));
948 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
949 clib_warning ("resolver: add mpls-o-e via %U retry failure",
952 (pme->next_hop_ip4_address_in_outer_vrf));
956 clib_warning ("BUG");
958 pool_put (vam->pending_routes, pr);
960 vec_reset_length (resolution_failures);
963 if (pool_elts (vam->pending_routes) == 0)
965 vec_reset_length (event_data);
967 return 0; /* or not */
971 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
972 .function = resolver_process,
973 .type = VLIB_NODE_TYPE_PROCESS,
974 .name = "vpe-route-resolver-process",
979 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
981 ip4_main_t *im = &ip4_main;
982 ip_lookup_main_t *lm = &im->lookup_main;
983 vnet_classify_main_t *cm = &vnet_classify_main;
984 stats_main_t *sm = &stats_main;
985 ip4_add_del_route_args_t a;
986 ip4_address_t next_hop_address;
988 vpe_api_main_t *vam = &vpe_api_main;
989 vnet_main_t *vnm = vam->vnet_main;
990 vlib_main_t *vm = vlib_get_main ();
992 vl_api_ip_add_del_route_t *adr;
998 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1001 if (mp->create_vrf_if_needed)
1004 f = find_ip4_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1006 fib_index = f->index;
1010 /* No such VRF, and we weren't asked to create one */
1011 return VNET_API_ERROR_NO_SUCH_FIB;
1019 if (~0 != mp->next_hop_sw_if_index &&
1020 pool_is_free_index (vnm->interface_main.sw_interfaces,
1021 ntohl (mp->next_hop_sw_if_index)))
1022 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1024 clib_memcpy (next_hop_address.data, mp->next_hop_address,
1025 sizeof (next_hop_address.data));
1027 /* Arp for the next_hop if necessary */
1028 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1031 ip_adjacency_t *adj;
1033 lookup_result = ip4_fib_lookup_with_table
1034 (im, fib_index, &next_hop_address, 1 /* disable default route */ );
1036 adj = ip_get_adjacency (lm, lookup_result);
1038 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1040 pool_get (vam->pending_routes, pr);
1041 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
1043 clib_memcpy (adr, mp, sizeof (*adr));
1044 /* recursion block, "just in case" */
1045 adr->resolve_if_needed = 0;
1046 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1047 vnet_register_ip4_arp_resolution_event
1048 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1049 RESOLUTION_EVENT, pr - vam->pending_routes);
1051 vlib_process_signal_event
1052 (vm, vpe_resolver_process_node.index,
1053 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1055 /* The interface may be down, etc. */
1056 e = ip4_probe_neighbor
1057 (vm, (ip4_address_t *) & (mp->next_hop_address),
1058 ntohl (mp->next_hop_sw_if_index));
1061 clib_error_report (e);
1063 return VNET_API_ERROR_IN_PROGRESS;
1067 if (mp->is_multipath)
1071 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1074 flags = IP4_ROUTE_FLAG_ADD;
1076 flags = IP4_ROUTE_FLAG_DEL;
1079 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1081 ip4_add_del_route_next_hop (im, flags,
1082 (ip4_address_t *) mp->dst_address,
1083 (u32) mp->dst_address_length,
1084 (ip4_address_t *) mp->next_hop_address,
1085 ntohl (mp->next_hop_sw_if_index),
1086 (u32) mp->next_hop_weight,
1087 ~0 /* adj_index */ ,
1093 memset (&a, 0, sizeof (a));
1094 clib_memcpy (a.dst_address.data, mp->dst_address,
1095 sizeof (a.dst_address.data));
1097 a.dst_address_length = mp->dst_address_length;
1099 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
1100 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
1101 a.table_index_or_table_id = fib_index;
1106 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1108 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1113 ai = lm->drop_adj_index;
1114 else if (mp->is_local)
1115 ai = lm->local_adj_index;
1116 else if (mp->is_classify)
1118 if (pool_is_free_index
1119 (cm->tables, ntohl (mp->classify_table_index)))
1122 return VNET_API_ERROR_NO_SUCH_TABLE;
1124 adj = ip_add_adjacency (lm,
1129 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
1130 adj->classify.table_index = ntohl (mp->classify_table_index);
1132 else if (mp->lookup_in_vrf)
1134 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1137 adj = ip_add_adjacency (lm,
1141 adj->explicit_fib_index = p[0];
1146 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1150 ai = ip4_route_get_next_hop_adj (im,
1153 ntohl (mp->next_hop_sw_if_index),
1156 if (ai == lm->miss_adj_index)
1159 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1164 ip_adjacency_t *adj;
1165 int disable_default_route = 1;
1167 /* Trying to delete the default route? */
1168 if (a.dst_address.as_u32 == 0 && a.dst_address_length == 0)
1169 disable_default_route = 0;
1171 ai = ip4_fib_lookup_with_table
1172 (im, fib_index, &a.dst_address, disable_default_route);
1173 if (ai == lm->miss_adj_index)
1176 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1179 adj = ip_get_adjacency (lm, ai);
1180 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1183 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1188 ip4_add_del_route (im, &a);
1195 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1197 ip6_main_t *im = &ip6_main;
1198 ip_lookup_main_t *lm = &im->lookup_main;
1199 vnet_main_t *vnm = vnet_get_main ();
1200 vlib_main_t *vm = vlib_get_main ();
1201 vpe_api_main_t *vam = &vpe_api_main;
1202 stats_main_t *sm = &stats_main;
1203 ip6_add_del_route_args_t a;
1204 ip6_address_t next_hop_address;
1205 pending_route_t *pr;
1206 vl_api_ip_add_del_route_t *adr;
1211 ip_adjacency_t *adj = 0;
1214 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1218 if (mp->create_vrf_if_needed)
1221 f = find_ip6_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1223 fib_index = f->index;
1227 /* No such VRF, and we weren't asked to create one */
1228 return VNET_API_ERROR_NO_SUCH_FIB;
1236 if (~0 != mp->next_hop_sw_if_index &&
1237 pool_is_free_index (vnm->interface_main.sw_interfaces,
1238 ntohl (mp->next_hop_sw_if_index)))
1239 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1241 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1242 sizeof (next_hop_address.as_u8));
1244 /* Arp for the next_hop if necessary */
1245 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1248 ip_adjacency_t *adj;
1250 lookup_result = ip6_fib_lookup_with_table
1251 (im, fib_index, &next_hop_address);
1253 adj = ip_get_adjacency (lm, lookup_result);
1255 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1257 pool_get (vam->pending_routes, pr);
1259 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1260 clib_memcpy (adr, mp, sizeof (*adr));
1261 /* recursion block, "just in case" */
1262 adr->resolve_if_needed = 0;
1263 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1264 vnet_register_ip6_neighbor_resolution_event
1265 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1266 RESOLUTION_EVENT, pr - vam->pending_routes);
1268 vlib_process_signal_event
1269 (vm, vpe_resolver_process_node.index,
1270 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1272 /* The interface may be down, etc. */
1273 e = ip6_probe_neighbor
1274 (vm, (ip6_address_t *) & (mp->next_hop_address),
1275 ntohl (mp->next_hop_sw_if_index));
1278 clib_error_report (e);
1280 return VNET_API_ERROR_IN_PROGRESS;
1284 if (mp->is_multipath)
1288 dslock (sm, 1 /* release hint */ , 11 /* tag */ );
1291 flags = IP6_ROUTE_FLAG_ADD;
1293 flags = IP6_ROUTE_FLAG_DEL;
1296 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1298 ip6_add_del_route_next_hop (im, flags,
1299 (ip6_address_t *) mp->dst_address,
1300 (u32) mp->dst_address_length,
1301 (ip6_address_t *) mp->next_hop_address,
1302 ntohl (mp->next_hop_sw_if_index),
1303 (u32) mp->next_hop_weight,
1304 ~0 /* adj_index */ ,
1310 memset (&a, 0, sizeof (a));
1311 clib_memcpy (a.dst_address.as_u8, mp->dst_address,
1312 sizeof (a.dst_address.as_u8));
1314 a.dst_address_length = mp->dst_address_length;
1316 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1317 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1318 a.table_index_or_table_id = fib_index;
1323 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1325 dslock (sm, 1 /* release hint */ , 3 /* tag */ );
1330 ai = lm->drop_adj_index;
1331 else if (mp->is_local)
1332 ai = lm->local_adj_index;
1333 else if (mp->lookup_in_vrf)
1335 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1338 adj = ip_add_adjacency (lm,
1342 adj->explicit_fib_index = p[0];
1347 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1351 ai = ip6_route_get_next_hop_adj (im,
1354 ntohl (mp->next_hop_sw_if_index),
1356 if (ai == lm->miss_adj_index)
1359 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1364 ip_adjacency_t *adj;
1366 ai = ip6_fib_lookup_with_table (im, fib_index, &a.dst_address);
1367 if (ai == lm->miss_adj_index)
1370 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1372 adj = ip_get_adjacency (lm, ai);
1373 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1376 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1381 ip6_add_del_route (im, &a);
1388 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1390 vl_api_ip_add_del_route_reply_t *rmp;
1392 vnet_main_t *vnm = vnet_get_main ();
1397 rv = ip6_add_del_route_t_handler (mp);
1399 rv = ip4_add_del_route_t_handler (mp);
1401 rv = (rv == 0) ? vnm->api_errno : rv;
1403 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1407 api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1408 u32 sw_if_index, u8 * next_hop_addr)
1410 vl_api_ip_add_del_route_t mp;
1413 memset (&mp, 0, sizeof (vl_api_ip_add_del_route_t));
1416 * Configure default IP route:
1417 * - ip route add 0.0.0.0/1 via <GW IP>
1418 * - ip route add 128.0.0.0/1 via <GW IP>
1420 mp.next_hop_sw_if_index = ntohl (sw_if_index);
1422 mp.resolve_attempts = ~0;
1423 mp.resolve_if_needed = 1;
1425 mp.is_ipv6 = is_ipv6;
1426 mp.next_hop_weight = 1;
1428 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1431 rv = ip6_add_del_route_t_handler (&mp);
1434 mp.dst_address_length = 1;
1436 mp.dst_address[0] = 0;
1437 rv = ip4_add_del_route_t_handler (&mp);
1439 mp.dst_address[0] = 128;
1440 rv |= ip4_add_del_route_t_handler (&mp);
1444 clib_error_return (0, "failed to config default IP route");
1449 vl_api_sw_interface_add_del_address_t_handler
1450 (vl_api_sw_interface_add_del_address_t * mp)
1452 vlib_main_t *vm = vlib_get_main ();
1453 vl_api_sw_interface_add_del_address_reply_t *rmp;
1457 VALIDATE_SW_IF_INDEX (mp);
1459 is_del = mp->is_add == 0;
1462 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1463 else if (mp->is_ipv6)
1464 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1465 (void *) mp->address,
1466 mp->address_length, is_del);
1468 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1469 (void *) mp->address,
1470 mp->address_length, is_del);
1472 BAD_SW_IF_INDEX_LABEL;
1474 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1478 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1481 u32 table_id = ntohl (mp->vrf_id);
1482 u32 sw_if_index = ntohl (mp->sw_if_index);
1483 vl_api_sw_interface_set_table_reply_t *rmp;
1484 stats_main_t *sm = &stats_main;
1486 VALIDATE_SW_IF_INDEX (mp);
1488 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1492 ip6_main_t *im = &ip6_main;
1493 ip6_fib_t *fib = find_ip6_fib_by_table_index_or_id (im, table_id,
1494 IP6_ROUTE_FLAG_TABLE_ID);
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 ip4_main_t *im = &ip4_main;
1508 ip4_fib_t *fib = find_ip4_fib_by_table_index_or_id
1509 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1511 /* Truthfully this can't fail */
1514 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1515 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1519 rv = VNET_API_ERROR_NO_SUCH_FIB;
1524 BAD_SW_IF_INDEX_LABEL;
1526 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1530 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1532 vlib_main_t *vm = vlib_get_main ();
1533 ip4_main_t *im4 = &ip4_main;
1534 ip6_main_t *im6 = &ip6_main;
1535 vl_api_sw_interface_set_vpath_reply_t *rmp;
1538 u32 sw_if_index = ntohl (mp->sw_if_index);
1539 ip4_main_t *ip4m = &ip4_main;
1540 ip6_main_t *ip6m = &ip6_main;
1541 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1542 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1543 ip_config_main_t *rx_cm4u =
1544 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1545 ip_config_main_t *rx_cm4m =
1546 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1547 ip_config_main_t *rx_cm6u =
1548 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1549 ip_config_main_t *rx_cm6m =
1550 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1552 VALIDATE_SW_IF_INDEX (mp);
1554 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1557 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1558 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1560 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1561 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1562 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1563 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1565 im4->ip4_multicast_rx_feature_vpath,
1567 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1568 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1569 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1571 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1572 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1573 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1574 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1576 im6->ip6_multicast_rx_feature_vpath,
1578 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1582 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1583 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1585 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1586 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1587 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1588 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1590 im4->ip4_multicast_rx_feature_vpath,
1592 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1593 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1594 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1596 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1597 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1598 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1599 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1601 im6->ip6_multicast_rx_feature_vpath,
1603 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1606 BAD_SW_IF_INDEX_LABEL;
1608 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1612 vl_api_sw_interface_set_l2_xconnect_t_handler
1613 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1615 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1617 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1618 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1619 vlib_main_t *vm = vlib_get_main ();
1620 vnet_main_t *vnm = vnet_get_main ();
1622 VALIDATE_RX_SW_IF_INDEX (mp);
1626 VALIDATE_TX_SW_IF_INDEX (mp);
1627 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1628 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1632 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1635 BAD_RX_SW_IF_INDEX_LABEL;
1636 BAD_TX_SW_IF_INDEX_LABEL;
1638 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1642 vl_api_sw_interface_set_l2_bridge_t_handler
1643 (vl_api_sw_interface_set_l2_bridge_t * mp)
1645 bd_main_t *bdm = &bd_main;
1646 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1648 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1649 u32 bd_id = ntohl (mp->bd_id);
1653 vlib_main_t *vm = vlib_get_main ();
1654 vnet_main_t *vnm = vnet_get_main ();
1656 VALIDATE_RX_SW_IF_INDEX (mp);
1658 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1662 //VALIDATE_TX_SW_IF_INDEX(mp);
1663 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1664 rx_sw_if_index, bd_index, bvi, shg, 0);
1668 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1671 BAD_RX_SW_IF_INDEX_LABEL;
1673 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1677 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1679 vlib_main_t *vm = vlib_get_main ();
1680 bd_main_t *bdm = &bd_main;
1681 vl_api_bridge_domain_add_del_reply_t *rmp;
1683 u32 enable_flags = 0, disable_flags = 0;
1684 u32 bd_id = ntohl (mp->bd_id);
1689 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1692 enable_flags |= L2_FLOOD;
1694 disable_flags |= L2_FLOOD;
1697 enable_flags |= L2_UU_FLOOD;
1699 disable_flags |= L2_UU_FLOOD;
1702 enable_flags |= L2_FWD;
1704 disable_flags |= L2_FWD;
1707 enable_flags |= L2_ARP_TERM;
1709 disable_flags |= L2_ARP_TERM;
1712 enable_flags |= L2_LEARN;
1714 disable_flags |= L2_LEARN;
1717 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1720 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1724 rv = bd_delete_bd_index (bdm, bd_id);
1726 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1730 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1732 clib_warning ("BUG");
1736 vl_api_bridge_domain_sw_if_details_t_handler
1737 (vl_api_bridge_domain_sw_if_details_t * mp)
1739 clib_warning ("BUG");
1743 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1744 l2_bridge_domain_t * bd_config,
1745 u32 n_sw_ifs, u32 context)
1747 vl_api_bridge_domain_details_t *mp;
1749 mp = vl_msg_api_alloc (sizeof (*mp));
1750 memset (mp, 0, sizeof (*mp));
1751 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1752 mp->bd_id = ntohl (bd_config->bd_id);
1753 mp->flood = bd_feature_flood (bd_config);
1754 mp->uu_flood = bd_feature_uu_flood (bd_config);
1755 mp->forward = bd_feature_forward (bd_config);
1756 mp->learn = bd_feature_learn (bd_config);
1757 mp->arp_term = bd_feature_arp_term (bd_config);
1758 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1759 mp->n_sw_ifs = ntohl (n_sw_ifs);
1760 mp->context = context;
1762 vl_msg_api_send_shmem (q, (u8 *) & mp);
1766 send_bd_sw_if_details (l2input_main_t * l2im,
1767 unix_shared_memory_queue_t * q,
1768 l2_flood_member_t * member, u32 bd_id, u32 context)
1770 vl_api_bridge_domain_sw_if_details_t *mp;
1771 l2_input_config_t *input_cfg;
1773 mp = vl_msg_api_alloc (sizeof (*mp));
1774 memset (mp, 0, sizeof (*mp));
1775 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1776 mp->bd_id = ntohl (bd_id);
1777 mp->sw_if_index = ntohl (member->sw_if_index);
1778 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1779 mp->shg = input_cfg->shg;
1780 mp->context = context;
1782 vl_msg_api_send_shmem (q, (u8 *) & mp);
1786 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1788 bd_main_t *bdm = &bd_main;
1789 l2input_main_t *l2im = &l2input_main;
1790 unix_shared_memory_queue_t *q;
1791 l2_bridge_domain_t *bd_config;
1792 u32 bd_id, bd_index;
1795 q = vl_api_client_index_to_input_queue (mp->client_index);
1800 bd_id = ntohl (mp->bd_id);
1802 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1803 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1804 for (; bd_index < end; bd_index++)
1806 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1807 /* skip dummy bd_id 0 */
1808 if (bd_config && (bd_config->bd_id > 0))
1811 l2_flood_member_t *m;
1813 n_sw_ifs = vec_len (bd_config->members);
1814 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1816 vec_foreach (m, bd_config->members)
1818 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1825 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1827 bd_main_t *bdm = &bd_main;
1828 l2input_main_t *l2im = &l2input_main;
1829 vl_api_l2fib_add_del_reply_t *rmp;
1832 u32 sw_if_index = ntohl (mp->sw_if_index);
1833 u32 bd_id = ntohl (mp->bd_id);
1842 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1845 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1846 goto bad_sw_if_index;
1852 VALIDATE_SW_IF_INDEX (mp);
1853 if (vec_len (l2im->configs) <= sw_if_index)
1855 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1856 goto bad_sw_if_index;
1860 l2_input_config_t *config;
1861 config = vec_elt_at_index (l2im->configs, sw_if_index);
1862 if (config->bridge == 0)
1864 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1865 goto bad_sw_if_index;
1868 static_mac = mp->static_mac ? 1 : 0;
1869 filter_mac = mp->filter_mac ? 1 : 0;
1870 bvi_mac = mp->bvi_mac ? 1 : 0;
1871 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1876 l2fib_del_entry (mac, bd_index);
1879 BAD_SW_IF_INDEX_LABEL;
1881 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1885 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1887 vl_api_l2_flags_reply_t *rmp;
1889 u32 sw_if_index = ntohl (mp->sw_if_index);
1890 u32 flags = ntohl (mp->feature_bitmap);
1893 VALIDATE_SW_IF_INDEX (mp);
1896 if (flags & L2INPUT_FEAT_ ## a) \
1897 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1898 foreach_l2input_feat;
1901 BAD_SW_IF_INDEX_LABEL;
1904 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1906 rmp->resulting_feature_bitmap = ntohl(rbm);
1912 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1914 vlib_main_t *vm = vlib_get_main ();
1915 bd_main_t *bdm = &bd_main;
1916 vl_api_bridge_flags_reply_t *rmp;
1918 u32 bd_id = ntohl (mp->bd_id);
1920 u32 flags = ntohl (mp->feature_bitmap);
1923 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1926 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1932 bd_set_flags (vm, bd_index, flags, mp->is_set);
1936 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1938 rmp->resulting_feature_bitmap = ntohl(flags);
1944 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1946 bd_main_t *bdm = &bd_main;
1947 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1949 u32 bd_id = ntohl (mp->bd_id);
1953 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1956 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1961 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1962 mp->mac_address, mp->is_ipv6, mp->is_add))
1963 rv = VNET_API_ERROR_UNSPECIFIED;
1966 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1970 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1973 vl_api_tap_connect_reply_t *rmp;
1974 unix_shared_memory_queue_t *q;
1975 u32 sw_if_index = (u32) ~ 0;
1977 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1978 mp->use_random_mac ? 0 : mp->mac_address,
1979 &sw_if_index, mp->renumber,
1980 ntohl (mp->custom_dev_instance));
1982 q = vl_api_client_index_to_input_queue (mp->client_index);
1986 rmp = vl_msg_api_alloc (sizeof (*rmp));
1987 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1988 rmp->context = mp->context;
1989 rmp->retval = ntohl (rv);
1990 rmp->sw_if_index = ntohl (sw_if_index);
1992 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1996 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
1999 vl_api_tap_modify_reply_t *rmp;
2000 unix_shared_memory_queue_t *q;
2001 u32 sw_if_index = (u32) ~ 0;
2003 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
2004 mp->use_random_mac ? 0 : mp->mac_address,
2005 &sw_if_index, mp->renumber,
2006 ntohl (mp->custom_dev_instance));
2008 q = vl_api_client_index_to_input_queue (mp->client_index);
2012 rmp = vl_msg_api_alloc (sizeof (*rmp));
2013 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
2014 rmp->context = mp->context;
2015 rmp->retval = ntohl (rv);
2016 rmp->sw_if_index = ntohl (sw_if_index);
2018 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2022 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
2025 vpe_api_main_t *vam = &vpe_api_main;
2026 vl_api_tap_delete_reply_t *rmp;
2027 unix_shared_memory_queue_t *q;
2028 u32 sw_if_index = ntohl (mp->sw_if_index);
2030 rv = vnet_tap_delete (vm, sw_if_index);
2032 q = vl_api_client_index_to_input_queue (mp->client_index);
2036 rmp = vl_msg_api_alloc (sizeof (*rmp));
2037 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
2038 rmp->context = mp->context;
2039 rmp->retval = ntohl (rv);
2041 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2044 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2048 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
2050 vl_api_create_vlan_subif_reply_t *rmp;
2051 vnet_main_t *vnm = vnet_get_main ();
2052 u32 hw_if_index, sw_if_index = (u32) ~ 0;
2053 vnet_hw_interface_t *hi;
2056 vnet_sw_interface_t template;
2058 vnet_interface_main_t *im = &vnm->interface_main;
2059 u64 sup_and_sub_key;
2061 unix_shared_memory_queue_t *q;
2062 clib_error_t *error;
2064 VALIDATE_SW_IF_INDEX (mp);
2066 hw_if_index = ntohl (mp->sw_if_index);
2067 hi = vnet_get_hw_interface (vnm, hw_if_index);
2069 id = ntohl (mp->vlan_id);
2070 if (id == 0 || id > 4095)
2072 rv = VNET_API_ERROR_INVALID_VLAN;
2076 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2078 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2081 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2085 kp = clib_mem_alloc (sizeof (*kp));
2086 *kp = sup_and_sub_key;
2088 memset (&template, 0, sizeof (template));
2089 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2090 template.sup_sw_if_index = hi->sw_if_index;
2091 template.sub.id = id;
2092 template.sub.eth.raw_flags = 0;
2093 template.sub.eth.flags.one_tag = 1;
2094 template.sub.eth.outer_vlan_id = id;
2095 template.sub.eth.flags.exact_match = 1;
2097 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2100 clib_error_report (error);
2101 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2104 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2105 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2107 BAD_SW_IF_INDEX_LABEL;
2110 q = vl_api_client_index_to_input_queue (mp->client_index);
2114 rmp = vl_msg_api_alloc (sizeof (*rmp));
2115 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2116 rmp->context = mp->context;
2117 rmp->retval = ntohl (rv);
2118 rmp->sw_if_index = ntohl (sw_if_index);
2119 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2123 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2125 vl_api_create_subif_reply_t *rmp;
2126 vnet_main_t *vnm = vnet_get_main ();
2127 u32 sw_if_index = ~0;
2130 vnet_sw_interface_t *si;
2131 vnet_hw_interface_t *hi;
2132 vnet_sw_interface_t template;
2134 vnet_interface_main_t *im = &vnm->interface_main;
2135 u64 sup_and_sub_key;
2137 clib_error_t *error;
2139 VALIDATE_SW_IF_INDEX (mp);
2141 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2142 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2144 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2146 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2150 sw_if_index = si->sw_if_index;
2151 sub_id = ntohl (mp->sub_id);
2153 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2155 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2159 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2160 sw_if_index, sub_id);
2161 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2165 kp = clib_mem_alloc (sizeof (*kp));
2166 *kp = sup_and_sub_key;
2168 memset (&template, 0, sizeof (template));
2169 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2170 template.sup_sw_if_index = sw_if_index;
2171 template.sub.id = sub_id;
2172 template.sub.eth.flags.no_tags = mp->no_tags;
2173 template.sub.eth.flags.one_tag = mp->one_tag;
2174 template.sub.eth.flags.two_tags = mp->two_tags;
2175 template.sub.eth.flags.dot1ad = mp->dot1ad;
2176 template.sub.eth.flags.exact_match = mp->exact_match;
2177 template.sub.eth.flags.default_sub = mp->default_sub;
2178 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2179 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2180 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2181 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2183 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2186 clib_error_report (error);
2187 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2191 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2192 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2194 BAD_SW_IF_INDEX_LABEL;
2199 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2201 rmp->sw_if_index = ntohl(sw_if_index);
2207 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2210 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2212 stats_main_t *sm = &stats_main;
2213 u32 tunnel_sw_if_index = ~0;
2215 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2217 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2218 (ip4_address_t *) (mp->dst_address),
2219 (ip4_address_t *) (mp->intfc_address),
2220 (u32) (mp->intfc_address_length),
2221 ntohl (mp->inner_vrf_id),
2222 ntohl (mp->outer_vrf_id),
2223 &tunnel_sw_if_index,
2224 mp->l2_only, mp->is_add);
2228 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2230 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2236 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2237 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2239 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2241 stats_main_t *sm = &stats_main;
2242 u32 tunnel_sw_if_index;
2244 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2246 rv = vnet_mpls_ethernet_add_del_tunnel
2247 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2248 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2249 ntohl (mp->tx_sw_if_index),
2250 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2255 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2257 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2263 * This piece of misery brought to you because the control-plane
2264 * can't figure out the tx interface + dst-mac address all by itself
2266 static int mpls_ethernet_add_del_tunnel_2_t_handler
2267 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2269 pending_route_t *pr;
2270 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2271 vnet_main_t *vnm = vnet_get_main ();
2272 vlib_main_t *vm = vlib_get_main ();
2273 stats_main_t *sm = &stats_main;
2274 vpe_api_main_t *vam = &vpe_api_main;
2275 u32 inner_fib_index, outer_fib_index;
2276 ip4_main_t *im = &ip4_main;
2277 ip_lookup_main_t *lm = &im->lookup_main;
2278 ip_adjacency_t *adj = 0;
2281 u8 *dst_mac_address;
2285 u32 tunnel_sw_if_index;
2287 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2289 return VNET_API_ERROR_NO_SUCH_FIB;
2291 outer_fib_index = p[0];
2294 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2296 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2298 inner_fib_index = p[0];
2300 if (inner_fib_index == outer_fib_index)
2301 return VNET_API_ERROR_INVALID_VALUE;
2303 lookup_result = ip4_fib_lookup_with_table
2304 (im, outer_fib_index,
2305 (ip4_address_t *) mp->next_hop_ip4_address_in_outer_vrf,
2306 1 /* disable default route */ );
2308 adj = ip_get_adjacency (lm, lookup_result);
2309 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2311 if (mp->is_add && mp->resolve_if_needed)
2313 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2315 pool_get (vam->pending_routes, pr);
2316 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2318 clib_memcpy (pme, mp, sizeof (*pme));
2319 /* recursion block, "just in case" */
2320 pme->resolve_if_needed = 0;
2321 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2322 pme->resolve_opaque = tx_sw_if_index;
2323 vnet_register_ip4_arp_resolution_event
2325 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2326 vpe_resolver_process_node.index,
2327 RESOLUTION_EVENT, pr - vam->pending_routes);
2329 vlib_process_signal_event
2330 (vm, vpe_resolver_process_node.index,
2331 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2333 /* The interface may be down, etc. */
2334 e = ip4_probe_neighbor
2335 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2339 clib_error_report (e);
2341 return VNET_API_ERROR_IN_PROGRESS;
2345 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2346 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2349 vnet_rewrite_get_data_internal
2350 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2352 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2354 rv = vnet_mpls_ethernet_add_del_tunnel
2355 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2356 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2357 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2365 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2366 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2368 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2371 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2373 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2378 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2380 vl_api_mpls_add_del_encap_reply_t *rmp;
2385 vec_reset_length (labels);
2387 for (i = 0; i < mp->nlabels; i++)
2388 vec_add1 (labels, ntohl (mp->labels[i]));
2391 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2392 ntohl (mp->vrf_id), labels,
2393 ~0 /* policy_tunnel_index */ ,
2394 0 /* no_dst_hash */ ,
2398 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2402 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2404 vl_api_mpls_add_del_decap_reply_t *rmp;
2407 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2408 ntohl (mp->label), ntohl (mp->next_index),
2409 mp->s_bit, mp->is_add);
2411 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2415 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2417 vl_api_proxy_arp_add_del_reply_t *rmp;
2420 ip4_main_t *im = &ip4_main;
2421 stats_main_t *sm = &stats_main;
2422 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2423 ip4_address_t * hi_addr,
2424 u32 fib_index, int is_del);
2427 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2429 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2433 rv = VNET_API_ERROR_NO_SUCH_FIB;
2439 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2440 (ip4_address_t *) mp->hi_address,
2441 fib_index, mp->is_add == 0);
2445 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2449 vl_api_proxy_arp_intfc_enable_disable_t_handler
2450 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2453 vnet_main_t *vnm = vnet_get_main ();
2454 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2455 vnet_sw_interface_t *si;
2458 VALIDATE_SW_IF_INDEX (mp);
2460 sw_if_index = ntohl (mp->sw_if_index);
2462 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2464 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2468 si = vnet_get_sw_interface (vnm, sw_if_index);
2472 if (mp->enable_disable)
2473 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2475 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2477 BAD_SW_IF_INDEX_LABEL;
2480 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2484 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2487 vl_api_ip_neighbor_add_del_reply_t *rmp;
2488 vnet_main_t *vnm = vnet_get_main ();
2491 stats_main_t *sm = &stats_main;
2493 VALIDATE_SW_IF_INDEX (mp);
2495 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2500 rv = vnet_set_ip6_ethernet_neighbor
2501 (vm, ntohl (mp->sw_if_index),
2502 (ip6_address_t *) (mp->dst_address),
2503 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2505 rv = vnet_unset_ip6_ethernet_neighbor
2506 (vm, ntohl (mp->sw_if_index),
2507 (ip6_address_t *) (mp->dst_address),
2508 mp->mac_address, sizeof (mp->mac_address));
2512 ip4_main_t *im = &ip4_main;
2513 ip_lookup_main_t *lm = &im->lookup_main;
2514 ethernet_arp_ip4_over_ethernet_address_t a;
2516 ip_adjacency_t *nh_adj;
2518 uword *p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2521 rv = VNET_API_ERROR_NO_SUCH_FIB;
2527 * Unfortunately, folks have a penchant for
2528 * adding interface addresses to the ARP cache, and
2529 * wondering why the forwarder eventually ASSERTs...
2531 ai = ip4_fib_lookup_with_table
2532 (im, fib_index, (ip4_address_t *) (mp->dst_address),
2533 1 /* disable default route */ );
2537 nh_adj = ip_get_adjacency (lm, ai);
2538 /* Never allow manipulation of a local adj! */
2539 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL)
2541 clib_warning ("%U matches local adj",
2543 (ip4_address_t *) (mp->dst_address));
2544 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2549 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2550 clib_memcpy (&a.ip4, mp->dst_address, 4);
2553 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2554 fib_index, &a, mp->is_static);
2556 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2560 BAD_SW_IF_INDEX_LABEL;
2563 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2567 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2570 vpe_main_t *rm = &vpe_main;
2571 ip4_main_t *im4 = &ip4_main;
2572 ip6_main_t *im6 = &ip6_main;
2573 ip_lookup_main_t *lm;
2579 u32 adj_index, sw_if_index;
2580 vl_api_is_address_reachable_t *rmp;
2581 ip_adjacency_t *adj;
2582 unix_shared_memory_queue_t *q;
2584 q = vl_api_client_index_to_input_queue (mp->client_index);
2587 increment_missing_api_client_counter (rm->vlib_main);
2591 rmp = vl_msg_api_alloc (sizeof (*rmp));
2592 clib_memcpy (rmp, mp, sizeof (*rmp));
2594 sw_if_index = mp->next_hop_sw_if_index;
2595 clib_memcpy (&addr, mp->address, sizeof (addr));
2598 lm = &im6->lookup_main;
2599 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2603 lm = &im4->lookup_main;
2604 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2606 if (adj_index == ~0)
2611 adj = ip_get_adjacency (lm, adj_index);
2613 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2614 && adj->rewrite_header.sw_if_index == sw_if_index)
2620 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2621 && adj->rewrite_header.sw_if_index == sw_if_index)
2624 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2626 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2628 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2637 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2642 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2644 clib_warning ("BUG");
2648 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2650 vl_api_sw_interface_set_flags_reply_t *rmp;
2651 vnet_main_t *vnm = vnet_get_main ();
2653 clib_error_t *error;
2656 VALIDATE_SW_IF_INDEX (mp);
2658 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2660 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2664 clib_error_report (error);
2667 BAD_SW_IF_INDEX_LABEL;
2668 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2672 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2675 vl_api_sw_interface_clear_stats_reply_t *rmp;
2677 vnet_main_t *vnm = vnet_get_main ();
2678 vnet_interface_main_t *im = &vnm->interface_main;
2679 vlib_simple_counter_main_t *sm;
2680 vlib_combined_counter_main_t *cm;
2681 static vnet_main_t **my_vnet_mains;
2682 int i, j, n_counters;
2685 if (mp->sw_if_index != ~0)
2686 VALIDATE_SW_IF_INDEX (mp);
2688 vec_reset_length (my_vnet_mains);
2690 for (i = 0; i < vec_len (vnet_mains); i++)
2693 vec_add1 (my_vnet_mains, vnet_mains[i]);
2696 if (vec_len (vnet_mains) == 0)
2697 vec_add1 (my_vnet_mains, vnm);
2699 n_counters = vec_len (im->combined_sw_if_counters);
2701 for (j = 0; j < n_counters; j++)
2703 for (i = 0; i < vec_len (my_vnet_mains); i++)
2705 im = &my_vnet_mains[i]->interface_main;
2706 cm = im->combined_sw_if_counters + j;
2707 if (mp->sw_if_index == (u32) ~ 0)
2708 vlib_clear_combined_counters (cm);
2710 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2714 n_counters = vec_len (im->sw_if_counters);
2716 for (j = 0; j < n_counters; j++)
2718 for (i = 0; i < vec_len (my_vnet_mains); i++)
2720 im = &my_vnet_mains[i]->interface_main;
2721 sm = im->sw_if_counters + j;
2722 if (mp->sw_if_index == (u32) ~ 0)
2723 vlib_clear_simple_counters (sm);
2725 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2729 BAD_SW_IF_INDEX_LABEL;
2731 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2735 send_sw_interface_details (vpe_api_main_t * am,
2736 unix_shared_memory_queue_t * q,
2737 vnet_sw_interface_t * swif,
2738 u8 * interface_name, u32 context)
2740 vl_api_sw_interface_details_t *mp;
2741 vnet_hw_interface_t *hi;
2743 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2745 mp = vl_msg_api_alloc (sizeof (*mp));
2746 memset (mp, 0, sizeof (*mp));
2747 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2748 mp->sw_if_index = ntohl (swif->sw_if_index);
2749 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2750 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2751 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2752 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2753 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2754 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2755 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2756 mp->link_mtu = ntohs (hi->max_packet_bytes);
2757 mp->context = context;
2759 strncpy ((char *) mp->interface_name,
2760 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2762 /* Send the L2 address for ethernet physical intfcs */
2763 if (swif->sup_sw_if_index == swif->sw_if_index
2764 && hi->hw_class_index == ethernet_hw_interface_class.index)
2766 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2767 ethernet_interface_t *ei;
2769 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2770 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2771 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2772 mp->l2_address_length = ntohl (sizeof (ei->address));
2774 else if (swif->sup_sw_if_index != swif->sw_if_index)
2776 vnet_sub_interface_t *sub = &swif->sub;
2777 mp->sub_id = ntohl (sub->id);
2778 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2779 mp->sub_number_of_tags =
2780 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2781 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2782 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2783 mp->sub_exact_match = sub->eth.flags.exact_match;
2784 mp->sub_default = sub->eth.flags.default_sub;
2785 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2786 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2788 /* vlan tag rewrite data */
2789 u32 vtr_op = L2_VTR_DISABLED;
2790 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2792 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2793 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2795 // error - default to disabled
2796 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2797 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2802 mp->vtr_op = ntohl (vtr_op);
2803 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2804 mp->vtr_tag1 = ntohl (vtr_tag1);
2805 mp->vtr_tag2 = ntohl (vtr_tag2);
2809 vl_msg_api_send_shmem (q, (u8 *) & mp);
2813 send_sw_interface_flags (vpe_api_main_t * am,
2814 unix_shared_memory_queue_t * q,
2815 vnet_sw_interface_t * swif)
2817 vl_api_sw_interface_set_flags_t *mp;
2818 vnet_main_t *vnm = am->vnet_main;
2820 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2822 mp = vl_msg_api_alloc (sizeof (*mp));
2823 memset (mp, 0, sizeof (*mp));
2824 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2825 mp->sw_if_index = ntohl (swif->sw_if_index);
2827 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2828 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2829 vl_msg_api_send_shmem (q, (u8 *) & mp);
2832 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2833 unix_shared_memory_queue_t * q,
2835 __attribute__ ((unused));
2838 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2839 unix_shared_memory_queue_t * q,
2842 vl_api_sw_interface_set_flags_t *mp;
2844 mp = vl_msg_api_alloc (sizeof (*mp));
2845 memset (mp, 0, sizeof (*mp));
2846 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2847 mp->sw_if_index = ntohl (sw_if_index);
2849 mp->admin_up_down = 0;
2850 mp->link_up_down = 0;
2852 vl_msg_api_send_shmem (q, (u8 *) & mp);
2856 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2858 vpe_api_main_t *am = &vpe_api_main;
2859 vnet_sw_interface_t *swif;
2860 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2861 u8 *filter_string = 0, *name_string = 0;
2862 unix_shared_memory_queue_t *q;
2863 char *strcasestr (char *, char *); /* lnx hdr file botch */
2865 q = vl_api_client_index_to_input_queue (mp->client_index);
2870 if (mp->name_filter_valid)
2872 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2873 filter_string = format (0, "%s%c", mp->name_filter, 0);
2877 pool_foreach (swif, im->sw_interfaces,
2879 name_string = format (name_string, "%U%c",
2880 format_vnet_sw_interface_name,
2881 am->vnet_main, swif, 0);
2883 if (mp->name_filter_valid == 0 ||
2884 strcasestr((char *) name_string, (char *) filter_string)) {
2886 send_sw_interface_details (am, q, swif, name_string, mp->context);
2888 _vec_len (name_string) = 0;
2892 vec_free (name_string);
2893 vec_free (filter_string);
2897 send_oam_event (oam_target_t * t)
2899 vpe_api_main_t *vam = &vpe_api_main;
2900 unix_shared_memory_queue_t *q;
2901 vpe_client_registration_t *reg;
2902 vl_api_oam_event_t *mp;
2905 pool_foreach(reg, vam->oam_events_registrations,
2907 q = vl_api_client_index_to_input_queue (reg->client_index);
2910 mp = vl_msg_api_alloc (sizeof (*mp));
2911 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2912 clib_memcpy (mp->dst_address, &t->dst_address,
2913 sizeof (mp->dst_address));
2914 mp->state = t->state;
2915 vl_msg_api_send_shmem (q, (u8 *)&mp);
2922 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2924 vl_api_oam_add_del_reply_t *rmp;
2927 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2928 (ip4_address_t *) mp->dst_address,
2929 ntohl (mp->vrf_id), (int) (mp->is_add));
2931 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2935 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2937 stats_main_t *sm = &stats_main;
2938 vnet_interface_main_t *im = sm->interface_main;
2939 vl_api_vnet_summary_stats_reply_t *rmp;
2940 vlib_combined_counter_main_t *cm;
2943 u64 total_pkts[VLIB_N_RX_TX];
2944 u64 total_bytes[VLIB_N_RX_TX];
2946 unix_shared_memory_queue_t *q =
2947 vl_api_client_index_to_input_queue (mp->client_index);
2952 rmp = vl_msg_api_alloc (sizeof (*rmp));
2953 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2954 rmp->context = mp->context;
2957 memset (total_pkts, 0, sizeof (total_pkts));
2958 memset (total_bytes, 0, sizeof (total_bytes));
2960 vnet_interface_counter_lock (im);
2962 vec_foreach (cm, im->combined_sw_if_counters)
2964 which = cm - im->combined_sw_if_counters;
2966 for (i = 0; i < vec_len (cm->maxi); i++)
2968 vlib_get_combined_counter (cm, i, &v);
2969 total_pkts[which] += v.packets;
2970 total_bytes[which] += v.bytes;
2973 vnet_interface_counter_unlock (im);
2975 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2976 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2977 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2978 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2980 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2982 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2986 typedef CLIB_PACKED (struct {
2987 ip4_address_t address;
2988 u32 address_length: 6;
2994 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
2996 vnet_main_t *vnm = vnet_get_main ();
2997 vnet_interface_main_t *im = &vnm->interface_main;
2998 ip4_main_t *im4 = &ip4_main;
2999 static ip4_route_t *routes;
3000 static u32 *sw_if_indices_to_shut;
3001 stats_main_t *sm = &stats_main;
3006 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3007 u32 target_fib_id = ntohl (mp->vrf_id);
3009 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
3011 vec_foreach (fib, im4->fibs)
3013 vnet_sw_interface_t *si;
3015 if (fib->table_id != target_fib_id)
3018 /* remove any mpls/gre tunnels in this fib */
3019 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
3021 /* remove any mpls encap/decap labels */
3022 mpls_fib_reset_labels (fib->table_id);
3024 /* remove any proxy arps in this fib */
3025 vnet_proxy_arp_fib_reset (fib->table_id);
3027 /* Set the flow hash for this fib to the default */
3028 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3030 vec_reset_length (sw_if_indices_to_shut);
3032 /* Shut down interfaces in this FIB / clean out intfc routes */
3034 pool_foreach (si, im->sw_interfaces,
3036 u32 sw_if_index = si->sw_if_index;
3038 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
3039 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
3041 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3045 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3047 sw_if_index = sw_if_indices_to_shut[i];
3048 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3050 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3051 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3052 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3055 vec_reset_length (routes);
3057 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++)
3059 uword *hash = fib->adj_index_by_dst_address[i];
3063 x.address_length = i;
3066 hash_foreach_pair (p, hash,
3068 x.address.data_u32 = p->key;
3069 vec_add1 (routes, x);
3074 vec_foreach (r, routes)
3076 ip4_add_del_route_args_t a;
3078 memset (&a, 0, sizeof (a));
3079 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
3080 a.table_index_or_table_id = fib - im4->fibs;
3081 a.dst_address = r->address;
3082 a.dst_address_length = r->address_length;
3085 ip4_add_del_route (im4, &a);
3086 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
3087 IP4_ROUTE_FLAG_FIB_INDEX);
3091 } /* vec_foreach (fib) */
3099 ip6_address_t address;
3107 ip6_route_t **routep;
3108 } add_routes_in_fib_arg_t;
3111 add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
3113 add_routes_in_fib_arg_t *ap = arg;
3115 if (kvp->key[2] >> 32 == ap->fib_index)
3117 ip6_address_t *addr;
3119 addr = (ip6_address_t *) kvp;
3120 vec_add2 (*ap->routep, r, 1);
3121 r->address = addr[0];
3122 r->address_length = kvp->key[2] & 0xFF;
3123 r->index = kvp->value;
3128 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3130 vnet_main_t *vnm = vnet_get_main ();
3131 vnet_interface_main_t *im = &vnm->interface_main;
3132 ip6_main_t *im6 = &ip6_main;
3133 stats_main_t *sm = &stats_main;
3134 static ip6_route_t *routes;
3135 static u32 *sw_if_indices_to_shut;
3140 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3141 u32 target_fib_id = ntohl (mp->vrf_id);
3142 add_routes_in_fib_arg_t _a, *a = &_a;
3143 clib_bihash_24_8_t *h = &im6->ip6_lookup_table;
3145 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3147 vec_foreach (fib, im6->fibs)
3149 vnet_sw_interface_t *si;
3151 if (fib->table_id != target_fib_id)
3154 vec_reset_length (sw_if_indices_to_shut);
3156 /* Shut down interfaces in this FIB / clean out intfc routes */
3158 pool_foreach (si, im->sw_interfaces,
3160 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3162 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3166 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3168 sw_if_index = sw_if_indices_to_shut[i];
3169 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3171 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3172 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3173 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3176 vec_reset_length (routes);
3178 a->fib_index = fib - im6->fibs;
3179 a->routep = &routes;
3181 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
3183 vec_foreach (r, routes)
3185 ip6_add_del_route_args_t a;
3187 memset (&a, 0, sizeof (a));
3188 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
3189 a.table_index_or_table_id = fib - im6->fibs;
3190 a.dst_address = r->address;
3191 a.dst_address_length = r->address_length;
3194 ip6_add_del_route (im6, &a);
3195 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
3196 IP6_ROUTE_FLAG_FIB_INDEX);
3199 /* Reinstall the neighbor / router discovery routes */
3200 vnet_ip6_fib_init (im6, fib - im6->fibs);
3202 } /* vec_foreach (fib) */
3209 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3212 vl_api_reset_fib_reply_t *rmp;
3215 rv = ip6_reset_fib_t_handler (mp);
3217 rv = ip4_reset_fib_t_handler (mp);
3219 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3224 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3226 vl_api_dhcp_proxy_config_reply_t *rmp;
3229 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3230 (ip4_address_t *) (&mp->dhcp_src_address),
3231 (u32) ntohl (mp->vrf_id),
3232 (int) mp->insert_circuit_id,
3233 (int) (mp->is_add == 0));
3235 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3240 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3242 vl_api_dhcp_proxy_config_reply_t *rmp;
3245 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3246 (ip6_address_t *) (&mp->dhcp_src_address),
3247 (u32) ntohl (mp->vrf_id),
3248 (int) mp->insert_circuit_id,
3249 (int) (mp->is_add == 0));
3251 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3255 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3257 vl_api_dhcp_proxy_config_reply_t *rmp;
3260 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3261 (ip4_address_t *) (&mp->dhcp_src_address),
3262 (u32) ntohl (mp->rx_vrf_id),
3263 (u32) ntohl (mp->server_vrf_id),
3264 (int) mp->insert_circuit_id,
3265 (int) (mp->is_add == 0));
3267 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3272 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3274 vl_api_dhcp_proxy_config_reply_t *rmp;
3278 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3279 (ip6_address_t *) (&mp->dhcp_src_address),
3280 (u32) ntohl (mp->rx_vrf_id),
3281 (u32) ntohl (mp->server_vrf_id),
3282 (int) mp->insert_circuit_id,
3283 (int) (mp->is_add == 0));
3285 rv = VNET_API_ERROR_UNIMPLEMENTED;
3288 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3293 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3295 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3298 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3301 (int) mp->is_add == 0);
3303 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3305 ntohl (mp->fib_id), (int) mp->is_add == 0);
3307 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3311 static void vl_api_dhcp_proxy_config_t_handler
3312 (vl_api_dhcp_proxy_config_t * mp)
3314 if (mp->is_ipv6 == 0)
3315 dhcpv4_proxy_config (mp);
3317 dhcpv6_proxy_config (mp);
3320 static void vl_api_dhcp_proxy_config_2_t_handler
3321 (vl_api_dhcp_proxy_config_2_t * mp)
3323 if (mp->is_ipv6 == 0)
3324 dhcpv4_proxy_config_2 (mp);
3326 dhcpv6_proxy_config_2 (mp);
3330 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3331 u8 is_ipv6, u8 * host_address, u8 * router_address,
3334 unix_shared_memory_queue_t *q;
3335 vl_api_dhcp_compl_event_t *mp;
3337 q = vl_api_client_index_to_input_queue (client_index);
3341 mp = vl_msg_api_alloc (sizeof (*mp));
3342 mp->client_index = client_index;
3344 mp->is_ipv6 = is_ipv6;
3345 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3346 mp->hostname[vec_len (hostname) + 1] = '\n';
3347 clib_memcpy (&mp->host_address[0], host_address, 16);
3348 clib_memcpy (&mp->router_address[0], router_address, 16);
3349 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3351 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3353 vl_msg_api_send_shmem (q, (u8 *) & mp);
3356 static void vl_api_dhcp_client_config_t_handler
3357 (vl_api_dhcp_client_config_t * mp)
3359 vlib_main_t *vm = vlib_get_main ();
3360 vl_api_dhcp_client_config_reply_t *rmp;
3363 VALIDATE_SW_IF_INDEX (mp);
3365 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3366 mp->hostname, mp->is_add, mp->client_index,
3367 mp->want_dhcp_event ? dhcp_compl_event_callback :
3370 BAD_SW_IF_INDEX_LABEL;
3372 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3376 vl_api_sw_interface_ip6nd_ra_config_t_handler
3377 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3379 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3381 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3384 is_no = mp->is_no == 1;
3385 suppress = mp->suppress == 1;
3386 managed = mp->managed == 1;
3387 other = mp->other == 1;
3388 ll_option = mp->ll_option == 1;
3389 send_unicast = mp->send_unicast == 1;
3390 cease = mp->cease == 1;
3391 default_router = mp->default_router == 1;
3393 VALIDATE_SW_IF_INDEX (mp);
3395 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3396 suppress, managed, other,
3397 ll_option, send_unicast, cease,
3398 default_router, ntohl (mp->lifetime),
3399 ntohl (mp->initial_count),
3400 ntohl (mp->initial_interval),
3401 ntohl (mp->max_interval),
3402 ntohl (mp->min_interval), is_no);
3404 BAD_SW_IF_INDEX_LABEL;
3406 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3410 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3411 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3413 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3415 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3417 VALIDATE_SW_IF_INDEX (mp);
3419 is_no = mp->is_no == 1;
3420 use_default = mp->use_default == 1;
3421 no_advertise = mp->no_advertise == 1;
3422 off_link = mp->off_link == 1;
3423 no_autoconfig = mp->no_autoconfig == 1;
3424 no_onlink = mp->no_onlink == 1;
3426 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3427 (ip6_address_t *) mp->address,
3428 mp->address_length, use_default,
3429 ntohl (mp->val_lifetime),
3430 ntohl (mp->pref_lifetime), no_advertise,
3431 off_link, no_autoconfig, no_onlink, is_no);
3433 BAD_SW_IF_INDEX_LABEL;
3434 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3438 vl_api_sw_interface_ip6_enable_disable_t_handler
3439 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3441 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3442 vnet_main_t *vnm = vnet_get_main ();
3444 clib_error_t *error;
3448 VALIDATE_SW_IF_INDEX (mp);
3451 (mp->enable == 1) ? enable_ip6_interface (vm,
3452 ntohl (mp->sw_if_index)) :
3453 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3457 clib_error_report (error);
3458 rv = VNET_API_ERROR_UNSPECIFIED;
3462 rv = vnm->api_errno;
3465 BAD_SW_IF_INDEX_LABEL;
3467 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3471 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3472 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3474 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3476 clib_error_t *error;
3477 vnet_main_t *vnm = vnet_get_main ();
3481 VALIDATE_SW_IF_INDEX (mp);
3483 error = set_ip6_link_local_address (vm,
3484 ntohl (mp->sw_if_index),
3485 (ip6_address_t *) mp->address,
3486 mp->address_length);
3489 clib_error_report (error);
3490 rv = VNET_API_ERROR_UNSPECIFIED;
3494 rv = vnm->api_errno;
3497 BAD_SW_IF_INDEX_LABEL;
3499 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3503 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3505 vl_api_set_ip_flow_hash_reply_t *rmp;
3506 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3508 clib_warning ("unimplemented...");
3510 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3514 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3516 vl_api_set_ip_flow_hash_reply_t *rmp;
3519 u32 flow_hash_config = 0;
3521 table_id = ntohl (mp->vrf_id);
3523 #define _(a,b) if (mp->a) flow_hash_config |= b;
3524 foreach_flow_hash_bit;
3527 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3529 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3534 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3536 if (mp->is_ipv6 == 0)
3537 set_ip4_flow_hash (mp);
3539 set_ip6_flow_hash (mp);
3542 static void vl_api_sw_interface_set_unnumbered_t_handler
3543 (vl_api_sw_interface_set_unnumbered_t * mp)
3545 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3547 vnet_sw_interface_t *si;
3548 vnet_main_t *vnm = vnet_get_main ();
3549 u32 sw_if_index, unnumbered_sw_if_index;
3551 sw_if_index = ntohl (mp->sw_if_index);
3552 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3555 * The API message field names are backwards from
3556 * the underlying data structure names.
3557 * It's not worth changing them now.
3559 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3560 unnumbered_sw_if_index))
3562 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3566 /* Only check the "use loop0" field when setting the binding */
3568 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3570 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3574 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3578 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3579 si->unnumbered_sw_if_index = sw_if_index;
3583 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3584 si->unnumbered_sw_if_index = (u32) ~ 0;
3588 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3592 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3594 vl_api_create_loopback_reply_t *rmp;
3598 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3601 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3603 rmp->sw_if_index = ntohl (sw_if_index);
3609 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3611 vl_api_delete_loopback_reply_t *rmp;
3615 sw_if_index = ntohl (mp->sw_if_index);
3616 rv = vnet_delete_loopback_interface (sw_if_index);
3618 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3622 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3624 vl_api_control_ping_reply_t *rmp;
3628 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3630 rmp->vpe_pid = ntohl (getpid());
3635 static void vl_api_noprint_control_ping_t_handler
3636 (vl_api_noprint_control_ping_t * mp)
3638 vl_api_noprint_control_ping_reply_t *rmp;
3642 REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY,
3644 rmp->vpe_pid = ntohl (getpid());
3650 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3652 u8 **shmem_vecp = (u8 **) arg;
3655 api_main_t *am = &api_main;
3658 shmem_vec = *shmem_vecp;
3660 offset = vec_len (shmem_vec);
3662 pthread_mutex_lock (&am->vlib_rp->mutex);
3663 oldheap = svm_push_data_heap (am->vlib_rp);
3665 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3667 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3669 svm_pop_heap (oldheap);
3670 pthread_mutex_unlock (&am->vlib_rp->mutex);
3672 *shmem_vecp = shmem_vec;
3677 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3679 vl_api_cli_reply_t *rp;
3680 unix_shared_memory_queue_t *q;
3681 vlib_main_t *vm = vlib_get_main ();
3682 api_main_t *am = &api_main;
3683 unformat_input_t input;
3687 q = vl_api_client_index_to_input_queue (mp->client_index);
3691 rp = vl_msg_api_alloc (sizeof (*rp));
3692 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3693 rp->context = mp->context;
3695 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3697 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3699 pthread_mutex_lock (&am->vlib_rp->mutex);
3700 oldheap = svm_push_data_heap (am->vlib_rp);
3702 vec_add1 (shmem_vec, 0);
3704 svm_pop_heap (oldheap);
3705 pthread_mutex_unlock (&am->vlib_rp->mutex);
3707 rp->reply_in_shmem = (uword) shmem_vec;
3709 vl_msg_api_send_shmem (q, (u8 *) & rp);
3713 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3715 u8 **mem_vecp = (u8 **) arg;
3716 u8 *mem_vec = *mem_vecp;
3717 u32 offset = vec_len (mem_vec);
3719 vec_validate (mem_vec, offset + buffer_bytes - 1);
3720 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3721 *mem_vecp = mem_vec;
3725 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3727 vl_api_cli_inband_reply_t *rmp;
3729 unix_shared_memory_queue_t *q;
3730 vlib_main_t *vm = vlib_get_main ();
3731 unformat_input_t input;
3734 q = vl_api_client_index_to_input_queue (mp->client_index);
3738 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3739 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3741 u32 len = vec_len (out_vec);
3743 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3745 rmp->length = htonl (len);
3746 clib_memcpy (rmp->reply, out_vec, len);
3753 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3756 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3757 vnet_main_t *vnm = vnet_get_main ();
3758 clib_error_t *error;
3763 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3765 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3769 clib_error_report (error);
3770 rv = VNET_API_ERROR_UNSPECIFIED;
3774 rv = vnm->api_errno;
3777 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3780 static void vl_api_sr_tunnel_add_del_t_handler
3781 (vl_api_sr_tunnel_add_del_t * mp)
3784 clib_warning ("unimplemented");
3786 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3788 vl_api_sr_tunnel_add_del_reply_t *rmp;
3789 ip6_address_t *segments = 0, *seg;
3790 ip6_address_t *tags = 0, *tag;
3791 ip6_address_t *this_address;
3794 if (mp->n_segments == 0)
3800 memset (a, 0, sizeof (*a));
3801 a->src_address = (ip6_address_t *) & mp->src_address;
3802 a->dst_address = (ip6_address_t *) & mp->dst_address;
3803 a->dst_mask_width = mp->dst_mask_width;
3804 a->flags_net_byte_order = mp->flags_net_byte_order;
3805 a->is_del = (mp->is_add == 0);
3806 a->rx_table_id = ntohl (mp->outer_vrf_id);
3807 a->tx_table_id = ntohl (mp->inner_vrf_id);
3809 a->name = format (0, "%s", mp->name);
3810 if (!(vec_len (a->name)))
3813 a->policy_name = format (0, "%s", mp->policy_name);
3814 if (!(vec_len (a->policy_name)))
3817 /* Yank segments and tags out of the API message */
3818 this_address = (ip6_address_t *) mp->segs_and_tags;
3819 for (i = 0; i < mp->n_segments; i++)
3821 vec_add2 (segments, seg, 1);
3822 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3825 for (i = 0; i < mp->n_tags; i++)
3827 vec_add2 (tags, tag, 1);
3828 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3832 a->segments = segments;
3835 rv = ip6_sr_add_del_tunnel (a);
3839 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3843 static void vl_api_sr_policy_add_del_t_handler
3844 (vl_api_sr_policy_add_del_t * mp)
3847 clib_warning ("unimplemented");
3849 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3851 vl_api_sr_policy_add_del_reply_t *rmp;
3854 memset (a, 0, sizeof (*a));
3855 a->is_del = (mp->is_add == 0);
3857 a->name = format (0, "%s", mp->name);
3858 if (!(vec_len (a->name)))
3860 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3864 if (!(mp->tunnel_names[0]))
3866 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3870 // start deserializing tunnel_names
3871 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3872 u8 *deser_tun_names = mp->tunnel_names;
3873 deser_tun_names += 1; //moving along
3876 int tun_name_len = 0;
3878 for (i = 0; i < num_tunnels; i++)
3880 tun_name_len = *deser_tun_names;
3881 deser_tun_names += 1;
3882 vec_resize (tun_name, tun_name_len);
3883 memcpy (tun_name, deser_tun_names, tun_name_len);
3884 vec_add1 (a->tunnel_names, tun_name);
3885 deser_tun_names += tun_name_len;
3889 rv = ip6_sr_add_del_policy (a);
3893 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3897 static void vl_api_sr_multicast_map_add_del_t_handler
3898 (vl_api_sr_multicast_map_add_del_t * mp)
3901 clib_warning ("unimplemented");
3903 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3905 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3907 memset (a, 0, sizeof (*a));
3908 a->is_del = (mp->is_add == 0);
3910 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3911 a->policy_name = format (0, "%s", mp->policy_name);
3913 if (a->multicast_address == 0)
3919 if (!(a->policy_name))
3925 #if DPDK > 0 /* Cannot call replicate without DPDK */
3926 rv = ip6_sr_add_del_multicastmap (a);
3928 clib_warning ("multicast replication without DPDK not implemented");
3929 rv = VNET_API_ERROR_UNIMPLEMENTED;
3934 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3938 #define foreach_classify_add_del_table_field \
3943 _(match_n_vectors) \
3944 _(next_table_index) \
3947 static void vl_api_classify_add_del_table_t_handler
3948 (vl_api_classify_add_del_table_t * mp)
3950 vl_api_classify_add_del_table_reply_t *rmp;
3951 vnet_classify_main_t *cm = &vnet_classify_main;
3952 vnet_classify_table_t *t;
3956 foreach_classify_add_del_table_field;
3959 #define _(a) a = ntohl(mp->a);
3960 foreach_classify_add_del_table_field;
3963 /* The underlying API fails silently, on purpose, so check here */
3964 if (mp->is_add == 0)
3965 if (pool_is_free_index (cm->tables, table_index))
3967 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3971 rv = vnet_classify_add_del_table
3972 (cm, mp->mask, nbuckets, memory_size,
3973 skip_n_vectors, match_n_vectors,
3974 next_table_index, miss_next_index, &table_index, mp->is_add);
3978 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3980 if (rv == 0 && mp->is_add)
3982 t = pool_elt_at_index (cm->tables, table_index);
3983 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3984 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3985 rmp->new_table_index = ntohl(table_index);
3989 rmp->skip_n_vectors = ~0;
3990 rmp->match_n_vectors = ~0;
3991 rmp->new_table_index = ~0;
3997 static void vl_api_classify_add_del_session_t_handler
3998 (vl_api_classify_add_del_session_t * mp)
4000 vnet_classify_main_t *cm = &vnet_classify_main;
4001 vl_api_classify_add_del_session_reply_t *rmp;
4003 u32 table_index, hit_next_index, opaque_index;
4006 table_index = ntohl (mp->table_index);
4007 hit_next_index = ntohl (mp->hit_next_index);
4008 opaque_index = ntohl (mp->opaque_index);
4009 advance = ntohl (mp->advance);
4011 rv = vnet_classify_add_del_session
4012 (cm, table_index, mp->match, hit_next_index, opaque_index,
4013 advance, mp->is_add);
4015 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
4018 static void vl_api_classify_set_interface_ip_table_t_handler
4019 (vl_api_classify_set_interface_ip_table_t * mp)
4021 vlib_main_t *vm = vlib_get_main ();
4022 vl_api_classify_set_interface_ip_table_reply_t *rmp;
4024 u32 table_index, sw_if_index;
4026 table_index = ntohl (mp->table_index);
4027 sw_if_index = ntohl (mp->sw_if_index);
4029 VALIDATE_SW_IF_INDEX (mp);
4032 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
4034 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
4036 BAD_SW_IF_INDEX_LABEL;
4038 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
4041 static void vl_api_classify_set_interface_l2_tables_t_handler
4042 (vl_api_classify_set_interface_l2_tables_t * mp)
4044 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
4046 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
4049 ip4_table_index = ntohl (mp->ip4_table_index);
4050 ip6_table_index = ntohl (mp->ip6_table_index);
4051 other_table_index = ntohl (mp->other_table_index);
4052 sw_if_index = ntohl (mp->sw_if_index);
4054 VALIDATE_SW_IF_INDEX (mp);
4057 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
4061 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
4067 if (ip4_table_index != ~0 || ip6_table_index != ~0
4068 || other_table_index != ~0)
4074 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
4076 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
4079 BAD_SW_IF_INDEX_LABEL;
4081 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
4085 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
4088 vl_api_l2_fib_clear_table_reply_t *rmp;
4090 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
4091 * that is not currently implemented. When that TODO is fixed
4092 * this call should be changed to pass 1 instead of 0.
4094 l2fib_clear_table (0);
4096 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
4099 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
4100 u32 sw_if_index, u32 enable);
4103 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
4107 vl_api_l2_interface_efp_filter_reply_t *rmp;
4108 vnet_main_t *vnm = vnet_get_main ();
4110 // enable/disable the feature
4111 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
4112 rv = vnm->api_errno;
4114 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
4118 vl_api_l2_interface_vlan_tag_rewrite_t_handler
4119 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
4122 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
4123 vnet_main_t *vnm = vnet_get_main ();
4124 vlib_main_t *vm = vlib_get_main ();
4127 VALIDATE_SW_IF_INDEX (mp);
4129 vtr_op = ntohl (mp->vtr_op);
4131 /* The L2 code is unsuspicious */
4134 case L2_VTR_DISABLED:
4139 case L2_VTR_TRANSLATE_1_1:
4140 case L2_VTR_TRANSLATE_1_2:
4141 case L2_VTR_TRANSLATE_2_1:
4142 case L2_VTR_TRANSLATE_2_2:
4146 rv = VNET_API_ERROR_INVALID_VALUE;
4147 goto bad_sw_if_index;
4150 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4151 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4154 BAD_SW_IF_INDEX_LABEL;
4156 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4160 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4163 vl_api_create_vhost_user_if_reply_t *rmp;
4164 u32 sw_if_index = (u32) ~ 0;
4166 vnet_main_t *vnm = vnet_get_main ();
4167 vlib_main_t *vm = vlib_get_main ();
4169 #if DPDK > 0 && DPDK_VHOST_USER
4170 rv = dpdk_vhost_user_create_if (
4172 rv = vhost_user_create_if (
4174 vnm, vm, (char *) mp->sock_filename,
4175 mp->is_server, &sw_if_index, (u64) ~ 0,
4176 mp->renumber, ntohl (mp->custom_dev_instance),
4177 (mp->use_custom_mac) ? mp->mac_address : NULL);
4180 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4182 rmp->sw_if_index = ntohl (sw_if_index);
4188 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4191 vl_api_modify_vhost_user_if_reply_t *rmp;
4192 u32 sw_if_index = ntohl (mp->sw_if_index);
4194 vnet_main_t *vnm = vnet_get_main ();
4195 vlib_main_t *vm = vlib_get_main ();
4197 #if DPDK > 0 && DPDK_VHOST_USER
4198 rv = dpdk_vhost_user_modify_if (
4200 rv = vhost_user_modify_if (
4202 vnm, vm, (char *) mp->sock_filename,
4203 mp->is_server, sw_if_index, (u64) ~ 0,
4204 mp->renumber, ntohl (mp->custom_dev_instance));
4205 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4209 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4212 vl_api_delete_vhost_user_if_reply_t *rmp;
4213 vpe_api_main_t *vam = &vpe_api_main;
4214 u32 sw_if_index = ntohl (mp->sw_if_index);
4216 vnet_main_t *vnm = vnet_get_main ();
4217 vlib_main_t *vm = vlib_get_main ();
4219 #if DPDK > 0 && DPDK_VHOST_USER
4220 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4222 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4225 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4228 unix_shared_memory_queue_t *q =
4229 vl_api_client_index_to_input_queue (mp->client_index);
4233 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4238 vl_api_sw_interface_vhost_user_details_t_handler
4239 (vl_api_sw_interface_vhost_user_details_t * mp)
4241 clib_warning ("BUG");
4245 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4246 unix_shared_memory_queue_t * q,
4247 vhost_user_intf_details_t * vui,
4250 vl_api_sw_interface_vhost_user_details_t *mp;
4252 mp = vl_msg_api_alloc (sizeof (*mp));
4253 memset (mp, 0, sizeof (*mp));
4254 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4255 mp->sw_if_index = ntohl (vui->sw_if_index);
4256 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4257 mp->features = clib_net_to_host_u64 (vui->features);
4258 mp->is_server = vui->is_server;
4259 mp->num_regions = ntohl (vui->num_regions);
4260 mp->sock_errno = ntohl (vui->sock_errno);
4261 mp->context = context;
4263 strncpy ((char *) mp->sock_filename,
4264 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4265 strncpy ((char *) mp->interface_name,
4266 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4268 vl_msg_api_send_shmem (q, (u8 *) & mp);
4272 vl_api_sw_interface_vhost_user_dump_t_handler
4273 (vl_api_sw_interface_vhost_user_dump_t * mp)
4276 vpe_api_main_t *am = &vpe_api_main;
4277 vnet_main_t *vnm = vnet_get_main ();
4278 vlib_main_t *vm = vlib_get_main ();
4279 vhost_user_intf_details_t *ifaces = NULL;
4280 vhost_user_intf_details_t *vuid = NULL;
4281 unix_shared_memory_queue_t *q;
4283 q = vl_api_client_index_to_input_queue (mp->client_index);
4287 #if DPDK > 0 && DPDK_VHOST_USER
4288 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4290 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4295 vec_foreach (vuid, ifaces)
4297 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4303 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4304 unix_shared_memory_queue_t * q,
4306 l2t_main_t * lm, u32 context)
4308 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4310 vnet_sw_interface_t *si = NULL;
4312 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4314 if_name = format (if_name, "%U",
4315 format_vnet_sw_interface_name, lm->vnet_main, si);
4317 mp = vl_msg_api_alloc (sizeof (*mp));
4318 memset (mp, 0, sizeof (*mp));
4319 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4320 strncpy ((char *) mp->interface_name,
4321 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4322 mp->sw_if_index = ntohl (si->sw_if_index);
4323 mp->local_session_id = s->local_session_id;
4324 mp->remote_session_id = s->remote_session_id;
4325 mp->local_cookie[0] = s->local_cookie[0];
4326 mp->local_cookie[1] = s->local_cookie[1];
4327 mp->remote_cookie = s->remote_cookie;
4328 clib_memcpy (mp->client_address, &s->client_address,
4329 sizeof (s->client_address));
4330 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4331 mp->l2_sublayer_present = s->l2_sublayer_present;
4332 mp->context = context;
4334 vl_msg_api_send_shmem (q, (u8 *) & mp);
4338 send_ip_address_details (vpe_api_main_t * am,
4339 unix_shared_memory_queue_t * q,
4340 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4342 vl_api_ip_address_details_t *mp;
4344 mp = vl_msg_api_alloc (sizeof (*mp));
4345 memset (mp, 0, sizeof (*mp));
4346 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4350 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4354 u32 *tp = (u32 *) mp->ip;
4355 *tp = ntohl (*(u32 *) ip);
4357 mp->prefix_length = prefix_length;
4358 mp->context = context;
4360 vl_msg_api_send_shmem (q, (u8 *) & mp);
4364 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4366 vpe_api_main_t *am = &vpe_api_main;
4367 unix_shared_memory_queue_t *q;
4370 ip6_main_t *im6 = &ip6_main;
4371 ip4_main_t *im4 = &ip4_main;
4372 ip_lookup_main_t *lm6 = &im6->lookup_main;
4373 ip_lookup_main_t *lm4 = &im4->lookup_main;
4374 ip_interface_address_t *ia = 0;
4375 u32 sw_if_index = ~0;
4376 int rv __attribute__ ((unused)) = 0;
4378 VALIDATE_SW_IF_INDEX (mp);
4380 sw_if_index = ntohl (mp->sw_if_index);
4382 q = vl_api_client_index_to_input_queue (mp->client_index);
4391 foreach_ip_interface_address (lm6, ia, sw_if_index,
4392 1 /* honor unnumbered */,
4394 r6 = ip_interface_address_get_address (lm6, ia);
4395 u16 prefix_length = ia->address_length;
4396 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4403 foreach_ip_interface_address (lm4, ia, sw_if_index,
4404 1 /* honor unnumbered */,
4406 r4 = ip_interface_address_get_address (lm4, ia);
4407 u16 prefix_length = ia->address_length;
4408 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4412 BAD_SW_IF_INDEX_LABEL;
4416 send_ip_details (vpe_api_main_t * am,
4417 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4419 vl_api_ip_details_t *mp;
4421 mp = vl_msg_api_alloc (sizeof (*mp));
4422 memset (mp, 0, sizeof (*mp));
4423 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4425 mp->sw_if_index = ntohl (sw_if_index);
4426 mp->context = context;
4428 vl_msg_api_send_shmem (q, (u8 *) & mp);
4432 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4435 vpe_api_main_t *am = &vpe_api_main;
4436 l2t_main_t *lm = &l2t_main;
4437 unix_shared_memory_queue_t *q;
4438 l2t_session_t *session;
4440 q = vl_api_client_index_to_input_queue (mp->client_index);
4445 pool_foreach (session, lm->sessions,
4447 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4454 send_sw_interface_tap_details (vpe_api_main_t * am,
4455 unix_shared_memory_queue_t * q,
4456 tapcli_interface_details_t * tap_if,
4459 vl_api_sw_interface_tap_details_t *mp;
4460 mp = vl_msg_api_alloc (sizeof (*mp));
4461 memset (mp, 0, sizeof (*mp));
4462 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4463 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4464 strncpy ((char *) mp->dev_name,
4465 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4466 mp->context = context;
4468 vl_msg_api_send_shmem (q, (u8 *) & mp);
4472 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4475 vpe_api_main_t *am = &vpe_api_main;
4476 unix_shared_memory_queue_t *q;
4477 tapcli_interface_details_t *tapifs = NULL;
4478 tapcli_interface_details_t *tap_if = NULL;
4480 q = vl_api_client_index_to_input_queue (mp->client_index);
4484 rv = vnet_tap_dump_ifs (&tapifs);
4488 vec_foreach (tap_if, tapifs)
4490 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4497 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4499 vpe_api_main_t *am = &vpe_api_main;
4500 vnet_main_t *vnm = vnet_get_main ();
4501 vlib_main_t *vm = vlib_get_main ();
4502 vnet_interface_main_t *im = &vnm->interface_main;
4503 unix_shared_memory_queue_t *q;
4504 vnet_sw_interface_t *si, *sorted_sis;
4505 u32 sw_if_index = ~0;
4507 q = vl_api_client_index_to_input_queue (mp->client_index);
4513 /* Gather interfaces. */
4514 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4515 _vec_len (sorted_sis) = 0;
4517 pool_foreach (si, im->sw_interfaces,
4519 vec_add1 (sorted_sis, si[0]);
4523 vec_foreach (si, sorted_sis)
4525 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4527 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4531 sw_if_index = si->sw_if_index;
4532 send_ip_details (am, q, sw_if_index, mp->context);
4538 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4540 clib_warning ("BUG");
4544 send_l2fib_table_entry (vpe_api_main_t * am,
4545 unix_shared_memory_queue_t * q,
4546 l2fib_entry_key_t * l2fe_key,
4547 l2fib_entry_result_t * l2fe_res, u32 context)
4549 vl_api_l2_fib_table_entry_t *mp;
4551 mp = vl_msg_api_alloc (sizeof (*mp));
4552 memset (mp, 0, sizeof (*mp));
4553 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4556 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4558 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4559 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4560 mp->static_mac = l2fe_res->fields.static_mac;
4561 mp->filter_mac = l2fe_res->fields.filter;
4562 mp->bvi_mac = l2fe_res->fields.bvi;
4563 mp->context = context;
4565 vl_msg_api_send_shmem (q, (u8 *) & mp);
4569 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4571 vpe_api_main_t *am = &vpe_api_main;
4572 bd_main_t *bdm = &bd_main;
4573 l2fib_entry_key_t *l2fe_key = NULL;
4574 l2fib_entry_result_t *l2fe_res = NULL;
4575 u32 ni, bd_id = ntohl (mp->bd_id);
4577 unix_shared_memory_queue_t *q;
4580 q = vl_api_client_index_to_input_queue (mp->client_index);
4584 /* see l2fib_table_dump: ~0 means "any" */
4589 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4596 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4598 vec_foreach_index (ni, l2fe_key)
4600 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4601 vec_elt_at_index (l2fe_res, ni), mp->context);
4603 vec_free (l2fe_key);
4604 vec_free (l2fe_res);
4608 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4610 vl_api_show_version_reply_t *rmp;
4612 char *vpe_api_get_build_directory (void);
4613 char *vpe_api_get_version (void);
4614 char *vpe_api_get_build_date (void);
4616 unix_shared_memory_queue_t *q =
4617 vl_api_client_index_to_input_queue (mp->client_index);
4623 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4625 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4626 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4627 ARRAY_LEN(rmp->build_directory)-1);
4628 strncpy ((char *) rmp->version, vpe_api_get_version(),
4629 ARRAY_LEN(rmp->version)-1);
4630 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4631 ARRAY_LEN(rmp->build_date)-1);
4637 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4639 vlib_main_t *vm = vlib_get_main ();
4640 vl_api_get_node_index_reply_t *rmp;
4643 u32 node_index = ~0;
4645 n = vlib_get_node_by_name (vm, mp->node_name);
4648 rv = VNET_API_ERROR_NO_SUCH_NODE;
4650 node_index = n->index;
4653 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4655 rmp->node_index = ntohl(node_index);
4661 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4663 vlib_main_t *vm = vlib_get_main ();
4664 vl_api_get_next_index_reply_t *rmp;
4665 vlib_node_t *node, *next_node;
4667 u32 next_node_index = ~0, next_index = ~0;
4670 node = vlib_get_node_by_name (vm, mp->node_name);
4674 rv = VNET_API_ERROR_NO_SUCH_NODE;
4678 next_node = vlib_get_node_by_name (vm, mp->next_name);
4682 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4686 next_node_index = next_node->index;
4688 p = hash_get (node->next_slot_by_node, next_node_index);
4692 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4700 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4702 rmp->next_index = ntohl(next_index);
4708 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4710 vlib_main_t *vm = vlib_get_main ();
4711 vl_api_add_node_next_reply_t *rmp;
4712 vlib_node_t *n, *next;
4714 u32 next_index = ~0;
4716 n = vlib_get_node_by_name (vm, mp->node_name);
4720 rv = VNET_API_ERROR_NO_SUCH_NODE;
4724 next = vlib_get_node_by_name (vm, mp->next_name);
4727 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4729 next_index = vlib_node_add_next (vm, n->index, next->index);
4733 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4735 rmp->next_index = ntohl(next_index);
4740 static void vl_api_l2tpv3_create_tunnel_t_handler
4741 (vl_api_l2tpv3_create_tunnel_t * mp)
4743 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4744 l2t_main_t *lm = &l2t_main;
4745 u32 sw_if_index = (u32) ~ 0;
4748 if (mp->is_ipv6 != 1)
4750 rv = VNET_API_ERROR_UNIMPLEMENTED;
4754 u32 encap_fib_index;
4756 if (mp->encap_vrf_id != ~0)
4759 ip6_main_t *im = &ip6_main;
4762 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4764 rv = VNET_API_ERROR_NO_SUCH_FIB;
4767 encap_fib_index = p[0];
4771 encap_fib_index = ~0;
4774 rv = create_l2tpv3_ipv6_tunnel (lm,
4775 (ip6_address_t *) mp->client_address,
4776 (ip6_address_t *) mp->our_address,
4777 ntohl (mp->local_session_id),
4778 ntohl (mp->remote_session_id),
4779 clib_net_to_host_u64 (mp->local_cookie),
4780 clib_net_to_host_u64 (mp->remote_cookie),
4781 mp->l2_sublayer_present,
4782 encap_fib_index, &sw_if_index);
4786 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4788 rmp->sw_if_index = ntohl (sw_if_index);
4793 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4794 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4796 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4797 l2t_main_t *lm = &l2t_main;
4800 VALIDATE_SW_IF_INDEX (mp);
4802 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4803 clib_net_to_host_u64 (mp->new_local_cookie),
4804 clib_net_to_host_u64
4805 (mp->new_remote_cookie));
4807 BAD_SW_IF_INDEX_LABEL;
4809 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4812 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4813 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4816 vnet_main_t *vnm = vnet_get_main ();
4817 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4819 VALIDATE_SW_IF_INDEX (mp);
4821 rv = l2tpv3_interface_enable_disable
4822 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4824 BAD_SW_IF_INDEX_LABEL;
4826 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4829 static void vl_api_l2tpv3_set_lookup_key_t_handler
4830 (vl_api_l2tpv3_set_lookup_key_t * mp)
4833 l2t_main_t *lm = &l2t_main;
4834 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4836 if (mp->key > L2T_LOOKUP_SESSION_ID)
4838 rv = VNET_API_ERROR_INVALID_VALUE;
4842 lm->lookup_type = mp->key;
4845 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4848 static void vl_api_vxlan_add_del_tunnel_t_handler
4849 (vl_api_vxlan_add_del_tunnel_t * mp)
4851 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4853 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4854 u32 encap_fib_index;
4856 ip4_main_t *im = &ip4_main;
4857 u32 sw_if_index = ~0;
4859 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4862 rv = VNET_API_ERROR_NO_SUCH_FIB;
4865 encap_fib_index = p[0];
4867 /* Check src & dst are different */
4868 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4869 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4871 rv = VNET_API_ERROR_SAME_SRC_DST;
4874 memset (a, 0, sizeof (*a));
4876 a->is_add = mp->is_add;
4877 a->is_ip6 = mp->is_ipv6;
4879 /* ip addresses sent in network byte order */
4882 memcpy (&(a->src.ip6), mp->src_address, 16);
4883 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4887 memcpy (&(a->src.ip4), mp->src_address, 4);
4888 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4891 a->encap_fib_index = encap_fib_index;
4892 a->decap_next_index = ntohl (mp->decap_next_index);
4893 a->vni = ntohl (mp->vni);
4894 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4898 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4900 rmp->sw_if_index = ntohl (sw_if_index);
4905 static void send_vxlan_tunnel_details
4906 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4908 vl_api_vxlan_tunnel_details_t *rmp;
4909 ip4_main_t *im4 = &ip4_main;
4910 ip6_main_t *im6 = &ip6_main;
4911 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4913 rmp = vl_msg_api_alloc (sizeof (*rmp));
4914 memset (rmp, 0, sizeof (*rmp));
4915 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4918 memcpy (rmp->src_address, &(t->src.ip6), 16);
4919 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4920 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
4924 memcpy (rmp->src_address, &(t->src.ip4), 4);
4925 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4926 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
4928 rmp->vni = htonl (t->vni);
4929 rmp->decap_next_index = htonl (t->decap_next_index);
4930 rmp->sw_if_index = htonl (t->sw_if_index);
4931 rmp->is_ipv6 = is_ipv6;
4932 rmp->context = context;
4934 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4937 static void vl_api_vxlan_tunnel_dump_t_handler
4938 (vl_api_vxlan_tunnel_dump_t * mp)
4940 unix_shared_memory_queue_t *q;
4941 vxlan_main_t *vxm = &vxlan_main;
4945 q = vl_api_client_index_to_input_queue (mp->client_index);
4951 sw_if_index = ntohl (mp->sw_if_index);
4953 if (~0 == sw_if_index)
4956 pool_foreach (t, vxm->tunnels,
4958 send_vxlan_tunnel_details(t, q, mp->context);
4964 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4965 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4969 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4970 send_vxlan_tunnel_details (t, q, mp->context);
4974 static void vl_api_gre_add_del_tunnel_t_handler
4975 (vl_api_gre_add_del_tunnel_t * mp)
4977 vl_api_gre_add_del_tunnel_reply_t *rmp;
4979 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4982 ip4_main_t *im = &ip4_main;
4983 u32 sw_if_index = ~0;
4985 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4988 rv = VNET_API_ERROR_NO_SUCH_FIB;
4991 outer_fib_id = p[0];
4993 /* Check src & dst are different */
4994 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4995 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4997 rv = VNET_API_ERROR_SAME_SRC_DST;
5000 memset (a, 0, sizeof (*a));
5002 a->is_add = mp->is_add;
5004 /* ip addresses sent in network byte order */
5005 clib_memcpy (&(a->src), mp->src_address, 4);
5006 clib_memcpy (&(a->dst), mp->dst_address, 4);
5008 a->outer_fib_id = outer_fib_id;
5009 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
5013 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
5015 rmp->sw_if_index = ntohl (sw_if_index);
5020 static void send_gre_tunnel_details
5021 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5023 vl_api_gre_tunnel_details_t *rmp;
5024 ip4_main_t *im = &ip4_main;
5026 rmp = vl_msg_api_alloc (sizeof (*rmp));
5027 memset (rmp, 0, sizeof (*rmp));
5028 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
5029 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
5030 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
5031 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
5032 rmp->sw_if_index = htonl (t->sw_if_index);
5033 rmp->context = context;
5035 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5039 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
5041 unix_shared_memory_queue_t *q;
5042 gre_main_t *gm = &gre_main;
5046 q = vl_api_client_index_to_input_queue (mp->client_index);
5052 sw_if_index = ntohl (mp->sw_if_index);
5054 if (~0 == sw_if_index)
5057 pool_foreach (t, gm->tunnels,
5059 send_gre_tunnel_details(t, q, mp->context);
5065 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
5066 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
5070 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
5071 send_gre_tunnel_details (t, q, mp->context);
5076 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
5078 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5080 vl_api_l2_patch_add_del_reply_t *rmp;
5081 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5085 VALIDATE_RX_SW_IF_INDEX (mp);
5086 VALIDATE_TX_SW_IF_INDEX (mp);
5088 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
5089 ntohl (mp->tx_sw_if_index),
5090 (int) (mp->is_add != 0));
5092 BAD_RX_SW_IF_INDEX_LABEL;
5093 BAD_TX_SW_IF_INDEX_LABEL;
5095 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
5099 vl_api_vxlan_gpe_add_del_tunnel_t_handler
5100 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
5102 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
5104 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
5105 u32 encap_fib_index, decap_fib_index;
5108 ip4_main_t *im = &ip4_main;
5109 u32 sw_if_index = ~0;
5112 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
5115 rv = VNET_API_ERROR_NO_SUCH_FIB;
5118 encap_fib_index = p[0];
5120 protocol = mp->protocol;
5122 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
5123 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
5125 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
5128 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
5131 decap_fib_index = p[0];
5135 decap_fib_index = ntohl (mp->decap_vrf_id);
5138 /* Check src & dst are different */
5139 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5140 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5142 rv = VNET_API_ERROR_SAME_SRC_DST;
5145 memset (a, 0, sizeof (*a));
5147 a->is_add = mp->is_add;
5148 a->is_ip6 = mp->is_ipv6;
5149 /* ip addresses sent in network byte order */
5152 clib_memcpy (&(a->local.ip6), mp->local, 16);
5153 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5157 clib_memcpy (&(a->local.ip4), mp->local, 4);
5158 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5160 a->encap_fib_index = encap_fib_index;
5161 a->decap_fib_index = decap_fib_index;
5162 a->protocol = protocol;
5163 a->vni = ntohl (mp->vni);
5164 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5168 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5170 rmp->sw_if_index = ntohl (sw_if_index);
5175 static void send_vxlan_gpe_tunnel_details
5176 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5178 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5179 ip4_main_t *im4 = &ip4_main;
5180 ip6_main_t *im6 = &ip6_main;
5181 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5183 rmp = vl_msg_api_alloc (sizeof (*rmp));
5184 memset (rmp, 0, sizeof (*rmp));
5185 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5188 memcpy (rmp->local, &(t->local.ip6), 16);
5189 memcpy (rmp->remote, &(t->remote.ip6), 16);
5190 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
5191 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].table_id);
5195 memcpy (rmp->local, &(t->local.ip4), 4);
5196 memcpy (rmp->remote, &(t->remote.ip4), 4);
5197 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
5198 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].table_id);
5200 rmp->vni = htonl (t->vni);
5201 rmp->protocol = t->protocol;
5202 rmp->sw_if_index = htonl (t->sw_if_index);
5203 rmp->is_ipv6 = is_ipv6;
5204 rmp->context = context;
5206 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5209 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5210 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5212 unix_shared_memory_queue_t *q;
5213 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5214 vxlan_gpe_tunnel_t *t;
5217 q = vl_api_client_index_to_input_queue (mp->client_index);
5223 sw_if_index = ntohl (mp->sw_if_index);
5225 if (~0 == sw_if_index)
5228 pool_foreach (t, vgm->tunnels,
5230 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5236 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5237 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5241 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5242 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5246 /** Used for transferring locators via VPP API */
5248 typedef CLIB_PACKED (struct {
5249 u32 sw_if_index; /**< locator sw_if_index */
5250 u8 priority; /**< locator priority */
5251 u8 weight; /**< locator weight */
5256 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5259 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5261 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5263 ls_locator_t *ls_loc;
5264 u32 ls_index = ~0, locator_num;
5265 u8 *locator_name = NULL;
5268 memset (a, 0, sizeof (a[0]));
5270 locator_name = format (0, "%s", mp->locator_set_name);
5272 a->name = locator_name;
5273 a->is_add = mp->is_add;
5275 locator_num = clib_net_to_host_u32 (mp->locator_num);
5277 memset (&locator, 0, sizeof (locator));
5278 for (i = 0; i < locator_num; i++)
5280 ls_loc = &((ls_locator_t *) mp->locators)[i];
5281 VALIDATE_SW_IF_INDEX (ls_loc);
5283 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5284 locator.priority = ls_loc->priority;
5285 locator.weight = ls_loc->weight;
5287 vec_add1 (a->locators, locator);
5290 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5292 BAD_SW_IF_INDEX_LABEL;
5294 vec_free (locator_name);
5295 vec_free (a->locators);
5298 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5300 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5306 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5308 vl_api_lisp_add_del_locator_reply_t *rmp;
5310 locator_t locator, *locators = NULL;
5311 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5313 u8 *locator_name = NULL;
5315 memset (&locator, 0, sizeof (locator));
5316 memset (a, 0, sizeof (a[0]));
5318 locator.sw_if_index = ntohl (mp->sw_if_index);
5319 locator.priority = mp->priority;
5320 locator.weight = mp->weight;
5322 vec_add1 (locators, locator);
5324 locator_name = format (0, "%s", mp->locator_set_name);
5326 a->name = locator_name;
5327 a->locators = locators;
5328 a->is_add = mp->is_add;
5331 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5333 vec_free (locators);
5334 vec_free (locator_name);
5336 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5340 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5346 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5347 gid_address_ip_set (dst, src, IP4);
5348 gid_address_ippref_len (dst) = len;
5349 ip_prefix_normalize (&gid_address_ippref (dst));
5352 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5353 gid_address_ip_set (dst, src, IP6);
5354 gid_address_ippref_len (dst) = len;
5355 ip_prefix_normalize (&gid_address_ippref (dst));
5357 case 2: /* l2 mac */
5358 gid_address_type (dst) = GID_ADDR_MAC;
5359 clib_memcpy (&gid_address_mac (dst), src, 6);
5363 return VNET_API_ERROR_INVALID_VALUE;
5366 gid_address_vni (dst) = vni;
5372 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5374 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5375 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5377 gid_address_t _eid, *eid = &_eid;
5379 u32 locator_set_index = ~0, map_index = ~0;
5380 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5382 memset (a, 0, sizeof (a[0]));
5383 memset (eid, 0, sizeof (eid[0]));
5385 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5386 mp->eid_type, mp->eid, mp->prefix_len);
5390 name = format (0, "%s", mp->locator_set_name);
5391 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5394 rv = VNET_API_ERROR_INVALID_VALUE;
5397 locator_set_index = p[0];
5399 /* XXX treat batch configuration */
5400 a->is_add = mp->is_add;
5401 gid_address_copy (&a->eid, eid);
5402 a->locator_set_index = locator_set_index;
5404 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5408 gid_address_free (&a->eid);
5410 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5414 vl_api_lisp_eid_table_add_del_map_t_handler
5415 (vl_api_lisp_eid_table_add_del_map_t * mp)
5417 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5419 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5420 clib_net_to_host_u32 (mp->dp_table),
5421 mp->is_l2, mp->is_add);
5422 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5424 /** Used for transferring locators via VPP API */
5426 typedef CLIB_PACKED (struct {
5427 u8 is_ip4; /**< is locator an IPv4 address */
5428 u8 priority; /**< locator priority */
5429 u8 weight; /**< locator weight */
5430 u8 addr[16]; /**< IPv4/IPv6 address */
5434 static locator_pair_t *
5435 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5438 locator_pair_t *pairs = 0, pair;
5441 for (i = 0; i < rloc_num; i++)
5444 r = &((rloc_t *) lcl_locs)[i];
5445 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5446 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5448 /* remote locators */
5449 r = &((rloc_t *) rmt_locs)[i];
5450 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5451 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5453 pair.priority = r->priority;
5454 pair.weight = r->weight;
5456 vec_add1 (pairs, pair);
5462 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5465 locator_t *locs = 0, loc;
5468 for (i = 0; i < rloc_num; i++)
5470 /* remote locators */
5471 r = &((rloc_t *) rmt_locs)[i];
5472 memset (&loc, 0, sizeof (loc));
5473 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5475 loc.priority = r->priority;
5476 loc.weight = r->weight;
5478 vec_add1 (locs, loc);
5484 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5485 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5487 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5488 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5489 locator_pair_t *pairs = 0;
5492 memset (a, 0, sizeof (a[0]));
5494 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5495 mp->rmt_eid, mp->rmt_len);
5496 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5497 mp->lcl_eid, mp->lcl_len);
5499 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5501 if (rv || 0 == pairs)
5504 a->is_add = mp->is_add;
5505 a->locator_pairs = pairs;
5506 a->dp_table = mp->dp_table;
5508 a->action = mp->action;
5510 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5513 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5517 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5520 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5522 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5524 memset (a, 0, sizeof (a[0]));
5526 a->is_add = mp->is_add;
5527 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5529 rv = vnet_lisp_add_del_map_resolver (a);
5531 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5535 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5538 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5540 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5542 a->is_en = mp->is_en;
5543 vnet_lisp_gpe_enable_disable (a);
5545 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5549 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5551 vl_api_lisp_enable_disable_reply_t *rmp;
5554 vnet_lisp_enable_disable (mp->is_en);
5555 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5559 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5561 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5563 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5565 a->is_add = mp->is_add;
5566 a->dp_table = mp->dp_table;
5568 a->is_l2 = mp->is_l2;
5569 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5571 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5575 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5578 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5582 ls_name = format (0, "%s", mp->ls_name);
5583 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5586 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5590 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5591 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5593 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5595 u8 *locator_set_name = NULL;
5596 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5598 locator_set_name = format (0, "%s", mp->locator_set_name);
5600 a->is_add = mp->is_add;
5601 a->locator_set_name = locator_set_name;
5603 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5605 vec_free (locator_set_name);
5607 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5611 vl_api_lisp_add_del_remote_mapping_t_handler
5612 (vl_api_lisp_add_del_remote_mapping_t * mp)
5614 locator_t *rlocs = 0;
5615 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5617 gid_address_t _eid, *eid = &_eid;
5618 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5620 memset (eid, 0, sizeof (eid[0]));
5622 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5623 mp->eid_type, mp->eid, mp->eid_len);
5627 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5631 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5632 gid_address_copy (&a->deid, eid);
5634 rv = vnet_lisp_add_del_adjacency (a);
5641 /* NOTE: for now this works as a static remote mapping, i.e.,
5642 * not authoritative and ttl infinite. */
5643 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5644 mp->is_add, 1 /* is_static */ , 0);
5647 vnet_lisp_clear_all_remote_adjacencies ();
5652 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5656 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5658 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5659 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5662 memset (a, 0, sizeof (a[0]));
5664 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5665 mp->eid_type, mp->seid, mp->seid_len);
5666 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5667 mp->eid_type, mp->deid, mp->deid_len);
5672 a->is_add = mp->is_add;
5673 rv = vnet_lisp_add_del_adjacency (a);
5676 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5680 send_lisp_locator_details (lisp_cp_main_t * lcm,
5682 unix_shared_memory_queue_t * q, u32 context)
5684 vl_api_lisp_locator_details_t *rmp;
5686 rmp = vl_msg_api_alloc (sizeof (*rmp));
5687 memset (rmp, 0, sizeof (*rmp));
5688 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5689 rmp->context = context;
5691 rmp->local = loc->local;
5694 rmp->sw_if_index = ntohl (loc->sw_if_index);
5698 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5699 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5701 rmp->priority = loc->priority;
5702 rmp->weight = loc->weight;
5704 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5708 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5710 unix_shared_memory_queue_t *q = 0;
5711 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5712 locator_set_t *lsit = 0;
5714 u32 ls_index = ~0, *locit = 0;
5717 q = vl_api_client_index_to_input_queue (mp->client_index);
5723 ls_index = htonl (mp->locator_set_index);
5725 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5727 filter = mp->filter;
5728 if (filter && !((1 == filter && lsit->local) ||
5729 (2 == filter && !lsit->local)))
5734 vec_foreach (locit, lsit->locator_indices)
5736 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5737 send_lisp_locator_details (lcm, loc, q, mp->context);
5742 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5743 locator_set_t * lsit,
5744 unix_shared_memory_queue_t * q,
5745 u32 context, u32 ls_index)
5747 vl_api_lisp_locator_set_details_t *rmp;
5750 rmp = vl_msg_api_alloc (sizeof (*rmp));
5751 memset (rmp, 0, sizeof (*rmp));
5752 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5753 rmp->context = context;
5755 rmp->local = lsit->local;
5756 rmp->locator_set_index = htonl (ls_index);
5759 ASSERT (lsit->name != NULL);
5760 strncpy ((char *) rmp->locator_set_name,
5761 (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1);
5765 str = format (0, "remote-%d", ls_index);
5766 strncpy ((char *) rmp->locator_set_name, (char *) str,
5767 ARRAY_LEN (rmp->locator_set_name) - 1);
5771 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5775 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5777 unix_shared_memory_queue_t *q = NULL;
5778 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5779 locator_set_t *lsit = NULL;
5783 q = vl_api_client_index_to_input_queue (mp->client_index);
5789 filter = mp->filter;
5792 pool_foreach (lsit, lcm->locator_set_pool,
5794 if (filter && !((1 == filter && lsit->local) ||
5795 (2 == filter && !lsit->local))) {
5799 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5805 send_lisp_eid_table_details (mapping_t * mapit,
5806 unix_shared_memory_queue_t * q,
5807 u32 context, u8 filter)
5809 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5810 locator_set_t *ls = 0;
5811 vl_api_lisp_eid_table_details_t *rmp = NULL;
5812 gid_address_t *gid = NULL;
5814 ip_prefix_t *ip_prefix = NULL;
5818 case 0: /* all mappings */
5821 case 1: /* local only */
5825 case 2: /* remote only */
5830 clib_warning ("Filter error, unknown filter: %d", filter);
5835 ip_prefix = &gid_address_ippref (gid);
5836 mac = gid_address_mac (gid);
5838 rmp = vl_msg_api_alloc (sizeof (*rmp));
5839 memset (rmp, 0, sizeof (*rmp));
5840 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5842 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5843 if (vec_len (ls->locator_indices) == 0)
5844 rmp->locator_set_index = ~0;
5846 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5848 rmp->is_local = mapit->local;
5849 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5850 rmp->action = mapit->action;
5851 rmp->authoritative = mapit->authoritative;
5853 switch (gid_address_type (gid))
5855 case GID_ADDR_IP_PREFIX:
5856 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5857 if (ip_prefix_version (ip_prefix) == IP4)
5859 rmp->eid_type = 0; /* ipv4 type */
5860 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5861 sizeof (ip_prefix_v4 (ip_prefix)));
5865 rmp->eid_type = 1; /* ipv6 type */
5866 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5867 sizeof (ip_prefix_v6 (ip_prefix)));
5871 rmp->eid_type = 2; /* l2 mac type */
5872 clib_memcpy (rmp->eid, mac, 6);
5877 rmp->context = context;
5878 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5879 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5883 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5886 unix_shared_memory_queue_t *q = NULL;
5887 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5888 mapping_t *mapit = NULL;
5889 gid_address_t _eid, *eid = &_eid;
5891 q = vl_api_client_index_to_input_queue (mp->client_index);
5899 memset (eid, 0, sizeof (*eid));
5901 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5902 mp->eid_type, mp->eid, mp->prefix_length);
5904 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5905 if ((u32) ~ 0 == mi)
5908 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5909 send_lisp_eid_table_details (mapit, q, mp->context,
5910 0 /* ignore filter */ );
5915 pool_foreach (mapit, lcm->mapping_pool,
5917 send_lisp_eid_table_details(mapit, q, mp->context,
5925 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5926 unix_shared_memory_queue_t * q, u32 context)
5928 vl_api_lisp_gpe_tunnel_details_t *rmp;
5929 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5931 rmp = vl_msg_api_alloc (sizeof (*rmp));
5932 memset (rmp, 0, sizeof (*rmp));
5933 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5935 rmp->tunnels = tunnel - lgm->tunnels;
5937 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5938 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5939 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5941 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5942 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5943 rmp->dcap_next = htonl (tunnel->decap_next_index);
5944 rmp->lisp_ver = tunnel->ver_res;
5945 rmp->next_protocol = tunnel->next_protocol;
5946 rmp->flags = tunnel->flags;
5947 rmp->ver_res = tunnel->ver_res;
5948 rmp->res = tunnel->res;
5949 rmp->iid = htonl (tunnel->vni);
5950 rmp->context = context;
5952 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5956 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5958 unix_shared_memory_queue_t *q = NULL;
5959 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5960 lisp_gpe_tunnel_t *tunnel = NULL;
5962 if (pool_elts (lgm->tunnels) == 0)
5967 q = vl_api_client_index_to_input_queue (mp->client_index);
5974 pool_foreach(tunnel, lgm->tunnels,
5976 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5982 send_lisp_map_resolver_details (ip_address_t * ip,
5983 unix_shared_memory_queue_t * q, u32 context)
5985 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5987 rmp = vl_msg_api_alloc (sizeof (*rmp));
5988 memset (rmp, 0, sizeof (*rmp));
5989 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5991 switch (ip_addr_version (ip))
5995 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
5996 sizeof (ip_addr_v4 (ip)));
6001 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
6002 sizeof (ip_addr_v6 (ip)));
6008 rmp->context = context;
6010 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6014 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
6016 unix_shared_memory_queue_t *q = NULL;
6017 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6020 q = vl_api_client_index_to_input_queue (mp->client_index);
6026 vec_foreach (mr, lcm->map_resolvers)
6028 send_lisp_map_resolver_details (&mr->address, q, mp->context);
6033 send_eid_table_map_pair (hash_pair_t * p,
6034 unix_shared_memory_queue_t * q, u32 context)
6036 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
6038 rmp = vl_msg_api_alloc (sizeof (*rmp));
6039 memset (rmp, 0, sizeof (*rmp));
6040 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
6042 rmp->vni = clib_host_to_net_u32 (p->key);
6043 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
6044 rmp->context = context;
6045 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6049 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
6052 unix_shared_memory_queue_t *q = NULL;
6053 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6055 uword *vni_table = 0;
6057 q = vl_api_client_index_to_input_queue (mp->client_index);
6065 vni_table = lcm->bd_id_by_vni;
6069 vni_table = lcm->table_id_by_vni;
6073 hash_foreach_pair (p, vni_table,
6075 send_eid_table_map_pair (p, q, mp->context);
6081 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6083 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6085 rmp = vl_msg_api_alloc (sizeof (*rmp));
6086 memset (rmp, 0, sizeof (*rmp));
6087 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6088 rmp->context = context;
6089 rmp->vni = clib_host_to_net_u32 (vni);
6090 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6094 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6099 unix_shared_memory_queue_t *q = 0;
6100 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6102 q = vl_api_client_index_to_input_queue (mp->client_index);
6109 hash_foreach_pair (p, lcm->table_id_by_vni,
6111 hash_set (vnis, p->key, 0);
6114 hash_foreach_pair (p, lcm->bd_id_by_vni,
6116 hash_set (vnis, p->key, 0);
6119 hash_foreach_pair (p, vnis,
6121 send_eid_table_vni (p->key, q, mp->context);
6129 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6131 unix_shared_memory_queue_t *q = NULL;
6132 vl_api_show_lisp_status_reply_t *rmp = NULL;
6135 q = vl_api_client_index_to_input_queue (mp->client_index);
6142 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6144 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6145 rmp->feature_status = vnet_lisp_enable_disable_status ();
6151 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6152 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6154 unix_shared_memory_queue_t *q = NULL;
6155 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6156 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6157 locator_set_t *loc_set = 0;
6161 q = vl_api_client_index_to_input_queue (mp->client_index);
6167 if (~0 == lcm->mreq_itr_rlocs)
6169 tmp_str = format (0, " ");
6174 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6175 tmp_str = format (0, "%s", loc_set->name);
6179 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6181 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6182 ARRAY_LEN(rmp->locator_set_name) - 1);
6190 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6192 unix_shared_memory_queue_t *q = NULL;
6193 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6194 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6196 locator_set_t *ls = 0;
6200 q = vl_api_client_index_to_input_queue (mp->client_index);
6206 if (!lcm->lisp_pitr)
6208 tmp_str = format (0, "N/A");
6212 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6213 if (~0 != m->locator_set_index)
6216 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6217 tmp_str = format (0, "%s", ls->name);
6221 tmp_str = format (0, "N/A");
6224 vec_add1 (tmp_str, 0);
6227 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6229 rmp->status = lcm->lisp_pitr;
6230 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6231 ARRAY_LEN(rmp->locator_set_name) - 1);
6237 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6240 vl_api_interface_name_renumber_reply_t *rmp;
6243 VALIDATE_SW_IF_INDEX (mp);
6245 rv = vnet_interface_name_renumber
6246 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6248 BAD_SW_IF_INDEX_LABEL;
6250 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6254 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6255 u32 sw_if_index, u32 address)
6257 vpe_api_main_t *am = &vpe_api_main;
6258 vlib_main_t *vm = am->vlib_main;
6259 vl_api_ip4_arp_event_t *event;
6260 static f64 arp_event_last_time;
6261 f64 now = vlib_time_now (vm);
6263 if (pool_is_free_index (am->arp_events, pool_index))
6266 event = pool_elt_at_index (am->arp_events, pool_index);
6268 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6270 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6274 if (sw_if_index == event->sw_if_index &&
6276 /* for BD case, also check IP address with 10 sec timeout */
6277 (address == event->address &&
6278 (now - arp_event_last_time) < 10.0)))
6283 arp_event_last_time = now;
6284 event->sw_if_index = sw_if_index;
6286 event->address = address;
6291 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6292 u32 sw_if_index, ip6_address_t * address)
6294 vpe_api_main_t *am = &vpe_api_main;
6295 vlib_main_t *vm = am->vlib_main;
6296 vl_api_ip6_nd_event_t *event;
6297 static f64 nd_event_last_time;
6298 f64 now = vlib_time_now (vm);
6300 if (pool_is_free_index (am->nd_events, pool_index))
6303 event = pool_elt_at_index (am->nd_events, pool_index);
6306 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6308 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6312 if (sw_if_index == event->sw_if_index &&
6314 /* for BD case, also check IP address with 10 sec timeout */
6315 (ip6_address_is_equal (address,
6316 (ip6_address_t *) event->address) &&
6317 (now - nd_event_last_time) < 10.0)))
6322 nd_event_last_time = now;
6323 event->sw_if_index = sw_if_index;
6325 clib_memcpy (event->address, address, sizeof (event->address));
6330 arp_change_delete_callback (u32 pool_index, u8 * notused)
6332 vpe_api_main_t *am = &vpe_api_main;
6334 if (pool_is_free_index (am->arp_events, pool_index))
6337 pool_put_index (am->arp_events, pool_index);
6342 nd_change_delete_callback (u32 pool_index, u8 * notused)
6344 vpe_api_main_t *am = &vpe_api_main;
6346 if (pool_is_free_index (am->nd_events, pool_index))
6349 pool_put_index (am->nd_events, pool_index);
6354 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6356 vpe_api_main_t *am = &vpe_api_main;
6357 vnet_main_t *vnm = vnet_get_main ();
6358 vl_api_want_ip4_arp_events_reply_t *rmp;
6359 vl_api_ip4_arp_event_t *event;
6362 if (mp->enable_disable)
6364 pool_get (am->arp_events, event);
6365 memset (event, 0, sizeof (*event));
6367 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6368 event->client_index = mp->client_index;
6369 event->context = mp->context;
6370 event->address = mp->address;
6371 event->pid = mp->pid;
6372 if (mp->address == 0)
6375 rv = vnet_add_del_ip4_arp_change_event
6376 (vnm, arp_change_data_callback,
6377 mp->pid, &mp->address /* addr, in net byte order */ ,
6378 vpe_resolver_process_node.index,
6379 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6383 rv = vnet_add_del_ip4_arp_change_event
6384 (vnm, arp_change_delete_callback,
6385 mp->pid, &mp->address /* addr, in net byte order */ ,
6386 vpe_resolver_process_node.index,
6387 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6389 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6393 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6395 vpe_api_main_t *am = &vpe_api_main;
6396 vnet_main_t *vnm = vnet_get_main ();
6397 vl_api_want_ip6_nd_events_reply_t *rmp;
6398 vl_api_ip6_nd_event_t *event;
6401 if (mp->enable_disable)
6403 pool_get (am->nd_events, event);
6404 memset (event, 0, sizeof (*event));
6406 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6407 event->client_index = mp->client_index;
6408 event->context = mp->context;
6409 clib_memcpy (event->address, mp->address, 16);
6410 event->pid = mp->pid;
6411 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6414 rv = vnet_add_del_ip6_nd_change_event
6415 (vnm, nd_change_data_callback,
6416 mp->pid, mp->address /* addr, in net byte order */ ,
6417 vpe_resolver_process_node.index,
6418 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6422 rv = vnet_add_del_ip6_nd_change_event
6423 (vnm, nd_change_delete_callback,
6424 mp->pid, mp->address /* addr, in net byte order */ ,
6425 vpe_resolver_process_node.index,
6426 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6428 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6431 static void vl_api_input_acl_set_interface_t_handler
6432 (vl_api_input_acl_set_interface_t * mp)
6434 vlib_main_t *vm = vlib_get_main ();
6435 vl_api_input_acl_set_interface_reply_t *rmp;
6437 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6439 ip4_table_index = ntohl (mp->ip4_table_index);
6440 ip6_table_index = ntohl (mp->ip6_table_index);
6441 l2_table_index = ntohl (mp->l2_table_index);
6442 sw_if_index = ntohl (mp->sw_if_index);
6444 VALIDATE_SW_IF_INDEX (mp);
6446 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6447 ip6_table_index, l2_table_index, mp->is_add);
6449 BAD_SW_IF_INDEX_LABEL;
6451 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6454 static void vl_api_ipsec_spd_add_del_t_handler
6455 (vl_api_ipsec_spd_add_del_t * mp)
6458 clib_warning ("unimplemented");
6461 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6462 vl_api_ipsec_spd_add_del_reply_t *rmp;
6466 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6468 rv = VNET_API_ERROR_UNIMPLEMENTED;
6471 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6475 static void vl_api_ipsec_interface_add_del_spd_t_handler
6476 (vl_api_ipsec_interface_add_del_spd_t * mp)
6478 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6479 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6481 u32 sw_if_index __attribute__ ((unused));
6482 u32 spd_id __attribute__ ((unused));
6484 sw_if_index = ntohl (mp->sw_if_index);
6485 spd_id = ntohl (mp->spd_id);
6487 VALIDATE_SW_IF_INDEX (mp);
6490 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6492 rv = VNET_API_ERROR_UNIMPLEMENTED;
6495 BAD_SW_IF_INDEX_LABEL;
6497 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6500 static void vl_api_ipsec_spd_add_del_entry_t_handler
6501 (vl_api_ipsec_spd_add_del_entry_t * mp)
6503 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6504 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6510 memset (&p, 0, sizeof (p));
6512 p.id = ntohl (mp->spd_id);
6513 p.priority = ntohl (mp->priority);
6514 p.is_outbound = mp->is_outbound;
6515 p.is_ipv6 = mp->is_ipv6;
6517 if (mp->is_ipv6 || mp->is_ip_any)
6519 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6520 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6521 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6522 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6526 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6527 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6528 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6529 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6531 p.protocol = mp->protocol;
6532 p.rport.start = ntohs (mp->remote_port_start);
6533 p.rport.stop = ntohs (mp->remote_port_stop);
6534 p.lport.start = ntohs (mp->local_port_start);
6535 p.lport.stop = ntohs (mp->local_port_stop);
6536 /* policy action resolve unsupported */
6537 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6539 clib_warning ("unsupported action: 'resolve'");
6540 rv = VNET_API_ERROR_UNIMPLEMENTED;
6543 p.policy = mp->policy;
6544 p.sa_id = ntohl (mp->sa_id);
6546 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6553 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6556 rv = VNET_API_ERROR_UNIMPLEMENTED;
6561 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6564 static void vl_api_ipsec_sad_add_del_entry_t_handler
6565 (vl_api_ipsec_sad_add_del_entry_t * mp)
6567 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6568 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6573 memset (&sa, 0, sizeof (sa));
6575 sa.id = ntohl (mp->sad_id);
6576 sa.spi = ntohl (mp->spi);
6577 /* security protocol AH unsupported */
6578 if (mp->protocol == IPSEC_PROTOCOL_AH)
6580 clib_warning ("unsupported security protocol 'AH'");
6581 rv = VNET_API_ERROR_UNIMPLEMENTED;
6584 sa.protocol = mp->protocol;
6585 /* check for unsupported crypto-alg */
6586 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6587 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6589 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6590 mp->crypto_algorithm);
6591 rv = VNET_API_ERROR_UNIMPLEMENTED;
6594 sa.crypto_alg = mp->crypto_algorithm;
6595 sa.crypto_key_len = mp->crypto_key_length;
6596 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6597 /* check for unsupported integ-alg */
6598 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6599 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6601 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6602 mp->integrity_algorithm);
6603 rv = VNET_API_ERROR_UNIMPLEMENTED;
6606 sa.integ_alg = mp->integrity_algorithm;
6607 sa.integ_key_len = mp->integrity_key_length;
6608 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6609 sa.use_esn = mp->use_extended_sequence_number;
6610 sa.is_tunnel = mp->is_tunnel;
6611 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6612 if (sa.is_tunnel_ip6)
6614 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6615 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6619 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6620 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6623 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6625 rv = VNET_API_ERROR_UNIMPLEMENTED;
6630 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6634 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6636 vl_api_ikev2_profile_add_del_reply_t *rmp;
6640 vlib_main_t *vm = vlib_get_main ();
6641 clib_error_t *error;
6642 u8 *tmp = format (0, "%s", mp->name);
6643 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6646 rv = VNET_API_ERROR_UNSPECIFIED;
6648 rv = VNET_API_ERROR_UNIMPLEMENTED;
6651 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6655 vl_api_ikev2_profile_set_auth_t_handler
6656 (vl_api_ikev2_profile_set_auth_t * mp)
6658 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6662 vlib_main_t *vm = vlib_get_main ();
6663 clib_error_t *error;
6664 u8 *tmp = format (0, "%s", mp->name);
6665 u8 *data = vec_new (u8, mp->data_len);
6666 clib_memcpy (data, mp->data, mp->data_len);
6667 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6671 rv = VNET_API_ERROR_UNSPECIFIED;
6673 rv = VNET_API_ERROR_UNIMPLEMENTED;
6676 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6680 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6682 vl_api_ikev2_profile_add_del_reply_t *rmp;
6686 vlib_main_t *vm = vlib_get_main ();
6687 clib_error_t *error;
6688 u8 *tmp = format (0, "%s", mp->name);
6689 u8 *data = vec_new (u8, mp->data_len);
6690 clib_memcpy (data, mp->data, mp->data_len);
6691 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6695 rv = VNET_API_ERROR_UNSPECIFIED;
6697 rv = VNET_API_ERROR_UNIMPLEMENTED;
6700 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6704 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6706 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6710 vlib_main_t *vm = vlib_get_main ();
6711 clib_error_t *error;
6712 u8 *tmp = format (0, "%s", mp->name);
6713 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6714 mp->end_port, (ip4_address_t) mp->start_addr,
6715 (ip4_address_t) mp->end_addr, mp->is_local);
6718 rv = VNET_API_ERROR_UNSPECIFIED;
6720 rv = VNET_API_ERROR_UNIMPLEMENTED;
6723 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6727 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6729 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6733 vlib_main_t *vm = vlib_get_main ();
6734 clib_error_t *error;
6736 error = ikev2_set_local_key (vm, mp->key_file);
6738 rv = VNET_API_ERROR_UNSPECIFIED;
6740 rv = VNET_API_ERROR_UNIMPLEMENTED;
6743 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6747 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6749 vl_api_map_add_domain_reply_t *rmp;
6752 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6754 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6755 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6756 (ip6_address_t *) & mp->ip6_src,
6757 mp->ip6_src_prefix_len, mp->ea_bits_len,
6758 mp->psid_offset, mp->psid_length, &index,
6759 ntohs (mp->mtu), flags);
6762 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6764 rmp->index = ntohl(index);
6770 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6772 vl_api_map_del_domain_reply_t *rmp;
6775 rv = map_delete_domain (ntohl (mp->index));
6777 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6781 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6783 vl_api_map_del_domain_reply_t *rmp;
6787 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6788 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6790 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6794 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6796 vl_api_map_domain_details_t *rmp;
6797 map_main_t *mm = &map_main;
6799 unix_shared_memory_queue_t *q;
6801 if (pool_elts (mm->domains) == 0)
6804 q = vl_api_client_index_to_input_queue (mp->client_index);
6811 pool_foreach(d, mm->domains,
6813 /* Make sure every field is initiated (or don't skip the memset()) */
6814 rmp = vl_msg_api_alloc (sizeof (*rmp));
6815 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6816 rmp->domain_index = htonl(d - mm->domains);
6817 rmp->ea_bits_len = d->ea_bits_len;
6818 rmp->psid_offset = d->psid_offset;
6819 rmp->psid_length = d->psid_length;
6820 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6821 rmp->ip4_prefix_len = d->ip4_prefix_len;
6822 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6823 rmp->ip6_prefix_len = d->ip6_prefix_len;
6824 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6825 rmp->ip6_src_len = d->ip6_src_len;
6826 rmp->mtu = htons(d->mtu);
6827 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6828 rmp->context = mp->context;
6830 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6836 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6838 unix_shared_memory_queue_t *q;
6841 vl_api_map_rule_details_t *rmp;
6842 map_main_t *mm = &map_main;
6843 u32 domain_index = ntohl (mp->domain_index);
6846 if (pool_elts (mm->domains) == 0)
6849 d = pool_elt_at_index (mm->domains, domain_index);
6850 if (!d || !d->rules)
6855 q = vl_api_client_index_to_input_queue (mp->client_index);
6861 for (i = 0; i < (0x1 << d->psid_length); i++)
6864 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6868 rmp = vl_msg_api_alloc (sizeof (*rmp));
6869 memset (rmp, 0, sizeof (*rmp));
6870 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6871 rmp->psid = htons (i);
6872 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6873 rmp->context = mp->context;
6874 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6879 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6881 vl_api_map_summary_stats_reply_t *rmp;
6882 vlib_combined_counter_main_t *cm;
6885 u64 total_pkts[VLIB_N_RX_TX];
6886 u64 total_bytes[VLIB_N_RX_TX];
6887 map_main_t *mm = &map_main;
6888 unix_shared_memory_queue_t *q =
6889 vl_api_client_index_to_input_queue (mp->client_index);
6894 rmp = vl_msg_api_alloc (sizeof (*rmp));
6895 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6896 rmp->context = mp->context;
6899 memset (total_pkts, 0, sizeof (total_pkts));
6900 memset (total_bytes, 0, sizeof (total_bytes));
6902 map_domain_counter_lock (mm);
6903 vec_foreach (cm, mm->domain_counters)
6905 which = cm - mm->domain_counters;
6907 for (i = 0; i < vec_len (cm->maxi); i++)
6909 vlib_get_combined_counter (cm, i, &v);
6910 total_pkts[which] += v.packets;
6911 total_bytes[which] += v.bytes;
6915 map_domain_counter_unlock (mm);
6917 /* Note: in network byte order! */
6918 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6919 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6920 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6921 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6922 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6923 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6924 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6925 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6926 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6927 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6928 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6929 clib_host_to_net_u64 (map_error_counter_get
6930 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6931 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6932 clib_host_to_net_u64 (map_error_counter_get
6933 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6935 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6939 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6941 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6942 vl_api_ipsec_sa_set_key_reply_t *rmp;
6946 sa.id = ntohl (mp->sa_id);
6947 sa.crypto_key_len = mp->crypto_key_length;
6948 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6949 sa.integ_key_len = mp->integrity_key_length;
6950 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6952 rv = ipsec_set_sa_key (vm, &sa);
6954 rv = VNET_API_ERROR_UNIMPLEMENTED;
6957 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6960 static void vl_api_cop_interface_enable_disable_t_handler
6961 (vl_api_cop_interface_enable_disable_t * mp)
6963 vl_api_cop_interface_enable_disable_reply_t *rmp;
6965 u32 sw_if_index = ntohl (mp->sw_if_index);
6968 VALIDATE_SW_IF_INDEX (mp);
6970 enable_disable = (int) mp->enable_disable;
6972 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6974 BAD_SW_IF_INDEX_LABEL;
6976 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6979 static void vl_api_cop_whitelist_enable_disable_t_handler
6980 (vl_api_cop_whitelist_enable_disable_t * mp)
6982 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6983 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6984 u32 sw_if_index = ntohl (mp->sw_if_index);
6987 VALIDATE_SW_IF_INDEX (mp);
6989 a->sw_if_index = sw_if_index;
6992 a->default_cop = mp->default_cop;
6993 a->fib_id = ntohl (mp->fib_id);
6995 rv = cop_whitelist_enable_disable (a);
6997 BAD_SW_IF_INDEX_LABEL;
6999 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
7003 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
7007 api_main_t *am = &api_main;
7008 vlib_main_t *vm = vlib_get_main ();
7010 vl_api_get_node_graph_reply_t *rmp;
7012 pthread_mutex_lock (&am->vlib_rp->mutex);
7013 oldheap = svm_push_data_heap (am->vlib_rp);
7016 * Keep the number of memcpy ops to a minimum (e.g. 1).
7018 vec_validate (vector, 16384);
7019 vec_reset_length (vector);
7022 vector = vlib_node_serialize (&vm->node_main, vector,
7023 (u32) ~ 0 /* all threads */ ,
7024 1 /* include nexts */ ,
7025 1 /* include stats */ );
7027 svm_pop_heap (oldheap);
7028 pthread_mutex_unlock (&am->vlib_rp->mutex);
7031 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
7033 rmp->reply_in_shmem = (uword) vector;
7038 static void vl_api_trace_profile_add_t_handler
7039 (vl_api_trace_profile_add_t * mp)
7042 vl_api_trace_profile_add_reply_t *rmp;
7043 clib_error_t *error;
7045 /* Ignoring the profile id as currently a single profile
7047 error = ip6_ioam_trace_profile_set (mp->trace_num_elt, mp->trace_type,
7048 ntohl (mp->node_id),
7049 ntohl (mp->trace_app_data),
7050 mp->pow_enable, mp->trace_tsp,
7054 clib_error_report (error);
7055 rv = clib_error_get_code (error);
7058 REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
7061 static void vl_api_trace_profile_apply_t_handler
7062 (vl_api_trace_profile_apply_t * mp)
7065 vl_api_trace_profile_apply_reply_t *rmp;
7067 if (mp->enable != 0)
7069 rv = ip6_ioam_set_destination ((ip6_address_t *) (&mp->dest_ipv6),
7070 ntohl (mp->prefix_length),
7072 mp->trace_op == IOAM_HBYH_ADD,
7073 mp->trace_op == IOAM_HBYH_POP,
7074 mp->trace_op == IOAM_HBYH_MOD);
7078 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
7080 REPLY_MACRO (VL_API_TRACE_PROFILE_APPLY_REPLY);
7083 static void vl_api_trace_profile_del_t_handler
7084 (vl_api_trace_profile_del_t * mp)
7087 vl_api_trace_profile_del_reply_t *rmp;
7088 clib_error_t *error;
7090 error = clear_ioam_rewrite_fn ();
7093 clib_error_report (error);
7094 rv = clib_error_get_code (error);
7097 REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
7101 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7103 vlib_main_t *vm = vlib_get_main ();
7104 vl_api_af_packet_create_reply_t *rmp;
7106 u8 *host_if_name = NULL;
7109 host_if_name = format (0, "%s", mp->host_if_name);
7110 vec_add1 (host_if_name, 0);
7112 rv = af_packet_create_if (vm, host_if_name,
7113 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7116 vec_free (host_if_name);
7119 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7121 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7127 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7129 vlib_main_t *vm = vlib_get_main ();
7130 vl_api_af_packet_delete_reply_t *rmp;
7132 u8 *host_if_name = NULL;
7134 host_if_name = format (0, "%s", mp->host_if_name);
7135 vec_add1 (host_if_name, 0);
7137 rv = af_packet_delete_if (vm, host_if_name);
7139 vec_free (host_if_name);
7141 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7145 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7147 vlib_main_t *vm = vlib_get_main ();
7148 vl_api_policer_add_del_reply_t *rmp;
7151 sse2_qos_pol_cfg_params_st cfg;
7152 clib_error_t *error;
7155 name = format (0, "%s", mp->name);
7157 memset (&cfg, 0, sizeof (cfg));
7159 cfg.rnd_type = mp->round_type;
7160 cfg.rate_type = mp->rate_type;
7161 cfg.rb.kbps.cir_kbps = mp->cir;
7162 cfg.rb.kbps.eir_kbps = mp->eir;
7163 cfg.rb.kbps.cb_bytes = mp->cb;
7164 cfg.rb.kbps.eb_bytes = mp->eb;
7165 cfg.conform_action.action_type = mp->conform_action_type;
7166 cfg.conform_action.dscp = mp->conform_dscp;
7167 cfg.exceed_action.action_type = mp->exceed_action_type;
7168 cfg.exceed_action.dscp = mp->exceed_dscp;
7169 cfg.violate_action.action_type = mp->violate_action_type;
7170 cfg.violate_action.dscp = mp->violate_dscp;
7171 cfg.color_aware = mp->color_aware;
7173 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7176 rv = VNET_API_ERROR_UNSPECIFIED;
7179 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7181 if (rv == 0 && mp->is_add)
7182 rmp->policer_index = ntohl(policer_index);
7184 rmp->policer_index = ~0;
7190 send_policer_details (u8 * name,
7191 sse2_qos_pol_cfg_params_st * config,
7192 policer_read_response_type_st * templ,
7193 unix_shared_memory_queue_t * q, u32 context)
7195 vl_api_policer_details_t *mp;
7197 mp = vl_msg_api_alloc (sizeof (*mp));
7198 memset (mp, 0, sizeof (*mp));
7199 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7200 mp->context = context;
7201 mp->cir = htonl (config->rb.kbps.cir_kbps);
7202 mp->eir = htonl (config->rb.kbps.eir_kbps);
7203 mp->cb = htonl (config->rb.kbps.cb_bytes);
7204 mp->eb = htonl (config->rb.kbps.eb_bytes);
7205 mp->rate_type = config->rate_type;
7206 mp->round_type = config->rnd_type;
7207 mp->type = config->rfc;
7208 mp->conform_action_type = config->conform_action.action_type;
7209 mp->conform_dscp = config->conform_action.dscp;
7210 mp->exceed_action_type = config->exceed_action.action_type;
7211 mp->exceed_dscp = config->exceed_action.dscp;
7212 mp->violate_action_type = config->violate_action.action_type;
7213 mp->violate_dscp = config->violate_action.dscp;
7214 mp->single_rate = templ->single_rate ? 1 : 0;
7215 mp->color_aware = templ->color_aware ? 1 : 0;
7216 mp->scale = htonl (templ->scale);
7217 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7218 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7219 mp->current_limit = htonl (templ->current_limit);
7220 mp->current_bucket = htonl (templ->current_bucket);
7221 mp->extended_limit = htonl (templ->extended_limit);
7222 mp->extended_bucket = htonl (templ->extended_bucket);
7223 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7225 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7227 vl_msg_api_send_shmem (q, (u8 *) & mp);
7231 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7233 unix_shared_memory_queue_t *q;
7234 vnet_policer_main_t *pm = &vnet_policer_main;
7240 sse2_qos_pol_cfg_params_st *config;
7241 policer_read_response_type_st *templ;
7243 q = vl_api_client_index_to_input_queue (mp->client_index);
7247 if (mp->match_name_valid)
7249 match_name = format (0, "%s%c", mp->match_name, 0);
7252 if (mp->match_name_valid)
7254 p = hash_get_mem (pm->policer_config_by_name, match_name);
7258 config = pool_elt_at_index (pm->configs, pool_index);
7259 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7260 send_policer_details (match_name, config, templ, q, mp->context);
7266 hash_foreach_pair (hp, pm->policer_config_by_name,
7268 name = (u8 *) hp->key;
7269 pool_index = hp->value[0];
7270 config = pool_elt_at_index (pm->configs, pool_index);
7271 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7272 send_policer_details(name, config, templ, q, mp->context);
7279 vl_api_policer_classify_set_interface_t_handler
7280 (vl_api_policer_classify_set_interface_t * mp)
7282 vlib_main_t *vm = vlib_get_main ();
7283 vl_api_policer_classify_set_interface_reply_t *rmp;
7285 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7287 ip4_table_index = ntohl (mp->ip4_table_index);
7288 ip6_table_index = ntohl (mp->ip6_table_index);
7289 l2_table_index = ntohl (mp->l2_table_index);
7290 sw_if_index = ntohl (mp->sw_if_index);
7292 VALIDATE_SW_IF_INDEX (mp);
7294 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7295 ip6_table_index, l2_table_index,
7298 BAD_SW_IF_INDEX_LABEL;
7300 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7304 send_policer_classify_details (u32 sw_if_index,
7306 unix_shared_memory_queue_t * q, u32 context)
7308 vl_api_policer_classify_details_t *mp;
7310 mp = vl_msg_api_alloc (sizeof (*mp));
7311 memset (mp, 0, sizeof (*mp));
7312 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7313 mp->context = context;
7314 mp->sw_if_index = htonl (sw_if_index);
7315 mp->table_index = htonl (table_index);
7317 vl_msg_api_send_shmem (q, (u8 *) & mp);
7321 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7323 unix_shared_memory_queue_t *q;
7324 policer_classify_main_t *pcm = &policer_classify_main;
7328 q = vl_api_client_index_to_input_queue (mp->client_index);
7332 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7334 if (vec_len (vec_tbl))
7336 for (i = 0; i < vec_len (vec_tbl); i++)
7338 if (vec_elt (vec_tbl, i) == ~0)
7341 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7348 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7350 vlib_main_t *vm = vlib_get_main ();
7351 vl_api_netmap_create_reply_t *rmp;
7355 if_name = format (0, "%s", mp->netmap_if_name);
7356 vec_add1 (if_name, 0);
7359 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7360 mp->is_pipe, mp->is_master, 0);
7364 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7368 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7370 vlib_main_t *vm = vlib_get_main ();
7371 vl_api_netmap_delete_reply_t *rmp;
7375 if_name = format (0, "%s", mp->netmap_if_name);
7376 vec_add1 (if_name, 0);
7378 rv = netmap_delete_if (vm, if_name);
7382 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7386 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7389 clib_warning ("BUG");
7393 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7394 unix_shared_memory_queue_t * q,
7395 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7397 vl_api_mpls_gre_tunnel_details_t *mp;
7398 mpls_main_t *mm = &mpls_main;
7403 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7404 nlabels = vec_len (e->labels);
7406 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7407 memset (mp, 0, sizeof (*mp));
7408 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7409 mp->context = context;
7411 mp->tunnel_index = htonl (index);
7412 mp->tunnel_src = gt->tunnel_src.as_u32;
7413 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7414 mp->intfc_address = gt->intfc_address.as_u32;
7415 mp->mask_width = htonl (gt->mask_width);
7416 mp->inner_fib_index = htonl (gt->inner_fib_index);
7417 mp->outer_fib_index = htonl (gt->outer_fib_index);
7418 mp->encap_index = htonl (gt->encap_index);
7419 mp->hw_if_index = htonl (gt->hw_if_index);
7420 mp->l2_only = htonl (gt->l2_only);
7421 mp->nlabels = htonl (nlabels);
7423 for (i = 0; i < nlabels; i++)
7426 htonl (vnet_mpls_uc_get_label
7427 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7430 vl_msg_api_send_shmem (q, (u8 *) & mp);
7434 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7436 vpe_api_main_t *am = &vpe_api_main;
7437 unix_shared_memory_queue_t *q;
7438 mpls_main_t *mm = &mpls_main;
7439 mpls_gre_tunnel_t *gt;
7440 u32 index = ntohl (mp->tunnel_index);
7442 q = vl_api_client_index_to_input_queue (mp->client_index);
7448 if (!pool_is_free_index (mm->gre_tunnels, index))
7450 gt = pool_elt_at_index (mm->gre_tunnels, index);
7451 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7458 pool_foreach (gt, mm->gre_tunnels,
7460 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7468 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7471 clib_warning ("BUG");
7475 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7476 unix_shared_memory_queue_t * q,
7477 mpls_eth_tunnel_t * et, u32 index, u32 context)
7479 mpls_main_t *mm = &mpls_main;
7483 vl_api_mpls_eth_tunnel_details_t *mp;
7485 e = pool_elt_at_index (mm->encaps, et->encap_index);
7486 nlabels = vec_len (e->labels);
7488 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7489 memset (mp, 0, sizeof (*mp));
7490 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7491 mp->context = context;
7493 mp->tunnel_index = htonl (index);
7494 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7495 mp->intfc_address = et->intfc_address.as_u32;
7496 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7497 mp->inner_fib_index = htonl (et->inner_fib_index);
7498 mp->mask_width = htonl (et->mask_width);
7499 mp->encap_index = htonl (et->encap_index);
7500 mp->hw_if_index = htonl (et->hw_if_index);
7501 mp->l2_only = htonl (et->l2_only);
7502 mp->nlabels = htonl (nlabels);
7504 for (i = 0; i < nlabels; i++)
7507 htonl (vnet_mpls_uc_get_label
7508 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7511 vl_msg_api_send_shmem (q, (u8 *) & mp);
7515 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7517 vpe_api_main_t *am = &vpe_api_main;
7518 unix_shared_memory_queue_t *q;
7519 mpls_main_t *mm = &mpls_main;
7520 mpls_eth_tunnel_t *et;
7521 u32 index = ntohl (mp->tunnel_index);
7523 q = vl_api_client_index_to_input_queue (mp->client_index);
7529 if (!pool_is_free_index (mm->eth_tunnels, index))
7531 et = pool_elt_at_index (mm->eth_tunnels, index);
7532 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7539 pool_foreach (et, mm->eth_tunnels,
7541 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7549 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7551 clib_warning ("BUG");
7555 send_mpls_fib_encap_details (vpe_api_main_t * am,
7556 unix_shared_memory_queue_t * q,
7557 show_mpls_fib_t * s, u32 context)
7559 vl_api_mpls_fib_encap_details_t *mp;
7560 mpls_main_t *mm = &mpls_main;
7565 e = pool_elt_at_index (mm->encaps, s->entry_index);
7566 nlabels = vec_len (e->labels);
7568 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7569 memset (mp, 0, sizeof (*mp));
7570 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7571 mp->context = context;
7573 mp->fib_index = htonl (s->fib_index);
7574 mp->entry_index = htonl (s->entry_index);
7576 mp->s_bit = htonl (s->s_bit);
7578 mp->nlabels = htonl (nlabels);
7580 for (i = 0; i < nlabels; i++)
7583 htonl (vnet_mpls_uc_get_label
7584 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7587 vl_msg_api_send_shmem (q, (u8 *) & mp);
7591 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7593 vpe_api_main_t *am = &vpe_api_main;
7594 unix_shared_memory_queue_t *q;
7595 vlib_main_t *vm = &vlib_global_main;
7598 show_mpls_fib_t *records = 0;
7600 mpls_main_t *mm = &mpls_main;
7601 ip4_main_t *im = &ip4_main;
7604 q = vl_api_client_index_to_input_queue (mp->client_index);
7609 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7611 vec_add2 (records, s, 1);
7612 s->fib_index = (u32)(key>>32);
7613 s->dest = (u32)(key & 0xFFFFFFFF);
7614 s->entry_index = (u32) value;
7618 if (0 == vec_len (records))
7620 vlib_cli_output (vm, "MPLS encap table empty");
7624 /* sort output by dst address within fib */
7625 vec_sort_with_function (records, mpls_dest_cmp);
7626 vec_sort_with_function (records, mpls_fib_index_cmp);
7627 vlib_cli_output (vm, "MPLS encap table");
7628 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7629 vec_foreach (s, records)
7631 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7632 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7633 format_ip4_address, &s->dest, format_mpls_encap_index,
7634 mm, s->entry_index);
7635 send_mpls_fib_encap_details (am, q, s, mp->context);
7643 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7645 clib_warning ("BUG");
7649 send_mpls_fib_decap_details (vpe_api_main_t * am,
7650 unix_shared_memory_queue_t * q,
7651 show_mpls_fib_t * s,
7653 u32 tx_table_id, char *swif_tag, u32 context)
7655 vl_api_mpls_fib_decap_details_t *mp;
7657 mp = vl_msg_api_alloc (sizeof (*mp));
7658 memset (mp, 0, sizeof (*mp));
7659 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7660 mp->context = context;
7662 mp->fib_index = htonl (s->fib_index);
7663 mp->entry_index = htonl (s->entry_index);
7665 mp->s_bit = htonl (s->s_bit);
7666 mp->label = htonl (s->label);
7667 mp->rx_table_id = htonl (rx_table_id);
7668 mp->tx_table_id = htonl (tx_table_id);
7669 strncpy ((char *) mp->swif_tag,
7670 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7672 vl_msg_api_send_shmem (q, (u8 *) & mp);
7676 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7678 vpe_api_main_t *am = &vpe_api_main;
7679 unix_shared_memory_queue_t *q;
7680 vlib_main_t *vm = &vlib_global_main;
7683 show_mpls_fib_t *records = 0;
7685 mpls_main_t *mm = &mpls_main;
7686 ip4_main_t *im = &ip4_main;
7692 q = vl_api_client_index_to_input_queue (mp->client_index);
7697 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7699 vec_add2 (records, s, 1);
7700 s->fib_index = (u32)(key>>32);
7701 s->entry_index = (u32) value;
7702 s->label = ((u32) key)>>12;
7703 s->s_bit = (key & (1<<8)) != 0;
7707 if (!vec_len (records))
7709 vlib_cli_output (vm, "MPLS decap table empty");
7713 vec_sort_with_function (records, mpls_label_cmp);
7714 vlib_cli_output (vm, "MPLS decap table");
7715 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7717 vec_foreach (s, records)
7720 d = pool_elt_at_index (mm->decaps, s->entry_index);
7721 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT)
7723 tx_fib = vec_elt_at_index (im->fibs, d->tx_fib_index);
7724 tx_table_id = tx_fib->table_id;
7729 tx_table_id = d->tx_fib_index;
7732 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7734 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7735 tx_table_id, swif_tag, s->label, s->s_bit);
7737 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7738 tx_table_id, swif_tag, mp->context);
7746 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7748 unix_shared_memory_queue_t *q;
7750 q = vl_api_client_index_to_input_queue (mp->client_index);
7754 vnet_classify_main_t *cm = &vnet_classify_main;
7755 vnet_classify_table_t *t;
7760 pool_foreach (t, cm->tables,
7762 vec_add1 (table_ids, ntohl(t - cm->tables));
7765 count = vec_len (table_ids);
7767 vl_api_classify_table_ids_reply_t *rmp;
7768 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7769 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7770 rmp->context = mp->context;
7771 rmp->count = ntohl (count);
7772 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7775 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7777 vec_free (table_ids);
7781 vl_api_classify_table_by_interface_t_handler
7782 (vl_api_classify_table_by_interface_t * mp)
7784 vl_api_classify_table_by_interface_reply_t *rmp;
7787 u32 sw_if_index = ntohl (mp->sw_if_index);
7790 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7793 VALIDATE_SW_IF_INDEX (mp);
7795 input_acl_main_t *am = &input_acl_main;
7800 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7802 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7803 if (vec_len (vec_tbl))
7805 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7807 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7811 acl[type] = vec_elt (vec_tbl, if_idx);
7816 BAD_SW_IF_INDEX_LABEL;
7819 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7821 rmp->sw_if_index = ntohl(sw_if_index);
7822 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7823 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7824 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7831 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7833 unix_shared_memory_queue_t *q;
7835 q = vl_api_client_index_to_input_queue (mp->client_index);
7839 vl_api_classify_table_info_reply_t *rmp = 0;
7841 vnet_classify_main_t *cm = &vnet_classify_main;
7842 u32 table_id = ntohl (mp->table_id);
7843 vnet_classify_table_t *t;
7846 pool_foreach (t, cm->tables,
7848 if (table_id == t - cm->tables)
7850 rmp = vl_msg_api_alloc_as_if_client
7851 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7852 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7853 rmp->context = mp->context;
7854 rmp->table_id = ntohl(table_id);
7855 rmp->nbuckets = ntohl(t->nbuckets);
7856 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7857 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7858 rmp->active_sessions = ntohl(t->active_elements);
7859 rmp->next_table_index = ntohl(t->next_table_index);
7860 rmp->miss_next_index = ntohl(t->miss_next_index);
7861 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7862 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7871 rmp = vl_msg_api_alloc (sizeof (*rmp));
7872 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7873 rmp->context = mp->context;
7874 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7877 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7881 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7884 clib_warning ("BUG");
7888 send_classify_session_details (unix_shared_memory_queue_t * q,
7891 vnet_classify_entry_t * e, u32 context)
7893 vl_api_classify_session_details_t *rmp;
7895 rmp = vl_msg_api_alloc (sizeof (*rmp));
7896 memset (rmp, 0, sizeof (*rmp));
7897 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7898 rmp->context = context;
7899 rmp->table_id = ntohl (table_id);
7900 rmp->hit_next_index = ntohl (e->next_index);
7901 rmp->advance = ntohl (e->advance);
7902 rmp->opaque_index = ntohl (e->opaque_index);
7903 rmp->match_length = ntohl (match_length);
7904 clib_memcpy (rmp->match, e->key, match_length);
7906 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7910 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7912 vnet_classify_main_t *cm = &vnet_classify_main;
7913 unix_shared_memory_queue_t *q;
7915 u32 table_id = ntohl (mp->table_id);
7916 vnet_classify_table_t *t;
7918 q = vl_api_client_index_to_input_queue (mp->client_index);
7921 pool_foreach (t, cm->tables,
7923 if (table_id == t - cm->tables)
7925 vnet_classify_bucket_t * b;
7926 vnet_classify_entry_t * v, * save_v;
7929 for (i = 0; i < t->nbuckets; i++)
7931 b = &t->buckets [i];
7935 save_v = vnet_classify_get_entry (t, b->offset);
7936 for (j = 0; j < (1<<b->log2_pages); j++)
7938 for (k = 0; k < t->entries_per_page; k++)
7940 v = vnet_classify_entry_at_index
7941 (t, save_v, j*t->entries_per_page + k);
7942 if (vnet_classify_entry_is_free (v))
7945 send_classify_session_details
7946 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7958 vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t * mp)
7960 vlib_main_t *vm = vlib_get_main ();
7961 flow_report_main_t *frm = &flow_report_main;
7962 vl_api_ipfix_enable_reply_t *rmp;
7963 ip4_address_t collector, src;
7964 u16 collector_port = UDP_DST_PORT_ipfix;
7966 u32 template_interval;
7971 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7972 collector_port = ntohs (mp->collector_port);
7973 if (collector_port == (u16) ~ 0)
7974 collector_port = UDP_DST_PORT_ipfix;
7975 memcpy (src.data, mp->src_address, sizeof (src.data));
7976 fib_id = ntohl (mp->vrf_id);
7978 ip4_main_t *im = &ip4_main;
7979 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7982 rv = VNET_API_ERROR_NO_SUCH_FIB;
7987 path_mtu = ntohl (mp->path_mtu);
7989 path_mtu = 512; // RFC 7011 section 10.3.3.
7990 template_interval = ntohl (mp->template_interval);
7991 if (template_interval == ~0)
7992 template_interval = 20;
7994 if (collector.as_u32 == 0)
7996 rv = VNET_API_ERROR_INVALID_VALUE;
8000 if (src.as_u32 == 0)
8002 rv = VNET_API_ERROR_INVALID_VALUE;
8006 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
8008 rv = VNET_API_ERROR_INVALID_VALUE;
8014 rv = VNET_API_ERROR_INVALID_VALUE;
8018 /* Reset report streams if we are reconfiguring IP addresses */
8019 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
8020 frm->src_address.as_u32 != src.as_u32 ||
8021 frm->collector_port != collector_port)
8022 vnet_flow_reports_reset (frm);
8024 frm->ipfix_collector.as_u32 = collector.as_u32;
8025 frm->collector_port = collector_port;
8026 frm->src_address.as_u32 = src.as_u32;
8027 frm->fib_index = fib_index;
8028 frm->path_mtu = path_mtu;
8029 frm->template_interval = template_interval;
8031 /* Turn on the flow reporting process */
8032 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
8035 REPLY_MACRO (VL_API_IPFIX_ENABLE_REPLY);
8039 vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t * mp)
8041 flow_report_main_t *frm = &flow_report_main;
8042 unix_shared_memory_queue_t *q;
8043 vl_api_ipfix_details_t *rmp;
8045 q = vl_api_client_index_to_input_queue (mp->client_index);
8049 rmp = vl_msg_api_alloc (sizeof (*rmp));
8050 memset (rmp, 0, sizeof (*rmp));
8051 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_DETAILS);
8052 rmp->context = mp->context;
8053 memcpy (rmp->collector_address, frm->ipfix_collector.data,
8054 sizeof (frm->ipfix_collector.data));
8055 rmp->collector_port = htons (frm->collector_port);
8056 memcpy (rmp->src_address, frm->src_address.data,
8057 sizeof (frm->src_address.data));
8058 rmp->fib_index = htonl (frm->fib_index);
8059 rmp->path_mtu = htonl (frm->path_mtu);
8060 rmp->template_interval = htonl (frm->template_interval);
8062 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8066 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8068 vl_api_pg_create_interface_reply_t *rmp;
8071 pg_main_t *pg = &pg_main;
8072 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8075 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8077 rmp->sw_if_index = ntohl(sw_if_index);
8083 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8085 vl_api_pg_capture_reply_t *rmp;
8088 vnet_main_t *vnm = vnet_get_main ();
8089 vnet_interface_main_t *im = &vnm->interface_main;
8090 vnet_hw_interface_t *hi = 0;
8092 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8093 u32 hw_if_index = ~0;
8094 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8097 vec_free (intf_name);
8099 if (hw_if_index != ~0)
8101 pg_capture_args_t _a, *a = &_a;
8103 u32 len = ntohl (mp->pcap_name_length);
8104 u8 *pcap_file_name = vec_new (u8, len);
8105 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8107 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8108 a->hw_if_index = hw_if_index;
8109 a->dev_instance = hi->dev_instance;
8110 a->is_enabled = mp->is_enabled;
8111 a->pcap_file_name = pcap_file_name;
8112 a->count = ntohl (mp->count);
8114 clib_error_t *e = pg_capture (a);
8117 clib_error_report (e);
8118 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8121 vec_free (pcap_file_name);
8123 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8127 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8129 vl_api_pg_enable_disable_reply_t *rmp;
8132 pg_main_t *pg = &pg_main;
8133 u32 stream_index = ~0;
8135 int is_enable = mp->is_enabled != 0;
8136 u32 len = ntohl (mp->stream_name_length) - 1;
8140 u8 *stream_name = vec_new (u8, len);
8141 clib_memcpy (stream_name, mp->stream_name, len);
8142 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8145 vec_free (stream_name);
8148 pg_enable_disable (stream_index, is_enable);
8150 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8154 vl_api_ip_source_and_port_range_check_add_del_t_handler
8155 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8157 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8160 u8 is_ipv6 = mp->is_ipv6;
8161 u8 is_add = mp->is_add;
8162 u8 mask_length = mp->mask_length;
8163 ip4_address_t ip4_addr;
8164 ip6_address_t ip6_addr;
8166 u16 *high_ports = 0;
8168 u16 tmp_low, tmp_high;
8172 // Validate port range
8173 num_ranges = mp->number_of_ranges;
8174 if (num_ranges > 32)
8175 { // This is size of array in VPE.API
8176 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8180 vec_reset_length (low_ports);
8181 vec_reset_length (high_ports);
8183 for (i = 0; i < num_ranges; i++)
8185 tmp_low = mp->low_ports[i];
8186 tmp_high = mp->high_ports[i];
8187 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8188 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8189 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8191 rv = VNET_API_ERROR_INVALID_VALUE;
8194 vec_add1 (low_ports, tmp_low);
8195 vec_add1 (high_ports, tmp_high + 1);
8198 // Validate mask_length
8199 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8201 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8205 vrf_id = ntohl (mp->vrf_id);
8209 rv = VNET_API_ERROR_INVALID_VALUE;
8216 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8217 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8221 high_ports, is_add);
8225 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8226 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8230 high_ports, is_add);
8234 vec_free (low_ports);
8235 vec_free (high_ports);
8236 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8240 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8241 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8243 vlib_main_t *vm = vlib_get_main ();
8244 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8245 ip4_main_t *im = &ip4_main;
8248 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8249 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8253 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8254 ntohl (mp->tcp_out_vrf_id);
8255 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8256 ntohl (mp->udp_out_vrf_id);
8257 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8258 ntohl (mp->tcp_in_vrf_id);
8259 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8260 ntohl (mp->udp_in_vrf_id);
8263 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8265 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8267 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8271 rv = VNET_API_ERROR_INVALID_VALUE;
8275 fib_index[i] = p[0];
8280 sw_if_index = ntohl (mp->sw_if_index);
8282 VALIDATE_SW_IF_INDEX (mp);
8285 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8288 BAD_SW_IF_INDEX_LABEL;
8291 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8295 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8298 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8300 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8301 u32 sw_if_index = ~0;
8303 /* Check src & dst are different */
8304 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8306 rv = VNET_API_ERROR_SAME_SRC_DST;
8310 memset (a, 0, sizeof (*a));
8312 /* ip addresses sent in network byte order */
8313 clib_memcpy (&(a->src), mp->src_address, 4);
8314 clib_memcpy (&(a->dst), mp->dst_address, 4);
8315 a->is_add = mp->is_add;
8316 a->lsa = ntohl (mp->local_sa_id);
8317 a->rsa = ntohl (mp->remote_sa_id);
8319 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8323 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8325 rmp->sw_if_index = ntohl (sw_if_index);
8330 static void send_ipsec_gre_tunnel_details
8331 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8333 vl_api_ipsec_gre_tunnel_details_t *rmp;
8335 rmp = vl_msg_api_alloc (sizeof (*rmp));
8336 memset (rmp, 0, sizeof (*rmp));
8337 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8338 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8339 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8340 rmp->sw_if_index = htonl (t->sw_if_index);
8341 rmp->local_sa_id = htonl (t->local_sa_id);
8342 rmp->remote_sa_id = htonl (t->remote_sa_id);
8343 rmp->context = context;
8345 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8348 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8349 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8351 unix_shared_memory_queue_t *q;
8352 ipsec_gre_main_t *igm = &ipsec_gre_main;
8353 ipsec_gre_tunnel_t *t;
8356 q = vl_api_client_index_to_input_queue (mp->client_index);
8362 sw_if_index = ntohl (mp->sw_if_index);
8364 if (~0 == sw_if_index)
8367 pool_foreach (t, igm->tunnels,
8369 send_ipsec_gre_tunnel_details(t, q, mp->context);
8375 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8376 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8380 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8381 send_ipsec_gre_tunnel_details (t, q, mp->context);
8386 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8388 vl_api_delete_subif_reply_t *rmp;
8391 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8393 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8396 #define BOUNCE_HANDLER(nn) \
8397 static void vl_api_##nn##_t_handler ( \
8398 vl_api_##nn##_t *mp) \
8400 vpe_client_registration_t *reg; \
8401 vpe_api_main_t * vam = &vpe_api_main; \
8402 unix_shared_memory_queue_t * q; \
8404 /* One registration only... */ \
8405 pool_foreach(reg, vam->nn##_registrations, \
8407 q = vl_api_client_index_to_input_queue (reg->client_index); \
8410 * If the queue is stuffed, turf the msg and complain \
8411 * It's unlikely that the intended recipient is \
8412 * alive; avoid deadlock at all costs. \
8414 if (q->cursize == q->maxsize) { \
8415 clib_warning ("ERROR: receiver queue full, drop msg"); \
8416 vl_msg_api_free (mp); \
8419 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8423 vl_msg_api_free (mp); \
8428 * Add vpe's API message handlers to the table.
8429 * vlib has alread mapped shared memory and
8430 * added the client registration handlers.
8431 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8434 static clib_error_t *
8435 vpe_api_hookup (vlib_main_t * vm)
8437 api_main_t *am = &api_main;
8440 vl_msg_api_set_handlers(VL_API_##N, #n, \
8441 vl_api_##n##_t_handler, \
8443 vl_api_##n##_t_endian, \
8444 vl_api_##n##_t_print, \
8445 sizeof(vl_api_##n##_t), 1);
8446 foreach_vpe_api_msg;
8450 * Manually register the sr tunnel add del msg, so we trace
8451 * enough bytes to capture a typical segment list
8453 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8454 "sr_tunnel_add_del",
8455 vl_api_sr_tunnel_add_del_t_handler,
8457 vl_api_sr_tunnel_add_del_t_endian,
8458 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8462 * Manually register the sr policy add del msg, so we trace
8463 * enough bytes to capture a typical tunnel name list
8465 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8466 "sr_policy_add_del",
8467 vl_api_sr_policy_add_del_t_handler,
8469 vl_api_sr_policy_add_del_t_endian,
8470 vl_api_sr_policy_add_del_t_print, 256, 1);
8473 * Trace space for 8 MPLS encap labels, classifier mask+match
8475 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8476 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8477 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8478 += 5 * sizeof (u32x4);
8479 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8482 * Thread-safe API messages
8484 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8485 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8490 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8492 static clib_error_t *
8493 vpe_api_init (vlib_main_t * vm)
8495 vpe_api_main_t *am = &vpe_api_main;
8498 am->vnet_main = vnet_get_main ();
8499 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8500 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8501 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8502 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8503 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8504 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8507 vl_set_memory_region_name ("/vpe-api");
8508 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8513 VLIB_INIT_FUNCTION (vpe_api_init);
8516 static clib_error_t *
8517 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8520 u64 baseva, size, pvt_heap_size;
8522 const int max_buf_size = 4096;
8524 struct passwd _pw, *pw;
8525 struct group _grp, *grp;
8527 buf = vec_new (char, 128);
8528 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8530 if (unformat (input, "prefix %s", &chroot_path))
8532 vec_add1 (chroot_path, 0);
8533 vl_set_memory_root_path ((char *) chroot_path);
8535 else if (unformat (input, "uid %d", &uid))
8536 vl_set_memory_uid (uid);
8537 else if (unformat (input, "gid %d", &gid))
8538 vl_set_memory_gid (gid);
8539 else if (unformat (input, "baseva %llx", &baseva))
8540 vl_set_global_memory_baseva (baseva);
8541 else if (unformat (input, "global-size %lldM", &size))
8542 vl_set_global_memory_size (size * (1ULL << 20));
8543 else if (unformat (input, "global-size %lldG", &size))
8544 vl_set_global_memory_size (size * (1ULL << 30));
8545 else if (unformat (input, "global-size %lld", &size))
8546 vl_set_global_memory_size (size);
8547 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8548 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8549 else if (unformat (input, "global-pvt-heap-size size %lld",
8551 vl_set_global_pvt_heap_size (pvt_heap_size);
8552 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8553 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8554 else if (unformat (input, "api-pvt-heap-size size %lld",
8556 vl_set_api_pvt_heap_size (pvt_heap_size);
8557 else if (unformat (input, "api-size %lldM", &size))
8558 vl_set_api_memory_size (size * (1ULL << 20));
8559 else if (unformat (input, "api-size %lldG", &size))
8560 vl_set_api_memory_size (size * (1ULL << 30));
8561 else if (unformat (input, "api-size %lld", &size))
8562 vl_set_api_memory_size (size);
8563 else if (unformat (input, "uid %s", &s))
8565 /* lookup the username */
8568 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8569 && (vec_len (buf) <= max_buf_size))
8571 vec_resize (buf, vec_len (buf) * 2);
8575 e = clib_error_return_code (0, rv,
8576 CLIB_ERROR_ERRNO_VALID |
8578 "cannot fetch username %s", s);
8586 clib_error_return_fatal (0, "username %s does not exist", s);
8592 vl_set_memory_uid (pw->pw_uid);
8594 else if (unformat (input, "gid %s", &s))
8596 /* lookup the group name */
8599 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8600 && (vec_len (buf) <= max_buf_size))
8602 vec_resize (buf, vec_len (buf) * 2);
8606 e = clib_error_return_code (0, rv,
8607 CLIB_ERROR_ERRNO_VALID |
8609 "cannot fetch group %s", s);
8616 e = clib_error_return_fatal (0, "group %s does not exist", s);
8623 vl_set_memory_gid (grp->gr_gid);
8626 return clib_error_return (0, "unknown input `%U'",
8627 format_unformat_error, input);
8632 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8635 get_unformat_vnet_sw_interface (void)
8637 return (void *) &unformat_vnet_sw_interface;
8640 #undef vl_api_version
8641 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8642 #include <vpp-api/vpe.api.h>
8643 #undef vl_api_version
8646 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8648 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8650 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8651 clib_host_to_net_u32 (mp->api_versions[0]),
8659 format_arp_event (u8 * s, va_list * args)
8661 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8663 s = format (s, "pid %d: ", event->pid);
8665 s = format (s, "bd mac/ip4 binding events");
8667 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8672 format_nd_event (u8 * s, va_list * args)
8674 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8676 s = format (s, "pid %d: ", event->pid);
8678 s = format (s, "bd mac/ip6 binding events");
8680 s = format (s, "resolution for %U", format_ip6_address, event->address);
8684 static clib_error_t *
8685 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8686 unformat_input_t * input, vlib_cli_command_t * cmd)
8688 vpe_api_main_t *am = &vpe_api_main;
8689 vl_api_ip4_arp_event_t *arp_event;
8690 vl_api_ip6_nd_event_t *nd_event;
8692 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8694 vlib_cli_output (vm, "No active arp or nd event registrations");
8699 pool_foreach (arp_event, am->arp_events,
8701 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8704 pool_foreach (nd_event, am->nd_events,
8706 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8714 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8715 .path = "show arp-nd-event registrations",
8716 .function = show_ip_arp_nd_events_fn,
8717 .short_help = "Show ip4 arp and ip6 nd event registrations",
8722 * fd.io coding-style-patch-verification: ON
8725 * eval: (c-set-style "gnu")