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> // alagalah TODO : committers please pay note, is this ok?
49 #include <vnet/vnet.h>
50 #include <vnet/l2/l2_input.h>
51 #include <vnet/l2/l2_bd.h>
52 #include <vnet/l2tp/l2tp.h>
53 #include <vnet/ip/ip.h>
54 #include <vnet/unix/tuntap.h>
55 #include <vnet/unix/tapcli.h>
56 #include <vnet/mpls-gre/mpls.h>
57 #include <vnet/dhcp/proxy.h>
58 #include <vnet/dhcp/client.h>
60 #include <vnet/sr/sr.h>
62 #include <vnet/dhcpv6/proxy.h>
63 #include <vlib/vlib.h>
64 #include <vlib/unix/unix.h>
65 #include <vlibapi/api.h>
66 #include <vlibmemory/api.h>
67 #include <vnet/classify/vnet_classify.h>
68 #include <vnet/classify/input_acl.h>
69 #include <vnet/classify/policer_classify.h>
70 #include <vnet/l2/l2_classify.h>
71 #include <vnet/vxlan/vxlan.h>
72 #include <vnet/gre/gre.h>
73 #include <vnet/l2/l2_vtr.h>
74 #include <vnet/vxlan-gpe/vxlan_gpe.h>
75 #include <vnet/lisp-gpe/lisp_gpe.h>
76 #include <vnet/lisp-cp/control.h>
77 #include <vnet/map/map.h>
78 #include <vnet/cop/cop.h>
79 #include <vnet/ip/ip6_hop_by_hop.h>
80 #include <vnet/ip/ip_source_and_port_range_check.h>
81 #include <vnet/devices/af_packet/af_packet.h>
82 #include <vnet/policer/policer.h>
83 #include <vnet/devices/netmap/netmap.h>
84 #include <vnet/flow/flow_report.h>
87 #undef __included_bihash_template_h__
88 #include <vnet/l2/l2_fib.h>
91 #include <vnet/ipsec/ipsec.h>
92 #include <vnet/ipsec/ikev2.h>
95 #include <vnet/devices/virtio/vhost-user.h>
98 #include <stats/stats.h>
101 #include <vnet/ethernet/ethernet.h>
102 #include <vnet/ethernet/arp_packet.h>
103 #include <vnet/interface.h>
105 #include <vnet/l2/l2_fib.h>
106 #include <vnet/l2/l2_bd.h>
107 #include <vpp-api/vpe_msg_enum.h>
109 #define f64_endian(a)
110 #define f64_print(a,b)
112 #define vl_typedefs /* define message structures */
113 #include <vpp-api/vpe_all_api_h.h>
116 #define vl_endianfun /* define message structures */
117 #include <vpp-api/vpe_all_api_h.h>
120 /* instantiate all the print functions we know about */
121 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
123 #include <vpp-api/vpe_all_api_h.h>
126 #define REPLY_MACRO(t) \
128 unix_shared_memory_queue_t * q; \
129 rv = vl_msg_api_pd_handler (mp, rv); \
130 q = vl_api_client_index_to_input_queue (mp->client_index); \
134 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
135 rmp->_vl_msg_id = ntohs((t)); \
136 rmp->context = mp->context; \
137 rmp->retval = ntohl(rv); \
139 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
142 #define REPLY_MACRO2(t, body) \
144 unix_shared_memory_queue_t * q; \
145 rv = vl_msg_api_pd_handler (mp, rv); \
146 q = vl_api_client_index_to_input_queue (mp->client_index); \
150 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
151 rmp->_vl_msg_id = ntohs((t)); \
152 rmp->context = mp->context; \
153 rmp->retval = ntohl(rv); \
154 do {body;} while (0); \
155 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
158 #if (1 || CLIB_DEBUG > 0) /* "trust, but verify" */
160 #define VALIDATE_SW_IF_INDEX(mp) \
161 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
162 vnet_main_t *__vnm = vnet_get_main(); \
163 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
165 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
166 goto bad_sw_if_index; \
170 #define BAD_SW_IF_INDEX_LABEL \
176 #define VALIDATE_RX_SW_IF_INDEX(mp) \
177 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
178 vnet_main_t *__vnm = vnet_get_main(); \
179 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
180 __rx_sw_if_index)) { \
181 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
182 goto bad_rx_sw_if_index; \
186 #define BAD_RX_SW_IF_INDEX_LABEL \
188 bad_rx_sw_if_index: \
192 #define VALIDATE_TX_SW_IF_INDEX(mp) \
193 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
194 vnet_main_t *__vnm = vnet_get_main(); \
195 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
196 __tx_sw_if_index)) { \
197 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
198 goto bad_tx_sw_if_index; \
202 #define BAD_TX_SW_IF_INDEX_LABEL \
204 bad_tx_sw_if_index: \
210 #define VALIDATE_SW_IF_INDEX(mp)
211 #define BAD_SW_IF_INDEX_LABEL
212 #define VALIDATE_RX_SW_IF_INDEX(mp)
213 #define BAD_RX_SW_IF_INDEX_LABEL
214 #define VALIDATE_TX_SW_IF_INDEX(mp)
215 #define BAD_TX_SW_IF_INDEX_LABEL
217 #endif /* CLIB_DEBUG > 0 */
219 #define foreach_vpe_api_msg \
220 _(WANT_INTERFACE_EVENTS, want_interface_events) \
221 _(WANT_OAM_EVENTS, want_oam_events) \
222 _(OAM_ADD_DEL, oam_add_del) \
223 _(SW_INTERFACE_DUMP, sw_interface_dump) \
224 _(SW_INTERFACE_DETAILS, sw_interface_details) \
225 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
226 _(IP_ADD_DEL_ROUTE, ip_add_del_route) \
227 _(IS_ADDRESS_REACHABLE, is_address_reachable) \
228 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
229 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
230 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
231 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
232 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
233 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
234 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
235 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
236 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
237 _(L2FIB_ADD_DEL, l2fib_add_del) \
238 _(L2_FLAGS, l2_flags) \
239 _(BRIDGE_FLAGS, bridge_flags) \
240 _(TAP_CONNECT, tap_connect) \
241 _(TAP_MODIFY, tap_modify) \
242 _(TAP_DELETE, tap_delete) \
243 _(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump) \
244 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
245 _(CREATE_SUBIF, create_subif) \
246 _(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel) \
247 _(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel) \
248 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2) \
249 _(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap) \
250 _(MPLS_ADD_DEL_DECAP, mpls_add_del_decap) \
251 _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \
252 _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \
253 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \
254 _(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \
255 _(RESET_FIB, reset_fib) \
256 _(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
257 _(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
258 _(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
259 _(DHCP_CLIENT_CONFIG, dhcp_client_config) \
260 _(SET_IP_FLOW_HASH,set_ip_flow_hash) \
261 _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \
262 _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \
263 _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \
264 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
265 sw_interface_ip6_set_link_local_address) \
266 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
267 _(CREATE_LOOPBACK, create_loopback) \
268 _(CONTROL_PING, control_ping) \
269 _(NOPRINT_CONTROL_PING, noprint_control_ping) \
270 _(CLI_REQUEST, cli_request) \
271 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \
272 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
273 _(CLASSIFY_ADD_DEL_TABLE, classify_add_del_table) \
274 _(CLASSIFY_ADD_DEL_SESSION, classify_add_del_session) \
275 _(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table) \
276 _(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables) \
277 _(GET_NODE_INDEX, get_node_index) \
278 _(ADD_NODE_NEXT, add_node_next) \
279 _(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel) \
280 _(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies) \
281 _(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable) \
282 _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
283 _(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
284 _(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
285 _(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
286 _(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \
287 _(GRE_TUNNEL_DUMP, gre_tunnel_dump) \
288 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
289 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
290 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
291 _(CREATE_VHOST_USER_IF, create_vhost_user_if) \
292 _(MODIFY_VHOST_USER_IF, modify_vhost_user_if) \
293 _(DELETE_VHOST_USER_IF, delete_vhost_user_if) \
294 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump) \
295 _(IP_ADDRESS_DUMP, ip_address_dump) \
296 _(IP_DUMP, ip_dump) \
297 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
298 _(SHOW_VERSION, show_version) \
299 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
300 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
301 _(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel) \
302 _(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump) \
303 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
304 _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \
305 _(INPUT_ACL_SET_INTERFACE, input_acl_set_interface) \
306 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
307 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
308 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
309 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
310 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
311 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
312 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
313 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
314 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
315 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
316 _(DELETE_LOOPBACK, delete_loopback) \
317 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
318 _(MAP_ADD_DOMAIN, map_add_domain) \
319 _(MAP_DEL_DOMAIN, map_del_domain) \
320 _(MAP_ADD_DEL_RULE, map_add_del_rule) \
321 _(MAP_DOMAIN_DUMP, map_domain_dump) \
322 _(MAP_RULE_DUMP, map_rule_dump) \
323 _(MAP_SUMMARY_STATS, map_summary_stats) \
324 _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
325 _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
326 _(GET_NODE_GRAPH, get_node_graph) \
327 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
328 _(TRACE_PROFILE_ADD, trace_profile_add) \
329 _(TRACE_PROFILE_APPLY, trace_profile_apply) \
330 _(TRACE_PROFILE_DEL, trace_profile_del) \
331 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
332 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
333 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
334 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
335 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
336 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
337 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
338 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface) \
339 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
340 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
341 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
342 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
343 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
344 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
345 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
346 _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \
347 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
348 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
349 _(SHOW_LISP_STATUS, show_lisp_status) \
350 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
351 lisp_add_del_map_request_itr_rlocs) \
352 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
353 _(SHOW_LISP_PITR, show_lisp_pitr) \
354 _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
355 _(AF_PACKET_CREATE, af_packet_create) \
356 _(AF_PACKET_DELETE, af_packet_delete) \
357 _(POLICER_ADD_DEL, policer_add_del) \
358 _(POLICER_DUMP, policer_dump) \
359 _(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface) \
360 _(POLICER_CLASSIFY_DUMP, policer_classify_dump) \
361 _(NETMAP_CREATE, netmap_create) \
362 _(NETMAP_DELETE, netmap_delete) \
363 _(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump) \
364 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
365 _(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump) \
366 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
367 _(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump) \
368 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
369 _(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump) \
370 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
371 _(CLASSIFY_TABLE_IDS,classify_table_ids) \
372 _(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface) \
373 _(CLASSIFY_TABLE_INFO,classify_table_info) \
374 _(CLASSIFY_SESSION_DUMP,classify_session_dump) \
375 _(CLASSIFY_SESSION_DETAILS,classify_session_details) \
376 _(IPFIX_ENABLE,ipfix_enable) \
377 _(IPFIX_DUMP,ipfix_dump) \
378 _(GET_NEXT_INDEX, get_next_index) \
379 _(PG_CREATE_INTERFACE, pg_create_interface) \
380 _(PG_CAPTURE, pg_capture) \
381 _(PG_ENABLE_DISABLE, pg_enable_disable) \
382 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
383 ip_source_and_port_range_check_add_del) \
384 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
385 ip_source_and_port_range_check_interface_add_del)
388 #define QUOTE(x) QUOTE_(x)
390 #define foreach_registration_hash \
391 _(interface_events) \
392 _(to_netconf_server) \
393 _(from_netconf_server) \
394 _(to_netconf_client) \
395 _(from_netconf_client) \
399 RESOLVE_IP4_ADD_DEL_ROUTE=1,
400 RESOLVE_IP6_ADD_DEL_ROUTE,
401 RESOLVE_MPLS_ETHERNET_ADD_DEL,
407 vl_api_ip_add_del_route_t r;
408 vl_api_mpls_ethernet_add_del_tunnel_2_t t;
414 #define _(a) uword *a##_registration_hash; \
415 vpe_client_registration_t * a##_registrations;
416 foreach_registration_hash
419 /* notifications happen really early in the game */
420 u8 link_state_process_up;
422 /* ip4 pending route adds */
423 pending_route_t * pending_routes;
425 /* ip4 arp event registration pool */
426 vl_api_ip4_arp_event_t * arp_events;
429 vlib_main_t * vlib_main;
430 vnet_main_t * vnet_main;
433 static vlib_node_registration_t vpe_resolver_process_node;
434 static vpe_api_main_t vpe_api_main;
436 static void send_sw_interface_flags (vpe_api_main_t * am,
437 unix_shared_memory_queue_t *q,
438 vnet_sw_interface_t * swif);
439 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
440 unix_shared_memory_queue_t *q,
443 static int arp_change_delete_callback (u32 pool_index, u8 * notused);
446 /* Clean up all registrations belonging to the indicated client */
447 int vl_api_memclnt_delete_callback (u32 client_index)
449 vpe_api_main_t * vam = &vpe_api_main;
450 vpe_client_registration_t *rp;
452 int stats_memclnt_delete_callback (u32 client_index);
454 stats_memclnt_delete_callback (client_index);
457 p = hash_get (vam->a##_registration_hash, client_index); \
459 rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
460 pool_put (vam->a##_registrations, rp); \
461 hash_unset (vam->a##_registration_hash, client_index); \
463 foreach_registration_hash;
468 #define API_LINK_STATE_EVENT 1
469 #define API_ADMIN_UP_DOWN_EVENT 2
472 event_data_cmp (void * a1, void * a2)
477 return (word) e1[0] - (word) e2[0];
481 link_state_process (vlib_main_t * vm,
482 vlib_node_runtime_t * rt,
485 vpe_api_main_t * vam = &vpe_api_main;
486 vnet_main_t * vnm = vam->vnet_main;
487 vnet_sw_interface_t * swif;
488 uword * event_data = 0;
489 vpe_client_registration_t *reg;
491 u32 prev_sw_if_index;
492 unix_shared_memory_queue_t * q;
494 vam->link_state_process_up = 1;
497 vlib_process_wait_for_event (vm);
499 /* Unified list of changed link or admin state sw_if_indices */
500 vlib_process_get_events_with_type
501 (vm, &event_data, API_LINK_STATE_EVENT);
502 vlib_process_get_events_with_type
503 (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
505 /* Sort, so we can eliminate duplicates */
506 vec_sort_with_function (event_data, event_data_cmp);
508 prev_sw_if_index = ~0;
510 for (i = 0; i < vec_len(event_data); i++) {
511 /* Only one message per swif */
512 if (prev_sw_if_index == event_data[i])
514 prev_sw_if_index = event_data[i];
516 pool_foreach(reg, vam->interface_events_registrations,
518 q = vl_api_client_index_to_input_queue (reg->client_index);
520 // sw_interface may be deleted already
521 if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
524 swif = vnet_get_sw_interface (vnm, event_data[i]);
525 send_sw_interface_flags (vam, q, swif);
530 vec_reset_length (event_data);
536 static clib_error_t *
537 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
538 static clib_error_t *
539 admin_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags);
541 VLIB_REGISTER_NODE (link_state_process_node,static) = {
542 .function = link_state_process,
543 .type = VLIB_NODE_TYPE_PROCESS,
544 .name = "vpe-link-state-process",
547 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
548 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
550 static clib_error_t *
551 link_up_down_function (vnet_main_t *vm, u32 hw_if_index, u32 flags)
553 vpe_api_main_t * vam = &vpe_api_main;
554 vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
556 if (vam->link_state_process_up)
557 vlib_process_signal_event (vam->vlib_main,
558 link_state_process_node.index,
559 API_LINK_STATE_EVENT,
564 static clib_error_t *
565 admin_up_down_function (vnet_main_t *vm, u32 sw_if_index, u32 flags)
567 vpe_api_main_t * vam = &vpe_api_main;
570 * Note: it's perfectly fair to set a subif admin up / admin down.
571 * Note the subtle distinction between this routine and the previous
574 if (vam->link_state_process_up)
575 vlib_process_signal_event (vam->vlib_main,
576 link_state_process_node.index,
577 API_ADMIN_UP_DOWN_EVENT,
582 #define pub_sub_handler(lca,UCA) \
583 static void vl_api_want_##lca##_t_handler ( \
584 vl_api_want_##lca##_t *mp) \
586 vpe_api_main_t *vam = &vpe_api_main; \
587 vpe_client_registration_t *rp; \
588 vl_api_want_##lca##_reply_t *rmp; \
592 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
594 if (mp->enable_disable) { \
595 clib_warning ("pid %d: already enabled...", mp->pid); \
596 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
599 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
600 pool_put (vam->lca##_registrations, rp); \
601 hash_unset (vam->lca##_registration_hash, \
606 if (mp->enable_disable == 0) { \
607 clib_warning ("pid %d: already disabled...", mp->pid); \
608 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
611 pool_get (vam->lca##_registrations, rp); \
612 rp->client_index = mp->client_index; \
613 rp->client_pid = mp->pid; \
614 hash_set (vam->lca##_registration_hash, rp->client_index, \
615 rp - vam->lca##_registrations); \
618 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
621 pub_sub_handler (interface_events,INTERFACE_EVENTS)
622 pub_sub_handler (oam_events,OAM_EVENTS)
624 #define RESOLUTION_EVENT 1
625 #define RESOLUTION_PENDING_EVENT 2
626 #define IP4_ARP_EVENT 3
628 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
629 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp);
630 static int mpls_ethernet_add_del_tunnel_2_t_handler
631 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp);
633 void handle_ip4_arp_event (u32 pool_index)
635 vpe_api_main_t * vam = &vpe_api_main;
636 vnet_main_t * vnm = vam->vnet_main;
637 vlib_main_t * vm = vam->vlib_main;
638 vl_api_ip4_arp_event_t * event;
639 vl_api_ip4_arp_event_t * mp;
640 unix_shared_memory_queue_t * q;
642 /* Client can cancel, die, etc. */
643 if (pool_is_free_index (vam->arp_events, pool_index))
646 event = pool_elt_at_index (vam->arp_events, pool_index);
648 q = vl_api_client_index_to_input_queue (event->client_index);
650 (void) vnet_add_del_ip4_arp_change_event
651 (vnm, arp_change_delete_callback,
652 event->pid, &event->address,
653 vpe_resolver_process_node.index, IP4_ARP_EVENT,
654 ~0 /* pool index, notused */, 0 /* is_add */);
658 if (q->cursize < q->maxsize) {
659 mp = vl_msg_api_alloc (sizeof (*mp));
660 clib_memcpy (mp, event, sizeof (*mp));
661 vl_msg_api_send_shmem (q, (u8 *)&mp);
663 static f64 last_time;
665 * Throttle syslog msgs.
666 * It's pretty tempting to just revoke the registration...
668 if (vlib_time_now (vm) > last_time + 10.0) {
669 clib_warning ("arp event for %U to pid %d: queue stuffed!",
670 format_ip4_address, &event->address, event->pid);
671 last_time = vlib_time_now(vm);
677 resolver_process (vlib_main_t * vm,
678 vlib_node_runtime_t * rt,
682 uword *event_data = 0;
684 vpe_api_main_t * vam = &vpe_api_main;
685 pending_route_t * pr;
686 vl_api_ip_add_del_route_t * adr;
687 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
688 u32 * resolution_failures = 0;
693 vlib_process_wait_for_event_or_clock (vm, timeout);
695 event_type = vlib_process_get_events (vm, &event_data);
697 switch (event_type) {
698 case RESOLUTION_PENDING_EVENT:
702 case RESOLUTION_EVENT:
703 for (i = 0; i < vec_len(event_data); i++) {
705 * Resolution events can occur long after the
706 * original request has timed out. $$$ add a cancel
709 if (pool_is_free_index (vam->pending_routes, event_data[i]))
712 pr = pool_elt_at_index (vam->pending_routes, event_data[i]);
716 switch (pr->resolve_type) {
717 case RESOLVE_IP4_ADD_DEL_ROUTE:
718 rv = ip4_add_del_route_t_handler (adr);
719 clib_warning ("resolver: add %U/%d via %U %s",
721 (ip4_address_t *)&(adr->dst_address),
722 adr->dst_address_length,
724 (ip4_address_t *)&(adr->next_hop_address),
725 (rv >= 0) ? "succeeded" : "failed");
728 case RESOLVE_IP6_ADD_DEL_ROUTE:
729 rv = ip6_add_del_route_t_handler (adr);
730 clib_warning ("resolver: add %U/%d via %U %s",
732 (ip6_address_t *)&(adr->dst_address),
733 adr->dst_address_length,
735 (ip6_address_t *)&(adr->next_hop_address),
736 (rv >= 0) ? "succeeded" : "failed");
739 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
740 rv = mpls_ethernet_add_del_tunnel_2_t_handler (pme);
741 clib_warning ("resolver: add mpls-o-e via %U %s",
743 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
744 (rv >= 0) ? "succeeded" : "failed");
748 clib_warning ("resolver: BOGUS TYPE %d", pr->resolve_type);
750 pool_put (vam->pending_routes, pr);
755 for (i = 0; i < vec_len(event_data); i++)
756 handle_ip4_arp_event (event_data[i]);
759 case ~0: /* timeout, retry pending resolutions */
760 pool_foreach (pr, vam->pending_routes,
766 /* May fail, e.g. due to interface down */
767 switch (pr->resolve_type) {
768 case RESOLVE_IP4_ADD_DEL_ROUTE:
769 e = ip4_probe_neighbor
770 (vm, (ip4_address_t *)&(adr->next_hop_address),
771 ntohl(adr->next_hop_sw_if_index));
774 case RESOLVE_IP6_ADD_DEL_ROUTE:
775 e = ip6_probe_neighbor
776 (vm, (ip6_address_t *)&(adr->next_hop_address),
777 ntohl(adr->next_hop_sw_if_index));
780 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
782 e = ip4_probe_neighbor
784 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
785 pme->resolve_opaque);
789 e = clib_error_return (0, "resolver: BOGUS TYPE %d",
793 clib_error_report (e);
795 adr->resolve_attempts = 1;
797 pme->resolve_attempts = 1;
801 adr->resolve_attempts -= 1;
802 if (adr->resolve_attempts == 0)
803 vec_add1 (resolution_failures,
804 pr - vam->pending_routes);
806 pme->resolve_attempts -= 1;
807 if (pme->resolve_attempts == 0)
808 vec_add1 (resolution_failures,
809 pr - vam->pending_routes);
813 for (i = 0; i < vec_len (resolution_failures); i++) {
814 pr = pool_elt_at_index (vam->pending_routes,
815 resolution_failures[i]);
819 switch (pr->resolve_type) {
820 case RESOLVE_IP4_ADD_DEL_ROUTE:
821 clib_warning ("resolver: add %U/%d via %U retry failure",
823 (ip4_address_t *)&(adr->dst_address),
824 adr->dst_address_length,
826 (ip4_address_t *)&(adr->next_hop_address));
829 case RESOLVE_IP6_ADD_DEL_ROUTE:
830 clib_warning ("resolver: add %U/%d via %U retry failure",
832 (ip6_address_t *)&(adr->dst_address),
833 adr->dst_address_length,
835 (ip6_address_t *)&(adr->next_hop_address));
838 case RESOLVE_MPLS_ETHERNET_ADD_DEL:
839 clib_warning ("resolver: add mpls-o-e via %U retry failure",
841 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf));
845 clib_warning ("BUG");
847 pool_put(vam->pending_routes, pr);
849 vec_reset_length (resolution_failures);
852 if (pool_elts (vam->pending_routes) == 0)
854 vec_reset_length (event_data);
856 return 0; /* or not */
859 VLIB_REGISTER_NODE (vpe_resolver_process_node,static) = {
860 .function = resolver_process,
861 .type = VLIB_NODE_TYPE_PROCESS,
862 .name = "vpe-route-resolver-process",
865 static int ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
867 ip4_main_t * im = &ip4_main;
868 ip_lookup_main_t * lm = &im->lookup_main;
869 vnet_classify_main_t * cm = &vnet_classify_main;
870 stats_main_t * sm = &stats_main;
871 ip4_add_del_route_args_t a;
872 ip4_address_t next_hop_address;
874 vpe_api_main_t * vam = &vpe_api_main;
875 vnet_main_t * vnm = vam->vnet_main;
876 vlib_main_t * vm = vlib_get_main();
877 pending_route_t * pr;
878 vl_api_ip_add_del_route_t * adr;
884 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
886 if (mp->create_vrf_if_needed) {
888 f = find_ip4_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
890 fib_index = f->index;
892 /* No such VRF, and we weren't asked to create one */
893 return VNET_API_ERROR_NO_SUCH_FIB;
899 if (~0 != mp->next_hop_sw_if_index &&
900 pool_is_free_index (vnm->interface_main.sw_interfaces,
901 ntohl(mp->next_hop_sw_if_index)))
902 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
904 clib_memcpy (next_hop_address.data, mp->next_hop_address,
905 sizeof (next_hop_address.data));
907 /* Arp for the next_hop if necessary */
908 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
910 ip_adjacency_t * adj;
912 lookup_result = ip4_fib_lookup_with_table
913 (im, fib_index, &next_hop_address, 1 /* disable default route */);
915 adj = ip_get_adjacency (lm, lookup_result);
917 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
918 pool_get (vam->pending_routes, pr);
919 pr->resolve_type = RESOLVE_IP4_ADD_DEL_ROUTE;
921 clib_memcpy (adr, mp, sizeof (*adr));
922 /* recursion block, "just in case" */
923 adr->resolve_if_needed = 0;
924 adr->resolve_attempts = ntohl(mp->resolve_attempts);
925 vnet_register_ip4_arp_resolution_event
926 (vnm, &next_hop_address, vpe_resolver_process_node.index,
927 RESOLUTION_EVENT, pr - vam->pending_routes);
929 vlib_process_signal_event
930 (vm, vpe_resolver_process_node.index,
931 RESOLUTION_PENDING_EVENT, 0 /* data */);
933 /* The interface may be down, etc. */
934 e = ip4_probe_neighbor
935 (vm, (ip4_address_t *)&(mp->next_hop_address),
936 ntohl(mp->next_hop_sw_if_index));
939 clib_error_report(e);
941 return VNET_API_ERROR_IN_PROGRESS;
945 if (mp->is_multipath) {
948 dslock (sm, 1 /* release hint */, 10 /* tag */);
951 flags = IP4_ROUTE_FLAG_ADD;
953 flags = IP4_ROUTE_FLAG_DEL;
956 flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
958 ip4_add_del_route_next_hop (im, flags,
959 (ip4_address_t *) mp->dst_address,
960 (u32) mp->dst_address_length,
961 (ip4_address_t *) mp->next_hop_address,
962 ntohl(mp->next_hop_sw_if_index),
963 (u32) mp->next_hop_weight,
970 memset (&a, 0, sizeof (a));
971 clib_memcpy (a.dst_address.data, mp->dst_address, sizeof (a.dst_address.data));
973 a.dst_address_length = mp->dst_address_length;
975 a.flags = (mp->is_add ? IP4_ROUTE_FLAG_ADD : IP4_ROUTE_FLAG_DEL);
976 a.flags |= IP4_ROUTE_FLAG_FIB_INDEX;
977 a.table_index_or_table_id = fib_index;
982 a.flags |= IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP;
984 dslock (sm, 1 /* release hint */, 2 /* tag */);
988 ai = lm->drop_adj_index;
989 else if (mp->is_local)
990 ai = lm->local_adj_index;
991 else if (mp->is_classify) {
992 if (pool_is_free_index (cm->tables, ntohl(mp->classify_table_index))) {
994 return VNET_API_ERROR_NO_SUCH_TABLE;
996 adj = ip_add_adjacency (lm,
1001 adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
1002 adj->classify.table_index = ntohl(mp->classify_table_index);
1004 else if (mp->lookup_in_vrf) {
1005 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1007 adj = ip_add_adjacency (lm,
1011 adj->explicit_fib_index = p[0];
1015 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1019 ai = ip4_route_get_next_hop_adj (im,
1022 ntohl(mp->next_hop_sw_if_index),
1025 if (ai == lm->miss_adj_index) {
1027 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1030 ip_adjacency_t * adj;
1031 int disable_default_route = 1;
1033 /* Trying to delete the default route? */
1034 if (a.dst_address.as_u32 == 0 &&
1035 a.dst_address_length == 0)
1036 disable_default_route = 0;
1038 ai = ip4_fib_lookup_with_table
1039 (im, fib_index, &a.dst_address, disable_default_route);
1040 if (ai == lm->miss_adj_index) {
1042 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1045 adj = ip_get_adjacency (lm, ai);
1046 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1048 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1053 ip4_add_del_route (im, &a);
1059 static int ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t *mp)
1061 ip6_main_t * im = &ip6_main;
1062 ip_lookup_main_t * lm = &im->lookup_main;
1063 vnet_main_t * vnm = vnet_get_main();
1064 vlib_main_t * vm = vlib_get_main();
1065 vpe_api_main_t * vam = &vpe_api_main;
1066 stats_main_t * sm = &stats_main;
1067 ip6_add_del_route_args_t a;
1068 ip6_address_t next_hop_address;
1069 pending_route_t * pr;
1070 vl_api_ip_add_del_route_t * adr;
1075 ip_adjacency_t *adj = 0;
1078 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
1081 if (mp->create_vrf_if_needed) {
1083 f = find_ip6_fib_by_table_index_or_id (im, ntohl(mp->vrf_id),
1085 fib_index = f->index;
1087 /* No such VRF, and we weren't asked to create one */
1088 return VNET_API_ERROR_NO_SUCH_FIB;
1094 if (~0 != mp->next_hop_sw_if_index &&
1095 pool_is_free_index (vnm->interface_main.sw_interfaces,
1096 ntohl(mp->next_hop_sw_if_index)))
1097 return VNET_API_ERROR_NO_MATCHING_INTERFACE;
1099 clib_memcpy (next_hop_address.as_u8, mp->next_hop_address,
1100 sizeof (next_hop_address.as_u8));
1102 /* Arp for the next_hop if necessary */
1103 if (mp->is_add && mp->resolve_if_needed && ~0 != mp->next_hop_sw_if_index) {
1105 ip_adjacency_t * adj;
1107 lookup_result = ip6_fib_lookup_with_table
1108 (im, fib_index, &next_hop_address);
1110 adj = ip_get_adjacency (lm, lookup_result);
1112 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1113 pool_get (vam->pending_routes, pr);
1115 pr->resolve_type = RESOLVE_IP6_ADD_DEL_ROUTE;
1116 clib_memcpy (adr, mp, sizeof (*adr));
1117 /* recursion block, "just in case" */
1118 adr->resolve_if_needed = 0;
1119 adr->resolve_attempts = ntohl(mp->resolve_attempts);
1120 vnet_register_ip6_neighbor_resolution_event
1121 (vnm, &next_hop_address, vpe_resolver_process_node.index,
1122 RESOLUTION_EVENT, pr - vam->pending_routes);
1124 vlib_process_signal_event
1125 (vm, vpe_resolver_process_node.index,
1126 RESOLUTION_PENDING_EVENT, 0 /* data */);
1128 /* The interface may be down, etc. */
1129 e = ip6_probe_neighbor
1130 (vm, (ip6_address_t *)&(mp->next_hop_address),
1131 ntohl(mp->next_hop_sw_if_index));
1134 clib_error_report(e);
1136 return VNET_API_ERROR_IN_PROGRESS;
1140 if (mp->is_multipath) {
1143 dslock (sm, 1 /* release hint */, 11 /* tag */);
1146 flags = IP6_ROUTE_FLAG_ADD;
1148 flags = IP6_ROUTE_FLAG_DEL;
1151 flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1153 ip6_add_del_route_next_hop (im, flags, (ip6_address_t *)mp->dst_address,
1154 (u32) mp->dst_address_length,
1155 (ip6_address_t *)mp->next_hop_address,
1156 ntohl(mp->next_hop_sw_if_index),
1157 (u32) mp->next_hop_weight,
1164 memset (&a, 0, sizeof (a));
1165 clib_memcpy (a.dst_address.as_u8, mp->dst_address, sizeof (a.dst_address.as_u8));
1167 a.dst_address_length = mp->dst_address_length;
1169 a.flags = (mp->is_add ? IP6_ROUTE_FLAG_ADD : IP6_ROUTE_FLAG_DEL);
1170 a.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
1171 a.table_index_or_table_id = fib_index;
1176 a.flags |= IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP;
1178 dslock (sm, 1 /* release hint */, 3 /* tag */);
1182 ai = lm->drop_adj_index;
1183 else if (mp->is_local)
1184 ai = lm->local_adj_index;
1185 else if (mp->lookup_in_vrf) {
1186 p = hash_get (im->fib_index_by_table_id, ntohl(mp->lookup_in_vrf));
1188 adj = ip_add_adjacency (lm,
1192 adj->explicit_fib_index = p[0];
1196 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
1200 ai = ip6_route_get_next_hop_adj (im,
1203 ntohl(mp->next_hop_sw_if_index),
1205 if (ai == lm->miss_adj_index) {
1207 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
1210 ip_adjacency_t * adj;
1212 ai = ip6_fib_lookup_with_table
1213 (im, fib_index, &a.dst_address);
1214 if (ai == lm->miss_adj_index) {
1216 return VNET_API_ERROR_UNKNOWN_DESTINATION;
1218 adj = ip_get_adjacency (lm, ai);
1219 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
1221 return VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
1226 ip6_add_del_route (im, &a);
1232 void vl_api_ip_add_del_route_t_handler (
1233 vl_api_ip_add_del_route_t *mp)
1235 vl_api_ip_add_del_route_reply_t * rmp;
1237 vnet_main_t * vnm = vnet_get_main();
1242 rv = ip6_add_del_route_t_handler (mp);
1244 rv = ip4_add_del_route_t_handler (mp);
1246 rv = (rv == 0) ? vnm->api_errno : rv;
1248 REPLY_MACRO(VL_API_IP_ADD_DEL_ROUTE_REPLY);
1251 void api_config_default_ip_route (u8 is_ipv6, u8 is_add, u32 vrf_id,
1252 u32 sw_if_index, u8 *next_hop_addr)
1254 vl_api_ip_add_del_route_t mp;
1257 memset (&mp, 0, sizeof(vl_api_ip_add_del_route_t));
1260 * Configure default IP route:
1261 * - ip route add 0.0.0.0/1 via <GW IP>
1262 * - ip route add 128.0.0.0/1 via <GW IP>
1264 mp.next_hop_sw_if_index = ntohl(sw_if_index);
1266 mp.resolve_attempts = ~0;
1267 mp.resolve_if_needed = 1;
1269 mp.is_ipv6 = is_ipv6;
1270 mp.next_hop_weight = 1;
1272 clib_memcpy (&mp.next_hop_address[0], next_hop_addr, 16);
1275 rv = ip6_add_del_route_t_handler (&mp);
1278 mp.dst_address_length = 1;
1280 mp.dst_address[0] = 0;
1281 rv = ip4_add_del_route_t_handler (&mp);
1283 mp.dst_address[0] = 128;
1284 rv |= ip4_add_del_route_t_handler (&mp);
1288 clib_error_return (0, "failed to config default IP route");
1293 vl_api_sw_interface_add_del_address_t_handler
1294 (vl_api_sw_interface_add_del_address_t *mp)
1296 vlib_main_t *vm = vlib_get_main();
1297 vl_api_sw_interface_add_del_address_reply_t * rmp;
1301 VALIDATE_SW_IF_INDEX(mp);
1303 is_del = mp->is_add == 0;
1306 ip_del_all_interface_addresses (vm, ntohl(mp->sw_if_index));
1307 else if (mp->is_ipv6)
1308 ip6_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1309 (void *)mp->address,
1310 mp->address_length, is_del);
1312 ip4_add_del_interface_address (vm, ntohl(mp->sw_if_index),
1313 (void *) mp->address,
1314 mp->address_length, is_del);
1316 BAD_SW_IF_INDEX_LABEL;
1318 REPLY_MACRO(VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
1322 vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t *mp)
1325 u32 table_id = ntohl(mp->vrf_id);
1326 u32 sw_if_index = ntohl(mp->sw_if_index);
1327 vl_api_sw_interface_set_table_reply_t * rmp;
1328 stats_main_t * sm = &stats_main;
1330 VALIDATE_SW_IF_INDEX(mp);
1332 dslock (sm, 1 /* release hint */, 4 /* tag */);
1335 ip6_main_t * im = &ip6_main;
1337 find_ip6_fib_by_table_index_or_id (im, table_id,
1338 IP6_ROUTE_FLAG_TABLE_ID);
1340 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1341 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1343 rv = VNET_API_ERROR_NO_SUCH_FIB;
1346 ip4_main_t * im = &ip4_main;
1347 ip4_fib_t * fib = find_ip4_fib_by_table_index_or_id
1348 (im, table_id, IP4_ROUTE_FLAG_TABLE_ID);
1350 /* Truthfully this can't fail */
1352 vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1353 im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
1355 rv = VNET_API_ERROR_NO_SUCH_FIB;
1360 BAD_SW_IF_INDEX_LABEL;
1362 REPLY_MACRO(VL_API_SW_INTERFACE_SET_TABLE_REPLY);
1366 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t *mp)
1368 vlib_main_t *vm = vlib_get_main();
1369 ip4_main_t * im4 = &ip4_main;
1370 ip6_main_t * im6 = &ip6_main;
1371 vl_api_sw_interface_set_vpath_reply_t * rmp;
1374 u32 sw_if_index = ntohl(mp->sw_if_index);
1375 ip4_main_t *ip4m = &ip4_main;
1376 ip6_main_t *ip6m = &ip6_main;
1377 ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
1378 ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
1379 ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
1380 ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
1381 ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
1382 ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
1384 VALIDATE_SW_IF_INDEX(mp);
1386 l2input_intf_bitmap_enable(sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1388 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1389 ci = vnet_config_add_feature(vm, &rx_cm4u->config_main,
1391 im4->ip4_unicast_rx_feature_vpath,
1393 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1394 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1395 ci = vnet_config_add_feature(vm, &rx_cm4m->config_main,
1397 im4->ip4_multicast_rx_feature_vpath,
1399 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1400 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1401 ci = vnet_config_add_feature(vm, &rx_cm6u->config_main,
1403 im6->ip6_unicast_rx_feature_vpath,
1405 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1406 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1407 ci = vnet_config_add_feature(vm, &rx_cm6m->config_main,
1409 im6->ip6_multicast_rx_feature_vpath,
1411 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1413 ci = rx_cm4u->config_index_by_sw_if_index[sw_if_index]; //IP4 unicast
1414 ci = vnet_config_del_feature(vm, &rx_cm4u->config_main,
1416 im4->ip4_unicast_rx_feature_vpath,
1418 rx_cm4u->config_index_by_sw_if_index[sw_if_index] = ci;
1419 ci = rx_cm4m->config_index_by_sw_if_index[sw_if_index]; //IP4 mcast
1420 ci = vnet_config_del_feature(vm, &rx_cm4m->config_main,
1422 im4->ip4_multicast_rx_feature_vpath,
1424 rx_cm4m->config_index_by_sw_if_index[sw_if_index] = ci;
1425 ci = rx_cm6u->config_index_by_sw_if_index[sw_if_index]; //IP6 unicast
1426 ci = vnet_config_del_feature(vm, &rx_cm6u->config_main,
1428 im6->ip6_unicast_rx_feature_vpath,
1430 rx_cm6u->config_index_by_sw_if_index[sw_if_index] = ci;
1431 ci = rx_cm6m->config_index_by_sw_if_index[sw_if_index]; //IP6 mcast
1432 ci = vnet_config_del_feature(vm, &rx_cm6m->config_main,
1434 im6->ip6_multicast_rx_feature_vpath,
1436 rx_cm6m->config_index_by_sw_if_index[sw_if_index] = ci;
1439 BAD_SW_IF_INDEX_LABEL;
1441 REPLY_MACRO(VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1445 vl_api_sw_interface_set_l2_xconnect_t_handler (
1446 vl_api_sw_interface_set_l2_xconnect_t *mp)
1448 vl_api_sw_interface_set_l2_xconnect_reply_t * rmp;
1450 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1451 u32 tx_sw_if_index = ntohl(mp->tx_sw_if_index);
1452 vlib_main_t *vm = vlib_get_main();
1453 vnet_main_t *vnm = vnet_get_main();
1455 VALIDATE_RX_SW_IF_INDEX(mp);
1458 VALIDATE_TX_SW_IF_INDEX(mp);
1459 rv = set_int_l2_mode(vm, vnm, MODE_L2_XC,
1460 rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
1462 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1465 BAD_RX_SW_IF_INDEX_LABEL;
1466 BAD_TX_SW_IF_INDEX_LABEL;
1468 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
1472 vl_api_sw_interface_set_l2_bridge_t_handler (
1473 vl_api_sw_interface_set_l2_bridge_t *mp)
1475 bd_main_t * bdm = &bd_main;
1476 vl_api_sw_interface_set_l2_bridge_reply_t * rmp;
1478 u32 rx_sw_if_index = ntohl(mp->rx_sw_if_index);
1479 u32 bd_id = ntohl(mp->bd_id);
1483 vlib_main_t *vm = vlib_get_main();
1484 vnet_main_t *vnm = vnet_get_main();
1486 VALIDATE_RX_SW_IF_INDEX(mp);
1488 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1491 //VALIDATE_TX_SW_IF_INDEX(mp);
1492 rv = set_int_l2_mode(vm, vnm, MODE_L2_BRIDGE,
1493 rx_sw_if_index, bd_index, bvi, shg, 0);
1495 rv = set_int_l2_mode(vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
1498 BAD_RX_SW_IF_INDEX_LABEL;
1500 REPLY_MACRO(VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
1504 vl_api_bridge_domain_add_del_t_handler (
1505 vl_api_bridge_domain_add_del_t *mp)
1507 vlib_main_t * vm = vlib_get_main ();
1508 bd_main_t * bdm = &bd_main;
1509 vl_api_bridge_domain_add_del_reply_t * rmp;
1511 u32 enable_flags = 0, disable_flags = 0;
1512 u32 bd_id = ntohl(mp->bd_id);
1516 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
1519 enable_flags |= L2_FLOOD;
1521 disable_flags |= L2_FLOOD;
1524 enable_flags |= L2_UU_FLOOD;
1526 disable_flags |= L2_UU_FLOOD;
1529 enable_flags |= L2_FWD;
1531 disable_flags |= L2_FWD;
1534 enable_flags |= L2_ARP_TERM;
1536 disable_flags |= L2_ARP_TERM;
1539 enable_flags |= L2_LEARN;
1541 disable_flags |= L2_LEARN;
1544 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */);
1547 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */);
1550 rv = bd_delete_bd_index(bdm, bd_id);
1552 REPLY_MACRO(VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
1555 static void vl_api_bridge_domain_details_t_handler (
1556 vl_api_bridge_domain_details_t * mp)
1558 clib_warning ("BUG");
1561 static void vl_api_bridge_domain_sw_if_details_t_handler (
1562 vl_api_bridge_domain_sw_if_details_t * mp)
1564 clib_warning ("BUG");
1567 static void send_bridge_domain_details (unix_shared_memory_queue_t *q,
1568 l2_bridge_domain_t * bd_config,
1572 vl_api_bridge_domain_details_t * mp;
1574 mp = vl_msg_api_alloc (sizeof (*mp));
1575 memset (mp, 0, sizeof (*mp));
1576 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
1577 mp->bd_id = ntohl (bd_config->bd_id);
1578 mp->flood = bd_feature_flood (bd_config);
1579 mp->uu_flood = bd_feature_uu_flood (bd_config);
1580 mp->forward = bd_feature_forward (bd_config);
1581 mp->learn = bd_feature_learn (bd_config);
1582 mp->arp_term = bd_feature_arp_term (bd_config);
1583 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
1584 mp->n_sw_ifs = ntohl (n_sw_ifs);
1585 mp->context = context;
1587 vl_msg_api_send_shmem (q, (u8 *)&mp);
1590 static void send_bd_sw_if_details (l2input_main_t * l2im,
1591 unix_shared_memory_queue_t *q,
1592 l2_flood_member_t * member, u32 bd_id,
1595 vl_api_bridge_domain_sw_if_details_t * mp;
1596 l2_input_config_t * input_cfg;
1598 mp = vl_msg_api_alloc (sizeof (*mp));
1599 memset (mp, 0, sizeof (*mp));
1600 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_SW_IF_DETAILS);
1601 mp->bd_id = ntohl (bd_id);
1602 mp->sw_if_index = ntohl (member->sw_if_index);
1603 input_cfg = vec_elt_at_index (l2im->configs, member->sw_if_index);
1604 mp->shg = input_cfg->shg;
1605 mp->context = context;
1607 vl_msg_api_send_shmem (q, (u8 *)&mp);
1610 static void vl_api_bridge_domain_dump_t_handler (
1611 vl_api_bridge_domain_dump_t *mp)
1613 bd_main_t * bdm = &bd_main;
1614 l2input_main_t * l2im = &l2input_main;
1615 unix_shared_memory_queue_t * q;
1616 l2_bridge_domain_t * bd_config;
1617 u32 bd_id, bd_index;
1620 q = vl_api_client_index_to_input_queue (mp->client_index);
1625 bd_id = ntohl(mp->bd_id);
1627 bd_index = (bd_id == ~0) ? 0 : bd_find_or_add_bd_index (bdm, bd_id);
1628 end = (bd_id == ~0) ? vec_len (l2im->bd_configs) : bd_index + 1;
1629 for (; bd_index < end; bd_index++) {
1630 bd_config = l2input_bd_config_from_index (l2im, bd_index);
1631 /* skip dummy bd_id 0 */
1632 if (bd_config && (bd_config->bd_id > 0)) {
1634 l2_flood_member_t * m;
1636 n_sw_ifs = vec_len (bd_config->members);
1637 send_bridge_domain_details (q, bd_config, n_sw_ifs, mp->context);
1639 vec_foreach (m, bd_config->members) {
1640 send_bd_sw_if_details (l2im, q, m, bd_config->bd_id, mp->context);
1647 vl_api_l2fib_add_del_t_handler (
1648 vl_api_l2fib_add_del_t *mp)
1650 bd_main_t * bdm = &bd_main;
1651 l2input_main_t * l2im = &l2input_main;
1652 vl_api_l2fib_add_del_reply_t * rmp;
1655 u32 sw_if_index = ntohl(mp->sw_if_index);
1656 u32 bd_id = ntohl(mp->bd_id);
1665 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1667 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1668 goto bad_sw_if_index;
1673 VALIDATE_SW_IF_INDEX(mp);
1674 if (vec_len(l2im->configs) <= sw_if_index) {
1675 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1676 goto bad_sw_if_index;
1678 l2_input_config_t * config;
1679 config = vec_elt_at_index(l2im->configs, sw_if_index);
1680 if (config->bridge == 0) {
1681 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1682 goto bad_sw_if_index;
1685 static_mac = mp->static_mac ? 1 : 0;
1686 filter_mac = mp->filter_mac ? 1 : 0;
1687 bvi_mac = mp->bvi_mac ? 1 : 0;
1688 l2fib_add_entry(mac, bd_index, sw_if_index, static_mac, filter_mac,
1691 l2fib_del_entry(mac, bd_index);
1694 BAD_SW_IF_INDEX_LABEL;
1696 REPLY_MACRO(VL_API_L2FIB_ADD_DEL_REPLY);
1700 vl_api_l2_flags_t_handler (
1701 vl_api_l2_flags_t *mp)
1703 vl_api_l2_flags_reply_t * rmp;
1705 u32 sw_if_index = ntohl(mp->sw_if_index);
1706 u32 flags = ntohl(mp->feature_bitmap);
1709 VALIDATE_SW_IF_INDEX(mp);
1712 if (flags & L2INPUT_FEAT_ ## a) \
1713 rbm = l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_ ## a, mp->is_set);
1714 foreach_l2input_feat;
1717 BAD_SW_IF_INDEX_LABEL;
1719 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, rmp->resulting_feature_bitmap = ntohl(rbm));
1723 vl_api_bridge_flags_t_handler (
1724 vl_api_bridge_flags_t *mp)
1726 vlib_main_t *vm = vlib_get_main();
1727 bd_main_t * bdm = &bd_main;
1728 vl_api_bridge_flags_reply_t * rmp;
1730 u32 bd_id = ntohl(mp->bd_id);
1732 u32 flags = ntohl(mp->feature_bitmap);
1735 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1737 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1743 bd_set_flags(vm, bd_index, flags, mp->is_set);
1746 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
1747 rmp->resulting_feature_bitmap = ntohl(flags));
1751 vl_api_bd_ip_mac_add_del_t_handler (
1752 vl_api_bd_ip_mac_add_del_t *mp)
1754 bd_main_t * bdm = &bd_main;
1755 vl_api_bd_ip_mac_add_del_reply_t * rmp;
1757 u32 bd_id = ntohl(mp->bd_id);
1761 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1763 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1768 if (bd_add_del_ip_mac(bd_index, mp->ip_address,
1769 mp->mac_address, mp->is_ipv6, mp->is_add))
1770 rv = VNET_API_ERROR_UNSPECIFIED;
1773 REPLY_MACRO(VL_API_BD_IP_MAC_ADD_DEL_REPLY);
1777 vl_api_tap_connect_t_handler (vl_api_tap_connect_t *mp, vlib_main_t *vm)
1780 vl_api_tap_connect_reply_t * rmp;
1781 unix_shared_memory_queue_t * q;
1782 u32 sw_if_index = (u32)~0;
1784 rv = vnet_tap_connect_renumber (vm, mp->tap_name,
1785 mp->use_random_mac ? 0 : mp->mac_address,
1786 &sw_if_index, mp->renumber,
1787 ntohl(mp->custom_dev_instance));
1789 q = vl_api_client_index_to_input_queue (mp->client_index);
1793 rmp = vl_msg_api_alloc (sizeof (*rmp));
1794 rmp->_vl_msg_id = ntohs(VL_API_TAP_CONNECT_REPLY);
1795 rmp->context = mp->context;
1796 rmp->retval = ntohl(rv);
1797 rmp->sw_if_index = ntohl(sw_if_index);
1799 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1803 vl_api_tap_modify_t_handler (vl_api_tap_modify_t *mp, vlib_main_t *vm)
1806 vl_api_tap_modify_reply_t * rmp;
1807 unix_shared_memory_queue_t * q;
1808 u32 sw_if_index = (u32)~0;
1810 rv = vnet_tap_modify (vm, ntohl(mp->sw_if_index), mp->tap_name,
1811 mp->use_random_mac ? 0 : mp->mac_address,
1812 &sw_if_index, mp->renumber,
1813 ntohl(mp->custom_dev_instance));
1815 q = vl_api_client_index_to_input_queue (mp->client_index);
1819 rmp = vl_msg_api_alloc (sizeof (*rmp));
1820 rmp->_vl_msg_id = ntohs(VL_API_TAP_MODIFY_REPLY);
1821 rmp->context = mp->context;
1822 rmp->retval = ntohl(rv);
1823 rmp->sw_if_index = ntohl(sw_if_index);
1825 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1829 vl_api_tap_delete_t_handler (vl_api_tap_delete_t *mp, vlib_main_t *vm)
1832 vpe_api_main_t * vam = &vpe_api_main;
1833 vl_api_tap_delete_reply_t * rmp;
1834 unix_shared_memory_queue_t * q;
1835 u32 sw_if_index = ntohl(mp->sw_if_index);
1837 rv = vnet_tap_delete (vm, sw_if_index);
1839 q = vl_api_client_index_to_input_queue (mp->client_index);
1843 rmp = vl_msg_api_alloc (sizeof (*rmp));
1844 rmp->_vl_msg_id = ntohs(VL_API_TAP_DELETE_REPLY);
1845 rmp->context = mp->context;
1846 rmp->retval = ntohl(rv);
1848 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1851 send_sw_interface_flags_deleted (vam, q, sw_if_index);
1855 vl_api_create_vlan_subif_t_handler (vl_api_create_vlan_subif_t * mp)
1857 vl_api_create_vlan_subif_reply_t * rmp;
1858 vnet_main_t * vnm = vnet_get_main();
1859 u32 hw_if_index, sw_if_index = (u32)~0;
1860 vnet_hw_interface_t * hi;
1863 vnet_sw_interface_t template;
1865 vnet_interface_main_t * im = &vnm->interface_main;
1866 u64 sup_and_sub_key;
1868 unix_shared_memory_queue_t * q;
1869 clib_error_t * error;
1871 VALIDATE_SW_IF_INDEX(mp);
1873 hw_if_index = ntohl(mp->sw_if_index);
1874 hi = vnet_get_hw_interface (vnm, hw_if_index);
1876 id = ntohl(mp->vlan_id);
1877 if (id == 0 || id > 4095) {
1878 rv = VNET_API_ERROR_INVALID_VLAN;
1882 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) | (u64) id;
1884 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1886 rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1890 kp = clib_mem_alloc (sizeof (*kp));
1891 *kp = sup_and_sub_key;
1893 memset (&template, 0, sizeof (template));
1894 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1895 template.sup_sw_if_index = hi->sw_if_index;
1896 template.sub.id = id;
1897 template.sub.eth.raw_flags = 0;
1898 template.sub.eth.flags.one_tag = 1;
1899 template.sub.eth.outer_vlan_id = id;
1900 template.sub.eth.flags.exact_match = 1;
1902 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1904 clib_error_report(error);
1905 rv = VNET_API_ERROR_INVALID_REGISTRATION;
1908 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1909 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1911 BAD_SW_IF_INDEX_LABEL;
1914 q = vl_api_client_index_to_input_queue (mp->client_index);
1918 rmp = vl_msg_api_alloc (sizeof (*rmp));
1919 rmp->_vl_msg_id = ntohs(VL_API_CREATE_VLAN_SUBIF_REPLY);
1920 rmp->context = mp->context;
1921 rmp->retval = ntohl(rv);
1922 rmp->sw_if_index = ntohl(sw_if_index);
1923 vl_msg_api_send_shmem (q, (u8 *)&rmp);
1927 vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
1929 vl_api_create_subif_reply_t * rmp;
1930 vnet_main_t * vnm = vnet_get_main();
1931 u32 sw_if_index = ~0;
1934 vnet_sw_interface_t *si;
1935 vnet_hw_interface_t *hi;
1936 vnet_sw_interface_t template;
1938 vnet_interface_main_t * im = &vnm->interface_main;
1939 u64 sup_and_sub_key;
1941 clib_error_t * error;
1943 VALIDATE_SW_IF_INDEX(mp);
1945 si = vnet_get_sup_sw_interface (vnm, ntohl(mp->sw_if_index));
1946 hi = vnet_get_sup_hw_interface (vnm, ntohl(mp->sw_if_index));
1948 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
1949 rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1953 sw_if_index = si->sw_if_index;
1954 sub_id = ntohl(mp->sub_id);
1956 sup_and_sub_key = ((u64)(sw_if_index) << 32) | (u64) sub_id;
1958 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1961 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
1962 sw_if_index, sub_id);
1963 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
1967 kp = clib_mem_alloc (sizeof (*kp));
1968 *kp = sup_and_sub_key;
1970 memset (&template, 0, sizeof (template));
1971 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1972 template.sup_sw_if_index = sw_if_index;
1973 template.sub.id = sub_id;
1974 template.sub.eth.flags.no_tags = mp->no_tags;
1975 template.sub.eth.flags.one_tag = mp->one_tag;
1976 template.sub.eth.flags.two_tags = mp->two_tags;
1977 template.sub.eth.flags.dot1ad = mp->dot1ad;
1978 template.sub.eth.flags.exact_match = mp->exact_match;
1979 template.sub.eth.flags.default_sub = mp->default_sub;
1980 template.sub.eth.flags.outer_vlan_id_any = mp->outer_vlan_id_any;
1981 template.sub.eth.flags.inner_vlan_id_any = mp->inner_vlan_id_any;
1982 template.sub.eth.outer_vlan_id = ntohs(mp->outer_vlan_id);
1983 template.sub.eth.inner_vlan_id = ntohs(mp->inner_vlan_id);
1985 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1987 clib_error_report (error);
1988 rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
1992 hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
1993 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1995 BAD_SW_IF_INDEX_LABEL;
1999 REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
2001 rmp->sw_if_index = ntohl(sw_if_index);
2006 vl_api_mpls_gre_add_del_tunnel_t_handler (vl_api_mpls_gre_add_del_tunnel_t *mp)
2008 vl_api_mpls_gre_add_del_tunnel_reply_t * rmp;
2010 stats_main_t * sm = &stats_main;
2011 u32 tunnel_sw_if_index = ~0;
2013 dslock (sm, 1 /* release hint */, 5 /* tag */);
2015 rv = vnet_mpls_gre_add_del_tunnel ((ip4_address_t *)(mp->src_address),
2016 (ip4_address_t *)(mp->dst_address),
2017 (ip4_address_t *)(mp->intfc_address),
2018 (u32)(mp->intfc_address_length),
2019 ntohl(mp->inner_vrf_id),
2020 ntohl(mp->outer_vrf_id),
2021 &tunnel_sw_if_index,
2026 REPLY_MACRO2(VL_API_MPLS_GRE_ADD_DEL_TUNNEL_REPLY,
2028 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2033 vl_api_mpls_ethernet_add_del_tunnel_t_handler
2034 (vl_api_mpls_ethernet_add_del_tunnel_t *mp)
2036 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2038 stats_main_t * sm = &stats_main;
2039 u32 tunnel_sw_if_index;
2041 dslock (sm, 1 /* release hint */, 5 /* tag */);
2043 rv = vnet_mpls_ethernet_add_del_tunnel
2044 (mp->dst_mac_address, (ip4_address_t *)(mp->adj_address),
2045 (u32)(mp->adj_address_length), ntohl(mp->vrf_id),
2046 ntohl(mp->tx_sw_if_index),
2047 &tunnel_sw_if_index,
2053 REPLY_MACRO2(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY,
2055 rmp->tunnel_sw_if_index = ntohl(tunnel_sw_if_index);
2060 * This piece of misery brought to you because the control-plane
2061 * can't figure out the tx interface + dst-mac address all by itself
2063 static int mpls_ethernet_add_del_tunnel_2_t_handler
2064 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2066 pending_route_t * pr;
2067 vl_api_mpls_ethernet_add_del_tunnel_2_t *pme;
2068 vnet_main_t * vnm = vnet_get_main();
2069 vlib_main_t * vm = vlib_get_main();
2070 stats_main_t * sm = &stats_main;
2071 vpe_api_main_t * vam = &vpe_api_main;
2072 u32 inner_fib_index, outer_fib_index;
2073 ip4_main_t * im = &ip4_main;
2074 ip_lookup_main_t * lm = &im->lookup_main;
2075 ip_adjacency_t * adj = 0;
2078 u8 * dst_mac_address;
2082 u32 tunnel_sw_if_index;
2084 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_vrf_id));
2086 return VNET_API_ERROR_NO_SUCH_FIB;
2088 outer_fib_index = p[0];
2091 p = hash_get (im->fib_index_by_table_id, ntohl(mp->inner_vrf_id));
2093 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
2095 inner_fib_index = p[0];
2097 if (inner_fib_index == outer_fib_index)
2098 return VNET_API_ERROR_INVALID_VALUE;
2100 lookup_result = ip4_fib_lookup_with_table
2101 (im, outer_fib_index,
2102 (ip4_address_t *)mp->next_hop_ip4_address_in_outer_vrf,
2103 1 /* disable default route */);
2105 adj = ip_get_adjacency (lm, lookup_result);
2106 tx_sw_if_index = adj->rewrite_header.sw_if_index;
2108 if (mp->is_add && mp->resolve_if_needed) {
2109 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP) {
2110 pool_get (vam->pending_routes, pr);
2111 pr->resolve_type = RESOLVE_MPLS_ETHERNET_ADD_DEL;
2113 clib_memcpy (pme, mp, sizeof (*pme));
2114 /* recursion block, "just in case" */
2115 pme->resolve_if_needed = 0;
2116 pme->resolve_attempts = ntohl(mp->resolve_attempts);
2117 pme->resolve_opaque = tx_sw_if_index;
2118 vnet_register_ip4_arp_resolution_event
2120 (ip4_address_t *)&(pme->next_hop_ip4_address_in_outer_vrf),
2121 vpe_resolver_process_node.index,
2122 RESOLUTION_EVENT, pr - vam->pending_routes);
2124 vlib_process_signal_event
2125 (vm, vpe_resolver_process_node.index,
2126 RESOLUTION_PENDING_EVENT, 0 /* data */);
2128 /* The interface may be down, etc. */
2129 e = ip4_probe_neighbor
2130 (vm, (ip4_address_t *)&(mp->next_hop_ip4_address_in_outer_vrf),
2134 clib_error_report(e);
2136 return VNET_API_ERROR_IN_PROGRESS;
2140 if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
2141 return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB;
2144 vnet_rewrite_get_data_internal
2145 (&adj->rewrite_header, sizeof (adj->rewrite_data));
2147 dslock (sm, 1 /* release hint */, 10 /* tag */);
2149 rv = vnet_mpls_ethernet_add_del_tunnel
2150 (dst_mac_address, (ip4_address_t *)(mp->adj_address),
2151 (u32)(mp->adj_address_length), ntohl(mp->inner_vrf_id),
2152 tx_sw_if_index, &tunnel_sw_if_index, mp->l2_only, mp->is_add);
2160 vl_api_mpls_ethernet_add_del_tunnel_2_t_handler
2161 (vl_api_mpls_ethernet_add_del_tunnel_2_t *mp)
2163 vl_api_mpls_ethernet_add_del_tunnel_reply_t * rmp;
2166 rv = mpls_ethernet_add_del_tunnel_2_t_handler (mp);
2168 REPLY_MACRO(VL_API_MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY);
2173 vl_api_mpls_add_del_encap_t_handler (vl_api_mpls_add_del_encap_t *mp)
2175 vl_api_mpls_add_del_encap_reply_t * rmp;
2177 static u32 * labels;
2180 vec_reset_length (labels);
2182 for (i = 0; i < mp->nlabels; i++)
2183 vec_add1 (labels, ntohl(mp->labels[i]));
2186 rv = vnet_mpls_add_del_encap ((ip4_address_t *)mp->dst_address,
2187 ntohl(mp->vrf_id), labels,
2188 ~0 /* policy_tunnel_index */,
2189 0 /* no_dst_hash */,
2193 REPLY_MACRO(VL_API_MPLS_ADD_DEL_ENCAP_REPLY);
2197 vl_api_mpls_add_del_decap_t_handler
2198 (vl_api_mpls_add_del_decap_t *mp)
2200 vl_api_mpls_add_del_decap_reply_t * rmp;
2203 rv = vnet_mpls_add_del_decap (ntohl(mp->rx_vrf_id), ntohl(mp->tx_vrf_id),
2204 ntohl(mp->label), ntohl(mp->next_index),
2205 mp->s_bit, mp->is_add);
2207 REPLY_MACRO(VL_API_MPLS_ADD_DEL_DECAP_REPLY);
2211 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t *mp)
2213 vl_api_proxy_arp_add_del_reply_t * rmp;
2216 ip4_main_t * im = &ip4_main;
2217 stats_main_t * sm = &stats_main;
2218 int vnet_proxy_arp_add_del (ip4_address_t *lo_addr,
2219 ip4_address_t *hi_addr,
2220 u32 fib_index, int is_del);
2223 dslock (sm, 1 /* release hint */, 6 /* tag */);
2225 p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2228 rv = VNET_API_ERROR_NO_SUCH_FIB;
2234 rv = vnet_proxy_arp_add_del ((ip4_address_t *)mp->low_address,
2235 (ip4_address_t *)mp->hi_address,
2236 fib_index, mp->is_add == 0);
2240 REPLY_MACRO(VL_API_PROXY_ARP_ADD_DEL_REPLY);
2244 vl_api_proxy_arp_intfc_enable_disable_t_handler
2245 (vl_api_proxy_arp_intfc_enable_disable_t *mp)
2248 vnet_main_t * vnm = vnet_get_main();
2249 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
2250 vnet_sw_interface_t * si;
2253 VALIDATE_SW_IF_INDEX(mp);
2255 sw_if_index = ntohl(mp->sw_if_index);
2257 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
2259 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2263 si = vnet_get_sw_interface (vnm, sw_if_index);
2267 if (mp->enable_disable)
2268 si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2270 si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP;
2272 BAD_SW_IF_INDEX_LABEL;
2275 REPLY_MACRO(VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
2279 vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t *mp, vlib_main_t * vm)
2281 vl_api_ip_neighbor_add_del_reply_t * rmp;
2282 vnet_main_t * vnm = vnet_get_main();
2285 stats_main_t * sm = &stats_main;
2287 VALIDATE_SW_IF_INDEX(mp);
2289 dslock (sm, 1 /* release hint */, 7 /* tag */);
2293 rv = vnet_set_ip6_ethernet_neighbor
2294 (vm, ntohl(mp->sw_if_index),
2295 (ip6_address_t *)(mp->dst_address),
2296 mp->mac_address, sizeof (mp->mac_address), mp->is_static);
2298 rv = vnet_unset_ip6_ethernet_neighbor
2299 (vm, ntohl(mp->sw_if_index),
2300 (ip6_address_t *)(mp->dst_address),
2301 mp->mac_address, sizeof(mp->mac_address));
2303 ip4_main_t * im = &ip4_main;
2304 ip_lookup_main_t * lm = &im->lookup_main;
2305 ethernet_arp_ip4_over_ethernet_address_t a;
2307 ip_adjacency_t *nh_adj;
2309 uword * p = hash_get (im->fib_index_by_table_id, ntohl(mp->vrf_id));
2311 rv = VNET_API_ERROR_NO_SUCH_FIB;
2317 * Unfortunately, folks have a penchant for
2318 * adding interface addresses to the ARP cache, and
2319 * wondering why the forwarder eventually ASSERTs...
2321 ai = ip4_fib_lookup_with_table
2322 (im, fib_index, (ip4_address_t *)(mp->dst_address),
2323 1 /* disable default route */);
2326 nh_adj = ip_get_adjacency (lm, ai);
2327 /* Never allow manipulation of a local adj! */
2328 if (nh_adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL) {
2329 clib_warning("%U matches local adj",
2331 (ip4_address_t *)(mp->dst_address));
2332 rv = VNET_API_ERROR_ADDRESS_MATCHES_INTERFACE_ADDRESS;
2337 clib_memcpy (&a.ethernet, mp->mac_address, 6);
2338 clib_memcpy (&a.ip4, mp->dst_address, 4);
2341 rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2342 fib_index, &a, mp->is_static);
2344 rv = vnet_arp_unset_ip4_over_ethernet (vnm, ntohl(mp->sw_if_index),
2348 BAD_SW_IF_INDEX_LABEL;
2351 REPLY_MACRO(VL_API_IP_NEIGHBOR_ADD_DEL_REPLY);
2355 vl_api_is_address_reachable_t_handler (vl_api_is_address_reachable_t *mp)
2358 vpe_main_t *rm = &vpe_main;
2359 ip4_main_t *im4 = &ip4_main;
2360 ip6_main_t *im6 = &ip6_main;
2361 ip_lookup_main_t * lm;
2366 u32 adj_index, sw_if_index;
2367 vl_api_is_address_reachable_t *rmp;
2368 ip_adjacency_t * adj;
2369 unix_shared_memory_queue_t *q;
2371 q = vl_api_client_index_to_input_queue (mp->client_index);
2373 increment_missing_api_client_counter (rm->vlib_main);
2377 rmp = vl_msg_api_alloc (sizeof (*rmp));
2378 clib_memcpy (rmp, mp, sizeof (*rmp));
2380 sw_if_index = mp->next_hop_sw_if_index;
2381 clib_memcpy (&addr, mp->address, sizeof (addr));
2383 lm = &im6->lookup_main;
2385 ip6_fib_lookup (im6, sw_if_index, &addr.ip6);
2387 lm = &im4->lookup_main;
2389 ip4_fib_lookup (im4, sw_if_index, &addr.ip4);
2391 if (adj_index == ~0) {
2395 adj = ip_get_adjacency (lm, adj_index);
2397 if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE
2398 && adj->rewrite_header.sw_if_index == sw_if_index) {
2401 if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
2402 && adj->rewrite_header.sw_if_index == sw_if_index) {
2404 ip6_probe_neighbor (rm->vlib_main, &addr.ip6, sw_if_index);
2406 ip4_probe_neighbor (rm->vlib_main, &addr.ip4, sw_if_index);
2407 } else if (adj->lookup_next_index == IP_LOOKUP_NEXT_DROP) {
2415 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2419 static void vl_api_sw_interface_details_t_handler (
2420 vl_api_sw_interface_details_t * mp)
2422 clib_warning ("BUG");
2425 static void vl_api_sw_interface_set_flags_t_handler (
2426 vl_api_sw_interface_set_flags_t * mp)
2428 vl_api_sw_interface_set_flags_reply_t *rmp;
2429 vnet_main_t * vnm = vnet_get_main();
2431 clib_error_t * error;
2434 VALIDATE_SW_IF_INDEX(mp);
2436 flags = mp->admin_up_down ? VNET_SW_INTERFACE_FLAG_ADMIN_UP : 0;
2438 error = vnet_sw_interface_set_flags (vnm,
2439 ntohl(mp->sw_if_index),
2443 clib_error_report (error);
2446 BAD_SW_IF_INDEX_LABEL;
2447 REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
2450 static void vl_api_sw_interface_clear_stats_t_handler (
2451 vl_api_sw_interface_clear_stats_t * mp)
2453 vl_api_sw_interface_clear_stats_reply_t *rmp;
2455 vnet_main_t * vnm = vnet_get_main();
2456 vnet_interface_main_t * im = &vnm->interface_main;
2457 vlib_simple_counter_main_t * sm;
2458 vlib_combined_counter_main_t * cm;
2459 static vnet_main_t ** my_vnet_mains;
2460 int i, j, n_counters;
2464 vec_reset_length (my_vnet_mains);
2466 for (i = 0; i < vec_len (vnet_mains); i++)
2469 vec_add1 (my_vnet_mains, vnet_mains[i]);
2472 if (vec_len (vnet_mains) == 0)
2473 vec_add1 (my_vnet_mains, vnm);
2475 n_counters = vec_len (im->combined_sw_if_counters);
2477 for (j = 0; j < n_counters; j++)
2479 for (i = 0; i < vec_len(my_vnet_mains); i++)
2481 im = &my_vnet_mains[i]->interface_main;
2482 cm = im->combined_sw_if_counters + j;
2483 if (mp->sw_if_index == (u32)~0)
2484 vlib_clear_combined_counters (cm);
2486 vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
2490 n_counters = vec_len (im->sw_if_counters);
2492 for (j = 0; j < n_counters; j++)
2494 for (i = 0; i < vec_len(my_vnet_mains); i++)
2496 im = &my_vnet_mains[i]->interface_main;
2497 sm = im->sw_if_counters + j;
2498 if (mp->sw_if_index == (u32)~0)
2499 vlib_clear_simple_counters (sm);
2501 vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
2505 REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
2508 static void send_sw_interface_details (vpe_api_main_t * am,
2509 unix_shared_memory_queue_t *q,
2510 vnet_sw_interface_t * swif,
2511 u8 * interface_name,
2514 vl_api_sw_interface_details_t * mp;
2515 vnet_hw_interface_t * hi;
2517 hi = vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
2519 mp = vl_msg_api_alloc (sizeof (*mp));
2520 memset (mp, 0, sizeof (*mp));
2521 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_DETAILS);
2522 mp->sw_if_index = ntohl(swif->sw_if_index);
2523 mp->sup_sw_if_index = ntohl(swif->sup_sw_if_index);
2524 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2526 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2528 mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >>
2529 VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
2530 mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
2531 VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
2532 mp->link_mtu = ntohs(hi->max_packet_bytes);
2533 mp->context = context;
2535 strncpy ((char *) mp->interface_name,
2536 (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
2538 /* Send the L2 address for ethernet physical intfcs */
2539 if (swif->sup_sw_if_index == swif->sw_if_index
2540 && hi->hw_class_index == ethernet_hw_interface_class.index) {
2541 ethernet_main_t *em = ethernet_get_main (am->vlib_main);
2542 ethernet_interface_t *ei;
2544 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
2545 ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
2546 clib_memcpy (mp->l2_address, ei->address, sizeof (ei->address));
2547 mp->l2_address_length = ntohl(sizeof (ei->address));
2548 } else if (swif->sup_sw_if_index != swif->sw_if_index) {
2549 vnet_sub_interface_t *sub = &swif->sub;
2550 mp->sub_id = ntohl(sub->id);
2551 mp->sub_dot1ad = sub->eth.flags.dot1ad;
2552 mp->sub_number_of_tags = sub->eth.flags.one_tag + sub->eth.flags.two_tags*2;
2553 mp->sub_outer_vlan_id = ntohs(sub->eth.outer_vlan_id);
2554 mp->sub_inner_vlan_id = ntohs(sub->eth.inner_vlan_id);
2555 mp->sub_exact_match = sub->eth.flags.exact_match;
2556 mp->sub_default = sub->eth.flags.default_sub;
2557 mp->sub_outer_vlan_id_any = sub->eth.flags.outer_vlan_id_any;
2558 mp->sub_inner_vlan_id_any = sub->eth.flags.inner_vlan_id_any;
2560 /* vlan tag rewrite data */
2561 u32 vtr_op = L2_VTR_DISABLED;
2562 u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
2564 if (l2vtr_get(am->vlib_main, am->vnet_main, swif->sw_if_index,
2565 &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0) {
2566 // error - default to disabled
2567 mp->vtr_op = ntohl(L2_VTR_DISABLED);
2568 clib_warning("cannot get vlan tag rewrite for sw_if_index %d",
2571 mp->vtr_op = ntohl(vtr_op);
2572 mp->vtr_push_dot1q = ntohl(vtr_push_dot1q);
2573 mp->vtr_tag1 = ntohl(vtr_tag1);
2574 mp->vtr_tag2 = ntohl(vtr_tag2);
2578 vl_msg_api_send_shmem (q, (u8 *)&mp);
2581 static void send_sw_interface_flags (vpe_api_main_t * am,
2582 unix_shared_memory_queue_t *q,
2583 vnet_sw_interface_t * swif)
2585 vl_api_sw_interface_set_flags_t *mp;
2586 vnet_main_t * vnm = am->vnet_main;
2588 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
2590 mp = vl_msg_api_alloc (sizeof (*mp));
2591 memset (mp, 0, sizeof (*mp));
2592 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2593 mp->sw_if_index = ntohl(swif->sw_if_index);
2595 mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
2597 mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
2599 vl_msg_api_send_shmem (q, (u8 *)&mp);
2602 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2603 unix_shared_memory_queue_t *q,
2605 __attribute__((unused));
2607 static void send_sw_interface_flags_deleted (vpe_api_main_t * am,
2608 unix_shared_memory_queue_t *q,
2611 vl_api_sw_interface_set_flags_t *mp;
2613 mp = vl_msg_api_alloc (sizeof (*mp));
2614 memset (mp, 0, sizeof (*mp));
2615 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_SET_FLAGS);
2616 mp->sw_if_index = ntohl(sw_if_index);
2618 mp->admin_up_down = 0;
2619 mp->link_up_down = 0;
2621 vl_msg_api_send_shmem (q, (u8 *)&mp);
2624 static void vl_api_sw_interface_dump_t_handler (
2625 vl_api_sw_interface_dump_t *mp)
2627 vpe_api_main_t * am = &vpe_api_main;
2628 vnet_sw_interface_t * swif;
2629 vnet_interface_main_t * im = &am->vnet_main->interface_main;
2630 u8 * filter_string = 0, * name_string = 0;
2631 unix_shared_memory_queue_t * q;
2632 char * strcasestr (char *, char *); /* lnx hdr file botch */
2634 q = vl_api_client_index_to_input_queue (mp->client_index);
2639 if (mp->name_filter_valid) {
2640 mp->name_filter [ARRAY_LEN(mp->name_filter)-1] = 0;
2641 filter_string = format (0, "%s%c", mp->name_filter, 0);
2644 pool_foreach (swif, im->sw_interfaces,
2646 name_string = format (name_string, "%U%c",
2647 format_vnet_sw_interface_name,
2648 am->vnet_main, swif, 0);
2650 if (mp->name_filter_valid == 0 ||
2651 strcasestr((char *) name_string, (char *) filter_string)) {
2653 send_sw_interface_details (am, q, swif, name_string, mp->context);
2655 _vec_len (name_string) = 0;
2658 vec_free (name_string);
2659 vec_free (filter_string);
2662 void send_oam_event (oam_target_t * t)
2664 vpe_api_main_t * vam = &vpe_api_main;
2665 unix_shared_memory_queue_t * q;
2666 vpe_client_registration_t *reg;
2667 vl_api_oam_event_t * mp;
2669 pool_foreach(reg, vam->oam_events_registrations,
2671 q = vl_api_client_index_to_input_queue (reg->client_index);
2673 mp = vl_msg_api_alloc (sizeof (*mp));
2674 mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
2675 clib_memcpy (mp->dst_address, &t->dst_address, sizeof (mp->dst_address));
2676 mp->state = t->state;
2677 vl_msg_api_send_shmem (q, (u8 *)&mp);
2683 vl_api_oam_add_del_t_handler (vl_api_oam_add_del_t *mp)
2685 vl_api_oam_add_del_reply_t * rmp;
2688 rv = vpe_oam_add_del_target ((ip4_address_t *)mp->src_address,
2689 (ip4_address_t *)mp->dst_address,
2693 REPLY_MACRO(VL_API_OAM_ADD_DEL_REPLY);
2697 vl_api_vnet_get_summary_stats_t_handler (
2698 vl_api_vnet_get_summary_stats_t *mp)
2700 stats_main_t * sm = &stats_main;
2701 vnet_interface_main_t * im = sm->interface_main;
2702 vl_api_vnet_summary_stats_reply_t *rmp;
2703 vlib_combined_counter_main_t * cm;
2706 u64 total_pkts[VLIB_N_RX_TX];
2707 u64 total_bytes[VLIB_N_RX_TX];
2709 unix_shared_memory_queue_t * q =
2710 vl_api_client_index_to_input_queue (mp->client_index);
2715 rmp = vl_msg_api_alloc (sizeof (*rmp));
2716 rmp->_vl_msg_id = ntohs(VL_API_VNET_SUMMARY_STATS_REPLY);
2717 rmp->context = mp->context;
2720 memset (total_pkts, 0, sizeof (total_pkts));
2721 memset (total_bytes, 0, sizeof (total_bytes));
2723 vnet_interface_counter_lock (im);
2725 vec_foreach (cm, im->combined_sw_if_counters) {
2726 which = cm - im->combined_sw_if_counters;
2728 for (i = 0; i < vec_len (cm->maxi); i++) {
2729 vlib_get_combined_counter (cm, i, &v);
2730 total_pkts[which] += v.packets;
2731 total_bytes[which] += v.bytes;
2734 vnet_interface_counter_unlock (im);
2736 /* Note: in HOST byte order! */
2737 rmp->total_pkts[VLIB_RX] = total_pkts[VLIB_RX];
2738 rmp->total_bytes[VLIB_RX] = total_bytes[VLIB_RX];
2739 rmp->total_pkts[VLIB_TX] = total_pkts[VLIB_TX];
2740 rmp->total_bytes[VLIB_TX] = total_bytes[VLIB_TX];
2741 rmp->vector_rate = vlib_last_vector_length_per_node (sm->vlib_main);
2743 vl_msg_api_send_shmem (q, (u8 *)&rmp);
2746 typedef CLIB_PACKED (struct {
2747 ip4_address_t address;
2749 u32 address_length : 6;
2754 static int ip4_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2756 vnet_main_t * vnm = vnet_get_main();
2757 vnet_interface_main_t * im = &vnm->interface_main;
2758 ip4_main_t * im4 = &ip4_main;
2759 static ip4_route_t * routes;
2760 static u32 * sw_if_indices_to_shut;
2761 stats_main_t * sm = &stats_main;
2766 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2767 u32 target_fib_id = ntohl(mp->vrf_id);
2769 dslock (sm, 1 /* release hint */, 8 /* tag */);
2771 vec_foreach (fib, im4->fibs) {
2772 vnet_sw_interface_t * si;
2774 if (fib->table_id != target_fib_id)
2777 /* remove any mpls/gre tunnels in this fib */
2778 vnet_mpls_gre_delete_fib_tunnels (fib->table_id);
2780 /* remove any mpls encap/decap labels */
2781 mpls_fib_reset_labels (fib->table_id);
2783 /* remove any proxy arps in this fib */
2784 vnet_proxy_arp_fib_reset (fib->table_id);
2786 /* Set the flow hash for this fib to the default */
2787 vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT);
2789 vec_reset_length (sw_if_indices_to_shut);
2791 /* Shut down interfaces in this FIB / clean out intfc routes */
2792 pool_foreach (si, im->sw_interfaces,
2794 u32 sw_if_index = si->sw_if_index;
2796 if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index)
2797 && (im4->fib_index_by_sw_if_index[si->sw_if_index] ==
2799 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2802 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2803 sw_if_index = sw_if_indices_to_shut[i];
2804 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2806 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2807 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2808 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2811 vec_reset_length (routes);
2813 for (i = 0; i < ARRAY_LEN (fib->adj_index_by_dst_address); i++) {
2814 uword * hash = fib->adj_index_by_dst_address[i];
2818 x.address_length = i;
2820 hash_foreach_pair (p, hash,
2822 x.address.data_u32 = p->key;
2823 vec_add1 (routes, x);
2827 vec_foreach (r, routes) {
2828 ip4_add_del_route_args_t a;
2830 memset (&a, 0, sizeof (a));
2831 a.flags = IP4_ROUTE_FLAG_FIB_INDEX | IP4_ROUTE_FLAG_DEL;
2832 a.table_index_or_table_id = fib - im4->fibs;
2833 a.dst_address = r->address;
2834 a.dst_address_length = r->address_length;
2837 ip4_add_del_route (im4, &a);
2838 ip4_maybe_remap_adjacencies (im4, fib - im4->fibs,
2839 IP4_ROUTE_FLAG_FIB_INDEX);
2843 } /* vec_foreach (fib) */
2850 ip6_address_t address;
2857 ip6_route_t ** routep;
2858 } add_routes_in_fib_arg_t;
2860 static void add_routes_in_fib (clib_bihash_kv_24_8_t * kvp, void *arg)
2862 add_routes_in_fib_arg_t * ap = arg;
2864 if (kvp->key[2]>>32 == ap->fib_index)
2866 ip6_address_t *addr;
2868 addr = (ip6_address_t *) kvp;
2869 vec_add2 (*ap->routep, r, 1);
2870 r->address = addr[0];
2871 r->address_length = kvp->key[2] & 0xFF;
2872 r->index = kvp->value;
2876 static int ip6_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2878 vnet_main_t * vnm = vnet_get_main();
2879 vnet_interface_main_t * im = &vnm->interface_main;
2880 ip6_main_t * im6 = &ip6_main;
2881 stats_main_t * sm = &stats_main;
2882 static ip6_route_t * routes;
2883 static u32 * sw_if_indices_to_shut;
2888 int rv = VNET_API_ERROR_NO_SUCH_FIB;
2889 u32 target_fib_id = ntohl(mp->vrf_id);
2890 add_routes_in_fib_arg_t _a, *a=&_a;
2891 clib_bihash_24_8_t * h = &im6->ip6_lookup_table;
2893 dslock (sm, 1 /* release hint */, 9 /* tag */);
2895 vec_foreach (fib, im6->fibs) {
2896 vnet_sw_interface_t * si;
2898 if (fib->table_id != target_fib_id)
2901 vec_reset_length (sw_if_indices_to_shut);
2903 /* Shut down interfaces in this FIB / clean out intfc routes */
2904 pool_foreach (si, im->sw_interfaces,
2906 if (im6->fib_index_by_sw_if_index[si->sw_if_index] ==
2908 vec_add1 (sw_if_indices_to_shut, si->sw_if_index);
2911 for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) {
2912 sw_if_index = sw_if_indices_to_shut[i];
2913 // vec_foreach (sw_if_index, sw_if_indices_to_shut) {
2915 u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index);
2916 flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP);
2917 vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
2920 vec_reset_length (routes);
2922 a->fib_index = fib - im6->fibs;
2923 a->routep = &routes;
2925 clib_bihash_foreach_key_value_pair_24_8 (h, add_routes_in_fib, a);
2927 vec_foreach (r, routes) {
2928 ip6_add_del_route_args_t a;
2930 memset (&a, 0, sizeof (a));
2931 a.flags = IP6_ROUTE_FLAG_FIB_INDEX | IP6_ROUTE_FLAG_DEL;
2932 a.table_index_or_table_id = fib - im6->fibs;
2933 a.dst_address = r->address;
2934 a.dst_address_length = r->address_length;
2937 ip6_add_del_route (im6, &a);
2938 ip6_maybe_remap_adjacencies (im6, fib - im6->fibs,
2939 IP6_ROUTE_FLAG_FIB_INDEX);
2942 /* Reinstall the neighbor / router discovery routes */
2943 vnet_ip6_fib_init (im6, fib - im6->fibs);
2945 } /* vec_foreach (fib) */
2951 static void vl_api_reset_fib_t_handler (vl_api_reset_fib_t *mp)
2954 vl_api_reset_fib_reply_t * rmp;
2957 rv = ip6_reset_fib_t_handler (mp);
2959 rv = ip4_reset_fib_t_handler (mp);
2961 REPLY_MACRO(VL_API_RESET_FIB_REPLY);
2966 dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2968 vl_api_dhcp_proxy_config_reply_t * rmp;
2971 rv = dhcp_proxy_set_server ((ip4_address_t *)(&mp->dhcp_server),
2972 (ip4_address_t *)(&mp->dhcp_src_address),
2973 (u32) ntohl(mp->vrf_id),
2974 (int) mp->insert_circuit_id,
2975 (int) (mp->is_add == 0));
2977 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2982 dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t *mp)
2984 vl_api_dhcp_proxy_config_reply_t * rmp;
2987 rv = dhcpv6_proxy_set_server ((ip6_address_t *)(&mp->dhcp_server),
2988 (ip6_address_t *)(&mp->dhcp_src_address),
2989 (u32) ntohl(mp->vrf_id),
2990 (int) mp->insert_circuit_id,
2991 (int) (mp->is_add == 0));
2993 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_REPLY);
2997 dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
2999 vl_api_dhcp_proxy_config_reply_t * rmp;
3002 rv = dhcp_proxy_set_server_2 ((ip4_address_t *)(&mp->dhcp_server),
3003 (ip4_address_t *)(&mp->dhcp_src_address),
3004 (u32) ntohl(mp->rx_vrf_id),
3005 (u32) ntohl(mp->server_vrf_id),
3006 (int) mp->insert_circuit_id,
3007 (int) (mp->is_add == 0));
3009 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3014 dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t *mp)
3016 vl_api_dhcp_proxy_config_reply_t * rmp;
3020 rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *)(&mp->dhcp_server),
3021 (ip6_address_t *)(&mp->dhcp_src_address),
3022 (u32) ntohl(mp->rx_vrf_id),
3023 (u32) ntohl(mp->server_vrf_id),
3024 (int) mp->insert_circuit_id,
3025 (int) (mp->is_add == 0));
3027 rv = VNET_API_ERROR_UNIMPLEMENTED;
3030 REPLY_MACRO(VL_API_DHCP_PROXY_CONFIG_2_REPLY);
3035 vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t *mp)
3037 vl_api_dhcp_proxy_set_vss_reply_t *rmp;
3040 rv = dhcp_proxy_set_option82_vss(ntohl(mp->tbl_id),
3043 (int)mp->is_add == 0);
3045 rv = dhcpv6_proxy_set_vss( ntohl(mp->tbl_id),
3048 (int)mp->is_add == 0);
3050 REPLY_MACRO(VL_API_DHCP_PROXY_SET_VSS_REPLY);
3054 static void vl_api_dhcp_proxy_config_t_handler
3055 (vl_api_dhcp_proxy_config_t *mp)
3057 if (mp->is_ipv6 == 0)
3058 dhcpv4_proxy_config (mp);
3060 dhcpv6_proxy_config (mp);
3063 static void vl_api_dhcp_proxy_config_2_t_handler
3064 (vl_api_dhcp_proxy_config_2_t *mp)
3066 if (mp->is_ipv6 == 0)
3067 dhcpv4_proxy_config_2 (mp);
3069 dhcpv6_proxy_config_2 (mp);
3072 void dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
3073 u8 is_ipv6, u8 * host_address, u8 * router_address, u8 * host_mac)
3075 unix_shared_memory_queue_t * q;
3076 vl_api_dhcp_compl_event_t * mp;
3078 q = vl_api_client_index_to_input_queue (client_index);
3082 mp = vl_msg_api_alloc (sizeof (*mp));
3083 mp->client_index = client_index;
3085 mp->is_ipv6 = is_ipv6;
3086 clib_memcpy (&mp->hostname, hostname, vec_len(hostname));
3087 mp->hostname[vec_len(hostname) + 1] = '\n';
3088 clib_memcpy (&mp->host_address[0], host_address, 16);
3089 clib_memcpy (&mp->router_address[0], router_address, 16);
3090 clib_memcpy (&mp->host_mac[0], host_mac, 6);
3092 mp->_vl_msg_id = ntohs (VL_API_DHCP_COMPL_EVENT);
3094 vl_msg_api_send_shmem (q, (u8 *)&mp);
3097 static void vl_api_dhcp_client_config_t_handler
3098 (vl_api_dhcp_client_config_t *mp)
3100 vlib_main_t *vm = vlib_get_main();
3101 vl_api_dhcp_client_config_reply_t * rmp;
3104 VALIDATE_SW_IF_INDEX(mp);
3106 rv = dhcp_client_config(vm, ntohl(mp->sw_if_index),
3107 mp->hostname, mp->is_add, mp->client_index,
3108 mp->want_dhcp_event ? dhcp_compl_event_callback : NULL,
3111 BAD_SW_IF_INDEX_LABEL;
3113 REPLY_MACRO(VL_API_DHCP_CLIENT_CONFIG_REPLY);
3117 vl_api_sw_interface_ip6nd_ra_config_t_handler
3118 (vl_api_sw_interface_ip6nd_ra_config_t *mp, vlib_main_t *vm)
3120 vl_api_sw_interface_ip6nd_ra_config_reply_t * rmp;
3122 u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, default_router;
3124 is_no = mp->is_no == 1;
3125 suppress = mp->suppress == 1;
3126 managed = mp->managed == 1;
3127 other = mp->other == 1;
3128 ll_option = mp->ll_option == 1;
3129 send_unicast = mp->send_unicast == 1;
3130 cease = mp->cease == 1;
3131 default_router = mp->default_router == 1;
3133 VALIDATE_SW_IF_INDEX(mp);
3135 rv = ip6_neighbor_ra_config(vm, ntohl(mp->sw_if_index),
3136 suppress, managed, other,
3137 ll_option, send_unicast, cease,
3138 default_router, ntohl (mp->lifetime),
3139 ntohl(mp->initial_count), ntohl(mp->initial_interval),
3140 ntohl(mp->max_interval), ntohl( mp->min_interval),
3143 BAD_SW_IF_INDEX_LABEL;
3145 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY);
3149 vl_api_sw_interface_ip6nd_ra_prefix_t_handler
3150 (vl_api_sw_interface_ip6nd_ra_prefix_t *mp, vlib_main_t *vm)
3152 vl_api_sw_interface_ip6nd_ra_prefix_reply_t * rmp;
3154 u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink;
3156 VALIDATE_SW_IF_INDEX(mp);
3158 is_no = mp->is_no == 1;
3159 use_default = mp->use_default == 1;
3160 no_advertise = mp->no_advertise == 1;
3161 off_link = mp->off_link == 1;
3162 no_autoconfig = mp->no_autoconfig == 1;
3163 no_onlink = mp->no_onlink == 1;
3165 rv = ip6_neighbor_ra_prefix(vm, ntohl(mp->sw_if_index),
3166 (ip6_address_t *)mp->address, mp->address_length,
3167 use_default, ntohl(mp->val_lifetime), ntohl(mp->pref_lifetime),
3168 no_advertise, off_link, no_autoconfig, no_onlink,
3171 BAD_SW_IF_INDEX_LABEL;
3172 REPLY_MACRO(VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY);
3176 vl_api_sw_interface_ip6_enable_disable_t_handler
3177 (vl_api_sw_interface_ip6_enable_disable_t *mp, vlib_main_t *vm)
3179 vl_api_sw_interface_ip6_enable_disable_reply_t * rmp;
3180 vnet_main_t * vnm = vnet_get_main();
3182 clib_error_t * error;
3186 VALIDATE_SW_IF_INDEX(mp);
3188 error = ( mp->enable == 1) ? enable_ip6_interface(vm,ntohl(mp->sw_if_index)) :
3189 disable_ip6_interface(vm,ntohl(mp->sw_if_index));
3192 clib_error_report(error);
3193 rv = VNET_API_ERROR_UNSPECIFIED;
3195 rv = vnm->api_errno;
3198 BAD_SW_IF_INDEX_LABEL;
3200 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY);
3204 vl_api_sw_interface_ip6_set_link_local_address_t_handler
3205 (vl_api_sw_interface_ip6_set_link_local_address_t *mp, vlib_main_t *vm)
3207 vl_api_sw_interface_ip6_set_link_local_address_reply_t * rmp;
3209 clib_error_t * error;
3210 vnet_main_t * vnm = vnet_get_main();
3214 VALIDATE_SW_IF_INDEX(mp);
3216 error = set_ip6_link_local_address(vm,
3217 ntohl(mp->sw_if_index),
3218 (ip6_address_t *)mp->address,
3219 mp->address_length);
3221 clib_error_report(error);
3222 rv = VNET_API_ERROR_UNSPECIFIED;
3224 rv = vnm->api_errno;
3227 BAD_SW_IF_INDEX_LABEL;
3229 REPLY_MACRO(VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY);
3232 static void set_ip6_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3234 vl_api_set_ip_flow_hash_reply_t *rmp;
3235 int rv = VNET_API_ERROR_UNIMPLEMENTED;
3237 clib_warning ("unimplemented...");
3239 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3242 static void set_ip4_flow_hash (vl_api_set_ip_flow_hash_t *mp)
3244 vl_api_set_ip_flow_hash_reply_t *rmp;
3247 u32 flow_hash_config = 0;
3249 table_id = ntohl(mp->vrf_id);
3251 #define _(a,b) if (mp->a) flow_hash_config |= b;
3252 foreach_flow_hash_bit;
3255 rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config);
3257 REPLY_MACRO(VL_API_SET_IP_FLOW_HASH_REPLY);
3261 static void vl_api_set_ip_flow_hash_t_handler
3262 (vl_api_set_ip_flow_hash_t *mp)
3264 if (mp->is_ipv6 == 0)
3265 set_ip4_flow_hash (mp);
3267 set_ip6_flow_hash (mp);
3270 static void vl_api_sw_interface_set_unnumbered_t_handler
3271 (vl_api_sw_interface_set_unnumbered_t *mp)
3273 vl_api_sw_interface_set_unnumbered_reply_t * rmp;
3275 vnet_sw_interface_t * si;
3276 vnet_main_t *vnm = vnet_get_main();
3277 u32 sw_if_index, unnumbered_sw_if_index;
3279 sw_if_index = ntohl(mp->sw_if_index);
3280 unnumbered_sw_if_index = ntohl(mp->unnumbered_sw_if_index);
3283 * The API message field names are backwards from
3284 * the underlying data structure names.
3285 * It's not worth changing them now.
3287 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
3288 unnumbered_sw_if_index)) {
3289 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
3293 /* Only check the "use loop0" field when setting the binding */
3295 pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) {
3296 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
3300 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
3303 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
3304 si->unnumbered_sw_if_index = sw_if_index;
3306 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
3307 si->unnumbered_sw_if_index = (u32)~0;
3311 REPLY_MACRO(VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
3314 static void vl_api_create_loopback_t_handler
3315 (vl_api_create_loopback_t *mp)
3317 vl_api_create_loopback_reply_t * rmp;
3321 rv = vnet_create_loopback_interface (&sw_if_index, mp->mac_address);
3323 REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
3325 rmp->sw_if_index = ntohl (sw_if_index);
3329 static void vl_api_delete_loopback_t_handler
3330 (vl_api_delete_loopback_t *mp)
3332 vl_api_delete_loopback_reply_t * rmp;
3336 sw_if_index = ntohl (mp->sw_if_index);
3337 rv = vnet_delete_loopback_interface (sw_if_index);
3339 REPLY_MACRO(VL_API_DELETE_LOOPBACK_REPLY);
3342 static void vl_api_control_ping_t_handler
3343 (vl_api_control_ping_t *mp)
3345 vl_api_control_ping_reply_t * rmp;
3348 REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
3350 rmp->vpe_pid = ntohl (getpid());
3354 static void vl_api_noprint_control_ping_t_handler
3355 (vl_api_noprint_control_ping_t *mp)
3357 vl_api_noprint_control_ping_reply_t * rmp;
3360 REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY,
3362 rmp->vpe_pid = ntohl (getpid());
3366 static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
3368 u8 **shmem_vecp = (u8 **)arg;
3371 api_main_t * am = &api_main;
3374 shmem_vec = *shmem_vecp;
3376 offset = vec_len (shmem_vec);
3378 pthread_mutex_lock (&am->vlib_rp->mutex);
3379 oldheap = svm_push_data_heap (am->vlib_rp);
3381 vec_validate (shmem_vec, offset + buffer_bytes - 1);
3383 clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
3385 svm_pop_heap (oldheap);
3386 pthread_mutex_unlock (&am->vlib_rp->mutex);
3388 *shmem_vecp = shmem_vec;
3392 static void vl_api_cli_request_t_handler
3393 (vl_api_cli_request_t *mp)
3395 vl_api_cli_reply_t *rp;
3396 unix_shared_memory_queue_t *q;
3397 vlib_main_t * vm = vlib_get_main();
3398 api_main_t * am = &api_main;
3399 unformat_input_t input;
3403 q = vl_api_client_index_to_input_queue (mp->client_index);
3407 rp = vl_msg_api_alloc (sizeof (*rp));
3408 rp->_vl_msg_id = ntohs(VL_API_CLI_REPLY);
3409 rp->context = mp->context;
3411 unformat_init_vector (&input, (u8 *)(uword)mp->cmd_in_shmem);
3413 vlib_cli_input (vm, &input, shmem_cli_output,
3416 pthread_mutex_lock (&am->vlib_rp->mutex);
3417 oldheap = svm_push_data_heap (am->vlib_rp);
3419 vec_add1(shmem_vec, 0);
3421 svm_pop_heap (oldheap);
3422 pthread_mutex_unlock (&am->vlib_rp->mutex);
3424 rp->reply_in_shmem = (uword)shmem_vec;
3426 vl_msg_api_send_shmem (q, (u8 *)&rp);
3429 static void vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t *mp)
3432 vl_api_set_arp_neighbor_limit_reply_t * rmp;
3433 vnet_main_t *vnm = vnet_get_main();
3434 clib_error_t * error;
3439 error = ip6_set_neighbor_limit (ntohl(mp->arp_neighbor_limit));
3441 error = ip4_set_arp_limit (ntohl(mp->arp_neighbor_limit));
3444 clib_error_report(error);
3445 rv = VNET_API_ERROR_UNSPECIFIED;
3447 rv = vnm->api_errno;
3450 REPLY_MACRO(VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
3453 static void vl_api_sr_tunnel_add_del_t_handler
3454 (vl_api_sr_tunnel_add_del_t *mp)
3457 clib_warning ("unimplemented");
3459 ip6_sr_add_del_tunnel_args_t _a, *a=&_a;
3461 vl_api_sr_tunnel_add_del_reply_t * rmp;
3462 ip6_address_t * segments = 0, * seg;
3463 ip6_address_t * tags = 0, *tag;
3464 ip6_address_t * this_address;
3467 if (mp->n_segments == 0) {
3472 memset (a, 0, sizeof (*a));
3473 a->src_address = (ip6_address_t *)&mp->src_address;
3474 a->dst_address = (ip6_address_t *)&mp->dst_address;
3475 a->dst_mask_width = mp->dst_mask_width;
3476 a->flags_net_byte_order = mp->flags_net_byte_order;
3477 a->is_del = (mp->is_add == 0);
3478 a->rx_table_id = ntohl(mp->outer_vrf_id);
3479 a->tx_table_id = ntohl(mp->inner_vrf_id);
3481 a->name = format(0, "%s", mp->name);
3482 if (!(vec_len(a->name)))
3485 a->policy_name = format(0, "%s", mp->policy_name);
3486 if (!(vec_len(a->policy_name)))
3489 /* Yank segments and tags out of the API message */
3490 this_address = (ip6_address_t *)mp->segs_and_tags;
3491 for (i = 0; i < mp->n_segments; i++) {
3492 vec_add2 (segments, seg, 1);
3493 clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address));
3496 for (i = 0; i < mp->n_tags; i++) {
3497 vec_add2 (tags, tag, 1);
3498 clib_memcpy (tag->as_u8, this_address->as_u8, sizeof (*this_address));
3502 a->segments = segments;
3505 rv = ip6_sr_add_del_tunnel (a);
3509 REPLY_MACRO(VL_API_SR_TUNNEL_ADD_DEL_REPLY);
3513 static void vl_api_sr_policy_add_del_t_handler
3514 (vl_api_sr_policy_add_del_t *mp)
3517 clib_warning ("unimplemented");
3519 ip6_sr_add_del_policy_args_t _a, *a=&_a;
3521 vl_api_sr_policy_add_del_reply_t * rmp;
3524 memset (a, 0, sizeof (*a));
3525 a->is_del = (mp->is_add == 0);
3527 a->name = format(0, "%s", mp->name);
3528 if (!(vec_len(a->name)))
3530 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3534 if (!(mp->tunnel_names[0]))
3536 rv = VNET_API_ERROR_NO_SUCH_NODE2;
3540 // start deserializing tunnel_names
3541 int num_tunnels = mp->tunnel_names[0]; //number of tunnels
3542 u8 * deser_tun_names = mp->tunnel_names;
3543 deser_tun_names += 1; //moving along
3546 int tun_name_len = 0;
3548 for (i=0; i < num_tunnels; i++)
3550 tun_name_len= *deser_tun_names;
3551 deser_tun_names += 1;
3552 vec_resize (tun_name, tun_name_len);
3553 memcpy(tun_name, deser_tun_names, tun_name_len);
3554 vec_add1 (a->tunnel_names, tun_name);
3555 deser_tun_names += tun_name_len;
3559 rv = ip6_sr_add_del_policy (a);
3563 REPLY_MACRO(VL_API_SR_POLICY_ADD_DEL_REPLY);
3567 static void vl_api_sr_multicast_map_add_del_t_handler
3568 (vl_api_sr_multicast_map_add_del_t *mp)
3571 clib_warning ("unimplemented");
3573 ip6_sr_add_del_multicastmap_args_t _a, *a=&_a;
3575 vl_api_sr_multicast_map_add_del_reply_t * rmp;
3577 memset (a, 0, sizeof (*a));
3578 a->is_del = (mp->is_add == 0);
3580 a->multicast_address = (ip6_address_t *)&mp->multicast_address;
3581 a->policy_name = format(0, "%s", mp->policy_name);
3583 if (a->multicast_address == 0)
3589 if (!(a->policy_name))
3595 #if DPDK > 0 /* Cannot call replicate without DPDK */
3596 rv = ip6_sr_add_del_multicastmap (a);
3598 clib_warning ("multicast replication without DPDK not implemented");
3599 rv = VNET_API_ERROR_UNIMPLEMENTED;
3604 REPLY_MACRO(VL_API_SR_MULTICAST_MAP_ADD_DEL_REPLY);
3608 #define foreach_classify_add_del_table_field \
3613 _(match_n_vectors) \
3614 _(next_table_index) \
3617 static void vl_api_classify_add_del_table_t_handler
3618 (vl_api_classify_add_del_table_t * mp)
3620 vl_api_classify_add_del_table_reply_t * rmp;
3621 vnet_classify_main_t * cm = &vnet_classify_main;
3622 vnet_classify_table_t * t;
3626 foreach_classify_add_del_table_field;
3629 #define _(a) a = ntohl(mp->a);
3630 foreach_classify_add_del_table_field;
3633 /* The underlying API fails silently, on purpose, so check here */
3634 if (mp->is_add == 0)
3635 if (pool_is_free_index (cm->tables, table_index)) {
3636 rv = VNET_API_ERROR_NO_SUCH_TABLE;
3640 rv = vnet_classify_add_del_table
3641 (cm, mp->mask, nbuckets, memory_size,
3642 skip_n_vectors, match_n_vectors,
3643 next_table_index, miss_next_index,
3644 &table_index, mp->is_add);
3647 REPLY_MACRO2(VL_API_CLASSIFY_ADD_DEL_TABLE_REPLY,
3649 if (rv == 0 && mp->is_add) {
3650 t = pool_elt_at_index (cm->tables, table_index);
3651 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
3652 rmp->match_n_vectors = ntohl(t->match_n_vectors);
3653 rmp->new_table_index = ntohl(table_index);
3655 rmp->skip_n_vectors = ~0;
3656 rmp->match_n_vectors = ~0;
3657 rmp->new_table_index = ~0;
3662 static void vl_api_classify_add_del_session_t_handler
3663 (vl_api_classify_add_del_session_t * mp)
3665 vnet_classify_main_t * cm = &vnet_classify_main;
3666 vl_api_classify_add_del_session_reply_t * rmp;
3668 u32 table_index, hit_next_index, opaque_index;
3671 table_index = ntohl (mp->table_index);
3672 hit_next_index = ntohl (mp->hit_next_index);
3673 opaque_index = ntohl (mp->opaque_index);
3674 advance = ntohl (mp->advance);
3676 rv = vnet_classify_add_del_session
3677 (cm, table_index, mp->match, hit_next_index, opaque_index,
3678 advance, mp->is_add);
3680 REPLY_MACRO(VL_API_CLASSIFY_ADD_DEL_SESSION_REPLY);
3683 static void vl_api_classify_set_interface_ip_table_t_handler
3684 (vl_api_classify_set_interface_ip_table_t * mp)
3686 vlib_main_t * vm = vlib_get_main();
3687 vl_api_classify_set_interface_ip_table_reply_t * rmp;
3689 u32 table_index, sw_if_index;
3691 table_index = ntohl (mp->table_index);
3692 sw_if_index = ntohl (mp->sw_if_index);
3694 VALIDATE_SW_IF_INDEX(mp);
3697 rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
3699 rv = vnet_set_ip4_classify_intfc (vm, sw_if_index, table_index);
3701 BAD_SW_IF_INDEX_LABEL;
3703 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY);
3706 static void vl_api_classify_set_interface_l2_tables_t_handler
3707 (vl_api_classify_set_interface_l2_tables_t * mp)
3709 vl_api_classify_set_interface_l2_tables_reply_t * rmp;
3711 u32 sw_if_index, ip4_table_index, ip6_table_index, other_table_index;
3714 ip4_table_index = ntohl(mp->ip4_table_index);
3715 ip6_table_index = ntohl(mp->ip6_table_index);
3716 other_table_index = ntohl(mp->other_table_index);
3717 sw_if_index = ntohl(mp->sw_if_index);
3719 VALIDATE_SW_IF_INDEX(mp);
3721 rv = vnet_l2_classify_set_tables (sw_if_index, ip4_table_index,
3722 ip6_table_index, other_table_index);
3725 if (ip4_table_index != ~0 || ip6_table_index != ~0
3726 || other_table_index != ~0)
3731 vnet_l2_classify_enable_disable (sw_if_index, enable);
3734 BAD_SW_IF_INDEX_LABEL;
3736 REPLY_MACRO(VL_API_CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY);
3740 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t *mp)
3743 vl_api_l2_fib_clear_table_reply_t * rmp;
3745 /* DAW-FIXME: This API should only clear non-static l2fib entries, but
3746 * that is not currently implemented. When that TODO is fixed
3747 * this call should be changed to pass 1 instead of 0.
3749 l2fib_clear_table (0);
3751 REPLY_MACRO(VL_API_L2_FIB_CLEAR_TABLE_REPLY);
3754 extern void l2_efp_filter_configure(vnet_main_t * vnet_main,
3759 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *mp)
3762 vl_api_l2_interface_efp_filter_reply_t * rmp;
3763 vnet_main_t *vnm = vnet_get_main();
3765 // enable/disable the feature
3766 l2_efp_filter_configure (vnm, mp->sw_if_index, mp->enable_disable);
3767 rv = vnm->api_errno;
3769 REPLY_MACRO(VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
3773 vl_api_l2_interface_vlan_tag_rewrite_t_handler (vl_api_l2_interface_vlan_tag_rewrite_t *mp)
3776 vl_api_l2_interface_vlan_tag_rewrite_reply_t * rmp;
3777 vnet_main_t * vnm = vnet_get_main();
3778 vlib_main_t * vm = vlib_get_main();
3781 VALIDATE_SW_IF_INDEX(mp);
3783 vtr_op = ntohl(mp->vtr_op);
3785 /* The L2 code is unsuspicious */
3787 case L2_VTR_DISABLED:
3792 case L2_VTR_TRANSLATE_1_1:
3793 case L2_VTR_TRANSLATE_1_2:
3794 case L2_VTR_TRANSLATE_2_1:
3795 case L2_VTR_TRANSLATE_2_2:
3799 rv = VNET_API_ERROR_INVALID_VALUE;
3800 goto bad_sw_if_index;
3803 rv = l2vtr_configure (vm, vnm, ntohl(mp->sw_if_index), vtr_op,
3804 ntohl(mp->push_dot1q), ntohl(mp->tag1),
3807 BAD_SW_IF_INDEX_LABEL;
3809 REPLY_MACRO(VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
3813 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
3816 vl_api_create_vhost_user_if_reply_t * rmp;
3817 #if DPDK > 0 && DPDK_VHOST_USER
3818 u32 sw_if_index = (u32)~0;
3820 vnet_main_t * vnm = vnet_get_main();
3821 vlib_main_t * vm = vlib_get_main();
3823 rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
3824 mp->is_server, &sw_if_index, (u64)~0,
3825 mp->renumber, ntohl(mp->custom_dev_instance),
3826 (mp->use_custom_mac)?mp->mac_address:NULL);
3828 REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
3830 rmp->sw_if_index = ntohl (sw_if_index);
3833 rv = VNET_API_ERROR_UNIMPLEMENTED;
3834 REPLY_MACRO(VL_API_CREATE_VHOST_USER_IF_REPLY);
3839 vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t *mp)
3842 vl_api_modify_vhost_user_if_reply_t * rmp;
3843 #if DPDK > 0 && DPDK_VHOST_USER
3844 u32 sw_if_index = ntohl(mp->sw_if_index);
3846 vnet_main_t * vnm = vnet_get_main();
3847 vlib_main_t * vm = vlib_get_main();
3849 rv = dpdk_vhost_user_modify_if(vnm, vm, (char *)mp->sock_filename,
3850 mp->is_server, sw_if_index, (u64)~0,
3851 mp->renumber, ntohl(mp->custom_dev_instance));
3853 rv = VNET_API_ERROR_UNIMPLEMENTED;
3855 REPLY_MACRO(VL_API_MODIFY_VHOST_USER_IF_REPLY);
3859 vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t *mp)
3862 vl_api_delete_vhost_user_if_reply_t * rmp;
3863 #if DPDK > 0 && DPDK_VHOST_USER
3864 vpe_api_main_t * vam = &vpe_api_main;
3865 u32 sw_if_index = ntohl(mp->sw_if_index);
3867 vnet_main_t * vnm = vnet_get_main();
3868 vlib_main_t * vm = vlib_get_main();
3870 rv = dpdk_vhost_user_delete_if(vnm, vm, sw_if_index);
3872 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3874 unix_shared_memory_queue_t * q =
3875 vl_api_client_index_to_input_queue (mp->client_index);
3879 send_sw_interface_flags_deleted (vam, q, sw_if_index);
3882 rv = VNET_API_ERROR_UNIMPLEMENTED;
3883 REPLY_MACRO(VL_API_DELETE_VHOST_USER_IF_REPLY);
3887 static void vl_api_sw_interface_vhost_user_details_t_handler (
3888 vl_api_sw_interface_vhost_user_details_t * mp)
3890 clib_warning ("BUG");
3893 #if DPDK > 0 && DPDK_VHOST_USER
3894 static void send_sw_interface_vhost_user_details (vpe_api_main_t * am,
3895 unix_shared_memory_queue_t *q,
3896 vhost_user_intf_details_t * vui,
3899 vl_api_sw_interface_vhost_user_details_t * mp;
3901 mp = vl_msg_api_alloc (sizeof (*mp));
3902 memset (mp, 0, sizeof (*mp));
3903 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
3904 mp->sw_if_index = ntohl(vui->sw_if_index);
3905 mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
3906 mp->features = clib_net_to_host_u64 (vui->features);
3907 mp->is_server = vui->is_server;
3908 mp->num_regions = ntohl(vui->num_regions);
3909 mp->sock_errno = ntohl(vui->sock_errno);
3910 mp->context = context;
3912 strncpy ((char *) mp->sock_filename,
3913 (char *) vui->sock_filename, ARRAY_LEN(mp->sock_filename)-1);
3914 strncpy ((char *) mp->interface_name,
3915 (char *) vui->if_name, ARRAY_LEN(mp->interface_name)-1);
3917 vl_msg_api_send_shmem (q, (u8 *)&mp);
3922 vl_api_sw_interface_vhost_user_dump_t_handler (
3923 vl_api_sw_interface_vhost_user_dump_t *mp)
3925 #if DPDK > 0 && DPDK_VHOST_USER
3927 vpe_api_main_t * am = &vpe_api_main;
3928 vnet_main_t * vnm = vnet_get_main();
3929 vlib_main_t * vm = vlib_get_main();
3930 vhost_user_intf_details_t *ifaces = NULL;
3931 vhost_user_intf_details_t *vuid = NULL;
3932 unix_shared_memory_queue_t * q;
3934 q = vl_api_client_index_to_input_queue (mp->client_index);
3938 rv = dpdk_vhost_user_dump_ifs(vnm, vm, &ifaces);
3942 vec_foreach (vuid, ifaces) {
3943 send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
3949 static void send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
3950 unix_shared_memory_queue_t *q,
3955 vl_api_sw_if_l2tpv3_tunnel_details_t * mp;
3956 u8 * if_name = NULL;
3957 vnet_sw_interface_t * si = NULL;
3959 si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
3961 if_name = format(if_name, "%U",
3962 format_vnet_sw_interface_name, lm->vnet_main, si);
3964 mp = vl_msg_api_alloc (sizeof (*mp));
3965 memset (mp, 0, sizeof (*mp));
3966 mp->_vl_msg_id = ntohs(VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
3967 strncpy((char *)mp->interface_name,
3968 (char *)if_name, ARRAY_LEN(mp->interface_name)-1);
3969 mp->sw_if_index = ntohl(si->sw_if_index);
3970 mp->local_session_id = s->local_session_id;
3971 mp->remote_session_id = s->remote_session_id;
3972 mp->local_cookie[0] = s->local_cookie[0];
3973 mp->local_cookie[1] = s->local_cookie[1];
3974 mp->remote_cookie = s->remote_cookie;
3975 clib_memcpy(mp->client_address, &s->client_address, sizeof(s->client_address));
3976 clib_memcpy(mp->our_address, &s->our_address, sizeof(s->our_address));
3977 mp->l2_sublayer_present = s->l2_sublayer_present;
3978 mp->context = context;
3980 vl_msg_api_send_shmem (q, (u8 *)&mp);
3983 static void send_ip_address_details (vpe_api_main_t * am,
3984 unix_shared_memory_queue_t * q,
3990 vl_api_ip_address_details_t * mp;
3992 mp = vl_msg_api_alloc (sizeof (*mp));
3993 memset (mp, 0, sizeof (*mp));
3994 mp->_vl_msg_id = ntohs(VL_API_IP_ADDRESS_DETAILS);
3997 clib_memcpy(&mp->ip, ip, sizeof(mp->ip));
3999 u32 * tp = (u32 *)mp->ip;
4000 *tp = ntohl(*(u32*)ip);
4002 mp->prefix_length = prefix_length;
4003 mp->context = context;
4005 vl_msg_api_send_shmem (q, (u8 *)&mp);
4009 vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t *mp)
4011 vpe_api_main_t * am = &vpe_api_main;
4012 unix_shared_memory_queue_t * q;
4015 ip6_main_t * im6 = &ip6_main;
4016 ip4_main_t * im4 = &ip4_main;
4017 ip_lookup_main_t * lm6 = &im6->lookup_main;
4018 ip_lookup_main_t * lm4 = &im4->lookup_main;
4019 ip_interface_address_t * ia = 0;
4020 u32 sw_if_index = ~0;
4021 int rv __attribute__ ((unused)) = 0;
4023 VALIDATE_SW_IF_INDEX(mp);
4025 sw_if_index = ntohl(mp->sw_if_index);
4027 q = vl_api_client_index_to_input_queue (mp->client_index);
4033 foreach_ip_interface_address (lm6, ia, sw_if_index,
4034 1 /* honor unnumbered */,
4036 r6 = ip_interface_address_get_address (lm6, ia);
4037 u16 prefix_length = ia->address_length;
4038 send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
4041 foreach_ip_interface_address (lm4, ia, sw_if_index,
4042 1 /* honor unnumbered */,
4044 r4 = ip_interface_address_get_address (lm4, ia);
4045 u16 prefix_length = ia->address_length;
4046 send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
4049 BAD_SW_IF_INDEX_LABEL;
4052 static void send_ip_details (vpe_api_main_t * am,
4053 unix_shared_memory_queue_t *q,
4057 vl_api_ip_details_t * mp;
4059 mp = vl_msg_api_alloc (sizeof (*mp));
4060 memset (mp, 0, sizeof (*mp));
4061 mp->_vl_msg_id = ntohs(VL_API_IP_DETAILS);
4063 mp->sw_if_index = ntohl(sw_if_index);
4064 mp->context = context;
4066 vl_msg_api_send_shmem (q, (u8 *)&mp);
4070 vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (
4071 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp)
4073 vpe_api_main_t * am = &vpe_api_main;
4074 l2t_main_t * lm = &l2t_main;
4075 unix_shared_memory_queue_t * q;
4076 l2t_session_t *session;
4078 q = vl_api_client_index_to_input_queue (mp->client_index);
4082 pool_foreach (session, lm->sessions,
4084 send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
4089 static void send_sw_interface_tap_details (vpe_api_main_t * am,
4090 unix_shared_memory_queue_t *q,
4091 tapcli_interface_details_t *tap_if,
4094 vl_api_sw_interface_tap_details_t * mp;
4095 mp = vl_msg_api_alloc (sizeof (*mp));
4096 memset (mp, 0, sizeof (*mp));
4097 mp->_vl_msg_id = ntohs(VL_API_SW_INTERFACE_TAP_DETAILS);
4098 mp->sw_if_index = ntohl(tap_if->sw_if_index);
4099 strncpy((char *)mp->dev_name,
4100 (char *)tap_if->dev_name, ARRAY_LEN(mp->dev_name)-1);
4101 mp->context = context;
4103 vl_msg_api_send_shmem (q, (u8 *)&mp);
4107 vl_api_sw_interface_tap_dump_t_handler (
4108 vl_api_sw_interface_tap_dump_t *mp)
4111 vpe_api_main_t * am = &vpe_api_main;
4112 unix_shared_memory_queue_t * q;
4113 tapcli_interface_details_t *tapifs = NULL;
4114 tapcli_interface_details_t *tap_if = NULL;
4116 q = vl_api_client_index_to_input_queue (mp->client_index);
4120 rv = vnet_tap_dump_ifs(&tapifs);
4124 vec_foreach(tap_if, tapifs) {
4125 send_sw_interface_tap_details(am, q, tap_if, mp->context);
4132 vl_api_ip_dump_t_handler (vl_api_ip_dump_t *mp)
4134 vpe_api_main_t * am = &vpe_api_main;
4135 vnet_main_t * vnm = vnet_get_main();
4136 vlib_main_t * vm = vlib_get_main();
4137 vnet_interface_main_t * im = &vnm->interface_main;
4138 unix_shared_memory_queue_t * q;
4139 vnet_sw_interface_t * si, * sorted_sis;
4140 u32 sw_if_index = ~0;
4142 q = vl_api_client_index_to_input_queue (mp->client_index);
4147 /* Gather interfaces. */
4148 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
4149 _vec_len (sorted_sis) = 0;
4150 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
4152 vec_foreach (si, sorted_sis) {
4153 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) {
4154 if (mp->is_ipv6 && !ip6_interface_enabled(vm, si->sw_if_index)) {
4157 sw_if_index = si->sw_if_index;
4158 send_ip_details(am, q, sw_if_index, mp->context);
4163 static void vl_api_l2_fib_table_entry_t_handler (
4164 vl_api_l2_fib_table_entry_t * mp)
4166 clib_warning ("BUG");
4169 static void send_l2fib_table_entry (vpe_api_main_t * am,
4170 unix_shared_memory_queue_t *q,
4171 l2fib_entry_key_t * l2fe_key,
4172 l2fib_entry_result_t * l2fe_res,
4175 vl_api_l2_fib_table_entry_t * mp;
4177 mp = vl_msg_api_alloc (sizeof (*mp));
4178 memset (mp, 0, sizeof (*mp));
4179 mp->_vl_msg_id = ntohs(VL_API_L2_FIB_TABLE_ENTRY);
4181 mp->bd_id = ntohl(l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
4183 mp->mac = l2fib_make_key (l2fe_key->fields.mac, 0);
4184 mp->sw_if_index = ntohl(l2fe_res->fields.sw_if_index);
4185 mp->static_mac = l2fe_res->fields.static_mac;
4186 mp->filter_mac = l2fe_res->fields.filter;
4187 mp->bvi_mac = l2fe_res->fields.bvi;
4188 mp->context = context;
4190 vl_msg_api_send_shmem (q, (u8 *)&mp);
4194 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t *mp)
4196 vpe_api_main_t * am = &vpe_api_main;
4197 bd_main_t * bdm = &bd_main;
4198 l2fib_entry_key_t *l2fe_key = NULL;
4199 l2fib_entry_result_t *l2fe_res = NULL;
4200 u32 ni, bd_id = ntohl (mp->bd_id);
4202 unix_shared_memory_queue_t * q;
4205 q = vl_api_client_index_to_input_queue (mp->client_index);
4209 /* see l2fib_table_dump: ~0 means "any" */
4213 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
4220 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
4222 vec_foreach_index (ni, l2fe_key) {
4223 send_l2fib_table_entry (am, q, vec_elt_at_index(l2fe_key, ni),
4224 vec_elt_at_index(l2fe_res, ni), mp->context);
4231 vl_api_show_version_t_handler (vl_api_show_version_t *mp)
4233 vl_api_show_version_reply_t *rmp;
4235 char * vpe_api_get_build_directory(void);
4236 char * vpe_api_get_version(void);
4237 char * vpe_api_get_build_date(void);
4239 unix_shared_memory_queue_t * q =
4240 vl_api_client_index_to_input_queue (mp->client_index);
4245 REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
4247 strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
4248 strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
4249 ARRAY_LEN(rmp->build_directory)-1);
4250 strncpy ((char *) rmp->version, vpe_api_get_version(),
4251 ARRAY_LEN(rmp->version)-1);
4252 strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
4253 ARRAY_LEN(rmp->build_date)-1);
4257 static void vl_api_get_node_index_t_handler
4258 (vl_api_get_node_index_t * mp)
4260 vlib_main_t * vm = vlib_get_main();
4261 vl_api_get_node_index_reply_t * rmp;
4264 u32 node_index = ~0;
4266 n = vlib_get_node_by_name (vm, mp->node_name);
4269 rv = VNET_API_ERROR_NO_SUCH_NODE;
4271 node_index = n->index;
4273 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4275 rmp->node_index = ntohl(node_index);
4279 static void vl_api_get_next_index_t_handler
4280 (vl_api_get_next_index_t * mp)
4282 vlib_main_t * vm = vlib_get_main();
4283 vl_api_get_next_index_reply_t * rmp;
4284 vlib_node_t * node, * next_node;
4286 u32 next_node_index = ~0, next_index = ~0;
4289 node = vlib_get_node_by_name (vm, mp->node_name);
4292 rv = VNET_API_ERROR_NO_SUCH_NODE;
4296 next_node = vlib_get_node_by_name (vm, mp->next_name);
4298 if (next_node == 0) {
4299 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4303 next_node_index = next_node->index;
4305 p = hash_get (node->next_slot_by_node, next_node_index);
4308 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
4315 REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
4317 rmp->next_index = ntohl(next_index);
4321 static void vl_api_add_node_next_t_handler
4322 (vl_api_add_node_next_t * mp)
4324 vlib_main_t * vm = vlib_get_main();
4325 vl_api_add_node_next_reply_t * rmp;
4326 vlib_node_t * n, * next;
4328 u32 next_index = ~0;
4330 n = vlib_get_node_by_name (vm, mp->node_name);
4333 rv = VNET_API_ERROR_NO_SUCH_NODE;
4337 next = vlib_get_node_by_name (vm, mp->next_name);
4340 rv = VNET_API_ERROR_NO_SUCH_NODE2;
4342 next_index = vlib_node_add_next (vm, n->index, next->index);
4345 REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
4347 rmp->next_index = ntohl(next_index);
4351 static void vl_api_l2tpv3_create_tunnel_t_handler
4352 (vl_api_l2tpv3_create_tunnel_t *mp)
4354 vl_api_l2tpv3_create_tunnel_reply_t * rmp;
4355 l2t_main_t *lm = &l2t_main;
4356 u32 sw_if_index = (u32)~0;
4359 if (mp->is_ipv6 != 1) {
4360 rv = VNET_API_ERROR_UNIMPLEMENTED;
4364 u32 encap_fib_index;
4366 if (mp->encap_vrf_id != ~0) {
4368 ip6_main_t *im = &ip6_main;
4369 if (!(p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id)))) {
4370 rv = VNET_API_ERROR_NO_SUCH_FIB;
4373 encap_fib_index = p[0];
4375 encap_fib_index = ~0;
4378 rv = create_l2tpv3_ipv6_tunnel (lm,
4379 (ip6_address_t *) mp->client_address,
4380 (ip6_address_t *) mp->our_address,
4381 ntohl(mp->local_session_id),
4382 ntohl(mp->remote_session_id),
4383 clib_net_to_host_u64(mp->local_cookie),
4384 clib_net_to_host_u64(mp->remote_cookie),
4385 mp->l2_sublayer_present,
4390 REPLY_MACRO2(VL_API_L2TPV3_CREATE_TUNNEL_REPLY,
4392 rmp->sw_if_index = ntohl (sw_if_index);
4396 static void vl_api_l2tpv3_set_tunnel_cookies_t_handler
4397 (vl_api_l2tpv3_set_tunnel_cookies_t *mp)
4399 vl_api_l2tpv3_set_tunnel_cookies_reply_t * rmp;
4400 l2t_main_t *lm = &l2t_main;
4403 VALIDATE_SW_IF_INDEX(mp);
4405 rv = l2tpv3_set_tunnel_cookies (lm, ntohl(mp->sw_if_index),
4406 clib_net_to_host_u64(mp->new_local_cookie),
4407 clib_net_to_host_u64(mp->new_remote_cookie));
4409 BAD_SW_IF_INDEX_LABEL;
4411 REPLY_MACRO (VL_API_L2TPV3_SET_TUNNEL_COOKIES_REPLY);
4414 static void vl_api_l2tpv3_interface_enable_disable_t_handler
4415 (vl_api_l2tpv3_interface_enable_disable_t * mp)
4418 vnet_main_t * vnm = vnet_get_main();
4419 vl_api_l2tpv3_interface_enable_disable_reply_t * rmp;
4421 VALIDATE_SW_IF_INDEX(mp);
4423 rv = l2tpv3_interface_enable_disable
4424 (vnm, ntohl(mp->sw_if_index), mp->enable_disable);
4426 BAD_SW_IF_INDEX_LABEL;
4428 REPLY_MACRO (VL_API_L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY);
4431 static void vl_api_l2tpv3_set_lookup_key_t_handler
4432 (vl_api_l2tpv3_set_lookup_key_t * mp)
4435 l2t_main_t *lm = &l2t_main;
4436 vl_api_l2tpv3_set_lookup_key_reply_t * rmp;
4438 if (mp->key > L2T_LOOKUP_SESSION_ID) {
4439 rv = VNET_API_ERROR_INVALID_VALUE;
4443 lm->lookup_type = mp->key;
4446 REPLY_MACRO (VL_API_L2TPV3_SET_LOOKUP_KEY_REPLY);
4449 static void vl_api_vxlan_add_del_tunnel_t_handler
4450 (vl_api_vxlan_add_del_tunnel_t * mp)
4452 vl_api_vxlan_add_del_tunnel_reply_t * rmp;
4454 vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
4455 u32 encap_fib_index;
4457 ip4_main_t * im = &ip4_main;
4458 u32 sw_if_index = ~0;
4460 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4462 rv = VNET_API_ERROR_NO_SUCH_FIB;
4465 encap_fib_index = p[0];
4467 /* Check src & dst are different */
4468 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4469 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4470 rv = VNET_API_ERROR_SAME_SRC_DST;
4473 memset (a, 0, sizeof (*a));
4475 a->is_add = mp->is_add;
4476 a->is_ip6 = mp->is_ipv6;
4478 /* ip addresses sent in network byte order */
4480 memcpy(&(a->src.ip6), mp->src_address, 16);
4481 memcpy(&(a->dst.ip6), mp->dst_address, 16);
4483 memcpy(&(a->src.ip4), mp->src_address, 4);
4484 memcpy(&(a->dst.ip4), mp->dst_address, 4);
4487 a->encap_fib_index = encap_fib_index;
4488 a->decap_next_index = ntohl(mp->decap_next_index);
4489 a->vni = ntohl(mp->vni);
4490 rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
4493 REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY,
4495 rmp->sw_if_index = ntohl (sw_if_index);
4499 static void send_vxlan_tunnel_details
4500 (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4502 vl_api_vxlan_tunnel_details_t * rmp;
4503 ip4_main_t * im4 = &ip4_main;
4504 ip6_main_t * im6 = &ip6_main;
4505 u8 is_ipv6 = !(t->flags & VXLAN_TUNNEL_IS_IPV4);
4507 rmp = vl_msg_api_alloc (sizeof (*rmp));
4508 memset (rmp, 0, sizeof (*rmp));
4509 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_TUNNEL_DETAILS);
4511 memcpy(rmp->src_address, &(t->src.ip6), 16);
4512 memcpy(rmp->dst_address, &(t->dst.ip6), 16);
4513 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4515 memcpy(rmp->src_address, &(t->src.ip4), 4);
4516 memcpy(rmp->dst_address, &(t->dst.ip4), 4);
4517 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4519 rmp->vni = htonl(t->vni);
4520 rmp->decap_next_index = htonl(t->decap_next_index);
4521 rmp->sw_if_index = htonl(t->sw_if_index);
4522 rmp->is_ipv6 = is_ipv6;
4523 rmp->context = context;
4525 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4528 static void vl_api_vxlan_tunnel_dump_t_handler
4529 (vl_api_vxlan_tunnel_dump_t * mp)
4531 unix_shared_memory_queue_t * q;
4532 vxlan_main_t * vxm = &vxlan_main;
4536 q = vl_api_client_index_to_input_queue (mp->client_index);
4541 sw_if_index = ntohl(mp->sw_if_index);
4543 if (~0 == sw_if_index) {
4544 pool_foreach (t, vxm->tunnels,
4546 send_vxlan_tunnel_details(t, q, mp->context);
4549 if ((sw_if_index >= vec_len(vxm->tunnel_index_by_sw_if_index)) ||
4550 (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) {
4553 t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]];
4554 send_vxlan_tunnel_details(t, q, mp->context);
4558 static void vl_api_gre_add_del_tunnel_t_handler
4559 (vl_api_gre_add_del_tunnel_t * mp)
4561 vl_api_gre_add_del_tunnel_reply_t * rmp;
4563 vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
4566 ip4_main_t * im = &ip4_main;
4567 u32 sw_if_index = ~0;
4569 p = hash_get (im->fib_index_by_table_id, ntohl(mp->outer_fib_id));
4571 rv = VNET_API_ERROR_NO_SUCH_FIB;
4574 outer_fib_id = p[0];
4576 /* Check src & dst are different */
4577 if ((mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 16) == 0) ||
4578 (!mp->is_ipv6 && memcmp(mp->src_address, mp->dst_address, 4) == 0)) {
4579 rv = VNET_API_ERROR_SAME_SRC_DST;
4582 memset (a, 0, sizeof (*a));
4584 a->is_add = mp->is_add;
4586 /* ip addresses sent in network byte order */
4587 clib_memcpy(&(a->src), mp->src_address, 4);
4588 clib_memcpy(&(a->dst), mp->dst_address, 4);
4590 a->outer_fib_id = outer_fib_id;
4591 rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
4594 REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
4596 rmp->sw_if_index = ntohl (sw_if_index);
4600 static void send_gre_tunnel_details
4601 (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4603 vl_api_gre_tunnel_details_t * rmp;
4604 ip4_main_t * im = &ip4_main;
4606 rmp = vl_msg_api_alloc (sizeof (*rmp));
4607 memset (rmp, 0, sizeof (*rmp));
4608 rmp->_vl_msg_id = ntohs(VL_API_GRE_TUNNEL_DETAILS);
4609 clib_memcpy(rmp->src_address, &(t->tunnel_src), 4);
4610 clib_memcpy(rmp->dst_address, &(t->tunnel_dst), 4);
4611 rmp->outer_fib_id = htonl(im->fibs[t->outer_fib_index].table_id);
4612 rmp->sw_if_index = htonl(t->sw_if_index);
4613 rmp->context = context;
4615 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4618 static void vl_api_gre_tunnel_dump_t_handler
4619 (vl_api_gre_tunnel_dump_t * mp)
4621 unix_shared_memory_queue_t * q;
4622 gre_main_t * gm = &gre_main;
4626 q = vl_api_client_index_to_input_queue (mp->client_index);
4631 sw_if_index = ntohl(mp->sw_if_index);
4633 if (~0 == sw_if_index) {
4634 pool_foreach (t, gm->tunnels,
4636 send_gre_tunnel_details(t, q, mp->context);
4639 if ((sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index)) ||
4640 (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) {
4643 t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
4644 send_gre_tunnel_details(t, q, mp->context);
4649 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t *mp)
4651 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4653 vl_api_l2_patch_add_del_reply_t * rmp;
4654 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
4658 VALIDATE_RX_SW_IF_INDEX(mp);
4659 VALIDATE_TX_SW_IF_INDEX(mp);
4661 rv = vnet_l2_patch_add_del (ntohl(mp->rx_sw_if_index),
4662 ntohl(mp->tx_sw_if_index),
4663 (int)(mp->is_add != 0));
4665 BAD_RX_SW_IF_INDEX_LABEL;
4666 BAD_TX_SW_IF_INDEX_LABEL;
4668 REPLY_MACRO(VL_API_L2_PATCH_ADD_DEL_REPLY);
4672 vl_api_vxlan_gpe_add_del_tunnel_t_handler
4673 (vl_api_vxlan_gpe_add_del_tunnel_t * mp)
4675 vl_api_vxlan_gpe_add_del_tunnel_reply_t * rmp;
4677 vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
4678 u32 encap_fib_index, decap_fib_index;
4681 ip4_main_t * im = &ip4_main;
4682 u32 sw_if_index = ~0;
4685 p = hash_get (im->fib_index_by_table_id, ntohl(mp->encap_vrf_id));
4687 rv = VNET_API_ERROR_NO_SUCH_FIB;
4690 encap_fib_index = p[0];
4692 protocol = mp->protocol;
4694 /* Interpret decap_vrf_id as an opaque if sending to other-than-ip4-input */
4695 if (protocol == VXLAN_GPE_INPUT_NEXT_IP4_INPUT) {
4696 p = hash_get (im->fib_index_by_table_id, ntohl(mp->decap_vrf_id));
4698 rv = VNET_API_ERROR_NO_SUCH_INNER_FIB;
4701 decap_fib_index = p[0];
4703 decap_fib_index = ntohl(mp->decap_vrf_id);
4706 /* Check src & dst are different */
4707 if ((mp->is_ipv6 && memcmp(mp->local, mp->remote, 16) == 0) ||
4708 (!mp->is_ipv6 && memcmp(mp->local, mp->remote, 4) == 0)) {
4709 rv = VNET_API_ERROR_SAME_SRC_DST;
4712 memset (a, 0, sizeof (*a));
4714 a->is_add = mp->is_add;
4715 a->is_ip6 = mp->is_ipv6;
4716 /* ip addresses sent in network byte order */
4718 clib_memcpy(&(a->local.ip6), mp->local, 16);
4719 clib_memcpy(&(a->remote.ip6), mp->remote, 16);
4721 clib_memcpy(&(a->local.ip4), mp->local, 4);
4722 clib_memcpy(&(a->remote.ip4), mp->remote, 4);
4724 a->encap_fib_index = encap_fib_index;
4725 a->decap_fib_index = decap_fib_index;
4726 a->protocol = protocol;
4727 a->vni = ntohl(mp->vni);
4728 rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
4731 REPLY_MACRO2(VL_API_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY,
4733 rmp->sw_if_index = ntohl (sw_if_index);
4737 static void send_vxlan_gpe_tunnel_details
4738 (vxlan_gpe_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
4740 vl_api_vxlan_gpe_tunnel_details_t * rmp;
4741 ip4_main_t * im4 = &ip4_main;
4742 ip6_main_t * im6 = &ip6_main;
4743 u8 is_ipv6 = !(t->flags & VXLAN_GPE_TUNNEL_IS_IPV4);
4745 rmp = vl_msg_api_alloc (sizeof (*rmp));
4746 memset (rmp, 0, sizeof (*rmp));
4747 rmp->_vl_msg_id = ntohs(VL_API_VXLAN_GPE_TUNNEL_DETAILS);
4749 memcpy(rmp->local, &(t->local.ip6), 16);
4750 memcpy(rmp->remote, &(t->remote.ip6), 16);
4751 rmp->encap_vrf_id = htonl(im6->fibs[t->encap_fib_index].table_id);
4752 rmp->decap_vrf_id = htonl(im6->fibs[t->decap_fib_index].table_id);
4754 memcpy(rmp->local, &(t->local.ip4), 4);
4755 memcpy(rmp->remote, &(t->remote.ip4), 4);
4756 rmp->encap_vrf_id = htonl(im4->fibs[t->encap_fib_index].table_id);
4757 rmp->decap_vrf_id = htonl(im4->fibs[t->decap_fib_index].table_id);
4759 rmp->vni = htonl(t->vni);
4760 rmp->protocol = t->protocol;
4761 rmp->sw_if_index = htonl(t->sw_if_index);
4762 rmp->is_ipv6 = is_ipv6;
4763 rmp->context = context;
4765 vl_msg_api_send_shmem (q, (u8 *)&rmp);
4768 static void vl_api_vxlan_gpe_tunnel_dump_t_handler
4769 (vl_api_vxlan_gpe_tunnel_dump_t * mp)
4771 unix_shared_memory_queue_t * q;
4772 vxlan_gpe_main_t * vgm = &vxlan_gpe_main;
4773 vxlan_gpe_tunnel_t * t;
4776 q = vl_api_client_index_to_input_queue (mp->client_index);
4781 sw_if_index = ntohl(mp->sw_if_index);
4783 if (~0 == sw_if_index) {
4784 pool_foreach (t, vgm->tunnels,
4786 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4789 if ((sw_if_index >= vec_len(vgm->tunnel_index_by_sw_if_index)) ||
4790 (~0 == vgm->tunnel_index_by_sw_if_index[sw_if_index])) {
4793 t = &vgm->tunnels[vgm->tunnel_index_by_sw_if_index[sw_if_index]];
4794 send_vxlan_gpe_tunnel_details(t, q, mp->context);
4798 /** Used for transferring locators via VPP API */
4799 typedef CLIB_PACKED(struct
4801 u32 sw_if_index; /**< locator sw_if_index */
4802 u8 priority; /**< locator priority */
4803 u8 weight; /**< locator weight */
4807 vl_api_lisp_add_del_locator_set_t_handler(vl_api_lisp_add_del_locator_set_t *mp)
4809 vl_api_lisp_add_del_locator_set_reply_t *rmp;
4811 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4813 ls_locator_t *ls_loc;
4815 u8 *locator_name = NULL;
4818 memset(a, 0, sizeof(a[0]));
4820 locator_name = format(0, "%s", mp->locator_set_name);
4822 a->name = locator_name;
4823 a->is_add = mp->is_add;
4826 memset(&locator, 0, sizeof(locator));
4827 for (i = 0; i < mp->locator_num; i++) {
4828 ls_loc = &((ls_locator_t *) mp->locators)[i];
4829 VALIDATE_SW_IF_INDEX(ls_loc);
4831 locator.sw_if_index = htonl(ls_loc->sw_if_index);
4832 locator.priority = ls_loc->priority;
4833 locator.weight = ls_loc->weight;
4835 vec_add1(a->locators, locator);
4838 rv = vnet_lisp_add_del_locator_set(a, &ls_index);
4840 BAD_SW_IF_INDEX_LABEL;
4842 vec_free(locator_name);
4843 vec_free(a->locators);
4845 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
4849 vl_api_lisp_add_del_locator_t_handler(
4850 vl_api_lisp_add_del_locator_t *mp)
4852 vl_api_lisp_add_del_locator_reply_t *rmp;
4854 locator_t locator, *locators = NULL;
4855 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
4857 u8 *locator_name = NULL;
4859 memset(&locator, 0, sizeof(locator));
4860 memset(a, 0, sizeof(a[0]));
4862 locator.sw_if_index = ntohl(mp->sw_if_index);
4863 locator.priority = mp->priority;
4864 locator.weight = mp->weight;
4866 vec_add1(locators, locator);
4868 locator_name = format(0, "%s", mp->locator_set_name);
4870 a->name = locator_name;
4871 a->locators = locators;
4872 a->is_add = mp->is_add;
4875 rv = vnet_lisp_add_del_locator(a, NULL, &ls_index);
4878 vec_free(locator_name);
4880 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
4884 vl_api_lisp_add_del_local_eid_t_handler(
4885 vl_api_lisp_add_del_local_eid_t *mp)
4887 vl_api_lisp_add_del_local_eid_reply_t *rmp;
4888 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
4890 ip_prefix_t *prefp = NULL;
4891 ip_address_t *ip_eid = NULL;
4893 u8 * mac = gid_address_mac (&eid);
4895 u32 locator_set_index = ~0, map_index = ~0;
4896 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
4898 memset (a, 0, sizeof (a[0]));
4899 memset (&eid, 0, sizeof (eid));
4901 prefp = &gid_address_ippref(&eid);
4902 ip_eid = &ip_prefix_addr(prefp);
4904 switch (mp->eid_type)
4907 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4908 ip_address_set(ip_eid, mp->eid, IP4);
4909 ip_prefix_len(prefp) = mp->prefix_len;
4910 ip_prefix_normalize(prefp);
4913 gid_address_type (&eid) = GID_ADDR_IP_PREFIX;
4914 ip_address_set(ip_eid, mp->eid, IP6);
4915 ip_prefix_len(prefp) = mp->prefix_len;
4916 ip_prefix_normalize(prefp);
4918 case 2: /* l2 mac */
4919 gid_address_type (&eid) = GID_ADDR_MAC;
4920 clib_memcpy(mac, mp->eid, 6);
4923 rv = VNET_API_ERROR_INVALID_EID_TYPE;
4927 name = format(0, "%s", mp->locator_set_name);
4928 p = hash_get_mem(lcm->locator_set_index_by_name, name);
4930 rv = VNET_API_ERROR_INVALID_VALUE;
4933 locator_set_index = p[0];
4935 /* XXX treat batch configuration */
4936 a->is_add = mp->is_add;
4937 gid_address_vni (&eid) = clib_net_to_host_u32 (mp->vni);
4938 gid_address_copy (&a->eid, &eid);
4939 a->locator_set_index = locator_set_index;
4941 rv = vnet_lisp_add_del_local_mapping(a, &map_index);
4945 gid_address_free (&a->eid);
4947 REPLY_MACRO(VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
4951 vl_api_lisp_eid_table_add_del_map_t_handler(
4952 vl_api_lisp_eid_table_add_del_map_t *mp)
4954 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
4956 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
4957 clib_net_to_host_u32 (mp->dp_table),
4958 mp->is_l2, mp->is_add);
4959 REPLY_MACRO(VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)
4963 lisp_gpe_add_del_fwd_entry_set_address(
4964 vl_api_lisp_gpe_add_del_fwd_entry_t *mp,
4965 ip_address_t *slocator,
4966 ip_address_t *dlocator,
4969 ip_address_t *ip_eid = NULL;
4970 ip_prefix_t *prefp = NULL;
4972 prefp = &gid_address_ippref(eid);
4973 ip_eid = &ip_prefix_addr(prefp);
4975 if (mp->eid_is_ipv6) {
4976 clib_memcpy(&ip_addr_v6(ip_eid), mp->eid_ip_address,
4977 sizeof(ip_addr_v6(ip_eid)));
4978 ip_addr_version(ip_eid) = IP6;
4980 clib_memcpy(&ip_addr_v4(ip_eid), mp->eid_ip_address,
4981 sizeof(ip_addr_v4(ip_eid)));
4982 ip_addr_version(ip_eid) = IP4;
4984 ip_prefix_len(prefp) = mp->eid_prefix_len;
4985 ip_prefix_normalize(prefp);
4987 if (mp->address_is_ipv6) {
4988 clib_memcpy(&ip_addr_v6(slocator), mp->source_ip_address,
4989 sizeof(ip_addr_v6(slocator)));
4990 ip_addr_version(slocator) = IP6;
4991 clib_memcpy(&ip_addr_v6(dlocator), mp->destination_ip_address,
4992 sizeof(ip_addr_v6(dlocator)));
4993 ip_addr_version(dlocator) = IP6;
4995 clib_memcpy(&ip_addr_v4(slocator), mp->source_ip_address,
4996 sizeof(ip_addr_v4(slocator)));
4997 ip_addr_version(slocator) = IP4;
4998 clib_memcpy(&ip_addr_v4(dlocator), mp->destination_ip_address,
4999 sizeof(ip_addr_v4(dlocator)));
5000 ip_addr_version(dlocator) = IP4;
5005 vl_api_lisp_gpe_add_del_fwd_entry_t_handler(
5006 vl_api_lisp_gpe_add_del_fwd_entry_t *mp)
5008 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
5010 ip_address_t slocator, dlocator;
5012 vnet_lisp_gpe_add_del_fwd_entry_args_t a;
5014 lisp_gpe_add_del_fwd_entry_set_address(mp, &slocator, &dlocator, &eid);
5016 memset (&a, 0, sizeof(a));
5018 a.is_add = mp->is_add;
5020 a.lcl_loc = slocator;
5021 a.rmt_loc = dlocator;
5022 rv = vnet_lisp_gpe_add_del_fwd_entry (&a, 0);
5024 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
5028 vl_api_lisp_add_del_map_resolver_t_handler(
5029 vl_api_lisp_add_del_map_resolver_t *mp)
5031 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
5033 ip_address_t *ip_addr = NULL;
5034 vnet_lisp_add_del_map_resolver_args_t _a, * a = &_a;
5036 a->is_add = mp->is_add;
5037 ip_addr = &a->address;
5040 clib_memcpy(&ip_addr_v6(ip_addr), mp->ip_address,
5041 sizeof(ip_addr_v6(ip_addr)));
5042 ip_addr_version(ip_addr) = IP6;
5044 clib_memcpy(&ip_addr_v4(ip_addr), mp->ip_address,
5045 sizeof(ip_addr_v4(ip_addr)));
5046 ip_addr_version(ip_addr) = IP4;
5049 rv = vnet_lisp_add_del_map_resolver (a);
5051 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
5055 vl_api_lisp_gpe_enable_disable_t_handler(
5056 vl_api_lisp_gpe_enable_disable_t *mp)
5058 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
5060 vnet_lisp_gpe_enable_disable_args_t _a, * a = &_a;
5062 a->is_en = mp->is_en;
5063 vnet_lisp_gpe_enable_disable (a);
5065 REPLY_MACRO(VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
5069 vl_api_lisp_enable_disable_t_handler(
5070 vl_api_lisp_enable_disable_t *mp)
5072 vl_api_lisp_enable_disable_reply_t *rmp;
5075 vnet_lisp_enable_disable (mp->is_en);
5076 REPLY_MACRO(VL_API_LISP_ENABLE_DISABLE_REPLY);
5080 vl_api_lisp_gpe_add_del_iface_t_handler(
5081 vl_api_lisp_gpe_add_del_iface_t *mp)
5083 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
5085 vnet_lisp_gpe_add_del_iface_args_t _a, * a = &_a;
5087 a->is_add = mp->is_add;
5088 a->table_id = mp->table_id;
5090 rv = vnet_lisp_gpe_add_del_iface (a, 0);
5092 REPLY_MACRO(VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
5096 vl_api_lisp_pitr_set_locator_set_t_handler(
5097 vl_api_lisp_pitr_set_locator_set_t *mp)
5099 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
5103 ls_name = format (0, "%s", mp->ls_name);
5104 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
5107 REPLY_MACRO(VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
5111 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
5112 (vl_api_lisp_add_del_map_request_itr_rlocs_t *mp)
5114 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
5116 u8 * locator_set_name = NULL;
5117 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, * a = &_a;
5119 locator_set_name = format (0, "%s", mp->locator_set_name);
5121 a->is_add = mp->is_add;
5122 a->locator_set_name = locator_set_name;
5124 rv = vnet_lisp_add_del_mreq_itr_rlocs(a);
5126 vec_free(locator_set_name);
5128 REPLY_MACRO(VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
5131 /** Used for transferring locators via VPP API */
5132 typedef CLIB_PACKED(struct
5134 u8 is_ip4; /**< is locator an IPv4 address */
5135 u8 priority; /**< locator priority */
5136 u8 weight; /**< locator weight */
5137 u8 addr[16]; /**< IPv4/IPv6 address */
5141 vl_api_lisp_add_del_remote_mapping_t_handler (
5142 vl_api_lisp_add_del_remote_mapping_t *mp)
5145 locator_t rloc, * rlocs = 0;
5146 vl_api_lisp_add_del_remote_mapping_reply_t * rmp;
5148 gid_address_t _eid, * eid = &_eid;
5149 ip_prefix_t * eid_pref = &gid_address_ippref(eid);
5151 memset (eid, 0, sizeof (eid[0]));
5152 ip_address_t * eid_addr = &ip_prefix_addr(eid_pref);
5153 ip_prefix_len(eid_pref) = mp->eid_len;
5154 u8 * eid_mac = gid_address_mac (eid);
5155 gid_address_vni (eid) = ntohl (mp->vni);
5157 switch (mp->eid_type)
5160 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5161 ip_address_set (eid_addr, mp->eid, IP4);
5162 ip_prefix_normalize (eid_pref);
5165 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5166 ip_address_set (eid_addr, mp->eid, IP6);
5167 ip_prefix_normalize (eid_pref);
5169 case 2: /* l2 mac */
5170 gid_address_type(eid) = GID_ADDR_MAC;
5171 clib_memcpy (eid_mac, mp->eid, 6);
5174 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5178 for (i = 0; i < mp->rloc_num; i++) {
5179 rloc_t * r = &((rloc_t *) mp->rlocs)[i];
5180 memset(&rloc, 0, sizeof(rloc));
5181 ip_address_set(&gid_address_ip(&rloc.address), &r->addr,
5182 r->is_ip4 ? IP4 : IP6);
5183 gid_address_ippref_len(&rloc.address) = r->is_ip4 ? 32: 128;
5184 gid_address_type(&rloc.address) = GID_ADDR_IP_PREFIX;
5185 rloc.priority = r->priority;
5186 rloc.weight = r->weight;
5187 vec_add1 (rlocs, rloc);
5191 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5192 gid_address_copy(&a->deid, eid);
5194 rv = vnet_lisp_add_del_adjacency (a);
5200 /* NOTE: for now this works as a static remote mapping, i.e.,
5201 * not authoritative and ttl infinite. */
5202 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
5206 vnet_lisp_clear_all_remote_adjacencies ();
5211 REPLY_MACRO(VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
5215 vl_api_lisp_add_del_adjacency_t_handler (
5216 vl_api_lisp_add_del_adjacency_t *mp)
5218 vl_api_lisp_add_del_adjacency_reply_t * rmp;
5219 vnet_lisp_add_del_adjacency_args_t _a, * a = &_a;
5222 memset(a, 0, sizeof(a[0]));
5224 ip_prefix_t * seid_pref = &gid_address_ippref(&a->seid);
5225 ip_prefix_t * deid_pref = &gid_address_ippref(&a->deid);
5227 ip_address_t * seid_addr = &ip_prefix_addr(seid_pref);
5228 ip_address_t * deid_addr = &ip_prefix_addr(deid_pref);
5229 ip_prefix_len(seid_pref) = mp->seid_len;
5230 ip_prefix_len(deid_pref) = mp->deid_len;
5231 u8 * seid_mac = gid_address_mac (&a->seid);
5232 u8 * deid_mac = gid_address_mac (&a->deid);
5233 gid_address_vni(&a->seid) = ntohl (mp->vni);
5234 gid_address_vni(&a->deid) = ntohl (mp->vni);
5236 switch (mp->eid_type)
5239 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5240 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5241 ip_address_set (seid_addr, mp->seid, IP4);
5242 ip_address_set (deid_addr, mp->deid, IP4);
5243 ip_prefix_normalize (seid_pref);
5244 ip_prefix_normalize (deid_pref);
5247 gid_address_type(&a->seid) = GID_ADDR_IP_PREFIX;
5248 gid_address_type(&a->deid) = GID_ADDR_IP_PREFIX;
5249 ip_address_set (seid_addr, mp->seid, IP6);
5250 ip_address_set (deid_addr, mp->deid, IP6);
5251 ip_prefix_normalize (seid_pref);
5252 ip_prefix_normalize (deid_pref);
5254 case 2: /* l2 mac */
5255 gid_address_type(&a->seid) = GID_ADDR_MAC;
5256 gid_address_type(&a->deid) = GID_ADDR_MAC;
5257 clib_memcpy (seid_mac, mp->seid, 6);
5258 clib_memcpy (deid_mac, mp->deid, 6);
5261 rv = VNET_API_ERROR_INVALID_EID_TYPE;
5265 a->is_add = mp->is_add;
5266 rv = vnet_lisp_add_del_adjacency (a);
5269 REPLY_MACRO(VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
5273 send_lisp_locator_details (lisp_cp_main_t *lcm,
5275 unix_shared_memory_queue_t *q,
5278 vl_api_lisp_locator_details_t *rmp;
5280 rmp = vl_msg_api_alloc (sizeof (*rmp));
5281 memset (rmp, 0, sizeof (*rmp));
5282 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_DETAILS);
5283 rmp->context = context;
5285 rmp->local = loc->local;
5287 rmp->sw_if_index = ntohl(loc->sw_if_index);
5289 rmp->is_ipv6 = gid_address_ip_version(&loc->address);
5290 ip_address_copy_addr(rmp->ip_address, &gid_address_ip(&loc->address));
5292 rmp->priority = loc->priority;
5293 rmp->weight = loc->weight;
5295 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5299 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t *mp)
5301 unix_shared_memory_queue_t * q = 0;
5302 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5303 locator_set_t * lsit = 0;
5304 locator_t * loc = 0;
5305 u32 ls_index = ~0, * locit = 0;
5308 q = vl_api_client_index_to_input_queue (mp->client_index);
5313 ls_index = htonl(mp->locator_set_index);
5315 lsit = pool_elt_at_index(lcm->locator_set_pool, ls_index);
5317 filter = mp->filter;
5318 if (filter && !((1 == filter && lsit->local) ||
5319 (2 == filter && !lsit->local))) {
5323 vec_foreach(locit, lsit->locator_indices) {
5324 loc = pool_elt_at_index(lcm->locator_pool, locit[0]);
5325 send_lisp_locator_details(lcm, loc, q, mp->context);
5330 send_lisp_locator_set_details (lisp_cp_main_t *lcm,
5331 locator_set_t *lsit,
5332 unix_shared_memory_queue_t *q,
5336 vl_api_lisp_locator_set_details_t *rmp;
5339 rmp = vl_msg_api_alloc (sizeof (*rmp));
5340 memset (rmp, 0, sizeof (*rmp));
5341 rmp->_vl_msg_id = ntohs(VL_API_LISP_LOCATOR_SET_DETAILS);
5342 rmp->context = context;
5344 rmp->local = lsit->local;
5345 rmp->locator_set_index= htonl(ls_index);
5347 ASSERT(lsit->name != NULL);
5348 strncpy((char *) rmp->locator_set_name,
5349 (char *) lsit->name, ARRAY_LEN(rmp->locator_set_name) - 1);
5351 str = format(0, "remote-%d", ls_index);
5352 strncpy((char *) rmp->locator_set_name, (char *) str,
5353 ARRAY_LEN(rmp->locator_set_name) - 1);
5357 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5361 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t *mp)
5363 unix_shared_memory_queue_t * q = NULL;
5364 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5365 locator_set_t * lsit = NULL;
5369 q = vl_api_client_index_to_input_queue (mp->client_index);
5374 filter = mp->filter;
5376 pool_foreach (lsit, lcm->locator_set_pool,
5378 if (filter && !((1 == filter && lsit->local) ||
5379 (2 == filter && !lsit->local))) {
5384 send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
5389 send_lisp_eid_table_details (mapping_t *mapit,
5390 unix_shared_memory_queue_t *q,
5391 u32 context, u8 filter)
5393 vl_api_lisp_eid_table_details_t *rmp = NULL;
5394 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5395 locator_set_t *ls = NULL;
5396 gid_address_t *gid = NULL;
5398 ip_prefix_t *ip_prefix = NULL;
5400 ls = pool_elt_at_index (lcm->locator_set_pool,
5401 mapit->locator_set_index);
5417 clib_warning("Filter error, unknown filter: %d\n", filter);
5422 ip_prefix = &gid_address_ippref(gid);
5423 mac = gid_address_mac(gid);
5425 rmp = vl_msg_api_alloc (sizeof (*rmp));
5426 memset (rmp, 0, sizeof (*rmp));
5427 rmp->_vl_msg_id = ntohs(VL_API_LISP_EID_TABLE_DETAILS);
5428 rmp->locator_set_index = mapit->locator_set_index;
5429 rmp->is_local = ls->local;
5430 rmp->ttl = mapit->ttl;
5431 rmp->authoritative = mapit->authoritative;
5433 switch (gid_address_type (gid))
5435 case GID_ADDR_IP_PREFIX:
5436 rmp->eid_prefix_len = ip_prefix_len(ip_prefix);
5437 if (ip_prefix_version(ip_prefix) == IP4)
5439 rmp->eid_type = 0; /* ipv4 type */
5440 clib_memcpy(rmp->eid, &ip_prefix_v4(ip_prefix),
5441 sizeof(ip_prefix_v4(ip_prefix)));
5445 rmp->eid_type = 1; /* ipv6 type */
5446 clib_memcpy(rmp->eid, &ip_prefix_v6(ip_prefix),
5447 sizeof(ip_prefix_v6(ip_prefix)));
5451 rmp->eid_type = 2; /* l2 mac type */
5452 clib_memcpy(rmp->eid, mac, 6);
5457 rmp->context = context;
5458 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
5459 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5463 vl_api_lisp_eid_table_dump_t_handler (
5464 vl_api_lisp_eid_table_dump_t *mp)
5467 unix_shared_memory_queue_t * q = NULL;
5468 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5469 mapping_t * mapit = NULL;
5470 gid_address_t _eid, * eid = &_eid;
5472 q = vl_api_client_index_to_input_queue (mp->client_index);
5478 memset (eid, 0, sizeof (*eid));
5479 gid_address_vni(eid) = ntohl(mp->vni);
5480 switch (mp->eid_type) {
5482 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5483 gid_address_ippref_len(eid) = mp->prefix_length;
5484 gid_address_ip_version(eid) = IP4;
5485 clib_memcpy (&gid_address_ippref(eid), mp->eid, 4);
5488 gid_address_type(eid) = GID_ADDR_IP_PREFIX;
5489 gid_address_ippref_len(eid) = mp->prefix_length;
5490 gid_address_ip_version(eid) = IP6;
5491 clib_memcpy (&gid_address_ippref(eid), mp->eid, 16);
5494 gid_address_type(eid) = GID_ADDR_MAC;
5495 clib_memcpy (gid_address_mac(eid), mp->eid, 6);
5498 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
5502 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
5503 send_lisp_eid_table_details(mapit, q, mp->context, mp->filter);
5505 pool_foreach (mapit, lcm->mapping_pool,
5507 send_lisp_eid_table_details(mapit, q, mp->context,
5514 send_lisp_gpe_tunnel_details (lisp_gpe_tunnel_t *tunnel,
5515 unix_shared_memory_queue_t *q,
5518 vl_api_lisp_gpe_tunnel_details_t *rmp;
5519 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5521 rmp = vl_msg_api_alloc (sizeof (*rmp));
5522 memset (rmp, 0, sizeof (*rmp));
5523 rmp->_vl_msg_id = ntohs(VL_API_LISP_GPE_TUNNEL_DETAILS);
5525 rmp->tunnels = tunnel - lgm->tunnels;
5527 rmp->is_ipv6 = ip_addr_version(&tunnel->src) == IP6 ? 1 : 0;
5528 ip_address_copy_addr(rmp->source_ip, &tunnel->src);
5529 ip_address_copy_addr(rmp->destination_ip, &tunnel->dst);
5531 rmp->encap_fib_id = htonl(tunnel->encap_fib_index);
5532 rmp->decap_fib_id = htonl(tunnel->decap_fib_index);
5533 rmp->dcap_next = htonl(tunnel->decap_next_index);
5534 rmp->lisp_ver = tunnel->ver_res;
5535 rmp->next_protocol = tunnel->next_protocol;
5536 rmp->flags = tunnel->flags;
5537 rmp->ver_res = tunnel->ver_res;
5538 rmp->res = tunnel->res;
5539 rmp->iid = htonl(tunnel->vni);
5540 rmp->context = context;
5542 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5546 vl_api_lisp_gpe_tunnel_dump_t_handler (
5547 vl_api_lisp_gpe_tunnel_dump_t *mp)
5549 unix_shared_memory_queue_t * q = NULL;
5550 lisp_gpe_main_t * lgm = &lisp_gpe_main;
5551 lisp_gpe_tunnel_t * tunnel = NULL;
5553 if (pool_elts(lgm->tunnels) == 0) {
5557 q = vl_api_client_index_to_input_queue (mp->client_index);
5562 pool_foreach(tunnel, lgm->tunnels,
5564 send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
5569 send_lisp_map_resolver_details (ip_address_t *ip,
5570 unix_shared_memory_queue_t *q,
5573 vl_api_lisp_map_resolver_details_t *rmp = NULL;
5575 rmp = vl_msg_api_alloc (sizeof (*rmp));
5576 memset (rmp, 0, sizeof (*rmp));
5577 rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
5579 switch (ip_addr_version(ip)) {
5582 clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
5587 clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
5593 rmp->context = context;
5595 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5599 vl_api_lisp_map_resolver_dump_t_handler (
5600 vl_api_lisp_map_resolver_dump_t *mp)
5602 unix_shared_memory_queue_t * q = NULL;
5603 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5604 ip_address_t *ip = NULL;
5606 q = vl_api_client_index_to_input_queue (mp->client_index);
5611 vec_foreach(ip, lcm->map_resolvers) {
5612 send_lisp_map_resolver_details(ip, q, mp->context);
5618 send_eid_table_map_pair (hash_pair_t * p,
5619 unix_shared_memory_queue_t * q,
5622 vl_api_lisp_eid_table_map_details_t * rmp = NULL;
5624 rmp = vl_msg_api_alloc (sizeof (*rmp));
5625 memset (rmp, 0, sizeof (*rmp));
5626 rmp->_vl_msg_id = ntohs(VL_API_LISP_EID_TABLE_MAP_DETAILS);
5628 rmp->vni = clib_host_to_net_u32 (p->key);
5629 rmp->vrf = clib_host_to_net_u32 (p->value[0]);
5630 rmp->context = context;
5631 vl_msg_api_send_shmem (q, (u8 *)&rmp);
5635 vl_api_lisp_eid_table_map_dump_t_handler (
5636 vl_api_lisp_eid_table_map_dump_t *mp)
5638 unix_shared_memory_queue_t * q = NULL;
5639 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5642 q = vl_api_client_index_to_input_queue (mp->client_index);
5646 hash_foreach_pair (p, lcm->table_id_by_vni, {
5647 send_eid_table_map_pair (p, q, mp->context);
5652 vl_api_show_lisp_status_t_handler
5653 (vl_api_show_lisp_status_t *mp)
5655 unix_shared_memory_queue_t * q = NULL;
5656 vl_api_show_lisp_status_reply_t *rmp = NULL;
5659 q = vl_api_client_index_to_input_queue (mp->client_index);
5664 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
5666 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
5667 rmp->feature_status = vnet_lisp_enable_disable_status ();
5672 vl_api_lisp_get_map_request_itr_rlocs_t_handler (
5673 vl_api_lisp_get_map_request_itr_rlocs_t *mp)
5675 unix_shared_memory_queue_t * q = NULL;
5676 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
5677 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5678 locator_set_t * loc_set = 0;
5682 q = vl_api_client_index_to_input_queue (mp->client_index);
5687 if (~0 == lcm->mreq_itr_rlocs) {
5688 tmp_str = format(0, " ");
5690 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
5691 tmp_str = format(0, "%s", loc_set->name);
5694 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
5696 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5697 ARRAY_LEN(rmp->locator_set_name) - 1);
5704 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
5706 unix_shared_memory_queue_t * q = NULL;
5707 vl_api_show_lisp_pitr_reply_t * rmp = NULL;
5708 lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
5710 locator_set_t * ls = 0;
5714 q = vl_api_client_index_to_input_queue (mp->client_index);
5719 if (~0 == lcm->pitr_map_index) {
5720 tmp_str = format(0, "N/A");
5722 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
5723 if (~0 != m->locator_set_index) {
5724 ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
5725 tmp_str = format(0, "%s", ls->name);
5727 tmp_str = format(0, "N/A");
5730 vec_add1(tmp_str, 0);
5732 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
5734 rmp->status = lcm->lisp_pitr;
5735 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
5736 ARRAY_LEN(rmp->locator_set_name) - 1);
5741 vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
5743 vl_api_interface_name_renumber_reply_t * rmp;
5746 VALIDATE_SW_IF_INDEX(mp);
5748 rv = vnet_interface_name_renumber
5749 (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
5751 BAD_SW_IF_INDEX_LABEL;
5753 REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
5756 static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
5757 u32 sw_if_index, u32 address)
5759 vpe_api_main_t * am = &vpe_api_main;
5760 vlib_main_t * vm = am->vlib_main;
5761 vl_api_ip4_arp_event_t * event;
5762 static f64 arp_event_last_time;
5763 f64 now = vlib_time_now (vm);
5765 if (pool_is_free_index (am->arp_events, pool_index))
5768 event = pool_elt_at_index (am->arp_events, pool_index);
5769 if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
5770 clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
5771 } else { /* same mac */
5772 if ((sw_if_index == event->sw_if_index) &&
5774 /* for BD case, also check IP address with 10 sec timeout */
5775 ((address == event->address) &&
5776 ((now - arp_event_last_time) < 10.0))))
5780 arp_event_last_time = now;
5781 event->sw_if_index = sw_if_index;
5782 if (address) event->address = address;
5786 static int arp_change_delete_callback (u32 pool_index, u8 * notused)
5788 vpe_api_main_t * am = &vpe_api_main;
5790 if (pool_is_free_index (am->arp_events, pool_index))
5793 pool_put_index (am->arp_events, pool_index);
5798 vl_api_want_ip4_arp_events_t_handler
5799 (vl_api_want_ip4_arp_events_t * mp)
5801 vpe_api_main_t * am = &vpe_api_main;
5802 vnet_main_t * vnm = vnet_get_main();
5803 vl_api_want_ip4_arp_events_reply_t *rmp;
5804 vl_api_ip4_arp_event_t * event;
5807 if (mp->enable_disable) {
5808 pool_get (am->arp_events, event);
5809 memset (event, 0, sizeof (*event));
5811 event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
5812 event->client_index = mp->client_index;
5813 event->context = mp->context;
5814 event->address = mp->address;
5815 event->pid = mp->pid;
5817 rv = vnet_add_del_ip4_arp_change_event
5818 (vnm, arp_change_data_callback,
5820 &mp->address /* addr, in net byte order */,
5821 vpe_resolver_process_node.index,
5822 IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
5824 rv = vnet_add_del_ip4_arp_change_event
5825 (vnm, arp_change_delete_callback,
5827 &mp->address /* addr, in net byte order */,
5828 vpe_resolver_process_node.index,
5829 IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
5831 REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
5834 static void vl_api_input_acl_set_interface_t_handler
5835 (vl_api_input_acl_set_interface_t * mp)
5837 vlib_main_t *vm = vlib_get_main();
5838 vl_api_input_acl_set_interface_reply_t * rmp;
5840 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
5842 ip4_table_index = ntohl(mp->ip4_table_index);
5843 ip6_table_index = ntohl(mp->ip6_table_index);
5844 l2_table_index = ntohl(mp->l2_table_index);
5845 sw_if_index = ntohl(mp->sw_if_index);
5847 VALIDATE_SW_IF_INDEX(mp);
5849 rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
5850 ip6_table_index, l2_table_index,
5853 BAD_SW_IF_INDEX_LABEL;
5855 REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
5858 static void vl_api_ipsec_spd_add_del_t_handler
5859 (vl_api_ipsec_spd_add_del_t * mp)
5862 clib_warning ("unimplemented");
5865 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5866 vl_api_ipsec_spd_add_del_reply_t * rmp;
5870 rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
5872 rv = VNET_API_ERROR_UNIMPLEMENTED;
5875 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
5879 static void vl_api_ipsec_interface_add_del_spd_t_handler
5880 (vl_api_ipsec_interface_add_del_spd_t * mp)
5882 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5883 vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
5885 u32 sw_if_index __attribute__((unused));
5886 u32 spd_id __attribute__((unused));
5888 sw_if_index = ntohl(mp->sw_if_index);
5889 spd_id = ntohl(mp->spd_id);
5891 VALIDATE_SW_IF_INDEX(mp);
5894 rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
5896 rv = VNET_API_ERROR_UNIMPLEMENTED;
5899 BAD_SW_IF_INDEX_LABEL;
5901 REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
5904 static void vl_api_ipsec_spd_add_del_entry_t_handler
5905 (vl_api_ipsec_spd_add_del_entry_t * mp)
5907 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5908 vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
5914 memset(&p, 0, sizeof(p));
5916 p.id = ntohl(mp->spd_id);
5917 p.priority = ntohl(mp->priority);
5918 p.is_outbound = mp->is_outbound;
5919 p.is_ipv6 = mp->is_ipv6;
5921 if (mp->is_ipv6 || mp->is_ip_any) {
5922 clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
5923 clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
5924 clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
5925 clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
5927 clib_memcpy(&p.raddr.start.ip4.data, mp->remote_address_start, 4);
5928 clib_memcpy(&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
5929 clib_memcpy(&p.laddr.start.ip4.data, mp->local_address_start, 4);
5930 clib_memcpy(&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
5932 p.protocol = mp->protocol;
5933 p.rport.start = ntohs(mp->remote_port_start);
5934 p.rport.stop = ntohs(mp->remote_port_stop);
5935 p.lport.start = ntohs(mp->local_port_start);
5936 p.lport.stop = ntohs(mp->local_port_stop);
5937 /* policy action resolve unsupported */
5938 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
5939 clib_warning("unsupported action: 'resolve'");
5940 rv = VNET_API_ERROR_UNIMPLEMENTED;
5943 p.policy = mp->policy;
5944 p.sa_id = ntohl(mp->sa_id);
5946 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5950 if (mp->is_ip_any) {
5952 rv = ipsec_add_del_policy(vm, &p, mp->is_add);
5955 rv = VNET_API_ERROR_UNIMPLEMENTED;
5960 REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
5963 static void vl_api_ipsec_sad_add_del_entry_t_handler
5964 (vl_api_ipsec_sad_add_del_entry_t * mp)
5966 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
5967 vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
5972 memset(&sa, 0, sizeof(sa));
5974 sa.id = ntohl(mp->sad_id);
5975 sa.spi = ntohl(mp->spi);
5976 /* security protocol AH unsupported */
5977 if (mp->protocol == IPSEC_PROTOCOL_AH) {
5978 clib_warning("unsupported security protocol 'AH'");
5979 rv = VNET_API_ERROR_UNIMPLEMENTED;
5982 sa.protocol = mp->protocol;
5983 /* check for unsupported crypto-alg */
5984 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
5985 mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
5986 clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
5987 mp->crypto_algorithm);
5988 rv = VNET_API_ERROR_UNIMPLEMENTED;
5991 sa.crypto_alg = mp->crypto_algorithm;
5992 sa.crypto_key_len = mp->crypto_key_length;
5993 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
5994 /* check for unsupported integ-alg */
5995 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
5996 mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
5997 clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
5998 mp->integrity_algorithm);
5999 rv = VNET_API_ERROR_UNIMPLEMENTED;
6002 sa.integ_alg = mp->integrity_algorithm;
6003 sa.integ_key_len = mp->integrity_key_length;
6004 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
6005 sa.use_esn = mp->use_extended_sequence_number;
6006 sa.is_tunnel = mp->is_tunnel;
6007 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
6008 if (sa.is_tunnel_ip6) {
6009 clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
6010 clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
6012 clib_memcpy(&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
6013 clib_memcpy(&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
6016 rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
6018 rv = VNET_API_ERROR_UNIMPLEMENTED;
6023 REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
6027 vl_api_ikev2_profile_add_del_t_handler
6028 (vl_api_ikev2_profile_add_del_t * mp)
6030 vl_api_ikev2_profile_add_del_reply_t * rmp;
6034 vlib_main_t * vm = vlib_get_main();
6035 clib_error_t * error;
6036 u8 * tmp = format(0, "%s", mp->name);
6037 error = ikev2_add_del_profile(vm, tmp, mp->is_add);
6040 rv = VNET_API_ERROR_UNSPECIFIED;
6042 rv = VNET_API_ERROR_UNIMPLEMENTED;
6045 REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
6049 vl_api_ikev2_profile_set_auth_t_handler
6050 (vl_api_ikev2_profile_set_auth_t * mp)
6052 vl_api_ikev2_profile_set_auth_reply_t * rmp;
6056 vlib_main_t * vm = vlib_get_main();
6057 clib_error_t * error;
6058 u8 * tmp = format(0, "%s", mp->name);
6059 u8 * data = vec_new (u8, mp->data_len);
6060 clib_memcpy(data, mp->data, mp->data_len);
6061 error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
6065 rv = VNET_API_ERROR_UNSPECIFIED;
6067 rv = VNET_API_ERROR_UNIMPLEMENTED;
6070 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
6074 vl_api_ikev2_profile_set_id_t_handler
6075 (vl_api_ikev2_profile_set_id_t * mp)
6077 vl_api_ikev2_profile_add_del_reply_t * rmp;
6081 vlib_main_t * vm = vlib_get_main();
6082 clib_error_t * error;
6083 u8 * tmp = format(0, "%s", mp->name);
6084 u8 * data = vec_new (u8, mp->data_len);
6085 clib_memcpy(data, mp->data, mp->data_len);
6086 error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
6090 rv = VNET_API_ERROR_UNSPECIFIED;
6092 rv = VNET_API_ERROR_UNIMPLEMENTED;
6095 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
6099 vl_api_ikev2_profile_set_ts_t_handler
6100 (vl_api_ikev2_profile_set_ts_t * mp)
6102 vl_api_ikev2_profile_set_ts_reply_t * rmp;
6106 vlib_main_t * vm = vlib_get_main();
6107 clib_error_t * error;
6108 u8 * tmp = format(0, "%s", mp->name);
6109 error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
6110 mp->end_port, (ip4_address_t) mp->start_addr,
6111 (ip4_address_t) mp->end_addr, mp->is_local);
6114 rv = VNET_API_ERROR_UNSPECIFIED;
6116 rv = VNET_API_ERROR_UNIMPLEMENTED;
6119 REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
6123 vl_api_ikev2_set_local_key_t_handler
6124 (vl_api_ikev2_set_local_key_t * mp)
6126 vl_api_ikev2_profile_set_ts_reply_t * rmp;
6130 vlib_main_t * vm = vlib_get_main();
6131 clib_error_t * error;
6133 error = ikev2_set_local_key(vm, mp->key_file);
6135 rv = VNET_API_ERROR_UNSPECIFIED;
6137 rv = VNET_API_ERROR_UNIMPLEMENTED;
6140 REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
6144 vl_api_map_add_domain_t_handler
6145 (vl_api_map_add_domain_t * mp)
6147 vl_api_map_add_domain_reply_t * rmp;
6150 u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
6151 rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
6152 (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
6153 (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
6154 mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
6156 REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
6158 rmp->index = ntohl(index);
6163 vl_api_map_del_domain_t_handler
6164 (vl_api_map_del_domain_t * mp)
6166 vl_api_map_del_domain_reply_t * rmp;
6169 rv = map_delete_domain(ntohl(mp->index));
6171 REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
6175 vl_api_map_add_del_rule_t_handler
6176 (vl_api_map_add_del_rule_t * mp)
6178 vl_api_map_del_domain_reply_t * rmp;
6181 rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
6183 REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
6187 vl_api_map_domain_dump_t_handler
6188 (vl_api_map_domain_dump_t * mp)
6190 vl_api_map_domain_details_t * rmp;
6191 map_main_t *mm = &map_main;
6193 unix_shared_memory_queue_t * q;
6195 if (pool_elts (mm->domains) == 0)
6198 q = vl_api_client_index_to_input_queue (mp->client_index);
6203 pool_foreach(d, mm->domains, ({
6204 /* Make sure every field is initiated (or don't skip the memset()) */
6205 rmp = vl_msg_api_alloc (sizeof (*rmp));
6206 rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
6207 rmp->domain_index = htonl(d - mm->domains);
6208 rmp->ea_bits_len = d->ea_bits_len;
6209 rmp->psid_offset = d->psid_offset;
6210 rmp->psid_length = d->psid_length;
6211 clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
6212 rmp->ip4_prefix_len = d->ip4_prefix_len;
6213 clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
6214 rmp->ip6_prefix_len = d->ip6_prefix_len;
6215 clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
6216 rmp->ip6_src_len = d->ip6_src_len;
6217 rmp->mtu = htons(d->mtu);
6218 rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
6219 rmp->context = mp->context;
6221 vl_msg_api_send_shmem (q, (u8 *)&rmp);
6226 vl_api_map_rule_dump_t_handler
6227 (vl_api_map_rule_dump_t * mp)
6229 unix_shared_memory_queue_t * q;
6232 vl_api_map_rule_details_t * rmp;
6233 map_main_t *mm = &map_main;
6234 u32 domain_index = ntohl(mp->domain_index);
6237 if (pool_elts (mm->domains) == 0)
6240 d = pool_elt_at_index(mm->domains, domain_index);
6241 if (!d || !d->rules) {
6245 q = vl_api_client_index_to_input_queue (mp->client_index);
6250 for (i = 0; i < (0x1 << d->psid_length); i++) {
6252 if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
6255 rmp = vl_msg_api_alloc(sizeof(*rmp));
6256 memset(rmp, 0, sizeof(*rmp));
6257 rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
6258 rmp->psid = htons(i);
6259 clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
6260 rmp->context = mp->context;
6261 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6266 vl_api_map_summary_stats_t_handler (
6267 vl_api_map_summary_stats_t *mp)
6269 vl_api_map_summary_stats_reply_t *rmp;
6270 vlib_combined_counter_main_t *cm;
6273 u64 total_pkts[VLIB_N_RX_TX];
6274 u64 total_bytes[VLIB_N_RX_TX];
6275 map_main_t *mm = &map_main;
6276 unix_shared_memory_queue_t *q =
6277 vl_api_client_index_to_input_queue(mp->client_index);
6282 rmp = vl_msg_api_alloc (sizeof (*rmp));
6283 rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
6284 rmp->context = mp->context;
6287 memset (total_pkts, 0, sizeof (total_pkts));
6288 memset (total_bytes, 0, sizeof (total_bytes));
6290 map_domain_counter_lock (mm);
6291 vec_foreach(cm, mm->domain_counters) {
6292 which = cm - mm->domain_counters;
6294 for (i = 0; i < vec_len(cm->maxi); i++) {
6295 vlib_get_combined_counter (cm, i, &v);
6296 total_pkts[which] += v.packets;
6297 total_bytes[which] += v.bytes;
6301 map_domain_counter_unlock (mm);
6303 /* Note: in network byte order! */
6304 rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
6305 rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
6306 rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
6307 rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
6308 rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
6309 rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
6310 rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
6311 rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
6313 vl_msg_api_send_shmem(q, (u8 *)&rmp);
6316 static void vl_api_ipsec_sa_set_key_t_handler
6317 (vl_api_ipsec_sa_set_key_t * mp)
6319 vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
6320 vl_api_ipsec_sa_set_key_reply_t *rmp;
6324 sa.id = ntohl(mp->sa_id);
6325 sa.crypto_key_len = mp->crypto_key_length;
6326 clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
6327 sa.integ_key_len = mp->integrity_key_length;
6328 clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
6330 rv = ipsec_set_sa_key(vm, &sa);
6332 rv = VNET_API_ERROR_UNIMPLEMENTED;
6335 REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
6338 static void vl_api_cop_interface_enable_disable_t_handler
6339 (vl_api_cop_interface_enable_disable_t * mp)
6341 vl_api_cop_interface_enable_disable_reply_t * rmp;
6343 u32 sw_if_index = ntohl(mp->sw_if_index);
6346 VALIDATE_SW_IF_INDEX(mp);
6348 enable_disable = (int) mp->enable_disable;
6350 rv = cop_interface_enable_disable (sw_if_index, enable_disable);
6352 BAD_SW_IF_INDEX_LABEL;
6354 REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
6357 static void vl_api_cop_whitelist_enable_disable_t_handler
6358 (vl_api_cop_whitelist_enable_disable_t * mp)
6360 vl_api_cop_whitelist_enable_disable_reply_t * rmp;
6361 cop_whitelist_enable_disable_args_t _a, *a=&_a;
6362 u32 sw_if_index = ntohl(mp->sw_if_index);
6365 VALIDATE_SW_IF_INDEX(mp);
6367 a->sw_if_index = sw_if_index;
6370 a->default_cop = mp->default_cop;
6371 a->fib_id = ntohl(mp->fib_id);
6373 rv = cop_whitelist_enable_disable (a);
6375 BAD_SW_IF_INDEX_LABEL;
6377 REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
6380 static void vl_api_get_node_graph_t_handler
6381 (vl_api_get_node_graph_t * mp)
6385 api_main_t * am = &api_main;
6386 vlib_main_t * vm = vlib_get_main();
6388 vl_api_get_node_graph_reply_t * rmp;
6390 pthread_mutex_lock (&am->vlib_rp->mutex);
6391 oldheap = svm_push_data_heap (am->vlib_rp);
6394 * Keep the number of memcpy ops to a minimum (e.g. 1).
6396 vec_validate (vector, 16384);
6397 vec_reset_length (vector);
6400 vector = vlib_node_serialize (&vm->node_main, vector,
6401 (u32)~0 /* all threads */,
6402 1 /* include nexts */,
6403 1 /* include stats */);
6405 svm_pop_heap (oldheap);
6406 pthread_mutex_unlock (&am->vlib_rp->mutex);
6408 REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
6409 rmp->reply_in_shmem = (uword) vector);
6412 static void vl_api_trace_profile_add_t_handler
6413 (vl_api_trace_profile_add_t *mp)
6416 vl_api_trace_profile_add_reply_t * rmp;
6417 clib_error_t *error;
6419 /* Ignoring the profile id as currently a single profile
6421 error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
6422 ntohl(mp->node_id), ntohl(mp->trace_app_data),
6423 mp->pow_enable, mp->trace_tsp,
6426 clib_error_report(error);
6427 rv = clib_error_get_code(error);
6430 REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
6433 static void vl_api_trace_profile_apply_t_handler
6434 (vl_api_trace_profile_apply_t *mp)
6437 vl_api_trace_profile_apply_reply_t * rmp;
6439 if (mp->enable != 0) {
6440 rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
6441 ntohl(mp->prefix_length),
6443 mp->trace_op == IOAM_HBYH_ADD,
6444 mp->trace_op == IOAM_HBYH_POP,
6445 mp->trace_op == IOAM_HBYH_MOD);
6447 //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
6449 REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
6452 static void vl_api_trace_profile_del_t_handler
6453 (vl_api_trace_profile_del_t *mp)
6456 vl_api_trace_profile_del_reply_t * rmp;
6457 clib_error_t *error;
6459 error = clear_ioam_rewrite_fn();
6461 clib_error_report(error);
6462 rv = clib_error_get_code(error);
6465 REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
6469 vl_api_af_packet_create_t_handler
6470 (vl_api_af_packet_create_t *mp)
6472 vlib_main_t *vm = vlib_get_main();
6473 vl_api_af_packet_create_reply_t *rmp;
6475 u8 *host_if_name = NULL;
6478 host_if_name = format(0, "%s", mp->host_if_name);
6479 vec_add1 (host_if_name, 0);
6481 rv = af_packet_create_if(vm, host_if_name,
6482 mp->use_random_hw_addr ? 0 : mp->hw_addr, &sw_if_index);
6484 vec_free(host_if_name);
6486 REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
6487 rmp->sw_if_index = clib_host_to_net_u32(sw_if_index));
6491 vl_api_af_packet_delete_t_handler
6492 (vl_api_af_packet_delete_t *mp)
6494 vlib_main_t * vm = vlib_get_main();
6495 vl_api_af_packet_delete_reply_t *rmp;
6497 u8 *host_if_name = NULL;
6499 host_if_name = format(0, "%s", mp->host_if_name);
6500 vec_add1 (host_if_name, 0);
6502 rv = af_packet_delete_if(vm, host_if_name);
6504 vec_free(host_if_name);
6506 REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
6510 vl_api_policer_add_del_t_handler
6511 (vl_api_policer_add_del_t *mp)
6513 vlib_main_t * vm = vlib_get_main();
6514 vl_api_policer_add_del_reply_t *rmp;
6517 sse2_qos_pol_cfg_params_st cfg;
6518 clib_error_t * error;
6521 name = format(0, "%s", mp->name);
6523 memset (&cfg, 0, sizeof (cfg));
6525 cfg.rnd_type = mp->round_type;
6526 cfg.rate_type = mp->rate_type;
6527 cfg.rb.kbps.cir_kbps = mp->cir;
6528 cfg.rb.kbps.eir_kbps = mp->eir;
6529 cfg.rb.kbps.cb_bytes = mp->cb;
6530 cfg.rb.kbps.eb_bytes = mp->eb;
6531 cfg.conform_action.action_type = mp->conform_action_type;
6532 cfg.conform_action.dscp = mp->conform_dscp;
6533 cfg.exceed_action.action_type = mp->exceed_action_type;
6534 cfg.exceed_action.dscp = mp->exceed_dscp;
6535 cfg.violate_action.action_type = mp->violate_action_type;
6536 cfg.violate_action.dscp = mp->violate_dscp;
6537 cfg.color_aware = mp->color_aware;
6539 error = policer_add_del(vm, name, &cfg, &policer_index, mp->is_add);
6542 rv = VNET_API_ERROR_UNSPECIFIED;
6544 REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY,
6546 if (rv == 0 && mp->is_add)
6547 rmp->policer_index = ntohl(policer_index);
6549 rmp->policer_index = ~0;
6554 send_policer_details (u8 *name,
6555 sse2_qos_pol_cfg_params_st *config,
6556 policer_read_response_type_st *templ,
6557 unix_shared_memory_queue_t *q,
6560 vl_api_policer_details_t * mp;
6562 mp = vl_msg_api_alloc (sizeof (*mp));
6563 memset (mp, 0, sizeof (*mp));
6564 mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
6565 mp->context = context;
6566 mp->cir = htonl(config->rb.kbps.cir_kbps);
6567 mp->eir = htonl(config->rb.kbps.eir_kbps);
6568 mp->cb = htonl(config->rb.kbps.cb_bytes);
6569 mp->eb = htonl(config->rb.kbps.eb_bytes);
6570 mp->rate_type = config->rate_type;
6571 mp->round_type = config->rnd_type;
6572 mp->type = config->rfc;
6573 mp->conform_action_type = config->conform_action.action_type;
6574 mp->conform_dscp = config->conform_action.dscp;
6575 mp->exceed_action_type = config->exceed_action.action_type;
6576 mp->exceed_dscp = config->exceed_action.dscp;
6577 mp->violate_action_type = config->violate_action.action_type;
6578 mp->violate_dscp = config->violate_action.dscp;
6579 mp->single_rate = templ->single_rate ? 1 : 0;
6580 mp->color_aware = templ->color_aware ? 1 : 0;
6581 mp->scale = htonl(templ->scale);
6582 mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
6583 mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
6584 mp->current_limit = htonl(templ->current_limit);
6585 mp->current_bucket = htonl(templ->current_bucket);
6586 mp->extended_limit = htonl(templ->extended_limit);
6587 mp->extended_bucket = htonl(templ->extended_bucket);
6588 mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
6590 strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
6592 vl_msg_api_send_shmem (q, (u8 *)&mp);
6596 vl_api_policer_dump_t_handler
6597 (vl_api_policer_dump_t *mp)
6599 unix_shared_memory_queue_t * q;
6600 vnet_policer_main_t * pm = &vnet_policer_main;
6604 u8 * match_name = 0;
6606 sse2_qos_pol_cfg_params_st *config;
6607 policer_read_response_type_st *templ;
6609 q = vl_api_client_index_to_input_queue (mp->client_index);
6613 if (mp->match_name_valid) {
6614 match_name = format(0, "%s%c", mp->match_name, 0);
6617 if (mp->match_name_valid) {
6618 p = hash_get_mem (pm->policer_config_by_name, match_name);
6621 config = pool_elt_at_index (pm->configs, pool_index);
6622 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6623 send_policer_details(match_name, config, templ, q, mp->context);
6626 hash_foreach_pair (hp, pm->policer_config_by_name,
6628 name = (u8 *) hp->key;
6629 pool_index = hp->value[0];
6630 config = pool_elt_at_index (pm->configs, pool_index);
6631 templ = pool_elt_at_index (pm->policer_templates, pool_index);
6632 send_policer_details(name, config, templ, q, mp->context);
6638 vl_api_policer_classify_set_interface_t_handler
6639 (vl_api_policer_classify_set_interface_t * mp)
6641 vlib_main_t *vm = vlib_get_main();
6642 vl_api_policer_classify_set_interface_reply_t * rmp;
6644 u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
6646 ip4_table_index = ntohl(mp->ip4_table_index);
6647 ip6_table_index = ntohl(mp->ip6_table_index);
6648 l2_table_index = ntohl(mp->l2_table_index);
6649 sw_if_index = ntohl(mp->sw_if_index);
6651 VALIDATE_SW_IF_INDEX(mp);
6653 rv = vnet_set_policer_classify_intfc(vm, sw_if_index, ip4_table_index,
6654 ip6_table_index, l2_table_index,
6657 BAD_SW_IF_INDEX_LABEL;
6659 REPLY_MACRO(VL_API_POLICER_CLASSIFY_SET_INTERFACE_REPLY);
6663 send_policer_classify_details (u32 sw_if_index,
6665 unix_shared_memory_queue_t *q,
6668 vl_api_policer_classify_details_t * mp;
6670 mp = vl_msg_api_alloc (sizeof (*mp));
6671 memset (mp, 0, sizeof (*mp));
6672 mp->_vl_msg_id = ntohs (VL_API_POLICER_CLASSIFY_DETAILS);
6673 mp->context = context;
6674 mp->sw_if_index= htonl(sw_if_index);
6675 mp->table_index= htonl(table_index);
6677 vl_msg_api_send_shmem (q, (u8 *)&mp);
6681 vl_api_policer_classify_dump_t_handler
6682 (vl_api_policer_classify_dump_t *mp)
6684 unix_shared_memory_queue_t * q;
6685 policer_classify_main_t * pcm = &policer_classify_main;
6689 q = vl_api_client_index_to_input_queue (mp->client_index);
6693 vec_tbl = pcm->classify_table_index_by_sw_if_index[mp->type];
6695 if (vec_len(vec_tbl)) {
6696 for (i = 0; i < vec_len (vec_tbl); i++) {
6697 if (vec_elt(vec_tbl, i) == ~0)
6700 send_policer_classify_details(i, vec_elt(vec_tbl, i), q,
6707 vl_api_netmap_create_t_handler
6708 (vl_api_netmap_create_t *mp)
6710 vlib_main_t *vm = vlib_get_main();
6711 vl_api_netmap_create_reply_t *rmp;
6715 if_name = format(0, "%s", mp->netmap_if_name);
6716 vec_add1 (if_name, 0);
6718 rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
6719 mp->is_pipe, mp->is_master, 0);
6723 REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
6727 vl_api_netmap_delete_t_handler
6728 (vl_api_netmap_delete_t *mp)
6730 vlib_main_t * vm = vlib_get_main();
6731 vl_api_netmap_delete_reply_t *rmp;
6735 if_name = format(0, "%s", mp->netmap_if_name);
6736 vec_add1 (if_name, 0);
6738 rv = netmap_delete_if(vm, if_name);
6742 REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
6745 static void vl_api_mpls_gre_tunnel_details_t_handler (
6746 vl_api_mpls_gre_tunnel_details_t * mp)
6748 clib_warning ("BUG");
6751 static void send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
6752 unix_shared_memory_queue_t *q,
6753 mpls_gre_tunnel_t * gt,
6757 vl_api_mpls_gre_tunnel_details_t * mp;
6759 mp = vl_msg_api_alloc (sizeof (*mp));
6760 memset (mp, 0, sizeof (*mp));
6761 mp->_vl_msg_id = ntohs(VL_API_MPLS_GRE_TUNNEL_DETAILS);
6762 mp->context = context;
6765 mp->tunnel_index = htonl(index);
6766 mp->tunnel_src = gt->tunnel_src.as_u32;
6767 mp->tunnel_dst = gt->tunnel_dst.as_u32;
6768 mp->intfc_address = gt->intfc_address.as_u32;
6769 mp->mask_width = htonl(gt->mask_width);
6770 mp->inner_fib_index = htonl(gt->inner_fib_index);
6771 mp->outer_fib_index = htonl(gt->outer_fib_index);
6772 mp->encap_index = htonl(gt->encap_index);
6773 mp->hw_if_index = htonl(gt->hw_if_index);
6774 mp->l2_only = htonl(gt->l2_only);
6777 mpls_main_t * mm = &mpls_main;
6782 e = pool_elt_at_index (mm->encaps, gt->encap_index);
6783 len = vec_len (e->labels);
6784 mp->nlabels = htonl(len);
6786 for (i = 0; i < len; i++) {
6787 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6788 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6791 vl_msg_api_send_shmem (q, (u8 *)&mp);
6795 vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t *mp)
6797 vpe_api_main_t * am = &vpe_api_main;
6798 unix_shared_memory_queue_t * q;
6799 vlib_main_t * vm = &vlib_global_main;
6800 mpls_main_t * mm = &mpls_main;
6801 mpls_gre_tunnel_t * gt;
6802 u32 index = ntohl(mp->tunnel_index);
6804 q = vl_api_client_index_to_input_queue (mp->client_index);
6808 if (pool_elts (mm->gre_tunnels)) {
6809 if(mp->tunnel_index >= 0) {
6810 vlib_cli_output (vm, "MPLS-GRE tunnel %u", index);
6811 gt = pool_elt_at_index (mm->gre_tunnels, index);
6812 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6814 vlib_cli_output (vm, "MPLS-GRE tunnels");
6815 pool_foreach (gt, mm->gre_tunnels,
6817 send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
6821 vlib_cli_output (vm, "No MPLS-GRE tunnels");
6825 static void vl_api_mpls_eth_tunnel_details_t_handler (
6826 vl_api_mpls_eth_tunnel_details_t * mp)
6828 clib_warning ("BUG");
6831 static void send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
6832 unix_shared_memory_queue_t *q,
6833 mpls_eth_tunnel_t * et,
6837 vl_api_mpls_eth_tunnel_details_t * mp;
6839 mp = vl_msg_api_alloc (sizeof (*mp));
6840 memset (mp, 0, sizeof (*mp));
6841 mp->_vl_msg_id = ntohs(VL_API_MPLS_ETH_TUNNEL_DETAILS);
6842 mp->context = context;
6845 mp->tunnel_index = htonl(index);
6846 memcpy(mp->tunnel_dst_mac, et->tunnel_dst, 6);
6847 mp->intfc_address = et->intfc_address.as_u32;
6848 mp->tx_sw_if_index = htonl(et->tx_sw_if_index);
6849 mp->inner_fib_index = htonl(et->inner_fib_index);
6850 mp->mask_width = htonl(et->mask_width);
6851 mp->encap_index = htonl(et->encap_index);
6852 mp->hw_if_index = htonl(et->hw_if_index);
6853 mp->l2_only = htonl(et->l2_only);
6856 mpls_main_t * mm = &mpls_main;
6861 e = pool_elt_at_index (mm->encaps, et->encap_index);
6862 len = vec_len (e->labels);
6863 mp->nlabels = htonl(len);
6865 for (i = 0; i < len; i++) {
6866 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6867 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6870 vl_msg_api_send_shmem (q, (u8 *)&mp);
6874 vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t *mp)
6876 vpe_api_main_t * am = &vpe_api_main;
6877 unix_shared_memory_queue_t * q;
6878 vlib_main_t * vm = &vlib_global_main;
6879 mpls_main_t * mm = &mpls_main;
6880 mpls_eth_tunnel_t * et;
6881 u32 index = ntohl(mp->tunnel_index);
6883 q = vl_api_client_index_to_input_queue (mp->client_index);
6887 clib_warning("Received mpls_eth_tunnel_dump");
6888 clib_warning("Received tunnel index: %u from client %u", index, mp->client_index);
6890 if (pool_elts (mm->eth_tunnels)) {
6891 if(mp->tunnel_index >= 0) {
6892 vlib_cli_output (vm, "MPLS-Ethernet tunnel %u", index);
6893 et = pool_elt_at_index (mm->eth_tunnels, index);
6894 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6896 clib_warning("MPLS-Ethernet tunnels");
6897 pool_foreach (et, mm->eth_tunnels,
6899 send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
6903 clib_warning("No MPLS-Ethernet tunnels");
6907 static void vl_api_mpls_fib_encap_details_t_handler (
6908 vl_api_mpls_fib_encap_details_t * mp)
6910 clib_warning ("BUG");
6913 static void send_mpls_fib_encap_details (vpe_api_main_t * am,
6914 unix_shared_memory_queue_t *q,
6918 vl_api_mpls_fib_encap_details_t * mp;
6920 mp = vl_msg_api_alloc (sizeof (*mp));
6921 memset (mp, 0, sizeof (*mp));
6922 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_ENCAP_DETAILS);
6923 mp->context = context;
6925 mp->fib_index = htonl(s->fib_index);
6926 mp->entry_index = htonl(s->entry_index);
6928 mp->s_bit = htonl(s->s_bit);
6930 mpls_main_t * mm = &mpls_main;
6935 e = pool_elt_at_index (mm->encaps, s->entry_index);
6936 len = vec_len (e->labels);
6937 mp->nlabels = htonl(len);
6939 for (i = 0; i < len; i++) {
6940 mp->labels[i] = htonl(vnet_mpls_uc_get_label(
6941 clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
6944 vl_msg_api_send_shmem (q, (u8 *)&mp);
6948 vl_api_mpls_fib_encap_dump_t_handler (vl_api_mpls_fib_encap_dump_t *mp)
6950 vpe_api_main_t * am = &vpe_api_main;
6951 unix_shared_memory_queue_t * q;
6952 vlib_main_t * vm = &vlib_global_main;
6955 show_mpls_fib_t *records = 0;
6957 mpls_main_t * mm = &mpls_main;
6958 ip4_main_t * im = &ip4_main;
6961 q = vl_api_client_index_to_input_queue (mp->client_index);
6965 hash_foreach (key, value, mm->mpls_encap_by_fib_and_dest,
6967 vec_add2 (records, s, 1);
6968 s->fib_index = (u32)(key>>32);
6969 s->dest = (u32)(key & 0xFFFFFFFF);
6970 s->entry_index = (u32) value;
6973 if (0 == vec_len(records)) {
6974 vlib_cli_output(vm, "MPLS encap table empty");
6978 /* sort output by dst address within fib */
6979 vec_sort_with_function(records, mpls_dest_cmp);
6980 vec_sort_with_function(records, mpls_fib_index_cmp);
6981 vlib_cli_output(vm, "MPLS encap table");
6982 vlib_cli_output(vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
6983 vec_foreach (s, records)
6985 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
6986 vlib_cli_output(vm, "%=6d%=16U%=16U", rx_fib->table_id,
6987 format_ip4_address, &s->dest, format_mpls_encap_index, mm,
6989 send_mpls_fib_encap_details (am, q, s, mp->context);
6996 static void vl_api_mpls_fib_decap_details_t_handler (
6997 vl_api_mpls_fib_decap_details_t * mp)
6999 clib_warning ("BUG");
7002 static void send_mpls_fib_decap_details (vpe_api_main_t * am,
7003 unix_shared_memory_queue_t *q,
7010 vl_api_mpls_fib_decap_details_t * mp;
7012 mp = vl_msg_api_alloc (sizeof (*mp));
7013 memset (mp, 0, sizeof (*mp));
7014 mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_DECAP_DETAILS);
7015 mp->context = context;
7017 mp->fib_index = htonl(s->fib_index);
7018 mp->entry_index = htonl(s->entry_index);
7020 mp->s_bit = htonl(s->s_bit);
7021 mp->label = htonl(s->label);
7022 mp->rx_table_id = htonl(rx_table_id);
7023 mp->tx_table_id = htonl(tx_table_id);
7024 strncpy ((char *) mp->swif_tag,
7025 (char *) swif_tag, ARRAY_LEN(mp->swif_tag)-1);
7027 vl_msg_api_send_shmem (q, (u8 *)&mp);
7031 vl_api_mpls_fib_decap_dump_t_handler (vl_api_mpls_fib_decap_dump_t *mp)
7033 vpe_api_main_t * am = &vpe_api_main;
7034 unix_shared_memory_queue_t * q;
7035 vlib_main_t * vm = &vlib_global_main;
7038 show_mpls_fib_t *records = 0;
7040 mpls_main_t * mm = &mpls_main;
7041 ip4_main_t * im = &ip4_main;
7047 q = vl_api_client_index_to_input_queue (mp->client_index);
7051 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
7053 vec_add2 (records, s, 1);
7054 s->fib_index = (u32)(key>>32);
7055 s->entry_index = (u32) value;
7056 s->label = ((u32) key)>>12;
7057 s->s_bit = (key & (1<<8)) != 0;
7060 if (!vec_len(records)) {
7061 vlib_cli_output(vm, "MPLS decap table empty");
7065 vec_sort_with_function(records, mpls_label_cmp);
7066 vlib_cli_output(vm, "MPLS decap table");
7067 vlib_cli_output(vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
7069 vec_foreach (s, records)
7072 d = pool_elt_at_index(mm->decaps, s->entry_index);
7073 if (d->next_index == MPLS_INPUT_NEXT_IP4_INPUT) {
7074 tx_fib = vec_elt_at_index(im->fibs, d->tx_fib_index);
7075 tx_table_id = tx_fib->table_id;
7078 tx_table_id = d->tx_fib_index;
7081 rx_fib = vec_elt_at_index(im->fibs, s->fib_index);
7083 vlib_cli_output(vm, "%=10d%=10d%=5s%=6d%=6d", rx_fib->table_id,
7084 tx_table_id, swif_tag, s->label, s->s_bit);
7086 send_mpls_fib_decap_details (am, q, s, rx_fib->table_id,
7087 tx_table_id, swif_tag, mp->context);
7094 static void vl_api_classify_table_ids_t_handler (vl_api_classify_table_ids_t *mp)
7096 unix_shared_memory_queue_t * q;
7098 q = vl_api_client_index_to_input_queue (mp->client_index);
7102 vnet_classify_main_t * cm = &vnet_classify_main;
7103 vnet_classify_table_t * t;
7104 u32 * table_ids = 0;
7107 pool_foreach (t, cm->tables,
7109 vec_add1 (table_ids, ntohl(t - cm->tables));
7111 count = vec_len(table_ids);
7113 vl_api_classify_table_ids_reply_t *rmp;
7114 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + count * sizeof(u32));
7115 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_IDS_REPLY);
7116 rmp->context = mp->context;
7117 rmp->count = ntohl(count);
7118 clib_memcpy(rmp->ids, table_ids, count * sizeof(u32));
7121 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7123 vec_free (table_ids);
7126 static void vl_api_classify_table_by_interface_t_handler (vl_api_classify_table_by_interface_t *mp)
7128 vl_api_classify_table_by_interface_reply_t *rmp;
7131 u32 sw_if_index = ntohl(mp->sw_if_index);
7134 vec_validate (acl, INPUT_ACL_N_TABLES - 1);
7137 VALIDATE_SW_IF_INDEX(mp);
7139 input_acl_main_t * am = &input_acl_main;
7144 for (type = 0; type < INPUT_ACL_N_TABLES; type++)
7146 u32 * vec_tbl = am->classify_table_index_by_sw_if_index[type];
7147 if (vec_len(vec_tbl)) {
7148 for (if_idx = 0; if_idx < vec_len (vec_tbl); if_idx++)
7150 if (vec_elt(vec_tbl, if_idx) == ~0 || sw_if_index != if_idx) {
7153 acl[type] = vec_elt(vec_tbl, if_idx);
7158 BAD_SW_IF_INDEX_LABEL;
7160 REPLY_MACRO2(VL_API_CLASSIFY_TABLE_BY_INTERFACE_REPLY,
7162 rmp->sw_if_index = ntohl(sw_if_index);
7163 rmp->l2_table_id = ntohl(acl[INPUT_ACL_TABLE_L2]);
7164 rmp->ip4_table_id = ntohl(acl[INPUT_ACL_TABLE_IP4]);
7165 rmp->ip6_table_id = ntohl(acl[INPUT_ACL_TABLE_IP6]);
7170 static void vl_api_classify_table_info_t_handler (vl_api_classify_table_info_t *mp)
7172 unix_shared_memory_queue_t * q;
7174 q = vl_api_client_index_to_input_queue (mp->client_index);
7178 vl_api_classify_table_info_reply_t *rmp = 0;
7180 vnet_classify_main_t * cm = &vnet_classify_main;
7181 u32 table_id = ntohl(mp->table_id);
7182 vnet_classify_table_t * t;
7184 pool_foreach (t, cm->tables,
7186 if (table_id == t - cm->tables) {
7187 rmp = vl_msg_api_alloc_as_if_client(sizeof (*rmp) + t->match_n_vectors * sizeof (u32x4));
7188 rmp->_vl_msg_id = ntohs (VL_API_CLASSIFY_TABLE_INFO_REPLY);
7189 rmp->context = mp->context;
7190 rmp->table_id = ntohl(table_id);
7191 rmp->nbuckets = ntohl(t->nbuckets);
7192 rmp->match_n_vectors = ntohl(t->match_n_vectors);
7193 rmp->skip_n_vectors = ntohl(t->skip_n_vectors);
7194 rmp->active_sessions = ntohl(t->active_elements);
7195 rmp->next_table_index = ntohl(t->next_table_index);
7196 rmp->miss_next_index = ntohl(t->miss_next_index);
7197 rmp->mask_length = ntohl(t->match_n_vectors * sizeof (u32x4));
7198 clib_memcpy(rmp->mask, t->mask, t->match_n_vectors * sizeof(u32x4));
7205 rmp = vl_msg_api_alloc (sizeof (*rmp));
7206 rmp->_vl_msg_id = ntohs((VL_API_CLASSIFY_TABLE_INFO_REPLY));
7207 rmp->context = mp->context;
7208 rmp->retval = ntohl(VNET_API_ERROR_CLASSIFY_TABLE_NOT_FOUND);
7211 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7214 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
7216 clib_warning ("BUG");
7219 static void send_classify_session_details (unix_shared_memory_queue_t * q,
7222 vnet_classify_entry_t * e,
7225 vl_api_classify_session_details_t *rmp;
7227 rmp = vl_msg_api_alloc (sizeof (*rmp));
7228 memset (rmp, 0, sizeof (*rmp));
7229 rmp->_vl_msg_id = ntohs(VL_API_CLASSIFY_SESSION_DETAILS);
7230 rmp->context = context;
7231 rmp->table_id = ntohl(table_id);
7232 rmp->hit_next_index = ntohl(e->next_index);
7233 rmp->advance = ntohl(e->advance);
7234 rmp->opaque_index = ntohl(e->opaque_index);
7235 rmp->match_length = ntohl(match_length);
7236 clib_memcpy(rmp->match, e->key, match_length);
7238 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7241 static void vl_api_classify_session_dump_t_handler (vl_api_classify_session_dump_t *mp)
7243 vnet_classify_main_t * cm = &vnet_classify_main;
7244 unix_shared_memory_queue_t * q;
7246 u32 table_id = ntohl(mp->table_id);
7247 vnet_classify_table_t * t;
7249 q = vl_api_client_index_to_input_queue (mp->client_index);
7251 pool_foreach (t, cm->tables,
7253 if (table_id == t - cm->tables) {
7254 vnet_classify_bucket_t * b;
7255 vnet_classify_entry_t * v, * save_v;
7258 for (i = 0; i < t->nbuckets; i++)
7260 b = &t->buckets [i];
7264 save_v = vnet_classify_get_entry (t, b->offset);
7265 for (j = 0; j < (1<<b->log2_pages); j++)
7267 for (k = 0; k < t->entries_per_page; k++)
7269 v = vnet_classify_entry_at_index (t, save_v, j*t->entries_per_page + k);
7270 if (vnet_classify_entry_is_free (v))
7273 send_classify_session_details(q, table_id,
7274 t->match_n_vectors * sizeof (u32x4), v, mp->context);
7283 static void vl_api_ipfix_enable_t_handler (vl_api_ipfix_enable_t *mp)
7285 vlib_main_t *vm = vlib_get_main();
7286 flow_report_main_t * frm = &flow_report_main;
7287 vl_api_ipfix_enable_reply_t *rmp;
7288 ip4_address_t collector, src;
7289 u16 collector_port = UDP_DST_PORT_ipfix;
7291 u32 template_interval;
7296 memcpy(collector.data, mp->collector_address, sizeof(collector.data));
7297 collector_port = ntohs(mp->collector_port);
7298 if (collector_port == (u16)~0)
7299 collector_port = UDP_DST_PORT_ipfix;
7300 memcpy(src.data, mp->src_address, sizeof(src.data));
7301 fib_id = ntohl(mp->vrf_id);
7303 ip4_main_t * im = &ip4_main;
7304 uword * p = hash_get (im->fib_index_by_table_id, fib_id);
7306 rv = VNET_API_ERROR_NO_SUCH_FIB;
7311 path_mtu = ntohl(mp->path_mtu);
7313 path_mtu = 512; // RFC 7011 section 10.3.3.
7314 template_interval = ntohl(mp->template_interval);
7315 if (template_interval == ~0)
7316 template_interval = 20;
7318 if (collector.as_u32 == 0) {
7319 rv = VNET_API_ERROR_INVALID_VALUE;
7323 if (src.as_u32 == 0) {
7324 rv = VNET_API_ERROR_INVALID_VALUE;
7328 if (path_mtu > 1450 /* vpp does not support fragmentation */) {
7329 rv = VNET_API_ERROR_INVALID_VALUE;
7333 if (path_mtu < 68) {
7334 rv = VNET_API_ERROR_INVALID_VALUE;
7338 /* Reset report streams if we are reconfiguring IP addresses */
7339 if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
7340 frm->src_address.as_u32 != src.as_u32 ||
7341 frm->collector_port != collector_port)
7342 vnet_flow_reports_reset(frm);
7344 frm->ipfix_collector.as_u32 = collector.as_u32;
7345 frm->collector_port = collector_port;
7346 frm->src_address.as_u32 = src.as_u32;
7347 frm->fib_index = fib_index;
7348 frm->path_mtu = path_mtu;
7349 frm->template_interval = template_interval;
7351 /* Turn on the flow reporting process */
7352 vlib_process_signal_event (vm, flow_report_process_node.index,
7356 REPLY_MACRO(VL_API_IPFIX_ENABLE_REPLY);
7359 static void vl_api_ipfix_dump_t_handler (vl_api_ipfix_dump_t *mp)
7361 flow_report_main_t * frm = &flow_report_main;
7362 unix_shared_memory_queue_t * q;
7363 vl_api_ipfix_details_t *rmp;
7365 q = vl_api_client_index_to_input_queue (mp->client_index);
7367 rmp = vl_msg_api_alloc (sizeof (*rmp));
7368 memset (rmp, 0, sizeof (*rmp));
7369 rmp->_vl_msg_id = ntohs(VL_API_IPFIX_DETAILS);
7370 rmp->context = mp->context;
7371 memcpy(rmp->collector_address, frm->ipfix_collector.data,
7372 sizeof(frm->ipfix_collector.data));
7373 rmp->collector_port = htons(frm->collector_port);
7374 memcpy(rmp->src_address, frm->src_address.data,
7375 sizeof(frm->src_address.data));
7376 rmp->fib_index = htonl(frm->fib_index);
7377 rmp->path_mtu = htonl(frm->path_mtu);
7378 rmp->template_interval = htonl(frm->template_interval);
7380 vl_msg_api_send_shmem (q, (u8 *)&rmp);
7383 static void vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t *mp)
7385 vl_api_pg_create_interface_reply_t *rmp;
7388 pg_main_t * pg = &pg_main;
7389 u32 sw_if_index = pg_interface_add_or_get (pg, ntohl(mp->interface_id));
7391 REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
7393 rmp->sw_if_index = ntohl(sw_if_index);
7397 static void vl_api_pg_capture_t_handler (vl_api_pg_capture_t *mp)
7399 vl_api_pg_capture_reply_t *rmp;
7402 vnet_main_t * vnm = vnet_get_main();
7403 vnet_interface_main_t * im = &vnm->interface_main;
7404 vnet_hw_interface_t * hi = 0;
7406 u8 * intf_name = format (0, "pg%d", ntohl(mp->interface_id), 0);
7407 u32 hw_if_index = ~0;
7408 uword * p = hash_get_mem (im->hw_interface_by_name, intf_name);
7411 vec_free (intf_name);
7413 if (hw_if_index != ~0) {
7414 pg_capture_args_t _a, *a=&_a;
7416 u32 len = ntohl(mp->pcap_name_length);
7417 u8 * pcap_file_name = vec_new(u8, len);
7418 clib_memcpy(pcap_file_name, mp->pcap_file_name, len);
7420 hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
7421 a->hw_if_index = hw_if_index;
7422 a->dev_instance = hi->dev_instance;
7423 a->is_enabled = mp->is_enabled;
7424 a->pcap_file_name = pcap_file_name;
7425 a->count = ntohl(mp->count);
7427 clib_error_t * e = pg_capture (a);
7429 clib_error_report(e);
7430 rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
7433 vec_free (pcap_file_name);
7435 REPLY_MACRO(VL_API_PG_CAPTURE_REPLY);
7438 static void vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t *mp)
7440 vl_api_pg_enable_disable_reply_t *rmp;
7443 pg_main_t * pg = &pg_main;
7444 u32 stream_index = ~0;
7446 int is_enable = mp->is_enabled != 0;
7447 u32 len = ntohl(mp->stream_name_length)-1;
7450 u8 * stream_name = vec_new(u8, len);
7451 clib_memcpy(stream_name, mp->stream_name, len);
7452 uword * p = hash_get_mem (pg->stream_index_by_name, stream_name);
7455 vec_free(stream_name);
7458 pg_enable_disable (stream_index, is_enable);
7460 REPLY_MACRO(VL_API_PG_ENABLE_DISABLE_REPLY);
7463 static void vl_api_ip_source_and_port_range_check_add_del_t_handler (
7464 vl_api_ip_source_and_port_range_check_add_del_t *mp)
7466 vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp;
7469 u8 is_ipv6 = mp->is_ipv6;
7470 u8 is_add = mp->is_add;
7471 u8 mask_length = mp->mask_length;
7472 ip4_address_t ip4_addr;
7473 //ip6_address_t ip6_addr;
7474 u16 * low_ports = 0 ;
7475 u16 * high_ports = 0 ;
7476 u16 tmp_low, tmp_high;
7481 // Validate port range
7482 num_ranges = mp->number_of_ranges;
7483 if (num_ranges > 32) { // This is size of array in VPE.API
7484 rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
7488 vec_reset_length (low_ports);
7489 vec_reset_length (high_ports);
7491 for (i = 0; i < num_ranges; i++) {
7492 tmp_low = mp->low_ports[i];
7493 tmp_high = mp->high_ports[i];
7494 // If tmp_low <= tmp_high then only need to check tmp_low = 0
7495 // If tmp_low <= tmp_high then only need to check tmp_high > 65535
7496 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535) {
7497 rv = VNET_API_ERROR_INVALID_VALUE;
7500 vec_add1 (low_ports, tmp_low );
7501 vec_add1 (high_ports, tmp_high+1 );
7504 // Validate mask_length
7505 if (mask_length < 0 ||
7506 ( is_ipv6 && mask_length > 128) ||
7507 ( !is_ipv6 && mask_length > 32)) {
7508 rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
7512 vrf_id = ntohl (mp->vrf_id);
7515 rv = VNET_API_ERROR_INVALID_VALUE;
7520 /* clib_memcpy (ip6_addr.as_u8, mp->address, */
7521 /* sizeof (ip6_addr.as_u8)); */
7522 /* rv = ip6_source_and_port_range_check_add_del (ip6_addr, */
7531 clib_memcpy (ip4_addr.data, mp->address,
7533 rv = ip4_source_and_port_range_check_add_del (&ip4_addr,
7542 vec_free (low_ports);
7543 vec_free (high_ports);
7545 REPLY_MACRO(VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY);
7549 vl_api_ip_source_and_port_range_check_interface_add_del_t_handler
7550 (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp)
7552 vlib_main_t *vm = vlib_get_main();
7553 vl_api_ip_source_and_port_range_check_interface_add_del_reply_t * rmp;
7554 ip4_main_t * im = &ip4_main;
7556 u32 sw_if_index, fib_index, vrf_id;
7559 vrf_id = ntohl(mp->vrf_id);
7561 p = hash_get (im->fib_index_by_table_id, vrf_id);
7564 rv = VNET_API_ERROR_INVALID_VALUE;
7570 sw_if_index = ntohl(mp->sw_if_index);
7572 VALIDATE_SW_IF_INDEX(mp);
7574 rv = set_ip_source_and_port_range_check (vm, fib_index, sw_if_index, mp->is_add);
7576 BAD_SW_IF_INDEX_LABEL;
7579 REPLY_MACRO(VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
7582 #define BOUNCE_HANDLER(nn) \
7583 static void vl_api_##nn##_t_handler ( \
7584 vl_api_##nn##_t *mp) \
7586 vpe_client_registration_t *reg; \
7587 vpe_api_main_t * vam = &vpe_api_main; \
7588 unix_shared_memory_queue_t * q; \
7590 /* One registration only... */ \
7591 pool_foreach(reg, vam->nn##_registrations, \
7593 q = vl_api_client_index_to_input_queue (reg->client_index); \
7596 * If the queue is stuffed, turf the msg and complain \
7597 * It's unlikely that the intended recipient is \
7598 * alive; avoid deadlock at all costs. \
7600 if (q->cursize == q->maxsize) { \
7601 clib_warning ("ERROR: receiver queue full, drop msg"); \
7602 vl_msg_api_free (mp); \
7605 vl_msg_api_send_shmem (q, (u8 *)&mp); \
7609 vl_msg_api_free (mp); \
7614 * Add vpe's API message handlers to the table.
7615 * vlib has alread mapped shared memory and
7616 * added the client registration handlers.
7617 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
7620 static clib_error_t *
7621 vpe_api_hookup (vlib_main_t *vm)
7623 api_main_t * am = &api_main;
7626 vl_msg_api_set_handlers(VL_API_##N, #n, \
7627 vl_api_##n##_t_handler, \
7629 vl_api_##n##_t_endian, \
7630 vl_api_##n##_t_print, \
7631 sizeof(vl_api_##n##_t), 1);
7632 foreach_vpe_api_msg;
7636 * Manually register the sr tunnel add del msg, so we trace
7637 * enough bytes to capture a typical segment list
7639 vl_msg_api_set_handlers (VL_API_SR_TUNNEL_ADD_DEL,
7640 "sr_tunnel_add_del",
7641 vl_api_sr_tunnel_add_del_t_handler,
7643 vl_api_sr_tunnel_add_del_t_endian,
7644 vl_api_sr_tunnel_add_del_t_print,
7649 * Manually register the sr policy add del msg, so we trace
7650 * enough bytes to capture a typical tunnel name list
7652 vl_msg_api_set_handlers (VL_API_SR_POLICY_ADD_DEL,
7653 "sr_policy_add_del",
7654 vl_api_sr_policy_add_del_t_handler,
7656 vl_api_sr_policy_add_del_t_endian,
7657 vl_api_sr_policy_add_del_t_print,
7661 * Trace space for 8 MPLS encap labels, classifier mask+match
7663 am->api_trace_cfg [VL_API_MPLS_ADD_DEL_ENCAP].size += 8 * sizeof(u32);
7664 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_TABLE].size
7665 += 5 * sizeof (u32x4);
7666 am->api_trace_cfg [VL_API_CLASSIFY_ADD_DEL_SESSION].size
7667 += 5 * sizeof (u32x4);
7668 am->api_trace_cfg [VL_API_VXLAN_ADD_DEL_TUNNEL].size
7669 += 16 * sizeof (u32);
7672 * Thread-safe API messages
7674 am->is_mp_safe [VL_API_IP_ADD_DEL_ROUTE] = 1;
7675 am->is_mp_safe [VL_API_GET_NODE_GRAPH] = 1;
7680 VLIB_API_INIT_FUNCTION(vpe_api_hookup);
7682 static clib_error_t *
7683 vpe_api_init (vlib_main_t *vm)
7685 vpe_api_main_t *am = &vpe_api_main;
7688 am->vnet_main = vnet_get_main();
7689 am->interface_events_registration_hash = hash_create (0, sizeof (uword));
7690 am->to_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7691 am->from_netconf_server_registration_hash = hash_create (0, sizeof (uword));
7692 am->to_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7693 am->from_netconf_client_registration_hash = hash_create (0, sizeof (uword));
7694 am->oam_events_registration_hash = hash_create (0, sizeof (uword));
7697 vl_set_memory_region_name ("/vpe-api");
7698 vl_enable_disable_memory_api (vm, 1 /* enable it */);
7703 VLIB_INIT_FUNCTION(vpe_api_init);
7706 static clib_error_t *
7707 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
7712 struct passwd _pw, *pw;
7713 struct group _grp, *grp;
7716 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7718 if (unformat (input, "prefix %s", &chroot_path))
7720 vec_add1 (chroot_path, 0);
7721 vl_set_memory_root_path ((char *)chroot_path);
7723 else if (unformat (input, "uid %d", &uid))
7724 vl_set_memory_uid (uid);
7725 else if (unformat (input, "gid %d", &gid))
7726 vl_set_memory_gid (gid);
7727 else if (unformat (input, "uid %s", &s))
7729 /* lookup the username */
7731 rv = getpwnam_r(s, &_pw, buf, sizeof(buf), &pw);
7734 e = clib_error_return_code(0, rv,
7735 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7736 "cannot fetch username %s", s);
7742 e = clib_error_return_fatal(0, "username %s does not exist", s);
7747 vl_set_memory_uid (pw->pw_uid);
7749 else if (unformat (input, "gid %s", &s))
7751 /* lookup the group name */
7753 rv = getgrnam_r(s, &_grp, buf, sizeof(buf), &grp);
7756 e = clib_error_return_code(0, rv,
7757 CLIB_ERROR_ERRNO_VALID | CLIB_ERROR_FATAL,
7758 "cannot fetch group %s", s);
7764 e = clib_error_return_fatal(0, "group %s does not exist", s);
7769 vl_set_memory_gid (grp->gr_gid);
7772 return clib_error_return (0, "unknown input `%U'",
7773 format_unformat_error, input);
7777 VLIB_EARLY_CONFIG_FUNCTION (api_segment_config, "api-segment");
7779 void * get_unformat_vnet_sw_interface (void)
7781 return (void *) &unformat_vnet_sw_interface;
7784 #undef vl_api_version
7785 #define vl_api_version(n,v) static u32 vpe_api_version = v;
7786 #include <vpp-api/vpe.api.h>
7787 #undef vl_api_version
7789 int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
7791 if (clib_host_to_net_u32(mp->api_versions[0]) != vpe_api_version) {
7792 clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
7793 clib_host_to_net_u32 (mp->api_versions[0]),
7800 static u8 * format_arp_event (u8 * s, va_list * args)
7802 vl_api_ip4_arp_event_t * event = va_arg (*args, vl_api_ip4_arp_event_t *);
7804 s = format (s, "pid %d: %U", event->pid,
7805 format_ip4_address, &event->address);
7809 static clib_error_t *
7810 show_ip4_arp_events_fn (vlib_main_t * vm,
7811 unformat_input_t * input,
7812 vlib_cli_command_t * cmd)
7814 vpe_api_main_t * am = &vpe_api_main;
7815 vl_api_ip4_arp_event_t * event;
7817 if (pool_elts (am->arp_events) == 0) {
7818 vlib_cli_output (vm, "No active arp event registrations");
7822 pool_foreach (event, am->arp_events,
7824 vlib_cli_output (vm, "%U", format_arp_event, event);
7830 VLIB_CLI_COMMAND (show_ip4_arp_events, static) = {
7831 .path = "show arp event registrations",
7832 .function = show_ip4_arp_events_fn,
7833 .short_help = "Show arp event registrations",