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>
87 #include <vnet/flow/flow_report_classify.h>
90 #undef __included_bihash_template_h__
91 #include <vnet/l2/l2_fib.h>
94 #include <vnet/ipsec/ipsec.h>
95 #include <vnet/ipsec/ikev2.h>
97 #include <vnet/devices/virtio/vhost-user.h>
99 #include <stats/stats.h>
102 #include <vnet/ethernet/ethernet.h>
103 #include <vnet/ethernet/arp_packet.h>
104 #include <vnet/interface.h>
106 #include <vnet/l2/l2_fib.h>
107 #include <vnet/l2/l2_bd.h>
108 #include <vpp-api/vpe_msg_enum.h>
110 #define f64_endian(a)
111 #define f64_print(a,b)
113 #define vl_typedefs /* define message structures */
114 #include <vpp-api/vpe_all_api_h.h>
117 #define vl_endianfun /* define message structures */
118 #include <vpp-api/vpe_all_api_h.h>
121 /* instantiate all the print functions we know about */
122 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
124 #include <vpp-api/vpe_all_api_h.h>
127 #define REPLY_MACRO(t) \
129 unix_shared_memory_queue_t * q; \
130 rv = vl_msg_api_pd_handler (mp, rv); \
131 q = vl_api_client_index_to_input_queue (mp->client_index); \
135 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
136 rmp->_vl_msg_id = ntohs((t)); \
137 rmp->context = mp->context; \
138 rmp->retval = ntohl(rv); \
140 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
143 #define REPLY_MACRO2(t, body) \
145 unix_shared_memory_queue_t * q; \
146 rv = vl_msg_api_pd_handler (mp, rv); \
147 q = vl_api_client_index_to_input_queue (mp->client_index); \
151 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
152 rmp->_vl_msg_id = ntohs((t)); \
153 rmp->context = mp->context; \
154 rmp->retval = ntohl(rv); \
155 do {body;} while (0); \
156 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
159 #define REPLY_MACRO3(t, n, body) \
161 unix_shared_memory_queue_t * q; \
162 rv = vl_msg_api_pd_handler (mp, rv); \
163 q = vl_api_client_index_to_input_queue (mp->client_index); \
167 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
168 rmp->_vl_msg_id = ntohs((t)); \
169 rmp->context = mp->context; \
170 rmp->retval = ntohl(rv); \
171 do {body;} while (0); \
172 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
175 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
177 #define VALIDATE_SW_IF_INDEX(mp) \
178 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
179 vnet_main_t *__vnm = vnet_get_main(); \
180 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
182 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
183 goto bad_sw_if_index; \
187 #define BAD_SW_IF_INDEX_LABEL \
193 #define VALIDATE_RX_SW_IF_INDEX(mp) \
194 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
195 vnet_main_t *__vnm = vnet_get_main(); \
196 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
197 __rx_sw_if_index)) { \
198 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
199 goto bad_rx_sw_if_index; \
203 #define BAD_RX_SW_IF_INDEX_LABEL \
205 bad_rx_sw_if_index: \
209 #define VALIDATE_TX_SW_IF_INDEX(mp) \
210 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
211 vnet_main_t *__vnm = vnet_get_main(); \
212 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
213 __tx_sw_if_index)) { \
214 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
215 goto bad_tx_sw_if_index; \
219 #define BAD_TX_SW_IF_INDEX_LABEL \
221 bad_tx_sw_if_index: \
227 #define VALIDATE_SW_IF_INDEX(mp)
228 #define BAD_SW_IF_INDEX_LABEL
229 #define VALIDATE_RX_SW_IF_INDEX(mp)
230 #define BAD_RX_SW_IF_INDEX_LABEL
231 #define VALIDATE_TX_SW_IF_INDEX(mp)
232 #define BAD_TX_SW_IF_INDEX_LABEL
234 #endif /* CLIB_DEBUG > 0 */
236 #define foreach_vpe_api_msg \
237 _(WANT_INTERFACE_EVENTS, want_interface_events) \
238 _(WANT_OAM_EVENTS, want_oam_events) \
239 _(OAM_ADD_DEL, oam_add_del) \
240 _(SW_INTERFACE_DUMP, sw_interface_dump) \
241 _(SW_INTERFACE_DETAILS, sw_interface_details) \
242 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
243 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
244 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
245 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
246 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
247 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
248 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
249 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
250 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
251 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
252 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
253 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
254 _(L2FIB_ADD_DEL, l2fib_add_del) \
255 _(L2_FLAGS, l2_flags) \
256 _(BRIDGE_FLAGS, bridge_flags) \
257 _(TAP_CONNECT, tap_connect) \
258 _(TAP_MODIFY, tap_modify) \
259 _(TAP_DELETE, tap_delete) \
260 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
261 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
262 _(CREATE_SUBIF, create_subif) \
263 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
264 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
265 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
266 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
267 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
268 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
269 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
270 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
271 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
272 _(RESET_FIB, reset_fib) \
273 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
274 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
275 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
276 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
277 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
278 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
279 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
280 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
281 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
282 sw_interface_ip6_set_link_local_address) \
283 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
284 _(CREATE_LOOPBACK, create_loopback) \
285 _(CONTROL_PING, control_ping) \
286 _(NOPRINT_CONTROL_PING, noprint_control_ping) \
287 _(CLI_REQUEST, cli_request) \
288 _(CLI_INBAND, cli_inband) \
289 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
290 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
291 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
292 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
293 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
294 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
295 _(GET_NODE_INDEX, get_node_index) \
296 _(ADD_NODE_NEXT, add_node_next) \
297 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
298 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
299 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
300 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
301 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
302 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
303 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
304 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
305 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
306 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
307 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
308 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
309 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
310 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
311 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
312 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
313 _(IP_ADDRESS_DUMP, ip_address_dump) \
314 _(IP_DUMP, ip_dump) \
315 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
316 _(SHOW_VERSION, show_version) \
317 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
318 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
319 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
320 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
321 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
322 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
323 _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \
324 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
325 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
326 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
327 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
328 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
329 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
330 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
331 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
332 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
333 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
334 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
335 _(DELETE_LOOPBACK, delete_loopback) \
336 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
337 _(MAP_ADD_DOMAIN, map_add_domain) \
338 _(MAP_DEL_DOMAIN, map_del_domain) \
339 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
340 _(MAP_DOMAIN_DUMP, map_domain_dump) \
341 _(MAP_RULE_DUMP, map_rule_dump) \
342 _(MAP_SUMMARY_STATS, map_summary_stats) \
343 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
344 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
345 _(GET_NODE_GRAPH, get_node_graph) \
346 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
347 _(IOAM_ENABLE, ioam_enable) \
348 _(IOAM_DISABLE, ioam_disable) \
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 _(SET_IPFIX_EXPORTER, set_ipfix_exporter) \
396 _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \
397 _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \
398 _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \
399 _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \
400 _(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \
401 _(GET_NEXT_INDEX, get_next_index) \
402 _(PG_CREATE_INTERFACE, pg_create_interface) \
403 _(PG_CAPTURE, pg_capture) \
404 _(PG_ENABLE_DISABLE, pg_enable_disable) \
405 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
406 ip_source_and_port_range_check_add_del) \
407 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
408 ip_source_and_port_range_check_interface_add_del) \
409 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
410 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \
411 _(DELETE_SUBIF, delete_subif)
414 #define QUOTE(x) QUOTE_(x)
416 #define foreach_registration_hash \
417 _(interface_events) \
418 _(to_netconf_server) \
419 _(from_netconf_server) \
420 _(to_netconf_client) \
421 _(from_netconf_client) \
426 RESOLVE_IP4_ADD_DEL_ROUTE = 1,
427 RESOLVE_IP6_ADD_DEL_ROUTE,
428 RESOLVE_MPLS_ETHERNET_ADD_DEL,
436 vl_api_ip_add_del_route_t r;
437 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
444 #define _(a) uword *a##_registration_hash; \
445 vpe_client_registration_t * a##_registrations;
446 foreach_registration_hash
448 /* notifications happen really early in the game */
449 u8 link_state_process_up;
451 /* ip4 and ip6 pending route adds */
452 pending_route_t *pending_routes;
454 /* ip4 arp event registration pool */
455 vl_api_ip4_arp_event_t *arp_events;
457 /* ip6 nd event registration pool */
458 vl_api_ip6_nd_event_t *nd_events;
461 vlib_main_t *vlib_main;
462 vnet_main_t *vnet_main;
465 static vlib_node_registration_t vpe_resolver_process_node;
466 static vpe_api_main_t vpe_api_main;
468 static void send_sw_interface_flags (vpe_api_main_t * am,
469 unix_shared_memory_queue_t * q,
470 vnet_sw_interface_t * swif);
471 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
472 unix_shared_memory_queue_t * q,
475 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
476 static int nd_change_delete_callback (u32 pool_index, u8 * notused);
479 /* Clean up all registrations belonging to the indicated client */
481 vl_api_memclnt_delete_callback (u32 client_index)
483 vpe_api_main_t *vam = &vpe_api_main;
484 vpe_client_registration_t *rp;
486 int stats_memclnt_delete_callback (u32 client_index);
488 stats_memclnt_delete_callback (client_index);
491 p = hash_get (vam->a##_registration_hash, client_index); \
493 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
494 pool_put (vam->a##_registrations, rp); \
495 hash_unset (vam->a##_registration_hash, client_index); \
497 foreach_registration_hash;
502 #define API_LINK_STATE_EVENT 1
503 #define API_ADMIN_UP_DOWN_EVENT 2
506 event_data_cmp (void *a1, void *a2)
511 return (word) e1[0] - (word) e2[0];
515 link_state_process (vlib_main_t * vm,
516 vlib_node_runtime_t * rt, vlib_frame_t * f)
518 vpe_api_main_t *vam = &vpe_api_main;
519 vnet_main_t *vnm = vam->vnet_main;
520 vnet_sw_interface_t *swif;
521 uword *event_data = 0;
522 vpe_client_registration_t *reg;
524 u32 prev_sw_if_index;
525 unix_shared_memory_queue_t *q;
527 vam->link_state_process_up = 1;
531 vlib_process_wait_for_event (vm);
533 /* Unified list of changed link or admin state sw_if_indices */
534 vlib_process_get_events_with_type
535 (vm, &event_data, API_LINK_STATE_EVENT);
536 vlib_process_get_events_with_type
537 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
539 /* Sort, so we can eliminate duplicates */
540 vec_sort_with_function (event_data, event_data_cmp);
542 prev_sw_if_index = ~0;
544 for (i = 0; i < vec_len (event_data); i++)
546 /* Only one message per swif */
547 if (prev_sw_if_index == event_data[i])
549 prev_sw_if_index = event_data[i];
552 pool_foreach(reg, vam->interface_events_registrations,
554 q = vl_api_client_index_to_input_queue (reg->client_index);
557 /* sw_interface may be deleted already */
558 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
561 swif = vnet_get_sw_interface (vnm, event_data[i]);
562 send_sw_interface_flags (vam, q, swif);
568 vec_reset_length (event_data);
574 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
576 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
577 u32 hw_if_index, u32 flags);
580 VLIB_REGISTER_NODE (link_state_process_node,static) = {
581 .function = link_state_process,
582 .type = VLIB_NODE_TYPE_PROCESS,
583 .name = "vpe-link-state-process",
587 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
588 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
590 static clib_error_t *
591 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
593 vpe_api_main_t *vam = &vpe_api_main;
594 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
596 if (vam->link_state_process_up)
597 vlib_process_signal_event (vam->vlib_main,
598 link_state_process_node.index,
599 API_LINK_STATE_EVENT, hi->sw_if_index);
603 static clib_error_t *
604 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
606 vpe_api_main_t *vam = &vpe_api_main;
609 * Note: it's perfectly fair to set a subif admin up / admin down.
610 * Note the subtle distinction between this routine and the previous
613 if (vam->link_state_process_up)
614 vlib_process_signal_event (vam->vlib_main,
615 link_state_process_node.index,
616 API_ADMIN_UP_DOWN_EVENT, sw_if_index);
620 #define pub_sub_handler(lca,UCA) \
621 static void vl_api_want_##lca##_t_handler ( \
622 vl_api_want_##lca##_t *mp) \
624 vpe_api_main_t *vam = &vpe_api_main; \
625 vpe_client_registration_t *rp; \
626 vl_api_want_##lca##_reply_t *rmp; \
630 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
632 if (mp->enable_disable) { \
633 clib_warning ("pid %d: already enabled...", mp->pid); \
634 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
637 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
638 pool_put (vam->lca##_registrations, rp); \
639 hash_unset (vam->lca##_registration_hash, \
644 if (mp->enable_disable == 0) { \
645 clib_warning ("pid %d: already disabled...", mp->pid); \
646 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
649 pool_get (vam->lca##_registrations, rp); \
650 rp->client_index = mp->client_index; \
651 rp->client_pid = mp->pid; \
652 hash_set (vam->lca##_registration_hash, rp->client_index, \
653 rp - vam->lca##_registrations); \
656 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
660 pub_sub_handler (interface_events, INTERFACE_EVENTS)
661 pub_sub_handler (oam_events, OAM_EVENTS)
664 #define RESOLUTION_EVENT 1
665 #define RESOLUTION_PENDING_EVENT 2
666 #define IP4_ARP_EVENT 3
667 #define IP6_ND_EVENT 4
669 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
671 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp);
673 static int mpls_ethernet_add_del_tunnel_2_t_handler
674 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp);
677 handle_ip4_arp_event (u32 pool_index)
679 vpe_api_main_t *vam = &vpe_api_main;
680 vnet_main_t *vnm = vam->vnet_main;
681 vlib_main_t *vm = vam->vlib_main;
682 vl_api_ip4_arp_event_t *event;
683 vl_api_ip4_arp_event_t *mp;
684 unix_shared_memory_queue_t *q;
686 /* Client can cancel, die, etc. */
687 if (pool_is_free_index (vam->arp_events, pool_index))
690 event = pool_elt_at_index (vam->arp_events, pool_index);
692 q = vl_api_client_index_to_input_queue (event->client_index);
695 (void) vnet_add_del_ip4_arp_change_event
696 (vnm, arp_change_delete_callback,
697 event->pid, &event->address,
698 vpe_resolver_process_node.index, IP4_ARP_EVENT,
699 ~0 /* pool index, notused */ , 0 /* is_add */ );
703 if (q->cursize < q->maxsize)
705 mp = vl_msg_api_alloc (sizeof (*mp));
706 clib_memcpy (mp, event, sizeof (*mp));
707 vl_msg_api_send_shmem (q, (u8 *) & mp);
711 static f64 last_time;
713 * Throttle syslog msgs.
714 * It's pretty tempting to just revoke the registration...
716 if (vlib_time_now (vm) > last_time + 10.0)
718 clib_warning ("arp event for %U to pid %d: queue stuffed!",
719 format_ip4_address, &event->address, event->pid);
720 last_time = vlib_time_now (vm);
726 handle_ip6_nd_event (u32 pool_index)
728 vpe_api_main_t *vam = &vpe_api_main;
729 vnet_main_t *vnm = vam->vnet_main;
730 vlib_main_t *vm = vam->vlib_main;
731 vl_api_ip6_nd_event_t *event;
732 vl_api_ip6_nd_event_t *mp;
733 unix_shared_memory_queue_t *q;
735 /* Client can cancel, die, etc. */
736 if (pool_is_free_index (vam->nd_events, pool_index))
739 event = pool_elt_at_index (vam->nd_events, pool_index);
741 q = vl_api_client_index_to_input_queue (event->client_index);
744 (void) vnet_add_del_ip6_nd_change_event
745 (vnm, nd_change_delete_callback,
746 event->pid, &event->address,
747 vpe_resolver_process_node.index, IP6_ND_EVENT,
748 ~0 /* pool index, notused */ , 0 /* is_add */ );
752 if (q->cursize < q->maxsize)
754 mp = vl_msg_api_alloc (sizeof (*mp));
755 clib_memcpy (mp, event, sizeof (*mp));
756 vl_msg_api_send_shmem (q, (u8 *) & mp);
760 static f64 last_time;
762 * Throttle syslog msgs.
763 * It's pretty tempting to just revoke the registration...
765 if (vlib_time_now (vm) > last_time + 10.0)
767 clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!",
768 format_ip6_address, &event->address, event->pid);
769 last_time = vlib_time_now (vm);
775 resolver_process (vlib_main_t * vm,
776 vlib_node_runtime_t * rt, vlib_frame_t * f)
779 uword *event_data = 0;
781 vpe_api_main_t *vam = &vpe_api_main;
783 vl_api_ip_add_del_route_t *adr;
784 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
785 u32 *resolution_failures = 0;
791 vlib_process_wait_for_event_or_clock (vm, timeout);
793 event_type = vlib_process_get_events (vm, &event_data);
797 case RESOLUTION_PENDING_EVENT:
801 case RESOLUTION_EVENT:
802 for (i = 0; i < vec_len (event_data); i++)
805 * Resolution events can occur long after the
806 * original request has timed out. $$$ add a cancel
809 if (pool_is_free_index (vam->pending_routes, event_data[i]))
812 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
816 switch (pr->resolve_type)
818 case RESOLVE_IP4_ADD_DEL_ROUTE:
819 rv = ip4_add_del_route_t_handler (adr);
820 clib_warning ("resolver: add %U/%d via %U %s",
822 (ip4_address_t *) & (adr->dst_address),
823 adr->dst_address_length,
825 (ip4_address_t *) & (adr->next_hop_address),
826 (rv >= 0) ? "succeeded" : "failed");
829 case RESOLVE_IP6_ADD_DEL_ROUTE:
830 rv = ip6_add_del_route_t_handler (adr);
831 clib_warning ("resolver: add %U/%d via %U %s",
833 (ip6_address_t *) & (adr->dst_address),
834 adr->dst_address_length,
836 (ip6_address_t *) & (adr->next_hop_address),
837 (rv >= 0) ? "succeeded" : "failed");
840 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
841 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
842 clib_warning ("resolver: add mpls-o-e via %U %s",
845 (pme->next_hop_ip4_address_in_outer_vrf),
846 (rv >= 0) ? "succeeded" : "failed");
850 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
852 pool_put (vam->pending_routes, pr);
857 for (i = 0; i < vec_len (event_data); i++)
858 handle_ip4_arp_event (event_data[i]);
862 for (i = 0; i < vec_len (event_data); i++)
863 handle_ip6_nd_event (event_data[i]);
866 case ~0: /* timeout, retry pending resolutions */
868 pool_foreach (pr, vam->pending_routes,
874 /* May fail, e.g. due to interface down */
875 switch (pr->resolve_type)
877 case RESOLVE_IP4_ADD_DEL_ROUTE:
878 e = ip4_probe_neighbor
879 (vm, (ip4_address_t *)&(adr->next_hop_address),
880 ntohl(adr->next_hop_sw_if_index));
883 case RESOLVE_IP6_ADD_DEL_ROUTE:
884 e = ip6_probe_neighbor
885 (vm, (ip6_address_t *)&(adr->next_hop_address),
886 ntohl(adr->next_hop_sw_if_index));
889 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
891 e = ip4_probe_neighbor
893 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
894 pme->resolve_opaque);
898 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
903 clib_error_report (e);
905 adr->resolve_attempts = 1;
907 pme->resolve_attempts = 1;
911 adr->resolve_attempts -= 1;
912 if (adr->resolve_attempts == 0)
913 vec_add1 (resolution_failures,
914 pr - vam->pending_routes);
918 pme->resolve_attempts -= 1;
919 if (pme->resolve_attempts == 0)
920 vec_add1 (resolution_failures,
921 pr - vam->pending_routes);
925 for (i = 0; i < vec_len (resolution_failures); i++)
927 pr = pool_elt_at_index (vam->pending_routes,
928 resolution_failures[i]);
932 switch (pr->resolve_type)
934 case RESOLVE_IP4_ADD_DEL_ROUTE:
935 clib_warning ("resolver: add %U/%d via %U retry failure",
937 (ip4_address_t *) & (adr->dst_address),
938 adr->dst_address_length,
940 (ip4_address_t *) & (adr->next_hop_address));
943 case RESOLVE_IP6_ADD_DEL_ROUTE:
944 clib_warning ("resolver: add %U/%d via %U retry failure",
946 (ip6_address_t *) & (adr->dst_address),
947 adr->dst_address_length,
949 (ip6_address_t *) & (adr->next_hop_address));
952 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
953 clib_warning ("resolver: add mpls-o-e via %U retry failure",
956 (pme->next_hop_ip4_address_in_outer_vrf));
960 clib_warning ("BUG");
962 pool_put (vam->pending_routes, pr);
964 vec_reset_length (resolution_failures);
967 if (pool_elts (vam->pending_routes) == 0)
969 vec_reset_length (event_data);
971 return 0; /* or not */
975 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
976 .function = resolver_process,
977 .type = VLIB_NODE_TYPE_PROCESS,
978 .name = "vpe-route-resolver-process",
983 ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
985 ip4_main_t *im = &ip4_main;
986 ip_lookup_main_t *lm = &im->lookup_main;
987 vnet_classify_main_t *cm = &vnet_classify_main;
988 stats_main_t *sm = &stats_main;
989 ip4_add_del_route_args_t a;
990 ip4_address_t next_hop_address;
992 vpe_api_main_t *vam = &vpe_api_main;
993 vnet_main_t *vnm = vam->vnet_main;
994 vlib_main_t *vm = vlib_get_main ();
996 vl_api_ip_add_del_route_t *adr;
1000 ip_adjacency_t *adj;
1002 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1005 if (mp->create_vrf_if_needed)
1008 f = find_ip4_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1010 fib_index = f->index;
1014 /* No such VRF, and we weren't asked to create one */
1015 return VNET_API_ERROR_NO_SUCH_FIB;
1023 if (~0 != mp->next_hop_sw_if_index &&
1024 pool_is_free_index (vnm->interface_main.sw_interfaces,
1025 ntohl (mp->next_hop_sw_if_index)))
1026 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1028 clib_memcpy (next_hop_address.data, mp->next_hop_address,
1029 sizeof (next_hop_address.data));
1031 /* Arp for the next_hop if necessary */
1032 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1035 ip_adjacency_t *adj;
1037 lookup_result = ip4_fib_lookup_with_table
1038 (im, fib_index, &next_hop_address, 1 /* disable default route */ );
1040 adj = ip_get_adjacency (lm, lookup_result);
1042 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1044 pool_get (vam->pending_routes, pr);
1045 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
1047 clib_memcpy (adr, mp, sizeof (*adr));
1048 /* recursion block, "just in case" */
1049 adr->resolve_if_needed = 0;
1050 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1051 vnet_register_ip4_arp_resolution_event
1052 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1053 RESOLUTION_EVENT, pr - vam->pending_routes);
1055 vlib_process_signal_event
1056 (vm, vpe_resolver_process_node.index,
1057 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1059 /* The interface may be down, etc. */
1060 e = ip4_probe_neighbor
1061 (vm, (ip4_address_t *) & (mp->next_hop_address),
1062 ntohl (mp->next_hop_sw_if_index));
1065 clib_error_report (e);
1067 return VNET_API_ERROR_IN_PROGRESS;
1071 if (mp->is_multipath)
1075 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
1078 flags = IP4_ROUTE_FLAG_ADD;
1080 flags = IP4_ROUTE_FLAG_DEL;
1083 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1085 ip4_add_del_route_next_hop (im, flags,
1086 (ip4_address_t *) mp->dst_address,
1087 (u32) mp->dst_address_length,
1088 (ip4_address_t *) mp->next_hop_address,
1089 ntohl (mp->next_hop_sw_if_index),
1090 (u32) mp->next_hop_weight,
1091 ~0 /* adj_index */ ,
1097 memset (&a, 0, sizeof (a));
1098 clib_memcpy (a.dst_address.data, mp->dst_address,
1099 sizeof (a.dst_address.data));
1101 a.dst_address_length = mp->dst_address_length;
1103 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
1104 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
1105 a.table_index_or_table_id = fib_index;
1110 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1112 dslock (sm, 1 /* release hint */ , 2 /* tag */ );
1117 ai = lm->drop_adj_index;
1118 else if (mp->is_local)
1119 ai = lm->local_adj_index;
1120 else if (mp->is_classify)
1122 if (pool_is_free_index
1123 (cm->tables, ntohl (mp->classify_table_index)))
1126 return VNET_API_ERROR_NO_SUCH_TABLE;
1128 adj = ip_add_adjacency (lm,
1133 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
1134 adj->classify.table_index = ntohl (mp->classify_table_index);
1136 else if (mp->lookup_in_vrf)
1138 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1141 adj = ip_add_adjacency (lm,
1145 adj->explicit_fib_index = p[0];
1150 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1154 ai = ip4_route_get_next_hop_adj (im,
1157 ntohl (mp->next_hop_sw_if_index),
1160 if (ai == lm->miss_adj_index)
1163 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1168 ip_adjacency_t *adj;
1169 int disable_default_route = 1;
1171 /* Trying to delete the default route? */
1172 if (a.dst_address.as_u32 == 0 && a.dst_address_length == 0)
1173 disable_default_route = 0;
1175 ai = ip4_fib_lookup_with_table
1176 (im, fib_index, &a.dst_address, disable_default_route);
1177 if (ai == lm->miss_adj_index)
1180 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1183 adj = ip_get_adjacency (lm, ai);
1184 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1187 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1192 ip4_add_del_route (im, &a);
1199 ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1201 ip6_main_t *im = &ip6_main;
1202 ip_lookup_main_t *lm = &im->lookup_main;
1203 vnet_main_t *vnm = vnet_get_main ();
1204 vlib_main_t *vm = vlib_get_main ();
1205 vpe_api_main_t *vam = &vpe_api_main;
1206 stats_main_t *sm = &stats_main;
1207 ip6_add_del_route_args_t a;
1208 ip6_address_t next_hop_address;
1209 pending_route_t *pr;
1210 vl_api_ip_add_del_route_t *adr;
1215 ip_adjacency_t *adj = 0;
1218 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
1222 if (mp->create_vrf_if_needed)
1225 f = find_ip6_fib_by_table_index_or_id (im, ntohl (mp->vrf_id),
1227 fib_index = f->index;
1231 /* No such VRF, and we weren't asked to create one */
1232 return VNET_API_ERROR_NO_SUCH_FIB;
1240 if (~0 != mp->next_hop_sw_if_index &&
1241 pool_is_free_index (vnm->interface_main.sw_interfaces,
1242 ntohl (mp->next_hop_sw_if_index)))
1243 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1245 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1246 sizeof (next_hop_address.as_u8));
1248 /* Arp for the next_hop if necessary */
1249 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index)
1252 ip_adjacency_t *adj;
1254 lookup_result = ip6_fib_lookup_with_table
1255 (im, fib_index, &next_hop_address);
1257 adj = ip_get_adjacency (lm, lookup_result);
1259 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1261 pool_get (vam->pending_routes, pr);
1263 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1264 clib_memcpy (adr, mp, sizeof (*adr));
1265 /* recursion block, "just in case" */
1266 adr->resolve_if_needed = 0;
1267 adr->resolve_attempts = ntohl (mp->resolve_attempts);
1268 vnet_register_ip6_neighbor_resolution_event
1269 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1270 RESOLUTION_EVENT, pr - vam->pending_routes);
1272 vlib_process_signal_event
1273 (vm, vpe_resolver_process_node.index,
1274 RESOLUTION_PENDING_EVENT, 0 /* data */ );
1276 /* The interface may be down, etc. */
1277 e = ip6_probe_neighbor
1278 (vm, (ip6_address_t *) & (mp->next_hop_address),
1279 ntohl (mp->next_hop_sw_if_index));
1282 clib_error_report (e);
1284 return VNET_API_ERROR_IN_PROGRESS;
1288 if (mp->is_multipath)
1292 dslock (sm, 1 /* release hint */ , 11 /* tag */ );
1295 flags = IP6_ROUTE_FLAG_ADD;
1297 flags = IP6_ROUTE_FLAG_DEL;
1300 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1302 ip6_add_del_route_next_hop (im, flags,
1303 (ip6_address_t *) mp->dst_address,
1304 (u32) mp->dst_address_length,
1305 (ip6_address_t *) mp->next_hop_address,
1306 ntohl (mp->next_hop_sw_if_index),
1307 (u32) mp->next_hop_weight,
1308 ~0 /* adj_index */ ,
1314 memset (&a, 0, sizeof (a));
1315 clib_memcpy (a.dst_address.as_u8, mp->dst_address,
1316 sizeof (a.dst_address.as_u8));
1318 a.dst_address_length = mp->dst_address_length;
1320 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1321 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1322 a.table_index_or_table_id = fib_index;
1327 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1329 dslock (sm, 1 /* release hint */ , 3 /* tag */ );
1334 ai = lm->drop_adj_index;
1335 else if (mp->is_local)
1336 ai = lm->local_adj_index;
1337 else if (mp->lookup_in_vrf)
1339 p = hash_get (im->fib_index_by_table_id, ntohl (mp->lookup_in_vrf));
1342 adj = ip_add_adjacency (lm,
1346 adj->explicit_fib_index = p[0];
1351 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1355 ai = ip6_route_get_next_hop_adj (im,
1358 ntohl (mp->next_hop_sw_if_index),
1360 if (ai == lm->miss_adj_index)
1363 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1368 ip_adjacency_t *adj;
1370 ai = ip6_fib_lookup_with_table (im, fib_index, &a.dst_address);
1371 if (ai == lm->miss_adj_index)
1374 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1376 adj = ip_get_adjacency (lm, ai);
1377 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
1380 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1385 ip6_add_del_route (im, &a);
1392 vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp)
1394 vl_api_ip_add_del_route_reply_t *rmp;
1396 vnet_main_t *vnm = vnet_get_main ();
1401 rv = ip6_add_del_route_t_handler (mp);
1403 rv = ip4_add_del_route_t_handler (mp);
1405 rv = (rv == 0) ? vnm->api_errno : rv;
1407 REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY);
1411 api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1412 u32 sw_if_index, u8 * next_hop_addr)
1414 vl_api_ip_add_del_route_t mp;
1417 memset (&mp, 0, sizeof (vl_api_ip_add_del_route_t));
1420 * Configure default IP route:
1421 * - ip route add 0.0.0.0/1 via <GW IP>
1422 * - ip route add 128.0.0.0/1 via <GW IP>
1424 mp.next_hop_sw_if_index = ntohl (sw_if_index);
1426 mp.resolve_attempts = ~0;
1427 mp.resolve_if_needed = 1;
1429 mp.is_ipv6 = is_ipv6;
1430 mp.next_hop_weight = 1;
1432 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1435 rv = ip6_add_del_route_t_handler (&mp);
1438 mp.dst_address_length = 1;
1440 mp.dst_address[0] = 0;
1441 rv = ip4_add_del_route_t_handler (&mp);
1443 mp.dst_address[0] = 128;
1444 rv |= ip4_add_del_route_t_handler (&mp);
1448 clib_error_return (0, "failed to config default IP route");
1453 vl_api_sw_interface_add_del_address_t_handler
1454 (vl_api_sw_interface_add_del_address_t * mp)
1456 vlib_main_t *vm = vlib_get_main ();
1457 vl_api_sw_interface_add_del_address_reply_t *rmp;
1461 VALIDATE_SW_IF_INDEX (mp);
1463 is_del = mp->is_add == 0;
1466 ip_del_all_interface_addresses (vm, ntohl (mp->sw_if_index));
1467 else if (mp->is_ipv6)
1468 ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1469 (void *) mp->address,
1470 mp->address_length, is_del);
1472 ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
1473 (void *) mp->address,
1474 mp->address_length, is_del);
1476 BAD_SW_IF_INDEX_LABEL;
1478 REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1482 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp)
1485 u32 table_id = ntohl (mp->vrf_id);
1486 u32 sw_if_index = ntohl (mp->sw_if_index);
1487 vl_api_sw_interface_set_table_reply_t *rmp;
1488 stats_main_t *sm = &stats_main;
1490 VALIDATE_SW_IF_INDEX (mp);
1492 dslock (sm, 1 /* release hint */ , 4 /* tag */ );
1496 ip6_main_t *im = &ip6_main;
1497 ip6_fib_t *fib = find_ip6_fib_by_table_index_or_id (im, table_id,
1498 IP6_ROUTE_FLAG_TABLE_ID);
1501 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1502 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1506 rv = VNET_API_ERROR_NO_SUCH_FIB;
1511 ip4_main_t *im = &ip4_main;
1512 ip4_fib_t *fib = find_ip4_fib_by_table_index_or_id
1513 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1515 /* Truthfully this can't fail */
1518 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1519 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1523 rv = VNET_API_ERROR_NO_SUCH_FIB;
1528 BAD_SW_IF_INDEX_LABEL;
1530 REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1534 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1536 vlib_main_t *vm = vlib_get_main ();
1537 ip4_main_t *im4 = &ip4_main;
1538 ip6_main_t *im6 = &ip6_main;
1539 vl_api_sw_interface_set_vpath_reply_t *rmp;
1542 u32 sw_if_index = ntohl (mp->sw_if_index);
1543 ip4_main_t *ip4m = &ip4_main;
1544 ip6_main_t *ip6m = &ip6_main;
1545 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1546 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1547 ip_config_main_t *rx_cm4u =
1548 &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1549 ip_config_main_t *rx_cm4m =
1550 &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1551 ip_config_main_t *rx_cm6u =
1552 &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
1553 ip_config_main_t *rx_cm6m =
1554 &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
1556 VALIDATE_SW_IF_INDEX (mp);
1558 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1561 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1562 ci = vnet_config_add_feature (vm, &rx_cm4u->config_main,
1564 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1565 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1566 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1567 ci = vnet_config_add_feature (vm, &rx_cm4m->config_main,
1569 im4->ip4_multicast_rx_feature_vpath,
1571 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1572 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1573 ci = vnet_config_add_feature (vm, &rx_cm6u->config_main,
1575 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1576 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1577 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1578 ci = vnet_config_add_feature (vm, &rx_cm6m->config_main,
1580 im6->ip6_multicast_rx_feature_vpath,
1582 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1586 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1587 ci = vnet_config_del_feature (vm, &rx_cm4u->config_main,
1589 im4->ip4_unicast_rx_feature_vpath, 0, 0);
1590 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1591 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1592 ci = vnet_config_del_feature (vm, &rx_cm4m->config_main,
1594 im4->ip4_multicast_rx_feature_vpath,
1596 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1597 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1598 ci = vnet_config_del_feature (vm, &rx_cm6u->config_main,
1600 im6->ip6_unicast_rx_feature_vpath, 0, 0);
1601 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1602 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1603 ci = vnet_config_del_feature (vm, &rx_cm6m->config_main,
1605 im6->ip6_multicast_rx_feature_vpath,
1607 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1610 BAD_SW_IF_INDEX_LABEL;
1612 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1616 vl_api_sw_interface_set_l2_xconnect_t_handler
1617 (vl_api_sw_interface_set_l2_xconnect_t * mp)
1619 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
1621 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1622 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
1623 vlib_main_t *vm = vlib_get_main ();
1624 vnet_main_t *vnm = vnet_get_main ();
1626 VALIDATE_RX_SW_IF_INDEX (mp);
1630 VALIDATE_TX_SW_IF_INDEX (mp);
1631 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
1632 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1636 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1639 BAD_RX_SW_IF_INDEX_LABEL;
1640 BAD_TX_SW_IF_INDEX_LABEL;
1642 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1646 vl_api_sw_interface_set_l2_bridge_t_handler
1647 (vl_api_sw_interface_set_l2_bridge_t * mp)
1649 bd_main_t *bdm = &bd_main;
1650 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
1652 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
1653 u32 bd_id = ntohl (mp->bd_id);
1657 vlib_main_t *vm = vlib_get_main ();
1658 vnet_main_t *vnm = vnet_get_main ();
1660 VALIDATE_RX_SW_IF_INDEX (mp);
1662 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1666 //VALIDATE_TX_SW_IF_INDEX(mp);
1667 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
1668 rx_sw_if_index, bd_index, bvi, shg, 0);
1672 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1675 BAD_RX_SW_IF_INDEX_LABEL;
1677 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1681 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
1683 vlib_main_t *vm = vlib_get_main ();
1684 bd_main_t *bdm = &bd_main;
1685 vl_api_bridge_domain_add_del_reply_t *rmp;
1687 u32 enable_flags = 0, disable_flags = 0;
1688 u32 bd_id = ntohl (mp->bd_id);
1693 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1696 enable_flags |= L2_FLOOD;
1698 disable_flags |= L2_FLOOD;
1701 enable_flags |= L2_UU_FLOOD;
1703 disable_flags |= L2_UU_FLOOD;
1706 enable_flags |= L2_FWD;
1708 disable_flags |= L2_FWD;
1711 enable_flags |= L2_ARP_TERM;
1713 disable_flags |= L2_ARP_TERM;
1716 enable_flags |= L2_LEARN;
1718 disable_flags |= L2_LEARN;
1721 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1724 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1728 rv = bd_delete_bd_index (bdm, bd_id);
1730 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1734 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
1736 clib_warning ("BUG");
1740 vl_api_bridge_domain_sw_if_details_t_handler
1741 (vl_api_bridge_domain_sw_if_details_t * mp)
1743 clib_warning ("BUG");
1747 send_bridge_domain_details (unix_shared_memory_queue_t * q,
1748 l2_bridge_domain_t * bd_config,
1749 u32 n_sw_ifs, u32 context)
1751 vl_api_bridge_domain_details_t *mp;
1753 mp = vl_msg_api_alloc (sizeof (*mp));
1754 memset (mp, 0, sizeof (*mp));
1755 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1756 mp->bd_id = ntohl (bd_config->bd_id);
1757 mp->flood = bd_feature_flood (bd_config);
1758 mp->uu_flood = bd_feature_uu_flood (bd_config);
1759 mp->forward = bd_feature_forward (bd_config);
1760 mp->learn = bd_feature_learn (bd_config);
1761 mp->arp_term = bd_feature_arp_term (bd_config);
1762 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1763 mp->n_sw_ifs = ntohl (n_sw_ifs);
1764 mp->context = context;
1766 vl_msg_api_send_shmem (q, (u8 *) & mp);
1770 send_bd_sw_if_details (l2input_main_t * l2im,
1771 unix_shared_memory_queue_t * q,
1772 l2_flood_member_t * member, u32 bd_id, u32 context)
1774 vl_api_bridge_domain_sw_if_details_t *mp;
1775 l2_input_config_t *input_cfg;
1777 mp = vl_msg_api_alloc (sizeof (*mp));
1778 memset (mp, 0, sizeof (*mp));
1779 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1780 mp->bd_id = ntohl (bd_id);
1781 mp->sw_if_index = ntohl (member->sw_if_index);
1782 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1783 mp->shg = input_cfg->shg;
1784 mp->context = context;
1786 vl_msg_api_send_shmem (q, (u8 *) & mp);
1790 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
1792 bd_main_t *bdm = &bd_main;
1793 l2input_main_t *l2im = &l2input_main;
1794 unix_shared_memory_queue_t *q;
1795 l2_bridge_domain_t *bd_config;
1796 u32 bd_id, bd_index;
1799 q = vl_api_client_index_to_input_queue (mp->client_index);
1804 bd_id = ntohl (mp->bd_id);
1806 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1807 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1808 for (; bd_index < end; bd_index++)
1810 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1811 /* skip dummy bd_id 0 */
1812 if (bd_config && (bd_config->bd_id > 0))
1815 l2_flood_member_t *m;
1817 n_sw_ifs = vec_len (bd_config->members);
1818 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1820 vec_foreach (m, bd_config->members)
1822 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1829 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
1831 bd_main_t *bdm = &bd_main;
1832 l2input_main_t *l2im = &l2input_main;
1833 vl_api_l2fib_add_del_reply_t *rmp;
1836 u32 sw_if_index = ntohl (mp->sw_if_index);
1837 u32 bd_id = ntohl (mp->bd_id);
1846 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1849 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1850 goto bad_sw_if_index;
1856 VALIDATE_SW_IF_INDEX (mp);
1857 if (vec_len (l2im->configs) <= sw_if_index)
1859 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1860 goto bad_sw_if_index;
1864 l2_input_config_t *config;
1865 config = vec_elt_at_index (l2im->configs, sw_if_index);
1866 if (config->bridge == 0)
1868 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1869 goto bad_sw_if_index;
1872 static_mac = mp->static_mac ? 1 : 0;
1873 filter_mac = mp->filter_mac ? 1 : 0;
1874 bvi_mac = mp->bvi_mac ? 1 : 0;
1875 l2fib_add_entry (mac, bd_index, sw_if_index, static_mac, filter_mac,
1880 l2fib_del_entry (mac, bd_index);
1883 BAD_SW_IF_INDEX_LABEL;
1885 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
1889 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
1891 vl_api_l2_flags_reply_t *rmp;
1893 u32 sw_if_index = ntohl (mp->sw_if_index);
1894 u32 flags = ntohl (mp->feature_bitmap);
1897 VALIDATE_SW_IF_INDEX (mp);
1900 if (flags & L2INPUT_FEAT_ ## a) \
1901 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1902 foreach_l2input_feat;
1905 BAD_SW_IF_INDEX_LABEL;
1908 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
1910 rmp->resulting_feature_bitmap = ntohl(rbm);
1916 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
1918 vlib_main_t *vm = vlib_get_main ();
1919 bd_main_t *bdm = &bd_main;
1920 vl_api_bridge_flags_reply_t *rmp;
1922 u32 bd_id = ntohl (mp->bd_id);
1924 u32 flags = ntohl (mp->feature_bitmap);
1927 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1930 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1936 bd_set_flags (vm, bd_index, flags, mp->is_set);
1940 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1942 rmp->resulting_feature_bitmap = ntohl(flags);
1948 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
1950 bd_main_t *bdm = &bd_main;
1951 vl_api_bd_ip_mac_add_del_reply_t *rmp;
1953 u32 bd_id = ntohl (mp->bd_id);
1957 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1960 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1965 if (bd_add_del_ip_mac (bd_index, mp->ip_address,
1966 mp->mac_address, mp->is_ipv6, mp->is_add))
1967 rv = VNET_API_ERROR_UNSPECIFIED;
1970 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1974 vl_api_tap_connect_t_handler (vl_api_tap_connect_t * mp, vlib_main_t * vm)
1977 vl_api_tap_connect_reply_t *rmp;
1978 unix_shared_memory_queue_t *q;
1979 u32 sw_if_index = (u32) ~ 0;
1981 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1982 mp->use_random_mac ? 0 : mp->mac_address,
1983 &sw_if_index, mp->renumber,
1984 ntohl (mp->custom_dev_instance));
1986 q = vl_api_client_index_to_input_queue (mp->client_index);
1990 rmp = vl_msg_api_alloc (sizeof (*rmp));
1991 rmp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT_REPLY);
1992 rmp->context = mp->context;
1993 rmp->retval = ntohl (rv);
1994 rmp->sw_if_index = ntohl (sw_if_index);
1996 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2000 vl_api_tap_modify_t_handler (vl_api_tap_modify_t * mp, vlib_main_t * vm)
2003 vl_api_tap_modify_reply_t *rmp;
2004 unix_shared_memory_queue_t *q;
2005 u32 sw_if_index = (u32) ~ 0;
2007 rv = vnet_tap_modify (vm, ntohl (mp->sw_if_index), mp->tap_name,
2008 mp->use_random_mac ? 0 : mp->mac_address,
2009 &sw_if_index, mp->renumber,
2010 ntohl (mp->custom_dev_instance));
2012 q = vl_api_client_index_to_input_queue (mp->client_index);
2016 rmp = vl_msg_api_alloc (sizeof (*rmp));
2017 rmp->_vl_msg_id = ntohs (VL_API_TAP_MODIFY_REPLY);
2018 rmp->context = mp->context;
2019 rmp->retval = ntohl (rv);
2020 rmp->sw_if_index = ntohl (sw_if_index);
2022 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2026 vl_api_tap_delete_t_handler (vl_api_tap_delete_t * mp, vlib_main_t * vm)
2029 vpe_api_main_t *vam = &vpe_api_main;
2030 vl_api_tap_delete_reply_t *rmp;
2031 unix_shared_memory_queue_t *q;
2032 u32 sw_if_index = ntohl (mp->sw_if_index);
2034 rv = vnet_tap_delete (vm, sw_if_index);
2036 q = vl_api_client_index_to_input_queue (mp->client_index);
2040 rmp = vl_msg_api_alloc (sizeof (*rmp));
2041 rmp->_vl_msg_id = ntohs (VL_API_TAP_DELETE_REPLY);
2042 rmp->context = mp->context;
2043 rmp->retval = ntohl (rv);
2045 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2048 send_sw_interface_flags_deleted (vam, q, sw_if_index);
2052 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
2054 vl_api_create_vlan_subif_reply_t *rmp;
2055 vnet_main_t *vnm = vnet_get_main ();
2056 u32 hw_if_index, sw_if_index = (u32) ~ 0;
2057 vnet_hw_interface_t *hi;
2060 vnet_sw_interface_t template;
2062 vnet_interface_main_t *im = &vnm->interface_main;
2063 u64 sup_and_sub_key;
2065 unix_shared_memory_queue_t *q;
2066 clib_error_t *error;
2068 VALIDATE_SW_IF_INDEX (mp);
2070 hw_if_index = ntohl (mp->sw_if_index);
2071 hi = vnet_get_hw_interface (vnm, hw_if_index);
2073 id = ntohl (mp->vlan_id);
2074 if (id == 0 || id > 4095)
2076 rv = VNET_API_ERROR_INVALID_VLAN;
2080 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
2082 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2085 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
2089 kp = clib_mem_alloc (sizeof (*kp));
2090 *kp = sup_and_sub_key;
2092 memset (&template, 0, sizeof (template));
2093 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2094 template.sup_sw_if_index = hi->sw_if_index;
2095 template.sub.id = id;
2096 template.sub.eth.raw_flags = 0;
2097 template.sub.eth.flags.one_tag = 1;
2098 template.sub.eth.outer_vlan_id = id;
2099 template.sub.eth.flags.exact_match = 1;
2101 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2104 clib_error_report (error);
2105 rv = VNET_API_ERROR_INVALID_REGISTRATION;
2108 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
2109 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2111 BAD_SW_IF_INDEX_LABEL;
2114 q = vl_api_client_index_to_input_queue (mp->client_index);
2118 rmp = vl_msg_api_alloc (sizeof (*rmp));
2119 rmp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF_REPLY);
2120 rmp->context = mp->context;
2121 rmp->retval = ntohl (rv);
2122 rmp->sw_if_index = ntohl (sw_if_index);
2123 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2127 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
2129 vl_api_create_subif_reply_t *rmp;
2130 vnet_main_t *vnm = vnet_get_main ();
2131 u32 sw_if_index = ~0;
2134 vnet_sw_interface_t *si;
2135 vnet_hw_interface_t *hi;
2136 vnet_sw_interface_t template;
2138 vnet_interface_main_t *im = &vnm->interface_main;
2139 u64 sup_and_sub_key;
2141 clib_error_t *error;
2143 VALIDATE_SW_IF_INDEX (mp);
2145 si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
2146 hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
2148 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
2150 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
2154 sw_if_index = si->sw_if_index;
2155 sub_id = ntohl (mp->sub_id);
2157 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
2159 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
2163 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
2164 sw_if_index, sub_id);
2165 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
2169 kp = clib_mem_alloc (sizeof (*kp));
2170 *kp = sup_and_sub_key;
2172 memset (&template, 0, sizeof (template));
2173 template.type = VNET_SW_INTERFACE_TYPE_SUB;
2174 template.sup_sw_if_index = sw_if_index;
2175 template.sub.id = sub_id;
2176 template.sub.eth.flags.no_tags = mp->no_tags;
2177 template.sub.eth.flags.one_tag = mp->one_tag;
2178 template.sub.eth.flags.two_tags = mp->two_tags;
2179 template.sub.eth.flags.dot1ad = mp->dot1ad;
2180 template.sub.eth.flags.exact_match = mp->exact_match;
2181 template.sub.eth.flags.default_sub = mp->default_sub;
2182 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
2183 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
2184 template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
2185 template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
2187 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
2190 clib_error_report (error);
2191 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
2195 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
2196 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
2198 BAD_SW_IF_INDEX_LABEL;
2203 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2205 rmp->sw_if_index = ntohl(sw_if_index);
2211 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *
2214 vl_api_mpls_gre_add_del_tunnel_reply_t *rmp;
2216 stats_main_t *sm = &stats_main;
2217 u32 tunnel_sw_if_index = ~0;
2219 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2221 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *) (mp->src_address),
2222 (ip4_address_t *) (mp->dst_address),
2223 (ip4_address_t *) (mp->intfc_address),
2224 (u32) (mp->intfc_address_length),
2225 ntohl (mp->inner_vrf_id),
2226 ntohl (mp->outer_vrf_id),
2227 &tunnel_sw_if_index,
2228 mp->l2_only, mp->is_add);
2232 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2234 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2240 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2241 (vl_api_mpls_ethernet_add_del_tunnel_t * mp)
2243 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2245 stats_main_t *sm = &stats_main;
2246 u32 tunnel_sw_if_index;
2248 dslock (sm, 1 /* release hint */ , 5 /* tag */ );
2250 rv = vnet_mpls_ethernet_add_del_tunnel
2251 (mp->dst_mac_address, (ip4_address_t *) (mp->adj_address),
2252 (u32) (mp->adj_address_length), ntohl (mp->vrf_id),
2253 ntohl (mp->tx_sw_if_index),
2254 &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2259 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2261 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2267 * This piece of misery brought to you because the control-plane
2268 * can't figure out the tx interface + dst-mac address all by itself
2270 static int mpls_ethernet_add_del_tunnel_2_t_handler
2271 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2273 pending_route_t *pr;
2274 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2275 vnet_main_t *vnm = vnet_get_main ();
2276 vlib_main_t *vm = vlib_get_main ();
2277 stats_main_t *sm = &stats_main;
2278 vpe_api_main_t *vam = &vpe_api_main;
2279 u32 inner_fib_index, outer_fib_index;
2280 ip4_main_t *im = &ip4_main;
2281 ip_lookup_main_t *lm = &im->lookup_main;
2282 ip_adjacency_t *adj = 0;
2285 u8 *dst_mac_address;
2289 u32 tunnel_sw_if_index;
2291 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_vrf_id));
2293 return VNET_API_ERROR_NO_SUCH_FIB;
2295 outer_fib_index = p[0];
2298 p = hash_get (im->fib_index_by_table_id, ntohl (mp->inner_vrf_id));
2300 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2302 inner_fib_index = p[0];
2304 if (inner_fib_index == outer_fib_index)
2305 return VNET_API_ERROR_INVALID_VALUE;
2307 lookup_result = ip4_fib_lookup_with_table
2308 (im, outer_fib_index,
2309 (ip4_address_t *) mp->next_hop_ip4_address_in_outer_vrf,
2310 1 /* disable default route */ );
2312 adj = ip_get_adjacency (lm, lookup_result);
2313 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2315 if (mp->is_add && mp->resolve_if_needed)
2317 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP)
2319 pool_get (vam->pending_routes, pr);
2320 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2322 clib_memcpy (pme, mp, sizeof (*pme));
2323 /* recursion block, "just in case" */
2324 pme->resolve_if_needed = 0;
2325 pme->resolve_attempts = ntohl (mp->resolve_attempts);
2326 pme->resolve_opaque = tx_sw_if_index;
2327 vnet_register_ip4_arp_resolution_event
2329 (ip4_address_t *) & (pme->next_hop_ip4_address_in_outer_vrf),
2330 vpe_resolver_process_node.index,
2331 RESOLUTION_EVENT, pr - vam->pending_routes);
2333 vlib_process_signal_event
2334 (vm, vpe_resolver_process_node.index,
2335 RESOLUTION_PENDING_EVENT, 0 /* data */ );
2337 /* The interface may be down, etc. */
2338 e = ip4_probe_neighbor
2339 (vm, (ip4_address_t *) & (mp->next_hop_ip4_address_in_outer_vrf),
2343 clib_error_report (e);
2345 return VNET_API_ERROR_IN_PROGRESS;
2349 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2350 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2353 vnet_rewrite_get_data_internal
2354 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2356 dslock (sm, 1 /* release hint */ , 10 /* tag */ );
2358 rv = vnet_mpls_ethernet_add_del_tunnel
2359 (dst_mac_address, (ip4_address_t *) (mp->adj_address),
2360 (u32) (mp->adj_address_length), ntohl (mp->inner_vrf_id),
2361 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2369 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2370 (vl_api_mpls_ethernet_add_del_tunnel_2_t * mp)
2372 vl_api_mpls_ethernet_add_del_tunnel_reply_t *rmp;
2375 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2377 REPLY_MACRO (VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2382 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t * mp)
2384 vl_api_mpls_add_del_encap_reply_t *rmp;
2389 vec_reset_length (labels);
2391 for (i = 0; i < mp->nlabels; i++)
2392 vec_add1 (labels, ntohl (mp->labels[i]));
2395 rv = vnet_mpls_add_del_encap ((ip4_address_t *) mp->dst_address,
2396 ntohl (mp->vrf_id), labels,
2397 ~0 /* policy_tunnel_index */ ,
2398 0 /* no_dst_hash */ ,
2402 REPLY_MACRO (VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2406 vl_api_mpls_add_del_decap_t_handler (vl_api_mpls_add_del_decap_t * mp)
2408 vl_api_mpls_add_del_decap_reply_t *rmp;
2411 rv = vnet_mpls_add_del_decap (ntohl (mp->rx_vrf_id), ntohl (mp->tx_vrf_id),
2412 ntohl (mp->label), ntohl (mp->next_index),
2413 mp->s_bit, mp->is_add);
2415 REPLY_MACRO (VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2419 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
2421 vl_api_proxy_arp_add_del_reply_t *rmp;
2424 ip4_main_t *im = &ip4_main;
2425 stats_main_t *sm = &stats_main;
2426 int vnet_proxy_arp_add_del (ip4_address_t * lo_addr,
2427 ip4_address_t * hi_addr,
2428 u32 fib_index, int is_del);
2431 dslock (sm, 1 /* release hint */ , 6 /* tag */ );
2433 p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2437 rv = VNET_API_ERROR_NO_SUCH_FIB;
2443 rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address,
2444 (ip4_address_t *) mp->hi_address,
2445 fib_index, mp->is_add == 0);
2449 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
2453 vl_api_proxy_arp_intfc_enable_disable_t_handler
2454 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
2457 vnet_main_t *vnm = vnet_get_main ();
2458 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2459 vnet_sw_interface_t *si;
2462 VALIDATE_SW_IF_INDEX (mp);
2464 sw_if_index = ntohl (mp->sw_if_index);
2466 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
2468 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2472 si = vnet_get_sw_interface (vnm, sw_if_index);
2476 if (mp->enable_disable)
2477 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2479 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2481 BAD_SW_IF_INDEX_LABEL;
2484 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2488 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp,
2491 vl_api_ip_neighbor_add_del_reply_t *rmp;
2492 vnet_main_t *vnm = vnet_get_main ();
2495 stats_main_t *sm = &stats_main;
2497 VALIDATE_SW_IF_INDEX (mp);
2499 dslock (sm, 1 /* release hint */ , 7 /* tag */ );
2504 rv = vnet_set_ip6_ethernet_neighbor
2505 (vm, ntohl (mp->sw_if_index),
2506 (ip6_address_t *) (mp->dst_address),
2507 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2509 rv = vnet_unset_ip6_ethernet_neighbor
2510 (vm, ntohl (mp->sw_if_index),
2511 (ip6_address_t *) (mp->dst_address),
2512 mp->mac_address, sizeof (mp->mac_address));
2516 ip4_main_t *im = &ip4_main;
2517 ip_lookup_main_t *lm = &im->lookup_main;
2518 ethernet_arp_ip4_over_ethernet_address_t a;
2520 ip_adjacency_t *nh_adj;
2522 uword *p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id));
2525 rv = VNET_API_ERROR_NO_SUCH_FIB;
2531 * Unfortunately, folks have a penchant for
2532 * adding interface addresses to the ARP cache, and
2533 * wondering why the forwarder eventually ASSERTs...
2535 ai = ip4_fib_lookup_with_table
2536 (im, fib_index, (ip4_address_t *) (mp->dst_address),
2537 1 /* disable default route */ );
2541 nh_adj = ip_get_adjacency (lm, ai);
2542 /* Never allow manipulation of a local adj! */
2543 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL)
2545 clib_warning ("%U matches local adj",
2547 (ip4_address_t *) (mp->dst_address));
2548 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2553 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2554 clib_memcpy (&a.ip4, mp->dst_address, 4);
2557 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2558 fib_index, &a, mp->is_static);
2560 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index),
2564 BAD_SW_IF_INDEX_LABEL;
2567 REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2571 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t * mp)
2574 vpe_main_t *rm = &vpe_main;
2575 ip4_main_t *im4 = &ip4_main;
2576 ip6_main_t *im6 = &ip6_main;
2577 ip_lookup_main_t *lm;
2583 u32 adj_index, sw_if_index;
2584 vl_api_is_address_reachable_t *rmp;
2585 ip_adjacency_t *adj;
2586 unix_shared_memory_queue_t *q;
2588 q = vl_api_client_index_to_input_queue (mp->client_index);
2591 increment_missing_api_client_counter (rm->vlib_main);
2595 rmp = vl_msg_api_alloc (sizeof (*rmp));
2596 clib_memcpy (rmp, mp, sizeof (*rmp));
2598 sw_if_index = mp->next_hop_sw_if_index;
2599 clib_memcpy (&addr, mp->address, sizeof (addr));
2602 lm = &im6->lookup_main;
2603 adj_index = ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2607 lm = &im4->lookup_main;
2608 adj_index = ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2610 if (adj_index == ~0)
2615 adj = ip_get_adjacency (lm, adj_index);
2617 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2618 && adj->rewrite_header.sw_if_index == sw_if_index)
2624 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2625 && adj->rewrite_header.sw_if_index == sw_if_index)
2628 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2630 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2632 else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP)
2641 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2646 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
2648 clib_warning ("BUG");
2652 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
2654 vl_api_sw_interface_set_flags_reply_t *rmp;
2655 vnet_main_t *vnm = vnet_get_main ();
2657 clib_error_t *error;
2660 VALIDATE_SW_IF_INDEX (mp);
2662 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2664 error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
2668 clib_error_report (error);
2671 BAD_SW_IF_INDEX_LABEL;
2672 REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2676 vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
2679 vl_api_sw_interface_clear_stats_reply_t *rmp;
2681 vnet_main_t *vnm = vnet_get_main ();
2682 vnet_interface_main_t *im = &vnm->interface_main;
2683 vlib_simple_counter_main_t *sm;
2684 vlib_combined_counter_main_t *cm;
2685 static vnet_main_t **my_vnet_mains;
2686 int i, j, n_counters;
2689 if (mp->sw_if_index != ~0)
2690 VALIDATE_SW_IF_INDEX (mp);
2692 vec_reset_length (my_vnet_mains);
2694 for (i = 0; i < vec_len (vnet_mains); i++)
2697 vec_add1 (my_vnet_mains, vnet_mains[i]);
2700 if (vec_len (vnet_mains) == 0)
2701 vec_add1 (my_vnet_mains, vnm);
2703 n_counters = vec_len (im->combined_sw_if_counters);
2705 for (j = 0; j < n_counters; j++)
2707 for (i = 0; i < vec_len (my_vnet_mains); i++)
2709 im = &my_vnet_mains[i]->interface_main;
2710 cm = im->combined_sw_if_counters + j;
2711 if (mp->sw_if_index == (u32) ~ 0)
2712 vlib_clear_combined_counters (cm);
2714 vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
2718 n_counters = vec_len (im->sw_if_counters);
2720 for (j = 0; j < n_counters; j++)
2722 for (i = 0; i < vec_len (my_vnet_mains); i++)
2724 im = &my_vnet_mains[i]->interface_main;
2725 sm = im->sw_if_counters + j;
2726 if (mp->sw_if_index == (u32) ~ 0)
2727 vlib_clear_simple_counters (sm);
2729 vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
2733 BAD_SW_IF_INDEX_LABEL;
2735 REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2739 send_sw_interface_details (vpe_api_main_t * am,
2740 unix_shared_memory_queue_t * q,
2741 vnet_sw_interface_t * swif,
2742 u8 * interface_name, u32 context)
2744 vl_api_sw_interface_details_t *mp;
2745 vnet_hw_interface_t *hi;
2747 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2749 mp = vl_msg_api_alloc (sizeof (*mp));
2750 memset (mp, 0, sizeof (*mp));
2751 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
2752 mp->sw_if_index = ntohl (swif->sw_if_index);
2753 mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
2754 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2755 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2756 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2757 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2758 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2759 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2760 mp->link_mtu = ntohs (hi->max_packet_bytes);
2761 mp->context = context;
2763 strncpy ((char *) mp->interface_name,
2764 (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
2766 /* Send the L2 address for ethernet physical intfcs */
2767 if (swif->sup_sw_if_index == swif->sw_if_index
2768 && hi->hw_class_index == ethernet_hw_interface_class.index)
2770 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2771 ethernet_interface_t *ei;
2773 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2774 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2775 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2776 mp->l2_address_length = ntohl (sizeof (ei->address));
2778 else if (swif->sup_sw_if_index != swif->sw_if_index)
2780 vnet_sub_interface_t *sub = &swif->sub;
2781 mp->sub_id = ntohl (sub->id);
2782 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2783 mp->sub_number_of_tags =
2784 sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
2785 mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
2786 mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
2787 mp->sub_exact_match = sub->eth.flags.exact_match;
2788 mp->sub_default = sub->eth.flags.default_sub;
2789 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2790 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2792 /* vlan tag rewrite data */
2793 u32 vtr_op = L2_VTR_DISABLED;
2794 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2796 if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
2797 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
2799 // error - default to disabled
2800 mp->vtr_op = ntohl (L2_VTR_DISABLED);
2801 clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
2806 mp->vtr_op = ntohl (vtr_op);
2807 mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
2808 mp->vtr_tag1 = ntohl (vtr_tag1);
2809 mp->vtr_tag2 = ntohl (vtr_tag2);
2813 vl_msg_api_send_shmem (q, (u8 *) & mp);
2817 send_sw_interface_flags (vpe_api_main_t * am,
2818 unix_shared_memory_queue_t * q,
2819 vnet_sw_interface_t * swif)
2821 vl_api_sw_interface_set_flags_t *mp;
2822 vnet_main_t *vnm = am->vnet_main;
2824 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2826 mp = vl_msg_api_alloc (sizeof (*mp));
2827 memset (mp, 0, sizeof (*mp));
2828 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2829 mp->sw_if_index = ntohl (swif->sw_if_index);
2831 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
2832 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
2833 vl_msg_api_send_shmem (q, (u8 *) & mp);
2836 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2837 unix_shared_memory_queue_t * q,
2839 __attribute__ ((unused));
2842 send_sw_interface_flags_deleted (vpe_api_main_t * am,
2843 unix_shared_memory_queue_t * q,
2846 vl_api_sw_interface_set_flags_t *mp;
2848 mp = vl_msg_api_alloc (sizeof (*mp));
2849 memset (mp, 0, sizeof (*mp));
2850 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
2851 mp->sw_if_index = ntohl (sw_if_index);
2853 mp->admin_up_down = 0;
2854 mp->link_up_down = 0;
2856 vl_msg_api_send_shmem (q, (u8 *) & mp);
2860 vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
2862 vpe_api_main_t *am = &vpe_api_main;
2863 vnet_sw_interface_t *swif;
2864 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2865 u8 *filter_string = 0, *name_string = 0;
2866 unix_shared_memory_queue_t *q;
2867 char *strcasestr (char *, char *); /* lnx hdr file botch */
2869 q = vl_api_client_index_to_input_queue (mp->client_index);
2874 if (mp->name_filter_valid)
2876 mp->name_filter[ARRAY_LEN (mp->name_filter) - 1] = 0;
2877 filter_string = format (0, "%s%c", mp->name_filter, 0);
2881 pool_foreach (swif, im->sw_interfaces,
2883 name_string = format (name_string, "%U%c",
2884 format_vnet_sw_interface_name,
2885 am->vnet_main, swif, 0);
2887 if (mp->name_filter_valid == 0 ||
2888 strcasestr((char *) name_string, (char *) filter_string)) {
2890 send_sw_interface_details (am, q, swif, name_string, mp->context);
2892 _vec_len (name_string) = 0;
2896 vec_free (name_string);
2897 vec_free (filter_string);
2901 send_oam_event (oam_target_t * t)
2903 vpe_api_main_t *vam = &vpe_api_main;
2904 unix_shared_memory_queue_t *q;
2905 vpe_client_registration_t *reg;
2906 vl_api_oam_event_t *mp;
2909 pool_foreach(reg, vam->oam_events_registrations,
2911 q = vl_api_client_index_to_input_queue (reg->client_index);
2914 mp = vl_msg_api_alloc (sizeof (*mp));
2915 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2916 clib_memcpy (mp->dst_address, &t->dst_address,
2917 sizeof (mp->dst_address));
2918 mp->state = t->state;
2919 vl_msg_api_send_shmem (q, (u8 *)&mp);
2926 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t * mp)
2928 vl_api_oam_add_del_reply_t *rmp;
2931 rv = vpe_oam_add_del_target ((ip4_address_t *) mp->src_address,
2932 (ip4_address_t *) mp->dst_address,
2933 ntohl (mp->vrf_id), (int) (mp->is_add));
2935 REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
2939 vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp)
2941 stats_main_t *sm = &stats_main;
2942 vnet_interface_main_t *im = sm->interface_main;
2943 vl_api_vnet_summary_stats_reply_t *rmp;
2944 vlib_combined_counter_main_t *cm;
2947 u64 total_pkts[VLIB_N_RX_TX];
2948 u64 total_bytes[VLIB_N_RX_TX];
2950 unix_shared_memory_queue_t *q =
2951 vl_api_client_index_to_input_queue (mp->client_index);
2956 rmp = vl_msg_api_alloc (sizeof (*rmp));
2957 rmp->_vl_msg_id = ntohs (VL_API_VNET_SUMMARY_STATS_REPLY);
2958 rmp->context = mp->context;
2961 memset (total_pkts, 0, sizeof (total_pkts));
2962 memset (total_bytes, 0, sizeof (total_bytes));
2964 vnet_interface_counter_lock (im);
2966 vec_foreach (cm, im->combined_sw_if_counters)
2968 which = cm - im->combined_sw_if_counters;
2970 for (i = 0; i < vec_len (cm->maxi); i++)
2972 vlib_get_combined_counter (cm, i, &v);
2973 total_pkts[which] += v.packets;
2974 total_bytes[which] += v.bytes;
2977 vnet_interface_counter_unlock (im);
2979 rmp->total_pkts[VLIB_RX] = clib_host_to_net_u64 (total_pkts[VLIB_RX]);
2980 rmp->total_bytes[VLIB_RX] = clib_host_to_net_u64 (total_bytes[VLIB_RX]);
2981 rmp->total_pkts[VLIB_TX] = clib_host_to_net_u64 (total_pkts[VLIB_TX]);
2982 rmp->total_bytes[VLIB_TX] = clib_host_to_net_u64 (total_bytes[VLIB_TX]);
2984 clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main));
2986 vl_msg_api_send_shmem (q, (u8 *) & rmp);
2990 typedef CLIB_PACKED (struct {
2991 ip4_address_t address;
2992 u32 address_length: 6;
2998 ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3000 vnet_main_t *vnm = vnet_get_main ();
3001 vnet_interface_main_t *im = &vnm->interface_main;
3002 ip4_main_t *im4 = &ip4_main;
3003 static ip4_route_t *routes;
3004 static u32 *sw_if_indices_to_shut;
3005 stats_main_t *sm = &stats_main;
3010 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3011 u32 target_fib_id = ntohl (mp->vrf_id);
3013 dslock (sm, 1 /* release hint */ , 8 /* tag */ );
3015 vec_foreach (fib, im4->fibs)
3017 vnet_sw_interface_t *si;
3019 if (fib->table_id != target_fib_id)
3022 /* remove any mpls/gre tunnels in this fib */
3023 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
3025 /* remove any mpls encap/decap labels */
3026 mpls_fib_reset_labels (fib->table_id);
3028 /* remove any proxy arps in this fib */
3029 vnet_proxy_arp_fib_reset (fib->table_id);
3031 /* Set the flow hash for this fib to the default */
3032 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
3034 vec_reset_length (sw_if_indices_to_shut);
3036 /* Shut down interfaces in this FIB / clean out intfc routes */
3038 pool_foreach (si, im->sw_interfaces,
3040 u32 sw_if_index = si->sw_if_index;
3042 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
3043 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
3045 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3049 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3051 sw_if_index = sw_if_indices_to_shut[i];
3052 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3054 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3055 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3056 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3059 vec_reset_length (routes);
3061 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++)
3063 uword *hash = fib->adj_index_by_dst_address[i];
3067 x.address_length = i;
3070 hash_foreach_pair (p, hash,
3072 x.address.data_u32 = p->key;
3073 vec_add1 (routes, x);
3078 vec_foreach (r, routes)
3080 ip4_add_del_route_args_t a;
3082 memset (&a, 0, sizeof (a));
3083 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
3084 a.table_index_or_table_id = fib - im4->fibs;
3085 a.dst_address = r->address;
3086 a.dst_address_length = r->address_length;
3089 ip4_add_del_route (im4, &a);
3090 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
3091 IP4_ROUTE_FLAG_FIB_INDEX);
3095 } /* vec_foreach (fib) */
3103 ip6_address_t address;
3111 ip6_route_t **routep;
3112 } add_routes_in_fib_arg_t;
3115 add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
3117 add_routes_in_fib_arg_t *ap = arg;
3119 if (kvp->key[2] >> 32 == ap->fib_index)
3121 ip6_address_t *addr;
3123 addr = (ip6_address_t *) kvp;
3124 vec_add2 (*ap->routep, r, 1);
3125 r->address = addr[0];
3126 r->address_length = kvp->key[2] & 0xFF;
3127 r->index = kvp->value;
3132 ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3134 vnet_main_t *vnm = vnet_get_main ();
3135 vnet_interface_main_t *im = &vnm->interface_main;
3136 ip6_main_t *im6 = &ip6_main;
3137 stats_main_t *sm = &stats_main;
3138 static ip6_route_t *routes;
3139 static u32 *sw_if_indices_to_shut;
3144 int rv = VNET_API_ERROR_NO_SUCH_FIB;
3145 u32 target_fib_id = ntohl (mp->vrf_id);
3146 add_routes_in_fib_arg_t _a, *a = &_a;
3147 clib_bihash_24_8_t *h = &im6->ip6_lookup_table;
3149 dslock (sm, 1 /* release hint */ , 9 /* tag */ );
3151 vec_foreach (fib, im6->fibs)
3153 vnet_sw_interface_t *si;
3155 if (fib->table_id != target_fib_id)
3158 vec_reset_length (sw_if_indices_to_shut);
3160 /* Shut down interfaces in this FIB / clean out intfc routes */
3162 pool_foreach (si, im->sw_interfaces,
3164 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
3166 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
3170 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++)
3172 sw_if_index = sw_if_indices_to_shut[i];
3173 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
3175 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
3176 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
3177 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
3180 vec_reset_length (routes);
3182 a->fib_index = fib - im6->fibs;
3183 a->routep = &routes;
3185 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
3187 vec_foreach (r, routes)
3189 ip6_add_del_route_args_t a;
3191 memset (&a, 0, sizeof (a));
3192 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
3193 a.table_index_or_table_id = fib - im6->fibs;
3194 a.dst_address = r->address;
3195 a.dst_address_length = r->address_length;
3198 ip6_add_del_route (im6, &a);
3199 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
3200 IP6_ROUTE_FLAG_FIB_INDEX);
3203 /* Reinstall the neighbor / router discovery routes */
3204 vnet_ip6_fib_init (im6, fib - im6->fibs);
3206 } /* vec_foreach (fib) */
3213 vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp)
3216 vl_api_reset_fib_reply_t *rmp;
3219 rv = ip6_reset_fib_t_handler (mp);
3221 rv = ip4_reset_fib_t_handler (mp);
3223 REPLY_MACRO (VL_API_RESET_FIB_REPLY);
3228 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3230 vl_api_dhcp_proxy_config_reply_t *rmp;
3233 rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
3234 (ip4_address_t *) (&mp->dhcp_src_address),
3235 (u32) ntohl (mp->vrf_id),
3236 (int) mp->insert_circuit_id,
3237 (int) (mp->is_add == 0));
3239 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3244 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
3246 vl_api_dhcp_proxy_config_reply_t *rmp;
3249 rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
3250 (ip6_address_t *) (&mp->dhcp_src_address),
3251 (u32) ntohl (mp->vrf_id),
3252 (int) mp->insert_circuit_id,
3253 (int) (mp->is_add == 0));
3255 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
3259 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3261 vl_api_dhcp_proxy_config_reply_t *rmp;
3264 rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
3265 (ip4_address_t *) (&mp->dhcp_src_address),
3266 (u32) ntohl (mp->rx_vrf_id),
3267 (u32) ntohl (mp->server_vrf_id),
3268 (int) mp->insert_circuit_id,
3269 (int) (mp->is_add == 0));
3271 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3276 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
3278 vl_api_dhcp_proxy_config_reply_t *rmp;
3282 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
3283 (ip6_address_t *) (&mp->dhcp_src_address),
3284 (u32) ntohl (mp->rx_vrf_id),
3285 (u32) ntohl (mp->server_vrf_id),
3286 (int) mp->insert_circuit_id,
3287 (int) (mp->is_add == 0));
3289 rv = VNET_API_ERROR_UNIMPLEMENTED;
3292 REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3297 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
3299 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3302 rv = dhcp_proxy_set_option82_vss (ntohl (mp->tbl_id),
3305 (int) mp->is_add == 0);
3307 rv = dhcpv6_proxy_set_vss (ntohl (mp->tbl_id),
3309 ntohl (mp->fib_id), (int) mp->is_add == 0);
3311 REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
3315 static void vl_api_dhcp_proxy_config_t_handler
3316 (vl_api_dhcp_proxy_config_t * mp)
3318 if (mp->is_ipv6 == 0)
3319 dhcpv4_proxy_config (mp);
3321 dhcpv6_proxy_config (mp);
3324 static void vl_api_dhcp_proxy_config_2_t_handler
3325 (vl_api_dhcp_proxy_config_2_t * mp)
3327 if (mp->is_ipv6 == 0)
3328 dhcpv4_proxy_config_2 (mp);
3330 dhcpv6_proxy_config_2 (mp);
3334 dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3335 u8 is_ipv6, u8 * host_address, u8 * router_address,
3338 unix_shared_memory_queue_t *q;
3339 vl_api_dhcp_compl_event_t *mp;
3341 q = vl_api_client_index_to_input_queue (client_index);
3345 mp = vl_msg_api_alloc (sizeof (*mp));
3346 mp->client_index = client_index;
3348 mp->is_ipv6 = is_ipv6;
3349 clib_memcpy (&mp->hostname, hostname, vec_len (hostname));
3350 mp->hostname[vec_len (hostname) + 1] = '\n';
3351 clib_memcpy (&mp->host_address[0], host_address, 16);
3352 clib_memcpy (&mp->router_address[0], router_address, 16);
3353 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3355 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3357 vl_msg_api_send_shmem (q, (u8 *) & mp);
3360 static void vl_api_dhcp_client_config_t_handler
3361 (vl_api_dhcp_client_config_t * mp)
3363 vlib_main_t *vm = vlib_get_main ();
3364 vl_api_dhcp_client_config_reply_t *rmp;
3367 VALIDATE_SW_IF_INDEX (mp);
3369 rv = dhcp_client_config (vm, ntohl (mp->sw_if_index),
3370 mp->hostname, mp->is_add, mp->client_index,
3371 mp->want_dhcp_event ? dhcp_compl_event_callback :
3374 BAD_SW_IF_INDEX_LABEL;
3376 REPLY_MACRO (VL_API_DHCP_CLIENT_CONFIG_REPLY);
3380 vl_api_sw_interface_ip6nd_ra_config_t_handler
3381 (vl_api_sw_interface_ip6nd_ra_config_t * mp, vlib_main_t * vm)
3383 vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp;
3385 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease,
3388 is_no = mp->is_no == 1;
3389 suppress = mp->suppress == 1;
3390 managed = mp->managed == 1;
3391 other = mp->other == 1;
3392 ll_option = mp->ll_option == 1;
3393 send_unicast = mp->send_unicast == 1;
3394 cease = mp->cease == 1;
3395 default_router = mp->default_router == 1;
3397 VALIDATE_SW_IF_INDEX (mp);
3399 rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index),
3400 suppress, managed, other,
3401 ll_option, send_unicast, cease,
3402 default_router, ntohl (mp->lifetime),
3403 ntohl (mp->initial_count),
3404 ntohl (mp->initial_interval),
3405 ntohl (mp->max_interval),
3406 ntohl (mp->min_interval), is_no);
3408 BAD_SW_IF_INDEX_LABEL;
3410 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3414 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3415 (vl_api_sw_interface_ip6nd_ra_prefix_t * mp, vlib_main_t * vm)
3417 vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp;
3419 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3421 VALIDATE_SW_IF_INDEX (mp);
3423 is_no = mp->is_no == 1;
3424 use_default = mp->use_default == 1;
3425 no_advertise = mp->no_advertise == 1;
3426 off_link = mp->off_link == 1;
3427 no_autoconfig = mp->no_autoconfig == 1;
3428 no_onlink = mp->no_onlink == 1;
3430 rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index),
3431 (ip6_address_t *) mp->address,
3432 mp->address_length, use_default,
3433 ntohl (mp->val_lifetime),
3434 ntohl (mp->pref_lifetime), no_advertise,
3435 off_link, no_autoconfig, no_onlink, is_no);
3437 BAD_SW_IF_INDEX_LABEL;
3438 REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3442 vl_api_sw_interface_ip6_enable_disable_t_handler
3443 (vl_api_sw_interface_ip6_enable_disable_t * mp, vlib_main_t * vm)
3445 vl_api_sw_interface_ip6_enable_disable_reply_t *rmp;
3446 vnet_main_t *vnm = vnet_get_main ();
3448 clib_error_t *error;
3452 VALIDATE_SW_IF_INDEX (mp);
3455 (mp->enable == 1) ? enable_ip6_interface (vm,
3456 ntohl (mp->sw_if_index)) :
3457 disable_ip6_interface (vm, ntohl (mp->sw_if_index));
3461 clib_error_report (error);
3462 rv = VNET_API_ERROR_UNSPECIFIED;
3466 rv = vnm->api_errno;
3469 BAD_SW_IF_INDEX_LABEL;
3471 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3475 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3476 (vl_api_sw_interface_ip6_set_link_local_address_t * mp, vlib_main_t * vm)
3478 vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp;
3480 clib_error_t *error;
3481 vnet_main_t *vnm = vnet_get_main ();
3485 VALIDATE_SW_IF_INDEX (mp);
3487 error = set_ip6_link_local_address (vm,
3488 ntohl (mp->sw_if_index),
3489 (ip6_address_t *) mp->address,
3490 mp->address_length);
3493 clib_error_report (error);
3494 rv = VNET_API_ERROR_UNSPECIFIED;
3498 rv = vnm->api_errno;
3501 BAD_SW_IF_INDEX_LABEL;
3503 REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3507 set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3509 vl_api_set_ip_flow_hash_reply_t *rmp;
3510 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3512 clib_warning ("unimplemented...");
3514 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3518 set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp)
3520 vl_api_set_ip_flow_hash_reply_t *rmp;
3523 u32 flow_hash_config = 0;
3525 table_id = ntohl (mp->vrf_id);
3527 #define _(a,b) if (mp->a) flow_hash_config |= b;
3528 foreach_flow_hash_bit;
3531 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3533 REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY);
3538 vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp)
3540 if (mp->is_ipv6 == 0)
3541 set_ip4_flow_hash (mp);
3543 set_ip6_flow_hash (mp);
3546 static void vl_api_sw_interface_set_unnumbered_t_handler
3547 (vl_api_sw_interface_set_unnumbered_t * mp)
3549 vl_api_sw_interface_set_unnumbered_reply_t *rmp;
3551 vnet_sw_interface_t *si;
3552 vnet_main_t *vnm = vnet_get_main ();
3553 u32 sw_if_index, unnumbered_sw_if_index;
3555 sw_if_index = ntohl (mp->sw_if_index);
3556 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
3559 * The API message field names are backwards from
3560 * the underlying data structure names.
3561 * It's not worth changing them now.
3563 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3564 unnumbered_sw_if_index))
3566 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3570 /* Only check the "use loop0" field when setting the binding */
3572 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
3574 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3578 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3582 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3583 si->unnumbered_sw_if_index = sw_if_index;
3587 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3588 si->unnumbered_sw_if_index = (u32) ~ 0;
3592 REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3596 vl_api_create_loopback_t_handler (vl_api_create_loopback_t * mp)
3598 vl_api_create_loopback_reply_t *rmp;
3602 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3605 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3607 rmp->sw_if_index = ntohl (sw_if_index);
3613 vl_api_delete_loopback_t_handler (vl_api_delete_loopback_t * mp)
3615 vl_api_delete_loopback_reply_t *rmp;
3619 sw_if_index = ntohl (mp->sw_if_index);
3620 rv = vnet_delete_loopback_interface (sw_if_index);
3622 REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
3626 vl_api_control_ping_t_handler (vl_api_control_ping_t * mp)
3628 vl_api_control_ping_reply_t *rmp;
3632 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3634 rmp->vpe_pid = ntohl (getpid());
3639 static void vl_api_noprint_control_ping_t_handler
3640 (vl_api_noprint_control_ping_t * mp)
3642 vl_api_noprint_control_ping_reply_t *rmp;
3646 REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY,
3648 rmp->vpe_pid = ntohl (getpid());
3654 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3656 u8 **shmem_vecp = (u8 **) arg;
3659 api_main_t *am = &api_main;
3662 shmem_vec = *shmem_vecp;
3664 offset = vec_len (shmem_vec);
3666 pthread_mutex_lock (&am->vlib_rp->mutex);
3667 oldheap = svm_push_data_heap (am->vlib_rp);
3669 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3671 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3673 svm_pop_heap (oldheap);
3674 pthread_mutex_unlock (&am->vlib_rp->mutex);
3676 *shmem_vecp = shmem_vec;
3681 vl_api_cli_request_t_handler (vl_api_cli_request_t * mp)
3683 vl_api_cli_reply_t *rp;
3684 unix_shared_memory_queue_t *q;
3685 vlib_main_t *vm = vlib_get_main ();
3686 api_main_t *am = &api_main;
3687 unformat_input_t input;
3691 q = vl_api_client_index_to_input_queue (mp->client_index);
3695 rp = vl_msg_api_alloc (sizeof (*rp));
3696 rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
3697 rp->context = mp->context;
3699 unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
3701 vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
3703 pthread_mutex_lock (&am->vlib_rp->mutex);
3704 oldheap = svm_push_data_heap (am->vlib_rp);
3706 vec_add1 (shmem_vec, 0);
3708 svm_pop_heap (oldheap);
3709 pthread_mutex_unlock (&am->vlib_rp->mutex);
3711 rp->reply_in_shmem = (uword) shmem_vec;
3713 vl_msg_api_send_shmem (q, (u8 *) & rp);
3717 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3719 u8 **mem_vecp = (u8 **) arg;
3720 u8 *mem_vec = *mem_vecp;
3721 u32 offset = vec_len (mem_vec);
3723 vec_validate (mem_vec, offset + buffer_bytes - 1);
3724 clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
3725 *mem_vecp = mem_vec;
3729 vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
3731 vl_api_cli_inband_reply_t *rmp;
3733 unix_shared_memory_queue_t *q;
3734 vlib_main_t *vm = vlib_get_main ();
3735 unformat_input_t input;
3738 q = vl_api_client_index_to_input_queue (mp->client_index);
3742 unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length));
3743 vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
3745 u32 len = vec_len (out_vec);
3747 REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
3749 rmp->length = htonl (len);
3750 clib_memcpy (rmp->reply, out_vec, len);
3757 vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
3760 vl_api_set_arp_neighbor_limit_reply_t *rmp;
3761 vnet_main_t *vnm = vnet_get_main ();
3762 clib_error_t *error;
3767 error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit));
3769 error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit));
3773 clib_error_report (error);
3774 rv = VNET_API_ERROR_UNSPECIFIED;
3778 rv = vnm->api_errno;
3781 REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3784 static void vl_api_sr_tunnel_add_del_t_handler
3785 (vl_api_sr_tunnel_add_del_t * mp)
3788 clib_warning ("unimplemented");
3790 ip6_sr_add_del_tunnel_args_t _a, *a = &_a;
3792 vl_api_sr_tunnel_add_del_reply_t *rmp;
3793 ip6_address_t *segments = 0, *seg;
3794 ip6_address_t *tags = 0, *tag;
3795 ip6_address_t *this_address;
3798 if (mp->n_segments == 0)
3804 memset (a, 0, sizeof (*a));
3805 a->src_address = (ip6_address_t *) & mp->src_address;
3806 a->dst_address = (ip6_address_t *) & mp->dst_address;
3807 a->dst_mask_width = mp->dst_mask_width;
3808 a->flags_net_byte_order = mp->flags_net_byte_order;
3809 a->is_del = (mp->is_add == 0);
3810 a->rx_table_id = ntohl (mp->outer_vrf_id);
3811 a->tx_table_id = ntohl (mp->inner_vrf_id);
3813 a->name = format (0, "%s", mp->name);
3814 if (!(vec_len (a->name)))
3817 a->policy_name = format (0, "%s", mp->policy_name);
3818 if (!(vec_len (a->policy_name)))
3821 /* Yank segments and tags out of the API message */
3822 this_address = (ip6_address_t *) mp->segs_and_tags;
3823 for (i = 0; i < mp->n_segments; i++)
3825 vec_add2 (segments, seg, 1);
3826 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3829 for (i = 0; i < mp->n_tags; i++)
3831 vec_add2 (tags, tag, 1);
3832 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3836 a->segments = segments;
3839 rv = ip6_sr_add_del_tunnel (a);
3843 REPLY_MACRO (VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3847 static void vl_api_sr_policy_add_del_t_handler
3848 (vl_api_sr_policy_add_del_t * mp)
3851 clib_warning ("unimplemented");
3853 ip6_sr_add_del_policy_args_t _a, *a = &_a;
3855 vl_api_sr_policy_add_del_reply_t *rmp;
3858 memset (a, 0, sizeof (*a));
3859 a->is_del = (mp->is_add == 0);
3861 a->name = format (0, "%s", mp->name);
3862 if (!(vec_len (a->name)))
3864 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3868 if (!(mp->tunnel_names[0]))
3870 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3874 // start deserializing tunnel_names
3875 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3876 u8 *deser_tun_names = mp->tunnel_names;
3877 deser_tun_names += 1; //moving along
3880 int tun_name_len = 0;
3882 for (i = 0; i < num_tunnels; i++)
3884 tun_name_len = *deser_tun_names;
3885 deser_tun_names += 1;
3886 vec_resize (tun_name, tun_name_len);
3887 memcpy (tun_name, deser_tun_names, tun_name_len);
3888 vec_add1 (a->tunnel_names, tun_name);
3889 deser_tun_names += tun_name_len;
3893 rv = ip6_sr_add_del_policy (a);
3897 REPLY_MACRO (VL_API_SR_POLICY_ADD_DEL_REPLY);
3901 static void vl_api_sr_multicast_map_add_del_t_handler
3902 (vl_api_sr_multicast_map_add_del_t * mp)
3905 clib_warning ("unimplemented");
3907 ip6_sr_add_del_multicastmap_args_t _a, *a = &_a;
3909 vl_api_sr_multicast_map_add_del_reply_t *rmp;
3911 memset (a, 0, sizeof (*a));
3912 a->is_del = (mp->is_add == 0);
3914 a->multicast_address = (ip6_address_t *) & mp->multicast_address;
3915 a->policy_name = format (0, "%s", mp->policy_name);
3917 if (a->multicast_address == 0)
3923 if (!(a->policy_name))
3929 #if DPDK > 0 /* Cannot call replicate without DPDK */
3930 rv = ip6_sr_add_del_multicastmap (a);
3932 clib_warning ("multicast replication without DPDK not implemented");
3933 rv = VNET_API_ERROR_UNIMPLEMENTED;
3938 REPLY_MACRO (VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3942 #define foreach_classify_add_del_table_field \
3947 _(match_n_vectors) \
3948 _(next_table_index) \
3951 static void vl_api_classify_add_del_table_t_handler
3952 (vl_api_classify_add_del_table_t * mp)
3954 vl_api_classify_add_del_table_reply_t *rmp;
3955 vnet_classify_main_t *cm = &vnet_classify_main;
3956 vnet_classify_table_t *t;
3960 foreach_classify_add_del_table_field;
3963 #define _(a) a = ntohl(mp->a);
3964 foreach_classify_add_del_table_field;
3967 /* The underlying API fails silently, on purpose, so check here */
3968 if (mp->is_add == 0)
3969 if (pool_is_free_index (cm->tables, table_index))
3971 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3975 rv = vnet_classify_add_del_table
3976 (cm, mp->mask, nbuckets, memory_size,
3977 skip_n_vectors, match_n_vectors,
3978 next_table_index, miss_next_index, &table_index, mp->is_add);
3982 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3984 if (rv == 0 && mp->is_add)
3986 t = pool_elt_at_index (cm->tables, table_index);
3987 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3988 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3989 rmp->new_table_index = ntohl(table_index);
3993 rmp->skip_n_vectors = ~0;
3994 rmp->match_n_vectors = ~0;
3995 rmp->new_table_index = ~0;
4001 static void vl_api_classify_add_del_session_t_handler
4002 (vl_api_classify_add_del_session_t * mp)
4004 vnet_classify_main_t *cm = &vnet_classify_main;
4005 vl_api_classify_add_del_session_reply_t *rmp;
4007 u32 table_index, hit_next_index, opaque_index;
4010 table_index = ntohl (mp->table_index);
4011 hit_next_index = ntohl (mp->hit_next_index);
4012 opaque_index = ntohl (mp->opaque_index);
4013 advance = ntohl (mp->advance);
4015 rv = vnet_classify_add_del_session
4016 (cm, table_index, mp->match, hit_next_index, opaque_index,
4017 advance, mp->is_add);
4019 REPLY_MACRO (VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
4022 static void vl_api_classify_set_interface_ip_table_t_handler
4023 (vl_api_classify_set_interface_ip_table_t * mp)
4025 vlib_main_t *vm = vlib_get_main ();
4026 vl_api_classify_set_interface_ip_table_reply_t *rmp;
4028 u32 table_index, sw_if_index;
4030 table_index = ntohl (mp->table_index);
4031 sw_if_index = ntohl (mp->sw_if_index);
4033 VALIDATE_SW_IF_INDEX (mp);
4036 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
4038 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
4040 BAD_SW_IF_INDEX_LABEL;
4042 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
4045 static void vl_api_classify_set_interface_l2_tables_t_handler
4046 (vl_api_classify_set_interface_l2_tables_t * mp)
4048 vl_api_classify_set_interface_l2_tables_reply_t *rmp;
4050 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
4053 ip4_table_index = ntohl (mp->ip4_table_index);
4054 ip6_table_index = ntohl (mp->ip6_table_index);
4055 other_table_index = ntohl (mp->other_table_index);
4056 sw_if_index = ntohl (mp->sw_if_index);
4058 VALIDATE_SW_IF_INDEX (mp);
4061 rv = vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
4065 rv = vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
4071 if (ip4_table_index != ~0 || ip6_table_index != ~0
4072 || other_table_index != ~0)
4078 vnet_l2_input_classify_enable_disable (sw_if_index, enable);
4080 vnet_l2_output_classify_enable_disable (sw_if_index, enable);
4083 BAD_SW_IF_INDEX_LABEL;
4085 REPLY_MACRO (VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
4089 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
4092 vl_api_l2_fib_clear_table_reply_t *rmp;
4094 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
4095 * that is not currently implemented. When that TODO is fixed
4096 * this call should be changed to pass 1 instead of 0.
4098 l2fib_clear_table (0);
4100 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
4103 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
4104 u32 sw_if_index, u32 enable);
4107 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
4111 vl_api_l2_interface_efp_filter_reply_t *rmp;
4112 vnet_main_t *vnm = vnet_get_main ();
4114 // enable/disable the feature
4115 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
4116 rv = vnm->api_errno;
4118 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
4122 vl_api_l2_interface_vlan_tag_rewrite_t_handler
4123 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
4126 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
4127 vnet_main_t *vnm = vnet_get_main ();
4128 vlib_main_t *vm = vlib_get_main ();
4131 VALIDATE_SW_IF_INDEX (mp);
4133 vtr_op = ntohl (mp->vtr_op);
4135 /* The L2 code is unsuspicious */
4138 case L2_VTR_DISABLED:
4143 case L2_VTR_TRANSLATE_1_1:
4144 case L2_VTR_TRANSLATE_1_2:
4145 case L2_VTR_TRANSLATE_2_1:
4146 case L2_VTR_TRANSLATE_2_2:
4150 rv = VNET_API_ERROR_INVALID_VALUE;
4151 goto bad_sw_if_index;
4154 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
4155 ntohl (mp->push_dot1q), ntohl (mp->tag1),
4158 BAD_SW_IF_INDEX_LABEL;
4160 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
4164 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
4167 vl_api_create_vhost_user_if_reply_t *rmp;
4168 u32 sw_if_index = (u32) ~ 0;
4170 vnet_main_t *vnm = vnet_get_main ();
4171 vlib_main_t *vm = vlib_get_main ();
4173 #if DPDK > 0 && DPDK_VHOST_USER
4174 rv = dpdk_vhost_user_create_if (
4176 rv = vhost_user_create_if (
4178 vnm, vm, (char *) mp->sock_filename,
4179 mp->is_server, &sw_if_index, (u64) ~ 0,
4180 mp->renumber, ntohl (mp->custom_dev_instance),
4181 (mp->use_custom_mac) ? mp->mac_address : NULL);
4184 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
4186 rmp->sw_if_index = ntohl (sw_if_index);
4192 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
4195 vl_api_modify_vhost_user_if_reply_t *rmp;
4196 u32 sw_if_index = ntohl (mp->sw_if_index);
4198 vnet_main_t *vnm = vnet_get_main ();
4199 vlib_main_t *vm = vlib_get_main ();
4201 #if DPDK > 0 && DPDK_VHOST_USER
4202 rv = dpdk_vhost_user_modify_if (
4204 rv = vhost_user_modify_if (
4206 vnm, vm, (char *) mp->sock_filename,
4207 mp->is_server, sw_if_index, (u64) ~ 0,
4208 mp->renumber, ntohl (mp->custom_dev_instance));
4209 REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
4213 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
4216 vl_api_delete_vhost_user_if_reply_t *rmp;
4217 vpe_api_main_t *vam = &vpe_api_main;
4218 u32 sw_if_index = ntohl (mp->sw_if_index);
4220 vnet_main_t *vnm = vnet_get_main ();
4221 vlib_main_t *vm = vlib_get_main ();
4223 #if DPDK > 0 && DPDK_VHOST_USER
4224 rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index);
4226 rv = vhost_user_delete_if (vnm, vm, sw_if_index);
4229 REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
4232 unix_shared_memory_queue_t *q =
4233 vl_api_client_index_to_input_queue (mp->client_index);
4237 send_sw_interface_flags_deleted (vam, q, sw_if_index);
4242 vl_api_sw_interface_vhost_user_details_t_handler
4243 (vl_api_sw_interface_vhost_user_details_t * mp)
4245 clib_warning ("BUG");
4249 send_sw_interface_vhost_user_details (vpe_api_main_t * am,
4250 unix_shared_memory_queue_t * q,
4251 vhost_user_intf_details_t * vui,
4254 vl_api_sw_interface_vhost_user_details_t *mp;
4256 mp = vl_msg_api_alloc (sizeof (*mp));
4257 memset (mp, 0, sizeof (*mp));
4258 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
4259 mp->sw_if_index = ntohl (vui->sw_if_index);
4260 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
4261 mp->features = clib_net_to_host_u64 (vui->features);
4262 mp->is_server = vui->is_server;
4263 mp->num_regions = ntohl (vui->num_regions);
4264 mp->sock_errno = ntohl (vui->sock_errno);
4265 mp->context = context;
4267 strncpy ((char *) mp->sock_filename,
4268 (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
4269 strncpy ((char *) mp->interface_name,
4270 (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
4272 vl_msg_api_send_shmem (q, (u8 *) & mp);
4276 vl_api_sw_interface_vhost_user_dump_t_handler
4277 (vl_api_sw_interface_vhost_user_dump_t * mp)
4280 vpe_api_main_t *am = &vpe_api_main;
4281 vnet_main_t *vnm = vnet_get_main ();
4282 vlib_main_t *vm = vlib_get_main ();
4283 vhost_user_intf_details_t *ifaces = NULL;
4284 vhost_user_intf_details_t *vuid = NULL;
4285 unix_shared_memory_queue_t *q;
4287 q = vl_api_client_index_to_input_queue (mp->client_index);
4291 #if DPDK > 0 && DPDK_VHOST_USER
4292 rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces);
4294 rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
4299 vec_foreach (vuid, ifaces)
4301 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
4307 send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
4308 unix_shared_memory_queue_t * q,
4310 l2t_main_t * lm, u32 context)
4312 vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
4314 vnet_sw_interface_t *si = NULL;
4316 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
4318 if_name = format (if_name, "%U",
4319 format_vnet_sw_interface_name, lm->vnet_main, si);
4321 mp = vl_msg_api_alloc (sizeof (*mp));
4322 memset (mp, 0, sizeof (*mp));
4323 mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
4324 strncpy ((char *) mp->interface_name,
4325 (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
4326 mp->sw_if_index = ntohl (si->sw_if_index);
4327 mp->local_session_id = s->local_session_id;
4328 mp->remote_session_id = s->remote_session_id;
4329 mp->local_cookie[0] = s->local_cookie[0];
4330 mp->local_cookie[1] = s->local_cookie[1];
4331 mp->remote_cookie = s->remote_cookie;
4332 clib_memcpy (mp->client_address, &s->client_address,
4333 sizeof (s->client_address));
4334 clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
4335 mp->l2_sublayer_present = s->l2_sublayer_present;
4336 mp->context = context;
4338 vl_msg_api_send_shmem (q, (u8 *) & mp);
4342 send_ip_address_details (vpe_api_main_t * am,
4343 unix_shared_memory_queue_t * q,
4344 u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
4346 vl_api_ip_address_details_t *mp;
4348 mp = vl_msg_api_alloc (sizeof (*mp));
4349 memset (mp, 0, sizeof (*mp));
4350 mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
4354 clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
4358 u32 *tp = (u32 *) mp->ip;
4359 *tp = ntohl (*(u32 *) ip);
4361 mp->prefix_length = prefix_length;
4362 mp->context = context;
4364 vl_msg_api_send_shmem (q, (u8 *) & mp);
4368 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
4370 vpe_api_main_t *am = &vpe_api_main;
4371 unix_shared_memory_queue_t *q;
4374 ip6_main_t *im6 = &ip6_main;
4375 ip4_main_t *im4 = &ip4_main;
4376 ip_lookup_main_t *lm6 = &im6->lookup_main;
4377 ip_lookup_main_t *lm4 = &im4->lookup_main;
4378 ip_interface_address_t *ia = 0;
4379 u32 sw_if_index = ~0;
4380 int rv __attribute__ ((unused)) = 0;
4382 VALIDATE_SW_IF_INDEX (mp);
4384 sw_if_index = ntohl (mp->sw_if_index);
4386 q = vl_api_client_index_to_input_queue (mp->client_index);
4395 foreach_ip_interface_address (lm6, ia, sw_if_index,
4396 1 /* honor unnumbered */,
4398 r6 = ip_interface_address_get_address (lm6, ia);
4399 u16 prefix_length = ia->address_length;
4400 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4407 foreach_ip_interface_address (lm4, ia, sw_if_index,
4408 1 /* honor unnumbered */,
4410 r4 = ip_interface_address_get_address (lm4, ia);
4411 u16 prefix_length = ia->address_length;
4412 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4416 BAD_SW_IF_INDEX_LABEL;
4420 send_ip_details (vpe_api_main_t * am,
4421 unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
4423 vl_api_ip_details_t *mp;
4425 mp = vl_msg_api_alloc (sizeof (*mp));
4426 memset (mp, 0, sizeof (*mp));
4427 mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
4429 mp->sw_if_index = ntohl (sw_if_index);
4430 mp->context = context;
4432 vl_msg_api_send_shmem (q, (u8 *) & mp);
4436 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
4439 vpe_api_main_t *am = &vpe_api_main;
4440 l2t_main_t *lm = &l2t_main;
4441 unix_shared_memory_queue_t *q;
4442 l2t_session_t *session;
4444 q = vl_api_client_index_to_input_queue (mp->client_index);
4449 pool_foreach (session, lm->sessions,
4451 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4458 send_sw_interface_tap_details (vpe_api_main_t * am,
4459 unix_shared_memory_queue_t * q,
4460 tapcli_interface_details_t * tap_if,
4463 vl_api_sw_interface_tap_details_t *mp;
4464 mp = vl_msg_api_alloc (sizeof (*mp));
4465 memset (mp, 0, sizeof (*mp));
4466 mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
4467 mp->sw_if_index = ntohl (tap_if->sw_if_index);
4468 strncpy ((char *) mp->dev_name,
4469 (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
4470 mp->context = context;
4472 vl_msg_api_send_shmem (q, (u8 *) & mp);
4476 vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
4479 vpe_api_main_t *am = &vpe_api_main;
4480 unix_shared_memory_queue_t *q;
4481 tapcli_interface_details_t *tapifs = NULL;
4482 tapcli_interface_details_t *tap_if = NULL;
4484 q = vl_api_client_index_to_input_queue (mp->client_index);
4488 rv = vnet_tap_dump_ifs (&tapifs);
4492 vec_foreach (tap_if, tapifs)
4494 send_sw_interface_tap_details (am, q, tap_if, mp->context);
4501 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
4503 vpe_api_main_t *am = &vpe_api_main;
4504 vnet_main_t *vnm = vnet_get_main ();
4505 vlib_main_t *vm = vlib_get_main ();
4506 vnet_interface_main_t *im = &vnm->interface_main;
4507 unix_shared_memory_queue_t *q;
4508 vnet_sw_interface_t *si, *sorted_sis;
4509 u32 sw_if_index = ~0;
4511 q = vl_api_client_index_to_input_queue (mp->client_index);
4517 /* Gather interfaces. */
4518 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4519 _vec_len (sorted_sis) = 0;
4521 pool_foreach (si, im->sw_interfaces,
4523 vec_add1 (sorted_sis, si[0]);
4527 vec_foreach (si, sorted_sis)
4529 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
4531 if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
4535 sw_if_index = si->sw_if_index;
4536 send_ip_details (am, q, sw_if_index, mp->context);
4542 vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
4544 clib_warning ("BUG");
4548 send_l2fib_table_entry (vpe_api_main_t * am,
4549 unix_shared_memory_queue_t * q,
4550 l2fib_entry_key_t * l2fe_key,
4551 l2fib_entry_result_t * l2fe_res, u32 context)
4553 vl_api_l2_fib_table_entry_t *mp;
4555 mp = vl_msg_api_alloc (sizeof (*mp));
4556 memset (mp, 0, sizeof (*mp));
4557 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_ENTRY);
4560 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4562 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4563 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
4564 mp->static_mac = l2fe_res->fields.static_mac;
4565 mp->filter_mac = l2fe_res->fields.filter;
4566 mp->bvi_mac = l2fe_res->fields.bvi;
4567 mp->context = context;
4569 vl_msg_api_send_shmem (q, (u8 *) & mp);
4573 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
4575 vpe_api_main_t *am = &vpe_api_main;
4576 bd_main_t *bdm = &bd_main;
4577 l2fib_entry_key_t *l2fe_key = NULL;
4578 l2fib_entry_result_t *l2fe_res = NULL;
4579 u32 ni, bd_id = ntohl (mp->bd_id);
4581 unix_shared_memory_queue_t *q;
4584 q = vl_api_client_index_to_input_queue (mp->client_index);
4588 /* see l2fib_table_dump: ~0 means "any" */
4593 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4600 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4602 vec_foreach_index (ni, l2fe_key)
4604 send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
4605 vec_elt_at_index (l2fe_res, ni), mp->context);
4607 vec_free (l2fe_key);
4608 vec_free (l2fe_res);
4612 vl_api_show_version_t_handler (vl_api_show_version_t * mp)
4614 vl_api_show_version_reply_t *rmp;
4616 char *vpe_api_get_build_directory (void);
4617 char *vpe_api_get_version (void);
4618 char *vpe_api_get_build_date (void);
4620 unix_shared_memory_queue_t *q =
4621 vl_api_client_index_to_input_queue (mp->client_index);
4627 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4629 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4630 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4631 ARRAY_LEN(rmp->build_directory)-1);
4632 strncpy ((char *) rmp->version, vpe_api_get_version(),
4633 ARRAY_LEN(rmp->version)-1);
4634 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4635 ARRAY_LEN(rmp->build_date)-1);
4641 vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp)
4643 vlib_main_t *vm = vlib_get_main ();
4644 vl_api_get_node_index_reply_t *rmp;
4647 u32 node_index = ~0;
4649 n = vlib_get_node_by_name (vm, mp->node_name);
4652 rv = VNET_API_ERROR_NO_SUCH_NODE;
4654 node_index = n->index;
4657 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4659 rmp->node_index = ntohl(node_index);
4665 vl_api_get_next_index_t_handler (vl_api_get_next_index_t * mp)
4667 vlib_main_t *vm = vlib_get_main ();
4668 vl_api_get_next_index_reply_t *rmp;
4669 vlib_node_t *node, *next_node;
4671 u32 next_node_index = ~0, next_index = ~0;
4674 node = vlib_get_node_by_name (vm, mp->node_name);
4678 rv = VNET_API_ERROR_NO_SUCH_NODE;
4682 next_node = vlib_get_node_by_name (vm, mp->next_name);
4686 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4690 next_node_index = next_node->index;
4692 p = hash_get (node->next_slot_by_node, next_node_index);
4696 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4704 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4706 rmp->next_index = ntohl(next_index);
4712 vl_api_add_node_next_t_handler (vl_api_add_node_next_t * mp)
4714 vlib_main_t *vm = vlib_get_main ();
4715 vl_api_add_node_next_reply_t *rmp;
4716 vlib_node_t *n, *next;
4718 u32 next_index = ~0;
4720 n = vlib_get_node_by_name (vm, mp->node_name);
4724 rv = VNET_API_ERROR_NO_SUCH_NODE;
4728 next = vlib_get_node_by_name (vm, mp->next_name);
4731 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4733 next_index = vlib_node_add_next (vm, n->index, next->index);
4737 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4739 rmp->next_index = ntohl(next_index);
4744 static void vl_api_l2tpv3_create_tunnel_t_handler
4745 (vl_api_l2tpv3_create_tunnel_t * mp)
4747 vl_api_l2tpv3_create_tunnel_reply_t *rmp;
4748 l2t_main_t *lm = &l2t_main;
4749 u32 sw_if_index = (u32) ~ 0;
4752 if (mp->is_ipv6 != 1)
4754 rv = VNET_API_ERROR_UNIMPLEMENTED;
4758 u32 encap_fib_index;
4760 if (mp->encap_vrf_id != ~0)
4763 ip6_main_t *im = &ip6_main;
4766 hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id))))
4768 rv = VNET_API_ERROR_NO_SUCH_FIB;
4771 encap_fib_index = p[0];
4775 encap_fib_index = ~0;
4778 rv = create_l2tpv3_ipv6_tunnel (lm,
4779 (ip6_address_t *) mp->client_address,
4780 (ip6_address_t *) mp->our_address,
4781 ntohl (mp->local_session_id),
4782 ntohl (mp->remote_session_id),
4783 clib_net_to_host_u64 (mp->local_cookie),
4784 clib_net_to_host_u64 (mp->remote_cookie),
4785 mp->l2_sublayer_present,
4786 encap_fib_index, &sw_if_index);
4790 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4792 rmp->sw_if_index = ntohl (sw_if_index);
4797 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4798 (vl_api_l2tpv3_set_tunnel_cookies_t * mp)
4800 vl_api_l2tpv3_set_tunnel_cookies_reply_t *rmp;
4801 l2t_main_t *lm = &l2t_main;
4804 VALIDATE_SW_IF_INDEX (mp);
4806 rv = l2tpv3_set_tunnel_cookies (lm, ntohl (mp->sw_if_index),
4807 clib_net_to_host_u64 (mp->new_local_cookie),
4808 clib_net_to_host_u64
4809 (mp->new_remote_cookie));
4811 BAD_SW_IF_INDEX_LABEL;
4813 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4816 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4817 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4820 vnet_main_t *vnm = vnet_get_main ();
4821 vl_api_l2tpv3_interface_enable_disable_reply_t *rmp;
4823 VALIDATE_SW_IF_INDEX (mp);
4825 rv = l2tpv3_interface_enable_disable
4826 (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
4828 BAD_SW_IF_INDEX_LABEL;
4830 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4833 static void vl_api_l2tpv3_set_lookup_key_t_handler
4834 (vl_api_l2tpv3_set_lookup_key_t * mp)
4837 l2t_main_t *lm = &l2t_main;
4838 vl_api_l2tpv3_set_lookup_key_reply_t *rmp;
4840 if (mp->key > L2T_LOOKUP_SESSION_ID)
4842 rv = VNET_API_ERROR_INVALID_VALUE;
4846 lm->lookup_type = mp->key;
4849 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4852 static void vl_api_vxlan_add_del_tunnel_t_handler
4853 (vl_api_vxlan_add_del_tunnel_t * mp)
4855 vl_api_vxlan_add_del_tunnel_reply_t *rmp;
4857 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4858 u32 encap_fib_index;
4860 ip4_main_t *im = &ip4_main;
4861 u32 sw_if_index = ~0;
4863 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
4866 rv = VNET_API_ERROR_NO_SUCH_FIB;
4869 encap_fib_index = p[0];
4871 /* Check src & dst are different */
4872 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4873 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
4875 rv = VNET_API_ERROR_SAME_SRC_DST;
4878 memset (a, 0, sizeof (*a));
4880 a->is_add = mp->is_add;
4881 a->is_ip6 = mp->is_ipv6;
4883 /* ip addresses sent in network byte order */
4886 memcpy (&(a->src.ip6), mp->src_address, 16);
4887 memcpy (&(a->dst.ip6), mp->dst_address, 16);
4891 memcpy (&(a->src.ip4), mp->src_address, 4);
4892 memcpy (&(a->dst.ip4), mp->dst_address, 4);
4895 a->encap_fib_index = encap_fib_index;
4896 a->decap_next_index = ntohl (mp->decap_next_index);
4897 a->vni = ntohl (mp->vni);
4898 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4902 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4904 rmp->sw_if_index = ntohl (sw_if_index);
4909 static void send_vxlan_tunnel_details
4910 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4912 vl_api_vxlan_tunnel_details_t *rmp;
4913 ip4_main_t *im4 = &ip4_main;
4914 ip6_main_t *im6 = &ip6_main;
4915 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4917 rmp = vl_msg_api_alloc (sizeof (*rmp));
4918 memset (rmp, 0, sizeof (*rmp));
4919 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS);
4922 memcpy (rmp->src_address, &(t->src.ip6), 16);
4923 memcpy (rmp->dst_address, &(t->dst.ip6), 16);
4924 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
4928 memcpy (rmp->src_address, &(t->src.ip4), 4);
4929 memcpy (rmp->dst_address, &(t->dst.ip4), 4);
4930 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
4932 rmp->vni = htonl (t->vni);
4933 rmp->decap_next_index = htonl (t->decap_next_index);
4934 rmp->sw_if_index = htonl (t->sw_if_index);
4935 rmp->is_ipv6 = is_ipv6;
4936 rmp->context = context;
4938 vl_msg_api_send_shmem (q, (u8 *) & rmp);
4941 static void vl_api_vxlan_tunnel_dump_t_handler
4942 (vl_api_vxlan_tunnel_dump_t * mp)
4944 unix_shared_memory_queue_t *q;
4945 vxlan_main_t *vxm = &vxlan_main;
4949 q = vl_api_client_index_to_input_queue (mp->client_index);
4955 sw_if_index = ntohl (mp->sw_if_index);
4957 if (~0 == sw_if_index)
4960 pool_foreach (t, vxm->tunnels,
4962 send_vxlan_tunnel_details(t, q, mp->context);
4968 if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) ||
4969 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index]))
4973 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4974 send_vxlan_tunnel_details (t, q, mp->context);
4978 static void vl_api_gre_add_del_tunnel_t_handler
4979 (vl_api_gre_add_del_tunnel_t * mp)
4981 vl_api_gre_add_del_tunnel_reply_t *rmp;
4983 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4986 ip4_main_t *im = &ip4_main;
4987 u32 sw_if_index = ~0;
4989 p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
4992 rv = VNET_API_ERROR_NO_SUCH_FIB;
4995 outer_fib_id = p[0];
4997 /* Check src & dst are different */
4998 if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
4999 (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
5001 rv = VNET_API_ERROR_SAME_SRC_DST;
5004 memset (a, 0, sizeof (*a));
5006 a->is_add = mp->is_add;
5008 /* ip addresses sent in network byte order */
5009 clib_memcpy (&(a->src), mp->src_address, 4);
5010 clib_memcpy (&(a->dst), mp->dst_address, 4);
5012 a->outer_fib_id = outer_fib_id;
5013 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
5017 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
5019 rmp->sw_if_index = ntohl (sw_if_index);
5024 static void send_gre_tunnel_details
5025 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5027 vl_api_gre_tunnel_details_t *rmp;
5028 ip4_main_t *im = &ip4_main;
5030 rmp = vl_msg_api_alloc (sizeof (*rmp));
5031 memset (rmp, 0, sizeof (*rmp));
5032 rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
5033 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
5034 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
5035 rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
5036 rmp->sw_if_index = htonl (t->sw_if_index);
5037 rmp->context = context;
5039 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5043 vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
5045 unix_shared_memory_queue_t *q;
5046 gre_main_t *gm = &gre_main;
5050 q = vl_api_client_index_to_input_queue (mp->client_index);
5056 sw_if_index = ntohl (mp->sw_if_index);
5058 if (~0 == sw_if_index)
5061 pool_foreach (t, gm->tunnels,
5063 send_gre_tunnel_details(t, q, mp->context);
5069 if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
5070 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
5074 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
5075 send_gre_tunnel_details (t, q, mp->context);
5080 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
5082 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5084 vl_api_l2_patch_add_del_reply_t *rmp;
5085 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
5089 VALIDATE_RX_SW_IF_INDEX (mp);
5090 VALIDATE_TX_SW_IF_INDEX (mp);
5092 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
5093 ntohl (mp->tx_sw_if_index),
5094 (int) (mp->is_add != 0));
5096 BAD_RX_SW_IF_INDEX_LABEL;
5097 BAD_TX_SW_IF_INDEX_LABEL;
5099 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
5103 vl_api_vxlan_gpe_add_del_tunnel_t_handler
5104 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
5106 vl_api_vxlan_gpe_add_del_tunnel_reply_t *rmp;
5108 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
5109 u32 encap_fib_index, decap_fib_index;
5112 ip4_main_t *im = &ip4_main;
5113 u32 sw_if_index = ~0;
5116 p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
5119 rv = VNET_API_ERROR_NO_SUCH_FIB;
5122 encap_fib_index = p[0];
5124 protocol = mp->protocol;
5126 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
5127 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT)
5129 p = hash_get (im->fib_index_by_table_id, ntohl (mp->decap_vrf_id));
5132 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
5135 decap_fib_index = p[0];
5139 decap_fib_index = ntohl (mp->decap_vrf_id);
5142 /* Check src & dst are different */
5143 if ((mp->is_ipv6 && memcmp (mp->local, mp->remote, 16) == 0) ||
5144 (!mp->is_ipv6 && memcmp (mp->local, mp->remote, 4) == 0))
5146 rv = VNET_API_ERROR_SAME_SRC_DST;
5149 memset (a, 0, sizeof (*a));
5151 a->is_add = mp->is_add;
5152 a->is_ip6 = mp->is_ipv6;
5153 /* ip addresses sent in network byte order */
5156 clib_memcpy (&(a->local.ip6), mp->local, 16);
5157 clib_memcpy (&(a->remote.ip6), mp->remote, 16);
5161 clib_memcpy (&(a->local.ip4), mp->local, 4);
5162 clib_memcpy (&(a->remote.ip4), mp->remote, 4);
5164 a->encap_fib_index = encap_fib_index;
5165 a->decap_fib_index = decap_fib_index;
5166 a->protocol = protocol;
5167 a->vni = ntohl (mp->vni);
5168 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
5172 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
5174 rmp->sw_if_index = ntohl (sw_if_index);
5179 static void send_vxlan_gpe_tunnel_details
5180 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
5182 vl_api_vxlan_gpe_tunnel_details_t *rmp;
5183 ip4_main_t *im4 = &ip4_main;
5184 ip6_main_t *im6 = &ip6_main;
5185 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
5187 rmp = vl_msg_api_alloc (sizeof (*rmp));
5188 memset (rmp, 0, sizeof (*rmp));
5189 rmp->_vl_msg_id = ntohs (VL_API_VXLAN_GPE_TUNNEL_DETAILS);
5192 memcpy (rmp->local, &(t->local.ip6), 16);
5193 memcpy (rmp->remote, &(t->remote.ip6), 16);
5194 rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].table_id);
5195 rmp->decap_vrf_id = htonl (im6->fibs[t->decap_fib_index].table_id);
5199 memcpy (rmp->local, &(t->local.ip4), 4);
5200 memcpy (rmp->remote, &(t->remote.ip4), 4);
5201 rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].table_id);
5202 rmp->decap_vrf_id = htonl (im4->fibs[t->decap_fib_index].table_id);
5204 rmp->vni = htonl (t->vni);
5205 rmp->protocol = t->protocol;
5206 rmp->sw_if_index = htonl (t->sw_if_index);
5207 rmp->is_ipv6 = is_ipv6;
5208 rmp->context = context;
5210 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5213 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
5214 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
5216 unix_shared_memory_queue_t *q;
5217 vxlan_gpe_main_t *vgm = &vxlan_gpe_main;
5218 vxlan_gpe_tunnel_t *t;
5221 q = vl_api_client_index_to_input_queue (mp->client_index);
5227 sw_if_index = ntohl (mp->sw_if_index);
5229 if (~0 == sw_if_index)
5232 pool_foreach (t, vgm->tunnels,
5234 send_vxlan_gpe_tunnel_details(t, q, mp->context);
5240 if ((sw_if_index >= vec_len (vgm->tunnel_index_by_sw_if_index)) ||
5241 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index]))
5245 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
5246 send_vxlan_gpe_tunnel_details (t, q, mp->context);
5250 /** Used for transferring locators via VPP API */
5252 typedef CLIB_PACKED (struct {
5253 u32 sw_if_index; /**< locator sw_if_index */
5254 u8 priority; /**< locator priority */
5255 u8 weight; /**< locator weight */
5260 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
5263 vl_api_lisp_add_del_locator_set_reply_t *rmp;
5265 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5267 ls_locator_t *ls_loc;
5268 u32 ls_index = ~0, locator_num;
5269 u8 *locator_name = NULL;
5272 memset (a, 0, sizeof (a[0]));
5274 locator_name = format (0, "%s", mp->locator_set_name);
5276 a->name = locator_name;
5277 a->is_add = mp->is_add;
5279 locator_num = clib_net_to_host_u32 (mp->locator_num);
5281 memset (&locator, 0, sizeof (locator));
5282 for (i = 0; i < locator_num; i++)
5284 ls_loc = &((ls_locator_t *) mp->locators)[i];
5285 VALIDATE_SW_IF_INDEX (ls_loc);
5287 locator.sw_if_index = htonl (ls_loc->sw_if_index);
5288 locator.priority = ls_loc->priority;
5289 locator.weight = ls_loc->weight;
5291 vec_add1 (a->locators, locator);
5294 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
5296 BAD_SW_IF_INDEX_LABEL;
5298 vec_free (locator_name);
5299 vec_free (a->locators);
5302 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
5304 rmp->ls_index = clib_host_to_net_u32 (ls_index);
5310 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
5312 vl_api_lisp_add_del_locator_reply_t *rmp;
5314 locator_t locator, *locators = NULL;
5315 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
5317 u8 *locator_name = NULL;
5319 memset (&locator, 0, sizeof (locator));
5320 memset (a, 0, sizeof (a[0]));
5322 locator.sw_if_index = ntohl (mp->sw_if_index);
5323 locator.priority = mp->priority;
5324 locator.weight = mp->weight;
5326 vec_add1 (locators, locator);
5328 locator_name = format (0, "%s", mp->locator_set_name);
5330 a->name = locator_name;
5331 a->locators = locators;
5332 a->is_add = mp->is_add;
5335 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
5337 vec_free (locators);
5338 vec_free (locator_name);
5340 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
5344 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
5350 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5351 gid_address_ip_set (dst, src, IP4);
5352 gid_address_ippref_len (dst) = len;
5353 ip_prefix_normalize (&gid_address_ippref (dst));
5356 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
5357 gid_address_ip_set (dst, src, IP6);
5358 gid_address_ippref_len (dst) = len;
5359 ip_prefix_normalize (&gid_address_ippref (dst));
5361 case 2: /* l2 mac */
5362 gid_address_type (dst) = GID_ADDR_MAC;
5363 clib_memcpy (&gid_address_mac (dst), src, 6);
5367 return VNET_API_ERROR_INVALID_VALUE;
5370 gid_address_vni (dst) = vni;
5376 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
5378 vl_api_lisp_add_del_local_eid_reply_t *rmp;
5379 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5381 gid_address_t _eid, *eid = &_eid;
5383 u32 locator_set_index = ~0, map_index = ~0;
5384 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
5386 memset (a, 0, sizeof (a[0]));
5387 memset (eid, 0, sizeof (eid[0]));
5389 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5390 mp->eid_type, mp->eid, mp->prefix_len);
5394 name = format (0, "%s", mp->locator_set_name);
5395 p = hash_get_mem (lcm->locator_set_index_by_name, name);
5398 rv = VNET_API_ERROR_INVALID_VALUE;
5401 locator_set_index = p[0];
5403 /* XXX treat batch configuration */
5404 a->is_add = mp->is_add;
5405 gid_address_copy (&a->eid, eid);
5406 a->locator_set_index = locator_set_index;
5408 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
5412 gid_address_free (&a->eid);
5414 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
5418 vl_api_lisp_eid_table_add_del_map_t_handler
5419 (vl_api_lisp_eid_table_add_del_map_t * mp)
5421 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
5423 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
5424 clib_net_to_host_u32 (mp->dp_table),
5425 mp->is_l2, mp->is_add);
5426 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
5428 /** Used for transferring locators via VPP API */
5430 typedef CLIB_PACKED (struct {
5431 u8 is_ip4; /**< is locator an IPv4 address */
5432 u8 priority; /**< locator priority */
5433 u8 weight; /**< locator weight */
5434 u8 addr[16]; /**< IPv4/IPv6 address */
5438 static locator_pair_t *
5439 unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
5442 locator_pair_t *pairs = 0, pair;
5445 for (i = 0; i < rloc_num; i++)
5448 r = &((rloc_t *) lcl_locs)[i];
5449 memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
5450 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5452 /* remote locators */
5453 r = &((rloc_t *) rmt_locs)[i];
5454 memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
5455 ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
5457 pair.priority = r->priority;
5458 pair.weight = r->weight;
5460 vec_add1 (pairs, pair);
5466 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
5469 locator_t *locs = 0, loc;
5472 for (i = 0; i < rloc_num; i++)
5474 /* remote locators */
5475 r = &((rloc_t *) rmt_locs)[i];
5476 memset (&loc, 0, sizeof (loc));
5477 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
5479 loc.priority = r->priority;
5480 loc.weight = r->weight;
5482 vec_add1 (locs, loc);
5488 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
5489 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
5491 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5492 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
5493 locator_pair_t *pairs = 0;
5496 memset (a, 0, sizeof (a[0]));
5498 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
5499 mp->rmt_eid, mp->rmt_len);
5500 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
5501 mp->lcl_eid, mp->lcl_len);
5503 pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
5505 if (rv || 0 == pairs)
5508 a->is_add = mp->is_add;
5509 a->locator_pairs = pairs;
5510 a->dp_table = mp->dp_table;
5512 a->action = mp->action;
5514 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
5517 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5521 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
5524 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5526 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
5528 memset (a, 0, sizeof (a[0]));
5530 a->is_add = mp->is_add;
5531 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
5533 rv = vnet_lisp_add_del_map_resolver (a);
5535 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5539 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
5542 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5544 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
5546 a->is_en = mp->is_en;
5547 vnet_lisp_gpe_enable_disable (a);
5549 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5553 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
5555 vl_api_lisp_enable_disable_reply_t *rmp;
5558 vnet_lisp_enable_disable (mp->is_en);
5559 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
5563 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
5565 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5567 vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
5569 a->is_add = mp->is_add;
5570 a->dp_table = mp->dp_table;
5572 a->is_l2 = mp->is_l2;
5573 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5575 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5579 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
5582 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5586 ls_name = format (0, "%s", mp->ls_name);
5587 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5590 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5594 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5595 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
5597 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5599 u8 *locator_set_name = NULL;
5600 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
5602 locator_set_name = format (0, "%s", mp->locator_set_name);
5604 a->is_add = mp->is_add;
5605 a->locator_set_name = locator_set_name;
5607 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
5609 vec_free (locator_set_name);
5611 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5615 vl_api_lisp_add_del_remote_mapping_t_handler
5616 (vl_api_lisp_add_del_remote_mapping_t * mp)
5618 locator_t *rlocs = 0;
5619 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
5621 gid_address_t _eid, *eid = &_eid;
5622 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
5624 memset (eid, 0, sizeof (eid[0]));
5626 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5627 mp->eid_type, mp->eid, mp->eid_len);
5631 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
5635 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5636 gid_address_copy (&a->deid, eid);
5638 rv = vnet_lisp_add_del_adjacency (a);
5645 /* NOTE: for now this works as a static remote mapping, i.e.,
5646 * not authoritative and ttl infinite. */
5647 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5648 mp->is_add, 1 /* is_static */ , 0);
5651 vnet_lisp_clear_all_remote_adjacencies ();
5656 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5660 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
5662 vl_api_lisp_add_del_adjacency_reply_t *rmp;
5663 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
5666 memset (a, 0, sizeof (a[0]));
5668 rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
5669 mp->eid_type, mp->seid, mp->seid_len);
5670 rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
5671 mp->eid_type, mp->deid, mp->deid_len);
5676 a->is_add = mp->is_add;
5677 rv = vnet_lisp_add_del_adjacency (a);
5680 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5684 send_lisp_locator_details (lisp_cp_main_t * lcm,
5686 unix_shared_memory_queue_t * q, u32 context)
5688 vl_api_lisp_locator_details_t *rmp;
5690 rmp = vl_msg_api_alloc (sizeof (*rmp));
5691 memset (rmp, 0, sizeof (*rmp));
5692 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
5693 rmp->context = context;
5695 rmp->local = loc->local;
5698 rmp->sw_if_index = ntohl (loc->sw_if_index);
5702 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
5703 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
5705 rmp->priority = loc->priority;
5706 rmp->weight = loc->weight;
5708 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5712 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
5714 unix_shared_memory_queue_t *q = 0;
5715 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5716 locator_set_t *lsit = 0;
5718 u32 ls_index = ~0, *locit = 0;
5721 q = vl_api_client_index_to_input_queue (mp->client_index);
5727 ls_index = htonl (mp->locator_set_index);
5729 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
5731 filter = mp->filter;
5732 if (filter && !((1 == filter && lsit->local) ||
5733 (2 == filter && !lsit->local)))
5738 vec_foreach (locit, lsit->locator_indices)
5740 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
5741 send_lisp_locator_details (lcm, loc, q, mp->context);
5746 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
5747 locator_set_t * lsit,
5748 unix_shared_memory_queue_t * q,
5749 u32 context, u32 ls_index)
5751 vl_api_lisp_locator_set_details_t *rmp;
5754 rmp = vl_msg_api_alloc (sizeof (*rmp));
5755 memset (rmp, 0, sizeof (*rmp));
5756 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
5757 rmp->context = context;
5759 rmp->local = lsit->local;
5760 rmp->locator_set_index = htonl (ls_index);
5763 ASSERT (lsit->name != NULL);
5764 strncpy ((char *) rmp->locator_set_name,
5765 (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1);
5769 str = format (0, "remote-%d", ls_index);
5770 strncpy ((char *) rmp->locator_set_name, (char *) str,
5771 ARRAY_LEN (rmp->locator_set_name) - 1);
5775 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5779 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
5781 unix_shared_memory_queue_t *q = NULL;
5782 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5783 locator_set_t *lsit = NULL;
5787 q = vl_api_client_index_to_input_queue (mp->client_index);
5793 filter = mp->filter;
5796 pool_foreach (lsit, lcm->locator_set_pool,
5798 if (filter && !((1 == filter && lsit->local) ||
5799 (2 == filter && !lsit->local))) {
5803 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5809 send_lisp_eid_table_details (mapping_t * mapit,
5810 unix_shared_memory_queue_t * q,
5811 u32 context, u8 filter)
5813 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5814 locator_set_t *ls = 0;
5815 vl_api_lisp_eid_table_details_t *rmp = NULL;
5816 gid_address_t *gid = NULL;
5818 ip_prefix_t *ip_prefix = NULL;
5822 case 0: /* all mappings */
5825 case 1: /* local only */
5829 case 2: /* remote only */
5834 clib_warning ("Filter error, unknown filter: %d", filter);
5839 ip_prefix = &gid_address_ippref (gid);
5840 mac = gid_address_mac (gid);
5842 rmp = vl_msg_api_alloc (sizeof (*rmp));
5843 memset (rmp, 0, sizeof (*rmp));
5844 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
5846 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
5847 if (vec_len (ls->locator_indices) == 0)
5848 rmp->locator_set_index = ~0;
5850 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
5852 rmp->is_local = mapit->local;
5853 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
5854 rmp->action = mapit->action;
5855 rmp->authoritative = mapit->authoritative;
5857 switch (gid_address_type (gid))
5859 case GID_ADDR_IP_PREFIX:
5860 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
5861 if (ip_prefix_version (ip_prefix) == IP4)
5863 rmp->eid_type = 0; /* ipv4 type */
5864 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
5865 sizeof (ip_prefix_v4 (ip_prefix)));
5869 rmp->eid_type = 1; /* ipv6 type */
5870 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
5871 sizeof (ip_prefix_v6 (ip_prefix)));
5875 rmp->eid_type = 2; /* l2 mac type */
5876 clib_memcpy (rmp->eid, mac, 6);
5881 rmp->context = context;
5882 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5883 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5887 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
5890 unix_shared_memory_queue_t *q = NULL;
5891 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
5892 mapping_t *mapit = NULL;
5893 gid_address_t _eid, *eid = &_eid;
5895 q = vl_api_client_index_to_input_queue (mp->client_index);
5903 memset (eid, 0, sizeof (*eid));
5905 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
5906 mp->eid_type, mp->eid, mp->prefix_length);
5908 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5909 if ((u32) ~ 0 == mi)
5912 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5913 send_lisp_eid_table_details (mapit, q, mp->context,
5914 0 /* ignore filter */ );
5919 pool_foreach (mapit, lcm->mapping_pool,
5921 send_lisp_eid_table_details(mapit, q, mp->context,
5929 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t * tunnel,
5930 unix_shared_memory_queue_t * q, u32 context)
5932 vl_api_lisp_gpe_tunnel_details_t *rmp;
5933 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5935 rmp = vl_msg_api_alloc (sizeof (*rmp));
5936 memset (rmp, 0, sizeof (*rmp));
5937 rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
5939 rmp->tunnels = tunnel - lgm->tunnels;
5941 rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
5942 ip_address_copy_addr (rmp->source_ip, &tunnel->src);
5943 ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
5945 rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
5946 rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
5947 rmp->dcap_next = htonl (tunnel->decap_next_index);
5948 rmp->lisp_ver = tunnel->ver_res;
5949 rmp->next_protocol = tunnel->next_protocol;
5950 rmp->flags = tunnel->flags;
5951 rmp->ver_res = tunnel->ver_res;
5952 rmp->res = tunnel->res;
5953 rmp->iid = htonl (tunnel->vni);
5954 rmp->context = context;
5956 vl_msg_api_send_shmem (q, (u8 *) & rmp);
5960 vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
5962 unix_shared_memory_queue_t *q = NULL;
5963 lisp_gpe_main_t *lgm = &lisp_gpe_main;
5964 lisp_gpe_tunnel_t *tunnel = NULL;
5966 if (pool_elts (lgm->tunnels) == 0)
5971 q = vl_api_client_index_to_input_queue (mp->client_index);
5978 pool_foreach(tunnel, lgm->tunnels,
5980 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5986 send_lisp_map_resolver_details (ip_address_t * ip,
5987 unix_shared_memory_queue_t * q, u32 context)
5989 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5991 rmp = vl_msg_api_alloc (sizeof (*rmp));
5992 memset (rmp, 0, sizeof (*rmp));
5993 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
5995 switch (ip_addr_version (ip))
5999 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
6000 sizeof (ip_addr_v4 (ip)));
6005 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
6006 sizeof (ip_addr_v6 (ip)));
6012 rmp->context = context;
6014 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6018 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
6020 unix_shared_memory_queue_t *q = NULL;
6021 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6024 q = vl_api_client_index_to_input_queue (mp->client_index);
6030 vec_foreach (mr, lcm->map_resolvers)
6032 send_lisp_map_resolver_details (&mr->address, q, mp->context);
6037 send_eid_table_map_pair (hash_pair_t * p,
6038 unix_shared_memory_queue_t * q, u32 context)
6040 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
6042 rmp = vl_msg_api_alloc (sizeof (*rmp));
6043 memset (rmp, 0, sizeof (*rmp));
6044 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
6046 rmp->vni = clib_host_to_net_u32 (p->key);
6047 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
6048 rmp->context = context;
6049 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6053 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
6056 unix_shared_memory_queue_t *q = NULL;
6057 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6059 uword *vni_table = 0;
6061 q = vl_api_client_index_to_input_queue (mp->client_index);
6069 vni_table = lcm->bd_id_by_vni;
6073 vni_table = lcm->table_id_by_vni;
6077 hash_foreach_pair (p, vni_table,
6079 send_eid_table_map_pair (p, q, mp->context);
6085 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
6087 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
6089 rmp = vl_msg_api_alloc (sizeof (*rmp));
6090 memset (rmp, 0, sizeof (*rmp));
6091 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
6092 rmp->context = context;
6093 rmp->vni = clib_host_to_net_u32 (vni);
6094 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6098 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
6103 unix_shared_memory_queue_t *q = 0;
6104 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6106 q = vl_api_client_index_to_input_queue (mp->client_index);
6113 hash_foreach_pair (p, lcm->table_id_by_vni,
6115 hash_set (vnis, p->key, 0);
6118 hash_foreach_pair (p, lcm->bd_id_by_vni,
6120 hash_set (vnis, p->key, 0);
6123 hash_foreach_pair (p, vnis,
6125 send_eid_table_vni (p->key, q, mp->context);
6133 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
6135 unix_shared_memory_queue_t *q = NULL;
6136 vl_api_show_lisp_status_reply_t *rmp = NULL;
6139 q = vl_api_client_index_to_input_queue (mp->client_index);
6146 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
6148 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
6149 rmp->feature_status = vnet_lisp_enable_disable_status ();
6155 vl_api_lisp_get_map_request_itr_rlocs_t_handler
6156 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
6158 unix_shared_memory_queue_t *q = NULL;
6159 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
6160 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6161 locator_set_t *loc_set = 0;
6165 q = vl_api_client_index_to_input_queue (mp->client_index);
6171 if (~0 == lcm->mreq_itr_rlocs)
6173 tmp_str = format (0, " ");
6178 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
6179 tmp_str = format (0, "%s", loc_set->name);
6183 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
6185 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6186 ARRAY_LEN(rmp->locator_set_name) - 1);
6194 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
6196 unix_shared_memory_queue_t *q = NULL;
6197 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
6198 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
6200 locator_set_t *ls = 0;
6204 q = vl_api_client_index_to_input_queue (mp->client_index);
6210 if (!lcm->lisp_pitr)
6212 tmp_str = format (0, "N/A");
6216 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
6217 if (~0 != m->locator_set_index)
6220 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
6221 tmp_str = format (0, "%s", ls->name);
6225 tmp_str = format (0, "N/A");
6228 vec_add1 (tmp_str, 0);
6231 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
6233 rmp->status = lcm->lisp_pitr;
6234 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
6235 ARRAY_LEN(rmp->locator_set_name) - 1);
6241 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *
6244 vl_api_interface_name_renumber_reply_t *rmp;
6247 VALIDATE_SW_IF_INDEX (mp);
6249 rv = vnet_interface_name_renumber
6250 (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
6252 BAD_SW_IF_INDEX_LABEL;
6254 REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
6258 arp_change_data_callback (u32 pool_index, u8 * new_mac,
6259 u32 sw_if_index, u32 address)
6261 vpe_api_main_t *am = &vpe_api_main;
6262 vlib_main_t *vm = am->vlib_main;
6263 vl_api_ip4_arp_event_t *event;
6264 static f64 arp_event_last_time;
6265 f64 now = vlib_time_now (vm);
6267 if (pool_is_free_index (am->arp_events, pool_index))
6270 event = pool_elt_at_index (am->arp_events, pool_index);
6272 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6274 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6278 if (sw_if_index == event->sw_if_index &&
6280 /* for BD case, also check IP address with 10 sec timeout */
6281 (address == event->address &&
6282 (now - arp_event_last_time) < 10.0)))
6287 arp_event_last_time = now;
6288 event->sw_if_index = sw_if_index;
6290 event->address = address;
6295 nd_change_data_callback (u32 pool_index, u8 * new_mac,
6296 u32 sw_if_index, ip6_address_t * address)
6298 vpe_api_main_t *am = &vpe_api_main;
6299 vlib_main_t *vm = am->vlib_main;
6300 vl_api_ip6_nd_event_t *event;
6301 static f64 nd_event_last_time;
6302 f64 now = vlib_time_now (vm);
6304 if (pool_is_free_index (am->nd_events, pool_index))
6307 event = pool_elt_at_index (am->nd_events, pool_index);
6310 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac)))
6312 clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac));
6316 if (sw_if_index == event->sw_if_index &&
6318 /* for BD case, also check IP address with 10 sec timeout */
6319 (ip6_address_is_equal (address,
6320 (ip6_address_t *) event->address) &&
6321 (now - nd_event_last_time) < 10.0)))
6326 nd_event_last_time = now;
6327 event->sw_if_index = sw_if_index;
6329 clib_memcpy (event->address, address, sizeof (event->address));
6334 arp_change_delete_callback (u32 pool_index, u8 * notused)
6336 vpe_api_main_t *am = &vpe_api_main;
6338 if (pool_is_free_index (am->arp_events, pool_index))
6341 pool_put_index (am->arp_events, pool_index);
6346 nd_change_delete_callback (u32 pool_index, u8 * notused)
6348 vpe_api_main_t *am = &vpe_api_main;
6350 if (pool_is_free_index (am->nd_events, pool_index))
6353 pool_put_index (am->nd_events, pool_index);
6358 vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp)
6360 vpe_api_main_t *am = &vpe_api_main;
6361 vnet_main_t *vnm = vnet_get_main ();
6362 vl_api_want_ip4_arp_events_reply_t *rmp;
6363 vl_api_ip4_arp_event_t *event;
6366 if (mp->enable_disable)
6368 pool_get (am->arp_events, event);
6369 memset (event, 0, sizeof (*event));
6371 event->_vl_msg_id = ntohs (VL_API_IP4_ARP_EVENT);
6372 event->client_index = mp->client_index;
6373 event->context = mp->context;
6374 event->address = mp->address;
6375 event->pid = mp->pid;
6376 if (mp->address == 0)
6379 rv = vnet_add_del_ip4_arp_change_event
6380 (vnm, arp_change_data_callback,
6381 mp->pid, &mp->address /* addr, in net byte order */ ,
6382 vpe_resolver_process_node.index,
6383 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ );
6387 rv = vnet_add_del_ip4_arp_change_event
6388 (vnm, arp_change_delete_callback,
6389 mp->pid, &mp->address /* addr, in net byte order */ ,
6390 vpe_resolver_process_node.index,
6391 IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6393 REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY);
6397 vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
6399 vpe_api_main_t *am = &vpe_api_main;
6400 vnet_main_t *vnm = vnet_get_main ();
6401 vl_api_want_ip6_nd_events_reply_t *rmp;
6402 vl_api_ip6_nd_event_t *event;
6405 if (mp->enable_disable)
6407 pool_get (am->nd_events, event);
6408 memset (event, 0, sizeof (*event));
6410 event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
6411 event->client_index = mp->client_index;
6412 event->context = mp->context;
6413 clib_memcpy (event->address, mp->address, 16);
6414 event->pid = mp->pid;
6415 if (ip6_address_is_zero ((ip6_address_t *) mp->address))
6418 rv = vnet_add_del_ip6_nd_change_event
6419 (vnm, nd_change_data_callback,
6420 mp->pid, mp->address /* addr, in net byte order */ ,
6421 vpe_resolver_process_node.index,
6422 IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
6426 rv = vnet_add_del_ip6_nd_change_event
6427 (vnm, nd_change_delete_callback,
6428 mp->pid, mp->address /* addr, in net byte order */ ,
6429 vpe_resolver_process_node.index,
6430 IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
6432 REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY);
6435 static void vl_api_input_acl_set_interface_t_handler
6436 (vl_api_input_acl_set_interface_t * mp)
6438 vlib_main_t *vm = vlib_get_main ();
6439 vl_api_input_acl_set_interface_reply_t *rmp;
6441 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6443 ip4_table_index = ntohl (mp->ip4_table_index);
6444 ip6_table_index = ntohl (mp->ip6_table_index);
6445 l2_table_index = ntohl (mp->l2_table_index);
6446 sw_if_index = ntohl (mp->sw_if_index);
6448 VALIDATE_SW_IF_INDEX (mp);
6450 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
6451 ip6_table_index, l2_table_index, mp->is_add);
6453 BAD_SW_IF_INDEX_LABEL;
6455 REPLY_MACRO (VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
6458 static void vl_api_ipsec_spd_add_del_t_handler
6459 (vl_api_ipsec_spd_add_del_t * mp)
6462 clib_warning ("unimplemented");
6465 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6466 vl_api_ipsec_spd_add_del_reply_t *rmp;
6470 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
6472 rv = VNET_API_ERROR_UNIMPLEMENTED;
6475 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
6479 static void vl_api_ipsec_interface_add_del_spd_t_handler
6480 (vl_api_ipsec_interface_add_del_spd_t * mp)
6482 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6483 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
6485 u32 sw_if_index __attribute__ ((unused));
6486 u32 spd_id __attribute__ ((unused));
6488 sw_if_index = ntohl (mp->sw_if_index);
6489 spd_id = ntohl (mp->spd_id);
6491 VALIDATE_SW_IF_INDEX (mp);
6494 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
6496 rv = VNET_API_ERROR_UNIMPLEMENTED;
6499 BAD_SW_IF_INDEX_LABEL;
6501 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
6504 static void vl_api_ipsec_spd_add_del_entry_t_handler
6505 (vl_api_ipsec_spd_add_del_entry_t * mp)
6507 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6508 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
6514 memset (&p, 0, sizeof (p));
6516 p.id = ntohl (mp->spd_id);
6517 p.priority = ntohl (mp->priority);
6518 p.is_outbound = mp->is_outbound;
6519 p.is_ipv6 = mp->is_ipv6;
6521 if (mp->is_ipv6 || mp->is_ip_any)
6523 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
6524 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
6525 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
6526 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
6530 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
6531 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
6532 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
6533 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
6535 p.protocol = mp->protocol;
6536 p.rport.start = ntohs (mp->remote_port_start);
6537 p.rport.stop = ntohs (mp->remote_port_stop);
6538 p.lport.start = ntohs (mp->local_port_start);
6539 p.lport.stop = ntohs (mp->local_port_stop);
6540 /* policy action resolve unsupported */
6541 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
6543 clib_warning ("unsupported action: 'resolve'");
6544 rv = VNET_API_ERROR_UNIMPLEMENTED;
6547 p.policy = mp->policy;
6548 p.sa_id = ntohl (mp->sa_id);
6550 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6557 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
6560 rv = VNET_API_ERROR_UNIMPLEMENTED;
6565 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
6568 static void vl_api_ipsec_sad_add_del_entry_t_handler
6569 (vl_api_ipsec_sad_add_del_entry_t * mp)
6571 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6572 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
6577 memset (&sa, 0, sizeof (sa));
6579 sa.id = ntohl (mp->sad_id);
6580 sa.spi = ntohl (mp->spi);
6581 /* security protocol AH unsupported */
6582 if (mp->protocol == IPSEC_PROTOCOL_AH)
6584 clib_warning ("unsupported security protocol 'AH'");
6585 rv = VNET_API_ERROR_UNIMPLEMENTED;
6588 sa.protocol = mp->protocol;
6589 /* check for unsupported crypto-alg */
6590 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
6591 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256)
6593 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
6594 mp->crypto_algorithm);
6595 rv = VNET_API_ERROR_UNIMPLEMENTED;
6598 sa.crypto_alg = mp->crypto_algorithm;
6599 sa.crypto_key_len = mp->crypto_key_length;
6600 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6601 /* check for unsupported integ-alg */
6602 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
6603 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256)
6605 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
6606 mp->integrity_algorithm);
6607 rv = VNET_API_ERROR_UNIMPLEMENTED;
6610 sa.integ_alg = mp->integrity_algorithm;
6611 sa.integ_key_len = mp->integrity_key_length;
6612 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6613 sa.use_esn = mp->use_extended_sequence_number;
6614 sa.is_tunnel = mp->is_tunnel;
6615 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6616 if (sa.is_tunnel_ip6)
6618 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6619 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6623 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6624 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6627 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
6629 rv = VNET_API_ERROR_UNIMPLEMENTED;
6634 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6638 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
6640 vl_api_ikev2_profile_add_del_reply_t *rmp;
6644 vlib_main_t *vm = vlib_get_main ();
6645 clib_error_t *error;
6646 u8 *tmp = format (0, "%s", mp->name);
6647 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
6650 rv = VNET_API_ERROR_UNSPECIFIED;
6652 rv = VNET_API_ERROR_UNIMPLEMENTED;
6655 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6659 vl_api_ikev2_profile_set_auth_t_handler
6660 (vl_api_ikev2_profile_set_auth_t * mp)
6662 vl_api_ikev2_profile_set_auth_reply_t *rmp;
6666 vlib_main_t *vm = vlib_get_main ();
6667 clib_error_t *error;
6668 u8 *tmp = format (0, "%s", mp->name);
6669 u8 *data = vec_new (u8, mp->data_len);
6670 clib_memcpy (data, mp->data, mp->data_len);
6671 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
6675 rv = VNET_API_ERROR_UNSPECIFIED;
6677 rv = VNET_API_ERROR_UNIMPLEMENTED;
6680 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6684 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
6686 vl_api_ikev2_profile_add_del_reply_t *rmp;
6690 vlib_main_t *vm = vlib_get_main ();
6691 clib_error_t *error;
6692 u8 *tmp = format (0, "%s", mp->name);
6693 u8 *data = vec_new (u8, mp->data_len);
6694 clib_memcpy (data, mp->data, mp->data_len);
6695 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
6699 rv = VNET_API_ERROR_UNSPECIFIED;
6701 rv = VNET_API_ERROR_UNIMPLEMENTED;
6704 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6708 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
6710 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6714 vlib_main_t *vm = vlib_get_main ();
6715 clib_error_t *error;
6716 u8 *tmp = format (0, "%s", mp->name);
6717 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
6718 mp->end_port, (ip4_address_t) mp->start_addr,
6719 (ip4_address_t) mp->end_addr, mp->is_local);
6722 rv = VNET_API_ERROR_UNSPECIFIED;
6724 rv = VNET_API_ERROR_UNIMPLEMENTED;
6727 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6731 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
6733 vl_api_ikev2_profile_set_ts_reply_t *rmp;
6737 vlib_main_t *vm = vlib_get_main ();
6738 clib_error_t *error;
6740 error = ikev2_set_local_key (vm, mp->key_file);
6742 rv = VNET_API_ERROR_UNSPECIFIED;
6744 rv = VNET_API_ERROR_UNIMPLEMENTED;
6747 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6751 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
6753 vl_api_map_add_domain_reply_t *rmp;
6756 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6758 map_create_domain ((ip4_address_t *) & mp->ip4_prefix, mp->ip4_prefix_len,
6759 (ip6_address_t *) & mp->ip6_prefix, mp->ip6_prefix_len,
6760 (ip6_address_t *) & mp->ip6_src,
6761 mp->ip6_src_prefix_len, mp->ea_bits_len,
6762 mp->psid_offset, mp->psid_length, &index,
6763 ntohs (mp->mtu), flags);
6766 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6768 rmp->index = ntohl(index);
6774 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
6776 vl_api_map_del_domain_reply_t *rmp;
6779 rv = map_delete_domain (ntohl (mp->index));
6781 REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
6785 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
6787 vl_api_map_del_domain_reply_t *rmp;
6791 map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
6792 (ip6_address_t *) mp->ip6_dst, mp->is_add);
6794 REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
6798 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
6800 vl_api_map_domain_details_t *rmp;
6801 map_main_t *mm = &map_main;
6803 unix_shared_memory_queue_t *q;
6805 if (pool_elts (mm->domains) == 0)
6808 q = vl_api_client_index_to_input_queue (mp->client_index);
6815 pool_foreach(d, mm->domains,
6817 /* Make sure every field is initiated (or don't skip the memset()) */
6818 rmp = vl_msg_api_alloc (sizeof (*rmp));
6819 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6820 rmp->domain_index = htonl(d - mm->domains);
6821 rmp->ea_bits_len = d->ea_bits_len;
6822 rmp->psid_offset = d->psid_offset;
6823 rmp->psid_length = d->psid_length;
6824 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6825 rmp->ip4_prefix_len = d->ip4_prefix_len;
6826 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6827 rmp->ip6_prefix_len = d->ip6_prefix_len;
6828 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6829 rmp->ip6_src_len = d->ip6_src_len;
6830 rmp->mtu = htons(d->mtu);
6831 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6832 rmp->context = mp->context;
6834 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6840 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
6842 unix_shared_memory_queue_t *q;
6845 vl_api_map_rule_details_t *rmp;
6846 map_main_t *mm = &map_main;
6847 u32 domain_index = ntohl (mp->domain_index);
6850 if (pool_elts (mm->domains) == 0)
6853 d = pool_elt_at_index (mm->domains, domain_index);
6854 if (!d || !d->rules)
6859 q = vl_api_client_index_to_input_queue (mp->client_index);
6865 for (i = 0; i < (0x1 << d->psid_length); i++)
6868 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
6872 rmp = vl_msg_api_alloc (sizeof (*rmp));
6873 memset (rmp, 0, sizeof (*rmp));
6874 rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS);
6875 rmp->psid = htons (i);
6876 clib_memcpy (rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
6877 rmp->context = mp->context;
6878 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6883 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
6885 vl_api_map_summary_stats_reply_t *rmp;
6886 vlib_combined_counter_main_t *cm;
6889 u64 total_pkts[VLIB_N_RX_TX];
6890 u64 total_bytes[VLIB_N_RX_TX];
6891 map_main_t *mm = &map_main;
6892 unix_shared_memory_queue_t *q =
6893 vl_api_client_index_to_input_queue (mp->client_index);
6898 rmp = vl_msg_api_alloc (sizeof (*rmp));
6899 rmp->_vl_msg_id = ntohs (VL_API_MAP_SUMMARY_STATS_REPLY);
6900 rmp->context = mp->context;
6903 memset (total_pkts, 0, sizeof (total_pkts));
6904 memset (total_bytes, 0, sizeof (total_bytes));
6906 map_domain_counter_lock (mm);
6907 vec_foreach (cm, mm->domain_counters)
6909 which = cm - mm->domain_counters;
6911 for (i = 0; i < vec_len (cm->maxi); i++)
6913 vlib_get_combined_counter (cm, i, &v);
6914 total_pkts[which] += v.packets;
6915 total_bytes[which] += v.bytes;
6919 map_domain_counter_unlock (mm);
6921 /* Note: in network byte order! */
6922 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
6923 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
6924 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
6925 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
6926 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
6927 clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
6928 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
6929 clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
6930 rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
6931 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6932 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
6933 clib_host_to_net_u64 (map_error_counter_get
6934 (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6935 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
6936 clib_host_to_net_u64 (map_error_counter_get
6937 (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6939 vl_msg_api_send_shmem (q, (u8 *) & rmp);
6943 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
6945 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
6946 vl_api_ipsec_sa_set_key_reply_t *rmp;
6950 sa.id = ntohl (mp->sa_id);
6951 sa.crypto_key_len = mp->crypto_key_length;
6952 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
6953 sa.integ_key_len = mp->integrity_key_length;
6954 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
6956 rv = ipsec_set_sa_key (vm, &sa);
6958 rv = VNET_API_ERROR_UNIMPLEMENTED;
6961 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
6964 static void vl_api_cop_interface_enable_disable_t_handler
6965 (vl_api_cop_interface_enable_disable_t * mp)
6967 vl_api_cop_interface_enable_disable_reply_t *rmp;
6969 u32 sw_if_index = ntohl (mp->sw_if_index);
6972 VALIDATE_SW_IF_INDEX (mp);
6974 enable_disable = (int) mp->enable_disable;
6976 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6978 BAD_SW_IF_INDEX_LABEL;
6980 REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6983 static void vl_api_cop_whitelist_enable_disable_t_handler
6984 (vl_api_cop_whitelist_enable_disable_t * mp)
6986 vl_api_cop_whitelist_enable_disable_reply_t *rmp;
6987 cop_whitelist_enable_disable_args_t _a, *a = &_a;
6988 u32 sw_if_index = ntohl (mp->sw_if_index);
6991 VALIDATE_SW_IF_INDEX (mp);
6993 a->sw_if_index = sw_if_index;
6996 a->default_cop = mp->default_cop;
6997 a->fib_id = ntohl (mp->fib_id);
6999 rv = cop_whitelist_enable_disable (a);
7001 BAD_SW_IF_INDEX_LABEL;
7003 REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
7007 vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp)
7011 api_main_t *am = &api_main;
7012 vlib_main_t *vm = vlib_get_main ();
7014 vl_api_get_node_graph_reply_t *rmp;
7016 pthread_mutex_lock (&am->vlib_rp->mutex);
7017 oldheap = svm_push_data_heap (am->vlib_rp);
7020 * Keep the number of memcpy ops to a minimum (e.g. 1).
7022 vec_validate (vector, 16384);
7023 vec_reset_length (vector);
7026 vector = vlib_node_serialize (&vm->node_main, vector,
7027 (u32) ~ 0 /* all threads */ ,
7028 1 /* include nexts */ ,
7029 1 /* include stats */ );
7031 svm_pop_heap (oldheap);
7032 pthread_mutex_unlock (&am->vlib_rp->mutex);
7035 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
7037 rmp->reply_in_shmem = (uword) vector;
7043 vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp)
7046 vl_api_ioam_enable_reply_t *rmp;
7047 clib_error_t *error;
7049 /* Ignoring the profile id as currently a single profile
7051 error = ip6_ioam_enable (mp->trace_enable, mp->pow_enable, mp->trace_ppc);
7054 clib_error_report (error);
7055 rv = clib_error_get_code (error);
7058 REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY);
7062 vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp)
7065 vl_api_ioam_disable_reply_t *rmp;
7066 clib_error_t *error;
7068 error = clear_ioam_rewrite_fn ();
7071 clib_error_report (error);
7072 rv = clib_error_get_code (error);
7075 REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY);
7079 vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
7081 vlib_main_t *vm = vlib_get_main ();
7082 vl_api_af_packet_create_reply_t *rmp;
7084 u8 *host_if_name = NULL;
7087 host_if_name = format (0, "%s", mp->host_if_name);
7088 vec_add1 (host_if_name, 0);
7090 rv = af_packet_create_if (vm, host_if_name,
7091 mp->use_random_hw_addr ? 0 : mp->hw_addr,
7094 vec_free (host_if_name);
7097 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
7099 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index);
7105 vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp)
7107 vlib_main_t *vm = vlib_get_main ();
7108 vl_api_af_packet_delete_reply_t *rmp;
7110 u8 *host_if_name = NULL;
7112 host_if_name = format (0, "%s", mp->host_if_name);
7113 vec_add1 (host_if_name, 0);
7115 rv = af_packet_delete_if (vm, host_if_name);
7117 vec_free (host_if_name);
7119 REPLY_MACRO (VL_API_AF_PACKET_DELETE_REPLY);
7123 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
7125 vlib_main_t *vm = vlib_get_main ();
7126 vl_api_policer_add_del_reply_t *rmp;
7129 sse2_qos_pol_cfg_params_st cfg;
7130 clib_error_t *error;
7133 name = format (0, "%s", mp->name);
7135 memset (&cfg, 0, sizeof (cfg));
7137 cfg.rnd_type = mp->round_type;
7138 cfg.rate_type = mp->rate_type;
7139 cfg.rb.kbps.cir_kbps = mp->cir;
7140 cfg.rb.kbps.eir_kbps = mp->eir;
7141 cfg.rb.kbps.cb_bytes = mp->cb;
7142 cfg.rb.kbps.eb_bytes = mp->eb;
7143 cfg.conform_action.action_type = mp->conform_action_type;
7144 cfg.conform_action.dscp = mp->conform_dscp;
7145 cfg.exceed_action.action_type = mp->exceed_action_type;
7146 cfg.exceed_action.dscp = mp->exceed_dscp;
7147 cfg.violate_action.action_type = mp->violate_action_type;
7148 cfg.violate_action.dscp = mp->violate_dscp;
7149 cfg.color_aware = mp->color_aware;
7151 error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add);
7154 rv = VNET_API_ERROR_UNSPECIFIED;
7157 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
7159 if (rv == 0 && mp->is_add)
7160 rmp->policer_index = ntohl(policer_index);
7162 rmp->policer_index = ~0;
7168 send_policer_details (u8 * name,
7169 sse2_qos_pol_cfg_params_st * config,
7170 policer_read_response_type_st * templ,
7171 unix_shared_memory_queue_t * q, u32 context)
7173 vl_api_policer_details_t *mp;
7175 mp = vl_msg_api_alloc (sizeof (*mp));
7176 memset (mp, 0, sizeof (*mp));
7177 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
7178 mp->context = context;
7179 mp->cir = htonl (config->rb.kbps.cir_kbps);
7180 mp->eir = htonl (config->rb.kbps.eir_kbps);
7181 mp->cb = htonl (config->rb.kbps.cb_bytes);
7182 mp->eb = htonl (config->rb.kbps.eb_bytes);
7183 mp->rate_type = config->rate_type;
7184 mp->round_type = config->rnd_type;
7185 mp->type = config->rfc;
7186 mp->conform_action_type = config->conform_action.action_type;
7187 mp->conform_dscp = config->conform_action.dscp;
7188 mp->exceed_action_type = config->exceed_action.action_type;
7189 mp->exceed_dscp = config->exceed_action.dscp;
7190 mp->violate_action_type = config->violate_action.action_type;
7191 mp->violate_dscp = config->violate_action.dscp;
7192 mp->single_rate = templ->single_rate ? 1 : 0;
7193 mp->color_aware = templ->color_aware ? 1 : 0;
7194 mp->scale = htonl (templ->scale);
7195 mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period);
7196 mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period);
7197 mp->current_limit = htonl (templ->current_limit);
7198 mp->current_bucket = htonl (templ->current_bucket);
7199 mp->extended_limit = htonl (templ->extended_limit);
7200 mp->extended_bucket = htonl (templ->extended_bucket);
7201 mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time);
7203 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1);
7205 vl_msg_api_send_shmem (q, (u8 *) & mp);
7209 vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp)
7211 unix_shared_memory_queue_t *q;
7212 vnet_policer_main_t *pm = &vnet_policer_main;
7218 sse2_qos_pol_cfg_params_st *config;
7219 policer_read_response_type_st *templ;
7221 q = vl_api_client_index_to_input_queue (mp->client_index);
7225 if (mp->match_name_valid)
7227 match_name = format (0, "%s%c", mp->match_name, 0);
7230 if (mp->match_name_valid)
7232 p = hash_get_mem (pm->policer_config_by_name, match_name);
7236 config = pool_elt_at_index (pm->configs, pool_index);
7237 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7238 send_policer_details (match_name, config, templ, q, mp->context);
7244 hash_foreach_pair (hp, pm->policer_config_by_name,
7246 name = (u8 *) hp->key;
7247 pool_index = hp->value[0];
7248 config = pool_elt_at_index (pm->configs, pool_index);
7249 templ = pool_elt_at_index (pm->policer_templates, pool_index);
7250 send_policer_details(name, config, templ, q, mp->context);
7257 vl_api_policer_classify_set_interface_t_handler
7258 (vl_api_policer_classify_set_interface_t * mp)
7260 vlib_main_t *vm = vlib_get_main ();
7261 vl_api_policer_classify_set_interface_reply_t *rmp;
7263 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
7265 ip4_table_index = ntohl (mp->ip4_table_index);
7266 ip6_table_index = ntohl (mp->ip6_table_index);
7267 l2_table_index = ntohl (mp->l2_table_index);
7268 sw_if_index = ntohl (mp->sw_if_index);
7270 VALIDATE_SW_IF_INDEX (mp);
7272 rv = vnet_set_policer_classify_intfc (vm, sw_if_index, ip4_table_index,
7273 ip6_table_index, l2_table_index,
7276 BAD_SW_IF_INDEX_LABEL;
7278 REPLY_MACRO (VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
7282 send_policer_classify_details (u32 sw_if_index,
7284 unix_shared_memory_queue_t * q, u32 context)
7286 vl_api_policer_classify_details_t *mp;
7288 mp = vl_msg_api_alloc (sizeof (*mp));
7289 memset (mp, 0, sizeof (*mp));
7290 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
7291 mp->context = context;
7292 mp->sw_if_index = htonl (sw_if_index);
7293 mp->table_index = htonl (table_index);
7295 vl_msg_api_send_shmem (q, (u8 *) & mp);
7299 vl_api_policer_classify_dump_t_handler (vl_api_policer_classify_dump_t * mp)
7301 unix_shared_memory_queue_t *q;
7302 policer_classify_main_t *pcm = &policer_classify_main;
7306 q = vl_api_client_index_to_input_queue (mp->client_index);
7310 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
7312 if (vec_len (vec_tbl))
7314 for (i = 0; i < vec_len (vec_tbl); i++)
7316 if (vec_elt (vec_tbl, i) == ~0)
7319 send_policer_classify_details (i, vec_elt (vec_tbl, i), q,
7326 vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp)
7328 vlib_main_t *vm = vlib_get_main ();
7329 vl_api_netmap_create_reply_t *rmp;
7333 if_name = format (0, "%s", mp->netmap_if_name);
7334 vec_add1 (if_name, 0);
7337 netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
7338 mp->is_pipe, mp->is_master, 0);
7342 REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY);
7346 vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp)
7348 vlib_main_t *vm = vlib_get_main ();
7349 vl_api_netmap_delete_reply_t *rmp;
7353 if_name = format (0, "%s", mp->netmap_if_name);
7354 vec_add1 (if_name, 0);
7356 rv = netmap_delete_if (vm, if_name);
7360 REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY);
7364 vl_api_mpls_gre_tunnel_details_t_handler (vl_api_mpls_gre_tunnel_details_t *
7367 clib_warning ("BUG");
7371 send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
7372 unix_shared_memory_queue_t * q,
7373 mpls_gre_tunnel_t * gt, u32 index, u32 context)
7375 vl_api_mpls_gre_tunnel_details_t *mp;
7376 mpls_main_t *mm = &mpls_main;
7381 e = pool_elt_at_index (mm->encaps, gt->encap_index);
7382 nlabels = vec_len (e->labels);
7384 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7385 memset (mp, 0, sizeof (*mp));
7386 mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
7387 mp->context = context;
7389 mp->tunnel_index = htonl (index);
7390 mp->tunnel_src = gt->tunnel_src.as_u32;
7391 mp->tunnel_dst = gt->tunnel_dst.as_u32;
7392 mp->intfc_address = gt->intfc_address.as_u32;
7393 mp->mask_width = htonl (gt->mask_width);
7394 mp->inner_fib_index = htonl (gt->inner_fib_index);
7395 mp->outer_fib_index = htonl (gt->outer_fib_index);
7396 mp->encap_index = htonl (gt->encap_index);
7397 mp->hw_if_index = htonl (gt->hw_if_index);
7398 mp->l2_only = htonl (gt->l2_only);
7399 mp->nlabels = htonl (nlabels);
7401 for (i = 0; i < nlabels; i++)
7404 htonl (vnet_mpls_uc_get_label
7405 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7408 vl_msg_api_send_shmem (q, (u8 *) & mp);
7412 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
7414 vpe_api_main_t *am = &vpe_api_main;
7415 unix_shared_memory_queue_t *q;
7416 mpls_main_t *mm = &mpls_main;
7417 mpls_gre_tunnel_t *gt;
7418 u32 index = ntohl (mp->tunnel_index);
7420 q = vl_api_client_index_to_input_queue (mp->client_index);
7426 if (!pool_is_free_index (mm->gre_tunnels, index))
7428 gt = pool_elt_at_index (mm->gre_tunnels, index);
7429 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7436 pool_foreach (gt, mm->gre_tunnels,
7438 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
7446 vl_api_mpls_eth_tunnel_details_t_handler (vl_api_mpls_eth_tunnel_details_t *
7449 clib_warning ("BUG");
7453 send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
7454 unix_shared_memory_queue_t * q,
7455 mpls_eth_tunnel_t * et, u32 index, u32 context)
7457 mpls_main_t *mm = &mpls_main;
7461 vl_api_mpls_eth_tunnel_details_t *mp;
7463 e = pool_elt_at_index (mm->encaps, et->encap_index);
7464 nlabels = vec_len (e->labels);
7466 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7467 memset (mp, 0, sizeof (*mp));
7468 mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
7469 mp->context = context;
7471 mp->tunnel_index = htonl (index);
7472 memcpy (mp->tunnel_dst_mac, et->tunnel_dst, 6);
7473 mp->intfc_address = et->intfc_address.as_u32;
7474 mp->tx_sw_if_index = htonl (et->tx_sw_if_index);
7475 mp->inner_fib_index = htonl (et->inner_fib_index);
7476 mp->mask_width = htonl (et->mask_width);
7477 mp->encap_index = htonl (et->encap_index);
7478 mp->hw_if_index = htonl (et->hw_if_index);
7479 mp->l2_only = htonl (et->l2_only);
7480 mp->nlabels = htonl (nlabels);
7482 for (i = 0; i < nlabels; i++)
7485 htonl (vnet_mpls_uc_get_label
7486 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7489 vl_msg_api_send_shmem (q, (u8 *) & mp);
7493 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
7495 vpe_api_main_t *am = &vpe_api_main;
7496 unix_shared_memory_queue_t *q;
7497 mpls_main_t *mm = &mpls_main;
7498 mpls_eth_tunnel_t *et;
7499 u32 index = ntohl (mp->tunnel_index);
7501 q = vl_api_client_index_to_input_queue (mp->client_index);
7507 if (!pool_is_free_index (mm->eth_tunnels, index))
7509 et = pool_elt_at_index (mm->eth_tunnels, index);
7510 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7517 pool_foreach (et, mm->eth_tunnels,
7519 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
7527 vl_api_mpls_fib_encap_details_t_handler (vl_api_mpls_fib_encap_details_t * mp)
7529 clib_warning ("BUG");
7533 send_mpls_fib_encap_details (vpe_api_main_t * am,
7534 unix_shared_memory_queue_t * q,
7535 show_mpls_fib_t * s, u32 context)
7537 vl_api_mpls_fib_encap_details_t *mp;
7538 mpls_main_t *mm = &mpls_main;
7543 e = pool_elt_at_index (mm->encaps, s->entry_index);
7544 nlabels = vec_len (e->labels);
7546 mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
7547 memset (mp, 0, sizeof (*mp));
7548 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
7549 mp->context = context;
7551 mp->fib_index = htonl (s->fib_index);
7552 mp->entry_index = htonl (s->entry_index);
7554 mp->s_bit = htonl (s->s_bit);
7556 mp->nlabels = htonl (nlabels);
7558 for (i = 0; i < nlabels; i++)
7561 htonl (vnet_mpls_uc_get_label
7562 (clib_host_to_net_u32 (e->labels[i].label_exp_s_ttl)));
7565 vl_msg_api_send_shmem (q, (u8 *) & mp);
7569 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t * mp)
7571 vpe_api_main_t *am = &vpe_api_main;
7572 unix_shared_memory_queue_t *q;
7573 vlib_main_t *vm = &vlib_global_main;
7576 show_mpls_fib_t *records = 0;
7578 mpls_main_t *mm = &mpls_main;
7579 ip4_main_t *im = &ip4_main;
7582 q = vl_api_client_index_to_input_queue (mp->client_index);
7587 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
7589 vec_add2 (records, s, 1);
7590 s->fib_index = (u32)(key>>32);
7591 s->dest = (u32)(key & 0xFFFFFFFF);
7592 s->entry_index = (u32) value;
7596 if (0 == vec_len (records))
7598 vlib_cli_output (vm, "MPLS encap table empty");
7602 /* sort output by dst address within fib */
7603 vec_sort_with_function (records, mpls_dest_cmp);
7604 vec_sort_with_function (records, mpls_fib_index_cmp);
7605 vlib_cli_output (vm, "MPLS encap table");
7606 vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
7607 vec_foreach (s, records)
7609 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7610 vlib_cli_output (vm, "%=6d%=16U%=16U", rx_fib->table_id,
7611 format_ip4_address, &s->dest, format_mpls_encap_index,
7612 mm, s->entry_index);
7613 send_mpls_fib_encap_details (am, q, s, mp->context);
7621 vl_api_mpls_fib_decap_details_t_handler (vl_api_mpls_fib_decap_details_t * mp)
7623 clib_warning ("BUG");
7627 send_mpls_fib_decap_details (vpe_api_main_t * am,
7628 unix_shared_memory_queue_t * q,
7629 show_mpls_fib_t * s,
7631 u32 tx_table_id, char *swif_tag, u32 context)
7633 vl_api_mpls_fib_decap_details_t *mp;
7635 mp = vl_msg_api_alloc (sizeof (*mp));
7636 memset (mp, 0, sizeof (*mp));
7637 mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DECAP_DETAILS);
7638 mp->context = context;
7640 mp->fib_index = htonl (s->fib_index);
7641 mp->entry_index = htonl (s->entry_index);
7643 mp->s_bit = htonl (s->s_bit);
7644 mp->label = htonl (s->label);
7645 mp->rx_table_id = htonl (rx_table_id);
7646 mp->tx_table_id = htonl (tx_table_id);
7647 strncpy ((char *) mp->swif_tag,
7648 (char *) swif_tag, ARRAY_LEN (mp->swif_tag) - 1);
7650 vl_msg_api_send_shmem (q, (u8 *) & mp);
7654 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t * mp)
7656 vpe_api_main_t *am = &vpe_api_main;
7657 unix_shared_memory_queue_t *q;
7658 vlib_main_t *vm = &vlib_global_main;
7661 show_mpls_fib_t *records = 0;
7663 mpls_main_t *mm = &mpls_main;
7664 ip4_main_t *im = &ip4_main;
7670 q = vl_api_client_index_to_input_queue (mp->client_index);
7675 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7677 vec_add2 (records, s, 1);
7678 s->fib_index = (u32)(key>>32);
7679 s->entry_index = (u32) value;
7680 s->label = ((u32) key)>>12;
7681 s->s_bit = (key & (1<<8)) != 0;
7685 if (!vec_len (records))
7687 vlib_cli_output (vm, "MPLS decap table empty");
7691 vec_sort_with_function (records, mpls_label_cmp);
7692 vlib_cli_output (vm, "MPLS decap table");
7693 vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7695 vec_foreach (s, records)
7698 d = pool_elt_at_index (mm->decaps, s->entry_index);
7699 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT)
7701 tx_fib = vec_elt_at_index (im->fibs, d->tx_fib_index);
7702 tx_table_id = tx_fib->table_id;
7707 tx_table_id = d->tx_fib_index;
7710 rx_fib = vec_elt_at_index (im->fibs, s->fib_index);
7712 vlib_cli_output (vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7713 tx_table_id, swif_tag, s->label, s->s_bit);
7715 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7716 tx_table_id, swif_tag, mp->context);
7724 vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t * mp)
7726 unix_shared_memory_queue_t *q;
7728 q = vl_api_client_index_to_input_queue (mp->client_index);
7732 vnet_classify_main_t *cm = &vnet_classify_main;
7733 vnet_classify_table_t *t;
7738 pool_foreach (t, cm->tables,
7740 vec_add1 (table_ids, ntohl(t - cm->tables));
7743 count = vec_len (table_ids);
7745 vl_api_classify_table_ids_reply_t *rmp;
7746 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp) + count * sizeof (u32));
7747 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7748 rmp->context = mp->context;
7749 rmp->count = ntohl (count);
7750 clib_memcpy (rmp->ids, table_ids, count * sizeof (u32));
7753 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7755 vec_free (table_ids);
7759 vl_api_classify_table_by_interface_t_handler
7760 (vl_api_classify_table_by_interface_t * mp)
7762 vl_api_classify_table_by_interface_reply_t *rmp;
7765 u32 sw_if_index = ntohl (mp->sw_if_index);
7768 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7771 VALIDATE_SW_IF_INDEX (mp);
7773 input_acl_main_t *am = &input_acl_main;
7778 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7780 u32 *vec_tbl = am->classify_table_index_by_sw_if_index[type];
7781 if (vec_len (vec_tbl))
7783 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7785 if (vec_elt (vec_tbl, if_idx) == ~0 || sw_if_index != if_idx)
7789 acl[type] = vec_elt (vec_tbl, if_idx);
7794 BAD_SW_IF_INDEX_LABEL;
7797 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7799 rmp->sw_if_index = ntohl(sw_if_index);
7800 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7801 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7802 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7809 vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t * mp)
7811 unix_shared_memory_queue_t *q;
7813 q = vl_api_client_index_to_input_queue (mp->client_index);
7817 vl_api_classify_table_info_reply_t *rmp = 0;
7819 vnet_classify_main_t *cm = &vnet_classify_main;
7820 u32 table_id = ntohl (mp->table_id);
7821 vnet_classify_table_t *t;
7824 pool_foreach (t, cm->tables,
7826 if (table_id == t - cm->tables)
7828 rmp = vl_msg_api_alloc_as_if_client
7829 (sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7830 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7831 rmp->context = mp->context;
7832 rmp->table_id = ntohl(table_id);
7833 rmp->nbuckets = ntohl(t->nbuckets);
7834 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7835 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7836 rmp->active_sessions = ntohl(t->active_elements);
7837 rmp->next_table_index = ntohl(t->next_table_index);
7838 rmp->miss_next_index = ntohl(t->miss_next_index);
7839 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7840 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7849 rmp = vl_msg_api_alloc (sizeof (*rmp));
7850 rmp->_vl_msg_id = ntohs ((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7851 rmp->context = mp->context;
7852 rmp->retval = ntohl (VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7855 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7859 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
7862 clib_warning ("BUG");
7866 send_classify_session_details (unix_shared_memory_queue_t * q,
7869 vnet_classify_entry_t * e, u32 context)
7871 vl_api_classify_session_details_t *rmp;
7873 rmp = vl_msg_api_alloc (sizeof (*rmp));
7874 memset (rmp, 0, sizeof (*rmp));
7875 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_SESSION_DETAILS);
7876 rmp->context = context;
7877 rmp->table_id = ntohl (table_id);
7878 rmp->hit_next_index = ntohl (e->next_index);
7879 rmp->advance = ntohl (e->advance);
7880 rmp->opaque_index = ntohl (e->opaque_index);
7881 rmp->match_length = ntohl (match_length);
7882 clib_memcpy (rmp->match, e->key, match_length);
7884 vl_msg_api_send_shmem (q, (u8 *) & rmp);
7888 vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t * mp)
7890 vnet_classify_main_t *cm = &vnet_classify_main;
7891 unix_shared_memory_queue_t *q;
7893 u32 table_id = ntohl (mp->table_id);
7894 vnet_classify_table_t *t;
7896 q = vl_api_client_index_to_input_queue (mp->client_index);
7901 pool_foreach (t, cm->tables,
7903 if (table_id == t - cm->tables)
7905 vnet_classify_bucket_t * b;
7906 vnet_classify_entry_t * v, * save_v;
7909 for (i = 0; i < t->nbuckets; i++)
7911 b = &t->buckets [i];
7915 save_v = vnet_classify_get_entry (t, b->offset);
7916 for (j = 0; j < (1<<b->log2_pages); j++)
7918 for (k = 0; k < t->entries_per_page; k++)
7920 v = vnet_classify_entry_at_index
7921 (t, save_v, j*t->entries_per_page + k);
7922 if (vnet_classify_entry_is_free (v))
7925 send_classify_session_details
7926 (q, table_id, t->match_n_vectors * sizeof (u32x4),
7938 vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp)
7940 vlib_main_t *vm = vlib_get_main ();
7941 flow_report_main_t *frm = &flow_report_main;
7942 vl_api_set_ipfix_exporter_reply_t *rmp;
7943 ip4_address_t collector, src;
7944 u16 collector_port = UDP_DST_PORT_ipfix;
7946 u32 template_interval;
7952 memcpy (collector.data, mp->collector_address, sizeof (collector.data));
7953 collector_port = ntohs (mp->collector_port);
7954 if (collector_port == (u16) ~ 0)
7955 collector_port = UDP_DST_PORT_ipfix;
7956 memcpy (src.data, mp->src_address, sizeof (src.data));
7957 fib_id = ntohl (mp->vrf_id);
7959 ip4_main_t *im = &ip4_main;
7966 uword *p = hash_get (im->fib_index_by_table_id, fib_id);
7969 rv = VNET_API_ERROR_NO_SUCH_FIB;
7975 path_mtu = ntohl (mp->path_mtu);
7977 path_mtu = 512; // RFC 7011 section 10.3.3.
7978 template_interval = ntohl (mp->template_interval);
7979 if (template_interval == ~0)
7980 template_interval = 20;
7981 udp_checksum = mp->udp_checksum;
7983 if (collector.as_u32 == 0)
7985 rv = VNET_API_ERROR_INVALID_VALUE;
7989 if (src.as_u32 == 0)
7991 rv = VNET_API_ERROR_INVALID_VALUE;
7995 if (path_mtu > 1450 /* vpp does not support fragmentation */ )
7997 rv = VNET_API_ERROR_INVALID_VALUE;
8003 rv = VNET_API_ERROR_INVALID_VALUE;
8007 /* Reset report streams if we are reconfiguring IP addresses */
8008 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
8009 frm->src_address.as_u32 != src.as_u32 ||
8010 frm->collector_port != collector_port)
8011 vnet_flow_reports_reset (frm);
8013 frm->ipfix_collector.as_u32 = collector.as_u32;
8014 frm->collector_port = collector_port;
8015 frm->src_address.as_u32 = src.as_u32;
8016 frm->fib_index = fib_index;
8017 frm->path_mtu = path_mtu;
8018 frm->template_interval = template_interval;
8019 frm->udp_checksum = udp_checksum;
8021 /* Turn on the flow reporting process */
8022 vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
8025 REPLY_MACRO (VL_API_SET_IPFIX_EXPORTER_REPLY);
8029 vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp)
8031 flow_report_main_t *frm = &flow_report_main;
8032 unix_shared_memory_queue_t *q;
8033 vl_api_ipfix_exporter_details_t *rmp;
8034 ip4_main_t *im = &ip4_main;
8037 q = vl_api_client_index_to_input_queue (mp->client_index);
8041 rmp = vl_msg_api_alloc (sizeof (*rmp));
8042 memset (rmp, 0, sizeof (*rmp));
8043 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS);
8044 rmp->context = mp->context;
8045 memcpy (rmp->collector_address, frm->ipfix_collector.data,
8046 sizeof (frm->ipfix_collector.data));
8047 rmp->collector_port = htons (frm->collector_port);
8048 memcpy (rmp->src_address, frm->src_address.data,
8049 sizeof (frm->src_address.data));
8050 if (frm->fib_index == ~0)
8053 vrf_id = im->fibs[frm->fib_index].table_id;
8054 rmp->vrf_id = htonl (vrf_id);
8055 rmp->path_mtu = htonl (frm->path_mtu);
8056 rmp->template_interval = htonl (frm->template_interval);
8057 rmp->udp_checksum = (frm->udp_checksum != 0);
8059 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8063 vl_api_set_ipfix_classify_stream_t_handler
8064 (vl_api_set_ipfix_classify_stream_t * mp)
8066 vl_api_set_ipfix_classify_stream_reply_t *rmp;
8067 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8068 flow_report_main_t *frm = &flow_report_main;
8070 u32 src_port = UDP_DST_PORT_ipfix;
8073 domain_id = ntohl (mp->domain_id);
8074 src_port = ntohs (mp->src_port);
8076 if (fcm->src_port != 0 &&
8077 (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
8079 int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
8080 domain_id, (u16) src_port);
8084 fcm->domain_id = domain_id;
8085 fcm->src_port = (u16) src_port;
8087 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8091 vl_api_ipfix_classify_stream_dump_t_handler
8092 (vl_api_ipfix_classify_stream_dump_t * mp)
8094 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8095 unix_shared_memory_queue_t *q;
8096 vl_api_ipfix_classify_stream_details_t *rmp;
8098 q = vl_api_client_index_to_input_queue (mp->client_index);
8102 rmp = vl_msg_api_alloc (sizeof (*rmp));
8103 memset (rmp, 0, sizeof (*rmp));
8104 rmp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_STREAM_DETAILS);
8105 rmp->context = mp->context;
8106 rmp->domain_id = htonl (fcm->domain_id);
8107 rmp->src_port = htons (fcm->src_port);
8109 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8113 vl_api_ipfix_classify_table_add_del_t_handler
8114 (vl_api_ipfix_classify_table_add_del_t * mp)
8116 vl_api_ipfix_classify_table_add_del_reply_t *rmp;
8117 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8118 flow_report_main_t *frm = &flow_report_main;
8119 vnet_flow_report_add_del_args_t args;
8120 ipfix_classify_table_t *table;
8122 u32 classify_table_index;
8124 u8 transport_protocol;
8127 classify_table_index = ntohl (mp->table_id);
8128 ip_version = mp->ip_version;
8129 transport_protocol = mp->transport_protocol;
8130 is_add = mp->is_add;
8132 if (fcm->src_port == 0)
8134 /* call set_ipfix_classify_stream first */
8135 rv = VNET_API_ERROR_UNSPECIFIED;
8139 memset (&args, 0, sizeof (args));
8143 for (i = 0; i < vec_len (fcm->tables); i++)
8144 if (ipfix_classify_table_index_valid (i))
8145 if (fcm->tables[i].classify_table_index == classify_table_index)
8147 table = &fcm->tables[i];
8155 rv = VNET_API_ERROR_VALUE_EXIST;
8158 table = ipfix_classify_add_table ();
8159 table->classify_table_index = classify_table_index;
8165 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
8170 table->ip_version = ip_version;
8171 table->transport_protocol = transport_protocol;
8173 args.opaque.as_uword = table - fcm->tables;
8174 args.rewrite_callback = ipfix_classify_template_rewrite;
8175 args.flow_data_callback = ipfix_classify_send_flows;
8176 args.is_add = is_add;
8177 args.domain_id = fcm->domain_id;
8178 args.src_port = fcm->src_port;
8180 rv = vnet_flow_report_add_del (frm, &args);
8182 /* If deleting, or add failed */
8183 if (is_add == 0 || (rv && is_add))
8184 ipfix_classify_delete_table (table - fcm->tables);
8187 REPLY_MACRO (VL_API_SET_IPFIX_CLASSIFY_STREAM_REPLY);
8191 send_ipfix_classify_table_details (u32 table_index,
8192 unix_shared_memory_queue_t * q,
8195 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8196 vl_api_ipfix_classify_table_details_t *mp;
8198 ipfix_classify_table_t *table = &fcm->tables[table_index];
8200 mp = vl_msg_api_alloc (sizeof (*mp));
8201 memset (mp, 0, sizeof (*mp));
8202 mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS);
8203 mp->context = context;
8204 mp->table_id = htonl (table->classify_table_index);
8205 mp->ip_version = table->ip_version;
8206 mp->transport_protocol = table->transport_protocol;
8208 vl_msg_api_send_shmem (q, (u8 *) & mp);
8212 vl_api_ipfix_classify_table_dump_t_handler
8213 (vl_api_ipfix_classify_table_dump_t * mp)
8215 flow_report_classify_main_t *fcm = &flow_report_classify_main;
8216 unix_shared_memory_queue_t *q;
8219 q = vl_api_client_index_to_input_queue (mp->client_index);
8223 for (i = 0; i < vec_len (fcm->tables); i++)
8224 if (ipfix_classify_table_index_valid (i))
8225 send_ipfix_classify_table_details (i, q, mp->context);
8229 vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
8231 vl_api_pg_create_interface_reply_t *rmp;
8234 pg_main_t *pg = &pg_main;
8235 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
8238 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
8240 rmp->sw_if_index = ntohl(sw_if_index);
8246 vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp)
8248 vl_api_pg_capture_reply_t *rmp;
8251 vnet_main_t *vnm = vnet_get_main ();
8252 vnet_interface_main_t *im = &vnm->interface_main;
8253 vnet_hw_interface_t *hi = 0;
8255 u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
8256 u32 hw_if_index = ~0;
8257 uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
8260 vec_free (intf_name);
8262 if (hw_if_index != ~0)
8264 pg_capture_args_t _a, *a = &_a;
8266 u32 len = ntohl (mp->pcap_name_length);
8267 u8 *pcap_file_name = vec_new (u8, len);
8268 clib_memcpy (pcap_file_name, mp->pcap_file_name, len);
8270 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
8271 a->hw_if_index = hw_if_index;
8272 a->dev_instance = hi->dev_instance;
8273 a->is_enabled = mp->is_enabled;
8274 a->pcap_file_name = pcap_file_name;
8275 a->count = ntohl (mp->count);
8277 clib_error_t *e = pg_capture (a);
8280 clib_error_report (e);
8281 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
8284 vec_free (pcap_file_name);
8286 REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
8290 vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp)
8292 vl_api_pg_enable_disable_reply_t *rmp;
8295 pg_main_t *pg = &pg_main;
8296 u32 stream_index = ~0;
8298 int is_enable = mp->is_enabled != 0;
8299 u32 len = ntohl (mp->stream_name_length) - 1;
8303 u8 *stream_name = vec_new (u8, len);
8304 clib_memcpy (stream_name, mp->stream_name, len);
8305 uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
8308 vec_free (stream_name);
8311 pg_enable_disable (stream_index, is_enable);
8313 REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
8317 vl_api_ip_source_and_port_range_check_add_del_t_handler
8318 (vl_api_ip_source_and_port_range_check_add_del_t * mp)
8320 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
8323 u8 is_ipv6 = mp->is_ipv6;
8324 u8 is_add = mp->is_add;
8325 u8 mask_length = mp->mask_length;
8326 ip4_address_t ip4_addr;
8327 ip6_address_t ip6_addr;
8329 u16 *high_ports = 0;
8331 u16 tmp_low, tmp_high;
8335 // Validate port range
8336 num_ranges = mp->number_of_ranges;
8337 if (num_ranges > 32)
8338 { // This is size of array in VPE.API
8339 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
8343 vec_reset_length (low_ports);
8344 vec_reset_length (high_ports);
8346 for (i = 0; i < num_ranges; i++)
8348 tmp_low = mp->low_ports[i];
8349 tmp_high = mp->high_ports[i];
8350 // If tmp_low <= tmp_high then only need to check tmp_low = 0
8351 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
8352 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535)
8354 rv = VNET_API_ERROR_INVALID_VALUE;
8357 vec_add1 (low_ports, tmp_low);
8358 vec_add1 (high_ports, tmp_high + 1);
8361 // Validate mask_length
8362 if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32))
8364 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
8368 vrf_id = ntohl (mp->vrf_id);
8372 rv = VNET_API_ERROR_INVALID_VALUE;
8379 clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8));
8380 rv = ip6_source_and_port_range_check_add_del (&ip6_addr,
8384 high_ports, is_add);
8388 clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr));
8389 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
8393 high_ports, is_add);
8397 vec_free (low_ports);
8398 vec_free (high_ports);
8399 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
8403 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
8404 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
8406 vlib_main_t *vm = vlib_get_main ();
8407 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp;
8408 ip4_main_t *im = &ip4_main;
8411 u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8412 u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
8416 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] =
8417 ntohl (mp->tcp_out_vrf_id);
8418 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] =
8419 ntohl (mp->udp_out_vrf_id);
8420 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] =
8421 ntohl (mp->tcp_in_vrf_id);
8422 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] =
8423 ntohl (mp->udp_in_vrf_id);
8426 for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++)
8428 if (vrf_id[i] != 0 && vrf_id[i] != ~0)
8430 p = hash_get (im->fib_index_by_table_id, vrf_id[i]);
8434 rv = VNET_API_ERROR_INVALID_VALUE;
8438 fib_index[i] = p[0];
8443 sw_if_index = ntohl (mp->sw_if_index);
8445 VALIDATE_SW_IF_INDEX (mp);
8448 set_ip_source_and_port_range_check (vm, fib_index, sw_if_index,
8451 BAD_SW_IF_INDEX_LABEL;
8454 REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
8458 vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
8461 vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
8463 vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
8464 u32 sw_if_index = ~0;
8466 /* Check src & dst are different */
8467 if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
8469 rv = VNET_API_ERROR_SAME_SRC_DST;
8473 memset (a, 0, sizeof (*a));
8475 /* ip addresses sent in network byte order */
8476 clib_memcpy (&(a->src), mp->src_address, 4);
8477 clib_memcpy (&(a->dst), mp->dst_address, 4);
8478 a->is_add = mp->is_add;
8479 a->lsa = ntohl (mp->local_sa_id);
8480 a->rsa = ntohl (mp->remote_sa_id);
8482 rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
8486 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
8488 rmp->sw_if_index = ntohl (sw_if_index);
8493 static void send_ipsec_gre_tunnel_details
8494 (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
8496 vl_api_ipsec_gre_tunnel_details_t *rmp;
8498 rmp = vl_msg_api_alloc (sizeof (*rmp));
8499 memset (rmp, 0, sizeof (*rmp));
8500 rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
8501 clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
8502 clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
8503 rmp->sw_if_index = htonl (t->sw_if_index);
8504 rmp->local_sa_id = htonl (t->local_sa_id);
8505 rmp->remote_sa_id = htonl (t->remote_sa_id);
8506 rmp->context = context;
8508 vl_msg_api_send_shmem (q, (u8 *) & rmp);
8511 static void vl_api_ipsec_gre_tunnel_dump_t_handler
8512 (vl_api_ipsec_gre_tunnel_dump_t * mp)
8514 unix_shared_memory_queue_t *q;
8515 ipsec_gre_main_t *igm = &ipsec_gre_main;
8516 ipsec_gre_tunnel_t *t;
8519 q = vl_api_client_index_to_input_queue (mp->client_index);
8525 sw_if_index = ntohl (mp->sw_if_index);
8527 if (~0 == sw_if_index)
8530 pool_foreach (t, igm->tunnels,
8532 send_ipsec_gre_tunnel_details(t, q, mp->context);
8538 if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
8539 (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
8543 t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
8544 send_ipsec_gre_tunnel_details (t, q, mp->context);
8549 vl_api_delete_subif_t_handler (vl_api_delete_subif_t * mp)
8551 vl_api_delete_subif_reply_t *rmp;
8554 rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
8556 REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
8559 #define BOUNCE_HANDLER(nn) \
8560 static void vl_api_##nn##_t_handler ( \
8561 vl_api_##nn##_t *mp) \
8563 vpe_client_registration_t *reg; \
8564 vpe_api_main_t * vam = &vpe_api_main; \
8565 unix_shared_memory_queue_t * q; \
8567 /* One registration only... */ \
8568 pool_foreach(reg, vam->nn##_registrations, \
8570 q = vl_api_client_index_to_input_queue (reg->client_index); \
8573 * If the queue is stuffed, turf the msg and complain \
8574 * It's unlikely that the intended recipient is \
8575 * alive; avoid deadlock at all costs. \
8577 if (q->cursize == q->maxsize) { \
8578 clib_warning ("ERROR: receiver queue full, drop msg"); \
8579 vl_msg_api_free (mp); \
8582 vl_msg_api_send_shmem (q, (u8 *)&mp); \
8586 vl_msg_api_free (mp); \
8591 * Add vpe's API message handlers to the table.
8592 * vlib has alread mapped shared memory and
8593 * added the client registration handlers.
8594 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
8597 static clib_error_t *
8598 vpe_api_hookup (vlib_main_t * vm)
8600 api_main_t *am = &api_main;
8603 vl_msg_api_set_handlers(VL_API_##N, #n, \
8604 vl_api_##n##_t_handler, \
8606 vl_api_##n##_t_endian, \
8607 vl_api_##n##_t_print, \
8608 sizeof(vl_api_##n##_t), 1);
8609 foreach_vpe_api_msg;
8613 * Manually register the sr tunnel add del msg, so we trace
8614 * enough bytes to capture a typical segment list
8616 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
8617 "sr_tunnel_add_del",
8618 vl_api_sr_tunnel_add_del_t_handler,
8620 vl_api_sr_tunnel_add_del_t_endian,
8621 vl_api_sr_tunnel_add_del_t_print, 256, 1);
8625 * Manually register the sr policy add del msg, so we trace
8626 * enough bytes to capture a typical tunnel name list
8628 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
8629 "sr_policy_add_del",
8630 vl_api_sr_policy_add_del_t_handler,
8632 vl_api_sr_policy_add_del_t_endian,
8633 vl_api_sr_policy_add_del_t_print, 256, 1);
8636 * Trace space for 8 MPLS encap labels, classifier mask+match
8638 am->api_trace_cfg[VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof (u32);
8639 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
8640 am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size
8641 += 5 * sizeof (u32x4);
8642 am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32);
8645 * Thread-safe API messages
8647 am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
8648 am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
8653 VLIB_API_INIT_FUNCTION (vpe_api_hookup);
8655 static clib_error_t *
8656 vpe_api_init (vlib_main_t * vm)
8658 vpe_api_main_t *am = &vpe_api_main;
8661 am->vnet_main = vnet_get_main ();
8662 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
8663 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8664 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
8665 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8666 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
8667 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
8670 vl_set_memory_region_name ("/vpe-api");
8671 vl_enable_disable_memory_api (vm, 1 /* enable it */ );
8676 VLIB_INIT_FUNCTION (vpe_api_init);
8679 static clib_error_t *
8680 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
8683 u64 baseva, size, pvt_heap_size;
8685 const int max_buf_size = 4096;
8687 struct passwd _pw, *pw;
8688 struct group _grp, *grp;
8690 buf = vec_new (char, 128);
8691 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8693 if (unformat (input, "prefix %s", &chroot_path))
8695 vec_add1 (chroot_path, 0);
8696 vl_set_memory_root_path ((char *) chroot_path);
8698 else if (unformat (input, "uid %d", &uid))
8699 vl_set_memory_uid (uid);
8700 else if (unformat (input, "gid %d", &gid))
8701 vl_set_memory_gid (gid);
8702 else if (unformat (input, "baseva %llx", &baseva))
8703 vl_set_global_memory_baseva (baseva);
8704 else if (unformat (input, "global-size %lldM", &size))
8705 vl_set_global_memory_size (size * (1ULL << 20));
8706 else if (unformat (input, "global-size %lldG", &size))
8707 vl_set_global_memory_size (size * (1ULL << 30));
8708 else if (unformat (input, "global-size %lld", &size))
8709 vl_set_global_memory_size (size);
8710 else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
8711 vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8712 else if (unformat (input, "global-pvt-heap-size size %lld",
8714 vl_set_global_pvt_heap_size (pvt_heap_size);
8715 else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
8716 vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
8717 else if (unformat (input, "api-pvt-heap-size size %lld",
8719 vl_set_api_pvt_heap_size (pvt_heap_size);
8720 else if (unformat (input, "api-size %lldM", &size))
8721 vl_set_api_memory_size (size * (1ULL << 20));
8722 else if (unformat (input, "api-size %lldG", &size))
8723 vl_set_api_memory_size (size * (1ULL << 30));
8724 else if (unformat (input, "api-size %lld", &size))
8725 vl_set_api_memory_size (size);
8726 else if (unformat (input, "uid %s", &s))
8728 /* lookup the username */
8731 getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
8732 && (vec_len (buf) <= max_buf_size))
8734 vec_resize (buf, vec_len (buf) * 2);
8738 e = clib_error_return_code (0, rv,
8739 CLIB_ERROR_ERRNO_VALID |
8741 "cannot fetch username %s", s);
8749 clib_error_return_fatal (0, "username %s does not exist", s);
8755 vl_set_memory_uid (pw->pw_uid);
8757 else if (unformat (input, "gid %s", &s))
8759 /* lookup the group name */
8762 getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
8763 && (vec_len (buf) <= max_buf_size))
8765 vec_resize (buf, vec_len (buf) * 2);
8769 e = clib_error_return_code (0, rv,
8770 CLIB_ERROR_ERRNO_VALID |
8772 "cannot fetch group %s", s);
8779 e = clib_error_return_fatal (0, "group %s does not exist", s);
8786 vl_set_memory_gid (grp->gr_gid);
8789 return clib_error_return (0, "unknown input `%U'",
8790 format_unformat_error, input);
8795 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
8798 get_unformat_vnet_sw_interface (void)
8800 return (void *) &unformat_vnet_sw_interface;
8803 #undef vl_api_version
8804 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8805 #include <vpp-api/vpe.api.h>
8806 #undef vl_api_version
8809 vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
8811 if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
8813 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
8814 clib_host_to_net_u32 (mp->api_versions[0]),
8822 format_arp_event (u8 * s, va_list * args)
8824 vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
8826 s = format (s, "pid %d: ", event->pid);
8828 s = format (s, "bd mac/ip4 binding events");
8830 s = format (s, "resolution for %U", format_ip4_address, &event->address);
8835 format_nd_event (u8 * s, va_list * args)
8837 vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
8839 s = format (s, "pid %d: ", event->pid);
8841 s = format (s, "bd mac/ip6 binding events");
8843 s = format (s, "resolution for %U", format_ip6_address, event->address);
8847 static clib_error_t *
8848 show_ip_arp_nd_events_fn (vlib_main_t * vm,
8849 unformat_input_t * input, vlib_cli_command_t * cmd)
8851 vpe_api_main_t *am = &vpe_api_main;
8852 vl_api_ip4_arp_event_t *arp_event;
8853 vl_api_ip6_nd_event_t *nd_event;
8855 if ((pool_elts (am->arp_events) == 0) && (pool_elts (am->nd_events) == 0))
8857 vlib_cli_output (vm, "No active arp or nd event registrations");
8862 pool_foreach (arp_event, am->arp_events,
8864 vlib_cli_output (vm, "%U", format_arp_event, arp_event);
8867 pool_foreach (nd_event, am->nd_events,
8869 vlib_cli_output (vm, "%U", format_nd_event, nd_event);
8877 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
8878 .path = "show arp-nd-event registrations",
8879 .function = show_ip_arp_nd_events_fn,
8880 .short_help = "Show ip4 arp and ip6 nd event registrations",
8885 * fd.io coding-style-patch-verification: ON
8888 * eval: (c-set-style "gnu")